Importerror: No Module Named 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 SeqRe
Solution 1:
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:
# File Name RandonProteinSequences.py# standard libraryimport os
import random
# biopythonfrom Bio.Seq import Seq
from Bio.Alphabet import IUPAC
from Bio.SeqRecord import SeqRecord
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"]
defgetProteinSeqRecord(residue, seqcount):
strSeq = ""for i inrange(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
defgetProteinSequence(residue):
strSeq = ""for i inrange(0,100,1):
index = random.randint(0, len(residue)-1)
strSeq += residue[index]
sequence = Seq(strSeq, IUPAC.IUPACProtein)
return sequence
defrandomProteinSeqRecord(index):
if(index%2)==0:
return getProteinSeqRecord(residueList1, index)
elif(index%3)==0:
return getProteinSeqRecord(residueList2, index)
else:
return getProteinSeqRecord(residueList3, index)
#informationprint'--- 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 stringtry:
filepath = raw_input('Enter filepath to save sequences ... ')
filepath = filepath + '.fasta'#handle = open(filepath, "w")#handle.close()
filepathProvided = Trueexcept IOError:
print'Invalid or No File provided will print results to console'print
ranSeqCount = 10try:
ranSeqCount = int(raw_input('Enter number of random sequences to generate ... '))
except ValueError:
ranSeqCount = 10passprint'Sequence Count : 'print ranSeqCount
records = []
for i inrange(0,ranSeqCount,1):
records.append(randomProteinSeqRecord(i+1))
if(filepathProvided):
SeqIO.write(records, filepath, "fasta")
print'File created at : ' + filepath
else:
print'Writing to console is actually not supported! :/'print
raw_input('Press any key to exit ...')
print
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.
Solution 2:
Maybe you have to change:
import Bio.writers.SeqRecord.fasta
for:
fromBio.writers.SeqRecordimport fasta
Post a Comment for "Importerror: No Module Named Writers.seqrecord.fasta"