上代码:
import requests import json import argparse import time from pandas import json_normalize parser = argparse.ArgumentParser(description="get ligands(BindingDB) by uniprots") parser.add_argument('--uniprots', '-u' , required=True, nargs='+', help='the list of uniprots(list)') parser.add_argument('--output', '-o' , required=True, type=str, help='output file path(csv)') args = parser.parse_args() uniprots = args.uniprots output = args.output def get_text(url): s = requests.session() text = s.get(url) return(text) def activities(uniprots,out_file): """ Parameters ---------- gene_name : list the list of uniprots out_file : TYPE output file path Returns ------- None. """ targets = ''.join(uniprots) print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), "start to craw data from BindingDB", '\n', '[','Target:', targets, ']') url = "http://bindingdb.org/axis2/services/BDBService/getLigandsByUniprots?uniprot=%s&code=[012]&response=application/json"%(targets) info = json.loads(get_text(url).content) df = json_normalize(info['getLigandsByUniprotsResponse']['affinities']) df.to_csv(out_file, index=False) print('\n', time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), "finished to craw data from BindingDB", '\n', '[','Output:', out_file, ']') activities(uniprots,output)
使用说明
在命令行输入:
python xxxx.py -u {uniprot_id1,uniprot_id2,uniprot_id3...} -o {output file path(csv)} 示例: python D:\PY_work\regular_use\bindingDB_activitis.py -u P09874,P11103,P27008,Q9R152,P18493,P31669, P26446,Q08824 -o F:\DATA\parp_1\parp_1_bindingDB.csv