【发布时间】:2019-02-08 05:48:23
【问题描述】:
我有以下代码,它读取包含 10 个基因序列的 FASTA 文件,并将每个序列作为矩阵返回。 然而,最后一个序列中的代码似乎丢失了,我想知道为什么?
file=open('/Users/vivianspro/Downloads/rosalind_cons (5).txt', 'r')
line=file.readline()
strings = []
sequence=''
while line:
#line=line.rstrip('\n')
line = line.strip() #empty () automatically strips the \n
if '>' in line:
if sequence != "":
strings.append(sequence)
sequence = ""
#sequence=line
else:
sequence+=line
line=file.readline()
for s in strings:
print(s)
Motifs = []
for seq in strings:
Motifs.append(list(seq))
#make every symbol into an element in the list separated by ,
for s in Motifs:
print(s) ````
【问题讨论】:
-
如果 '>' 在行中,您只能附加到字符串。我们可以看看一些示例数据吗?
-
@AustinHastings 这就是 FASTA 的格式。通过查找格式很容易看到一些样本,例如在维基百科上。
标签: python bioinformatics biopython fasta