Question: Biopython How to generate random Position-Weight Matrices
0
gravatar for romeasy
3.4 years ago by
romeasy10
European Union
romeasy10 wrote:

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 explicitely?

 

Thanks for any suggestions.

biopython sequence • 1.1k views
ADD COMMENTlink modified 3.4 years ago • written 3.4 years ago by romeasy10
2
gravatar for romeasy
3.4 years ago by
romeasy10
European Union
romeasy10 wrote:

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 COMMENTlink modified 3.4 years ago • written 3.4 years ago by romeasy10

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 REPLYlink modified 7 months ago • written 7 months ago by mdsiddra20
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1143 users visited in the last hour