Skip to content

Instantly share code, notes, and snippets.

@srynobio
Created November 6, 2019 18:20
Show Gist options
  • Save srynobio/4492273b1a7c4124a6d0815cf5c475b4 to your computer and use it in GitHub Desktop.
Save srynobio/4492273b1a7c4124a6d0815cf5c475b4 to your computer and use it in GitHub Desktop.
### ------------------------------------------------------------------- ##
def post_sample(mosaic_meta, sample, project_id, data_file):
path = "{}/projects/{}/samples"
url = path.format(mosaic_meta['url'], project_id)
headers = {
'Authorization' : mosaic_meta['authorization'],
}
data = {
'name' : sample,
}
params = {
'project_id' : project_id,
}
response = requests.post(url, headers=headers, data=data, params=params)
if response.ok:
print('sample {} created.'.format(sample))
sample_id = response.json()['id']
post_file(mosaic_meta, sample_id, project_id, data_file)
### ------------------------------------------------------------------- ##
def post_file(mosaic_meta, sample_id, project_id, data_file):
path = "{}/projects/{}/samples/{}/files"
url = path.format(mosaic_meta['url'], project_id, sample_id)
try:
if not os.path.isfile(data_file):
raise FileExistsError
except FileExistsError as e:
print(e)
headers = {
'Authorization' : mosaic_meta['authorization'],
'Content-Type' : mosaic_meta['content-type'],
}
body = {
'uri' : data_file,
}
parameter = {
'project_id' : project_id,
'sample_id' : sample_id,
}
response = requests.post(url, headers=headers, data=body, params=parameter)
if not response.ok:
print('API GO BOOM!')
print(response.reason)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment