Biopython How to generate random Position-Weight Matrices
1
0
Entering edit mode
9.1 years ago
romeasy ▴ 10

Hi,

I am looking for a way to generate random Position-Weight Matrices (PWM) using Biopython.

I have to use Biopython for various reasons (fast motif finding for instance) but seem to be unable to create a Motif or PWM object by hand.

Is there any method to create PWMs from either numpy arrays or by specifying the 'counts' variable explicitly?

Thanks for any suggestions.

sequence Biopython • 3.2k views
ADD COMMENT
2
Entering edit mode
9.1 years ago
romeasy ▴ 10

Okay, I already solved it myself.

For anyone interested, here is how I did it:

def createRandomMotif (motifLength, alphabet):
    counts = {}
    for letter in alphabet.letters:
        counts[letter] = [random.randint(0,100) for x in xrange(motifLength)]
    return mat.PositionWeightMatrix(alphabet, counts)

x = createRandomMotif(6, alphabet)
print x

Console:

        0      1      2      3      4      5
A:   0.20   0.22   0.12   0.31   0.27   0.23
C:   0.03   0.33   0.34   0.28   0.39   0.38
G:   0.33   0.00   0.24   0.26   0.02   0.23
T:   0.44   0.45   0.29   0.16   0.32   0.16

This generates a random motif matrix for any given alphabet and motif length (k-mer length) k.

ADD COMMENT
0
Entering edit mode

I am also using biopython and I am looking for a way to generate 'WAG' matrix from aligned protein sequence file. What kind of matrix is this one? How does the formula is applied to calculate frequencies of amino acids?

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