Skip to content

Commit

Permalink
single-stranded library web interface support #145
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewMah committed May 2, 2024
1 parent ad0dcee commit 1a871ec
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
17 changes: 10 additions & 7 deletions samples/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,12 +537,14 @@ def __init__(self, *args, **kwargs):
for option in ['rotated']:
self.fields[option].disabled = True
# ensure current values are allowed form values
if self.instance.protocol:
self.fields['protocol'].queryset = LibraryProtocol.objects.filter(Q(active=True) | Q(id=self.instance.protocol.id) ).order_by('-start_date')
if self.instance.protocol.library_type == 'ss':
self.fields['p7_offset'].required = False
if self.instance.control_set:
self.fields['control_set'].queryset = ControlSet.objects.filter(Q(active=True) | Q(id=self.instance.control_set.id)).order_by('layout_name')
self.fields['p7_offset'].required = False
if self.instance:
if self.instance.protocol:
self.fields['protocol'].queryset = LibraryProtocol.objects.filter(Q(active=True) | Q(id=self.instance.protocol.id) ).order_by('-start_date')
if self.instance.protocol.library_type == 'ds':
self.fields['p7_offset'].required = True
if self.instance.control_set:
self.fields['control_set'].queryset = ControlSet.objects.filter(Q(active=True) | Q(id=self.instance.control_set.id)).order_by('layout_name')

# to view fields without being able to modify prior to deletion
def disable_fields(self):
Expand Down Expand Up @@ -573,13 +575,14 @@ class Meta:
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['reich_lab_library_id'].disabled = True
for option in ['nanodrop', 'qpcr_ds', 'qpcr_assay_a_1_ss', 'qpcr_assay_a_2_ss', 'qpcr_assay_b_1_ss', 'qpcr_assay_b_2_ss', 'assay_a_percent_inhibition', 'assay_b_total_molecules']:
for option in ['p5_index', 'p7_index', 'p5_barcode', 'p7_barcode', 'nanodrop', 'qpcr_ds', 'qpcr_assay_a_1_ss', 'qpcr_assay_a_2_ss', 'qpcr_assay_b_1_ss', 'qpcr_assay_b_2_ss', 'assay_a_percent_inhibition', 'assay_b_total_molecules']:
self.fields[option].required = False
if self.instance:
layout_elements = self.instance.librarybatchlayout_set
layout_element = layout_elements.get(library=self.instance)
self.initial['well_position'] = str(layout_element)


LibraryFormset = modelformset_factory(Library, form=LibraryForm, extra=0)

# raise validation error if capture batch name already exists
Expand Down
17 changes: 10 additions & 7 deletions samples/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1731,9 +1731,7 @@ def create_library_from_extract(layout_element, user, *, i5=None, i7=None, ul_ex
p5_barcode = Barcode.objects.get(label = p5_qstr)
p7_barcode = Barcode.objects.get(label = p7_qstr)
elif library_batch.protocol.library_type == 'ss':
# indices are assigned in arguments
if i5 is None or i7 is None:
raise ValueError(f'single stranded needs assigned indices')
# indices are assigned in arguments, or deferred and loaded later
p5_barcode = None
p7_barcode = None
else:
Expand All @@ -1753,7 +1751,8 @@ def create_library_from_extract(layout_element, user, *, i5=None, i7=None, ul_ex
p5_barcode = p5_barcode,
p7_barcode = p7_barcode
)
library.clean()
if library_batch.protocol.library_type != 'ss': # ss indices can be assigned later
library.clean()
library.save(save_user=user)
layout_element.library = library
layout_element.ul_extract_used = library.ul_extract_used
Expand Down Expand Up @@ -1841,8 +1840,9 @@ def create_libraries(self, user):
layout = self.layout_elements()
duplicate_positions_check_db(layout)

for layout_element in layout:
create_library_from_extract(layout_element, user)
with transaction.atomic():
for layout_element in layout:
create_library_from_extract(layout_element, user)

def get_robot_layout(self):
self.check_p7_offset()
Expand Down Expand Up @@ -1885,6 +1885,7 @@ def set_controls(self, user):
layout_element.ul_extract_used = 0
layout_element.save(save_user=user)

@transaction.atomic
def libraries_from_spreadsheet(self, spreadsheet, user):
headers, data_rows = spreadsheet_headers_and_data_rows(spreadsheet)

Expand Down Expand Up @@ -2120,6 +2121,8 @@ def clean(self):
raise ValidationError(_('Library must have either indices or barcodes'))
if self.sample and self.extract and self.sample != self.extract.get_sample():
raise ValidationError(_('Library has sample mismatch'))
if self.library_type == 'ss' and self.p5_index is None or self.p7_index is None:
raise ValidationError(_('single-stranded library is missing indices'))

# barcodes and indices are unique, so we only need to check ids, not DNA sequences
def barcodes_are_distinct(self, other):
Expand Down Expand Up @@ -2247,7 +2250,7 @@ def from_spreadsheet_row(self, headers, arg_array, user):
except Barcode.DoesNotExist:
library.p7_barcode = None

library.nanodrop = float(arg_array[headers.index('nanodrop')])
library.nanodrop = value_convert_or_none(arg_array[headers.index('nanodrop')], float)
library.qpcr_ds = value_convert_or_none(arg_array[headers.index('qpcr_ds')], decimal.Decimal)
library.qpcr_assay_a_1_ss = value_convert_or_none(arg_array[headers.index('qpcr_assay_a_1_ss')], decimal.Decimal)
library.qpcr_assay_a_2_ss = value_convert_or_none(arg_array[headers.index('qpcr_assay_a_2_ss')], decimal.Decimal)
Expand Down
2 changes: 2 additions & 0 deletions samples/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,8 @@ def libraries_in_batch(request):
if library_batch_form.is_valid() and libraries_formset.is_valid():
if library_batch.status == library_batch.OPEN:
return redirect(f'{reverse("library_batch_assign_extract")}?library_batch_name={library_batch_name}')
elif library_batch.status == library_batch.CLOSED:
library_batch.clean()

elif request.method == 'GET':
library_batch_form = LibraryBatchForm(instance=library_batch, user=request.user)
Expand Down
2 changes: 2 additions & 0 deletions screening/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@

USE_TZ = True

DATA_UPLOAD_MAX_NUMBER_FIELDS = 2000


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/
Expand Down

0 comments on commit 1a871ec

Please sign in to comment.