Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avrilcoghlan/06f37d77aa7eceff8327cf85d3a05828 to your computer and use it in GitHub Desktop.
Save avrilcoghlan/06f37d77aa7eceff8327cf85d3a05828 to your computer and use it in GitHub Desktop.
Example script to retrieve phenotype data for a C. elegans gene using the WormBase REST API
# script to retrieve the phenotype info for a particular gene from WormBase
import requests, sys
server = "http://rest.wormbase.org"
ext = "/rest/field/gene/WBGene00000079/phenotype"
r = requests.get(server+ext, headers={ "Content-Type" : "application/json", "Accept" : ""})
if not r.ok:
r.raise_for_status()
sys.exit()
decoded = r.json()
# print(decoded)
# based on looking at the example http://rest.wormbase.org/rest/field/gene/WBGene00000079/phenotype
phenotypes = decoded["phenotype"]
phenotypes = phenotypes["data"]
for phenotype in phenotypes:
phenotype = phenotype["phenotype"]
phenotype_id = phenotype["id"]
label = phenotype["label"]
print("id=",phenotype_id,"label=",label)
print("FINISHED\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment