Updating submitted samples

A pretty cool thing about BioSamples is that you can always update the sample after submission. Let’s say you’ve got a sample, and you want to add a couple extra fields; you looked into your lab notebook and finally deciphered those scribbles that you thought was either elf language or LSD exposition.

The BsdApi makes it even simpler; you just need to retrieve your samples, update them as needed, and send the list back to the update function.

IMPORTANT NOTE: Biosamples does NOT accept patch requests. What this means in plain english is: You replace the sample completely when updating. Please take that into account when performing updates!

Set-up and retrieve existing samples

[2]:
## Import everything we need
from biobroker.authenticator import WebinAuthenticator # Biosamples uses the WebinAuthenticator
from biobroker.api import BsdApi # BioSamples Database (BSD) API
import os

os.environ['API_ENVIRONMENT'] = "dev" # There are multiple ways to set up environment variables

username = "" # Your username goes here
password = "" # Your password goes here
authenticator = WebinAuthenticator(username=username, password=password)

api = BsdApi(authenticator=authenticator)

my_sample = api.retrieve(['SAMEA131394580'])
2024-10-14 10:46:04,052 - BsdApi - INFO - Set up BSD API successfully: using base uri 'https://wwwdev.ebi.ac.uk/biosamples/samples'
2024-10-14 10:46:04,052 - BsdApi - INFO - Trying to retrieve sample with accession SAMEA131394580

Now that we got the samples, let’s apply the modifications!

For this example, I will be adding a new field with the same value (I won’t be going through the work of making multiple values, this is just an example of what you can do)

Please note that you can use an output processor to get your samples back in tsv/xlsx format, modify them, load them back with an input processor and perform the update operation. It’s very intuitive and very simple, for those modifications that need an extra non-programmatic eye!

(But I am not doing that because that would involve more work and making screenshots. Nope)

[4]:
for sample in my_sample:
    sample['myNewField'] = "aNewValue"

my_updated_sample = api.update(my_sample)
[5]:
print(my_updated_sample[0].entity)
{'characteristics': {'SRA accession': [{'text': 'ERS30993787'}], 'collected_at': [{'text': 'noon'}], 'myNewField': [{'text': 'aNewValue'}], 'organism': [{'text': 'Homo sapiens'}]}, 'name': 'sumple', 'accession': 'SAMEA131394580', 'release': '2024-09-26T07:52:45Z', 'sraAccession': 'ERS30993787', 'webinSubmissionAccountId': 'Webin-64342', 'taxId': 9606, 'status': 'PUBLIC', 'update': '2024-10-14T09:46:43.551Z', 'submitted': '2024-09-26T08:03:34.403Z', 'submittedVia': 'JSON_API', 'create': '2024-09-26T08:03:34.403Z', '_links': {'self': {'href': 'https://wwwdev.ebi.ac.uk/biosamples/samples/SAMEA131394580'}, 'curationDomain': {'href': 'https://wwwdev.ebi.ac.uk/biosamples/samples/SAMEA131394580{?curationdomain}', 'templated': True}, 'curationLinks': {'href': 'https://wwwdev.ebi.ac.uk/biosamples/samples/SAMEA131394580/curationlinks'}, 'curationLink': {'href': 'https://wwwdev.ebi.ac.uk/biosamples/samples/SAMEA131394580/curationlinks/{hash}', 'templated': True}, 'structuredData': {'href': 'https://wwwdev.ebi.ac.uk/biosamples/structureddata/SAMEA131394580'}}}

Pretty easy, right?