This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How To Generate A Motif Object Directly For A Count Matrix In Biopython

If I have a variable in python like this:

pfm = {'A': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
       'C': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
       'G': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
       'T': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]}

how to generate a Biopython Motif object from this variable directly other than save above matrix in a file and use Motif.read() to load the matrix into a Motif object.

biopython

2 answers

You can use:

m = Motif(counts=pfm)

As far as I can see there is no way to do this with a proper function of the Motif class. You could try to just do:

m = Motif()
m.counts = pfm
m.has_counts = True
m.set_mask("*"*m.length)

I did not test it and have no idea if there are any problems with the alphabet, but something along this lines could work.

Log in to answer this question.