Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hack to remove the null values in external reference #169

Merged
merged 2 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions eva_submission/biosamples_submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,15 @@ def validate_in_bsd(self, samples_data):
def convert_sample_data_to_curation_object(self, future_sample):
"""Curation object can only change 3 attributes characteristics, externalReferences and relationships"""
current_sample = self.communicator.follows_link('samples', method='GET', join_url=future_sample.get('accession'))

#FIXME: Remove this hack when this i fixed on BioSample's side
# remove null values in externalReferences that causes crash when POSTing the curation object
if 'externalReferences' in current_sample:
current_sample['externalReferences'] = [
dict([(k, v) for k, v in external_ref.items() if v is not None])
for external_ref in current_sample['externalReferences']
]

curation_object = {}
attributes_pre = []
attributes_post = []
Expand Down Expand Up @@ -481,5 +490,14 @@ def retrieve_biosamples(self):
if 'externalReferences' not in sample_json:
sample_json['externalReferences'] = []
sample_json['externalReferences'].append({'url': eva_study_url})

# FIXME: Remove this hack when this i fixed on BioSample's side
# remove null values in externalReferences that causes crash when POSTing the curation object
if 'externalReferences' in sample_json:
sample_json['externalReferences'] = [
dict([(k, v) for k, v in external_ref.items() if v is not None])
for external_ref in sample_json['externalReferences']
]
biosample_objects.append(sample_json)

return biosample_objects
4 changes: 2 additions & 2 deletions tests/test_submit_to_bsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,12 +352,12 @@ class TestSampleReferenceSubmitter(BSDTestCase):
def test_retrieve_biosamples(self):
sample_accessions = ['SAME001', 'SAME002']
project_accession = 'PRJEB001'
sample_1 = {"name": "FakeSample1", "accession": "SAME001", "domain": "self.ExampleDomain", "_links": {}}
sample_1 = {"name": "FakeSample1", "accession": "SAME001", "domain": "self.ExampleDomain", "_links": {}, 'externalReferences': [{'url': 'test_url', 'duo': None}]}
sample_2 = {"name": "FakeSample2", "accession": "SAME002", "domain": "self.ExampleDomain", "_links": {}}
with patch.object(HALCommunicator, 'follows_link', side_effect=[sample_1, sample_2]):
self.submitter = SampleReferenceSubmitter(sample_accessions, project_accession)
assert self.submitter.sample_data == [
{'name': 'FakeSample1', 'accession': 'SAME001', 'domain': 'self.ExampleDomain', 'externalReferences': [{'url': 'https://www.ebi.ac.uk/eva/?eva-study=PRJEB001'}]},
{'name': 'FakeSample1', 'accession': 'SAME001', 'domain': 'self.ExampleDomain', 'externalReferences': [{'url': 'test_url'}, {'url': 'https://www.ebi.ac.uk/eva/?eva-study=PRJEB001'}]},
{'name': 'FakeSample2', 'accession': 'SAME002', 'domain': 'self.ExampleDomain', 'externalReferences': [{'url': 'https://www.ebi.ac.uk/eva/?eva-study=PRJEB001'}]}
]

Loading