Jupyter Notebook 中的 Biopython? Windows 7
Biopython in Jupyter Notebook? Windows 7
我已经在 windows 和 Anaconda 上安装了 Python 版本 3.6。我想在 Jupyter Notebook 中的代码中使用 Biopython 包。我还使用以下命令安装了 biopython:
conda install -c anaconda biopython=1.68
当我想 运行 我的下面的代码时,它不起作用。 fasta 只是一个包含序列的文件。
from Bio import SeqIO
handle = open("Q1.fasta")
record_iterator = SeqIO.parse(handle, "fasta")
seq1_20 = record_iterator.next()
seq2_20 = record_iterator.next()
seq3_20 = record_iterator.next()
seq1_100 = record_iterator.next()
seq2_100 = record_iterator.next()
handle.close()
print seq1_20
print seq2_20
print seq3_20
print seq1_100
print seq2_100
它应该输出那些序列,但它说:
AttributeError
Traceback (most recent call last)
<ipython-input-4-d5af48173555> in <module>()
2 handle = open("Q1.fasta")
3 record_iterator = SeqIO.parse(handle, "fasta")
----> 4 seq1_20 = record_iterator.next()
5 seq2_20 = record_iterator.next()
6 seq3_20 = record_iterator.next()
AttributeError: 'generator' object has no attribute 'next'
拜托,有人帮我摆脱困境!
问题是您的示例代码仅适用于 Python 2。
Python 3 取消了迭代器 类 上的 .next()
方法,您应该改用内置函数 next(...)
(在 Python 2.6 中可用以后)。
试试 next(record_iterator)
。
我已经在 windows 和 Anaconda 上安装了 Python 版本 3.6。我想在 Jupyter Notebook 中的代码中使用 Biopython 包。我还使用以下命令安装了 biopython:
conda install -c anaconda biopython=1.68
当我想 运行 我的下面的代码时,它不起作用。 fasta 只是一个包含序列的文件。
from Bio import SeqIO
handle = open("Q1.fasta")
record_iterator = SeqIO.parse(handle, "fasta")
seq1_20 = record_iterator.next()
seq2_20 = record_iterator.next()
seq3_20 = record_iterator.next()
seq1_100 = record_iterator.next()
seq2_100 = record_iterator.next()
handle.close()
print seq1_20
print seq2_20
print seq3_20
print seq1_100
print seq2_100
它应该输出那些序列,但它说:
AttributeError
Traceback (most recent call last)
<ipython-input-4-d5af48173555> in <module>()
2 handle = open("Q1.fasta")
3 record_iterator = SeqIO.parse(handle, "fasta")
----> 4 seq1_20 = record_iterator.next()
5 seq2_20 = record_iterator.next()
6 seq3_20 = record_iterator.next()
AttributeError: 'generator' object has no attribute 'next'
拜托,有人帮我摆脱困境!
问题是您的示例代码仅适用于 Python 2。
Python 3 取消了迭代器 类 上的 .next()
方法,您应该改用内置函数 next(...)
(在 Python 2.6 中可用以后)。
试试 next(record_iterator)
。