Exemplo n.º 1
0
    def test_loading_differing_index_equality(self):
        # Note: I'm not sure if this is a feature or a bug so if this test fails it's okay,
        # but it's a situation worth noting about our current implementation
        s_1 = {
            's_alias': 'STUD',
            's_index': 'over-written index1',
            's_name': 'over-written name1'
        }
        s_2 = {
            's_index': 'STUD',
            's_name': 'over-written name2'
        }
        s_3 = {
            's_name': 'STUD'
        }
        expected_s = {
            's_alias': 'STUD',
            's_index': 'STUD',
            's_name': 'STUD'
        }
        submission = ExcelSubmission()
        s_entity1 = ExcelLoader.map_row_entity(submission, 1, 's', s_1)
        s_entity2 = ExcelLoader.map_row_entity(submission, 2, 's', s_2)
        s_entity3 = ExcelLoader.map_row_entity(submission, 3, 's', s_3)

        self.assertEqual(s_entity1, s_entity2)
        self.assertEqual(s_entity1, s_entity3)        
        self.assertDictEqual(expected_s, s_entity1.attributes)
    def test_unmapped_service_accessions(self):
        expected_accessions = {
            'array_express': {'A1', 'A2'},
            'eva': {'EVA1', 'EVA2'}
        }
        submission = ExcelSubmission()
        sequence1 = {
            'sequence_array_express_accession': 'A1',
            'sequence_eva_accession': 'EVA1',
        }
        sequence2 = {
            'sequence_array_express_accession': 'A2',
            'sequence_eva_accession': 'EVA2',
        }
        sequence_entity1 = ExcelLoader.map_row_entity(submission, 1,
                                                      'sequence', sequence1)
        sequence_entity2 = ExcelLoader.map_row_entity(submission, 2,
                                                      'sequence', sequence2)

        self.assertDictEqual(expected_accessions,
                             submission.get_all_accessions())
        self.assertEqual('A1', sequence_entity1.get_accession('array_express'))
        self.assertEqual('EVA1', sequence_entity1.get_accession('eva'))
        self.assertEqual('A2', sequence_entity2.get_accession('array_express'))
        self.assertEqual('EVA2', sequence_entity2.get_accession('eva'))
Exemplo n.º 3
0
    def test_loading_without_index(self):
        submission = ExcelSubmission()
        entity1 = ExcelLoader.map_row_entity(submission, 1, 'lorem', {})
        entity2 = ExcelLoader.map_row_entity(submission, 2, 'ipsum', {})

        self.assertNotEqual(entity1, entity2)
        self.assertEqual('lorem:1', entity1.identifier.index)
        self.assertEqual('ipsum:2', entity2.identifier.index)
Exemplo n.º 4
0
    def test_loading_accession_equality(self):
        submission = ExcelSubmission()
        study_entity1 = ExcelLoader.map_row_entity(submission, 1, 'study', {'study_accession': 'STUD1'})
        sample_entity1 = ExcelLoader.map_row_entity(submission, 1, 'sample', {'sample_accession': 'SAME1'})

        study_entity2 = ExcelLoader.map_row_entity(submission, 2, 'study', {'study_accession': 'STUD1'})
        sample_entity2 = ExcelLoader.map_row_entity(submission, 2, 'sample', {'sample_accession': 'SAME2'})

        self.assertEqual(study_entity1, study_entity2)
        self.assertNotEqual(sample_entity1, sample_entity2)
    def test_mapped_accessions(self):
        expected_accessions = {
            'BioStudies': {'S-BSST1'},
            'BioSamples': {'SAME1'},
            'ENA_Project': {'PRJEB1'},
            'ENA_Study': {'ERP1'},
            'ENA_Sample': {'ERS1'},
            'ENA_Experiment': {'ERX1', 'ERX2'},
            'ENA_Run': {'ERR1', 'ERR2'}
        }
        submission = ExcelSubmission()
        study = {
            'study_biostudies_accession': 'S-BSST1',
            'study_ena_project_accession': 'PRJEB1',
            'study_ena_study_accession': 'ERP1'
        }
        sample = {
            'sample_biosamples_accession': 'SAME1',
            'sample_ena_sample_accession': 'ERS1'
        }
        run_experiment1 = {
            'run_experiment_ena_experiment_accession': 'ERX1',
            'run_experiment_ena_run_accession': 'ERR1',
        }
        run_experiment2 = {
            'run_experiment_ena_experiment_accession': 'ERX2',
            'run_experiment_ena_run_accession': 'ERR2',
        }
        study_entity1 = ExcelLoader.map_row_entity(submission, 1, 'study',
                                                   study)
        sample_entity1 = ExcelLoader.map_row_entity(submission, 1, 'sample',
                                                    sample)
        run_entity1 = ExcelLoader.map_row_entity(submission, 1,
                                                 'run_experiment',
                                                 run_experiment1)
        run_entity2 = ExcelLoader.map_row_entity(submission, 2,
                                                 'run_experiment',
                                                 run_experiment2)

        self.assertDictEqual(expected_accessions,
                             submission.get_all_accessions())
        self.assertEqual('S-BSST1', study_entity1.get_accession('BioStudies'))
        self.assertEqual('PRJEB1', study_entity1.get_accession('ENA_Project'))
        self.assertEqual('ERP1', study_entity1.get_accession('ENA_Study'))

        self.assertEqual('SAME1', sample_entity1.get_accession('BioSamples'))
        self.assertEqual('ERS1', sample_entity1.get_accession('ENA_Sample'))

        self.assertEqual('ERR1', run_entity1.get_accession('ENA_Run'))
        self.assertEqual('ERX1', run_entity1.get_accession('ENA_Experiment'))

        self.assertEqual('ERR2', run_entity2.get_accession('ENA_Run'))
        self.assertEqual('ERX2', run_entity2.get_accession('ENA_Experiment'))
    def test_default_accessions(self):
        expected_accessions = {
            'BioStudies': {'S-BSST1'},
            'BioSamples': {'SAME1'},
            'ENA_Run': {'ERR1', 'ERR2'}
        }
        submission = ExcelSubmission()
        study = {
            'study_accession': 'S-BSST1',
        }
        sample = {
            'sample_accession': 'SAME1',
        }
        run_experiment1 = {
            'run_experiment_accession': 'ERR1',
        }
        run_experiment2 = {
            'run_experiment_accession': 'ERR2',
        }
        study_entity1 = ExcelLoader.map_row_entity(submission, 1, 'study',
                                                   study)
        sample_entity1 = ExcelLoader.map_row_entity(submission, 1, 'sample',
                                                    sample)
        run_entity1 = ExcelLoader.map_row_entity(submission, 1,
                                                 'run_experiment',
                                                 run_experiment1)
        run_entity2 = ExcelLoader.map_row_entity(submission, 2,
                                                 'run_experiment',
                                                 run_experiment2)

        self.assertDictEqual(expected_accessions,
                             submission.get_all_accessions())
        self.assertEqual('S-BSST1', study_entity1.identifier.index)
        self.assertEqual('S-BSST1', study_entity1.get_accession('BioStudies'))

        self.assertEqual('SAME1', sample_entity1.identifier.index)
        self.assertEqual('SAME1', sample_entity1.get_accession('BioSamples'))

        self.assertEqual('ERR1', run_entity1.identifier.index)
        self.assertEqual('ERR1', run_entity1.get_accession('ENA_Run'))

        self.assertEqual('ERR2', run_entity2.identifier.index)
        self.assertEqual('ERR2', run_entity2.get_accession('ENA_Run'))
    def test_umnapped_no_service_accession(self):
        # In the case that {object}_accession is used in the excel for an object that isn't configured with a default service
        # Use the accession as an index but do not add the accession to the entity.
        attributes = {'lorem_accession': 'ipsum'}

        submission = ExcelSubmission()
        lorem_entity = ExcelLoader.map_row_entity(submission, 1, 'lorem',
                                                  attributes)

        self.assertEqual('ipsum', lorem_entity.identifier.index)
        self.assertFalse(lorem_entity.get_accessions())
