def test_annotate(self):
    collection = self.res.collection.create(name='Test annotate collection')
    (reads_1, reads_2, reads_2b, reads_4, reads_5) = self.get_reads(5, collection)
    bam = self.get_bams(1, collection)[0]
    sample_1 = reads_1.sample
    sample_1.name = 'Sample 1'
    sample_1.save()
    sample_2 = reads_2.sample
    sample_2.name = 'Sample 2'
    sample_2.save()
    sample_2b = reads_2b.sample
    sample_2b.name = 'Sample 2'
    sample_2b.save()
    sample_3 = bam.sample
    sample_3.name = 'Sample 3'
    sample_3.save()
    sample_4 = reads_4.sample
    sample_4.name = 'missing organism'
    sample_4.save()
    sample_5 = reads_5.sample
    sample_5.name = 'missing source'
    sample_5.save()
    samplesheet = self.get_samplesheet()
    with self.assertLogs() as logs:
        collection.annotate(samplesheet)
    self.assertEqual(len(logs.output), 14)
    samplesheet_errprefix = 'ERROR:resdk.data_upload.samplesheet:'
    samplesheet_errors = ["For the sample, '', '' is not a valid SAMPLE_NAME.", "For the sample, 'missing annotator', '' is not a valid ANNOTATOR.", "For the sample, 'missing organism', '' is not a valid ORGANISM.", "For the sample, 'missing source', '' is not a valid SOURCE.", "For the sample, 'missing molecule', '' is not a valid MOLECULE.", "For the sample, 'missing seq_type', '' is not a valid SEQ_TYPE.", "The sample name 'duplicated sample' is duplicated. Please use unique sample names."]
    for error in samplesheet_errors:
        message = (samplesheet_errprefix + error)
        self.assertIn(message, logs.output)
    invalid_samples = [' ,', 'missing annotator', 'missing organism', 'missing source', 'missing molecule', 'missing seq_type', 'duplicated sample']
    for invalid in invalid_samples:
        self.assertIn(invalid, logs.output[7])
    missing_samples = ['single-reads', 'paired-reads', 'bad single path', 'bad paired path', ' ,', 'missing annotator', 'missing molecule', 'missing seq_type', 'duplicated sample']
    for missing in missing_samples:
        self.assertIn(missing, logs.output[8])
    present_samples = ['Sample 1', 'Sample 2', 'Sample 3', 'missing organism', 'missing source']
    for present in present_samples:
        self.assertNotIn(present, logs.output[8])
    duplicate_error = "ERROR:resdk.data_upload.annotate_samples:Multiple samples are queried by the name 'Sample 2'. Annotation will not be applied."
    self.assertIn(duplicate_error, logs.output)
    ann_1 = {'sample': {'genotype': 'ANIMAL 1:\xa0PBCAG-FUS1, PBCAG-eGFP, PBCAG-mCherry, GLAST-PBase,\xa0PX330-P53', 'cell_type': 'Mixed', 'optional_char': ['AGE:38 days', 'LIBRARY_STRATEGY:Illumina Standard Prep ', 'OTHER_CHAR_1:2x75 bp', 'OTHER_CHAR_2:subdural cortical tumor, frontal/lateral location. Easily isolated sample', 'TISSUE:Tumor'], 'strain': '', 'source': 'Tumor', 'organism': 'Rattus norvegicus', 'molecule': 'total RNA', 'annotator': 'Tristan Brown', 'description': ''}}
    ann_2 = {}
    ann_3 = {'sample': {'genotype': 'AX4', 'cell_type': '', 'optional_char': ['LIBRARY_STRATEGY:Illumina Standard Prep ', 'OTHER_CHAR_1:300 bp'], 'strain': 'Non-aggregating', 'source': 'Cell', 'organism': 'Dictyostelium discoideum', 'molecule': 'genomic DNA', 'annotator': 'Tristan Brown', 'description': ''}}
    reads_ann_1 = {'experiment_type': 'RNA-Seq', 'protocols': {'antibody_information': {'manufacturer': ''}, 'extract_protocol': 'Standard', 'fragmentation_method': '', 'growth_protocol': 'Standard media', 'library_prep': 'Illumina', 'treatment_protocol': 'Control'}, 'reads_info': {'barcode': '', 'facility': '', 'instrument_type': ''}}
    sample_1.update()
    sample_2.update()
    sample_2b.update()
    sample_3.update()
    self.assertEqual(sample_1.descriptor, ann_1)
    self.assertEqual(sample_1.data[0].descriptor, reads_ann_1)
    self.assertEqual(sample_1.tags, ['community:rna-seq'])
    self.assertEqual(sample_2.descriptor, ann_2)
    self.assertEqual(sample_2b.descriptor, ann_2)
    self.assertEqual(sample_3.descriptor, ann_3)
    self.assertEqual(sample_4.descriptor, {})
    self.assertEqual(sample_5.descriptor, {})
