import re
gene_dict = {}
f1 = open('human.gtf')
f2 = open('mRNAmatrix.txt')
f3 = open('sym.txt','w')
for lines in f1:
if lines.startswith('#'):
continue
line = lines.strip().split('\t')
#print(line[2])
if line[2] == "gene":
gene_id = re.search(r'gene_id "([^;]+)";',line[8]).group(1)
#print(geneid)
gene_name = re.search(r' gene_name "([^;]+)";',line[8]).group(1)
#print(gene_name)
gene_dict[gene_id] = gene_name
for lines in f2:
lines = lines.strip()
if lines.startswith('id'):
print(lines,file = f3)
continue
line = lines.split('\t')
gene_inf = line[0][:15]
if gene_inf in gene_dict:
print(gene_dict[gene_inf]+"\t"+'\t'.join(line[1:]),file = f3 )
网友评论