Skip to content

Instantly share code, notes, and snippets.

@gourneau
Created April 7, 2014 22:45
Show Gist options
  • Save gourneau/10070227 to your computer and use it in GitHub Desktop.
Save gourneau/10070227 to your computer and use it in GitHub Desktop.
Ion Torrent: Use REST API to change experiment storage_options based on result PK
import requests
from requests.auth import HTTPBasicAuth
import json
import sys
server = "http://fall.local"
auth = HTTPBasicAuth('username', 'password')
#get this from somewhere else, this is just an example , maybe from sys.argv[1]
key = 4
#find the parent experiment for the given result (report)
parent = requests.get(server + "/rundb/api/v1/results/" + str(key) +"/?format=json", auth=auth)
experiment = parent.json()["experiment"]
"""
#From the TS source code
STORAGE_CHOICES = (
('KI', 'Keep'),
('A', 'Archive Raw'),
('D', 'Delete Raw'),
)
"""
#KI is keep
storage_options = json.dumps({"storage_options": "KI"})
#the patch will update the storage_options field
r = requests.patch(server + experiment + "/?format=json", data=storage_options, auth=auth )
#now just check that is it right
check = requests.get(server + experiment + "/?format=json")
print "Experiment" , check.json()["id"] , check.json()["storage_options"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment