我试图用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.")
你离正确的密码不远了:
需要注意的事项:
相关问题 更多 >
编程相关推荐