Skip to content

Instantly share code, notes, and snippets.

@bicycle1885
Created March 10, 2020 07:04
Show Gist options
  • Save bicycle1885/52daaebed04dd5c02e995c59fc3e7a6d to your computer and use it in GitHub Desktop.
Save bicycle1885/52daaebed04dd5c02e995c59fc3e7a6d to your computer and use it in GitHub Desktop.
PANTHER (http://pantherdb.org/) interface
# LICENSE: Public Domain
import requests
def panther(species, genelist, ontology='biological_process',
correction='fdr', format='html', resource='PANTHER', timeout=15):
"""Post a over/under-representation test request to PANTHER."""
# NOTE: The species parameter seems to be different from conventional
# names. For example, Homo sapiens is 'HUMAN' and Yarrowia lipolytica is 'YARLI'.
# request analysis
url = 'http://pantherdb.org/webservices/go/overrep.jsp'
data = {'species': species, 'input': "\n".join(genelist),
'correction': correction, 'format': format, 'resource': resource}
r = requests.post(url, data=data, timeout=timeout)
r.raise_for_status()
# request xml data containing the result
url = 'http://pantherdb.org/tools/exportCompareToRefList.jsp'
params = {'sortOrder': -1, 'sortList': 'upload_1', 'sortField': 'hierarchy', 'format': 'xml'}
r = requests.get(url, params=params, cookies=r.cookies, timeout=timeout)
r.raise_for_status()
# decode the content and fix the encoding signature
xml = r.content.decode('UTF-8')
xml = xml.replace('encoding="UTF-16"', 'encoding="UTF-8"', 1)
return xml
if __name__ == '__main__':
import sys
if len(sys.argv) != 3:
print("Usage: panther.py <species> <input file>")
sys.exit(1)
species, inputfile = sys.argv[1:]
with open(inputfile) as f:
genelist = f.readlines()
print(panther(species, genelist))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment