Import Fasta Sequences To A Motif
1
1
Entering edit mode
13.3 years ago
RossCampbell ▴ 140

I need to construct a PWM from every sequence in a fasta file, using biopython. The way I'm trying to do this is to import each line of sequence into a motif, then run a PWM on each instance of the motif. Currently, I'm trying it this way, but different variations of it have generated their fair share of errors, mostly "Wrong Alphabet" and "NoneType object is not iterable":

alphabet = IUPAC.unambiguous_dna
m = Motif.Motif(alphabet)

for seq_record in SeqIO.parse("10fasta.fasta", "fasta"):
    m.add_instance(seq_record.seq)
    print m1.pwm()

Does anyone see what's wrong with the way I'm adding instances to the motif? Of course, if there's a better way to do this that I'm completely missing, feel free to comment on that too.

biopython motif parsing • 4.0k views
ADD COMMENT
2
Entering edit mode
13.3 years ago
brentp 24k

You need to tell SeqIO.parse which alphabet to use as well:

from Bio import SeqIO
from Bio.Alphabet import IUPAC
from Bio import Motif

alphabet = IUPAC.unambiguous_dna
m = Motif.Motif(alphabet)

for seq_record in SeqIO.parse("some.fasta", "fasta", alphabet=alphabet):
    m.add_instance(seq_record.seq)
    print m.pwm()

(and your m1 is undefined).

ADD COMMENT
0
Entering edit mode

Thanks. m1 == m, I just haven't updated all the variable names yet from my other program that I borrowed this block of code from.

ADD REPLY

Login before adding your answer.

Traffic: 2303 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6