From: westcott Date: Thu, 9 Jul 2009 13:10:26 +0000 (+0000) Subject: added getline function to mothur and modified places where we use getline to use... X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=commitdiff_plain;h=5ff964d3871ce86f59fec3052f9c25e872f22c42 added getline function to mothur and modified places where we use getline to use this new function. --- diff --git a/aligncommand.cpp b/aligncommand.cpp index 5af8e95..2fda252 100644 --- a/aligncommand.cpp +++ b/aligncommand.cpp @@ -197,7 +197,7 @@ int AlignCommand::execute(){ string input; while(!inFASTA.eof()){ - getline(inFASTA, input); + input = getline(inFASTA); if (input.length() != 0) { if(input[0] == '>'){ int pos = inFASTA.tellg(); positions.push_back(pos - input.length() - 1); } } diff --git a/chimeraseqscommand.cpp b/chimeraseqscommand.cpp index b451721..a334ea3 100644 --- a/chimeraseqscommand.cpp +++ b/chimeraseqscommand.cpp @@ -9,6 +9,8 @@ #include "chimeraseqscommand.h" #include "eachgapdist.h" +#include "ignoregaps.h" +#include "onegapdist.h" //*************************************************************************************************************** @@ -228,13 +230,22 @@ cout << "increment = " << increment << endl; delete distCalculator; - //find average pref score across windows - //if (increment != 0) { - - //for (int i = 0; i < pref.size(); i++) { - //pref[i].score[0] = pref[i].score[0] / iters; - //} - //} + //rank preference score to eachother + float dme = 0.0; + float expectedPercent = 1 / (float) (pref.size()); + + for (int i = 0; i < pref.size(); i++) { dme += pref[i].score[0]; } + + for (int i = 0; i < pref.size(); i++) { + + //gives the actual percentage of the dme this seq adds + pref[i].score[0] = pref[i].score[0] / dme; + + //how much higher or lower is this than expected + pref[i].score[0] = pref[i].score[0] / expectedPercent; + + } + //sort Preferences highest to lowest sort(pref.begin(), pref.end(), comparePref); @@ -364,8 +375,8 @@ void ChimeraSeqsCommand::generatePreferences(vector left, vector itL = currentLeft.find(j); itR = currentRight.find(j); -cout << " i = " << i << " j = " << j << " distLeft = " << itL->second << endl; -cout << " i = " << i << " j = " << j << " distright = " << itR->second << endl; +//cout << " i = " << i << " j = " << j << " distLeft = " << itL->second << endl; +//cout << " i = " << i << " j = " << j << " distright = " << itR->second << endl; //if you can find this entry update the preferences if ((itL != currentLeft.end()) && (itR != currentRight.end())) { @@ -373,31 +384,31 @@ cout << " i = " << i << " j = " << j << " distright = " << itR->second << endl; if (!correction) { pref[i].score[1] += abs((itL->second - itR->second)); pref[j].score[1] += abs((itL->second - itR->second)); -cout << "left " << i << " " << j << " = " << itL->second << " right " << i << " " << j << " = " << itR->second << endl; -cout << "abs = " << abs((itL->second - itR->second)) << endl; -cout << i << " score = " << pref[i].score[1] << endl; -cout << j << " score = " << pref[j].score[1] << endl; +//cout << "left " << i << " " << j << " = " << itL->second << " right " << i << " " << j << " = " << itR->second << endl; +//cout << "abs = " << abs((itL->second - itR->second)) << endl; +//cout << i << " score = " << pref[i].score[1] << endl; +//cout << j << " score = " << pref[j].score[1] << endl; }else { pref[i].score[1] += abs((sqrt(itL->second) - sqrt(itR->second))); pref[j].score[1] += abs((sqrt(itL->second) - sqrt(itR->second))); -cout << "left " << i << " " << j << " = " << itL->second << " right " << i << " " << j << " = " << itR->second << endl; -cout << "abs = " << abs((sqrt(itL->second) - sqrt(itR->second))) << endl; -cout << i << " score = " << pref[i].score[1] << endl; -cout << j << " score = " << pref[j].score[1] << endl; +//cout << "left " << i << " " << j << " = " << itL->second << " right " << i << " " << j << " = " << itR->second << endl; +//cout << "abs = " << abs((sqrt(itL->second) - sqrt(itR->second))) << endl; +//cout << i << " score = " << pref[i].score[1] << endl; +//cout << j << " score = " << pref[j].score[1] << endl; } -cout << "pref[" << i << "].closestLeft[1] = " << pref[i].closestLeft[1] << " parent = " << pref[i].leftParent[1] << endl; +//cout << "pref[" << i << "].closestLeft[1] = " << pref[i].closestLeft[1] << " parent = " << pref[i].leftParent[1] << endl; //are you the closest left sequence if (itL->second < pref[i].closestLeft[1]) { pref[i].closestLeft[1] = itL->second; pref[i].leftParent[1] = seqs[j].getName(); -cout << "updating closest left to " << pref[i].leftParent[1] << endl; +//cout << "updating closest left to " << pref[i].leftParent[1] << endl; } -cout << "pref[" << j << "].closestLeft[1] = " << pref[j].closestLeft[1] << " parent = " << pref[j].leftParent[1] << endl; +//cout << "pref[" << j << "].closestLeft[1] = " << pref[j].closestLeft[1] << " parent = " << pref[j].leftParent[1] << endl; if (itL->second < pref[j].closestLeft[1]) { pref[j].closestLeft[1] = itL->second; pref[j].leftParent[1] = seqs[i].getName(); -cout << "updating closest left to " << pref[j].leftParent[1] << endl; +//cout << "updating closest left to " << pref[j].leftParent[1] << endl; } //are you the closest right sequence @@ -418,22 +429,25 @@ cout << "updating closest left to " << pref[j].leftParent[1] << endl; //calculate the dme + int count0 = 0; for (int i = 0; i < pref.size(); i++) { dme += pref[i].score[1]; if (pref[i].score[1] == 0.0) { count0++; } } float expectedPercent = 1 / (float) (pref.size() - count0); -cout << endl << "dme = " << dme << endl; +//cout << endl << "dme = " << dme << endl; //recalculate prefernences based on dme for (int i = 0; i < pref.size(); i++) { -cout << "unadjusted pref " << i << " = " << pref[i].score[1] << endl; +//cout << "unadjusted pref " << i << " = " << pref[i].score[1] << endl; // gives the actual percentage of the dme this seq adds pref[i].score[1] = pref[i].score[1] / dme; //how much higher or lower is this than expected pref[i].score[1] = pref[i].score[1] / expectedPercent; + //pref[i].score[1] = dme / (dme - 2 * pref[i].score[1]); + //so a non chimeric sequence would be around 1, and a chimeric would be signifigantly higher. -cout << "adjusted pref " << i << " = " << pref[i].score[1] << endl; +//cout << "adjusted pref " << i << " = " << pref[i].score[1] << endl; } //is this score bigger then the last score @@ -449,8 +463,6 @@ cout << "adjusted pref " << i << " = " << pref[i].score[1] << endl; pref[i].midpoint = mid; } - //total of preference scores across windows - //pref[i].score[0] += pref[i].score[1]; } } diff --git a/distancedb.cpp b/distancedb.cpp index 90b7724..30f9359 100644 --- a/distancedb.cpp +++ b/distancedb.cpp @@ -29,8 +29,7 @@ DistanceDB::DistanceDB(string fastaFileName, string distanceFileName) : Database mostSimSequenceVector.resize(numCandSeqs); for(int i=0;i> candidateSeqName >> closestMatch.seqName >> closestMatch.indexNumber >> closestMatch.simScore; -// getline(inputData, junk); + inputData >> candidateSeqName >> closestMatch.seqName >> closestMatch.indexNumber >> closestMatch.simScore; mostSimSequenceVector[i] = closestMatch; } mothurOut(toString(numCandSeqs)); mothurOutEndLine(); diff --git a/engine.cpp b/engine.cpp index 42938d8..2215e08 100644 --- a/engine.cpp +++ b/engine.cpp @@ -86,14 +86,6 @@ BatchEngine::BatchEngine(string path, string batchFileName){ openedBatch = openInputFile(batchFileName, inputBatchFile); globaldata->argv = path; - - - // char buffer = ' '; - // ifstream header("introtext.txt"); - // while(!header.eof()){ - // cout << buffer; - // buffer = header.get(); - // } } catch(exception& e) { errorOut(e, "BatchEngine", "BatchEngine"); @@ -127,7 +119,7 @@ bool BatchEngine::getInput(){ while(quitCommandCalled == 0){ if (inputBatchFile.eof()) { input = "quit()"; } - else { getline(inputBatchFile, input); } + else { input = getline(inputBatchFile); } diff --git a/fileoutput.cpp b/fileoutput.cpp index 63130a8..597a05a 100644 --- a/fileoutput.cpp +++ b/fileoutput.cpp @@ -27,7 +27,7 @@ void ThreeColumnFile::initFile(string label){ openInputFile(inName, inFile); string inputBuffer; - getline(inFile, inputBuffer); + inputBuffer = getline(inFile); outFile << inputBuffer << '\t' << label << "\tlci\thci" << endl; } @@ -51,7 +51,7 @@ void ThreeColumnFile::output(int nSeqs, vector data){ try { if(counter != 0){ string inputBuffer; - getline(inFile, inputBuffer); + inputBuffer = getline(inFile); outFile << inputBuffer << setprecision(4) << '\t' << data[0] << '\t' << data[1] << '\t' << data[2] << endl; } @@ -110,7 +110,7 @@ void ColumnFile::initFile(string label, vector tags){ openInputFile(inName, inFile); string inputBuffer; - getline(inFile, inputBuffer); + inputBuffer = getline(inFile); outFile << inputBuffer << '\t'; for(int i = 0; i < tags.size(); i++) { @@ -142,7 +142,7 @@ void ColumnFile::output(vector data){ if(counter != 0){ string inputBuffer; - getline(inFile, inputBuffer); + inputBuffer = getline(inFile); outFile << inputBuffer << '\t' << setprecision(6) << data[0] << setprecision(iters.length()); for (int i = 1; i< data.size(); i++) { @@ -210,7 +210,7 @@ void SharedThreeColumnFile::initFile(string label){ openInputFile(inName, inFile); string inputBuffer; - getline(inFile, inputBuffer); + inputBuffer = getline(inFile); outFile << inputBuffer << '\t' << label << "\tlci\thci" << endl; } @@ -234,7 +234,7 @@ void SharedThreeColumnFile::output(int nSeqs, vector data){ try { if(counter != 0){ string inputBuffer; - getline(inFile, inputBuffer); + inputBuffer = getline(inFile); outFile << inputBuffer << setprecision(4) << '\t' << data[0] << '\t' << data[1] << '\t' << data[2] << endl; } @@ -294,7 +294,7 @@ void OneColumnFile::initFile(string label){ openInputFile(inName, inFile); string inputBuffer; - getline(inFile, inputBuffer); + inputBuffer = getline(inFile); outFile << inputBuffer << '\t' << label << endl; } @@ -318,7 +318,7 @@ void OneColumnFile::output(int nSeqs, vector data){ try { if(counter != 0){ string inputBuffer; - getline(inFile, inputBuffer); + inputBuffer = getline(inFile); outFile << inputBuffer << setprecision(4) << '\t' << data[0] << endl; } @@ -376,7 +376,7 @@ void SharedOneColumnFile::initFile(string label){ openInputFile(inName, inFile); string inputBuffer; - getline(inFile, inputBuffer); + inputBuffer = getline(inFile); outFile << inputBuffer << '\t' << label << endl; @@ -409,7 +409,7 @@ void SharedOneColumnFile::output(int nSeqs, vector data){ } if(counter != 0){ string inputBuffer; - getline(inFile, inputBuffer); + inputBuffer = getline(inFile); outFile << inputBuffer << setprecision(2) << '\t' << dataOutput << endl; } diff --git a/mothur.h b/mothur.h index 2efdda8..2912433 100644 --- a/mothur.h +++ b/mothur.h @@ -167,6 +167,30 @@ inline int openOutputFileAppend(string fileName, ofstream& fileHandle){ } } +/***********************************************************************/ + +inline string getline(ifstream& fileHandle) { + try { + + string line = ""; + + while (!fileHandle.eof()) { + //get next character + char c = fileHandle.get(); + + //are you at the end of the line + if (c == 10 || c == 13){ break; } + else { line += c; } + } + + return line; + + } + catch(exception& e) { + cout << "Error in mothur function getline" << endl; + exit(1); + } +} /**************************************************************************************************/ diff --git a/systemcommand.cpp b/systemcommand.cpp index 5bc9b46..0820b05 100644 --- a/systemcommand.cpp +++ b/systemcommand.cpp @@ -19,23 +19,8 @@ SystemCommand::SystemCommand(string option){ if(option == "help") { help(); abort = true; } else { - //valid paramters for this command - string Array[] = {"command"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - - OptionParser parser(option); - map parameters = parser.getParameters(); - - ValidParameters validParameter; - - //check to make sure all parameters are valid for command - for (map::iterator it = parameters.begin(); it != parameters.end(); it++) { - if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } - } - - //check for required parameters - command = validParameter.validFile(parameters, "command", false); - if (command == "not found") { mothurOut("command is a required parameter."); mothurOutEndLine(); abort = true; } + if (option = "") { mothurOut("You must enter a command to run."); mothurOutEndLine(); abort = true; } + else { command = option; } } } @@ -49,10 +34,9 @@ SystemCommand::SystemCommand(string option){ void SystemCommand::help(){ try { mothurOut("The system command allows you to execute a system command from within mothur.\n"); - mothurOut("The system command parameter is command and it is required.\n"); - mothurOut("The system command should be in the following format: system(command=yourCommand).\n"); - mothurOut("Example system(command=clear).\n"); - mothurOut("Note: No spaces between parameter labels (i.e. command), '=' and parameters (i.e.yourCommand).\n\n"); + mothurOut("The system has no parameters.\n"); + mothurOut("The system command should be in the following format: system(yourCommand).\n"); + mothurOut("Example system(clear).\n"); } catch(exception& e) { errorOut(e, "SystemCommand", "help");