Exemplo n.º 8
0
    def test_links(self):
        submission = ExcelSubmission()
        study_entity1 = ExcelLoader.map_row_entity(submission, 1, 'study', {'study_accession': 'STUD1'})
        sample_entity1 = ExcelLoader.map_row_entity(submission, 1, 'sample', {'sample_accession': 'SAME1'})
        run_entity1 = ExcelLoader.map_row_entity(submission, 1, 'run_experiment', {'run_experiment_accession': 'RUN1'})
        ExcelLoader.map_row_entity(submission, 2, 'study', {'study_accession': 'STUD1'})
        ExcelLoader.map_row_entity(submission, 2, 'sample', {'sample_accession': 'SAME1'})
        run_entity2 = ExcelLoader.map_row_entity(submission, 2, 'run_experiment', {'run_experiment_accession': 'RUN2'})
        
        self.assertSetEqual({'SAME1'}, study_entity1.get_linked_indexes('sample'))
        self.assertSetEqual({'RUN1', 'RUN2'}, study_entity1.get_linked_indexes('run_experiment'))

        self.assertSetEqual({'STUD1'}, sample_entity1.get_linked_indexes('study'))
        self.assertSetEqual({'RUN1', 'RUN2'}, sample_entity1.get_linked_indexes('run_experiment'))

        self.assertSetEqual({'STUD1'}, run_entity1.get_linked_indexes('study'))
        self.assertSetEqual({'SAME1'}, run_entity1.get_linked_indexes('sample'))

        self.assertSetEqual({'STUD1'}, run_entity2.get_linked_indexes('study'))
        self.assertSetEqual({'SAME1'}, run_entity2.get_linked_indexes('sample'))
Exemplo n.º 9
0
    def test_loading_index_equality(self):
        submission = ExcelSubmission()
        study_entity1 = ExcelLoader.map_row_entity(submission, 1, 'study', {'study_alias': 'STUD1'})
        sample_entity1 = ExcelLoader.map_row_entity(submission, 1, 'sample', {'sample_index': 'SAME1'})
        run_entity1 = ExcelLoader.map_row_entity(submission, 1, 'run', {'run_name': 'John'})

        study_entity2 = ExcelLoader.map_row_entity(submission, 2, 'study', {'study_alias': 'STUD1'})
        sample_entity2 = ExcelLoader.map_row_entity(submission, 2, 'sample', {'sample_index': 'SAME1'})
        run_entity2 = ExcelLoader.map_row_entity(submission, 2, 'run', {'run_name': 'Jill'})

        self.assertEqual(study_entity1, study_entity2)
        self.assertEqual(sample_entity1, sample_entity2)
        self.assertNotEqual(run_entity1, run_entity2)