]> git.donarmstrong.com Git - mothur.git/commitdiff
added count.groups command and paralellized align.seqs for windows
authorwestcott <westcott>
Tue, 9 Aug 2011 10:32:41 +0000 (10:32 +0000)
committerwestcott <westcott>
Tue, 9 Aug 2011 10:32:41 +0000 (10:32 +0000)
27 files changed:
Mothur.xcodeproj/project.pbxproj
aligncommand.cpp
aligncommand.h
alignmentdb.cpp
alignmentdb.h
blastdb.hpp
commandfactory.cpp
countgroupscommand.cpp [new file with mode: 0644]
countgroupscommand.h [new file with mode: 0644]
database.hpp
dist.h
distancedb.cpp
distancedb.hpp
eachgapdist.h
eachgapignore.h
ignoregaps.h
kmerdb.hpp
onegapdist.h
onegapignore.h
parsimonycommand.cpp
sequence.hpp
suffixdb.hpp
suffixnodes.hpp
suffixtree.cpp
suffixtree.hpp
treemap.cpp
treemap.h

index 49de82685f9d1a43325306eb1854b7011eee86b7..73a36ad2fd8b9c17cc78c492c8625638102fc297 100644 (file)
@@ -46,6 +46,7 @@
                A778FE6B134CA6CA00C0BA33 /* getcommandinfocommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A778FE6A134CA6CA00C0BA33 /* getcommandinfocommand.cpp */; };
                A77A221F139001B600B0BE70 /* deuniquetreecommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A77A221E139001B600B0BE70 /* deuniquetreecommand.cpp */; };
                A79234D713C74BF6002B08E2 /* mothurfisher.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A79234D613C74BF6002B08E2 /* mothurfisher.cpp */; };
+               A795840D13F13CD900F201D5 /* countgroupscommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A795840C13F13CD900F201D5 /* countgroupscommand.cpp */; };
                A799F5B91309A3E000AEEFA0 /* makefastqcommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A799F5B81309A3E000AEEFA0 /* makefastqcommand.cpp */; };
                A7A61F2D130062E000E05B6B /* amovacommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7A61F2C130062E000E05B6B /* amovacommand.cpp */; };
                A7E9B88112D37EC400DA6239 /* ace.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7E9B64F12D37EC300DA6239 /* ace.cpp */; };
                A77A221E139001B600B0BE70 /* deuniquetreecommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = deuniquetreecommand.cpp; sourceTree = "<group>"; };
                A79234D513C74BF6002B08E2 /* mothurfisher.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = mothurfisher.h; sourceTree = "<group>"; };
                A79234D613C74BF6002B08E2 /* mothurfisher.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = mothurfisher.cpp; sourceTree = "<group>"; };
+               A795840B13F13CD900F201D5 /* countgroupscommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = countgroupscommand.h; sourceTree = "<group>"; };
+               A795840C13F13CD900F201D5 /* countgroupscommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = countgroupscommand.cpp; sourceTree = "<group>"; };
                A799F5B71309A3E000AEEFA0 /* makefastqcommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = makefastqcommand.h; sourceTree = "<group>"; };
                A799F5B81309A3E000AEEFA0 /* makefastqcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = makefastqcommand.cpp; sourceTree = "<group>"; };
                A7A61F1A130035C800E05B6B /* LICENSE */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = LICENSE; sourceTree = "<group>"; };
                A7E9B84E12D37EC400DA6239 /* structpearson.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = structpearson.h; sourceTree = "<group>"; };
                A7E9B84F12D37EC400DA6239 /* subsamplecommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = subsamplecommand.cpp; sourceTree = "<group>"; };
                A7E9B85012D37EC400DA6239 /* subsamplecommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = subsamplecommand.h; sourceTree = "<group>"; };
-               A7E9B85112D37EC400DA6239 /* suffixdb.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = suffixdb.cpp; sourceTree = SOURCE_ROOT; };
-               A7E9B85212D37EC400DA6239 /* suffixdb.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = suffixdb.hpp; sourceTree = SOURCE_ROOT; };
-               A7E9B85312D37EC400DA6239 /* suffixnodes.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = suffixnodes.cpp; sourceTree = SOURCE_ROOT; };
-               A7E9B85412D37EC400DA6239 /* suffixnodes.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = suffixnodes.hpp; sourceTree = SOURCE_ROOT; };
-               A7E9B85512D37EC400DA6239 /* suffixtree.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = suffixtree.cpp; sourceTree = SOURCE_ROOT; };
-               A7E9B85612D37EC400DA6239 /* suffixtree.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = suffixtree.hpp; sourceTree = SOURCE_ROOT; };
+               A7E9B85112D37EC400DA6239 /* suffixdb.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = suffixdb.cpp; sourceTree = "<group>"; };
+               A7E9B85212D37EC400DA6239 /* suffixdb.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = suffixdb.hpp; sourceTree = "<group>"; };
+               A7E9B85312D37EC400DA6239 /* suffixnodes.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = suffixnodes.cpp; sourceTree = "<group>"; };
+               A7E9B85412D37EC400DA6239 /* suffixnodes.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = suffixnodes.hpp; sourceTree = "<group>"; };
+               A7E9B85512D37EC400DA6239 /* suffixtree.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = suffixtree.cpp; sourceTree = "<group>"; };
+               A7E9B85612D37EC400DA6239 /* suffixtree.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = suffixtree.hpp; sourceTree = "<group>"; };
                A7E9B85712D37EC400DA6239 /* summarycommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = summarycommand.cpp; sourceTree = "<group>"; };
                A7E9B85812D37EC400DA6239 /* summarycommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = summarycommand.h; sourceTree = "<group>"; };
                A7E9B85912D37EC400DA6239 /* summarysharedcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = summarysharedcommand.cpp; sourceTree = "<group>"; };
                                A7E9B82412D37EC400DA6239 /* sharedutilities.h */,
                                A7E9B82D12D37EC400DA6239 /* singlelinkage.cpp */,
                                A7E9B83012D37EC400DA6239 /* slibshuff.cpp */,
-                               A7E9B85112D37EC400DA6239 /* suffixdb.cpp */,
                                A7E9B83112D37EC400DA6239 /* slibshuff.h */,
-                               A7E9B85212D37EC400DA6239 /* suffixdb.hpp */,
-                               A7E9B85312D37EC400DA6239 /* suffixnodes.cpp */,
-                               A7E9B85412D37EC400DA6239 /* suffixnodes.hpp */,
-                               A7E9B85512D37EC400DA6239 /* suffixtree.cpp */,
-                               A7E9B85612D37EC400DA6239 /* suffixtree.hpp */,
                                A7E9B87412D37EC400DA6239 /* validcalculator.cpp */,
                                A7E9B87512D37EC400DA6239 /* validcalculator.h */,
                                A7E9B87612D37EC400DA6239 /* validparameter.cpp */,
                                A7E9B6B712D37EC400DA6239 /* consensusseqscommand.cpp */,
                                A7E9B6BA12D37EC400DA6239 /* corraxescommand.h */,
                                A7E9B6B912D37EC400DA6239 /* corraxescommand.cpp */,
+                               A795840B13F13CD900F201D5 /* countgroupscommand.h */,
+                               A795840C13F13CD900F201D5 /* countgroupscommand.cpp */,
                                A7730EFD13967241007433A3 /* countseqscommand.h */,
                                A7730EFE13967241007433A3 /* countseqscommand.cpp */,
                                A7E9B6C412D37EC400DA6239 /* deconvolutecommand.h */,
                                A7E9B81412D37EC400DA6239 /* sharedsabundvector.h */,
                                A7E9B83912D37EC400DA6239 /* sparsematrix.cpp */,
                                A7E9B83A12D37EC400DA6239 /* sparsematrix.hpp */,
