This is a test version of Biostars. For the public version, visit https://www.biostars.org.
convert PWM to IUPAC/consensus

Hi,

I installed rsat in my working environment. I have thousands of PWM results I got after running an application. The PWM looks like this:

A | 0.3247 | 0.4065 | 0.9253 | 0.1905 | 1.0000 | 0.2675 | 0.0741 | 0.5867 | 0.3564 | 0.0981 | 0.0000 | 1.0000 |
C | 0.6381 | 0.0416 | 0.0000 | 0.0000 | 0.0000 | 0.2910 | 0.7501 | 0.0000 | 0.0000 | 0.0000 | 0.0000 | 0.0000 |
G | 0.0000 | 0.4572 | 0.0747 | 0.7103 | 0.0000 | 0.0962 | 0.0949 | 0.0000 | 0.6436 | 0.0000 | 1.0000 | 0.0000 |
T | 0.0373 | 0.0948 | 0.0000 | 0.0992 | 0.0000 | 0.3454 | 0.0809 | 0.4133 | 0.0000 | 0.9019 | 0.0000 | 0.0000 |

I removed the pipeline characters in between and tried to use convert-matrix command from rsat with no luck.

Any advice please?

Thanks,
J.

rsat

1 answer

You should post the error from the RSAT command that failed, but I'm guessing it is because the matrix isn't in tab format.

When I replace the pipes (actually " | ", note the spaces) with tabs, and delete the trailing " |", the RSAT online convert matrix tool works.

For example, you want to change

A | 0.5 | 0.5 |
.
.
T | 0.5 | 0.5 |

To

A\t0.5\t0.5
.
.
T\t0.5\t0.5

This command should work, assuming each PWM is in a separate file, just change "mat.txt" to the name of your file:

sed "s/ | /@/g" mat.txt | sed "s/ |//g" | tr "@" "\t"

You can automate for all of your PWMs with xargs or GNU parallel.

Here's an example script:

#!/bin/bash
matlist=$1

while read mat
do
    sed "s/ | /@/g" $mat | sed "s/ |//g" | tr "@" "\t" > ${mat/%.*/.tabmat}
done < $matlist

Get each matrix file in a list, maybe "matlist.txt" and run the script. It will reformat the matrix and save the reformatted PWM to a file with a new suffix called ".tabmat".

Perfect! Thank you so much.

Log in to answer this question.