]> git.donarmstrong.com Git - mothur.git/blobdiff - aligncommand.cpp
pat's changes to seq.error command
[mothur.git] / aligncommand.cpp
index 63a117d5064cc8178051017173bacdfd80cb6b3a..39408427d87d439d6cdf8e637dd656df5049becd 100644 (file)
@@ -64,6 +64,7 @@ vector<string> AlignCommand::getRequiredFiles(){
 //**********************************************************************************************************************
 AlignCommand::AlignCommand(){  
        try {
+               abort = true;
                //initialize outputTypes
                vector<string> tempOutNames;
                outputTypes["fasta"] = tempOutNames;
@@ -153,15 +154,17 @@ AlignCommand::AlignCommand(string option)  {
        
                                        int ableToOpen;
                                        ifstream in;
-
                                        ableToOpen = m->openInputFile(candidateFileNames[i], in, "noerror");
-                               
+                                       in.close();     
+                                       
                                        //if you can't open it, try default location
                                        if (ableToOpen == 1) {
                                                if (m->getDefaultPath() != "") { //default path is set
                                                        string tryPath = m->getDefaultPath() + m->getSimpleName(candidateFileNames[i]);
                                                        m->mothurOut("Unable to open " + candidateFileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine();
-                                                       ableToOpen = m->openInputFile(tryPath, in, "noerror");
+                                                       ifstream in2;
+                                                       ableToOpen = m->openInputFile(tryPath, in2, "noerror");
+                                                       in2.close();
                                                        candidateFileNames[i] = tryPath;
                                                }
                                        }
@@ -171,12 +174,14 @@ AlignCommand::AlignCommand(string option)  {
                                                if (m->getOutputDir() != "") { //default path is set
                                                        string tryPath = m->getOutputDir() + m->getSimpleName(candidateFileNames[i]);
                                                        m->mothurOut("Unable to open " + candidateFileNames[i] + ". Trying output directory " + tryPath); m->mothurOutEndLine();
-                                                       ableToOpen = m->openInputFile(tryPath, in, "noerror");
+                                                       ifstream in2;
+                                                       ableToOpen = m->openInputFile(tryPath, in2, "noerror");
+                                                       in2.close();
                                                        candidateFileNames[i] = tryPath;
                                                }
                                        }
                                        
-                                       in.close();                                     
+                                                                       
 
                                        if (ableToOpen == 1) { 
                                                m->mothurOut("Unable to open " + candidateFileNames[i] + ". It will be disregarded."); m->mothurOutEndLine(); 
@@ -550,7 +555,8 @@ int AlignCommand::driver(linePair* filePos, string alignFName, string reportFNam
                        if (m->control_pressed) {  return 0; }
                        
                        Sequence* candidateSeq = new Sequence(inFASTA);  m->gobble(inFASTA);
-                       
+                       report.setCandidate(candidateSeq);
+
                        int origNumBases = candidateSeq->getNumBases();
                        string originalUnaligned = candidateSeq->getUnaligned();
                        int numBasesNeeded = origNumBases * threshold;
@@ -613,7 +619,6 @@ int AlignCommand::driver(linePair* filePos, string alignFName, string reportFNam
                                        accnosFile << candidateSeq->getName() << wasBetter << endl;
                                }
                                
-                               report.setCandidate(candidateSeq);
                                report.setTemplate(templateSeq);
                                report.setSearchParameters(search, searchScore);
                                report.setAlignmentParameters(align, alignment);
@@ -701,7 +706,8 @@ int AlignCommand::driverMPI(int start, int num, MPI_File& inMPI, MPI_File& align
                        istringstream iss (tempBuf,istringstream::in);
 
                        Sequence* candidateSeq = new Sequence(iss);  
-       
+                       report.setCandidate(candidateSeq);
+
                        int origNumBases = candidateSeq->getNumBases();
                        string originalUnaligned = candidateSeq->getUnaligned();
                        int numBasesNeeded = origNumBases * threshold;
@@ -750,6 +756,7 @@ int AlignCommand::driverMPI(int start, int num, MPI_File& inMPI, MPI_File& align
                                                        delete nast;
                                                        nast = nast2;
                                                        needToDeleteCopy = true;
+                                                       wasBetter = "\treverse complement produced a better alignment, so mothur used the reverse complement.";
                                                }else{  
                                                        wasBetter = "\treverse complement did NOT produce a better alignment, please check sequence.";
                                                        delete nast2;
@@ -771,7 +778,6 @@ int AlignCommand::driverMPI(int start, int num, MPI_File& inMPI, MPI_File& align
                                        MPIWroteAccnos = true;
                                }
                                
-                               report.setCandidate(candidateSeq);
                                report.setTemplate(templateSeq);
                                report.setSearchParameters(search, searchScore);
                                report.setAlignmentParameters(align, alignment);
@@ -844,7 +850,11 @@ int AlignCommand::createProcesses(string alignFileName, string reportFileName, s
                                out.close();
                                
                                exit(0);
-                       }else { m->mothurOut("unable to spawn the necessary processes."); m->mothurOutEndLine(); exit(0); }
+                       }else { 
+                               m->mothurOut("[ERROR]: unable to spawn the necessary processes."); m->mothurOutEndLine(); 
+                               for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); }
+                               exit(0);
+                       }
                }
                
                //force parent to wait until all the processes are done