]> git.donarmstrong.com Git - mothur.git/blobdiff - aligncommand.cpp
modified calculators to use doubles, added numotu and fontsize parameters to heatmap...
[mothur.git] / aligncommand.cpp
index 1f93068d6451d701d6587b7b913bcc0e0856fd90..4641ed7f65a65374df52836bb6c9e6b943fa8e61 100644 (file)
@@ -45,7 +45,7 @@ AlignCommand::AlignCommand(string option)  {
                        OptionParser parser(option);
                        map<string, string> parameters = parser.getParameters(); 
                        
-                       ValidParameters validParameter;
+                       ValidParameters validParameter("align.seqs");
                        map<string, string>::iterator it;
                        
                        //check to make sure all parameters are valid for command
@@ -98,31 +98,22 @@ AlignCommand::AlignCommand(string option)  {
        
                                        int ableToOpen;
                                        ifstream in;
-                                       
-                                       #ifdef USE_MPI  
-                                               int pid;
-                                               MPI_Comm_size(MPI_COMM_WORLD, &processors); //set processors to the number of mpi processes running
-                                               MPI_Comm_rank(MPI_COMM_WORLD, &pid); //find out who we are
-                               
-                                               if (pid == 0) {
-                                       #endif
 
-                                       ableToOpen = openInputFile(candidateFileNames[i], in);
-                                       in.close();
-                                       
-                                       #ifdef USE_MPI  
-                                                       for (int j = 1; j < processors; j++) {
-                                                               MPI_Send(&ableToOpen, 1, MPI_INT, j, 2001, MPI_COMM_WORLD); 
-                                                       }
-                                               }else{
-                                                       MPI_Status status;
-                                                       MPI_Recv(&ableToOpen, 1, MPI_INT, 0, 2001, MPI_COMM_WORLD, &status);
+                                       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;
                                                }
-                                               
-                                       #endif
+                                       }
+                                       in.close();                                     
 
                                        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--;
@@ -252,9 +243,9 @@ int AlignCommand::execute(){
 #ifdef USE_MPI 
                                int pid, end, numSeqsPerProcessor; 
                                int tag = 2001;
-                               vector<long> MPIPos;
+                               vector<unsigned long int> MPIPos;
                                MPIWroteAccnos = false;
-                               
+                       
                                MPI_Status status; 
                                MPI_Comm_rank(MPI_COMM_WORLD, &pid); //find out who we are
                                MPI_Comm_size(MPI_COMM_WORLD, &processors); 
@@ -267,26 +258,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());
@@ -398,7 +377,7 @@ int AlignCommand::execute(){
                                }
                        }
                        else{
-                               vector<int> positions;
+                               vector<unsigned long int> positions;
                                processIDS.resize(0);
                                
                                ifstream inFASTA;
@@ -408,7 +387,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 +397,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;
                                        }
@@ -583,7 +562,7 @@ int AlignCommand::driver(linePair* line, string alignFName, string reportFName,
                                //if there is a possibility that this sequence should be reversed
                                if (candidateSeq->getNumBases() < numBasesNeeded) {
                                        
-                                       string wasBetter = "";
+                                       string wasBetter =  "";
                                        //if the user wants you to try the reverse
                                        if (flip) {
                                                //get reverse compliment
@@ -605,8 +584,9 @@ int AlignCommand::driver(linePair* line, string alignFName, string reportFName,
                                                        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.";
+                                                       wasBetter = "\treverse complement did NOT produce a better alignment so it was not used, please check sequence.";
                                                        delete nast2;
                                                        delete copy;    
                                                }
@@ -649,7 +629,7 @@ int AlignCommand::driver(linePair* line, string alignFName, string reportFName,
 }
 //**********************************************************************************************************************
 #ifdef USE_MPI
-int AlignCommand::driverMPI(int start, int num, MPI_File& inMPI, MPI_File& alignFile, MPI_File& reportFile, MPI_File& accnosFile, vector<long>& MPIPos){
+int AlignCommand::driverMPI(int start, int num, MPI_File& inMPI, MPI_File& alignFile, MPI_File& reportFile, MPI_File& accnosFile, vector<unsigned long int>& MPIPos){
        try {
                string outputString = "";
                MPI_Status statusReport; 
@@ -681,7 +661,7 @@ int AlignCommand::driverMPI(int start, int num, MPI_File& inMPI, MPI_File& align
                        int length = MPIPos[start+i+1] - MPIPos[start+i];
 
                        char* buf4 = new char[length];
-                       memcpy(buf4, outputString.c_str(), length);
+                       //memcpy(buf4, outputString.c_str(), length);
 
                        MPI_File_read_at(inMPI, MPIPos[start+i], buf4, length, MPI_CHAR, &status);
                        
@@ -690,9 +670,11 @@ int AlignCommand::driverMPI(int start, int num, MPI_File& inMPI, MPI_File& align
                        delete buf4;
 
                        if (tempBuf.length() > length) { tempBuf = tempBuf.substr(0, length);  }
-                       istringstream iss (tempBuf,istringstream::in);
        
+                       istringstream iss (tempBuf,istringstream::in);
+
                        Sequence* candidateSeq = new Sequence(iss);  
+       
                        int origNumBases = candidateSeq->getNumBases();
                        string originalUnaligned = candidateSeq->getUnaligned();
                        int numBasesNeeded = origNumBases * threshold;