def test_annotate(self):
    collection = self.res.collection.create(name='Test annotate collection')
    (reads_1, reads_2, reads_2b, reads_4, reads_5) = self.get_reads(5, collection)
    bam = self.get_bams(1, collection)[0]
    sample_1 = reads_1.sample
    sample_1.name = 'Sample 1'
    sample_1.save()
    sample_2 = reads_2.sample
    sample_2.name = 'Sample 2'
    sample_2.save()
    sample_2b = reads_2b.sample
    sample_2b.name = 'Sample 2'
    sample_2b.save()
    sample_3 = bam.sample
    sample_3.name = 'Sample 3'
    sample_3.save()
    sample_4 = reads_4.sample
    sample_4.name = 'missing organism'
    sample_4.save()
    sample_5 = reads_5.sample
    sample_5.name = 'missing source'
    sample_5.save()
    samplesheet = self.get_samplesheet()
    with self.assertLogs() as logs:
        collection.annotate(samplesheet)
    self.assertEqual(len(logs.output), 14)
    samplesheet_errprefix = 'ERROR:resdk.data_upload.samplesheet:'
    samplesheet_errors = ["For the sample, ,  is not a valid SAMPLE_NAME.", "For the sample, 'missing annotator',  is not a valid ANNOTATOR.", "For the sample, 'missing organism',  is not a valid ORGANISM.", "For the sample, 'missing source',  is not a valid SOURCE.", "For the sample, 'missing molecule',  is not a valid MOLECULE.", "For the sample, 'missing seq_type',  is not a valid SEQ_TYPE.", "The sample name 'duplicated sample' is duplicated. Please use unique sample names."]
    for error in samplesheet_errors:
        message = (samplesheet_errprefix + error)
        self.assertIn(message, logs.output)
    invalid_samples = [' ,', 'missing annotator', 'missing organism', 'missing source', 'missing molecule', 'missing seq_type', 'duplicated sample']
    for invalid in invalid_samples:
        self.assertIn(invalid, logs.output[7])
    missing_samples = ['single-reads', 'paired-reads', 'bad single path', 'bad paired path', ' ,', 'missing annotator', 'missing molecule', 'missing seq_type', 'duplicated sample']
    for missing in missing_samples:
        self.assertIn(missing, logs.output[8])
    present_samples = ['Sample 1', 'Sample 2', 'Sample 3', 'missing organism', 'missing source']
    for present in present_samples:
        self.assertNotIn(present, logs.output[8])
    duplicate_error = "ERROR:resdk.data_upload.annotate_samples:Multiple samples are queried by the name 'Sample 2'. Annotation will not be applied."
    self.assertIn(duplicate_error, logs.output)
    ann_1 = {'sample': {'genotype': 'ANIMAL 1:\xa0PBCAG-FUS1, PBCAG-eGFP, PBCAG-mCherry, GLAST-PBase,\xa0PX330-P53', 'cell_type': 'Mixed', 'optional_char': ['AGE:38 days', 'LIBRARY_STRATEGY:Illumina Standard Prep ', 'OTHER_CHAR_1:2x75 bp', 'OTHER_CHAR_2:subdural cortical tumor, frontal/lateral location. Easily isolated sample', 'TISSUE:Tumor'], 'strain': , 'source': 'Tumor', 'organism': 'Rattus norvegicus', 'molecule': 'total RNA', 'annotator': 'Tristan Brown', 'description': }}
    ann_2 = {}
    ann_3 = {'sample': {'genotype': 'AX4', 'cell_type': , 'optional_char': ['LIBRARY_STRATEGY:Illumina Standard Prep ', 'OTHER_CHAR_1:300 bp'], 'strain': 'Non-aggregating', 'source': 'Cell', 'organism': 'Dictyostelium discoideum', 'molecule': 'genomic DNA', 'annotator': 'Tristan Brown', 'description': }}
    reads_ann_1 = {'experiment_type': 'RNA-Seq', 'protocols': {'antibody_information': {'manufacturer': }, 'extract_protocol': 'Standard', 'fragmentation_method': , 'growth_protocol': 'Standard media', 'library_prep': 'Illumina', 'treatment_protocol': 'Control'}, 'reads_info': {'barcode': , 'facility': , 'instrument_type': }}
    sample_1.update()
    sample_2.update()
    sample_2b.update()
    sample_3.update()
    self.assertEqual(sample_1.descriptor, ann_1)
    self.assertEqual(sample_1.data[0].descriptor, reads_ann_1)
    self.assertEqual(sample_1.tags, ['community:rna-seq'])
    self.assertEqual(sample_2.descriptor, ann_2)
    self.assertEqual(sample_2b.descriptor, ann_2)
    self.assertEqual(sample_3.descriptor, ann_3)
    self.assertEqual(sample_4.descriptor, {})
    self.assertEqual(sample_5.descriptor, {})