"DSTROOT[sdk=*]" = TARGET_BUILD_DIR;
GCC_DYNAMIC_NO_PIC = NO;
GCC_MODEL_TUNING = G5;
- GCC_OPTIMIZATION_LEVEL = 3;
+ GCC_OPTIMIZATION_LEVEL = 0;
"INSTALL_PATH[sdk=*]" = TARGET_BUILD_DIR;
PRODUCT_NAME = mothur;
SDKROOT = macosx;
DEPLOYMENT_LOCATION = YES;
DSTROOT = TARGET_BUILD_DIR;
GCC_MODEL_TUNING = G5;
- GCC_OPTIMIZATION_LEVEL = 3;
+ GCC_OPTIMIZATION_LEVEL = 0;
GCC_WARN_UNUSED_VALUE = YES;
PRODUCT_NAME = mothur;
SDKROOT = macosx;
m->mothurOut(list->getLabel()); m->mothurOutEndLine();
//for each bin in the list vector
+ vector<string> binLabels = list->getLabels();
for (int i = 0; i < list->size(); i++) {
if (m->control_pressed) { return 1; }
}
if (groups.size() != 0) { groupInfo += groups[groups.size()-1]; }
else { groupInfo = "not found"; }
- name = name + "\t" + groupInfo + "\t" + toString(i+1)+ "\tNumRep=" + toString(ct.getNumSeqs(name));
+ name = name + "\t" + groupInfo + "\t" + binLabels[i] + "\tNumRep=" + toString(ct.getNumSeqs(name));
out << ">" << name << endl;
out << sequence << endl;
}else {
- name = name + "\t" + toString(i+1) + "\tNumRep=" + toString(ct.getNumSeqs(name));
+ name = name + "\t" + binLabels[i] + "\tNumRep=" + toString(ct.getNumSeqs(name));
out << ">" << name << endl;
out << sequence << endl;
}
if (sequence != "not found") {
//if you don't have groups
if (groupfile == "") {
- name = name + "\t" + toString(i+1);
+ name = name + "\t" + binLabels[i];
out << ">" << name << endl;
out << sequence << endl;
}else {//if you do have groups
m->mothurOut(name + " is missing from your group file. Please correct. "); m->mothurOutEndLine();
return 1;
}else{
- name = name + "\t" + group + "\t" + toString(i+1);
+ name = name + "\t" + group + "\t" + binLabels[i];
out << ">" << name << endl;
out << sequence << endl;
}
//for each bin in the list vector
string snumBins = toString(processList->getNumBins());
+ vector<string> binLabels = processList->getLabels();
for (int i = 0; i < processList->getNumBins(); i++) {
if (m->control_pressed) { break; }
names = findConsensusTaxonomy(thisNames, size, conTax);
if (m->control_pressed) { break; }
-
- //output to new names file
- 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;
- out << binLabel << '\t' << size << '\t' << conTax << endl;
+ out << binLabels[i] << '\t' << size << '\t' << conTax << endl;
string noConfidenceConTax = conTax;
m->removeConfidences(noConfidenceConTax);
if (m->control_pressed) { break; }
- //output to new names file
- 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;
- (*outs[groupIndex[itParsed->first]]) << binLabel << '\t' << size << '\t' << conTax << endl;
+ (*outs[groupIndex[itParsed->first]]) << binLabels[i] << '\t' << size << '\t' << conTax << endl;
string noConfidenceConTax = conTax;
m->removeConfidences(noConfidenceConTax);
}
m->openOutputFile(listFileName, listFile);
outputNames.push_back(listFileName); outputTypes["list"].push_back(listFileName);
-
+ list->printHeaders(listFile);
time_t estart = time(NULL);
float previousDist = 0.00000;
}
m->openOutputFile(listFileName, listFile);
outputNames.push_back(listFileName); outputTypes["list"].push_back(listFileName);
+ list->printHeaders(listFile);
float previousDist = 0.00000;
float rndPreviousDist = 0.00000;
m->openOutputFile(listFileName, outList);
outputNames.push_back(listFileName); outputTypes["list"].push_back(listFileName);
-
map<float, int>::iterator itLabel;
+
+ //clears out junk for autocompleting of list files above. Perhaps there is a beter way to handle this from within the data structure?
+ m->printedListHeaders = false;
//for each label needed
for(itLabel = userLabels.begin(); itLabel != userLabels.end(); itLabel++) {
rabund->print(outRabund);
}
//outList << endl;
+ if (!m->printedListHeaders) {
+ m->listBinLabelsInFile.clear(); completeList.printHeaders(outList); }
completeList.print(outList);
if (rabund != NULL) { delete rabund; }
helpString += "The all parameter is used to specify if you want the estimate of all your groups together. This estimate can only be made for sharedsobs and sharedchao calculators. The default is false.\n";
helpString += "If you use sharedchao and run into memory issues, set all to false. \n";
helpString += "The groups parameter allows you to specify which of the groups in your groupfile you would like analyzed. You must enter at least 2 valid groups.\n";
- helpString += "Note: No spaces between parameter labels (i.e. list), '=' and parameters (i.e.yourListfile).\n";
+ helpString += "Note: No spaces between parameter labels (i.e. shared), '=' and parameters (i.e.yourSharedfile).\n";
return helpString;
}
catch(exception& e) {
outSummary << "OTU#\tPositioninAlignment\tA\tT\tG\tC\tGap\tNumberofSeqs\tConsensusBase" << endl;
string snumBins = toString(list->getNumBins());
+ vector<string> binLabels = list->getLabels();
for (int i = 0; i < list->getNumBins(); i++) {
if (m->control_pressed) { outSummary.close(); outName.close(); outFasta.close(); return 0; }
string bin = list->get(i);
string consSeq = getConsSeq(bin, outSummary, i);
-
- string seqName = "Otu";
- string sbinNumber = toString(i+1);
- if (sbinNumber.length() < snumBins.length()) {
- int diff = snumBins.length() - sbinNumber.length();
- for (int h = 0; h < diff; h++) { seqName += "0"; }
- }
- seqName += sbinNumber;
- outFasta << ">" << seqName << endl << consSeq << endl;
- outName << seqName << '\t' << seqName << "," << bin << endl;
+ outFasta << ">" << binLabels[i] << endl << consSeq << endl;
+ outName << binLabels[i] << '\t' << binLabels[i] << "," << bin << endl;
}
outSummary.close(); outName.close(); outFasta.close();
//for each otu
for (int i = 0; i < lookupFloat[0]->getNumBins(); i++) {
- if (metadatafile == "") { out << m->currentBinLabels[i]; }
+ if (metadatafile == "") { out << m->currentSharedBinLabels[i]; }
else { out << metadataLabels[i]; }
//find the averages this otu - Y
//for each otu
for (int i = 0; i < lookupFloat[0]->getNumBins(); i++) {
- if (metadatafile == "") { out << m->currentBinLabels[i]; }
+ if (metadatafile == "") { out << m->currentSharedBinLabels[i]; }
else { out << metadataLabels[i]; }
//find the ranks of this otu - Y
//for each otu
for (int i = 0; i < lookupFloat[0]->getNumBins(); i++) {
- if (metadatafile == "") { out << m->currentBinLabels[i]; }
+ if (metadatafile == "") { out << m->currentSharedBinLabels[i]; }
else { out << metadataLabels[i]; }
//find the ranks of this otu - Y
for (int h = 0; h < diff; h++) { binLabel += "0"; }
}
binLabel += sbinNumber;
- if (i < m->currentBinLabels.size()) { binLabel = m->currentBinLabels[i]; }
+ if (i < m->currentSharedBinLabels.size()) { binLabel = m->currentSharedBinLabels[i]; }
newBinLabels.push_back(binLabel);
}
for (int j = 0; j < thislookup.size(); j++) { delete thislookup[j]; }
thislookup = newLookup;
- m->currentBinLabels = newBinLabels;
+ m->currentSharedBinLabels = newBinLabels;
return 0;
header += "repSeqName\trepSeq\tOTUConTaxonomy";
out << header << endl;
+ vector<string> binLabels = list->getLabels();
for (int i = 0; i < list->getNumBins(); i++) {
+ int index = findIndex(otuLabels, binLabels[i]);
+ if (index == -1) { m->mothurOut("[ERROR]: " + binLabels[i] + " is not in your constaxonomy file, aborting.\n"); m->control_pressed = true; }
+
if (m->control_pressed) { break; }
- out << otuLabels[i] << '\t';
+ out << otuLabels[index] << '\t';
vector<string> binNames;
string bin = list->get(i);
map<string, string>::iterator it = repNames.find(bin);
if (it == repNames.end()) {
- m->mothurOut("[ERROR: OTU " + otuLabels[i] + " is not in the repnames file. Make sure you are using files for the same distance.\n"); m->control_pressed = true; break;
+ m->mothurOut("[ERROR: OTU " + otuLabels[index] + " is not in the repnames file. Make sure you are using files for the same distance.\n"); m->control_pressed = true; break;
}else { seqRepName = it->second; numSeqsRep = binNames.size(); }
//sanity check
- if (binNames.size() != classifyOtuSizes[i]) {
- m->mothurOut("[ERROR: OTU " + otuLabels[i] + " contains " + toString(binNames.size()) + " sequence, but the rep and taxonomy files indicated this OTU should have " + toString(classifyOtuSizes[i]) + ". Make sure you are using files for the same distance.\n"); m->control_pressed = true; break;
+ if (binNames.size() != classifyOtuSizes[index]) {
+ m->mothurOut("[ERROR: OTU " + otuLabels[index] + " contains " + toString(binNames.size()) + " sequence, but the rep and taxonomy files indicated this OTU should have " + toString(classifyOtuSizes[index]) + ". Make sure you are using files for the same distance.\n"); m->control_pressed = true; break;
}
}else {
//find rep sequence in bin
}
if (seqRepName == "") {
- m->mothurOut("[ERROR: OTU " + otuLabels[i] + " is not in the count file. Make sure you are using files for the same distance.\n"); m->control_pressed = true; break;
+ m->mothurOut("[ERROR: OTU " + otuLabels[index] + " is not in the count file. Make sure you are using files for the same distance.\n"); m->control_pressed = true; break;
}
if (numSeqsRep != classifyOtuSizes[i]) {
- m->mothurOut("[ERROR: OTU " + otuLabels[i] + " contains " + toString(numSeqsRep) + " sequence, but the rep and taxonomy files indicated this OTU should have " + toString(classifyOtuSizes[i]) + ". Make sure you are using files for the same distance.\n"); m->control_pressed = true; break;
+ m->mothurOut("[ERROR: OTU " + otuLabels[index] + " contains " + toString(numSeqsRep) + " sequence, but the rep and taxonomy files indicated this OTU should have " + toString(classifyOtuSizes[index]) + ". Make sure you are using files for the same distance.\n"); m->control_pressed = true; break;
}
}
}else { out << numSeqsRep << '\t'; }
//output repSeq
- out << seqRepName << '\t' << seqs[i].getAligned() << '\t' << taxonomies[i] << endl;
+ out << seqRepName << '\t' << seqs[index].getAligned() << '\t' << taxonomies[index] << endl;
}
if (m->control_pressed) { break; }
- int index = findIndex(otuLabels, m->currentBinLabels[h]);
- if (index == -1) { m->mothurOut("[ERROR]: " + m->currentBinLabels[h] + " is not in your constaxonomy file, aborting.\n"); m->control_pressed = true; }
+ int index = findIndex(otuLabels, m->currentSharedBinLabels[h]);
+ if (index == -1) { m->mothurOut("[ERROR]: " + m->currentSharedBinLabels[h] + " is not in your constaxonomy file, aborting.\n"); m->control_pressed = true; }
if (m->control_pressed) { break; }
//sanity check
if (totalAbund != classifyOtuSizes[index]) {
- m->mothurOut("[WARNING]: OTU " + m->currentBinLabels[h] + " contains " + toString(totalAbund) + " sequence, but the rep and taxonomy files indicated this OTU should have " + toString(classifyOtuSizes[index]) + ". Make sure you are using files for the same distance.\n"); //m->control_pressed = true; break;
+ m->mothurOut("[WARNING]: OTU " + m->currentSharedBinLabels[h] + " contains " + toString(totalAbund) + " sequence, but the rep and taxonomy files indicated this OTU should have " + toString(classifyOtuSizes[index]) + ". Make sure you are using files for the same distance.\n"); //m->control_pressed = true; break;
}
//output repSeq
public:
DataVector(){ m = MothurOut::getInstance(); }// : maxRank(0), numBins(0), numSeqs(0){};
- DataVector(string l) : label(l) {};
- DataVector(const DataVector& dv) : label(dv.label){};//, maxRank(dv.maxRank), numBins(dv.numBins), numSeqs(dv.numSeqs) {};
- DataVector(ifstream&);
- DataVector(ifstream&, GroupMap*);
+ DataVector(string l) : label(l) { m = MothurOut::getInstance();};
+ DataVector(const DataVector& dv) : label(dv.label){ m = MothurOut::getInstance();};//, maxRank(dv.maxRank), numBins(dv.numBins), numSeqs(dv.numSeqs) {};
+ DataVector(ifstream&) {m = MothurOut::getInstance();}
+ DataVector(ifstream&, GroupMap*){m = MothurOut::getInstance();}
virtual ~DataVector(){};
// virtual int getNumBins() { return numBins; }
mout->clearAllGroups();
mout->Treenames.clear();
mout->saveNextLabel = "";
- mout->printedHeaders = false;
- mout->commandInputsConvertError = false;
- mout->currentBinLabels.clear();
- mout->binLabelsInFile.clear();
+ mout->commandInputsConvertError = false;
+ mout->printedSharedHeaders = false;
+ mout->currentSharedBinLabels.clear();
+ mout->sharedBinLabelsInFile.clear();
+ mout->printedListHeaders = false;
+ mout->listBinLabelsInFile.clear();
Command* command = cFactory->getCommand(commandName, options);
if (mout->commandInputsConvertError) { quitCommandCalled = 2; }
mout->clearAllGroups();
mout->Treenames.clear();
mout->saveNextLabel = "";
- mout->printedHeaders = false;
mout->commandInputsConvertError = false;
- mout->currentBinLabels.clear();
- mout->binLabelsInFile.clear();
+ mout->printedSharedHeaders = false;
+ mout->currentSharedBinLabels.clear();
+ mout->sharedBinLabelsInFile.clear();
+ mout->printedListHeaders = false;
+ mout->listBinLabelsInFile.clear();
Command* command = cFactory->getCommand(commandName, options);
mout->clearAllGroups();
mout->Treenames.clear();
mout->saveNextLabel = "";
- mout->printedHeaders = false;
- mout->commandInputsConvertError = false;
- mout->currentBinLabels.clear();
- mout->binLabelsInFile.clear();
+ mout->commandInputsConvertError = false;
+ mout->printedSharedHeaders = false;
+ mout->currentSharedBinLabels.clear();
+ mout->sharedBinLabelsInFile.clear();
+ mout->printedListHeaders = false;
+ mout->listBinLabelsInFile.clear();
Command* command = cFactory->getCommand(commandName, options);
if (mout->commandInputsConvertError) { quitCommandCalled = 2; }
try {
//save mothurOut's binLabels to restore for next label
- vector<string> saveBinLabels = m->currentBinLabels;
+ vector<string> saveBinLabels = m->currentSharedBinLabels;
map<string, string> variables;
variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(sharedfile));
m->openOutputFile(outputFileName, out);
outputTypes["shared"].push_back(outputFileName); outputNames.push_back(outputFileName);
- m->currentBinLabels = filteredLabels;
+ m->currentSharedBinLabels = filteredLabels;
filteredLookup[0]->printHeaders(out);
//save mothurOut's binLabels to restore for next label
- m->currentBinLabels = saveBinLabels;
+ m->currentSharedBinLabels = saveBinLabels;
for (int j = 0; j < filteredLookup.size(); j++) { delete filteredLookup[j]; }
for (int k = 0; k < counts[j]; k++) { table[j][k]++; }
if ((abund == -1) && (samples != -1)) { //we want all OTUs with this number of samples
- if (counts[j] >= samples) { otuNames[j].push_back(m->currentBinLabels[i]); }
+ if (counts[j] >= samples) { otuNames[j].push_back(m->currentSharedBinLabels[i]); }
}else if ((abund != -1) && (samples == -1)) { //we want all OTUs with this relabund
if (j == abund) {
- for (int k = 0; k < counts[j]; k++) { otuNames[k+1].push_back(m->currentBinLabels[i]); }
+ for (int k = 0; k < counts[j]; k++) { otuNames[k+1].push_back(m->currentSharedBinLabels[i]); }
}
}else if ((abund != -1) && (samples != -1)) { //we want only OTUs with this relabund for this number of samples
if ((j == abund) && (counts[j] >= samples)) {
- otuNames[j].push_back(m->currentBinLabels[i]);
+ otuNames[j].push_back(m->currentSharedBinLabels[i]);
}
}
}
else if (type == "name") { pattern = "[filename],pick,[extension]"; }
else if (type == "group") { pattern = "[filename],pick,[extension]"; }
else if (type == "count") { pattern = "[filename],pick,[extension]"; }
- else if (type == "list") { pattern = "[filename],pick,[extension]"; }
+ else if (type == "list") { pattern = "[filename],[tag],pick,[extension]"; }
else if (type == "shared") { pattern = "[filename],[tag],pick,[extension]"; }
else if (type == "design") { pattern = "[filename],pick,[extension]"; }
else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; }
map<string, string> variables;
variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(listfile));
variables["[extension]"] = m->getExtension(listfile);
- string outputFileName = getOutputFileName("list", variables);
-
- ofstream out;
- m->openOutputFile(outputFileName, out);
ifstream in;
m->openInputFile(listfile, in);
while(!in.eof()){
selectedCount = 0;
-
+
//read in list vector
ListVector list(in);
+
+ variables["[tag]"] = list.getLabel();
+ string outputFileName = getOutputFileName("list", variables);
+
+ ofstream out;
+ m->openOutputFile(outputFileName, out);
+ outputTypes["list"].push_back(outputFileName); outputNames.push_back(outputFileName);
+
+ vector<string> binLabels = list.getLabels();
+ vector<string> newBinLabels;
//make a new list vector
ListVector newList;
//parse out names that are in accnos file
string binnames = list.get(i);
+ vector<string> thisBinNames;
+ m->splitAtComma(binnames, thisBinNames);
string newNames = "";
- while (binnames.find_first_of(',') != -1) {
- string name = binnames.substr(0,binnames.find_first_of(','));
- binnames = binnames.substr(binnames.find_first_of(',')+1, binnames.length());
-
- //if that name is in the .accnos file, add it
+ for (int j = 0; j < thisBinNames.size(); j++) {
+ string name = thisBinNames[j];
+
+ //if that name is in the .accnos file, add it
if (names.count(name) != 0) { newNames += name + ","; selectedCount++; }
else{
//if you are not in the accnos file check if you are a name that needs to be changed
selectedCount++;
}
}
- }
-
- //get last name
- if (names.count(binnames) != 0) { newNames += binnames + ","; selectedCount++; }
- else{
- //if you are not in the accnos file check if you are a name that needs to be changed
- map<string, string>::iterator it = uniqueToRedundant.find(binnames);
- if (it != uniqueToRedundant.end()) {
- newNames += it->second + ",";
- selectedCount++;
- }
- }
-
+ }
+
//if there are names in this bin add to new list
if (newNames != "") {
newNames = newNames.substr(0, newNames.length()-1); //rip off extra comma
- newList.push_back(newNames);
+ newList.push_back(newNames);
+ newBinLabels.push_back(binLabels[i]);
}
}
//print new listvector
if (newList.getNumBins() != 0) {
wroteSomething = true;
+ newList.setLabels(newBinLabels);
+ newList.printHeaders(out);
newList.print(out);
}
m->gobble(in);
+ out.close();
}
- in.close();
- out.close();
+ in.close();
if (wroteSomething == false) { m->mothurOut("Your file does NOT contain sequences from the groups you wish to get."); m->mothurOutEndLine(); }
- outputTypes["list"].push_back(outputFileName); outputNames.push_back(outputFileName);
m->mothurOut("Selected " + toString(selectedCount) + " sequences from your list file."); m->mothurOutEndLine();
else if (type == "name") { pattern = "[filename],pick,[extension]"; }
else if (type == "group") { pattern = "[filename],pick,[extension]"; }
else if (type == "count") { pattern = "[filename],pick,[extension]"; }
- else if (type == "list") { pattern = "[filename],pick,[extension]-[filename],[distance],pick,[extension]"; }
+ else if (type == "list") { pattern = "[filename],[distance],pick,[extension]"; }
else if (type == "shared") { pattern = "[filename],[distance],pick,[extension]"; }
else if (type == "alignreport") { pattern = "[filename],pick.align.report"; }
else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; }
map<string, string> variables;
variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(listfile));
variables["[extension]"] = m->getExtension(listfile);
- string outputFileName = getOutputFileName("list", variables);
- ofstream out;
- m->openOutputFile(outputFileName, out);
-
+
ifstream in;
m->openInputFile(listfile, in);
bool wroteSomething = false;
while(!in.eof()){
-
- if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outputFileName); return 0; }
//read in list vector
ListVector list(in);
//make a new list vector
ListVector newList;
newList.setLabel(list.getLabel());
+
+ variables["[distance]"] = list.getLabel();
+ string outputFileName = getOutputFileName("list", variables);
+
+ ofstream out;
+ m->openOutputFile(outputFileName, out);
+ outputTypes["list"].push_back(outputFileName); outputNames.push_back(outputFileName);
+
+ if (m->control_pressed) { in.close(); out.close(); return 0; }
+
+ vector<string> binLabels = list.getLabels();
+ vector<string> newBinLabels;
//for each bin
for (int i = 0; i < list.getNumBins(); i++) {
//if there are names in this bin add to new list
if (newNames != "") {
newNames = newNames.substr(0, newNames.length()-1); //rip off extra comma
- newList.push_back(newNames);
+ newList.push_back(newNames);
+ newBinLabels.push_back(binLabels[i]);
}
}
//print new listvector
if (newList.getNumBins() != 0) {
wroteSomething = true;
+ newList.setLabels(newBinLabels);
+ newList.printHeaders(out);
newList.print(out);
}
m->gobble(in);
+ out.close();
}
in.close();
- out.close();
+
if (wroteSomething == false) { m->mothurOut("Your file contains does not contain any sequences from " + taxons + "."); m->mothurOutEndLine(); }
- outputNames.push_back(outputFileName); outputTypes["list"].push_back(outputFileName);
return 0;
bool wroteSomething = false;
string snumBins = toString(list->getNumBins());
+ vector<string> binLabels = list->getLabels();
+ vector<string> newBinLabels;
for (int i = 0; i < list->getNumBins(); i++) {
if (m->control_pressed) { delete list; return 0;}
if (names.count(m->getSimpleLabel(otuLabel)) != 0) {
selectedCount++;
newList.push_back(list->get(i));
+ newBinLabels.push_back(binLabels[i]);
}
}
//print new listvector
if (newList.getNumBins() != 0) {
wroteSomething = true;
+ newList.setLabels(newBinLabels);
+ newList.printHeaders(out);
newList.print(out);
}
out.close();
if (m->control_pressed) { for (int j = 0; j < newLookup.size(); j++) { delete newLookup[j]; } for (int j = 0; j < lookup.size(); j++) { delete lookup[j]; } return 0; }
//is this otu on the list
- if (names.count(m->getSimpleLabel(m->currentBinLabels[i])) != 0) {
+ if (names.count(m->getSimpleLabel(m->currentSharedBinLabels[i])) != 0) {
numSelected++; wroteSomething = true;
- newLabels.push_back(m->currentBinLabels[i]);
+ newLabels.push_back(m->currentSharedBinLabels[i]);
for (int j = 0; j < newLookup.size(); j++) { //add this OTU to the new lookup
newLookup[j]->push_back(lookup[j]->getAbundance(i), lookup[j]->getGroup());
}
for (int j = 0; j < lookup.size(); j++) { delete lookup[j]; }
- m->currentBinLabels = newLabels;
+ m->currentSharedBinLabels = newLabels;
newLookup[0]->printHeaders(out);
m->mothurOut(list->getLabel()); m->mothurOutEndLine();
//for each bin in the list vector
+ vector<string> binLabels = list->getLabels();
for (int i = 0; i < list->getNumBins(); i++) {
if (m->control_pressed) { break; }
binnames = list->get(i);
if (sort == "otu") {
- out << i+1 << '\t' << binnames << endl;
+ out << binLabels[i] << '\t' << binnames << endl;
}else{ //sort = name
vector<string> names;
m->splitAtComma(binnames, names);
for (int j = 0; j < names.size(); j++) {
- out << names[j] << '\t' << i+1 << endl;
+ out << names[j] << '\t' << binLabels[i] << endl;
}
}
}
outputNames.push_back(matrixName); outputTypes["matrix"].push_back(matrixName);
findQ.printZMatrix(matrixName, thisGroups);
- findQ.printRelAbund(relabund, m->currentBinLabels);
+ findQ.printRelAbund(relabund, m->currentSharedBinLabels);
if(optimizegap != -1 && (numPartitions - minPartition) >= optimizegap && numPartitions >= minpartitions){
string tempDoneFile = m->getRootName(m->getSimpleName(sharedfile)) + toString(processID) + ".done.temp";
if (m->control_pressed) { for (int j = 0; j < newLookup.size(); j++) { delete newLookup[j]; } for (int j = 0; j < lookup.size(); j++) { delete lookup[j]; } return 0; }
//is this otu on the list
- if (labels.count(m->getSimpleLabel(m->currentBinLabels[i])) != 0) {
+ if (labels.count(m->getSimpleLabel(m->currentSharedBinLabels[i])) != 0) {
numSelected++; wroteSomething = true;
- newLabels.push_back(m->currentBinLabels[i]);
+ newLabels.push_back(m->currentSharedBinLabels[i]);
for (int j = 0; j < newLookup.size(); j++) { //add this OTU to the new lookup
newLookup[j]->push_back(lookup[j]->getAbundance(i), lookup[j]->getGroup());
}
for (int j = 0; j < lookup.size(); j++) { delete lookup[j]; }
- m->currentBinLabels = newLabels;
+ m->currentSharedBinLabels = newLabels;
newLookup[0]->printHeaders(out);
bool wroteSomething = false;
string snumBins = toString(list->getNumBins());
+ vector<string> binLabels = list->getLabels();
+ vector<string> newLabels;
for (int i = 0; i < list->getNumBins(); i++) {
if (m->control_pressed) { delete list; return 0;}
- //create a label for this otu
- string otuLabel = "Otu";
- string sbinNumber = toString(i+1);
- if (sbinNumber.length() < snumBins.length()) {
- int diff = snumBins.length() - sbinNumber.length();
- for (int h = 0; h < diff; h++) { otuLabel += "0"; }
- }
- otuLabel += sbinNumber;
-
- if (labels.count(m->getSimpleLabel(otuLabel)) != 0) {
+ if (labels.count(m->getSimpleLabel(binLabels[i])) != 0) {
selectedCount++;
newList.push_back(list->get(i));
+ newLabels.push_back(binLabels[i]);
}
}
//print new listvector
if (newList.getNumBins() != 0) {
wroteSomething = true;
+ newList.setLabels(newLabels);
+ newList.printHeaders(out);
newList.print(out);
}
out.close();
//**********************************************************************************************************************
int GetOtusCommand::readListGroup(){
try {
- string thisOutputDir = outputDir;
+ InputData* input = new InputData(listfile, "list");
+ ListVector* list = input->getListVector();
+ string lastLabel = list->getLabel();
+
+ //using first label seen if none is provided
+ if (label == "") { label = lastLabel; }
+
+ string thisOutputDir = outputDir;
if (outputDir == "") { thisOutputDir += m->hasPath(listfile); }
- map<string, string> variables;
+ map<string, string> variables;
variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(listfile));
variables["[tag]"] = label;
variables["[extension]"] = m->getExtension(listfile);
ofstream out;
m->openOutputFile(outputFileName, out);
-
- string GroupOutputDir = outputDir;
+
+ string GroupOutputDir = outputDir;
if (outputDir == "") { GroupOutputDir += m->hasPath(groupfile); }
variables["[filename]"] = GroupOutputDir + m->getRootName(m->getSimpleName(groupfile));
variables["[extension]"] = m->getExtension(groupfile);
ofstream outGroup;
m->openOutputFile(outputGroupFileName, outGroup);
-
- InputData* input = new InputData(listfile, "list");
- ListVector* list = input->getListVector();
- string lastLabel = list->getLabel();
-
- //using first label seen if none is provided
- if (label == "") { label = lastLabel; }
+
//if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
set<string> labels; labels.insert(label);
int numOtus = 0;
//for each bin
+ vector<string> binLabels = list->getLabels();
+ vector<string> newBinLabels;
for (int i = 0; i < list->getNumBins(); i++) {
if (m->control_pressed) { return 0; }
//if there are sequences from the groups we want in this bin add to new list, output to groupfile
if (keepBin) {
- newList.push_back(binnames);
+ newList.push_back(binnames);
+ newBinLabels.push_back(binLabels[i]);
outGroup << groupFileOutput;
numOtus++;
}
//print new listvector
if (newList.getNumBins() != 0) {
wroteSomething = true;
- newList.print(out);
+ newList.setLabels(newBinLabels);
+ newList.printHeaders(out);
+ newList.print(out);
}
m->mothurOut(newList.getLabel() + " - selected " + toString(numOtus) + " of the " + toString(list->getNumBins()) + " OTUs."); m->mothurOutEndLine();
if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){
m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
- if (!m->printedHeaders) { lookup[0]->printHeaders(out); }
+ if (!m->printedSharedHeaders) { lookup[0]->printHeaders(out); }
getRelAbundance(lookup, out);
processedLabels.insert(lookup[0]->getLabel());
for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
lookup = input->getSharedRAbundVectors(lastLabel);
m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
- if (!m->printedHeaders) { lookup[0]->printHeaders(out); }
+ if (!m->printedSharedHeaders) { lookup[0]->printHeaders(out); }
getRelAbundance(lookup, out);
processedLabels.insert(lookup[0]->getLabel());
lookup = input->getSharedRAbundVectors(lastLabel);
m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
- if (!m->printedHeaders) { lookup[0]->printHeaders(out); }
+ if (!m->printedSharedHeaders) { lookup[0]->printHeaders(out); }
getRelAbundance(lookup, out);
for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
else if (type == "name") { pattern = "[filename],pick,[extension]"; }
else if (type == "group") { pattern = "[filename],pick,[extension]"; }
else if (type == "count") { pattern = "[filename],pick,[extension]"; }
- else if (type == "list") { pattern = "[filename],pick,[extension]"; }
+ else if (type == "list") { pattern = "[filename],[distance],pick,[extension]"; }
else if (type == "qfile") { pattern = "[filename],pick,[extension]"; }
else if (type == "accnosreport") { pattern = "[filename],pick.accnos.report"; }
else if (type == "alignreport") { pattern = "[filename],pick.align.report"; }
map<string, string> variables;
variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(listfile));
variables["[extension]"] = m->getExtension(listfile);
- string outputFileName = getOutputFileName("list", variables);
- ofstream out;
- m->openOutputFile(outputFileName, out);
ifstream in;
m->openInputFile(listfile, in);
while(!in.eof()){
selectedCount = 0;
-
- if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outputFileName); return 0; }
//read in list vector
ListVector list(in);
//make a new list vector
ListVector newList;
newList.setLabel(list.getLabel());
+
+ variables["[distance]"] = list.getLabel();
+ string outputFileName = getOutputFileName("list", variables);
+
+ ofstream out;
+ m->openOutputFile(outputFileName, out);
+ outputTypes["list"].push_back(outputFileName); outputNames.push_back(outputFileName);
+
+ vector<string> binLabels = list.getLabels();
+ vector<string> newBinLabels;
+
+ if (m->control_pressed) { in.close(); out.close(); return 0; }
//for each bin
for (int i = 0; i < list.getNumBins(); i++) {
//if there are names in this bin add to new list
if (newNames != "") {
newNames = newNames.substr(0, newNames.length()-1); //rip off extra comma
- newList.push_back(newNames);
+ newList.push_back(newNames);
+ newBinLabels.push_back(binLabels[i]);
}
}
//print new listvector
if (newList.getNumBins() != 0) {
wroteSomething = true;
+ newList.setLabels(newBinLabels);
+ newList.printHeaders(out);
newList.print(out);
}
m->gobble(in);
+ out.close();
}
in.close();
- out.close();
+
if (wroteSomething == false) { m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine(); }
- outputNames.push_back(outputFileName); outputTypes["list"].push_back(outputFileName);
m->mothurOut("Selected " + toString(selectedCount) + " sequences from your list file."); m->mothurOutEndLine();
int num = 0;
//go through each bin, find out if shared
+ vector<string> binLabels = shared->getLabels();
for (int i = 0; i < shared->getNumBins(); i++) {
if (m->control_pressed) { outNames.close(); m->mothurRemove(outputFileNames); return 0; }
//find group
string seqGroup = groupMap->getGroup(name);
if (output != "accnos") {
- namesOfSeqsInThisBin.push_back((name + "|" + seqGroup + "|" + toString(i+1)));
+ namesOfSeqsInThisBin.push_back((name + "|" + seqGroup + "|" + binLabels[i]));
}else { namesOfSeqsInThisBin.push_back(name); }
if (seqGroup == "not found") { m->mothurOut(name + " is not in your groupfile. Please correct."); m->mothurOutEndLine(); exit(1); }
for(int j = 0; j < lookup.size(); j++) {
string seqGroup = lookup[j]->getGroup();
- string name = m->currentBinLabels[i];
+ string name = m->currentSharedBinLabels[i];
if (lookup[j]->getAbundance(i) != 0) {
if (output != "accnos") {
}else{
m->mothurOut("Error: no list vector!"); m->mothurOutEndLine(); return 0;
}
-
+
+ list->printHeaders(listFile);
+
float previousDist = 0.00000;
float rndPreviousDist = 0.00000;
oldRAbund = *rabund;
}
//sort lookup so shared bins are on top
- vector<string> sortedLabels = m->currentBinLabels;
+ vector<string> sortedLabels = m->currentSharedBinLabels;
if (sorted != "none") { sortedLabels = sortSharedVectors(lookup); }
vector<vector<string> > scaleRelAbund;
map<int, int> place; //spot in lookup where you insert shared by, ie, 3 -> 2 if they are shared by 3 inset into location 2.
map<int, int>::iterator it;
- vector<string> sortedLabels = m->currentBinLabels;
+ vector<string> sortedLabels = m->currentSharedBinLabels;
/****************** find order of otus **********************/
if (sorted == "shared") {
int newAbund = looktemp[j]->getAbundance(i); // 1 -> 3
lookup[j]->set(place[i], newAbund, looktemp[j]->getGroup()); //binNumber, abundance, group
}
- sortedLabels[place[i]] = m->currentBinLabels[i];
+ sortedLabels[place[i]] = m->currentSharedBinLabels[i];
}
//delete looktemp -- Sarah look at - this is causing segmentation faults
}
//sort lookup so shared bins are on top
- vector<string> sortedLabels = m->currentBinLabels;
+ vector<string> sortedLabels = m->currentSharedBinLabels;
if (sorted != "none") { sortedLabels = sortSharedVectors(lookup); }
vector<vector<string> > scaleRelAbund;
map<int, int> place; //spot in lookup where you insert shared by, ie, 3 -> 2 if they are shared by 3 inset into location 2.
map<int, int>::iterator it;
- vector<string> sortedLabels = m->currentBinLabels;
+ vector<string> sortedLabels = m->currentSharedBinLabels;
/****************** find order of otus **********************/
if (sorted == "shared") {
for (int j = 0; j < looktemp.size(); j++) { // 3 -> 2
float newAbund = looktemp[j]->getAbundance(i); // 1 -> 3
lookup[j]->set(place[i], newAbund, looktemp[j]->getGroup()); //binNumber, abundance, group
- sortedLabels[place[i]] = m->currentBinLabels[i];
+ sortedLabels[place[i]] = m->currentSharedBinLabels[i];
}
}
if (m->control_pressed) { out.close(); return 0; }
- out << m->currentBinLabels[j] << '\t' << indicatorGroups[j] << '\t' << indicatorValues[j] << '\t';
+ out << m->currentSharedBinLabels[j] << '\t' << indicatorGroups[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 << m->currentBinLabels[j] << '\t' << indicatorGroups[j] << '\t' << indicatorValues[j] << '\t';
+ cout << m->currentSharedBinLabels[j] << '\t' << indicatorGroups[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(m->currentBinLabels[j] + "\t" + indicatorGroups[j] + "\t" + toString(indicatorValues[j]) + "\t" + pValueString);
+ m->mothurOutJustToLog(m->currentSharedBinLabels[j] + "\t" + indicatorGroups[j] + "\t" + toString(indicatorValues[j]) + "\t" + pValueString);
m->mothurOutEndLine();
}
}
//print headings
out << "TreeNode\t";
- for (int i = 0; i < numBins; i++) { out << m->currentBinLabels[i] << "_IndGroups" << '\t' << m->currentBinLabels[i] << "_IndValue" << '\t' << "pValue" << '\t'; }
+ for (int i = 0; i < numBins; i++) { out << m->currentSharedBinLabels[i] << "_IndGroups" << '\t' << m->currentSharedBinLabels[i] << "_IndValue" << '\t' << "pValue" << '\t'; }
out << endl;
m->mothurOutEndLine(); m->mothurOut("Node\tSpecies\tIndicator_Groups\tIndicatorValue\tpValue\n");
}
if (pValues[j] <= 0.05) {
- cout << i+1 << '\t' << m->currentBinLabels[j] << '\t' << indicatorGroups[j] << '\t' << indicatorValues[j] << '\t';
+ cout << i+1 << '\t' << m->currentSharedBinLabels[j] << '\t' << indicatorGroups[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) + "\t" + m->currentBinLabels[j] + "\t" + indicatorGroups[j] + "\t" + toString(indicatorValues[j]) + "\t" + pValueString);
+ m->mothurOutJustToLog(toString(i) + "\t" + m->currentSharedBinLabels[j] + "\t" + indicatorGroups[j] + "\t" + toString(indicatorValues[j]) + "\t" + pValueString);
m->mothurOutEndLine();
}
}
double H = linear.calcKruskalWallis(values, pValue);
//output H and signifigance
- out << m->currentBinLabels[i] << '\t' << H << '\t' << pValue << endl;
+ out << m->currentSharedBinLabels[i] << '\t' << H << '\t' << pValue << endl;
}
out.close();
if (maxMean > logMaxMean) { logMaxMean = maxMean; }
logMaxMean = log10(logMaxMean);
- out << m->currentBinLabels[i] << '\t' << logMaxMean << '\t';
- if (m->debug) { temp = m->currentBinLabels[i] + '\t' + toString(logMaxMean) + '\t'; }
+ out << m->currentSharedBinLabels[i] << '\t' << logMaxMean << '\t';
+ if (m->debug) { temp = m->currentSharedBinLabels[i] + '\t' + toString(logMaxMean) + '\t'; }
map<int, double>::iterator it = sigLDA.find(i);
if (it != sigLDA.end()) {
for (map<int, double>::iterator it = bins.begin(); it != bins.end(); it++) {
if (m->control_pressed) { break; }
- cout << m->currentBinLabels[it->first] << " <- c(";
+ cout << m->currentSharedBinLabels[it->first] << " <- c(";
for (int h = 0; h < rand_s.size()-1; h++) { cout << (adjustedLookup[count][rand_s[h]]) << ", "; }
cout << (adjustedLookup[count][rand_s[rand_s.size()-1]]) << ")\n";
count++;
for (map<int, double>::iterator it = bins.begin(); it != bins.end(); it++) {
if (m->control_pressed) { break; }
- tempOutput += "\"" + m->currentBinLabels[it->first] + "\"=" + m->currentBinLabels[it->first] + ",";
+ tempOutput += "\"" + m->currentSharedBinLabels[it->first] + "\"=" + m->currentSharedBinLabels[it->first] + ",";
}
//tempOutput = tempOutput.substr(0, tempOutput.length()-1);
tempOutput += " class=treatments";
for (map<int, double>::iterator it = bins.begin(); it != bins.end(); it++) {
if (m->control_pressed) { break; }
- tempOutput += m->currentBinLabels[it->first] + "+";
+ tempOutput += m->currentSharedBinLabels[it->first] + "+";
}
tempOutput = tempOutput.substr(0, tempOutput.length()-1); //rip off extra plus sign
tempOutput += "), data = dat, tol = 1e-10))";
lookup.push_back(temp);
}
- m->currentBinLabels.clear();
+ m->currentSharedBinLabels.clear();
int count = 0;
while (!in.eof()) {
if (m->control_pressed) { return 0; }
lookup[i-1]->push_back(value, toString(i-1));
//cout << pieces[i] << '\t';
}
- m->currentBinLabels.push_back(toString(count));
+ m->currentSharedBinLabels.push_back(toString(count));
//m->currentBinLabels.push_back(pieces[0]);
//cout << line<< endl;
//cout << endl;
ofstream out;
m->openOutputFile(outputFileName, out);
- for (int i = 0; i < m->currentBinLabels.size(); i++) { out << m->currentBinLabels[i] << endl; }
+ for (int i = 0; i < m->currentSharedBinLabels.size(); i++) { out << m->currentSharedBinLabels[i] << endl; }
out.close();
ofstream out;
m->openOutputFile(outputFileName, out);
- for (int i = 0; i < m->currentBinLabels.size(); i++) { out << m->currentBinLabels[i] << endl; }
+ for (int i = 0; i < m->currentSharedBinLabels.size(); i++) { out << m->currentSharedBinLabels[i] << endl; }
out.close();
ofstream out;
m->openOutputFile(outputFileName, out);
- string snumBins = toString(list->getNumBins());
- for (int i = 0; i < list->getNumBins(); i++) {
- if (m->control_pressed) { break; }
-
- string otuLabel = "Otu";
- string sbinNumber = toString(i+1);
- if (sbinNumber.length() < snumBins.length()) {
- int diff = snumBins.length() - sbinNumber.length();
- for (int h = 0; h < diff; h++) { otuLabel += "0"; }
- }
- otuLabel += sbinNumber;
-
- out << otuLabel << endl;
- }
+ vector<string> binLabels = list->getLabels();
+ for (int i = 0; i < binLabels.size(); i++) { out << binLabels[i] << endl; }
out.close();
ListVector::ListVector(ifstream& f) : DataVector(), maxRank(0), numBins(0), numSeqs(0) {
try {
int hold;
- f >> label >> hold;
+
+ //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 "numOtus"
+ f >> label; m->gobble(f);
+
+ //eat rest of line
+ label = m->getline(f); m->gobble(f);
+
+ //parse labels to save
+ istringstream iStringStream(label);
+ m->listBinLabelsInFile.clear();
+ while(!iStringStream.eof()){
+ if (m->control_pressed) { break; }
+ string temp;
+ iStringStream >> temp; m->gobble(iStringStream);
+
+ m->listBinLabelsInFile.push_back(temp);
+ }
+
+ f >> label >> hold;
+ }else {
+ //read in first row
+ f >> hold;
+
+ //make binlabels because we don't have any
+ string snumBins = toString(hold);
+ m->listBinLabelsInFile.clear();
+ for (int i = 0; i < hold; 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->listBinLabelsInFile.push_back(binLabel);
+ }
+ }
+ m->saveNextLabel = label;
+ }else {
+ f >> label >> hold;
+ m->saveNextLabel = label;
+ }
+ binLabels.assign(m->listBinLabelsInFile.begin(), m->listBinLabelsInFile.begin()+hold);
+
data.assign(hold, "");
string inputData = "";
set(i, inputData);
}
m->gobble(f);
+
+ if (f.eof()) { m->saveNextLabel = ""; }
}
catch(exception& e) {
m->errorOut(e, "ListVector", "ListVector");
string ListVector::get(int index){
return data[index];
}
+/***********************************************************************/
+
+void ListVector::setLabels(vector<string> labels){
+ try {
+ binLabels = labels;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "ListVector", "setLabels");
+ exit(1);
+ }
+}
+
+/***********************************************************************/
+//could potentially end up with duplicate binlabel names with code below.
+//we don't currently use them in a way that would do that.
+//if you had a listfile that had been subsampled and then added to it, dup names would be possible.
+vector<string> ListVector::getLabels(){
+ try {
+
+ string tagHeader = "Otu";
+ if (m->sharedHeaderMode == "tax") { tagHeader = "PhyloType"; }
+
+ if (binLabels.size() < data.size()) {
+ string snumBins = toString(numBins);
+
+ for (int i = 0; i < numBins; i++) {
+ string binLabel = tagHeader;
+
+ if (i < binLabels.size()) { //label exists, check leading zeros length
+ string sbinNumber = m->getSimpleLabel(binLabels[i]);
+ if (sbinNumber.length() < snumBins.length()) {
+ int diff = snumBins.length() - sbinNumber.length();
+ for (int h = 0; h < diff; h++) { binLabel += "0"; }
+ }
+ binLabel += sbinNumber;
+ binLabels[i] = binLabel;
+ }else{
+ 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;
+ binLabels.push_back(binLabel);
+ }
+ }
+ }
+ return binLabels;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "ListVector", "getLabels");
+ exit(1);
+ }
+}
/***********************************************************************/
}
+/***********************************************************************/
+void ListVector::printHeaders(ostream& output){
+ try {
+ string snumBins = toString(numBins);
+ output << "label\tnumOtus\t";
+ if (m->sharedHeaderMode == "tax") {
+ for (int i = 0; i < numBins; i++) {
+
+ //if there is a bin label use it otherwise make one
+ string binLabel = "PhyloType";
+ 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;
+ if (i < binLabels.size()) { binLabel = binLabels[i]; }
+
+ output << binLabel << '\t';
+ }
+ output << endl;
+ }else {
+ for (int i = 0; i < numBins; 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;
+ if (i < binLabels.size()) { binLabel = binLabels[i]; }
+
+ output << binLabel << '\t';
+ }
+
+ output << endl;
+ }
+ m->printedListHeaders = true;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "ListVector", "printHeaders");
+ exit(1);
+ }
+}
+
/***********************************************************************/
void ListVector::print(ostream& output){
ListVector(int);
// ListVector(const ListVector&);
ListVector(string, vector<string>);
- ListVector(const ListVector& lv) : DataVector(lv.label), data(lv.data), maxRank(lv.maxRank), numBins(lv.numBins), numSeqs(lv.numSeqs){};
+ ListVector(const ListVector& lv) : DataVector(lv.label), data(lv.data), maxRank(lv.maxRank), numBins(lv.numBins), numSeqs(lv.numSeqs), binLabels(lv.binLabels) {};
ListVector(ifstream&);
~ListVector(){};
void set(int, string);
string get(int);
+ vector<string> getLabels();
+ void setLabels(vector<string>);
void push_back(string);
void resize(int);
void clear();
int size();
void print(ostream&);
+ void printHeaders(ostream&);
RAbundVector getRAbundVector();
SAbundVector getSAbundVector();
int maxRank;
int numBins;
int numSeqs;
+ vector<string> binLabels;
};
string rowBack = "\", \"metadata\":";
for (int i = 0; i < numBins-1; i++) {
if (m->control_pressed) { out.close(); return 0; }
- if (!picrust) { out << rowFront << m->currentBinLabels[i] << rowBack << metadata[i] << "},\n"; }
+ if (!picrust) { out << rowFront << m->currentSharedBinLabels[i] << rowBack << metadata[i] << "},\n"; }
else { out << rowFront << picrustLabels[i] << rowBack << metadata[i] << "},\n"; }
}
- if (!picrust) { out << rowFront << m->currentBinLabels[(numBins-1)] << rowBack << metadata[(numBins-1)] << "}\n" + spaces + "],\n"; }
+ if (!picrust) { out << rowFront << m->currentSharedBinLabels[(numBins-1)] << rowBack << metadata[(numBins-1)] << "}\n" + spaces + "],\n"; }
else { out << rowFront << picrustLabels[(numBins-1)] << rowBack << metadata[(numBins-1)] << "}\n" + spaces + "],\n"; }
//get column info
/*"columns": [
in.close();
//should the labels be Otu001 or PhyloType001
- string firstBin = m->currentBinLabels[0];
+ string firstBin = m->currentSharedBinLabels[0];
string binTag = "Otu";
if ((firstBin.find("Otu")) == string::npos) { binTag = "PhyloType"; }
if (m->control_pressed) { return metadata; }
- it = labelTaxMap.find(m->getSimpleLabel(m->currentBinLabels[i]));
+ it = labelTaxMap.find(m->getSimpleLabel(m->currentSharedBinLabels[i]));
- if (it == labelTaxMap.end()) { m->mothurOut("[ERROR]: can't find taxonomy information for " + m->currentBinLabels[i] + ".\n"); m->control_pressed = true; }
+ if (it == labelTaxMap.end()) { m->mothurOut("[ERROR]: can't find taxonomy information for " + m->currentSharedBinLabels[i] + ".\n"); m->control_pressed = true; }
else {
if (picrust) {
string temp = it->second; m->removeConfidences(temp);
for (int i = 0; i < lookup[0]->getNumBins(); i++) { //process each otu
if (m->control_pressed) { break; }
- string nameOfOtu = m->currentBinLabels[i];
+ string nameOfOtu = m->currentSharedBinLabels[i];
if (constaxonomyfile != "") { //try to find the otuName in consTax to replace with consensus taxonomy
map<string, consTax2>::iterator it = consTax.find(nameOfOtu);
if (it != consTax.end()) {
//remove confidences and change ; to |
m->removeConfidences(nameOfOtu);
for (int j = 0; j < nameOfOtu.length()-1; j++) {
- if (nameOfOtu[j] == ';') { fixedName += "_" + m->currentBinLabels[i] + '|'; }
+ if (nameOfOtu[j] == ';') { fixedName += "_" + m->currentSharedBinLabels[i] + '|'; }
else { fixedName += nameOfOtu[j]; }
}
nameOfOtu = fixedName;
m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
- if (!m->printedHeaders) { lookup[0]->printHeaders(out); }
+ if (!m->printedSharedHeaders) { lookup[0]->printHeaders(out); }
process(lookup, out);
processedLabels.insert(lookup[0]->getLabel());
lookup = input.getSharedRAbundVectors(lastLabel);
m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
- if (!m->printedHeaders) { lookup[0]->printHeaders(out); }
+ if (!m->printedSharedHeaders) { lookup[0]->printHeaders(out); }
process(lookup, out);
processedLabels.insert(lookup[0]->getLabel());
m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
- if (!m->printedHeaders) { lookup[0]->printHeaders(out); }
+ if (!m->printedSharedHeaders) { lookup[0]->printHeaders(out); }
process(lookup, out);
for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
out << subset[subset.size()-1]->getGroup() << endl;
for (int i = 0; i < subset[0]->getNumBins(); i++) {
- out << m->currentBinLabels[i] << '\t';
+ out << m->currentSharedBinLabels[i] << '\t';
for (int j = 0; j < subset.size()-1; j++) {
out << subset[j]->getAbundance(i) << '\t';
}
m->openOutputFile(rabundFileName, rabundFile);
}
m->openOutputFile(listFileName, listFile);
+ list->printHeaders(listFile);
if (m->control_pressed) {
delete nameMap; delete read; delete list; delete rabund;
if (m->control_pressed) { out.close(); return 0; }
//if there are binlabels use them otherwise count.
- if (m->binLabelsInFile.size() == row) { out << m->binLabelsInFile[i] << '\t'; }
+ if (i < m->currentSharedBinLabels.size()) { out << m->currentSharedBinLabels[i] << '\t'; }
else { out << (i+1) << '\t'; }
out << C1[i][0] << '\t' << C1[i][1] << '\t' << C1[i][2] << '\t' << C2[i][0] << '\t' << C2[i][1] << '\t' << C2[i][2] << '\t' << pvalues[i] << '\t' << qvalues[i] << endl;
vector<string> getAllGroups() { sort(namesOfGroups.begin(), namesOfGroups.end()); return namesOfGroups; }
vector<string> Treenames;
//map<string, string> names;
- vector<string> binLabelsInFile;
- vector<string> currentBinLabels;
+ vector<string> sharedBinLabelsInFile;
+ vector<string> currentSharedBinLabels;
+ vector<string> listBinLabelsInFile;
+ //vector<string> currentListBinLabels;
string saveNextLabel, argv, sharedHeaderMode, groupMode;
- bool printedHeaders, commandInputsConvertError, changedSeqNames, modifyNames;
+ bool printedSharedHeaders, printedListHeaders, commandInputsConvertError, changedSeqNames, modifyNames;
//functions from mothur.h
//file operations
counttablefile = "";
summaryfile = "";
gui = false;
- printedHeaders = false;
+ printedSharedHeaders = false;
+ printedListHeaders = false;
commandInputsConvertError = false;
mothurCalling = false;
debug = false;
int NormalizeSharedCommand::normalize(vector<SharedRAbundVector*>& thisLookUp){
try {
//save mothurOut's binLabels to restore for next label
- vector<string> saveBinLabels = m->currentBinLabels;
+ vector<string> saveBinLabels = m->currentSharedBinLabels;
if (pickedGroups) { eliminateZeroOTUS(thisLookUp); }
out.close();
- m->currentBinLabels = saveBinLabels;
+ m->currentSharedBinLabels = saveBinLabels;
return 0;
}
try {
//save mothurOut's binLabels to restore for next label
- vector<string> saveBinLabels = m->currentBinLabels;
+ vector<string> saveBinLabels = m->currentSharedBinLabels;
map<string, string> variables;
variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(inputfile));
out.close();
- m->currentBinLabels = saveBinLabels;
+ m->currentSharedBinLabels = saveBinLabels;
return 0;
}
for (int h = 0; h < diff; h++) { binLabel += "0"; }
}
binLabel += sbinNumber;
- if (i < m->currentBinLabels.size()) { binLabel = m->currentBinLabels[i]; }
+ if (i < m->currentSharedBinLabels.size()) { binLabel = m->currentSharedBinLabels[i]; }
newBinLabels.push_back(binLabel);
}
for (int j = 0; j < thislookup.size(); j++) { delete thislookup[j]; }
thislookup = newLookup;
- m->currentBinLabels = newBinLabels;
+ m->currentSharedBinLabels = newBinLabels;
return 0;
for (int h = 0; h < diff; h++) { binLabel += "0"; }
}
binLabel += sbinNumber;
- if (i < m->currentBinLabels.size()) { binLabel = m->currentBinLabels[i]; }
+ if (i < m->currentSharedBinLabels.size()) { binLabel = m->currentSharedBinLabels[i]; }
newBinLabels.push_back(binLabel);
}
for (int j = 0; j < thislookup.size(); j++) { delete thislookup[j]; }
thislookup = newLookup;
- m->currentBinLabels = newBinLabels;
+ m->currentSharedBinLabels = newBinLabels;
return 0;
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 (sig < cutoff) { out << m->binLabelsInFile[i] << '\t' << m->binLabelsInFile[k] << '\t' << coef << '\t' << sig << endl; }
+ if (sig < cutoff) { out << m->currentSharedBinLabels[i] << '\t' << m->currentSharedBinLabels[k] << '\t' << coef << '\t' << sig << endl; }
}
}
}else { //compare otus to metadata
else if (method == "kendall") { coef = linear.calcKendall(xy[i], metadata[k], sig); }
else { m->mothurOut("[ERROR]: invalid method, choices are spearman, pearson or kendall."); m->mothurOutEndLine(); m->control_pressed = true; }
- if (sig < cutoff) { out << m->binLabelsInFile[i] << '\t' << metadataLabels[k] << '\t' << coef << '\t' << sig << endl; }
+ if (sig < cutoff) { out << m->currentSharedBinLabels[i] << '\t' << metadataLabels[k] << '\t' << coef << '\t' << sig << endl; }
}
}
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 (sig < cutoff) { out << m->binLabelsInFile[i] << '\t' << m->binLabelsInFile[k] << '\t' << coef << '\t' << sig << endl; }
+ if (sig < cutoff) { out << m->currentSharedBinLabels[i] << '\t' << m->currentSharedBinLabels[k] << '\t' << coef << '\t' << sig << endl; }
}
}
}else { //compare otus to metadata
else if (method == "kendall") { coef = linear.calcKendall(xy[i], metadata[k], sig); }
else { m->mothurOut("[ERROR]: invalid method, choices are spearman, pearson or kendall."); m->mothurOutEndLine(); m->control_pressed = true; }
- if (sig < cutoff) { out << m->binLabelsInFile[i] << '\t' << metadataLabels[k] << '\t' << coef << '\t' << sig << endl; }
+ if (sig < cutoff) { out << m->currentSharedBinLabels[i] << '\t' << metadataLabels[k] << '\t' << coef << '\t' << sig << endl; }
}
}
}
//map sequences to bin number in the "little" otu
- map<string, int> littleBins;
+ map<string, int> littleBins;
+ vector<string> binLabels0 = lists[0].getLabels();
for (int i = 0; i < lists[0].getNumBins(); i++) {
if (m->control_pressed) { return 0; }
-
string bin = lists[0].get(i);
vector<string> names; m->splitAtComma(bin, names);
for (int j = 0; j < names.size(); j++) { littleBins[names[j]] = i; }
m->openOutputFile(outputFileName, out);
//go through each bin in "big" otu and output the bins in "little" otu which created it
+ vector<string> binLabels1 = lists[1].getLabels();
for (int i = 0; i < lists[1].getNumBins(); i++) {
if (m->control_pressed) { outputTypes.clear(); out.close(); m->mothurRemove(outputFileName); return 0; }
string binnames = lists[1].get(i);
vector<string> names; m->splitAtComma(binnames, names);
-
//output column 1
if (output == "name") { out << binnames << '\t'; }
- else { out << (i+1) << '\t'; }
+ else { out << binLabels1[i] << '\t'; }
map<int, int> bins; //bin numbers in little that are in this bin in big
map<int, int>::iterator it;
string col2 = "";
for (it = bins.begin(); it != bins.end(); it++) {
if (output == "name") { col2 += lists[0].get(it->first) + "\t"; }
- else { col2 += toString(it->first) + "\t"; }
+ else { col2 += binLabels0[it->first] + "\t"; }
}
//output column 2
m->openOutputFile(filename, out);
out <<"OTU\tMean decrease accuracy\n";
for (int i = 0; i < globalVariableRanks.size(); i++) {
- out << m->currentBinLabels[(int)globalVariableRanks[i].first] << '\t' << globalVariableImportanceList[globalVariableRanks[i].first] << endl;
+ out << m->currentSharedBinLabels[(int)globalVariableRanks[i].first] << '\t' << globalVariableImportanceList[globalVariableRanks[i].first] << endl;
}
out.close();
return 0;
m->setGroups(groupsToKeep);
m->clearAllGroups();
m->saveNextLabel = "";
- m->printedHeaders = false;
- m->currentBinLabels.clear();
- m->binLabelsInFile.clear();
+ m->printedSharedHeaders = false;
+ m->currentSharedBinLabels.clear();
+ m->sharedBinLabelsInFile.clear();
InputData input(sharedfile, "sharedfile");
lookup = input.getSharedRAbundVectors();
if (m->control_pressed) { for (int j = 0; j < newLookup.size(); j++) { delete newLookup[j]; } for (int j = 0; j < lookup.size(); j++) { delete lookup[j]; } return 0; }
//is this otu on the list
- if (names.count(m->getSimpleLabel(m->currentBinLabels[i])) == 0) {
+ if (names.count(m->getSimpleLabel(m->currentSharedBinLabels[i])) == 0) {
wroteSomething = true;
- newLabels.push_back(m->currentBinLabels[i]);
+ newLabels.push_back(m->currentSharedBinLabels[i]);
for (int j = 0; j < newLookup.size(); j++) { //add this OTU to the new lookup
newLookup[j]->push_back(lookup[j]->getAbundance(i), lookup[j]->getGroup());
}
for (int j = 0; j < lookup.size(); j++) { delete lookup[j]; }
- m->currentBinLabels = newLabels;
+ m->currentSharedBinLabels = newLabels;
newLookup[0]->printHeaders(out);
if (m->control_pressed) { for (int j = 0; j < newLookup.size(); j++) { delete newLookup[j]; } for (int j = 0; j < lookup.size(); j++) { delete lookup[j]; } return 0; }
//is this otu on the list
- if (labels.count(m->getSimpleLabel(m->currentBinLabels[i])) == 0) {
+ if (labels.count(m->getSimpleLabel(m->currentSharedBinLabels[i])) == 0) {
wroteSomething = true;
- newLabels.push_back(m->currentBinLabels[i]);
+ newLabels.push_back(m->currentSharedBinLabels[i]);
for (int j = 0; j < newLookup.size(); j++) { //add this OTU to the new lookup
newLookup[j]->push_back(lookup[j]->getAbundance(i), lookup[j]->getGroup());
}
for (int j = 0; j < lookup.size(); j++) { delete lookup[j]; }
- m->currentBinLabels = newLabels;
+ m->currentSharedBinLabels = newLabels;
newLookup[0]->printHeaders(out);
//eliminates zero otus
if (allZero) { for (int j = 0; j < newRabunds.size(); j++) { newRabunds[j].pop_back(); } }
- else { headers.push_back(m->currentBinLabels[i]); }
+ else { headers.push_back(m->currentSharedBinLabels[i]); }
}
}else {
//for each otu
//eliminates otus below rare cutoff
if (totalAbund <= nseqs) { for (int j = 0; j < newRabunds.size(); j++) { newRabunds[j].pop_back(); } }
- else { headers.push_back(m->currentBinLabels[i]); }
+ else { headers.push_back(m->currentSharedBinLabels[i]); }
}
}
try {
string pattern = "";
- if (type == "shared") { pattern = "[filename],shared"; }
+ if (type == "shared") { pattern = "[filename],shared-[filename],[distance],shared"; }
else if (type == "rabund") { pattern = "[filename],[group],rabund"; }
else if (type == "group") { pattern = "[filename],[group],groups"; }
else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; }
try {
if (abort == true) { if (calledHelp) { return 0; } return 2; }
-
- //getting output filename
- string filename = "";
- if (listfile != "") { filename = listfile; }
- else { filename = biomfile; }
-
- if (outputDir == "") { outputDir += m->hasPath(filename); }
-
- map<string, string> variables;
- variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(filename));
- filename = getOutputFileName("shared",variables);
- outputNames.push_back(filename); outputTypes["shared"].push_back(filename);
-
- if (listfile != "") { createSharedFromListGroup(filename); }
- else { createSharedFromBiom(filename); }
+
+ if (listfile != "") { createSharedFromListGroup(); }
+ else { createSharedFromBiom(); }
if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } }
}
}
//**********************************************************************************************************************
-int SharedCommand::createSharedFromBiom(string filename) {
+int SharedCommand::createSharedFromBiom() {
try {
+ //getting output filename
+ string filename = biomfile;
+ if (outputDir == "") { outputDir += m->hasPath(filename); }
+
+ map<string, string> variables;
+ variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(filename));
+ filename = getOutputFileName("shared",variables);
+ outputNames.push_back(filename); outputTypes["shared"].push_back(filename);
+
ofstream out;
m->openOutputFile(filename, out);
if (it == fileLines.end()) { m->mothurOut("[ERROR]: you file does not have a data provided.\n"); }
else {
string thisLine = it->second;
- m->currentBinLabels = otuNames;
+ m->currentSharedBinLabels = otuNames;
//read data
vector<SharedRAbundVector*> lookup = readData(matrixFormat, thisLine, matrixElementType, groupNames, otuNames.size());
for (int h = 0; h < diff; h++) { binLabel += "0"; }
}
binLabel += sbinNumber;
- if (i < m->currentBinLabels.size()) { binLabel = m->currentBinLabels[i]; }
+ if (i < m->currentSharedBinLabels.size()) { binLabel = m->currentSharedBinLabels[i]; }
newBinLabels.push_back(binLabel);
}
for (int j = 0; j < thislookup.size(); j++) { delete thislookup[j]; }
thislookup = newLookup;
- m->currentBinLabels = newBinLabels;
+ m->currentSharedBinLabels = newBinLabels;
return 0;
}
}
//**********************************************************************************************************************
-int SharedCommand::createSharedFromListGroup(string filename) {
+int SharedCommand::createSharedFromListGroup() {
try {
- ofstream out;
- m->openOutputFile(filename, out);
GroupMap* groupMap = NULL;
CountTable* countTable = NULL;
m->setGroups(Groups);
}else { pickedGroups = true; }
+
+ ofstream out;
+ string filename = "";
+ if (!pickedGroups) {
+ string filename = listfile;
+ if (outputDir == "") { outputDir += m->hasPath(filename); }
+
+ map<string, string> variables;
+ variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(filename));
+ filename = getOutputFileName("shared",variables);
+ outputNames.push_back(filename); outputTypes["shared"].push_back(filename);
+ m->openOutputFile(filename, out);
+ }
+
//fill filehandles with neccessary ofstreams
int i;
ofstream* temp;
if (m->control_pressed) {
delete SharedList; if (groupMap != NULL) { delete groupMap; } if (countTable != NULL) { delete countTable; }
for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { delete it3->second; }
- out.close(); m->mothurRemove(filename);
+ out.close(); if (!pickedGroups) { m->mothurRemove(filename); }
for (int i=0; i<Groups.size(); i++) { variables["[group]"] = Groups[i];
string rabundFIleName = getOutputFileName("rabund",variables);
m->mothurRemove(rabundFIleName); }
if ((!pickedGroups) && (SharedList->getNumSeqs() != numGroupNames)) { //if the user has not specified any groups and their files don't match exit with error
m->mothurOut("Your group file contains " + toString(numGroupNames) + " sequences and list file contains " + toString(SharedList->getNumSeqs()) + " sequences. Please correct."); m->mothurOutEndLine(); m->control_pressed = true;
- out.close(); m->mothurRemove(filename); //remove blank shared file you made
+ out.close(); if (!pickedGroups) { m->mothurRemove(filename); } //remove blank shared file you made
//delete memory
for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { delete it3->second; }
if ((pickedGroups) && (m->groupMode == "group")) { //make new group file
string groups = "";
if (m->getNumGroups() < 4) {
- for (int i = 0; i < m->getNumGroups(); i++) {
+ for (int i = 0; i < m->getNumGroups()-1; i++) {
groups += (m->getGroups())[i] + ".";
}
+ groups+=(m->getGroups())[m->getNumGroups()-1];
}else { groups = "merge"; }
map<string, string> variables;
variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(listfile));
if (m->control_pressed) {
delete SharedList; if (groupMap != NULL) { delete groupMap; } if (countTable != NULL) { delete countTable; }
for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { delete it3->second; }
- out.close(); m->mothurRemove(filename);
+ if (!pickedGroups) { out.close(); m->mothurRemove(filename); }
for (int i=0; i<Groups.size(); i++) { variables["[group]"] = Groups[i];
string rabundFIleName = getOutputFileName("rabund",variables);
m->mothurRemove(rabundFIleName); }
lookup = SharedList->getSharedRAbundVector();
m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
- if (pickedGroups) { //check for otus with no seqs in them
- eliminateZeroOTUS(lookup);
- }
if (m->control_pressed) {
delete SharedList; if (groupMap != NULL) { delete groupMap; } if (countTable != NULL) { delete countTable; }
for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { delete it3->second; }
- out.close(); m->mothurRemove(filename);
+ if (!pickedGroups) { out.close(); m->mothurRemove(filename); }
for (int i=0; i<Groups.size(); i++) { variables["[group]"] = Groups[i];
string rabundFIleName = getOutputFileName("rabund",variables);
m->mothurRemove(rabundFIleName); }
return 0;
}
- if (!m->printedHeaders) { lookup[0]->printHeaders(out); }
- printSharedData(lookup, out); //prints info to the .shared file
+ //if picked groups must split the shared file by label
+ if (pickedGroups) {
+ string filename = listfile;
+ if (outputDir == "") { outputDir += m->hasPath(filename); }
+
+ map<string, string> variables;
+ variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(filename));
+ variables["[distance]"] = lookup[0]->getLabel();
+ filename = getOutputFileName("shared",variables);
+ outputNames.push_back(filename); outputTypes["shared"].push_back(filename);
+ ofstream out2;
+ m->openOutputFile(filename, out2);
+
+ vector<string> savedLabels = m->currentSharedBinLabels;
+ eliminateZeroOTUS(lookup);
+ lookup[0]->printHeaders(out2);
+ printSharedData(lookup, out2);
+ out2.close();
+ m->currentSharedBinLabels = savedLabels; //restore old labels
+
+ }else {
+ if (!m->printedSharedHeaders) { lookup[0]->printHeaders(out); }
+ printSharedData(lookup, out); //prints info to the .shared file
+ }
for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
processedLabels.insert(SharedList->getLabel());
lookup = SharedList->getSharedRAbundVector();
m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
- if (pickedGroups) { //check for otus with no seqs in them
- eliminateZeroOTUS(lookup);
- }
-
if (m->control_pressed) {
delete SharedList; if (groupMap != NULL) { delete groupMap; } if (countTable != NULL) { delete countTable; }
for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { delete it3->second; }
- out.close(); m->mothurRemove(filename);
+ if (!pickedGroups) { out.close(); m->mothurRemove(filename); }
for (int i=0; i<Groups.size(); i++) { variables["[group]"] = Groups[i];
string rabundFIleName = getOutputFileName("rabund",variables);
m->mothurRemove(rabundFIleName); }
return 0;
}
- if (!m->printedHeaders) { lookup[0]->printHeaders(out); }
- printSharedData(lookup, out); //prints info to the .shared file
+ //if picked groups must split the shared file by label
+ if (pickedGroups) {
+ string filename = listfile;
+ if (outputDir == "") { outputDir += m->hasPath(filename); }
+
+ map<string, string> variables;
+ variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(filename));
+ variables["[distance]"] = lookup[0]->getLabel();
+ filename = getOutputFileName("shared",variables);
+ outputNames.push_back(filename); outputTypes["shared"].push_back(filename);
+ ofstream out2;
+ m->openOutputFile(filename, out2);
+
+ vector<string> savedLabels = m->currentSharedBinLabels;
+ eliminateZeroOTUS(lookup);
+ lookup[0]->printHeaders(out2);
+ printSharedData(lookup, out2);
+ out2.close();
+ m->currentSharedBinLabels = savedLabels; //restore old labels
+
+ }else {
+ if (!m->printedSharedHeaders) { lookup[0]->printHeaders(out); }
+ printSharedData(lookup, out); //prints info to the .shared file
+ }
+
for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
processedLabels.insert(SharedList->getLabel());
lookup = SharedList->getSharedRAbundVector();
m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
- if (pickedGroups) { //check for otus with no seqs in them
- eliminateZeroOTUS(lookup);
- }
if (m->control_pressed) {
if (groupMap != NULL) { delete groupMap; } if (countTable != NULL) { delete countTable; }
for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { delete it3->second; }
- out.close(); m->mothurRemove(filename);
+ if (!pickedGroups) { out.close(); m->mothurRemove(filename); }
for (int i=0; i<Groups.size(); i++) { variables["[group]"] = Groups[i];
string rabundFIleName = getOutputFileName("rabund",variables);
m->mothurRemove(rabundFIleName); }
return 0;
}
- if (!m->printedHeaders) { lookup[0]->printHeaders(out); }
- printSharedData(lookup, out); //prints info to the .shared file
+ //if picked groups must split the shared file by label
+ if (pickedGroups) {
+ string filename = listfile;
+ if (outputDir == "") { outputDir += m->hasPath(filename); }
+
+ map<string, string> variables;
+ variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(filename));
+ variables["[distance]"] = lookup[0]->getLabel();
+ filename = getOutputFileName("shared",variables);
+ outputNames.push_back(filename); outputTypes["shared"].push_back(filename);
+ ofstream out2;
+ m->openOutputFile(filename, out2);
+
+ vector<string> savedLabels = m->currentSharedBinLabels;
+ eliminateZeroOTUS(lookup);
+ lookup[0]->printHeaders(out2);
+ printSharedData(lookup, out2);
+ out2.close();
+ m->currentSharedBinLabels = savedLabels; //restore old labels
+
+ }else {
+ if (!m->printedSharedHeaders) { lookup[0]->printHeaders(out); }
+ printSharedData(lookup, out); //prints info to the .shared file
+ }
for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
delete SharedList;
}
- out.close();
+ if (!pickedGroups) { out.close(); }
for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) {
delete it3->second;
if (groupMap != NULL) { delete groupMap; } if (countTable != NULL) { delete countTable; }
if (m->control_pressed) {
- m->mothurRemove(filename);
+ if (!pickedGroups) { m->mothurRemove(filename); }
for (int i=0; i<Groups.size(); i++) { variables["[group]"] = Groups[i];
string rabundFIleName = getOutputFileName("rabund",variables);
m->mothurRemove(rabundFIleName); }
bool isValidGroup(string, vector<string>);
int eliminateZeroOTUS(vector<SharedRAbundVector*>&);
int ListGroupSameSeqs(vector<string>&, SharedListVector*);
- int createSharedFromListGroup(string);
- int createSharedFromBiom(string);
+ int createSharedFromListGroup();
+ int createSharedFromBiom();
string getTag(string&);
vector<string> readRows(string, int&);
int getDims(string, int&, int&);
countTable->readTable(m->getCountTableFile(), true, false);
}
- int hold;
- string inputData;
- f >> label >> hold;
-
- data.assign(hold, "");
+ int hold;
+
+ //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 "numOtus"
+ f >> label; m->gobble(f);
+
+ //eat rest of line
+ label = m->getline(f); m->gobble(f);
+
+ //parse labels to save
+ istringstream iStringStream(label);
+ m->listBinLabelsInFile.clear();
+ while(!iStringStream.eof()){
+ if (m->control_pressed) { break; }
+ string temp;
+ iStringStream >> temp; m->gobble(iStringStream);
+
+ m->listBinLabelsInFile.push_back(temp);
+ }
+
+ f >> label >> hold;
+ }else {
+ //read in first row
+ f >> hold;
+
+ //make binlabels because we don't have any
+ string snumBins = toString(hold);
+ m->listBinLabelsInFile.clear();
+ for (int i = 0; i < hold; 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->listBinLabelsInFile.push_back(binLabel);
+ }
+ }
+ m->saveNextLabel = label;
+ }else {
+ f >> label >> hold;
+ m->saveNextLabel = label;
+ }
+
+ binLabels.assign(m->listBinLabelsInFile.begin(), m->listBinLabelsInFile.begin()+hold);
+ data.assign(hold, "");
+ string inputData = "";
+
for(int i=0;i<hold;i++){
f >> inputData;
set(i, inputData);
}
+ m->gobble(f);
+
+ if (f.eof()) { m->saveNextLabel = ""; }
}
catch(exception& e) {
string SharedListVector::get(int index){
return data[index];
}
+/***********************************************************************/
+
+void SharedListVector::setLabels(vector<string> labels){
+ try {
+ binLabels = labels;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "SharedListVector", "setLabels");
+ exit(1);
+ }
+}
+/***********************************************************************/
+//could potentially end up with duplicate binlabel names with code below.
+//we don't currently use them in a way that would do that.
+//if you had a listfile that had been subsampled and then added to it, dup names would be possible.
+vector<string> SharedListVector::getLabels(){
+ try {
+ string tagHeader = "Otu";
+ if (m->sharedHeaderMode == "tax") { tagHeader = "PhyloType"; }
+
+ if (binLabels.size() < data.size()) {
+ string snumBins = toString(numBins);
+
+ for (int i = 0; i < numBins; i++) {
+ string binLabel = tagHeader;
+
+ if (i < binLabels.size()) { //label exists, check leading zeros length
+ string sbinNumber = m->getSimpleLabel(binLabels[i]);
+ if (sbinNumber.length() < snumBins.length()) {
+ int diff = snumBins.length() - sbinNumber.length();
+ for (int h = 0; h < diff; h++) { binLabel += "0"; }
+ }
+ binLabel += sbinNumber;
+ binLabels[i] = binLabel;
+ }else{
+ 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;
+ binLabels.push_back(binLabel);
+ }
+ }
+ }
+ return binLabels;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "SharedListVector", "getLabels");
+ exit(1);
+ }
+}
/***********************************************************************/
void SharedListVector::push_back(string seqNames){
/***********************************************************************/
SharedRAbundVector SharedListVector::getSharedRAbundVector(string groupName) {
try {
+ m->currentSharedBinLabels = binLabels;
+
SharedRAbundVector rav(data.size());
for(int i=0;i<numBins;i++){
/***********************************************************************/
vector<SharedRAbundVector*> SharedListVector::getSharedRAbundVector() {
try {
+ m->currentSharedBinLabels = binLabels;
+
SharedUtil* util;
util = new SharedUtil();
vector<SharedRAbundVector*> lookup; //contains just the groups the user selected
SharedListVector();
SharedListVector(int);
SharedListVector(ifstream&);
- SharedListVector(const SharedListVector& lv) : DataVector(lv.label), data(lv.data), maxRank(lv.maxRank), numBins(lv.numBins), numSeqs(lv.numSeqs){ groupmap = NULL; countTable = NULL; };
+ SharedListVector(const SharedListVector& lv) : DataVector(lv.label), data(lv.data), maxRank(lv.maxRank), numBins(lv.numBins), numSeqs(lv.numSeqs), binLabels(lv.binLabels) { groupmap = NULL; countTable = NULL; };
~SharedListVector(){ if (groupmap != NULL) { delete groupmap; } if (countTable != NULL) { delete countTable; } };
int getNumBins() { return numBins; }
void set(int, string);
string get(int);
+ vector<string> getLabels();
+ void setLabels(vector<string>);
void push_back(string);
void resize(int);
void clear();
int maxRank;
int numBins;
int numSeqs;
+ vector<string> binLabels;
};
//parse labels to save
istringstream iStringStream(label);
- m->binLabelsInFile.clear();
+ m->sharedBinLabelsInFile.clear();
while(!iStringStream.eof()){
if (m->control_pressed) { break; }
string temp;
iStringStream >> temp; m->gobble(iStringStream);
- m->binLabelsInFile.push_back(temp);
+ m->sharedBinLabelsInFile.push_back(temp);
}
f >> label;
}else { label = m->saveNextLabel; }
//reset labels, currentLabels may have gotten changed as otus were eliminated because of group choices or sampling
- m->currentBinLabels = m->binLabelsInFile;
+ m->currentSharedBinLabels = m->sharedBinLabelsInFile;
//read in first row since you know there is at least 1 group.
f >> groupN >> num;
//parse labels to save
istringstream iStringStream(label);
- m->binLabelsInFile.clear();
+ m->sharedBinLabelsInFile.clear();
while(!iStringStream.eof()){
if (m->control_pressed) { break; }
string temp;
iStringStream >> temp; m->gobble(iStringStream);
- m->binLabelsInFile.push_back(temp);
+ m->sharedBinLabelsInFile.push_back(temp);
}
f >> label >> groupN >> num;
//make binlabels because we don't have any
string snumBins = toString(num);
- m->binLabelsInFile.clear();
+ m->sharedBinLabelsInFile.clear();
for (int i = 0; i < num; i++) {
//if there is a bin label use it otherwise make one
string binLabel = "Otu";
for (int h = 0; h < diff; h++) { binLabel += "0"; }
}
binLabel += sbinNumber;
- m->binLabelsInFile.push_back(binLabel);
+ m->sharedBinLabelsInFile.push_back(binLabel);
}
}
}else {
}
//reset labels, currentLabels may have gotten changed as otus were eliminated because of group choices or sampling
- m->currentBinLabels = m->binLabelsInFile;
+ m->currentSharedBinLabels = m->sharedBinLabelsInFile;
holdLabel = label;
for (int h = 0; h < diff; h++) { binLabel += "0"; }
}
binLabel += sbinNumber;
- if (i < m->currentBinLabels.size()) { binLabel = m->currentBinLabels[i]; }
+ if (i < m->currentSharedBinLabels.size()) { binLabel = m->currentSharedBinLabels[i]; }
output << binLabel << '\t';
}
for (int h = 0; h < diff; h++) { binLabel += "0"; }
}
binLabel += sbinNumber;
- if (i < m->currentBinLabels.size()) { binLabel = m->currentBinLabels[i]; }
+ if (i < m->currentSharedBinLabels.size()) { binLabel = m->currentSharedBinLabels[i]; }
output << binLabel << '\t';
}
output << endl;
}
- m->printedHeaders = true;
+ m->printedSharedHeaders = true;
}
catch(exception& e) {
m->errorOut(e, "SharedRAbundVector", "printHeaders");
for (int h = 0; h < diff; h++) { binLabel += "0"; }
}
binLabel += sbinNumber;
- if (i < m->currentBinLabels.size()) { binLabel = m->currentBinLabels[i]; }
+ if (i < m->currentSharedBinLabels.size()) { binLabel = m->currentSharedBinLabels[i]; }
newBinLabels.push_back(binLabel);
}
for (int j = 0; j < thislookup.size(); j++) { delete thislookup[j]; }
thislookup = newLookup;
- m->currentBinLabels = newBinLabels;
+ m->currentSharedBinLabels = newBinLabels;
return 0;
//parse labels to save
istringstream iStringStream(label);
- m->binLabelsInFile.clear();
+ m->sharedBinLabelsInFile.clear();
while(!iStringStream.eof()){
if (m->control_pressed) { break; }
string temp;
iStringStream >> temp; m->gobble(iStringStream);
- m->binLabelsInFile.push_back(temp);
+ m->sharedBinLabelsInFile.push_back(temp);
}
f >> label >> groupN >> num;
//make binlabels because we don't have any
string snumBins = toString(num);
- m->binLabelsInFile.clear();
+ m->sharedBinLabelsInFile.clear();
for (int i = 0; i < num; i++) {
//if there is a bin label use it otherwise make one
string binLabel = "Otu";
for (int h = 0; h < diff; h++) { binLabel += "0"; }
}
binLabel += sbinNumber;
- m->binLabelsInFile.push_back(binLabel);
+ m->sharedBinLabelsInFile.push_back(binLabel);
}
}
}else {
}
//reset labels, currentLabels may have gotten changed as otus were eliminated because of group choices or sampling
- m->currentBinLabels = m->binLabelsInFile;
+ m->currentSharedBinLabels = m->sharedBinLabelsInFile;
holdLabel = label;
for (int h = 0; h < diff; h++) { binLabel += "0"; }
}
binLabel += sbinNumber;
- if (i < m->currentBinLabels.size()) { binLabel = m->currentBinLabels[i]; }
+ if (i < m->currentSharedBinLabels.size()) { binLabel = m->currentSharedBinLabels[i]; }
output << binLabel << '\t';
}
for (int h = 0; h < diff; h++) { binLabel += "0"; }
}
binLabel += sbinNumber;
- if (i < m->currentBinLabels.size()) { binLabel = m->currentBinLabels[i]; }
+ if (i < m->currentSharedBinLabels.size()) { binLabel = m->currentSharedBinLabels[i]; }
output << binLabel << '\t';
}
output << endl;
}
- m->printedHeaders = true;
+ m->printedSharedHeaders = true;
}
catch(exception& e) {
m->errorOut(e, "SharedRAbundVector", "printHeaders");
for (int h = 0; h < diff; h++) { binLabel += "0"; }
}
binLabel += sbinNumber;
- if (i < m->currentBinLabels.size()) { binLabel = m->currentBinLabels[i]; }
+ if (i < m->currentSharedBinLabels.size()) { binLabel = m->currentSharedBinLabels[i]; }
newBinLabels.push_back(binLabel);
}
for (int j = 0; j < thislookup.size(); j++) { delete thislookup[j]; }
thislookup = newLookup;
- m->currentBinLabels = newBinLabels;
+ m->currentSharedBinLabels = newBinLabels;
return 0;
}
//they are shared
- if (sharedByAll == true) { observed++; labels.push_back(m->currentBinLabels[i]); }
+ if (sharedByAll == true) { observed++; labels.push_back(m->currentSharedBinLabels[i]); }
}
data[0] = observed;
cout.setf(ios::showpoint);
vector<vector<float> > sharedVector;
- vector<string> otuNames = m->currentBinLabels;
+ vector<string> otuNames = m->currentSharedBinLabels;
//fill sharedVector to pass to CalcSparcc
for (int i = 0; i < lookup.size(); i++) {
try {
//save mothurOut's binLabels to restore for next label
- vector<string> saveBinLabels = m->currentBinLabels;
+ vector<string> saveBinLabels = m->currentSharedBinLabels;
int numBins = thislookup[0]->getNumBins();
for (int i = 0; i < thislookup.size(); i++) {
for (int j = 0; j < size; j++) {
- if (m->control_pressed) { return m->currentBinLabels; }
+ if (m->control_pressed) { return m->currentSharedBinLabels; }
int bin = order.get(j);
//subsampling may have created some otus with no sequences in them
eliminateZeroOTUS(thislookup);
- if (m->control_pressed) { return m->currentBinLabels; }
+ if (m->control_pressed) { return m->currentSharedBinLabels; }
//save mothurOut's binLabels to restore for next label
- vector<string> subsampleBinLabels = m->currentBinLabels;
- m->currentBinLabels = saveBinLabels;
+ vector<string> subsampleBinLabels = m->currentSharedBinLabels;
+ m->currentSharedBinLabels = saveBinLabels;
return subsampleBinLabels;
for (int h = 0; h < diff; h++) { binLabel += "0"; }
}
binLabel += sbinNumber;
- if (i < m->currentBinLabels.size()) { binLabel = m->currentBinLabels[i]; }
+ if (i < m->currentSharedBinLabels.size()) { binLabel = m->currentSharedBinLabels[i]; }
newBinLabels.push_back(binLabel);
}
thislookup.clear();
thislookup = newLookup;
- m->currentBinLabels = newBinLabels;
+ m->currentSharedBinLabels = newBinLabels;
return 0;
try {
//save mothurOut's binLabels to restore for next label
- vector<string> saveBinLabels = m->currentBinLabels;
+ vector<string> saveBinLabels = m->currentSharedBinLabels;
string thisOutputDir = outputDir;
if (outputDir == "") { thisOutputDir += m->hasPath(sharedfile); }
m->openOutputFile(outputFileName, out);
outputTypes["shared"].push_back(outputFileName); outputNames.push_back(outputFileName);
- m->currentBinLabels = subsampledLabels;
+ m->currentSharedBinLabels = subsampledLabels;
thislookup[0]->printHeaders(out);
//save mothurOut's binLabels to restore for next label
- m->currentBinLabels = saveBinLabels;
+ m->currentSharedBinLabels = saveBinLabels;
return 0;