如何根据uniports号,爬取bindingDB的活性实验数据

上代码:

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

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值