]> git.donarmstrong.com Git - mothur.git/blobdiff - shhhercommand.cpp
*** empty log message ***
[mothur.git] / shhhercommand.cpp
index d1732cd0dc37ba3db1edcfdb3835413d3ddaf559..5bf802ef304dde8c9d628db63a9e0915f23f236e 100644 (file)
@@ -48,7 +48,7 @@ vector<string> ShhherCommand::getValidParameters(){
 
 ShhherCommand::ShhherCommand(){        
        try {
-               abort = true;
+               abort = true; calledHelp = true;
                
                //initialize outputTypes
                vector<string> tempOutNames;
@@ -101,11 +101,11 @@ ShhherCommand::ShhherCommand(string option) {
 #endif
                
                
-               abort = false;
+               abort = false; calledHelp = false;   
                
                
                //allow user to run help
-               if(option == "help") { help(); abort = true; }
+               if(option == "help") { help(); abort = true; calledHelp = true; }
                
                else {
                        
@@ -171,7 +171,15 @@ ShhherCommand::ShhherCommand(string option) {
                                m->mothurOutEndLine();
                                abort = true; 
                        }
-                       else if (flowFileName == "not open" || flowFilesFileName == "not open") { abort = true; }       
+                       else if (flowFileName == "not open" || flowFilesFileName == "not open") { abort = true; }
+                       
+                       if(flowFileName != "not found"){        compositeFASTAFileName = "";    }
+                       else{
+                               compositeFASTAFileName = flowFilesFileName.substr(0, flowFilesFileName.length()-10) + "pn.fasta";
+                               ofstream temp;
+                               m->openOutputFile(compositeFASTAFileName, temp);
+                               temp.close();
+                       }
                        
                        //if the user changes the output directory command factory will send this info to us in the output parameter 
                        outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  
@@ -237,16 +245,13 @@ void ShhherCommand::help(){
 #ifdef USE_MPI
 int ShhherCommand::execute(){
        try {
+               if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
+               
                int tag = 1976;
                MPI_Status status; 
 
                double begClock = clock();
                unsigned long int begTime = time(NULL);
-
-               cout.setf(ios::fixed, ios::floatfield);
-               cout.setf(ios::showpoint);
-               cout << setprecision(2);
-               
                
                if(pid == 0){
 
@@ -257,7 +262,7 @@ int ShhherCommand::execute(){
 
                        processors = ncpus;
                        
-                       cout << "\nGetting preliminary data..." << endl;
+                       m->mothurOut("\nGetting preliminary data...\n");
                        getSingleLookUp();
                        getJointLookUp();
                        
@@ -285,13 +290,14 @@ int ShhherCommand::execute(){
                        for(int i=0;i<numFiles;i++){
                                flowFileName = flowFileVector[i];
                        
-                               cout << "\n>>>>>\tProcessing " << flowFileName << " (file " << i+1 << " of " << numFiles << ")\t<<<<<" << endl;
-                               cout << "Reading flowgrams..." << endl;
+                               m->mothurOut("\n>>>>>\tProcessing " + flowFileName + " (file " + toString(i+1) + " of " + toString(numFiles) + ")\t<<<<<\n");
+                               m->mothurOut("Reading flowgrams...\n");
+                               
                                getFlowData();
-                               cout << "Identifying unique flowgrams..." << endl;
+                               m->mothurOut("Identifying unique flowgrams...\n");
                                getUniques();
 
-                               cout << "Calculating distances between flowgrams..." << endl;
+                               m->mothurOut("Calculating distances between flowgrams...\n");
                                char fileName[1024];
                                strcpy(fileName, flowFileName.c_str());
 
@@ -322,11 +328,9 @@ int ShhherCommand::execute(){
 
                                string namesFileName = createNamesFile();
                                
-                               cout << "\nClustering flowgrams..." << endl;
+                               m->mothurOut("\nClustering flowgrams...\n");
                                string listFileName = cluster(distFileName, namesFileName);
-       //                      string listFileName = "PriestPot_C7.pn.list";
-       //                      string listFileName = "test.mock_rep3.v69.pn.list";
-                       
+
                                getOTUData(listFileName);
                                initPyroCluster();
 
@@ -343,9 +347,8 @@ int ShhherCommand::execute(){
                                
                                int numOTUsOnCPU = numOTUs / ncpus;
                                int numSeqsOnCPU = numSeqs / ncpus;
-                               
-                               cout << "\nDenoising flowgrams..." << endl;
-                               cout << "iter\tmaxDelta\tnLL\t\tcycletime" << endl;
+                               m->mothurOut("\nDenoising flowgrams...\n");
+                               m->mothurOut("iter\tmaxDelta\tnLL\t\tcycletime\n");
                                
                                while((maxIters == 0 && maxDelta > minDelta) || iter < MIN_ITER || (maxDelta > minDelta && iter < maxIters)){
 
@@ -446,7 +449,7 @@ int ShhherCommand::execute(){
                                        
                                        iter++;
                                        
-                                       cout << iter << '\t' << maxDelta << '\t' << setprecision(2) << nLL << '\t' << time(NULL) - cycTime << '\t' << setprecision(6) << (clock() - cycClock)/(double)CLOCKS_PER_SEC << endl;                   
+                                       m->mothurOut(toString(iter) + '\t' + toString(maxDelta) + '\t' + toString(nLL) + '\t' + toString(time(NULL) - cycTime) + '\t' + toString((clock() - cycClock)/(double)CLOCKS_PER_SEC) + '\n');                  
 
                                        if((maxIters == 0 && maxDelta > minDelta) || iter < MIN_ITER || (maxDelta > minDelta && iter < maxIters)){
                                                int live = 1;
@@ -463,7 +466,7 @@ int ShhherCommand::execute(){
                                        
                                }       
                                
-                               cout << "\nFinalizing..." << endl;
+                               m->mothurOut("\nFinalizing...\n");
                                fill();
                                setOTUs();
                                vector<int> otuCounts(numOTUs, 0);
@@ -478,10 +481,9 @@ int ShhherCommand::execute(){
                                remove(distFileName.c_str());
                                remove(namesFileName.c_str());
                                remove(listFileName.c_str());
-                               
-                               cout << "Total time to process " << flowFileName << ":\t" << time(NULL) - begTime << '\t' << setprecision(6) << (clock() - begClock)/(double)CLOCKS_PER_SEC << endl;                    
+                                                                
+                               m->mothurOut("Total time to process " + toString(flowFileName) + ":\t" + toString(time(NULL) - begTime) + '\t' + toString((clock() - begClock)/(double)CLOCKS_PER_SEC) + '\n');                 
                        }
-
                }
                else{
                        int abort = 1;
@@ -624,10 +626,11 @@ string ShhherCommand::flowDistMPI(int startSeq, int stopSeq){
                                }
                        }
                        if(i % 100 == 0){
-                               cout << i << "\t" << (time(NULL) - begTime) << "\t" << (clock()-begClock)/CLOCKS_PER_SEC << endl;
+                               m->mothurOut(toString(i) + '\t' + toString(time(NULL) - begTime) + '\t' + toString((clock()-begClock)/CLOCKS_PER_SEC) + '\n');
                        }
                }
-               cout << stopSeq << "\t" << (time(NULL) - begTime) << "\t" << (clock()-begClock)/CLOCKS_PER_SEC << endl;
+               
+               m->mothurOut(toString(stopSeq) + '\t' + toString(time(NULL) - begTime) + '\t' + toString((clock()-begClock)/CLOCKS_PER_SEC) + '\n');
                
                string fDistFileName = flowFileName.substr(0,flowFileName.find_last_of('.')) + ".pn.dist";
                if(pid != 0){   fDistFileName += ".temp." + toString(pid);      }
@@ -651,9 +654,6 @@ int ShhherCommand::execute(){
        try {
                if (abort == true) { return 0; }
                
-               cout.setf(ios::fixed, ios::floatfield);
-               cout.setf(ios::showpoint);
-               
                getSingleLookUp();
                getJointLookUp();
                                
@@ -678,18 +678,19 @@ int ShhherCommand::execute(){
                for(int i=0;i<numFiles;i++){
                        flowFileName = flowFileVector[i];
 
-                       cout << "\n>>>>>\tProcessing " << flowFileName << " (file " << i+1 << " of " << numFiles << ")\t<<<<<" << endl;
-                       cout << "Reading flowgrams..." << endl;
+                       m->mothurOut("\n>>>>>\tProcessing " + flowFileName + " (file " + toString(i+1) + " of " + toString(numFiles) + ")\t<<<<<\n");
+                       m->mothurOut("Reading flowgrams...\n");
                        getFlowData();
-                       cout << "Identifying unique flowgrams..." << endl;
+                       
+                       m->mothurOut("Identifying unique flowgrams...\n");
                        getUniques();
                        
                        
-                       cout << "Calculating distances between flowgrams..." << endl;                   
+                       m->mothurOut("Calculating distances between flowgrams...\n");
                        string distFileName = createDistFile(processors);
                        string namesFileName = createNamesFile();
-                       
-                       cout << "\nClustering flowgrams..." << endl;
+                               
+                       m->mothurOut("\nClustering flowgrams...\n");
                        string listFileName = cluster(distFileName, namesFileName);
                        getOTUData(listFileName);
                        
@@ -701,8 +702,8 @@ int ShhherCommand::execute(){
                        double begClock = clock();
                        unsigned long int begTime = time(NULL);
 
-                       cout << "\nDenoising flowgrams..." << endl;
-                       cout << "iter\tmaxDelta\tnLL\t\tcycletime" << endl;
+                       m->mothurOut("\nDenoising flowgrams...\n");
+                       m->mothurOut("iter\tmaxDelta\tnLL\t\tcycletime\n");
                        
                        while((maxIters == 0 && maxDelta > minDelta) || iter < MIN_ITER || (maxDelta > minDelta && iter < maxIters)){
                                
@@ -720,10 +721,11 @@ int ShhherCommand::execute(){
 
                                iter++;
                                
-                               cout << iter << '\t' << maxDelta << '\t' << setprecision(2) << nLL << '\t' << time(NULL) - cycTime << '\t' << setprecision(6) << (clock() - cycClock)/(double)CLOCKS_PER_SEC << endl;                   
+                               m->mothurOut(toString(iter) + '\t' + toString(maxDelta) + '\t' + toString(nLL) + '\t' + toString(time(NULL) - cycTime) + '\t' + toString((clock() - cycClock)/(double)CLOCKS_PER_SEC) + '\n');
+
                        }       
                        
-                       cout << "\nFinalizing..." << endl;
+                       m->mothurOut("\nFinalizing...\n");
                        fill();
                        setOTUs();
                        
@@ -741,7 +743,7 @@ int ShhherCommand::execute(){
                        remove(namesFileName.c_str());
                        remove(listFileName.c_str());
                        
-                       cout << "Total time to process " << flowFileName << ":\t" << time(NULL) - begTime << '\t' << setprecision(6) << (clock() - begClock)/(double)CLOCKS_PER_SEC << endl;                    
+                       m->mothurOut("Total time to process " + flowFileName + ":\t" + toString(time(NULL) - begTime) + '\t' + toString((clock() - begClock)/(double)CLOCKS_PER_SEC) + '\n');
                }
                return 0;
        }
@@ -838,10 +840,10 @@ void ShhherCommand::getJointLookUp(){
                for(int i=0;i<NUMBINS;i++){
                        for(int j=0;j<NUMBINS;j++){             
                                
-                               float minSum = 10000000000;
+                               double minSum = 100000000;
                                
                                for(int k=0;k<HOMOPS;k++){
-                                       float sum = singleLookUp[k * NUMBINS + i] + singleLookUp[k * NUMBINS + j];
+                                       double sum = singleLookUp[k * NUMBINS + i] + singleLookUp[k * NUMBINS + j];
                                        
                                        if(sum < minSum)        {       minSum = sum;           }
                                }       
@@ -857,9 +859,11 @@ void ShhherCommand::getJointLookUp(){
 
 /**************************************************************************************************/
 
-float ShhherCommand::getProbIntensity(int intIntensity){                          
+double ShhherCommand::getProbIntensity(int intIntensity){                          
        try{
-               float minNegLogProb = 10000000000; 
+
+               double minNegLogProb = 100000000; 
+
                
                for(int i=0;i<HOMOPS;i++){//loop signal strength
                        float negLogProb = singleLookUp[i * NUMBINS + intIntensity];
@@ -893,13 +897,19 @@ void ShhherCommand::getUniques(){
                        int index = 0;
                        
                        vector<short> current(numFlowCells);
-                       for(int j=0;j<numFlowCells;j++){        current[j] = short(((flowDataIntI[i * numFlowCells + j] + 50.0)/100.0));        }
+                       for(int j=0;j<numFlowCells;j++){
+                               current[j] = short(((flowDataIntI[i * numFlowCells + j] + 50.0)/100.0));
+                       }
                                                
                        for(int j=0;j<numUniques;j++){
                                int offset = j * numFlowCells;
                                bool toEnd = 1;
                                
-                               for(int k=0;k<numFlowCells;k++){
+                               int shorterLength;
+                               if(lengths[i] < uniqueLengths[j])       {       shorterLength = lengths[i];                     }
+                               else                                                            {       shorterLength = uniqueLengths[j];       }
+
+                               for(int k=0;k<shorterLength;k++){
                                        if(current[k] != uniqueFlowgrams[offset + k]){
                                                toEnd = 0;
                                                break;
@@ -910,6 +920,7 @@ void ShhherCommand::getUniques(){
                                        mapSeqToUnique[i] = j;
                                        uniqueCount[j]++;
                                        index = j;
+                                       if(lengths[i] > uniqueLengths[j])       {       uniqueLengths[j] = lengths[i];  }
                                        break;
                                }
                                index++;
@@ -990,10 +1001,10 @@ void ShhherCommand::flowDistParentFork(string distFileName, int startSeq, int st
                                float flowDistance = calcPairwiseDist(mapUniqueToSeq[i], mapUniqueToSeq[j]);
 
                                if(flowDistance < 1e-6){
-                                       outStream << seqNameVector[mapUniqueToSeq[i]] << '\t' << seqNameVector[mapUniqueToSeq[j]] << '\t' << 0.000000 << endl;
+                                       outStream << mapUniqueToSeq[i] << '\t' << mapUniqueToSeq[j] << '\t' << 0.000000 << endl;
                                }
                                else if(flowDistance <= cutoff){
-                                       outStream << seqNameVector[mapUniqueToSeq[i]] << '\t' << seqNameVector[mapUniqueToSeq[j]] << '\t' << flowDistance << endl;
+                                       outStream << mapUniqueToSeq[i] << '\t' << mapUniqueToSeq[j] << '\t' << flowDistance << endl;
                                }
                        }
                        if(i % 100 == 0){
@@ -1086,7 +1097,8 @@ string ShhherCommand::createDistFile(int processors){
 
                m->mothurOutEndLine();
                
-               cout << "Total time: " << (time(NULL) - begTime) << "\t"  << (clock() - begClock)/CLOCKS_PER_SEC << endl;;
+               m-mothurOut("Total time: " + toString(time(NULL) - begTime) + '\t' + toString((clock() - begClock)/CLOCKS_PER_SEC) + '\n');
+               
 
                return fDistFileName;
        }
@@ -1131,9 +1143,6 @@ string ShhherCommand::createNamesFile(){
 string ShhherCommand::cluster(string distFileName, string namesFileName){
        try {
                
-               SparseMatrix* matrix;
-               ListVector* list;
-               RAbundVector* rabund;
                
                globaldata->setNameFile(namesFileName);
                globaldata->setColumnFile(distFileName);
@@ -1146,13 +1155,13 @@ string ShhherCommand::cluster(string distFileName, string namesFileName){
                clusterNameMap->readMap();
                read->read(clusterNameMap);
                
-               list = read->getListVector();
-               matrix = read->getMatrix();
+               ListVector* list = read->getListVector();
+               SparseMatrix* matrix = read->getMatrix();
                
                delete read; 
                delete clusterNameMap; 
                                
-               rabund = new RAbundVector(list->getRAbundVector());
+               RAbundVector* rabund = new RAbundVector(list->getRAbundVector());
                
                Cluster* cluster = new CompleteLinkage(rabund, list, matrix, cutoff, "furthest"); 
                string tag = cluster->getTag();
@@ -1988,7 +1997,6 @@ void ShhherCommand::writeQualities(vector<int> otuCounts){
 
 void ShhherCommand::writeSequences(vector<int> otuCounts){
        try {
-               
                string bases = "TACG";
                
                string fastaFileName = flowFileName.substr(0,flowFileName.find_last_of('.')) + ".pn.fasta";
@@ -2014,6 +2022,10 @@ void ShhherCommand::writeSequences(vector<int> otuCounts){
                        }
                }
                fastaFile.close();
+               
+               if(compositeFASTAFileName != ""){
+                       m->appendFiles(fastaFileName, compositeFASTAFileName);
+               }
        }
        catch(exception& e) {
                m->errorOut(e, "ShhherCommand", "writeSequences");