Welcome, Guest. Please Login
YaBB - Yet another Bulletin Board
 
  HomeHelpSearchLogin  
 
Substitution Matrix Assignment (Read 3280 times)
SamW
YaBB Newbies
*
Offline


Feed your monkey!

Posts: 18
Substitution Matrix Assignment
Nov 23rd, 2009 at 7:45pm
 
When I assign a rate matrix with dependence assignment, I get back flat likelihoods (0).  I'm ultimately trying to loop through the codon sub matrix and then input it into LikelihoodFunction without assigning each position in the matrix.
nucleotide example:

TMatrixc = {4,4};
for(j=0; j<4; j=j+1)
{
for(z=0; z<4; z=z+1)
     {
     if (j!=z)
           {
           TMatrixc[j][z]:=mu;
               }
        }
}
*this doesn't give the same answer when plugged into LikelihoodFunction than if I use the assignments from your manual.  Example -
TMatrixc={
{*,mu,mu,mu}
{mu,*,mu,mu}
{mu,mu,*,mu}
{mu,mu,mu,*}
};
(which provides reasonable likelihoods)

Can you help as to how I need to assign the sub matrix positions for the liklihood function?
Back to top
 
 
IP Logged
 
SamW
YaBB Newbies
*
Offline


Feed your monkey!

Posts: 18
Re: Substitution Matrix Assignment
Reply #1 - Nov 23rd, 2009 at 9:23pm
 
I've been looking at this and the example above is misleading.  It works for me in the nucleotide case, but when applying it to the codon situation (61x61) it provides a matrix with no likelihood.  I get the same likelihood whether I use matrix = {61,61}; as I do with matrix[i][j]:=mu; for each i!=j point in the matrix.
Back to top
 
 
IP Logged
 
Sergei
YaBB Administrator
*****
Offline


Datamonkeys are forever...

Posts: 1658
UCSD
Gender: male
Re: Substitution Matrix Assignment
Reply #2 - Nov 23rd, 2009 at 9:25pm
 
Hi Sam,

Could you please attach your complete code example? I don't see anything wrong with the double-loop code.

Sergei
Back to top
 

Associate Professor
Division of Infectious Diseases
Division of Biomedical Informatics
School of Medicine
University of California San Diego
WWW WWW  
IP Logged
 
SamW
YaBB Newbies
*
Offline


Feed your monkey!

Posts: 18
Re: Substitution Matrix Assignment
Reply #3 - Nov 23rd, 2009 at 10:04pm
 
Thanks for the incredibly quick reply!  Below is the actual code I'm running and getting a flat likelihood.  I get the same likelihood if I insert a matrix designated as matrix = {61,61};


DataSet myData = ReadDataFile ("brown.nuc");
DataSetFilter codonFilter = CreateFilter (myData,3,"","","TAA,TAG,TGA");

HarvestFrequencies (obsFreqs, codonFilter, 3, 3, 1);

CFreqs = {61,1};
for(i=0; i<64; i=i+1)
{
count=0;
if(i!=48 && i!=50 && i!=56)
     {
     CFreqs[count][1] = obsFreqs[i][1];
     count = count+1;
     }
}

TMatrix = {61,61};
for(j=0; j<61; j=j+1)
{
for(z=0; z<61; z=z+1)
     {
     if(j!=z)
           {
           TMatrix[j][z]:=mu;
           }
     }
}

Model eval = (TMatrix , CFreqs);
Tree myTree = (((Human,Chimpanzee),Gorilla),(Orangutan,Gibbon));
LikelihoodFunction theLikFun = (codonFilter , myTree);
Optimize (MLEs, theLikFun);
fprintf (stdout, "\n","\n", MLEs[1][0], "\n","\n");
Back to top
 
 
IP Logged
 
Sergei
YaBB Administrator
*****
Offline


Datamonkeys are forever...

Posts: 1658
UCSD
Gender: male
Re: Substitution Matrix Assignment
Reply #4 - Nov 24th, 2009 at 12:48am
 
Hi Sam,

SamW wrote on Nov 23rd, 2009 at 10:04pm:
CFreqs = {61,1};
for(i=0; i<64; i=i+1)
{
count=0;
if(i!=48 && i!=50 && i!=56)
     {
     CFreqs[count][1] = obsFreqs[i][1];
     count = count+1;
     }
}


Because "count" is reset to '0' in every iteration of this loop, none of the codon frequencies (except for index 0, i.e. AAA) are positive. HyPhy was reporting a (numerical) -Infinity for the MLE. This is actually correct, because the probability of the data containing multiple codons under the model which only permits 'AAA' is 0.

If you move "count = 0;" outside the loop, you should get sensible LogL values.

Cheers,
Sergei
Back to top
 

Associate Professor
Division of Infectious Diseases
Division of Biomedical Informatics
School of Medicine
University of California San Diego
WWW WWW  
IP Logged
 
SamW
YaBB Newbies
*
Offline


Feed your monkey!

Posts: 18
Re: Substitution Matrix Assignment
Reply #5 - Nov 24th, 2009 at 6:15am
 
Thank you!  That clearly fixes it and I just ran it to check as well.
However, I will admit to you that I do not feel very intelligent at this moment Sad

Sam
Back to top
 
 
IP Logged
 
Sergei
YaBB Administrator
*****
Offline


Datamonkeys are forever...

Posts: 1658
UCSD
Gender: male
Re: Substitution Matrix Assignment
Reply #6 - Nov 24th, 2009 at 9:01am
 
Hi Sam,

Glad I could help. You shouldn't feel bad - I missed the problem on first reading as well, and had to run the code through HyPhy and inspect model objects through the GUI to see what the problem was.

Happy coding,
Sergei
Back to top
 

Associate Professor
Division of Infectious Diseases
Division of Biomedical Informatics
School of Medicine
University of California San Diego
WWW WWW  
IP Logged