KEGG
KEGG (https://www.kegg.jp/) 是一個資料庫資源,用於理解生物系統(如細胞、生物體和生態系統)的高階功能和用途,這些資訊來自分子層面的資訊,特別是透過基因組定序和其他高通量實驗技術產生的大規模分子數據集。
請注意,Biopython 中 KEGG 解析器的實作並不完整。雖然 KEGG 網站表示有許多平面檔案格式,但目前僅實作了 compound、enzyme 和 map 的解析器和寫入器。不過,實作了一個通用解析器來處理其他格式。
解析 KEGG 記錄
解析 KEGG 記錄就像使用 Biopython 中的任何其他檔案格式解析器一樣簡單。(在執行以下程式碼之前,請用您的網頁瀏覽器開啟 http://rest.kegg.jp/get/ec:5.4.2.2 並將其儲存為 ec_5.4.2.2.txt
。)
>>> from Bio.KEGG import Enzyme
>>> records = Enzyme.parse(open("ec_5.4.2.2.txt"))
>>> record = list(records)[0]
>>> record.classname
['Isomerases;', 'Intramolecular transferases;', 'Phosphotransferases (phosphomutases)']
>>> record.entry
'5.4.2.2'
或者,如果輸入的 KEGG 檔案只有一個條目,您可以使用 read
>>> from Bio.KEGG import Enzyme
>>> record = Enzyme.read(open("ec_5.4.2.2.txt"))
>>> record.classname
['Isomerases;', 'Intramolecular transferases;', 'Phosphotransferases (phosphomutases)']
>>> record.entry
'5.4.2.2'
以下章節將說明如何使用 KEGG api 下載上述酶,以及如何將通用解析器與未實作自訂解析器的資料一起使用。
查詢 KEGG API
Biopython 完全支援查詢 KEGG api。支援查詢所有 KEGG 端點;支援 KEGG (https://www.kegg.jp/kegg/rest/keggapi.html) 文件中記錄的所有方法。該介面會對查詢進行一些驗證,這些驗證遵循 KEGG 網站上定義的規則。但是,使用者必須處理傳回 400 或 404 的無效查詢。
首先,以下是如何擴展上述範例,下載相關酶並將其傳遞給 Enzyme 解析器。
>>> from Bio.KEGG import REST
>>> from Bio.KEGG import Enzyme
>>> request = REST.kegg_get("ec:5.4.2.2")
>>> open("ec_5.4.2.2.txt", "w").write(request.read())
>>> records = Enzyme.parse(open("ec_5.4.2.2.txt"))
>>> record = list(records)[0]
>>> record.classname
['Isomerases;', 'Intramolecular transferases;', 'Phosphotransferases (phosphomutases)']
>>> record.entry
'5.4.2.2'
現在,這裡有一個更實際的範例,它顯示了查詢 KEGG API 的組合。這將示範如何提取一組與 DNA 修復相關的所有人類途徑基因符號。執行此操作的步驟如下。首先,我們需要取得所有人類途徑的列表。其次,我們需要篩選那些與「修復」相關的途徑。最後,我們需要取得所有修復途徑中所有基因符號的列表。
from Bio.KEGG import REST
human_pathways = REST.kegg_list("pathway", "hsa").read()
# Filter all human pathways for repair pathways
repair_pathways = []
for line in human_pathways.rstrip().split("\n"):
entry, description = line.split("\t")
if "repair" in description:
repair_pathways.append(entry)
# Get the genes for pathways and add them to a list
repair_genes = []
for pathway in repair_pathways:
pathway_file = REST.kegg_get(pathway).read() # query and read each pathway
# iterate through each KEGG pathway file, keeping track of which section
# of the file we're in, only read the gene in each pathway
current_section = None
for line in pathway_file.rstrip().split("\n"):
section = line[:12].strip() # section names are within 12 columns
if not section == "":
current_section = section
if current_section == "GENE":
gene_identifiers, gene_description = line[12:].split("; ")
gene_id, gene_symbol = gene_identifiers.split()
if not gene_symbol in repair_genes:
repair_genes.append(gene_symbol)
print(
"There are %d repair pathways and %d repair genes. The genes are:"
% (len(repair_pathways), len(repair_genes))
)
print(", ".join(repair_genes))
KEGG API 包裝器與所有端點相容。用法基本上是將 URL 中的所有斜線替換為逗號,並將該列表用作 KEGG 模組中對應方法的參數。以下是來自 api 文件的一些範例 (https://www.kegg.jp/kegg/docs/keggapi.html)。
/list/hsa:10458+ece:Z5100 -> REST.kegg_list(["hsa:10458", "ece:Z5100"])
/find/compound/300-310/mol_weight -> REST.kegg_find("compound", "300-310", "mol_weight")
/get/hsa:10458+ece:Z5100/aaseq -> REST.kegg_get(["hsa:10458", "ece:Z5100"], "aaseq")