def _get_ahringer_384_parent(child_stock): """ Get the 384-format LibraryStock corresponding to a 96-format child stock. Assumes standard Ahringer naming conventions. If the parent doesn't exist, creates it, assuming same parent as the child. """ child_plate_parts = child_stock.plate.id.split('-') parent_plate_name = child_plate_parts[0] + '-' + child_plate_parts[1] parent_plate = get_library_plate(parent_plate_name) child_well = child_stock.well parent_well = get_384_parent_well(child_plate_parts[2], child_well) parent_pk = generate_library_stock_name(parent_plate_name, parent_well) try: parent_stock = LibraryStock.objects.get(pk=parent_pk) except ObjectDoesNotExist: parent_stock = LibraryStock( id=parent_pk, plate=parent_plate, well=parent_well, parent_stock=None, intended_clone=child_stock.intended_clone, ) parent_stock.save() return parent_stock
def get_library_stock(legacy_plate_name, well): """Get a library well from its legacy plate name and well.""" library_stock_name = generate_library_stock_name(legacy_plate_name, well) try: return LibraryStock.objects.get(id=library_stock_name) except ObjectDoesNotExist: raise ObjectDoesNotExist(get_missing_object_message( 'LibraryStock', id=library_stock_name))
def sync_secondary_L4440_row(legacy_row): plate_name = legacy_row[0] well = get_three_character_well(legacy_row[1]) new_well = LibraryStock( id=generate_library_stock_name(plate_name, well), plate=get_library_plate(plate_name), well=well, parent_stock=None, intended_clone=get_clone('L4440')) return update_or_save_object(command, new_well, recorded_wells, fields_to_compare)
def handle(self, **options): require_db_write_acknowledgement() all_wells = get_well_set() # Get all wells, to determine which wells are missing. # # Skip 384-well plates, since the empty wells from these Ahringer # parent plates can be created in concert with their 96-well children. # # Also skip 'GHR-' style plates. Since we don't actually have these # plates in the lab, we only care about the small fraction of the # wells from these plates that were used to generated our Vidal # rearrays. library_stocks = (LibraryStock.objects.filter( plate__number_of_wells=96).exclude(plate__id__startswith='GHR-')) plate_wells = {} for library_stock in library_stocks: if library_stock.plate not in plate_wells: plate_wells[library_stock.plate] = set() plate_wells[library_stock.plate].add(library_stock.well) for library_plate in plate_wells: missing_wells = all_wells - plate_wells[library_plate] for missing_well in missing_wells: library_stock = LibraryStock( id=generate_library_stock_name(library_plate.id, missing_well), plate=library_plate, well=missing_well, parent_stock=None, intended_clone=None, ) if library_plate.is_ahringer_96_plate(): parent_stock = _get_ahringer_384_parent(library_stock) if parent_stock.intended_clone: self.stderr.write( '384 well {} has a non-null intended clone, ' 'but its 96-well derivative {} is empty\n'.format( parent_stock, library_stock)) library_stock.parent_stock = parent_stock library_stock.save()
def handle(self, **options): require_db_write_acknowledgement() all_wells = get_well_set() # Get all wells, to determine which wells are missing. # # Skip 384-well plates, since the empty wells from these Ahringer # parent plates can be created in concert with their 96-well children. # # Also skip 'GHR-' style plates. Since we don't actually have these # plates in the lab, we only care about the small fraction of the # wells from these plates that were used to generated our Vidal # rearrays. library_stocks = (LibraryStock.objects .filter(plate__number_of_wells=96) .exclude(plate__id__startswith='GHR-')) plate_wells = {} for library_stock in library_stocks: if library_stock.plate not in plate_wells: plate_wells[library_stock.plate] = set() plate_wells[library_stock.plate].add(library_stock.well) for library_plate in plate_wells: missing_wells = all_wells - plate_wells[library_plate] for missing_well in missing_wells: library_stock = LibraryStock( id=generate_library_stock_name(library_plate.id, missing_well), plate=library_plate, well=missing_well, parent_stock=None, intended_clone=None, ) if library_plate.is_ahringer_96_plate(): parent_stock = _get_ahringer_384_parent(library_stock) if parent_stock.intended_clone: self.stderr.write( '384 well {} has a non-null intended clone, ' 'but its 96-well derivative {} is empty\n' .format(parent_stock, library_stock)) library_stock.parent_stock = parent_stock library_stock.save()
def sync_primary_row(legacy_row): plate_name = legacy_row[0] well = get_three_character_well(legacy_row[1]) clone_name = legacy_row[2] parent_plate_name = legacy_row[4] if re.match('sjj', clone_name): parent_chromosome = legacy_row[3] parent_plate_name = generate_ahringer_384_plate_name( parent_chromosome, parent_plate_name) parent_well_improper = legacy_row[5] if re.match('mv', clone_name): clone_name = generate_vidal_clone_name(parent_plate_name, parent_well_improper) intended_clone = get_clone(clone_name) if re.match('L4440', clone_name): parent_stock = None else: parent_well_proper = get_three_character_well(parent_well_improper) parent_stock = get_library_stock(parent_plate_name, parent_well_proper) # Confirm that this intended clone matches parent's clone if parent_stock.intended_clone != intended_clone: raise CommandError('Clone {} does not match parent\n' .format(clone_name)) new_well = LibraryStock( id=generate_library_stock_name(plate_name, well), plate=get_library_plate(plate_name), well=well, parent_stock=parent_stock, intended_clone=intended_clone) return update_or_save_object(command, new_well, recorded_wells, fields_to_compare)
def sync_source_row(legacy_row): plate_name = legacy_row[0] clone_name = legacy_row[3] if re.match('sjj', clone_name): chromosome = legacy_row[2] plate_name = generate_ahringer_384_plate_name( chromosome, plate_name) well_improper = legacy_row[1] well_proper = get_three_character_well(well_improper) if re.match('mv', clone_name): clone_name = generate_vidal_clone_name(plate_name, well_improper) new_well = LibraryStock( id=generate_library_stock_name(plate_name, well_proper), plate=get_library_plate(plate_name), well=well_proper, parent_stock=None, intended_clone=get_clone(clone_name)) return update_or_save_object(command, new_well, recorded_wells, fields_to_compare)
def sync_eliana_row(legacy_row): plate_name = legacy_row[0] well = get_three_character_well(legacy_row[1]) if legacy_row[2]: try: parent_stock = get_library_stock(legacy_row[2], legacy_row[3]) intended_clone = parent_stock.intended_clone except ObjectDoesNotExist: parent_stock = None intended_clone = None else: parent_stock = None intended_clone = None new_well = LibraryStock( id=generate_library_stock_name(plate_name, well), plate=get_library_plate(plate_name), well=well, parent_stock=parent_stock, intended_clone=intended_clone) return update_or_save_object(command, new_well, recorded_wells, fields_to_compare)
def sync_secondary_row(legacy_row): plate_name = legacy_row[0] well = get_three_character_well(legacy_row[1]) clone_name = legacy_row[2] definite_parent_plate_name = legacy_row[3] definite_parent_well = legacy_row[4] if definite_parent_well: definite_parent_well = get_three_character_well( definite_parent_well) likely_parent_plate_name = legacy_row[5] likely_parent_well = legacy_row[6] if likely_parent_well: likely_parent_well = get_three_character_well(likely_parent_well) likely_parent_clone_name = legacy_row[7] if (definite_parent_plate_name and likely_parent_plate_name and definite_parent_plate_name != likely_parent_plate_name): raise CommandError( 'ERROR: definite and likely parent plates disagree ' 'for {} {}\n'.format(plate_name, well)) if (definite_parent_well and likely_parent_well and definite_parent_well != likely_parent_well): raise CommandError( 'ERROR: definite and likely parent wells disagree ' 'for {} {}\n'.format(plate_name, well)) try: if definite_parent_plate_name and definite_parent_well: parent_stock = get_library_stock(definite_parent_plate_name, definite_parent_well) else: parent_stock = get_library_stock(likely_parent_plate_name, likely_parent_well) intended_clone = parent_stock.intended_clone except ObjectDoesNotExist: command.stderr.write( 'WARNING for LibraryStock {} {}: parent not ' 'found in LibraryStock\n'.format(plate_name, well)) parent_stock = None intended_clone = None if clone_name and (clone_name != likely_parent_clone_name): command.stderr.write( 'WARNING for LibraryStock {} {}: clone recorded ' 'in CherryPickRNAiPlate is inconsistent with ' 'CherryPickTemplate source/destination records\n' .format(plate_name, well)) if re.match('sjj', clone_name): try: recorded_clone = get_clone(clone_name) if recorded_clone != intended_clone: command.stderr.write( 'WARNING for LibraryStock {} {}: clone recorded ' 'in CherryPickRNAiPlate does not match its ' 'parent\'s clone\n'.format(plate_name, well)) except ObjectDoesNotExist: command.stderr.write( 'WARNING for LibraryStock {} {}: clone recorded in ' 'CherryPickRNAiPlate not found at all in RNAiPlate\n' .format(plate_name, well)) new_well = LibraryStock( id=generate_library_stock_name(plate_name, well), plate=get_library_plate(plate_name), well=well, parent_stock=parent_stock, intended_clone=intended_clone) return update_or_save_object(command, new_well, recorded_wells, fields_to_compare)