mothurOut("\tDone."); mothurOutEndLine();
//delete globaldata's tree
- for (int m = 0; m < globaldata->gTree.size(); m++) { delete globaldata->gTree[m]; }
- globaldata->clear();
+ //for (int m = 0; m < globaldata->gTree.size(); m++) { delete globaldata->gTree[m]; }
+ //globaldata->gTree.clear();
//create consensus trees for each bootstrapped tree set
delete consensus;
//delete globaldata's tree
- for (int m = 0; m < globaldata->gTree.size(); m++) { delete globaldata->gTree[m]; }
- globaldata->clear();
+ //for (int m = 0; m < globaldata->gTree.size(); m++) { delete globaldata->gTree[m]; }
+ //globaldata->gTree.clear();
}
void GetSeqsCommand::readName(){
try {
- string outputFileName = getRootName(namefile) + "pick" + getExtension(namefile);;
+ string outputFileName = getRootName(namefile) + "pick" + getExtension(namefile);
ofstream out;
openOutputFile(outputFileName, out);
for (int i = 0; i < parsedNames.size(); i++) {
if (names.count(parsedNames[i]) == 1) {
validSecond.push_back(parsedNames[i]);
- names.erase(parsedNames[i]);
}
}
for (int i = 0; i < validSecond.size()-1; i++) { out << validSecond[i] << ','; }
out << validSecond[validSecond.size()-1] << endl;
- names.erase(firstCol);
//make first name in set you come to first column and then add the remaining names to second column
}else {
//free memory
if (gGroupmap != NULL) { delete gGroupmap; gGroupmap = NULL; }
+
if (gListVector != NULL) { delete gListVector; gListVector = NULL;}
+
if (gSparseMatrix != NULL) { delete gSparseMatrix; gSparseMatrix = NULL; }
+
if (ginput != NULL) { delete ginput; ginput = NULL;}
+
if (gorder != NULL) { delete gorder; gorder = NULL; }
+
if (glist != NULL) { delete glist; glist = NULL;}
+
if (gSharedList != NULL) { delete gSharedList; gSharedList = NULL; }
+
if (sabund != NULL) { delete sabund; sabund = NULL;}
+
if (rabund != NULL) { delete rabund; rabund = NULL; }
+
if (gMatrix != NULL) { delete gMatrix; gMatrix = NULL;}
+
if (gTreemap != NULL) { delete gTreemap; gTreemap = NULL; }
+
if (gSequenceDB != NULL) { delete gSequenceDB; gSequenceDB = NULL;}
+
gTree.clear();
Treenames.clear();
labels.clear(); lines.clear(); Groups.clear();
}
//make sure the user has already run the read.otu command
- if ((globaldata->getListFile() == "") && (globaldata->getSharedFile() == "")) {
- mothurOut("You must read a list, or a list and a group, or a shared before you can use the heatmap.bin command."); mothurOutEndLine(); abort = true;
+ if ((globaldata->getListFile() == "") && (globaldata->getRabundFile() == "") && (globaldata->getSabundFile() == "") && (globaldata->getSharedFile() == "")) {
+ mothurOut("You must read a list, rabund, sabund, or a list and a group, or a shared before you can use the heatmap.bin command."); mothurOutEndLine(); abort = true;
}
//check for optional parameter and set defaults
try {
if (abort == true) { return 0; }
-
+
int count = 1;
string lastLabel;
input = globaldata->ginput;
lookup = input->getSharedRAbundVectors();
lastLabel = lookup[0]->getLabel();
- }else if (format == "list") {
+
+ }else if ((format == "list") || (format == "rabund") || (format == "sabund")) {
//you are using just a list file and have only one group
read = new ReadOTUFile(globaldata->inputFileName);
read->read(&*globaldata);
-
+
rabund = globaldata->rabund;
lastLabel = rabund->getLabel();
- input = globaldata->ginput;
+ input = globaldata->ginput;
+
}
//if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
set<string> userLabels = labels;
set<int> userLines = lines;
- if (format != "list") {
+ if ((format != "list") && (format != "rabund") && (format != "sabund")) {
//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) || (userLines.size() != 0))) {
globaldata->Groups.clear();
}else{
-
+
while((rabund != NULL) && ((allLines == 1) || (userLabels.size() != 0) || (userLines.size() != 0))) {
if(allLines == 1 || lines.count(count) == 1 || labels.count(rabund->getLabel()) == 1){
}
+ globaldata->rabund = NULL;
delete input; globaldata->ginput = NULL;
return 0;
}
if(fileHandle){
if(format == "list") {
list = new ListVector(fileHandle);
- }
+ }else{ list = NULL; }
gobble(fileHandle);
return list;
else { delete list; }
gobble(in);
}
- }
+ }else{ list = NULL; }
in.close();
return list;
if(fileHandle){
if (format == "shared") {
SharedList = new SharedListVector(fileHandle);
- }
+ }else{ SharedList = NULL; }
gobble(fileHandle);
return SharedList;
gobble(in);
}
- }
+ }else{ SharedList = NULL; }
in.close();
return SharedList;
if(fileHandle){
if (format == "sharedfile") {
SharedOrder = new SharedOrderVector(fileHandle);
- }
+ }else{ SharedOrder = NULL; }
gobble(fileHandle);
return SharedOrder;
gobble(in);
}
- }
+ }else{ SharedOrder = NULL; }
in.close();
return SharedOrder;
else if(format == "sabund"){
input = new SAbundVector(fileHandle);
}
-
+
gobble(fileHandle);
- output = new OrderVector();
- *output = (input->getOrderVector());
+ output = new OrderVector();
+ *output = (input->getOrderVector());
+
return output;
}
else{
for (int i = lines[0]->start; i < lines[0]->end; i++) {
it = trimmed[i].begin();
- map<int, int> win = decalc->findWindows(querySeqs[i], it->first, it->second, windowSizes[i], increment);
- windows[i] = win;
+ vector<int> win = decalc->findWindows(querySeqs[i], it->first, it->second, windowSizes[i], increment);
+ windowsForeachQuery[i] = win;
}
#endif
#else
mothurOut("Calculating observed distance... "); cout.flush();
for (int i = lines[0]->start; i < lines[0]->end; i++) {
- vector<float> obsi = decalc->calcObserved(querySeqs[i], bestfit[i], windows[i], windowSizes[i]);
+ vector<float> obsi = decalc->calcObserved(querySeqs[i], bestfit[i], windowsForeachQuery[i], windowSizes[i]);
obsDistance[i] = obsi;
}
mothurOut("Done."); mothurOutEndLine();
mothurOut("Finding variability... "); cout.flush();
for (int i = lines[0]->start; i < lines[0]->end; i++) {
- vector<float> q = decalc->findQav(windows[i], windowSizes[i], probabilityProfile, h[i]);
+ vector<float> q = decalc->findQav(windowsForeachQuery[i], windowSizes[i], probabilityProfile);
Qav[i] = q;
}
mothurOut("Done."); mothurOutEndLine();
OrderVector RAbundVector::getOrderVector(map<string,int>* nameMap = NULL) {
try {
OrderVector ov;
-
+
for(int i=0;i<data.size();i++){
for(int j=0;j<data[i];j++){
ov.push_back(i);
}
}
random_shuffle(ov.begin(), ov.end());
-
ov.setLabel(label);
+ ov.getNumBins();
+
return ov;
}
catch(exception& e) {
//memory leak prevention
//if (globaldata->ginput != NULL) { delete globaldata->ginput; }
globaldata->ginput = input; //saving to be used by collector and rarefact commands.
-
+
if ((globaldata->getFormat() == "list") || (globaldata->getFormat() == "rabund") || (globaldata->getFormat() == "sabund")) {//you are reading a list, rabund or sabund file for collect, rarefaction or summary.
+
+//cout << input << '\t' << globaldata << endl;
order = input->getOrderVector();
//memory leak prevention
+
//if (globaldata->gorder != NULL) { delete globaldata->gorder; }
globaldata->gorder = order; //saving to be used by collect and rarefact commands.
sabund = inputSabund->getSAbundVector();
//if (globaldata->sabund != NULL) { delete globaldata->sabund; }
globaldata->sabund = sabund; //saving to be used by summary command.
delete inputSabund;
+
rabund = inputRabund->getRAbundVector();
//if (globaldata->rabund != NULL) { delete globaldata->rabund; }
globaldata->rabund = rabund; //saving to be used by heatmap.bin command.
delete inputRabund;
+
list = inputList->getListVector();
//if (globaldata->gListVector != NULL) { delete globaldata->gListVector; }
globaldata->gListVector = list;
//make new tree
T = new Tree();
+
numNodes = T->getNumNodes();
numLeaves = T->getNumLeaves();
try {
string outputFileName = getRootName(namefile) + "pick" + getExtension(namefile);
+
ofstream out;
openOutputFile(outputFileName, out);
in >> firstCol;
in >> secondCol;
-
+
vector<string> parsedNames;
//parse second column saving each name
while (secondCol.find_first_of(',') != -1) {
name = secondCol.substr(0,secondCol.find_first_of(','));
secondCol = secondCol.substr(secondCol.find_first_of(',')+1, secondCol.length());
parsedNames.push_back(name);
+
}
//get name after last ,
parsedNames.push_back(secondCol);
-
- vector<string> validSecond;
+
+ vector<string> validSecond; validSecond.clear();
for (int i = 0; i < parsedNames.size(); i++) {
if (names.count(parsedNames[i]) == 0) {
validSecond.push_back(parsedNames[i]);
- }else { names.erase(parsedNames[i]); }
+ }
}
-
//if the name in the first column is in the set then print it and any other names in second column also in set
if (names.count(firstCol) == 0) {
-
+
wroteSomething = true;
out << firstCol << '\t';
//make first name in set you come to first column and then add the remaining names to second column
}else {
- names.erase(firstCol);
-
+
//you want part of this row
if (validSecond.size() != 0) {
//alignreport file has a column header line then all other lines contain 16 columns. we just want the first column since that contains the name
void RemoveSeqsCommand::readAlign(){
try {
- string outputFileName = getRootName(alignfile) + "pick" + getExtension(alignfile);
+ string outputFileName = getRootName(getRootName(alignfile)) + "pick.align.report";
ofstream out;
openOutputFile(outputFileName, out);
out << thislookup[i]->getLabel() << '\t' << thislookup[i]->getGroup() << '\t';
thislookup[i]->print(out);
+ RAbundVector rav = thislookup[i]->getRAbundVector();
openOutputFileAppend(fileroot + thislookup[i]->getGroup() + ".rabund", *(filehandles[thislookup[i]->getGroup()]));
- (*filehandles[thislookup[i]->getGroup()]) << thislookup[i]->getLabel() << '\t' << thislookup[i]->getGroup() << '\t';
- thislookup[i]->print(*(filehandles[thislookup[i]->getGroup()]));
+ rav.print(*(filehandles[thislookup[i]->getGroup()]));
(*(filehandles[thislookup[i]->getGroup()])).close();
}
RAbundVector SharedRAbundVector::getRAbundVector() {
try {
- RAbundVector rav(data.size());
+ RAbundVector rav;
for (int i = 0; i < data.size(); i++) {
- rav.set(i, data[i].abundance);
+ if(data[i].abundance != 0) {
+ rav.push_back(data[i].abundance);
+ }
}
-
+
+ rav.setLabel(label);
return rav;
}
catch(exception& e) {
globaldata = GlobalData::getInstance();
if (globaldata->runParse == true) { parseTreeFile(); globaldata->runParse = false; }
-
+//for(int i = 0; i < globaldata->Treenames.size(); i++) { cout << i << '\t' << globaldata->Treenames[i] << endl; }
numLeaves = globaldata->Treenames.size();
numNodes = 2*numLeaves - 1;
}
/*****************************************************************/
-
+//this code is a mess and should be rethought...-slw
void Tree::parseTreeFile() {
//only takes names from the first tree and assumes that all trees use the same names.
openInputFile(filename, filehandle);
int c, comment;
comment = 0;
+ int done = 1;
//ifyou are not a nexus file
if((c = filehandle.peek()) != '#') {
filehandle.get();
}
- readTreeString(filehandle);
+ done = readTreeString(filehandle);
+ if (done == 0) { break; }
}
//ifyou are a nexus file
}else if((c = filehandle.peek()) == '#') {
comment = 0;
}
filehandle >> holder;
-
- //ifthere is no translate then you must read tree string otherwise use translate to get names
- if(holder == "tree" && comment != 1){
+
+ //if there is no translate then you must read tree string otherwise use translate to get names
+ if((holder == "tree") && (comment != 1)){
//pass over the "tree rep.6878900 = "
while (((c = filehandle.get()) != '(') && ((c = filehandle.peek()) != EOF)) {;}
if(c == EOF) { break; }
filehandle.putback(c); //put back first ( of tree.
- readTreeString(filehandle);
+ done = readTreeString(filehandle);
+
break;
}
+
+ if (done == 0) { break; }
}
//use nexus translation rather than parsing tree to save time
/*******************************************************/
/*******************************************************/
-void Tree::readTreeString(ifstream& filehandle) {
+int Tree::readTreeString(ifstream& filehandle) {
try {
int c;
- string name;// k;
+ string name; //, k
while((c = filehandle.peek()) != ';') {
//k = c;
while((c!=',') && (c != -1) && (c!= ':') && (c!=';')){ c=filehandle.get(); }
filehandle.putback(c);
}
- if(c == ';') { break; }
+ if(c == ';') { return 0; }
+ if(c == -1) { return 0; }
//if you are a name
if((c != '(') && (c != ')') && (c != ',') && (c != ':') && (c != '\n') && (c != '\t') && (c != 32)) { //32 is space
name = "";
if(c == ':') { //read until you reach the end of the branch length
while ((c != '(') && (c != ')') && (c != ',') && (c != ';') && (c != '\n') && (c != '\t') && (c != 32)) {
c = filehandle.get();
- //k = c;
+ //k = c;
//cout << " in branch while " << k << endl;
}
filehandle.putback(c);
}
-
+
c = filehandle.get();
- if(c == ';') { break; }
+//k = c;
+ //cout << " here after get " << k << endl;
+ if(c == ';') { return 0; }
if(c == ')') { filehandle.putback(c); }
- // k = c;
+ //k = c;
//cout << k << endl;
}
+ return 0;
}
catch(exception& e) {
errorOut(e, "Tree", "readTreeString");
//this is required in case user has sequences in the names file that are
//not included in the tree.
//only takes names from the first tree in the tree file and assumes that all trees use the same names.
- void readTreeString(ifstream&);
+ int readTreeString(ifstream&);
};
#endif