From: westcott Date: Tue, 20 Apr 2010 11:34:53 +0000 (+0000) Subject: a few modifications for 1.9 X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=commitdiff_plain;h=813f0516e9c7533859f57ebe6d7b8854896bf009 a few modifications for 1.9 --- diff --git a/chimera.cpp b/chimera.cpp index 32351f9..83d40fe 100644 --- a/chimera.cpp +++ b/chimera.cpp @@ -109,7 +109,7 @@ vector Chimera::readSeqs(string file) { MPI_File inMPI; MPI_Comm_rank(MPI_COMM_WORLD, &pid); //find out who we are - char* inFileName = new char[file.length()]; + char* inFileName = new char[file.length()]; memcpy(inFileName, file.c_str(), file.length()); MPI_File_open(MPI_COMM_WORLD, inFileName, MPI_MODE_RDONLY, MPI_INFO_NULL, &inMPI); //comm, filename, mode, info, filepointer @@ -199,7 +199,7 @@ void Chimera::setMask(string filename) { MPI_Offset size; MPI_Status status; - char* inFileName = new char[filename.length()]; + char* inFileName = new char[filename.length()]; memcpy(inFileName, filename.c_str(), filename.length()); MPI_File_open(MPI_COMM_WORLD, inFileName, MPI_MODE_RDONLY, MPI_INFO_NULL, &inMPI); //comm, filename, mode, info, filepointer diff --git a/chimeraslayer.cpp b/chimeraslayer.cpp index c30404f..2c4f7fb 100644 --- a/chimeraslayer.cpp +++ b/chimeraslayer.cpp @@ -10,6 +10,7 @@ #include "chimeraslayer.h" #include "chimerarealigner.h" #include "kmerdb.hpp" +#include "blastdb.hpp" //*************************************************************************************************************** ChimeraSlayer::ChimeraSlayer(string file, string temp, string mode, int k, int ms, int mms, int win, float div, @@ -46,7 +47,6 @@ int minsim, int mincov, int minbs, int minsnp, int par, int it, int inc, int num int ChimeraSlayer::doPrep() { try { - //read in all query seqs vector tempQuerySeqs = readSeqs(fastafile); @@ -148,6 +148,13 @@ int ChimeraSlayer::doPrep() { databaseRight->setNumSeqs(templateSeqs.size()); #endif + }else if (searchMethod == "blast") { + + //generate blastdb + databaseLeft = new BlastDB(-2.0, -1.0, match, misMatch); + for (int i = 0; i < templateSeqs.size(); i++) { databaseLeft->addSequence(*templateSeqs[i]); } + databaseLeft->generateDB(); + databaseLeft->setNumSeqs(templateSeqs.size()); } return 0; @@ -159,7 +166,11 @@ int ChimeraSlayer::doPrep() { } } //*************************************************************************************************************** -ChimeraSlayer::~ChimeraSlayer() { delete decalc; if (searchMethod == "kmer") { delete databaseRight; delete databaseLeft; } } +ChimeraSlayer::~ChimeraSlayer() { + delete decalc; + if (searchMethod == "kmer") { delete databaseRight; delete databaseLeft; } + else if (searchMethod == "blast") { delete databaseLeft; } +} //*************************************************************************************************************** void ChimeraSlayer::printHeader(ostream& out) { m->mothurOutEndLine(); @@ -221,7 +232,7 @@ int ChimeraSlayer::print(MPI_File& out, MPI_File& outAcc) { //write to accnos file int length = outAccString.length(); - char* buf2 = new char[length]; + char* buf2 = new char[length]; memcpy(buf2, outAccString.c_str(), length); MPI_File_write_shared(outAcc, buf2, length, MPI_CHAR, &status); @@ -231,17 +242,28 @@ int ChimeraSlayer::print(MPI_File& out, MPI_File& outAcc) { outputString = getBlock(chimeraResults[0]); outputString += "\n"; - - }else { outputString += querySeq->getName() + "\tno\n"; } - - //write to output file - int length = outputString.length(); - char* buf = new char[length]; - memcpy(buf, outputString.c_str(), length); + //cout << outputString << endl; + //write to output file + int length = outputString.length(); + char* buf = new char[length]; + memcpy(buf, outputString.c_str(), length); - MPI_File_write_shared(out, buf, length, MPI_CHAR, &status); - delete buf; + MPI_File_write_shared(out, buf, length, MPI_CHAR, &status); + delete buf; + }else { + outputString += querySeq->getName() + "\tno\n"; + //cout << outputString << endl; + //write to output file + int length = outputString.length(); + char* buf = new char[length]; + memcpy(buf, outputString.c_str(), length); + + MPI_File_write_shared(out, buf, length, MPI_CHAR, &status); + delete buf; + } + + return results; } catch(exception& e) { @@ -255,7 +277,7 @@ int ChimeraSlayer::print(MPI_File& out, MPI_File& outAcc) { int ChimeraSlayer::getChimeras(Sequence* query) { try { chimeraFlags = "no"; - + //filter query spotMap = runFilter(query); diff --git a/chimeraslayercommand.cpp b/chimeraslayercommand.cpp index 777584b..4b309c0 100644 --- a/chimeraslayercommand.cpp +++ b/chimeraslayercommand.cpp @@ -217,13 +217,13 @@ int ChimeraSlayerCommand::execute(){ int outMode=MPI_MODE_CREATE|MPI_MODE_WRONLY; int inMode=MPI_MODE_RDONLY; - char* outFilename = new char[outputFileName.length()]; + char* outFilename = new char[outputFileName.length()]; memcpy(outFilename, outputFileName.c_str(), outputFileName.length()); - char* outAccnosFilename = new char[accnosFileName.length()]; + char* outAccnosFilename = new char[accnosFileName.length()]; memcpy(outAccnosFilename, accnosFileName.c_str(), accnosFileName.length()); - char* inFileName = new char[fastafile.length()]; + char* inFileName = new char[fastafile.length()]; memcpy(inFileName, fastafile.c_str(), fastafile.length()); MPI_File_open(MPI_COMM_WORLD, inFileName, inMode, MPI_INFO_NULL, &inMPI); //comm, filename, mode, info, filepointer @@ -235,7 +235,6 @@ int ChimeraSlayerCommand::execute(){ 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,7 +245,7 @@ int ChimeraSlayerCommand::execute(){ //print header int length = outTemp.length(); - char* buf2 = new char[length]; + char* buf2 = new char[length]; memcpy(buf2, outTemp.c_str(), length); MPI_File_write_shared(outMPI, buf2, length, MPI_CHAR, &status); @@ -427,7 +426,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()); @@ -510,8 +509,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& MPIPos){ - try { - + try { MPI_Status status; int pid; MPI_Comm_rank(MPI_COMM_WORLD, &pid); //find out who we are @@ -522,30 +520,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 = 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; diff --git a/engine.cpp b/engine.cpp index c6ceb59..b68bf61 100644 --- a/engine.cpp +++ b/engine.cpp @@ -99,6 +99,15 @@ bool InteractEngine::getInput(){ /***********************************************************************/ string Engine::getCommand() { try { + #ifdef USE_MPI //mpirun doesn't work with readline + string nextCommand = ""; + + mout->mothurOut("mothur > "); + getline(cin, nextCommand); + mout->mothurOutJustToLog(toString(nextCommand)); + + return nextCommand; + #else #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) #ifdef USE_READLINE char* nextCommand = NULL; @@ -129,8 +138,7 @@ string Engine::getCommand() { return nextCommand; #endif - - mout->mothurOutEndLine(); + #endif } catch(exception& e) { diff --git a/makefile b/makefile index 9915286..d95b5ef 100644 --- a/makefile +++ b/makefile @@ -10,9 +10,8 @@ # Macros # -CC = mpic++ +CC = g++ CC_OPTIONS = -O3 -LNK_OPTIONS = # if you do not want to use the readline library set to no, default yes. # make sure you have the library installed @@ -27,7 +26,7 @@ ifeq ($(strip $(USEREADLINE)),yes) -L../readline-6.0 endif -USEMPI ?= yes +USEMPI ?= no ifeq ($(strip $(USEMPI)),yes) CC_OPTIONS += -DUSE_MPI diff --git a/maligner.cpp b/maligner.cpp index f06884f..5da4b9f 100644 --- a/maligner.cpp +++ b/maligner.cpp @@ -496,12 +496,7 @@ vector Maligner::getBlastSeqs(Sequence* q, int num) { try { indexes.clear(); vector refResults; - //generate blastdb - Database* database = new BlastDB(-2.0, -1.0, matchScore, misMatchPenalty); - for (int i = 0; i < db.size(); i++) { database->addSequence(*db[i]); } - database->generateDB(); - database->setNumSeqs(db.size()); - + //get parts of query string queryUnAligned = q->getUnaligned(); string leftQuery = queryUnAligned.substr(0, int(queryUnAligned.length() * 0.33)); //first 1/3 of the sequence @@ -510,8 +505,8 @@ vector Maligner::getBlastSeqs(Sequence* q, int num) { Sequence* queryLeft = new Sequence(q->getName(), leftQuery); Sequence* queryRight = new Sequence(q->getName(), rightQuery); - vector tempIndexesRight = database->findClosestMegaBlast(queryRight, num+1); - vector tempIndexesLeft = database->findClosestMegaBlast(queryLeft, num+1); + vector tempIndexesRight = databaseLeft->findClosestMegaBlast(queryRight, num+1); + vector tempIndexesLeft = databaseLeft->findClosestMegaBlast(queryLeft, num+1); //if ((tempIndexesRight.size() != (num+1)) || (tempIndexesLeft.size() != (num+1))) { m->mothurOut("megablast returned " + toString(tempIndexesRight.size()) + " results for the right end, and " + toString(tempIndexesLeft.size()) + " for the left end. Needed " + toString(num+1) + ". Unable to porcess sequence " + q->getName()); m->mothurOutEndLine(); return refResults; } @@ -564,8 +559,7 @@ vector Maligner::getBlastSeqs(Sequence* q, int num) { //cout << endl; delete queryRight; delete queryLeft; - delete database; - + return refResults; } catch(exception& e) {