Java教程

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

本文主要是介绍如何根据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

                    
这篇关于如何根据uniports号,爬取bindingDB的活性实验数据的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!