Import the libraries so that they can be used within the notebook
import requests
import json
import string
import getpass
The base_url holds the URL to the SEEK instance that will be used in the notebook
headers holds the HTTP headers that will be sent with every HTTP call
base_url = 'https://testing.sysmo-db.org'
headers = {"Content-type": "application/vnd.api+json",
"Accept": "application/vnd.api+json",
"Accept-Charset": "ISO-8859-1"}
Create a requests HTTP Session. A Session has re-usable settings such as headers
The authorization is username and password. The user is prompted for this information.
session = requests.Session()
session.headers.update(headers)
session.auth = (input('Username: '), getpass.getpass('Password: '))
The Investigation, Study and Assay will be created within Project 33
containing_project_id = 33
Initialize an investigation as a hierarchical structure
The title of the investigation is input by the user
The investigation is linked to the containing project
investigation = {}
investigation['data'] = {}
investigation['data']['type'] = 'investigations'
investigation['data']['attributes'] = {}
investigation['data']['attributes']['title'] = input('Please enter the name for the investigation: ')
investigation['data']['relationships'] = {}
investigation['data']['relationships']['projects'] = {}
investigation['data']['relationships']['projects']['data'] = [{'id' : containing_project_id, 'type' : 'projects'}]
POST the investigation to the SEEK instance
Check the status of the response
r = session.post(base_url + '/investigations', json=investigation)
r.raise_for_status()
Extract the created investigation from JSON into populated_investigation
populated_investigation = r.json()
Extract the id and URL to the newly created investigation
investigation_id = populated_investigation['data']['id']
investigation_url = populated_investigation['data']['links']['self']
Initialize a study as a hierarchical structure
The title of the study is input by the user
The study is linked to the containing investigation
study = {}
study['data'] = {}
study['data']['type'] = 'studies'
study['data']['attributes'] = {}
study['data']['attributes']['title'] = input('Please enter the name for the study: ')
study['data']['relationships'] = {}
study['data']['relationships']['investigation'] = {}
study['data']['relationships']['investigation']['data'] = {'id' : investigation_id, 'type' : 'investigations'}
POST the study to the SEEK instance
Check the status of the response
r = session.post(base_url + '/studies', json=study)
r.raise_for_status()
Extract the created study from JSON into *populated_study*
populated_study = r.json()
Extract the id and URL to the newly created study
study_id = populated_study['data']['id']
study_url = populated_study['data']['links']['self']
Initialize an assay as a hierarchical structure
The title of the assay is input by the user
The assay is linked to the containing study
assay = {}
assay['data'] = {}
assay['data']['type'] = 'assays'
assay['data']['attributes'] = {}
assay['data']['attributes']['title'] = input('Please enter the name for the assay: ')
assay['data']['attributes']['assay_class'] = {'key' : 'EXP'}
assay['data']['attributes']['assay_type'] = {'uri' : 'http://jermontology.org/ontology/JERMOntology#Metabolomics'}
assay['data']['attributes']['technology_type'] = {'uri' : 'http://jermontology.org/ontology/JERMOntology#Electrophoresis'}
assay['data']['relationships'] = {}
assay['data']['relationships']['study'] = {}
assay['data']['relationships']['study']['data'] = {'id' : study_id, 'type' : 'studies'}
POST the assay to the SEEK instance
Check the status of the response
r = session.post(base_url + '/assays', json=assay)
r.raise_for_status()
Extract the created assay from JSON into *populated_assay*
populated_assay = r.json()
Extract the id and URL to the newly created assay
assay_id = populated_assay['data']['id']
assay_url = populated_assay['data']['links']['self']
Initialize a data_file as a hierarchical structure
The title of the data_file is input by the user
The data_file is linked to the containing project and to the newly created assay
data_file = {}
data_file['data'] = {}
data_file['data']['type'] = 'data_files'
data_file['data']['attributes'] = {}
data_file['data']['attributes']['title'] = input('Please enter the name for the data_file: ')
remote_blob = {'url' : input('Please enter the URL for the remote data: ')}
data_file['data']['attributes']['content_blobs'] = [remote_blob]
data_file['data']['relationships'] = {}
data_file['data']['relationships']['projects'] = {}
data_file['data']['relationships']['projects']['data'] = [{'id' : containing_project_id, 'type' : 'projects'}]
data_file['data']['relationships']['assays'] = {}
data_file['data']['relationships']['assays']['data'] = [{'id' : assay_id, 'type' : 'assays'}]
POST the data_file to the SEEK instance
Check the status of the response
r = session.post(base_url + '/data_files', json=data_file)
r.raise_for_status()
Extract the created data_file from JSON into populated_data_file
populated_data_file = r.json()
Extract the id and URL to the newly created data_file
data_file_id = populated_data_file['data']['id']
data_file_url = populated_data_file['data']['links']['self']