ImportError:没有名为 writers.SeqRecord.fasta 的模块
# File Name RandonProteinSequences.py
# standard library
import os
import random
# biopython
from Bio.Seq import Seq
from Bio.Alphabet import IUPAC
from Bio.SeqRecord import SeqRecord
import Bio.writers.SeqRecord.fasta
from Bio import SeqIO
from sys import *
residueList1 = ["C","D","E","F","G","H","I"]
residueList2 = ["A","K","L","M","N","S"]
residueList3 = ["P","Q","R","T","V","W","Y"]
residueList4 = ["C","A","G","U"]
def getProteinSeqRecord(residue, seqcount):
strSeq = ""
for i in range(0,100,1):
index = random.randint(0, len(residue)-1)
strSeq += residue[index]
sequence = Seq(strSeq, IUPAC.IUPACProtein)
seqRec = SeqRecord(sequence, id = 'randSeq' + str(seqcount), description= 'A random sequence using Amino acid residues.')
return seqRec
def getProteinSequence(residue):
strSeq = ""
for i in range(0,100,1):
index = random.randint(0, len(residue)-1)
strSeq += residue[index]
sequence = Seq(strSeq, IUPAC.IUPACProtein)
return sequence
def randomProteinSeqRecord(index):
if(index%2)==0:
return getProteinSeqRecord(residueList1, index)
elif(index%3)==0:
return getProteinSeqRecord(residueList2, index)
else:
return getProteinSeqRecord(residueList3, index)
#information
print '--- This is python based program to generate random sequences ---'
print '--- Provide number of random sequences to generate. Default 10 ---'
print '--- Inorder to save to a file provide file path or filename ---'
print '--- If none or invalid filepath is provided then results will be displayed to console ---'
print '--- The file will be created in fasta format ---'
print
filepathProvided = False
#raw_input received the user input as string
try:
filepath = raw_input('Enter filepath to save sequences ... ')
filepath = filepath + '.fasta'
handle = open(filepath, "w")
handle.close()
filepathProvided = True
except IOError:
print 'Invalid or No File provided will print results to console'
print
ranSeqCount = 10
try:
ranSeqCount = int(raw_input('Enter number of random sequences to generate ... '))
except ValueError:
ranSeqCount = 10
pass
if(filepathProvided):
handle = open(filepath, "w")
if(filepathProvided):
fasta_writer = Bio.writers.SeqRecord.fasta.WriteFasta(handle)
else:
fasta_writer = Bio.writers.SeqRecord.fasta.WriteFasta(stdout)
print 'Sequence Count : '
print ranSeqCount
for i in range(0,ranSeqCount,1):
fasta_writer.write(randomProteinSeqRecord(i+1))
if(filepathProvided):
handle.close()
print 'File created at : ' + filepath
print
raw_input('Press any key to exit ...')
print
出现此错误: 回溯(最近一次调用最后一次): 文件“C:\Users\Hemant\Desktop\RandonProteinSequences.py”,第 10 行,位于 导入 Bio.writers.SeqRecord.fasta 导入错误:没有名为 writers.SeqRecord.fasta 的模块
# File Name RandonProteinSequences.py
# standard library
import os
import random
# biopython
from Bio.Seq import Seq
from Bio.Alphabet import IUPAC
from Bio.SeqRecord import SeqRecord
import Bio.writers.SeqRecord.fasta
from Bio import SeqIO
from sys import *
residueList1 = ["C","D","E","F","G","H","I"]
residueList2 = ["A","K","L","M","N","S"]
residueList3 = ["P","Q","R","T","V","W","Y"]
residueList4 = ["C","A","G","U"]
def getProteinSeqRecord(residue, seqcount):
strSeq = ""
for i in range(0,100,1):
index = random.randint(0, len(residue)-1)
strSeq += residue[index]
sequence = Seq(strSeq, IUPAC.IUPACProtein)
seqRec = SeqRecord(sequence, id = 'randSeq' + str(seqcount), description= 'A random sequence using Amino acid residues.')
return seqRec
def getProteinSequence(residue):
strSeq = ""
for i in range(0,100,1):
index = random.randint(0, len(residue)-1)
strSeq += residue[index]
sequence = Seq(strSeq, IUPAC.IUPACProtein)
return sequence
def randomProteinSeqRecord(index):
if(index%2)==0:
return getProteinSeqRecord(residueList1, index)
elif(index%3)==0:
return getProteinSeqRecord(residueList2, index)
else:
return getProteinSeqRecord(residueList3, index)
#information
print '--- This is python based program to generate random sequences ---'
print '--- Provide number of random sequences to generate. Default 10 ---'
print '--- Inorder to save to a file provide file path or filename ---'
print '--- If none or invalid filepath is provided then results will be displayed to console ---'
print '--- The file will be created in fasta format ---'
print
filepathProvided = False
#raw_input received the user input as string
try:
filepath = raw_input('Enter filepath to save sequences ... ')
filepath = filepath + '.fasta'
handle = open(filepath, "w")
handle.close()
filepathProvided = True
except IOError:
print 'Invalid or No File provided will print results to console'
print
ranSeqCount = 10
try:
ranSeqCount = int(raw_input('Enter number of random sequences to generate ... '))
except ValueError:
ranSeqCount = 10
pass
if(filepathProvided):
handle = open(filepath, "w")
if(filepathProvided):
fasta_writer = Bio.writers.SeqRecord.fasta.WriteFasta(handle)
else:
fasta_writer = Bio.writers.SeqRecord.fasta.WriteFasta(stdout)
print 'Sequence Count : '
print ranSeqCount
for i in range(0,ranSeqCount,1):
fasta_writer.write(randomProteinSeqRecord(i+1))
if(filepathProvided):
handle.close()
print 'File created at : ' + filepath
print
raw_input('Press any key to exit ...')
print
Getting this ERROR:
Traceback (most recent call last):
File "C:\Users\Hemant\Desktop\RandonProteinSequences.py", line 10, in
import Bio.writers.SeqRecord.fasta
ImportError: No module named writers.SeqRecord.fasta
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我已经在你的其他问题中提到过这一点,我会在这里再说一遍:
此代码需要更新,因为 Bio.writers.SeqRecord。 fasta 已弃用。
我快速浏览了 Biopython 的文档,试图弄清楚如何编写 FASTA 文件。
试试这个:
请注意:我没有安装 Biopython,所以我没有运行此代码。
我想在这里帮助你,但事实是我还有更重要的事情要做。
I've already mentioned this in your other question and I'll say it here again:
This code is in need of an update, since Bio.writers.SeqRecord.fasta is deprecated.
I took a quick look at Biopython's documentation trying to figure out how you can write a FASTA file.
Try this:
Please note: I don't have Biopython installed, so I didn't run this code.
I'm trying to help you here, but the truth is I've got better things to do.
也许你必须改变:
为:
Maybe you have to change:
for: