Did you know? Programmers convert coffee to code.

If you like my articles, sponsor me a coffee.

At the other end of the link I post some results of my other hobbies, like playing bass. It is worth checking it out ;)

Creating a Profile Matrix

Previously I have written about the Greedy Motif Search. There I got a question about creating the profile matrix. Let’s take a look at how it is calculated.

What is the profile matrix?

It is a matrix which is calculated on the number of nucleotides in each string at the given position. The nucleotide-count adds up to 1 in each column.

To be more clear let’s see an example:

<br />
GGCGTTCAGGCA<br />
AAGAATCAGTCA<br />
CAAGGAGTTCGC<br />
CACGTCAATCAC<br />
CAATAATATTCG<br />

In the example above we see a list of nucleotides. If we generate the profile we get the following result:

<br />
A: 0.2, 0.8, 0.4, 0.2, 0.4, 0.4, 0.2, 0.8, 0.0, 0.0, 0.2, 0.4<br />
C: 0.6, 0.0, 0.4, 0.0, 0.0, 0.2, 0.4, 0.0, 0.0, 0.4, 0.6, 0.4<br />
G: 0.2, 0.2, 0.2, 0.6, 0.2, 0.0, 0.2, 0.0, 0.4, 0.2, 0.2, 0.2<br />
T: 0.0, 0.0, 0.0, 0.2, 0.4, 0.4, 0.2, 0.2, 0.6, 0.4, 0.0, 0.0<br />

 As you can see, the profile is the amount of each nucleotide in the given position divided by the number of nucleotide strings provided.
If we want to code a profile generator in Python we could do it like this function:

<br />
def generate_profile(motifs):<br />
    k = len(motifs[0])<br />
    profile = {'A': [0] * k, 'C': [0] * k, 'G': [0] * k, 'T': [0] * k}<br />
    div = float(len(motifs))<br />
    for i in range(k):<br />
        for motif in motifs:<br />
            profile[motif[i]][i] += 1<br />
        for key in profile:<br />
            profile[key][i] /= div<br />
    return profile<br />

 This function returns the profile matrix as a dictionary with the nucleotide as the key and the profile score as the value.
This was easy. Now you can use this function to generate the profile for a Greedy Motif Search.
Share the knowledge!
GHajba

Senior developer, consultant, author, mentor, apprentice. I love to share my knowledge and insights what I achieve through my daily work which is not trivial -- at least not for me.

Click Here to Leave a Comment Below

>
%d bloggers like this: