85bd10da37f403d155c4434d90edcd146e682948 braney Mon May 15 13:03:32 2017 -0700 add sorting to composite wiggles. diff --git src/optimalLeaf/bestArr.cc src/optimalLeaf/bestArr.cc new file mode 100644 index 0000000..8110031 --- /dev/null +++ src/optimalLeaf/bestArr.cc @@ -0,0 +1,230 @@ +//----------------------------------------------------------- +// Bestarrange.cc +// Builds an hierarchical clustering tree, and finds its optimal +// leaf ordering. The program gets as an input an expression +// file (see README) and generates four files as output. +// The first two (for an input file named foo.txt, these are called fooIn.GTR +// and fooIn.CDT) are the hierarchical clustering reuslts. The other two +// files (foo.CDT and foo.GTR) are the optima leaf ordering results. +// Both these results can be viewed using Michael Eisen's TreeView +// software. +//---------------------------------------------------------- + +#include +#include +#include +using namespace std; +#include +#include +#include "general.hh" +#include "Tree.hh" +#include "SimMat.hh" + +extern "C" +{ +#include "optimalLeaf.h" +} + +const int BUFSIZE = 100; +Tree *createTree(int num,float **m,char *str); +char *nameFile(char *name,char *e,char *m); +void copyFile(char *from, char *to); + +#ifdef NOTNOW +main(int argc,char** argv) { + + int i,len = strlen(argv[1]); + char *fullName = new char[len+6]; + strcpy(fullName,argv[1]); + strcat(fullName,".txt"); + fullName[len+5] = '\0'; + int newD = descLen; // initial maximum length of description + int newO = orfLen; // initial maximum length of orf name + int meanZ = 0; + int mult = 0; + if(argc>2) { + for(i=3;i<=argc;i++) { + if(argv[i-1][0] == '-' && argv[i-1][1] == 'd') + newD = atoi(argv[i-1]+2); + if(argv[i-1][0] == '-' && argv[i-1][1] == 'o') + newO = atoi(argv[i-1]+2); + if(argv[i-1][0] == '-' && argv[i-1][1] == 'c') + meanZ = 1; + if(argv[i-1][0] == '-' && argv[i-1][1] == 'm') + mult = 1; + } + } + SimMat inputData(fullName,newO,newD,meanZ); + // output files names + char *cdtFile = nameFile(argv[1],".CDT",0); + char *gtrFile = nameFile(argv[1],".GTR",0); + char *inCdtFile = nameFile(argv[1],".CDT","In"); + char *inGtrFile = nameFile(argv[1],".GTR","In"); + char *atrFile = nameFile(argv[1],".ATR",0); + float **mat = inputData.giveMat(); // similarity matrix + int num = inputData.giveGenes(); + Tree *t = createTree(num,mat,gtrFile,"GENE"); // hierarchical clustering tree + copyFile(gtrFile,inGtrFile); + float init = -1*t->curDist(mat); // initial ordering score + cerr<<"Initial sum of similarities "<initOrder(); + float min; + int *arr = t->returnOrder(&min,num); // the optimal leaf algorithm call + min = -1*min; + cerr<<"Optimal sum of similarities: "<curDist(cMat); // initial ordering score + int *orderC = tc->initOrder(); + float minC; + delete []arrC; + arrC = tc->returnOrder(&minC,numC); // the optimal leaf algorithm call + minC = -1*minC; + cerr<<"Initial column similarity: "<giveNumLeafs(); + lSize = allTrees[l]->giveNumLeafs(); +#ifdef NOTNOW + to<<"NODE"<isLeaf()) + to<giveIndex()<<"X"<<'\t'; + else + to<<"NODE"<giveIndex()<<"X"<<'\t'; + if(allTrees[r]->isLeaf()) + to<giveIndex()<<"X"<<'\t'; + else + to<<"NODE"<giveIndex()<<"X"<<'\t'; + to<initOrder(); + float min; + int *arr = t->returnOrder(&min,num); // the optimal leaf algorithm call + +return arr; +} + +}