我的代码:
GFF = raw_input("Please enter gff3 file: ")
GFF = open(GFF, "r")
GFF= GFF.read()
new_dict = {}
for i in GFF:
element = i.split()
if (element[2] == "five_prime_UTR"):
if element[7] in new_dict:
new_dict[element[2]]+= 1
if element[3] in new_dict:
new_dict[element[3]] += 1
我得到的element[2] == "five_prime_UTR"
索引超出范围
如何为geneid(如Zm00001d027231)及其五个主要utr区域编号(如50887)创建字典。我一直在尝试这样做,首先均衡五个素数utr区域,然后从那里开始
期望输出
new_dict ={Zm00001d027231:50887}
gff3文件是一个基因注释文件。看起来是这样的:
1 gramene exon 55222 55682 . - . Parent=transcript:Zm00001d027231_T003;Name=Zm00001d027231_T003.exon1;constitutive=0;ensembl_end_phase=0;ensembl_phase=-1;exon_id=Zm00001d027231_T003.exon1;rank=1
1 gramene five_prime_UTR 55549 55682 . - . Parent=transcript:Zm00001d027231_T003
1 gramene mRNA 50887 55668 . - . ID=transcript:Zm00001d027231_T004;Parent=gene:Zm00001d027231;biotype=protein_coding;transcript_id=Zm00001d027231_T004
1 gramene three_prime_UTR 50887 51120 . - . Parent=transcript:Zm00001d027231_T004
1 gramene exon 50887 51239 . - . Parent=transcript:Zm00001d027231_T004;Name=Zm00001d027231_T004.exon9;constitutive=0;ensembl_e
变量
GFF
保存gff3文件的内容现在,您正在每个字符上循环文件字符的内容
您想使用
for i in GFF.splitlines():
逐行循环文件的内容您还可以使代码更加清晰,为正在解析的字段命名,如:
相关问题 更多 >
编程相关推荐