]> git.donarmstrong.com Git - mothur.git/blobdiff - aligncommand.cpp
1.12.0
[mothur.git] / aligncommand.cpp
index c5407ca345a2ff7bdec2ed47089f7e10d1df1fc3..ee27776c11912bd9fe346f300ffc867f5164223f 100644 (file)
@@ -107,9 +107,18 @@ AlignCommand::AlignCommand(string option)  {
                                                if (pid == 0) {
                                        #endif
 
-                                       ableToOpen = openInputFile(candidateFileNames[i], in);
-                                       in.close();
-                                       
+                                       ableToOpen = openInputFile(candidateFileNames[i], in, "noerror");
+                               
+                                       //if you can't open it, try default location
+                                       if (ableToOpen == 1) {
+                                               if (m->getDefaultPath() != "") { //default path is set
+                                                       string tryPath = m->getDefaultPath() + getSimpleName(candidateFileNames[i]);
+                                                       m->mothurOut("Unable to open " + candidateFileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine();
+                                                       ableToOpen = openInputFile(tryPath, in, "noerror");
+                                                       candidateFileNames[i] = tryPath;
+                                               }
+                                       }
+                                       in.close();                                     
                                        #ifdef USE_MPI  
                                                        for (int j = 1; j < processors; j++) {
                                                                MPI_Send(&ableToOpen, 1, MPI_INT, j, 2001, MPI_COMM_WORLD); 
@@ -122,7 +131,7 @@ AlignCommand::AlignCommand(string option)  {
                                        #endif
 
                                        if (ableToOpen == 1) { 
-                                               m->mothurOut(candidateFileNames[i] + " will be disregarded."); m->mothurOutEndLine(); 
+                                               m->mothurOut("Unable to open " + candidateFileNames[i] + ". It will be disregarded."); m->mothurOutEndLine(); 
                                                //erase from file list
                                                candidateFileNames.erase(candidateFileNames.begin()+i);
                                                i--;
@@ -267,26 +276,14 @@ int AlignCommand::execute(){
                                int outMode=MPI_MODE_CREATE|MPI_MODE_WRONLY; 
                                int inMode=MPI_MODE_RDONLY; 
                                
-                               //char* outAlignFilename = new char[alignFileName.length()];
-                               //memcpy(outAlignFilename, alignFileName.c_str(), alignFileName.length());
-                               
                                char outAlignFilename[1024];
                                strcpy(outAlignFilename, alignFileName.c_str());
-
-                               //char* outReportFilename = new char[reportFileName.length()];
-                               //memcpy(outReportFilename, reportFileName.c_str(), reportFileName.length());
                                
                                char outReportFilename[1024];
                                strcpy(outReportFilename, reportFileName.c_str());
-
-                               //char* outAccnosFilename = new char[accnosFileName.length()];
-                               //memcpy(outAccnosFilename, accnosFileName.c_str(), accnosFileName.length());
                                
                                char outAccnosFilename[1024];
                                strcpy(outAccnosFilename, accnosFileName.c_str());
-
-                               //char* inFileName = new char[candidateFileNames[s].length()];
-                               //memcpy(inFileName, candidateFileNames[s].c_str(), candidateFileNames[s].length());
                                
                                char inFileName[1024];
                                strcpy(inFileName, candidateFileNames[s].c_str());
@@ -373,7 +370,7 @@ int AlignCommand::execute(){
                        if(processors == 1){
                                ifstream inFASTA;
                                openInputFile(candidateFileNames[s], inFASTA);
-                               numFastaSeqs=count(istreambuf_iterator<char>(inFASTA),istreambuf_iterator<char>(), '>');
+                               getNumSeqs(inFASTA, numFastaSeqs);
                                inFASTA.close();
                                
                                lines.push_back(new linePair(0, numFastaSeqs));
@@ -398,7 +395,7 @@ int AlignCommand::execute(){
                                }
                        }
                        else{
-                               vector<int> positions;
+                               vector<unsigned long int> positions;
                                processIDS.resize(0);
                                
                                ifstream inFASTA;
@@ -408,7 +405,7 @@ int AlignCommand::execute(){
                                while(!inFASTA.eof()){
                                        input = getline(inFASTA);
                                        if (input.length() != 0) {
-                                               if(input[0] == '>'){    long int pos = inFASTA.tellg(); positions.push_back(pos - input.length() - 1);  }
+                                               if(input[0] == '>'){    unsigned long int pos = inFASTA.tellg(); positions.push_back(pos - input.length() - 1); }
                                        }
                                }
                                inFASTA.close();
@@ -418,7 +415,7 @@ int AlignCommand::execute(){
                                int numSeqsPerProcessor = numFastaSeqs / processors;
                                
                                for (int i = 0; i < processors; i++) {
-                                       long int startPos = positions[ i * numSeqsPerProcessor ];
+                                       unsigned long int startPos = positions[ i * numSeqsPerProcessor ];
                                        if(i == processors - 1){
                                                numSeqsPerProcessor = numFastaSeqs - i * numSeqsPerProcessor;
                                        }
@@ -472,7 +469,7 @@ int AlignCommand::execute(){
        #else
                        ifstream inFASTA;
                        openInputFile(candidateFileNames[s], inFASTA);
-                       numFastaSeqs=count(istreambuf_iterator<char>(inFASTA),istreambuf_iterator<char>(), '>');
+                       getNumSeqs(inFASTA, numFastaSeqs);
                        inFASTA.close();
                        
                        lines.push_back(new linePair(0, numFastaSeqs));