【发布时间】:2018-03-30 16:14:01
【问题描述】:
我正在尝试用 python 编写一个脚本来解析一个大的 fasta 文件,我不想使用 biopython,因为我正在学习脚本。脚本需要将入藏号、序列长度、序列gc内容打印到控制台。我已经能够提取入藏号,但无法提取序列,因为它们被读取为行,这使我无法计算序列长度和 gc 内容。
谁能帮帮我? 我尝试将列表中的行分组,但随后在列表中创建了多个列表,我也不知道如何加入它们。
seq=""
seqcount=0
seqlen=0
gc=0
#prompt user for file name
infile=input("Enter the name of your designated .fasta file: ")
with open(infile, "r") as fasta:
print("\n")
print ("Accession Number \t Sequence Length \t GC content (%)")
for line in fasta:
line.strip()
if line[0]==">":
seqcount+=1 #counts number sequences in file
accession=line.split("|")[3] #extract accession
seq=""
else:
seq+=line[:-1]
seqlen=len(seq)
print(accession, "\t \t", seqlen)
print("\n")
print("There are a total of", seqcount, "sequences in this file.")
【问题讨论】:
-
什么是fasta文件?它有什么格式?我想没有多少人知道。
-
我认为您处于一个小众领域,正如@EugeneLisitsky 所说,没有多少人会知道 fasta 文件的外观并且无法为您提供帮助,如果您是最好的选择想自己学习如何做是通过 biopython 方法阅读。 github.com/biopython/biopython/blob/master/Bio/SeqIO/FastaIO.py
-
.fasta 文件是一种基于文本的格式,通常用于表示核苷酸或肽。标题或基因名称通常看起来像这样:>gene|accession ACTGACTAGGGACTGADEA
-
这种情况的幽默是 - 我熟悉 python 和遗传学(密码子三联体等),但我从未使用过 fasta 或 biopython。所以好的定义是非常有用的。谢谢 ;)