}
//for each bin
+ vector<string> newBinLabels;
for (int i = 0; i < thislookup[0]->getNumBins(); i++) {
if (m->control_pressed) { for (int j = 0; j < newLookup.size(); j++) { delete newLookup[j]; } return 0; }
for (int j = 0; j < thislookup.size(); j++) {
newLookup[j]->push_back(thislookup[j]->getAbundance(i), thislookup[j]->getGroup());
}
+
+ //if there is a bin label use it otherwise make one
+ string binLabel = "Otu" + (i+1);
+ if (i < m->currentBinLabels.size()) { binLabel = m->currentBinLabels[i]; }
+
+ newBinLabels.push_back(binLabel);
}
}
for (int j = 0; j < thislookup.size(); j++) { delete thislookup[j]; }
thislookup = newLookup;
+ m->currentBinLabels = newBinLabels;
return 0;
mout->names.clear();
mout->saveNextLabel = "";
mout->printedHeaders = false;
+ mout->currentBinLabels.clear();
+ mout->binLabelsInFile.clear();
Command* command = cFactory->getCommand(commandName, options);
quitCommandCalled = command->execute();
mout->names.clear();
mout->saveNextLabel = "";
mout->printedHeaders = false;
+ mout->currentBinLabels.clear();
+ mout->binLabelsInFile.clear();
+
Command* command = cFactory->getCommand(commandName, options);
quitCommandCalled = command->execute();
mout->names.clear();
mout->saveNextLabel = "";
mout->printedHeaders = false;
+ mout->currentBinLabels.clear();
+ mout->binLabelsInFile.clear();
+
Command* command = cFactory->getCommand(commandName, options);
quitCommandCalled = command->execute();
m->openInputFile(fName, fileHandle);
filename = fName;
m->saveNextLabel = "";
-
-
}
/***********************************************************************/
InputData::~InputData(){
fileHandle.close();
m->saveNextLabel = "";
-
}
/***********************************************************************/
m->openInputFile(fName, fileHandle);
m->saveNextLabel = "";
+
}
catch(exception& e) {
m->errorOut(e, "InputData", "InputData");
//get filename
string outputFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + thisLookUp[0]->getLabel() + "." + setA + "-" + setB + ".metastats";
outputNames.push_back(outputFileName); outputTypes["metastats"].push_back(outputFileName);
- int nameLength = outputFileName.length();
- char * output = new char[nameLength];
- strcpy(output, outputFileName.c_str());
+ //int nameLength = outputFileName.length();
+ //char * output = new char[nameLength];
+ //strcpy(output, outputFileName.c_str());
//build matrix from shared rabunds
- double** data;
- data = new double*[thisLookUp[0]->getNumBins()];
+ //double** data;
+ //data = new double*[thisLookUp[0]->getNumBins()];
vector< vector<double> > data2; data2.resize(thisLookUp[0]->getNumBins());
}else {
//fill data
for (int j = 0; j < thisLookUp[0]->getNumBins(); j++) {
- data[j] = new double[subset.size()];
+ //data[j] = new double[subset.size()];
data2[j].resize(subset.size(), 0.0);
for (int i = 0; i < subset.size(); i++) {
- data[j][i] = (subset[i]->getAbundance(j));
+ //data[j][i] = (subset[i]->getAbundance(j));
data2[j][i] = (subset[i]->getAbundance(j));
}
}
m->mothurOut("Comparing " + setA + " and " + setB + "..."); m->mothurOutEndLine();
- metastat_main(output, thisLookUp[0]->getNumBins(), subset.size(), threshold, iters, data, setACount);
+ //metastat_main(output, thisLookUp[0]->getNumBins(), subset.size(), threshold, iters, data, setACount);
m->mothurOutEndLine();
MothurMetastats mothurMeta(threshold, iters);
- mothurMeta.runMetastats(outputFileName+".myVersion" , data2, setACount);
+ mothurMeta.runMetastats(outputFileName , data2, setACount);
m->mothurOutEndLine();
m->mothurOutEndLine();
}
//free memory
- delete output;
- for(int i = 0; i < thisLookUp[0]->getNumBins(); i++) { delete[] data[i]; }
- delete[] data;
+ //delete output;
+ //for(int i = 0; i < thisLookUp[0]->getNumBins(); i++) { delete[] data[i]; }
+ //delete[] data;
}
return 0;
for (int i = 0; i < C1.size(); i++) { C1[i].resize(3, 0.0); }
vector< vector<double> > C2; C2.resize(row);
for (int i = 0; i < C2.size(); i++) { C2[i].resize(3, 0.0); }
- vector<double> storage; storage.resize(row, 0.0);
- vector<double> tool; tool.resize(row, 0.0);
+ vector<double> storage; storage.resize(a, 0.0);
+ vector<double> tool; tool.resize(a, 0.0);
double xbardiff = 0.0; double denom = 0.0;
meanvar(Pmatrix, secondGroupingStart, storage);
vector<string> Treenames;
map<string, string> names;
vector<string> namesOfGroups;
+ vector<string> binLabelsInFile;
+ vector<string> currentBinLabels;
string saveNextLabel, argv, sharedHeaderMode;
bool printedHeaders;
if (abort == true) { if (calledHelp) { return 0; } return 2; }
- string outputFileName = outputDir + m->getRootName(m->getSimpleName(inputfile)) + "norm.shared";
- ofstream out;
- m->openOutputFile(outputFileName, out);
-
input = new InputData(inputfile, format);
//you are reading a sharedfile and you do not want to make relabund
//as long as you are not at the end of the file or done wih the lines you want
while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
- if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } m->Groups.clear(); out.close(); m->mothurRemove(outputFileName); return 0; }
+ if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } m->Groups.clear(); return 0; }
if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){
m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
- if (!m->printedHeaders) { lookup[0]->printHeaders(out); }
- normalize(lookup, out);
+ normalize(lookup);
processedLabels.insert(lookup[0]->getLabel());
userLabels.erase(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); }
- normalize(lookup, out);
+
+ normalize(lookup);
processedLabels.insert(lookup[0]->getLabel());
userLabels.erase(lookup[0]->getLabel());
//prevent memory leak
for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; lookup[i] = NULL; }
- if (m->control_pressed) { outputTypes.clear(); m->Groups.clear(); out.close(); m->mothurRemove(outputFileName); return 0; }
+ if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); m->Groups.clear(); return 0; }
//get next line to process
lookup = input->getSharedRAbundVectors();
}
- if (m->control_pressed) { outputTypes.clear(); m->Groups.clear(); out.close(); m->mothurRemove(outputFileName); return 0; }
+ if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); m->Groups.clear(); return 0; }
//output error messages about any remaining user labels
set<string>::iterator it;
lookup = input->getSharedRAbundVectors(lastLabel);
m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
- if (!m->printedHeaders) { lookup[0]->printHeaders(out); }
- normalize(lookup, out);
+
+ normalize(lookup);
for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
}
//as long as you are not at the end of the file or done wih the lines you want
while((lookupFloat[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
- if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; } m->Groups.clear(); out.close(); m->mothurRemove(outputFileName); return 0; }
+ if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; } m->Groups.clear(); return 0; }
if(allLines == 1 || labels.count(lookupFloat[0]->getLabel()) == 1){
m->mothurOut(lookupFloat[0]->getLabel()); m->mothurOutEndLine();
- if (!m->printedHeaders) { lookupFloat[0]->printHeaders(out); }
- normalize(lookupFloat, out);
+ normalize(lookupFloat);
processedLabels.insert(lookupFloat[0]->getLabel());
userLabels.erase(lookupFloat[0]->getLabel());
lookupFloat = input->getSharedRAbundFloatVectors(lastLabel);
m->mothurOut(lookupFloat[0]->getLabel()); m->mothurOutEndLine();
- if (!m->printedHeaders) { lookupFloat[0]->printHeaders(out); }
- normalize(lookupFloat, out);
+
+ normalize(lookupFloat);
processedLabels.insert(lookupFloat[0]->getLabel());
userLabels.erase(lookupFloat[0]->getLabel());
//prevent memory leak
for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; lookupFloat[i] = NULL; }
- if (m->control_pressed) { outputTypes.clear(); m->Groups.clear(); out.close(); m->mothurRemove(outputFileName); return 0; }
+ if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); m->Groups.clear(); return 0; }
//get next line to process
lookupFloat = input->getSharedRAbundFloatVectors();
}
- if (m->control_pressed) { outputTypes.clear(); m->Groups.clear(); out.close(); m->mothurRemove(outputFileName); return 0; }
+ if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); m->Groups.clear(); return 0; }
//output error messages about any remaining user labels
set<string>::iterator it;
m->mothurOut(lookupFloat[0]->getLabel()); m->mothurOutEndLine();
- if (!m->printedHeaders) { lookupFloat[0]->printHeaders(out); }
- normalize(lookupFloat, out);
+ normalize(lookupFloat);
for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; }
}
//reset groups parameter
m->Groups.clear();
delete input;
- out.close();
- if (m->control_pressed) { outputTypes.clear(); m->mothurRemove(outputFileName); return 0;}
+ if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); return 0;}
m->mothurOutEndLine();
m->mothurOut("Output File Names: "); m->mothurOutEndLine();
- m->mothurOut(outputFileName); m->mothurOutEndLine(); outputNames.push_back(outputFileName); outputTypes["shared"].push_back(outputFileName);
+ //m->mothurOut(outputFileName); m->mothurOutEndLine(); outputNames.push_back(outputFileName); outputTypes["shared"].push_back(outputFileName);
+ for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
m->mothurOutEndLine();
//set shared file as new current sharedfile
}
//**********************************************************************************************************************
-int NormalizeSharedCommand::normalize(vector<SharedRAbundVector*>& thisLookUp, ofstream& out){
+int NormalizeSharedCommand::normalize(vector<SharedRAbundVector*>& thisLookUp){
try {
+ //save mothurOut's binLabels to restore for next label
+ vector<string> saveBinLabels = m->currentBinLabels;
+
if (pickedGroups) { eliminateZeroOTUS(thisLookUp); }
+
+ string outputFileName = outputDir + m->getRootName(m->getSimpleName(inputfile)) + thisLookUp[0]->getLabel() + ".norm.shared";
+ ofstream out;
+ m->openOutputFile(outputFileName, out);
+ outputNames.push_back(outputFileName); outputTypes["shared"].push_back(outputFileName);
if (method == "totalgroup") {
for (int i = 0; i < thisLookUp.size(); i++) {
- if (m->control_pressed) { return 0; }
+ if (m->control_pressed) { out.close(); return 0; }
int abund = thisLookUp[i]->getAbundance(j);
for (int j = 0; j < thisLookUp[0]->getNumBins(); j++) {
- if (m->control_pressed) { return 0; }
+ if (m->control_pressed) { out.close(); return 0; }
//calc mean
float mean = 0.0;
eliminateZeroOTUS(thisLookUp);
+
+ thisLookUp[0]->printHeaders(out);
for (int i = 0; i < thisLookUp.size(); i++) {
out << thisLookUp[i]->getLabel() << '\t' << thisLookUp[i]->getGroup() << '\t';
thisLookUp[i]->print(out);
}
+ out.close();
+
+ m->currentBinLabels = saveBinLabels;
+
return 0;
}
catch(exception& e) {
}
//**********************************************************************************************************************
-int NormalizeSharedCommand::normalize(vector<SharedRAbundFloatVector*>& thisLookUp, ofstream& out){
+int NormalizeSharedCommand::normalize(vector<SharedRAbundFloatVector*>& thisLookUp){
try {
+
+ //save mothurOut's binLabels to restore for next label
+ vector<string> saveBinLabels = m->currentBinLabels;
+
+ string outputFileName = outputDir + m->getRootName(m->getSimpleName(inputfile)) + thisLookUp[0]->getLabel() + ".norm.shared";
+ ofstream out;
+ m->openOutputFile(outputFileName, out);
+ outputNames.push_back(outputFileName); outputTypes["shared"].push_back(outputFileName);
+
+
if (pickedGroups) { eliminateZeroOTUS(thisLookUp); }
if (method == "totalgroup") {
for (int i = 0; i < thisLookUp.size(); i++) {
- if (m->control_pressed) { return 0; }
+ if (m->control_pressed) { out.close(); return 0; }
float abund = thisLookUp[i]->getAbundance(j);
}else if (method == "zscore") {
for (int j = 0; j < thisLookUp[0]->getNumBins(); j++) {
- if (m->control_pressed) { return 0; }
+ if (m->control_pressed) { out.close(); return 0; }
//calc mean
float mean = 0.0;
eliminateZeroOTUS(thisLookUp);
+ thisLookUp[0]->printHeaders(out);
+
for (int i = 0; i < thisLookUp.size(); i++) {
out << thisLookUp[i]->getLabel() << '\t' << thisLookUp[i]->getGroup() << '\t';
thisLookUp[i]->print(out);
}
+ out.close();
+
+ m->currentBinLabels = saveBinLabels;
+
return 0;
}
catch(exception& e) {
}
//for each bin
+ vector<string> newBinLabels;
for (int i = 0; i < thislookup[0]->getNumBins(); i++) {
if (m->control_pressed) { for (int j = 0; j < newLookup.size(); j++) { delete newLookup[j]; } return 0; }
for (int j = 0; j < thislookup.size(); j++) {
newLookup[j]->push_back(thislookup[j]->getAbundance(i), thislookup[j]->getGroup());
}
+ //if there is a bin label use it otherwise make one
+ string binLabel = "Otu" + (i+1);
+ if (i < m->currentBinLabels.size()) { binLabel = m->currentBinLabels[i]; }
+
+ newBinLabels.push_back(binLabel);
}
}
for (int j = 0; j < thislookup.size(); j++) { delete thislookup[j]; }
thislookup = newLookup;
+ m->currentBinLabels = newBinLabels;
return 0;
}
//for each bin
+ vector<string> newBinLabels;
for (int i = 0; i < thislookup[0]->getNumBins(); i++) {
if (m->control_pressed) { for (int j = 0; j < newLookup.size(); j++) { delete newLookup[j]; } return 0; }
for (int j = 0; j < thislookup.size(); j++) {
newLookup[j]->push_back(thislookup[j]->getAbundance(i), thislookup[j]->getGroup());
}
+ //if there is a bin label use it otherwise make one
+ string binLabel = "Otu" + (i+1);
+ if (i < m->currentBinLabels.size()) { binLabel = m->currentBinLabels[i]; }
+
+ newBinLabels.push_back(binLabel);
}
}
for (int j = 0; j < thislookup.size(); j++) { delete thislookup[j]; }
thislookup = newLookup;
+ m->currentBinLabels = newBinLabels;
return 0;
int norm;
vector<string> Groups, outputNames;
- int normalize(vector<SharedRAbundVector*>&, ofstream&);
- int normalize(vector<SharedRAbundFloatVector*>&, ofstream&);
+ int normalize(vector<SharedRAbundVector*>&);
+ int normalize(vector<SharedRAbundFloatVector*>&);
int eliminateZeroOTUS(vector<SharedRAbundVector*>&);
int eliminateZeroOTUS(vector<SharedRAbundFloatVector*>&);
for (int j = 0; j < thislookup.size(); j++) {
newLookup[j]->push_back(thislookup[j]->getAbundance(i), thislookup[j]->getGroup());
}
+ //if there is a bin label use it otherwise make one
}
//else{ cout << "bin # " << i << " is all zeros" << endl; }
}
bool operator()(const individual& i1, const individual& i2) {
return (i1.abundance > i2.abundance);
}
- individual() { group = ""; bin = 0; abundance = 0; }
+ individual() { group = ""; bin = 0; abundance = 0; }
};
struct individualFloat {
//is this a shared file that has headers
if (label == "label") {
+ //gets "group"
+ f >> label; m->gobble(f);
+
+ //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->binLabelsInFile.clear();
+ while(!iStringStream.eof()){
+ if (m->control_pressed) { break; }
+ string temp;
+ iStringStream >> temp; m->gobble(iStringStream);
+
+ m->binLabelsInFile.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;
+
//read in first row since you know there is at least 1 group.
f >> groupN >> num;
try {
output << "label\tGroup\tnumOtus\t";
if (m->sharedHeaderMode == "tax") {
- for (int i = 0; i < numBins; i++) { output << "PhyloType" << (i+1) << '\t'; }
+ for (int i = 0; i < numBins; i++) {
+
+ //if there is a bin label use it otherwise make one
+ string binLabel = "PhyloType" + toString(i+1);
+ if (i < m->currentBinLabels.size()) { binLabel = m->currentBinLabels[i]; }
+
+ output << binLabel << '\t';
+ }
output << endl;
}else {
- for (int i = 0; i < numBins; i++) { output << "Otu" << (i+1) << '\t'; }
+ for (int i = 0; i < numBins; i++) {
+ //if there is a bin label use it otherwise make one
+ string binLabel = "Otu" + toString(i+1);
+ if (i < m->currentBinLabels.size()) { binLabel = m->currentBinLabels[i]; }
+
+ output << binLabel << '\t';
+ }
+
output << endl;
}
+
m->printedHeaders = true;
}
catch(exception& e) {
}
//for each bin
+ vector<string> newBinLabels;
for (int i = 0; i < thislookup[0]->getNumBins(); i++) {
if (m->control_pressed) { for (int j = 0; j < newLookup.size(); j++) { delete newLookup[j]; } return 0; }
for (int j = 0; j < thislookup.size(); j++) {
newLookup[j]->push_back(thislookup[j]->getAbundance(i), thislookup[j]->getGroup());
}
+ //if there is a bin label use it otherwise make one
+ string binLabel = "Otu" + (i+1);
+ if (i < m->currentBinLabels.size()) { binLabel = m->currentBinLabels[i]; }
+
+ newBinLabels.push_back(binLabel);
}
}
for (int j = 0; j < thislookup.size(); j++) { delete thislookup[j]; }
thislookup = newLookup;
+ m->currentBinLabels = newBinLabels;
return 0;
//is this a shared file that has headers
if (label == "label") {
+ //gets "group"
+ f >> label; m->gobble(f);
+
+ //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->binLabelsInFile.clear();
+ while(!iStringStream.eof()){
+ if (m->control_pressed) { break; }
+ string temp;
+ iStringStream >> temp; m->gobble(iStringStream);
+
+ m->binLabelsInFile.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;
+
//read in first row since you know there is at least 1 group.
f >> groupN >> num;
lookup[0]->push_back(inputData, groupN); //abundance, bin, group
push_back(inputData, groupN);
- //numSeqs += inputData;
- //numBins++;
+
if (inputData > maxRank) { maxRank = inputData; }
}
//fill vector.
for(int i=0;i<num;i++){
f >> inputData;
+
lookup[count]->push_back(inputData, groupN); //abundance, bin, group
}
/***********************************************************************/
void SharedRAbundVector::printHeaders(ostream& output){
try {
+
output << "label\tGroup\tnumOtus\t";
if (m->sharedHeaderMode == "tax") {
- for (int i = 0; i < numBins; i++) { output << "PhyloType" << (i+1) << '\t'; }
+ for (int i = 0; i < numBins; i++) {
+
+ //if there is a bin label use it otherwise make one
+ string binLabel = "PhyloType" + toString(i+1);
+ if (i < m->currentBinLabels.size()) { binLabel = m->currentBinLabels[i]; }
+
+ output << binLabel << '\t';
+ }
output << endl;
}else {
- for (int i = 0; i < numBins; i++) { output << "Otu" << (i+1) << '\t'; }
+ for (int i = 0; i < numBins; i++) {
+ //if there is a bin label use it otherwise make one
+ string mybinLabel = "Otu" + toString(i+1);
+ if (i < m->currentBinLabels.size()) { mybinLabel = m->currentBinLabels[i]; }
+
+ output << mybinLabel << '\t';
+ }
+
output << endl;
}
m->printedHeaders = true;
}
//for each bin
+ vector<string> newBinLabels;
for (int i = 0; i < thislookup[0]->getNumBins(); i++) {
if (m->control_pressed) { for (int j = 0; j < newLookup.size(); j++) { delete newLookup[j]; } return 0; }
for (int j = 0; j < thislookup.size(); j++) {
newLookup[j]->push_back(thislookup[j]->getAbundance(i), thislookup[j]->getGroup());
}
+
+ //if there is a bin label use it otherwise make one
+ string binLabel = "Otu" + (i+1);
+ if (i < m->currentBinLabels.size()) { binLabel = m->currentBinLabels[i]; }
+
+ newBinLabels.push_back(binLabel);
}
}
for (int j = 0; j < thislookup.size(); j++) { delete thislookup[j]; }
thislookup = newLookup;
+ m->currentBinLabels = newBinLabels;
return 0;
int getMaxRank();
string getGroup();
void setGroup(string);
+ string getBinLabel();
+ void setBinLabel(string);
int getGroupIndex();
void setGroupIndex(int);
if (lookup.size() == 0) { m->mothurOut("The size you selected is too large, skipping shared file."); m->mothurOutEndLine(); delete input; return 0; }
- string thisOutputDir = outputDir;
- if (outputDir == "") { thisOutputDir += m->hasPath(sharedfile); }
- string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(sharedfile)) + "subsample" + m->getExtension(sharedfile);
-
- ofstream out;
- m->openOutputFile(outputFileName, out);
- outputTypes["shared"].push_back(outputFileName); outputNames.push_back(outputFileName);
-
-
m->mothurOut("Sampling " + toString(size) + " from each group."); m->mothurOutEndLine();
//as long as you are not at the end of the file or done wih the lines you want
while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
- if (m->control_pressed) { delete input; for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; lookup[i] = NULL; } out.close(); return 0; }
+ if (m->control_pressed) { delete input; for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; lookup[i] = NULL; } return 0; }
if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){
m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
- if (!m->printedHeaders) { lookup[0]->printHeaders(out); }
- processShared(lookup, out);
+ processShared(lookup);
processedLabels.insert(lookup[0]->getLabel());
userLabels.erase(lookup[0]->getLabel());
lookup = input->getSharedRAbundVectors(lastLabel);
m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
- if (!m->printedHeaders) { lookup[0]->printHeaders(out); }
- processShared(lookup, out);
+ processShared(lookup);
processedLabels.insert(lookup[0]->getLabel());
userLabels.erase(lookup[0]->getLabel());
}
- if (m->control_pressed) { out.close(); return 0; }
+ if (m->control_pressed) { return 0; }
//output error messages about any remaining user labels
set<string>::iterator it;
m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
- if (!m->printedHeaders) { lookup[0]->printHeaders(out); }
- processShared(lookup, out);
+ processShared(lookup);
for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
}
delete input;
- out.close();
return 0;
}
}
//**********************************************************************************************************************
-int SubSampleCommand::processShared(vector<SharedRAbundVector*>& thislookup, ofstream& out) {
+int SubSampleCommand::processShared(vector<SharedRAbundVector*>& thislookup) {
try {
+ //save mothurOut's binLabels to restore for next label
+ vector<string> saveBinLabels = m->currentBinLabels;
+
+ string thisOutputDir = outputDir;
+ if (outputDir == "") { thisOutputDir += m->hasPath(sharedfile); }
+ string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(sharedfile)) + thislookup[0]->getLabel() + ".subsample" + m->getExtension(sharedfile);
+
+
+ ofstream out;
+ m->openOutputFile(outputFileName, out);
+ outputTypes["shared"].push_back(outputFileName); outputNames.push_back(outputFileName);
+
int numBins = thislookup[0]->getNumBins();
for (int i = 0; i < thislookup.size(); i++) {
int thisSize = thislookup[i]->getNumSeqs();
for (int j = 0; j < size; j++) {
- if (m->control_pressed) { delete order; return 0; }
+ if (m->control_pressed) { delete order; out.close(); return 0; }
//get random number to sample from order between 0 and thisSize-1.
int myrand = int((float)(thisSize) * (float)(rand()) / ((float)RAND_MAX+1.0));
//subsampling may have created some otus with no sequences in them
eliminateZeroOTUS(thislookup);
- if (m->control_pressed) { return 0; }
+ if (m->control_pressed) { out.close(); return 0; }
+
+ thislookup[0]->printHeaders(out);
for (int i = 0; i < thislookup.size(); i++) {
out << thislookup[i]->getLabel() << '\t' << thislookup[i]->getGroup() << '\t';
thislookup[i]->print(out);
}
+ out.close();
+
+ //save mothurOut's binLabels to restore for next label
+ m->currentBinLabels = saveBinLabels;
+
return 0;
}
}
//for each bin
+ vector<string> newBinLabels;
for (int i = 0; i < thislookup[0]->getNumBins(); i++) {
if (m->control_pressed) { for (int j = 0; j < newLookup.size(); j++) { delete newLookup[j]; } return 0; }
for (int j = 0; j < thislookup.size(); j++) {
newLookup[j]->push_back(thislookup[j]->getAbundance(i), thislookup[j]->getGroup());
}
+ //if there is a bin label use it otherwise make one
+ string binLabel = "Otu" + (i+1);
+ if (i < m->currentBinLabels.size()) { binLabel = m->currentBinLabels[i]; }
+
+ newBinLabels.push_back(binLabel);
}
}
thislookup.clear();
thislookup = newLookup;
+ m->currentBinLabels = newBinLabels;
return 0;
int getSubSampleRabund();
int getSubSampleSabund();
int getSubSampleFasta();
- int processShared(vector<SharedRAbundVector*>&, ofstream&);
+ int processShared(vector<SharedRAbundVector*>&);
int processRabund(RAbundVector*&, ofstream&);
int processSabund(SAbundVector*&, ofstream&);
int processList(ListVector*&, ofstream&, set<string>&);
numFPrimers = 0; //this needs to be initialized
numRPrimers = 0;
+ createGroup = false;
vector<vector<string> > fastaFileNames;
vector<vector<string> > qualFileNames;
vector<vector<string> > nameFileNames;
string outputGroupFileName;
if(oligoFile != ""){
- outputGroupFileName = outputDir + m->getRootName(m->getSimpleName(fastaFile)) + "groups";
- outputNames.push_back(outputGroupFileName); outputTypes["group"].push_back(outputGroupFileName);
- getOligos(fastaFileNames, qualFileNames, nameFileNames);
+ createGroup = getOligos(fastaFileNames, qualFileNames, nameFileNames);
+ if (createGroup) {
+ outputGroupFileName = outputDir + m->getRootName(m->getSimpleName(fastaFile)) + "groups";
+ outputNames.push_back(outputGroupFileName); outputTypes["group"].push_back(outputGroupFileName);
+ }
}
vector<unsigned long int> fastaFilePos;
ofstream outGroupsFile;
- if (oligoFile != ""){ m->openOutputFile(groupFileName, outGroupsFile); }
+ if (createGroup){ m->openOutputFile(groupFileName, outGroupsFile); }
if(allFiles){
for (int i = 0; i < fastaFileNames.size(); i++) { //clears old file
for (int j = 0; j < fastaFileNames[i].size(); j++) { //clears old file
if (m->control_pressed) {
inFASTA.close(); trimFASTAFile.close(); scrapFASTAFile.close();
- if (oligoFile != "") { outGroupsFile.close(); }
+ if (createGroup) { outGroupsFile.close(); }
if(qFileName != ""){
qFile.close();
else { m->mothurOut("[ERROR]: " + currSeq.getName() + " is not in your namefile, please correct."); m->mothurOutEndLine(); }
}
- if(barcodes.size() != 0){
- string thisGroup = barcodeNameVector[barcodeIndex];
- if (primers.size() != 0) { if (primerNameVector[primerIndex] != "") { thisGroup += "." + primerNameVector[primerIndex]; } }
-
- outGroupsFile << currSeq.getName() << '\t' << thisGroup << endl;
-
- if (nameFile != "") {
- map<string, string>::iterator itName = nameMap.find(currSeq.getName());
- if (itName != nameMap.end()) {
- vector<string> thisSeqsNames;
- m->splitAtChar(itName->second, thisSeqsNames, ',');
- for (int k = 1; k < thisSeqsNames.size(); k++) { //start at 1 to skip self
- outGroupsFile << thisSeqsNames[k] << '\t' << thisGroup << endl;
- }
- }else { m->mothurOut("[ERROR]: " + currSeq.getName() + " is not in your namefile, please correct."); m->mothurOutEndLine(); }
- }
-
- map<string, int>::iterator it = groupCounts.find(thisGroup);
- if (it == groupCounts.end()) { groupCounts[thisGroup] = 1; }
- else { groupCounts[it->first]++; }
+ if (createGroup) {
+ if(barcodes.size() != 0){
+ string thisGroup = barcodeNameVector[barcodeIndex];
+ if (primers.size() != 0) {
+ if (primerNameVector[primerIndex] != "") {
+ if(thisGroup != "") {
+ thisGroup += "." + primerNameVector[primerIndex];
+ }else {
+ thisGroup = primerNameVector[primerIndex];
+ }
+ }
+ }
+ outGroupsFile << currSeq.getName() << '\t' << thisGroup << endl;
+
+ if (nameFile != "") {
+ map<string, string>::iterator itName = nameMap.find(currSeq.getName());
+ if (itName != nameMap.end()) {
+ vector<string> thisSeqsNames;
+ m->splitAtChar(itName->second, thisSeqsNames, ',');
+ for (int k = 1; k < thisSeqsNames.size(); k++) { //start at 1 to skip self
+ outGroupsFile << thisSeqsNames[k] << '\t' << thisGroup << endl;
+ }
+ }else { m->mothurOut("[ERROR]: " + currSeq.getName() + " is not in your namefile, please correct."); m->mothurOutEndLine(); }
+ }
+
+ map<string, int>::iterator it = groupCounts.find(thisGroup);
+ if (it == groupCounts.end()) { groupCounts[thisGroup] = 1; }
+ else { groupCounts[it->first]++; }
+
+ }
}
-
if(allFiles){
ofstream output;
m->openOutputFileAppend(fastaFileNames[barcodeIndex][primerIndex], output);
inFASTA.close();
trimFASTAFile.close();
scrapFASTAFile.close();
- if (oligoFile != "") { outGroupsFile.close(); }
+ if (createGroup) { outGroupsFile.close(); }
if(qFileName != "") { qFile.close(); scrapQualFile.close(); trimQualFile.close(); }
if(nameFile != "") { scrapNameFile.close(); trimNameFile.close(); }
qLines[process]);
//pass groupCounts to parent
- if(oligoFile != ""){
+ if(createGroup){
ofstream out;
string tempFile = filename + toString(getpid()) + ".num.temp";
m->openOutputFile(tempFile, out);
m->mothurRemove((scrapNameFileName + toString(processIDS[i]) + ".temp"));
}
- if(oligoFile != ""){
+ if(createGroup){
m->appendFiles((groupFile + toString(processIDS[i]) + ".temp"), groupFile);
m->mothurRemove((groupFile + toString(processIDS[i]) + ".temp"));
}
}
}
- if(oligoFile != ""){
+ if(createGroup){
ifstream in;
string tempFile = filename + toString(processIDS[i]) + ".num.temp";
m->openInputFile(tempFile, in);
//***************************************************************************************************************
-void TrimSeqsCommand::getOligos(vector<vector<string> >& fastaFileNames, vector<vector<string> >& qualFileNames, vector<vector<string> >& nameFileNames){
+bool TrimSeqsCommand::getOligos(vector<vector<string> >& fastaFileNames, vector<vector<string> >& qualFileNames, vector<vector<string> >& nameFileNames){
try {
ifstream inOligos;
m->openInputFile(oligoFile, inOligos);
}
numFPrimers = primers.size();
numRPrimers = revPrimer.size();
-
+
+ bool allBlank = true;
+ for (int i = 0; i < barcodeNameVector.size(); i++) {
+ if (barcodeNameVector[i] != "") {
+ allBlank = false;
+ break;
+ }
+ }
+ for (int i = 0; i < primerNameVector.size(); i++) {
+ if (primerNameVector[i] != "") {
+ allBlank = false;
+ break;
+ }
+ }
+
+ if (allBlank) {
+ m->mothurOut("[WARNING]: your oligos file does not contain any group names. mothur will not create a groupfile."); m->mothurOutEndLine();
+ allFiles = false;
+ return false;
+ }
+
+ return true;
+
}
catch(exception& e) {
m->errorOut(e, "TrimSeqsCommand", "getOligos");
linePair(unsigned long int i, unsigned long int j) : start(i), end(j) {}
};
- void getOligos(vector<vector<string> >&, vector<vector<string> >&, vector<vector<string> >&);
+ bool getOligos(vector<vector<string> >&, vector<vector<string> >&, vector<vector<string> >&);
int stripBarcode(Sequence&, QualityScores&, int&);
int stripForward(Sequence&, QualityScores&, int&);
bool stripReverse(Sequence&, QualityScores&);
bool compareDNASeq(string, string);
int countDiffs(string, string);
- bool abort;
+ bool abort, createGroup;
string fastaFile, oligoFile, qFileName, groupfile, nameFile, outputDir;
bool flip, allFiles, qtrim;