From 9a339a6b007b23c39b7eb20cc777af66dd2cebef Mon Sep 17 00:00:00 2001
From: pschloss <pschloss>
Date: Thu, 30 Jul 2009 11:25:41 +0000
Subject: [PATCH] pat's edits prior to v.1.5

---
 Mothur.xcodeproj/project.pbxproj |  4 ++--
 aligncommand.cpp                 |  4 +++-
 libshuffcommand.cpp              |  2 +-
 mothur.h                         | 20 +++++++++-----------
 nast.cpp                         |  8 ++------
 sharedchao1.cpp                  |  2 +-
 simpson.cpp                      | 10 +++++-----
 trimseqscommand.cpp              |  9 ++++-----
 8 files changed, 27 insertions(+), 32 deletions(-)

diff --git a/Mothur.xcodeproj/project.pbxproj b/Mothur.xcodeproj/project.pbxproj
index ab3240e..75294bc 100644
--- a/Mothur.xcodeproj/project.pbxproj
+++ b/Mothur.xcodeproj/project.pbxproj
@@ -288,8 +288,8 @@
 		375AA1360F9E433D008EF9B8 /* readotu.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = readotu.h; sourceTree = SOURCE_ROOT; };
 		375AA1370F9E433D008EF9B8 /* readphylip.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = readphylip.cpp; sourceTree = SOURCE_ROOT; };
 		375AA1380F9E433D008EF9B8 /* readphylip.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = readphylip.h; sourceTree = SOURCE_ROOT; };
-		377326630FAF16E0007ABB8B /* consensuscommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = consensuscommand.cpp; sourceTree = "<group>"; };
-		377326640FAF16E0007ABB8B /* consensuscommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = consensuscommand.h; sourceTree = "<group>"; };
+		377326630FAF16E0007ABB8B /* consensuscommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = consensuscommand.cpp; sourceTree = SOURCE_ROOT; };
+		377326640FAF16E0007ABB8B /* consensuscommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = consensuscommand.h; sourceTree = SOURCE_ROOT; };
 		378598640FDD497000EF9D03 /* heatmapsimcommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = heatmapsimcommand.h; sourceTree = SOURCE_ROOT; };
 		378598650FDD497000EF9D03 /* heatmapsimcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = heatmapsimcommand.cpp; sourceTree = SOURCE_ROOT; };
 		378598720FDD4C1500EF9D03 /* heatmapsim.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = heatmapsim.h; sourceTree = SOURCE_ROOT; };
diff --git a/aligncommand.cpp b/aligncommand.cpp
index d672fc3..958f29b 100644
--- a/aligncommand.cpp
+++ b/aligncommand.cpp
@@ -171,6 +171,8 @@ int AlignCommand::execute(){
 			mothurOutEndLine();
 			alignment = new NeedlemanOverlap(gapOpen, match, misMatch, longestBase);
 		}
+		mothurOut("Aligning sequences...");
+		mothurOutEndLine();
 		
 		string alignFileName = candidateFileName.substr(0,candidateFileName.find_last_of(".")+1) + "align";
 		string reportFileName = candidateFileName.substr(0,candidateFileName.find_last_of(".")+1) + "align.report";
@@ -283,7 +285,7 @@ int AlignCommand::driver(linePair* line, string alignFName, string reportFName){
 			report.setAlignmentParameters(align, alignment);
 
 			report.setNastParameters(nast);
-			
+
 			alignmentFile << '>' << candidateSeq->getName() << '\n' << candidateSeq->getAligned() << endl;
 			
 			report.print();
diff --git a/libshuffcommand.cpp b/libshuffcommand.cpp
index 73c0a74..e78c00d 100644
--- a/libshuffcommand.cpp
+++ b/libshuffcommand.cpp
@@ -208,7 +208,7 @@ void LibShuffCommand::printCoverageFile() {
 		vector<int> prevRow = it->second;
 		it++;
 		
-		for(it;it!=allDistances.end();it++){
+		for(;it!=allDistances.end();it++){
 			for(int i=0;i<it->second.size();i++){
 				it->second[i] += prevRow[i];
 			}
diff --git a/mothur.h b/mothur.h
index 2912433..b27c5ad 100644
--- a/mothur.h
+++ b/mothur.h
@@ -44,20 +44,17 @@
 #include <cerrno>
 #include <ctime>
 #include <limits>
+#include <sys/wait.h>
+#include <unistd.h>
 
 using namespace std;
 
-#ifdef _WIN32
-	#define exp(x) (exp((double) x))
-	#define sqrt(x) (sqrt((double) x))
-	#define log10(x) (log10((double) x))
-	#define log2(x) (log10(x)/log10(2))
-	#define isnan(x) ((x) != (x))
-	#define isinf(x) (fabs(x) == std::numeric_limits<double>::infinity())
-#else
-	#include <sys/wait.h>
-	#include <unistd.h>
-#endif
+#define exp(x) (exp((double) x))
+#define sqrt(x) (sqrt((double) x))
+#define log10(x) (log10((double) x))
+#define log2(x) (log10(x)/log10(2))
+#define isnan(x) ((x) != (x))
+#define isinf(x) (fabs(x) == std::numeric_limits<double>::infinity())
 
 
 typedef unsigned long ull;
@@ -96,6 +93,7 @@ inline void convert(const string& s, T& x, bool failIfLeftoverChars = true){
 	if (!(i >> x) || (failIfLeftoverChars && i.get(c)))
 		throw BadConversion(s);
 }
+
 //**********************************************************************************************************************
 
 template<typename T>
diff --git a/nast.cpp b/nast.cpp
index 4aed590..804e3c1 100644
--- a/nast.cpp
+++ b/nast.cpp
@@ -53,7 +53,6 @@ void Nast::pairwiseAlignSeqs(){	//	Here we call one of the pairwise alignment me
 
 		}
 		else{
-
 			if(tempAln[0] == '-'){
 				int pairwiseAlignmentLength = tempAln.length();	//	we need to make sure that the candidate sequence alignment
 				for(int i=0;i<pairwiseAlignmentLength;i++){		//	starts where the template sequence alignment starts, if it
@@ -64,7 +63,6 @@ void Nast::pairwiseAlignSeqs(){	//	Here we call one of the pairwise alignment me
 					}
 				}
 			}
-			
 			int pairwiseAlignmentLength = tempAln.length();
 			if(tempAln[pairwiseAlignmentLength-1] == '-'){		//	we need to make sure that the candidate sequence alignment
 				for(int i=pairwiseAlignmentLength-1; i>=0; i--){//	ends where the template sequence alignment ends, if it runs
@@ -113,8 +111,7 @@ void Nast::removeExtraGaps(string& candAln, string tempAln, string newTemplateAl
 						break;
 					}
 				}
-				
-				
+
 				for(rightIndex=i+1;rightIndex<longAlignmentLength-1;rightIndex++){
 					if(!isalpha(candAln[rightIndex])){
 						rightRoom = 1;	//count how far it is to the nearest gap on the RIGHT side of the anomaly
@@ -207,7 +204,6 @@ void Nast::removeExtraGaps(string& candAln, string tempAln, string newTemplateAl
 		errorOut(e, "Nast", "removeExtraGaps");
 		exit(1);
 	}	
-	
 }
 
 /**************************************************************************************************/
