官方网站: https://www.drugbank.ca 最近好像很多人在关注这个网站,就暂时开一个 官网就是这个样子
简介 DrugBank数据库是独特的生物信息学和化学信息学资源,它将详细的药物数据与全面的药物靶标信息结合在一起。 简而言之就是这个数据库比较综合,里面包含了各种信息,然后你可以进去自己查询。 直接输入搜索就可以,我现在不讲如何搜索。
下载以及分析
想当初我还曾经用爬虫爬过drugbank的信息,现在想想真的是傻
下载链接: https://www.drugbank.ca/releases/latest
下载界面:
图2 别说没有sdf文件,你看看complete database旁边就有很多灰色的按钮,你自己点点看看效果,截图太累,我就不一个一个放了。
然后看下complete database这个界面的XML文件 貌似还需要注册,我记得以前是不需要的 好吧,直接下载,点击download 135MB,好吧,看看xml文件结构
看一个实例
<?xml version="1.0" encoding="UTF-8"?>
<drugbank xmlns="http://www.drugbank.ca" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.drugbank.ca http://www.drugbank.ca/docs/drugbank.xsd" version="5.1" exported-on="2020-01-03">
<drug type="biotech" created="2005-06-13" updated="2020-01-02">
<drugbank-id primary="true">DB00001</drugbank-id>
<drugbank-id>BTD00024</drugbank-id>
<drugbank-id>BIOD00024</drugbank-id>
<name>Lepirudin</name>
<description>Lepirudin is identical to natural hirudin except for substitution of leucine for isoleucine at the N-terminal end of the molecule and the absence of a sulfate group on the tyrosine at position 63. It is produced via yeast cells. Bayer ceased the production of lepirudin (Refludan) effective May 31, 2012.</description>
实际上更长,我这边就先放头几行就可以了,不然太长了
进入代码阶段
#对了我的版本是python3
#安装一个包
pip install lxml
#导入
import lxml
from lxml import etree
#打开xml,读取内容
f=open('full_database.xml','r')
xml_text=f.read()
#读取
xml_test=etree.fromstring(xml_text.encode('utf-8'))
#随便看下
xml_test
<Element {http://www.drugbank.ca}drugbank at 0x7f2fe62ff5f0>
type(xml_test)
lxml.etree._Element
#这样也可以
xml_test2=etree.parse('full_database.xml',etree.XMLParser())
#获得tree
root_tree = xml_test.getroottree()
#拿到根节点
troot = root.getroot()
#看下有多少个个节点,总共13475个药物
len(troot)
13475
#看下对于单个元素怎么操作
dir(troot)
['__bool__',
'__class__',
'__contains__',
'__copy__',
'__deepcopy__',
'__delattr__',
'__delitem__',
'__dir__',
'__doc__',
'__eq__',
'__format__',
'__ge__',
'__getattribute__',
'__getitem__',
'__gt__',
'__hash__',
'__init__',
'__init_subclass__',
'__iter__',
'__le__',
'__len__',
'__lt__',
'__ne__',
'__new__',
'__reduce__',
'__reduce_ex__',
'__repr__',
'__reversed__',
'__setattr__',
'__setitem__',
'__sizeof__',
'__str__',
'__subclasshook__',
'_init',
'addnext',
'addprevious',
'append',
'attrib',
'base',
'clear',
'cssselect',
'extend',
'find',
'findall',
'findtext',
'get',
'getchildren',
'getiterator',
'getnext',
'getparent',
'getprevious',
'getroottree',
'index',
'insert',
'items',
'iter',
'iterancestors',
'iterchildren',
'iterdescendants',
'iterfind',
'itersiblings',
'itertext',
'keys',
'makeelement',
'nsmap',
'prefix',
'remove',
'replace',
'set',
'sourceline',
'tag',
'tail',
'text',
'values',
'xpath']
#看下每个元素的长度
for i in troot:
print(len(i))
#很明显,长短不一
50
50
49
48
50
52
49
50
50
50
48
#对第一个元素,也就是第一个药物打印相关标签以及文本内容
for i in troot[1]:
print(i.tag)
print(i.text)
#结果,好长,这里只放一部分
{http://www.drugbank.ca}drugbank-id
DB00002
{http://www.drugbank.ca}drugbank-id
BTD00071
{http://www.drugbank.ca}drugbank-id
BIOD00071
{http://www.drugbank.ca}name
Cetuximab
{http://www.drugbank.ca}description
Cetuximab is an epidermal growth factor receptor binding FAB. Cetuximab is composed of the Fv (variable; antigen-binding) regions of the 225 murine EGFr monoclonal antibody specific for the N-terminal portion of human EGFr with human IgG1 heavy and kappa light chain constant (framework) regions. Cetuximab is marketed under the brand Erbitux® by Eli Lilly and Company. In the United States, a regimen of cetuximab costs approximately $30,790 for an eight-week course.
#好了就这样