BioPython SeqIO:[Errno 2] 没有这样的文件或目录:'d'

BioPython SeqIO: [Errno 2] No such file or directory: 'd'

我正在尝试使用 SeqIO.parse 遍历大型 fasta 文件,但我遇到了一些问题。这是我的测试脚本示例:

from Bio import SeqIO

file = 'large.fasta'

for seq_record in SeqIO.parse(file[0], 'fasta'):
    print (seq_record)

它给出的错误是:

Traceback (most recent call last):
  File "test.py", line 12, in <module>
    for seq_record in SeqIO.parse(file[0], 'fasta'):
  File "/Users/francoiskroll/miniconda3/lib/python3.6/site-packages/Bio/SeqIO/__init__.py", line 618, in parse
    with as_handle(handle, mode) as fp:
  File "/Users/francoiskroll/miniconda3/lib/python3.6/contextlib.py", line 81, in __enter__
    return next(self.gen)
  File "/Users/francoiskroll/miniconda3/lib/python3.6/site-packages/Bio/File.py", line 101, in as_handle
    with open(handleish, mode, **kwargs) as fp:
FileNotFoundError: [Errno 2] No such file or directory: 'l'

你能帮忙吗?

你的文件的第一个字母是d,因为如果file是一个字符串,file[0]就是第一个字符

for seq_record in SeqIO.parse(file, 'fasta'):
    print (seq_record)