X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=normalizesharedcommand.cpp;fp=normalizesharedcommand.cpp;h=10c7a3068da7bf4ce015e221b6ca042cbd7ffb7d;hb=19fcbbdba99658f5eca244803280f9ee7f9f6607;hp=a4bdd47099c350e77cfe238bcf34e254d1db9341;hpb=65b6a38d00b3a72021611211e7c25392022c69ed;p=mothur.git diff --git a/normalizesharedcommand.cpp b/normalizesharedcommand.cpp index a4bdd47..10c7a30 100644 --- a/normalizesharedcommand.cpp +++ b/normalizesharedcommand.cpp @@ -244,7 +244,7 @@ int NormalizeSharedCommand::execute(){ //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(); remove(outputFileName.c_str()); return 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(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){ @@ -276,13 +276,13 @@ int NormalizeSharedCommand::execute(){ //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(); remove(outputFileName.c_str()); return 0; } + if (m->control_pressed) { outputTypes.clear(); m->Groups.clear(); out.close(); m->mothurRemove(outputFileName); return 0; } //get next line to process lookup = input->getSharedRAbundVectors(); } - if (m->control_pressed) { outputTypes.clear(); m->Groups.clear(); out.close(); remove(outputFileName.c_str()); return 0; } + if (m->control_pressed) { outputTypes.clear(); m->Groups.clear(); out.close(); m->mothurRemove(outputFileName); return 0; } //output error messages about any remaining user labels set::iterator it; @@ -348,7 +348,7 @@ int NormalizeSharedCommand::execute(){ //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(); remove(outputFileName.c_str()); return 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(allLines == 1 || labels.count(lookupFloat[0]->getLabel()) == 1){ @@ -382,13 +382,13 @@ int NormalizeSharedCommand::execute(){ //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(); remove(outputFileName.c_str()); return 0; } + if (m->control_pressed) { outputTypes.clear(); m->Groups.clear(); out.close(); m->mothurRemove(outputFileName); return 0; } //get next line to process lookupFloat = input->getSharedRAbundFloatVectors(); } - if (m->control_pressed) { outputTypes.clear(); m->Groups.clear(); out.close(); remove(outputFileName.c_str()); return 0; } + if (m->control_pressed) { outputTypes.clear(); m->Groups.clear(); out.close(); m->mothurRemove(outputFileName); return 0; } //output error messages about any remaining user labels set::iterator it; @@ -422,7 +422,7 @@ int NormalizeSharedCommand::execute(){ delete input; out.close(); - if (m->control_pressed) { outputTypes.clear(); remove(outputFileName.c_str()); return 0;} + if (m->control_pressed) { outputTypes.clear(); m->mothurRemove(outputFileName); return 0;} m->mothurOutEndLine(); m->mothurOut("Output File Names: "); m->mothurOutEndLine(); @@ -450,6 +450,10 @@ int NormalizeSharedCommand::normalize(vector& thisLookUp, o if (pickedGroups) { eliminateZeroOTUS(thisLookUp); } if (method == "totalgroup") { + + //save numSeqs since they will change as the data is normalized + vector sizes; + for (int i = 0; i < thisLookUp.size(); i++) { sizes.push_back(thisLookUp[i]->getNumSeqs()); } for (int j = 0; j < thisLookUp[0]->getNumBins(); j++) { @@ -459,7 +463,7 @@ int NormalizeSharedCommand::normalize(vector& thisLookUp, o int abund = thisLookUp[i]->getAbundance(j); - float relabund = abund / (float) thisLookUp[i]->getNumSeqs(); + float relabund = abund / (float) sizes[i]; float newNorm = relabund * norm; //round to nearest int @@ -525,6 +529,10 @@ int NormalizeSharedCommand::normalize(vector& thisLook if (method == "totalgroup") { + //save numSeqs since they will change as the data is normalized + vector sizes; + for (int i = 0; i < thisLookUp.size(); i++) { sizes.push_back(thisLookUp[i]->getNumSeqs()); } + for (int j = 0; j < thisLookUp[0]->getNumBins(); j++) { for (int i = 0; i < thisLookUp.size(); i++) { @@ -533,7 +541,7 @@ int NormalizeSharedCommand::normalize(vector& thisLook float abund = thisLookUp[i]->getAbundance(j); - float relabund = abund / (float) thisLookUp[i]->getNumSeqs(); + float relabund = abund / (float) sizes[i]; float newNorm = relabund * norm; thisLookUp[i]->set(j, newNorm, thisLookUp[i]->getGroup());