/usr/share/hyphy/TemplateBatchFiles/LRTRecombTest.bf is in hyphy-common 2.2.7+dfsg-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | VERBOSITY_LEVEL = -1;
ALLOW_SEQUENCE_MISMATCH = 1;
fprintf(stdout,"\n ---- RUNNING KH ALTERNATIVE TOPOLOGY TEST ---- \n");
ChoiceList (dataType,"Data type",1,SKIP_NONE,"Nucleotide/Protein","Nucleotide or amino-acid (protein).",
"Codon","Codon (several available genetic codes).");
if (dataType<0)
{
return;
}
if (dataType)
{
NICETY_LEVEL = 3;
SetDialogPrompt ("Please choose a codon data file:");
#include "TemplateModels/chooseGeneticCode.def";
}
else
{
SetDialogPrompt ("Please choose a nucleotide or amino-acid data file:");
}
DataSet ds = ReadDataFile (PROMPT_FOR_FILE);
fprintf (stdout,"The following data were read:\n",ds,"\n");
ChoiceList (compType,"Comparison Kind",1,SKIP_NONE,"Full Alignment","Compare the trees applied to the full alignment.",
"Recombination Test","Compare the trees on 2 parts of the alignment, reversing their roles before and after the breakpoint.");
if (compType<0)
{
return;
}
if (dataType)
{
DataSetFilter filteredData = CreateFilter (ds,3,"","",GeneticCodeExclusions);
}
else
{
DataSetFilter filteredData = CreateFilter (ds,1);
}
SelectTemplateModel(filteredData);
firstTreeString = "";
secondTreeString = "";
if (Rows(NEXUS_FILE_TREE_MATRIX)>=2)
{
ChoiceList (tc,"Choose first tree",1,SKIP_NONE,NEXUS_FILE_TREE_MATRIX);
if (tc>=0)
{
firstTreeString = NEXUS_FILE_TREE_MATRIX[tc][1];
skipMx = {{tc__}};
ChoiceList (tc,"Choose second tree",1,skipMx,NEXUS_FILE_TREE_MATRIX);
if (tc>=0)
{
secondTreeString = NEXUS_FILE_TREE_MATRIX[tc][1];
}
}
else
{
ChoiceList (tc,"Choose second tree",1,SKIP_NONE,NEXUS_FILE_TREE_MATRIX);
if (tc>=0)
{
secondTreeString = NEXUS_FILE_TREE_MATRIX[tc][1];
}
}
}
if (Abs(firstTreeString) == 0)
{
SetDialogPrompt ("Locate the file with the first tree:");
fscanf (PROMPT_FOR_FILE,"Tree",firstTree);
}
else
{
Tree firstTree = firstTreeString;
}
if (Abs(secondTreeString) == 0)
{
SetDialogPrompt ("Locate the file with the second tree:");
fscanf (PROMPT_FOR_FILE,"Tree",secondTree);
}
else
{
Tree secondTree = secondTreeString;
}
if (firstTree == secondTree)
{
fprintf (stdout, "\nERROR: The two trees cannot be equal\n");
return 0;
}
firstTreeString = ""+firstTree;
secondTreeString = ""+secondTree;
fprintf (stdout, "\nFirst tree:\n",firstTreeString, "\n\nSecond Tree:\n",secondTreeString,"\n");
itCount = 0;
while (itCount<1)
{
fprintf (stdout, "\nHow many bootstrap replicates should be done (>0):");
fscanf (stdin, "Number", itCount);
}
labels = {{"Resampled LRT"}};
if (compType)
{
breakPoint = 0;
if (dataType)
{
pPrompt = "codons";
}
else
{
pPrompt = "bp";
}
while (breakPoint<1 || breakPoint > filteredData.sites-2)
{
fprintf (stdout, "\nEnter the location of the breakpoint (0-based and measured in ", pPrompt, "). Valid locations are [1-", filteredData.sites-3, "]:");
fscanf (stdin, "Number", breakPoint);
}
fprintf (stdout, "\nUsing the breakpoint at ", breakPoint, "-th ", pPrompt, "\n");
if (dataType)
{
DataSetFilter filteredData1 = CreateFilter (ds,3,siteIndex<3*breakPoint,"",GeneticCodeExclusions);
DataSetFilter filteredData2 = CreateFilter (ds,3,siteIndex>=3*breakPoint,"",GeneticCodeExclusions);
}
else
{
DataSetFilter filteredData1 = CreateFilter (ds,1,siteIndex<breakPoint);
DataSetFilter filteredData2 = CreateFilter (ds,1,siteIndex>=breakPoint);
}
LikelihoodFunction lf1_1 = (filteredData1,firstTree);
Optimize (res1_1, lf1_1);
ConstructCategoryMatrix (v1,lf1_1,COMPLETE);
fprintf (stdout, "\n\n1). FITTING TREE 1 TO PARTITION 1\n", lf1_1);
LikelihoodFunction lf1_2 = (filteredData1,secondTree);
Optimize (res1_2, lf1_2);
ConstructCategoryMatrix (v2,lf1_2,COMPLETE);
fprintf (stdout, "\n\n2). FITTING TREE 2 TO PARTITION 1\n", lf1_2);
LikelihoodFunction lf2_1 = (filteredData2,firstTree);
Optimize (res2_1, lf2_1);
ConstructCategoryMatrix (v3,lf2_1,COMPLETE);
fprintf (stdout, "\n\n3). FITTING TREE 1 TO PARTITION 2\n", lf2_1);
LikelihoodFunction lf2_2 = (filteredData2,secondTree);
Optimize (res2_2, lf2_2);
ConstructCategoryMatrix (v4,lf2_2,COMPLETE);
fprintf (stdout, "\n\n4). FITTING TREE 2 TO PARTITION 2\n", lf2_2);
LRT1 = 2*(res1_1[1][0]-res1_2[1][0]);
LRT2 = 2*(res2_2[1][0]-res2_1[1][0]);
fprintf (stdout, "\n\nSUMMARY:\n\n\tPARTITION 1 LRT = ",LRT1, "\n\tPARTITION 2 LRT = ", LRT2);
if (LRT1 < 0 || LRT2 < 0)
{
fprintf (stdout, "\n\nERROR: Both LRTs were expeceted to be positive.\nPlease check your trees and partition");
return 0;
}
test1 = testLRT (v1,v2)%0;
for (k=0; k<Columns(v1); k=k+1)
{
if (test1[k]>0)
{
break;
}
}
fprintf (stdout, "\n\nEstimated p-value for the FIRST partition (based on ", itCount," replicates): ", Format(k/itCount,10,4));
OpenWindow (CHARTWINDOW,{{"Simulated LRT for the First Partition"}
{"labels"}
{"test1"}
{"Step Plot"}
{"Index"}
{labels[0]}
{"Index"}
{"LRT"}
{"LRT"}
{""}
{""+LRT1}
{""}
{"10;1.309;0.785398"}
{"Times:12:0;Times:10:0;Times:14:2"}
{"0;0;16777215;5000268;0;0;6750054;11842740;13158600;14474460;0;3947580;0;5000268;11776947;10066329;9199669;7018159;1460610;16748822;11184810;14173291"}
{"16"}
},
"(SCREEN_WIDTH-30)/2;(SCREEN_HEIGHT-50)/2;10;40");
test2 = testLRT (v4,v3)%0;
for (k=0; k<Columns(v3); k=k+1)
{
if (test2[k]>0)
{
break;
}
}
fprintf (stdout, "\n\nEstimated p-value for the SECOND partition (based on ", itCount," replicates): ", Format(k/itCount,10,4),"\n");
OpenWindow (CHARTWINDOW,{{"Simulated LRT for the Second Partition"}
{"labels"}
{"test2"}
{"Step Plot"}
{"Index"}
{labels[0]}
{"Index"}
{"LRT"}
{"LRT"}
{""}
{""+LRT2}
{""}
{"10;1.309;0.785398"}
{"Times:12:0;Times:10:0;Times:14:2"}
{"0;0;16777215;5000268;0;0;6750054;11842740;13158600;14474460;0;3947580;0;5000268;11776947;10066329;9199669;7018159;1460610;16748822;11184810;14173291"}
{"16"}
},
"(SCREEN_WIDTH-30)/2;(SCREEN_HEIGHT-50)/2;20+(SCREEN_WIDTH)/2;40");
}
else
{
LikelihoodFunction lf1 = (filteredData,firstTree);
Optimize (res1, lf1);
ConstructCategoryMatrix (v1,lf1,COMPLETE);
fprintf (stdout, "\n\n1). FITTING TREE 1 TO THE DATA\n", lf1);
LikelihoodFunction lf2 = (filteredData,secondTree);
Optimize (res2, lf2);
ConstructCategoryMatrix (v1,lf2,COMPLETE);
fprintf (stdout, "\n\n2). FITTING TREE 2 TO THE DATA1\n", lf2);
LRT1 = 2*(res1[1][0]-res2[1][0]);
fprintf (stdout, "\n\nSUMMARY:\n\n\tLRT = ",LRT1);
if (LRT1 < 0)
{
fprintf (stdout, "\n\nERROR: The LRTs was expeceted to be positive.\nPlease check your trees and alignemt");
return 0;
}
test1 = testLRT (v1,v2)%0;
for (k=0; k<Columns(v1); k=k+1)
{
if (test1[k]>0)
{
break;
}
}
fprintf (stdout, "\n\nEstimated p-value for (based on ", itCount," replicates): ", Format(k/itCount,10,4),"\n");
OpenWindow (CHARTWINDOW,{{"Simulated LRT"}
{"labels"}
{"test1"}
{"Step Plot"}
{"Index"}
{labels[0]}
{"Index"}
{"LRT"}
{"LRT"}
{""}
{""+LRT1}
{""}
{"10;1.309;0.785398"}
{"Times:12:0;Times:10:0;Times:14:2"}
{"0;0;16777215;5000268;0;0;6750054;11842740;13158600;14474460;0;3947580;13421772;5000268;11776947;10066329;9199669;7018159;1460610;16748822;11184810;14173291;14173291"}
{"16"}
},
"(SCREEN_WIDTH-30)/2;(SCREEN_HEIGHT-50)/2;20+(SCREEN_WIDTH)/2;40");
}
/*--------------------------------------------------------------------------------------*/
function testLRT (vec1, vec2)
{
size1 = Columns(vec1);
sumVec1 = {size1,1};
jvec = {2,size1};
resMx1 = {itCount,1};
resMx2 = {itCount,1};
for (k=0; k<size1; k=k+1)
{
sumVec1 [k] = 1;
jvec [0][k] = Log(vec1[k]);
jvec [1][k] = Log(vec2[k]);
}
for (k=0; k<itCount; k=k+1)
{
resampled = Random(jvec,1);
resampled = resampled*sumVec1;
resMx1[k] = resampled[0];
resMx2[k] = resampled[1];
}
return (resMx1-resMx2)*2;
}
|