From 4884e09a6f1f67f9a57aafcef82e248a1c633956 Mon Sep 17 00:00:00 2001 From: Sarah Westcott Date: Fri, 13 Apr 2012 14:44:22 -0400 Subject: [PATCH] fixing out labels to match those in shared file. If shared file does not have column headers create them. --- indicatorcommand.cpp | 12 ++++++------ metastatscommand.cpp | 13 ++----------- otuassociationcommand.cpp | 6 ++---- sharedrabundfloatvector.cpp | 36 ++++++++++++++++++++++++++++-------- sharedrabundvector.cpp | 32 ++++++++++++++++++++++++++------ 5 files changed, 64 insertions(+), 35 deletions(-) diff --git a/indicatorcommand.cpp b/indicatorcommand.cpp index 94d5c84..97f480e 100644 --- a/indicatorcommand.cpp +++ b/indicatorcommand.cpp @@ -468,17 +468,17 @@ int IndicatorCommand::GetIndicatorSpecies(){ if (m->control_pressed) { out.close(); return 0; } - out << (j+1) << '\t' << indicatorValues[j] << '\t'; + out << m->currentBinLabels[j] << '\t' << indicatorValues[j] << '\t'; if (pValues[j] > (1/(float)iters)) { out << pValues[j] << endl; } else { out << "<" << (1/(float)iters) << endl; } if (pValues[j] <= 0.05) { - cout << "OTU" << j+1 << '\t' << indicatorValues[j] << '\t'; + cout << m->currentBinLabels[j] << '\t' << indicatorValues[j] << '\t'; string pValueString = "<" + toString((1/(float)iters)); if (pValues[j] > (1/(float)iters)) { pValueString = toString(pValues[j]); cout << pValues[j];} else { cout << "<" << (1/(float)iters); } - m->mothurOutJustToLog("OTU" + toString(j+1) + "\t" + toString(indicatorValues[j]) + "\t" + pValueString); + m->mothurOutJustToLog(m->currentBinLabels[j] + "\t" + toString(indicatorValues[j]) + "\t" + pValueString); m->mothurOutEndLine(); } } @@ -514,7 +514,7 @@ int IndicatorCommand::GetIndicatorSpecies(Tree*& T){ //print headings out << "TreeNode\t"; - for (int i = 0; i < numBins; i++) { out << "OTU" << (i+1) << "_IndValue" << '\t' << "pValue" << '\t'; } + for (int i = 0; i < numBins; i++) { out << m->currentBinLabels[i] << "_IndValue" << '\t' << "pValue" << '\t'; } out << endl; m->mothurOutEndLine(); m->mothurOut("Node\tSpecies\tIndicatorValue\tpValue\n"); @@ -671,11 +671,11 @@ int IndicatorCommand::GetIndicatorSpecies(Tree*& T){ } if (pValues[j] <= 0.05) { - cout << i+1 << "\tOTU" << j+1 << '\t' << indicatorValues[j] << '\t'; + cout << i+1 << '\t' << m->currentBinLabels[j] << '\t' << indicatorValues[j] << '\t'; string pValueString = "<" + toString((1/(float)iters)); if (pValues[j] > (1/(float)iters)) { pValueString = toString(pValues[j]); cout << pValues[j];} else { cout << "<" << (1/(float)iters); } - m->mothurOutJustToLog(toString(i) + "\tOTU" + toString(j+1) + "\t" + toString(indicatorValues[j]) + "\t" + pValueString); + m->mothurOutJustToLog(toString(i) + "\t" + m->currentBinLabels[j] + "\t" + toString(indicatorValues[j]) + "\t" + pValueString); m->mothurOutEndLine(); } } diff --git a/metastatscommand.cpp b/metastatscommand.cpp index 4744424..c5d349b 100644 --- a/metastatscommand.cpp +++ b/metastatscommand.cpp @@ -483,25 +483,16 @@ int MetaStatsCommand::driver(int start, int num, vector& th outputNames.pop_back(); }else { - ofstream outTemp; - string tempOut = outputDir + "data." + setA + "-" + setB + ".matrix"; - m->openOutputFile(tempOut, outTemp); - for (int i = 0; i < subset.size(); i++) { outTemp << '\t' << subset[i]->getGroup(); } - outTemp << endl; - - //fill data for (int j = 0; j < thisLookUp[0]->getNumBins(); j++) { //data[j] = new double[subset.size()]; data2[j].resize(subset.size(), 0.0); - outTemp << "OTU" << (j+1); + for (int i = 0; i < subset.size(); i++) { data2[j][i] = (subset[i]->getAbundance(j)); - outTemp << '\t' << subset[i]->getAbundance(j); } - outTemp << endl; } - outTemp.close(); + m->mothurOut("Comparing " + setA + " and " + setB + "..."); m->mothurOutEndLine(); //metastat_main(output, thisLookUp[0]->getNumBins(), subset.size(), threshold, iters, data, setACount); diff --git a/otuassociationcommand.cpp b/otuassociationcommand.cpp index eeefb41..0d41e63 100644 --- a/otuassociationcommand.cpp +++ b/otuassociationcommand.cpp @@ -308,8 +308,7 @@ int OTUAssociationCommand::process(vector& lookup){ else if (method == "kendall") { coef = linear.calcKendall(xy[i], xy[k], sig); } else { m->mothurOut("[ERROR]: invalid method, choices are spearman, pearson or kendall."); m->mothurOutEndLine(); m->control_pressed = true; } - if (m->binLabelsInFile.size() != 0) { out << m->binLabelsInFile[i] << '\t' << m->binLabelsInFile[k] << '\t' << coef << '\t' << sig << endl; } - else { out << i+1 << '\t' << k+1 << '\t' << coef << '\t' << sig << endl; } + out << m->binLabelsInFile[i] << '\t' << m->binLabelsInFile[k] << '\t' << coef << '\t' << sig << endl; } } @@ -437,8 +436,7 @@ int OTUAssociationCommand::process(vector& lookup){ else if (method == "kendall") { coef = linear.calcKendall(xy[i], xy[k], sig); } else { m->mothurOut("[ERROR]: invalid method, choices are spearman, pearson or kendall."); m->mothurOutEndLine(); m->control_pressed = true; } - if (m->binLabelsInFile.size() != 0) { out << m->binLabelsInFile[i] << '\t' << m->binLabelsInFile[k] << '\t' << coef << '\t' << sig << endl; } - else { out << i+1 << '\t' << k+1 << '\t' << coef << '\t' << sig << endl; } + out << m->binLabelsInFile[i] << '\t' << m->binLabelsInFile[k] << '\t' << coef << '\t' << sig << endl; } } diff --git a/sharedrabundfloatvector.cpp b/sharedrabundfloatvector.cpp index 9f6c156..b6d916a 100644 --- a/sharedrabundfloatvector.cpp +++ b/sharedrabundfloatvector.cpp @@ -48,7 +48,7 @@ SharedRAbundFloatVector::SharedRAbundFloatVector(ifstream& f) : DataVector(), ma //are we at the beginning of the file?? if (m->saveNextLabel == "") { f >> label; - + //is this a shared file that has headers if (label == "label") { //gets "group" @@ -67,20 +67,40 @@ SharedRAbundFloatVector::SharedRAbundFloatVector(ifstream& f) : DataVector(), ma if (m->control_pressed) { break; } string temp; iStringStream >> temp; m->gobble(iStringStream); - + m->binLabelsInFile.push_back(temp); } - f >> label; - } - }else { label = m->saveNextLabel; } + f >> label >> groupN >> num; + }else { + //read in first row since you know there is at least 1 group. + f >> groupN >> num; + + //make binlabels because we don't have any + string snumBins = toString(num); + m->binLabelsInFile.clear(); + for (int i = 0; i < num; i++) { + //if there is a bin label use it otherwise make one + string binLabel = "Otu"; + string sbinNumber = toString(i+1); + if (sbinNumber.length() < snumBins.length()) { + int diff = snumBins.length() - sbinNumber.length(); + for (int h = 0; h < diff; h++) { binLabel += "0"; } + } + binLabel += sbinNumber; + m->binLabelsInFile.push_back(binLabel); + } + } + }else { + label = m->saveNextLabel; + + //read in first row since you know there is at least 1 group. + f >> groupN >> num; + } //reset labels, currentLabels may have gotten changed as otus were eliminated because of group choices or sampling m->currentBinLabels = m->binLabelsInFile; - //read in first row since you know there is at least 1 group. - f >> groupN >> num; - holdLabel = label; //add new vector to lookup diff --git a/sharedrabundvector.cpp b/sharedrabundvector.cpp index 70b0960..3901650 100644 --- a/sharedrabundvector.cpp +++ b/sharedrabundvector.cpp @@ -95,16 +95,36 @@ SharedRAbundVector::SharedRAbundVector(ifstream& f) : DataVector(), maxRank(0), m->binLabelsInFile.push_back(temp); } - f >> label; - } - }else { label = m->saveNextLabel; } + f >> label >> groupN >> num; + }else { + //read in first row since you know there is at least 1 group. + f >> groupN >> num; + + //make binlabels because we don't have any + string snumBins = toString(num); + m->binLabelsInFile.clear(); + for (int i = 0; i < num; i++) { + //if there is a bin label use it otherwise make one + string binLabel = "Otu"; + string sbinNumber = toString(i+1); + if (sbinNumber.length() < snumBins.length()) { + int diff = snumBins.length() - sbinNumber.length(); + for (int h = 0; h < diff; h++) { binLabel += "0"; } + } + binLabel += sbinNumber; + m->binLabelsInFile.push_back(binLabel); + } + } + }else { + label = m->saveNextLabel; + + //read in first row since you know there is at least 1 group. + f >> groupN >> num; + } //reset labels, currentLabels may have gotten changed as otus were eliminated because of group choices or sampling m->currentBinLabels = m->binLabelsInFile; - //read in first row since you know there is at least 1 group. - f >> groupN >> num; - holdLabel = label; //add new vector to lookup -- 2.39.2