]> git.donarmstrong.com Git - mothur.git/blobdiff - chimeraslayercommand.cpp
made classifier faster
[mothur.git] / chimeraslayercommand.cpp
index 1a5ae09df87ee9e37abbf81621b0da532a4549dd..58aecf58ccd10354c5aca094d20827c44fc00ff9 100644 (file)
@@ -8,10 +8,6 @@
  */
 
 #include "chimeraslayercommand.h"
-#include "bellerophon.h"
-#include "pintail.h"
-#include "ccode.h"
-#include "chimeracheckrdp.h"
 #include "chimeraslayer.h"
 
 
@@ -141,14 +137,13 @@ void ChimeraSlayerCommand::help(){
        
                m->mothurOut("The chimera.slayer command reads a fastafile and templatefile and outputs potentially chimeric sequences.\n");
                m->mothurOut("This command was modeled after the chimeraSlayer written by the Broad Institute.\n");
-               m->mothurOut("The chimera.slayer command parameters are fasta, template, filter, mask, processors, ksize, window, match, mismatch, divergence. minsim, mincov, minbs, minsnp, parents, search, iters, increment and numwanted.\n"); //realign,
+               m->mothurOut("The chimera.slayer command parameters are fasta, template, processors, ksize, window, match, mismatch, divergence. minsim, mincov, minbs, minsnp, parents, search, iters, increment and numwanted.\n"); //realign,
                m->mothurOut("The fasta parameter allows you to enter the fasta file containing your potentially chimeric sequences, and is required. \n");
                m->mothurOut("The template parameter allows you to enter a template file containing known non-chimeric sequences, and is required. \n");
                m->mothurOut("The processors parameter allows you to specify how many processors you would like to use.  The default is 1. \n");
                #ifdef USE_MPI
                m->mothurOut("When using MPI, the processors parameter is set to the number of MPI processes running. \n");
                #endif
-               m->mothurOut("The mask parameter allows you to specify a file containing one sequence you wish to use as a mask for the your sequences. \n");
                m->mothurOut("The window parameter allows you to specify the window size for searching for chimeras, default=50. \n");
                m->mothurOut("The increment parameter allows you to specify how far you move each window while finding chimeric sequences, default=5.\n");
                m->mothurOut("The numwanted parameter allows you to specify how many sequences you would each query sequence compared with, default=15.\n");
@@ -164,7 +159,6 @@ void ChimeraSlayerCommand::help(){
                m->mothurOut("The minsnp parameter allows you to specify percent of SNPs to sample on each side of breakpoint for computing bootstrap support (default: 10) \n");
                m->mothurOut("The search parameter allows you to specify search method for finding the closest parent. Choices are distance, blast, and kmer, default distance. \n");
                //m->mothurOut("The realign parameter allows you to realign the query to the potential parents. Choices are true or false, default false. Found to make results worse. \n");
-               m->mothurOut("NOT ALL PARAMETERS ARE USED BY ALL METHODS. Please look below for method specifics.\n\n");
                m->mothurOut("The chimera.slayer command should be in the following format: \n");
                m->mothurOut("chimera.slayer(fasta=yourFastaFile, template=yourTemplate, search=yourSearch) \n");
                m->mothurOut("Example: chimera.slayer(fasta=AD.align, template=core_set_aligned.imputed.fasta, search=kmer) \n");
@@ -220,22 +214,34 @@ int ChimeraSlayerCommand::execute(){
                        
                        int outMode=MPI_MODE_CREATE|MPI_MODE_WRONLY; 
                        int inMode=MPI_MODE_RDONLY; 
-                                                       
-                       char outFilename[outputFileName.length()];
+                       
+                       //char* outFilename = new char[outputFileName.length()];
+                       //memcpy(outFilename, outputFileName.c_str(), outputFileName.length());
+                       
+                       char outFilename[1024];
                        strcpy(outFilename, outputFileName.c_str());
                        
-                       char outAccnosFilename[accnosFileName.length()];
+                       //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[fastafile.length()];
+                       //memcpy(inFileName, fastafile.c_str(), fastafile.length());
                        
-                       char inFileName[fastafile.length()];
+                       char inFileName[1024];
                        strcpy(inFileName, fastafile.c_str());
 
                        MPI_File_open(MPI_COMM_WORLD, inFileName, inMode, MPI_INFO_NULL, &inMPI);  //comm, filename, mode, info, filepointer
                        MPI_File_open(MPI_COMM_WORLD, outFilename, outMode, MPI_INFO_NULL, &outMPI);
                        MPI_File_open(MPI_COMM_WORLD, outAccnosFilename, outMode, MPI_INFO_NULL, &outMPIAccnos);
                        
-                       if (m->control_pressed) {  MPI_File_close(&inMPI);  MPI_File_close(&outMPI);   MPI_File_close(&outMPIAccnos);  delete chimera; return 0;  }
+                       //delete inFileName;
+                       //delete outFilename;
+                       //delete outAccnosFilename;
 
+                       if (m->control_pressed) {  MPI_File_close(&inMPI);  MPI_File_close(&outMPI);   MPI_File_close(&outMPIAccnos);  delete chimera; return 0;  }
                
                        if (pid == 0) { //you are the root process 
                                m->mothurOutEndLine();
@@ -246,10 +252,12 @@ int ChimeraSlayerCommand::execute(){
                                
                                //print header
                                int length = outTemp.length();
-                               char buf2[length];
-                               strcpy(buf2, outTemp.c_str()); 
+                               char* buf2 = new char[length];
+                               memcpy(buf2, outTemp.c_str(), length);
+
                                MPI_File_write_shared(outMPI, buf2, length, MPI_CHAR, &status);
-                               
+                               delete buf2;
+
                                MPIPos = setFilePosFasta(fastafile, numSeqs); //fills MPIPos, returns numSeqs
                                
                                //send file positions to all processes
@@ -425,7 +433,7 @@ int ChimeraSlayerCommand::execute(){
                        if (isBlank(accnosFileName)) {  remove(accnosFileName.c_str());  hasAccnos = false; }
                #endif
                
-               appendFiles(tempHeader, outputFileName);
+               appendFiles(outputFileName, tempHeader);
        
                remove(outputFileName.c_str());
                rename(tempHeader.c_str(), outputFileName.c_str());
@@ -508,8 +516,7 @@ int ChimeraSlayerCommand::driver(linePair* line, string outputFName, string file
 //**********************************************************************************************************************
 #ifdef USE_MPI
 int ChimeraSlayerCommand::driverMPI(int start, int num, MPI_File& inMPI, MPI_File& outMPI, MPI_File& outAccMPI, vector<long>& MPIPos){
-       try {
-                               
+       try {                           
                MPI_Status status; 
                int pid;
                MPI_Comm_rank(MPI_COMM_WORLD, &pid); //find out who we are
@@ -520,29 +527,33 @@ int ChimeraSlayerCommand::driverMPI(int start, int num, MPI_File& inMPI, MPI_Fil
                        
                        //read next sequence
                        int length = MPIPos[start+i+1] - MPIPos[start+i];
-       
-                       char buf4[length];
+
+                       char* buf4 = new char[length];
                        MPI_File_read_at(inMPI, MPIPos[start+i], buf4, length, MPI_CHAR, &status);
-                       
+       
                        string tempBuf = buf4;
                        if (tempBuf.length() > length) { tempBuf = tempBuf.substr(0, length);  }
                        istringstream iss (tempBuf,istringstream::in);
 
+                       delete buf4;
+
                        Sequence* candidateSeq = new Sequence(iss);  gobble(iss);
-                               
+               
                        if (candidateSeq->getName() != "") { //incase there is a commented sequence at the end of a file
                                
                                if (candidateSeq->getAligned().length() != templateSeqsLength) {  
                                        m->mothurOut(candidateSeq->getName() + " is not the same length as the template sequences. Skipping."); m->mothurOutEndLine();
                                }else{
+               
                                        //find chimeras
                                        chimera->getChimeras(candidateSeq);
-                                       
+                       
                                        if (m->control_pressed) {       delete candidateSeq; return 1;  }
-               
+               //cout << "about to print" << endl;
                                        //print results
                                        bool isChimeric = chimera->print(outMPI, outAccMPI);
                                        if (isChimeric) { MPIWroteAccnos = true;  }
+       
                                }
                        }
                        delete candidateSeq;