@@ -239,7 +235,7 @@ void Nast::regapSequences(){	//This is essentially part B in Fig 2. of DeSantis
 			newTemplateAlign += tempAln[fullAlignIndex];//	pairwise sequences
 			fullAlignIndex++;
 		}
-		
+
 		string lastLoop = "";
 		
 		while(pairwiseAlignIndex<pairwiseLength){
diff --git a/sharedchao1.cpp b/sharedchao1.cpp
index 803e953..cbb5192 100644
--- a/sharedchao1.cpp
+++ b/sharedchao1.cpp
@@ -50,7 +50,7 @@ EstOutput SharedChao1::getValues(vector<SharedRAbundVector*> shared){
 		//calculate chao1, (numleaves-1) because numleaves contains the ++ values.
 		bool bias;
 		for(int i=0;i<numLeaves;i++){
-			if ((f2leaves[i]->lvalue == 0) || (f2leaves[i]->rvalue == 0))  { bias = true;  }// break;}
+			if (f2leaves[i]->lvalue == 0 || f2leaves[i]->rvalue == 0) { bias = true;}// break;}
 		}
 
 		if(bias){
diff --git a/simpson.cpp b/simpson.cpp
index d260800..8e176cf 100644
--- a/simpson.cpp
+++ b/simpson.cpp
@@ -19,8 +19,8 @@ EstOutput Simpson::getValues(SAbundVector* rank){
 		double ci = 0;
 	
 		double maxRank = (double)rank->getMaxRank();
-		int sampled = rank->getNumSeqs();
-		int sobs = rank->getNumBins();
+		double sampled = (double)rank->getNumSeqs();
+		double sobs = (double)rank->getNumBins();
 	
 		double firstTerm = 0;
 		double secondTerm = 0;
@@ -31,8 +31,8 @@ EstOutput Simpson::getValues(SAbundVector* rank){
 			for(int i=1;i<=maxRank;i++){
 				simnum += (double)(rank->get(i)*i*(i-1));
 			}
-		
-			simpson = simnum / (double)(sampled*(sampled-1));
+			
+			simpson = simnum / (sampled*(sampled-1));
 		
 			for(int i=1;i<=maxRank;i++){
 				double piI = (double) i / (double)sampled;
@@ -40,7 +40,7 @@ EstOutput Simpson::getValues(SAbundVector* rank){
 				secondTerm += rank->get(i) * pow(piI, 2);
 			}
 		
-			double var = (4.0 / (double)sampled) * (firstTerm - secondTerm*secondTerm);
+			double var = (4.0 / sampled) * (firstTerm - secondTerm*secondTerm);
 			ci = 1.95 * pow(var, 0.5);
 		}
 	
diff --git a/trimseqscommand.cpp b/trimseqscommand.cpp
index 937b130..2a982c7 100644
--- a/trimseqscommand.cpp
+++ b/trimseqscommand.cpp
@@ -171,7 +171,6 @@ int TrimSeqsCommand::execute(){
 				if(qThreshold != 0)		{	success = stripQualThreshold(currSeq, qFile);	}
 				else if(qAverage != 0)	{	success = cullQualAverage(currSeq, qFile);		}
 				if(!success)			{	trashCode += 'q';								}
-				qFile.close();
 			}
 			if(barcodes.size() != 0){
 				success = stripBarcode(currSeq, group);
@@ -221,6 +220,7 @@ int TrimSeqsCommand::execute(){
 		outFASTA.close();
 		scrapFASTA.close();
 		outGroups.close();
+		if(qFileName != "")	{	qFile.close();	}
 		
 		for(int i=0;i<fastaFileNames.size();i++){
 			fastaFileNames[i]->close();
@@ -548,7 +548,8 @@ bool TrimSeqsCommand::cullQualAverage(Sequence& seq, ifstream& qFile){
 		string name;
 		
 		qFile >> name;
-		if (name.length() != 0) {  if(name.substr(1) != seq.getName())	{	mothurOut("sequence name mismatch btwn fasta and qual file"); mothurOutEndLine();	} }
+		if (name[0] == '>') {  if(name.substr(1) != seq.getName())	{	mothurOut("sequence name mismatch btwn fasta: " + seq.getName() + " and qual file: " + name); mothurOutEndLine();	} }
+		
 		while (!qFile.eof())	{	char c = qFile.get(); if (c == 10 || c == 13){	break;	}	}
 		
 		float score;	
@@ -559,7 +560,7 @@ bool TrimSeqsCommand::cullQualAverage(Sequence& seq, ifstream& qFile){
 			average += score;
 		}
 		average /= seqLength;
-		
+
 		if(average >= qAverage)	{	success = 1;	}
 		else					{	success = 0;	}
 		
@@ -572,5 +573,3 @@ bool TrimSeqsCommand::cullQualAverage(Sequence& seq, ifstream& qFile){
 }
 
 //***************************************************************************************************************
-
-
-- 
2.39.5