{ "cells": [ { "cell_type": "markdown", "id": "a9960294-dcdd-4b0e-9417-09a2bf149061", "metadata": {}, "source": [ "**NOTE**: Please be mindful that the log messages are logged across the code box that instantiates the object, so if a log message from a previous execution of the notebook does not match up with the markdown notes, please re-run the code again and look in the first box. I don't know how to fix that, sorry!\n", "\n", "# Submit your samples validating them against a checklist\n", "\n", "This notebook is an extension from the first notebook; here, we will focus on another aspect of a biosamples submission: validation against a checklist.\n", "\n", "Checklists are the name that the validation rules for the samples receive. Currently, BioSamples is mostly tailored to 2 types of checklists:\n", "- BioSamples checklists: Accessioned as \"BSDXXX\"\n", "- ENA checklists: Accessioned as `ERCXXX`. Full list, with explanation on mandatory/required fields, can be found [here](https://www.ebi.ac.uk/ena/browser/checklists)\n", "\n", "For the first steps, we will do the same as in the previous notebook: Set up the required components, and create a sample." ] }, { "cell_type": "code", "execution_count": 3, "id": "051e34c8-c365-4572-a169-c7bc16bb23df", "metadata": {}, "outputs": [], "source": [ "## Import everything we need\n", "from biobroker.authenticator import WebinAuthenticator # Biosamples uses the WebinAuthenticator\n", "from biobroker.api import BsdApi # BioSamples Database (BSD) API\n", "from biobroker.metadata_entity import Biosample # The metadata entity\n", "from biobroker.input_processor import TsvInputProcessor # An input processor\n", "from biobroker.output_processor import XlsxOutputProcessor # An output processor\n", "import os\n", "\n", "## Generate sample\n", "sample_tsv = [\n", " [\"name\", \"collected_at\", \"organism\", \"release\"],\n", " [\"sumple\", \"noon\", \"Homo sapiens\", \"2024-07-10\"] \n", "]\n", "\n", "writable_sample = \"\\n\".join([\"\\t\".join(row) for row in sample_tsv])\n", "with open(\"simple_sample_sumple.tsv\", \"w\") as f:\n", " f.write(writable_sample)\n", "\n", "path = \"simple_sample_sumple.tsv\" # This is the file we created previously\n", "\n", "## Set up the required entities\n", "\n", "input_processor = TsvInputProcessor(input_data=path)\n", "my_sample = input_processor.process(Biosample)\n", "\n", "os.environ['API_ENVIRONMENT'] = \"dev\" # There are multiple ways to set up environment variables\n", "\n", "username = \"\" # Your username goes here\n", "password = \"\" # Your password goes here\n", "authenticator = WebinAuthenticator(username=username, password=password)\n", "\n", "api = BsdApi(authenticator=authenticator)" ] }, { "cell_type": "markdown", "id": "20dd01e5-ef39-4139-b71c-8a9e84ea7716", "metadata": {}, "source": [ "## Choosing a checklist and validating\n", "\n", "After everything is set-up, we need to choose one of the checklist for validation. Let's say we browsed the available checklists, and since our sample is of human skin, we want to align with the GSC MIxS Human Skin checklist (https://www.ebi.ac.uk/ena/browser/view/ERC000017). \n", "\n", "In BioSamples, checklists are chosen by attaching the accesion of the list as metadata to the sample. Let's start by adding just the checklist and trying to submit, to see what happens:" ] }, { "cell_type": "code", "execution_count": 4, "id": "8f300364-5163-4889-96da-3834dfd825d7", "metadata": {}, "outputs": [ { "ename": "BiosamplesValidationError", "evalue": "Found following errors in sample validation:\n\t- /characteristics.project name: should have required property 'project name'\n\t- /characteristics.collection date: should have required property 'collection date'\n\t- /characteristics.geographic location (country and/or sea): should have required property 'geographic location (country and/or sea)'\n\t- /characteristics.geographic location (latitude): should have required property 'geographic location (latitude)'\n\t- /characteristics.geographic location (longitude): should have required property 'geographic location (longitude)'\n\t- /characteristics.broad-scale environmental context: should have required property 'broad-scale environmental context'\n\t- /characteristics.local environmental context: should have required property 'local environmental context'\n\t- /characteristics.environmental medium: should have required property 'environmental medium')", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mBiosamplesValidationError\u001b[0m Traceback (most recent call last)", "Cell \u001b[0;32mIn[4], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m my_sample[\u001b[38;5;241m0\u001b[39m][\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mchecklist\u001b[39m\u001b[38;5;124m'\u001b[39m] \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mERC000017\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m----> 2\u001b[0m \u001b[43mapi\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msubmit\u001b[49m\u001b[43m(\u001b[49m\u001b[43mmy_sample\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m~/PycharmProjects/biobroker/biobroker/api/api.py:51\u001b[0m, in \u001b[0;36mGenericApi.submit\u001b[0;34m(self, entities, **kwargs)\u001b[0m\n\u001b[1;32m 49\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_submit_multiple(entities, kwargs)\n\u001b[1;32m 50\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m---> 51\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m [\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_submit\u001b[49m\u001b[43m(\u001b[49m\u001b[43mentities\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m]\n", "File \u001b[0;32m~/PycharmProjects/biobroker/biobroker/api/api.py:172\u001b[0m, in \u001b[0;36mBsdApi._submit\u001b[0;34m(self, entity, kwargs)\u001b[0m\n\u001b[1;32m 170\u001b[0m r \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mauthenticator\u001b[38;5;241m.\u001b[39mpost(submit_url, payload\u001b[38;5;241m=\u001b[39mentity\u001b[38;5;241m.\u001b[39mentity)\n\u001b[1;32m 171\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m r\u001b[38;5;241m.\u001b[39mstatus_code \u001b[38;5;241m>\u001b[39m \u001b[38;5;241m300\u001b[39m:\n\u001b[0;32m--> 172\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_submit_errors\u001b[49m\u001b[43m(\u001b[49m\u001b[43mr\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 173\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m Biosample(r\u001b[38;5;241m.\u001b[39mjson())\n", "File \u001b[0;32m~/PycharmProjects/biobroker/biobroker/api/api.py:390\u001b[0m, in \u001b[0;36mBsdApi._submit_errors\u001b[0;34m(self, response)\u001b[0m\n\u001b[1;32m 388\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m response\u001b[38;5;241m.\u001b[39mstatus_code \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m400\u001b[39m:\n\u001b[1;32m 389\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mdataPath\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;129;01min\u001b[39;00m response\u001b[38;5;241m.\u001b[39mtext:\n\u001b[0;32m--> 390\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m BiosamplesValidationError(response\u001b[38;5;241m.\u001b[39mtext, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mlogger)\n\u001b[1;32m 391\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 392\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m BiosamplesNoErrorMessageError(response\u001b[38;5;241m.\u001b[39mstatus_code, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mlogger)\n", "\u001b[0;31mBiosamplesValidationError\u001b[0m: Found following errors in sample validation:\n\t- /characteristics.project name: should have required property 'project name'\n\t- /characteristics.collection date: should have required property 'collection date'\n\t- /characteristics.geographic location (country and/or sea): should have required property 'geographic location (country and/or sea)'\n\t- /characteristics.geographic location (latitude): should have required property 'geographic location (latitude)'\n\t- /characteristics.geographic location (longitude): should have required property 'geographic location (longitude)'\n\t- /characteristics.broad-scale environmental context: should have required property 'broad-scale environmental context'\n\t- /characteristics.local environmental context: should have required property 'local environmental context'\n\t- /characteristics.environmental medium: should have required property 'environmental medium')" ] } ], "source": [ "my_sample[0]['checklist'] = \"ERC000017\"\n", "api.submit(my_sample)" ] }, { "cell_type": "markdown", "id": "981b1a1f-19f0-4367-9b21-cf6c80b2ff22", "metadata": {}, "source": [ "As we can see, a custom python Exception is raised when we try to do this; This is the biobroker's way of raising the checklist errors. It's complaining about a bunch of missing fields, so let's fix that!\n", "\n", "(Please note: For the purpose of this notebook, we will do it here, but it would be much, MUCH easier to just fix the input tsv or xlsx file and load the samples again)" ] }, { "cell_type": "code", "execution_count": 5, "id": "e095147b-6078-48c6-9634-fb65b4536f37", "metadata": {}, "outputs": [ { "ename": "BiosamplesValidationError", "evalue": "Found following errors in sample validation:\n\t- geographic location (country and~1or sea)/0/text: should be equal to one of the allowed values: [\"Afghanistan\",\"Albania\",\"Algeria\",\"American Samoa\",\"Andorra\",\"Angola\",\"Anguilla\",\"Antarctica\",\"Antigua and Barbuda\",\"Arctic Ocean\",\"Argentina\",\"Armenia\",\"Aruba\",\"Ashmore and Cartier Islands\",\"Atlantic Ocean\",\"Australia\",\"Austria\",\"Azerbaijan\",\"Bahamas\",\"Bahrain\",\"Baker Island\",\"Baltic Sea\",\"Bangladesh\",\"Barbados\",\"Bassas da India\",\"Belarus\",\"Belgium\",\"Belize\",\"Benin\",\"Bermuda\",\"Bhutan\",\"Bolivia\",\"Borneo\",\"Bosnia and Herzegovina\",\"Botswana\",\"Bouvet Island\",\"Brazil\",\"British Virgin Islands\",\"Brunei\",\"Bulgaria\",\"Burkina Faso\",\"Burundi\",\"Cambodia\",\"Cameroon\",\"Canada\",\"Cape Verde\",\"Cayman Islands\",\"Central African Republic\",\"Chad\",\"Chile\",\"China\",\"Christmas Island\",\"Clipperton Island\",\"Cocos Islands\",\"Colombia\",\"Comoros\",\"Cook Islands\",\"Coral Sea Islands\",\"Costa Rica\",\"Cote d'Ivoire\",\"Croatia\",\"Cuba\",\"Curacao\",\"Cyprus\",\"Czechia\",\"Democratic Republic of the Congo\",\"Denmark\",\"Djibouti\",\"Dominica\",\"Dominican Republic\",\"East Timor\",\"Ecuador\",\"Egypt\",\"El Salvador\",\"Equatorial Guinea\",\"Eritrea\",\"Estonia\",\"Ethiopia\",\"Europa Island\",\"Falkland Islands (Islas Malvinas)\",\"Faroe Islands\",\"Fiji\",\"Finland\",\"France\",\"French Guiana\",\"French Polynesia\",\"French Southern and Antarctic Lands\",\"Gabon\",\"Gambia\",\"Gaza Strip\",\"Georgia\",\"Germany\",\"Ghana\",\"Gibraltar\",\"Glorioso Islands\",\"Greece\",\"Greenland\",\"Grenada\",\"Guadeloupe\",\"Guam\",\"Guatemala\",\"Guernsey\",\"Guinea\",\"Guinea-Bissau\",\"Guyana\",\"Haiti\",\"Heard Island and McDonald Islands\",\"Honduras\",\"Hong Kong\",\"Howland Island\",\"Hungary\",\"Iceland\",\"India\",\"Indian Ocean\",\"Indonesia\",\"Iran\",\"Iraq\",\"Ireland\",\"Isle of Man\",\"Israel\",\"Italy\",\"Jamaica\",\"Jan Mayen\",\"Japan\",\"Jarvis Island\",\"Jersey\",\"Johnston Atoll\",\"Jordan\",\"Juan de Nova Island\",\"Kazakhstan\",\"Kenya\",\"Kerguelen Archipelago\",\"Kingman Reef\",\"Kiribati\",\"Kosovo\",\"Kuwait\",\"Kyrgyzstan\",\"Laos\",\"Latvia\",\"Lebanon\",\"Lesotho\",\"Liberia\",\"Libya\",\"Liechtenstein\",\"Lithuania\",\"Luxembourg\",\"Macau\",\"Macedonia\",\"Madagascar\",\"Malawi\",\"Malaysia\",\"Maldives\",\"Mali\",\"Malta\",\"Marshall Islands\",\"Martinique\",\"Mauritania\",\"Mauritius\",\"Mayotte\",\"Mediterranean Sea\",\"Mexico\",\"Micronesia\",\"Midway Islands\",\"Moldova\",\"Monaco\",\"Mongolia\",\"Montenegro\",\"Montserrat\",\"Morocco\",\"Mozambique\",\"Myanmar\",\"Namibia\",\"Nauru\",\"Navassa Island\",\"Nepal\",\"Netherlands\",\"New Caledonia\",\"New Zealand\",\"Nicaragua\",\"Niger\",\"Nigeria\",\"Niue\",\"Norfolk Island\",\"North Korea\",\"North Sea\",\"Northern Mariana Islands\",\"Norway\",\"Oman\",\"Pacific Ocean\",\"Pakistan\",\"Palau\",\"Palmyra Atoll\",\"Panama\",\"Papua New Guinea\",\"Paracel Islands\",\"Paraguay\",\"Peru\",\"Philippines\",\"Pitcairn Islands\",\"Poland\",\"Portugal\",\"Puerto Rico\",\"Qatar\",\"Republic of the Congo\",\"Reunion\",\"Romania\",\"Ross Sea\",\"Russia\",\"Rwanda\",\"Saint Helena\",\"Saint Kitts and Nevis\",\"Saint Lucia\",\"Saint Pierre and Miquelon\",\"Saint Vincent and the Grenadines\",\"Samoa\",\"San Marino\",\"Sao Tome and Principe\",\"Saudi Arabia\",\"Senegal\",\"Serbia\",\"Seychelles\",\"Sierra Leone\",\"Singapore\",\"Sint Maarten\",\"Slovakia\",\"Slovenia\",\"Solomon Islands\",\"Somalia\",\"South Africa\",\"South Georgia and the South Sandwich Islands\",\"South Korea\",\"Southern Ocean\",\"Spain\",\"Spratly Islands\",\"Sri Lanka\",\"Sudan\",\"Suriname\",\"Svalbard\",\"Swaziland\",\"Sweden\",\"Switzerland\",\"Syria\",\"Taiwan\",\"Tajikistan\",\"Tanzania\",\"Tasman Sea\",\"Thailand\",\"Togo\",\"Tokelau\",\"Tonga\",\"Trinidad and Tobago\",\"Tromelin Island\",\"Tunisia\",\"Turkey\",\"Turkmenistan\",\"Turks and Caicos Islands\",\"Tuvalu\",\"USA\",\"Uganda\",\"Ukraine\",\"United Arab Emirates\",\"United Kingdom\",\"Uruguay\",\"Uzbekistan\",\"Vanuatu\",\"Venezuela\",\"Viet Nam\",\"Virgin Islands\",\"Wake Island\",\"Wallis and Futuna\",\"West Bank\",\"Western Sahara\",\"Yemen\",\"Zambia\",\"Zimbabwe\",\"missing: control sample\",\"missing: data agreement established pre-2023\",\"missing: endangered species\",\"missing: human-identifiable\",\"missing: lab stock\",\"missing: sample group\",\"missing: synthetic construct\",\"missing: third party data\",\"not applicable\",\"not collected\",\"not provided\",\"restricted access\"])", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mBiosamplesValidationError\u001b[0m Traceback (most recent call last)", "Cell \u001b[0;32mIn[5], line 11\u001b[0m\n\u001b[1;32m 8\u001b[0m my_sample[\u001b[38;5;241m0\u001b[39m][\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mlocal environmental context\u001b[39m\u001b[38;5;124m'\u001b[39m] \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mMostly rainy\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 9\u001b[0m my_sample[\u001b[38;5;241m0\u001b[39m][\u001b[38;5;124m'\u001b[39m\u001b[38;5;124menvironmental medium\u001b[39m\u001b[38;5;124m'\u001b[39m] \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mPlease read my plant\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m---> 11\u001b[0m \u001b[43mapi\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msubmit\u001b[49m\u001b[43m(\u001b[49m\u001b[43mmy_sample\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m~/PycharmProjects/biobroker/biobroker/api/api.py:51\u001b[0m, in \u001b[0;36mGenericApi.submit\u001b[0;34m(self, entities, **kwargs)\u001b[0m\n\u001b[1;32m 49\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_submit_multiple(entities, kwargs)\n\u001b[1;32m 50\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m---> 51\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m [\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_submit\u001b[49m\u001b[43m(\u001b[49m\u001b[43mentities\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m]\n", "File \u001b[0;32m~/PycharmProjects/biobroker/biobroker/api/api.py:172\u001b[0m, in \u001b[0;36mBsdApi._submit\u001b[0;34m(self, entity, kwargs)\u001b[0m\n\u001b[1;32m 170\u001b[0m r \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mauthenticator\u001b[38;5;241m.\u001b[39mpost(submit_url, payload\u001b[38;5;241m=\u001b[39mentity\u001b[38;5;241m.\u001b[39mentity)\n\u001b[1;32m 171\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m r\u001b[38;5;241m.\u001b[39mstatus_code \u001b[38;5;241m>\u001b[39m \u001b[38;5;241m300\u001b[39m:\n\u001b[0;32m--> 172\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_submit_errors\u001b[49m\u001b[43m(\u001b[49m\u001b[43mr\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 173\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m Biosample(r\u001b[38;5;241m.\u001b[39mjson())\n", "File \u001b[0;32m~/PycharmProjects/biobroker/biobroker/api/api.py:390\u001b[0m, in \u001b[0;36mBsdApi._submit_errors\u001b[0;34m(self, response)\u001b[0m\n\u001b[1;32m 388\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m response\u001b[38;5;241m.\u001b[39mstatus_code \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m400\u001b[39m:\n\u001b[1;32m 389\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mdataPath\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;129;01min\u001b[39;00m response\u001b[38;5;241m.\u001b[39mtext:\n\u001b[0;32m--> 390\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m BiosamplesValidationError(response\u001b[38;5;241m.\u001b[39mtext, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mlogger)\n\u001b[1;32m 391\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 392\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m BiosamplesNoErrorMessageError(response\u001b[38;5;241m.\u001b[39mstatus_code, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mlogger)\n", "\u001b[0;31mBiosamplesValidationError\u001b[0m: Found following errors in sample validation:\n\t- geographic location (country and~1or sea)/0/text: should be equal to one of the allowed values: [\"Afghanistan\",\"Albania\",\"Algeria\",\"American Samoa\",\"Andorra\",\"Angola\",\"Anguilla\",\"Antarctica\",\"Antigua and Barbuda\",\"Arctic Ocean\",\"Argentina\",\"Armenia\",\"Aruba\",\"Ashmore and Cartier Islands\",\"Atlantic Ocean\",\"Australia\",\"Austria\",\"Azerbaijan\",\"Bahamas\",\"Bahrain\",\"Baker Island\",\"Baltic Sea\",\"Bangladesh\",\"Barbados\",\"Bassas da India\",\"Belarus\",\"Belgium\",\"Belize\",\"Benin\",\"Bermuda\",\"Bhutan\",\"Bolivia\",\"Borneo\",\"Bosnia and Herzegovina\",\"Botswana\",\"Bouvet Island\",\"Brazil\",\"British Virgin Islands\",\"Brunei\",\"Bulgaria\",\"Burkina Faso\",\"Burundi\",\"Cambodia\",\"Cameroon\",\"Canada\",\"Cape Verde\",\"Cayman Islands\",\"Central African Republic\",\"Chad\",\"Chile\",\"China\",\"Christmas Island\",\"Clipperton Island\",\"Cocos Islands\",\"Colombia\",\"Comoros\",\"Cook Islands\",\"Coral Sea Islands\",\"Costa Rica\",\"Cote d'Ivoire\",\"Croatia\",\"Cuba\",\"Curacao\",\"Cyprus\",\"Czechia\",\"Democratic Republic of the Congo\",\"Denmark\",\"Djibouti\",\"Dominica\",\"Dominican Republic\",\"East Timor\",\"Ecuador\",\"Egypt\",\"El Salvador\",\"Equatorial Guinea\",\"Eritrea\",\"Estonia\",\"Ethiopia\",\"Europa Island\",\"Falkland Islands (Islas Malvinas)\",\"Faroe Islands\",\"Fiji\",\"Finland\",\"France\",\"French Guiana\",\"French Polynesia\",\"French Southern and Antarctic Lands\",\"Gabon\",\"Gambia\",\"Gaza Strip\",\"Georgia\",\"Germany\",\"Ghana\",\"Gibraltar\",\"Glorioso Islands\",\"Greece\",\"Greenland\",\"Grenada\",\"Guadeloupe\",\"Guam\",\"Guatemala\",\"Guernsey\",\"Guinea\",\"Guinea-Bissau\",\"Guyana\",\"Haiti\",\"Heard Island and McDonald Islands\",\"Honduras\",\"Hong Kong\",\"Howland Island\",\"Hungary\",\"Iceland\",\"India\",\"Indian Ocean\",\"Indonesia\",\"Iran\",\"Iraq\",\"Ireland\",\"Isle of Man\",\"Israel\",\"Italy\",\"Jamaica\",\"Jan Mayen\",\"Japan\",\"Jarvis Island\",\"Jersey\",\"Johnston Atoll\",\"Jordan\",\"Juan de Nova Island\",\"Kazakhstan\",\"Kenya\",\"Kerguelen Archipelago\",\"Kingman Reef\",\"Kiribati\",\"Kosovo\",\"Kuwait\",\"Kyrgyzstan\",\"Laos\",\"Latvia\",\"Lebanon\",\"Lesotho\",\"Liberia\",\"Libya\",\"Liechtenstein\",\"Lithuania\",\"Luxembourg\",\"Macau\",\"Macedonia\",\"Madagascar\",\"Malawi\",\"Malaysia\",\"Maldives\",\"Mali\",\"Malta\",\"Marshall Islands\",\"Martinique\",\"Mauritania\",\"Mauritius\",\"Mayotte\",\"Mediterranean Sea\",\"Mexico\",\"Micronesia\",\"Midway Islands\",\"Moldova\",\"Monaco\",\"Mongolia\",\"Montenegro\",\"Montserrat\",\"Morocco\",\"Mozambique\",\"Myanmar\",\"Namibia\",\"Nauru\",\"Navassa Island\",\"Nepal\",\"Netherlands\",\"New Caledonia\",\"New Zealand\",\"Nicaragua\",\"Niger\",\"Nigeria\",\"Niue\",\"Norfolk Island\",\"North Korea\",\"North Sea\",\"Northern Mariana Islands\",\"Norway\",\"Oman\",\"Pacific Ocean\",\"Pakistan\",\"Palau\",\"Palmyra Atoll\",\"Panama\",\"Papua New Guinea\",\"Paracel Islands\",\"Paraguay\",\"Peru\",\"Philippines\",\"Pitcairn Islands\",\"Poland\",\"Portugal\",\"Puerto Rico\",\"Qatar\",\"Republic of the Congo\",\"Reunion\",\"Romania\",\"Ross Sea\",\"Russia\",\"Rwanda\",\"Saint Helena\",\"Saint Kitts and Nevis\",\"Saint Lucia\",\"Saint Pierre and Miquelon\",\"Saint Vincent and the Grenadines\",\"Samoa\",\"San Marino\",\"Sao Tome and Principe\",\"Saudi Arabia\",\"Senegal\",\"Serbia\",\"Seychelles\",\"Sierra Leone\",\"Singapore\",\"Sint Maarten\",\"Slovakia\",\"Slovenia\",\"Solomon Islands\",\"Somalia\",\"South Africa\",\"South Georgia and the South Sandwich Islands\",\"South Korea\",\"Southern Ocean\",\"Spain\",\"Spratly Islands\",\"Sri Lanka\",\"Sudan\",\"Suriname\",\"Svalbard\",\"Swaziland\",\"Sweden\",\"Switzerland\",\"Syria\",\"Taiwan\",\"Tajikistan\",\"Tanzania\",\"Tasman Sea\",\"Thailand\",\"Togo\",\"Tokelau\",\"Tonga\",\"Trinidad and Tobago\",\"Tromelin Island\",\"Tunisia\",\"Turkey\",\"Turkmenistan\",\"Turks and Caicos Islands\",\"Tuvalu\",\"USA\",\"Uganda\",\"Ukraine\",\"United Arab Emirates\",\"United Kingdom\",\"Uruguay\",\"Uzbekistan\",\"Vanuatu\",\"Venezuela\",\"Viet Nam\",\"Virgin Islands\",\"Wake Island\",\"Wallis and Futuna\",\"West Bank\",\"Western Sahara\",\"Yemen\",\"Zambia\",\"Zimbabwe\",\"missing: control sample\",\"missing: data agreement established pre-2023\",\"missing: endangered species\",\"missing: human-identifiable\",\"missing: lab stock\",\"missing: sample group\",\"missing: synthetic construct\",\"missing: third party data\",\"not applicable\",\"not collected\",\"not provided\",\"restricted access\"])" ] } ], "source": [ "my_sample[0]['project name'] = \"Your fake project\"\n", "my_sample[0]['organism'] = \"Homo sapiens\"\n", "my_sample[0]['collection date'] = \"2024-09-01\"\n", "my_sample[0]['geographic location (country and/or sea)'] = \"Mushroom kingdom\"\n", "my_sample[0]['geographic location (latitude)'] = 1.2234\n", "my_sample[0]['geographic location (longitude)'] = 7.21\n", "my_sample[0]['broad-scale environmental context'] = \"United Kingdom weather\"\n", "my_sample[0]['local environmental context'] = \"Mostly rainy\"\n", "my_sample[0]['environmental medium'] = \"Please read my plant\"\n", "\n", "api.submit(my_sample)" ] }, { "cell_type": "markdown", "id": "55cbd9f1-8e08-41cf-a3e7-79f5bbe9c2ff", "metadata": {}, "source": [ "What do you mean Mushroom Kingdom is not an accepted country or sea? ugh" ] }, { "cell_type": "code", "execution_count": 6, "id": "b905e423-ceba-4b2b-87cb-587ec014ae23", "metadata": {}, "outputs": [], "source": [ "my_sample[0]['geographic location (country and/or sea)'] = \"Mediterranean Sea\"\n", "\n", "new_sample = api.submit(my_sample)" ] }, { "cell_type": "markdown", "id": "fc4fc28c-5c18-4309-85dc-c87aa4005746", "metadata": {}, "source": [ "And it's done!! Let's see what it looks like:" ] }, { "cell_type": "code", "execution_count": 8, "id": "acd98899-e70d-452a-9ab5-201df030a5f4", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "https://wwwdev.ebi.ac.uk/biosamples/samples/SAMEA131421914\n" ] } ], "source": [ "print(f\"https://wwwdev.ebi.ac.uk/biosamples/samples/{new_sample[0]['accession']}\")" ] }, { "cell_type": "code", "execution_count": null, "id": "5d15de07-27a2-4b97-9ee0-167a42ce8fc2", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.11" } }, "nbformat": 4, "nbformat_minor": 5 }