+                               A7E9B85112D37EC400DA6239 /* suffixdb.cpp */,
+                               A7E9B85212D37EC400DA6239 /* suffixdb.hpp */,
+                               A7E9B85312D37EC400DA6239 /* suffixnodes.cpp */,
+                               A7E9B85412D37EC400DA6239 /* suffixnodes.hpp */,
+                               A7E9B85512D37EC400DA6239 /* suffixtree.cpp */,
+                               A7E9B85612D37EC400DA6239 /* suffixtree.hpp */,
                                A7E9B85F12D37EC400DA6239 /* tree.cpp */,
                                A7E9B86012D37EC400DA6239 /* tree.h */,
                                A7E9B86412D37EC400DA6239 /* treemap.cpp */,
                                A73DDBBA13C4A0D1006AAE38 /* clearmemorycommand.cpp in Sources */,
                                A73DDC3813C4BF64006AAE38 /* mothurmetastats.cpp in Sources */,
                                A79234D713C74BF6002B08E2 /* mothurfisher.cpp in Sources */,
+                               A795840D13F13CD900F201D5 /* countgroupscommand.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index a32ec4df279b2fa1158ec5e818ce03545de4ed0c..b7c684311a5e186576d6f70c91dade75c76b31f4 100644 (file)
  */
 
 #include "aligncommand.h"
-#include "sequence.hpp"
-
-#include "gotohoverlap.hpp"
-#include "needlemanoverlap.hpp"
-#include "blastalign.hpp"
-#include "noalign.hpp"
-
-#include "nast.hpp"
-#include "nastreport.hpp"
 #include "referencedb.h"
 
 //**********************************************************************************************************************
