Example #1
0
 def upload_to_bioSamples(self, force=False):
     metadata_spreadsheet = self.eload_cfg['validation']['valid'][
         'metadata_spreadsheet']
     sample_tab_submitter = SampleMetadataSubmitter(metadata_spreadsheet)
     if sample_tab_submitter.check_submit_done() and not force:
         self.info(
             'Biosamples accession already provided in the metadata, Skip!')
         self.eload_cfg.set('brokering', 'Biosamples', 'pass', value=True)
     elif self.eload_cfg.query('brokering', 'Biosamples',
                               'Samples') and not force:
         self.info('BioSamples brokering is already done, Skip!')
     else:
         sample_name_to_accession = sample_tab_submitter.submit_to_bioSamples(
         )
         self.eload_cfg.set('brokering',
                            'Biosamples',
                            'date',
                            value=self.now)
         self.eload_cfg.set('brokering',
                            'Biosamples',
                            'Samples',
                            value=sample_name_to_accession)
         self.eload_cfg.set('brokering',
                            'Biosamples',
                            'pass',
                            value=bool(sample_name_to_accession))
Example #2
0
 def upload_to_bioSamples(self, force=False):
     metadata_spreadsheet = self.eload_cfg['validation']['valid']['metadata_spreadsheet']
     sample_metadata_submitter = SampleMetadataSubmitter(metadata_spreadsheet)
     if sample_metadata_submitter.check_submit_done() and not force:
         self.info('Biosamples accession already provided in the metadata, Skip!')
         self.eload_cfg.set('brokering', 'Biosamples', 'pass', value=True)
         # Retrieve the sample names to accession from the metadata
         sample_name_to_accession = sample_metadata_submitter.already_submitted_sample_names_to_accessions()
         self.eload_cfg.set('brokering', 'Biosamples', 'Samples', value=sample_name_to_accession)
     elif (
         self.eload_cfg.query('brokering', 'Biosamples', 'Samples')
         and self.eload_cfg.query('brokering', 'Biosamples', 'pass')
         and not force
     ):
         self.info('BioSamples brokering is already done, Skip!')
     else:
         sample_name_to_accession = sample_metadata_submitter.submit_to_bioSamples()
         # Check whether all samples have been accessioned
         passed = (
             bool(sample_name_to_accession)
             and all(sample_name in sample_name_to_accession for sample_name in sample_metadata_submitter.all_sample_names())
         )
         self.eload_cfg.set('brokering', 'Biosamples', 'date', value=self.now)
         self.eload_cfg.set('brokering', 'Biosamples', 'Samples', value=sample_name_to_accession)
         self.eload_cfg.set('brokering', 'Biosamples', 'pass', value=passed)
         # Make sure we crash if we haven't brokered everything
         if not passed:
             raise ValueError('Brokering to BioSamples failed!')
Example #3
0
 def setUp(self) -> None:
     brokering_folder = os.path.join(ROOT_DIR, 'tests', 'resources', 'brokering')
     metadata_file1 = os.path.join(brokering_folder, 'metadata_sheet.xlsx')
     metadata_file2 = os.path.join(brokering_folder, 'metadata_sheet2.xlsx')
     metadata_partial_file = os.path.join(brokering_folder, 'metadata_sheet_partial.xlsx')
     self.submitter_no_biosample_ids = SampleMetadataSubmitter(metadata_file1)
     self.submitter = SampleMetadataSubmitter(metadata_file2)
     self.submitter_partial_biosample_ids = SampleMetadataSubmitter(metadata_partial_file)
Example #4
0
class TestSampleMetadataSubmitter(BSDTestCase):

    top_dir = os.path.dirname(os.path.dirname(__file__))
    resources_folder = os.path.join(os.path.dirname(__file__), 'resources')

    def setUp(self) -> None:
        brokering_folder = os.path.join(ROOT_DIR, 'tests', 'resources', 'brokering')
        metadata_file1 = os.path.join(brokering_folder, 'metadata_sheet.xlsx')
        metadata_file2 = os.path.join(brokering_folder, 'metadata_sheet2.xlsx')
        self.submitter_no_biosample_ids = SampleMetadataSubmitter(metadata_file1)
        self.submitter = SampleMetadataSubmitter(metadata_file2)

    def test_map_metadata_to_bsd_data(self):
        now = '2020-07-06T19:09:29.090Z'
        biosamples_submission._now = now
        expected_payload = [
            {'name': 'S%s' % (i + 1), 'taxId': 9606, 'release': now,
             'contact': [{'LastName': 'John', 'FirstName': 'Doe', 'E-mail': '*****@*****.**'},
                         {'LastName': 'Jane', 'FirstName': 'Doe', 'E-mail': '*****@*****.**'}],
             'organization': [{'Name': 'GPE', 'Address': 'The place to be'},
                              {'Name': 'GPE', 'Address': 'The place to be'}],
             'characteristics': {
                'Organism': [{'text': 'H**o sapiens'}],
                'description': [{'text': 'Sample %s' % (i+1)}],
                'scientific name': [{'text': 'H**o sapiens'}]
            }}
            for i in range(100)
        ]
        payload = self.submitter.map_metadata_to_bsd_data()
        self.assertEqual(payload, expected_payload)

    def test_check_submit_done(self):
        # This data has already been brokered to BioSamples
        self.assertTrue(self.submitter_no_biosample_ids.check_submit_done())

    def test_check_submit_not_done(self):
        # This submitter contains data to broker to BioSamples
        self.assertFalse(self.submitter.check_submit_done())