美文网首页生物信息编程
尝试着看懂第一个处理生物信息的python程序并自己编写一个py

尝试着看懂第一个处理生物信息的python程序并自己编写一个py

作者: 龙star180 | 来源:发表于2019-05-13 16:04 被阅读5次

今天学了几个新的函数:

line.strip()和line.split()具体参考见如下:https://www.cnblogs.com/yunyinzhihua/p/6884920.html

chl.replace()具体参考见下:https://www.runoob.com/python3/python3-string-replace.html

file.write()具体参考见下:https://blog.csdn.net/sxingming/article/details/51337664


要用read函数 achieve

哈哈哈哈,靠自己写下生平第一个程序:用在生信上就是根据目标基因ID从全基因组fasta文件中提取目标序列的fasta序列。作为纪念,有喜欢的朋友欢迎拿去使用哈哈!

gene_name = open('10.ti.name.txt') #your gene_family id

#print(gene_name.read())

fasta_file = open('Si.new.genome.cds.fasta') #the whole genomes

#print(fasta_file.read())

chl_fasta = {}

out_file = open('Si.10.GRF.cds.fasta','w') #the result file

for row in fasta_file:

if ">" in row:

fsy = row.split()

chl_gene = fsy[0].replace('>', '')

fsy_sequence = ''

else:

row.strip()

sequences = row.split()

store = sequences[0] + "\n"

fsy_sequence = fsy_sequence + store

chl_fasta[chl_gene] = fsy_sequence

#print(chl_fasta)

for line in gene_name:

my_gene = line.split()

my_id = my_gene[0]

if my_id in chl_fasta: 

# print(">" + my_id + "\n" + chl_fasta[my_id][:-1])

results = ">" + my_id + "\n" + chl_fasta[my_id][:-1] + "\n"

out_file.write(results)

#make by chl

#也可以在前面的if语句内将字典里的键都存在一空列表里,然后在此判断给的ID是否存在列表中

祝自己和大家做生信愉快!

相关文章

网友评论

    本文标题:尝试着看懂第一个处理生物信息的python程序并自己编写一个py

    本文链接:https://www.haomeiwen.com/subject/zsflaqtx.html