我想寫一個Python腳本,它需要一個特殊類型的文件作爲輸入。
此文件包含有關多個基因的信息,並且關於一個基因的信息被寫在多行上,其中行數對於每個基因都不相同。一個例子是:從一個文件到Python中的多個詞典
gene join(373616..374161,1..174)
/locus_tag="AM1_A0001"
/db_xref="GeneID:5685236"
CDS join(373616..374161,1..174)
/locus_tag="AM1_A0001"
/codon_start=1
/transl_table=11
/product="glutathione S-transferase, putative"
/protein_id="YP_001520660.1"
/db_xref="GI:158339653"
/db_xref="GeneID:5685236"
/translation="MKIVSFKICPFVQRVTALLEAKGIDYDIEYIDLSHKPQWFLDLS
PNAQVPILITDDDDVLFESDAIVEFLDEVVGTPLSSDNAVKKAQDRAWSYLATKHYLV
QCSAQRSPDAKTLEERSKKLSKAFGKIKVQLGESRYINGDDLSMVDIAWLPLLHRAAI
IEQYSGYDFLEEFPKVKQWQQHLLSTGIAEKSVPEDFEERFTAFYLAESTCLGQLAKS
KNGEACCGTAECTVDDLGCCA"
gene 241..381
/locus_tag="AM1_A0002"
/db_xref="GeneID:5685411"
CDS 241..381
/locus_tag="AM1_A0002"
/codon_start=1
/transl_table=11
/product="hypothetical protein"
/protein_id="YP_001520661.1"
/db_xref="GI:158339654"
/db_xref="GeneID:5685411"
/translation="MLINPEDKQVEIYRPGQDVELLQSPSTISGADVLPEFSLNLEWI
WR"
gene 388..525
/locus_tag="AM1_A0003"
/db_xref="GeneID:5685412"
CDS 388..525
/locus_tag="AM1_A0003"
/codon_start=1
/transl_table=11
/product="hypothetical protein"
/protein_id="YP_001520662.1"
/db_xref="GI:158339655"
/db_xref="GeneID:5685412"
/translation="MKEAGFSENSRSREGQPKLAKDAAIAKPYLVAMTAELQIMATET
L"
我想要什麼,現在,是創建字典,其中每個字典包含一個基因的信息,像這樣的列表:我絕對
gene_1 = {"locus": /locus_tag, "product": /product, ...}
gene_2 = {"locus": /locus_tag, "product": /product, ...}
沒有想法當一個基因/字典完成後,我應該如何讓Python知道,下一個應該開始。
有人可以幫我嗎?有沒有辦法做到這一點?
澄清:我知道如何提取我想要的信息,將它保存在變量中並將其存入字典中。我只是不知道如何告訴Python爲每個基因創建一個字典。
你把*任何*代碼在一起作爲一個企圖解決這個問題?如果是這樣,請張貼它。 –
冒號可以作爲值的一部分出現嗎?如果沒有,你可以簡單地通過檢查該行是否包含冒號來找到新實體的開始... – l4mpi
@PaulC我試着簡單地循環遍歷文件,但那不會。我一直在尋找新的想法幾天,但我似乎是一個初學者太多,想出點什麼。提取數據和填充字典不是問題,只是簡單的循環不會。 –