我正在尝试用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.")