def test_sample_composition_attributes(self): # Test a sample obs = SampleComposition(1) self.assertEqual(obs.sample_composition_type, 'experimental sample') self.assertEqual(obs.sample_id, '1.SKB1.640202') self.assertEqual(obs.content, '1.SKB1.640202.Test.plate.1.A1') self.assertEqual(obs.upstream_process, SamplePlatingProcess(11)) self.assertEqual(obs.container, Well(3073)) self.assertEqual(obs.total_volume, 10) self.assertIsNone(obs.notes) obs.notes = 'New Notes' self.assertEqual(obs.notes, 'New Notes') obs.notes = None self.assertIsNone(obs.notes) self.assertEqual(obs.composition_id, 3082) self.assertEqual(obs.study, Study(1)) # Test a control sample obs = SampleComposition(8) self.assertEqual(obs.sample_composition_type, 'blank') self.assertIsNone(obs.sample_id) self.assertEqual(obs.content, 'blank.Test.plate.1.H1') self.assertEqual(obs.upstream_process, SamplePlatingProcess(11)) self.assertEqual(obs.container, Well(3115)) self.assertEqual(obs.total_volume, 10) self.assertIsNone(obs.notes) self.assertEqual(obs.composition_id, 3124) self.assertIsNone(obs.study)
def test_get_well(self): # Plate 21 - Defined in the test DB tester = Plate(21) self.assertEqual(tester.get_well(1, 1), Well(3073)) self.assertEqual(tester.get_well(1, 2), Well(3121)) self.assertEqual(tester.get_well(7, 2), Well(3157)) self.assertEqual(tester.get_well(8, 12), Well(3643)) with self.assertRaises(LabControlError): tester.get_well(8, 13) with self.assertRaises(LabControlError): tester.get_well(9, 12)
def test_primer_set_composition_attributes(self): obs = PrimerSetComposition(1) self.assertEqual(obs.container, Well(1)) self.assertEqual(obs.total_volume, 0) self.assertIsNone(obs.notes) self.assertEqual(obs.composition_id, 1) self.assertEqual(obs.barcode, 'AGCCTTCGTCGC') self.assertIsNone(obs.study)
def test_library_prep_16S_composition_attributes(self): obs = LibraryPrep16SComposition(1) self.assertEqual(obs.container, Well(3075)) self.assertEqual(obs.total_volume, 10) self.assertIsNone(obs.notes) self.assertEqual(obs.gdna_composition, GDNAComposition(1)) self.assertEqual(obs.primer_composition, PrimerComposition(1)) self.assertEqual(obs.composition_id, 3084) self.assertEqual(obs.study, Study(1))
def test_gDNA_composition_attributes(self): obs = GDNAComposition(1) self.assertEqual(obs.sample_composition, SampleComposition(1)) self.assertEqual(obs.upstream_process, GDNAExtractionProcess(1)) self.assertEqual(obs.container, Well(3074)) self.assertEqual(obs.total_volume, 10) self.assertIsNone(obs.notes) self.assertEqual(obs.composition_id, 3083) self.assertEqual(obs.study, Study(1))
def test_properties(self): tester = Well(3073) self.assertEqual(tester.plate, Plate(21)) self.assertEqual(tester.row, 1) self.assertEqual(tester.column, 1) self.assertEqual(tester.remaining_volume, 10) self.assertIsNone(tester.notes) self.assertEqual(tester.latest_process, SamplePlatingProcess(11)) self.assertEqual(tester.container_id, 3082) self.assertEqual(tester.composition, SampleComposition(1))
def test_library_prep_shotgun_composition_attributes(self): obs = LibraryPrepShotgunComposition(1) self.assertEqual(obs.container, Well(3078)) self._baseAssertEqual(obs.total_volume, 4000) self.assertIsNone(obs.notes) self.assertEqual(obs.normalized_gdna_composition, NormalizedGDNAComposition(1)) self.assertEqual(obs.i5_composition, PrimerComposition(769)) self.assertEqual(obs.i7_composition, PrimerComposition(770)) self.assertEqual(obs.composition_id, 3087) self.assertEqual(obs.study, Study(1))
def test_normalized_gDNA_composition_attributes(self): obs = NormalizedGDNAComposition(1) self.assertEqual(obs.container, Well(3077)) self.assertEqual(obs.total_volume, 3500) self.assertIsNone(obs.notes) self.assertEqual(obs.compressed_gdna_composition, CompressedGDNAComposition(1)) self.assertEqual(obs.dna_volume, 415) self.assertEqual(obs.water_volume, 3085) self.assertEqual(obs.composition_id, 3086) self.assertEqual(obs.study, Study(1))
def test_well_id(self): self.assertEqual(Well(1).well_id, 'A1') self.assertEqual(Well(2).well_id, 'A2') self.assertEqual(Well(3).well_id, 'A3') self.assertEqual(Well(13).well_id, 'B1') self.assertEqual(Well(54).well_id, 'E6') self.assertEqual(Well(96).well_id, 'H12')
def test_primer_composition_attributes(self): obs = PrimerComposition(1) self.assertEqual(obs.container, Well(1537)) self.assertEqual(obs.total_volume, 10) self.assertIsNone(obs.notes) # NB: the fact that the composition id is 1538 and the well id is 1537 # is not a mistake. There is a placeholder composition (for "Not # Applicable", supporting externally extracted DNA) added in # db_patch_manual.sql, before populate_test_db.sql is run to create the # records being tested here--but that composition is "stored" in a # placeholder TUBE rather than a placeholder WELL, so there is no # analogous extra well record. self.assertEqual(obs.composition_id, 1538) self.assertEqual(obs.primer_set_composition, PrimerSetComposition(1)) self.assertIsNone(obs.study)
def test_get_previously_plated_wells(self): tester = Plate(21) three_plates_list = [Plate(27), Plate(30), Plate(33)] exp = { Well(3073): three_plates_list, Well(3079): three_plates_list, Well(3085): three_plates_list, Well(3091): three_plates_list, Well(3097): three_plates_list, Well(3103): three_plates_list, Well(3121): three_plates_list, Well(3127): three_plates_list, Well(3133): three_plates_list, Well(3139): three_plates_list, Well(3145): three_plates_list, Well(3151): three_plates_list, Well(3169): three_plates_list, Well(3175): three_plates_list, Well(3181): three_plates_list, Well(3187): three_plates_list, Well(3193): three_plates_list, Well(3199): three_plates_list, Well(3217): three_plates_list, Well(3223): three_plates_list, Well(3229): three_plates_list, Well(3235): three_plates_list, Well(3241): three_plates_list, Well(3247): three_plates_list, Well(3265): three_plates_list, Well(3271): three_plates_list, Well(3277): three_plates_list, Well(3283): three_plates_list, Well(3289): three_plates_list, Well(3295): three_plates_list, Well(3313): three_plates_list, Well(3319): three_plates_list, Well(3325): three_plates_list, Well(3331): three_plates_list, Well(3337): three_plates_list, Well(3343): three_plates_list, Well(3361): three_plates_list, Well(3367): three_plates_list, Well(3373): three_plates_list, Well(3379): three_plates_list, Well(3385): three_plates_list, Well(3391): three_plates_list, Well(3409): three_plates_list, Well(3415): three_plates_list, Well(3421): three_plates_list, Well(3427): three_plates_list, Well(3433): three_plates_list, Well(3439): three_plates_list, Well(3457): three_plates_list, Well(3463): three_plates_list, Well(3469): three_plates_list, Well(3475): three_plates_list, Well(3481): three_plates_list, Well(3487): three_plates_list, Well(3505): three_plates_list, Well(3511): three_plates_list, Well(3517): three_plates_list, Well(3523): three_plates_list, Well(3529): three_plates_list, Well(3535): three_plates_list, Well(3553): three_plates_list, Well(3559): three_plates_list, Well(3565): three_plates_list, Well(3571): three_plates_list, Well(3577): three_plates_list, Well(3583): three_plates_list, Well(3601): three_plates_list, Well(3607): three_plates_list, Well(3613): three_plates_list, Well(3619): three_plates_list, Well(3625): three_plates_list } obs = tester.get_previously_plated_wells() self.assertEqual(obs, exp) # Create another plate and put a sample on it that isn't anywhere else spp = SamplePlatingProcess.create(User('*****@*****.**'), PlateConfiguration(1), 'New Plate For Prev') spp.update_well(1, 1, '1.SKM1.640184') obs = spp.plate.get_previously_plated_wells() self.assertEqual(obs, {})
def test_get_wells_by_sample(self): tester = Plate(21) exp = [ Well(3073), Well(3121), Well(3169), Well(3217), Well(3265), Well(3313), Well(3361), Well(3409), Well(3457), Well(3505), Well(3553), Well(3601) ] self.assertEqual(tester.get_wells_by_sample('1.SKB1.640202'), exp) self.assertEqual(tester.get_wells_by_sample('1.SKM1.640183'), [])
def test_properties(self): # Plate 21 - Defined in the test DB tester = Plate(21) obs = tester.creation_timestamp obs = str(datetime.datetime(obs.year, obs.month, obs.day)) exp = datetime.datetime.now() exp = str(datetime.datetime(exp.year, exp.month, exp.day)) self.assertEqual(obs, exp) self.assertEqual(tester.external_id, 'Test plate 1') self.assertEqual(tester.plate_configuration, PlateConfiguration(1)) self.assertFalse(tester.discarded) tester.discarded = True self.assertTrue(tester.discarded) self.assertIsNone(tester.notes) obs_layout = tester.layout self.assertEqual(len(obs_layout), 8) for row in obs_layout: self.assertEqual(len(row), 12) self.assertEqual(tester.studies, {Study(1)}) self.assertListEqual(tester.quantification_processes, []) self.assertEqual(tester.process, SamplePlatingProcess(11)) # Test changing the name of the plate tester.external_id = 'Some new name' self.assertEqual(tester.external_id, 'Some new name') tester.external_id = 'Test plate 1' self.assertEqual(tester.external_id, 'Test plate 1') self.assertEqual(len(Plate(23).quantification_processes), 1) self.assertEqual( Plate(23).quantification_processes[0], QuantificationProcess(1)) self.assertEqual(Plate(22).process, GDNAExtractionProcess(1)) exp = { '1.SKB1.640202': [[Well(3073), '1.SKB1.640202.Test.plate.1.A1'], [Well(3121), '1.SKB1.640202.Test.plate.1.A2'], [Well(3169), '1.SKB1.640202.Test.plate.1.A3'], [Well(3217), '1.SKB1.640202.Test.plate.1.A4'], [Well(3265), '1.SKB1.640202.Test.plate.1.A5'], [Well(3313), '1.SKB1.640202.Test.plate.1.A6'], [Well(3361), '1.SKB1.640202.Test.plate.1.A7'], [Well(3409), '1.SKB1.640202.Test.plate.1.A8'], [Well(3457), '1.SKB1.640202.Test.plate.1.A9'], [Well(3505), '1.SKB1.640202.Test.plate.1.A10'], [Well(3553), '1.SKB1.640202.Test.plate.1.A11'], [Well(3601), '1.SKB1.640202.Test.plate.1.A12']], '1.SKB2.640194': [[Well(3079), '1.SKB2.640194.Test.plate.1.B1'], [Well(3127), '1.SKB2.640194.Test.plate.1.B2'], [Well(3175), '1.SKB2.640194.Test.plate.1.B3'], [Well(3223), '1.SKB2.640194.Test.plate.1.B4'], [Well(3271), '1.SKB2.640194.Test.plate.1.B5'], [Well(3319), '1.SKB2.640194.Test.plate.1.B6'], [Well(3367), '1.SKB2.640194.Test.plate.1.B7'], [Well(3415), '1.SKB2.640194.Test.plate.1.B8'], [Well(3463), '1.SKB2.640194.Test.plate.1.B9'], [Well(3511), '1.SKB2.640194.Test.plate.1.B10'], [Well(3559), '1.SKB2.640194.Test.plate.1.B11'], [Well(3607), '1.SKB2.640194.Test.plate.1.B12']], '1.SKB3.640195': [[Well(3085), '1.SKB3.640195.Test.plate.1.C1'], [Well(3133), '1.SKB3.640195.Test.plate.1.C2'], [Well(3181), '1.SKB3.640195.Test.plate.1.C3'], [Well(3229), '1.SKB3.640195.Test.plate.1.C4'], [Well(3277), '1.SKB3.640195.Test.plate.1.C5'], [Well(3325), '1.SKB3.640195.Test.plate.1.C6'], [Well(3373), '1.SKB3.640195.Test.plate.1.C7'], [Well(3421), '1.SKB3.640195.Test.plate.1.C8'], [Well(3469), '1.SKB3.640195.Test.plate.1.C9'], [Well(3517), '1.SKB3.640195.Test.plate.1.C10'], [Well(3565), '1.SKB3.640195.Test.plate.1.C11'], [Well(3613), '1.SKB3.640195.Test.plate.1.C12']], '1.SKB4.640189': [[Well(3091), '1.SKB4.640189.Test.plate.1.D1'], [Well(3139), '1.SKB4.640189.Test.plate.1.D2'], [Well(3187), '1.SKB4.640189.Test.plate.1.D3'], [Well(3235), '1.SKB4.640189.Test.plate.1.D4'], [Well(3283), '1.SKB4.640189.Test.plate.1.D5'], [Well(3331), '1.SKB4.640189.Test.plate.1.D6'], [Well(3379), '1.SKB4.640189.Test.plate.1.D7'], [Well(3427), '1.SKB4.640189.Test.plate.1.D8'], [Well(3475), '1.SKB4.640189.Test.plate.1.D9'], [Well(3523), '1.SKB4.640189.Test.plate.1.D10'], [Well(3571), '1.SKB4.640189.Test.plate.1.D11'], [Well(3619), '1.SKB4.640189.Test.plate.1.D12']], '1.SKB5.640181': [[Well(3097), '1.SKB5.640181.Test.plate.1.E1'], [Well(3145), '1.SKB5.640181.Test.plate.1.E2'], [Well(3193), '1.SKB5.640181.Test.plate.1.E3'], [Well(3241), '1.SKB5.640181.Test.plate.1.E4'], [Well(3289), '1.SKB5.640181.Test.plate.1.E5'], [Well(3337), '1.SKB5.640181.Test.plate.1.E6'], [Well(3385), '1.SKB5.640181.Test.plate.1.E7'], [Well(3433), '1.SKB5.640181.Test.plate.1.E8'], [Well(3481), '1.SKB5.640181.Test.plate.1.E9'], [Well(3529), '1.SKB5.640181.Test.plate.1.E10'], [Well(3577), '1.SKB5.640181.Test.plate.1.E11'], [Well(3625), '1.SKB5.640181.Test.plate.1.E12']], '1.SKB6.640176': [[Well(3103), '1.SKB6.640176.Test.plate.1.F1'], [Well(3151), '1.SKB6.640176.Test.plate.1.F2'], [Well(3199), '1.SKB6.640176.Test.plate.1.F3'], [Well(3247), '1.SKB6.640176.Test.plate.1.F4'], [Well(3295), '1.SKB6.640176.Test.plate.1.F5'], [Well(3343), '1.SKB6.640176.Test.plate.1.F6'], [Well(3391), '1.SKB6.640176.Test.plate.1.F7'], [Well(3439), '1.SKB6.640176.Test.plate.1.F8'], [Well(3487), '1.SKB6.640176.Test.plate.1.F9'], [Well(3535), '1.SKB6.640176.Test.plate.1.F10'], [Well(3583), '1.SKB6.640176.Test.plate.1.F11']] } self.assertEqual(tester.duplicates, exp) self.assertEqual(tester.unknown_samples, []) exp = tester.get_well(1, 1) exp.composition.update('Unknown') self.assertEqual(tester.unknown_samples, [exp]) exp.composition.update('1.SKB1.640202') # test that the quantification_processes attribute correctly # orders multiple processes in order from oldest to newest tester2 = Plate(26) self.assertEqual(len(tester2.quantification_processes), 2) # we are going to test the dates as string because in the database we # have the full date (including seconds) obs_date = str(tester2.quantification_processes[0].date) self.assertEqual(obs_date, "2017-10-25 19:10:25") obs_date = str(tester2.quantification_processes[1].date) self.assertEqual(obs_date, "2017-10-26 03:10:25")
def test_factory(self): self.assertEqual(Container.factory(3077), Tube(5)) self.assertEqual(Container.factory(1825), Well(1824))
def test_compressed_gDNA_composition_attributes(self): obs = CompressedGDNAComposition(1) self.assertEqual(obs.container, Well(3076)) self.assertEqual(obs.total_volume, 10) self.assertIsNone(obs.notes) self.assertEqual(obs.gdna_composition, GDNAComposition(1))
def get(self, plate_id): plate = _get_plate(plate_id) # sorting is done in plate.duplicates duplicates = [[ sample_info[0].row, sample_info[0].column, sample_info[1] ] for sample_info in chain.from_iterable(plate.duplicates.values())] # sorting of wells has to be done here as they are in a dictionary previous_plates = [] prev_plated = plate.get_previously_plated_wells() well_ids = sorted([w.id for w in prev_plated.keys()]) for curr_well_id in well_ids: curr_well = Well(curr_well_id) curr_plates = prev_plated[curr_well] # plates are sorted in plate id order in # get_previously_plated_wells previous_plates.append([[curr_well.row, curr_well.column], [{ 'plate_id': p.id, 'plate_name': p.external_id } for p in curr_plates]]) # sorting is done in plate.unknown_samples unknowns = [[well.row, well.column] for well in plate.unknown_samples] # sorting is done in plate.quantification processes quantitation_processes = [[ q.id, q.personnel.name, q.date.strftime(q.get_date_format()), q.notes ] for q in plate.quantification_processes] plate_config = plate.plate_configuration result = { 'plate_id': plate.id, 'plate_name': plate.external_id, 'discarded': plate.discarded, 'plate_configuration': [ plate_config.id, plate_config.description, plate_config.num_rows, plate_config.num_columns ], 'notes': plate.notes, 'process_notes': plate.process.notes, 'studies': sorted(s.id for s in plate.studies), 'duplicates': duplicates, 'previous_plates': previous_plates, 'unknowns': unknowns, 'quantitation_processes': quantitation_processes } self.write(result) self.finish()