# Passing custom distance matrix to T_Coffee

I am trying to pass a custom distance matrix to T_Coffee, as per the docs, but can't seem to get it to work.

The documentation says to pass a matrix like this using BLAST format https://tcoffee.readthedocs.io/en/latest/tcoffee_technical_documentation.html#blast-format-recommended

# BLAST_MATRIX FORMAT
# ALPHABET=AGCT
A G C T
A 0 1 2 3
G 0 2 3 4
C 1 1 2 3
...


I've tried with and without the leading # comments, and with and without the trailing ..., but no matter what I keep getting this error:

Parsing_error when reading blast_matrix doolittle:
A C
0


Here, my distance matrix file is titled doolittle and is the difference between the hydropathy indices of amino acids based on the doolittle scale * 10 to make them all integers. I've pasted the full matrix below. I am calling the command from linux 18.08 ubuntu terminal (although I've tried a combination of others.)

t_coffee -in=rhomboids.fasta -matrix doolittle



Any help would be appreciated. Thank you!

doolittle

# BLAST_MATRIX FORMAT
# ALPHABET=ACDEFGHIKLMNPQRSTVWY
A C D E F G H I K L M N P Q R S T V W Y
A 0 7 53 53 10 22 50 27 57 20 1 53 34 53 58 26 25 24 27 31
C 7 0 60 60 3 29 57 20 64 13 6 60 41 60 65 33 32 17 34 38
D 53 60 0 0 63 31 3 80 4 73 54 0 19 0 5 27 28 77 26 22
E 53 60 0 0 63 31 3 80 4 73 54 0 19 0 5 27 28 77 26 22
F 10 3 63 63 0 32 60 17 67 10 9 63 44 63 68 36 35 14 37 41
G 22 29 31 31 32 0 28 49 35 42 23 31 12 31 36 4 3 46 5 9
H 50 57 3 3 60 28 0 77 7 70 51 3 16 3 8 24 25 74 23 19
I 27 20 80 80 17 49 77 0 84 7 26 80 61 80 85 53 52 3 54 58
K 57 64 4 4 67 35 7 84 0 77 58 4 23 4 1 31 32 81 30 26
L 20 13 73 73 10 42 70 7 77 0 19 73 54 73 78 46 45 4 47 51
M 1 6 54 54 9 23 51 26 58 19 0 54 35 54 59 27 26 23 28 32
N 53 60 0 0 63 31 3 80 4 73 54 0 19 0 5 27 28 77 26 22
P 34 41 19 19 44 12 16 61 23 54 35 19 0 19 24 8 9 58 7 3
Q 53 60 0 0 63 31 3 80 4 73 54 0 19 0 5 27 28 77 26 22
R 58 65 5 5 68 36 8 85 1 78 59 5 24 5 0 32 33 82 31 27
S 26 33 27 27 36 4 24 53 31 46 27 27 8 27 32 0 1 50 1 5
T 25 32 28 28 35 3 25 52 32 45 26 28 9 28 33 1 0 49 2 6
V 24 17 77 77 14 46 74 3 81 4 23 77 58 77 82 50 49 0 51 55
W 27 34 26 26 37 5 23 54 30 47 28 26 7 26 31 1 2 51 0 4
Y 31 38 22 22 41 9 19 58 26 51 32 22 3 22 27 5 6 55 4 0

• I'm sorry that I am only able to give you non specific advice, but have you tried the most recent version of t-coffee? Which version are you using? Maybe you could try a smaller sized matrix to test (like a 4x4). You could also submit an issue on their github. May 6 '20 at 14:53
• Could this be a simple line ending issue? Are you using Windows to generate the file by any chance? May 7 '20 at 18:07
• @terdon I am using Ubuntu, but good suggestion. Definitely been stung by the \r\n windows bug/feature before. May 7 '20 at 19:40

So I didn't find an answer,but I did find a way around if it anyone else has this problem. It does involve modifying the source code, but even if you don't understand c (I barely do) its still easy to do.

1) Download source code from github https://github.com/cbcrg/tcoffee Source code is here, view the dependency list - you will need all these libraries to compile the code for the change to take effect.

2) Add your custom matrix to source code. Search matrices.h. In this version it is t_coffee/lib/matrices.h You will see how they are defining their default matrices. Just add your matrix with the same format and give it a name. For example:

int customMT[]={
4,
0,  5,
-3, -2, 17,
0,  5, -3,  9,
0,  0,  1,  1,  6,
-2, -3, -3, -5, -4, 10,
0,  0, -4, -1, -2, -3,  8,
-2, -2, -5, -2,  0, -3, -3, 14,
0, -2, -2, -4, -3,  0, -1, -2,  6,
0,  0, -3,  0,  2, -1, -1, -2, -2,  4,
-1, -1,  0, -1, -1,  2, -2, -1,  2, -2,  4,
1, -2, -2, -3, -1, -2, -2,  2,  1,  2,  2,  6,
0,  4, -1,  1, -1, -1,  0, -1,  0,  0, -2,  0,  8,
-1, -2, -3, -1,  1, -4, -1,  1, -3,  1, -3, -4, -3, 11,
1, -1, -2, -1,  2, -3, -2,  0, -2,  0, -2, -1, -1,  0,  8,
-1, -2, -2, -1, -1, -1, -2, -1, -3,  1, -2,  0, -2, -1,  3,  8,
1,  0, -2,  0,  0, -1,  0, -1, -1,  0, -2, -2,  0, -1, -1, -1,  4,
1,  0, -2, -1, -2, -2, -2, -2,  0, -1,  0,  0,  1,  0,  0, -3,  2,  5,
1, -2, -2, -2, -3,  1, -3, -3,  4, -2,  1,  0, -2, -4, -3, -1, -1,  1,  5,
-5, -5, -2, -4, -1,  1,  1, -5, -3, -2, -2, -3, -7, -3, -1,  0, -3, -5, -3, 20,
0, -1, -2, -1, -1, -1, -1, -1,  0,  0,  0,  0,  0, -1,  0, -1,  0,  0,  0, -2, -1,
-4, -3, -6, -1, -2,  3, -3,  0, -1, -1,  3, -1, -4, -2, -1,  0, -2, -1,  1,  5, -1,  9,
0,  0,  0,  0,  5, -4, -2,  0, -3,  1, -1, -1, -1,  0,  4,  0, -1, -1, -3, -1,  0, -2,  4};


Then, search for file tcoffee/lib/io_lib/io_func.c Find the function

int ** read_matrices( char *mat_name_in)


You will see a long list of if else clauses, add the name of your custom matrix using the same pattern as they do.

/*Read Header Matrices*/
if (strm(mat_name, "pam250mt"))vector=pam250mt;
else if (strm(mat_name, "idmat"))vector=idmat;
else if (strm(mat_name, "dna_idmat"))vector=idmat;

else if (strm(mat_name, "customMT"))vector=customMT;


3) Save the files, move into tcoffee/src/. Rebuild the files using the make file as described on the github installation. It is here you need make, g++, perl, and whatever else on the list as dependencies

make t_coffee


4) Now, align your file! The only thing here is to use the t_coffee of the source code you just edited, and not t_coffee that might already be on your path. So change t_coffee/src/t_coffee to whatever the relative path to this folder is.

tcoffee/src/t_coffee rhomboids.fasta -matrix customMT


And that's it!