]> git.donarmstrong.com Git - mothur.git/commitdiff
Initial revision
authorwestcott <westcott>
Fri, 16 Jan 2009 22:17:34 +0000 (22:17 +0000)
committerwestcott <westcott>
Fri, 16 Jan 2009 22:17:34 +0000 (22:17 +0000)
154 files changed:
Mothur.1 [new file with mode: 0644]
Mothur.xcodeproj/project.pbxproj [new file with mode: 0644]
ace.cpp [new file with mode: 0644]
ace.h [new file with mode: 0644]
averagelinkage.cpp [new file with mode: 0644]
bootstrap.cpp [new file with mode: 0644]
bootstrap.h [new file with mode: 0644]
calculator.cpp [new file with mode: 0644]
calculator.h [new file with mode: 0644]
chao1.cpp [new file with mode: 0644]
chao1.h [new file with mode: 0644]
cluster.cpp [new file with mode: 0644]
cluster.hpp [new file with mode: 0644]
clustercommand.cpp [new file with mode: 0644]
clustercommand.h [new file with mode: 0644]
collect.cpp [new file with mode: 0644]
collect.h [new file with mode: 0644]
collectcommand.cpp [new file with mode: 0644]
collectcommand.h [new file with mode: 0644]
collectdisplay.h [new file with mode: 0644]
collectorscurvedata.h [new file with mode: 0644]
collectsharedcommand.cpp [new file with mode: 0644]
collectsharedcommand.h [new file with mode: 0644]
command.hpp [new file with mode: 0644]
commandfactory.cpp [new file with mode: 0644]
commandfactory.hpp [new file with mode: 0644]
commandoptionparser.cpp [new file with mode: 0644]
commandoptionparser.hpp [new file with mode: 0644]
completelinkage.cpp [new file with mode: 0644]
database.cpp [new file with mode: 0644]
database.hpp [new file with mode: 0644]
datavector.hpp [new file with mode: 0644]
display.h [new file with mode: 0644]
engine.cpp [new file with mode: 0644]
engine.hpp [new file with mode: 0644]
errorchecking.cpp [new file with mode: 0644]
errorchecking.h [new file with mode: 0644]
fastamap.cpp [new file with mode: 0644]
fastamap.h [new file with mode: 0644]
fileoutput.cpp [new file with mode: 0644]
fileoutput.h [new file with mode: 0644]
globaldata.cpp [new file with mode: 0644]
globaldata.hpp [new file with mode: 0644]
groupmap.cpp [new file with mode: 0644]
groupmap.h [new file with mode: 0644]
helpcommand.cpp [new file with mode: 0644]
helpcommand.h [new file with mode: 0644]
inputdata.cpp [new file with mode: 0644]
inputdata.h [new file with mode: 0644]
jackknife.cpp [new file with mode: 0644]
jackknife.h [new file with mode: 0644]
kmer.cpp [new file with mode: 0644]
kmer.hpp [new file with mode: 0644]
kmerdb.cpp [new file with mode: 0644]
kmerdb.hpp [new file with mode: 0644]
listvector.cpp [new file with mode: 0644]
listvector.hpp [new file with mode: 0644]
mothur.cpp [new file with mode: 0644]
nameassignment.cpp [new file with mode: 0644]
nameassignment.hpp [new file with mode: 0644]
nocommand.cpp [new file with mode: 0644]
nocommand.h [new file with mode: 0644]
npshannon.cpp [new file with mode: 0644]
npshannon.h [new file with mode: 0644]
observable.h [new file with mode: 0644]
ordervector.cpp [new file with mode: 0644]
ordervector.hpp [new file with mode: 0644]
parselistcommand.cpp [new file with mode: 0644]
parselistcommand.h [new file with mode: 0644]
progress.cpp [new file with mode: 0644]
progress.hpp [new file with mode: 0644]
quitcommand.cpp [new file with mode: 0644]
quitcommand.h [new file with mode: 0644]
rabundvector.cpp [new file with mode: 0644]
rabundvector.hpp [new file with mode: 0644]
rarecalc.cpp [new file with mode: 0644]
rarecalc.h [new file with mode: 0644]
raredisplay.cpp [new file with mode: 0644]
raredisplay.h [new file with mode: 0644]
rarefact.cpp [new file with mode: 0644]
rarefact.h [new file with mode: 0644]
rarefactcommand.cpp [new file with mode: 0644]
rarefactcommand.h [new file with mode: 0644]
rarefactioncurvedata.h [new file with mode: 0644]
rarefactsharedcommand.cpp [new file with mode: 0644]
rarefactsharedcommand.h [new file with mode: 0644]
readdistcolumnfilecommand.h [new file with mode: 0644]
readdistphylipfilecommand.cpp [new file with mode: 0644]
readdistphylipfilecommand.h [new file with mode: 0644]
readlistfilecommand.h [new file with mode: 0644]
readmatrix.cpp [new file with mode: 0644]
readmatrix.hpp [new file with mode: 0644]
readrabundfilecommand.cpp [new file with mode: 0644]
readsabundfilecommand.cpp [new file with mode: 0644]
readsabundfilecommand.h [new file with mode: 0644]
sabundvector.cpp [new file with mode: 0644]
sabundvector.hpp [new file with mode: 0644]
sequence.cpp [new file with mode: 0644]
sequence.hpp [new file with mode: 0644]
shannon.cpp [new file with mode: 0644]
shannon.h [new file with mode: 0644]
shared.cpp [new file with mode: 0644]
shared.h [new file with mode: 0644]
sharedace.cpp [new file with mode: 0644]
sharedace.h [new file with mode: 0644]
sharedchao1.cpp [new file with mode: 0644]
sharedchao1.h [new file with mode: 0644]
sharedcommand.cpp [new file with mode: 0644]
sharedcommand.h [new file with mode: 0644]
sharedjabund.cpp [new file with mode: 0644]
sharedjabund.h [new file with mode: 0644]
sharedjclass.cpp [new file with mode: 0644]
sharedjclass.h [new file with mode: 0644]
sharedjest.cpp [new file with mode: 0644]
sharedjest.h [new file with mode: 0644]
sharedordervector.cpp [new file with mode: 0644]
sharedordervector.h [new file with mode: 0644]
sharedrabundvector.cpp [new file with mode: 0644]
sharedrabundvector.h [new file with mode: 0644]
sharedsabundvector.cpp [new file with mode: 0644]
sharedsabundvector.h [new file with mode: 0644]
sharedsobs.cpp [new file with mode: 0644]
sharedsobs.h [new file with mode: 0644]
sharedsorabund.cpp [new file with mode: 0644]
sharedsorabund.h [new file with mode: 0644]
sharedsorclass.cpp [new file with mode: 0644]
sharedsorclass.h [new file with mode: 0644]
sharedsorest.cpp [new file with mode: 0644]
sharedsorest.h [new file with mode: 0644]
sharedthetan.cpp [new file with mode: 0644]
sharedthetan.h [new file with mode: 0644]
sharedthetayc.cpp [new file with mode: 0644]
sharedthetayc.h [new file with mode: 0644]
simpson.cpp [new file with mode: 0644]
simpson.h [new file with mode: 0644]
singlelinkage.cpp [new file with mode: 0644]
sobs.h [new file with mode: 0644]
sparsematrix.cpp [new file with mode: 0644]
sparsematrix.hpp [new file with mode: 0644]
summarycommand.cpp [new file with mode: 0644]
summarycommand.h [new file with mode: 0644]
summarydata.h [new file with mode: 0644]
summarydisplay.h [new file with mode: 0644]
summarysharedcommand.cpp [new file with mode: 0644]
summarysharedcommand.h [new file with mode: 0644]
utilities.hpp [new file with mode: 0644]
uvest.cpp [new file with mode: 0644]
uvest.h [new file with mode: 0644]
validcalculator.cpp [new file with mode: 0644]
validcalculator.h [new file with mode: 0644]
validcommands.cpp [new file with mode: 0644]
validcommands.h [new file with mode: 0644]
validparameter.cpp [new file with mode: 0644]
validparameter.h [new file with mode: 0644]

diff --git a/Mothur.1 b/Mothur.1
new file mode 100644 (file)
index 0000000..42e748c
--- /dev/null
+++ b/Mothur.1
@@ -0,0 +1,79 @@
+.\"Modified from man(1) of FreeBSD, the NetBSD mdoc.template, and mdoc.samples.\r
+.\"See Also:\r
+.\"man mdoc.samples for a complete listing of options\r
+.\"man mdoc for the short list of editing options\r
+.\"/usr/share/misc/mdoc.template\r
+.Dd 1/16/09               \" DATE \r
+.Dt Mothur 1      \" Program name and manual section number \r
+.Os Darwin\r
+.Sh NAME                 \" Section Header - required - don't modify \r
+.Nm Mothur,\r
+.\" The following lines are read in generating the apropos(man -k) database. Use only key\r
+.\" words here as the database is built based on the words here and in the .ND line. \r
+.Nm Other_name_for_same_program(),\r
+.Nm Yet another name for the same program.\r
+.\" Use .Nm macro to designate other names for the documented program.\r
+.Nd This line parsed for whatis database.\r
+.Sh SYNOPSIS             \" Section Header - required - don't modify\r
+.Nm\r
+.Op Fl abcd              \" [-abcd]\r
+.Op Fl a Ar path         \" [-a path] \r
+.Op Ar file              \" [file]\r
+.Op Ar                   \" [file ...]\r
+.Ar arg0                 \" Underlined argument - use .Ar anywhere to underline\r
+arg2 ...                 \" Arguments\r
+.Sh DESCRIPTION          \" Section Header - required - don't modify\r
+Use the .Nm macro to refer to your program throughout the man page like such:\r
+.Nm\r
+Underlining is accomplished with the .Ar macro like this:\r
+.Ar underlined text .\r
+.Pp                      \" Inserts a space\r
+A list of items with descriptions:\r
+.Bl -tag -width -indent  \" Begins a tagged list \r
+.It item a               \" Each item preceded by .It macro\r
+Description of item a\r
+.It item b\r
+Description of item b\r
+.El                      \" Ends the list\r
+.Pp\r
+A list of flags and their descriptions:\r
+.Bl -tag -width -indent  \" Differs from above in tag removed \r
+.It Fl a                 \"-a flag as a list item\r
+Description of -a flag\r
+.It Fl b\r
+Description of -b flag\r
+.El                      \" Ends the list\r
+.Pp\r
+.\" .Sh ENVIRONMENT      \" May not be needed\r
+.\" .Bl -tag -width "ENV_VAR_1" -indent \" ENV_VAR_1 is width of the string ENV_VAR_1\r
+.\" .It Ev ENV_VAR_1\r
+.\" Description of ENV_VAR_1\r
+.\" .It Ev ENV_VAR_2\r
+.\" Description of ENV_VAR_2\r
+.\" .El                      \r
+.Sh FILES                \" File used or created by the topic of the man page\r
+.Bl -tag -width "/Users/joeuser/Library/really_long_file_name" -compact\r
+.It Pa /usr/share/file_name\r
+FILE_1 description\r
+.It Pa /Users/joeuser/Library/really_long_file_name\r
+FILE_2 description\r
+.El                      \" Ends the list\r
+.\" .Sh DIAGNOSTICS       \" May not be needed\r
+.\" .Bl -diag\r
+.\" .It Diagnostic Tag\r
+.\" Diagnostic informtion here.\r
+.\" .It Diagnostic Tag\r
+.\" Diagnostic informtion here.\r
+.\" .El\r
+.Sh SEE ALSO \r
+.\" List links in ascending order by section, alphabetically within a section.\r
+.\" Please do not reference files that do not exist without filing a bug report\r
+.Xr a 1 , \r
+.Xr b 1 ,\r
+.Xr c 1 ,\r
+.Xr a 2 ,\r
+.Xr b 2 ,\r
+.Xr a 3 ,\r
+.Xr b 3 \r
+.\" .Sh BUGS              \" Document known, unremedied bugs \r
+.\" .Sh HISTORY           \" Document history if command behaves in a unique manner 
\ No newline at end of file
diff --git a/Mothur.xcodeproj/project.pbxproj b/Mothur.xcodeproj/project.pbxproj
new file mode 100644 (file)
index 0000000..a60c514
--- /dev/null
@@ -0,0 +1,696 @@
+// !$*UTF8*$!
+{
+       archiveVersion = 1;
+       classes = {
+       };
+       objectVersion = 44;
+       objects = {
+
+/* Begin PBXBuildFile section */
+               37D928550F21331F001D4494 /* ace.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D927B80F21331F001D4494 /* ace.cpp */; };
+               37D928560F21331F001D4494 /* averagelinkage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D927BA0F21331F001D4494 /* averagelinkage.cpp */; };
+               37D928570F21331F001D4494 /* bootstrap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D927BB0F21331F001D4494 /* bootstrap.cpp */; };
+               37D928580F21331F001D4494 /* calculator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D927BD0F21331F001D4494 /* calculator.cpp */; };
+               37D928590F21331F001D4494 /* chao1.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D927BF0F21331F001D4494 /* chao1.cpp */; };
+               37D9285A0F21331F001D4494 /* cluster.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D927C10F21331F001D4494 /* cluster.cpp */; };
+               37D9285B0F21331F001D4494 /* clustercommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D927C30F21331F001D4494 /* clustercommand.cpp */; };
+               37D9285C0F21331F001D4494 /* collect.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D927C50F21331F001D4494 /* collect.cpp */; };
+               37D9285D0F21331F001D4494 /* collectcommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D927C70F21331F001D4494 /* collectcommand.cpp */; };
+               37D9285E0F21331F001D4494 /* collectsharedcommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D927CB0F21331F001D4494 /* collectsharedcommand.cpp */; };
+               37D9285F0F21331F001D4494 /* commandfactory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D927CE0F21331F001D4494 /* commandfactory.cpp */; };
+               37D928600F21331F001D4494 /* commandoptionparser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D927D00F21331F001D4494 /* commandoptionparser.cpp */; };
+               37D928610F21331F001D4494 /* completelinkage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D927D20F21331F001D4494 /* completelinkage.cpp */; };
+               37D928620F21331F001D4494 /* database.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D927D30F21331F001D4494 /* database.cpp */; };
+               37D928630F21331F001D4494 /* engine.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D927D70F21331F001D4494 /* engine.cpp */; };
+               37D928640F21331F001D4494 /* errorchecking.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D927D90F21331F001D4494 /* errorchecking.cpp */; };
+               37D928650F21331F001D4494 /* fastamap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D927DB0F21331F001D4494 /* fastamap.cpp */; };
+               37D928660F21331F001D4494 /* fileoutput.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D927DD0F21331F001D4494 /* fileoutput.cpp */; };
+               37D928670F21331F001D4494 /* globaldata.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D927DF0F21331F001D4494 /* globaldata.cpp */; };
+               37D928680F21331F001D4494 /* groupmap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D927E10F21331F001D4494 /* groupmap.cpp */; };
+               37D928690F21331F001D4494 /* helpcommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D927E30F21331F001D4494 /* helpcommand.cpp */; };
+               37D9286A0F21331F001D4494 /* inputdata.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D927E50F21331F001D4494 /* inputdata.cpp */; };
+               37D9286B0F21331F001D4494 /* jackknife.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D927E70F21331F001D4494 /* jackknife.cpp */; };
+               37D9286C0F21331F001D4494 /* kmer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D927E90F21331F001D4494 /* kmer.cpp */; };
+               37D9286D0F21331F001D4494 /* kmerdb.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D927EB0F21331F001D4494 /* kmerdb.cpp */; };
+               37D9286E0F21331F001D4494 /* listvector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D927ED0F21331F001D4494 /* listvector.cpp */; };
+               37D9286F0F21331F001D4494 /* mothur.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D927EF0F21331F001D4494 /* mothur.cpp */; };
+               37D928700F21331F001D4494 /* nameassignment.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D927F00F21331F001D4494 /* nameassignment.cpp */; };
+               37D928710F21331F001D4494 /* nocommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D927F20F21331F001D4494 /* nocommand.cpp */; };
+               37D928720F21331F001D4494 /* npshannon.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D927F40F21331F001D4494 /* npshannon.cpp */; };
+               37D928730F21331F001D4494 /* ordervector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D927F70F21331F001D4494 /* ordervector.cpp */; };
+               37D928740F21331F001D4494 /* parselistcommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D927F90F21331F001D4494 /* parselistcommand.cpp */; };
+               37D928750F21331F001D4494 /* progress.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D927FB0F21331F001D4494 /* progress.cpp */; };
+               37D928760F21331F001D4494 /* quitcommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D927FD0F21331F001D4494 /* quitcommand.cpp */; };
+               37D928770F21331F001D4494 /* rabundvector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D927FF0F21331F001D4494 /* rabundvector.cpp */; };
+               37D928780F21331F001D4494 /* rarecalc.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D928010F21331F001D4494 /* rarecalc.cpp */; };
+               37D928790F21331F001D4494 /* raredisplay.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D928030F21331F001D4494 /* raredisplay.cpp */; };
+               37D9287A0F21331F001D4494 /* rarefact.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D928050F21331F001D4494 /* rarefact.cpp */; };
+               37D9287B0F21331F001D4494 /* rarefactcommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D928070F21331F001D4494 /* rarefactcommand.cpp */; };
+               37D9287C0F21331F001D4494 /* rarefactsharedcommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D9280A0F21331F001D4494 /* rarefactsharedcommand.cpp */; };
+               37D9287D0F21331F001D4494 /* readdistcolumnfilecommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D9280C0F21331F001D4494 /* readdistcolumnfilecommand.cpp */; };
+               37D9287E0F21331F001D4494 /* readdistphylipfilecommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D9280E0F21331F001D4494 /* readdistphylipfilecommand.cpp */; };
+               37D9287F0F21331F001D4494 /* readlistfilecommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D928100F21331F001D4494 /* readlistfilecommand.cpp */; };
+               37D928800F21331F001D4494 /* readmatrix.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D928120F21331F001D4494 /* readmatrix.cpp */; };
+               37D928810F21331F001D4494 /* readrabundfilecommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D928140F21331F001D4494 /* readrabundfilecommand.cpp */; };
+               37D928820F21331F001D4494 /* readsabundfilecommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D928160F21331F001D4494 /* readsabundfilecommand.cpp */; };
+               37D928830F21331F001D4494 /* readsharedfilecommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D928180F21331F001D4494 /* readsharedfilecommand.cpp */; };
+               37D928840F21331F001D4494 /* sabundvector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D9281A0F21331F001D4494 /* sabundvector.cpp */; };
+               37D928850F21331F001D4494 /* sequence.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D9281C0F21331F001D4494 /* sequence.cpp */; };
+               37D928860F21331F001D4494 /* shannon.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D9281E0F21331F001D4494 /* shannon.cpp */; };
+               37D928870F21331F001D4494 /* shared.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D928200F21331F001D4494 /* shared.cpp */; };
+               37D928880F21331F001D4494 /* sharedace.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D928220F21331F001D4494 /* sharedace.cpp */; };
+               37D928890F21331F001D4494 /* sharedchao1.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D928240F21331F001D4494 /* sharedchao1.cpp */; };
+               37D9288A0F21331F001D4494 /* sharedcommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D928260F21331F001D4494 /* sharedcommand.cpp */; };
+               37D9288B0F21331F001D4494 /* sharedjabund.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D928280F21331F001D4494 /* sharedjabund.cpp */; };
+               37D9288C0F21331F001D4494 /* sharedjclass.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D9282A0F21331F001D4494 /* sharedjclass.cpp */; };
+               37D9288D0F21331F001D4494 /* sharedjest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D9282C0F21331F001D4494 /* sharedjest.cpp */; };
+               37D9288E0F21331F001D4494 /* sharedordervector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D9282E0F21331F001D4494 /* sharedordervector.cpp */; };
+               37D9288F0F21331F001D4494 /* sharedrabundvector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D928300F21331F001D4494 /* sharedrabundvector.cpp */; };
+               37D928900F21331F001D4494 /* sharedsabundvector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D928320F21331F001D4494 /* sharedsabundvector.cpp */; };
+               37D928910F21331F001D4494 /* sharedsobs.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D928340F21331F001D4494 /* sharedsobs.cpp */; };
+               37D928920F21331F001D4494 /* sharedsorabund.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D928360F21331F001D4494 /* sharedsorabund.cpp */; };
+               37D928930F21331F001D4494 /* sharedsorclass.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D928380F21331F001D4494 /* sharedsorclass.cpp */; };
+               37D928940F21331F001D4494 /* sharedsorest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D9283A0F21331F001D4494 /* sharedsorest.cpp */; };
+               37D928950F21331F001D4494 /* sharedthetan.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D9283C0F21331F001D4494 /* sharedthetan.cpp */; };
+               37D928960F21331F001D4494 /* sharedthetayc.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D9283E0F21331F001D4494 /* sharedthetayc.cpp */; };
+               37D928970F21331F001D4494 /* simpson.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D928400F21331F001D4494 /* simpson.cpp */; };
+               37D928980F21331F001D4494 /* singlelinkage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D928420F21331F001D4494 /* singlelinkage.cpp */; };
+               37D928990F21331F001D4494 /* sparsematrix.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D928440F21331F001D4494 /* sparsematrix.cpp */; };
+               37D9289A0F21331F001D4494 /* summarycommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D928460F21331F001D4494 /* summarycommand.cpp */; };
+               37D9289B0F21331F001D4494 /* summarysharedcommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D9284A0F21331F001D4494 /* summarysharedcommand.cpp */; };
+               37D9289C0F21331F001D4494 /* uvest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D9284D0F21331F001D4494 /* uvest.cpp */; };
+               37D9289D0F21331F001D4494 /* validcalculator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D9284F0F21331F001D4494 /* validcalculator.cpp */; };
+               37D9289E0F21331F001D4494 /* validcommands.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D928510F21331F001D4494 /* validcommands.cpp */; };
+               37D9289F0F21331F001D4494 /* validparameter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D928530F21331F001D4494 /* validparameter.cpp */; };
+               8DD76F6A0486A84900D96B5E /* Mothur.1 in CopyFiles */ = {isa = PBXBuildFile; fileRef = C6859E8B029090EE04C91782 /* Mothur.1 */; };
+/* End PBXBuildFile section */
+
+/* Begin PBXCopyFilesBuildPhase section */
+               8DD76F690486A84900D96B5E /* CopyFiles */ = {
+                       isa = PBXCopyFilesBuildPhase;
+                       buildActionMask = 8;
+                       dstPath = /usr/share/man/man1/;
+                       dstSubfolderSpec = 0;
+                       files = (
+                               8DD76F6A0486A84900D96B5E /* Mothur.1 in CopyFiles */,
+                       );
+                       runOnlyForDeploymentPostprocessing = 1;
+               };
+/* End PBXCopyFilesBuildPhase section */
+
+/* Begin PBXFileReference section */
+               37D927B80F21331F001D4494 /* ace.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ace.cpp; sourceTree = "<group>"; };
+               37D927B90F21331F001D4494 /* ace.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ace.h; sourceTree = "<group>"; };
+               37D927BA0F21331F001D4494 /* averagelinkage.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = averagelinkage.cpp; sourceTree = "<group>"; };
+               37D927BB0F21331F001D4494 /* bootstrap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = bootstrap.cpp; sourceTree = "<group>"; };
+               37D927BC0F21331F001D4494 /* bootstrap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = bootstrap.h; sourceTree = "<group>"; };
+               37D927BD0F21331F001D4494 /* calculator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = calculator.cpp; sourceTree = "<group>"; };
+               37D927BE0F21331F001D4494 /* calculator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = calculator.h; sourceTree = "<group>"; };
+               37D927BF0F21331F001D4494 /* chao1.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = chao1.cpp; sourceTree = "<group>"; };
+               37D927C00F21331F001D4494 /* chao1.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = chao1.h; sourceTree = "<group>"; };
+               37D927C10F21331F001D4494 /* cluster.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = cluster.cpp; sourceTree = "<group>"; };
+               37D927C20F21331F001D4494 /* cluster.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = cluster.hpp; sourceTree = "<group>"; };
+               37D927C30F21331F001D4494 /* clustercommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = clustercommand.cpp; sourceTree = "<group>"; };
+               37D927C40F21331F001D4494 /* clustercommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = clustercommand.h; sourceTree = "<group>"; };
+               37D927C50F21331F001D4494 /* collect.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = collect.cpp; sourceTree = "<group>"; };
+               37D927C60F21331F001D4494 /* collect.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = collect.h; sourceTree = "<group>"; };
+               37D927C70F21331F001D4494 /* collectcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = collectcommand.cpp; sourceTree = "<group>"; };
+               37D927C80F21331F001D4494 /* collectcommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = collectcommand.h; sourceTree = "<group>"; };
+               37D927C90F21331F001D4494 /* collectdisplay.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = collectdisplay.h; sourceTree = "<group>"; };
+               37D927CA0F21331F001D4494 /* collectorscurvedata.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = collectorscurvedata.h; sourceTree = "<group>"; };
+               37D927CB0F21331F001D4494 /* collectsharedcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = collectsharedcommand.cpp; sourceTree = "<group>"; };
+               37D927CC0F21331F001D4494 /* collectsharedcommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = collectsharedcommand.h; sourceTree = "<group>"; };
+               37D927CD0F21331F001D4494 /* command.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = command.hpp; sourceTree = "<group>"; };
+               37D927CE0F21331F001D4494 /* commandfactory.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = commandfactory.cpp; sourceTree = "<group>"; };
+               37D927CF0F21331F001D4494 /* commandfactory.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = commandfactory.hpp; sourceTree = "<group>"; };
+               37D927D00F21331F001D4494 /* commandoptionparser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = commandoptionparser.cpp; sourceTree = "<group>"; };
+               37D927D10F21331F001D4494 /* commandoptionparser.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = commandoptionparser.hpp; sourceTree = "<group>"; };
+               37D927D20F21331F001D4494 /* completelinkage.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = completelinkage.cpp; sourceTree = "<group>"; };
+               37D927D30F21331F001D4494 /* database.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = database.cpp; sourceTree = "<group>"; };
+               37D927D40F21331F001D4494 /* database.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = database.hpp; sourceTree = "<group>"; };
+               37D927D50F21331F001D4494 /* datavector.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = datavector.hpp; sourceTree = "<group>"; };
+               37D927D60F21331F001D4494 /* display.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = display.h; sourceTree = "<group>"; };
+               37D927D70F21331F001D4494 /* engine.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = engine.cpp; sourceTree = "<group>"; };
+               37D927D80F21331F001D4494 /* engine.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = engine.hpp; sourceTree = "<group>"; };
+               37D927D90F21331F001D4494 /* errorchecking.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = errorchecking.cpp; sourceTree = "<group>"; };
+               37D927DA0F21331F001D4494 /* errorchecking.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = errorchecking.h; sourceTree = "<group>"; };
+               37D927DB0F21331F001D4494 /* fastamap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = fastamap.cpp; sourceTree = "<group>"; };
+               37D927DC0F21331F001D4494 /* fastamap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = fastamap.h; sourceTree = "<group>"; };
+               37D927DD0F21331F001D4494 /* fileoutput.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = fileoutput.cpp; sourceTree = "<group>"; };
+               37D927DE0F21331F001D4494 /* fileoutput.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = fileoutput.h; sourceTree = "<group>"; };
+               37D927DF0F21331F001D4494 /* globaldata.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = globaldata.cpp; sourceTree = "<group>"; };
+               37D927E00F21331F001D4494 /* globaldata.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = globaldata.hpp; sourceTree = "<group>"; };
+               37D927E10F21331F001D4494 /* groupmap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = groupmap.cpp; sourceTree = "<group>"; };
+               37D927E20F21331F001D4494 /* groupmap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = groupmap.h; sourceTree = "<group>"; };
+               37D927E30F21331F001D4494 /* helpcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = helpcommand.cpp; sourceTree = "<group>"; };
+               37D927E40F21331F001D4494 /* helpcommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = helpcommand.h; sourceTree = "<group>"; };
+               37D927E50F21331F001D4494 /* inputdata.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = inputdata.cpp; sourceTree = "<group>"; };
+               37D927E60F21331F001D4494 /* inputdata.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = inputdata.h; sourceTree = "<group>"; };
+               37D927E70F21331F001D4494 /* jackknife.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = jackknife.cpp; sourceTree = "<group>"; };
+               37D927E80F21331F001D4494 /* jackknife.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = jackknife.h; sourceTree = "<group>"; };
+               37D927E90F21331F001D4494 /* kmer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = kmer.cpp; sourceTree = "<group>"; };
+               37D927EA0F21331F001D4494 /* kmer.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = kmer.hpp; sourceTree = "<group>"; };
+               37D927EB0F21331F001D4494 /* kmerdb.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = kmerdb.cpp; sourceTree = "<group>"; };
+               37D927EC0F21331F001D4494 /* kmerdb.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = kmerdb.hpp; sourceTree = "<group>"; };
+               37D927ED0F21331F001D4494 /* listvector.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = listvector.cpp; sourceTree = "<group>"; };
+               37D927EE0F21331F001D4494 /* listvector.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = listvector.hpp; sourceTree = "<group>"; };
+               37D927EF0F21331F001D4494 /* mothur.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = mothur.cpp; sourceTree = "<group>"; };
+               37D927F00F21331F001D4494 /* nameassignment.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = nameassignment.cpp; sourceTree = "<group>"; };
+               37D927F10F21331F001D4494 /* nameassignment.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = nameassignment.hpp; sourceTree = "<group>"; };
+               37D927F20F21331F001D4494 /* nocommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = nocommand.cpp; sourceTree = "<group>"; };
+               37D927F30F21331F001D4494 /* nocommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = nocommand.h; sourceTree = "<group>"; };
+               37D927F40F21331F001D4494 /* npshannon.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = npshannon.cpp; sourceTree = "<group>"; };
+               37D927F50F21331F001D4494 /* npshannon.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = npshannon.h; sourceTree = "<group>"; };
+               37D927F60F21331F001D4494 /* observable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = observable.h; sourceTree = "<group>"; };
+               37D927F70F21331F001D4494 /* ordervector.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ordervector.cpp; sourceTree = "<group>"; };
+               37D927F80F21331F001D4494 /* ordervector.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = ordervector.hpp; sourceTree = "<group>"; };
+               37D927F90F21331F001D4494 /* parselistcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = parselistcommand.cpp; sourceTree = "<group>"; };
+               37D927FA0F21331F001D4494 /* parselistcommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = parselistcommand.h; sourceTree = "<group>"; };
+               37D927FB0F21331F001D4494 /* progress.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = progress.cpp; sourceTree = "<group>"; };
+               37D927FC0F21331F001D4494 /* progress.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = progress.hpp; sourceTree = "<group>"; };
+               37D927FD0F21331F001D4494 /* quitcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = quitcommand.cpp; sourceTree = "<group>"; };
+               37D927FE0F21331F001D4494 /* quitcommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = quitcommand.h; sourceTree = "<group>"; };
+               37D927FF0F21331F001D4494 /* rabundvector.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = rabundvector.cpp; sourceTree = "<group>"; };
+               37D928000F21331F001D4494 /* rabundvector.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = rabundvector.hpp; sourceTree = "<group>"; };
+               37D928010F21331F001D4494 /* rarecalc.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = rarecalc.cpp; sourceTree = "<group>"; };
+               37D928020F21331F001D4494 /* rarecalc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = rarecalc.h; sourceTree = "<group>"; };
+               37D928030F21331F001D4494 /* raredisplay.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = raredisplay.cpp; sourceTree = "<group>"; };
+               37D928040F21331F001D4494 /* raredisplay.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = raredisplay.h; sourceTree = "<group>"; };
+               37D928050F21331F001D4494 /* rarefact.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = rarefact.cpp; sourceTree = "<group>"; };
+               37D928060F21331F001D4494 /* rarefact.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = rarefact.h; sourceTree = "<group>"; };
+               37D928070F21331F001D4494 /* rarefactcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = rarefactcommand.cpp; sourceTree = "<group>"; };
+               37D928080F21331F001D4494 /* rarefactcommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = rarefactcommand.h; sourceTree = "<group>"; };
+               37D928090F21331F001D4494 /* rarefactioncurvedata.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = rarefactioncurvedata.h; sourceTree = "<group>"; };
+               37D9280A0F21331F001D4494 /* rarefactsharedcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = rarefactsharedcommand.cpp; sourceTree = "<group>"; };
+               37D9280B0F21331F001D4494 /* rarefactsharedcommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = rarefactsharedcommand.h; sourceTree = "<group>"; };
+               37D9280C0F21331F001D4494 /* readdistcolumnfilecommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = readdistcolumnfilecommand.cpp; sourceTree = "<group>"; };
+               37D9280D0F21331F001D4494 /* readdistcolumnfilecommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = readdistcolumnfilecommand.h; sourceTree = "<group>"; };
+               37D9280E0F21331F001D4494 /* readdistphylipfilecommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = readdistphylipfilecommand.cpp; sourceTree = "<group>"; };
+               37D9280F0F21331F001D4494 /* readdistphylipfilecommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = readdistphylipfilecommand.h; sourceTree = "<group>"; };
+               37D928100F21331F001D4494 /* readlistfilecommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = readlistfilecommand.cpp; sourceTree = "<group>"; };
+               37D928110F21331F001D4494 /* readlistfilecommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = readlistfilecommand.h; sourceTree = "<group>"; };
+               37D928120F21331F001D4494 /* readmatrix.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = readmatrix.cpp; sourceTree = "<group>"; };
+               37D928130F21331F001D4494 /* readmatrix.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = readmatrix.hpp; sourceTree = "<group>"; };
+               37D928140F21331F001D4494 /* readrabundfilecommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = readrabundfilecommand.cpp; sourceTree = "<group>"; };
+               37D928150F21331F001D4494 /* readrabundfilecommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = readrabundfilecommand.h; sourceTree = "<group>"; };
+               37D928160F21331F001D4494 /* readsabundfilecommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = readsabundfilecommand.cpp; sourceTree = "<group>"; };
+               37D928170F21331F001D4494 /* readsabundfilecommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = readsabundfilecommand.h; sourceTree = "<group>"; };
+               37D928180F21331F001D4494 /* readsharedfilecommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = readsharedfilecommand.cpp; sourceTree = "<group>"; };
+               37D928190F21331F001D4494 /* readsharedfilecommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = readsharedfilecommand.h; sourceTree = "<group>"; };
+               37D9281A0F21331F001D4494 /* sabundvector.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sabundvector.cpp; sourceTree = "<group>"; };
+               37D9281B0F21331F001D4494 /* sabundvector.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = sabundvector.hpp; sourceTree = "<group>"; };
+               37D9281C0F21331F001D4494 /* sequence.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sequence.cpp; sourceTree = "<group>"; };
+               37D9281D0F21331F001D4494 /* sequence.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = sequence.hpp; sourceTree = "<group>"; };
+               37D9281E0F21331F001D4494 /* shannon.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = shannon.cpp; sourceTree = "<group>"; };
+               37D9281F0F21331F001D4494 /* shannon.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = shannon.h; sourceTree = "<group>"; };
+               37D928200F21331F001D4494 /* shared.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = shared.cpp; sourceTree = "<group>"; };
+               37D928210F21331F001D4494 /* shared.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = shared.h; sourceTree = "<group>"; };
+               37D928220F21331F001D4494 /* sharedace.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sharedace.cpp; sourceTree = "<group>"; };
+               37D928230F21331F001D4494 /* sharedace.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sharedace.h; sourceTree = "<group>"; };
+               37D928240F21331F001D4494 /* sharedchao1.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sharedchao1.cpp; sourceTree = "<group>"; };
+               37D928250F21331F001D4494 /* sharedchao1.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sharedchao1.h; sourceTree = "<group>"; };
+               37D928260F21331F001D4494 /* sharedcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sharedcommand.cpp; sourceTree = "<group>"; };
+               37D928270F21331F001D4494 /* sharedcommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sharedcommand.h; sourceTree = "<group>"; };
+               37D928280F21331F001D4494 /* sharedjabund.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sharedjabund.cpp; sourceTree = "<group>"; };
+               37D928290F21331F001D4494 /* sharedjabund.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sharedjabund.h; sourceTree = "<group>"; };
+               37D9282A0F21331F001D4494 /* sharedjclass.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sharedjclass.cpp; sourceTree = "<group>"; };
+               37D9282B0F21331F001D4494 /* sharedjclass.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sharedjclass.h; sourceTree = "<group>"; };
+               37D9282C0F21331F001D4494 /* sharedjest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sharedjest.cpp; sourceTree = "<group>"; };
+               37D9282D0F21331F001D4494 /* sharedjest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sharedjest.h; sourceTree = "<group>"; };
+               37D9282E0F21331F001D4494 /* sharedordervector.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sharedordervector.cpp; sourceTree = "<group>"; };
+               37D9282F0F21331F001D4494 /* sharedordervector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sharedordervector.h; sourceTree = "<group>"; };
+               37D928300F21331F001D4494 /* sharedrabundvector.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sharedrabundvector.cpp; sourceTree = "<group>"; };
+               37D928310F21331F001D4494 /* sharedrabundvector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sharedrabundvector.h; sourceTree = "<group>"; };
+               37D928320F21331F001D4494 /* sharedsabundvector.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sharedsabundvector.cpp; sourceTree = "<group>"; };
+               37D928330F21331F001D4494 /* sharedsabundvector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sharedsabundvector.h; sourceTree = "<group>"; };
+               37D928340F21331F001D4494 /* sharedsobs.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sharedsobs.cpp; sourceTree = "<group>"; };
+               37D928350F21331F001D4494 /* sharedsobs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sharedsobs.h; sourceTree = "<group>"; };
+               37D928360F21331F001D4494 /* sharedsorabund.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sharedsorabund.cpp; sourceTree = "<group>"; };
+               37D928370F21331F001D4494 /* sharedsorabund.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sharedsorabund.h; sourceTree = "<group>"; };
+               37D928380F21331F001D4494 /* sharedsorclass.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sharedsorclass.cpp; sourceTree = "<group>"; };
+               37D928390F21331F001D4494 /* sharedsorclass.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sharedsorclass.h; sourceTree = "<group>"; };
+               37D9283A0F21331F001D4494 /* sharedsorest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sharedsorest.cpp; sourceTree = "<group>"; };
+               37D9283B0F21331F001D4494 /* sharedsorest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sharedsorest.h; sourceTree = "<group>"; };
+               37D9283C0F21331F001D4494 /* sharedthetan.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sharedthetan.cpp; sourceTree = "<group>"; };
+               37D9283D0F21331F001D4494 /* sharedthetan.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sharedthetan.h; sourceTree = "<group>"; };
+               37D9283E0F21331F001D4494 /* sharedthetayc.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sharedthetayc.cpp; sourceTree = "<group>"; };
+               37D9283F0F21331F001D4494 /* sharedthetayc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sharedthetayc.h; sourceTree = "<group>"; };
+               37D928400F21331F001D4494 /* simpson.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = simpson.cpp; sourceTree = "<group>"; };
+               37D928410F21331F001D4494 /* simpson.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = simpson.h; sourceTree = "<group>"; };
+               37D928420F21331F001D4494 /* singlelinkage.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = singlelinkage.cpp; sourceTree = "<group>"; };
+               37D928430F21331F001D4494 /* sobs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sobs.h; sourceTree = "<group>"; };
+               37D928440F21331F001D4494 /* sparsematrix.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sparsematrix.cpp; sourceTree = "<group>"; };
+               37D928450F21331F001D4494 /* sparsematrix.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = sparsematrix.hpp; sourceTree = "<group>"; };
+               37D928460F21331F001D4494 /* summarycommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = summarycommand.cpp; sourceTree = "<group>"; };
+               37D928470F21331F001D4494 /* summarycommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = summarycommand.h; sourceTree = "<group>"; };
+               37D928480F21331F001D4494 /* summarydata.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = summarydata.h; sourceTree = "<group>"; };
+               37D928490F21331F001D4494 /* summarydisplay.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = summarydisplay.h; sourceTree = "<group>"; };
+               37D9284A0F21331F001D4494 /* summarysharedcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = summarysharedcommand.cpp; sourceTree = "<group>"; };
+               37D9284B0F21331F001D4494 /* summarysharedcommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = summarysharedcommand.h; sourceTree = "<group>"; };
+               37D9284C0F21331F001D4494 /* utilities.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = utilities.hpp; sourceTree = "<group>"; };
+               37D9284D0F21331F001D4494 /* uvest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = uvest.cpp; sourceTree = "<group>"; };
+               37D9284E0F21331F001D4494 /* uvest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = uvest.h; sourceTree = "<group>"; };
+               37D9284F0F21331F001D4494 /* validcalculator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = validcalculator.cpp; sourceTree = "<group>"; };
+               37D928500F21331F001D4494 /* validcalculator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = validcalculator.h; sourceTree = "<group>"; };
+               37D928510F21331F001D4494 /* validcommands.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = validcommands.cpp; sourceTree = "<group>"; };
+               37D928520F21331F001D4494 /* validcommands.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = validcommands.h; sourceTree = "<group>"; };
+               37D928530F21331F001D4494 /* validparameter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = validparameter.cpp; sourceTree = "<group>"; };
+               37D928540F21331F001D4494 /* validparameter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = validparameter.h; sourceTree = "<group>"; };
+               8DD76F6C0486A84900D96B5E /* Mothur */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = Mothur; sourceTree = BUILT_PRODUCTS_DIR; };
+               C6859E8B029090EE04C91782 /* Mothur.1 */ = {isa = PBXFileReference; lastKnownFileType = text.man; path = Mothur.1; sourceTree = "<group>"; };
+/* End PBXFileReference section */
+
+/* Begin PBXFrameworksBuildPhase section */
+               8DD76F660486A84900D96B5E /* Frameworks */ = {
+                       isa = PBXFrameworksBuildPhase;
+                       buildActionMask = 2147483647;
+                       files = (
+                       );
+                       runOnlyForDeploymentPostprocessing = 0;
+               };
+/* End PBXFrameworksBuildPhase section */
+
+/* Begin PBXGroup section */
+               08FB7794FE84155DC02AAC07 /* Mothur */ = {
+                       isa = PBXGroup;
+                       children = (
+                               08FB7795FE84155DC02AAC07 /* Source */,
+                               C6859E8C029090F304C91782 /* Documentation */,
+                               1AB674ADFE9D54B511CA2CBB /* Products */,
+                       );
+                       name = Mothur;
+                       sourceTree = "<group>";
+               };
+               08FB7795FE84155DC02AAC07 /* Source */ = {
+                       isa = PBXGroup;
+                       children = (
+                               37D927BA0F21331F001D4494 /* averagelinkage.cpp */,
+                               37D928A60F2133C0001D4494 /* calculators */,
+                               37D927C10F21331F001D4494 /* cluster.cpp */,
+                               37D927C20F21331F001D4494 /* cluster.hpp */,
+                               37D928A90F2133E5001D4494 /* commands */,
+                               37D927C50F21331F001D4494 /* collect.cpp */,
+                               37D927C60F21331F001D4494 /* collect.h */,
+                               37D927C90F21331F001D4494 /* collectdisplay.h */,
+                               37D928AC0F213420001D4494 /* containers */,
+                               37D927CA0F21331F001D4494 /* collectorscurvedata.h */,
+                               37D927CE0F21331F001D4494 /* commandfactory.cpp */,
+                               37D927CF0F21331F001D4494 /* commandfactory.hpp */,
+                               37D927D00F21331F001D4494 /* commandoptionparser.cpp */,
+                               37D927D10F21331F001D4494 /* commandoptionparser.hpp */,
+                               37D927D20F21331F001D4494 /* completelinkage.cpp */,
+                               37D927D30F21331F001D4494 /* database.cpp */,
+                               37D927D40F21331F001D4494 /* database.hpp */,
+                               37D927D60F21331F001D4494 /* display.h */,
+                               37D927D70F21331F001D4494 /* engine.cpp */,
+                               37D927D80F21331F001D4494 /* engine.hpp */,
+                               37D928B10F213472001D4494 /* errorcheckor */,
+                               37D927DD0F21331F001D4494 /* fileoutput.cpp */,
+                               37D927DE0F21331F001D4494 /* fileoutput.h */,
+                               37D927DF0F21331F001D4494 /* globaldata.cpp */,
+                               37D927E00F21331F001D4494 /* globaldata.hpp */,
+                               37D927E50F21331F001D4494 /* inputdata.cpp */,
+                               37D927E60F21331F001D4494 /* inputdata.h */,
+                               37D927E90F21331F001D4494 /* kmer.cpp */,
+                               37D927EA0F21331F001D4494 /* kmer.hpp */,
+                               37D927EB0F21331F001D4494 /* kmerdb.cpp */,
+                               37D927EC0F21331F001D4494 /* kmerdb.hpp */,
+                               37D927EF0F21331F001D4494 /* mothur.cpp */,
+                               37D927F00F21331F001D4494 /* nameassignment.cpp */,
+                               37D927F10F21331F001D4494 /* nameassignment.hpp */,
+                               37D927F60F21331F001D4494 /* observable.h */,
+                               37D927FB0F21331F001D4494 /* progress.cpp */,
+                               37D927FC0F21331F001D4494 /* progress.hpp */,
+                               37D928030F21331F001D4494 /* raredisplay.cpp */,
+                               37D928040F21331F001D4494 /* raredisplay.h */,
+                               37D928050F21331F001D4494 /* rarefact.cpp */,
+                               37D928060F21331F001D4494 /* rarefact.h */,
+                               37D928090F21331F001D4494 /* rarefactioncurvedata.h */,
+                               37D928120F21331F001D4494 /* readmatrix.cpp */,
+                               37D928130F21331F001D4494 /* readmatrix.hpp */,
+                               37D9281C0F21331F001D4494 /* sequence.cpp */,
+                               37D9281D0F21331F001D4494 /* sequence.hpp */,
+                               37D928200F21331F001D4494 /* shared.cpp */,
+                               37D928210F21331F001D4494 /* shared.h */,
+                               37D928420F21331F001D4494 /* singlelinkage.cpp */,
+                               37D928440F21331F001D4494 /* sparsematrix.cpp */,
+                               37D928450F21331F001D4494 /* sparsematrix.hpp */,
+                               37D928480F21331F001D4494 /* summarydata.h */,
+                               37D928490F21331F001D4494 /* summarydisplay.h */,
+                               37D9284C0F21331F001D4494 /* utilities.hpp */,
+                       );
+                       name = Source;
+                       sourceTree = "<group>";
+               };
+               1AB674ADFE9D54B511CA2CBB /* Products */ = {
+                       isa = PBXGroup;
+                       children = (
+                               8DD76F6C0486A84900D96B5E /* Mothur */,
+                       );
+                       name = Products;
+                       sourceTree = "<group>";
+               };
+               37D928A60F2133C0001D4494 /* calculators */ = {
+                       isa = PBXGroup;
+                       children = (
+                               37D927BE0F21331F001D4494 /* calculator.h */,
+                               37D927BD0F21331F001D4494 /* calculator.cpp */,
+                               37D927B90F21331F001D4494 /* ace.h */,
+                               37D927B80F21331F001D4494 /* ace.cpp */,
+                               37D927BC0F21331F001D4494 /* bootstrap.h */,
+                               37D927BB0F21331F001D4494 /* bootstrap.cpp */,
+                               37D927C00F21331F001D4494 /* chao1.h */,
+                               37D927BF0F21331F001D4494 /* chao1.cpp */,
+                               37D927E70F21331F001D4494 /* jackknife.cpp */,
+                               37D927E80F21331F001D4494 /* jackknife.h */,
+                               37D927F40F21331F001D4494 /* npshannon.cpp */,
+                               37D927F50F21331F001D4494 /* npshannon.h */,
+                               37D928010F21331F001D4494 /* rarecalc.cpp */,
+                               37D928020F21331F001D4494 /* rarecalc.h */,
+                               37D9281E0F21331F001D4494 /* shannon.cpp */,
+                               37D9281F0F21331F001D4494 /* shannon.h */,
+                               37D928220F21331F001D4494 /* sharedace.cpp */,
+                               37D928230F21331F001D4494 /* sharedace.h */,
+                               37D928240F21331F001D4494 /* sharedchao1.cpp */,
+                               37D928250F21331F001D4494 /* sharedchao1.h */,
+                               37D928280F21331F001D4494 /* sharedjabund.cpp */,
+                               37D928290F21331F001D4494 /* sharedjabund.h */,
+                               37D9282A0F21331F001D4494 /* sharedjclass.cpp */,
+                               37D9282B0F21331F001D4494 /* sharedjclass.h */,
+                               37D9282C0F21331F001D4494 /* sharedjest.cpp */,
+                               37D9282D0F21331F001D4494 /* sharedjest.h */,
+                               37D928340F21331F001D4494 /* sharedsobs.cpp */,
+                               37D928350F21331F001D4494 /* sharedsobs.h */,
+                               37D928360F21331F001D4494 /* sharedsorabund.cpp */,
+                               37D928370F21331F001D4494 /* sharedsorabund.h */,
+                               37D928380F21331F001D4494 /* sharedsorclass.cpp */,
+                               37D928390F21331F001D4494 /* sharedsorclass.h */,
+                               37D9283A0F21331F001D4494 /* sharedsorest.cpp */,
+                               37D9283B0F21331F001D4494 /* sharedsorest.h */,
+                               37D9283C0F21331F001D4494 /* sharedthetan.cpp */,
+                               37D9283D0F21331F001D4494 /* sharedthetan.h */,
+                               37D9283E0F21331F001D4494 /* sharedthetayc.cpp */,
+                               37D9283F0F21331F001D4494 /* sharedthetayc.h */,
+                               37D928400F21331F001D4494 /* simpson.cpp */,
+                               37D928410F21331F001D4494 /* simpson.h */,
+                               37D928430F21331F001D4494 /* sobs.h */,
+                               37D9284D0F21331F001D4494 /* uvest.cpp */,
+                               37D9284E0F21331F001D4494 /* uvest.h */,
+                       );
+                       name = calculators;
+                       sourceTree = "<group>";
+               };
+               37D928A90F2133E5001D4494 /* commands */ = {
+                       isa = PBXGroup;
+                       children = (
+                               37D927CD0F21331F001D4494 /* command.hpp */,
+                               37D927C40F21331F001D4494 /* clustercommand.h */,
+                               37D927C30F21331F001D4494 /* clustercommand.cpp */,
+                               37D927C80F21331F001D4494 /* collectcommand.h */,
+                               37D927C70F21331F001D4494 /* collectcommand.cpp */,
+                               37D927CB0F21331F001D4494 /* collectsharedcommand.cpp */,
+                               37D927CC0F21331F001D4494 /* collectsharedcommand.h */,
+                               37D927E30F21331F001D4494 /* helpcommand.cpp */,
+                               37D927E40F21331F001D4494 /* helpcommand.h */,
+                               37D927F20F21331F001D4494 /* nocommand.cpp */,
+                               37D927F30F21331F001D4494 /* nocommand.h */,
+                               37D927F90F21331F001D4494 /* parselistcommand.cpp */,
+                               37D927FA0F21331F001D4494 /* parselistcommand.h */,
+                               37D927FD0F21331F001D4494 /* quitcommand.cpp */,
+                               37D927FE0F21331F001D4494 /* quitcommand.h */,
+                               37D928070F21331F001D4494 /* rarefactcommand.cpp */,
+                               37D928080F21331F001D4494 /* rarefactcommand.h */,
+                               37D9280A0F21331F001D4494 /* rarefactsharedcommand.cpp */,
+                               37D9280B0F21331F001D4494 /* rarefactsharedcommand.h */,
+                               37D9280C0F21331F001D4494 /* readdistcolumnfilecommand.cpp */,
+                               37D9280D0F21331F001D4494 /* readdistcolumnfilecommand.h */,
+                               37D9280E0F21331F001D4494 /* readdistphylipfilecommand.cpp */,
+                               37D9280F0F21331F001D4494 /* readdistphylipfilecommand.h */,
+                               37D928100F21331F001D4494 /* readlistfilecommand.cpp */,
+                               37D928110F21331F001D4494 /* readlistfilecommand.h */,
+                               37D928140F21331F001D4494 /* readrabundfilecommand.cpp */,
+                               37D928150F21331F001D4494 /* readrabundfilecommand.h */,
+                               37D928160F21331F001D4494 /* readsabundfilecommand.cpp */,
+                               37D928170F21331F001D4494 /* readsabundfilecommand.h */,
+                               37D928180F21331F001D4494 /* readsharedfilecommand.cpp */,
+                               37D928190F21331F001D4494 /* readsharedfilecommand.h */,
+                               37D928260F21331F001D4494 /* sharedcommand.cpp */,
+                               37D928270F21331F001D4494 /* sharedcommand.h */,
+                               37D928460F21331F001D4494 /* summarycommand.cpp */,
+                               37D928470F21331F001D4494 /* summarycommand.h */,
+                               37D9284A0F21331F001D4494 /* summarysharedcommand.cpp */,
+                               37D9284B0F21331F001D4494 /* summarysharedcommand.h */,
+                       );
+                       name = commands;
+                       sourceTree = "<group>";
+               };
+               37D928AC0F213420001D4494 /* containers */ = {
+                       isa = PBXGroup;
+                       children = (
+                               37D927D50F21331F001D4494 /* datavector.hpp */,
+                               37D927DB0F21331F001D4494 /* fastamap.cpp */,
+                               37D927DC0F21331F001D4494 /* fastamap.h */,
+                               37D927E10F21331F001D4494 /* groupmap.cpp */,
+                               37D927E20F21331F001D4494 /* groupmap.h */,
+                               37D927ED0F21331F001D4494 /* listvector.cpp */,
+                               37D927EE0F21331F001D4494 /* listvector.hpp */,
+                               37D927F70F21331F001D4494 /* ordervector.cpp */,
+                               37D927F80F21331F001D4494 /* ordervector.hpp */,
+                               37D927FF0F21331F001D4494 /* rabundvector.cpp */,
+                               37D928000F21331F001D4494 /* rabundvector.hpp */,
+                               37D9281A0F21331F001D4494 /* sabundvector.cpp */,
+                               37D9281B0F21331F001D4494 /* sabundvector.hpp */,
+                               37D9282E0F21331F001D4494 /* sharedordervector.cpp */,
+                               37D9282F0F21331F001D4494 /* sharedordervector.h */,
+                               37D928300F21331F001D4494 /* sharedrabundvector.cpp */,
+                               37D928310F21331F001D4494 /* sharedrabundvector.h */,
+                               37D928320F21331F001D4494 /* sharedsabundvector.cpp */,
+                               37D928330F21331F001D4494 /* sharedsabundvector.h */,
+                       );
+                       name = containers;
+                       sourceTree = "<group>";
+               };
+               37D928B10F213472001D4494 /* errorcheckor */ = {
+                       isa = PBXGroup;
+                       children = (
+                               37D927D90F21331F001D4494 /* errorchecking.cpp */,
+                               37D927DA0F21331F001D4494 /* errorchecking.h */,
+                               37D9284F0F21331F001D4494 /* validcalculator.cpp */,
+                               37D928500F21331F001D4494 /* validcalculator.h */,
+                               37D928510F21331F001D4494 /* validcommands.cpp */,
+                               37D928520F21331F001D4494 /* validcommands.h */,
+                               37D928530F21331F001D4494 /* validparameter.cpp */,
+                               37D928540F21331F001D4494 /* validparameter.h */,
+                       );
+                       name = errorcheckor;
+                       sourceTree = "<group>";
+               };
+               C6859E8C029090F304C91782 /* Documentation */ = {
+                       isa = PBXGroup;
+                       children = (
+                               C6859E8B029090EE04C91782 /* Mothur.1 */,
+                       );
+                       name = Documentation;
+                       sourceTree = "<group>";
+               };
+/* End PBXGroup section */
+
+/* Begin PBXNativeTarget section */
+               8DD76F620486A84900D96B5E /* Mothur */ = {
+                       isa = PBXNativeTarget;
+                       buildConfigurationList = 1DEB923108733DC60010E9CD /* Build configuration list for PBXNativeTarget "Mothur" */;
+                       buildPhases = (
+                               8DD76F640486A84900D96B5E /* Sources */,
+                               8DD76F660486A84900D96B5E /* Frameworks */,
+                               8DD76F690486A84900D96B5E /* CopyFiles */,
+                       );
+                       buildRules = (
+                       );
+                       dependencies = (
+                       );
+                       name = Mothur;
+                       productInstallPath = "$(HOME)/bin";
+                       productName = Mothur;
+                       productReference = 8DD76F6C0486A84900D96B5E /* Mothur */;
+                       productType = "com.apple.product-type.tool";
+               };
+/* End PBXNativeTarget section */
+
+/* Begin PBXProject section */
+               08FB7793FE84155DC02AAC07 /* Project object */ = {
+                       isa = PBXProject;
+                       buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "Mothur" */;
+                       compatibilityVersion = "Xcode 3.0";
+                       hasScannedForEncodings = 1;
+                       mainGroup = 08FB7794FE84155DC02AAC07 /* Mothur */;
+                       projectDirPath = "";
+                       projectRoot = "";
+                       targets = (
+                               8DD76F620486A84900D96B5E /* Mothur */,
+                       );
+               };
+/* End PBXProject section */
+
+/* Begin PBXSourcesBuildPhase section */
+               8DD76F640486A84900D96B5E /* Sources */ = {
+                       isa = PBXSourcesBuildPhase;
+                       buildActionMask = 2147483647;
+                       files = (
+                               37D928550F21331F001D4494 /* ace.cpp in Sources */,
+                               37D928560F21331F001D4494 /* averagelinkage.cpp in Sources */,
+                               37D928570F21331F001D4494 /* bootstrap.cpp in Sources */,
+                               37D928580F21331F001D4494 /* calculator.cpp in Sources */,
+                               37D928590F21331F001D4494 /* chao1.cpp in Sources */,
+                               37D9285A0F21331F001D4494 /* cluster.cpp in Sources */,
+                               37D9285B0F21331F001D4494 /* clustercommand.cpp in Sources */,
+                               37D9285C0F21331F001D4494 /* collect.cpp in Sources */,
+                               37D9285D0F21331F001D4494 /* collectcommand.cpp in Sources */,
+                               37D9285E0F21331F001D4494 /* collectsharedcommand.cpp in Sources */,
+                               37D9285F0F21331F001D4494 /* commandfactory.cpp in Sources */,
+                               37D928600F21331F001D4494 /* commandoptionparser.cpp in Sources */,
+                               37D928610F21331F001D4494 /* completelinkage.cpp in Sources */,
+                               37D928620F21331F001D4494 /* database.cpp in Sources */,
+                               37D928630F21331F001D4494 /* engine.cpp in Sources */,
+                               37D928640F21331F001D4494 /* errorchecking.cpp in Sources */,
+                               37D928650F21331F001D4494 /* fastamap.cpp in Sources */,
+                               37D928660F21331F001D4494 /* fileoutput.cpp in Sources */,
+                               37D928670F21331F001D4494 /* globaldata.cpp in Sources */,
+                               37D928680F21331F001D4494 /* groupmap.cpp in Sources */,
+                               37D928690F21331F001D4494 /* helpcommand.cpp in Sources */,
+                               37D9286A0F21331F001D4494 /* inputdata.cpp in Sources */,
+                               37D9286B0F21331F001D4494 /* jackknife.cpp in Sources */,
+                               37D9286C0F21331F001D4494 /* kmer.cpp in Sources */,
+                               37D9286D0F21331F001D4494 /* kmerdb.cpp in Sources */,
+                               37D9286E0F21331F001D4494 /* listvector.cpp in Sources */,
+                               37D9286F0F21331F001D4494 /* mothur.cpp in Sources */,
+                               37D928700F21331F001D4494 /* nameassignment.cpp in Sources */,
+                               37D928710F21331F001D4494 /* nocommand.cpp in Sources */,
+                               37D928720F21331F001D4494 /* npshannon.cpp in Sources */,
+                               37D928730F21331F001D4494 /* ordervector.cpp in Sources */,
+                               37D928740F21331F001D4494 /* parselistcommand.cpp in Sources */,
+                               37D928750F21331F001D4494 /* progress.cpp in Sources */,
+                               37D928760F21331F001D4494 /* quitcommand.cpp in Sources */,
+                               37D928770F21331F001D4494 /* rabundvector.cpp in Sources */,
+                               37D928780F21331F001D4494 /* rarecalc.cpp in Sources */,
+                               37D928790F21331F001D4494 /* raredisplay.cpp in Sources */,
+                               37D9287A0F21331F001D4494 /* rarefact.cpp in Sources */,
+                               37D9287B0F21331F001D4494 /* rarefactcommand.cpp in Sources */,
+                               37D9287C0F21331F001D4494 /* rarefactsharedcommand.cpp in Sources */,
+                               37D9287D0F21331F001D4494 /* readdistcolumnfilecommand.cpp in Sources */,
+                               37D9287E0F21331F001D4494 /* readdistphylipfilecommand.cpp in Sources */,
+                               37D9287F0F21331F001D4494 /* readlistfilecommand.cpp in Sources */,
+                               37D928800F21331F001D4494 /* readmatrix.cpp in Sources */,
+                               37D928810F21331F001D4494 /* readrabundfilecommand.cpp in Sources */,
+                               37D928820F21331F001D4494 /* readsabundfilecommand.cpp in Sources */,
+                               37D928830F21331F001D4494 /* readsharedfilecommand.cpp in Sources */,
+                               37D928840F21331F001D4494 /* sabundvector.cpp in Sources */,
+                               37D928850F21331F001D4494 /* sequence.cpp in Sources */,
+                               37D928860F21331F001D4494 /* shannon.cpp in Sources */,
+                               37D928870F21331F001D4494 /* shared.cpp in Sources */,
+                               37D928880F21331F001D4494 /* sharedace.cpp in Sources */,
+                               37D928890F21331F001D4494 /* sharedchao1.cpp in Sources */,
+                               37D9288A0F21331F001D4494 /* sharedcommand.cpp in Sources */,
+                               37D9288B0F21331F001D4494 /* sharedjabund.cpp in Sources */,
+                               37D9288C0F21331F001D4494 /* sharedjclass.cpp in Sources */,
+                               37D9288D0F21331F001D4494 /* sharedjest.cpp in Sources */,
+                               37D9288E0F21331F001D4494 /* sharedordervector.cpp in Sources */,
+                               37D9288F0F21331F001D4494 /* sharedrabundvector.cpp in Sources */,
+                               37D928900F21331F001D4494 /* sharedsabundvector.cpp in Sources */,
+                               37D928910F21331F001D4494 /* sharedsobs.cpp in Sources */,
+                               37D928920F21331F001D4494 /* sharedsorabund.cpp in Sources */,
+                               37D928930F21331F001D4494 /* sharedsorclass.cpp in Sources */,
+                               37D928940F21331F001D4494 /* sharedsorest.cpp in Sources */,
+                               37D928950F21331F001D4494 /* sharedthetan.cpp in Sources */,
+                               37D928960F21331F001D4494 /* sharedthetayc.cpp in Sources */,
+                               37D928970F21331F001D4494 /* simpson.cpp in Sources */,
+                               37D928980F21331F001D4494 /* singlelinkage.cpp in Sources */,
+                               37D928990F21331F001D4494 /* sparsematrix.cpp in Sources */,
+                               37D9289A0F21331F001D4494 /* summarycommand.cpp in Sources */,
+                               37D9289B0F21331F001D4494 /* summarysharedcommand.cpp in Sources */,
+                               37D9289C0F21331F001D4494 /* uvest.cpp in Sources */,
+                               37D9289D0F21331F001D4494 /* validcalculator.cpp in Sources */,
+                               37D9289E0F21331F001D4494 /* validcommands.cpp in Sources */,
+                               37D9289F0F21331F001D4494 /* validparameter.cpp in Sources */,
+                       );
+                       runOnlyForDeploymentPostprocessing = 0;
+               };
+/* End PBXSourcesBuildPhase section */
+
+/* Begin XCBuildConfiguration section */
+               1DEB923208733DC60010E9CD /* Debug */ = {
+                       isa = XCBuildConfiguration;
+                       buildSettings = {
+                               COPY_PHASE_STRIP = NO;
+                               GCC_DYNAMIC_NO_PIC = NO;
+                               GCC_ENABLE_FIX_AND_CONTINUE = YES;
+                               GCC_MODEL_TUNING = G5;
+                               GCC_OPTIMIZATION_LEVEL = 0;
+                               GCC_PREPROCESSOR_DEFINITIONS = (
+                                       "_GLIBCXX_DEBUG=1",
+                                       "_GLIBCXX_DEBUG_PEDANTIC=1",
+                               );
+                               INSTALL_PATH = /usr/local/bin;
+                               PRODUCT_NAME = Mothur;
+                               ZERO_LINK = YES;
+                       };
+                       name = Debug;
+               };
+               1DEB923308733DC60010E9CD /* Release */ = {
+                       isa = XCBuildConfiguration;
+                       buildSettings = {
+                               DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
+                               GCC_MODEL_TUNING = G5;
+                               INSTALL_PATH = /usr/local/bin;
+                               PRODUCT_NAME = Mothur;
+                       };
+                       name = Release;
+               };
+               1DEB923608733DC60010E9CD /* Debug */ = {
+                       isa = XCBuildConfiguration;
+                       buildSettings = {
+                               GCC_WARN_ABOUT_RETURN_TYPE = YES;
+                               GCC_WARN_UNUSED_VARIABLE = YES;
+                               PREBINDING = NO;
+                               SDKROOT = "$(DEVELOPER_SDK_DIR)/MacOSX10.5.sdk";
+                       };
+                       name = Debug;
+               };
+               1DEB923708733DC60010E9CD /* Release */ = {
+                       isa = XCBuildConfiguration;
+                       buildSettings = {
+                               ARCHS = (
+                                       ppc,
+                                       i386,
+                               );
+                               GCC_WARN_ABOUT_RETURN_TYPE = YES;
+                               GCC_WARN_UNUSED_VARIABLE = YES;
+                               PREBINDING = NO;
+                               SDKROOT = "$(DEVELOPER_SDK_DIR)/MacOSX10.5.sdk";
+                       };
+                       name = Release;
+               };
+/* End XCBuildConfiguration section */
+
+/* Begin XCConfigurationList section */
+               1DEB923108733DC60010E9CD /* Build configuration list for PBXNativeTarget "Mothur" */ = {
+                       isa = XCConfigurationList;
+                       buildConfigurations = (
+                               1DEB923208733DC60010E9CD /* Debug */,
+                               1DEB923308733DC60010E9CD /* Release */,
+                       );
+                       defaultConfigurationIsVisible = 0;
+                       defaultConfigurationName = Release;
+               };
+               1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "Mothur" */ = {
+                       isa = XCConfigurationList;
+                       buildConfigurations = (
+                               1DEB923608733DC60010E9CD /* Debug */,
+                               1DEB923708733DC60010E9CD /* Release */,
+                       );
+                       defaultConfigurationIsVisible = 0;
+                       defaultConfigurationName = Release;
+               };
+/* End XCConfigurationList section */
+       };
+       rootObject = 08FB7793FE84155DC02AAC07 /* Project object */;
+}
diff --git a/ace.cpp b/ace.cpp
new file mode 100644 (file)
index 0000000..0647794
--- /dev/null
+++ b/ace.cpp
@@ -0,0 +1,153 @@
+/*
+ *  ace.cpp
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/7/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "ace.h"
+
+/***********************************************************************/
+
+EstOutput Ace::getValues(SAbundVector* rank) {
+       try {
+               data.resize(3,0);
+       //      vector<double> aceData(3,0);
+               double ace, acelci, acehci;
+       
+               int nrare = 0;
+               int srare = 0;
+               int sabund = 0;
+       
+               double Cace, term1, gamace;
+               int numsum = 0;
+       
+               double maxRank = (double)rank->getMaxRank();
+       
+               for(int i=1;i<=maxRank;i++){
+                       if(i<=abund){
+                               srare += rank->get(i);
+                               nrare += i*rank->get(i);
+                               numsum += (i-1)*i*rank->get(i);
+                       }
+                       else if(i>abund)        {sabund += rank->get(i);}
+               }
+               int sobs = srare + sabund;
+       
+               if (nrare == 0){ Cace = 0.0000; }
+               else { Cace = 1.0000 -(double)rank->get(1)/(double)nrare; }
+       
+               double denom = Cace * (double)(nrare * (nrare-1));
+       
+               if(denom <= 0.0){       term1=0.0000;   } else {        term1 = (double)(srare * numsum)/(double)denom - 1.0;   }
+               if(term1 >= 0.0){       gamace = term1; } else {        gamace = 0.0;                                                                                   }
+
+               if(gamace >= 0.64){
+                       gamace = gamace * (1 + (nrare * (1 - Cace) * numsum) / denom);
+                       if(gamace<0){                   gamace = 0;                     }
+               }
+       
+               if(Cace == 0.0){
+                       ace = 0.00;}//ace
+               else{
+                       ace = (double)sabund+((double)srare+(double)rank->get(1)*gamace)/Cace;//ace
+               }
+       
+               /*              
+               The following code was obtained from Anne Chao for calculating the SE for her ACE estimator                     
+               My modification was to reset the frequencies so that a singleton is found in rank[1] insted
+               of in rank[0], etc.
+               
+               I have also added the forumlae to calculate the 95% confidence intervals.
+               */
+       
+               int j,D_s=0,nn=0,ww=0,Max_Index=rank->getMaxRank()+1;
+               double pp, temp1, temp2;
+               vector<double> Part_N_Part_F(Max_Index+1,0.0);
+    
+               for (j=1; j<Max_Index; j++) if(j<=abund) D_s += rank->get(j);
+               for (j=1; j<Max_Index; j++){
+                       if(j<=abund){
+                               nn += rank->get(j) * j;
+                               ww += rank->get(j) * j * ( j - 1);
+                       }
+               }
+               double C_hat = 1.-rank->get(1)/double(nn);
+               double Gamma = ( D_s * ww) / ( C_hat * nn * ( nn - 1.)) - 1.; 
+               temp1 = double(nn - rank->get(1));
+               temp2 = double(nn - 1.); 
+       
+               if ( Gamma > 0.){
+                       Part_N_Part_F[1] =  ( D_s + nn) * ( 1. + rank->get(1) * ww / temp1 / temp2) / temp1 + nn * D_s * ww * ( temp1 - 1.) /
+                       ( temp1 * temp1 * temp2 * temp2) - ( nn + rank->get(1)) / temp1;
+                       for ( j=2; j<=Max_Index; j++){
+                               if(j<=abund){
+                                       Part_N_Part_F[j] = ( nn * temp1 - j * rank->get(1) * D_s) / temp1 / temp1 * ( 1. + rank->get(1) * ww / temp1 / temp2)
+                                       + j * rank->get(1) * D_s * nn * ( ( j - 1.) * temp1 * temp2 - ww * ( temp1 + temp2))
+                                       / temp1 / temp1 / temp1 / temp2 / temp2 + j * rank->get(1) * rank->get(1) / temp1 / temp1;
+                               }
+                       }
+               }
+               else{
+                       Part_N_Part_F[1] = ( nn + D_s ) / temp1;
+                       for ( j=2; j<=Max_Index; j++){
+                               if(j<=abund){
+                                       Part_N_Part_F[j-1] = ( nn * temp1 - j * rank->get(1) * D_s ) / temp1 / temp1;
+                               }
+                       }
+               }
+               if(Max_Index>abund){
+                       for ( j=abund+1; j<=Max_Index; j++){                            
+                               Part_N_Part_F[j-1] = 1.;        
+                       }
+               } 
+               for ( temp1=0., temp2=0., j=0; j<Max_Index; j++) {
+                       pp = Part_N_Part_F[j];
+                       temp1 += pp * rank->get(j);
+                       temp2 += pp * pp * rank->get(j);
+               }
+       
+               double se = temp2 - temp1 * temp1 / ace;
+       
+               if(toString(se) == "nan"){
+                       acelci = ace;
+                       acehci = ace;
+               }       
+               else if(ace==0.000){
+                       acelci = ace;
+                       acehci = ace;
+               }
+               else if(ace==sobs){
+                       double ci = 1.96*pow(se,0.5);
+                       acelci = ace-ci;                                        //ace lci
+                       acehci = ace+ci;                                        //ace hci
+               }else{
+                       double denom = pow(ace-sobs,2);
+                       double c = exp(1.96*pow((log(1+se/denom)),0.5));
+                       acelci = sobs+(ace-sobs)/c;                     //ace lci 
+                       acehci = sobs+(ace-sobs)*c;                     //ace hci
+               }
+               
+               data[0] = ace;
+               data[1] = acelci;
+               data[2] = acehci;       
+               
+               if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; }
+               if (isnan(data[1]) || isinf(data[1])) { data[1] = 0; }
+               if (isnan(data[2]) || isinf(data[2])) { data[2] = 0; }
+               
+               return data;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the Ace class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the Ace class function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+/***********************************************************************/
diff --git a/ace.h b/ace.h
new file mode 100644 (file)
index 0000000..19188fa
--- /dev/null
+++ b/ace.h
@@ -0,0 +1,33 @@
+#ifndef ACE_H
+#define ACE_H
+
+/*
+ *  ace.h
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/7/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+/* This class implements the Ace estimator on a single group. 
+It is a child of the calculator class. */
+
+#include <Carbon/Carbon.h>
+#include "calculator.h"
+
+/***********************************************************************/
+
+class Ace : public Calculator  {
+       
+public:
+       Ace(int n=10) : abund(n), Calculator("ACE", 3) {};
+       EstOutput getValues(SAbundVector*);
+       EstOutput getValues(SharedRAbundVector*, SharedRAbundVector*) {return data;};
+private:
+       int abund;
+};
+
+/***********************************************************************/
+
+#endif
diff --git a/averagelinkage.cpp b/averagelinkage.cpp
new file mode 100644 (file)
index 0000000..1ab5160
--- /dev/null
@@ -0,0 +1,78 @@
+
+#include "cluster.hpp"
+#include "rabundvector.hpp"
+#include "sparsematrix.hpp"
+#include <exception>
+
+/* This class implements the average UPGMA, average neighbor clustering algorithm */
+
+/***********************************************************************/
+
+AverageLinkage::AverageLinkage(RAbundVector* rav, ListVector* lv, SparseMatrix* dm) :
+Cluster(rav, lv, dm)
+{}
+
+/***********************************************************************/
+//THis function clusters based on the average method
+void AverageLinkage::update(){
+       try{
+               getRowColCells();               
+       
+               vector<int> found(nColCells, 0);
+       
+               int rowBin = rabund->get(smallRow);
+               int colBin = rabund->get(smallCol);
+               int totalBin = rowBin + colBin;
+       
+               for(int i=1;i<nRowCells;i++){
+               
+                       int search;
+               
+                       if(rowCells[i]->row == smallRow){
+                               search = rowCells[i]->column;
+                       }
+                       else{
+                               search = rowCells[i]->row;
+                       }
+               
+                       for(int j=1;j<nColCells;j++){
+                       
+                               if(colCells[j]->row == search || colCells[j]->column == search){
+                                       colCells[j]->dist = (colBin * colCells[j]->dist + rowBin * rowCells[i]->dist) / totalBin;               
+                               
+                                       found[j] = 1;
+                               
+                                       if(colCells[j]->vectorMap != NULL){
+                                               *(colCells[j]->vectorMap) = NULL;
+                                               colCells[j]->vectorMap = NULL;
+                                       }
+                               
+                                       break;
+                               }
+                       
+                       }                       
+                       dMatrix->rmCell(rowCells[i]);
+               }       
+       
+               clusterBins();
+               clusterNames();
+       
+               for(int i=0;i<nColCells;i++){
+                       if(found[i] == 0){
+                               dMatrix->rmCell(colCells[i]);
+                       }
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the AverageLinkage class Function update. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the AverageLinkage class function update. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+
+       
+}
+
+/***********************************************************************/
diff --git a/bootstrap.cpp b/bootstrap.cpp
new file mode 100644 (file)
index 0000000..2cba2fe
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ *  bootstrap.cpp
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/7/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "bootstrap.h"
+
+/***********************************************************************/
+
+EstOutput Bootstrap::getValues(SAbundVector* rank){
+       try {
+               //vector<double> bootData(3,0);
+               data.resize(1,0);
+               double maxRank = (double)rank->getMaxRank();
+               int sampled = rank->getNumSeqs();
+               int sobs = rank->getNumBins();
+
+               double boot = (double)sobs;
+
+               for(int i=1;i<=maxRank;i++){
+                       boot += (double)rank->get(i)*pow((1.0-(double)i/(double)sampled),sampled);
+               }
+               
+               data[0] = boot;
+               
+               if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; }
+       
+               return data;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the Bootstrap class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the Bootstrap class function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+/***********************************************************************/
diff --git a/bootstrap.h b/bootstrap.h
new file mode 100644 (file)
index 0000000..71d2c26
--- /dev/null
@@ -0,0 +1,32 @@
+#ifndef BOOTSTRAP_H
+#define BOOTSTRAP_H
+/*
+ *  bootstrap.h
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/7/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+/* This class implements the Bootstrap estimator on single group. 
+It is a child of the calculator class. */
+
+#include <Carbon/Carbon.h>
+#include "calculator.h"
+
+/***********************************************************************/
+
+
+class Bootstrap : public Calculator  {
+       
+public:
+       Bootstrap() : Calculator("Bootstrap", 1) {};
+       EstOutput getValues(SAbundVector*);
+       EstOutput getValues(SharedRAbundVector*, SharedRAbundVector*) {return data;};
+       
+};
+
+/***********************************************************************/
+
+#endif
\ No newline at end of file
diff --git a/calculator.cpp b/calculator.cpp
new file mode 100644 (file)
index 0000000..6bac62d
--- /dev/null
@@ -0,0 +1,1190 @@
+/*
+ *  calculator.cpp
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 11/18/08.
+ *  Copyright 2008 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "calculator.h"
+
+/***********************************************************************/
+void VecCalc::printElements(vector<double> vec){
+       try {
+               for(int i = 0; i < vec.size(); i++)
+                       cout << vec.at(i) << " ";
+               cout << "\n\n";
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the VecCalc class Function printElements. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the VecCalc class function printElements. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+/***********************************************************************/
+
+void VecCalc::printElements(vector<string> vec){
+       try {
+               for(int i = 0; i < vec.size(); i++)
+                       cout << vec.at(i) << " ";
+               cout << "\n\n";
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the VecCalc class Function printElements. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the VecCalc class function printElements. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+/***********************************************************************/
+int VecCalc::findString(vector<string> vec, string str){
+       try {
+               for(int i = 0; i < vec.size(); i++)
+                       if(str.compare(vec.at(i)) == 0)
+                               return i;
+               return -1;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the VecCalc class Function findString. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the VecCalc class function findString. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+/***********************************************************************/
+double VecCalc::mean(vector<double> vec){
+       return sumElements(vec)/vec.size();
+}
+/***********************************************************************/
+double VecCalc::stError(vector<double> vec){
+       try {
+               double sum = 0;
+               double m = mean(vec);
+               for(int i = 0; i < vec.size(); i++)
+                       sum += pow(vec.at(i)-m,2);
+               return pow(sum/(vec.size()*(vec.size()-1)), .5);
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the VecCalc class Function stError. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the VecCalc class function stError. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+/***********************************************************************/
+double VecCalc::sumElements(vector<double> vec){
+       try {
+               double sum = 0;
+               for(int i = 0; i < vec.size(); i++)
+                       sum += vec.at(i);
+               return sum;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the VecCalc class Function sumElements. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the VecCalc class function sumElements. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+/***********************************************************************/
+double VecCalc::sumElements(vector<double> vec, int index){
+       try {
+               double sum = 0;
+               for(int i = index; i < vec.size(); i++)
+                       sum += vec.at(i);
+               return sum;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the VecCalc class Function sumElements. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the VecCalc class function sumElements. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+/***********************************************************************/
+double VecCalc::findMax(vector<double> vec){
+       try {
+               double max = -1000000.0;
+               for(int i = 0; i < vec.size(); i++)
+                       if(vec.at(i) > max)
+                               max = vec.at(i);
+               return max;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the VecCalc class Function findMax. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the VecCalc class function findMax. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+/***********************************************************************/
+double VecCalc::numNZ(vector<double> vec){
+       try {
+               double numNZ = 0;
+               for(int i = 0; i < vec.size(); i++)
+                       if(vec.at(i) != 0)
+                               numNZ++;
+               return numNZ;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the VecCalc class Function numNZ. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the VecCalc class function numNZ. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+/***********************************************************************/
+double VecCalc::numPos(vector<double> vec){
+       try {
+               double numPos = 0;
+               for(int i = 0 ; i < vec.size(); i++)
+                       if(vec.at(i) > 0)
+                               numPos++;
+               return numPos;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the VecCalc class Function numPos. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the VecCalc class function numPos. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+/***********************************************************************/
+double VecCalc::findMaxDiff(vector<double> vec1, vector<double> vec2){
+       try {
+               double maxDiff = -10000000000.0;
+               for(int i = 0; i < vec1.size(); i++)
+                       if(fabs(vec1.at(i)-vec2.at(i)) > maxDiff)
+                               maxDiff = fabs(vec1.at(i)-vec2.at(i));
+               return maxDiff;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the VecCalc class Function findMaxDiff. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the VecCalc class function findMaxDiff. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+/***********************************************************************/
+double VecCalc::findDStat(vector<double> vec1, vector<double> vec2, double num){
+       try {
+               double mDiff = findMaxDiff(vec1, vec2);
+               return (mDiff+.5)/num;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the VecCalc class Function findDStat. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the VecCalc class function findDStat. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+/***********************************************************************/
+vector<int> VecCalc::findQuartiles(vector<double> vec){
+       try {
+               vector<int> quartiles;
+               double max = vec.at(vec.size()-1);
+               double r1 = max/4;
+               double r2 = max*3/4;
+               bool r1found = false;
+               bool r2found = false;
+               for(int i = 0; i < vec.size(); i++)
+               {
+                       if(vec.at(i) > r1 && !r1found)
+                       {
+                               quartiles.push_back(i);
+                               r1found = true;
+                       }
+                       if(vec.at(i) > r2 && !r2found)
+                       {
+                               quartiles.push_back(i);
+                               i = vec.size();
+                       }
+               }
+               return quartiles;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the VecCalc class Function findQuartiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the VecCalc class function findQuartiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+/***********************************************************************/
+vector<double> VecCalc::add(vector<double> vec, double x){
+       try {
+               vector<double> newVec;
+               for(int i = 0; i < vec.size(); i++)
+                       newVec.push_back(vec.at(i)+x);
+               return newVec;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the VecCalc class Function add. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the VecCalc class function add. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+/***********************************************************************/
+vector<double> VecCalc::multiply(vector<double> vec, double x){
+       try {
+               vector<double> newVec;
+               for(int i = 0; i < vec.size(); i++)
+                       newVec.push_back(vec.at(i)*x);
+               return newVec;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the VecCalc class Function multiply. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the VecCalc class function multiply. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+/***********************************************************************/
+vector<double> VecCalc::power(vector<double> vec, double p){
+       try {
+               vector<double> newVec;
+               for(int i = 0; i < vec.size(); i++)
+                       newVec.push_back(pow(vec.at(i), p));
+               return newVec;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the VecCalc class Function power. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the VecCalc class function power. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+/***********************************************************************/
+vector<double> VecCalc::addVecs(vector<double> vec1, vector<double> vec2) //Vectors must be the same size.
+{      try {
+               vector<double> newVec;
+               for(int i = 0; i < vec1.size(); i++)
+                       newVec.push_back(vec1.at(i)+vec2.at(i));
+               return newVec;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the VecCalc class Function addVecs. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the VecCalc class function addVecs. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+/***********************************************************************/
+vector<double> VecCalc::multVecs(vector<double> vec1, vector<double> vec2) //Vectors must be the same size.
+{      try {
+               vector<double> newVec;
+               for(int i = 0; i < vec1.size(); i++)
+                       newVec.push_back(vec1.at(i)*vec2.at(i));
+               return newVec;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the VecCalc class Function multVecs. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the VecCalc class function multVecs. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+/***********************************************************************/
+vector<double> VecCalc::remDup(vector<double> vec){
+       try {
+               vector<double> newVec;
+               newVec.push_back(vec.at(0));
+               for(int i = 1; i < vec.size(); i++)
+                       if(vec.at(i) != vec.at(i-1))
+                               newVec.push_back(vec.at(i));
+               return newVec;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the VecCalc class Function remDup. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the VecCalc class function remDup. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}      
+/***********************************************************************/      
+vector<double> VecCalc::genCVec(vector<double> vec1){
+       try {
+               vector<double> vec2;
+               double sum = 0;
+               for(int i = 0; i < vec1.size(); i++)
+               {
+                       sum += vec1.at(i);
+                       vec2.push_back(sum);
+               }
+               return vec2;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the VecCalc class Function genCVec. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the VecCalc class function genCVec. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+/***********************************************************************/
+vector<double> VecCalc::genRelVec(vector<double> vec){ 
+       try {
+               vector<double> newVec;
+               double sum = sumElements(vec);
+               for(int i = 0; i < vec.size(); i++)
+                       newVec.push_back(vec.at(i)/sum);
+               return newVec;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the VecCalc class Function genRelVec. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the VecCalc class function genRelVec. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+/***********************************************************************/
+vector<double> VecCalc::genDiffVec(vector<double> vec1, vector<double> vec2){
+       try {
+               vector<double> newVec;
+               for(int i = 0; i < vec1.size(); i++)
+                       newVec.push_back(vec1.at(i)-vec2.at(i));
+               return newVec;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the VecCalc class Function genDiffVec. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the VecCalc class function genDiffVec. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+/***********************************************************************/
+vector<double> VecCalc::genCSVec(vector<double> vec){
+       try {
+               vector<double> newVec;
+               double curInd = vec.at(vec.size()-1);
+               double sumSpec = 0;
+               double cSumSpec = 0;
+               for(int i = vec.size()-1; i >= 0; i--)
+               {
+                       if(vec.at(i) == curInd)
+                               sumSpec++;
+                       else
+                       {
+                               cSumSpec += sumSpec;
+                               newVec.push_back(cSumSpec);
+                               sumSpec = 1;
+                               curInd = vec.at(i);
+                       }
+                       if(i == 0)
+                               newVec.push_back(cSumSpec + sumSpec);
+               }
+               return newVec;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the VecCalc class Function genCSVec. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the VecCalc class function genCSVec. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+/***********************************************************************/      
+vector<double> VecCalc::genTotVec(vector<vector<double> > vec){
+       try {
+               vector<double> newVec = vec.at(0);
+               for(int i = 1; i < vec.size(); i++)
+                       newVec = addVecs(newVec, vec.at(i));
+               return newVec;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the VecCalc class Function genTotVec. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the VecCalc class function genTotVec. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+/***********************************************************************/
+vector<double> VecCalc::quicksort(vector<double> vec){
+       try {
+               sort(vec.rbegin(), vec.rend());
+               return vec;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the VecCalc class Function quicksort. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the VecCalc class function quicksort. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+/***********************************************************************/
+vector<vector<double> > VecCalc::gen2DVec(vector<double> vec, int div, int type){
+       try {
+               vector<vector<double> > vec2D;
+               int gap = vec.size()/div;
+               for(int i = 0; i < div; i++)
+               {
+                       vector<double> inVec;
+                       for(int j = 0; j < gap; j++)
+                               if(type == 0)
+                                       inVec.push_back(vec.at(j + i*gap)); //Rows
+                               else
+                                       inVec.push_back(vec.at(i + j*div)); //Columns
+                       vec2D.push_back(inVec);
+               }
+               return vec2D;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the VecCalc class Function gen2DVec. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the VecCalc class function gen2DVec. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+/***********************************************************************/
+vector<string> VecCalc::getSData(char name[]){
+       try {
+               vector<string> vec;
+               string data;
+               ifstream file(name);
+               if(file.is_open())
+               {
+                       while(file >> data)             
+                               vec.push_back(data);
+                       file.close();
+               }
+               return vec;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the VecCalc class Function getSData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the VecCalc class function getSData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+/***********************************************************************/      
+double BDiversity::getWhitt(vector<double> vec1, vector<double> vec2){
+       try {
+               VecCalc vecCalc;
+               double numSpec = vecCalc.numNZ(vecCalc.addVecs(vec1,vec2));
+               return 2*numSpec/(vecCalc.numNZ(vec1)+vecCalc.numNZ(vec2))-1;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the BDiversity class Function getWhitt. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the BDiversity class function getWhitt. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+/***********************************************************************/
+double BDiversity::getMS(vector<double> vec1, vector<double> vec2){
+       try {
+               VecCalc vecCalc;
+               double a = vecCalc.numNZ(vecCalc.multVecs(vec1, vec2));
+               double b = vecCalc.numPos(vecCalc.addVecs(vecCalc.addVecs(vec1, vecCalc.multiply(vec2, -1)), vecCalc.multiply(vecCalc.multVecs(vec1, vec2), -1)));
+               double c = vecCalc.numPos(vecCalc.addVecs(vecCalc.addVecs(vec2, vecCalc.multiply(vec1, -1)), vecCalc.multiply(vecCalc.multVecs(vec2, vec1), -1)));
+               return a/(a+b+c);
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the BDiversity class Function getMS. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the BDiversity class function getMS. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+/***********************************************************************/
+double BDiversity::getSor(vector<double> vec1, vector<double> vec2){
+       try {
+               double sum = 0;
+               double asum = 0;
+               double bsum = 0;
+               for(int i = 0; i < vec1.size(); i++)
+               {
+                       asum += vec1.at(i);
+                       bsum += vec2.at(i);
+                       if(vec1.at(i) >= vec2.at(i))
+                               sum += vec2.at(i);
+                       else
+                               sum += vec1.at(i);
+               }
+               return 2*sum/(asum+bsum);
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the BDiversity class Function getSor. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the BDiversity class function getSor. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+/***********************************************************************/
+double BDiversity::getMor(vector<double> vec1, vector<double> vec2){
+       try {
+               double sum = 0;
+               double asum = 0;
+               double bsum = 0;
+               double sum1 = 0;
+               double sum2 = 0;
+               for(int i = 0; i < vec1.size(); i++)
+               {
+                       sum += vec1.at(i)*vec2.at(i);
+                       asum += pow(vec1.at(i),2);
+                       bsum += pow(vec2.at(i),2);
+                       sum1 += vec1.at(i);
+                       sum2 += vec2.at(i);
+               }
+               return 2*sum/((asum/pow(sum1,2)+bsum/pow(sum2,2))*(sum1*sum2));
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the BDiversity class Function getMor. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the BDiversity class function getMor. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+/***********************************************************************/
+void BDiversity::printD(vector<vector<double> > columns, int type){
+       try {
+               cout << "         ";
+               for(int i = 0; i < columns.size(); i++)
+                       cout << "Column:" << i << "    ";
+               cout << "\n";
+               for(int i = 0; i < columns.size(); i++)
+               {
+                       cout << "Column " << i << ":";
+                       for(int j = 0; j < columns.size(); j++)
+                       {
+                               if(j > i)
+                               {
+                                       double B;
+                                       if(type == 1)
+                                               B = getWhitt(columns.at(i), columns.at(j));
+                                       else if(type == 2)
+                                               B = 1-getMS(columns.at(i), columns.at(j));
+                                       else if(type == 3)
+                                               B = 1-getSor(columns.at(i), columns.at(j));
+                                       else if(type == 4)
+                                               B = 1-getMor(columns.at(i), columns.at(j));
+
+                                       cout << B << "    ";
+                               }
+                               else
+                                       cout << "            ";
+                       }       
+                       cout << "\n";
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the BDiversity class Function printD. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the BDiversity class function printD. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+/***********************************************************************/
+void BDiversity::doBD(vector<double> vec, double cols)//vec = The data vector if the data table was read left-to-right, top-to-bottom. cols = the number of columns in the data table.
+{      try {
+               VecCalc vecCalc;
+               vector<vector<double> > columns = vecCalc.gen2DVec(vec,cols,1);
+       
+               cout.setf(ios_base::fixed, ios_base::floatfield);
+               cout.precision(6);//This formats the data so the tables look pretty.
+       
+               //Whittaker's measure Bw (presence/absence data)
+               cout << "Whittaker's measure Bw (presence/absence data):\n";
+               printD(columns, 1);
+               double sum = 0;
+               for(int i = 0; i < cols; i++)
+                       sum += vecCalc.numNZ(columns.at(i));
+               double meanRichness = sum/cols;
+               vector<double> totVec = vecCalc.genTotVec(columns);
+               double totRichness = vecCalc.numNZ(totVec);
+               cout << "\nOverall B Diversity = " << totRichness/meanRichness << "\n\n\n";//The overall B Diversity
+       
+               //Marczewski-Steinhaus(MS) distance(Jaccard index) (presence/abscence data)
+               cout << "Marczewski-Steinhaus(MS) distance(Jaccard index) (presence/abscence data):\n";
+               printD(columns, 2);
+               sum = 0;
+               for(int i = 0; i < cols; i++)
+                       for(int j = 0; j < cols; j++)
+                               if(j > i)
+                                       sum += vecCalc.numNZ(columns.at(i))+vecCalc.numNZ(columns.at(j)) - 2*vecCalc.numNZ(vecCalc.multVecs(columns.at(i), columns.at(j)));
+               cout << "\nOverall B Diversity = " << sum/cols << "\n\n\n";//The overall B Diversity
+       
+               //Sorensen quantitative index (abundance data)
+               cout << "Sorensen quantitative index (abundance data):\n";
+               printD(columns, 3);
+               cout << "\n\n";
+       
+               //Sorensen quantitative index (abundance data)
+               cout << "Morisita-Horn index (abundance data):\n";
+               printD(columns,4);
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the BDiversity class Function doBD. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the BDiversity class function doBD. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+/***********************************************************************/
+void BrokenStick::doBStick(vector<double> vec)//vec = The data vector.
+{      try {
+               VecCalc vecCalc;
+               vec = vecCalc.quicksort(vec);
+               double numInd = vecCalc.sumElements(vec);
+               double numSpec = vecCalc.numNZ(vec);
+               vector<double> cObsVec = vecCalc.genCVec(vec);
+               vector<double> cExpVec;
+               vec = vecCalc.power(vec, -1);
+               double sumExp = 0;
+               for(int i = 0; i < numSpec; i++)
+               {
+                       double n = 0;
+                       for(int j = i; j < numSpec; j++)
+                               n += 1/(double)(j+1);
+       
+                       sumExp += numInd/numSpec*n;
+                       cExpVec.push_back(sumExp);
+               }
+       
+               //Statistical analysis
+               double maxDiff = vecCalc.findMaxDiff(cObsVec, cExpVec);
+               double DStatistic = maxDiff/numInd;
+       
+               cout << "D-Statistic = " << DStatistic << "\n";
+               if(vec.size() > 30)
+                       cout << "Critical value for 95% confidence interval = " << .886/sqrt(vec.size()) << "\n";
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the BrokenStick class Function doBStick. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the BrokenStick class function doBStick. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+/***********************************************************************/
+double kEq(double k, double spec)
+{
+       return k/(1-k)*pow(1-k, spec)/(1-pow(1-k, spec));
+}
+/***********************************************************************/
+void GeometricSeries::doGeomTest(vector<double> vec)//vec = the data vector
+{      try {
+               VecCalc vecCalc;
+               vec = vecCalc.quicksort(vec);//Sorts vec
+               double numInd = vecCalc.sumElements(vec);//numInd = The total number of individuals in the data set.
+               double numSpec = vecCalc.numNZ(vec);//numSpec = the number of nonzero elements in the data set.
+               double min = -1.0*vecCalc.findMax(vecCalc.multiply(vec, -1));
+               double k = .5;
+               double step = .49999;
+               while(fabs(min - numInd*kEq(k, numSpec)) > .0001)//This uses a binary search to find the value of k.
+               {
+                       if(numInd*kEq(k, numSpec) > min)
+                               k += step;
+                       else
+                               k -= step;
+                       step /= 2;
+               }
+               cout << "k = " << k << "\n";
+               double cK = 1/(1-pow(1-k, numSpec));
+       
+               vector<double> cObsVec = vecCalc.genCVec(vec);
+               vector<double> cExpVec;
+               double sumExp = 0;
+               for(int i = 0; i < vec.size(); i++)
+               {
+                       sumExp += numInd*cK*k*pow(1-k, i);
+                       cExpVec.push_back(sumExp);
+               }
+               double maxDiff = vecCalc.findMaxDiff(cObsVec, cExpVec);
+               double DStatistic = maxDiff/numInd;
+       
+               //Statistical Analysis
+               cout << "D-Statistic = " << DStatistic << "\n";
+               if(vec.size() > 30)
+                       cout << "Critical value for 95% confidence interval = " << .886/sqrt(vec.size()) << "\n";
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the GeometricSeries class Function doGeomTest. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the GeometricSeries class function doGeomTest. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+/***********************************************************************/
+void Jackknifing::doJK(vector<double> vec, double cols)//vec = the data vector if the data table was read left-to-right, top-to-bottom. cols = The number of columns in the data table.
+{      try {
+               VecCalc vecCalc;
+               SSBPDiversityIndices ssbp;
+               double rows = vec.size()/cols;
+               vector<vector<double> > species = vecCalc.gen2DVec(vec, rows, 0);//converts vec into a 2 dimensional vector
+               vector<double> sumRows;
+               vector<double> pVals;
+
+               for(int i = 0; i < rows; i++)
+                       sumRows.push_back(vecCalc.sumElements(species.at(i)));
+               double st = 1/ssbp.getSimp(sumRows);//The observed estimate using the Simpson Index. Can be changed to use other indexes of diversity.
+               for(int i = 0; i < cols; i++)
+               {
+                       vector<double> newVec;
+                       for(int j = 0; j < rows; j++)
+                               newVec.push_back(vecCalc.sumElements(species.at(j))-species.at(j).at(i));
+                       pVals.push_back(cols*st-((cols-1)/ssbp.getSimp(newVec)));
+               }
+
+               double mean = vecCalc.mean(pVals);
+               double stErr = vecCalc.stError(pVals);//stErr = standard error
+               TDTable table;
+               double confidence = .95;
+               double confLimit;
+               cout << "Confidence Level (.8, .9, .95, .98, .99, .998, .999): ";
+               cin >> confidence;
+               double confLevels[] = {.80,.90,.95,.98,.99,.998,.999};
+               for(int i = 0; i < 7; i++)
+                       if(confidence == confLevels[i])
+                       {
+                               confLimit = table.getConfLimit(cols-2,i);
+                               i = 7;
+                       }
+
+               //Statistical Analysis
+               cout << "Lower limit = " << mean - confLimit*stErr << "\n";
+               cout << "Upper limit = " << mean + confLimit*stErr << "\n";
+               cout << "Observed estimate = " << st << "\n\n";
+               cout << "Jackknifed estimate = " << mean << "\n";
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the Jackknifing class Function doJK. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the Jackknifing class function doJK. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+/***********************************************************************/
+void KS2SampleTest::doKSTest(vector<double> abun1, vector<double> abun2)//abun1 = 1st vector of abundances, abun2 = 2nd vector of abundances
+{      try {
+               VecCalc vecCalc;
+               double numNZ1 = vecCalc.numNZ(abun1);//Number of nonzero elements in abun1
+               double numNZ2 = vecCalc.numNZ(abun2);//Number of nonzero elements in abun2
+               abun1 = vecCalc.quicksort(abun1);//Sorts abun1
+               abun2 = vecCalc.quicksort(abun2);//Sorts abun2
+               abun1 = vecCalc.genRelVec(abun1);//Generates the relative vector for abun1
+               abun2 = vecCalc.genRelVec(abun2);//Generates the relative vector for abun2
+       
+               abun1 = vecCalc.genCVec(abun1);//Generates the cumulative vector for abun1
+               abun2 = vecCalc.genCVec(abun2);//Generates the cumulative vector for abun2
+       
+               double maxDiff = vecCalc.findMaxDiff(abun1, abun2);
+               double DStatistic = maxDiff*numNZ1*numNZ2;
+       
+               cout << "Null Hypothesis = There is no difference.\n";
+               cout << "D-Statistic = " << DStatistic << "\n";
+       
+               double a = pow((numNZ1 + numNZ2)/(numNZ1*numNZ2),.5);
+               double pVal = exp(-2*pow(maxDiff/a,2));
+       
+               if(numNZ1 > 25 && numNZ2 > 25) //If the sample sizes are both bigger than 25.
+                       cout << "P-Value = " << pVal << "\n\n";
+               else
+               {       
+                       cout << "D-Statistic must be higher than the critical value to reject the null hypothesis.\n" ;
+                       cout << "90% Confidence Critical Value = " << 1.22*a*numNZ1*numNZ2 << "\n";
+                       cout << "95% Confidence Critical Value = " << 1.36*a*numNZ1*numNZ2 << "\n";
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the KS2SampleTest class Function doKSTest. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the KS2SampleTest class function doKSTest. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+/***********************************************************************/
+double logS(double num)
+{
+       return -(1-num)*log(1-num)/num;
+}
+
+/***********************************************************************/
+void LogSD::doLogSD(vector<double> indVec, vector<double> specVec) //indVec = individuals vector, specVec = species vector
+{      try {
+               VecCalc vecCalc;
+               double numSpec = vecCalc.sumElements(specVec);//numSpec = The total number of species
+               cout << "number of species = " << numSpec << "\n";
+               double numInd = vecCalc.sumElements(vecCalc.multVecs(indVec, specVec));
+               double snRatio = numSpec/numInd;
+               double x = .5;
+               double step = .4999999999;
+               while(fabs(snRatio - logS(x)) > .00001) //This uses a binary search to find the value of x.
+               {
+                       if(logS(x) > snRatio)
+                               x += step;
+                       else
+                               x -= step;
+                       step /= 2;
+               }
+               double alpha = numInd*(1-x)/x;
+       
+               int ind;
+               cout << "Number of individuals:"; //Ask the user for the number of individuals.
+               cin >> ind;
+               double spec = alpha*pow(x, ind)/ind;
+               cout << "Number of species expected = " << spec << "\n" << "X value = " << x << "\n" << "Alpha value= " << alpha << "\n";//Outputs the number of species expected with the given number of individuals.
+       
+               vector<double> obsSpec;
+               vector<double> cObsSpec;
+               vector<double> expSpec;
+               vector<double> cExpSpec;
+               vector<double> cDiff;
+       
+               // Generates the cumulative observed species vector.
+               int oct = 1;
+               double octSumObs = 0;
+               for(int y = 0; y < specVec.size(); y++)
+               {
+                       if(indVec.at(y) - .5 < pow(2.0, oct))
+                               octSumObs += specVec.at(y);
+                       else
+                       {
+                               obsSpec.push_back(octSumObs);
+                               octSumObs = specVec.at(y);
+                               oct++;
+                       }
+                       if(y == specVec.size()-1)
+                               obsSpec.push_back(octSumObs);
+               }
+               cObsSpec = vecCalc.genCVec(obsSpec);
+               cObsSpec = vecCalc.add(cObsSpec,-.5);
+       
+               // Generates the cumulative expected species vector.
+               oct = 1;
+               double octSumExp = 0;
+               for(int g = 1; g <= indVec.at(indVec.size()-1); g++)
+               {
+                       if(g - .5 < pow(2.0, oct))
+                               octSumExp += alpha*pow(x,g)/(g);
+                       else
+                       {
+                               expSpec.push_back(octSumExp);
+                               octSumExp = alpha*pow(x,g)/(g);
+                               oct++;
+                       }
+                       if(g == indVec.at(indVec.size()-1))
+                               expSpec.push_back(octSumExp);
+               }
+               cExpSpec = vecCalc.genCVec(expSpec);
+       
+               // Statistical Analysis
+               double dTStat = vecCalc.findDStat(cObsSpec, cExpSpec, numSpec);
+               cout << "D Test Statistic = " << dTStat << "\n";
+               cout << ".05 confidence value = " << .89196/sqrt(numSpec) << "\n";
+               cout << ".01 confidence value = " << 1.0471/sqrt(numSpec) << "\n\n";
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the LogSD class Function doLogSD. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the LogSD class function doLogSD. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+/***********************************************************************/
+void QStatistic::doQStat(vector<double> vec)//vec = The data vector.
+{      try {
+               VecCalc vecCalc;
+               vector<double> cVec = vecCalc.genCSVec(vec);
+               vector<int> q = vecCalc.findQuartiles(cVec);//q.at(0) is the index of the first quartile; q.at(1) is the index of the second quartile.
+               vector<double> nDupVec = vecCalc.remDup(vec);//nDupVec only contains one of every unique element in cVec.
+               double Q;
+               if(q.at(0) != 0)//The case if neither quartile is 0 or 1
+                       Q = (.5*(cVec.at(q.at(0))-cVec.at(q.at(0)-1)) + (cVec.at(q.at(1)-1)-cVec.at(q.at(0))) + .5*(cVec.at(q.at(1))-cVec.at(q.at(1)-1)))/log(nDupVec.at(nDupVec.size()-1-q.at(1))/nDupVec.at(nDupVec.size()-1-q.at(0)));
+               else if(q.at(0) == 0 && (q.at(1) == 0 || q.at(1) == 1))//The case if the quartiles are both at index 0 or one is at 0 and the other at 1.
+                       Q = (.5*cVec.at(0) + .5*(cVec.at(1)-cVec.at(0)))/log(nDupVec.at(nDupVec.size()-2)/nDupVec.at(nDupVec.size()-1));
+               else if(q.at(0) == 0 && q.at(1) > 1) //The case if the lower quartile is at index 0 and upper quartile index is above index 1.
+                       Q = (.5*cVec.at(0) + (cVec.at(q.at(1)-1)-cVec.at(q.at(0))) + .5*(cVec.at(q.at(1))-cVec.at(q.at(1)-1)))/log(nDupVec.at(nDupVec.size()-1-q.at(1))/nDupVec.at(nDupVec.size()-1));
+       
+               cout << "Q = " << Q << "\n";
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the QStatistic class Function doQStat. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the QStatistic class function doQStat. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+/***********************************************************************/
+double SSBPDiversityIndices::getShan(vector<double> vec)//vec = The data vector.
+{      try {
+               VecCalc vecCalc;
+               double nz = vecCalc.numNZ(vec);
+               double nSum = vecCalc.sumElements(vec);
+               double H = 0;
+               for(int i = 0; i < nz; i++)
+                       H += vec.at(i)/nSum*log(vec.at(i)/nSum);
+               H *= -1;
+               return H;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SSBPDiversityIndices class Function getShan. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SSBPDiversityIndices class function getShan. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+/***********************************************************************/
+double SSBPDiversityIndices::getSimp(vector<double> vec)//vec = The data vector.
+{      try {
+               VecCalc vecCalc;
+               double nSum = vecCalc.sumElements(vec);
+               double D = 0;
+               for(int j = 0; j < vec.size(); j++)
+                       D += vec.at(j)*(vec.at(j)-1)/(nSum*(nSum-1));
+               return D;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SSBPDiversityIndices class Function getSimp. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SSBPDiversityIndices class function getSimp. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+/***********************************************************************/
+double SSBPDiversityIndices::getBP(vector<double> vec)//vec = The data vector.
+{      try {
+               VecCalc vecCalc;
+               double nSum = vecCalc.sumElements(vec);
+               return vecCalc.findMax(vec)/nSum;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SSBPDiversityIndices class Function getBP. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SSBPDiversityIndices class function getBP. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+/***********************************************************************/
+void SSBPDiversityIndices::doSSBP(vector<double> vec)//vec = The data vector.
+{      try {
+               VecCalc vecCalc;
+               double nz = vecCalc.numNZ(vec);
+       
+               //Shannon index
+               double H = getShan(vec);
+               cout << "H = " << H << "\n";
+               cout << "Eveness = " << H/log(nz) << "\n\n";
+       
+               //Simpson index
+               double D = getSimp(vec);
+               cout << "D diversity = " << 1/D << "\n";
+               cout << "Eveness = " << 1/D/nz << "\n\n";
+       
+               //Berger-Parker index
+               double BP = getBP(vec);
+               cout << "BP index = " << BP << "\n\n";
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SSBPDiversityIndices class Function doSSBP. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SSBPDiversityIndices class function doSSBP. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+/***********************************************************************/
+double TDTable::getConfLimit(int row, int col) //Rows are the degrees of freedom
+{    try {                       
+               //Confidence Level        .80    .90     .95     .98     .99     .998     .999
+               double values[33][7] = {{3.078, 6.314,  12.706, 31.821, 63.656, 318.289, 636.578},
+                                                   {1.886,     2.920,  4.303,  6.965,  9.925,  22.328, 31.600},
+                                                       {1.638, 2.353,  3.182,  4.541,  5.841,  10.214, 12.924},
+                                                       {1.533, 2.132,  2.776,  3.747,  4.604,  7.173,  8.610},
+                                                       {1.476, 2.015,  2.571,  3.365,  4.032,  5.894,  6.869},
+                                                       {1.440, 1.943,  2.447,  3.143,  3.707,  5.208,  5.959},
+                                                       {1.415, 1.895,  2.365,  2.998,  3.499,  4.785,  5.408},
+                                                       {1.397, 1.860,  2.306,  2.896,  3.355,  4.501,  5.041},
+                                                       {1.383, 1.833,  2.262,  2.821,  3.250,  4.297,  4.781},
+                                                       {1.372, 1.812,  2.228,  2.764,  3.169,  4.144,  4.587},
+                                                       {1.363, 1.796,  2.201,  2.718,  3.106,  4.025,  4.437},
+                                                       {1.356, 1.782,  2.179,  2.681,  3.055,  3.930,  4.318},
+                                                       {1.350, 1.771,  2.160,  2.650,  3.012,  3.852,  4.221},
+                                                       {1.345, 1.761,  2.145,  2.624,  2.977,  3.787,  4.140},
+                                                       {1.341, 1.753,  2.131,  2.602,  2.947,  3.733,  4.073},
+                                                       {1.337, 1.746,  2.120,  2.583,  2.921,  3.686,  4.015},
+                                                       {1.333, 1.740,  2.110,  2.567,  2.898,  3.646,  3.965},
+                                                       {1.330, 1.734,  2.101,  2.552,  2.878,  3.610,  3.922},
+                                                       {1.328, 1.729,  2.093,  2.539,  2.861,  3.579,  3.883},
+                                                       {1.325, 1.725,  2.086,  2.528,  2.845,  3.552,  3.850},
+                                                       {1.323, 1.721,  2.080,  2.518,  2.831,  3.527,  3.819},
+                                                       {1.321, 1.717,  2.074,  2.508,  2.819,  3.505,  3.792},
+                                                       {1.319, 1.714,  2.069,  2.500,  2.807,  3.485,  3.768},
+                                                       {1.318, 1.711,  2.064,  2.492,  2.797,  3.467,  3.745},
+                                                       {1.316, 1.708,  2.060,  2.485,  2.787,  3.450,  3.725},
+                                                       {1.315, 1.706,  2.056,  2.479,  2.779,  3.435,  3.707},
+                                                       {1.314, 1.703,  2.052,  2.473,  2.771,  3.421,  3.689},
+                                                       {1.313, 1.701,  2.048,  2.467,  2.763,  3.408,  3.674},
+                                                       {1.311, 1.699,  2.045,  2.462,  2.756,  3.396,  3.660},
+                                                       {1.310, 1.697,  2.042,  2.457,  2.750,  3.385,  3.646},
+                                                       {1.296, 1.671,  2.000,  2.390,  2.660,  3.232,  3.460},
+                                                       {1.289, 1.658,  1.980,  2.358,  2.617,  3.160,  3.373},
+                                                       {1.282, 1.645,  1.960,  2.326,  2.576,  3.091,  3.291}};
+               return values[row][col];
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the TDTable class Function getConfLimit. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the TDTable class function getConfLimit. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+/***********************************************************************
+void TrunLN::doTrunLN(vector<double> indVec, vector<double> specVec) //indVec = individuals vector, specVec = species vector
+{      
+       VecCalc vecCalc;
+       double numSpec = vecCalc.sumElements(specVec); //numSpec = The total number of species
+       double numInd = vecCalc.sumElements(vecCalc.multVecs(indVec,specVec)); //numInd = The total number of individuals
+       
+       double obsMean = 0;
+       for(int i = 0; i < indVec.size(); i++)
+               obsMean += log10(indVec.at(i));
+       obsMean /= numSpec; //obsMean = observed mean of the individuals vector
+       cout << "obsMean = " << obsMean << "\n";
+       double variance = 0;
+       for(int t = 0; t < indVec.size(); t++)
+               variance += pow(log10(indVec.at(t))-obsMean,2)/numSpec;
+        
+        double rO = 0;
+        for(int k = 0; k < indVec.size(); k++)
+               rO += log10(indVec.at(k));
+        rO /= indVec.size();
+        double veilLine = .5;//The desired veil line.
+        double auxFunc = -(obsMean-rO)/(obsMean-log10(veilLine));
+        double uX = obsMean-auxFunc*(obsMean-log10(veilLine));
+        double vX = variance + auxFunc*pow(obsMean-log10(veilLine),2);
+        double z = (log10(veilLine)-uX)/pow(vX, .5);
+        double p = .5*(erf(z)+1);
+        double specRichness = numSpec/(1-p);
+        
+        double numUnseen = .5*(erf((log10(.5)-uX)/pow(vX,.5))+1)*specRichness;
+        
+        
+        vector<double> cExp;
+        for(int i = 1; i < 8; i++)
+        {
+               double a = pow(10, i-1)+.5;
+               double b = log10(a);
+               double c = (b - uX)/pow(vX,.5);
+               double d = .5*(erf(c)+1);
+               double numS = d*specRichness;
+               double toPush = numS - numUnseen;
+               cExp.push_back(toPush);
+       }       
+       vector<double> cObs;
+       double sumOct = 0;
+       for(int i = 0; i < 8; i++)
+       {
+               sumOct = 0;
+               for(int r = 0; r < indVec.size(); r++)
+               {
+                       if(indVec.at(r) < pow(10, i-1)+.5)
+                               sumOct += specVec.at(r);
+                       else
+                       {
+                               cObs.push_back(sumOct);
+                               sumOct = specVec.at(r);
+                               r = indVec.size();
+                       }
+                       if(r == indVec.size()-1)
+                               cObs.push_back(sumOct);
+               }
+       }
+
+       //Statistical Analysis
+       double d = vecCalc.findDStat(cExp, cObs, numSpec);
+       cout << "DStat = " << d << "\n";
+       cout << ".05 confidence value = " << .89196/sqrt(numSpec) << "\n";
+       cout << ".01 confidence value = " << 1.0471/sqrt(numSpec) << "\n\n";
+}
+/***********************************************************************/
diff --git a/calculator.h b/calculator.h
new file mode 100644 (file)
index 0000000..06c3a24
--- /dev/null
@@ -0,0 +1,198 @@
+#ifndef CALCULATOR_H
+#define CALCULATOR_H
+
+using namespace std;
+
+#include <vector>
+#include <cmath>
+#include <iostream>
+#include <fstream>
+#include <math.h>
+#include <string>
+#include <map>
+#include <algorithm>
+#include "utilities.hpp"
+#include "sabundvector.hpp"
+#include "sharedsabundvector.h"
+#include "rabundvector.hpp"
+#include "uvest.h"
+
+/* The calculator class is the parent class for all the different estimators implemented in mothur.
+It has 2 pure functions EstOutput getValues(SAbundVector*), which works on a single group, and 
+EstOutput getValues(SharedRAbundVector* shared1, SharedRAbundVector* shared2), which compares 2 groups. */ 
+
+
+using namespace std;
+typedef vector<double> EstOutput;
+
+/***********************************************************************/
+
+class Calculator {
+
+public:
+       Calculator(){};
+       Calculator(string n, int c) : name(n), cols(c) {};
+       virtual EstOutput getValues(SAbundVector*) = 0; 
+       virtual EstOutput getValues(SharedRAbundVector* shared1, SharedRAbundVector* shared2) = 0;
+       virtual void print(ostream& f)  { f.setf(ios::fixed, ios::floatfield); f.setf(ios::showpoint);
+                                                                         f << data[0]; for(int i=1;i<data.size();i++){ f << '\t' << data[i];   }}
+       virtual string getName()                {       return name;    }
+       virtual int getCols()           {       return cols;    }
+protected:
+       EstOutput data;
+       string name;
+       int cols;
+
+};
+
+/**************************************************************************************************/
+/*This Class holds all of the methods that manipulate vectors.
+These methods are used in the other classes.
+This class must be included if any of the other classes are to be used.*/
+
+class VecCalc
+{
+       // The methods seen in the order here is how they are ordered throughout the class.
+       public:
+               void printElements(vector<double>); //This prints the values of the vector on one line with a space between each value.
+               void printElements(vector<string>); //This prints the values of the vector on one line with a space between each value.
+               int findString(vector<string>, string);//This returns the index of the given string in the given <string> vector, if the string does not exist in the vector it returns -1.
+               double mean(vector<double>); //This returns the mean value of the vector.
+               double stError(vector<double>); //This returns the standard error of the vector.
+               double sumElements(vector<double>); //This returns the sum of all the values in the vector.
+               double sumElements(vector<double>, int); //This returns the sum of all the values in the vector excluding those whose index is before the given index.  
+               double findMax(vector<double>); //This returns the maximum value in the vector.
+               double numNZ(vector<double>); //This returns the number of non-zero values in the vector.
+               double numPos(vector<double>); //This returns the number of positive values in the vector.
+               double findMaxDiff(vector<double>, vector<double>); //This returns the absolute value of the maximum difference between the two vectors.
+               double findDStat(vector<double>, vector<double>, double); //This returns the D-Statistic of the two vectors with the given total number of species.
+               vector<int> findQuartiles(vector<double>); //This returns a vector with the first element being the index of the lower quartile of the vector and the second element being the index of the upper quartile of the vector.
+               vector<double> add(vector<double>, double); //This adds the given number to every element in the given vector and returns the new vector.
+               vector<double> multiply(vector<double>, double); //This multiplies every element in the given vector by the given number and returns the new vector.
+               vector<double> power(vector<double>, double); //This raises every element in the given vector to the given number and returns the new vector.
+               vector<double> addVecs(vector<double>,vector<double>); //The given vectors must be the same size. This adds the ith element of the first given vector to the ith element of the second given vector and returns the new vector.
+               vector<double> multVecs(vector<double>,vector<double>); //The given vectors must be the same size. This multiplies the ith element of the first given vector to the ith element of the second given vector and returns the new vector.
+               vector<double> remDup(vector<double>); //This returns a vector that contains 1 of each unique element in the given vector. The order of the elements is not changed.
+               vector<double> genCVec(vector<double>); //This returns a cumilative vector of the given vector. The ith element of the returned vector is the sum of all the elements in the given vector up to i.
+               vector<double> genRelVec(vector<double>); //This finds the sum of all the elements in the given vector and then divides the ith element in the given vector by that sum and then puts the result into a new vector, which is returned after all of the elements in the given vector have been used.
+               vector<double> genDiffVec(vector<double>, vector<double>);//This subtracts the ith element of the second given vector from the ith element of the first given vector and returns the new vector.
+               vector<double> genCSVec(vector<double>);//This calculates the number of species that have the same number of individuals as the ith element of the given vector and then returns a cumulative vector.
+               vector<double> genTotVec(vector<vector<double> >); //This adds up the ith element of all the columns and puts that value into a new vector. It those this for all the rows and then returns the new vector.
+               vector<double> quicksort(vector<double>); //This sorts the given vector from highest to lowest and returns the sorted vector.
+               vector<vector<double> > gen2DVec(vector<double>, int, int); //(vector, #rows/columns, 0 if the second parameter was rows, 1 if the second parameter was columns) Transforms a single vector that was formatted like a table into a 2D vector.
+               vector<string> getSData(char[]);//This takes a file name as a parameter and reads all of the data in the file into a <string> vector.
+};
+
+/**************************************************************************************************/
+/*This Class contains methods that return the B Diverstiy of two sets
+of data. The four methods are the Whittaker's measure, the Marczewski-Stainhaus distance,
+the Sorensen quantitative index, and the Morisita-Horn index.
+The main method takes a number of columns of data and performs all 4 methods on each
+combination of columns. It prints a table for every method that shows the B Diverstiy for 
+each combination. It also calculates the overall diversity for Whittaker's measure and 
+the Marczewski-Steinhaus distance.*/
+
+
+class BDiversity
+{
+       public:
+               void doBD(vector<double>, double);//Main method
+               double getWhitt(vector<double>,vector<double>);//Whittacker's measure
+               double getMS(vector<double>, vector<double>);//Marczewski-Stainhaus distance
+               double getSor(vector<double>, vector<double>);//Sorensen quantitative index
+               double getMor(vector<double>, vector<double>);//Morisita-Horn index
+               void printD(vector<vector<double> >, int);//This prints a table that represents the given 2D vector, the second paramter specifies which method is to be used (1 for Whitt, 2 for MS, 3 for Sor, and 4 for Mor)
+};
+
+/**************************************************************************************************/
+
+/*This Class is similar to the GeometricSeries.h class. It calculates
+the broken stick distribution of the table and prints the D-Statistic 
+and the confidence limits for the Kolmogorov-Smirnov 1-Sample test
+with a 95% confidence level.*/
+
+class BrokenStick
+{
+       public:
+               void doBStick(vector<double>);
+};
+
+/**************************************************************************************************/
+/*This Class calculates the geometric series distribution for the data.
+It prints the D-Statistic and the critical values for the Kolmogorov-Smirnov
+1-sample test at the 95% confidence interval.*/
+
+class GeometricSeries
+{
+       public:
+               void doGeomTest(vector<double>);
+};
+
+/**************************************************************************************************/
+//This Class calculates the jackknifed estimate of the data and
+//prints it and the confidence limits at a chosen confidence level.
+
+class Jackknifing
+{
+       public:
+               void doJK(vector<double>, double);
+};
+/**************************************************************************************************/
+/*This Class stores calculates the Kolmogorov-Smirnov 2-Sample test between two samples.
+It prints the D-Statistic and the critical value for the test at 
+the 90% and 95% confidence interval.*/
+
+class KS2SampleTest
+{
+       public:
+               void doKSTest(vector<double>, vector<double>);
+};
+/**************************************************************************************************/
+/*This Class calculates the Log Series Distribution for the data.
+It then generates a D-Statistic and prints the D-Statistic and
+the critical values for the Kolmogorov-Smirnov 1 sample test.*/
+
+class LogSD
+{
+       public:
+               void doLogSD(vector<double>, vector<double>);
+};
+
+/**************************************************************************************************/
+//This Class calculates and prints the Q-Statistic for the data.
+class QStatistic
+{
+       public:
+               void doQStat(vector<double>);
+};
+/**************************************************************************************************/
+class SSBPDiversityIndices
+{
+       public:
+               void doSSBP(vector<double>);
+               double getShan(vector<double> vec);//The Shannon Index
+               double getSimp(vector<double> vec);//The Simpson Index
+               double getBP(vector<double> vec);//The Berger-Parker Index
+};
+/**************************************************************************************************/
+//This Class stores the table of the confidence limits of the Student-T distribution.
+class TDTable
+{
+       public:
+               double getConfLimit(int,int);
+};
+
+/**************************************************************************************************/
+/*This Class calculates the truncated lognormal for the data.
+It then prints the D-Statistic and the critical values for the
+Kolmogorov-Smirnov 1-Sample test.*
+
+class TrunLN
+{
+       public:
+               void doTrunLN(vector<double>, vector<double>);
+};
+/**************************************************************************************************/
+
+#endif
+
diff --git a/chao1.cpp b/chao1.cpp
new file mode 100644 (file)
index 0000000..d938eb4
--- /dev/null
+++ b/chao1.cpp
@@ -0,0 +1,66 @@
+/*
+ *  chao1.cpp
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/7/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "chao1.h"
+
+/***********************************************************************/
+EstOutput Chao1::getValues(SAbundVector* rank){
+       try {
+               data.resize(3,0);
+       
+               double sobs = (double)rank->getNumBins();
+       
+               double singles = (double)rank->get(1);
+               double doubles = (double)rank->get(2);
+               double chaovar = 0.0000;
+       
+               double chao = sobs + pow(singles,2)/(2*(doubles+1)) - (singles*doubles/(2*pow(doubles+1,2)));
+       
+               if(doubles==0){chaovar=0;}
+               else{
+                       double g=singles/doubles;
+                       chaovar = doubles*(0.25*pow(g,4)+pow(g,3)+0.5*pow(g,2));
+               }
+
+       
+               double chaohci, chaolci;
+       
+               if(chao==sobs){
+                       double ci = 1.96*pow(chaovar,0.5);
+                       chaolci = chao-ci;//chao lci
+                       chaohci = chao+ci;//chao hci
+               }
+               else{
+                       double denom = pow(chao-sobs,2);
+                       double c = exp(1.96*pow((log(1+chaovar/denom)),0.5));
+                       chaolci = sobs+(chao-sobs)/c;//chao lci
+                       chaohci = sobs+(chao-sobs)*c;//chao hci
+               }
+               
+               data[0] = chao;
+               data[1] = chaolci;
+               data[2] = chaohci;
+
+           if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; }
+               if (isnan(data[1]) || isinf(data[1])) { data[1] = 0; }
+               if (isnan(data[2]) || isinf(data[2])) { data[2] = 0; }
+               
+               return data;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the Chao1 class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the Chao1 class function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+};
+
+/***********************************************************************/
diff --git a/chao1.h b/chao1.h
new file mode 100644 (file)
index 0000000..3a7cfc7
--- /dev/null
+++ b/chao1.h
@@ -0,0 +1,31 @@
+#ifndef CHAO1_H
+#define CHAO1_H
+/*
+ *  chao1.h
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/7/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include <Carbon/Carbon.h>
+#include "calculator.h"
+
+/* This class implements the Ace estimator on single group. 
+It is a child of the calculator class. */
+
+/***********************************************************************/
+
+class Chao1 : public Calculator  {
+       
+public: 
+       Chao1() : Calculator("Chao", 3) {};
+       EstOutput getValues(SAbundVector*);     
+       EstOutput getValues(SharedRAbundVector*, SharedRAbundVector*) {return data;};
+};
+
+
+/***********************************************************************/
+
+#endif
\ No newline at end of file
diff --git a/cluster.cpp b/cluster.cpp
new file mode 100644 (file)
index 0000000..5bd0099
--- /dev/null
@@ -0,0 +1,115 @@
+/*
+ *  cluster.cpp
+ *  
+ *
+ *  Created by Pat Schloss on 8/14/08.
+ *  Copyright 2008 Patrick D. Schloss. All rights reserved.
+ *
+ */
+
+#include "cluster.hpp"
+#include "rabundvector.hpp"
+#include "listvector.hpp"
+#include <exception>
+
+/***********************************************************************/
+
+Cluster::Cluster(RAbundVector* rav, ListVector* lv, SparseMatrix* dm) :
+rabund(rav), list(lv), dMatrix(dm)
+{
+}
+
+/***********************************************************************/
+
+void Cluster::getRowColCells(){
+       try {
+               PCell* smallCell = dMatrix->getSmallestCell();  //find the smallest cell - this routine should probably not be in the SpMat class
+       
+               smallRow = smallCell->row;              //get its row
+               smallCol = smallCell->column;   //get its column
+               smallDist = smallCell->dist;    //get the smallest distance
+       
+               rowCells.clear();
+               colCells.clear();
+               
+               for(MatData currentCell=dMatrix->begin();currentCell!=dMatrix->end();currentCell++){
+               
+                       if(&*currentCell == smallCell){                         //put the smallest cell first
+                               rowCells.insert(rowCells.begin(), currentCell);
+                               colCells.insert(colCells.begin(), currentCell);
+                       }
+                       else if(currentCell->row == smallRow){
+                               rowCells.push_back(currentCell);
+                       }
+                       else if(currentCell->column == smallRow){
+                               rowCells.push_back(currentCell);
+                       }
+                       else if(currentCell->row == smallCol){
+                               colCells.push_back(currentCell);
+                       }
+                       else if(currentCell->column == smallCol){
+                               colCells.push_back(currentCell);
+                       }
+               }
+       
+               nRowCells = rowCells.size();
+               nColCells = colCells.size();
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the Cluster class Function getRowColCells. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the Cluster class function getRowColCells. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+/***********************************************************************/
+
+void Cluster::clusterBins(){
+       try {
+       //      cout << smallCol << '\t' << smallRow << '\t' << smallDist << '\t' << rabund->get(smallRow) << '\t' << rabund->get(smallCol);
+
+               rabund->set(smallCol, rabund->get(smallRow)+rabund->get(smallCol));     
+               rabund->set(smallRow, 0);       
+               rabund->setLabel(toString(smallDist));
+
+       //      cout << '\t' << rabund->get(smallRow) << '\t' << rabund->get(smallCol) << endl;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the Cluster class Function clusterBins. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the Cluster class function clusterBins. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+
+
+}
+
+/***********************************************************************/
+
+void Cluster::clusterNames(){
+       try {
+       //      cout << smallCol << '\t' << smallRow << '\t' << smallDist << '\t' << list->get(smallRow) << '\t' << list->get(smallCol);
+
+               list->set(smallCol, list->get(smallRow)+','+list->get(smallCol));
+               list->set(smallRow, "");        
+               list->setLabel(toString(smallDist));
+       
+       //      cout << '\t' << list->get(smallRow) << '\t' << list->get(smallCol) << endl;
+    }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the Cluster class Function clusterNames. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the Cluster class function clusterNames. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+/***********************************************************************/
+
diff --git a/cluster.hpp b/cluster.hpp
new file mode 100644 (file)
index 0000000..a673027
--- /dev/null
@@ -0,0 +1,78 @@
+#ifndef CLUSTER_H
+#define CLUSTER_H
+
+using namespace std;
+
+#include <iostream>
+#include <list>
+
+#include "utilities.hpp"
+#include "sparsematrix.hpp"
+#include "rabundvector.hpp"
+
+class RAbundVector;
+class ListVector;
+class SparseMatrix;
+
+typedef list<PCell>::iterator MatData;
+
+class Cluster {
+       
+public:
+       Cluster(RAbundVector*, ListVector*, SparseMatrix*);
+       virtual void update() = 0;
+       
+protected:     
+       void getRowColCells();
+       virtual void clusterBins();
+       virtual void clusterNames();
+       
+       RAbundVector* rabund;
+       ListVector* list;
+       SparseMatrix* dMatrix;  
+       
+       int smallRow;
+       int smallCol;
+       float smallDist;
+       vector<MatData> rowCells;
+       vector<MatData> colCells;
+       ull nRowCells;
+       ull nColCells;
+};
+
+/***********************************************************************/
+
+class CompleteLinkage : public Cluster {
+public:
+       CompleteLinkage(RAbundVector*, ListVector*, SparseMatrix*);
+       void update();
+       
+private:
+               
+};
+
+/***********************************************************************/
+
+class SingleLinkage : public Cluster {
+public:
+       SingleLinkage(RAbundVector*, ListVector*, SparseMatrix*);
+       void update();
+       
+private:
+               
+};
+
+/***********************************************************************/
+
+class AverageLinkage : public Cluster {
+public:
+       AverageLinkage(RAbundVector*, ListVector*, SparseMatrix*);
+       void update();
+       
+private:
+               
+};
+
+/***********************************************************************/
+
+#endif
diff --git a/clustercommand.cpp b/clustercommand.cpp
new file mode 100644 (file)
index 0000000..7972816
--- /dev/null
@@ -0,0 +1,151 @@
+/*
+ *  clustercommand.cpp
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/2/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "clustercommand.h"
+
+//**********************************************************************************************************************
+//This function checks to make sure the cluster command has no errors and then clusters based on the method chosen.
+ClusterCommand::ClusterCommand(){
+       try{
+               globaldata = GlobalData::getInstance();
+       
+               if(globaldata->getSparseMatrix() != NULL)       {       matrix = new SparseMatrix(*globaldata->getSparseMatrix());              }
+       //  Not sure if we want the address or an entire new memory allocation.  Might be nice to have new memory so data
+       //  doesn't need to be re-read, but then again, it could suck up a ton of memory.  Dunno.
+       //      if(globaldata->getSparseMatrix() != NULL)       {       matrix = globaldata->getSparseMatrix();         }
+       
+               if(globaldata->getListVector() != NULL){
+                       list = new ListVector(*globaldata->getListVector());
+                       rabund = new RAbundVector(list->getRAbundVector());
+                       //rabund->print(cout);
+               }
+       
+               if(globaldata->getMethod() != "")       {       method = globaldata->getMethod();               }               
+               //if no method given use furthest, initialized in globaldata
+               if(method == "furthest")        {       cluster = new CompleteLinkage(rabund, list, matrix);    tag = "fn";     }
+               else if(method == "nearest"){   cluster = new SingleLinkage(rabund, list, matrix);              tag = "nn";     }
+               else if(method == "average"){   cluster = new AverageLinkage(rabund, list, matrix);             tag = "an";     }
+               else                                            {       cout << "error - not recognized method" << endl;                                                                                        }
+       
+               if(globaldata->getPrecision() != ""){
+                       convert(globaldata->getPrecision(), precision); 
+               }
+               
+               //saves precision legnth for formatting below
+               length = globaldata->getPrecision().length();
+               
+               if(globaldata->getCutOff() != ""){
+                       convert(globaldata->getCutOff(), cutoff);       
+                       cutoff += (5 / (precision * 10.0));
+               }
+       
+               fileroot = getRootName(globaldata->getFileRoot());
+               
+               openOutputFile(fileroot+ tag + ".sabund",       sabundFile);
+               openOutputFile(fileroot+ tag + ".rabund",       rabundFile);
+               openOutputFile(fileroot+ tag + ".list",         listFile);
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ClusterCommand class Function ClusterCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ClusterCommand class function ClusterCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+
+ClusterCommand::~ClusterCommand(){
+       delete cluster;
+       delete matrix;
+       delete list;
+       delete rabund;
+}
+
+//**********************************************************************************************************************
+
+int ClusterCommand::execute(){
+       try {
+               float previousDist = 0.00000;
+               float rndPreviousDist = 0.00000;
+               oldRAbund = *rabund;
+               oldList = *list;
+               
+               float x;
+               x=0.1;
+               toString(x, 2);
+       
+               while(matrix->getSmallDist() < cutoff && matrix->getNNodes() > 0){
+                       cluster->update();
+                       float dist = matrix->getSmallDist();
+                       float rndDist = roundDist(dist, precision);
+
+                       if(previousDist <= 0.0000 && dist != previousDist){
+                               printData("unique");
+                       }
+                       else if(rndDist != rndPreviousDist){
+                               printData(toString(rndPreviousDist,  length-1));
+                       }
+               
+                       previousDist = dist;
+                       rndPreviousDist = rndDist;
+                       oldRAbund = *rabund;
+                       oldList = *list;
+               }
+       
+               if(previousDist <= 0.0000){
+                       printData("unique");
+               }
+               else if(rndPreviousDist<cutoff){
+                       printData(toString(rndPreviousDist, length-1));
+               }
+       
+               //saves .list file so you can do the collect, rarefaction and summary commands without doing a read.list
+               globaldata->setDistFile("");
+               globaldata->setListFile(fileroot+ tag + ".list");
+               globaldata->setNameFile("");
+               globaldata->setFormat("list");
+               
+               return 0;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ClusterCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ClusterCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+
+}
+
+//**********************************************************************************************************************
+
+void ClusterCommand::printData(string label){
+       try {
+               oldRAbund.setLabel(label);
+               oldRAbund.getSAbundVector().print(cout);
+               oldRAbund.print(rabundFile);
+               oldRAbund.getSAbundVector().print(sabundFile);
+       
+               oldList.setLabel(label);
+               oldList.print(listFile);
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ClusterCommand class Function printData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ClusterCommand class function printData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+
+}
+//**********************************************************************************************************************
diff --git a/clustercommand.h b/clustercommand.h
new file mode 100644 (file)
index 0000000..9dfd2a0
--- /dev/null
@@ -0,0 +1,56 @@
+#ifndef CLUSTERCOMMAND_H
+#define CLUSTERCOMMAND_H
+/*
+ *  clustercommand.h
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/2/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include <Carbon/Carbon.h>
+#include <iostream>
+#include <fstream>
+#include "command.hpp"
+#include "rabundvector.hpp"
+#include "listvector.hpp"
+#include "cluster.hpp"
+#include "sparsematrix.hpp"
+
+/* The cluster() command:
+       The cluster command can only be executed after a successful read.phylip or read.column command.   
+       The cluster command outputs a .list , .rabund and .sabund files.  
+       The cluster command parameter options are method, cuttoff and precision. No parameters are required.  
+       The cluster command should be in the following format: cluster(method=yourMethod, cutoff=yourCutoff, precision=yourPrecision).  
+       The acceptable methods are furthest, nearest and average.  If you do not provide a method the default algorythm is furthest neighbor.  
+       The cluster() command outputs three files *.list, *.rabund, and *.sabund.   */
+
+
+class GlobalData;
+
+class ClusterCommand : public Command {
+       
+public:
+       ClusterCommand();       
+       ~ClusterCommand();
+       int execute();  
+       
+private:
+       GlobalData* globaldata;
+       Cluster* cluster;
+       SparseMatrix* matrix;
+       ListVector* list;
+       RAbundVector* rabund;
+       RAbundVector oldRAbund;
+       ListVector oldList;
+       
+       string method, fileroot, tag;
+       double cutoff;
+       int precision, length;
+       ofstream sabundFile, rabundFile, listFile;
+       
+       void printData(string label);
+};
+
+#endif
\ No newline at end of file
diff --git a/collect.cpp b/collect.cpp
new file mode 100644 (file)
index 0000000..7f589ce
--- /dev/null
@@ -0,0 +1,166 @@
+/*
+ *  collect.cpp
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 11/18/08.
+ *  Copyright 2008 __MyCompanyName__. All rights reserved.
+ *
+ */
+
+#include "collect.h"
+
+
+/***********************************************************************/
+
+void Collect::getCurve(int increment = 1){
+       try {
+               RAbundVector* lookup = new RAbundVector(order->getNumBins());
+               SAbundVector* rank      = new SAbundVector(order->getMaxRank()+1);
+
+               CollectorsCurveData* ccd = new CollectorsCurveData();
+       
+               for(int i=0;i<displays.size();i++){
+                       ccd->registerDisplay(displays[i]); //adds a display[i] to cdd
+                       displays[i]->init(label);                  //sets displays label
+               }                                                                          
+               for(int i=0;i<numSeqs;i++){
+
+                       int binNumber = order->get(i);
+                       int abundance = lookup->get(binNumber);
+               
+                       rank->set(abundance, rank->get(abundance)-1); 
+               
+                       abundance++;
+               
+                       lookup->set(binNumber, abundance);
+                       rank->set(abundance, rank->get(abundance)+1); //increment rank(abundance)
+
+                       if((i == 0) || (i+1) % increment == 0){
+                               ccd->updateRankData(rank);
+                       }
+               }
+       
+               if(numSeqs % increment != 0){
+                       ccd->updateRankData(rank);
+               }
+       
+               for(int i=0;i<displays.size();i++){
+                       displays[i]->reset();
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the Collect class Function getCurve. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the Collect class function getCurve. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+
+}
+
+/***********************************************************************/
+void Collect::getSharedCurve(int increment = 1){
+try {
+               globaldata = GlobalData::getInstance();
+               vector<SharedRAbundVector*> lookup; 
+
+               //create and initialize vector of sharedvectors, one for each group
+               for (int i = 0; i < globaldata->gGroupmap->getNumGroups(); i++) { 
+                       SharedRAbundVector* temp = new SharedRAbundVector(sharedorder->getNumBins());
+                       temp->setLabel(sharedorder->getLabel());
+                       temp->setGroup(globaldata->gGroupmap->namesOfGroups[i]);
+                       lookup.push_back(temp);
+               }
+
+               SharedCollectorsCurveData* ccd = new SharedCollectorsCurveData();
+       
+               //initialize labels for output
+               //makes  'uniqueAB       uniqueAC  uniqueBC' if your groups are A, B, C
+               getGroupComb();
+               groupLabel = "";
+               for (int s = 0; s < groupComb.size(); s++) {
+                       groupLabel = groupLabel + label + groupComb[s] + "\t";
+               }
+
+               for(int i=0;i<displays.size();i++){
+                       ccd->registerDisplay(displays[i]); //adds a display[i] to cdd
+                       displays[i]->init(groupLabel);            
+               }
+               
+               //sample all the members
+               for(int i=0;i<numSeqs;i++){
+                       //get first sample
+                       individual chosen = sharedorder->get(i);
+                       int abundance; 
+                                       
+                       //set info for sharedvector in chosens group
+                       for (int j = 0; j < lookup.size(); j++) { 
+                               if (chosen.group == lookup[j]->getGroup()) {
+                                        abundance = lookup[j]->getAbundance(chosen.bin);
+                                        lookup[j]->set(chosen.bin, (abundance + 1), chosen.group);
+                                        break;
+                               }
+                       }
+                       
+                       //calculate at 0 and the given increment
+                       if((i == 0) || (i+1) % increment == 0){
+                               //randomize group order
+                               if (globaldata->getJumble() == "1") { random_shuffle(lookup.begin(), lookup.end()); }
+                               //how many comparisons to make i.e. for group a, b, c = ab, ac, bc.
+                               int n = 1;
+                               for (int k = 0; k < (lookup.size() - 1); k++) { // pass cdd each set of groups to commpare
+                                       for (int l = n; l < lookup.size(); l++) {
+                                               ccd->updateSharedData(lookup[k], lookup[l], i+1, numGroupComb);
+                                       }
+                                       n++;
+                               }
+                       }
+                       totalNumSeq = i+1;
+               }
+               
+               //calculate last line if you haven't already
+               if(numSeqs % increment != 0){
+                       //how many comparisons to make i.e. for group a, b, c = ab, ac, bc.
+                       int n = 1;
+                       for (int k = 0; k < (lookup.size() - 1); k++) { // pass cdd each set of groups to commpare
+                               for (int l = n; l < lookup.size(); l++) {
+                                       ccd->updateSharedData(lookup[k], lookup[l], totalNumSeq, numGroupComb);
+                               }
+                               n++;
+                       }
+               }
+               
+               //resets output files
+               for(int i=0;i<displays.size();i++){
+                       displays[i]->reset();
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the Collect class Function getSharedCurve. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the Collect class function getSharedCurve. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+
+}
+
+/**************************************************************************************/
+void Collect::getGroupComb() {
+               string group;
+               
+               numGroupComb = 0;
+               
+               int n = 1;
+               for (int i = 0; i < (globaldata->gGroupmap->getNumGroups() - 1); i++) {
+                       for (int l = n; l < globaldata->gGroupmap->getNumGroups(); l++) {
+                               group = globaldata->gGroupmap->namesOfGroups[i] + globaldata->gGroupmap->namesOfGroups[l];
+                               groupComb.push_back(group);     
+                               numGroupComb++;
+                       }
+                       n++;
+               }
+
+}
\ No newline at end of file
diff --git a/collect.h b/collect.h
new file mode 100644 (file)
index 0000000..fe78dda
--- /dev/null
+++ b/collect.h
@@ -0,0 +1,43 @@
+#ifndef COLLECT_H
+#define COLLECT_H
+
+using namespace std;
+
+
+#include "collectorscurvedata.h"
+#include "display.h"
+#include "ordervector.hpp"
+#include "sabundvector.hpp"
+#include "rabundvector.hpp"
+#include "sharedordervector.h"
+#include "datavector.hpp"
+#include "globaldata.hpp"
+
+/***********************************************************************/
+
+class Collect {
+       
+public:
+       Collect(OrderVector* order, vector<Display*> disp) :
+                                       numSeqs(order->getNumSeqs()), order(order), displays(disp), label(order->getLabel())  {};
+       Collect(SharedOrderVector* sharedorder, vector<Display*> disp) :
+                                       numSeqs(sharedorder->getNumSeqs()), sharedorder(sharedorder), displays(disp), label(sharedorder->getLabel())  {};
+
+       ~Collect(){             };
+       void getCurve(int);
+       void getSharedCurve(int);
+       
+private:
+       SharedOrderVector* sharedorder;
+       GlobalData* globaldata;
+       OrderVector* order;
+       vector<Display*> displays;
+       int numSeqs, numGroupComb, totalNumSeq;
+       string label, groupLabel;
+       void getGroupComb();
+       vector<string> groupComb;
+};
+
+
+#endif
+
diff --git a/collectcommand.cpp b/collectcommand.cpp
new file mode 100644 (file)
index 0000000..4687c6e
--- /dev/null
@@ -0,0 +1,112 @@
+/*
+ *  collectcommand.cpp
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/2/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "collectcommand.h"
+#include "ace.h"
+#include "sobs.h"
+#include "chao1.h"
+#include "bootstrap.h"
+#include "simpson.h"
+#include "npshannon.h"
+#include "shannon.h"
+#include "jackknife.h"
+
+
+//**********************************************************************************************************************
+
+
+CollectCommand::CollectCommand(){
+       try {
+               globaldata = GlobalData::getInstance();
+               string fileNameRoot;
+               fileNameRoot = getRootName(globaldata->inputFileName);
+               int i;
+               for (i=0; i<globaldata->singleEstimators.size(); i++) {
+                       if (globaldata->singleEstimators[i] == "sobs") { 
+                               cDisplays.push_back(new CollectDisplay(new Sobs(), new OneColumnFile(fileNameRoot+"sobs")));
+                       }else if (globaldata->singleEstimators[i] == "chao") { 
+                               cDisplays.push_back(new CollectDisplay(new Chao1(), new ThreeColumnFile(fileNameRoot+"chao")));
+                       }else if (globaldata->singleEstimators[i] == "ace") { 
+                               cDisplays.push_back(new CollectDisplay(new Ace(), new ThreeColumnFile(fileNameRoot+"ace")));
+                       }else if (globaldata->singleEstimators[i] == "jack") { 
+                               cDisplays.push_back(new CollectDisplay(new Jackknife(), new ThreeColumnFile(fileNameRoot+"jack")));
+                       }else if (globaldata->singleEstimators[i] == "shannon") { 
+                               cDisplays.push_back(new CollectDisplay(new Shannon(), new ThreeColumnFile(fileNameRoot+"shannon")));
+                       }else if (globaldata->singleEstimators[i] == "npshannon") { 
+                               cDisplays.push_back(new CollectDisplay(new NPShannon(), new OneColumnFile(fileNameRoot+"np_shannon")));
+                       }else if (globaldata->singleEstimators[i] == "simpson") { 
+                               cDisplays.push_back(new CollectDisplay(new Simpson(), new ThreeColumnFile(fileNameRoot+"simpson")));
+                       }else if (globaldata->singleEstimators[i] == "bootstrap") { 
+                               cDisplays.push_back(new CollectDisplay(new Bootstrap(), new OneColumnFile(fileNameRoot+"bootstrap")));
+                       }
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the CollectCommand class Function CollectCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the CollectCommand class function CollectCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+                       
+}
+
+//**********************************************************************************************************************
+
+CollectCommand::~CollectCommand(){
+       delete order;
+       delete input;
+       delete cCurve;
+       delete read;
+}
+
+//**********************************************************************************************************************
+
+int CollectCommand::execute(){
+       try {
+               int count = 1;
+               read = new ReadPhilFile(globaldata->inputFileName);     
+               read->read(&*globaldata); 
+               
+               order = globaldata->gorder;
+               input = globaldata->ginput;
+                       
+               while(order != NULL){
+               
+                       if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
+                       
+                               cCurve = new Collect(order, cDisplays);
+                               convert(globaldata->getFreq(), freq);
+                               cCurve->getCurve(freq);
+                       
+                               delete cCurve;
+                       
+                               cout << order->getLabel() << '\t' << count << endl;
+                       }
+               
+                       order = (input->getOrderVector());
+                       count++;
+               
+               }
+       
+               for(int i=0;i<cDisplays.size();i++){    delete cDisplays[i];    }       
+               return 0;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the CollectCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the CollectCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+//**********************************************************************************************************************
diff --git a/collectcommand.h b/collectcommand.h
new file mode 100644 (file)
index 0000000..633f345
--- /dev/null
@@ -0,0 +1,58 @@
+#ifndef COLLECTCOMMAND_H
+#define COLLECTCOMMAND_H
+/*
+ *  collectcommand.h
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/2/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include <Carbon/Carbon.h>
+#include <iostream>
+#include <fstream>
+#include <vector>
+#include "command.hpp"
+#include "ordervector.hpp"
+#include "inputdata.h"
+#include "groupmap.h"
+#include "collect.h"
+#include "display.h"
+#include "readmatrix.hpp"
+
+/*The collect() command:
+       The collect command generates a collector's curve from the given file.  
+       The collect command can only be executed after a successful read.list, read.sabund or read.rabund command, with one exception. 
+       The collect command can be executed after a successful cluster command.  It will use the .list file from the output of the cluster.  
+       The collect command outputs a file for each estimator you choose to use.  The collect command parameters are label, line, freq, single.  
+       No parameters are required, but you may not use both the line and label  parameters at the same time.  
+       The collect command should be in the following format: collect(label=yourLabel, line=yourLines, freq=yourFreq, single=yourEstimators). 
+       example collect(label=unique-.01-.03, line=0,5,10, freq=10, single=collect-chao-ace-jack).  
+       The default values for  freq is 100, and single are collect-chao-ace-jack-bootstrap-shannon-npshannon-simpson.  
+       The valid single estimators are: collect-chao-ace-jack-bootstrap-shannon-npshannon-simpson. 
+       The label and line parameters are used to analyze specific lines in your input. */
+
+
+
+class GlobalData;
+
+class CollectCommand : public Command {
+       
+public:
+       CollectCommand();       
+       ~CollectCommand();
+       int execute();  
+       
+private:
+       GlobalData* globaldata;
+       ReadMatrix* read;
+       OrderVector* order;
+       InputData* input;
+       Collect* cCurve;
+       vector<Display*> cDisplays;
+       int freq;
+
+};
+
+#endif
\ No newline at end of file
diff --git a/collectdisplay.h b/collectdisplay.h
new file mode 100644 (file)
index 0000000..7127573
--- /dev/null
@@ -0,0 +1,54 @@
+#ifndef COLLECTDISPLAY_H
+#define COLLECTDISPLAY_H
+
+#include "sabundvector.hpp"
+#include "sharedsabundvector.h"
+#include "calculator.h"
+#include "fileoutput.h"
+#include "display.h"
+#include <vector>
+
+using namespace std;
+
+/***********************************************************************/
+
+class CollectDisplay : public Display {
+       
+public:
+       CollectDisplay(Calculator* calc, FileOutput* file) : estimate(calc), output(file) {timesCalled = 0;};
+       ~CollectDisplay()       {       delete estimate; delete output;         }
+       void update(SAbundVector* rank){
+               nSeqs=rank->getNumSeqs();
+               data = estimate->getValues(rank);
+               output->output(nSeqs, data);    
+       };
+       
+       void update(SharedRAbundVector* shared1, SharedRAbundVector* shared2, int numSeqs, int numGroupComb){
+               timesCalled++;
+               data = estimate->getValues(shared1, shared2);  //passes estimators a shared vector from each group to be compared
+               //fills groupdata with datas info
+               for (int i = 0; i < data.size(); i++) {
+                       groupData.push_back(data[i]);
+               }
+               //when you get all your groups info then output
+               if ((timesCalled % numGroupComb) == 0) {
+                       output->output(numSeqs, groupData);     
+                       groupData.clear();
+               }
+       };
+       
+       void init(string s)             {       output->initFile(s);    };
+       void reset()                    {       output->resetFile();    };
+       void close()                    {       output->resetFile();    };
+       
+private:
+       Calculator* estimate;
+       FileOutput* output;
+       int nSeqs, timesCalled;
+       vector<double> data;
+       vector<double> groupData;
+};
+
+/***********************************************************************/
+
+#endif
\ No newline at end of file
diff --git a/collectorscurvedata.h b/collectorscurvedata.h
new file mode 100644 (file)
index 0000000..e6f6278
--- /dev/null
@@ -0,0 +1,66 @@
+#ifndef COLLECTORSCURVEDATA_H
+#define COLLECTORSCURVEDATA_H
+
+#include <set>
+#include "sabundvector.hpp"
+#include "sharedRAbundvector.h"
+#include "display.h"
+#include "observable.h"
+
+using namespace std;
+
+/***********************************************************************/
+
+class CollectorsCurveData : public Observable {
+       
+public:
+       CollectorsCurveData() : rank(0) {};
+       
+       void registerDisplay(Display* o)                {       displays.insert(o);                             };
+       void removeDisplay(Display* o)                  {       displays.erase(o);      delete o;       };
+       SAbundVector* getRankData()                             {       return rank;                                    };
+       void rankDataChanged()                                  {       notifyDisplays();                               };
+       void updateRankData(SAbundVector* rv)   {       rank = rv; rankDataChanged();   };
+
+       void notifyDisplays(){  
+               for(set<Display*>::iterator pos=displays.begin();pos!=displays.end();pos++){
+                       (*pos)->update(rank);
+               }       
+       };
+       
+private:
+       set<Display*> displays;
+       SAbundVector* rank;
+       
+};
+
+/***********************************************************************/
+
+
+class SharedCollectorsCurveData : public Observable {
+       
+public:
+       SharedCollectorsCurveData() : shared1(0), shared2(0) {};
+       
+       void registerDisplay(Display* o)                {       displays.insert(o);                             };
+       void removeDisplay(Display* o)                  {       displays.erase(o);      delete o;       };
+       void SharedDataChanged()                                        {       notifyDisplays();                               };
+       void updateSharedData(SharedRAbundVector* rv, SharedRAbundVector* rv2, int numSeqs, int numGroupComb)   {       shared1 = rv; shared2 = rv2; NumSeqs = numSeqs; NumGroupComb = numGroupComb; SharedDataChanged();       };
+
+       void notifyDisplays(){  
+               for(set<Display*>::iterator pos=displays.begin();pos!=displays.end();pos++){
+                       (*pos)->update(shared1, shared2, NumSeqs, NumGroupComb);
+               }       
+       };
+       
+private:
+       set<Display*> displays;
+       SharedRAbundVector* shared1;
+       SharedRAbundVector* shared2;
+       int NumSeqs, NumGroupComb;
+};
+
+/***********************************************************************/
+
+#endif
+
diff --git a/collectsharedcommand.cpp b/collectsharedcommand.cpp
new file mode 100644 (file)
index 0000000..63a267d
--- /dev/null
@@ -0,0 +1,126 @@
+/*
+ *  collectsharedcommand.cpp
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/2/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "collectsharedcommand.h"
+#include "sharedchao1.h"
+#include "sharedace.h"
+#include "sharedjabund.h"
+#include "sharedsorabund.h"
+#include "sharedjclass.h"
+#include "sharedsorclass.h"
+#include "sharedjest.h"
+#include "sharedsorest.h"
+#include "sharedthetayc.h"
+#include "sharedthetan.h"
+
+
+//**********************************************************************************************************************
+
+CollectSharedCommand::CollectSharedCommand(){
+       try {
+               globaldata = GlobalData::getInstance();
+               string fileNameRoot;
+               fileNameRoot = getRootName(globaldata->inputFileName);
+               groupmap = globaldata->gGroupmap;
+               
+               int i;
+               for (i=0; i<globaldata->sharedEstimators.size(); i++) {
+                       if (globaldata->sharedEstimators[i] == "sharedChao") { 
+                               cDisplays.push_back(new CollectDisplay(new SharedChao1(), new SharedOneColumnFile(fileNameRoot+"sharedChao", groupmap->namesOfGroups)));
+                       }else if (globaldata->sharedEstimators[i] == "sharedAce") { 
+                               cDisplays.push_back(new CollectDisplay(new SharedAce(), new SharedOneColumnFile(fileNameRoot+"sharedAce", groupmap->namesOfGroups)));
+                       }else if (globaldata->sharedEstimators[i] == "sharedJabund") {  
+                               cDisplays.push_back(new CollectDisplay(new SharedJAbund(), new SharedOneColumnFile(fileNameRoot+"SharedJabund", groupmap->namesOfGroups)));
+                       }else if (globaldata->sharedEstimators[i] == "sharedSorensonAbund") { 
+                               cDisplays.push_back(new CollectDisplay(new SharedSorAbund(), new SharedOneColumnFile(fileNameRoot+"SharedSorensonAbund", groupmap->namesOfGroups)));
+                       }else if (globaldata->sharedEstimators[i] == "sharedJclass") { 
+                               cDisplays.push_back(new CollectDisplay(new SharedJclass(), new SharedOneColumnFile(fileNameRoot+"SharedJclass", groupmap->namesOfGroups)));
+                       }else if (globaldata->sharedEstimators[i] == "sharedSorClass") { 
+                               cDisplays.push_back(new CollectDisplay(new SharedSorClass(), new SharedOneColumnFile(fileNameRoot+"SharedSorClass", groupmap->namesOfGroups)));
+                       }else if (globaldata->sharedEstimators[i] == "sharedJest") { 
+                               cDisplays.push_back(new CollectDisplay(new SharedJest(), new SharedOneColumnFile(fileNameRoot+"SharedJest", groupmap->namesOfGroups)));
+                       }else if (globaldata->sharedEstimators[i] == "sharedSorEst") { 
+                               cDisplays.push_back(new CollectDisplay(new SharedSorEst(), new SharedOneColumnFile(fileNameRoot+"SharedSorEst", groupmap->namesOfGroups)));
+                       }else if (globaldata->sharedEstimators[i] == "SharedThetaYC") { 
+                               cDisplays.push_back(new CollectDisplay(new SharedThetaYC(), new SharedOneColumnFile(fileNameRoot+"SharedThetaYC", groupmap->namesOfGroups)));
+                       }else if (globaldata->sharedEstimators[i] == "SharedThetaN") { 
+                               cDisplays.push_back(new CollectDisplay(new SharedThetaN(), new SharedOneColumnFile(fileNameRoot+"SharedThetaN", groupmap->namesOfGroups)));
+                       }
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the CollectSharedCommand class Function CollectSharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the CollectSharedCommand class function CollectSharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+                       
+}
+
+//**********************************************************************************************************************
+
+CollectSharedCommand::~CollectSharedCommand(){
+       delete order;
+       delete input;
+       delete cCurve;
+       delete read;
+}
+
+//**********************************************************************************************************************
+
+int CollectSharedCommand::execute(){
+       try {
+               int count = 1;
+               read = new ReadPhilFile(globaldata->inputFileName);     
+               read->read(&*globaldata); 
+               
+               input = globaldata->ginput;
+               list = globaldata->glist;
+               order = list->getSharedOrderVector();
+               
+               while(order != NULL){
+               
+                       if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
+                               //create collectors curve
+                               cCurve = new Collect(order, cDisplays);
+                               convert(globaldata->getFreq(), freq);
+                               cCurve->getSharedCurve(freq);
+                       
+                               delete cCurve;
+                       
+                               cout << order->getLabel() << '\t' << count << endl;
+                       }
+                       
+                       list = input->getListVector(); //get new list vector to process
+                       if (list != NULL) {
+                               order = list->getSharedOrderVector(); //gets new order vector with group info.
+                               count++;
+                       }else {
+                               break;
+                       }
+               
+               }
+       
+               for(int i=0;i<cDisplays.size();i++){    delete cDisplays[i];    }       
+               return 0;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the CollectSharedCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the CollectSharedCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+
+//**********************************************************************************************************************
diff --git a/collectsharedcommand.h b/collectsharedcommand.h
new file mode 100644 (file)
index 0000000..ee11a70
--- /dev/null
@@ -0,0 +1,60 @@
+#ifndef COLLECTSHAREDCOMMAND_H
+#define COLLECTSHAREDCOMMAND_H
+/*
+ *  collectsharedcommand.h
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/2/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include <Carbon/Carbon.h>
+#include <iostream>
+#include <fstream>
+#include <vector>
+#include "command.hpp"
+#include "sharedordervector.h"
+#include "listvector.hpp"
+#include "inputdata.h"
+#include "groupmap.h"
+#include "collect.h"
+#include "display.h"
+#include "readmatrix.hpp"
+
+/* The collect.shared() command:
+       The collect command generates a collector's curve from the given file representing several groups.  
+       The collect.shared command can only be executed after a successful read.shared command. 
+       It outputs a file for each estimator you choose to use.  The collect.shared command parameters are label, line, freq, jumble and shared.  
+       No parameters are required, but you may not use both the line and label parameters at the same time. 
+       The collect.shared command should be in the following format: collect.shared(label=yourLabel, line=yourLines, 
+       freq=yourFreq,  jumble=yourJumble, shared=yourEstimators). Example collect.shared(label=unique-.01-.03, line=0,5,10, freq=10, jumble=1, 
+       shared=sharedChao-sharedAce-sharedJabund). The default values for jumble is 0 (meaning don’t jumble, if it’s set to 1 then it will jumble), 
+       freq is 100 and shared are sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN.  
+       The valid shared estimators are: sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN.  
+       The label and line parameters are used to analyze specific lines in your input. */
+
+
+class GlobalData;
+
+class CollectSharedCommand : public Command {
+       
+public:
+       CollectSharedCommand(); 
+       ~CollectSharedCommand();
+       int execute();  
+       
+private:
+       GlobalData* globaldata;
+       GroupMap* groupmap;
+       ListVector* list;
+       ReadMatrix* read;
+       SharedOrderVector* order;
+       InputData* input;
+       Collect* cCurve;
+       vector<Display*> cDisplays;
+       int freq;
+
+};
+
+#endif
\ No newline at end of file
diff --git a/command.hpp b/command.hpp
new file mode 100644 (file)
index 0000000..6d734e0
--- /dev/null
@@ -0,0 +1,26 @@
+#ifndef COMMAND_HPP
+#define COMMAND_HPP
+
+/*
+ *  command.h
+ *  
+ *
+ *  Created by Pat Schloss on 10/23/08.
+ *  Copyright 2008 Patrick D. Schloss. All rights reserved.
+ *
+ */
+
+/*This class is a parent to all the command classes.  It has one pure int execute(). */
+
+using namespace std;
+
+#include <iostream>
+#include <fstream>
+
+
+class Command {
+       public:
+               virtual int execute() = 0;
+};
+
+#endif
diff --git a/commandfactory.cpp b/commandfactory.cpp
new file mode 100644 (file)
index 0000000..224a4cc
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ *  commandfactory.cpp
+ *  
+ *
+ *  Created by Pat Schloss on 10/25/08.
+ *  Copyright 2008 Patrick D. Schloss. All rights reserved.
+ *
+ */
+
+#include "command.hpp"
+#include "readdistphylipfilecommand.h"
+#include "readdistcolumnfilecommand.h"
+#include "readlistfilecommand.h"
+#include "readrabundfilecommand.h"
+#include "readsabundfilecommand.h"
+#include "readsharedfilecommand.h"
+#include "clustercommand.h"
+#include "parselistcommand.h"
+#include "sharedcommand.h"
+#include "collectcommand.h"
+#include "collectsharedcommand.h"
+#include "rarefactcommand.h"
+#include "summarycommand.h"
+#include "summarysharedcommand.h"
+#include "rarefactsharedcommand.h"
+#include "nocommand.h"
+#include "quitcommand.h"
+#include "helpcommand.h"
+#include "commandfactory.hpp"
+#include <exception>
+
+
+/***********************************************************/
+
+/***********************************************************/
+CommandFactory::CommandFactory(){
+       command = new NoCommand();
+}
+
+/***********************************************************/
+
+/***********************************************************/
+CommandFactory::~CommandFactory(){
+       delete command;
+}
+
+/***********************************************************/
+
+/***********************************************************/
+//This function calls the appropriate command fucntions based on user input.
+Command* CommandFactory::getCommand(string commandName){
+       try {
+               delete command;   //delete the old command
+
+                        if(commandName == "read.phylip")                       {       command = new ReadDistPhylipFileCommand();      }
+               else if(commandName == "read.column")                   {       command = new ReadDistColumnFileCommand();      }
+               else if(commandName == "read.list")                             {       command = new ReadListFileCommand();    }
+               else if(commandName == "read.rabund")                   {       command = new ReadRAbundFileCommand();  }
+               else if(commandName == "read.sabund")                   {       command = new ReadSAbundFileCommand();  }
+               else if(commandName == "read.shared")                   {       command = new ReadSharedFileCommand();  }
+               else if(commandName == "cluster")                               {       command = new ClusterCommand();                 }
+               else if(commandName == "help")                                  {       command = new HelpCommand();                    }
+               else if(commandName == "quit")                                  {       command = new QuitCommand();                    }
+               else if(commandName == "collect.single")                {       command = new CollectCommand();                 }
+               else if(commandName == "shared")                                {       command = new SharedCommand();                  }
+               else if(commandName == "collect.shared")                {       command = new CollectSharedCommand();   }
+               else if(commandName == "rarefaction.single")    {       command = new RareFactCommand();                }
+               else if(commandName == "rarefaction.shared")    {       command = new RareFactSharedCommand();  }
+               else if(commandName == "summary.single")                {       command = new SummaryCommand();                 }
+               else if(commandName == "summary.shared")                {       command = new SummarySharedCommand();   }
+               else if(commandName == "parselist")                             {       command = new ParseListCommand();               }
+               else                                                                                    {       command = new NoCommand();                              }
+
+               return command;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the CommandFactory class Function getCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the CommandFactory class function getCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+
+}
+/***********************************************************/
+
+/***********************************************************/
\ No newline at end of file
diff --git a/commandfactory.hpp b/commandfactory.hpp
new file mode 100644 (file)
index 0000000..9bbba57
--- /dev/null
@@ -0,0 +1,25 @@
+#ifndef COMMANDFACTORY_HPP
+#define COMMANDFACTORY_HPP
+
+/*
+ *  commandfactory.h
+ *  
+ *
+ *  Created by Pat Schloss on 10/25/08.
+ *  Copyright 2008 Patrick D. Schloss. All rights reserved.
+ *
+ */
+
+class Command;
+
+class CommandFactory {
+public:
+       CommandFactory();
+       ~CommandFactory();
+       Command* getCommand(string);
+private:
+       Command* command;
+
+};
+
+#endif
diff --git a/commandoptionparser.cpp b/commandoptionparser.cpp
new file mode 100644 (file)
index 0000000..893d0d9
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ *  commandoptionparser.cpp
+ *  
+ *
+ *  Created by Pat Schloss on 10/23/08.
+ *  Copyright 2008 Patrick D. Schloss. All rights reserved.
+ *
+ */
+
+#include <string>
+
+using namespace std;
+
+#include "globaldata.hpp"
+#include "commandoptionparser.hpp"
+#include <exception>
+#include <iostream>
+
+//**********************************************************************************************************************
+//This Function parses through the command line and pulls out the command then sends the options to  the parseGlobalData
+CommandOptionParser::CommandOptionParser(string input){
+       try {
+               int openParen = input.find_first_of('(');
+               int closeParen = input.find_last_of(')');
+               string optionString = "";
+               commandString = "";
+       
+               if(openParen != -1 && closeParen != -1){                        
+                       commandString = input.substr(0, openParen);   //commandString contains everything before "("
+                       optionString = input.substr(openParen+1, closeParen-openParen-1); //optionString contains everything between "(" and ")".
+               }
+                                       
+               GlobalData* globaldata = GlobalData::getInstance();
+               globaldata->parseGlobalData(commandString, optionString);                       //parser to separate and check options
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the CommandOptionParser class Function CommandOptionParser. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the CommandOptionParser class function CommandOptionParser. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+
+}
+
+//**********************************************************************************************************************
+
+string CommandOptionParser::getCommandString() {       return commandString;   }
+
+//**********************************************************************************************************************
diff --git a/commandoptionparser.hpp b/commandoptionparser.hpp
new file mode 100644 (file)
index 0000000..6a61628
--- /dev/null
@@ -0,0 +1,17 @@
+#ifndef COMMANDOPTIONPARSER_HPP
+#define COMMANDOPTIONPARSER_HPP
+
+//**********************************************************************************************************************
+
+class CommandOptionParser {
+public:
+       CommandOptionParser(string);
+       string getCommandString();
+       
+private:
+       string commandString;
+};
+
+//**********************************************************************************************************************
+
+#endif
diff --git a/completelinkage.cpp b/completelinkage.cpp
new file mode 100644 (file)
index 0000000..69b68a0
--- /dev/null
@@ -0,0 +1,71 @@
+
+#include "cluster.hpp"
+#include <exception>
+
+/***********************************************************************/
+
+CompleteLinkage::CompleteLinkage(RAbundVector* rav, ListVector* lv, SparseMatrix* dm) :
+Cluster(rav, lv, dm)
+{}
+
+/***********************************************************************/
+//This function clusters based on the furthest neighbor method.
+void CompleteLinkage::update(){
+       try {
+               getRowColCells();       
+       
+               vector<int> found(nColCells, 0);
+       
+               for(int i=1;i<nRowCells;i++){
+               
+                       int search;
+               
+                       if(rowCells[i]->row == smallRow){
+                               search = rowCells[i]->column;
+                       }
+                       else{
+                               search = rowCells[i]->row;
+                       }
+               
+                       for(int j=1;j<nColCells;j++){
+                       
+                               if(colCells[j]->row == search || colCells[j]->column == search){
+                               
+                                       if(colCells[j]->dist < rowCells[i]->dist){
+                                               colCells[j]->dist = rowCells[i]->dist;
+                                       
+                                               if(colCells[j]->vectorMap != NULL){
+                                                       *(colCells[j]->vectorMap) = NULL;
+                                                       colCells[j]->vectorMap = NULL;
+                                               }
+                                       
+                                       }
+                               
+                                       found[j] = 1;
+                                       break;
+                               }
+                       }
+                       dMatrix->rmCell(rowCells[i]);
+               
+               }       
+               clusterBins();
+               clusterNames();
+       
+               for(int i=0;i<nColCells;i++){
+                       if(found[i] == 0){
+                               dMatrix->rmCell(colCells[i]);
+                       }
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the CompleteLinkage class Function update. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the CompleteLinkage class function update. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+
+}
+
+/***********************************************************************/
diff --git a/database.cpp b/database.cpp
new file mode 100644 (file)
index 0000000..153876f
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ *  database.cpp
+ *  
+ *
+ *  Created by Pat Schloss on 12/16/08.
+ *  Copyright 2008 Patrick D. Schloss. All rights reserved.
+ *
+ */
+
+using namespace std;
+
+#include <string>
+#include <vector>
+#include <fstream>
+#include <iostream>
+
+#include "sequence.hpp"
+#include "database.hpp"
+
+/**************************************************************************************************/
+
+Database::Database(string fastaFileName){
+       
+       ifstream fastaFile(fastaFileName.c_str());
+       if(!fastaFile) {
+               cerr << "Error: Could not open " << fastaFileName << endl;
+               exit(1);
+       }
+       cout << endl << "Reading in the " << fastaFileName << " template sequences...\t";       cout.flush();
+
+       numSeqs=count(istreambuf_iterator<char>(fastaFile),istreambuf_iterator<char>(), '>');
+       fastaFile.seekg(0);
+       
+       templateSequences.resize(numSeqs);
+       
+       string seqName, sequence;
+       for(int i=0;i<numSeqs;i++){
+               templateSequences[i] = new Sequence();
+               
+               fastaFile >> seqName;
+               templateSequences[i]->setName(seqName);
+               
+               char letter;
+               string aligned;
+               
+               while(fastaFile && (letter=fastaFile.get()) != '>'){
+                       if(isprint(letter)){
+                               letter = toupper(letter);
+                               aligned += letter;
+                       }
+               }
+               templateSequences[i]->setAligned(aligned);
+               templateSequences[i]->setUnaligned(aligned);
+               fastaFile.putback(letter);
+       }
+       
+       fastaFile.close();
+       cout << "DONE." << endl;        cout.flush();
+
+}
+
+/**************************************************************************************************/
diff --git a/database.hpp b/database.hpp
new file mode 100644 (file)
index 0000000..e497fa4
--- /dev/null
@@ -0,0 +1,23 @@
+#ifndef DATABASE_HPP
+#define DATABASE_HPP
+
+/*
+ *  database.hpp
+ *  
+ *
+ *  Created by Pat Schloss on 12/16/08.
+ *  Copyright 2008 Patrick D. Schloss. All rights reserved.
+ *
+ */
+
+class Database {
+public:
+       Database(string);
+       virtual Sequence* findClosestSequence(Sequence*) = 0;
+       
+protected:
+       int numSeqs;
+       vector<Sequence*> templateSequences;    
+};
+
+#endif
diff --git a/datavector.hpp b/datavector.hpp
new file mode 100644 (file)
index 0000000..4ddb1aa
--- /dev/null
@@ -0,0 +1,48 @@
+#ifndef datavector_h
+#define datavector_h
+
+using namespace std;
+
+#include <iostream>
+#include <string>
+#include <vector>
+#include <map>
+
+class RAbundVector;
+class SAbundVector;
+class OrderVector;
+
+class DataVector {
+       
+public:
+       DataVector(){};// : 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(){};
+       
+//     virtual int getNumBins()        {       return numBins;         }
+//     virtual int getNumSeqs()        {       return numSeqs;         }
+//     virtual int getMaxRank()        {       return maxRank;         }
+       
+       virtual void resize(int) = 0;
+       virtual int size()      = 0;
+       virtual void print(ostream&) = 0;
+       
+       void setLabel(string l)         {       label = l;                      }
+       string getLabel()                       {       return label;           }
+
+       //virtual RAbundVector getRAbundVector() = 0;
+       virtual SAbundVector getSAbundVector() = 0;
+       virtual OrderVector getOrderVector(map<string,int>* hold = NULL) = 0;
+       
+protected:
+       string label;
+//     int maxRank;
+//     int numBins;
+//     int numSeqs;    
+};
+
+/***********************************************************************/
+
+#endif
diff --git a/display.h b/display.h
new file mode 100644 (file)
index 0000000..e526e56
--- /dev/null
+++ b/display.h
@@ -0,0 +1,29 @@
+#ifndef DISPLAY_H
+#define DISPLAY_H
+
+#include "sabundvector.hpp"
+#include "sharedsabundvector.h"
+#include "calculator.h"
+#include "fileoutput.h"
+#include <vector>
+
+using namespace std;
+
+/***********************************************************************/
+
+class Display {
+       
+public:
+       virtual void update(SAbundVector* rank) = 0;
+       virtual void update(SharedRAbundVector* shared1, SharedRAbundVector* shared2, int numSeqs, int numGroupComb) = 0;
+       virtual void init(string) = 0;
+       virtual void reset() = 0;
+       virtual void close() = 0;
+       
+private:
+
+};
+
+/***********************************************************************/
+
+#endif
\ No newline at end of file
diff --git a/engine.cpp b/engine.cpp
new file mode 100644 (file)
index 0000000..e1bc23d
--- /dev/null
@@ -0,0 +1,187 @@
+/*
+ *  engine.cpp
+ *  
+ *
+ *  Created by Pat Schloss on 8/15/08.
+ *  Copyright 2008 Patrick D. Schloss. All rights reserved.
+ *
+ *  There's a TON of duplicated code between InteractEngine and BatchEngine
+ *  I couldn't figure out how to transition between ifstream (batch) and cin (interact)
+ *  Fix later, don't have time now.
+ *
+ */
+using namespace std;
+
+#include <string>
+#include <iostream>
+#include <iomanip>
+#include <fstream>
+#include <vector>
+#include <set>
+#include <exception>
+
+#include "utilities.hpp"
+#include "globaldata.hpp"
+#include "commandoptionparser.hpp"
+#include "command.hpp"
+#include "commandfactory.hpp"
+#include "errorchecking.h"
+#include "engine.hpp"
+
+/***********************************************************************/
+
+InteractEngine::InteractEngine(){
+
+       globaldata = GlobalData::getInstance();
+
+       system("clear");
+//     char buffer = ' ';
+//     ifstream header("introtext.txt");
+//     while(!header.eof()){
+//             cout << buffer;
+//             buffer = header.get();
+//     }
+}
+
+/***********************************************************************/
+
+InteractEngine::~InteractEngine(){
+       }
+
+/***********************************************************************/
+//This function allows the user to input commands one line at a time until they quit.
+//If the command is garbage it does nothing.
+bool InteractEngine::getInput(){
+       try {
+               string input = "";
+               string commandName = "";
+               int quitCommandCalled = 0;
+               bool errorFree;
+               ErrorCheck* errorCheckor = new ErrorCheck();
+               
+               cout << "MOTHUR v2.0 (Martha)" << endl;
+               cout << "Last updated: 1/07/2009" << endl << endl;
+               cout << "(Distance-based OTU and Richness)" << endl << endl;
+               cout << "by" << endl;
+               cout << "Patrick D. Schloss" << endl << endl;
+               cout << "Department of Microbiology" << endl;
+               cout << "The University of Massachusetts" << endl;
+               cout << "pschloss@micro.umass.edu" << endl;
+               cout << "http://schloss.micro.umass.edu" << endl << endl << endl;
+               cout << "Distributed under the GNU General Public License" << endl << endl;
+               cout << "Type 'help()' for information on the commands that are available" << endl << endl;
+               cout << "Type 'quit()' to exit program" << endl;
+
+               while(quitCommandCalled != 1){
+
+                       cout << endl << "mothur > ";
+                       getline(cin, input);
+                       errorFree = errorCheckor->checkInput(input);
+                       if (errorFree == true) {
+                               CommandOptionParser parser(input);
+                               commandName = parser.getCommandString();
+                       
+                               //executes valid command
+                               CommandFactory cFactory;
+                               Command* command = cFactory.getCommand(commandName);
+                               quitCommandCalled = command->execute();
+               
+                       }else {
+                                       cout << "Your input contains errors. Please try again." << endl;
+                       }
+               }       
+               return 1;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the InteractEngine class Function getInput. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the InteractEngine class function getInput. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+
+}
+
+/***********************************************************************/
+//This function opens the batchfile to be used by BatchEngine::getInput.
+BatchEngine::BatchEngine(string batchFileName){
+       try {
+               globaldata = GlobalData::getInstance();
+               openedBatch = openInputFile(batchFileName, inputBatchFile);
+
+               system("clear");
+       
+       //      char buffer = ' ';
+       //      ifstream header("introtext.txt");
+       //      while(!header.eof()){
+       //              cout << buffer;
+       //              buffer = header.get();
+       //      }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the BatchEngine class Function BatchEngine. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the BatchEngine class function BatchEngine. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+/***********************************************************************/
+
+BatchEngine::~BatchEngine(){
+       }
+
+/***********************************************************************/
+//This Function allows the user to run a batchfile containing several commands on Dotur
+bool BatchEngine::getInput(){
+       try {
+               string input = "";
+               string commandName = "";
+               bool errorFree;
+               ErrorCheck* errorCheckor = new ErrorCheck();
+
+               CommandFactory cFactory;
+               int quitCommandCalled = 0;
+       
+               while(quitCommandCalled == 0){
+               
+                       getline(inputBatchFile, input);
+                       cout << endl << "dotur > " << input << endl;
+                       errorFree = errorCheckor->checkInput(input);
+                       if (errorFree == true) {
+                               CommandOptionParser parser(input);
+                               commandName = parser.getCommandString();
+                               ifstream filehandle;
+               
+                               if (openedBatch == 0) { //able to open batchfile
+                                       //executes valid command
+                                       CommandFactory cFactory;
+                                       Command* command = cFactory.getCommand(commandName);
+                                       quitCommandCalled = command->execute();
+                               }
+                               else {
+                                       cout << "Invalid." << endl;
+                               }
+                       }
+                       else {
+                               cout << "Unable to open batchfile." << endl;
+                       }
+               }
+               return 1;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the BatchEngine class Function getInput. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the BatchEngine class function getInput. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+
+/***********************************************************************/
+
diff --git a/engine.hpp b/engine.hpp
new file mode 100644 (file)
index 0000000..7990d17
--- /dev/null
@@ -0,0 +1,60 @@
+#ifndef ENGINE_HPP
+#define ENGINE_HPP
+
+/*
+ *  engine.hpp
+ *  
+ *
+ *  Created by Pat Schloss on 8/15/08.
+ *  Copyright 2008 Patrick D. Schloss. All rights reserved.
+ *
+ */
+
+
+#include <vector>
+#include <set>
+#include <string>
+
+using namespace std;
+
+class GlobalData;
+
+class Engine {
+public:
+       virtual ~Engine(){};
+       virtual bool getInput() = 0;
+//     string getCommand()                     {       return command;         }
+       vector<string> getOptions() {   return options;         }
+protected:
+//     string command;
+       vector<string> options;
+};
+
+
+
+class BatchEngine : public Engine {
+public:
+       BatchEngine(string);
+       ~BatchEngine();
+       virtual bool getInput();
+       int openedBatch;
+private:
+       GlobalData* globaldata;
+       ifstream inputBatchFile;
+
+};
+
+
+
+class InteractEngine : public Engine {
+public:
+       InteractEngine();
+       ~InteractEngine();
+       virtual bool getInput();
+private:
+       GlobalData* globaldata;
+};
+
+
+#endif
diff --git a/errorchecking.cpp b/errorchecking.cpp
new file mode 100644 (file)
index 0000000..78b082d
--- /dev/null
@@ -0,0 +1,431 @@
+/*
+ *  errorchecking.cpp
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/2/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "errorchecking.h"
+
+/*******************************************************/
+
+/******************************************************/
+
+ErrorCheck::ErrorCheck() {
+       globaldata = GlobalData::getInstance();
+       validCommand = new ValidCommands();
+       validParameter = new ValidParameters();
+       validCalculator = new ValidCalculators();
+       distfile = globaldata->getDistFile();
+       listfile = globaldata->getListFile();
+       rabundfile = globaldata->getRabundFile();
+       sabundfile = globaldata->getSabundFile();
+       namefile = globaldata->getNameFile();
+       groupfile = globaldata->getGroupFile();
+       orderfile = globaldata->getOrderFile();
+       cutoff = globaldata->getCutOff();
+       format = globaldata->getFormat();
+       method = globaldata->getMethod();
+
+}
+/*******************************************************/
+
+/******************************************************/
+
+ErrorCheck::~ErrorCheck() {}
+
+/*******************************************************/
+
+/******************************************************/
+
+bool ErrorCheck::checkInput(string input) {
+               errorFree = true;
+               clear();
+
+               //get command name and parameters
+               int openParen = input.find_first_of('(');
+               int closeParen = input.find_last_of(')');
+
+               if(openParen != -1 && closeParen != -1){                        
+                       commandName = input.substr(0, openParen);   //commandName contains everything before "("
+                       optionText = input.substr(openParen+1, closeParen-openParen-1); //optionString contains everything between "(" and ")".
+               }else if (openParen == -1) { //there is no parenthesis
+                       cout << input << " is not a valid command. You are missing the ()." << endl;
+                       return false;
+               }
+               
+               //is it a valid command
+               if (validCommand->isValidCommand(commandName) != true) { return false; }
+               
+               string parameter, value;
+               //reads in parameters and values
+               if((optionText != "") && (commandName != "help")){
+                       while((optionText.find_first_of(',') != -1) && (errorFree)) {  //while there are parameters
+                               globaldata->splitAtComma(value, optionText);
+                               globaldata->splitAtEquals(parameter, value);
+                               
+                               //is it a valid parameter
+                               if (validParameter->isValidParameter(parameter) != true) { return false; }
+                               
+                               if (parameter == "distfile" )           { distfile = value; }
+                               if (parameter == "listfile" )           { listfile = value; }
+                               if (parameter == "rabundfile" )         { rabundfile = value; }
+                               if (parameter == "sabundfile" )         { sabundfile = value; }
+                               if (parameter == "namefile" )           { namefile = value; }
+                               if (parameter == "orderfile" )          { orderfile = value; }
+                               if (parameter == "groupfile" )          { groupfile = value; }
+                               if (parameter == "cutoff" )                     { cutoff = value; }
+                               if (parameter == "precision" )          { precision = value; }
+                               if (parameter == "iters" )                      { iters = value; }
+                               if (parameter == "jumble" )                     { jumble = value; }
+                               if (parameter == "freq" )                       { freq = value; }
+                               if (parameter == "method" )                     { method = value; }
+                               if (parameter == "fileroot" )           { fileroot = value; }
+                               if (parameter == "line" )                       { line = value; }
+                               if (parameter == "label" )                      { label = value; }
+
+                               if (parameter == "single") {//stores estimators in a vector
+                                       singleEsimators.clear(); //clears out old values
+                                       globaldata->splitAtDash(value, singleEsimators);
+                                       for (int i = 0; i < singleEsimators.size(); i++) { //loop through estimators
+                                               //is it a valid calculator
+                                               if (validCalculator->isValidCalculator(parameter, singleEsimators[i]) != true) { return false; }
+                                       }
+                               }
+                               if (parameter == "rarefaction") {//stores estimators in a vector
+                                       rareEstimators.clear(); //clears out old values
+                                       globaldata->splitAtDash(value, rareEstimators);
+                                       for (int i = 0; i < rareEstimators.size(); i++) { //loop through estimators
+                                               //is it a valid calculator
+                                               if (validCalculator->isValidCalculator(parameter, rareEstimators[i]) != true) { return false; }
+                                       }
+                               }
+                               if (parameter == "shared") {//stores estimators in a vector
+                                       sharedEstimators.clear(); //clears out old values
+                                       globaldata->splitAtDash(value, sharedEstimators);
+                                       for (int i = 0; i < sharedEstimators.size(); i++) { //loop through estimators
+                                               //is it a valid calculator
+                                               if (validCalculator->isValidCalculator(parameter, sharedEstimators[i]) != true) { return false; }
+                                       }
+                               }
+                               if (parameter == "summary") { //stores summaries to be used in a vector
+                                       summaryEstimators.clear(); //clears out old values
+                                       globaldata->splitAtDash(value, summaryEstimators);
+                                       for (int i = 0; i < summaryEstimators.size(); i++) { //loop through estimators
+                                               //is it a valid calculator
+                                               if (validCalculator->isValidCalculator(parameter, summaryEstimators[i]) != true) { return false; }
+                                       }
+                               }
+                               if (parameter == "sharedrarefaction") { //stores summaries to be used in a vector
+                                       sharedRareEstimators.clear(); //clears out old values
+                                       globaldata->splitAtDash(value, sharedRareEstimators);
+                                       for (int i = 0; i < sharedRareEstimators.size(); i++) { //loop through estimators
+                                               //is it a valid calculator
+                                               if (validCalculator->isValidCalculator(parameter, sharedRareEstimators[i]) != true) { return false; }
+                                       }
+                               }
+                       }
+                       
+                       //gets the last parameter and value
+                       if (errorFree)  { //gets the last parameter and value
+                               value = optionText;
+                               globaldata->splitAtEquals(parameter, value);
+                               //is it a valid parameter
+                               if (validParameter->isValidParameter(parameter) != true) { return false; }
+                               
+                               if (parameter == "distfile" )           { distfile = value; }
+                               if (parameter == "listfile" )           { listfile = value; }
+                               if (parameter == "rabundfile" )         { rabundfile = value; }
+                               if (parameter == "sabundfile" )         { sabundfile = value; }
+                               if (parameter == "namefile" )           { namefile = value; }
+                               if (parameter == "orderfile" )          { orderfile = value; }
+                               if (parameter == "groupfile" )          { groupfile = value; }
+                               if (parameter == "cutoff" )                     { cutoff = value; }
+                               if (parameter == "precision" )          { precision = value; }
+                               if (parameter == "iters" )                      { iters = value; }
+                               if (parameter == "jumble" )                     { jumble = value; }
+                               if (parameter == "freq" )                       { freq = value; }
+                               if (parameter == "method" )                     { method = value; }
+                               if (parameter == "fileroot" )           { fileroot = value; }
+                               if (parameter == "line" )                       { line = value; }
+                               if (parameter == "label" )                      { label = value; }
+
+                               if (parameter == "single") {//stores estimators in a vector
+                                       singleEsimators.clear(); //clears out old values
+                                       globaldata->splitAtDash(value, singleEsimators);
+                                       for (int i = 0; i < singleEsimators.size(); i++) { //loop through estimators
+                                               //is it a valid calculator
+                                               if (validCalculator->isValidCalculator(parameter, singleEsimators[i]) != true) { return false; }
+                                       }
+                               }
+                               if (parameter == "rarefaction") {//stores estimators in a vector
+                                       rareEstimators.clear(); //clears out old values
+                                       globaldata->splitAtDash(value, rareEstimators);
+                                       for (int i = 0; i < rareEstimators.size(); i++) { //loop through estimators
+                                               //is it a valid calculator
+                                               if (validCalculator->isValidCalculator(parameter, rareEstimators[i]) != true) { return false; }
+                                       }
+                               }
+                               if (parameter == "shared") {//stores estimators in a vector
+                                       sharedEstimators.clear(); //clears out old values
+                                       globaldata->splitAtDash(value, sharedEstimators);
+                                       for (int i = 0; i < sharedEstimators.size(); i++) { //loop through estimators
+                                               //is it a valid calculator
+                                               if (validCalculator->isValidCalculator(parameter, sharedEstimators[i]) != true) { return false; }
+                                       }
+                               }
+                               if (parameter == "summary") { //stores summaries to be used in a vector
+                                       summaryEstimators.clear(); //clears out old values
+                                       globaldata->splitAtDash(value, summaryEstimators);
+                                       for (int i = 0; i < summaryEstimators.size(); i++) { //loop through estimators
+                                               //is it a valid calculator
+                                               if (validCalculator->isValidCalculator(parameter, summaryEstimators[i]) != true) { return false; }
+                                       }
+                               }
+                               if (parameter == "sharedrarefaction") { //stores summaries to be used in a vector
+                                       sharedRareEstimators.clear(); //clears out old values
+                                       globaldata->splitAtDash(value, sharedRareEstimators);
+                                       for (int i = 0; i < sharedRareEstimators.size(); i++) { //loop through estimators
+                                               //is it a valid calculator
+                                               if (validCalculator->isValidCalculator(parameter, sharedRareEstimators[i]) != true) { return false; }
+                                       }
+                               }
+
+                       }
+               }
+               
+               //make sure the user does not use both the line and label parameters
+               if ((line != "") && (label != "")) { cout << "You may use either the line or label parameters, but not both." << endl; return false; }
+               
+               //validate files
+               if (commandName == "parselist") {
+                       validateParseFiles(commandName);
+               }
+               if ((commandName == "read.phylip") || (commandName == "read.column")) { 
+                       validateReadFiles();
+                       validateReadDist();
+               }else if ((commandName == "read.list") || (commandName == "read.rabund") || (commandName == "read.sabund")){ 
+                       validateReadFiles();
+                       validateReadPhil(commandName);  
+               }else if (commandName == "read.shared") { 
+                       validateReadFiles();
+                       validateParseFiles(commandName); //checks the listfile and groupfile parameters
+               }
+               
+               //are you trying to cluster before you have read something                      
+               if ((commandName == "cluster") && (globaldata->getSparseMatrix() == NULL) ||
+                       (commandName == "cluster") && (globaldata->getListVector() == NULL)) {
+                               cout << "Before you use the cluster command, you first need to read in a distance matrix." << endl; 
+                               errorFree = false;
+               } 
+               
+               //check for valid method
+               if (commandName == "cluster") {
+                       if ((method == "furthest") || (method == "nearest") || (method == "average")) { }
+                       else {cout << "Not a valid clustering method.  Valid clustering algorithms are furthest, nearest or average." << endl; return false; }
+               }
+               
+               if ((commandName == "collect.single") || (commandName == "rarefaction.single") || (commandName == "summary.single") ){ 
+                       if ((globaldata->getListFile() == "") && (globaldata->getRabundFile() == "") && (globaldata->getSabundFile() == "")) { cout << "You must read a listfile, sabundfile or rabundfile before you can use the collect.single, rarefaction.single or summary.single commands." << endl; return false; }
+               }
+               
+               if ((commandName == "collect.shared") || (commandName == "rarefaction.shared") || (commandName == "summary.shared") || (commandName == "shared") ){ 
+                       if (globaldata->getListFile() == "") { cout << "You must read a listfile and a groupfile before you can use the collect.shared, rarefaction.shared, summary.shared or shared commands." << endl; return false; }
+                       else if (globaldata->getGroupFile() == "") { cout << "You must read a listfile and a groupfile before you can use the collect.shared, rarefaction.shared, summary.shared or shared commands." << endl; return false; }
+               }
+               
+               return errorFree;
+}
+
+/*******************************************************/
+
+/******************************************************/
+//This function checks to make sure the user entered a file to 
+// read and that the file exists and can be opened.
+void ErrorCheck::validateReadFiles() {
+       try {
+               //Validating files for read
+               ifstream filehandle;
+               int ableToOpen;
+       
+               //are we reading a distfile
+               if (distfile != "") {
+                       ableToOpen = openInputFile(distfile, filehandle);
+                       filehandle.close();
+                       //unable to open
+                       if (ableToOpen == 1) { errorFree = false; }
+                       else { globaldata->inputFileName = distfile; }
+               //are we reading a listfile
+               }else if (listfile!= "") {
+                       ableToOpen = openInputFile(listfile, filehandle);
+                       filehandle.close();
+                       //unable to open
+                       if (ableToOpen == 1) {  errorFree = false; }
+                       else { globaldata->inputFileName = listfile; }
+               //are we reading a rabundfile
+               }else if (rabundfile != "") {
+                       ableToOpen = openInputFile(rabundfile, filehandle);
+                       filehandle.close();
+                       //unable to open
+                       if (ableToOpen == 1) {  errorFree = false; }
+                       else { globaldata->inputFileName = rabundfile; }
+               //are we reading a sabundfile
+               }else if (sabundfile != "") {
+                       ableToOpen = openInputFile(sabundfile, filehandle);
+                       filehandle.close();
+                       //unable to open
+                       if (ableToOpen == 1) {  errorFree = false; }
+                       else { globaldata->inputFileName = sabundfile; }
+               }else{ //no file given
+                       errorFree = false;
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ErrorCheck class Function validateReadFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ErrorCheck class function validateReadFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       
+}
+/*******************************************************/
+
+/******************************************************/
+//This function checks to make sure the user entered appropriate
+// format parameters on a distfile read
+void ErrorCheck::validateReadDist() {
+       try {
+               ifstream filehandle;
+               int ableToOpen;
+               
+               if (distfile == "") { cout << "When executing a read.phylip or read.column you must enter a distfile." << endl; errorFree = false; }
+               
+               if (commandName == "read.column") {
+                       if (namefile == "") {
+                               cout << "You need to provide a namefile name if you are going to use the column format." << endl;
+                               errorFree = false; 
+                       }else {
+                               ableToOpen = openInputFile(namefile, filehandle);
+                               filehandle.close();
+                               //unable to open
+                               if (ableToOpen == 1) { errorFree = false; }
+                       }
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ErrorCheck class Function validateReadDist. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ErrorCheck class function validateReadDist. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+/*******************************************************/
+
+/******************************************************/
+//This function checks to make sure the user entered appropriate
+// format parameters on a parselistcommand
+void ErrorCheck::validateParseFiles(string command) {
+       try {
+               ifstream filehandle;
+               int ableToOpen;
+               
+               //checks for valid files
+               if (command == "read.shared" ) {
+                       if (listfile == "") { cout << "When executing a read.shared you must enter a listfile and a groupfile." << endl; errorFree = false; }
+                       else if (groupfile == "") { cout << "When executing a read.shared you must enter a listfile and a groupfile." << endl; errorFree = false; }
+               }else if (command == "parselist" ) {
+                       if (listfile == "") { cout << "When executing a parselist you must enter a listfile and a groupfile." << endl; errorFree = false; }
+                       else if (groupfile == "") { cout << "When executing a parselist you must enter a listfile and a groupfile." << endl; errorFree = false; }
+               }
+               
+               //checks parameters on the read command
+               if (listfile != "") {
+                       ableToOpen = openInputFile(listfile, filehandle);
+                       filehandle.close();
+                       if (ableToOpen == 1) { //unable to open
+                               errorFree = false;
+                       }
+                       if (groupfile != "") {
+                               ableToOpen = openInputFile(groupfile, filehandle);
+                               filehandle.close();
+                               if (ableToOpen == 1) { //unable to open
+                                       errorFree = false;;
+                               }
+                       }
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ErrorCheck class Function validateReadPhil. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ErrorCheck class function validateReadPhil. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+/*******************************************************/
+
+/******************************************************/
+//This function checks to make sure the user entered appropriate
+// format parameters on a distfile read
+void ErrorCheck::validateReadPhil(string command) {
+       try {
+               ifstream filehandle;
+               int ableToOpen;
+               
+               //checks for valid files
+               if (command == "read.list" ) {
+                       if (listfile == "") { cout << "When executing a read.list you must enter a listfile." << endl; errorFree = false; }
+               }else if (command == "read.sabund" ) {
+                       if (sabundfile == "") { cout << "When executing a read.sabund you must enter a sabundfile." << endl; errorFree = false; }
+               }else if (command == "read.rabund" ) {
+                       if (rabundfile == "") { cout << "When executing a read.rabund you must enter a rabundfile." << endl; errorFree = false; }
+               }
+               
+               //checks parameters on the read command
+               if (orderfile != "") {
+                       ableToOpen = openInputFile(orderfile, filehandle);
+                       filehandle.close();
+                       if (ableToOpen == 1) { //unable to open
+                               errorFree = false;
+                       }
+               }       
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ErrorCheck class Function validateReadPhil. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ErrorCheck class function validateReadPhil. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+/*******************************************************/
+
+/******************************************************/
+
+void ErrorCheck::clear() {
+       //option definitions should go here...
+       distfile                =       "";
+       listfile                =       "";
+       rabundfile              =       "";
+       sabundfile              =       "";
+       namefile                =       "";
+       groupfile               =       ""; 
+       orderfile               =       "";
+       line                    =       "";
+       label                   =       "";
+       method                  =   "furthest";
+}
+/*******************************************************/
+
+/******************************************************/
+
diff --git a/errorchecking.h b/errorchecking.h
new file mode 100644 (file)
index 0000000..55795b2
--- /dev/null
@@ -0,0 +1,46 @@
+#ifndef ERRORCHECKING_H
+#define ERRORCHECKING_H
+/*
+ *  errorchecking.h
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/2/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include <Carbon/Carbon.h>
+#include <iostream>
+#include <map>
+#include "globaldata.hpp"
+#include "validcommands.h"
+#include "validparameter.h"
+#include "validcalculator.h"
+
+class ErrorCheck {
+       public:
+               ErrorCheck();
+               ~ErrorCheck();
+               bool checkInput(string);
+       
+       private: 
+               GlobalData* globaldata;
+               ValidCommands* validCommand;
+               ValidParameters* validParameter;
+               ValidCalculators* validCalculator;
+               void splitAtDash(string&, vector<string>&);
+               void splitAtDash(string&, set<int>&);
+               void splitAtDash(string&, set<string>&);
+               void validateReadFiles();
+               void validateReadDist();
+               void validateReadPhil(string);
+               void validateParseFiles(string);
+               void clear();
+               string distfile, listfile, rabundfile, sabundfile, namefile, groupfile, orderfile, cutoff, format; 
+               string precision, method, fileroot, label, line, iters, jumble, freq, single, rarefaction, shared, summary;
+               string commandName, optionText;
+               bool errorFree;
+               vector<string> singleEsimators, sharedEstimators, rareEstimators, summaryEstimators, sharedRareEstimators;
+               
+};
+#endif
\ No newline at end of file
diff --git a/fastamap.cpp b/fastamap.cpp
new file mode 100644 (file)
index 0000000..4f4bf33
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ *  fastamap.cpp
+ *  mothur
+ *
+ *  Created by Sarah Westcott on 1/16/09.
+ *  Copyright 2009 Schloss Lab UMASS AMherst. All rights reserved.
+ *
+ */
+
+#include "fastamap.h"
+
+/*******************************************************************************/
+ FastaMap::FastaMap(ifstream& in) {
+       //int numberOfSequences = 0;
+       
+       string name, sequence, line;
+       sequence = "";
+       
+       getline(in, line);
+       name = line.substr(1, line.length());  //rips off '>'
+       
+       //read through file
+       while (getline(in, line)) {
+               if (isalnum(line.at(0))){  //if it's a sequence line
+                       sequence += line;
+               }
+               else{
+                       //input sequence info into map
+                       it = data.find(sequence);
+                       if (it == data.end()) {         //it's unique.
+                               data[sequence].groupname = name;  //group name will be the name of the first duplicate sequence found.
+                               data[sequence].groupnumber = 1;
+                               data[sequence].names = name;
+                       }else { // its a duplicate.
+                               data[sequence].names += "," + name;
+                               data[sequence].groupnumber++;   
+                       }
+                       name = (line.substr(1, (line.npos))); //The line you just read is a new name so rip off '>'
+               }
+       }
+       
+       //store last sequence and name info.
+       it = data.find(sequence);
+       if (it == data.end()) {         //it's unique.
+               data[sequence].groupname = name;  //group name will be the name of the first duplicate sequence found.
+               data[sequence].groupnumber = 1;
+               data[sequence].names = name;
+       }else { // its a duplicate.
+               data[sequence].names += "," + name;
+               data[sequence].groupnumber++;   
+       }       
+}
+/*******************************************************************************/
+string FastaMap::getGroupName(string seq) {  //pass a sequence name get its group
+       return data[seq].groupname;
+}
+/*******************************************************************************/
+int FastaMap::getGroupNumber(string seq) {  //pass a sequence name get number of sequence in its group
+       return data[seq].groupnumber;
+}
+/*******************************************************************************/
+string FastaMap::getNames(string seq) {        //pass a sequence get the string of names in the group separated by ','s.
+       return data[seq].names;
+}
+/*******************************************************************************/
+void FastaMap::push_back(string seq, string Name) {//sequencename, name
+       data[seq].groupname = Name;
+       data[seq].groupnumber = 1;
+       data[seq].names = Name;
+}
+/*******************************************************************************/
+void FastaMap::clear() { //clears out data
+       data.clear();
+}
+/*******************************************************************************/
+int FastaMap::size(){ //returns datas size which is the number of unique sequences
+       return data.size();
+}
+/*******************************************************************************/
+void FastaMap::print(ostream&){ //prints data
+
+}
+/*******************************************************************************/
diff --git a/fastamap.h b/fastamap.h
new file mode 100644 (file)
index 0000000..bd262c4
--- /dev/null
@@ -0,0 +1,48 @@
+#ifndef FASTAMAP_H
+#define FASTAMAP_H
+
+/*
+ *  fastamap.h
+ *  mothur
+ *
+ *  Created by Sarah Westcott on 1/16/09.
+ *  Copyright 2009 Schloss Lab UMASS AMherst. All rights reserved.
+ *
+ */
+using namespace std;
+#include <iostream>
+#include <fstream>
+#include <string>
+#include <map>
+#include "utilities.hpp"
+
+
+class FastaMap  {
+
+public:
+       FastaMap() {};
+       FastaMap(ifstream&);
+       ~FastaMap() {};
+       
+       string getGroupName(string);  //pass a sequence name get its group
+       int getGroupNumber(string);  //pass a sequence name get number of sequence in its group
+       string getNames(string);        //pass a sequence get the string of names in the group separated by ','s.
+       void push_back(string, string); //sequencename, groupname
+       void clear();
+       int size();                                     //returns number of unique sequences
+       void print(ostream&);
+
+private:
+       struct group {
+               string groupname;                                       //the group name for identical sequences, will be set to the first sequence found.
+               int groupnumber;                                        //the number of sequences in that group.
+               string names;                                           //the names of the sequence separated by ','.
+       };
+
+       map<string, group>  data;  //sequence, group
+       map<string, group>::iterator it;        
+};
+
+#endif
\ No newline at end of file
diff --git a/fileoutput.cpp b/fileoutput.cpp
new file mode 100644 (file)
index 0000000..c8df770
--- /dev/null
@@ -0,0 +1,382 @@
+/*
+ *  fileoutput.cpp
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 11/18/08.
+ *  Copyright 2008 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "fileoutput.h"
+
+/***********************************************************************/
+
+ThreeColumnFile::~ThreeColumnFile(){
+       
+       inFile.close();
+       outFile.close();
+       remove(outName.c_str());
+};
+
+/***********************************************************************/
+
+void ThreeColumnFile::initFile(string label){
+       try {
+               if(counter != 0){
+                       openOutputFile(outName, outFile);
+                       openInputFile(inName, inFile);
+
+                       string inputBuffer;
+                       getline(inFile, inputBuffer);
+               
+                       outFile <<  inputBuffer << '\t' << label << "\tlci\thci" << endl;
+               }
+               else{
+                       openOutputFile(outName, outFile);
+                       outFile << "numsampled\t" << label << "\tlci\thci" << endl;
+               }
+
+               outFile.setf(ios::fixed, ios::floatfield);
+               outFile.setf(ios::showpoint);
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ThreeColumnFile class Function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ThreeColumnFile class function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+/***********************************************************************/
+
+void ThreeColumnFile::output(int nSeqs, vector<double> data){
+       try {
+               if(counter != 0){               
+                       string inputBuffer;
+                       getline(inFile, inputBuffer);
+               
+                       outFile <<  inputBuffer << setprecision(4) << '\t' << data[0] << '\t' << data[1] << '\t' << data[2] << endl;
+               }
+               else{
+                       outFile << nSeqs << setprecision(4) << '\t' << data[0] << '\t' << data[1] << '\t' << data[2] << endl;
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ThreeColumnFile class Function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ThreeColumnFile class function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+};
+
+/***********************************************************************/
+
+void ThreeColumnFile::resetFile(){
+       try {
+               if(counter != 0){
+                       outFile.close();
+                       inFile.close();
+               }
+               else{
+                       outFile.close();
+               }
+               counter = 1;
+               remove(inName.c_str());
+               rename(outName.c_str(), inName.c_str());
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ThreeColumnFile class Function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ThreeColumnFile class function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+/***********************************************************************/
+/***********************************************************************/
+
+SharedThreeColumnFile::~SharedThreeColumnFile(){
+       
+       inFile.close();
+       outFile.close();
+       remove(outName.c_str());
+};
+
+/***********************************************************************/
+
+void SharedThreeColumnFile::initFile(string label){
+       try {
+               if(counter != 0){
+                       openOutputFile(outName, outFile);
+                       openInputFile(inName, inFile);
+
+                       string inputBuffer;
+                       getline(inFile, inputBuffer);
+               
+                       outFile <<  inputBuffer << '\t' << label << "\tlci\thci" << endl;
+               }
+               else{
+                       openOutputFile(outName, outFile);
+                       outFile << "numsampled\t" << groupLabel << '\t' << label << "\tlci\thci" << endl;
+               }
+
+               outFile.setf(ios::fixed, ios::floatfield);
+               outFile.setf(ios::showpoint);
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SharedThreeColumnFile class Function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SharedThreeColumnFile class function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+/***********************************************************************/
+
+void SharedThreeColumnFile::output(int nSeqs, vector<double> data){
+       try {
+               if(counter != 0){               
+                       string inputBuffer;
+                       getline(inFile, inputBuffer);
+               
+                       outFile <<  inputBuffer << setprecision(4) << '\t' << data[0] << '\t' << data[1] << '\t' << data[2] << endl;
+               }
+               else{
+                       outFile << numGroup << setprecision(4) << '\t' << data[0] << '\t' << data[1] << '\t' << data[2] << endl;
+                       numGroup++;
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SharedThreeColumnFile class Function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SharedThreeColumnFile class function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+};
+
+/***********************************************************************/
+
+void SharedThreeColumnFile::resetFile(){
+       try {
+               if(counter != 0){
+                       outFile.close();
+                       inFile.close();
+               }
+               else{
+                       outFile.close();
+               }
+               counter = 1;
+               remove(inName.c_str());
+               rename(outName.c_str(), inName.c_str());
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SharedThreeColumnFile class Function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SharedThreeColumnFile class function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+/***********************************************************************/
+
+/***********************************************************************/
+
+OneColumnFile::~OneColumnFile(){
+       
+       inFile.close();
+       outFile.close();
+       remove(outName.c_str());        
+};
+
+/***********************************************************************/
+
+void OneColumnFile::initFile(string label){
+       try {
+               if(counter != 0){
+                       openOutputFile(outName, outFile);
+                       openInputFile(inName, inFile);
+               
+                       string inputBuffer;
+                       getline(inFile, inputBuffer);
+               
+                       outFile <<  inputBuffer << '\t' << label << endl;
+               }
+               else{
+                       openOutputFile(outName, outFile);
+                       outFile << "numsequences\t" << label << endl;
+               }
+       
+               outFile.setf(ios::fixed, ios::floatfield);
+               outFile.setf(ios::showpoint);
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the OneColumnFile class Function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the OneColumnFile class function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+/***********************************************************************/
+
+void OneColumnFile::output(int nSeqs, vector<double> data){
+       try {   
+               if(counter != 0){               
+                       string inputBuffer;
+                       getline(inFile, inputBuffer);
+               
+                       outFile <<  inputBuffer << setprecision(4) << '\t'  << data[0] << endl;
+               }
+               else{   
+                       outFile << nSeqs << setprecision(4) << '\t' << data[0] << endl;
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the OneColumnFile class Function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the OneColumnFile class function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+};
+
+/***********************************************************************/
+
+void OneColumnFile::resetFile(){
+       try {
+               if(counter != 0){
+                       outFile.close();
+                       inFile.close();
+               }
+               else{
+                       outFile.close();
+               }       
+               counter = 1;
+               remove(inName.c_str());
+               rename(outName.c_str(), inName.c_str());
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the OneColumnFile class Function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the OneColumnFile class function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+/***********************************************************************/
+/***********************************************************************/
+
+SharedOneColumnFile::~OneColumnFile(){
+       
+       inFile.close();
+       outFile.close();
+       remove(outName.c_str());        
+};
+
+/***********************************************************************/
+
+void SharedOneColumnFile::initFile(string label){
+       try {
+               if(counter != 0){
+                       openOutputFile(outName, outFile);
+                       openInputFile(inName, inFile);
+               
+                       string inputBuffer;
+                       getline(inFile, inputBuffer);
+               
+                       outFile <<  inputBuffer << '\t' << label  << endl;
+
+               }
+               else{
+                       openOutputFile(outName, outFile);
+                       outFile << "sampled\t" << label << endl;
+               
+               }
+       
+               outFile.setf(ios::fixed, ios::floatfield);
+               outFile.setf(ios::showpoint);
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the OneColumnFile class Function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the OneColumnFile class function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+/***********************************************************************/
+
+void SharedOneColumnFile::output(int nSeqs, vector<double> data){
+       try {   
+                       string dataOutput;
+                       float sam;
+                       sam = data[0];
+                       dataOutput = "";
+                       for (int i = 0; i < data.size(); i++) {
+                               dataOutput = dataOutput + "\t" + toString(data[i]);
+                       }
+                       if(counter != 0){               
+                               string inputBuffer;
+                               getline(inFile, inputBuffer);
+
+                               outFile <<  inputBuffer << setprecision(2) << '\t' << dataOutput << endl;
+                       }
+                       else{   
+                               outFile << nSeqs << setprecision(2) << '\t' << dataOutput << endl;
+                       }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the OneColumnFile class Function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the OneColumnFile class function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+};
+
+/***********************************************************************/
+
+void SharedOneColumnFile::resetFile(){
+       try {
+               if(counter != 0){
+                       outFile.close();
+                       inFile.close();
+               }
+               else{
+                       outFile.close();
+               }       
+               counter = 1;
+               remove(inName.c_str());
+               rename(outName.c_str(), inName.c_str());
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the OneColumnFile class Function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the OneColumnFile class function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+/***********************************************************************/
diff --git a/fileoutput.h b/fileoutput.h
new file mode 100644 (file)
index 0000000..6eb5e8d
--- /dev/null
@@ -0,0 +1,110 @@
+#ifndef FILEOUTPUT_H
+#define FILEOUTPUT_H
+
+#include <iostream>
+#include <fstream>
+#include <iomanip>
+#include <vector>
+#include "utilities.hpp"
+#include "globaldata.hpp"
+
+using namespace std;
+
+/***********************************************************************/
+
+class FileOutput {
+       
+public:
+       FileOutput(){};
+       ~FileOutput(){};
+       virtual void output(int, vector<double>) = 0;
+       virtual void initFile(string) = 0;
+       virtual void resetFile() = 0;
+       virtual string getFileName() = 0;
+
+};     
+       
+/***********************************************************************/
+
+class ThreeColumnFile : public FileOutput {
+       
+public:
+       ThreeColumnFile(string n) : FileOutput(), inName(n), counter(0), outName(getPathName(n) + ".temp." + getSimpleName(n)) { };
+       ~ThreeColumnFile();
+       void initFile(string);
+       void output(int, vector<double>);
+       void resetFile();
+       string getFileName()    { return inName;        };
+private:
+       string inName;
+       string outName;
+       ifstream inFile;
+       ofstream outFile;
+       int counter;
+};
+
+
+/***********************************************************************/
+class OneColumnFile : public FileOutput {
+       
+       
+public:
+       OneColumnFile(string n) : inName(n), counter(0), outName(getPathName(n) + ".temp." + getSimpleName(n)) {};
+       ~OneColumnFile();
+       void output(int, vector<double>);
+       void initFile(string);
+       void resetFile();
+       string getFileName()    { return inName;        };
+
+private:
+       string outName;
+       ifstream inFile;
+       string inName;
+       ofstream outFile;
+       int counter;
+};
+
+/***********************************************************************/
+class SharedOneColumnFile : public FileOutput {
+       
+       
+public:
+       SharedOneColumnFile(string n, vector<string> g) : inName(n), counter(0), outName(getPathName(n) + ".temp." + getSimpleName(n)) {};
+       ~SharedOneColumnFile();
+       void output(int, vector<double>);
+       void initFile(string);
+       void resetFile();
+       string getFileName()    { return inName;        };
+
+private:
+       string outName;
+       ifstream inFile;
+       string inName;
+       ofstream outFile;
+       int counter;
+               
+};
+
+/***********************************************************************/
+
+class SharedThreeColumnFile : public FileOutput {
+       
+public:
+       SharedThreeColumnFile(string n, string groups) : FileOutput(), groupLabel(groups), inName(n), counter(0), numGroup(1), outName(getPathName(n) + ".temp." + getSimpleName(n)) {  };
+       ~SharedThreeColumnFile();
+       void initFile(string);
+       void output(int, vector<double>);
+       void resetFile();
+       string getFileName()    { return inName;        };
+private:
+       string inName, groupLabel;
+       string outName;
+       ifstream inFile;
+       ofstream outFile;
+       int counter, numGroup;
+};
+
+
+
+#endif
+
diff --git a/globaldata.cpp b/globaldata.cpp
new file mode 100644 (file)
index 0000000..c28321d
--- /dev/null
@@ -0,0 +1,500 @@
+#include <iostream>
+#include <iomanip>
+#include <string>
+#include <map>
+#include <sstream>
+#include <stdexcept>
+
+using namespace std;
+
+#include "globaldata.hpp"
+#include "sparsematrix.hpp"
+#include "rabundvector.hpp"
+#include "sabundvector.hpp"
+#include "listvector.hpp"
+#include <exception>
+#include <iostream>
+
+/*******************************************************/
+
+/******************************************************/
+GlobalData* GlobalData::getInstance() {
+       if( _uniqueInstance == 0 ) {
+               _uniqueInstance = new GlobalData();
+       }
+       return _uniqueInstance;
+}
+/*******************************************************/
+
+/******************************************************/
+
+ListVector* GlobalData::getListVector()                {       return gListVector;             }
+/*******************************************************/
+
+/******************************************************/
+void GlobalData::setListVector(ListVector* lv){
+       try {
+               if(gListVector != NULL){        delete gListVector;     }
+               gListVector = new ListVector(*lv);
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function setListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the GlobalData class function setListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+/*******************************************************/
+
+/******************************************************/
+
+SparseMatrix* GlobalData::getSparseMatrix()    {       return gSparseMatrix;   }
+/*******************************************************/
+
+/******************************************************/
+void GlobalData::setSparseMatrix(SparseMatrix* sm){
+       try{
+               if(gSparseMatrix != NULL){      delete gSparseMatrix;   }
+               gSparseMatrix = new SparseMatrix(*sm);
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function setSparseMatrix. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the GlobalData class function setSparseMatrix. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+
+}
+/*******************************************************/
+
+/******************************************************/
+//This function parses through the option string of the command to remove its parameters
+void GlobalData::parseGlobalData(string commandString, string optionText){
+       try {
+               allLines = 1;
+               commandName = commandString; //save command name to be used by other classes
+               
+               //clears out data from previous read and sets format
+               setReadFormat(commandName);
+               
+               //saves help request
+               if (commandName =="help") {
+                       helpRequest = optionText;
+               }
+               
+               string key, value;              
+               //reads in parameters and values
+               if((optionText != "") && (commandName != "help")){
+                       while((optionText.find_first_of(',') != -1)) {  //while there are parameters
+                               splitAtComma(value, optionText);
+                               splitAtEquals(key, value);
+                               
+                               if (key == "distfile" )         { distfile = value; inputFileName = value; fileroot = value;}
+                               if (key == "listfile" )         { listfile = value; inputFileName = value; fileroot = value;}
+                               if (key == "rabundfile" )       { rabundfile = value; inputFileName = value; fileroot = value;}
+                               if (key == "sabundfile" )       { sabundfile = value; inputFileName = value; fileroot = value;}
+                               if (key == "namefile" )         { namefile = value; }
+                               if (key == "orderfile" )        { orderfile = value; }
+                               if (key == "groupfile" )        { groupfile = value; }
+                               if (key == "cutoff" )           { cutoff = value; }
+                               if (key == "precision" )        { precision = value; }
+                               if (key == "iters" )            { iters = value; }
+                               if (key == "jumble" )           { jumble = value; }
+                               if (key == "freq" )                     { freq = value; }
+                               if (key == "method" )           { method = value; }
+                               if (key == "fileroot" )         { fileroot = value; }
+                               
+                               if (key == "single") {//stores estimators in a vector
+                                       singleEstimators.clear(); //clears out old values
+                                       if (value == "default") { value = "sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson-rarefraction"; }
+                                       splitAtDash(value, singleEstimators);
+                               }
+                               if (key == "rarefaction") {//stores estimators in a vector
+                                       rareEstimators.clear(); //clears out old values
+                                       if (value == "default") { value = "rarefraction"; }
+                                       splitAtDash(value, rareEstimators);
+                               }
+                               if (key == "shared") {//stores estimators in a vector
+                                       sharedEstimators.clear(); //clears out old values
+                                       if (value == "default") { value = "sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN"; }
+                                       splitAtDash(value, sharedEstimators);
+                               }
+                               if (key == "summary") { //stores summaries to be used in a vector
+                                       summaryEstimators.clear();
+                                       if (value == "default") { value = "summary-chao-ace-jack-bootstrap-shannon-npshannon-simpson"; }
+                                       splitAtDash(value, summaryEstimators);
+                               }
+                               if (key == "sharedsummary") { //stores sharedSummaries to be used in a vector
+                                       sharedSummaryEstimators.clear();
+                                       if (value == "default") { value = "sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN"; }
+                                       splitAtDash(value, sharedSummaryEstimators);
+                               }
+                               if (key == "sharedrarefaction") { //stores sharedrarefaction to be used in a vector
+                                       sharedRareEstimators.clear();
+                                       if (value == "default") { value = "sharedobserved"; }
+                                       splitAtDash(value, sharedRareEstimators);
+                               }
+                               if (key == "line") {//stores lines to be used in a vector
+                                       lines.clear();
+                                       line = value;
+                                       splitAtDash(value, lines);
+                                       allLines = 0;
+                               }
+                               if (key == "label") {//stores lines to be used in a vector
+                                       labels.clear();
+                                       label = value;
+                                       splitAtDash(value, labels);
+                                       allLines = 0;
+                               }
+                       }
+                       
+                       //saves the last parameter
+                       value = optionText;
+                       splitAtEquals(key, value);
+                       if (key == "distfile" )         { distfile = value; inputFileName = value; fileroot = value; }
+                       if (key == "listfile" )         { listfile = value; inputFileName = value; fileroot = value; }
+                       if (key == "rabundfile" )       { rabundfile = value; inputFileName = value; fileroot = value; }
+                       if (key == "sabundfile" )       { sabundfile = value; inputFileName = value; fileroot = value; }
+                       if (key == "namefile" )         { namefile = value; }
+                       if (key == "orderfile" )        { orderfile = value; }
+                       if (key == "groupfile" )        { groupfile = value; }
+                       if (key == "cutoff" )           { cutoff = value; }
+                       if (key == "precision" )        { precision = value; }
+                       if (key == "iters" )            { iters = value; }
+                       if (key == "jumble" )           { jumble = value; }
+                       if (key == "freq" )                     { freq = value; }
+                       if (key == "method" )           { method = value; }
+                       if (key == "fileroot" )         { fileroot = value; }
+
+                       if (key == "single") {//stores estimators in a vector
+                               singleEstimators.clear(); //clears out old values
+                               if (value == "default") { value = "sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson-rarefraction"; }
+                               splitAtDash(value, singleEstimators);
+                       }
+                       if (key == "rarefaction") {//stores estimators in a vector
+                               rareEstimators.clear(); //clears out old values
+                               if (value == "default") { value = "rarefraction"; }
+                               splitAtDash(value, rareEstimators);
+                       }
+                       if (key == "shared") {//stores estimators in a vector
+                               sharedEstimators.clear(); //clears out old values
+                               if (value == "default") { value = "sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN"; }
+                               splitAtDash(value, sharedEstimators);
+                       }
+                       if (key == "summary") { //stores summaries to be used in a vector
+                               summaryEstimators.clear();
+                               if (value == "default") { value = "summary-chao-ace-jack-bootstrap-shannon-npshannon-simpson"; }
+                               splitAtDash(value, summaryEstimators);
+                       }
+                       if (key == "sharedsummary") { //stores sharedSummaries to be used in a vector
+                               sharedSummaryEstimators.clear();
+                               if (value == "default") { value = "sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN"; }
+                               splitAtDash(value, sharedSummaryEstimators);
+                       }
+                       if (key == "sharedrarefaction") { //stores sharedrarefaction to be used in a vector
+                               sharedRareEstimators.clear();
+                               if (value == "default") { value = "sharedobserved"; }
+                               splitAtDash(value, sharedRareEstimators);
+                       }
+                       
+                       if (key == "line") {//stores lines to be used in a vector
+                               lines.clear();
+                               line = value;
+                               splitAtDash(value, lines);
+                               allLines = 0;
+                       }
+                       if (key == "label") {//stores lines to be used in a vector
+                               labels.clear();
+                               label = value;
+                               splitAtDash(value, labels);
+                               allLines = 0;
+                       }
+               }
+               
+                               
+               //input defaults
+               if (commandString == "collect.single") {
+                       if (singleEstimators.size() == 0) { splitAtDash(single, singleEstimators); }    
+               }
+               if (commandString == "rarefaction.single") {
+                       if (rareEstimators.size() == 0) { splitAtDash(rarefaction, rareEstimators);  }  
+               }
+               if (commandString == "collect.shared") {
+                       if (sharedEstimators.size() == 0) { splitAtDash(shared, sharedEstimators); }    
+               }
+               if (commandString == "summary.single") {
+                       if (summaryEstimators.size() == 0) { splitAtDash(summary, summaryEstimators); }
+               }
+               if (commandString == "summary.shared") {
+                       if (sharedSummaryEstimators.size() == 0) { splitAtDash(sharedsummary, sharedSummaryEstimators); }
+               }
+               if (commandString == "rarefaction.shared") {
+                       if (sharedRareEstimators.size() == 0) { splitAtDash(sharedrarefaction, sharedRareEstimators); }
+               }
+
+                               
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function parseGlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the GlobalData class function parseGlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+
+}
+/*******************************************************/
+
+/******************************************************/
+void GlobalData::setReadFormat(string command){
+       try {
+               if (command == "read.phylip") { 
+                       clear();
+                       format = "phylip";
+               }else if (command == "read.column") { 
+                       clear();
+                       format = "column";
+               }else if (command == "read.list") { 
+                       clear();
+                       format = "list";
+               }else if (command == "read.rabund") { 
+                       clear();
+                       format = "rabund";
+               }else if (command == "read.sabund") { 
+                       clear();
+                       format = "sabund";
+               }else if (command == "read.shared") { 
+                       clear();
+                       format = "shared";
+               }else if (command == "parselist") { format = "list"; }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function setReadFormat. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the GlobalData class function setReadFormat. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+/*******************************************************/
+
+/******************************************************/
+// These functions give you the option parameters of the commands
+string GlobalData::getDistFile()               {       return distfile;        }
+string GlobalData::getListFile()               {       return listfile;        }
+string GlobalData::getRabundFile()             {       return rabundfile;      }
+string GlobalData::getSabundFile()             {       return sabundfile;      }
+string GlobalData::getNameFile()               {       return namefile;        }
+string GlobalData::getGroupFile()              {       return groupfile;       }
+string GlobalData::getOrderFile()              {       return orderfile;       }
+string GlobalData::getCutOff()                 {       return cutoff;          }
+string GlobalData::getFormat()                 {       return format;          }
+string GlobalData::getPrecision()              {       return precision;       }
+string GlobalData::getMethod()                 {       return method;          }
+string GlobalData::getFileRoot()               {       return fileroot;        }
+string GlobalData::getIters()                  {       return iters;           }
+string GlobalData::getJumble()                 {       return jumble;          }
+string GlobalData::getFreq()                   {       return freq;            }
+void GlobalData::setListFile(string file)      {       listfile = file;        inputFileName = file;}
+void GlobalData::setRabundFile(string file)    {       rabundfile = file;      inputFileName = file;}
+void GlobalData::setSabundFile(string file)    {       sabundfile = file;      inputFileName = file;}
+void GlobalData::setDistFile(string file)      {       distfile = file;    inputFileName = file;}
+void GlobalData::setNameFile(string file)      {       namefile = file;        }
+void GlobalData::setFormat(string Format)      {       format = Format;        }
+
+
+/*******************************************************/
+
+/******************************************************/
+
+GlobalData::GlobalData() {
+       //option definitions should go here...
+       helpRequest = "";
+       clear();
+}
+/*******************************************************/
+
+/******************************************************/
+
+void GlobalData::clear() {
+       //option definitions should go here...
+       distfile                =       "";
+       listfile                =       "";///users/westcott/desktop/s.list
+       rabundfile              =       "";
+       sabundfile              =       "";
+       namefile                =       "";
+       groupfile               =       ""; ///users/westcott/desktop/s.names
+       orderfile               =       "";
+       cutoff                  =       "10.00";
+       format                  =       "";
+       precision               =       "100";
+       iters                   =       "1000"; 
+       line                    =   "";
+       label                   =       "";
+       jumble                  =       "0";
+       freq                    =       "100";
+       method                  =       "furthest";
+       fileroot                =       "";
+       single                  =       "sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson-rarefraction";
+       rarefaction             =       "rarefaction";
+       shared                  =       "sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN";
+       sharedsummary   =   "sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN";
+       summary                 =       "summary-chao-ace-jack-bootstrap-shannon-npshannon-simpson";
+       sharedrarefaction = "sharedobserved";
+}
+/*******************************************************/
+
+/******************************************************/
+
+GlobalData::~GlobalData() {
+       _uniqueInstance = 0;
+       if(gListVector != NULL)         {       delete gListVector;             }
+       if(gSparseMatrix != NULL)       {       delete gSparseMatrix;   }
+       if(gorder != NULL)                      {       delete gorder;          }
+}
+/*******************************************************/
+
+/******************************************************/
+//This function parses the estimator options and puts them in a vector
+void GlobalData::splitAtDash(string& estim, vector<string>& container) {
+       try {
+               string individual;
+               
+               while (estim.find_first_of('-') != -1) {
+                       individual = estim.substr(0,estim.find_first_of('-'));
+                       if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
+                               estim = estim.substr(estim.find_first_of('-')+1, estim.length());
+                               container.push_back(individual);
+                       }
+               }
+               //get last one
+               container.push_back(estim);
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the GlobalData class function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+
+}
+/*******************************************************/
+
+/******************************************************/
+//This function parses the label options and puts them in a set
+void GlobalData::splitAtDash(string& estim, set<string>& container) {
+       try {
+               string individual;
+               
+               while (estim.find_first_of('-') != -1) {
+                       individual = estim.substr(0,estim.find_first_of('-'));
+                       if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
+                               estim = estim.substr(estim.find_first_of('-')+1, estim.length());
+                               container.insert(individual);
+                       }
+               }
+               //get last one
+               container.insert(estim);
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the GlobalData class function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+
+}
+/*******************************************************/
+
+/******************************************************/
+//This function parses the line options and puts them in a set
+void GlobalData::splitAtDash(string& estim, set<int>& container) {
+       try {
+               string individual;
+               int lineNum;
+               
+               while (estim.find_first_of('-') != -1) {
+                       individual = estim.substr(0,estim.find_first_of('-'));
+                       if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
+                               estim = estim.substr(estim.find_first_of('-')+1, estim.length());
+                               convert(individual, lineNum); //convert the string to int
+                               container.insert(lineNum);
+                       }
+               }
+               //get last one
+               convert(estim, lineNum); //convert the string to int
+               container.insert(lineNum);
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the GlobalData class function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+
+}
+/*******************************************************/
+
+/******************************************************/
+
+//This function splits up the various option parameters
+void GlobalData::splitAtComma(string& prefix, string& suffix){
+       try {
+               prefix = suffix.substr(0,suffix.find_first_of(','));
+               if ((suffix.find_first_of(',')+2) <= suffix.length()) {  //checks to make sure you don't have comma at end of string
+                       suffix = suffix.substr(suffix.find_first_of(',')+2, suffix.length());
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function splitAtComma. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the GlobalData class function splitAtComma. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+
+}
+/*******************************************************/
+
+/******************************************************/
+//This function separates the key value from the option value i.e. distfile = "96_..."
+void GlobalData::splitAtEquals(string& key, string& value){            
+       try {
+               if(value.find_first_of('=') != -1){
+                       key = value.substr(0,value.find_first_of('='));
+                       if ((value.find_first_of('=')+1) <= value.length()) {
+                               value = value.substr(value.find_first_of('=')+1, value.length());
+                       }
+               }else{
+                       key = value;
+                       value = 1;
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function splitAtEquals. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the GlobalData class function splitAtEquals. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+
+}
+/*******************************************************/
+
+/******************************************************/
diff --git a/globaldata.hpp b/globaldata.hpp
new file mode 100644 (file)
index 0000000..fbad525
--- /dev/null
@@ -0,0 +1,84 @@
+#ifndef GLOBALDATA_HPP
+#define GLOBALDATA_HPP
+
+#include <string>
+#include <vector>
+#include <set>
+#include "groupmap.h"
+
+using namespace std;
+
+class ListVector;
+class SparseMatrix;
+class OrderVector;
+class InputData;
+class GroupMap;
+class SAbundVector;
+
+class GlobalData {
+public:
+       static GlobalData* getInstance();
+       ListVector* getListVector();
+       SparseMatrix* getSparseMatrix();
+       InputData* ginput;
+       OrderVector* gorder;
+       ListVector* glist;
+       SAbundVector* sabund;
+       GroupMap* gGroupmap;
+       string inputFileName, helpRequest, commandName;
+       bool allLines;
+       vector<string> singleEstimators, summaryEstimators, sharedEstimators, rareEstimators, sharedRareEstimators, sharedSummaryEstimators; //holds estimators to be used
+       set<int> lines; //hold lines to be used
+       set<string> labels; //holds labels to be used
+       
+       string getDistFile();
+       string getListFile();
+       string getRabundFile();
+       string getSabundFile();
+       string getNameFile();
+       string getGroupFile();
+       string getOrderFile();
+       string getCutOff();
+       string getFormat();
+       string getPrecision();
+       string getMethod();
+       string getFileRoot();
+       string getIters();
+       string getJumble();
+       string getFreq();
+       void setListFile(string);
+       void setDistFile(string);
+       void setNameFile(string);
+       void setRabundFile(string);
+       void setSabundFile(string);
+       void setFormat(string);
+
+       
+       void setListVector(ListVector*);
+       void setSparseMatrix(SparseMatrix*);
+       void clear(); 
+       
+       void parseGlobalData(string, string);
+       void splitAtEquals(string&, string&);
+       void splitAtComma(string&, string&);
+       void splitAtDash(string&, vector<string>&);
+       void splitAtDash(string&, set<int>&);
+       void splitAtDash(string&, set<string>&);
+       
+private:
+       string distfile, listfile, rabundfile, sabundfile, namefile, groupfile, orderfile, line, label;
+       string cutoff, format, precision, method, fileroot, iters, jumble, freq, single, rarefaction, shared, summary, sharedsummary, sharedrarefaction;
+       static GlobalData* _uniqueInstance;
+       GlobalData( const GlobalData& ); // Disable copy constructor
+       void operator=( const GlobalData& ); // Disable assignment operator
+       GlobalData();
+       ~GlobalData();
+       ListVector* gListVector;
+       SparseMatrix* gSparseMatrix;
+       void setReadFormat(string);
+       
+       };
+
+//**********************************************************************************************************************
+
+#endif
diff --git a/groupmap.cpp b/groupmap.cpp
new file mode 100644 (file)
index 0000000..9cf5d7a
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ *  groupmap.cpp
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 12/1/08.
+ *  Copyright 2008 __MyCompanyName__. All rights reserved.
+ *
+ */
+
+#include "groupmap.h"
+
+/************************************************************/
+
+ GroupMap::GroupMap(string filename) {
+       groupFileName = filename;
+       openInputFile(filename, fileHandle);
+}
+
+/************************************************************/
+ GroupMap::~GroupMap(){};
+
+/************************************************************/
+void GroupMap::readMap() {
+               string seqName, seqGroup;
+       
+               while(fileHandle){
+                       fileHandle >> seqName;                  //read from first column
+                       fileHandle >> seqGroup;                 //read from second column
+                       
+                       setNamesOfGroups(seqGroup);
+                                               
+                       groupmap[seqName] = seqGroup;   //store data in map
+               
+                       gobble(fileHandle);
+               }
+               fileHandle.close();
+}
+/************************************************************/
+
+int GroupMap::getNumGroups() {
+                       
+       return namesOfGroups.size();    
+               
+}
+/************************************************************/
+
+string GroupMap::getGroup(string sequenceName) {
+                       
+       it = groupmap.find(sequenceName);
+       if (it != groupmap.end()) { //sequence name was in group file
+               return it->second;      
+       }else {
+               return "not found";
+       }
+               
+}
+
+/************************************************************/
+
+void GroupMap::setNamesOfGroups(string seqGroup) {
+                       int i, count;
+                       count = 0;
+                       for (i=0; i<namesOfGroups.size(); i++) {
+                               if (namesOfGroups[i] != seqGroup) {
+                                       count++; //you have not found this group
+                               }else {
+                                       break; //you already have it
+                               }
+                       }
+                       if (count == namesOfGroups.size()) {
+                               namesOfGroups.push_back(seqGroup); //new group
+                       }
+}
+/************************************************************/
\ No newline at end of file
diff --git a/groupmap.h b/groupmap.h
new file mode 100644 (file)
index 0000000..75e0fdc
--- /dev/null
@@ -0,0 +1,39 @@
+#ifndef GROUPMAP_H
+#define GROUPMAP_H
+/*
+ *  groupmap.h
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 12/1/08.
+ *  Copyright 2008 __MyCompanyName__. All rights reserved.
+ *
+ */
+
+#include <Carbon/Carbon.h>
+#include <map>
+#include <string>
+#include <iostream>
+#include <fstream>
+#include "utilities.hpp"
+
+
+class GroupMap {
+public:
+       GroupMap(string);
+       ~GroupMap();
+       void readMap();
+       int getNumGroups();
+       string getGroup(string);
+       vector<string> namesOfGroups;
+       
+       
+private:
+       ifstream fileHandle;
+       string groupFileName;
+       int numGroups;
+       map<string, string>::iterator it;
+       void setNamesOfGroups(string); 
+       map<string, string> groupmap; //sequence name and groupname
+};
+
+#endif
\ No newline at end of file
diff --git a/helpcommand.cpp b/helpcommand.cpp
new file mode 100644 (file)
index 0000000..f1cf893
--- /dev/null
@@ -0,0 +1,153 @@
+/*
+ *  helpcommand.cpp
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/2/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "helpcommand.h"
+
+//**********************************************************************************************************************
+
+HelpCommand::HelpCommand(){}
+
+//**********************************************************************************************************************
+
+HelpCommand::~HelpCommand(){}
+
+//**********************************************************************************************************************
+
+int HelpCommand::execute(){
+
+       globaldata = GlobalData::getInstance();
+       
+       if (globaldata->helpRequest == "read.phylip") {
+               cout << "The read.phylip command parameter options are distfile, namefile, cutoff and precision" << "\n";
+               cout << "The read.phylip command should be in the following format: " << "\n";
+               cout << "read.phylip(distfile=yourDistFile, namefile=yourNameFile, cutoff=yourCutoff, precision=yourPrecision) " << "\n";
+               cout << "The distfile parameter is required.  If you do not provide a cutoff value 10.00 is assumed. If you do not provide a precision value then 100 is assumed." << "\n";
+               cout << "Note: No spaces between parameter labels (i.e. distfile), '=' and parameters (i.e.yourDistfile)." << "\n" << "\n";
+       }else if (globaldata->helpRequest == "read.column") {
+               cout << "The read.column command parameter options are distfile, namefile, cutoff and precision" << "\n";
+               cout << "The read.column command should be in the following format: " << "\n";
+               cout << "read.column(distfile=yourDistFile, namefile=yourNameFile, cutoff=yourCutoff, precision=yourPrecision) " << "\n";
+               cout << "The distfile and namefile parameters are required.  If you do not provide a cutoff value 10.00 is assumed. If you do not provide a precision value then 100 is assumed." << "\n";
+               cout << "Note: No spaces between parameter labels (i.e. distfile), '=' and parameters (i.e.yourDistfile)." << "\n" << "\n";
+       }else if (globaldata->helpRequest == "read.list") {
+               cout << "The read.list command parameter options are listfile and orderfile." << "\n";
+               cout << "The read.list command should be in the following format: " << "\n";
+               cout << "read.list(listfile=yourListFile, orderfile=yourOrderFile) " << "\n";
+               cout << "The listfile parameter is required." << "\n";
+               cout << "Note: No spaces between parameter labels (i.e. listfile), '=' and parameters (i.e.yourListfile)." << "\n" << "\n";
+       }else if (globaldata->helpRequest == "read.rabund") {
+               cout << "The read.rabund command parameter options are rabundfile and orderfile." << "\n";
+               cout << "The read.rabund command should be in the following format: " << "\n";
+               cout << "read.rabund(rabundfile=yourRAbundFile, orderfile=yourOrderFile) " << "\n";
+               cout << "The rabundfile parameter is required." << "\n";
+               cout << "Note: No spaces between parameter labels (i.e. rabundfile), '=' and parameters (i.e.yourRAbundfile)." << "\n" << "\n";
+       }else if (globaldata->helpRequest == "read.sabund") {
+               cout << "The read.sabund command parameter options are sabundfile and orderfile." << "\n";
+               cout << "The read.sabund command should be in the following format: " << "\n";
+               cout << "read.sabund(sabundfile=yourSAbundFile, orderfile=yourOrderFile) " << "\n";
+               cout << "The sabundfile parameter is required." << "\n";
+               cout << "Note: No spaces between parameter labels (i.e. sabundfile), '=' and parameters (i.e.yourSAbundfile)." << "\n" << "\n";
+       }else if (globaldata->helpRequest == "read.shared") {
+               cout << "The read.shared command parameter options are listfile and groupfile." << "\n";
+               cout << "The read.shared command should be in the following format: " << "\n";
+               cout << "read.shared(listfile=yourListFile, groupfile=yourGroupFile) " << "\n";
+               cout << "The listfile parameter and groupfile paramaters are required." << "\n";
+               cout << "Note: No spaces between parameter labels (i.e. listfile), '=' and parameters (i.e.yourListfile)." << "\n" << "\n";
+       }else if (globaldata->helpRequest == "cluster") {
+               cout << "The cluster command can only be executed after a successful read.phylip or read.column command." << "\n";
+               cout << "The cluster command parameter options are method, cuttoff and precision. No parameters are required." << "\n";
+               cout << "The cluster command should be in the following format: " << "\n";
+               cout << "cluster(method=yourMethod, cutoff=yourCutoff, precision=yourPrecision) " << "\n";
+               cout << "The acceptable cluster methods are furthest, nearest and average.  If no method is provided then furthest is assumed." << "\n" << "\n";
+       }else if (globaldata->helpRequest == "collect.single") {
+               cout << "The collect.single command can only be executed after a successful read.list read.rabund or rad.sabund command. WITH ONE EXECEPTION. " << "\n";
+               cout << "The collect.single command can be executed after a successful cluster command.  It will use the .list file from the output of the cluster." << "\n";
+               cout << "The collect.single command parameters are label, line, freq, single.  No parameters are required, but you may not use " << "\n";
+               cout << "both the line and label parameters at the same time. The collect.single command should be in the following format: " << "\n";
+               cout << "collect.single(label=yourLabel, line=yourLines, iters=yourIters, freq=yourFreq, single=yourEstimators)." << "\n";
+               cout << "Example collect(label=unique-.01-.03, line=0,5,10, iters=10000, freq=10, single=collect-chao-ace-jack)." << "\n";
+               cout << "The default values for freq is 100, and single are sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson." << "\n";
+               cout << "The label and line parameters are used to analyze specific lines in your input." << "\n";
+               cout << "Note: No spaces between parameter labels (i.e. listfile), '=' and parameters (i.e.yourListfile)." << "\n" << "\n";
+       }else if (globaldata->helpRequest == "collect.shared") {
+               cout << "The collect.shared command can only be executed after a successful read.shared command." << "\n";
+               cout << "The collect.shared command parameters are label, line, freq, jumble, shared.  No parameters are required, but you may not use " << "\n";
+               cout << "both the line and label parameters at the same time. The collect.shared command should be in the following format: " << "\n";
+               cout << "collect.shared(label=yourLabel, line=yourLines, freq=yourFreq, jumble=yourJumble, shared=yourEstimators)." << "\n";
+               cout << "Example collect.shared(label=unique-.01-.03, line=0,5,10, freq=10, jumble=1, shared=sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN)." << "\n";
+               cout << "The default values for jumble is 0 (meaning don’t jumble, if it’s set to 1 then it will jumble), freq is 100 and shared are sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN." << "\n";
+               cout << "The label and line parameters are used to analyze specific lines in your input." << "\n";
+               cout << "Note: No spaces between parameter labels (i.e. listfile), '=' and parameters (i.e.yourListfile)." << "\n" << "\n";
+       }else if (globaldata->helpRequest == "rarefaction.single") {
+               cout << "The rarefaction.single command can only be executed after a successful read.list, read.rabund or read.sabund. WTIH ONE EXECEPTION." << "\n";
+               cout << "The rarefaction.single command can be executed after a successful cluster command.  It will use the .list file from the output of the cluster." << "\n";
+               cout << "The rarefaction.single command parameters are label, line, iters, freq, rarefaction.  No parameters are required, but you may not use " << "\n";
+               cout << "both the line and label parameters at the same time. The rarefaction.single command should be in the following format: " << "\n";
+               cout << "rarefaction.single(label=yourLabel, line=yourLines, iters=yourIters, freq=yourFreq, rarefaction=yourEstimators)." << "\n";
+               cout << "Example rarefaction.single(label=unique-.01-.03, line=0,5,10, iters=10000, freq=10, rarefaction=rarefaction-rchao-race-rjack-rbootstrap-rshannon-rnpshannon-rsimpson)." << "\n";
+               cout << "The default values for iters is 1000, freq is 100, and rarefaction is rarefaction which calculates the rarefaction curve for the observed richness." << "\n";
+               cout << "The label and line parameters are used to analyze specific lines in your input." << "\n";
+               cout << "Note: No spaces between parameter labels (i.e. listfile), '=' and parameters (i.e.yourListfile)." << "\n" << "\n";
+       }else if (globaldata->helpRequest == "rarefaction.shared") {
+               cout << "The rarefaction.shared command can only be executed after a successful read.shared command." << "\n";
+               cout << "The rarefaction.shared command parameters are label, line, iters, jumble and sharedrarefaction.  No parameters are required, but you may not use " << "\n";
+               cout << "both the line and label parameters at the same time. The rarefaction command should be in the following format: " << "\n";
+               cout << "rarefaction.shared(label=yourLabel, line=yourLines, iters=yourIters, jumble=yourJumble, sharedrarefaction=yourEstimators)." << "\n";
+               cout << "Example rarefaction.shared(label=unique-.01-.03, line=0,5,10, iters=10000, jumble=1, sharedrarefaction=sharedobserved)." << "\n";
+               cout << "The default values for iters is 1000, jumble is 0 (meaning don’t jumble, if it’s set to 1 then it will jumble), freq is 100, and sharedrarefaction is sharedobserved which calculates the shared rarefaction curve for the observed richness." << "\n";
+               cout << "The label and line parameters are used to analyze specific lines in your input." << "\n";
+               cout << "Note: No spaces between parameter labels (i.e. listfile), '=' and parameters (i.e.yourListfile)." << "\n" << "\n";
+       }else if (globaldata->helpRequest == "summary.single") { 
+               cout << "The summary.single command can only be executed after a successful read.list, read.rabund or read.sabund. WTIH ONE EXECEPTION." << "\n";
+               cout << "The summary.single command can be executed after a successful cluster command.  It will use the .list file from the output of the cluster." << "\n";
+               cout << "The summary.single command parameters are label, line, summary.  No parameters are required, but you may not use " << "\n";
+               cout << "both the line and label parameters at the same time. The summary.single command should be in the following format: " << "\n";
+               cout << "summary.single(label=yourLabel, line=yourLines, summary=yourEstimators)." << "\n";
+               cout << "Example summary.single(label=unique-.01-.03, line=0,5,10, summary=sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson)." << "\n";
+               cout << "The default value summary is sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson" << "\n";
+               cout << "The label and line parameters are used to analyze specific lines in your input." << "\n";
+               cout << "Note: No spaces between parameter labels (i.e. listfile), '=' and parameters (i.e.yourListfile)." << "\n" << "\n";
+       }else if (globaldata->helpRequest == "summary.shared") { 
+               cout << "The summary.shared command can only be executed after a successful read.shared command." << "\n";
+               cout << "The summary.shared command parameters are label, line, jumble and sharedsummary.  No parameters are required, but you may not use " << "\n";
+               cout << "both the line and label parameters at the same time. The summary.shared command should be in the following format: " << "\n";
+               cout << "summary.shared(label=yourLabel, line=yourLines, jumble=yourJumble, sharedsummary=yourEstimators)." << "\n";
+               cout << "Example summary.shared(label=unique-.01-.03, line=0,5,10, jumble=1, sharedsummary=sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN)." << "\n";
+               cout << "The default value for jumble is 0 (meaning don’t jumble, if it’s set to 1 then it will jumble) and sharedsummary is sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN" << "\n";
+               cout << "The label and line parameters are used to analyze specific lines in your input." << "\n";
+               cout << "Note: No spaces between parameter labels (i.e. listfile), '=' and parameters (i.e.yourListfile)." << "\n" << "\n";
+       }else if (globaldata->helpRequest == "shared") { 
+               cout << "The shared command can only be executed after a successful read.shared command." << "\n";
+               cout << "The shared command parses a list file and separates it into groups." << "\n";
+               cout << "It outputs a shared file containing the otu information for each group.  There are no shared command parameters." << "\n";
+               cout << "The shared command should be in the following format: shared()." << "\n";
+               cout << "Example shared()." << "\n";
+       }else if (globaldata->helpRequest == "parselist") { 
+               cout << "The parselist command parses a list file and separates it into groups." << "\n";
+               cout << "It outputs a list file for each group." << "\n";
+               cout << "The parselist command parameter options are listfile and groupfile." << "\n";
+               cout << "The parselist command should be in the following format: " << "\n";
+               cout << "parselist(listfile=yourListFile, groupfile=yourGroupFile) " << "\n";
+               cout << "The listfile parameter and groupfile paramater are required." << "\n";
+               cout << "Note: No spaces between parameter labels (i.e. listfile), '=' and parameters (i.e.yourListfile)." << "\n" << "\n";
+       }else if (globaldata->helpRequest == "quit") {
+               cout << "The quit command will terminate Dotur and should be in the following format: " << "\n";
+               cout << "quit()" << "\n" << "\n";
+       }else if (globaldata->helpRequest == "") {
+               cout << "Valid commands are read.phylip(), read.column(), read.list(), read.rabund(), read.sabund(), cluster(), collect.single(), rarefaction.single(), summary.single(), collect.shared(), rarefaction.shared(), summary.shared(), shared(), pareselist(), quit(), help()." << "\n";
+               cout << "For more information about a specific command type 'help(commandName)' i.e. 'help(read.phylip)'" << endl;
+       }else {
+               cout << "not a valid command" << endl;
+       }
+       
+       cout << endl << "For further assistance please refer to the Mothur manual, or contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+       return 0;
+}
+
+//**********************************************************************************************************************/
diff --git a/helpcommand.h b/helpcommand.h
new file mode 100644 (file)
index 0000000..4ea4628
--- /dev/null
@@ -0,0 +1,32 @@
+#ifndef HELPCOMMAND_H
+#define HELPCOMMAND_H
+/*
+ *  helpcommand.h
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/2/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+/* This class is designed to aid the user in running mothur. */
+
+#include <Carbon/Carbon.h>
+#include "command.hpp"
+#include "globaldata.hpp"
+
+
+class HelpCommand : public Command {
+       
+public:
+       HelpCommand();
+       ~HelpCommand();
+       int execute();
+private:
+       GlobalData* globaldata;
+       
+private:
+               
+};
+#endif
\ No newline at end of file
diff --git a/inputdata.cpp b/inputdata.cpp
new file mode 100644 (file)
index 0000000..2ecebe3
--- /dev/null
@@ -0,0 +1,169 @@
+/*
+ *  inputdata.cpp
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 11/18/08.
+ *  Copyright 2008 __MyCompanyName__. All rights reserved.
+ *
+ */
+
+#include "inputdata.h"
+#include "ordervector.hpp"
+#include "listvector.hpp"
+#include "utilities.hpp"
+
+/***********************************************************************/
+
+InputData::InputData(string fName, string f) : format(f){
+       
+       openInputFile(fName, fileHandle);
+       
+}
+
+/***********************************************************************/
+
+
+InputData::~InputData(){
+       
+//     delete output;
+       
+}
+
+/***********************************************************************/
+
+InputData::InputData(string fName, string orderFileName, string f) : format(f){
+       try {
+               ifstream ofHandle;
+               openInputFile(orderFileName, ofHandle);
+               string name;
+
+               int count = 0;
+       
+               while(ofHandle){
+                       ofHandle >> name;
+                       orderMap[name] = count;
+                       count++;
+                       gobble(ofHandle);
+               }
+               ofHandle.close();
+       
+               openInputFile(fName, fileHandle);
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function InputData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the InputData class function InputData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+/***********************************************************************/
+
+ListVector* InputData::getListVector(){
+       try {
+               if(fileHandle){
+                       if((format == "list") || (format == "shared")){
+                               list = new ListVector(fileHandle);
+                       }
+                                       
+                       gobble(fileHandle);
+                       return list;
+               }
+               else{
+                       return 0;
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the InputData class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+
+
+/***********************************************************************/
+
+OrderVector* InputData::getOrderVector(){
+       try {
+               if(fileHandle){
+                       if((format == "list") || (format == "shared")){
+                               input = new ListVector(fileHandle);
+                       }
+                       else if(format == "rabund"){
+                               input = new RAbundVector(fileHandle);
+                       }
+                       else if(format == "order"){             
+                               input = new OrderVector(fileHandle);
+                       }
+                       else if(format == "sabund"){
+                               input = new SAbundVector(fileHandle);
+                       }
+                       else if(format == "listorder"){                                 
+                               input = new ListVector(fileHandle); 
+                       }
+               
+                       gobble(fileHandle);
+                       output = new OrderVector();
+                       *output = (input->getOrderVector());
+                       //delete input;
+                       return output;
+               }
+               else{
+                       return 0;
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the InputData class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+/***********************************************************************/
+
+SAbundVector* InputData::getSAbundVector(){
+       try {
+               if(fileHandle){
+                       if((format == "list") || (format == "shared")){
+                               input = new ListVector(fileHandle);
+                       }
+                       else if(format == "rabund"){
+                               input = new RAbundVector(fileHandle);
+                       }
+                       else if(format == "order"){                     
+                               input = new OrderVector(fileHandle);
+                       }
+                       else if(format == "sabund"){
+                               input = new SAbundVector(fileHandle);
+                       }
+                                       
+                       gobble(fileHandle);
+
+                       sabund = new SAbundVector();
+                       *sabund = (input->getSAbundVector());
+
+                       return sabund;
+               }
+               else{
+                       return 0;
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the InputData class function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+/***********************************************************************/
diff --git a/inputdata.h b/inputdata.h
new file mode 100644 (file)
index 0000000..46d1655
--- /dev/null
@@ -0,0 +1,35 @@
+#ifndef INPUTDATA_H
+#define INPUTDATA_H
+
+#include <iostream>
+#include <iomanip>
+#include <string>
+#include <fstream>
+#include "ordervector.hpp"
+#include "listvector.hpp"
+
+
+using namespace std;
+
+class InputData {
+       
+public:
+       InputData(string, string);
+       InputData(string, string, string);
+       ~InputData();
+       ListVector* getListVector();
+       OrderVector* getOrderVector();
+       SAbundVector* getSAbundVector();
+       
+private:
+       string format;
+       ifstream fileHandle;
+       DataVector* input;
+       ListVector* list;
+       OrderVector* output;
+       SAbundVector* sabund;
+       map<string,int> orderMap;
+};
+
+
+#endif
\ No newline at end of file
diff --git a/jackknife.cpp b/jackknife.cpp
new file mode 100644 (file)
index 0000000..a166eb4
--- /dev/null
@@ -0,0 +1,164 @@
+/*
+ *  jacknife.cpp
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/7/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "jackknife.h"
+
+/***********************************************************************/
+void Jackknife::getAMatrix(void){
+       try {
+               vector<vector<double> > B = binomial(maxOrder);
+
+               aMat.resize(maxOrder+1);
+
+               for(int i=0;i<=maxOrder;i++){
+                       aMat[i].resize(maxOrder+1);
+                       for(int j=1;j<=maxOrder;j++){
+                       
+                               aMat[i][j] = 1 + B[i][j] * (int)(pow(-1.0,j+1));
+                       }
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the Jackknife class Function getAMatrix. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the Jackknife class function getAMatrix. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+/**************************************************************************************************/
+
+double Jackknife::CN(double z){
+       try {
+               if(z>6.0)       {       return 0.0;             }
+               if(z<-6.0)      {       return 0.0;             }
+       
+               const double b1=  0.31938153;
+               const double b2= -0.356563782;
+               const double b3=  1.781477937;
+               const double b4= -1.821255978;
+               const double b5=  1.330274429;
+               const double p=   0.2316419;
+               const double c2=  0.3989423;
+       
+               double a=abs(z);
+               double t=1.0/(1.0+a*p);
+               double b=c2*exp((-z)*(z/2.0));
+               double n=((((b5*t+b4)*t+b3)*t+b2)*t+b1)*t;
+               n = 2*b*n;
+               return n;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the Jackknife class Function CN. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the Jackknife class function CN. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+/***********************************************************************/
+
+EstOutput Jackknife::getValues(SAbundVector* rank){
+       try {
+               //EstOutput jackData(3,0);
+               data.resize(3,0);
+       
+               double jack, jacklci, jackhci;
+       
+               double maxRank = (double)rank->getMaxRank();
+               int S = rank->getNumBins();
+
+               double N[maxOrder+1];
+               double variance[maxOrder+1];
+               double p[maxOrder+1];
+       
+               int k = 0;
+
+               for(int i=0;i<=maxOrder;i++){
+                       N[i]=0.0000;
+                       variance[i]=0.0000;
+                       for(int j=1;j<=maxRank;j++){
+                               if(j<=i){
+                                       N[i] += aMat[i][j]*rank->get(j);
+                                       variance[i] += aMat[i][j]*aMat[i][j]*rank->get(j);
+                               }
+                               else{
+                                       N[i] += rank->get(j);
+                                       variance[i] += rank->get(j);
+                               }
+                       }
+                       variance[i] = variance[i]-N[i];
+                       double var = 0.0000;
+                       if(i>0){
+                               for(int j=1;j<=maxRank;j++){
+                                       if(j<=i){       var += rank->get(j)*pow((aMat[i][j]-aMat[i-1][j]),2.0); }
+                                       else    {       var += 0.0000;  }
+                               }
+                               var -= ((N[i]-N[i-1])*(N[i]-N[i-1]))/S;
+                               var = var * S / (S-1);
+                               double T = (N[i]-N[i-1])/sqrt(var);
+                               if(T<=0.00){    p[i-1] = 1.00000;               }
+                               else{                   p[i-1] = CN(T);                 }
+                       
+                               if(p[i-1]>=0.05){
+                                       k = i-1;
+                                       break;
+                               }
+                       }
+                       if(i == maxOrder){      k=1;    }
+               }
+
+               double ci = 0;
+       
+               if(k>1){
+                       double c = (0.05-p[k-1])/(p[k]-p[k-1]);
+                       ci = 0.0000;
+                       jack = c*N[k]+(1-c)*N[k-1];
+                       for(int j=1;j<=maxRank;j++){
+                               if(j<=k){       ci += rank->get(j)*pow((c*aMat[k][j]+(1-c)*aMat[k-1][j]),2.0);  }
+                               else    {       ci += rank->get(j);     }
+                       }
+                       ci = 1.96 * sqrt(ci - jack);
+               }
+               else if(k=1){
+                       jack = N[1];
+                       ci = 1.96*sqrt(variance[1]);
+               }else{
+                       jack = 0.0;
+                       ci = 0.0;
+               }
+       
+               jacklci = jack-ci;
+               jackhci = jack+ci;
+               
+               data[0] = jack;
+               data[1] = jacklci;
+               data[2] = jackhci;
+               
+               if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; }
+               if (isnan(data[1]) || isinf(data[1])) { data[1] = 0; }
+               if (isnan(data[2]) || isinf(data[2])) { data[2] = 0; }
+       
+               return data;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the Jackknife class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the Jackknife class function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+/***********************************************************************/
diff --git a/jackknife.h b/jackknife.h
new file mode 100644 (file)
index 0000000..45f9287
--- /dev/null
@@ -0,0 +1,38 @@
+#ifndef JACKKNIFE_H
+#define JACKKNIFE_H
+
+/*
+ *  jacknife.h
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/7/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include <Carbon/Carbon.h>
+#include "calculator.h"
+
+/* This class implements the JackKnife estimator on single group. 
+It is a child of the calculator class. */
+
+/***********************************************************************/
+
+class Jackknife : public Calculator  {
+       
+public:
+       Jackknife() : Calculator("Jackknife", 3) {      getAMatrix(); };
+       EstOutput getValues(SAbundVector*);
+       EstOutput getValues(SharedRAbundVector*, SharedRAbundVector*) {return data;};
+
+private:
+       static const int maxOrder = 30;
+       vector<vector<double> > aMat;
+
+       void getAMatrix();
+       double CN(double);
+};
+
+/***********************************************************************/
+
+#endif
\ No newline at end of file
diff --git a/kmer.cpp b/kmer.cpp
new file mode 100644 (file)
index 0000000..2c27833
--- /dev/null
+++ b/kmer.cpp
@@ -0,0 +1,94 @@
+/*
+ *  kmer.cpp
+ *  
+ *
+ *  Created by Pat Schloss on 12/15/08.
+ *  Copyright 2008 Patrick D. Schloss. All rights reserved.
+ *
+ */
+
+using namespace std;
+
+#include <string>
+#include <vector>
+
+#include "kmer.hpp"
+
+/**************************************************************************************************/
+
+Kmer::Kmer(int size) : kmerSize(size) {
+       
+       int power4s[9] = { 1, 4, 16, 64, 256, 1024, 4096, 16384, 65536 };
+       maxKmer = power4s[kmerSize]+1;// (int)pow(4.,k)+1;
+       
+}
+
+/**************************************************************************************************/
+
+string Kmer::getKmerString(string sequence){
+       int length = sequence.length();
+       int nKmers = length - kmerSize + 1;
+       vector<int> counts(maxKmer, 0);
+       
+       for(int i=0;i<nKmers;i++){
+               int kmerNumber = getKmerNumber(sequence, i);
+               counts[kmerNumber]++;
+       }
+       
+       string kmerString = "";
+       for(int i=0;i<maxKmer;i++){
+               kmerString += getASCII(counts[i]);
+       }               
+       
+       return kmerString;      
+}
+       
+/**************************************************************************************************/
+
+int Kmer::getKmerNumber(string sequence, int index){
+       int power4s[9] = { 1, 4, 16, 64, 256, 1024, 4096, 16384, 65536 };
+       int kmer = 0;
+       for(int i=0;i<kmerSize;i++){
+               if(toupper(sequence[i+index]) == 'A')           {       kmer += (0 * power4s[kmerSize-i-1]);    }
+               else if(toupper(sequence[i+index]) == 'C')      {       kmer += (1 * power4s[kmerSize-i-1]);    }
+               else if(toupper(sequence[i+index]) == 'G')      {       kmer += (2 * power4s[kmerSize-i-1]);    }
+               else if(toupper(sequence[i+index]) == 'U')      {       kmer += (3 * power4s[kmerSize-i-1]);    }
+               else if(toupper(sequence[i+index]) == 'T')      {       kmer += (3 * power4s[kmerSize-i-1]);    }
+               else if(toupper(sequence[i+index]) == 'N')      {       return (int)power4s[kmerSize];                  }
+       }
+       return kmer;    
+}
+       
+/**************************************************************************************************/
+       
+string Kmer::getKmerBases(int kmerNumber){
+       int power4s[9] = { 1, 4, 16, 64, 256, 1024, 4096, 16384, 65536 };
+       
+       string kmer = "";
+       
+       if(kmerNumber == power4s[kmerSize]){//pow(4.,7)){       
+               for(int i=0;i<kmerSize;i++){
+                       kmer += 'N';
+               }
+       }
+       else{
+               for(int i=0;i<kmerSize;i++){
+                       int nt = (int)(kmerNumber / (float)power4s[i]) % 4;
+                       if(nt == 0)             {       kmer = 'A' + kmer;      }
+                       else if(nt == 1){       kmer = 'C' + kmer;      }
+                       else if(nt == 2){       kmer = 'G' + kmer;      }
+                       else if(nt == 3){       kmer = 'T' + kmer;      }
+               }
+       }
+       return kmer;
+}
+
+/**************************************************************************************************/
+
+char Kmer::getASCII(int number)                {       return (char)(33+number);                       }
+
+/**************************************************************************************************/
+
+int Kmer::getNumber(char character)    {       return ((int)(character-'!'));          }
+
+/**************************************************************************************************/
diff --git a/kmer.hpp b/kmer.hpp
new file mode 100644 (file)
index 0000000..75ec538
--- /dev/null
+++ b/kmer.hpp
@@ -0,0 +1,35 @@
+#ifndef KMER_HPP
+#define KMER_HPP
+
+/*
+ *  kmer.hpp
+ *  
+ *
+ *  Created by Pat Schloss on 12/15/08.
+ *  Copyright 2008 Patrick D. Schloss. All rights reserved.
+ *
+ */
+
+/**************************************************************************************************/
+
+class Kmer {
+       
+public:
+       Kmer(int);
+       string getKmerString(string);
+       int getKmerNumber(string, int);
+       
+       
+private:
+       string getKmerBases(int);
+       
+       char getASCII(int);
+       int getNumber(char);
+       int kmerSize;
+       int maxKmer;
+       int nKmers;
+};
+
+/**************************************************************************************************/
+
+#endif
diff --git a/kmerdb.cpp b/kmerdb.cpp
new file mode 100644 (file)
index 0000000..e15bb91
--- /dev/null
@@ -0,0 +1,139 @@
+/*
+ *  kmerdb.cpp
+ *  
+ *
+ *  Created by Pat Schloss on 12/16/08.
+ *  Copyright 2008 Patrick D. Schloss. All rights reserved.
+ *
+ */
+
+using namespace std;
+
+#include <vector>
+#include <string>
+#include <fstream>
+#include <iostream>
+
+#include "sequence.hpp"
+#include "kmer.hpp"
+#include "database.hpp"
+#include "kmerdb.hpp"
+
+/**************************************************************************************************/
+
+KmerDB::KmerDB(string fastaFileName, int kSize) : Database(fastaFileName), kmerSize(kSize) {
+
+       string kmerDBName = fastaFileName.substr(0,fastaFileName.find_last_of(".")+1) + char('0'+ kmerSize) + "mer";
+       ifstream kmerFileTest(kmerDBName.c_str());
+       
+       int power4s[9] = { 1, 4, 16, 64, 256, 1024, 4096, 16384, 65536 };
+       
+       maxKmer = power4s[kmerSize];
+       kmerLocations.resize(maxKmer+1);
+       
+       if(!kmerFileTest){
+               cout << "Generating the " << kmerDBName << " database...\t";    cout.flush();
+               generateKmerDB(kmerDBName);     
+       }
+       else{
+               cout << "Reading in the " << kmerDBName << " database...\t";    cout.flush();
+               readKmerDB(kmerDBName, kmerFileTest);
+       }
+       cout << "DONE." << endl << endl;        cout.flush();
+
+}
+
+/**************************************************************************************************/
+
+Sequence* KmerDB::findClosestSequence(Sequence* candidateSeq){
+       
+       vector<int> matches(numSeqs, 0);
+       vector<int> timesKmerFound(kmerLocations.size()+1, 0);
+       
+       int maxMatches = 0;
+       int maxSequence = 0;
+       
+       string query = candidateSeq->getUnaligned();
+       
+       int numKmers = query.length() - kmerSize + 1;
+       Kmer kmer(kmerSize);
+       
+       for(int i=0;i<numKmers;i++){
+               
+               int kmerNumber = kmer.getKmerNumber(query, i);
+               
+               if(timesKmerFound[kmerNumber] == 0){
+                       for(int j=0;j<kmerLocations[kmerNumber].size();j++){
+                               matches[kmerLocations[kmerNumber][j]]++;
+                       }
+               }
+               timesKmerFound[kmerNumber] = 1;
+               
+       }
+       for(int i=0;i<numSeqs;i++){
+               if(matches[i] > maxMatches){
+                       maxMatches = matches[i];
+                       maxSequence = i;
+               }
+       }
+       return templateSequences[maxSequence];
+       
+}
+
+/**************************************************************************************************/
+
+void KmerDB::generateKmerDB(string kmerDBName){
+       
+       
+       Kmer kmer(kmerSize);
+       
+       for(int i=0;i<numSeqs;i++){
+
+               string seq = templateSequences[i]->getUnaligned();
+               int numKmers = seq.length() - kmerSize + 1;
+               
+               for(int j=0;j<numKmers;j++){
+                       int kmerNumber = kmer.getKmerNumber(seq, j);
+                       kmerLocations[kmerNumber].push_back(i);
+               }
+       }
+       
+       ofstream kmerFile(kmerDBName.c_str(), ios::trunc);
+       if(!kmerFile) {
+               cerr << "Error: Could not open " << kmerDBName << endl;
+               exit(1);
+       }
+       
+       for(int i=0;i<maxKmer;i++){
+               kmerFile << i << ' ' << kmerLocations[i].size();
+               for(int j=0;j<kmerLocations[i].size();j++){
+                       kmerFile << ' ' << kmerLocations[i][j];
+               }
+               kmerFile << endl;
+       }
+       kmerFile.close();
+       
+}
+
+/**************************************************************************************************/
+
+void KmerDB::readKmerDB(string kmerDBName, ifstream& kmerDBFile){
+
+       kmerDBFile.seekg(0);
+       
+       string seqName;
+       int seqNumber;
+       
+       for(int i=0;i<numSeqs;i++){
+               int numValues;
+               kmerDBFile >> seqName >> numValues;
+               
+               for(int j=0;j<numValues;j++){
+                       kmerDBFile >> seqNumber;
+                       kmerLocations[i].push_back(seqNumber);
+               }
+       }
+       kmerDBFile.close();
+}
+
+/**************************************************************************************************/
diff --git a/kmerdb.hpp b/kmerdb.hpp
new file mode 100644 (file)
index 0000000..0088efd
--- /dev/null
@@ -0,0 +1,27 @@
+#ifndef KMERDB_HPP
+#define KMERDB_HPP
+
+/*
+ *  kmerdb.h
+ *  
+ *
+ *  Created by Pat Schloss on 12/16/08.
+ *  Copyright 2008 Patrick D. Schloss. All rights reserved.
+ *
+ */
+
+class KmerDB : public Database {
+       
+public:
+       KmerDB(string, int);
+       Sequence* findClosestSequence(Sequence*);
+
+private:
+       void generateKmerDB(string);
+       void readKmerDB(string, ifstream&);
+       int kmerSize;
+       int maxKmer;
+       vector<vector<int> > kmerLocations;
+};
+
+#endif
diff --git a/listvector.cpp b/listvector.cpp
new file mode 100644 (file)
index 0000000..3af7cfe
--- /dev/null
@@ -0,0 +1,330 @@
+/*
+ *  list.cpp
+ *  
+ *
+ *  Created by Pat Schloss on 8/8/08.
+ *  Copyright 2008 Patrick D. Schloss. All rights reserved.
+ *
+ */
+
+using namespace std;
+
+#include <map>
+#include <exception>
+#include "sabundvector.hpp"
+#include "rabundvector.hpp"
+#include "ordervector.hpp"
+#include "datavector.hpp"
+#include "utilities.hpp"
+#include "listvector.hpp"
+
+
+/***********************************************************************/
+
+ListVector::ListVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0){};
+
+/***********************************************************************/
+
+ListVector::ListVector(int n): DataVector(), data(n, "") , maxRank(0), numBins(0), numSeqs(0){};
+
+/***********************************************************************/
+
+ListVector::ListVector(string id, vector<string> lv) : DataVector(id), data(lv){
+       try {
+               for(int i=0;i<data.size();i++){
+                       if(data[i] != ""){
+                               int binSize = getNumNames(data[i]);
+                               numBins = i+1;
+                               if(binSize > maxRank)   {       maxRank = binSize;      }
+                               numSeqs += binSize;
+                       }
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ListVector class Function ListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ListVector class function ListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+/**********************************************************************/
+
+ListVector::ListVector(ifstream& f) : DataVector(), maxRank(0), numBins(0), numSeqs(0) {
+       try {
+               int hold;
+               f >> label >> hold;
+       
+               data.assign(hold, "");
+               string inputData = "";
+       
+               for(int i=0;i<hold;i++){
+                       f >> inputData;
+                       set(i, inputData);
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ListVector class Function ListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ListVector class function ListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+/***********************************************************************/
+
+void ListVector::set(int binNumber, string seqNames){
+       try {
+               int nNames_old = getNumNames(data[binNumber]);
+               data[binNumber] = seqNames;
+               int nNames_new = getNumNames(seqNames);
+       
+               if(nNames_old == 0)                     {       numBins++;                              }
+               if(nNames_new == 0)                     {       numBins--;                              }
+               if(nNames_new > maxRank)        {       maxRank = nNames_new;   }
+       
+               numSeqs += (nNames_new - nNames_old);
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ListVector class Function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ListVector class function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+/***********************************************************************/
+
+string ListVector::get(int index){
+       return data[index];
+}
+
+/***********************************************************************/
+
+void ListVector::push_back(string seqNames){
+       try {
+               data.push_back(seqNames);
+               int nNames = getNumNames(seqNames);
+       
+               numBins++;
+       
+               if(nNames > maxRank)    {       maxRank = nNames;       }
+       
+               numSeqs += nNames;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ListVector class Function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ListVector class function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+/***********************************************************************/
+
+void ListVector::resize(int size){
+       data.resize(size);              
+}
+
+/***********************************************************************/
+
+int ListVector::size(){
+       return data.size();
+}
+/***********************************************************************/
+
+void ListVector::clear(){
+       numBins = 0;
+       maxRank = 0;
+       numSeqs = 0;
+       return data.clear();
+       
+}
+
+/***********************************************************************/
+
+void ListVector::print(ostream& output){
+       try {
+               output << label << '\t' << numBins << '\t';
+       
+               for(int i=0;i<data.size();i++){
+                       if(data[i] != ""){
+                               output << data[i] << '\t';
+                       }
+               }
+               output << endl;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ListVector class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ListVector class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+
+/***********************************************************************/
+
+RAbundVector ListVector::getRAbundVector(){
+       try {
+               RAbundVector rav;
+       
+               for(int i=0;i<data.size();i++){
+                       int binSize = getNumNames(data[i]);
+                       rav.push_back(binSize);
+               }
+       
+       //  This was here before to output data in a nice format, but it screws up the name mapping steps
+       //      sort(rav.rbegin(), rav.rend());
+       //      
+       //      for(int i=data.size()-1;i>=0;i--){
+       //              if(rav.get(i) == 0){    rav.pop_back(); }
+       //              else{
+       //                      break;
+       //              }
+       //      }
+               rav.setLabel(label);
+       
+               return rav;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ListVector class Function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ListVector class function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+/***********************************************************************/
+
+SAbundVector ListVector::getSAbundVector(){
+       try {
+               SAbundVector sav(maxRank+1);
+       
+               for(int i=0;i<data.size();i++){
+                       int binSize = getNumNames(data[i]);     
+                       sav.set(binSize, sav.get(binSize) + 1); 
+               }
+               sav.set(0, 0);
+               sav.setLabel(label);
+       
+               return sav;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ListVector class Function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ListVector class function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+/***********************************************************************/
+SharedOrderVector* ListVector::getSharedOrderVector(){
+       globaldata = GlobalData::getInstance();
+       string groupName, names, name;
+       groupmap = globaldata->gGroupmap;
+       SharedOrderVector* order;
+       order = new SharedOrderVector();
+       order->setLabel(label);
+       
+       for(int i=0;i<numBins;i++){
+               int binSize = getNumNames(get(i));      //find number of individual in given bin        
+               names = get(i);
+               while (names.find_first_of(',') != -1) { 
+                       name = names.substr(0,names.find_first_of(','));
+                       names = names.substr(names.find_first_of(',')+1, names.length());
+                       groupName = groupmap->getGroup(name);
+                       order->push_back(i, binSize, groupName);  //i represents what bin you are in
+               }
+               //get last name
+               groupName = groupmap->getGroup(names);
+               order->push_back(i, binSize, groupName);
+       }
+       random_shuffle(order->begin(), order->end());
+       return order;
+}
+
+/***********************************************************************/
+
+OrderVector ListVector::getOrderVector(map<string,int>* orderMap = NULL){
+       
+       try {
+               if(orderMap == NULL){
+                       OrderVector ov;
+               
+                       for(int i=0;i<data.size();i++){
+                               int binSize = getNumNames(data[i]);             
+                               for(int j=0;j<binSize;j++){
+                                       ov.push_back(i);
+                               }
+                       }
+                       random_shuffle(ov.begin(), ov.end());
+                       ov.setLabel(label);
+                       ov.getNumBins();
+               
+                       return ov;
+               
+               }
+               else{
+                       OrderVector ov(numSeqs);
+               
+                       for(int i=0;i<data.size();i++){
+                               string listOTU = data[i];
+                               int length = listOTU.size();
+                               
+                               string seqName="";
+                       
+                               for(int j=0;j<length;j++){
+                               
+                                       if(listOTU[j] != ','){
+                                               seqName += listOTU[j];
+                                       }
+                                       else{
+                                               if(orderMap->count(seqName) == 0){
+                                                       cerr << seqName << " not found, check *.names file\n";
+                                                       exit(1);
+                                               }
+                                       
+                                               ov.set((*orderMap)[seqName], i);
+                                               seqName = "";
+                                       }                                               
+                               }
+                       
+                               if(orderMap->count(seqName) == 0){
+                                       cerr << seqName << " not found, check *.names file\n";
+                                       exit(1);
+                               }
+                               ov.set((*orderMap)[seqName], i);        
+                       }
+               
+                       ov.setLabel(label);
+                       ov.getNumBins();
+               
+                       return ov;              
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ListVector class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ListVector class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+/***********************************************************************/
diff --git a/listvector.hpp b/listvector.hpp
new file mode 100644 (file)
index 0000000..dbd61cd
--- /dev/null
@@ -0,0 +1,50 @@
+#ifndef LIST_H
+#define LIST_H
+
+#include "datavector.hpp"
+#include "groupmap.h"
+#include "globaldata.hpp"
+#include "sharedordervector.h"
+#include <iostream>
+#include <map>
+
+
+class ListVector : public DataVector {
+       
+public:
+       ListVector();
+       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(ifstream&);
+       ~ListVector(){};
+       
+       int getNumBins()                                                        {       return numBins;         }
+       int getNumSeqs()                                                        {       return numSeqs;         }
+       int getMaxRank()                                                        {       return maxRank;         }
+
+       void set(int, string);  
+       string get(int);
+       void push_back(string);
+       void resize(int);
+       void clear();
+       int size();
+       void print(ostream&);
+       
+       RAbundVector getRAbundVector();
+       SAbundVector getSAbundVector();
+       OrderVector getOrderVector(map<string,int>*);
+       SharedOrderVector* getSharedOrderVector();
+       
+private:
+       vector<string> data;
+       GlobalData* globaldata;
+       GroupMap* groupmap;
+       int maxRank;
+       int numBins;
+       int numSeqs;
+
+};
+
+#endif
diff --git a/mothur.cpp b/mothur.cpp
new file mode 100644 (file)
index 0000000..2b3f8f5
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ *  interface.cpp
+ *  
+ *
+ *  Created by Pat Schloss on 8/14/08.
+ *  Copyright 2008 Patrick D. Schloss. All rights reserved.
+ *
+ */
+#include <string>
+#include <iostream>
+#include <iomanip>
+#include <fstream>
+#include <sstream>
+#include <exception>
+
+#include "engine.hpp"
+#include "globaldata.hpp"
+
+using namespace std;
+
+GlobalData* GlobalData::_uniqueInstance = 0;
+
+int main(int argc, char *argv[]){
+       try {
+       //      srand(54321);
+               srand( (unsigned)time( NULL ) );
+
+               Engine* dotur;
+               bool bail = 0;
+
+               if(argc>1){
+                       dotur = new BatchEngine(argv[1]);
+               }
+               else{
+                       dotur = new InteractEngine();           
+               }
+
+               while(bail == 0)                {       bail = dotur->getInput();                       }
+       
+               delete dotur;
+       
+               return 0;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the dotur class Function main. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the dotur class function main. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
diff --git a/nameassignment.cpp b/nameassignment.cpp
new file mode 100644 (file)
index 0000000..1f2feac
--- /dev/null
@@ -0,0 +1,97 @@
+using namespace std;
+
+#include <string>
+#include <map>
+#include <exception>
+
+#include "nameassignment.hpp"
+
+//**********************************************************************************************************************
+
+NameAssignment::NameAssignment(string nameMapFile){
+       
+       openInputFile(nameMapFile, fileHandle);
+       
+}
+
+//**********************************************************************************************************************
+
+void NameAssignment::readMap(int colA, int colB){
+       try{
+               string firstCol, secondCol, skip;
+       //      int index = 0;
+       
+               int skipNCols = colB-colA-1;
+       
+               map<string, string> data;
+       
+               while(fileHandle){
+                       fileHandle >> firstCol;                         //read from first column
+               
+                       for(int i=0;i<skipNCols;i++){           //allows for anticipated file format
+                               fileHandle >> skip;
+                       }
+               
+                       fileHandle >> secondCol;                        //read from second column
+               
+                       data[firstCol] = secondCol;                     //store data in map
+               
+                       gobble(fileHandle);
+               }
+               fileHandle.close();
+       
+               int rowIndex = 0;
+               map<string, string>::iterator it = data.begin();
+               for(it;it!=data.end();it++){
+                       list.push_back(it->second);             //adds data's value to list
+                       (*this)[it->first] = rowIndex;
+                       rowIndex++;
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the NameAssignment class Function readMap. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the NameAssignment class function readMap. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+//**********************************************************************************************************************
+
+ListVector NameAssignment::getListVector(void){
+
+       return list;
+       
+}
+
+//**********************************************************************************************************************
+
+void NameAssignment::print(void){
+       try {
+               map<string,int>::iterator it = (*this).begin();
+               for(it;it!=(*this).end();it++){
+                       cout << it->first << '\t' << it->second << endl;  //prints out keys and values of the map this.
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the NameAssignment class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the NameAssignment class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+//**********************************************************************************************************************
+
+int NameAssignment::get(string key){
+       
+       return  (*this)[key];   
+
+}
+
+//**********************************************************************************************************************
+
diff --git a/nameassignment.hpp b/nameassignment.hpp
new file mode 100644 (file)
index 0000000..f3a99fb
--- /dev/null
@@ -0,0 +1,26 @@
+#ifndef NAMEASSIGNMENT_HPP
+#define NAMEASSIGNMENT_HPP
+
+using namespace std;
+
+#include <string>
+#include <map>
+#include "utilities.hpp"
+#include "listvector.hpp"
+
+class NameAssignment : public map<string,int> {
+public:
+       NameAssignment(string);
+       void readMap(int, int);
+       ListVector getListVector();
+       int get(string);
+       void print();
+private:
+       ifstream fileHandle;
+       ListVector list;
+};
+
+
+
+
+#endif
diff --git a/nocommand.cpp b/nocommand.cpp
new file mode 100644 (file)
index 0000000..b585318
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ *  nocommand.cpp
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/2/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "nocommand.h"
+
+//**********************************************************************************************************************
+
+NoCommand::NoCommand(){}
+
+//**********************************************************************************************************************
+
+NoCommand::~NoCommand(){}
+
+//**********************************************************************************************************************
+
+int NoCommand::execute(){
+       //Could choose to give more help here?fdsah
+       cout << "Invalid command - choices are read.phylip(), read.column(), read.list(), read.rabund(), read.sabund(), cluster(), collect(), collect.shared(), parselist(), shared(), rarefaction(), summary(), summary.shared(), quit(), help()." << "\n";
+       cout << "For more information on command parameters use the help() command." << "\n";
+       return 0;
+}
+
+//**********************************************************************************************************************
diff --git a/nocommand.h b/nocommand.h
new file mode 100644 (file)
index 0000000..ce202e4
--- /dev/null
@@ -0,0 +1,28 @@
+#ifndef NOCOMMAND_H
+#define NOCOMMAND_H
+/*
+ *  nocommand.h
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/2/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+/* This command is run if the user enters an invalid command. */
+
+#include <Carbon/Carbon.h>
+#include "command.hpp"
+
+class NoCommand : public Command {
+
+public:
+       NoCommand();
+       ~NoCommand();
+       int execute();
+       
+private:
+               
+};
+
+#endif
\ No newline at end of file
diff --git a/npshannon.cpp b/npshannon.cpp
new file mode 100644 (file)
index 0000000..4ff2611
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ *  npshannon.cpp
+ *  Dotur
+ *
+ *  Created by John Westcott on 1/7/09.
+ *  Copyright 2009 __MyCompanyName__. All rights reserved.
+ *
+ */
+
+#include "npshannon.h"
+
+/***********************************************************************/
+
+
+EstOutput NPShannon::getValues(SAbundVector* rank){
+       try {
+               data.resize(1,0);
+               float npShannon = 0.0000;
+       
+               double maxRank = (double)rank->getMaxRank();
+               int sampled = rank->getNumSeqs();
+       
+               double Chat = 1.0000 - (double)rank->get(1)/(double)sampled;
+       
+               if(Chat>0)      {       
+                       for(int i=1;i<=maxRank;i++){
+                               double pi = ((double) i)/((double)sampled);
+                               double ChatPi = Chat*pi;
+                               if(ChatPi>0){
+                                       npShannon += rank->get(i) * ChatPi*log(ChatPi)/(1-pow(1-ChatPi,(double)sampled));
+                               }
+                       }
+                       npShannon = -npShannon;
+               }
+               else{
+                       npShannon = 0.000;
+               }
+       
+               data[0] = npShannon;
+               
+               if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; }
+               
+               return data;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the NPShannon class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the NPShannon class function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+/***********************************************************************/
diff --git a/npshannon.h b/npshannon.h
new file mode 100644 (file)
index 0000000..4a633b3
--- /dev/null
@@ -0,0 +1,33 @@
+#ifndef NPSHANNON_H
+#define NPSHANNON_H
+
+/*
+ *  npshannon.h
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/7/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+/* This class implements the NPShannon estimator on single group. 
+It is a child of the calculator class. */
+
+#include <Carbon/Carbon.h>
+#include "calculator.h"
+
+/***********************************************************************/
+
+class NPShannon : public Calculator  {
+       
+public:
+       NPShannon() : Calculator("NPShannon", 1) {};
+       EstOutput getValues(SAbundVector*);
+       EstOutput getValues(SharedRAbundVector*, SharedRAbundVector*) {return data;};
+private:
+       
+};
+
+/***********************************************************************/
+
+#endif
\ No newline at end of file
diff --git a/observable.h b/observable.h
new file mode 100644 (file)
index 0000000..616ef0d
--- /dev/null
@@ -0,0 +1,21 @@
+#ifndef OBSERVABLE_H
+#define OBSERVABLE_H
+
+
+#include "collectdisplay.h"
+
+using namespace std;
+
+/***********************************************************************/
+
+class Observable {
+       
+public:
+       virtual void registerDisplay(Display*) = 0;
+       virtual void removeDisplay(Display*) = 0;
+       virtual void notifyDisplays() = 0;      
+};
+
+/***********************************************************************/
+
+#endif
diff --git a/ordervector.cpp b/ordervector.cpp
new file mode 100644 (file)
index 0000000..8732c8a
--- /dev/null
@@ -0,0 +1,261 @@
+/*
+ *  order.cpp
+ *  
+ *
+ *  Created by Pat Schloss on 8/8/08.
+ *  Copyright 2008 Patrick D. Schloss. All rights reserved.
+ *
+ */
+
+using namespace std;
+
+#include "ordervector.hpp"
+#include "datavector.hpp"
+#include "utilities.hpp"
+#include <exception>
+
+/***********************************************************************/
+
+OrderVector::OrderVector() : DataVector() {}
+
+/***********************************************************************/
+
+//OrderVector::OrderVector(int ns) : DataVector(), data(ns, -1) {};
+
+/***********************************************************************/
+
+OrderVector::OrderVector(string id, vector<int> ov) : 
+                                                                                       DataVector(id), data(ov)
+{
+       updateStats();  
+}
+
+/***********************************************************************/
+
+OrderVector::OrderVector(ifstream& f) : DataVector() {
+       try {
+               int hold;
+       
+               f >> label;
+               f >> hold;
+       
+               data.assign(hold, -1);
+       
+               int inputData;
+       
+               for(int i=0;i<hold;i++){
+                       f >> inputData;
+                       set(i, inputData);
+               }
+       
+               updateStats();
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the OrderVector class Function OrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the OrderVector class function OrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+/***********************************************************************/
+
+
+int OrderVector::getNumBins(){
+       if(needToUpdate == 1){  updateStats();  }
+       return numBins;
+}
+
+/***********************************************************************/
+
+int OrderVector::getNumSeqs(){
+       if(needToUpdate == 1){  updateStats();  }
+       return numSeqs;
+}
+
+/***********************************************************************/
+
+int OrderVector::getMaxRank(){
+       if(needToUpdate == 1){  updateStats();  }
+       return maxRank;
+}
+
+/***********************************************************************/
+
+
+
+void OrderVector::set(int index, int binNumber){
+       
+       data[index] = binNumber;
+       needToUpdate = 1;
+       
+}
+
+/***********************************************************************/
+
+int OrderVector::get(int index){
+       return data[index];                     
+}
+
+/***********************************************************************/
+
+void OrderVector::push_back(int index){
+
+       data.push_back(index);
+       needToUpdate = 1;
+       
+}
+
+/***********************************************************************/
+
+void OrderVector::print(ostream& output){
+       try {
+               output << label << '\t' << numSeqs << '\t';
+       
+               for(int i=0;i<data.size();i++){
+                       output << data[i] << '\t';
+               }
+               output << endl;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the OrderVector class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the OrderVector class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+/***********************************************************************/
+
+void OrderVector::print(string prefix, ostream& output){
+       try {
+               output << prefix << '\t' << numSeqs << '\t';
+       
+               for(int i=0;i<numSeqs;i++){
+                       output << data[i] << '\t';
+               }
+               output << endl;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the OrderVector class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the OrderVector class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+/***********************************************************************/
+
+void OrderVector::resize(int){
+       cout << "resize() did nothing in class OrderVector";
+}
+
+/***********************************************************************/
+
+int OrderVector::size(){
+       return data.size();                                     
+}
+
+/***********************************************************************/
+
+vector<int>::iterator OrderVector::begin(){
+       return data.begin();    
+}
+
+/***********************************************************************/
+
+vector<int>::iterator OrderVector::end(){
+       return data.end();              
+}
+
+/***********************************************************************/
+
+RAbundVector OrderVector::getRAbundVector(){
+       try {
+               RAbundVector rav(data.size());
+       
+               for(int i=0;i<numSeqs;i++){
+                       rav.set(data[i], rav.get(data[i]) + 1);
+               }       
+               sort(rav.rbegin(), rav.rend());
+               for(int i=numSeqs-1;i>=0;i--){
+                       if(rav.get(i) == 0){    rav.pop_back(); }
+                       else{
+                               break;
+                       }
+               }
+               rav.setLabel(label);
+
+               return rav;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the OrderVector class Function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the OrderVector class function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+/***********************************************************************/
+
+SAbundVector OrderVector::getSAbundVector(){
+       
+       RAbundVector rav(this->getRAbundVector());
+       return rav.getSAbundVector();
+
+}
+
+/***********************************************************************/
+
+OrderVector OrderVector::getOrderVector(map<string,int>* hold = 0){
+       return *this;                   
+}
+
+/***********************************************************************/
+
+void OrderVector::updateStats(){
+       try {
+               needToUpdate = 0;
+       //      int maxBinVectorLength = 0;
+               numSeqs = 0;
+               numBins = 0;
+               maxRank = 0;
+       
+               for(int i=0;i<data.size();i++){
+                       if(data[i] != -1){
+                               numSeqs++;
+                       }
+               }
+       
+               vector<int> hold(numSeqs);
+       
+               for(int i=0;i<numSeqs;i++){
+                       if(data[i] != -1){
+                               hold[data[i]] = hold[data[i]]+1;
+                       }
+               }       
+               for(int i=0;i<numSeqs;i++){
+                       if(hold[i] > 0)                 {       numBins++;                      }
+                       if(hold[i] > maxRank)   {       maxRank = hold[i];      }
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the OrderVector class Function updateStats. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the OrderVector class function updateStats. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+/***********************************************************************/
+
diff --git a/ordervector.hpp b/ordervector.hpp
new file mode 100644 (file)
index 0000000..92259a8
--- /dev/null
@@ -0,0 +1,51 @@
+#ifndef ORDER_H
+#define ORDER_H
+
+#include "datavector.hpp"
+#include "sabundvector.hpp"
+#include "rabundvector.hpp"
+
+
+class OrderVector : public DataVector {
+       
+public:
+       OrderVector();
+//     OrderVector(int);
+//     OrderVector(const OrderVector& ov);
+       OrderVector(int ns, int nb=0, int mr=0) : DataVector(), data(ns, -1), maxRank(0), numBins(0), numSeqs(0) {};
+       OrderVector(const OrderVector& ov)      : DataVector(ov.label), data(ov.data), maxRank(ov.maxRank), numBins(ov.numBins), numSeqs(ov.numSeqs), needToUpdate(ov.needToUpdate) {if(needToUpdate == 1){     updateStats();}};
+
+
+       OrderVector(string, vector<int>);
+       OrderVector(ifstream&);
+       ~OrderVector(){};
+       
+       void set(int, int);
+       int get(int);
+       void push_back(int);
+       void resize(int);
+       int size();
+       void print(string, ostream&);
+       vector<int>::iterator begin();
+       vector<int>::iterator end();
+
+       void print(ostream&);
+
+       int getNumBins();
+       int getNumSeqs();
+       int getMaxRank();
+               
+       RAbundVector getRAbundVector();
+       SAbundVector getSAbundVector();
+       OrderVector getOrderVector(map<string,int>*);
+       
+private:
+       vector<int> data;
+       int maxRank;
+       int numBins;
+       int numSeqs;
+       bool needToUpdate;
+       void updateStats();
+};
+
+#endif
diff --git a/parselistcommand.cpp b/parselistcommand.cpp
new file mode 100644 (file)
index 0000000..8a848e7
--- /dev/null
@@ -0,0 +1,153 @@
+/*
+ *  parselistcommand.cpp
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/2/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "parselistcommand.h"
+
+//**********************************************************************************************************************
+ParseListCommand::ParseListCommand(){
+       try {
+               globaldata = GlobalData::getInstance();
+               
+               //read in group map info.
+               groupMap = new GroupMap(globaldata->getGroupFile());
+               groupMap->readMap();
+                       
+               //fill filehandles with neccessary ofstreams
+               int i;
+               ofstream* temp;
+               for (i=0; i<groupMap->getNumGroups(); i++) {
+                       temp = new ofstream;
+                       filehandles[groupMap->namesOfGroups[i]] = temp;
+               }
+               
+               //set fileroot
+               if(globaldata->getFileRoot() != ""){
+                       fileroot = globaldata->getFileRoot();
+               }
+               else{
+                       fileroot = getRootName(globaldata->getDistFile());
+               }
+               
+               //open output list files
+               for (i=0; i<groupMap->getNumGroups(); i++) {//opens an output file for each group
+                       openOutputFile(fileroot + groupMap->namesOfGroups[i] + ".list", *(filehandles[groupMap->namesOfGroups[i]]));
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ParseListCommand class Function ParseListCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ParseListCommand class function ParseListCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+/***********************************************************************/
+void ParseListCommand::parse(int index) {
+       try {
+               string prefix, suffix, groupsName;
+               suffix = list->get(index);
+       
+               while (suffix.find_first_of(',') != -1) {//while you still have sequences
+                       prefix = suffix.substr(0,suffix.find_first_of(','));
+                       if ((suffix.find_first_of(',')+1) <= suffix.length()) {  //checks to make sure you don't have comma at end of string
+                               suffix = suffix.substr(suffix.find_first_of(',')+1, suffix.length());
+                       }
+                       
+                       groupsName = groupMap->getGroup(prefix);
+                       if (groupsName != "not found") {
+                               listGroups[groupsName] = listGroups[groupsName] + "," + prefix; //adds prefix to the correct group.
+                       }else {
+                               cerr << "Error: Sequence '" << prefix << "' was not found in the group file, please correct\n";
+                       }
+               }
+               
+               //save last name after comma
+               groupsName = groupMap->getGroup(suffix);
+               if (groupsName != "not found") {
+                       listGroups[groupsName] = listGroups[groupsName] + "," + suffix; //adds prefix to the correct group.
+               }else {
+                       cerr << "Error: Sequence '" << suffix << "' was not found in the group file, please correct\n";
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ParseListCommand class Function parse. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ParseListCommand class function parse. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+//**********************************************************************************************************************
+
+int ParseListCommand::execute(){
+       try{
+                       globaldata = GlobalData::getInstance();
+                       
+                       //read in listfile
+                       read = new ReadPhilFile(globaldata->inputFileName);     
+                       read->read(&*globaldata); 
+                       input = globaldata->ginput;
+                       //list = input->getListVector();
+                       list = globaldata->glist;
+
+                       //read in group map info.
+                       groupMap = new GroupMap(globaldata->getGroupFile());
+                       groupMap->readMap();
+                       
+                       string seq, label;
+                       int i;
+                       //create new list vectors to fill with parsed data
+                       for (i=0; i<groupMap->getNumGroups(); i++) {
+                               groupOfLists[groupMap->namesOfGroups[i]] = new ListVector();
+                       }
+                       
+                       //parses and sets each groups listvector
+                       while(list != NULL){
+                               label = list->getLabel();
+                               for(i=0; i<list->size(); i++) {
+                                       parse(i); //parses data[i] list of sequence names
+                                       for (it=listGroups.begin(); it != listGroups.end(); it++) {  //loop through map and set new list vectors
+                                               seq = it->second;
+                                               seq = seq.substr(1, seq.length()); //rips off extra comma
+                                               groupOfLists[it->first]->push_back(seq); //sets new listvector for each group
+                                       }
+                                       listGroups.clear();
+                               }
+                               //prints each new list file
+                               for (i=0; i<groupMap->getNumGroups(); i++) {
+                                       groupOfLists[groupMap->namesOfGroups[i]]->setLabel(label);
+                                       groupOfLists[groupMap->namesOfGroups[i]]->print(*(filehandles[groupMap->namesOfGroups[i]]));
+                                       groupOfLists[groupMap->namesOfGroups[i]]->clear();
+                               }
+                               list = input->getListVector();
+                       }
+                       return 0;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ParseListCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ParseListCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+
+}
+//**********************************************************************************************************************
+
+ParseListCommand::~ParseListCommand(){
+       delete list;
+       delete groupMap;
+       delete input;
+       delete read;    
+}
+//**********************************************************************************************************************
diff --git a/parselistcommand.h b/parselistcommand.h
new file mode 100644 (file)
index 0000000..c986e4f
--- /dev/null
@@ -0,0 +1,56 @@
+#ifndef PARSELISTCOMMAND_H
+#define PARSELISTCOMMAND_H
+/*
+ *  parselistcommand.h
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/2/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include <Carbon/Carbon.h>
+#include <iostream>
+#include <fstream>
+#include <map>
+#include "command.hpp"
+#include "rabundvector.hpp"
+#include "listvector.hpp"
+#include "inputdata.h"
+#include "groupmap.h"
+#include "readmatrix.hpp"
+
+
+/* The parselist() command:
+       The parselist command is similar to the shared command.  
+       It parses a list file and separates it into groups.   It outputs a .list file for each group.  
+       The parselist command parameter options are listfile and groupfile.  
+       The parselist command should be in the following format: parselist(listfile=yourListFile, groupfile=yourGroupFile). 
+       The listfile parameter and groupfile paramater are required.  */
+
+class GlobalData;
+
+class ParseListCommand : public Command {
+       
+public:
+       ParseListCommand();     
+       ~ParseListCommand();
+       int execute();  
+       
+private:
+       GlobalData* globaldata;
+       GroupMap* groupMap;
+       InputData* input;
+       ReadMatrix* read;
+       map<string, ofstream*> filehandles;
+       map<string, ListVector*> groupOfLists;
+       ListVector* list;
+       map<string, string> listGroups; //maps group name to sequences from that group in a specific OTU
+       map<string, string>::iterator it;
+       map<string, ListVector*>::iterator it2;
+       map<string, ofstream*>::iterator it3;
+       void parse(int);
+       string fileroot;
+};
+
+#endif
\ No newline at end of file
diff --git a/progress.cpp b/progress.cpp
new file mode 100644 (file)
index 0000000..94ad416
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+ *  progress.cpp
+ *  
+ *
+ *  Created by Pat Schloss on 8/14/08.
+ *  Copyright 2008 Patrick D. Schloss. All rights reserved.
+ *
+ */
+
+#include <iostream>
+#include <string>
+#include "progress.hpp"
+#include <exception>
+
+using namespace std;
+
+const int totalTicks = 50;
+const char marker = '|';
+
+
+/***********************************************************************/
+
+Progress::Progress(string job, int end){
+       try {
+               cout << "*******************#****#****#****#****#****#****#****#****#****#****#\n";
+               cout << job << marker;
+               cout.flush();
+       
+               nTicks = 0;
+               finalPos = end;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the Progress class Function Progress. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the Progress class function Progress. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+/***********************************************************************/
+
+void Progress::update(const int currentPos){
+       try {
+               int ratio = int(totalTicks * (float)currentPos / finalPos);
+       
+               if(ratio > nTicks){
+                       for(int i=nTicks;i<ratio;i++){
+                               cout << marker;
+                               cout.flush();
+                       }
+                       nTicks = ratio;
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the Progress class Function update. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the Progress class function update. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+/***********************************************************************/
+
+void Progress::finish(){
+       try {
+               for(int i=nTicks;i<totalTicks;i++){
+                       cout << marker;
+                       cout.flush();
+               }
+       
+       
+               cout << endl;
+               cout << "**********************************************************************\n";
+               cout.flush();
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the Progress class Function finish. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the Progress class function finish. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+/***********************************************************************/
diff --git a/progress.hpp b/progress.hpp
new file mode 100644 (file)
index 0000000..82eed70
--- /dev/null
@@ -0,0 +1,19 @@
+#ifndef PROGRESS_H
+#define PROGRESS_H
+
+#include <string>
+using namespace std;
+
+class Progress {
+       
+public:
+       Progress(string, int);
+       void update(int);
+       void finish();
+       
+private:
+       int nTicks;
+       int finalPos;   
+};
+
+#endif
diff --git a/quitcommand.cpp b/quitcommand.cpp
new file mode 100644 (file)
index 0000000..6b90f4b
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ *  quitcommand.cpp
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/2/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "quitcommand.h"
+
+//**********************************************************************************************************************
+
+QuitCommand::QuitCommand(){}
+
+//**********************************************************************************************************************
+
+QuitCommand::~QuitCommand(){}
+
+//**********************************************************************************************************************
+
+int QuitCommand::execute(){
+       return 1;
+}
+
+//**********************************************************************************************************************
diff --git a/quitcommand.h b/quitcommand.h
new file mode 100644 (file)
index 0000000..c54e7f2
--- /dev/null
@@ -0,0 +1,30 @@
+#ifndef QUITCOMMAND_H
+#define QUITCOMMAND_H
+/*
+ *  quitcommand.h
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/2/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include <Carbon/Carbon.h>
+#include "command.hpp"
+
+/* The quit() command:
+       The quit command terminates the mothur program. 
+       The quit command should be in the following format: quit ().   */
+
+
+class QuitCommand : public Command {
+       
+public:
+       QuitCommand();
+       ~QuitCommand();
+       int execute();
+       
+private:
+               
+};
+#endif
\ No newline at end of file
diff --git a/rabundvector.cpp b/rabundvector.cpp
new file mode 100644 (file)
index 0000000..fd7f3ac
--- /dev/null
@@ -0,0 +1,289 @@
+/*
+ *  rabundvector.cpp
+ *  
+ *
+ *  Created by Pat Schloss on 8/8/08.
+ *  Copyright 2008 Patrick D. Schloss. All rights reserved.
+ *
+ */
+using namespace std;
+#include "datavector.hpp"
+#include "utilities.hpp"
+#include <exception>
+#include "rabundvector.hpp"
+#include "sabundvector.hpp"
+#include "ordervector.hpp"
+
+
+/***********************************************************************/
+
+RAbundVector::RAbundVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0) {};
+
+/***********************************************************************/
+
+RAbundVector::RAbundVector(int n) : DataVector(), data(n,0) , maxRank(0), numBins(0), numSeqs(0) {};
+
+/***********************************************************************/
+
+//RAbundVector::RAbundVector(const RAbundVector& rav) : DataVector(rav), data(rav.data), (rav.label),  (rav.maxRank), (rav.numBins), (rav.numSeqs){};
+
+
+/***********************************************************************/
+
+RAbundVector::RAbundVector(string id, vector<int> rav) : DataVector(id), data(rav) {
+       try {
+               numBins = 0;
+               maxRank = 0;
+               numSeqs = 0;
+               
+               for(int i=0;i<data.size();i++){
+                       if(data[i] != 0)                {       numBins = i+1;          }
+                       if(data[i] > maxRank)   {       maxRank = data[i];      }
+                       numSeqs += data[i];
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function RAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the RAbundVector class function RAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+
+/***********************************************************************/
+
+
+RAbundVector::RAbundVector(ifstream& f) : DataVector(), maxRank(0), numBins(0), numSeqs(0) {
+       try {
+               int hold;
+               f >> label >> hold;
+       
+               data.assign(hold, 0);
+               int inputData;
+       
+               for(int i=0;i<hold;i++){
+                       f >> inputData;
+                       set(i, inputData);
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function RAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the RAbundVector class function RAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+/***********************************************************************/
+
+RAbundVector::~RAbundVector() {
+
+}
+
+/***********************************************************************/
+
+void RAbundVector::set(int binNumber, int newBinSize){
+       try {
+               int oldBinSize = data[binNumber];
+               data[binNumber] = newBinSize;
+       
+               if(oldBinSize == 0)                     {       numBins++;                              }
+               if(newBinSize == 0)                     {       numBins--;                              }
+               if(newBinSize > maxRank)        {       maxRank = newBinSize;   }
+       
+               numSeqs += (newBinSize - oldBinSize);
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the RAbundVector class function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+/***********************************************************************/
+
+int RAbundVector::get(int index){
+       return data[index];
+       
+}
+
+/***********************************************************************/
+
+void RAbundVector::push_back(int binSize){
+       try {
+               data.push_back(binSize);
+               numBins++;
+       
+               if(binSize > maxRank){
+                       maxRank = binSize;
+               }
+       
+               numSeqs += binSize;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the RAbundVector class function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+/***********************************************************************/
+
+void RAbundVector::pop_back(){
+
+       return data.pop_back();
+}
+
+/***********************************************************************/
+
+void RAbundVector::resize(int size){
+       
+       data.resize(size);
+}
+
+/***********************************************************************/
+
+int RAbundVector::size(){
+       return data.size();
+}
+
+/***********************************************************************/
+
+vector<int>::reverse_iterator RAbundVector::rbegin(){
+       return data.rbegin();                           
+}
+
+/***********************************************************************/
+
+vector<int>::reverse_iterator RAbundVector::rend(){
+       return data.rend();                                     
+}
+
+/***********************************************************************/
+void RAbundVector::print(string prefix, ostream& output){
+       try {   
+               output << prefix << '\t' << numBins << '\t';
+       
+               vector<int> hold = data;
+               sort(hold.rbegin(), hold.rend());
+       
+               for(int i=0;i<numBins;i++){             output << hold[i] << '\t';              }
+               output << endl;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the RAbundVector class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+/***********************************************************************/
+void RAbundVector::print(ostream& output){
+       try {
+               output << label << '\t' << numBins << '\t';
+       
+               vector<int> hold = data;
+               sort(hold.rbegin(), hold.rend());
+               
+               for(int i=0;i<numBins;i++){             output << hold[i] << '\t';              }
+               output << endl;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the RAbundVector class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+/***********************************************************************/
+int RAbundVector::getNumBins(){
+       return numBins;
+}
+
+/***********************************************************************/
+
+int RAbundVector::getNumSeqs(){
+       return numSeqs;
+}
+
+/***********************************************************************/
+
+int RAbundVector::getMaxRank(){
+       return maxRank;
+}
+
+/***********************************************************************/
+
+RAbundVector RAbundVector::getRAbundVector(){
+       return *this;                   
+}
+
+/***********************************************************************/
+
+SAbundVector RAbundVector::getSAbundVector() {
+       try {
+               SAbundVector sav(maxRank+1);
+               
+               for(int i=0;i<data.size();i++){
+                       int abund = data[i];
+                       sav.set(abund, sav.get(abund) + 1);
+               }
+               sav.set(0, 0);
+               sav.setLabel(label);
+               return sav;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the RAbundVector class function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+/***********************************************************************/
+
+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);     
+               return ov;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the RAbundVector class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+/***********************************************************************/
diff --git a/rabundvector.hpp b/rabundvector.hpp
new file mode 100644 (file)
index 0000000..a0807e5
--- /dev/null
@@ -0,0 +1,45 @@
+#ifndef RABUND_H
+#define RABUND_H
+
+#include "datavector.hpp"
+
+class RAbundVector : public DataVector {
+       
+public:
+       RAbundVector();
+       RAbundVector(int);
+//     RAbundVector(const RAbundVector&);
+       RAbundVector(string, vector<int>);
+       RAbundVector(const RAbundVector& bv) : DataVector(bv), data(bv.data), maxRank(bv.maxRank), numBins(bv.numBins), numSeqs(bv.numSeqs){};
+       RAbundVector(ifstream&);
+       ~RAbundVector();
+
+       int getNumBins();               
+       int getNumSeqs();                                                       
+       int getMaxRank();                                                       
+
+       void set(int, int);     
+       int get(int);
+       void push_back(int);
+       void pop_back();
+       void resize(int);
+       int size();
+       vector<int>::reverse_iterator rbegin();
+       vector<int>::reverse_iterator rend();
+       
+       void print(ostream&);
+       void print(string, ostream&);
+       
+       RAbundVector getRAbundVector();
+       SAbundVector getSAbundVector();
+       OrderVector getOrderVector(map<string,int>*);
+       
+private:
+       vector<int> data;
+       int maxRank;
+       int numBins;
+       int numSeqs;    
+};
+
+
+#endif
diff --git a/rarecalc.cpp b/rarecalc.cpp
new file mode 100644 (file)
index 0000000..88c704a
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ *  rarecalc.cpp
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/7/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "rarecalc.h"
+
+/***********************************************************************/
+
+EstOutput RareCalc::getValues(int n){
+       try {
+               EstOutput output(3,0);
+
+               double richness = (double)numBins;
+               double varS = 0.0000;
+       
+               double varTerm1 = 0.0000;
+               double varTerm2 = 0.0000;
+       
+               double rSummation = 0;
+               for(int i=0;i<numBins;i++){
+                       int N_ni = numSeqs - bins->get(i);
+                       rSummation += (bMatrix[N_ni][n]);
+               
+                       varTerm1 += (bMatrix[N_ni][n] * (1.0 - bMatrix[N_ni][n] / bMatrix[numSeqs][n]));
+
+                       for(int j=i+1;j<numBins;j++){
+                               varTerm2 += ( bMatrix[N_ni-bins->get(j)][n] - bMatrix[N_ni][n] * bMatrix[numSeqs-bins->get(j)][n] / bMatrix[numSeqs][n]);
+                       }
+               
+               }
+               richness -= (rSummation / bMatrix[numSeqs][n]);
+               varS = (varTerm1 + 2 * varTerm2) / bMatrix[numSeqs][n];
+               float sd = pow(varS, 0.5);
+       
+
+               output[0] = richness;
+               output[1] = richness - 1.96 * sd;       
+               output[2] = richness + 1.96 * sd;
+       
+               return output;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the RareCalc class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the RareCalc class function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+/***********************************************************************/
diff --git a/rarecalc.h b/rarecalc.h
new file mode 100644 (file)
index 0000000..1079b96
--- /dev/null
@@ -0,0 +1,33 @@
+#ifndef RARECALC_H
+#define RARECALC_H
+/*
+ *  rarecalc.h
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/7/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+/* This class is not currently used by Mothur */
+
+
+#include <Carbon/Carbon.h>
+#include "calculator.h"
+
+/***********************************************************************/
+class RareCalc {
+
+public:
+       RareCalc(RAbundVector* b) : bins(b), numSeqs(b->getNumSeqs()), maxRank(b->getMaxRank()), numBins(b->getNumBins()) {     bMatrix = binomial(numSeqs+1);  };
+       EstOutput getValues(int);
+       string getName()        {       return "RareCalc";      }
+private:
+       RAbundVector* bins;
+       vector<vector<double> > bMatrix;
+       int numSeqs, maxRank, numBins;
+};
+
+/***********************************************************************/
+
+#endif
diff --git a/raredisplay.cpp b/raredisplay.cpp
new file mode 100644 (file)
index 0000000..e2c75e9
--- /dev/null
@@ -0,0 +1,175 @@
+/*
+ *  raredisplay.cpp
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 11/18/08.
+ *  Copyright 2008 __MyCompanyName__. All rights reserved.
+ *
+ */
+
+#include "raredisplay.h"
+
+/***********************************************************************/
+
+void RareDisplay::init(string label){
+       try {
+               this->label = label;
+               if(nIters != 1){
+                       openOutputFile(tempOutName, tempOutFile);
+                       openInputFile(tempInName, tempInFile);
+               }
+               else{
+                       openOutputFile(tempOutName, tempOutFile);
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the RareDisplay class Function init. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the RareDisplay class function init. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+/***********************************************************************/
+
+void RareDisplay::update(SAbundVector* rank){
+       try {
+               int newNSeqs = rank->getNumSeqs();
+               vector<double> data = estimate->getValues(rank);
+
+               if(nIters != 1){
+
+                       double oldNSeqs, oldMean, oldVar;
+               
+                       tempInFile >> oldNSeqs >> oldMean >> oldVar;
+               
+                       double oldS = oldVar * ( nIters - 2 );
+                       double delta = data[0] - oldMean;
+                       double newMean = oldMean + delta / nIters;
+                       double newS = oldS + delta * ( data[0] - newMean );
+                       double newVar = newS / ( nIters - 1 );
+
+                       tempOutFile << newNSeqs << '\t' << newMean << '\t' << newVar << endl;
+               }
+               else{
+                       tempOutFile << newNSeqs << '\t' << data[0] << '\t' << 0 << endl;
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the RareDisplay class Function update. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the RareDisplay class function update. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+};
+
+/***********************************************************************/
+void RareDisplay::update(SharedRAbundVector* shared1, SharedRAbundVector* shared2, int numSeqs, int numGroupComb) {
+       try {
+               vector<double> data = estimate->getValues(shared1, shared2); 
+               double newNSeqs = data[0];
+               
+               if(nIters != 1){
+                       double oldNSeqs, oldMean, oldVar;
+               
+                       tempInFile >> oldNSeqs >> oldMean >> oldVar;
+               
+                       double oldS = oldVar * ( nIters - 2 );
+                       double delta = data[0] - oldMean;
+                       double newMean = oldMean + delta / nIters;
+                       double newS = oldS + delta * ( data[0] - newMean );
+                       double newVar = newS / ( nIters - 1 );
+
+                       tempOutFile << newNSeqs << '\t' << newMean << '\t' << newVar << endl;
+               }
+               else{
+                       tempOutFile << newNSeqs << '\t' << data[0] << '\t' << 0 << endl;
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the RareDisplay class Function update. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the RareDisplay class function update. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+};
+
+/***********************************************************************/
+
+void RareDisplay::reset(){
+       try {
+               if(nIters != 1){
+                       tempOutFile.close();
+                       tempInFile.close();
+               }
+               else{
+                       tempOutFile.close();
+               }
+       
+               nIters++;
+       
+               remove(tempInName.c_str());
+               rename(tempOutName.c_str(), tempInName.c_str());        
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the RareDisplay class Function reset. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the RareDisplay class function reset. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+/***********************************************************************/
+
+void RareDisplay::close(){
+       try {
+               output->initFile(label);
+       
+               openInputFile(tempInName, tempInFile);
+       
+               while(!tempInFile.eof()){
+                       int nSeqs;
+                       tempInFile >> nSeqs;
+               
+                       vector<double> data(3,0);
+                       double variance = 0;
+               
+                       tempInFile >> data[0];
+                       tempInFile >> variance;
+               
+                       double ci = 1.96 * pow(variance, 0.5);
+                       data[1] = data[0] - ci;
+                       data[2] = data[0] + ci;
+               
+                       output->output(nSeqs, data);
+               
+                       gobble(tempInFile);
+               }
+               tempInFile.close();
+       
+               remove(tempInName.c_str());
+               remove(tempOutName.c_str());
+       
+               nIters = 1;
+               output->resetFile();
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the RareDisplay class Function close. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the RareDisplay class function close. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+/***********************************************************************/
+
diff --git a/raredisplay.h b/raredisplay.h
new file mode 100644 (file)
index 0000000..ad6a389
--- /dev/null
@@ -0,0 +1,38 @@
+#ifndef RAREDISPLAY_H
+#define RAREDISPLAY_H
+
+#include "sabundvector.hpp"
+#include "calculator.h"
+#include "fileoutput.h"
+#include "display.h"
+#include <vector>
+
+using namespace std;
+
+/***********************************************************************/
+
+class RareDisplay : public Display {
+       
+public:
+       RareDisplay(Calculator* calc, FileOutput* file) : estimate(calc), output(file), nIters(1),
+                                                       tempInName(getPathName(output->getFileName()) + ".tempin."+ getSimpleName(output->getFileName())), tempOutName(getPathName(output->getFileName()) + ".tempout."+ getSimpleName(output->getFileName())) {};
+       ~RareDisplay()                                  {       delete estimate; delete output;         };
+       void init(string);
+       void reset();
+       void update(SAbundVector*);
+       void update(SharedRAbundVector* shared1, SharedRAbundVector* shared2, int numSeqs, int numGroupComb);
+       void close();
+       
+private:
+       Calculator* estimate;
+       FileOutput* output;
+       string label;
+       int nIters;
+       string tempInName, tempOutName;
+       ifstream tempInFile;
+       ofstream tempOutFile;
+
+};
+
+#endif
+
diff --git a/rarefact.cpp b/rarefact.cpp
new file mode 100644 (file)
index 0000000..0be0327
--- /dev/null
@@ -0,0 +1,172 @@
+/*
+ *  rarefact.cpp
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 11/18/08.
+ *  Copyright 2008 __MyCompanyName__. All rights reserved.
+ *
+ */
+
+#include "rarefact.h"
+#include "ordervector.hpp"
+
+/***********************************************************************/
+
+void Rarefact::getCurve(int increment = 1, int nIters = 1000){
+       try {
+               RarefactionCurveData* rcd = new RarefactionCurveData();
+               for(int i=0;i<displays.size();i++){
+                       rcd->registerDisplay(displays[i]);
+               }
+       
+               for(int iter=0;iter<nIters;iter++){
+               
+                       for(int i=0;i<displays.size();i++){
+                               displays[i]->init(label);
+                       }
+               
+                       RAbundVector* lookup    = new RAbundVector(order->getNumBins());
+                       SAbundVector* rank      = new SAbundVector(order->getMaxRank()+1);
+                       random_shuffle(order->begin(), order->end());
+               
+                       for(int i=0;i<numSeqs;i++){
+                       
+                               int binNumber = order->get(i);
+                               int abundance = lookup->get(binNumber);
+                       
+                               rank->set(abundance, rank->get(abundance)-1);
+                               abundance++;
+               
+                               lookup->set(binNumber, abundance);
+                               rank->set(abundance, rank->get(abundance)+1);
+
+                               if((i == 0) || (i+1) % increment == 0){
+                                       rcd->updateRankData(rank);
+                               }
+                       }
+       
+                       if(numSeqs % increment != 0){
+                               rcd->updateRankData(rank);
+                       }
+
+                       for(int i=0;i<displays.size();i++){
+                               displays[i]->reset();
+                       }
+               }
+
+               for(int i=0;i<displays.size();i++){
+                       displays[i]->close();
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the Rarefact class Function getCurve. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the Rarefact class function getCurve. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+/***********************************************************************/
+
+void Rarefact::getSharedCurve(int increment = 1, int nIters = 1000){
+try {
+               globaldata = GlobalData::getInstance();
+               SharedRarefactionCurveData* rcd = new SharedRarefactionCurveData();
+               
+               //register the displays
+               for(int i=0;i<displays.size();i++){
+                       rcd->registerDisplay(displays[i]);
+               }
+
+               for(int iter=0;iter<nIters;iter++){
+                       //clear out old values for new iter
+                       lookup.clear();
+               
+                       //create and initialize vector of sharedvectors, one for each group
+                       for (int i = 0; i < globaldata->gGroupmap->getNumGroups(); i++) { 
+                               SharedRAbundVector* temp = new SharedRAbundVector(sharedorder->getNumBins());
+                               temp->setLabel(sharedorder->getLabel());
+                               temp->setGroup(globaldata->gGroupmap->namesOfGroups[i]);
+                               lookup.push_back(temp);
+                       }
+                       
+                       for(int i=0;i<displays.size();i++){
+                               displays[i]->init(label);                 
+                       }
+               
+                       //sample all the members
+                       for(int i=0;i<numSeqs;i++){
+                               //get first sample
+                               individual chosen = sharedorder->get(i);
+                               int abundance; 
+                                       
+                               //set info for sharedvector in chosens group
+                               for (int j = 0; j < lookup.size(); j++) { 
+                                       if (chosen.group == lookup[j]->getGroup()) {
+                                               abundance = lookup[j]->getAbundance(chosen.bin);
+                                               lookup[j]->set(chosen.bin, (abundance + 1), chosen.group);
+                                               break;
+                                       }
+                               }
+                       }
+                       
+                       //randomize the groups
+                       random_shuffle(lookup.begin(), lookup.end());
+               
+                       //send the first group
+                       rcd->updateSharedData(lookup[0], lookup[0], 1, numGroupComb);
+                               
+                       //send each additional group one at a time
+                       int n = 1;
+                       for (int k = 0; k < (lookup.size() - 1); k++) { 
+                               for (int l = n; l < lookup.size(); l++) {
+                                       rcd->updateSharedData(lookup[k], lookup[l], l+1, numGroupComb);
+                                       mergeVectors(lookup[0], lookup[l]);
+                               }
+                               n++;
+                       }
+
+                       //resets output files
+                       for(int i=0;i<displays.size();i++){
+                               displays[i]->reset();
+                       }
+               }
+               
+               for(int i=0;i<displays.size();i++){
+                       displays[i]->close();
+               }
+
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the Rarefact class Function getSharedCurve. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the Rarefact class function getSharedCurve. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+
+}
+
+/**************************************************************************************/
+void Rarefact::mergeVectors(SharedRAbundVector* shared1, SharedRAbundVector* shared2) {
+       try{
+               for (int k = 0; k < shared1->size(); k++) {
+                       //merge new species into shared1
+                       if ((shared1->getAbundance(k) == 0) && (shared2->getAbundance(k) != 0)) {
+                               shared1->set(k, shared2->getAbundance(k), "combo");  //set to 'combo' since this vector now contains multiple groups
+                       }
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the Rarefact class Function mergeVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the Rarefact class function mergeVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
diff --git a/rarefact.h b/rarefact.h
new file mode 100644 (file)
index 0000000..b4a4cfe
--- /dev/null
@@ -0,0 +1,38 @@
+#ifndef RAREFACT_H
+#define RAREFACT_H
+
+using namespace std;
+
+#include "rarefactioncurvedata.h"
+#include "raredisplay.h"
+#include "ordervector.hpp"
+
+
+
+class Rarefact {
+       
+public:
+       Rarefact(OrderVector* o, vector<Display*> disp) :
+                       numSeqs(o->getNumSeqs()), order(o), displays(disp), label(o->getLabel())  {};
+       Rarefact(SharedOrderVector* sharedorder, vector<Display*> disp) :
+                                       numSeqs(sharedorder->getNumSeqs()), sharedorder(sharedorder), displays(disp), label(sharedorder->getLabel())  {};
+
+       ~Rarefact(){};
+       void getCurve(int, int);
+       void getSharedCurve(int, int);
+       
+private:
+       SharedOrderVector* sharedorder;
+       GlobalData* globaldata;
+       OrderVector* order;
+       vector<Display*> displays;
+       int numSeqs, numGroupComb;
+       string label;
+       void mergeVectors(SharedRAbundVector*, SharedRAbundVector*);
+       vector<SharedRAbundVector*> lookup; 
+
+};
+
+
+#endif
+
diff --git a/rarefactcommand.cpp b/rarefactcommand.cpp
new file mode 100644 (file)
index 0000000..c2204e7
--- /dev/null
@@ -0,0 +1,114 @@
+/*
+ *  rarefactcommand.cpp
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/2/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "rarefactcommand.h"
+#include "ace.h"
+#include "sobs.h"
+#include "chao1.h"
+#include "bootstrap.h"
+#include "simpson.h"
+#include "npshannon.h"
+#include "shannon.h"
+#include "jackknife.h"
+
+//**********************************************************************************************************************
+
+
+RareFactCommand::RareFactCommand(){
+       try {
+               globaldata = GlobalData::getInstance();
+               string fileNameRoot;
+               fileNameRoot = getRootName(globaldata->inputFileName);
+               int i;
+               for (i=0; i<globaldata->rareEstimators.size(); i++) {
+                       if (globaldata->rareEstimators[i] == "sobs") { 
+                               rDisplays.push_back(new RareDisplay(new Sobs(), new ThreeColumnFile(fileNameRoot+"rarefaction")));
+                       }else if (globaldata->rareEstimators[i] == "chao") { 
+                               rDisplays.push_back(new RareDisplay(new Chao1(), new ThreeColumnFile(fileNameRoot+"r_chao")));
+                       }else if (globaldata->rareEstimators[i] == "ace") { 
+                               rDisplays.push_back(new RareDisplay(new Ace(), new ThreeColumnFile(fileNameRoot+"r_ace")));
+                       }else if (globaldata->rareEstimators[i] == "jack") { 
+                               rDisplays.push_back(new RareDisplay(new Jackknife(), new ThreeColumnFile(fileNameRoot+"r_jack")));
+                       }else if (globaldata->rareEstimators[i] == "shannon") { 
+                               rDisplays.push_back(new RareDisplay(new Shannon(), new ThreeColumnFile(fileNameRoot+"r_shannon")));
+                       }else if (globaldata->rareEstimators[i] == "npshannon") { 
+                               rDisplays.push_back(new RareDisplay(new NPShannon(), new ThreeColumnFile(fileNameRoot+"r_npshannon")));
+                       }else if (globaldata->rareEstimators[i] == "simpson") { 
+                               rDisplays.push_back(new RareDisplay(new Simpson(), new ThreeColumnFile(fileNameRoot+"r_simpson")));
+                       }else if (globaldata->rareEstimators[i] == "bootstrap") { 
+                               rDisplays.push_back(new RareDisplay(new Bootstrap(), new ThreeColumnFile(fileNameRoot+"r_bootstrap")));
+                       }
+               }
+       
+       
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the RareFactCommand class Function RareFactCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the RareFactCommand class function RareFactCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+                       
+}
+
+//**********************************************************************************************************************
+
+RareFactCommand::~RareFactCommand(){
+       delete order;
+       delete input;
+       delete rCurve;
+       delete read;
+}
+
+//**********************************************************************************************************************
+
+int RareFactCommand::execute(){
+       try {
+               int count = 1;
+               read = new ReadPhilFile(globaldata->inputFileName);     
+               read->read(&*globaldata); 
+
+               order = globaldata->gorder;
+               input = globaldata->ginput;
+       
+               while(order != NULL){
+               
+                       if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
+                       
+                               rCurve = new Rarefact(order, rDisplays);
+                               convert(globaldata->getFreq(), freq);
+                               convert(globaldata->getIters(), nIters);
+                               rCurve->getCurve(freq, nIters);
+                       
+                               delete rCurve;
+                       
+                               cout << order->getLabel() << '\t' << count << endl;
+                       }
+               
+                       order = (input->getOrderVector());
+                       count++;
+               
+               }
+       
+               for(int i=0;i<rDisplays.size();i++){    delete rDisplays[i];    }       
+               return 0;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the RareFactCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the RareFactCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+//**********************************************************************************************************************
diff --git a/rarefactcommand.h b/rarefactcommand.h
new file mode 100644 (file)
index 0000000..b1b706c
--- /dev/null
@@ -0,0 +1,57 @@
+#ifndef RAREFACTCOMMAND_H
+#define RAREFACTCOMMAND_H
+/*
+ *  rarefactcommand.h
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/2/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include <Carbon/Carbon.h>
+#include <iostream>
+#include <fstream>
+#include <vector>
+#include "command.hpp"
+#include "ordervector.hpp"
+#include "inputdata.h"
+#include "rarefact.h"
+#include "display.h"
+#include "readmatrix.hpp"
+
+
+/*The rarefaction() command:
+       The rarefaction command generates a rarefaction curve from a given file.  
+       The rarefaction command can only be executed after a successful read.list, read.sabund or read.rabund command, with one exception. 
+       The rarefaction command can be executed after a successful cluster command.  It will use the .list file from the output of the cluster. 
+       The rarefaction command outputs a file for each estimator you choose to use.  It is recommended to only use rarefaction estimator.  
+       The rarefaction command parameters are label, line, iters, freq, rarefaction.  No parameters are required, 
+       but you may not use both the line and label  parameters at the same time. The rarefaction command should be in the following format: 
+       rarefaction(label=yourLabel, line=yourLines, iters=yourIters, freq=yourFreq, rarefaction=yourEstimators). 
+       Example rarefaction(label=unique-.01-.03, line=0,5,10, iters=10000, freq=10, rarefaction=rarefaction-rchao-race-rjack-rbootstrap-rshannon-rnpshannon-rsimpson). 
+       The default values for iters is 1000, freq is 100, and rarefaction is rarefaction which calculates the rarefaction curve for the observed richness. 
+       The valid rarefaction estimators are: rarefaction-rchao-race-rjack-rbootstrap-rshannon-rnpshannon-rsimpson.  
+       Rarefaction is the only recommended estimator.  The label and line parameters are used to analyze specific lines in your input. */
+       
+
+class GlobalData;
+
+class RareFactCommand : public Command {
+       
+public:
+       RareFactCommand();      
+       ~RareFactCommand();
+       int execute();  
+       
+private:
+       GlobalData* globaldata;
+       vector<Display*> rDisplays;
+       ReadMatrix* read;
+       OrderVector* order;
+       InputData* input;
+       Rarefact* rCurve;
+       int freq, nIters;
+};
+
+#endif
\ No newline at end of file
diff --git a/rarefactioncurvedata.h b/rarefactioncurvedata.h
new file mode 100644 (file)
index 0000000..e08f9d7
--- /dev/null
@@ -0,0 +1,66 @@
+#ifndef RAREFACTIONCURVEDATA_H
+#define RAREFACTIONCURVEDATA_H
+
+#include <set>
+#include "sabundvector.hpp"
+#include "display.h"
+#include "observable.h"
+
+using namespace std;
+
+/***********************************************************************/
+
+class RarefactionCurveData : public Observable {
+       
+public:
+       RarefactionCurveData() : rank(0) {};
+       
+       void registerDisplay(Display* o)        {       displays.insert(o);                             };
+       void removeDisplay(Display* o)          {       displays.erase(o);      delete o;       };
+       SAbundVector* getRankData()                     {       return rank;                                    };
+       void rankDataChanged()                          {       notifyDisplays();                               };
+       void updateRankData(SAbundVector* rv)   {       rank = rv; rankDataChanged();   };
+
+       void notifyDisplays(){  
+               for(set<Display*>::iterator pos=displays.begin();pos!=displays.end();pos++){
+                       (*pos)->update(rank);
+               }       
+       };
+       
+private:
+       set<Display*> displays;
+       SAbundVector* rank;
+       
+};
+
+/***********************************************************************/
+
+class SharedRarefactionCurveData : public Observable {
+       
+public:
+       SharedRarefactionCurveData() : shared1(0), shared2(0) {};
+       
+       void registerDisplay(Display* o)        {       displays.insert(o);                             };
+       void removeDisplay(Display* o)          {       displays.erase(o);      delete o;       };
+       void SharedDataChanged()                        {       notifyDisplays();                               };
+       void updateSharedData(SharedRAbundVector* rv, SharedRAbundVector* rv2, int numSeqs, int numGroupComb)   {       shared1 = rv; shared2 = rv2; NumSeqs = numSeqs; NumGroupComb = numGroupComb; SharedDataChanged(); };
+
+       void notifyDisplays(){  
+               for(set<Display*>::iterator pos=displays.begin();pos!=displays.end();pos++){
+                               (*pos)->update(shared1, shared2, NumSeqs, NumGroupComb);
+               }       
+       };
+       
+private:
+       set<Display*> displays;
+       SharedRAbundVector* shared1;
+       SharedRAbundVector* shared2;
+       int NumSeqs, NumGroupComb;
+       
+};
+
+/***********************************************************************/
+
+
+#endif
+
diff --git a/rarefactsharedcommand.cpp b/rarefactsharedcommand.cpp
new file mode 100644 (file)
index 0000000..4ed4795
--- /dev/null
@@ -0,0 +1,105 @@
+/*
+ *  rarefactsharedcommand.cpp
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/6/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "rarefactsharedcommand.h"
+#include "sharedsobs.h"
+
+//**********************************************************************************************************************
+
+RareFactSharedCommand::RareFactSharedCommand(){
+       try {
+               globaldata = GlobalData::getInstance();
+               string fileNameRoot, groups;
+               fileNameRoot = getRootName(globaldata->inputFileName);
+               groupmap = globaldata->gGroupmap;
+               
+               //initialize groups for label
+               groups = "";
+               for (int i = 0; i < groupmap->namesOfGroups.size(); i++) {
+                       groups = groups + groupmap->namesOfGroups[i];
+               }
+               
+               int i;
+               for (i=0; i<globaldata->sharedRareEstimators.size(); i++) {
+                       if (globaldata->sharedRareEstimators[i] == "sharedobserved") { 
+                               rDisplays.push_back(new RareDisplay(new SharedSobs(), new SharedThreeColumnFile(fileNameRoot+"sharedObserved", groups)));
+                       }
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the RareFactSharedCommand class Function RareFactSharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the RareFactSharedCommand class function RareFactSharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+                       
+}
+
+//**********************************************************************************************************************
+
+RareFactSharedCommand::~RareFactSharedCommand(){
+       delete order;
+       delete input;
+       delete rCurve;
+       delete read;
+}
+
+//**********************************************************************************************************************
+
+int RareFactSharedCommand::execute(){
+       try {
+               int count = 1;
+               read = new ReadPhilFile(globaldata->inputFileName);     
+               read->read(&*globaldata); 
+               
+               input = globaldata->ginput;
+               list = globaldata->glist;
+               order = list->getSharedOrderVector();
+               
+               while(order != NULL){
+               
+                       if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
+                               //create collectors curve
+                               rCurve = new Rarefact(order, rDisplays);
+                               convert(globaldata->getFreq(), freq);
+                               convert(globaldata->getIters(), nIters);
+                               rCurve->getSharedCurve(freq, nIters);
+                       
+                               delete rCurve;
+                       
+                               cout << order->getLabel() << '\t' << count << endl;
+                       }
+                       
+                       list = input->getListVector(); //get new list vector to process
+                       if (list != NULL) {
+                               order = list->getSharedOrderVector(); //gets new order vector with group info.
+                               count++;
+                       }else {
+                               break;
+                       }
+               
+               }
+       
+               for(int i=0;i<rDisplays.size();i++){    delete rDisplays[i];    }       
+               return 0;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the RareFactSharedCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the RareFactSharedCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+
+//**********************************************************************************************************************
diff --git a/rarefactsharedcommand.h b/rarefactsharedcommand.h
new file mode 100644 (file)
index 0000000..cb2219f
--- /dev/null
@@ -0,0 +1,59 @@
+#ifndef RAREFACTSHAREDCOMMAND_H
+#define RAREFACTSHAREDCOMMAND_H
+/*
+ *  rarefactsharedcommand.h
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/6/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include <Carbon/Carbon.h>
+#include <iostream>
+#include <fstream>
+#include <vector>
+#include "command.hpp"
+#include "sharedordervector.h"
+#include "listvector.hpp"
+#include "inputdata.h"
+#include "groupmap.h"
+#include "rarefact.h"
+#include "display.h"
+#include "readmatrix.hpp"
+
+/* The rarefaction.shared() command:
+       The rarefaction command generates a rarefaction curve from a given file representing several groups.  
+       The rarefaction.shared command can only be executed after a successful read.shared command. It outputs a file for each estimator you choose to use.  
+       The rarefaction.shared command parameters are label, line, iters, jumble and sharedrarefaction.  
+       No parameters are required, but you may not use both the line and label  parameters at the same time.  
+       The rarefaction command should be in the following format: rarefaction.shared(label=yourLabel, line=yourLines, iters=yourIters, 
+       jumble= yourJumble, sharedrarefaction=yourEstimators).  Example rarefaction.shared(label=unique-.01-.03, line=0,5,10, iters=10000, 
+       jumble=1, sharedrarefaction =sharedobserved).  The default values for jumble is 0 (meaning don’t jumble, if it’s set to 1 then it will jumble), 
+       iters is 1000 and sharedrarefaction is sharedobserved which calculates the shared rarefaction curve for the observed richness. 
+        The valid sharedrarefaction estimator is sharedobserved. The label and line parameters are used to analyze specific lines in your input. */
+
+
+class GlobalData;
+
+class RareFactSharedCommand : public Command {
+       
+public:
+       RareFactSharedCommand();        
+       ~RareFactSharedCommand();
+       int execute();  
+       
+private:
+       GlobalData* globaldata;
+       GroupMap* groupmap;
+       ListVector* list;
+       ReadMatrix* read;
+       SharedOrderVector* order;
+       InputData* input;
+       Rarefact* rCurve;
+       vector<Display*> rDisplays;
+       int freq, nIters;
+
+};
+
+#endif
\ No newline at end of file
diff --git a/readdistcolumnfilecommand.h b/readdistcolumnfilecommand.h
new file mode 100644 (file)
index 0000000..79ec5a7
--- /dev/null
@@ -0,0 +1,43 @@
+#ifndef READDISTCOLUMNFILECOMMAND_H
+#define READDISTCOLUMNFILECOMMAND_H
+/*
+ *  readdistcolumnfilecommand.h
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/2/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include <Carbon/Carbon.h>
+#include <iostream>
+#include <fstream>
+#include "command.hpp"
+#include "readmatrix.hpp"
+
+/* The read.column command is used to read a distance matrix file in column format.  
+The read.column command parameter options are distfile, namefile, cutoff and precision. 
+The read.column command should be in the following format: read.column (distfile=yourDistFile, 
+namefile=yourNameFile, cutoff=yourCutoff, precision=yourPrecision). The distfile and namefile parameters are required.  
+If you do not provide a cutoff value 10.00 is assumed. If you do not provide a precision value then 100 is assumed.  */
+
+class NameAssignment;
+class GlobalData;
+
+
+class ReadDistColumnFileCommand : public Command {
+public:
+       ReadDistColumnFileCommand();
+       ~ReadDistColumnFileCommand();
+       int execute();
+       
+private:
+       GlobalData* globaldata;
+       double cutoff;
+       int precision;
+       ReadMatrix* read;
+       string filename, format, method;
+       NameAssignment* nameMap;
+};
+
+#endif
\ No newline at end of file
diff --git a/readdistphylipfilecommand.cpp b/readdistphylipfilecommand.cpp
new file mode 100644 (file)
index 0000000..90804b2
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ *  readdistphylipfilecommand.cpp
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/2/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "readdistphylipfilecommand.h"
+
+//**********************************************************************************************************************
+
+ReadDistPhylipFileCommand::ReadDistPhylipFileCommand(){
+       try {
+               globaldata = GlobalData::getInstance();
+               
+               filename = globaldata->inputFileName;
+                               
+               format = globaldata->getFormat();       
+               read = new ReadPhylipMatrix(filename);  
+               
+               if(globaldata->getPrecision() != ""){
+                       convert(globaldata->getPrecision(), precision); 
+               }
+               
+               if(globaldata->getCutOff() != ""){
+                       convert(globaldata->getCutOff(), cutoff);       
+                       cutoff += (5 / (precision * 10.0));
+               }
+               read->setCutoff(cutoff);
+       
+               if(globaldata->getNameFile() != ""){    
+                       nameMap = new NameAssignment(globaldata->getNameFile());
+                       nameMap->readMap(1,2);
+               }
+               else{
+                       nameMap = NULL;
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ReadDistPhylipFileCommand class Function ReadDistPhylipFileCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ReadDistPhylipFileCommand class function ReadDistPhylipFileCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+//**********************************************************************************************************************
+
+ReadDistPhylipFileCommand::~ReadDistPhylipFileCommand(){
+       delete read;
+       delete nameMap;
+}
+
+//**********************************************************************************************************************
+
+int ReadDistPhylipFileCommand::execute(){
+       try {
+               read->read(nameMap);
+               globaldata->setListVector(read->getListVector());
+               globaldata->setSparseMatrix(read->getMatrix());
+               return 0;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ReadDistPhylipFileCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ReadDistPhylipFileCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
diff --git a/readdistphylipfilecommand.h b/readdistphylipfilecommand.h
new file mode 100644 (file)
index 0000000..9133c92
--- /dev/null
@@ -0,0 +1,45 @@
+#ifndef READDISTPHYLIPFILECOMMAND_H
+#define READDISTPHYLIPFILECOMMAND_H
+/*
+ *  readdistphylipfilecommand.h
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/2/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include <Carbon/Carbon.h>
+
+#include <iostream>
+#include <fstream>
+#include "command.hpp"
+#include "readmatrix.hpp"
+
+/* The read.phylip command is used to read a distance matrix file in phylip format.  
+The read.phylip command parameter options are distfile, namefile, cutoff and precision. 
+The read.phylip command should be in the following format: read.phylip(distfile=yourDistFile, 
+namefile=yourNameFile, cutoff=yourCutoff, precision=yourPrecision). The distfile parameter is required.  
+If you do not provide a cutoff value 10.00 is assumed. If you do not provide a precision value then 100 is assumed.  */
+
+
+class NameAssignment;
+class GlobalData;
+
+
+class ReadDistPhylipFileCommand : public Command {
+public:
+       ReadDistPhylipFileCommand();
+       ~ReadDistPhylipFileCommand();
+       int execute();
+       
+private:
+       GlobalData* globaldata;
+       double cutoff;
+       int precision;
+       ReadMatrix* read;
+       string filename, format, method;
+       NameAssignment* nameMap;
+};
+
+#endif
\ No newline at end of file
diff --git a/readlistfilecommand.h b/readlistfilecommand.h
new file mode 100644 (file)
index 0000000..b444b38
--- /dev/null
@@ -0,0 +1,38 @@
+#ifndef READLISTFILECOMMAND_H
+#define READLISTFILECOMMAND_H
+/*
+ *  readlistfilecommand.h
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/2/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include <Carbon/Carbon.h>
+#include <iostream>
+#include <fstream>
+#include "command.hpp"
+#include "readmatrix.hpp"
+#include "inputdata.h"
+
+/* The read.list command parameter options are listfile and orderfile.  
+The read.list command should be in the following format: 
+read.list(listfile=yourListFile, orderfile=yourOrderFile). The listfile parameter is required. */
+
+class GlobalData;
+
+class ReadListFileCommand : public Command {
+public:
+       ReadListFileCommand();
+       ~ReadListFileCommand();
+       int execute();
+       
+private:
+       GlobalData* globaldata;
+       ReadMatrix* read;
+       InputData* input;
+       string filename;
+};
+
+#endif
\ No newline at end of file
diff --git a/readmatrix.cpp b/readmatrix.cpp
new file mode 100644 (file)
index 0000000..0b9e3ec
--- /dev/null
@@ -0,0 +1,383 @@
+/*
+ *  readmatrix.cpp
+ *  
+ *
+ *  Created by Pat Schloss on 8/13/08.
+ *  Copyright 2008 Patrick D. Schloss. All rights reserved.
+ *
+ */
+
+using namespace std;
+
+#include <string>
+#include <map>
+#include "utilities.hpp"
+#include "sparsematrix.hpp"
+#include "progress.hpp"
+#include "listvector.hpp"
+#include "rabundvector.hpp"
+#include <exception>
+
+#include "readmatrix.hpp"
+
+
+/***********************************************************************/
+
+ReadPhylipMatrix::ReadPhylipMatrix(string distFile){
+       
+       successOpen = openInputFile(distFile, fileHandle);
+       
+}
+
+/***********************************************************************/
+
+void ReadPhylipMatrix::read(NameAssignment* nameMap){
+       try {
+       
+                       float distance;
+                       int square, nseqs;
+                       string name;
+                       vector<string> matrixNames;
+       
+                       fileHandle >> nseqs >> name;
+
+                       matrixNames.push_back(name);
+
+                       if(nameMap == NULL){
+                               list = new ListVector(nseqs);
+                               list->set(0, name);
+                       }
+                       else{
+                               list = new ListVector(nameMap->getListVector());
+                               if(nameMap->count(name)==0){    cout << "Error: Sequence '" << name << "' was not found in the names file, please correct" << endl; }
+                       }
+       
+                       char d;
+                       while((d=fileHandle.get()) != EOF){
+               
+                               if(isalnum(d)){
+                                       square = 1;
+                                       fileHandle.putback(d);
+                                       for(int i=0;i<nseqs;i++){
+                                               fileHandle >> distance;
+                                       }
+                                       break;
+                               }
+                               if(d == '\n'){
+                                       square = 0;
+                                       break;
+                               }
+                       }
+       
+                       Progress* reading;
+       
+                       if(square == 0){
+
+                               reading = new Progress("Reading matrix:    ", nseqs * (nseqs - 1) / 2);
+               
+                               int     index = 0;
+               
+                               for(int i=1;i<nseqs;i++){
+                                       fileHandle >> name;
+                                       matrixNames.push_back(name);
+       
+                                       //there's A LOT of repeated code throughout this method...
+                                       if(nameMap == NULL){
+                                               list->set(i, name);
+                                       
+                                               for(int j=0;j<i;j++){
+                                                       fileHandle >> distance;
+                                               
+                                                       if(distance < cutoff){
+                                                               PCell value(i, j, distance);
+                                                               D->addCell(value);
+                                                       }
+                                                       index++;
+                                                       reading->update(index);
+                                               }
+                               
+                                       }
+                                       else{
+                                               if(nameMap->count(name)==0){    cout << "Error: Sequence '" << name << "' was not found in the names file, please correct" << endl; }
+                               
+                                               for(int j=0;j<i;j++){
+                                                       fileHandle >> distance;
+                                               
+                                                       if(distance < cutoff){
+                                                               PCell value(nameMap->get(matrixNames[i]), nameMap->get(matrixNames[j]), distance);
+                                                               D->addCell(value);
+                                                       }
+                                                       index++;
+                                                       reading->update(index);
+                                               }
+                                       }
+                               }
+                       }
+                       else{
+
+                               reading = new Progress("Reading matrix:    ", nseqs * nseqs);
+                       
+                               int index = nseqs;
+               
+                               for(int i=1;i<nseqs;i++){
+                                       fileHandle >> name;             
+                                       matrixNames.push_back(name);
+       
+                                       if(nameMap == NULL){
+                                               list->set(i, name);
+                                               for(int j=0;j<nseqs;j++){
+                                                       fileHandle >> distance;
+                                       
+                                                       if(distance < cutoff && j < i){
+                                                               PCell value(i, j, distance);
+                                                               D->addCell(value);
+                                                       }
+                                                       index++;
+                                                       reading->update(index);
+                                               }
+                                       
+                                       }
+                                       else{
+                                               if(nameMap->count(name)==0){    cout << "Error: Sequence '" << name << "' was not found in the names file, please correct" << endl; }
+                               
+                                               for(int j=0;j<nseqs;j++){
+                                                       fileHandle >> distance;
+                                       
+                                                       if(distance < cutoff && j < i){
+                                                               PCell value(nameMap->get(matrixNames[i]), nameMap->get(matrixNames[j]), distance);
+                                                               D->addCell(value);
+                                                       }
+                                                       index++;
+                                                       reading->update(index);
+                                               }
+                                       }
+                               }
+                       }
+                       reading->finish();
+                       delete reading;
+
+                       list->setLabel("0");
+                       fileHandle.close();
+
+                       if(nameMap != NULL){
+                               for(int i=0;i<matrixNames.size();i++){
+                                       nameMap->erase(matrixNames[i]);
+                               }
+                               if(nameMap->size() > 0){
+                                       //should probably tell them what is missing if we missed something
+                                       cout << "missed something" << '\t' << nameMap->size() << endl;
+                               }
+                       }
+
+               }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ReadPhylipMatrix class Function read. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ReadPhylipMatrix class function read. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+/***********************************************************************/
+
+ReadPhylipMatrix::~ReadPhylipMatrix(){
+       delete D;
+       delete list;
+}
+
+/***********************************************************************/
+
+ReadColumnMatrix::ReadColumnMatrix(string df) : distFile(df){
+       
+       successOpen = openInputFile(distFile, fileHandle);
+       
+}
+
+/***********************************************************************/
+
+void ReadColumnMatrix::read(NameAssignment* nameMap){
+       try {           
+       
+                       string firstName, secondName;
+                       float distance;
+                       int nseqs = nameMap->size();
+
+                       list = new ListVector(nameMap->getListVector());
+               
+                       Progress* reading = new Progress("Reading matrix:    ", nseqs * nseqs);
+       
+                       int lt = 1;
+                       int refRow = 0; //we'll keep track of one cell - Cell(refRow,refCol) - and see if it's transpose
+                       int refCol = 0; //shows up later - Cell(refCol,refRow).  If it does, then its a square matrix
+       
+                       //need to see if this is a square or a triangular matrix...
+                       while(fileHandle && lt == 1){  //let's assume it's a triangular matrix...
+                       
+                               fileHandle >> firstName >> secondName >> distance;      // get the row and column names and distance
+               
+                               if(nameMap->count(firstName)==0){
+                                       cerr << "AError: Sequence '" << firstName << "' was not found in the names file, please correct\n";
+                               }
+                               if(nameMap->count(secondName)==0){
+                                       cerr << "AError: Sequence '" << secondName << "' was not found in the names file, please correct\n";
+                               }
+               
+                               if(distance < cutoff && nameMap->get(firstName) != nameMap->get(secondName)){
+                                       if(nameMap->get(firstName) > nameMap->get(secondName)){
+                                               PCell value(nameMap->get(firstName), nameMap->get(secondName), distance);
+                               
+                                               if(refRow == refCol){           // in other words, if we haven't loaded refRow and refCol...
+                                                       refRow = nameMap->get(firstName);
+                                                       refCol = nameMap->get(secondName);
+                                                       D->addCell(value);
+                                               }
+                                               else if(refRow == nameMap->get(firstName) && refCol == nameMap->get(secondName)){
+                                                       lt = 0;
+                                               }
+                                               else{
+                                                       D->addCell(value);
+                                               }
+                                       }
+                                       else if(nameMap->get(firstName) < nameMap->get(secondName)){
+                                               PCell value(nameMap->get(secondName), nameMap->get(firstName), distance);
+                               
+                                               if(refRow == refCol){           // in other words, if we haven't loaded refRow and refCol...
+                                                       refRow = nameMap->get(firstName);
+                                                       refCol = nameMap->get(secondName);
+                                                       D->addCell(value);
+                                               }
+                                               else if(refRow == nameMap->get(secondName) && refCol == nameMap->get(firstName)){
+                                                       lt = 0;
+                                               }
+                                               else{
+                                                       D->addCell(value);
+                                               }
+                                       }
+                                       reading->update(nameMap->get(firstName) * nseqs);
+                               }
+                               gobble(fileHandle);
+                       }
+
+                       if(lt == 0){  // oops, it was square
+                               fileHandle.close();  //let's start over
+                               D->clear();  //let's start over
+                          
+                               openInputFile(distFile, fileHandle);  //let's start over
+
+                               while(fileHandle){
+                                       fileHandle >> firstName >> secondName >> distance;
+                       
+                                       if(nameMap->count(firstName)==0){
+                                               cerr << "BError: Sequence '" << firstName << "' was not found in the names file, please correct\n";
+                                       }
+                                       if(nameMap->count(secondName)==0){
+                                               cerr << "BError: Sequence '" << secondName << "' was not found in the names file, please correct\n";
+                                       }
+                       
+                                       if(distance < cutoff && nameMap->get(firstName) > nameMap->get(secondName)){
+                                               PCell value(nameMap->get(firstName), nameMap->get(secondName), distance);
+                                               D->addCell(value);
+                                               reading->update(nameMap->get(firstName) * nseqs);
+                                       }
+                       
+                                       gobble(fileHandle);
+                               }
+                       }
+               //      else if(lt == 0){
+               //              while(fileHandle){
+               //                      fileHandle >> firstName >> secondName >> distance;
+               //                      
+               //                      if(nameMap->count(firstName)==0){
+               //                              cerr << "CError: Sequence '" << firstName << "' was not found in the names file, please correct\n";
+               //                      }
+               //                      if(nameMap->count(secondName)==0){
+               //                              cerr << "CError: Sequence '" << secondName << "' was not found in the names file, please correct\n";
+               //                      }
+               //                      
+               //                      if(distance < cutoff && (*nameMap)[firstName].second < (*nameMap)[secondName].second){
+               ////                            cout << (*nameMap)[secondName] << ' ' << (*nameMap)[firstName] << ' ' << distance << endl;
+               //                              D->addCell(Cell((*nameMap)[secondName].second, (*nameMap)[firstName].second, distance));
+               //                              reading->update((*nameMap)[secondName].second * nseqs);
+               //                      }
+               //
+               //                      gobble(fileHandle);
+               //              }
+               //      }       
+                       reading->finish();
+                       fileHandle.close();
+       
+                       list->setLabel("0");
+       
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ReadColumnMatrix class Function read. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ReadColumnMatrix class function read. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+
+}
+
+/***********************************************************************/
+
+ReadColumnMatrix::~ReadColumnMatrix(){
+       delete D;
+       delete list;
+}
+
+
+/***********************************************************************/
+
+ReadPhilFile::ReadPhilFile(string pf): philFile(pf){
+       
+       successOpen = openInputFile(philFile, fileHandle);
+       
+}
+
+/***********************************************************************/
+//This function reads the list, rabund or sabund files to be used by collect and rarefact command.
+void ReadPhilFile::read(GlobalData* globaldata){
+       try {
+               if (globaldata->getOrderFile() == "") {
+                       //you have two inputs because in the next if statement if you only have one then it moves ahead in the same file.  
+                       //So when you run the collect or summary commands you miss a line.
+                       input = new InputData(philFile, globaldata->getFormat()); //format tells you whether philFile is list, rabund, sabund.
+                       inputSabund = new InputData(philFile, globaldata->getFormat()); //format tells you whether philFile is list, rabund, sabund.
+               }else {//there is an orderfile
+                       input = new InputData(philFile, globaldata->getOrderFile(), globaldata->getFormat());
+               }
+               globaldata->ginput = input;     //saving to be used by collector and rarefact commands.
+               
+               if (globaldata->getGroupFile() == "") {//you are reading a list, rabund or sabund file for collect, rarefaction or summary.
+                       order = input->getOrderVector();
+                       globaldata->gorder = order;     //saving to be used by collect and rarefact commands.
+                       sabund = inputSabund->getSAbundVector(); 
+                       globaldata->sabund = sabund; //saving to be used by summary command.
+               }else {
+                       list = input->getListVector(); //you are reading for parselist command, or shared commands.
+                       globaldata->glist = list;
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ReadPhilFile class Function read. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ReadPhilFile class function read. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+/***********************************************************************/
+
+ReadPhilFile::~ReadPhilFile(){
+//     delete input;
+//     delete order;
+}
+
+/***********************************************************************/
+
diff --git a/readmatrix.hpp b/readmatrix.hpp
new file mode 100644 (file)
index 0000000..9c71732
--- /dev/null
@@ -0,0 +1,93 @@
+#ifndef READMATRIX_HPP
+#define READMATRIX_HPP
+
+/*
+ *  readmatrix.hpp
+ *  
+ *
+ *  Created by Pat Schloss on 8/13/08.
+ *  Copyright 2008 Patrick D. Schloss. All rights reserved.
+ *
+ */
+
+#include "rabundvector.hpp"
+#include "listvector.hpp"
+#include "sparsematrix.hpp"
+#include "nameassignment.hpp"
+#include "inputdata.h"
+#include "globaldata.hpp"
+#include "sabundvector.hpp"
+#include "groupmap.h"
+
+class SparseMatrix;
+
+class ReadMatrix {
+
+public:
+       ReadMatrix(){   D = new SparseMatrix(); }
+       virtual void read(NameAssignment*){};
+       virtual void read(GlobalData* globaldata){};
+       void setCutoff(float c)                 {       cutoff = c;             }
+       SparseMatrix* getMatrix()               {       return D;               }
+       ListVector* getListVector()             {       return list;    }
+//     OrderVector* getOrderVector()   {       return order;   }
+
+       int successOpen;
+       
+protected:
+       SparseMatrix* D;
+       ListVector* list;
+       GlobalData* globaldata;
+       OrderVector* order;
+       InputData* input;
+       float cutoff;
+};
+
+
+
+class ReadPhylipMatrix : public ReadMatrix {
+       
+public:
+       ReadPhylipMatrix(string);
+       ~ReadPhylipMatrix();
+       void read(NameAssignment*);
+private:
+       ifstream fileHandle;
+       string distFile;
+};
+
+
+
+class ReadColumnMatrix : public ReadMatrix {
+       
+public:
+       ReadColumnMatrix(string);
+       ~ReadColumnMatrix();
+       void read(NameAssignment*);
+private:
+       ifstream fileHandle;
+       string distFile;
+};
+
+
+class ReadPhilFile : public ReadMatrix {
+       
+public:
+       ReadPhilFile(string);
+       ~ReadPhilFile();
+       void read(GlobalData* globaldata);
+private:
+       ifstream fileHandle;
+       string philFile;
+       InputData* input;
+       InputData* inputSabund;
+       ListVector* list;
+       OrderVector* order;
+       SAbundVector* sabund;
+       GlobalData* globaldata;
+       // InputData* getInput()                        {       return input;   }
+};
+
+
+
+#endif
diff --git a/readrabundfilecommand.cpp b/readrabundfilecommand.cpp
new file mode 100644 (file)
index 0000000..315cdaf
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ *  readrabundfilecommand.cpp
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/2/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "readrabundfilecommand.h"
+
+//**********************************************************************************************************************
+ReadRAbundFileCommand::ReadRAbundFileCommand(){
+       try {
+               globaldata = GlobalData::getInstance();
+               filename = globaldata->inputFileName;
+               read = new ReadPhilFile(filename);
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ReadRAbundFileCommand class Function ReadRAbundFileCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ReadRAbundFileCommand class function ReadRAbundFileCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+//**********************************************************************************************************************
+
+ReadRAbundFileCommand::~ReadRAbundFileCommand(){
+       delete read;
+}
+
+//**********************************************************************************************************************
+
+int ReadRAbundFileCommand::execute(){
+       try {
+               read->read(&*globaldata); 
+               return 0;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ReadRAbundFileCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ReadRAbundFileCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
diff --git a/readsabundfilecommand.cpp b/readsabundfilecommand.cpp
new file mode 100644 (file)
index 0000000..443b79e
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ *  readsabundfilecommand.cpp
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/2/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "readsabundfilecommand.h"
+
+//**********************************************************************************************************************
+ReadSAbundFileCommand::ReadSAbundFileCommand(){
+       try {
+               globaldata = GlobalData::getInstance();
+               filename = globaldata->inputFileName;   
+               read = new ReadPhilFile(filename);
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ReadSAbundFileCommand class Function ReadSAbundFileCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ReadSAbundFileCommand class function ReadSAbundFileCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+//**********************************************************************************************************************
+
+ReadSAbundFileCommand::~ReadSAbundFileCommand(){
+       delete read;
+}
+
+//**********************************************************************************************************************
+
+int ReadSAbundFileCommand::execute(){
+       try {
+               read->read(&*globaldata); 
+               return 0;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ReadSAbundFileCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ReadSAbundFileCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
diff --git a/readsabundfilecommand.h b/readsabundfilecommand.h
new file mode 100644 (file)
index 0000000..8e2526b
--- /dev/null
@@ -0,0 +1,38 @@
+#ifndef READSABUNDFILECOMMAND_H
+#define READSABUNDFILECOMMAND_H
+/*
+ *  readsabundfilecommand.h
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/2/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include <Carbon/Carbon.h>
+#include <iostream>
+#include <fstream>
+#include "command.hpp"
+#include "readmatrix.hpp"
+#include "inputdata.h"
+
+/* The read.sabund command parameter options are sabundfile and orderfile.  
+The read.sabund command should be in the following format: 
+read.sabund(sabundfile=yourSabundFile, orderfile=yourOrderFile). The sabundfile parameter is required.*/
+
+class GlobalData;
+
+class ReadSAbundFileCommand : public Command {
+public:
+       ReadSAbundFileCommand();
+       ~ReadSAbundFileCommand();
+       int execute();
+       
+private:
+       GlobalData* globaldata;
+       ReadMatrix* read;
+       InputData* input;
+       string filename;
+};
+
+#endif
\ No newline at end of file
diff --git a/sabundvector.cpp b/sabundvector.cpp
new file mode 100644 (file)
index 0000000..4a926b2
--- /dev/null
@@ -0,0 +1,250 @@
+/*
+ *  sabund.cpp
+ *  
+ *
+ *  Created by Pat Schloss on 8/8/08.
+ *  Copyright 2008 Patrick D. Schloss. All rights resesaved.
+ *
+ */
+using namespace std;
+
+#include "sabundvector.hpp"
+#include "datavector.hpp"
+#include "utilities.hpp"
+#include <exception>
+
+/***********************************************************************/
+
+SAbundVector::SAbundVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0){};
+
+/***********************************************************************/
+
+SAbundVector::SAbundVector(int size) : DataVector(), data(size, 0), maxRank(0), numBins(0), numSeqs(0) {};
+
+/***********************************************************************/
+
+SAbundVector::SAbundVector(string id, vector<int> sav) : DataVector(id), data(sav) {
+       try {
+               
+               for(int i=0;i<sav.size();i++){
+                       if(data[i] != 0){       maxRank = i;    }
+                       numSeqs += i*data[i];
+                       numBins += data[i];
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SAbundVector class Function SAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SAbundVector class function SAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+/***********************************************************************/
+
+SAbundVector::SAbundVector(ifstream& f): DataVector(), maxRank(0), numBins(0), numSeqs(0) {
+       try {
+               int hold;
+               f >> label >> hold;
+       
+               data.assign(hold+1, 0);
+               int inputData;
+       
+               for(int i=1;i<=hold;i++){
+                       f >> inputData;
+                       set(i, inputData);
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SAbundVector class Function SAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SAbundVector class function SAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+/***********************************************************************/
+
+void SAbundVector::set(int sabund, int abundance){
+       try {
+
+               int initSize = data[sabund];
+               data[sabund] = abundance;
+       
+               if(sabund != 0){
+                       numBins += (abundance - initSize);
+               }
+       
+               numSeqs += sabund * (abundance - initSize);
+       
+               if(sabund > maxRank)    {       maxRank = sabund;               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SAbundVector class Function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SAbundVector class function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+/***********************************************************************/
+
+int SAbundVector::get(int index){
+       return data[index];
+}
+
+/***********************************************************************/
+
+void SAbundVector::push_back(int abundance){
+       try {
+               data.push_back(abundance);
+       
+               maxRank++;      
+       
+               numBins += abundance;
+       
+               numSeqs += (maxRank * abundance);
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SAbundVector class Function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SAbundVector class function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }               
+}
+
+/***********************************************************************/
+
+void SAbundVector::resize(int size){
+       data.resize(size);
+}
+
+/***********************************************************************/
+
+int SAbundVector::size(){
+       return data.size();             
+}
+
+/***********************************************************************/
+void SAbundVector::print(string prefix, ostream& output){
+       
+       output << prefix << '\t' << maxRank << '\t';
+       
+       for(int i=1;i<=maxRank;i++){
+               output << data[i] << '\t';
+       }
+       output << endl;
+}
+
+/***********************************************************************/
+void SAbundVector::print(ostream& output){
+       try {
+               output << label << '\t' << maxRank << '\t';
+       
+               for(int i=1;i<=maxRank;i++){
+                       output << data[i] << '\t';
+               }
+               output << endl;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SAbundVector class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SAbundVector class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }               
+}
+
+/**********************************************************************/
+int SAbundVector::getNumBins(){
+//     if(needToUpdate == 1){  updateStats();  }
+       return numBins;
+}
+
+/***********************************************************************/
+
+int SAbundVector::getNumSeqs(){
+//     if(needToUpdate == 1){  updateStats();  }
+       return numSeqs;
+}
+
+/***********************************************************************/
+
+int SAbundVector::getMaxRank(){
+//     if(needToUpdate == 1){  updateStats();  }
+       return maxRank;
+}
+/***********************************************************************/
+RAbundVector SAbundVector::getRAbundVector(){
+       try {
+               RAbundVector rav;
+       
+               for(int i=1;i<=data.size();i++){                
+                       for(int j=0;j<data[i];j++){
+                               rav.push_back(i);
+                       }
+               }
+               sort(rav.rbegin(), rav.rend());
+       
+               rav.setLabel(label);
+               return rav;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SAbundVector class Function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SAbundVector class function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }               
+}
+
+/***********************************************************************/
+
+SAbundVector SAbundVector::getSAbundVector(){
+       return *this;                   
+}
+
+/***********************************************************************/
+
+OrderVector SAbundVector::getOrderVector(map<string,int>* hold = NULL){
+       try {
+               OrderVector ov;
+       
+               int binIndex = 0;
+       
+               for(int i=1;i<data.size();i++){
+                       for(int j=0;j<data[i];j++){
+                               for(int k=0;k<i;k++){
+                                       ov.push_back(binIndex);
+                               }
+                               binIndex++;
+                       }
+               }
+       
+               random_shuffle(ov.begin(), ov.end());
+
+               ov.setLabel(label);
+               ov.getNumBins();
+               return ov;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SAbundVector class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SAbundVector class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }               
+}
+
+/***********************************************************************/
diff --git a/sabundvector.hpp b/sabundvector.hpp
new file mode 100644 (file)
index 0000000..f45ef60
--- /dev/null
@@ -0,0 +1,48 @@
+#ifndef SABUND_H
+#define SABUND_H
+
+using namespace std;
+
+#include "datavector.hpp"
+#include "rabundvector.hpp"
+#include "ordervector.hpp"
+
+class SAbundVector : public DataVector {
+       
+public:
+       SAbundVector();
+       SAbundVector(int);
+//     SAbundVector(const SAbundVector&);
+       SAbundVector(string, vector<int>);
+       SAbundVector(const SAbundVector& rv) : DataVector(rv.label), data(rv.data), maxRank(rv.maxRank), numBins(rv.numBins), numSeqs(rv.numSeqs){};
+       SAbundVector(ifstream&);
+       ~SAbundVector(){};
+
+       int getNumBins();       
+       int getNumSeqs();       
+       int getMaxRank();       
+       
+       void set(int, int);
+       int get(int);
+       void push_back(int);
+       void resize(int);
+       int size();
+
+       void print(ostream&);
+       void print(string, ostream&);
+               
+       RAbundVector getRAbundVector(); 
+       SAbundVector getSAbundVector();
+       OrderVector getOrderVector(map<string,int>*);
+       
+private:
+       vector<int> data;
+//     bool needToUpdate;
+//     void updateStats();
+       int maxRank;
+       int numBins;
+       int numSeqs;
+
+};
+
+#endif
diff --git a/sequence.cpp b/sequence.cpp
new file mode 100644 (file)
index 0000000..3f64db5
--- /dev/null
@@ -0,0 +1,131 @@
+/*
+ *  sequence.cpp
+ *  
+ *
+ *  Created by Pat Schloss on 12/15/08.
+ *  Copyright 2008 Patrick D. Schloss. All rights reserved.
+ *
+ */
+
+using namespace std;
+
+#include <string>
+#include <fstream>
+
+#include "sequence.hpp"
+
+//********************************************************************************************************************
+
+Sequence::Sequence(){}
+
+//********************************************************************************************************************
+
+Sequence::Sequence(ifstream& fastaFile){
+       
+       string accession;
+       fastaFile >> accession;
+       setName(accession);
+
+       char letter;
+       string sequence;
+       
+       while(fastaFile && letter != '>'){
+       
+               letter = fastaFile.get();
+               
+               if(isalpha(letter)){
+               
+                       sequence += letter;
+                       
+               }
+               
+       }
+       fastaFile.putback(letter);
+
+       if(sequence.find_first_of('-') != string::npos){
+               setAligned(sequence);
+       }
+       setUnaligned(sequence);
+}
+
+
+//********************************************************************************************************************
+
+string Sequence::convert2ints(){
+       
+       if(unaligned == "")     {       /* need to throw an error */    }
+       
+       string processed;
+       
+       for(int i=0;i<unaligned.length();i++){
+               if(toupper(unaligned[i]) == 'A')                        {       processed += '0';       }
+               else if(toupper(unaligned[i]) == 'C')   {       processed += '1';       }
+               else if(toupper(unaligned[i]) == 'G')   {       processed += '2';       }
+               else if(toupper(unaligned[i]) == 'T')   {       processed += '3';       }
+               else if(toupper(unaligned[i]) == 'U')   {       processed += '3';       }
+               else                                                                    {       processed += '4';       }
+       }
+       return processed;
+}
+
+//********************************************************************************************************************
+
+void Sequence::setName(string seqName){
+       if(seqName[0] == '>')   {       name = seqName.substr(1);       }
+       else                                    {       name = seqName;                         }
+}
+
+//********************************************************************************************************************
+
+void Sequence::setUnaligned(string sequence){
+       
+       if(sequence.find_first_of('-') != string::npos){
+               string temp = "";
+               for(int j=0;j<sequence.length();j++){
+                       if(isalpha(sequence[j]))        {       temp += sequence[j];    }
+               }
+               unaligned = temp;
+       }
+       else{
+               unaligned = sequence;
+       }
+       
+}
+
+//********************************************************************************************************************
+
+void Sequence::setAligned(string sequence){
+       aligned = sequence;
+}
+
+//********************************************************************************************************************
+
+void Sequence::setPairwise(string sequence){
+       pairwise = sequence;
+}
+
+//********************************************************************************************************************
+
+string Sequence::getSeqName(){
+       return name;
+}
+
+//********************************************************************************************************************
+
+string Sequence::getAligned(){
+       return aligned;
+}
+
+//********************************************************************************************************************
+
+string Sequence::getPairwise(){
+       return pairwise;
+}
+
+//********************************************************************************************************************
+
+string Sequence::getUnaligned(){
+       return unaligned;
+}
+
+//********************************************************************************************************************
diff --git a/sequence.hpp b/sequence.hpp
new file mode 100644 (file)
index 0000000..32063ef
--- /dev/null
@@ -0,0 +1,41 @@
+#ifndef SEQUENCE_H
+#define SEQUENCE_H
+
+/*
+ *  sequence.h
+ *  
+ *
+ *  Created by Pat Schloss on 12/15/08.
+ *  Copyright 2008 Patrick D. Schloss. All rights reserved.
+ *
+ */
+using namespace std;
+
+#include <string>
+
+
+/**************************************************************************************************/
+
+class Sequence {
+public:
+       Sequence();
+       Sequence(ifstream&);
+       void setName(string);
+       void setUnaligned(string);
+       void setPairwise(string);
+       void setAligned(string);
+       string convert2ints();
+       string getSeqName();
+       string getAligned();
+       string getPairwise();
+       string getUnaligned();
+private:
+       string name;
+       string unaligned;
+       string pairwise;
+       string aligned;
+};
+
+/**************************************************************************************************/
+
+#endif
diff --git a/shannon.cpp b/shannon.cpp
new file mode 100644 (file)
index 0000000..5045954
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ *  shannon.cpp
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/7/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "shannon.h"
+
+/***********************************************************************/
+
+EstOutput Shannon::getValues(SAbundVector* rank){
+       try {
+               //vector<double> shannonData(3,0);
+               data.resize(3,0);
+       
+               double shannon = 0.0000;  //hprime
+               double hvara=0.0000;
+    
+               double maxRank = rank->getMaxRank();
+               int sampled = rank->getNumSeqs();
+               int sobs = rank->getNumBins();
+       
+               for(int i=1;i<=maxRank;i++){
+                       double p = ((double) i)/((double)sampled);
+                       shannon += (double)rank->get(i)*p*log(p); //hprime
+                       hvara  += (double)rank->get(i)*p*pow(log(p),2);
+               }
+               shannon = -shannon;
+    
+               double hvar = (hvara-pow(shannon,2))/(double)sampled+(double)sobs/(double)(2*sampled*sampled);
+    
+               double ci = 0;
+       
+               if(hvar>0){
+                       ci = 1.96*pow(hvar,0.5);
+               }
+       
+               double shannonhci = shannon + ci;
+               double shannonlci = shannon - ci;
+               
+               data[0] = shannon;
+               data[1] = shannonlci;
+               data[2] = shannonhci;
+               
+               if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; }
+               if (isnan(data[1]) || isinf(data[1])) { data[1] = 0; }
+               if (isnan(data[2]) || isinf(data[2])) { data[2] = 0; }
+
+               return data;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the Shannon class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the Shannon class function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+/***********************************************************************/
diff --git a/shannon.h b/shannon.h
new file mode 100644 (file)
index 0000000..223bc90
--- /dev/null
+++ b/shannon.h
@@ -0,0 +1,33 @@
+#ifndef SHANNON_H
+#define SHANNON_H
+/*
+ *  shannon.h
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/7/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+/* This class implements the Shannon estimator on single group. 
+It is a child of the calculator class. */
+
+
+#include <Carbon/Carbon.h>
+#include "calculator.h"
+
+/***********************************************************************/
+
+class Shannon : public Calculator  {
+       
+public:
+       Shannon() : Calculator("Shannon", 3) {};
+       EstOutput getValues(SAbundVector* rank);
+       EstOutput getValues(SharedRAbundVector*, SharedRAbundVector*) {return data;};
+private:
+       
+};
+
+/***********************************************************************/
+
+#endif
diff --git a/shared.cpp b/shared.cpp
new file mode 100644 (file)
index 0000000..3208156
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ *  shared.cpp
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 12/5/08.
+ *  Copyright 2008 Schloss Lab Umass Amherst. All rights reserved.
+ *
+ */
+
+#include "shared.h"
+
+/**************************************************************************************************/
+
+Shared::Shared(){
+   globaldata = GlobalData::getInstance();
+}
+
+/**************************************************************************************************/
+void Shared::getSharedVectors(int index, ListVector* list) {
+               string label, group;
+               int i,j;
+               label = list->getLabel();
+               
+               sharedGroups.clear();  //removes old info.
+               
+               //initalize sharedGroups 
+               for (j=0; j<globaldata->gGroupmap->getNumGroups(); j++) {//for each group
+                       group = globaldata->gGroupmap->namesOfGroups[j];
+                       sharedGroups[group] = new SharedRAbundVector();
+                       sharedGroups[group]->setLabel(label);
+                       for (i = 0; i<list->size(); i++) { //for each otu
+                               sharedGroups[group]->push_back(0, i, group); //initialize to 0.
+                       }
+               }
+                       
+               //fills sharedGroups
+               for (i = 0; i<list->size(); i++) {
+                       parse(i, list);
+               }
+               
+               //updates sharedVector
+               sharedRAbund.push_back(sharedGroups);
+}
+
+
+
+/***********************************************************************/
+void Shared::parse(int index, ListVector* list) {
+
+               string prefix, suffix, groupsName;
+               suffix = list->get(index);
+       
+               while (suffix.find_first_of(',') != -1) {//while you still have sequences
+                       prefix = suffix.substr(0,suffix.find_first_of(','));
+                       if ((suffix.find_first_of(',')+1) <= suffix.length()) {  //checks to make sure you don't have comma at end of string
+                               suffix = suffix.substr(suffix.find_first_of(',')+1, suffix.length());
+                       }
+                       groupsName = globaldata->gGroupmap->getGroup(prefix);
+                       if (groupsName != "not found") {
+                               sharedGroups[groupsName]->set(index, (sharedGroups[groupsName]->getAbundance(index) + 1), groupsName); //increment shared vector for that group
+                       }else {
+                               cerr << "Error: Sequence '" << prefix << "' was not found in the group file, please correct\n";
+                       }
+               }
+               
+               //save last name after comma
+               groupsName = globaldata->gGroupmap->getGroup(suffix);
+               if (groupsName != "not found") {
+                       sharedGroups[groupsName]->set(index, ((sharedGroups[groupsName]->getAbundance(index)) + 1), groupsName); //increment shared vector for that group
+               }else {
+                       cerr << "Error: Sequence '" << suffix << "' was not found in the group file, please correct\n";
+               }
+       }
diff --git a/shared.h b/shared.h
new file mode 100644 (file)
index 0000000..42c9d65
--- /dev/null
+++ b/shared.h
@@ -0,0 +1,39 @@
+#ifndef SHARED_H
+#define SHARED_H
+
+/*
+ *  shared.h
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 12/5/08.
+ *  Copyright 2008 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+using namespace std;
+
+#include <Carbon/Carbon.h>
+#include <iostream>
+#include <fstream>
+#include <iomanip>
+#include <vector>
+#include <string>
+#include <sstream>
+#include <map>
+#include "sharedrabundvector.h"
+#include "listvector.hpp"
+
+class Shared {
+       public:
+               Shared();
+               ~Shared();
+               void getSharedVectors(int, ListVector*);
+               map<string, SharedRAbundVector*> sharedGroups; //string is groupname, SharedVector* is out info for that group
+               
+       private:
+               GlobalData* globaldata;
+               void parse(int, ListVector*);
+               vector< map<string, SharedRAbundVector*> > sharedRAbund;  //contains all the info needed to create the .shared file not sure if we will need 
+};
+
+#endif
\ No newline at end of file
diff --git a/sharedace.cpp b/sharedace.cpp
new file mode 100644 (file)
index 0000000..791b526
--- /dev/null
@@ -0,0 +1,114 @@
+
+/*
+ *  sharedace.cpp
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/8/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "sharedace.h"
+
+/***********************************************************************/
+
+EstOutput SharedAce::getValues(SharedRAbundVector* shared1, SharedRAbundVector* shared2) {
+       try {
+               data.resize(1,0);
+               string label;
+               label = shared1->getLabel();
+
+               int fARare, fBRare, S12Rare, S12Abund, S12, f11, tempA, tempB, t10, t01, t11, t21, t12, t22, C12Numerator;
+               fARare = 0; fBRare = 0; S12Rare = 0; S12Abund = 0; S12 = 0; f11 = 0; t10 = 0; t01 = 0; t11= 0; t21= 0; t12= 0; t22= 0; C12Numerator = 0;
+       
+               float SharedAce, C12, part1, part2, part3, part4, part5, Gamma1, Gamma2, Gamma3;
+       
+               /*fARare = number of OTUs with one individual found in A and less than or equal to 10 in B. 
+               fBRare = number of OTUs with one individual found in B and less than or equal to 10 in A. 
+               arare = number of sequences from A that contain less than 10 sequences. 
+               brare = number of sequences from B that contain less than 10 sequences. 
+               S12Rare = number of shared OTUs where both of the communities are represented by less than or equal to 10 sequences 
+               S12Abund = number of shared OTUs where at least one of the communities is represented by more than 10 sequences 
+               S12 = number of shared OTUs in A and B
+               This estimator was changed to reflect Caldwell's changes, eliminating the nrare / nrare - 1 */
+
+               for (int i = 0; i < shared1->size(); i++) {
+                       //store in temps to avoid multiple repetitive function calls
+                       tempA = shared1->getAbundance(i);
+                       tempB = shared2->getAbundance(i);
+                       if ((tempA != 0) && (tempB != 0)) {//they are shared
+                               S12++;
+                               //do both A and B have one
+                               if ((tempA == 1) && (tempB == 1))               {       f11++;   }
+                               //is A one and B rare
+                               if ((tempA == 1) && (tempB <= abund))   {  fARare++; }
+                               //is B one and A rare
+                               if ((tempB == 1) && (tempA <= abund))   {  fBRare++; }
+                       
+                               if ((tempA <= abund) && (tempB <= abund)) { //shared and both rare
+                                       S12Rare++;
+                                       t10 += tempA;   //Sum Xi
+                                       t01 += tempB;   //Sum Yi
+                                       
+                                       //calculate top of C12
+                                       // YiI(Xi = 1)
+                                       if (tempA == 1) { C12Numerator += tempB; }
+                                       //XiI(Yi = 1)
+                                       if (tempB == 1) { C12Numerator += tempA; }
+                                       //-I(Xi=Yi=1)
+                                       if ((tempA == 1) && (tempB == 1)) { C12Numerator--; }
+                                       
+                                       //calculate t11 - Sum of XiYi
+                                       t11 += tempA * tempB;
+                                       //calculate t21  - Sum of Xi(Xi - 1)Yi
+                                       t21 += tempA * (tempA - 1) * tempB;
+                                       //calculate t12  - Sum of Xi(Yi - 1)Yi
+                                       t12 += tempA * (tempB - 1) * tempB;
+                                       //calculate t22  - Sum of Xi(Xi - 1)Yi(Yi - 1)
+                                       t22 += tempA * (tempA - 1) * tempB * (tempB - 1);
+
+                               }
+                               if ((tempA > 10) || (tempB > 10)) {
+                                       S12Abund++;
+                               }
+                       }
+               }
+       
+               C12 = 1 - (C12Numerator /(float) t11);
+               part1 = S12Rare / (float)C12;
+               part2 = 1 / (float)C12;
+       
+               //calculate gammas
+               Gamma1 = ((S12Rare * t21) / (float)((C12 * t10 * t11)) - 1);
+               Gamma2 = ((S12Rare * t12) / (float)((C12 * t01 * t11)) - 1);
+               Gamma3 = ((S12Rare / C12) * (S12Rare / C12)) * ( t22 / (float)(t10 * t01 * t11));
+               Gamma3 = Gamma3 - ((S12Rare * t11) / (float)(C12 * t01 * t10)) - Gamma1 - Gamma2;       
+       
+               if (isnan(Gamma1) || isinf(Gamma1)) { Gamma1 = 0; }
+               if (isnan(Gamma2) || isinf(Gamma2)) { Gamma2 = 0; }
+               if (isnan(Gamma3) || isinf(Gamma3)) { Gamma3 = 0; }
+               if (isnan(part1)  || isinf(part1))  { part1 = 0;  }
+               if (isnan(part2)  || isinf(part2))  { part2 = 0;  }
+                       
+               part3 = fARare * Gamma1;
+               part4 = fBRare * Gamma2;
+               part5 = f11 * Gamma3;
+
+               SharedAce = S12Abund + part1 + (part2 * (part3 + part4 + part5));
+               data[0] = SharedAce;
+       
+               return data;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SharedAce class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SharedAce class function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+
+}
+/***********************************************************************/
+
+
diff --git a/sharedace.h b/sharedace.h
new file mode 100644 (file)
index 0000000..fead251
--- /dev/null
@@ -0,0 +1,33 @@
+#ifndef SHAREDACE_H
+#define SHAREDACE_H
+/*
+ *  sharedace.h
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/8/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+/* This class implements the SharedAce estimator on two groups. 
+It is a child of the calculator class. */
+
+
+#include <Carbon/Carbon.h>
+#include "calculator.h"
+
+/***********************************************************************/
+
+class SharedAce : public Calculator  {
+       
+public:
+       SharedAce(int n=10) : abund(n),  Calculator("SharedAce", 3) {};
+       EstOutput getValues(SAbundVector*) {return data;};
+       EstOutput getValues(SharedRAbundVector*, SharedRAbundVector*);
+private:
+       int abund;
+};
+
+/***********************************************************************/
+#endif
+
diff --git a/sharedchao1.cpp b/sharedchao1.cpp
new file mode 100644 (file)
index 0000000..0536528
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ *  sharedchao1.cpp
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/8/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "sharedchao1.h"
+
+/***********************************************************************/
+EstOutput SharedChao1::getValues(SharedRAbundVector* sharedA, SharedRAbundVector* sharedB){
+       try {
+               data.resize(1,0);
+               
+               int f11, f1A, f2A, f1B, f2B, S12, tempA, tempB;
+               f11 = 0; f1A = 0; f2A = 0; f1B = 0; f2B = 0; S12 = 0;
+               float ChaoAB, part1, part2, part3;
+
+       /*      f11 = number of shared OTUs with one observed individual in A and B 
+               f1A, f2A = number of shared OTUs with one or two individuals observed in A 
+               f1B, f2B = number of shared OTUs with one or two individuals observed in B 
+               S12 = number of shared OTUs in A and B  */
+
+               //loop through vectors calculating the f11, f1A, f2A, f1B, f2B, S12 values
+               for (int i = 0; i< sharedA->size(); i++) {
+                       tempA = sharedA->getAbundance(i); //store in temps to avoid calling getAbundance multiple times
+                       tempB = sharedB->getAbundance(i);
+                       if ((tempA != 0) && (tempB != 0)) {//they are shared
+                               S12++; //they are shared
+                               //do both A and B have one
+                               if ((tempA == 1) && (tempB == 1)) { f11++; }
+                               
+                               //does A have one or two
+                               if (tempA == 1)                 { f1A++; }
+                               else if (tempA == 2)    { f2A++; }
+                               
+                               //does B have one or two
+                               if (tempB == 1)                 { f1B++; }
+                               else if (tempB == 2)    { f2B++; }
+                       }
+               }
+               
+               //checks for divide by zero error
+               if ((f2A == 0) || (f2B == 0)) {
+                       part1 = ((float)(f1A*f1B)/(float)(4*(f2A+1)*(f2B+1)));
+                       part2 = ((float)(f1A*(f1A-1))/(float)(2*f2A+2));
+                       part3 = ((float)(f1B*(f1B-1))/(float)(2*f2B+2));
+               }else {
+                       part1 = ((float)(f1A*f1B)/(float)(4*f2A*f2B));
+                       part2 = ((float)(f1A*f1A)/(float)(2*f2A));
+                       part3 = ((float)(f1B*f1B)/(float)(2*f2B));
+               }
+               
+               ChaoAB = (float)S12 + (float)(f11*part1) + part2 + part3;
+               data[0] = ChaoAB;
+               
+               return data;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SharedChao1 class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SharedChao1 class function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+
+}
+/***********************************************************************/
\ No newline at end of file
diff --git a/sharedchao1.h b/sharedchao1.h
new file mode 100644 (file)
index 0000000..86f718f
--- /dev/null
@@ -0,0 +1,30 @@
+#ifndef SHAREDCHAO1_H
+#define SHAREDCHAO1_H
+/*
+ *  sharedchao1.h
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/8/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+/* This class implements the Sharedchao1 estimator on two groups. 
+It is a child of the calculator class. */
+
+
+#include <Carbon/Carbon.h>
+#include "calculator.h"
+
+/***********************************************************************/
+
+class SharedChao1 : public Calculator  {
+       
+public: 
+       SharedChao1() : Calculator("SharedChao", 3) {};
+       EstOutput getValues(SAbundVector*) {return data;};
+       EstOutput getValues(SharedRAbundVector*, SharedRAbundVector*);
+};
+
+/***********************************************************************/
+#endif
\ No newline at end of file
diff --git a/sharedcommand.cpp b/sharedcommand.cpp
new file mode 100644 (file)
index 0000000..6c4c8ac
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ *  sharedcommand.cpp
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/2/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "sharedcommand.h"
+
+//**********************************************************************************************************************
+
+SharedCommand::SharedCommand(){
+       try {
+               globaldata = GlobalData::getInstance();
+               
+               //getting output filename
+               filename = globaldata->inputFileName;
+               filename = getRootName(filename);
+               filename = filename + "shared";
+               openOutputFile(filename, out);
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SharedCommand class Function SharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SharedCommand class function SharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+
+}
+//**********************************************************************************************************************
+
+int SharedCommand::execute(){
+       try {
+               globaldata = GlobalData::getInstance();
+                       
+               //read in listfile
+               read = new ReadPhilFile(globaldata->inputFileName);     
+               read->read(&*globaldata); 
+               input = globaldata->ginput;
+               list = globaldata->glist;
+               
+               shared = new Shared();
+               int i = 0;
+               while(list != NULL){
+                       shared->getSharedVectors(i, list); //fills sharedGroups with new info and updates sharedVector
+                       list = input->getListVector(); //get new list vector to process
+                       printSharedData(); //prints info to the .shared file
+                       i++;
+               }
+               return 0;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SharedCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SharedCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+
+}
+//**********************************************************************************************************************
+void SharedCommand::printSharedData() {
+       try {
+               //prints out horizontally
+               for (it = shared->sharedGroups.begin(); it != shared->sharedGroups.end(); it++) {
+                       out << it->second->getLabel() << "\t" << it->first << "\t"; //prints out label and groupname
+                       it->second->print(out); // prints sharedrabundvector
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SharedCommand class Function printSharedData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SharedCommand class function printSharedData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       
+}
+
+//**********************************************************************************************************************
+
+SharedCommand::~SharedCommand(){
+       //delete list;
+       delete read;
+}
+
+//**********************************************************************************************************************
diff --git a/sharedcommand.h b/sharedcommand.h
new file mode 100644 (file)
index 0000000..1b1df17
--- /dev/null
@@ -0,0 +1,51 @@
+#ifndef SHAREDCOMMAND_H
+#define SHAREDCOMMAND_H
+/*
+ *  sharedcommand.h
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/2/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include <Carbon/Carbon.h>
+#include <iostream>
+#include <fstream>
+#include <map>
+#include "command.hpp"
+#include "listvector.hpp"
+#include "inputdata.h"
+#include "shared.h"
+#include "readmatrix.hpp"
+
+/* The shared() command:
+       The shared command can only be executed after a successful read.shared command.  
+       The shared command parses a .list file and separates it into groups.  
+       It outputs a .shared file containing the OTU information for each group.  
+       There are no shared command parameters.  The shared command should be in the following format: shared(). */
+
+
+class GlobalData;
+
+class SharedCommand : public Command {
+       
+public:
+       SharedCommand();        
+       ~SharedCommand();
+       int execute();  
+       
+private:
+       void printSharedData();
+       GlobalData* globaldata;
+       ReadMatrix* read;
+       ListVector* list;
+       InputData* input;
+       Shared* shared;
+       map<string, SharedRAbundVector*>::iterator it;
+       ofstream out;
+       string filename;
+
+};
+
+#endif
\ No newline at end of file
diff --git a/sharedjabund.cpp b/sharedjabund.cpp
new file mode 100644 (file)
index 0000000..9cd938e
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ *  sharedjabund.cpp
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/8/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "sharedjabund.h"
+
+/***********************************************************************/
+
+EstOutput SharedJAbund::getValues(SharedRAbundVector* shared1, SharedRAbundVector* shared2) {
+       try {
+               EstOutput UVest;
+               UVest.resize(2,0);
+               data.resize(1,0);
+               
+               UVest = uv->getUVest(shared1, shared2);
+               
+               //UVest[0] is Uest UVest[1] is Vest
+               data[0] = (UVest[0] * UVest[1]) / ((float)(UVest[0] + UVest[1] - (UVest[0] * UVest[1])));
+               
+               if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; }
+               
+               return data;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SharedJAbund class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SharedJAbund class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+/***********************************************************************/
diff --git a/sharedjabund.h b/sharedjabund.h
new file mode 100644 (file)
index 0000000..cba2d98
--- /dev/null
@@ -0,0 +1,34 @@
+#ifndef SHAREDJABUND_H
+#define SHAREDJABUND_H
+/*
+ *  sharedjabund.h
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/8/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+/* This class implements the SharedJAbund estimator on two groups. 
+It is a child of the calculator class. */
+
+
+#include <Carbon/Carbon.h>
+#include "calculator.h"
+
+/***********************************************************************/
+
+class SharedJAbund : public Calculator  {
+       
+public:
+       SharedJAbund() :  Calculator("SharedJAbund", 3) {};
+       EstOutput getValues(SAbundVector*) {return data;};
+       EstOutput getValues(SharedRAbundVector*, SharedRAbundVector*);
+private:
+       UVEst* uv;
+       
+};
+
+/***********************************************************************/
+
+#endif
\ No newline at end of file
diff --git a/sharedjclass.cpp b/sharedjclass.cpp
new file mode 100644 (file)
index 0000000..52591f5
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ *  sharedjclass.cpp
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/8/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "sharedjclass.h"
+
+/***********************************************************************/
+
+EstOutput SharedJclass::getValues(SharedRAbundVector* shared1, SharedRAbundVector* shared2) {
+       try {
+               int S1, S2, S12, tempA, tempB;
+               S1 = 0; S2 = 0; S12 = 0; tempA = 0; tempB = 0; 
+               
+               /*S1, S2 = number of OTUs observed or estimated in A and B 
+               S12=number of OTUs shared between A and B */
+
+               data.resize(1,0);
+               
+               for (int i = 0; i < shared1->size(); i++) {
+                       //store in temps to avoid multiple repetitive function calls
+                       tempA = shared1->getAbundance(i);
+                       tempB = shared2->getAbundance(i);
+
+                       S1 += tempA;
+                       S2 += tempB;
+                       
+                       //they are shared
+                       if ((tempA != 0) && (tempB != 0)) {     S12++; }
+               }
+               
+               data[0] = S12 / (float)(S1 + S2 - S12);
+               
+               if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; }
+               
+               return data;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SharedJclass class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SharedJclass class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+/***********************************************************************/
diff --git a/sharedjclass.h b/sharedjclass.h
new file mode 100644 (file)
index 0000000..c35abff
--- /dev/null
@@ -0,0 +1,33 @@
+#ifndef SHAREDJCLASS_H
+#define SHAREDJCLASS_H
+/*
+ *  sharedjclass.h
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/8/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+/* This class implements the SharedJclass estimator on two groups. 
+It is a child of the calculator class. */
+
+
+#include <Carbon/Carbon.h>
+#include "calculator.h"
+
+/***********************************************************************/
+
+class SharedJclass : public Calculator  {
+       
+public:
+       SharedJclass() :  Calculator("SharedJclass", 3) {};
+       EstOutput getValues(SAbundVector*) {return data;};
+       EstOutput getValues(SharedRAbundVector*, SharedRAbundVector*);
+private:
+       
+};
+
+/***********************************************************************/
+
+#endif
\ No newline at end of file
diff --git a/sharedjest.cpp b/sharedjest.cpp
new file mode 100644 (file)
index 0000000..ba62e33
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ *  sharedjest.cpp
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/8/09.
+ *  Copyright 2009 Schloss Lab Umass Amherst. All rights reserved.
+ *
+ */
+#include "sharedchao1.h"
+#include "chao1.h"
+#include "sharedjest.h"
+
+
+/***********************************************************************/
+
+EstOutput SharedJest::getValues(SharedRAbundVector* shared1, SharedRAbundVector* shared2) {
+       try {
+               EstOutput S1, S2, S12;
+               S12.resize(1,0);
+               S1.resize(3,0);
+               S2.resize(3,0); 
+               
+               /*S1, S2 = number of OTUs estimated in A and B using the Chao estimator
+               S12 = estimated number of OTUs shared between A and B using the SharedChao estimator*/
+
+               data.resize(1,0);
+               
+               SharedChao1* sharedChao = new SharedChao1();
+               Chao1* chaoS1 = new Chao1();
+               Chao1* chaoS2 = new Chao1();
+               SAbundVector* chaoS1Sabund = new SAbundVector();
+               SAbundVector* chaoS2Sabund = new SAbundVector();
+               
+               *chaoS1Sabund = shared1->getSAbundVector();
+               *chaoS2Sabund = shared2->getSAbundVector();
+               
+               S12 = sharedChao->getValues(shared1, shared2);
+               S1 = chaoS1->getValues(chaoS1Sabund);
+               S2 = chaoS2->getValues(chaoS2Sabund);
+                               
+               data[0] = S12[0] / (float)(S1[0] + S2[0] - S12[0]);
+               
+               if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; }
+                
+               return data;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SharedJest class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SharedJest class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+/***********************************************************************/
+
+
diff --git a/sharedjest.h b/sharedjest.h
new file mode 100644 (file)
index 0000000..19f36f9
--- /dev/null
@@ -0,0 +1,35 @@
+#ifndef SHAREDJEST_H
+#define SHAREDJEST_H
+/*
+ *  sharedjest.h
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/8/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+/* This class implements the SharedJest estimator on two groups. 
+It is a child of the calculator class. */
+
+
+#include <Carbon/Carbon.h>
+#include "calculator.h"
+
+
+
+/***********************************************************************/
+
+class SharedJest : public Calculator  {
+       
+public:
+       SharedJest() :  Calculator("SharedJest", 3) {};
+       EstOutput getValues(SAbundVector*) {return data;};
+       EstOutput getValues(SharedRAbundVector*, SharedRAbundVector*);
+private:
+       
+};
+
+/***********************************************************************/
+
+#endif
diff --git a/sharedordervector.cpp b/sharedordervector.cpp
new file mode 100644 (file)
index 0000000..fc81feb
--- /dev/null
@@ -0,0 +1,273 @@
+/*
+ *  sharedSharedOrderVector.cpp
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 12/9/08.
+ *  Copyright 2008 __MyCompanyName__. All rights reserved.
+ *
+ */
+
+using namespace std;
+
+
+#include "sharedordervector.h"
+#include "datavector.hpp"
+#include "utilities.hpp"
+#include <exception>
+
+/***********************************************************************/
+
+SharedOrderVector::SharedOrderVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0)  {}
+
+/***********************************************************************/
+
+SharedOrderVector::SharedOrderVector(string id, vector<individual>  ov) : 
+                                                                                       DataVector(id), data(ov)
+{
+               updateStats();
+}
+
+/***********************************************************************
+
+SharedOrderVector::SharedOrderVector(ifstream& f) : DataVector() {
+       try {
+               int hold;
+       
+               f >> label;
+               f >> hold;
+       
+               data.assign(hold, -1);
+       
+               int inputData;
+       
+               for(int i=0;i<hold;i++){
+                       f >> inputData;
+                       set(i, inputData);
+               }
+       
+               updateStats();
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SharedOrderVector class Function SharedOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SharedOrderVector class function SharedOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+/***********************************************************************/
+
+
+int SharedOrderVector::getNumBins(){
+       if(needToUpdate == 1){  updateStats();  }
+       return numBins;
+}
+
+/***********************************************************************/
+
+int SharedOrderVector::getNumSeqs(){
+       if(needToUpdate == 1){  updateStats();  }
+       return numSeqs;
+}
+
+/***********************************************************************/
+
+int SharedOrderVector::getMaxRank(){
+       if(needToUpdate == 1){  updateStats();  }
+       return maxRank;
+}
+
+
+/***********************************************************************/
+
+
+
+void SharedOrderVector::set(int index, int binNumber, int abund, string groupName){
+       
+       data[index].group = groupName;
+       data[index].bin = binNumber;
+       data[index].abundance = abund;
+       needToUpdate = 1;
+       
+}
+
+/***********************************************************************/
+
+individual SharedOrderVector::get(int index){
+       return data[index];                     
+}
+
+
+/***********************************************************************/
+
+void SharedOrderVector::push_back(int binNumber, int abund, string groupName){
+       individual newGuy;
+       newGuy.group = groupName;
+       newGuy.abundance = abund;
+       newGuy.bin = binNumber;
+       data.push_back(newGuy);
+       needToUpdate = 1;
+       
+}
+
+/***********************************************************************/
+
+void SharedOrderVector::print(ostream& output){
+       try {
+               output << label << '\t' << numSeqs << '\t';
+       
+               for(int i=0;i<data.size();i++){
+                       output << data[i].bin << '\t';
+               }
+               output << endl;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SharedOrderVector class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SharedOrderVector class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+
+/***********************************************************************/
+
+void SharedOrderVector::resize(int){
+       cout << "resize() did nothing in class SharedOrderVector";
+}
+
+/***********************************************************************/
+
+
+vector<individual>::iterator SharedOrderVector::begin(){
+       return data.begin();    
+}
+
+/***********************************************************************/
+
+vector<individual>::iterator SharedOrderVector::end(){
+       return data.end();              
+}
+
+/***********************************************************************/
+
+int SharedOrderVector::size(){
+       return data.size();                                     
+}
+
+/***********************************************************************/
+
+RAbundVector SharedOrderVector::getRAbundVector(){
+       try {
+               RAbundVector rav(data.size());
+       
+               for(int i=0;i<numSeqs;i++){
+                       rav.set(data[i].bin, rav.get(data[i].bin) + 1);
+               }       
+               sort(rav.rbegin(), rav.rend());
+               for(int i=numSeqs-1;i>=0;i--){
+                       if(rav.get(i) == 0){    rav.pop_back(); }
+                       else{
+                               break;
+                       }
+               }
+               rav.setLabel(label);
+
+               return rav;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SharedOrderVector class Function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SharedOrderVector class function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+/***********************************************************************/
+
+OrderVector SharedOrderVector::getOrderVector(map<string,int>* nameMap = NULL) {
+       try {
+               OrderVector ov;
+       
+               for (int i = 0; i < data.size(); i++) {
+                       ov.push_back(data[i].bin);
+               }
+               
+               random_shuffle(ov.begin(), ov.end());
+
+               ov.setLabel(label);     
+               return ov;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SharedOrderVector class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SharedOrderVector class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+
+/***********************************************************************/
+
+SAbundVector SharedOrderVector::getSAbundVector(){
+       
+       RAbundVector rav(this->getRAbundVector());
+       return rav.getSAbundVector();
+
+}
+
+/***********************************************************************/
+
+SharedOrderVector SharedOrderVector::getSharedOrderVector(){
+       return *this;                   
+}
+
+/***********************************************************************/
+
+void SharedOrderVector::updateStats(){
+       try {
+               needToUpdate = 0;
+               numSeqs = 0;
+               numBins = 0;
+               maxRank = 0;
+       
+               for(int i=0;i<data.size();i++){
+                       if(data[i].bin != -1){
+                               numSeqs++;
+                       }
+               }
+       
+               vector<individual> hold(numSeqs);
+       
+               for(int i=0;i<numSeqs;i++){
+                       if(data[i].bin != -1){
+                               hold[data[i].bin].bin = hold[data[i].bin].bin+1;
+                       }
+               }       
+
+               for(int i=0;i<numSeqs;i++){
+                       if(data[i].bin > numBins) { numBins = data[i].bin;      } 
+                       if(data[i].abundance > maxRank) {       maxRank = data[i].abundance;    }
+               }
+               numBins++; //if you have 10 bins largest .bin is 9 since we start at 0.
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SharedOrderVector class Function updateStats. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SharedOrderVector class function updateStats. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+/***********************************************************************/
+
+
diff --git a/sharedordervector.h b/sharedordervector.h
new file mode 100644 (file)
index 0000000..ef9d6a7
--- /dev/null
@@ -0,0 +1,65 @@
+#ifndef SHAREDORDER_H
+#define SHAREDORDER_H
+/*
+ *  sharedorder.h
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 12/9/08.
+ *  Copyright 2008 __MyCompanyName__. All rights reserved.
+ *
+ */
+
+#include <Carbon/Carbon.h>
+#include "datavector.hpp"
+#include "sabundvector.hpp"
+#include "rabundvector.hpp"
+
+struct individual {
+               string group;
+               int bin;
+               int abundance;
+};
+
+
+class SharedOrderVector : public DataVector {
+       
+public:
+       SharedOrderVector();
+//     SharedOrderVector(int ns, int nb=0, int mr=0)   : DataVector(), data(ns, -1), maxRank(0), numBins(0), numSeqs(0) {};
+       SharedOrderVector(const SharedOrderVector& ov)  : DataVector(ov.label), data(ov.data), maxRank(ov.maxRank), numBins(ov.numBins), numSeqs(ov.numSeqs), needToUpdate(ov.needToUpdate) {if(needToUpdate == 1){     updateStats();}};
+
+       SharedOrderVector(string, vector<individual>);
+//     SharedOrderVector(ifstream&);
+       ~SharedOrderVector(){};
+       
+       void set(int, int, int, string);
+       individual get(int);
+       void push_back(int, int, string);
+       void resize(int);
+       int size();
+       void print(ostream&);
+       vector<individual>::iterator begin();
+       vector<individual>::iterator end();
+
+
+       int getNumBins();
+       int getNumSeqs();
+       int getMaxRank();
+               
+       RAbundVector getRAbundVector();
+       SAbundVector getSAbundVector();
+       OrderVector getOrderVector(map<string,int>*);
+       SharedOrderVector getSharedOrderVector();
+       
+private:
+       vector<individual>  data; 
+       map< int, vector<individual> >::iterator it;
+       int maxRank;
+       int numBins;
+       int numSeqs;
+       bool needToUpdate;
+       void updateStats();
+};
+
+#endif
+
diff --git a/sharedrabundvector.cpp b/sharedrabundvector.cpp
new file mode 100644 (file)
index 0000000..6bdeed0
--- /dev/null
@@ -0,0 +1,327 @@
+/*
+ *  sharedvector.cpp
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 12/5/08.
+ *  Copyright 2008 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+
+using namespace std;
+
+#include "sharedrabundvector.h" 
+#include "datavector.hpp"
+#include "utilities.hpp"
+#include <exception>
+#include "sharedrabundvector.h"
+#include "sabundvector.hpp"
+#include "ordervector.hpp"
+
+
+/***********************************************************************/
+
+SharedRAbundVector::SharedRAbundVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0) {};
+
+/***********************************************************************/
+
+SharedRAbundVector::SharedRAbundVector(int n) : DataVector(), maxRank(0), numBins(n), numSeqs(0) {
+               individual newGuy;
+               //initialize data
+               for (int i=0; i< n; i++) {
+                       newGuy.bin = i;
+                       newGuy.abundance = 0;
+                       data.push_back(newGuy);
+               }
+};
+
+/***********************************************************************
+
+SharedRAbundVector::SharedRAbundVector(string id, vector<individual> rav) : DataVector(id), data(rav) {
+       try {
+               numBins = 0;
+               maxRank = 0;
+               numSeqs = 0;
+               
+               for(int i=0;i<data.size();i++){
+                       if(data[i].abundance != 0)              {       numBins = i+1;          }
+                       if(data[i].abundance > maxRank) {       maxRank = data[i].abundance;    }
+                       numSeqs += data[i].abundance;
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function SharedRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SharedRAbundVector class function SharedRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+
+/***********************************************************************
+
+
+SharedRAbundVector::SharedRAbundVector(ifstream& f) : DataVector(), maxRank(0), numBins(0), numSeqs(0) {
+       try {
+               int i, hold;
+               individual newGuy;
+               
+               f >> label >> hold;
+               
+               //initialize data
+               for (i=0; i<hold; i++) {
+                       newGuy = new individual;
+                       newGuy.abundance = 0;
+                       newGuy.bin = i;
+                       data.push_back(newGuy);
+               }
+               int inputData;
+       
+               for(int i=0;i<hold;i++){
+                       f >> inputData;
+                       set(i, inputData);
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function SharedRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SharedRAbundVector class function SharedRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+/***********************************************************************/
+
+SharedRAbundVector::~SharedRAbundVector() {
+
+}
+
+/***********************************************************************/
+
+void SharedRAbundVector::set(int binNumber, int newBinSize, string groupname){
+       try {
+               int oldBinSize = data[binNumber].abundance;
+               data[binNumber].abundance = newBinSize;
+               data[binNumber].group = groupname;
+       
+               if(newBinSize > maxRank)        {       maxRank = newBinSize;   }
+       
+               numSeqs += (newBinSize - oldBinSize);
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SharedRAbundVector class function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+/***********************************************************************/
+
+int SharedRAbundVector::getAbundance(int index){
+       return data[index].abundance;
+       
+}
+
+/***********************************************************************/
+
+individual SharedRAbundVector::get(int index){
+       return data[index];
+       
+}
+
+/***********************************************************************/
+
+void SharedRAbundVector::push_back(int binSize, int otu, string groupName){
+       try {
+               individual newGuy;
+               newGuy.abundance = binSize;
+               newGuy.group = groupName;
+               newGuy.bin = otu;
+               
+               data.push_back(newGuy);
+               numBins++;
+       
+               if(binSize > maxRank){
+                       maxRank = binSize;
+               }
+       
+               numSeqs += binSize;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SharedRAbundVector class function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+/***********************************************************************/
+
+void SharedRAbundVector::pop_back(){
+
+       return data.pop_back();
+}
+
+/***********************************************************************/
+
+
+vector<individual>::reverse_iterator SharedRAbundVector::rbegin(){
+       return data.rbegin();                           
+}
+
+/***********************************************************************/
+
+vector<individual>::reverse_iterator SharedRAbundVector::rend(){
+       return data.rend();                                     
+}
+
+/***********************************************************************/
+void SharedRAbundVector::resize(int size){
+       
+       data.resize(size);
+}
+
+/***********************************************************************/
+
+int SharedRAbundVector::size(){
+       return data.size();
+}
+
+/***********************************************************************/
+void SharedRAbundVector::print(ostream& output){
+       try {
+               output << numBins << '\t';
+       
+               for(int i=0;i<numBins;i++){             output << data[i].abundance << '\t';            }
+               output << endl;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SharedRAbundVector class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+/***********************************************************************/
+string SharedRAbundVector::getGroup(){
+       return group;
+}
+
+/***********************************************************************/
+
+void SharedRAbundVector::setGroup(string groupName){
+       group = groupName;
+}
+
+
+/***********************************************************************/
+int SharedRAbundVector::getNumBins(){
+       return numBins;
+}
+
+/***********************************************************************/
+
+int SharedRAbundVector::getNumSeqs(){
+       return numSeqs;
+}
+
+/***********************************************************************/
+
+int SharedRAbundVector::getMaxRank(){
+       return maxRank;
+}
+
+/***********************************************************************/
+
+SharedRAbundVector SharedRAbundVector::getSharedRAbundVector(){
+       return *this;                   
+}
+
+/***********************************************************************/
+
+SAbundVector SharedRAbundVector::getSAbundVector() {
+       try {
+               SAbundVector sav(maxRank+1);
+               
+               for(int i=0;i<data.size();i++){
+                       int abund = data[i].abundance;
+                       sav.set(abund, sav.get(abund) + 1);
+               }
+               sav.set(0, 0);
+               sav.setLabel(label);
+               return sav;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SharedRAbundVector class function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+/***********************************************************************/
+
+SharedOrderVector SharedRAbundVector::getSharedOrderVector() {
+       try {
+               SharedOrderVector ov;
+       
+               for(int i=0;i<data.size();i++){
+                       for(int j=0;j<data[i].abundance;j++){
+                               ov.push_back(data[i].bin, data[i].abundance, data[i].group);
+                       }
+               }
+               random_shuffle(ov.begin(), ov.end());
+
+               ov.setLabel(label);     
+               return ov;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SharedRAbundVector class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+/***********************************************************************/
+
+OrderVector SharedRAbundVector::getOrderVector(map<string,int>* nameMap = NULL) {
+       try {
+               OrderVector ov;
+       
+               for(int i=0;i<data.size();i++){
+                       for(int j=0;j<data[i].abundance;j++){
+                               ov.push_back(i);
+                       }
+               }
+               random_shuffle(ov.begin(), ov.end());
+
+               ov.setLabel(label);     
+               return ov;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SharedRAbundVector class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+/***********************************************************************/
+
diff --git a/sharedrabundvector.h b/sharedrabundvector.h
new file mode 100644 (file)
index 0000000..6f8d630
--- /dev/null
@@ -0,0 +1,63 @@
+#ifndef SHAREDVECTOR_H
+#define SHAREDVECTOR_H
+
+/*
+ *  sharedvector.h
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 12/5/08.
+ *  Copyright 2008 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include <Carbon/Carbon.h>
+#include "datavector.hpp"
+#include "sharedordervector.h"
+
+
+
+
+class SharedRAbundVector : public DataVector {
+       
+public:
+       SharedRAbundVector();
+       SharedRAbundVector(int);
+       //SharedRAbundVector(string, vector<int>);
+       SharedRAbundVector(const SharedRAbundVector& bv) : DataVector(bv), data(bv.data), maxRank(bv.maxRank), numBins(bv.numBins), numSeqs(bv.numSeqs){};
+//     SharedRAbundVector(ifstream&);
+       ~SharedRAbundVector();
+
+       int getNumBins();               
+       int getNumSeqs();                                                       
+       int getMaxRank();
+       string getGroup();
+       void setGroup(string);                                                  
+
+       void set(int, int, string);     
+       individual get(int);
+       int getAbundance(int);
+       void push_back(int, int, string);
+       void pop_back();
+       void resize(int);
+       int size();
+       vector<individual>::reverse_iterator rbegin();
+       vector<individual>::reverse_iterator rend();
+       
+       void print(ostream&);
+               
+       SharedRAbundVector getSharedRAbundVector();
+       SAbundVector getSAbundVector();
+       OrderVector getOrderVector(map<string,int>*);
+       SharedOrderVector getSharedOrderVector();
+       
+private:
+       vector<individual>  data; 
+       int maxRank;
+       int numBins;
+       int numSeqs;
+       string group;   
+};
+
+
+#endif
+
diff --git a/sharedsabundvector.cpp b/sharedsabundvector.cpp
new file mode 100644 (file)
index 0000000..5175f5e
--- /dev/null
@@ -0,0 +1,336 @@
+/*
+ *  sharedSharedSAbundVector.cpp
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 12/10/08.
+ *  Copyright 2008 __MyCompanyName__. All rights reserved.
+ *
+ */
+
+#include "sharedsabundvector.h"
+#include "sabundvector.hpp"
+#include "datavector.hpp"
+#include "utilities.hpp"
+#include <exception>
+
+using namespace std;
+
+
+/***********************************************************************/
+
+SharedSAbundVector::SharedSAbundVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0){};
+
+/***********************************************************************/
+
+SharedSAbundVector::SharedSAbundVector(int size) :     DataVector(), maxRank(0), numBins(0), numSeqs(0) {
+               individual newGuy;
+               //initialize data
+               for (int i=0; i< size; i++) {
+                       newGuy.bin = i;
+                       newGuy.abundance = 0;
+                       data.push_back(newGuy);
+               }
+       //      for(int i=0;i<data.size();i++){
+       //              if(data[i].abundance != 0){     maxRank = i;    }
+       //              numSeqs += i*data[i].abundance;
+       //              numBins += data[i].abundance;
+       //      }
+
+};
+
+/***********************************************************************
+
+SharedSAbundVector::SharedSAbundVector(string id, vector<int> sav) : DataVector(id), data(sav) {
+       try {
+               
+               for(int i=0;i<sav.size();i++){
+                       if(data[i] != 0){       maxRank = i;    }
+                       numSeqs += i*data[i];
+                       numBins += data[i];
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SharedSAbundVector class Function SharedSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SharedSAbundVector class function SharedSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+/***********************************************************************
+
+SharedSAbundVector::SharedSAbundVector(ifstream& f): DataVector(), maxRank(0), numBins(0), numSeqs(0) {
+       try {
+               int hold;
+               f >> label >> hold;
+       
+               data.assign(hold+1, 0);
+               int inputData;
+       
+               for(int i=1;i<=hold;i++){
+                       f >> inputData;
+                       set(i, inputData);
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SharedSAbundVector class Function SharedSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SharedSAbundVector class function SharedSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+/***********************************************************************/
+
+void SharedSAbundVector::set(int bin, int abundance, string groupName){
+       try {
+
+               int initSize = data[bin].abundance;
+               data[bin].abundance = abundance;
+               data[bin].group = groupName;
+       
+               if(bin != 0){
+                       numBins += (abundance - initSize);
+               }
+       
+               numSeqs += bin * (abundance - initSize);
+       
+               if(bin > maxRank)       {       maxRank = bin;          }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SharedSAbundVector class Function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SharedSAbundVector class function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+/***********************************************************************/
+
+individual SharedSAbundVector::get(int index){
+       return data[index];
+}
+/***********************************************************************/
+
+int SharedSAbundVector::getAbundance(int index){
+       return data[index].abundance;
+}
+
+/***********************************************************************/
+
+void SharedSAbundVector::push_back(int abundance, int bin, string groupName){
+       try {
+               individual newGuy;
+               newGuy.abundance = abundance;
+               newGuy.bin = bin;
+               newGuy.group = groupName;
+               
+               data.push_back(newGuy);
+       
+               maxRank++;      
+       
+               numBins += abundance;
+       
+               numSeqs += (maxRank * abundance);
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SharedSAbundVector class Function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SharedSAbundVector class function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }               
+}
+
+/***********************************************************************/
+
+void SharedSAbundVector::resize(int size){
+       data.resize(size);
+}
+
+/***********************************************************************/
+
+int SharedSAbundVector::size(){
+       return data.size();             
+}
+
+/***********************************************************************/
+void SharedSAbundVector::print(ostream& output){
+       try {
+               output << label << '\t' << maxRank << '\t';
+       
+               for(int i=1;i<=maxRank;i++){
+                       output << data[i].abundance << '\t';
+               }
+               output << endl;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SharedSAbundVector class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SharedSAbundVector class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }               
+}
+/***********************************************************************/
+string SharedSAbundVector::getGroup(){
+       return group;
+}
+
+/***********************************************************************/
+
+void SharedSAbundVector::setGroup(string groupName){
+       group = groupName;
+}
+
+/**********************************************************************/
+int SharedSAbundVector::getNumBins(){
+       return numBins;
+}
+
+/***********************************************************************/
+
+int SharedSAbundVector::getNumSeqs(){
+       return numSeqs;
+}
+
+/***********************************************************************/
+
+int SharedSAbundVector::getMaxRank(){
+       return maxRank;
+}
+/***********************************************************************/
+RAbundVector SharedSAbundVector::getRAbundVector(){
+       try {
+               RAbundVector rav;
+       
+               for(int i=1;i<=data.size();i++){                
+                       for(int j=0;j<data[i].abundance;j++){
+                               rav.push_back(i);
+                       }
+               }
+               sort(rav.rbegin(), rav.rend());
+       
+               rav.setLabel(label);
+               return rav;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SharedSAbundVector class Function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SharedSAbundVector class function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }               
+}
+/***********************************************************************/
+SAbundVector SharedSAbundVector::getSAbundVector(){
+       try {
+               RAbundVector rav;
+               SAbundVector sav;
+               
+               rav = getRAbundVector();
+               sav = rav.getSAbundVector();
+               return sav;
+       
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SharedSAbundVector class Function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SharedSAbundVector class function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }               
+}
+
+/***********************************************************************/
+
+bool compareMembers (individual member, individual member2){
+
+  if(member.abundance < member2.abundance){
+    return true;   }   
+  else{
+       return false; 
+  }
+}
+
+/***********************************************************************/
+SharedRAbundVector SharedSAbundVector::getSharedVector(){
+       try {
+               SharedRAbundVector rav;
+               
+               int binNumber = 0;
+               for(int i=1;i<=data.size();i++){                
+                       for(int j=0;j<data[i].abundance;j++){
+                               rav.push_back(i, binNumber, data[i].group);
+                               binNumber++;
+                       }
+               }
+               sort(rav.rbegin(), rav.rend(), compareMembers);
+       
+               rav.setLabel(label);
+               rav.setGroup(group);
+               
+               return rav;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SharedSAbundVector class Function getSharedVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SharedSAbundVector class function getSharedVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }               
+}
+
+
+/***********************************************************************/
+
+SharedSAbundVector SharedSAbundVector::getSharedSAbundVector(){
+       return *this;                   
+}
+
+/***********************************************************************/
+
+OrderVector SharedSAbundVector::getOrderVector(map<string,int>* hold = NULL){
+       try {
+               OrderVector ov;
+       
+               int binIndex = 0;
+       
+               for(int i=1;i<data.size();i++){
+                       for(int j=0;j<data[i].abundance;j++){
+                               for(int k=0;k<i;k++){
+                                       ov.push_back(binIndex);
+                               }
+                               binIndex++;
+                       }
+               }
+       
+               random_shuffle(ov.begin(), ov.end());
+
+               ov.setLabel(label);
+               ov.getNumBins();
+               return ov;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SharedSAbundVector class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SharedSAbundVector class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }               
+}
+
+/***********************************************************************/
+
diff --git a/sharedsabundvector.h b/sharedsabundvector.h
new file mode 100644 (file)
index 0000000..7010968
--- /dev/null
@@ -0,0 +1,64 @@
+#ifndef SHAREDSABUND_H
+#define SHAREDSABUND_H
+
+
+/*
+ *  sharedSharedSAbundVector.h
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 12/10/08.
+ *  Copyright 2008 __MyCompanyName__. All rights reserved.
+ *
+ */
+
+
+#include <Carbon/Carbon.h>
+#include "datavector.hpp"
+#include "rabundvector.hpp"
+#include "ordervector.hpp"
+#include "sharedordervector.h"
+#include "sharedrabundvector.h"
+
+using namespace std;
+
+class SharedSAbundVector : public DataVector {
+       
+public:
+       SharedSAbundVector();
+       SharedSAbundVector(int);
+       SharedSAbundVector(const SharedSAbundVector& rv) : DataVector(rv.label), data(rv.data), maxRank(rv.maxRank), numBins(rv.numBins), numSeqs(rv.numSeqs){};
+       ~SharedSAbundVector(){};
+
+       int getNumBins();       
+       int getNumSeqs();       
+       int getMaxRank();       
+       string getGroup();
+       void setGroup(string);  
+       
+       void set(int, int, string);     
+       individual get(int);
+       int getAbundance(int);
+       void push_back(int, int, string);
+       void pop_back();
+       void resize(int);
+       int size();
+
+       void print(ostream&);
+               
+       RAbundVector getRAbundVector(); 
+       SAbundVector getSAbundVector();
+       SharedSAbundVector getSharedSAbundVector();
+       SharedRAbundVector getSharedVector();
+       OrderVector getOrderVector(map<string,int>*);
+       
+private:
+       vector<individual> data;
+       
+       int maxRank;
+       int numBins;
+       int numSeqs;
+       string group;
+};
+
+#endif
+
diff --git a/sharedsobs.cpp b/sharedsobs.cpp
new file mode 100644 (file)
index 0000000..14f5bf5
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ *  sharedsobs.cpp
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/7/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "sharedsobs.h"
+
+/***********************************************************************/
+//This returns the number of unique species observed in several groups.  
+//The shared vector is each groups sharedrabundvector.
+
+EstOutput SharedSobs::getValues(SharedRAbundVector* shared1, SharedRAbundVector* shared2){
+       try {
+               data.resize(1,0);
+               int observed = 0;;
+
+               //loop through the species in each group
+               for (int k = 0; k < shared1->size(); k++) {
+                       //if you have found a new species
+                       if (shared1->getAbundance(k) != 0) { observed++; } 
+                       else if ((shared1->getAbundance(k) == 0) && (shared2->getAbundance(k) != 0)) { observed++; }
+               }
+
+               data[0] = observed;
+               return data;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SharedSobs class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SharedSobs class function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+/***********************************************************************/
diff --git a/sharedsobs.h b/sharedsobs.h
new file mode 100644 (file)
index 0000000..3a7037e
--- /dev/null
@@ -0,0 +1,31 @@
+#ifndef SHAREDSOBS_H
+#define SHAREDSOBS_H
+/*
+ *  sharedsobs.h
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/7/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+/* This class implements the SharedSobs estimator on two groups. 
+It is a child of the calculator class. */
+
+
+#include <Carbon/Carbon.h>
+#include "calculator.h"
+
+/***********************************************************************/
+class SharedSobs : public Calculator {
+
+public:
+       SharedSobs() : Calculator("SharedSobs", 1) {};
+       EstOutput getValues(SAbundVector* rank){ return data; };
+       EstOutput getValues(SharedRAbundVector* shared1, SharedRAbundVector* shared2);
+};
+
+/***********************************************************************/
+
+#endif
+
diff --git a/sharedsorabund.cpp b/sharedsorabund.cpp
new file mode 100644 (file)
index 0000000..e895381
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ *  sharedsorabund.cpp
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/8/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "sharedsorabund.h"
+
+/***********************************************************************/
+
+EstOutput SharedSorAbund::getValues(SharedRAbundVector* shared1, SharedRAbundVector* shared2) {
+       try {
+               EstOutput UVest;
+               UVest.resize(2,0);
+               data.resize(1,0);
+               
+               UVest = uv->getUVest(shared1, shared2);
+               
+               //UVest[0] is Uest, UVest[1] is Vest
+               data[0] = (2 * UVest[0] * UVest[1]) / ((float)(UVest[0] + UVest[1]));
+               
+               if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; }
+               
+               return data;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SharedSorAbund class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SharedSorAbund class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+/***********************************************************************/
+
diff --git a/sharedsorabund.h b/sharedsorabund.h
new file mode 100644 (file)
index 0000000..7fd6434
--- /dev/null
@@ -0,0 +1,33 @@
+#ifndef SHAREDSORABUND_H
+#define SHAREDSORABUND_H
+/*
+ *  sharedsorabund.h
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/8/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+/* This class implements the SharedSorAbund estimator on two groups. 
+It is a child of the calculator class. */
+
+
+#include <Carbon/Carbon.h>
+#include "calculator.h"
+
+/***********************************************************************/
+
+class SharedSorAbund : public Calculator  {
+       
+public:
+       SharedSorAbund() :  Calculator("SharedSorAbund", 3) {};
+       EstOutput getValues(SAbundVector*) {return data;};
+       EstOutput getValues(SharedRAbundVector*, SharedRAbundVector*);
+private:
+       UVEst* uv;
+       
+};
+/***********************************************************************/
+
+#endif
diff --git a/sharedsorclass.cpp b/sharedsorclass.cpp
new file mode 100644 (file)
index 0000000..c9debf7
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ *  sharedsorclass.cpp
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/8/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "sharedsorclass.h"
+
+/***********************************************************************/
+
+EstOutput SharedSorClass::getValues(SharedRAbundVector* shared1, SharedRAbundVector* shared2) {
+       try {
+               int S1, S2, S12, tempA, tempB;
+               S1 = 0; S2 = 0; S12 = 0; tempA = 0; tempB = 0; 
+               
+               /*S1, S2 = number of OTUs observed or estimated in A and B 
+               S12=number of OTUs shared between A and B */
+
+               data.resize(1,0);
+               
+               for (int i = 0; i < shared1->size(); i++) {
+                       //store in temps to avoid multiple repetitive function calls
+                       tempA = shared1->getAbundance(i);
+                       tempB = shared2->getAbundance(i);
+
+                       S1 += tempA;
+                       S2 += tempB;
+                       
+                       //they are shared
+                       if ((tempA != 0) && (tempB != 0)) {     S12++; }
+               }
+               
+               data[0] = (2 * S12) / (float)(S1 + S2);
+               
+               if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; }
+               
+               return data;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SharedSorClass class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SharedSorClass class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+/***********************************************************************/
diff --git a/sharedsorclass.h b/sharedsorclass.h
new file mode 100644 (file)
index 0000000..d8702ff
--- /dev/null
@@ -0,0 +1,32 @@
+#ifndef SHAREDSORCLASS_H
+#define SHAREDSORCLASS_H
+/*
+ *  sharedsorclass.h
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/8/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+/* This class implements the SharedSorClass estimator on two groups. 
+It is a child of the calculator class. */
+
+
+#include <Carbon/Carbon.h>
+#include "calculator.h"
+
+/***********************************************************************/
+
+class SharedSorClass : public Calculator  {
+       
+public:
+       SharedSorClass() :  Calculator("SharedSorClass", 3) {};
+       EstOutput getValues(SAbundVector*) {return data;};
+       EstOutput getValues(SharedRAbundVector*, SharedRAbundVector*);
+private:
+       
+};
+/***********************************************************************/
+
+#endif
\ No newline at end of file
diff --git a/sharedsorest.cpp b/sharedsorest.cpp
new file mode 100644 (file)
index 0000000..4f44b91
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ *  sharedsorest.cpp
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/8/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "sharedsorest.h"
+#include "chao1.h"
+#include "sharedchao1.h"
+
+/***********************************************************************/
+
+EstOutput SharedSorEst::getValues(SharedRAbundVector* shared1, SharedRAbundVector* shared2) {
+       try {
+               EstOutput S1, S2, S12;
+               S12.resize(1,0);
+               S1.resize(3,0);
+               S2.resize(3,0); 
+               
+               /*S1, S2 = number of OTUs estimated in A and B using the Chao estimator
+               S12 = estimated number of OTUs shared between A and B using the SharedChao estimator*/
+
+               data.resize(1,0);
+               
+               SharedChao1* sharedChao = new SharedChao1();
+               Chao1* chaoS1 = new Chao1();
+               Chao1* chaoS2 = new Chao1();
+               SAbundVector* chaoS1Sabund = new SAbundVector();
+               SAbundVector* chaoS2Sabund = new SAbundVector();
+               
+               *chaoS1Sabund = shared1->getSAbundVector();
+               *chaoS2Sabund = shared2->getSAbundVector();
+               
+               S12 = sharedChao->getValues(shared1, shared2);
+               S1 = chaoS1->getValues(chaoS1Sabund);
+               S2 = chaoS2->getValues(chaoS2Sabund);
+               
+               data[0] = (2 * S12[0]) / (float)(S1[0] + S2[0]);
+                
+               if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; }
+               
+               return data;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SharedSorEst class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SharedSorEst class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+/***********************************************************************/
diff --git a/sharedsorest.h b/sharedsorest.h
new file mode 100644 (file)
index 0000000..1795f66
--- /dev/null
@@ -0,0 +1,33 @@
+#ifndef SHAREDSOREST_H
+#define SHAREDSOREST_H
+/*
+ *  sharedsorest.h
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/8/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+/* This class implements the SharedSorEst estimator on two groups. 
+It is a child of the calculator class. */
+
+
+#include <Carbon/Carbon.h>
+#include "calculator.h"
+
+/***********************************************************************/
+
+class SharedSorEst : public Calculator  {
+       
+public:
+       SharedSorEst() :  Calculator("SharedSorEst", 3) {};
+       EstOutput getValues(SAbundVector*) {return data;};
+       EstOutput getValues(SharedRAbundVector*, SharedRAbundVector*);
+private:
+       
+};
+
+/***********************************************************************/
+
+#endif
diff --git a/sharedthetan.cpp b/sharedthetan.cpp
new file mode 100644 (file)
index 0000000..3293689
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ *  sharedthetan.cpp
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/8/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "sharedthetan.h"
+
+/***********************************************************************/
+EstOutput SharedThetaN::getValues(SharedRAbundVector* shared1, SharedRAbundVector* shared2) {
+       try {   
+               data.resize(1,0);
+               
+               int Atotal, Btotal, tempA, tempB;
+               Atotal = 0; Btotal = 0; 
+               float numerator, denominator, thetaN, sumSharedA, sumSharedB, a, b, d;
+               numerator = 0.0; denominator = 0.0; thetaN = 0.0; sumSharedA = 0.0; sumSharedB = 0.0; a = 0.0; b = 0.0; d = 0.0;
+               
+               //get the total values we need to calculate the theta denominator sums
+               for (int i = 0; i < shared1->size(); i++) {
+                       //store in temps to avoid multiple repetitive function calls
+                       Atotal += shared1->getAbundance(i);
+                       Btotal += shared2->getAbundance(i);
+               }
+               
+               //calculate the theta denominator sums
+               for (int j = 0; j < shared1->size(); j++) {
+                       //store in temps to avoid multiple repetitive function calls
+                       tempA = shared1->getAbundance(j);
+                       tempB = shared2->getAbundance(j);
+                       
+                       //they are shared
+                       if ((tempA != 0) && (tempB != 0)) {
+                               if (Atotal != 0)        { sumSharedA = (tempA / (float)Atotal); }
+                               if (Btotal != 0)        { sumSharedB = (tempB / (float)Btotal); }
+                       
+                               a += sumSharedA;
+                               b += sumSharedB;
+                       }
+               }
+
+               thetaN = (a * b) / (a + b - (a * b));
+               
+               if (isnan(thetaN) || isinf(thetaN)) { thetaN = 0; }
+               
+               data[0] = thetaN;
+               
+               return data;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SharedThetaN class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SharedThetaN class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+/***********************************************************************/
diff --git a/sharedthetan.h b/sharedthetan.h
new file mode 100644 (file)
index 0000000..b6f2c87
--- /dev/null
@@ -0,0 +1,33 @@
+#ifndef SHAREDTHETAN_H
+#define SHAREDTHETAN_H
+/*
+ *  sharedthetan.h
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/8/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+/* This class implements the SharedThetaN estimator on two groups. 
+It is a child of the calculator class. */
+
+
+#include <Carbon/Carbon.h>
+#include "calculator.h"
+
+/***********************************************************************/
+
+class SharedThetaN : public Calculator  {
+       
+public:
+       SharedThetaN() :  Calculator("SharedThetaN", 3) {};
+       EstOutput getValues(SAbundVector*) {return data;};
+       EstOutput getValues(SharedRAbundVector*, SharedRAbundVector*);
+private:
+       
+};
+
+/***********************************************************************/
+
+#endif
\ No newline at end of file
diff --git a/sharedthetayc.cpp b/sharedthetayc.cpp
new file mode 100644 (file)
index 0000000..a055b66
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ *  sharedthetayc.cpp
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/8/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "sharedthetayc.h"
+
+/***********************************************************************/
+EstOutput SharedThetaYC::getValues(SharedRAbundVector* shared1, SharedRAbundVector* shared2) {
+       try {   
+               data.resize(1,0);
+               
+               int Atotal, Btotal, tempA, tempB;
+               Atotal = 0; Btotal = 0; 
+               float numerator, denominator, thetaYC, sumSharedA, sumSharedB, a, b, d;
+               numerator = 0.0; denominator = 0.0; thetaYC = 0.0; sumSharedA = 0.0; sumSharedB = 0.0; a = 0.0; b = 0.0; d = 0.0;
+               
+               //get the total values we need to calculate the theta denominator sums
+               for (int i = 0; i < shared1->size(); i++) {
+                       //store in temps to avoid multiple repetitive function calls
+                       Atotal += shared1->getAbundance(i);
+                       Btotal += shared2->getAbundance(i);
+               }
+               
+               //calculate the theta denominator sums
+               for (int j = 0; j < shared1->size(); j++) {
+                       //store in temps to avoid multiple repetitive function calls
+                       tempA = shared1->getAbundance(j);
+                       tempB = shared2->getAbundance(j);
+                       
+                       //they are shared
+                       if ((tempA != 0) && (tempB != 0)) {
+                               if (Atotal != 0)        { sumSharedA = (tempA / (float)Atotal); }
+                               if (Btotal != 0)        { sumSharedB = (tempB / (float)Btotal); }
+                       
+                               a += sumSharedA * sumSharedA;
+                               b += sumSharedB * sumSharedB;
+                               d += sumSharedA * sumSharedB;
+                       }
+               }
+
+               thetaYC = d / (float) (a + b - d);
+               
+               if (isnan(thetaYC) || isinf(thetaYC)) { thetaYC = 0; }
+               
+               data[0] = thetaYC;
+               
+               return data;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SharedThetaYC class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SharedThetaYC class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+/***********************************************************************/
diff --git a/sharedthetayc.h b/sharedthetayc.h
new file mode 100644 (file)
index 0000000..9c69fb1
--- /dev/null
@@ -0,0 +1,33 @@
+#ifndef SHAREDTHETAYC_H
+#define SHAREDTHETAYC_H
+/*
+ *  sharedthetayc.h
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/8/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+/* This class implements the SharedThetaYC estimator on two groups. 
+It is a child of the calculator class. */
+
+
+#include <Carbon/Carbon.h>
+#include "calculator.h"
+
+/***********************************************************************/
+
+class SharedThetaYC : public Calculator  {
+       
+public:
+       SharedThetaYC() :  Calculator("SharedThetaYC", 3) {};
+       EstOutput getValues(SAbundVector*) {return data;};
+       EstOutput getValues(SharedRAbundVector*, SharedRAbundVector*);
+private:
+       
+};
+
+/***********************************************************************/
+ #endif
+
diff --git a/simpson.cpp b/simpson.cpp
new file mode 100644 (file)
index 0000000..758c4a3
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ *  simpson.cpp
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/7/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "simpson.h"
+
+/***********************************************************************/
+
+EstOutput Simpson::getValues(SAbundVector* rank){
+       try {
+               //vector<double> simpsonData(3,0);
+               data.resize(3,0);
+               double simpson = 0.0000;
+               double ci = 0;
+       
+               double maxRank = (double)rank->getMaxRank();
+               int sampled = rank->getNumSeqs();
+               int sobs = rank->getNumBins();
+       
+               double firstTerm = 0;
+               double secondTerm = 0;
+       
+               if(sobs != 0){
+                       double simnum=0.0000;
+               
+                       for(int i=1;i<=maxRank;i++){
+                               simnum += (double)(rank->get(i)*i*(i-1));
+                       }
+               
+                       simpson = simnum / (double)(sampled*(sampled-1));
+               
+                       for(int i=1;i<=maxRank;i++){
+                               double piI = (double) i / (double)sampled;
+                               firstTerm += rank->get(i) * pow(piI, 3);
+                               secondTerm += rank->get(i) * pow(piI, 2);
+                       }
+               
+                       double var = (4.0 / (double)sampled) * (firstTerm - secondTerm*secondTerm);
+                       ci = 1.95 * pow(var, 0.5);
+               }
+       
+               double simpsonlci = simpson - ci;
+               double simpsonhci = simpson + ci;
+               
+               data[0] = simpson;
+               data[1] = simpsonlci;
+               data[2] = simpsonhci;
+               
+               if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; }
+               if (isnan(data[1]) || isinf(data[1])) { data[1] = 0; }
+               if (isnan(data[2]) || isinf(data[2])) { data[2] = 0; }
+       
+               return data;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the Simpson class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the Simpson class function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+/***********************************************************************/
diff --git a/simpson.h b/simpson.h
new file mode 100644 (file)
index 0000000..968d5a1
--- /dev/null
+++ b/simpson.h
@@ -0,0 +1,31 @@
+#ifndef SIMPSON_H
+#define SIMPSON_H
+/*
+ *  simpson.h
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/7/09.
+ *  Copyright 2009 Schloss Lab Umass Amherst. All rights reserved.
+ *
+ */
+
+/* This class implements the Simpson estimator on single group. 
+It is a child of the calculator class. */
+
+
+#include <Carbon/Carbon.h>
+#include "calculator.h"
+
+/***********************************************************************/
+
+class Simpson : public Calculator  {
+
+public:
+       Simpson() : Calculator("Simpson", 3) {};
+       EstOutput getValues(SAbundVector*);
+       EstOutput getValues(SharedRAbundVector*, SharedRAbundVector*) {return data;};
+};
+
+/***********************************************************************/
+
+#endif
\ No newline at end of file
diff --git a/singlelinkage.cpp b/singlelinkage.cpp
new file mode 100644 (file)
index 0000000..3c26977
--- /dev/null
@@ -0,0 +1,70 @@
+
+#include "cluster.hpp"
+#include <exception>
+
+/***********************************************************************/
+
+SingleLinkage::SingleLinkage(RAbundVector* rav, ListVector* lv, SparseMatrix* dm) :
+Cluster(rav, lv, dm)
+{}
+
+/***********************************************************************/
+//This function clusters based on nearest method.
+void SingleLinkage::update(){
+       try {
+               getRowColCells();               
+       
+               for(int i=1;i<nRowCells;i++){
+               
+                       int search;
+               
+                       if(rowCells[i]->row == smallRow){
+                               search = rowCells[i]->column;
+                       }
+                       else{
+                               search = rowCells[i]->row;
+                       }
+               
+                       for(int j=1;j<nColCells;j++){
+                       
+                               if(colCells[j]->row == search || colCells[j]->column == search){
+                               
+                                       if(colCells[j]->dist > rowCells[i]->dist){
+                                               colCells[j]->dist = rowCells[i]->dist;
+                                       
+                                               if(colCells[j]->vectorMap != NULL){
+                                                       *(colCells[j]->vectorMap) = NULL;
+                                                       colCells[j]->vectorMap = NULL;
+                                               }
+                                       
+                                       }
+                                       dMatrix->rmCell(rowCells[i]);
+                                       break;
+                               }
+                       }                       
+               
+                       if(search < smallCol){
+                               rowCells[i]->row = smallCol;
+                               rowCells[i]->column = search;
+                       }
+                       else{
+                               rowCells[i]->row = search;
+                               rowCells[i]->column = smallCol;
+                       }
+               
+               }       
+               clusterBins();
+               clusterNames();
+               dMatrix->rmCell(rowCells[0]);
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SingleLinkage class Function update. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SingleLinkage class function update. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+/***********************************************************************/
diff --git a/sobs.h b/sobs.h
new file mode 100644 (file)
index 0000000..3162f70
--- /dev/null
+++ b/sobs.h
@@ -0,0 +1,35 @@
+#ifndef SOBS_H
+#define SOBS_H
+/*
+ *  sobs.h
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/7/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+/* This class implements the Sobs estimator on single group. 
+It is a child of the calculator class. */
+
+
+#include <Carbon/Carbon.h>
+#include "calculator.h"
+
+/***********************************************************************/
+
+class Sobs : public Calculator {
+
+public:
+       Sobs() : Calculator("Sobs", 1) {};
+       EstOutput getValues(SAbundVector* rank){
+               data.resize(1,0);
+               data[0] = (double)rank->getNumBins();
+               return data;
+       }
+       EstOutput getValues(SharedRAbundVector* shared1, SharedRAbundVector* shared2) {return data;};
+};
+
+/***********************************************************************/
+
+#endif
\ No newline at end of file
diff --git a/sparsematrix.cpp b/sparsematrix.cpp
new file mode 100644 (file)
index 0000000..6eaf3ec
--- /dev/null
@@ -0,0 +1,208 @@
+#include <vector>
+#include <iostream>
+#include <list>
+#include "utilities.hpp"
+#include "sparsematrix.hpp"
+#include "listvector.hpp"
+#include <exception>
+
+using namespace std;
+
+typedef list<PCell>::iterator MatData;
+
+/***********************************************************************/
+
+SparseMatrix::SparseMatrix() : numNodes(0), minsIndex(0), smallDist(1e6){};
+
+/***********************************************************************/
+
+int SparseMatrix::getNNodes(){
+       return numNodes; 
+}
+
+/***********************************************************************/
+
+float SparseMatrix::getSmallDist(){
+       return smallDist;
+}
+
+/***********************************************************************/
+
+void SparseMatrix::rmCell(MatData data){
+       try {
+               if(data->vectorMap != NULL ){
+                       *(data->vectorMap) = NULL;
+                       data->vectorMap = NULL;
+               }
+               matrix.erase(data);             
+               numNodes--;
+       
+       //  seems like i should be updating smallDist here, but the only time we remove cells is when
+       //  clustering and the clustering algorithm updates smallDist
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SparseMatrix class Function rmCell. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SparseMatrix class function rmCell. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+/***********************************************************************/
+
+void SparseMatrix::addCell(PCell value){
+       try {
+               matrix.push_back(value);
+               numNodes++;
+               if(value.dist < smallDist){
+                       smallDist = value.dist;
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SparseMatrix class Function addCell. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SparseMatrix class function addCell. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+/***********************************************************************/
+
+void SparseMatrix::clear(){
+       try {
+               matrix.clear();
+               mins.clear();
+               numNodes = 0;
+               minsIndex = 0;
+               smallDist = 1e6;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SparseMatrix class Function clear. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SparseMatrix class function clear. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+/***********************************************************************/
+
+MatData SparseMatrix::begin(){
+       return matrix.begin();  
+}
+
+/***********************************************************************/
+
+MatData SparseMatrix::end(){
+       return matrix.end();    
+}
+
+/***********************************************************************/
+
+void SparseMatrix::print(){
+       try {
+               int index = 0;
+       
+               cout << endl << "Index\tRow\tColumn\tDistance" << endl;
+       
+               for(MatData currentCell=matrix.begin();currentCell!=matrix.end();currentCell++){
+                       cout << index << '\t' << currentCell->row  << '\t' << currentCell->column << '\t' << currentCell->dist << endl;
+                       index++;
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SparseMatrix class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SparseMatrix class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+/***********************************************************************/
+
+void SparseMatrix::print(ListVector* list){
+       try {
+               int index = 0;
+       
+               cout << endl << "Index\tRow\tColumn\tDistance" << endl;
+       
+               for(MatData currentCell=matrix.begin();currentCell!=matrix.end();currentCell++){
+                       cout << index << '\t' << list->get(currentCell->row)  << '\t' << list->get(currentCell->column) << '\t' << currentCell->dist << endl;
+                       index++;
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SparseMatrix class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SparseMatrix class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+/***********************************************************************/
+
+PCell* SparseMatrix::getSmallestCell(){
+       try {
+       //      this is where I check to see if the next small distance has the correct distance
+       //      if it doesn't then I remove the offending Cell -> should also be able to check for
+       //      invalid iterator / pointer -- right???
+       
+               while(!mins.empty() && mins.back() == NULL){
+                       mins.pop_back();                
+               }
+       
+       //      if the mins vector is empty go here...
+               if(mins.empty()){               
+                       mins.clear();
+               
+                       smallDist = begin()->dist;  //set the first candidate small distance
+               
+                       for(MatData currentCell=begin();currentCell!=end();currentCell++){
+                       
+                               float dist = currentCell->dist;
+                       
+                               if(dist < smallDist){  //found a new smallest distance
+                                       mins.clear();
+                                       smallDist = dist;
+                                       mins.push_back(&*currentCell);  //this is the address of the data in the list being pointed to by the MatData iterator
+                               }
+                               else if(dist == smallDist){  //if a subsequent distance is the same as mins distance add the new iterator to the mins vector
+                                       mins.push_back(&*currentCell); //this is the address of the data in the list being pointed to by the MatData iterator
+                               }
+
+                       }
+                       random_shuffle(mins.begin(), mins.end());  //randomize the order of the iterators in the mins vector
+
+                       for(int i=0;i<mins.size();i++){
+                               mins[i]->vectorMap = &mins[i];  //assign vectorMap to the address for the container
+                       }
+                       
+               }
+       
+               smallCell = mins.back();        //make the smallestCell the last element of the vector
+
+               mins.pop_back();                        //remove the last element from the vector
+
+               return smallCell;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SparseMatrix class Function getSmallestCell. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SparseMatrix class function getSmallestCell. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+/***********************************************************************/
+
diff --git a/sparsematrix.hpp b/sparsematrix.hpp
new file mode 100644 (file)
index 0000000..58aca0d
--- /dev/null
@@ -0,0 +1,53 @@
+#ifndef SPARSEMATRIX_H
+#define SPARSEMATRIX_H
+
+#include "utilities.hpp"
+#include <list>
+
+
+class ListVector;
+
+/***********************************************************************/
+
+
+ struct PCell{
+       ull row;
+       ull column;
+       float dist;
+       PCell** vectorMap;
+       PCell() : row(0), column(0), dist(0), vectorMap(NULL) {};
+       PCell(ull r, ull c, float d) : row(r), column(c), dist(d), vectorMap(NULL) {};
+};
+
+/***********************************************************************/
+
+class SparseMatrix {
+       
+public:
+       SparseMatrix();
+       int getNNodes();
+       void print();                                   //Print the contents of the matrix
+       void print(ListVector*);                                        //Print the contents of the matrix
+       PCell* getSmallestCell();               //Return the cell with the smallest distance
+       float getSmallDist();
+       
+       void rmCell(list<PCell>::iterator);
+       void addCell(PCell);
+       void clear();
+       list<PCell>::iterator begin();
+       list<PCell>::iterator end();
+
+private:
+       PCell* smallCell;                               //The cell with the smallest distance
+       int numNodes;
+
+       list<PCell> matrix;
+       
+       vector<PCell*> mins;
+       float smallDist;
+       int minsIndex;
+};
+
+/***********************************************************************/
+
+#endif
diff --git a/summarycommand.cpp b/summarycommand.cpp
new file mode 100644 (file)
index 0000000..c6170d1
--- /dev/null
@@ -0,0 +1,118 @@
+/*
+ *  summarycommand.cpp
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/2/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "summarycommand.h"
+#include "ace.h"
+#include "sobs.h"
+#include "chao1.h"
+#include "bootstrap.h"
+#include "simpson.h"
+#include "npshannon.h"
+#include "shannon.h"
+#include "jackknife.h"
+
+//**********************************************************************************************************************
+
+SummaryCommand::SummaryCommand(){
+       try {
+               globaldata = GlobalData::getInstance();
+               int i;
+               for (i=0; i<globaldata->summaryEstimators.size(); i++) {
+                       if(globaldata->summaryEstimators[i] == "sobs"){
+                               sumCalculators.push_back(new Sobs());
+                       }else if(globaldata->summaryEstimators[i] == "chao"){
+                               sumCalculators.push_back(new Chao1());
+                       }else if(globaldata->summaryEstimators[i] == "ace"){
+                               sumCalculators.push_back(new Ace());
+                       }else if(globaldata->summaryEstimators[i] == "jack"){
+                               sumCalculators.push_back(new Jackknife());
+                       }else if(globaldata->summaryEstimators[i] == "shannon"){
+                               sumCalculators.push_back(new Shannon());
+                       }else if(globaldata->summaryEstimators[i] == "npshannon"){
+                               sumCalculators.push_back(new NPShannon());
+                       }else if(globaldata->summaryEstimators[i] == "simpson"){
+                               sumCalculators.push_back(new Simpson());
+                       }else if(globaldata->summaryEstimators[i] == "bootstrap"){
+                               sumCalculators.push_back(new Bootstrap());
+                       }
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SummaryCommand class Function SummaryCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SummaryCommand class function SummaryCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+//**********************************************************************************************************************
+
+SummaryCommand::~SummaryCommand(){
+       delete sabund;
+       delete input;
+       delete read;
+}
+
+//**********************************************************************************************************************
+
+int SummaryCommand::execute(){
+       try {
+               outputFileName = ((getRootName(globaldata->inputFileName)) + "summary");
+               openOutputFile(outputFileName, outputFileHandle);
+               outputFileHandle << "label";
+       
+               read = new ReadPhilFile(globaldata->inputFileName);     
+               read->read(&*globaldata); 
+
+               for(int i=0;i<sumCalculators.size();i++){
+                       if(sumCalculators[i]->getCols() == 1){
+                               outputFileHandle << '\t' << sumCalculators[i]->getName();
+                       }
+                       else{
+                               outputFileHandle << '\t' << sumCalculators[i]->getName() << "\t" << sumCalculators[i]->getName() << "_lci\t" << sumCalculators[i]->getName() << "_hci";
+                       }
+               }
+               outputFileHandle << endl;
+               
+               sabund = globaldata->sabund;
+               input = globaldata->ginput;
+               int count = 1;
+               while(sabund != NULL){
+               
+                       if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(sabund->getLabel()) == 1){                      
+       
+                               cout << sabund->getLabel() << '\t' << count << endl;
+                       
+                               outputFileHandle << sabund->getLabel();
+                               for(int i=0;i<sumCalculators.size();i++){
+                                       vector<double> data = sumCalculators[i]->getValues(sabund);
+                                       outputFileHandle << '\t';
+                                       sumCalculators[i]->print(outputFileHandle);
+                               }
+                               outputFileHandle << endl;
+                       }
+               
+                       sabund = input->getSAbundVector();
+                       count++;
+               }
+       
+               return 0;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SummaryCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SummaryCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }               
+}
+
+//**********************************************************************************************************************
diff --git a/summarycommand.h b/summarycommand.h
new file mode 100644 (file)
index 0000000..1f24cd4
--- /dev/null
@@ -0,0 +1,52 @@
+#ifndef SUMMARYCOMMAND_H
+#define SUMMARYCOMMAND_H
+/*
+ *  summarycommand.h
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/2/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include <Carbon/Carbon.h>
+#include <iostream>
+#include <fstream>
+#include <vector>
+#include "command.hpp"
+#include "sabundvector.hpp"
+#include "inputdata.h"
+#include "calculator.h"
+#include "readmatrix.hpp"
+
+/* The summary() command:
+       The summary command can only be executed after a successful read.list, read.sabund or read.rabund command, with one exception. 
+       The summary command can be executed after a successful cluster command.  It will use the .list file from the output of the cluster. 
+       The summary command outputs a file for each estimator you choose to use.  The summary command parameters are label, line, summary. 
+        No parameters are required, but you may not use both the line and label  parameters at the same time. 
+        The summary command should be in the following format: summary(label=yourLabel, line=yourLines, summary=yourEstimators). 
+        Example summary(label=unique-.01-.03, line=0,5,10, summary=collect-chao-ace-jack-bootstrap-shannon-npshannon-simpson). 
+        The default value for summary is collect-chao-ace-jack-bootstrap-shannon-npshannon-simpson.  
+        The valid summary estimators are: collect-chao-ace-jack-bootstrap-shannon-npshannon-simpson.  
+        The label and line parameters are used to analyze specific lines in your input.  */
+
+
+class GlobalData;
+
+class SummaryCommand : public Command {
+
+public:
+       SummaryCommand();
+       ~SummaryCommand();
+       int execute();
+       
+private:
+       GlobalData* globaldata;
+       ReadMatrix* read;
+       vector<Calculator*> sumCalculators;     
+       InputData* input;
+       SAbundVector* sabund;
+       string outputFileName;
+       ofstream outputFileHandle;
+};
+#endif
\ No newline at end of file
diff --git a/summarydata.h b/summarydata.h
new file mode 100644 (file)
index 0000000..8a4d2da
--- /dev/null
@@ -0,0 +1,38 @@
+#ifndef SUMMARYDATA_H
+#define SUMMARYDATA_H
+
+#include <set>
+#include "sabundvector.hpp"
+#include "display.h"
+#include "observable.h"
+
+using namespace std;
+
+/***********************************************************************/
+
+class SummaryData : public Observable {
+       
+public:
+       SummaryData() : sabund(0) {};
+       
+       void registerDisplay(Display* o)        {       displays.insert(o);                             };
+       void removeDisplay(Display* o)          {       displays.erase(o);      delete o;       };
+       SAbundVector* getSabundData()                   {       return sabund;                                  };
+       void sabundDataChanged()                                {       notifyDisplays();                               };
+       void updatesabundData(SAbundVector* rv) {       sabund = rv; sabundDataChanged();       };
+       
+       void notifyDisplays(){  
+               for(set<Display*>::iterator pos=displays.begin();pos!=displays.end();pos++){
+                       (*pos)->update(sabund);
+               }       
+       };
+       
+private:
+       set<Display*> displays;
+       SAbundVector* sabund;
+       
+};
+
+/***********************************************************************/
+
+#endif
diff --git a/summarydisplay.h b/summarydisplay.h
new file mode 100644 (file)
index 0000000..42e6e19
--- /dev/null
@@ -0,0 +1,35 @@
+#ifndef SUMMARY_H
+#define SUMMARY_H
+
+#include <iostream>
+#include <iomanip>
+#include <fstream>
+#include <string>
+#include "display.h"
+
+
+
+class SummaryDisplay : public Display {
+
+public:
+       SummaryDisplay(Calculator* calc, FileOutput* file) : estimate(calc), output(file){      };
+       
+       void update(SAbundVector* sabund)       {       output->output(sabund->getLabel(), estimate->getValues(rank));  };
+       void init(string s)                             {       output->initFile(s);    };
+       void reset()                                    {       output->resetFile();    };
+       void close(){};
+       string getLabel(){      return estimate->getName();     }
+       
+private:
+       Calculator* estimate;
+       FileOutput* output;
+       
+       int nIters;
+       string tempInName, tempOutName;
+       ifstream tempInFile;
+       ofstream tempOutFile;
+};
+
+/***********************************************************************/
+
+#endif
\ No newline at end of file
diff --git a/summarysharedcommand.cpp b/summarysharedcommand.cpp
new file mode 100644 (file)
index 0000000..b9fd08d
--- /dev/null
@@ -0,0 +1,203 @@
+/*
+ *  summarysharedcommand.cpp
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/2/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "summarysharedcommand.h"
+#include "sharedchao1.h"
+#include "sharedace.h"
+#include "sharedjabund.h"
+#include "sharedsorabund.h"
+#include "sharedjclass.h"
+#include "sharedsorclass.h"
+#include "sharedjest.h"
+#include "sharedsorest.h"
+#include "sharedthetayc.h"
+#include "sharedthetan.h"
+
+//**********************************************************************************************************************
+
+SummarySharedCommand::SummarySharedCommand(){
+       try {
+               globaldata = GlobalData::getInstance();
+               
+               int i;
+               for (i=0; i<globaldata->sharedSummaryEstimators.size(); i++) {
+                       if (globaldata->sharedSummaryEstimators[i] == "sharedChao") { 
+                               sumCalculators.push_back(new SharedChao1());
+                       }else if (globaldata->sharedSummaryEstimators[i] == "sharedAce") { 
+                               sumCalculators.push_back(new SharedAce());
+                       }else if (globaldata->sharedSummaryEstimators[i] == "sharedJabund") {   
+                               sumCalculators.push_back(new SharedJAbund());
+                       }else if (globaldata->sharedSummaryEstimators[i] == "sharedSorensonAbund") { 
+                               sumCalculators.push_back(new SharedSorAbund());
+                       }else if (globaldata->sharedSummaryEstimators[i] == "sharedJclass") { 
+                               sumCalculators.push_back(new SharedJclass());
+                       }else if (globaldata->sharedSummaryEstimators[i] == "sharedSorClass") { 
+                               sumCalculators.push_back(new SharedSorClass());
+                       }else if (globaldata->sharedSummaryEstimators[i] == "sharedJest") { 
+                               sumCalculators.push_back(new SharedJest());
+                       }else if (globaldata->sharedSummaryEstimators[i] == "sharedSorEst") { 
+                               sumCalculators.push_back(new SharedSorEst());
+                       }else if (globaldata->sharedSummaryEstimators[i] == "SharedThetaYC") { 
+                               sumCalculators.push_back(new SharedThetaYC());
+                       }else if (globaldata->sharedSummaryEstimators[i] == "SharedThetaN") { 
+                               sumCalculators.push_back(new SharedThetaN());
+                       }
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SummarySharedCommand class Function SummarySharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SummarySharedCommand class function SummarySharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+//**********************************************************************************************************************
+
+SummarySharedCommand::~SummarySharedCommand(){
+       delete input;
+       delete read;
+}
+
+//**********************************************************************************************************************
+
+int SummarySharedCommand::execute(){
+       try {
+               outputFileName = ((getRootName(globaldata->inputFileName)) + "sharedSummary");
+               openOutputFile(outputFileName, outputFileHandle);
+       
+               read = new ReadPhilFile(globaldata->inputFileName);     
+               read->read(&*globaldata); 
+               
+               outputFileHandle << '\t' << '\t' << '\t' << '\t'; //pads file for labels and groupnames
+               for(int i=0;i<sumCalculators.size();i++){
+                       outputFileHandle << '\t' << sumCalculators[i]->getName();
+               }
+               outputFileHandle << endl;
+               
+               list = globaldata->glist;
+               input = globaldata->ginput;
+               order = list->getSharedOrderVector();
+               getGroupComb();
+               
+               int count = 1;
+               while(order != NULL){
+               
+                       if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){                       
+       
+                               cout << order->getLabel() << '\t' << count << endl;
+                               getSharedVectors();  //fills group vectors from order vector.
+                               
+                               //randomize group order
+                               if (globaldata->getJumble() == "1") { random_shuffle(lookup.begin(), lookup.end()); }
+
+                               int n = 1; 
+                               for (int k = 0; k < (lookup.size() - 1); k++) { // pass cdd each set of groups to commpare
+                                       for (int l = n; l < lookup.size(); l++) {
+                                               outputFileHandle << order->getLabel() << '\t' << groupComb[n-1] << '\t'; //print out label and group
+                                               for(int i=0;i<sumCalculators.size();i++){
+                                                       sumCalculators[i]->getValues(lookup[k], lookup[l]); //saves the calculator outputs
+                                                       outputFileHandle << '\t';
+                                                       sumCalculators[i]->print(outputFileHandle);
+                                               }
+                                               outputFileHandle << endl;
+                                       }
+                                       n++;
+                               }
+                       }
+               
+                       list = input->getListVector(); //get new list vector to process
+                       if (list != NULL) {
+                               order = list->getSharedOrderVector(); //gets new order vector with group info.
+                               count++;
+                       }else {
+                               break;
+                       }
+               }
+       
+               return 0;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SummarySharedCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SummarySharedCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }               
+}
+
+//**********************************************************************************************************************
+
+void SummarySharedCommand::getSharedVectors(){
+try {
+               lookup.clear();
+               //create and initialize vector of sharedvectors, one for each group
+               for (int i = 0; i < globaldata->gGroupmap->getNumGroups(); i++) { 
+                       SharedRAbundVector* temp = new SharedRAbundVector(order->getNumBins());
+                       temp->setLabel(order->getLabel());
+                       temp->setGroup(globaldata->gGroupmap->namesOfGroups[i]);
+                       lookup.push_back(temp);
+               }
+               
+               int numSeqs = order->size();
+               //sample all the members
+               for(int i=0;i<numSeqs;i++){
+                       //get first sample
+                       individual chosen = order->get(i);
+                       int abundance; 
+                                       
+                       //set info for sharedvector in chosens group
+                       for (int j = 0; j < lookup.size(); j++) { 
+                               if (chosen.group == lookup[j]->getGroup()) {
+                                        abundance = lookup[j]->getAbundance(chosen.bin);
+                                        lookup[j]->set(chosen.bin, (abundance + 1), chosen.group);
+                                        break;
+                               }
+                       }
+                       
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SummarySharedCommand class Function getSharedVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SummarySharedCommand class function getSharedVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+
+}
+
+/**************************************************************************************/
+void SummarySharedCommand::getGroupComb() {
+       try {
+               string group;
+               
+               int n = 1;
+               for (int i = 0; i < (globaldata->gGroupmap->getNumGroups() - 1); i++) {
+                       for (int l = n; l < globaldata->gGroupmap->getNumGroups(); l++) {
+                               group = globaldata->gGroupmap->namesOfGroups[i] + globaldata->gGroupmap->namesOfGroups[l];
+                               groupComb.push_back(group);     
+                       }
+                       n++;
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SummarySharedCommand class Function getGroupComb. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SummarySharedCommand class function getGroupComb. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+
+}
+
diff --git a/summarysharedcommand.h b/summarysharedcommand.h
new file mode 100644 (file)
index 0000000..6188b96
--- /dev/null
@@ -0,0 +1,64 @@
+#ifndef SUMMARYSHAREDCOMMAND_H
+#define SUMMARYSHAREDCOMMAND_H
+/*
+ *  summarysharedcommand.h
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/2/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include <Carbon/Carbon.h>
+#include <iostream>
+#include <fstream>
+#include <vector>
+#include "command.hpp"
+#include "sharedrabundvector.h"
+#include "inputdata.h"
+#include "calculator.h"
+#include "readmatrix.hpp"
+
+/*The summary.shared() command
+       The summary.shared command can only be executed after a successful read.shared command. 
+       It outputs a file for each estimator you choose to use.  The summary.shared command parameters are label, 
+       line, jumble and sharedsummary.  No parameters are required, but you may not use both the line and label parameters at the same time.  
+       The summary.shared command should be in the following format: summary.shared(label=yourLabel, 
+       line=yourLines, jumble=yourJumble, sharedsummary=yourEstimators).  
+       Example summary.shared(label=unique-.01-.03, line=0,5,10, jumble=1, sharedsummary=sharedChao-sharedAce-sharedJabund
+       -sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN).  
+       The default value for jumble is 0 (meaning don’t jumble, if it’s set to 1 then it will jumble) and 
+       sharedsummary is sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN. 
+       The valid sharedsummary estimators are: sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass
+       -sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN.  The label and line parameters are used to analyze specific lines in your input. */
+
+
+class GlobalData;
+
+
+class SummarySharedCommand : public Command {
+
+public:
+       SummarySharedCommand();
+       ~SummarySharedCommand();
+       int execute();
+       
+private:
+       void getGroupComb();
+       void getSharedVectors();
+       
+       GlobalData* globaldata;
+       ReadMatrix* read;
+       vector<Calculator*> sumCalculators;     
+       InputData* input;
+       ListVector* list;
+       SharedOrderVector* order;
+       vector<SharedRAbundVector*> lookup;
+       SharedRAbundVector* shared1, shared2;
+       string outputFileName;
+       ofstream outputFileHandle;
+       vector<string> groupComb;
+
+};
+
+#endif
\ No newline at end of file
diff --git a/utilities.hpp b/utilities.hpp
new file mode 100644 (file)
index 0000000..16e762c
--- /dev/null
@@ -0,0 +1,199 @@
+#ifndef UTILITIES_H
+#define UTILITIES_H
+
+using namespace std;
+
+#include <iostream>
+#include <iomanip>
+#include <fstream>
+#include <sstream>
+#include <cmath>
+#include <vector>
+#include <stdexcept>
+
+typedef unsigned long long ull;
+
+/***********************************************************************/
+
+// snagged from http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.2
+// works for now, but there should be a way to do it without killing the whole program
+
+class BadConversion : public runtime_error {
+public:
+       BadConversion(const string& s) : runtime_error(s){ }
+};
+
+//**********************************************************************************************************************
+
+template<typename T>
+inline void convert(const string& s, T& x, bool failIfLeftoverChars = true){
+       istringstream i(s);
+       char c;
+       if (!(i >> x) || (failIfLeftoverChars && i.get(c)))
+               throw BadConversion(s);
+}
+
+//**********************************************************************************************************************
+
+template<typename T>
+string toString(const T&x){
+    stringstream output;
+    output << x;
+    return output.str();
+}
+
+//**********************************************************************************************************************
+
+template<typename T>
+string toString(const T&x, int i){
+       stringstream output;
+       
+       output.precision(i);
+    output << fixed << x;
+       
+    return output.str();
+}
+
+
+/***********************************************************************/
+
+inline void gobble(ifstream& f){
+       
+       char d;
+    while(isspace(d=f.get()))          {;}
+       f.putback(d);
+       
+}
+
+/***********************************************************************/
+
+inline float roundDist(float dist, int precision){
+       
+       return int(dist * precision + 0.5)/float(precision);
+       
+}
+
+/***********************************************************************/
+
+inline int getNumNames(string names){
+       
+       int count = 0;
+       
+       if(names != ""){
+               count = 1;
+               for(int i=0;i<names.size();i++){
+                       if(names[i] == ','){
+                               count++;
+                       }
+               }
+       }
+       
+       return count;
+       
+}
+
+/**************************************************************************************************/
+
+inline vector<vector<double> > binomial(int maxOrder){
+       
+       vector<vector<double> > binomial(maxOrder+1);
+       
+    for(int i=0;i<=maxOrder;i++){
+               binomial[i].resize(maxOrder+1);
+               binomial[i][0]=1;
+               binomial[0][i]=0;
+    }
+    binomial[0][0]=1;
+       
+    binomial[1][0]=1;
+    binomial[1][1]=1;
+       
+    for(int i=2;i<=maxOrder;i++){
+               binomial[1][i]=0;
+    }
+       
+    for(int i=2;i<=maxOrder;i++){
+               for(int j=1;j<=maxOrder;j++){
+                       if(i==j){       binomial[i][j]=1;                                                                       }
+                       if(j>i) {       binomial[i][j]=0;                                                                       }
+                       else    {       binomial[i][j]=binomial[i-1][j-1]+binomial[i-1][j];     }
+               }
+    }
+       
+       return binomial;
+}
+
+/***********************************************************************/
+
+inline string getRootName(string longName){
+       string rootName = longName;
+       
+       if(longName.find_last_of(".") != longName.npos){
+               int pos = longName.find_last_of('.')+1;
+               rootName = longName.substr(0, pos);
+       }
+
+       return rootName;
+}
+/***********************************************************************/
+
+inline string getSimpleName(string longName){
+       string simpleName = longName;
+       
+       if(longName.find_last_of("/") != longName.npos){
+               int pos = longName.find_last_of('/')+1;
+               simpleName = longName.substr(pos, longName.length());
+       }
+
+       return simpleName;
+}
+
+/***********************************************************************/
+
+inline string getPathName(string longName){
+       string rootPathName = longName;
+       
+       if(longName.find_last_of("/") != longName.npos){
+               int pos = longName.find_last_of('/')+1;
+               rootPathName = longName.substr(0, pos);
+       }
+
+       return rootPathName;
+}
+
+/***********************************************************************/
+
+inline int openInputFile(string fileName, ifstream& fileHandle){
+
+       fileHandle.open(fileName.c_str());
+       if(!fileHandle) {
+               cerr << "Error: Could not open " << fileName << endl;
+               return 1;
+       }
+       else {
+               return 0;
+       }
+       
+}
+
+/***********************************************************************/
+
+inline int openOutputFile(string fileName, ofstream& fileHandle){
+       
+       fileHandle.open(fileName.c_str(), ios::trunc);
+       if(!fileHandle) {
+               cerr << "Error: Could not open " << fileName << endl;
+               return 1;
+       }
+       else {
+               return 0;
+       }
+
+}
+
+/***********************************************************************/
+
+#endif
diff --git a/uvest.cpp b/uvest.cpp
new file mode 100644 (file)
index 0000000..725bcd1
--- /dev/null
+++ b/uvest.cpp
@@ -0,0 +1,94 @@
+/*
+ *  uvest.cpp
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/8/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "uvest.h"
+
+/***********************************************************************/
+//This is used by SharedJAbund and SharedSorAbund
+EstOutput UVEst::getUVest(SharedRAbundVector* shared1, SharedRAbundVector* shared2) {
+       try {   
+               EstOutput results;
+               results.resize(2,0);
+               
+               int S12, Atotal, Btotal, f1A, f2A, f1B, f2B, sumSharedA, sumSharedB, sumSharedA1, sumSharedB1, tempA, tempB;
+               S12 = 0; Atotal = 0; Btotal = 0; f1A = 0; f2A = 0; f1B = 0; f2B = 0; sumSharedA = 0; sumSharedB = 0; sumSharedA1 = 0; sumSharedB1 = 0;
+               float Upart1, Upart2, Upart3, Vpart1, Vpart2, Vpart3, Uest, Vest;
+               Upart1 = 0.0; Upart2 = 0.0; Upart3 = 0.0; Vpart1 = 0.0; Vpart2 = 0.0; Vpart3 = 0.0;
+               
+               /*Xi, Yi = abundance of the ith shared OTU in A and B 
+               ntotal, mtotal = total number of sequences sampled in A and B 
+               I(•) = if the argument, â€¢, is true then I(•) is 1; otherwise it is 0. 
+               sumSharedA = the sum of all shared otus in A
+               sumSharedB = the sum of all shared otus in B
+               sumSharedA1 = the sum of all shared otus in A where B = 1
+               sumSharedB1 = the sum of all shared otus in B where A = 1 */
+               
+               for (int i = 0; i < shared1->size(); i++) {
+                       //store in temps to avoid multiple repetitive function calls
+                       tempA = shared1->getAbundance(i);
+                       tempB = shared2->getAbundance(i);
+
+                       Atotal += tempA;
+                       Btotal += tempB;
+                       
+                       if ((tempA != 0) && (tempB != 0)) {//they are shared
+                               sumSharedA += tempA;
+                               sumSharedB += tempB;
+                               
+                               //does A have one or two
+                               if (tempA == 1)                 { f1A++; sumSharedB1 += tempB;}
+                               else if (tempA == 2)    { f2A++; }
+                               
+                               //does B have one or two
+                               if (tempB == 1)                 { f1B++; sumSharedA1 += tempA;}
+                               else if (tempB == 2)    { f2B++; }
+                       }
+               }
+               
+               Upart1 = sumSharedA / (float) Atotal;
+               Upart2 = ((Btotal - 1) * f1B) / (float) (Btotal * 2 * f2B);
+               Upart3 = sumSharedA1 / (float) Atotal;
+               
+               if (isnan(Upart1) || isinf(Upart1)) { Upart1 = 0; }
+               if (isnan(Upart2) || isinf(Upart2)) { Upart2 = 0; }
+               if (isnan(Upart3) || isinf(Upart3)) { Upart3 = 0; }
+               
+               Uest = Upart1 + (Upart2 * Upart3);
+               
+               Vpart1 = sumSharedB / (float) Btotal;
+               Vpart2 = ((Atotal - 1) * f1A) / (float) (Atotal * 2 * f2A);
+               Vpart3 = sumSharedB1 / (float) Btotal;
+               
+               if (isnan(Vpart1) || isinf(Vpart1)) { Vpart1 = 0; }
+               if (isnan(Vpart2) || isinf(Vpart2)) { Vpart2 = 0; }
+               if (isnan(Vpart3) || isinf(Vpart3)) { Vpart3 = 0; }
+               
+               Vest = Vpart1 + (Vpart2 * Vpart3);
+               
+               if (Uest > 1) { Uest = 1; }
+               if (Vest > 1) { Vest = 1; }
+               
+               results[0] = Uest;
+               results[1] = Vest;
+               
+               return results;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the UVEst class Function getUVest. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the UVEst class Function getUVest. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+
+
+}
+
+/***********************************************************************/
diff --git a/uvest.h b/uvest.h
new file mode 100644 (file)
index 0000000..7c7ac6f
--- /dev/null
+++ b/uvest.h
@@ -0,0 +1,33 @@
+#ifndef UVEST_H
+#define UVEST_H
+/*
+ *  uvest.h
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/8/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+/* This class implements the UVEst estimator on two groups. 
+It is used by sharedJAbund and SharedSorensonAbund. */
+using namespace std;
+
+#include <Carbon/Carbon.h>
+#include <vector>
+#include <iostream>
+#include <fstream>
+#include "sharedrabundvector.h"
+
+typedef vector<double> EstOutput;
+
+/***********************************************************************/
+class UVEst {
+       public:
+               EstOutput getUVest(SharedRAbundVector* shared1, SharedRAbundVector* shared2);           
+};
+/***********************************************************************/
+
+#endif
\ No newline at end of file
diff --git a/validcalculator.cpp b/validcalculator.cpp
new file mode 100644 (file)
index 0000000..8659be3
--- /dev/null
@@ -0,0 +1,232 @@
+/*
+ *  validcalculator.cpp
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/5/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "validcalculator.h"
+
+/********************************************************************/
+ValidCalculators::ValidCalculators() {
+       try {
+                initialSingle();
+                initialShared();
+                initialRarefaction();
+                initialSharedRarefact();
+                initialSummary();
+                initialSharedSummary();
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ValidCalculator class Function ValidCalculator. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ValidCalculator class function ValidCalculator. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }                
+}
+
+/********************************************************************/
+
+ValidCalculators::~ValidCalculators() {}
+
+/********************************************************************/
+
+bool ValidCalculators::isValidCalculator(string parameter, string calculator) {
+       try {   
+               //are you looking for a calculator for a single parameter
+               if (parameter == "single") {
+                       //is it valid
+                       if ((single.find(calculator)) != (single.end())) {
+                               return true;
+                       }else { cout << calculator << " is not a valid single estimator. Valid single estimators are collect-chao-ace-jack-bootstrap-shannon-npshannon-simpson." << endl; return false; }
+               //are you looking for a calculator for a shared parameter
+               }else if (parameter == "shared") {
+                       //is it valid
+                       if ((shared.find(calculator)) != (shared.end())) {
+                               return true;
+                       }else { cout << calculator << " is not a valid shared estimator.  Valid shared estimators are sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN." << endl; return false; }
+               //are you looking for a calculator for a rarefaction parameter
+               }else if (parameter == "rarefaction") {
+                       //is it valid
+                       if ((rarefaction.find(calculator)) != (rarefaction.end())) {
+                               return true;
+                       }else { cout << calculator << " is not a valid rarefaction estimator. Valid rarefaction estimators are rarefaction-rchao-race-rjack-rbootstrap-rshannon-rnpshannon-rsimpson." << endl; return false; }
+               //are you looking for a calculator for a summary parameter
+               }else if (parameter == "summary") {
+                       //is it valid
+                       if ((summary.find(calculator)) != (summary.end())) {
+                               return true;
+                       }else { cout << calculator << " is not a valid summary estimator. Valid summary estimators are collect-chao-ace-jack-bootstrap-shannon-npshannon-simpson." << endl; return false; }
+               //are you looking for a calculator for a sharedsummary parameter
+               }else if (parameter == "sharedsummary") {
+                       //is it valid
+                       if ((sharedsummary.find(calculator)) != (sharedsummary.end())) {
+                               return true;
+                       }else { cout << calculator << " is not a valid sharedsummary estimator. Valid sharedsummary estimators are: sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN." << endl; return false; }
+
+               }else if (parameter == "sharedrarefaction") {
+                       //is it valid
+                       if ((sharedrarefaction.find(calculator)) != (sharedrarefaction.end())) {
+                               return true;
+                       }else { cout << calculator << " is not a valid sharedrarefaction estimator. Valid sharedrarefaction estimator is sharedobserved." << endl; return false; }
+               //not a valid paramter
+               }else { return false; }
+               
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ValidCalculator class Function isValidCalculator. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ValidCalculator class function isValidCalculator. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+/********************************************************************/
+void ValidCalculators::initialSingle() {
+       try {   
+       
+               single["sobs"]  = "sobs";
+               single["chao"]          = "chao";
+               single["ace"]           = "ace";
+               single["jack"]          = "jack";
+               single["shannon"]       = "shannon";
+               single["npshannon"]     = "npshannon";
+               single["simpson"]       = "simpson";
+               single["bootstrap"]     = "bootstrap";
+               single["default"]       = "default";
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ValidCalculator class Function initialSingle. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ValidCalculator class function initialSingle. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+/********************************************************************/
+void ValidCalculators::initialShared() {
+       try {   
+               shared["sharedChao"]                    = "sharedChao";
+               shared["sharedAce"]                             = "sharedAce";
+               shared["sharedJabund"]                  = "sharedJabund";
+               shared["sharedSorensonAbund"]   = "sharedSorensonAbund";
+               shared["sharedJclass"]                  = "sharedJclass";
+               shared["sharedSorClass"]                = "sharedSorClass";
+               shared["sharedJest"]                    = "sharedJest";
+               shared["sharedSorEst"]                  = "sharedSorEst";
+               shared["SharedThetaYC"]                 = "SharedThetaYC";
+               shared["SharedThetaN"]                  = "SharedThetaN";
+               shared["default"]                   = "default";
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ValidCalculator class Function initialShared. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ValidCalculator class function initialShared. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+/********************************************************************/
+void ValidCalculators::initialRarefaction() {
+       try {   
+               rarefaction["sobs"]                     = "sobs";
+               rarefaction["chao"]                     = "chao";
+               rarefaction["ace"]                      = "ace";
+               rarefaction["jack"]                     = "jack";
+               rarefaction["shannon"]          = "shannon";
+               rarefaction["npshannon"]        = "npshannon";
+               rarefaction["simpson"]          = "simpson";
+               rarefaction["bootstrap"]        = "bootstrap";
+               rarefaction["default"]      = "default";
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ValidCalculator class Function initialRarefaction. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ValidCalculator class function initialRarefaction. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+/********************************************************************/
+
+void ValidCalculators::initialSummary() {
+       try {   
+               summary["sobs"]                 = "sobs";
+               summary["chao"]                 = "chao";
+               summary["ace"]                  = "ace";
+               summary["jack"]                 = "jack";
+               summary["shannon"]              = "shannon";
+               summary["npshannon"]    = "npshannon";
+               summary["simpson"]              = "simpson";
+               summary["bootstrap"]    = "bootstrap";
+               summary["default"]          = "default";
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ValidCalculator class Function initialSummary. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ValidCalculator class function initialSummary. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+/********************************************************************/
+void ValidCalculators::initialSharedSummary() {
+       try {   
+               sharedsummary["sharedChao"]                             = "sharedChao";
+               sharedsummary["sharedAce"]                              = "sharedAce";
+               sharedsummary["sharedJabund"]                   = "sharedJabund";
+               sharedsummary["sharedSorensonAbund"]    = "sharedSorensonAbund";
+               sharedsummary["sharedJclass"]                   = "sharedJclass";
+               sharedsummary["sharedSorClass"]                 = "sharedSorClass";
+               sharedsummary["sharedJest"]                             = "sharedJest";
+               sharedsummary["sharedSorEst"]                   = "sharedSorEst";
+               sharedsummary["SharedThetaYC"]                  = "SharedThetaYC";
+               sharedsummary["SharedThetaN"]                   = "SharedThetaN";
+               sharedsummary["default"]                                = "default";
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ValidCalculator class Function initialSharedSummary. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ValidCalculator class function initialSharedSummary. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+
+/********************************************************************/
+
+void ValidCalculators::initialSharedRarefact() {
+       try {   
+               sharedrarefaction["sharedobserved"]     = "sharedobserved";
+               sharedrarefaction["default"]        = "default";
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ValidCalculator class Function initialSharedRarefact. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ValidCalculator class function initialSharedRarefact. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+/********************************************************************/
+
+
+
diff --git a/validcalculator.h b/validcalculator.h
new file mode 100644 (file)
index 0000000..36a1174
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ *  validcalculator.h
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/5/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+using namespace std;
+
+#include <Carbon/Carbon.h>
+#include <string>
+#include <iostream>
+#include <map>
+
+//This class contains a list of all valid calculators in Mothur.  
+//It has a function which will tell you if your calculator is valid for the given parameter.
+//When adding a new calculator you must add it to the valid list.
+
+
+class ValidCalculators {
+       public:
+               ValidCalculators();
+               ~ValidCalculators();
+               bool isValidCalculator(string, string);
+               
+       private:
+               map<string, string> single;
+               map<string, string> shared;
+               map<string, string> rarefaction;
+               map<string, string> summary;
+               map<string, string> sharedrarefaction;
+               map<string, string> sharedsummary;
+               void initialSingle();
+               void initialShared();
+               void initialRarefaction();
+               void initialSharedRarefact();
+               void initialSummary();
+               void initialSharedSummary();
+               
+               
+};
diff --git a/validcommands.cpp b/validcommands.cpp
new file mode 100644 (file)
index 0000000..9b6aeed
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ *  validcommands.cpp
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/5/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "validcommands.h"
+
+/***********************************************************************/
+
+ValidCommands::ValidCommands() {
+       try {
+       
+               commands["read.phylip"]                 = "read.phylip"; 
+               commands["read.column"]                 = "read.column"; 
+               commands["read.list"]                   = "read.list"; 
+               commands["read.rabund"]                 = "read.rabund"; 
+               commands["read.sabund"]                 = "read.sabund"; 
+               commands["read.shared"]                 = "read.shared"; 
+               commands["cluster"]                             = "cluster"; 
+               commands["help"]                                = "help"; 
+               commands["quit"]                                = "quit"; 
+               commands["collect.single"]              = "collect.single"; 
+               commands["shared"]                              = "shared"; 
+               commands["collect.shared"]              = "collect.shared"; 
+               commands["rarefaction.single"]  = "rarefaction.single"; 
+               commands["rarefaction.shared"]  = "rarefaction.shared"; 
+               commands["summary.single"]              = "summary.single"; 
+               commands["summary.shared"]              = "summary.shared"; 
+               commands["parselist"]                   = "parselist"; 
+               
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ValidCommands class Function ValidCommands. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ValidCommands class function ValidCommands. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+/***********************************************************************/
+
+ValidCommands::~ValidCommands() {}
+
+/***********************************************************************/
+bool ValidCommands::isValidCommand(string command) {
+       try {   
+       
+               //is the command in the map
+               if ((commands.find(command)) != (commands.end())) {
+                       return true;
+               }else{
+                       cout << command << " is not a valid command in Mothur.  Valid commands are read.phylip(), read.column(), read.list(), read.rabund(), read.sabund(), read.shared(), cluster(), collect.single(), collect.shared(), parselist(), shared(), rarefaction.single(), rarefaction.shared(), summary.single(), summary.shared(), quit(), help()." << endl;
+                       return false;
+               }
+               
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ValidCommands class Function isValidCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ValidCommands class function isValidCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+/***********************************************************************/
\ No newline at end of file
diff --git a/validcommands.h b/validcommands.h
new file mode 100644 (file)
index 0000000..658d5e4
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ *  validcommands.h
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/5/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+using namespace std;
+
+#include <Carbon/Carbon.h>
+#include <string>
+#include <iostream>
+#include <map>
+
+//This class contains a list of all valid commands in Mothur.  
+//It has a function which will tell you if your command is valid.
+//When adding a new command you must add it to the valid list in the class constructor.
+
+class ValidCommands {
+
+       public:
+               ValidCommands();
+               ~ValidCommands();
+               bool isValidCommand(string);
+       private:
+               map<string, string> commands;
+
+};
\ No newline at end of file
diff --git a/validparameter.cpp b/validparameter.cpp
new file mode 100644 (file)
index 0000000..fd9998e
--- /dev/null
@@ -0,0 +1,79 @@
+/*
+ *  validparameter.cpp
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/5/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "validparameter.h"
+
+/***********************************************************************/
+
+ValidParameters::ValidParameters() {
+       try {
+       
+               parameters["distfile"]                  = "distfile"; 
+               parameters["listfile"]                  = "listfile"; 
+               parameters["rabundfile"]                = "rabundfile"; 
+               parameters["sabundfile"]                = "sabundfile"; 
+               parameters["namefile"]                  = "namefile"; 
+               parameters["groupfile"]                 = "groupfile"; 
+               parameters["orderfile"]                 = "orderfile"; 
+               parameters["fileroot"]                  = "fileroot";
+               parameters["cutoff"]                    = "cutoff"; 
+               parameters["method"]                    = "method";
+               parameters["format"]                    = "format"; 
+               parameters["precision"]                 = "precision"; 
+               parameters["label"]                             = "label"; 
+               parameters["line"]                              = "line"; 
+               parameters["iters"]                             = "iters"; 
+               parameters["jumble"]                    = "jumble"; 
+               parameters["freq"]                              = "freq"; 
+               parameters["single"]                    = "single"; 
+               parameters["rarefaction"]               = "rarefaction"; 
+               parameters["sharedrarefaction"] = "sharedrarefaction";
+               parameters["shared"]                    = "shared"; 
+               parameters["summary"]                   = "summary"; 
+               parameters["sharedsummary"]             = "sharedsummary";
+
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ValidParameters class Function ValidParameters. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ValidParameters class function ValidParameters. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+/***********************************************************************/
+
+ValidParameters::~ValidParameters() {}
+
+/***********************************************************************/
+bool ValidParameters::isValidParameter(string parameter) {
+       try {   
+       
+               //is the parameter in the map
+               if ((parameters.find(parameter)) != (parameters.end())) {
+                       return true;
+               }else{
+                       cout << parameter << " is not a valid parameter in Mothur." << endl;
+                       return false;
+               }
+               
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ValidParameters class Function isValidParameter. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ValidParameters class function isValidParameter. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+/***********************************************************************/
\ No newline at end of file
diff --git a/validparameter.h b/validparameter.h
new file mode 100644 (file)
index 0000000..d3fb2b7
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ *  validparameter.h
+ *  Dotur
+ *
+ *  Created by Sarah Westcott on 1/5/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+using namespace std;
+
+#include <Carbon/Carbon.h>
+#include <iostream>
+#include <string>
+#include <map>
+
+//This class contains a list of all valid parameters in Mothur.  
+//It has a function which will tell you if your parameter is valid.
+//When adding a new parameter you must add it to the valid list in the class constructor.
+
+
+class ValidParameters {
+
+       public:
+               ValidParameters();
+               ~ValidParameters();
+               bool isValidParameter(string);
+       private:
+               map<string, string> parameters;
+
+};
\ No newline at end of file