@@ -256,6 +247,11 @@ AlignCommand::AlignCommand(string option)  {
                        
                        temp = validParameter.validFile(parameters, "save", false);                     if (temp == "not found"){       temp = "f";                             }
                        save = m->isTrue(temp); 
+                       //this is so the threads can quickly load the reference data
+                       #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
+                       #else
+                               if (processors != 1) { save = true; }
+                       #endif
                        rdb->save = save; 
                        if (save) { //clear out old references
                                rdb->clearMemory();
@@ -298,7 +294,6 @@ AlignCommand::~AlignCommand(){
        if (abort == false) {
                for (int i = 0; i < lines.size(); i++) {  delete lines[i];  }  lines.clear();
                delete templateDB;
-               delete alignment;
        }
 }
 //**********************************************************************************************************************
@@ -308,17 +303,6 @@ int AlignCommand::execute(){
                if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
 
                templateDB = new AlignmentDB(templateFileName, search, kmerSize, gapOpen, gapExtend, match, misMatch);
-               int longestBase = templateDB->getLongestBase();
-               
-               if(align == "gotoh")                    {       alignment = new GotohOverlap(gapOpen, gapExtend, match, misMatch, longestBase);                 }
-               else if(align == "needleman")   {       alignment = new NeedlemanOverlap(gapOpen, match, misMatch, longestBase);                                }
-               else if(align == "blast")               {       alignment = new BlastAlignment(gapOpen, gapExtend, match, misMatch);            }
-               else if(align == "noalign")             {       alignment = new NoAlign();                                                                                                      }
-               else {
-                       m->mothurOut(align + " is not a valid alignment option. I will run the command using needleman.");
-                       m->mothurOutEndLine();
-                       alignment = new NeedlemanOverlap(gapOpen, match, misMatch, longestBase);
-               }
                
                for (int s = 0; s < candidateFileNames.size(); s++) {
                        if (m->control_pressed) { outputTypes.clear(); return 0; }
@@ -442,20 +426,28 @@ int AlignCommand::execute(){
                                
 #else
 
-               vector<unsigned long int> positions = m->divideFile(candidateFileNames[s], processors);
-               for (int i = 0; i < (positions.size()-1); i++) {
-                       lines.push_back(new linePair(positions[i], positions[(i+1)]));
-               }       
-       #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
+                       vector<unsigned long int> positions; 
+               #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
+                       positions = m->divideFile(candidateFileNames[s], processors);
+                       for (int i = 0; i < (positions.size()-1); i++) {        lines.push_back(new linePair(positions[i], positions[(i+1)]));  }
+               #else
+                       positions = m->setFilePosFasta(candidateFileNames[s], numFastaSeqs); 
+                       
+                       //figure out how many sequences you have to process
+                       int numSeqsPerProcessor = numFastaSeqs / processors;
+                       for (int i = 0; i < processors; i++) {
+                               int startIndex =  i * numSeqsPerProcessor;
+                               if(i == (processors - 1)){      numSeqsPerProcessor = numFastaSeqs - i * numSeqsPerProcessor;   }
+                               lines.push_back(new linePair(positions[startIndex], numSeqsPerProcessor));
+                       }
+               #endif
+                       
                        if(processors == 1){
                                numFastaSeqs = driver(lines[0], alignFileName, reportFileName, accnosFileName, candidateFileNames[s]);
                        }else{
                                numFastaSeqs = createProcesses(alignFileName, reportFileName, accnosFileName, candidateFileNames[s]); 
                        }
-       #else
-                       numFastaSeqs = driver(lines[0], alignFileName, reportFileName, accnosFileName, candidateFileNames[s]);
-       #endif
-                       
+                               
                        if (m->control_pressed) { m->mothurRemove(accnosFileName); m->mothurRemove(alignFileName); m->mothurRemove(reportFileName); outputTypes.clear();  return 0; }
                        
                        //delete accnos file if its blank else report to user
@@ -511,7 +503,6 @@ int AlignCommand::execute(){
 }
 
 //**********************************************************************************************************************
-
 int AlignCommand::driver(linePair* filePos, string alignFName, string reportFName, string accnosFName, string filename){
        try {
                ofstream alignmentFile;
@@ -529,10 +520,23 @@ int AlignCommand::driver(linePair* filePos, string alignFName, string reportFNam
 
                bool done = false;
                int count = 0;
+               
+               //moved this into driver to avoid deep copies in windows paralellized version
+               Alignment* alignment;
+               int longestBase = templateDB->getLongestBase();
+               if(align == "gotoh")                    {       alignment = new GotohOverlap(gapOpen, gapExtend, match, misMatch, longestBase);                 }
+               else if(align == "needleman")   {       alignment = new NeedlemanOverlap(gapOpen, match, misMatch, longestBase);                                }
+               else if(align == "blast")               {       alignment = new BlastAlignment(gapOpen, gapExtend, match, misMatch);            }
+               else if(align == "noalign")             {       alignment = new NoAlign();                                                                                                      }
+               else {
+                       m->mothurOut(align + " is not a valid alignment option. I will run the command using needleman.");
+                       m->mothurOutEndLine();
+                       alignment = new NeedlemanOverlap(gapOpen, match, misMatch, longestBase);
+               }
        
                while (!done) {
                        
-                       if (m->control_pressed) {  return 0; }
+                       if (m->control_pressed) {  break; }
                        
                        Sequence* candidateSeq = new Sequence(inFASTA);  m->gobble(inFASTA);
                        report.setCandidate(candidateSeq);
@@ -548,7 +552,7 @@ int AlignCommand::driver(linePair* filePos, string alignFName, string reportFNam
                                                                
                                Sequence temp = templateDB->findClosestSequence(candidateSeq);
                                Sequence* templateSeq = &temp;
-                       
+                               
                                float searchScore = templateDB->getSearchScore();
                                                                
                                Nast* nast = new Nast(alignment, candidateSeq, templateSeq);
@@ -628,6 +632,7 @@ int AlignCommand::driver(linePair* filePos, string alignFName, string reportFNam
                //report progress
                if((count) % 100 != 0){ m->mothurOut(toString(count)); m->mothurOutEndLine();           }
                
+               delete alignment;
                alignmentFile.close();
                inFASTA.close();
                accnosFile.close();
@@ -665,9 +670,22 @@ int AlignCommand::driverMPI(int start, int num, MPI_File& inMPI, MPI_File& align
             delete buf;
                }
                
+               Alignment* alignment;
+               int longestBase = templateDB->getLongestBase();
+               if(align == "gotoh")                    {       alignment = new GotohOverlap(gapOpen, gapExtend, match, misMatch, longestBase);                 }
+               else if(align == "needleman")   {       alignment = new NeedlemanOverlap(gapOpen, match, misMatch, longestBase);                                }
+               else if(align == "blast")               {       alignment = new BlastAlignment(gapOpen, gapExtend, match, misMatch);            }
+               else if(align == "noalign")             {       alignment = new NoAlign();                                                                                                      }
+               else {
+                       m->mothurOut(align + " is not a valid alignment option. I will run the command using needleman.");
+                       m->mothurOutEndLine();
+                       alignment = new NeedlemanOverlap(gapOpen, match, misMatch, longestBase);
+               }
+               
+               
                for(int i=0;i<num;i++){
                
-                       if (m->control_pressed) {  return 0; }
+                       if (m->control_pressed) { delete alignment; return 0; }
 
                        //read next sequence
                        int length = MPIPos[start+i+1] - MPIPos[start+i];
@@ -807,11 +825,10 @@ int AlignCommand::driverMPI(int start, int num, MPI_File& inMPI, MPI_File& align
 
 int AlignCommand::createProcesses(string alignFileName, string reportFileName, string accnosFName, string filename) {
        try {
-#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
+               int num = 0;
                processIDS.resize(0);
+#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
                int process = 1;
-               int num = 0;
-               //              processIDS.resize(0);
                
                //loop through and create all the processes you want
                while (process != processors) {
@@ -883,9 +900,90 @@ int AlignCommand::createProcesses(string alignFileName, string reportFileName, s
                        m->openOutputFile(accnosFName, out);
                        out.close();
                }
+#else
+               //////////////////////////////////////////////////////////////////////////////////////////////////////
+               //Windows version shared memory, so be careful when passing variables through the alignData struct. 
+               //Above fork() will clone, so memory is separate, but that's not the case with windows, 
+               //////////////////////////////////////////////////////////////////////////////////////////////////////
+               
+               vector<alignData*> pDataArray; 
+               DWORD   dwThreadIdArray[processors-1];
+               HANDLE  hThreadArray[processors-1]; 
+               
+               //Create processor worker threads.
+               for( int i=0; i<processors-1; i++ ){
+                       //copy templateDb
+                       //AlignmentDB* tempDB = new AlignmentDB(*templateDB);
+                       
+                       // Allocate memory for thread data.
+                       string extension = "";
+                       if (i != 0) { extension = toString(i) + ".temp"; }
+                       
+                       alignData* tempalign = new alignData((alignFileName + extension), (reportFileName + extension), (accnosFName + extension), filename, align, search, kmerSize, m, lines[i]->start, lines[i]->end, flip, match, misMatch, gapOpen, gapExtend, threshold);
+                       pDataArray.push_back(tempalign);
+                       processIDS.push_back(i);
+                               
+                       //MySeqSumThreadFunction is in header. It must be global or static to work with the threads.
+                       //default security attributes, thread function name, argument to thread function, use default creation flags, returns the thread identifier
+                       hThreadArray[i] = CreateThread(NULL, 0, MyAlignThreadFunction, pDataArray[i], 0, &dwThreadIdArray[i]);   
+               }
+               
+               //need to check for line ending error
+               ifstream inFASTA;
+               m->openInputFile(filename, inFASTA);
+               inFASTA.seekg(lines[processors-1]->start-1);
+               char c = inFASTA.peek();
+               
+               if (c == '>') { //we need to move back
+                       lines[processors-1]->start--; 
+               }
+               
+               //using the main process as a worker saves time and memory
+               //do my part - do last piece because windows is looking for eof
+               num = driver(lines[processors-1], (alignFileName + toString(processors-1) + ".temp"), (reportFileName + toString(processors-1) + ".temp"), (accnosFName + toString(processors-1) + ".temp"), filename);
+               
+               //Wait until all threads have terminated.
+               WaitForMultipleObjects(processors-1, hThreadArray, TRUE, INFINITE);
+               
+               //Close all thread handles and free memory allocations.
+               for(int i=0; i < pDataArray.size(); i++){
+                       num += pDataArray[i]->count;
+                       CloseHandle(hThreadArray[i]);
+                       delete pDataArray[i];
+               }
+               
+               vector<string> nonBlankAccnosFiles;
+               if (!(m->isBlank(accnosFName))) { nonBlankAccnosFiles.push_back(accnosFName); }
+               else { m->mothurRemove(accnosFName); } //remove so other files can be renamed to it
+               
+               for (int i = 1; i < processors; i++) {
+                       appendAlignFiles((alignFileName + toString(i) + ".temp"), alignFileName);
+                       m->mothurRemove((alignFileName + toString(i) + ".temp"));
+                       
+                       appendReportFiles((reportFileName + toString(i) + ".temp"), reportFileName);
+                       m->mothurRemove((reportFileName + toString(i) + ".temp"));
+                       
+                       if (!(m->isBlank(accnosFName + toString(i) + ".temp"))) {
+                               nonBlankAccnosFiles.push_back(accnosFName + toString(i) + ".temp");
+                       }else { m->mothurRemove((accnosFName + toString(i) + ".temp"));  }
+               }
+               
+               //append accnos files
+               if (nonBlankAccnosFiles.size() != 0) { 
+                       rename(nonBlankAccnosFiles[0].c_str(), accnosFName.c_str());
+                       
+                       for (int h=1; h < nonBlankAccnosFiles.size(); h++) {
+                               appendAlignFiles(nonBlankAccnosFiles[h], accnosFName);
+                               m->mothurRemove(nonBlankAccnosFiles[h]);
+                       }
+               }else { //recreate the accnosfile if needed
+                       ofstream out;
+                       m->openOutputFile(accnosFName, out);
+                       out.close();
+               }       
+#endif 
                
                return num;
-#endif         
        }
        catch(exception& e) {
                m->errorOut(e, "AlignCommand", "createProcesses");
index 75b9c2ba8ffa727b84dadbc4ebdd25479e11674c..193eeacae57c5bb62deb844bac610b40437d14a2 100644 (file)
 #include "database.hpp"
 #include "alignment.hpp"
 #include "alignmentdb.h"
+#include "sequence.hpp"
+
+#include "gotohoverlap.hpp"
+#include "needlemanoverlap.hpp"
+#include "blastalign.hpp"
+#include "noalign.hpp"
+
+#include "nast.hpp"
+#include "nastreport.hpp"
+
 
 class AlignCommand : public Command {
        
@@ -44,7 +54,6 @@ private:
        bool MPIWroteAccnos;
        
        AlignmentDB* templateDB;
-       Alignment* alignment;
        
        int driver(linePair*, string, string, string, string);
        int createProcesses(string, string, string, string);
@@ -65,4 +74,196 @@ private:
 
 };
 
+/**************************************************************************************************/
+//custom data structure for threads to use.
+// This is passed by void pointer so it can be any data type
+// that can be passed using a single void pointer (LPVOID).
+typedef struct alignData {
+       string alignFName; 
+       string reportFName; 
+       string accnosFName;
+       string filename;
+       string align;
+       string search;
+       bool flip;
+       unsigned long int start;
+       unsigned long int end;
+       MothurOut* m;
+       //AlignmentDB* templateDB;
+       float match, misMatch, gapOpen, gapExtend, threshold;
+       int count, kmerSize;
+       
+       alignData(){}
+       alignData(string a, string r, string ac, string f, string al, string se, int ks, MothurOut* mout, unsigned long int st, unsigned long int en, bool fl, float ma, float misMa, float gapO, float gapE, float thr) {
+               alignFName = a;
+               reportFName = r;
+               accnosFName = ac;
+               filename = f;
+               flip = fl;
+               m = mout;
+               start = st;
+               end = en;
+               //templateDB = tdb;
+               match = ma; 
+               misMatch = misMa;
+               gapOpen = gapO; 
+               gapExtend = gapE; 
+               threshold = thr;
+               align = al;
+               search = se;
+               count = 0;
+               kmerSize = ks;
+       }
+};
+
+/**************************************************************************************************/
+#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
+#else
+static DWORD WINAPI MyAlignThreadFunction(LPVOID lpParam){ 
+       alignData* pDataArray;
+       pDataArray = (alignData*)lpParam;
+       
+       try {
+               ofstream alignmentFile;
+               pDataArray->m->openOutputFile(pDataArray->alignFName, alignmentFile);
+               
+               ofstream accnosFile;
+               pDataArray->m->openOutputFile(pDataArray->accnosFName, accnosFile);
+               
+               NastReport report(pDataArray->reportFName);
+               
+               ifstream inFASTA;
+               pDataArray->m->openInputFile(pDataArray->filename, inFASTA);
+               
+               //print header if you are process 0
+               if ((pDataArray->start == 0) || (pDataArray->start == 1)) {
+                       inFASTA.seekg(0);
+               }else { //this accounts for the difference in line endings. 
+                       inFASTA.seekg(pDataArray->start-1); pDataArray->m->gobble(inFASTA); 
+               }
+               
+               pDataArray->count = pDataArray->end;
+               
+               AlignmentDB* templateDB = new AlignmentDB("saved-silent", pDataArray->search, pDataArray->kmerSize, pDataArray->gapOpen, pDataArray->gapExtend, pDataArray->match, pDataArray->misMatch);
+               
+               //moved this into driver to avoid deep copies in windows paralellized version
+               Alignment* alignment;
+               int longestBase = templateDB->getLongestBase();
+               if(pDataArray->align == "gotoh")                        {       alignment = new GotohOverlap(pDataArray->gapOpen, pDataArray->gapExtend, pDataArray->match, pDataArray->misMatch, longestBase);                 }
+               else if(pDataArray->align == "needleman")       {       alignment = new NeedlemanOverlap(pDataArray->gapOpen, pDataArray->match, pDataArray->misMatch, longestBase);                            }
+               else if(pDataArray->align == "blast")           {       alignment = new BlastAlignment(pDataArray->gapOpen, pDataArray->gapExtend, pDataArray->match, pDataArray->misMatch);            }
+               else if(pDataArray->align == "noalign")         {       alignment = new NoAlign();                                                                                                      }
+               else {
+                       pDataArray->m->mothurOut(pDataArray->align + " is not a valid alignment option. I will run the command using needleman.");
+                       pDataArray->m->mothurOutEndLine();
+                       alignment = new NeedlemanOverlap(pDataArray->gapOpen, pDataArray->match, pDataArray->misMatch, longestBase);
+               }
+               
+               int count = 0;
+               for(int i = 0; i < pDataArray->end; i++){ //end is the number of sequences to process
+                       
+                       if (pDataArray->m->control_pressed) {  break; }
+                       
+                       Sequence* candidateSeq = new Sequence(inFASTA);  pDataArray->m->gobble(inFASTA);
+                       report.setCandidate(candidateSeq);
+                       
+                       int origNumBases = candidateSeq->getNumBases();
+                       string originalUnaligned = candidateSeq->getUnaligned();
+                       int numBasesNeeded = origNumBases * pDataArray->threshold;
+                       
+                       if (candidateSeq->getName() != "") { //incase there is a commented sequence at the end of a file
+                               if (candidateSeq->getUnaligned().length() > alignment->getnRows()) {
+                                       alignment->resize(candidateSeq->getUnaligned().length()+1);
+                               }
+                               
+                               Sequence temp = templateDB->findClosestSequence(candidateSeq);
+                               Sequence* templateSeq = &temp;
+                               
+                               float searchScore = templateDB->getSearchScore();
+                               
+                               Nast* nast = new Nast(alignment, candidateSeq, templateSeq);
+                               
+                               Sequence* copy;
+                               
+                               Nast* nast2;
+                               bool needToDeleteCopy = false;  //this is needed in case you have you enter the ifs below
+                               //since nast does not make a copy of hte sequence passed, and it is used by the reporter below
+                               //you can't delete the copy sequence til after you report, but you may choose not to create it in the first place
+                               //so this bool tells you if you need to delete it
+                               
+                               //if there is a possibility that this sequence should be reversed
+                               if (candidateSeq->getNumBases() < numBasesNeeded) {
+                                       
+                                       string wasBetter =  "";
+                                       //if the user wants you to try the reverse
+                                       if (pDataArray->flip) {
+                                               
+                                               //get reverse compliment
+                                               copy = new Sequence(candidateSeq->getName(), originalUnaligned);
+                                               copy->reverseComplement();
+                                               
+                                               //rerun alignment
+                                               Sequence temp2 = templateDB->findClosestSequence(copy);
+                                               Sequence* templateSeq2 = &temp2;
+                                               
+                                               searchScore = templateDB->getSearchScore();
+                                               
+                                               nast2 = new Nast(alignment, copy, templateSeq2);
+                                               
+                                               //check if any better
+                                               if (copy->getNumBases() > candidateSeq->getNumBases()) {
+                                                       candidateSeq->setAligned(copy->getAligned());  //use reverse compliments alignment since its better
+                                                       templateSeq = templateSeq2; 
+                                                       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 so it was not used, please check sequence.";
+                                                       delete nast2;
+                                                       delete copy;    
+                                               }
+                                       }
+                                       
+                                       //create accnos file with names
+                                       accnosFile << candidateSeq->getName() << wasBetter << endl;
+                               }
+                               
+                               report.setTemplate(templateSeq);
+                               report.setSearchParameters(pDataArray->search, searchScore);
+                               report.setAlignmentParameters(pDataArray->align, alignment);
+                               report.setNastParameters(*nast);
+                               
+                               alignmentFile << '>' << candidateSeq->getName() << '\n' << candidateSeq->getAligned() << endl;
+                               
+                               report.print();
+                               delete nast;
+                               if (needToDeleteCopy) {   delete copy;   }
+                               
+                               count++;
+                       }
+                       delete candidateSeq;
+                       
+                       //report progress
+                       if((count) % 100 == 0){ pDataArray->m->mothurOut(toString(count)); pDataArray->m->mothurOutEndLine();           }
+                       
+               }
+               //report progress
+               if((count) % 100 != 0){ pDataArray->m->mothurOut(toString(count)); pDataArray->m->mothurOutEndLine();           }
+               
+               delete alignment;
+               delete templateDB;
+               alignmentFile.close();
+               inFASTA.close();
+               accnosFile.close();
+       }
+       catch(exception& e) {
+               pDataArray->m->errorOut(e, "AlignCommand", "MyAlignThreadFunction");
+               exit(1);
+       }
+} 
+#endif
+
+
+
 #endif
index bac61c451854b96e256bae11545448fa38589ebd..6ccfd39edf3562d6795db6c9de131287b86241e0 100644 (file)
 #include "blastdb.hpp"
 #include "referencedb.h"
 
-
+/**************************************************************************************************/
+//deep copy
+AlignmentDB::AlignmentDB(const AlignmentDB& adb) : numSeqs(adb.numSeqs), longest(adb.longest), method(adb.method), emptySequence(adb.emptySequence) {
+       try {
+               
+               m = MothurOut::getInstance();
+               if (adb.method == "blast") {
+                       search = new BlastDB(*((BlastDB*)adb.search));
+               }else if(adb.method == "kmer") {
+                       search = new KmerDB(*((KmerDB*)adb.search));
+               }else if(adb.method == "suffix") {
+                       search = new SuffixDB(*((SuffixDB*)adb.search));
+               }else {
+                       m->mothurOut("[ERROR]: cannot create copy of alignment database, unrecognized method - " + adb.method); m->mothurOutEndLine();
+               }
+               
+               for (int i = 0; i < adb.templateSequences.size(); i++) {
+                       Sequence temp(adb.templateSequences[i]);
+                       templateSequences.push_back(temp);
+               }
+       }
+       catch(exception& e) {
+               m->errorOut(e, "AlignmentDB", "AlignmentDB");
+               exit(1);
+       }
+       
+}
 /**************************************************************************************************/
 AlignmentDB::AlignmentDB(string fastaFileName, string s, int kmerSize, float gapOpen, float gapExtend, float match, float misMatch){           //      This assumes that the template database is in fasta format, may 
        try {                                                                                   //      need to alter this in the future?
@@ -22,10 +48,16 @@ AlignmentDB::AlignmentDB(string fastaFileName, string s, int kmerSize, float gap
                method = s;
                bool needToGenerate = true;
                ReferenceDB* rdb = ReferenceDB::getInstance();
+               bool silent = false;
+               
+               if (fastaFileName == "saved-silent") {
+                       fastaFileName = "saved"; silent = true;
+               }
                
                if (fastaFileName == "saved") {
                        int start = time(NULL);
-                       m->mothurOutEndLine();  m->mothurOut("Using sequences from " + rdb->getSavedReference() + " that are saved in memory.");        m->mothurOutEndLine();
+                       
+                       if (!silent) { m->mothurOutEndLine();  m->mothurOut("Using sequences from " + rdb->getSavedReference() + " that are saved in memory."); m->mothurOutEndLine(); }
 
                        for (int i = 0; i < rdb->referenceSeqs.size(); i++) {
                                templateSequences.push_back(rdb->referenceSeqs[i]);
@@ -35,7 +67,7 @@ AlignmentDB::AlignmentDB(string fastaFileName, string s, int kmerSize, float gap
                        fastaFileName = rdb->getSavedReference();
                        
                        numSeqs = templateSequences.size();
-                       m->mothurOut("It took " + toString(time(NULL) - start) + " to load " + toString(rdb->referenceSeqs.size()) + " sequences.");m->mothurOutEndLine();  
+                       if (!silent) { m->mothurOut("It took " + toString(time(NULL) - start) + " to load " + toString(rdb->referenceSeqs.size()) + " sequences.");m->mothurOutEndLine();  }
 
                }else {
                        int start = time(NULL);
@@ -159,6 +191,7 @@ AlignmentDB::AlignmentDB(string fastaFileName, string s, int kmerSize, float gap
                else if(method == "suffix")             {       search = new SuffixDB(numSeqs);                                                         }
                else if(method == "blast")              {       search = new BlastDB(fastaFileName.substr(0,fastaFileName.find_last_of(".")+1), gapOpen, gapExtend, match, misMatch, "");       }
                else {
+                       method = "kmer";
                        m->mothurOut(method + " is not a valid search option. I will run the command using kmer, ksize=8.");
                        m->mothurOutEndLine();
                        search = new KmerDB(fastaFileName, 8);
index 22d2dd35c044a652fabafbc5deb1bef3f2022391..27d0434e7cbc453c6cf98dba633d65d8a9bf7790 100644 (file)
@@ -22,6 +22,7 @@ public:
 
        AlignmentDB(string, string, int, float, float, float, float);  //reads fastafile passed in and stores sequences
        AlignmentDB(string);
+       AlignmentDB(const AlignmentDB& adb);
        ~AlignmentDB();
        
        Sequence findClosestSequence(Sequence*);
index 99a99879f427efd0ea068f125bbf8b1cd003e95e..0c3ac4b4ef1d7c49e98d3b79d5b2e40f1a1fe9bb 100644 (file)
@@ -18,6 +18,8 @@ class BlastDB : public Database {
 public:
        BlastDB(string, float, float, float, float, string);
        BlastDB(string);
+       BlastDB(const BlastDB& bdb) : dbFileName(bdb.dbFileName), queryFileName(bdb.queryFileName), blastFileName(bdb.blastFileName), path(bdb.path),
+                                                                       count(bdb.count), gapOpen(bdb.gapOpen), gapExtend(bdb.gapExtend), match(bdb.match), misMatch(bdb.misMatch), Database(bdb) {}
        ~BlastDB();
        
        void generateDB();
index 5aaa7b7b120ffdd5b0258b16643ce4bad89be93e..dcd811fd6669e2d1ca8d6902d2c942d758ba23b4 100644 (file)
 #include "getcommandinfocommand.h"
 #include "deuniquetreecommand.h"
 #include "countseqscommand.h"
+#include "countgroupscommand.h"
 #include "clearmemorycommand.h"
 
 /*******************************************************/
@@ -244,6 +245,7 @@ CommandFactory::CommandFactory(){
        commands["get.commandinfo"]             = "get.commandinfo";
        commands["deunique.tree"]               = "deunique.tree";
        commands["count.seqs"]                  = "count.seqs";
+       commands["count.groups"]                = "count.groups";
        commands["clear.memory"]                = "clear.memory";
        commands["pairwise.seqs"]               = "MPIEnabled";
        commands["pipeline.pds"]                = "MPIEnabled";
@@ -417,6 +419,7 @@ Command* CommandFactory::getCommand(string commandName, string optionString){
                else if(commandName == "get.commandinfo")               {       command = new GetCommandInfoCommand(optionString);                      }
                else if(commandName == "deunique.tree")                 {       command = new DeuniqueTreeCommand(optionString);                        }
                else if(commandName == "count.seqs")                    {       command = new CountSeqsCommand(optionString);                           }
+               else if(commandName == "count.groups")                  {       command = new CountGroupsCommand(optionString);                         }
                else if(commandName == "clear.memory")                  {       command = new ClearMemoryCommand(optionString);                         }
                else                                                                                    {       command = new NoCommand(optionString);                                          }
 
@@ -556,6 +559,7 @@ Command* CommandFactory::getCommand(string commandName, string optionString, str
                else if(commandName == "get.commandinfo")               {       pipecommand = new GetCommandInfoCommand(optionString);                  }
                else if(commandName == "deunique.tree")                 {       pipecommand = new DeuniqueTreeCommand(optionString);                    }
                else if(commandName == "count.seqs")                    {       pipecommand = new CountSeqsCommand(optionString);                               }
+               else if(commandName == "count.groups")                  {       pipecommand = new CountGroupsCommand(optionString);                             }
                else if(commandName == "clear.memory")                  {       pipecommand = new ClearMemoryCommand(optionString);                             }
                else                                                                                    {       pipecommand = new NoCommand(optionString);                                              }
 
@@ -683,6 +687,7 @@ Command* CommandFactory::getCommand(string commandName){
                else if(commandName == "get.commandinfo")               {       shellcommand = new GetCommandInfoCommand();                     }
                else if(commandName == "deunique.tree")                 {       shellcommand = new DeuniqueTreeCommand();                       }
                else if(commandName == "count.seqs")                    {       shellcommand = new CountSeqsCommand();                          }
+               else if(commandName == "count.groups")                  {       shellcommand = new CountGroupsCommand();                        }
                else if(commandName == "clear.memory")                  {       shellcommand = new ClearMemoryCommand();                        }
                else                                                                                    {       shellcommand = new NoCommand();                                         }
 
diff --git a/countgroupscommand.cpp b/countgroupscommand.cpp
new file mode 100644 (file)
index 0000000..af9993c
--- /dev/null
@@ -0,0 +1,237 @@
+/*
+ *  countgroupscommand.cpp
+ *  Mothur
+ *
+ *  Created by westcott on 8/9/11.
+ *  Copyright 2011 Schloss Lab. All rights reserved.
+ *
+ */
+
+#include "countgroupscommand.h"
+#include "sharedutilities.h"
+#include "inputdata.h"
+
+//**********************************************************************************************************************
+vector<string> CountGroupsCommand::setParameters(){    
+       try {
+               CommandParameter pshared("shared", "InputTypes", "", "", "sharedGroup", "sharedGroup", "none",false,false); parameters.push_back(pshared);
+               CommandParameter pgroup("group", "InputTypes", "", "", "sharedGroup", "sharedGroup", "none",false,false); parameters.push_back(pgroup);
+               CommandParameter paccnos("accnos", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(paccnos);
+               CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups);
+               CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir);
+               CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir);
+               
+               vector<string> myArray;
+               for (int i = 0; i < parameters.size(); i++) {   myArray.push_back(parameters[i].name);          }
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "CountGroupsCommand", "setParameters");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+string CountGroupsCommand::getHelpString(){    
+       try {
+               string helpString = "";
+               helpString += "The count.groups command counts sequences from a specfic group or set of groups from the following file types: group or shared file.\n";
+               helpString += "The count.groups command parameters are accnos, group, shared and groups. You must provide a group or shared file.\n";
+               helpString += "The accnos parameter allows you to provide a file containing the list of groups.\n";
+               helpString += "The groups parameter allows you to specify which of the groups in your groupfile you would like.  You can separate group names with dashes.\n";
+               helpString += "The count.groups command should be in the following format: count.groups(accnos=yourAccnos, group=yourGroupFile).\n";
+               helpString += "Example count.groups(accnos=amazon.accnos, group=amazon.groups).\n";
+               helpString += "or count.groups(groups=pasture, group=amazon.groups).\n";
+               helpString += "Note: No spaces between parameter labels (i.e. group), '=' and parameters (i.e.yourGroupFile).\n";
+               return helpString;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "CountGroupsCommand", "getHelpString");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+CountGroupsCommand::CountGroupsCommand(){      
+       try {
+               abort = true; calledHelp = true;
+               setParameters();
+       }
+       catch(exception& e) {
+               m->errorOut(e, "CountGroupsCommand", "CountGroupsCommand");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+CountGroupsCommand::CountGroupsCommand(string option)  {
+       try {
+               abort = false; calledHelp = false;   
+               
+               //allow user to run help
+               if(option == "help") { help(); abort = true; calledHelp = true; }
+               else if(option == "citation") { citation(); abort = true; calledHelp = true;}
+               
+               else {
+                       vector<string> myArray = setParameters();
+                       
+                       OptionParser parser(option);
+                       map<string,string> parameters = parser.getParameters();
+                       
+                       ValidParameters validParameter;
+                       map<string,string>::iterator it;
+                       
+                       //check to make sure all parameters are valid for command
+                       for (it = parameters.begin(); it != parameters.end(); it++) { 
+                               if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
+                       }
+                       
+                       //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"){  outputDir = "";         }
+                       
+                       //if the user changes the input directory command factory will send this info to us in the output parameter 
+                       string inputDir = validParameter.validFile(parameters, "inputdir", false);              
+                       if (inputDir == "not found"){   inputDir = "";          }
+                       else {
+                               string path;
+                               it = parameters.find("accnos");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = m->hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["accnos"] = inputDir + it->second;           }
+                               }
+                               
+                               it = parameters.find("group");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = m->hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["group"] = inputDir + it->second;            }
+                               }
+                               
+                               it = parameters.find("shared");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = m->hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["shared"] = inputDir + it->second;           }
+                               }
+                       }
+                       
+                       
+                       //check for required parameters
+                       accnosfile = validParameter.validFile(parameters, "accnos", true);
+                       if (accnosfile == "not open") { abort = true; }
+                       else if (accnosfile == "not found") {  accnosfile = ""; }
+                       else { m->setAccnosFile(accnosfile); }
+                       
+                       groups = validParameter.validFile(parameters, "groups", false);                 
+                       if (groups == "not found") { groups = ""; }
+                       else {
+                               m->splitAtDash(groups, Groups);
+                               m->Groups = Groups;
+                       }
+                       
+                       sharedfile = validParameter.validFile(parameters, "shared", true);
+                       if (sharedfile == "not open") { sharedfile = ""; abort = true; }
+                       else if (sharedfile == "not found") {  sharedfile = "";  }
+                       else { m->setSharedFile(sharedfile); }
+                       
+                       groupfile = validParameter.validFile(parameters, "group", true);
+                       if (groupfile == "not open") { groupfile = ""; abort = true; }
+                       else if (groupfile == "not found") {    groupfile = ""; }
+                       else { m->setGroupFile(groupfile); }    
+                       
+                       if ((sharedfile == "") && (groupfile == "")) { 
+                               //give priority to shared, then group
+                               sharedfile = m->getSharedFile(); 
+                               if (sharedfile != "") {  m->mothurOut("Using " + sharedfile + " as input file for the shared parameter."); m->mothurOutEndLine(); }
+                               else { 
+                                       groupfile = m->getGroupFile(); 
+                                       if (groupfile != "") { m->mothurOut("Using " + groupfile + " as input file for the group parameter."); m->mothurOutEndLine(); }
+                                       else { 
+                                               m->mothurOut("You have no current groupfile or sharedfile and one is required."); m->mothurOutEndLine(); abort = true;
+                                       }
+                               }
+                       }
+                       
+                       if ((accnosfile == "") && (Groups.size() == 0)) { Groups.push_back("all"); m->Groups = Groups; }
+               }
+               
+       }
+       catch(exception& e) {
+               m->errorOut(e, "CountGroupsCommand", "CountGroupsCommand");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+
+int CountGroupsCommand::execute(){
+       try {
+               
+               if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
+               
+               //get groups you want to remove
+               if (accnosfile != "") { readAccnos(); }
+               
+               if (groupfile != "") {
+                       GroupMap groupMap(groupfile);
+                       groupMap.readMap();
+                       
+                       //make sure groups are valid
+                       //takes care of user setting groupNames that are invalid or setting groups=all
+                       SharedUtil util;
+                       util.setGroups(Groups, groupMap.namesOfGroups);
+                       
+                       for (int i = 0; i < Groups.size(); i++) {
+                               m->mothurOut(Groups[i] + " contains " + toString(groupMap.getNumSeqs(Groups[i])) + "."); m->mothurOutEndLine();
+                       }
+               }
+               
+               if (m->control_pressed) { return 0; }
+               
+               if (sharedfile != "")           {               
+                       InputData input(sharedfile, "sharedfile");
+                       vector<SharedRAbundVector*> lookup = input.getSharedRAbundVectors();
+                       
+                       for (int i = 0; i < lookup.size(); i++) {
+                               m->mothurOut(lookup[i]->getGroup() + " contains " + toString(lookup[i]->getNumSeqs()) + "."); m->mothurOutEndLine();
+                               delete lookup[i];
+                       }                       
+               }
+                               
+               return 0;               
+       }
+       
+       catch(exception& e) {
+               m->errorOut(e, "CountGroupsCommand", "execute");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+void CountGroupsCommand::readAccnos(){
+       try {
+               Groups.clear();
+               
+               ifstream in;
+               m->openInputFile(accnosfile, in);
+               string name;
+               
+               while(!in.eof()){
+                       in >> name;
+                       
+                       Groups.push_back(name);
+                       
+                       m->gobble(in);
+               }
+               in.close();             
+               
+               m->Groups = Groups;
+               
+       }
+       catch(exception& e) {
+               m->errorOut(e, "CountGroupsCommand", "readAccnos");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+
+
diff --git a/countgroupscommand.h b/countgroupscommand.h
new file mode 100644 (file)
index 0000000..2532a80
--- /dev/null
@@ -0,0 +1,42 @@
+#ifndef COUNTGROUPSCOMMAND_H
+#define COUNTGROUPSCOMMAND_H
+
+/*
+ *  countgroupscommand.h
+ *  Mothur
+ *
+ *  Created by westcott on 8/9/11.
+ *  Copyright 2011 Schloss Lab. All rights reserved.
+ *
+ */
+
+#include "command.hpp"
+
+class CountGroupsCommand : public Command {
+       
+public:
+       
+       CountGroupsCommand(string);
+       CountGroupsCommand();   
+       ~CountGroupsCommand(){}
+       
+       vector<string> setParameters();
+       string getCommandName()                 { return "count.groups";                        }
+       string getCommandCategory()             { return "Sequence Processing";         }
+       string getHelpString(); 
+       string getCitation() { return "http://www.mothur.org/wiki/Count.groups"; }
+       string getDescription()         { return "counts the number of sequences in each group"; }
+       
+       int execute(); 
+       void help() { m->mothurOut(getHelpString()); }  
+       
+       
+private:
+       string sharedfile, groupfile, outputDir, groups, accnosfile;
+       bool abort;
+       vector<string> Groups;
+       
+       void readAccnos();
+};
+
+#endif
index f974ae966ed5f85c1136ed59a0c82b79f2f847d2..580c3f2d4587ba80b8286d5b46968d6faa3818c3 100644 (file)
@@ -45,6 +45,7 @@ class Database {
 
 public:
        Database();
+       Database(const Database& db) : numSeqs(db.numSeqs), longest(db.longest), searchScore(db.searchScore), results(db.results), Scores(db.Scores) { m = MothurOut::getInstance(); }
        virtual ~Database();
        virtual void generateDB() = 0; 
        virtual void addSequence(Sequence) = 0;  //add sequence to search engine
@@ -57,7 +58,7 @@ public:
        virtual void readKmerDB(ifstream&){};
        virtual void setNumSeqs(int i) {        numSeqs = i;    }
        virtual vector<int> getSequencesWithKmer(int){ vector<int> filler; return filler; };  
-       virtual int getMaxKmer(){       return 1;       };
+       virtual int getMaxKmer(){       return 1;       }
        
 protected:
        MothurOut* m;
diff --git a/dist.h b/dist.h
index 71055ae67bab87eb434a7dbe7f9370155a7efa53..1412424b8da755dbe6a35f2a7d14ae37c36929e5 100644 (file)
--- a/dist.h
+++ b/dist.h
@@ -17,7 +17,8 @@
 class Dist {
        
 public:
-       Dist(){dist = 0; m = MothurOut::getInstance(); }
+       Dist(){ dist = 0; m = MothurOut::getInstance(); }
+       Dist(const Dist& d) : dist(d.dist) { m = MothurOut::getInstance(); }
        virtual ~Dist() {}
        virtual void calcDist(Sequence, Sequence) = 0;
        double getDist()        {       return dist;    }
index c1bf7e7fb08dc3fae5b3cf17f575580269677148..2cbf5cad6edf5df5b62b7c345cf09032eaf7e10f 100644 (file)
 #include "distancedb.hpp"
 #include "onegapignore.h"
 
+
+/**************************************************************************************************/
+DistanceDB::DistanceDB(const DistanceDB& ddb) : data(ddb.data), templateSeqsLength(ddb.templateSeqsLength), templateAligned(ddb.templateAligned), Database(ddb) { 
+       distCalculator = new oneGapIgnoreTermGapDist(); 
+}
 /**************************************************************************************************/
-DistanceDB::DistanceDB() { 
+DistanceDB::DistanceDB() : Database() 
        try {
                templateAligned = true;  
                templateSeqsLength = 0; 
index 2624d6d6440190520e02af09c43264bf365c9f33..d7e05db85afed819b9f2d26c99d06c1426ca19f9 100644 (file)
@@ -19,6 +19,7 @@ class DistanceDB : public Database {
 public:
        
        DistanceDB();
+       DistanceDB(const DistanceDB& ddb); 
        ~DistanceDB() { delete distCalculator; }
        
        void generateDB() {} //doesn't generate a search db 
index 84fe56ec58da1652d9484832b9b55ec69f420814..fe9bc3099d7a1dcdd347bfe98a23e1bceb44768a 100644 (file)
@@ -18,6 +18,9 @@ class eachGapDist : public Dist {
        
 public:
        
+       eachGapDist() {}
+       eachGapDist(const eachGapDist& ddb) {}
+       
        void calcDist(Sequence A, Sequence B){          
                int diff = 0;
                int length = 0;
index 824a8b87b936c75dbfe21fdaf6a1b9a54c1440b0..2e7fbd6bd228d3ed625cd1904ecd7d15075d9234 100644 (file)
@@ -17,6 +17,8 @@
 class eachGapIgnoreTermGapDist : public Dist {
        
 public:
+       eachGapIgnoreTermGapDist() {}
+       eachGapIgnoreTermGapDist(const eachGapIgnoreTermGapDist& ddb) {}
        
        void calcDist(Sequence A, Sequence B){          
                int diff = 0;
index d4e5ee507219bcfd943b371b0f19b86aea132da5..ccc6b96ee9d6f0e5f3761f9e969741f5e08defdd 100644 (file)
@@ -20,6 +20,9 @@ class ignoreGaps : public Dist {
        
 public:
        
+       ignoreGaps() {}
+       ignoreGaps(const ignoreGaps& ddb) {}
+       
        void calcDist(Sequence A, Sequence B){          
                int diff = 0;
                int length = 0;
index becdeda7fa5f343b9d5d54e81c0e5df62a1661b6..62d4836a066f9bc10cf1a041e21cb07e1e0a1f84 100644 (file)
@@ -26,6 +26,7 @@ class KmerDB : public Database {
        
 public:
        KmerDB(string, int);
+       KmerDB(const KmerDB& kdb) : kmerSize(kdb.kmerSize), maxKmer(kdb.maxKmer), count(kdb.count), kmerDBName(kdb.kmerDBName), kmerLocations(kdb.kmerLocations), Database(kdb) {}
        KmerDB();
        ~KmerDB();
        
index cb63ae678fa691b0a08b3935432eec9a5e874bd8..971e6b0ebbad92014347872ee92f4222c044db72 100644 (file)
 class oneGapDist : public Dist {
        
 public:
+       
+       oneGapDist() {}
+       oneGapDist(const oneGapDist& ddb) {}
+       
        void calcDist(Sequence A, Sequence B){
                
                int difference = 0;
index 32818e3df6fce4bc5ab8a4ddda975572146a2a53..dba3f38292ced957330631ece5572901ee3438ae 100644 (file)
 class oneGapIgnoreTermGapDist : public Dist {
        
 public:
+       
+       oneGapIgnoreTermGapDist() {}
+       oneGapIgnoreTermGapDist(const oneGapIgnoreTermGapDist& ddb) {}
+       
        void calcDist(Sequence A, Sequence B){
                
                int difference = 0;
index ff1209287b4e17b2fcc58678703123aae2cadbc1..66f8193e647c94db5bc8ac815bb6eea9796cd138 100644 (file)
@@ -219,7 +219,7 @@ int ParsimonyCommand::execute() {
                        read->AssembleTrees();
                        T = read->getTrees();
                        delete read;
-                       
+
                        //make sure all files match
                        //if you provide a namefile we will use the numNames in the namefile as long as the number of unique match the tree names size.
                        int numNamesInTree;
index 94d7d29b6117da80862e9fc8b3d0855c4adb8edd..b4337405a811545d4c3b2f64dc8771d42898d1fc 100644 (file)
@@ -25,6 +25,8 @@ public:
        Sequence(string, string);
        Sequence(ifstream&);
        Sequence(istringstream&);
+       Sequence(const Sequence& se) : name(se.name), unaligned(se.unaligned), aligned(se.aligned), pairwise(se.pairwise), numBases(se.numBases), startPos(se.startPos), endPos(se.endPos),
+                                                                       alignmentLength(se.alignmentLength), isAligned(se.isAligned), longHomoPolymer(se.longHomoPolymer), ambigBases(se.ambigBases) { m = MothurOut::getInstance(); }
        
        //these constructors just set the unaligned string to save space
        Sequence(string, string, string);  
index 393b4a52f3fde135a1dd80009b6dc44dc5340737..ca1ff42a11c6bcbd689e0e49e2cdfb36604e0807 100644 (file)
 
 #include "mothur.h"
 #include "database.hpp"
-
-class SuffixTree;
+#include "suffixtree.hpp"
+//class SuffixTree;
 
 class SuffixDB : public Database {
        
 public:
        SuffixDB(int);
        SuffixDB();
+       SuffixDB(const SuffixDB& sdb) : count(sdb.count), Database(sdb) {
+               for (int i = 0; i < sdb.suffixForest.size(); i++) {
+                       SuffixTree temp(sdb.suffixForest[i]);
+                       suffixForest.push_back(temp);
+               }
+       }
        ~SuffixDB();
        
        void generateDB() {}; //adding sequences generates the db
index 6a22c4d4359b8ee6120c3e683b2d14318fd0c05c..1e078a63a759a99b4b47ed123526da752e2404bd 100644 (file)
@@ -25,6 +25,7 @@ class SuffixNode {
        
 public:
        SuffixNode(int, int, int);
+       SuffixNode(const SuffixNode& sn) : parentNode(sn.parentNode), startCharPosition(sn.startCharPosition), endCharPosition(sn.endCharPosition) {m = MothurOut::getInstance();}
        virtual ~SuffixNode() {}
        virtual void print(string, int) = 0;
        virtual void setChildren(char, int);
@@ -62,6 +63,7 @@ class SuffixBranch : public SuffixNode {
        
 public:
        SuffixBranch(int, int, int);
+       SuffixBranch(const SuffixBranch& sb) : suffixNode(sb.suffixNode), childNodes(sb.childNodes), SuffixNode(sb.parentNode, sb.startCharPosition, sb.endCharPosition) {}
        ~SuffixBranch() {}
        void print(string, int);                //      need a special method for printing the node because there are children
        void eraseChild(char);                  //      need a special method for erasing the children
index 9cd835185c31a61bd024590f5a3fc7396d31610f..fd18109513bea9f59590e16a1c705128f61ca43e 100644 (file)
@@ -33,6 +33,25 @@ inline bool compareParents(SuffixNode* left, SuffixNode* right){//   this is neces
        return (left->getParentNode() < right->getParentNode());        //      nodes in order of their parent
 }
 
+//********************************************************************************************************************
+SuffixTree::SuffixTree(const SuffixTree& st) : root(st.root), activeEndPosition(st.activeEndPosition), activeStartPosition(st.activeStartPosition), activeNode(st.activeNode),
+                                                                                               nodeCounter(st.nodeCounter), seqName(st.seqName), sequence(st.sequence) { 
+       try {
+               m = MothurOut::getInstance(); 
+               
+               for (int i = 0; i < st.nodeVector.size(); i++) {
+                       SuffixNode* temp = new SuffixBranch(*((SuffixBranch*)st.nodeVector[i]));
+                       nodeVector.push_back(temp);
+               }
+               
+               
+       }catch(exception& e) {
+               m->errorOut(e, "SuffixTree", "SuffixTree");
+               exit(1);
+       }
+}
 //********************************************************************************************************************
 
 SuffixTree::SuffixTree(){ m = MothurOut::getInstance(); }
index 805b9b0fda003cbeade1ce5ea875cb994ab3c960..492db54772ddcc1b2e2d60ea46c1700529453e22 100644 (file)
@@ -37,6 +37,7 @@ public:
        SuffixTree();
        ~SuffixTree();
 //     SuffixTree(string, string);
+       SuffixTree(const SuffixTree&);
 
        void loadSequence(Sequence);
        string getSeqName();
index 75423855a7f583ae5ce62fc10118cf260589df6b..1fc5c01b796a67bd948a70147fa4dead9320ea08 100644 (file)
@@ -12,6 +12,7 @@
 /************************************************************/
 
  TreeMap::TreeMap(string filename) {
+       m = MothurOut::getInstance();
        groupFileName = filename;
        m->openInputFile(filename, fileHandle);
 }
  TreeMap::~TreeMap(){}
 
 /************************************************************/
-void TreeMap::readMap() {
+int TreeMap::readMap() {
                string seqName, seqGroup;
-       
+               int error = 0;
+               
                while(fileHandle){
-                       fileHandle >> seqName;                  //read from first column
+                       fileHandle >> seqName;          //read from first column
                        fileHandle >> seqGroup;                 //read from second column
-
-                       namesOfSeqs.push_back(seqName);
+                       
+                       if (m->control_pressed) {  fileHandle.close();  return 1; }
+                       
                        setNamesOfGroups(seqGroup);
                                        
-                       treemap[seqName].groupname = seqGroup;  //store data in map
-                       
-                       it2 = seqsPerGroup.find(seqGroup);
-                       if (it2 == seqsPerGroup.end()) { //if it's a new group
-                               seqsPerGroup[seqGroup] = 1;
-                       }else {//it's a group we already have
-                               seqsPerGroup[seqGroup]++;
+                       map<string, GroupIndex>::iterator itCheck = treemap.find(seqName);
+                       if (itCheck != treemap.end()) { error = 1; m->mothurOut("[WARNING]: Your groupfile contains more than 1 sequence named " + seqName + ", sequence names must be unique. Please correct."); m->mothurOutEndLine();  }
+                       else {
+                               namesOfSeqs.push_back(seqName);
+                               treemap[seqName].groupname = seqGroup;  //store data in map
+                               
+                               it2 = seqsPerGroup.find(seqGroup);
+                               if (it2 == seqsPerGroup.end()) { //if it's a new group
+                                       seqsPerGroup[seqGroup] = 1;
+                               }else {//it's a group we already have
+                                       seqsPerGroup[seqGroup]++;
+                               }                               
                        }
-
+                       
                        m->gobble(fileHandle);
                }
                fileHandle.close();
+       
+
+               return error;
 }
 /************************************************************/
 void TreeMap::addSeq(string seqName, string seqGroup) {
index 9f10f375660be529a2b2b53e6a87745d426bba19..244348ef1f52d3768a585e1960fd0d1b20424d49 100644 (file)
--- a/treemap.h
+++ b/treemap.h
@@ -28,7 +28,7 @@ public:
        TreeMap() { m = MothurOut::getInstance(); }
        TreeMap(string);
        ~TreeMap();
-       void readMap();
+       int readMap();
        int getNumGroups();
        int getNumSeqs();
        void setIndex(string, int);  //sequencename, index