]> git.donarmstrong.com Git - mothur.git/commitdiff
added getline function to mothur and modified places where we use getline to use...
authorwestcott <westcott>
Thu, 9 Jul 2009 13:10:26 +0000 (13:10 +0000)
committerwestcott <westcott>
Thu, 9 Jul 2009 13:10:26 +0000 (13:10 +0000)
aligncommand.cpp
chimeraseqscommand.cpp
distancedb.cpp
engine.cpp
fileoutput.cpp
mothur.h
systemcommand.cpp

index 5af8e959a6caa3edd98a33a21fa680bd5815d2dc..2fda2529176bb263070c055965e74eaac732faf4 100644 (file)
@@ -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);       }
                                }
index b451721ca8a0d951b8e01ed5b398dd3b94dbe22a..a334ea31ccc2a7fd0334f687d3f84c16c00d3494 100644 (file)
@@ -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<SeqMap> left, vector<SeqMap>
                                
                                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];
                }
 
        }
index 90b7724ed709ac27f510cad9c928a8b48fca9675..30f93597983e9c83fdc1ffcf54fb1998dc6112d0 100644 (file)
@@ -29,8 +29,7 @@ DistanceDB::DistanceDB(string fastaFileName, string distanceFileName) : Database
        mostSimSequenceVector.resize(numCandSeqs);
        
        for(int i=0;i<numCandSeqs;i++){
-               inputData >> 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();
index 42938d8a0bf157e0d31a837134d477bc65dca9c3..2215e081af76c8c2ccb3064aebe8d04dc6a94818 100644 (file)
@@ -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); }
                        
                        
                        
index 63130a83ba6c850bc8db4ea720ba51a15d80ff81..597a05a6ad9a892caff5f0b6f69269ae6af4013d 100644 (file)
@@ -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<double> 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<string> 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<double> 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<double> 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<double> 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<double> data){
                        }
                        if(counter != 0){               
                                string inputBuffer;
-                               getline(inFile, inputBuffer);
+                               inputBuffer = getline(inFile);
 
                                outFile <<  inputBuffer << setprecision(2) << '\t' << dataOutput << endl;
                        }
index 2efdda8bda209ec303dd7e6bc1b8650b5eb65949..29124330420f1af5e8a7b5f54fb8f86689e20ee9 100644 (file)
--- 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);
+       }
+}
 
 /**************************************************************************************************/
 
index 5bc9b46e47522d38fe4a89f0119df8785a4d8d4d..0820b0521961224c04f3b7c6207f4fd3d490c5fd 100644 (file)
@@ -19,23 +19,8 @@ SystemCommand::SystemCommand(string option){
                if(option == "help") { help(); abort = true; }
                
                else {
-                       //valid paramters for this command
-                       string Array[] =  {"command"};
-                       vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-                       
-                       OptionParser parser(option);
-                       map<string,string> parameters = parser.getParameters();
-                       
-                       ValidParameters validParameter;
-                       
-                       //check to make sure all parameters are valid for command
-                       for (map<string,string>::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");