From 154e089bcd37c2c2f773e53ffb88a20170b27037 Mon Sep 17 00:00:00 2001 From: westcott Date: Tue, 21 Apr 2009 18:29:12 +0000 Subject: [PATCH] broke apart read matrix file --- Mothur.xcodeproj/project.pbxproj | 22 +- binsequencecommand.cpp | 2 +- binsequencecommand.h | 4 +- bootstrapsharedcommand.cpp | 4 +- bootstrapsharedcommand.h | 4 +- collectcommand.cpp | 2 +- collectcommand.h | 4 +- collectsharedcommand.cpp | 4 +- collectsharedcommand.h | 4 +- getoturepcommand.cpp | 2 +- getoturepcommand.h | 4 +- heatmapcommand.cpp | 6 +- heatmapcommand.h | 4 +- parselistcommand.cpp | 2 +- parselistcommand.h | 4 +- rarefactcommand.cpp | 2 +- rarefactcommand.h | 4 +- rarefactsharedcommand.cpp | 4 +- rarefactsharedcommand.h | 4 +- readcolumn.cpp | 160 +++++++++++++ readcolumn.h | 29 +++ readdistcommand.cpp | 2 + readmatrix.cpp | 388 ------------------------------- readmatrix.hpp | 54 ----- readotu.cpp | 71 ++++++ readotu.h | 44 ++++ readotucommand.cpp | 2 +- readotucommand.h | 4 +- readphylip.cpp | 186 +++++++++++++++ readphylip.h | 29 +++ sharedcommand.cpp | 2 +- sharedcommand.h | 4 +- summarycommand.cpp | 2 +- summarycommand.h | 4 +- summarysharedcommand.cpp | 4 +- summarysharedcommand.h | 4 +- treegroupscommand.cpp | 4 +- treegroupscommand.h | 4 +- venncommand.cpp | 6 +- venncommand.h | 4 +- 40 files changed, 593 insertions(+), 500 deletions(-) create mode 100644 readcolumn.cpp create mode 100644 readcolumn.h delete mode 100644 readmatrix.cpp create mode 100644 readotu.cpp create mode 100644 readotu.h create mode 100644 readphylip.cpp create mode 100644 readphylip.h diff --git a/Mothur.xcodeproj/project.pbxproj b/Mothur.xcodeproj/project.pbxproj index aaeab8d..1c8df76 100644 --- a/Mothur.xcodeproj/project.pbxproj +++ b/Mothur.xcodeproj/project.pbxproj @@ -32,6 +32,9 @@ 375874060F7D64EF0040F377 /* sharedkulczynskicody.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 375874020F7D64EF0040F377 /* sharedkulczynskicody.cpp */; }; 3758740C0F7D64FC0040F377 /* sharedmorisitahorn.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 375874080F7D64FC0040F377 /* sharedmorisitahorn.cpp */; }; 3758740D0F7D64FC0040F377 /* sharedochiai.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3758740B0F7D64FC0040F377 /* sharedochiai.cpp */; }; + 375AA1390F9E433D008EF9B8 /* readcolumn.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 375AA1330F9E433D008EF9B8 /* readcolumn.cpp */; }; + 375AA13A0F9E433D008EF9B8 /* readotu.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 375AA1350F9E433D008EF9B8 /* readotu.cpp */; }; + 375AA13B0F9E433D008EF9B8 /* readphylip.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 375AA1370F9E433D008EF9B8 /* readphylip.cpp */; }; 379293C30F2DE73400B9034A /* treemap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 379293C20F2DE73400B9034A /* treemap.cpp */; }; 379294700F2E191800B9034A /* parsimonycommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3792946F0F2E191800B9034A /* parsimonycommand.cpp */; }; 3792948A0F2E258500B9034A /* parsimony.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 379294890F2E258500B9034A /* parsimony.cpp */; }; @@ -79,7 +82,6 @@ 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 */; }; - 37D928800F21331F001D4494 /* readmatrix.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D928120F21331F001D4494 /* readmatrix.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 */; }; @@ -191,6 +193,12 @@ 375874090F7D64FC0040F377 /* sharedochiai.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sharedochiai.h; sourceTree = ""; }; 3758740A0F7D64FC0040F377 /* sharednseqs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sharednseqs.h; sourceTree = ""; }; 3758740B0F7D64FC0040F377 /* sharedochiai.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sharedochiai.cpp; sourceTree = ""; }; + 375AA1330F9E433D008EF9B8 /* readcolumn.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = readcolumn.cpp; sourceTree = ""; }; + 375AA1340F9E433D008EF9B8 /* readcolumn.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = readcolumn.h; sourceTree = ""; }; + 375AA1350F9E433D008EF9B8 /* readotu.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = readotu.cpp; sourceTree = ""; }; + 375AA1360F9E433D008EF9B8 /* readotu.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = readotu.h; sourceTree = ""; }; + 375AA1370F9E433D008EF9B8 /* readphylip.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = readphylip.cpp; sourceTree = ""; }; + 375AA1380F9E433D008EF9B8 /* readphylip.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = readphylip.h; sourceTree = ""; }; 379293C10F2DE73400B9034A /* treemap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = treemap.h; sourceTree = ""; }; 379293C20F2DE73400B9034A /* treemap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = treemap.cpp; sourceTree = ""; }; 3792946E0F2E191800B9034A /* parsimonycommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = parsimonycommand.h; sourceTree = ""; }; @@ -291,7 +299,6 @@ 37D928090F21331F001D4494 /* rarefactioncurvedata.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = rarefactioncurvedata.h; sourceTree = ""; }; 37D9280A0F21331F001D4494 /* rarefactsharedcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = rarefactsharedcommand.cpp; sourceTree = ""; }; 37D9280B0F21331F001D4494 /* rarefactsharedcommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = rarefactsharedcommand.h; sourceTree = ""; }; - 37D928120F21331F001D4494 /* readmatrix.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = readmatrix.cpp; sourceTree = ""; }; 37D928130F21331F001D4494 /* readmatrix.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = readmatrix.hpp; sourceTree = ""; }; 37D9281A0F21331F001D4494 /* sabundvector.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sabundvector.cpp; sourceTree = ""; }; 37D9281B0F21331F001D4494 /* sabundvector.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = sabundvector.hpp; sourceTree = ""; }; @@ -461,8 +468,13 @@ 37D928060F21331F001D4494 /* rarefact.h */, 37D928050F21331F001D4494 /* rarefact.cpp */, 37D928090F21331F001D4494 /* rarefactioncurvedata.h */, + 375AA1340F9E433D008EF9B8 /* readcolumn.h */, + 375AA1330F9E433D008EF9B8 /* readcolumn.cpp */, 37D928130F21331F001D4494 /* readmatrix.hpp */, - 37D928120F21331F001D4494 /* readmatrix.cpp */, + 375AA1360F9E433D008EF9B8 /* readotu.h */, + 375AA1350F9E433D008EF9B8 /* readotu.cpp */, + 375AA1380F9E433D008EF9B8 /* readphylip.h */, + 375AA1370F9E433D008EF9B8 /* readphylip.cpp */, 37AD4DC80F28F3DD00AA2D49 /* readtree.h */, 37AD4DC90F28F3DD00AA2D49 /* readtree.cpp */, 37D9281D0F21331F001D4494 /* sequence.hpp */, @@ -785,7 +797,6 @@ 37D9287A0F21331F001D4494 /* rarefact.cpp in Sources */, 37D9287B0F21331F001D4494 /* rarefactcommand.cpp in Sources */, 37D9287C0F21331F001D4494 /* rarefactsharedcommand.cpp in Sources */, - 37D928800F21331F001D4494 /* readmatrix.cpp in Sources */, 37D928840F21331F001D4494 /* sabundvector.cpp in Sources */, 37D928850F21331F001D4494 /* sequence.cpp in Sources */, 37D928860F21331F001D4494 /* shannon.cpp in Sources */, @@ -863,6 +874,9 @@ 211C38320F961DD400FEE541 /* sharedutilities.cpp in Sources */, 211C38380F961E1F00FEE541 /* treegroupscommand.cpp in Sources */, 21DDC01B0F97A8FE0060691C /* bootstrapsharedcommand.cpp in Sources */, + 375AA1390F9E433D008EF9B8 /* readcolumn.cpp in Sources */, + 375AA13A0F9E433D008EF9B8 /* readotu.cpp in Sources */, + 375AA13B0F9E433D008EF9B8 /* readphylip.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/binsequencecommand.cpp b/binsequencecommand.cpp index 7c70604..375eec2 100644 --- a/binsequencecommand.cpp +++ b/binsequencecommand.cpp @@ -57,7 +57,7 @@ int BinSeqCommand::execute(){ } //read list file - read = new ReadPhilFile(globaldata->getListFile()); + read = new ReadOTUFile(globaldata->getListFile()); read->read(&*globaldata); input = globaldata->ginput; diff --git a/binsequencecommand.h b/binsequencecommand.h index 25f5216..617f5ec 100644 --- a/binsequencecommand.h +++ b/binsequencecommand.h @@ -14,7 +14,7 @@ #include "command.hpp" #include "inputdata.h" #include "listvector.hpp" -#include "readmatrix.hpp" +#include "readotu.h" #include "fastamap.h" @@ -30,7 +30,7 @@ public: private: GlobalData* globaldata; ListVector* list; - ReadMatrix* read; + ReadOTUFile* read; InputData* input; FastaMap* fasta; string filename, fastafile, namesfile; diff --git a/bootstrapsharedcommand.cpp b/bootstrapsharedcommand.cpp index b2a64ed..56611a8 100644 --- a/bootstrapsharedcommand.cpp +++ b/bootstrapsharedcommand.cpp @@ -93,14 +93,14 @@ int BootSharedCommand::execute(){ if (treeCalculators.size() == 0) { return 0; } if (format == "sharedfile") { - read = new ReadPhilFile(globaldata->inputFileName); + read = new ReadOTUFile(globaldata->inputFileName); read->read(&*globaldata); input = globaldata->ginput; order = input->getSharedOrderVector(); }else { //you are using a list and a groupfile - read = new ReadPhilFile(globaldata->inputFileName); + read = new ReadOTUFile(globaldata->inputFileName); read->read(&*globaldata); input = globaldata->ginput; diff --git a/bootstrapsharedcommand.h b/bootstrapsharedcommand.h index 194aa33..322cd28 100644 --- a/bootstrapsharedcommand.h +++ b/bootstrapsharedcommand.h @@ -15,7 +15,7 @@ #include "sharedlistvector.h" #include "inputdata.h" #include "groupmap.h" -#include "readmatrix.hpp" +#include "readotu.h" #include "validcalculator.h" #include "tree.h" #include "treemap.h" @@ -36,7 +36,7 @@ private: GlobalData* globaldata; SharedUtil* util; - ReadMatrix* read; + ReadOTUFile* read; TreeMap* tmap; Tree* t; vector treeCalculators; diff --git a/collectcommand.cpp b/collectcommand.cpp index 5994af5..62258a8 100644 --- a/collectcommand.cpp +++ b/collectcommand.cpp @@ -99,7 +99,7 @@ int CollectCommand::execute(){ //if the users entered no valid calculators don't execute command if (cDisplays.size() == 0) { return 0; } - read = new ReadPhilFile(globaldata->inputFileName); + read = new ReadOTUFile(globaldata->inputFileName); read->read(&*globaldata); order = globaldata->gorder; diff --git a/collectcommand.h b/collectcommand.h index 93b5607..016f37e 100644 --- a/collectcommand.h +++ b/collectcommand.h @@ -15,7 +15,7 @@ #include "groupmap.h" #include "collect.h" #include "display.h" -#include "readmatrix.hpp" +#include "readotu.h" #include "validcalculator.h" /*The collect() command: @@ -43,7 +43,7 @@ public: private: GlobalData* globaldata; - ReadMatrix* read; + ReadOTUFile* read; OrderVector* order; InputData* input; Collect* cCurve; diff --git a/collectsharedcommand.cpp b/collectsharedcommand.cpp index 41dc573..ad392e7 100644 --- a/collectsharedcommand.cpp +++ b/collectsharedcommand.cpp @@ -127,14 +127,14 @@ int CollectSharedCommand::execute(){ if (cDisplays.size() == 0) { return 0; } if (format == "sharedfile") { - read = new ReadPhilFile(globaldata->inputFileName); + read = new ReadOTUFile(globaldata->inputFileName); read->read(&*globaldata); input = globaldata->ginput; order = input->getSharedOrderVector(); }else { //you are using a list and a groupfile - read = new ReadPhilFile(globaldata->inputFileName); + read = new ReadOTUFile(globaldata->inputFileName); read->read(&*globaldata); input = globaldata->ginput; diff --git a/collectsharedcommand.h b/collectsharedcommand.h index 8c7aa00..aac31c1 100644 --- a/collectsharedcommand.h +++ b/collectsharedcommand.h @@ -17,7 +17,7 @@ #include "groupmap.h" #include "collect.h" #include "display.h" -#include "readmatrix.hpp" +#include "readotu.h" #include "validcalculator.h" #include "sharedutilities.h" @@ -48,7 +48,7 @@ private: SharedUtil* util; GroupMap* groupmap; SharedListVector* SharedList; - ReadMatrix* read; + ReadOTUFile* read; SharedOrderVector* order; InputData* input; ValidCalculators* validCalculator; diff --git a/getoturepcommand.cpp b/getoturepcommand.cpp index 6daad97..45f34fe 100644 --- a/getoturepcommand.cpp +++ b/getoturepcommand.cpp @@ -80,7 +80,7 @@ int GetOTURepCommand::execute(){ } //read list file - read = new ReadPhilFile(globaldata->getListFile()); + read = new ReadOTUFile(globaldata->getListFile()); read->read(&*globaldata); input = globaldata->ginput; diff --git a/getoturepcommand.h b/getoturepcommand.h index 4e2b3a0..706b219 100644 --- a/getoturepcommand.h +++ b/getoturepcommand.h @@ -16,7 +16,7 @@ #include "sparsematrix.hpp" #include "listvector.hpp" #include "inputdata.h" -#include "readmatrix.hpp" +#include "readotu.h" #include "fastamap.h" @@ -36,7 +36,7 @@ private: SparseMatrix* matrix; ListVector* list; ListVector* listOfNames; - ReadMatrix* read; + ReadOTUFile* read; InputData* input; FastaMap* fasta; string filename, fastafile, namesfile; diff --git a/heatmapcommand.cpp b/heatmapcommand.cpp index bbda2b3..b8b3820 100644 --- a/heatmapcommand.cpp +++ b/heatmapcommand.cpp @@ -46,14 +46,14 @@ int HeatMapCommand::execute(){ if (format == "sharedfile") { //you have groups - read = new ReadPhilFile(globaldata->inputFileName); + read = new ReadOTUFile(globaldata->inputFileName); read->read(&*globaldata); input = globaldata->ginput; order = input->getSharedOrderVector(); }else if (format == "shared") { //you are using a list and a groupfile - read = new ReadPhilFile(globaldata->inputFileName); + read = new ReadOTUFile(globaldata->inputFileName); read->read(&*globaldata); input = globaldata->ginput; @@ -61,7 +61,7 @@ int HeatMapCommand::execute(){ order = SharedList->getSharedOrderVector(); }else if (format == "list") { //you are using just a list file and have only one group - read = new ReadPhilFile(globaldata->inputFileName); + read = new ReadOTUFile(globaldata->inputFileName); read->read(&*globaldata); ordersingle = globaldata->gorder; diff --git a/heatmapcommand.h b/heatmapcommand.h index f75c064..edb3460 100644 --- a/heatmapcommand.h +++ b/heatmapcommand.h @@ -13,7 +13,7 @@ #include "command.hpp" #include "inputdata.h" -#include "readmatrix.hpp" +#include "readotu.h" #include "sharedlistvector.h" #include "heatmap.h" #include "sharedutilities.h" @@ -31,7 +31,7 @@ public: private: GlobalData* globaldata; - ReadMatrix* read; + ReadOTUFile* read; SharedUtil* util; InputData* input; SharedListVector* SharedList; diff --git a/parselistcommand.cpp b/parselistcommand.cpp index 1457c62..f144798 100644 --- a/parselistcommand.cpp +++ b/parselistcommand.cpp @@ -89,7 +89,7 @@ int ParseListCommand::execute(){ int count = 1; //read in listfile - read = new ReadPhilFile(globaldata->inputFileName); + read = new ReadOTUFile(globaldata->inputFileName); read->read(&*globaldata); input = globaldata->ginput; list = globaldata->gSharedList; diff --git a/parselistcommand.h b/parselistcommand.h index bf8ee5d..0477acd 100644 --- a/parselistcommand.h +++ b/parselistcommand.h @@ -14,7 +14,7 @@ #include "sharedlistvector.h" #include "inputdata.h" #include "groupmap.h" -#include "readmatrix.hpp" +#include "readotu.h" /* The parselist() command: @@ -37,7 +37,7 @@ private: GlobalData* globaldata; GroupMap* groupMap; InputData* input; - ReadMatrix* read; + ReadOTUFile* read; map filehandles; map groupOfLists; SharedListVector* list; diff --git a/rarefactcommand.cpp b/rarefactcommand.cpp index a83a750..3c79757 100644 --- a/rarefactcommand.cpp +++ b/rarefactcommand.cpp @@ -89,7 +89,7 @@ int RareFactCommand::execute(){ //if the users entered no valid calculators don't execute command if (rDisplays.size() == 0) { return 0; } - read = new ReadPhilFile(globaldata->inputFileName); + read = new ReadOTUFile(globaldata->inputFileName); read->read(&*globaldata); order = globaldata->gorder; diff --git a/rarefactcommand.h b/rarefactcommand.h index 28be17c..5ac970e 100644 --- a/rarefactcommand.h +++ b/rarefactcommand.h @@ -14,7 +14,7 @@ #include "inputdata.h" #include "rarefact.h" #include "display.h" -#include "readmatrix.hpp" +#include "readotu.h" #include "validcalculator.h" @@ -44,7 +44,7 @@ public: private: GlobalData* globaldata; vector rDisplays; - ReadMatrix* read; + ReadOTUFile* read; OrderVector* order; InputData* input; ValidCalculators* validCalculator; diff --git a/rarefactsharedcommand.cpp b/rarefactsharedcommand.cpp index dc71b22..89cf4e2 100644 --- a/rarefactsharedcommand.cpp +++ b/rarefactsharedcommand.cpp @@ -69,14 +69,14 @@ int RareFactSharedCommand::execute(){ if (rDisplays.size() == 0) { return 0; } if (format == "sharedfile") { - read = new ReadPhilFile(globaldata->inputFileName); + read = new ReadOTUFile(globaldata->inputFileName); read->read(&*globaldata); input = globaldata->ginput; order = input->getSharedOrderVector(); }else { //you are using a list and a groupfile - read = new ReadPhilFile(globaldata->inputFileName); + read = new ReadOTUFile(globaldata->inputFileName); read->read(&*globaldata); input = globaldata->ginput; diff --git a/rarefactsharedcommand.h b/rarefactsharedcommand.h index 2f7920e..a16fdb9 100644 --- a/rarefactsharedcommand.h +++ b/rarefactsharedcommand.h @@ -15,7 +15,7 @@ #include "inputdata.h" #include "rarefact.h" #include "display.h" -#include "readmatrix.hpp" +#include "readotu.h" #include "validcalculator.h" #include "sharedutilities.h" @@ -44,7 +44,7 @@ private: GlobalData* globaldata; SharedUtil* util; SharedListVector* SharedList; - ReadMatrix* read; + ReadOTUFile* read; SharedOrderVector* order; InputData* input; ValidCalculators* validCalculator; diff --git a/readcolumn.cpp b/readcolumn.cpp new file mode 100644 index 0000000..1d29208 --- /dev/null +++ b/readcolumn.cpp @@ -0,0 +1,160 @@ +/* + * readcolumn.cpp + * Mothur + * + * Created by Sarah Westcott on 4/21/09. + * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. + * + */ + +#include "readcolumn.h" +#include "progress.hpp" + +/***********************************************************************/ + +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 == -1) { distance = 1000000; } + + 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 == -1) { distance = 1000000; } + + 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 == -1) { distance = 1000000; } + + // 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; +} + + diff --git a/readcolumn.h b/readcolumn.h new file mode 100644 index 0000000..2e0120f --- /dev/null +++ b/readcolumn.h @@ -0,0 +1,29 @@ +#ifndef READCOLUMN_H +#define READCOLUMN_H +/* + * readcolumn.h + * Mothur + * + * Created by Sarah Westcott on 4/21/09. + * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. + * + */ + +#include "readmatrix.hpp" + +/******************************************************/ + +class ReadColumnMatrix : public ReadMatrix { + +public: + ReadColumnMatrix(string); + ~ReadColumnMatrix(); + void read(NameAssignment*); +private: + ifstream fileHandle; + string distFile; +}; + +/******************************************************/ + +#endif \ No newline at end of file diff --git a/readdistcommand.cpp b/readdistcommand.cpp index d8c3db1..f19bf11 100644 --- a/readdistcommand.cpp +++ b/readdistcommand.cpp @@ -8,6 +8,8 @@ */ #include "readdistcommand.h" +#include "readphylip.h" +#include "readcolumn.h" ReadDistCommand::ReadDistCommand(){ try { diff --git a/readmatrix.cpp b/readmatrix.cpp deleted file mode 100644 index 4cf39fa..0000000 --- a/readmatrix.cpp +++ /dev/null @@ -1,388 +0,0 @@ -/* - * readmatrix.cpp - * - * - * Created by Pat Schloss on 8/13/08. - * Copyright 2008 Patrick D. Schloss. All rights reserved. - * - */ - -using namespace std; - -#include "sparsematrix.hpp" -#include "progress.hpp" -#include "listvector.hpp" -#include "rabundvector.hpp" -#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 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> 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> 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> 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> 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> name; - matrixNames.push_back(name); - - if(nameMap == NULL){ - list->set(i, name); - for(int j=0;j> 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> 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;ierase(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. - inputList = 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 or shared. - }else {//there is an orderfile - input = new InputData(philFile, globaldata->getOrderFile(), globaldata->getFormat()); - } - - //memory leak prevention - //if (globaldata->ginput != NULL) { delete globaldata->ginput; } - globaldata->ginput = input; //saving to be used by collector and rarefact commands. - - if ((globaldata->getFormat() == "list") || (globaldata->getFormat() == "rabund") || (globaldata->getFormat() == "sabund")) {//you are reading a list, rabund or sabund file for collect, rarefaction or summary. - order = input->getOrderVector(); - //memory leak prevention - //if (globaldata->gorder != NULL) { delete globaldata->gorder; } - globaldata->gorder = order; //saving to be used by collect and rarefact commands. - sabund = inputSabund->getSAbundVector(); - globaldata->sabund = sabund; //saving to be used by summary command. - list = inputList->getListVector(); - globaldata->gListVector = list; - }else if (globaldata->getFormat() == "shared") { - SharedList = input->getSharedListVector(); //you are reading for collect.shared, rarefaction.shared, summary.shared, parselist command, or shared commands. - //memory leak prevention - //if (globaldata->gSharedList != NULL) { delete globaldata->gSharedList; } - globaldata->gSharedList = SharedList; - } - } - 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 index cfa7731..66480e7 100644 --- a/readmatrix.hpp +++ b/readmatrix.hpp @@ -11,15 +11,10 @@ */ #include "mothur.h" -#include "rabundvector.hpp" #include "listvector.hpp" -#include "sharedlistvector.h" #include "sparsematrix.hpp" #include "nameassignment.hpp" -#include "inputdata.h" #include "globaldata.hpp" -#include "sabundvector.hpp" -#include "groupmap.h" class SparseMatrix; @@ -40,58 +35,9 @@ 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; - InputData* inputList; - ListVector* list; - SharedListVector* SharedList; - OrderVector* order; - SAbundVector* sabund; - GlobalData* globaldata; - // InputData* getInput() { return input; } -}; - - - #endif diff --git a/readotu.cpp b/readotu.cpp new file mode 100644 index 0000000..0bcfd32 --- /dev/null +++ b/readotu.cpp @@ -0,0 +1,71 @@ +/* + * readotu.cpp + * Mothur + * + * Created by Sarah Westcott on 4/21/09. + * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. + * + */ + +#include "readotu.h" + +/***********************************************************************/ + +ReadOTUFile::ReadOTUFile(string pf): philFile(pf){ + + openInputFile(philFile, fileHandle); +} + +/***********************************************************************/ +//This function reads the list, rabund or sabund files to be used by collect and rarefact command. +void ReadOTUFile::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. + inputList = 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 or shared. + }else {//there is an orderfile + input = new InputData(philFile, globaldata->getOrderFile(), globaldata->getFormat()); + } + + //memory leak prevention + //if (globaldata->ginput != NULL) { delete globaldata->ginput; } + globaldata->ginput = input; //saving to be used by collector and rarefact commands. + + if ((globaldata->getFormat() == "list") || (globaldata->getFormat() == "rabund") || (globaldata->getFormat() == "sabund")) {//you are reading a list, rabund or sabund file for collect, rarefaction or summary. + order = input->getOrderVector(); + //memory leak prevention + //if (globaldata->gorder != NULL) { delete globaldata->gorder; } + globaldata->gorder = order; //saving to be used by collect and rarefact commands. + sabund = inputSabund->getSAbundVector(); + globaldata->sabund = sabund; //saving to be used by summary command. + list = inputList->getListVector(); + globaldata->gListVector = list; + }else if (globaldata->getFormat() == "shared") { + SharedList = input->getSharedListVector(); //you are reading for collect.shared, rarefaction.shared, summary.shared, parselist command, or shared commands. + //memory leak prevention + //if (globaldata->gSharedList != NULL) { delete globaldata->gSharedList; } + globaldata->gSharedList = SharedList; + } + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the ReadOTUFile class Function read. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the ReadOTUFile class function read. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } +} + +/***********************************************************************/ + +ReadOTUFile::~ReadOTUFile(){ +// delete input; +// delete order; +} + +/***********************************************************************/ + diff --git a/readotu.h b/readotu.h new file mode 100644 index 0000000..e954cbd --- /dev/null +++ b/readotu.h @@ -0,0 +1,44 @@ +#ifndef READOTU_H +#define READOTU_H +/* + * readotu.h + * Mothur + * + * Created by Sarah Westcott on 4/21/09. + * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. + * + */ + + + +#include "rabundvector.hpp" +#include "listvector.hpp" +#include "sharedlistvector.h" +#include "inputdata.h" +#include "globaldata.hpp" +#include "sabundvector.hpp" +#include "groupmap.h" + + +class ReadOTUFile { + +public: + ReadOTUFile(string); + ~ReadOTUFile(); + void read(GlobalData* globaldata); +private: + ifstream fileHandle; + string philFile; + InputData* input; + InputData* inputSabund; + InputData* inputList; + ListVector* list; + SharedListVector* SharedList; + OrderVector* order; + SAbundVector* sabund; + GlobalData* globaldata; + // InputData* getInput() { return input; } +}; + + +#endif \ No newline at end of file diff --git a/readotucommand.cpp b/readotucommand.cpp index 7a48f2c..9f27057 100644 --- a/readotucommand.cpp +++ b/readotucommand.cpp @@ -14,7 +14,7 @@ ReadOtuCommand::ReadOtuCommand(){ try { globaldata = GlobalData::getInstance(); filename = globaldata->inputFileName; - read = new ReadPhilFile(filename); + read = new ReadOTUFile(filename); if (globaldata->getFormat() == "shared") { //read in group map info. groupMap = new GroupMap(globaldata->getGroupFile()); diff --git a/readotucommand.h b/readotucommand.h index 7bd1ead..a21167e 100644 --- a/readotucommand.h +++ b/readotucommand.h @@ -10,7 +10,7 @@ */ #include "command.hpp" -#include "readmatrix.hpp" +#include "readotu.h" #include "inputdata.h" #include "groupmap.h" #include "sharedcommand.h" @@ -39,7 +39,7 @@ public: private: GlobalData* globaldata; - ReadMatrix* read; + ReadOTUFile* read; InputData* input; Command* shared; Command* parselist; diff --git a/readphylip.cpp b/readphylip.cpp new file mode 100644 index 0000000..174b7e3 --- /dev/null +++ b/readphylip.cpp @@ -0,0 +1,186 @@ +/* + * readphylip.cpp + * Mothur + * + * Created by Sarah Westcott on 4/21/09. + * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. + * + */ + +#include "readphylip.h" +#include "progress.hpp" + +/***********************************************************************/ + +ReadPhylipMatrix::ReadPhylipMatrix(string distFile){ + + successOpen = openInputFile(distFile, fileHandle); + +} + +/***********************************************************************/ + +void ReadPhylipMatrix::read(NameAssignment* nameMap){ + try { + + float distance; + int square, nseqs; + string name; + vector 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> 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> 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> distance; + + if (distance == -1) { distance = 1000000; } + + 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> distance; + + if (distance == -1) { distance = 1000000; } + + 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> name; + matrixNames.push_back(name); + + if(nameMap == NULL){ + list->set(i, name); + for(int j=0;j> distance; + + if (distance == -1) { distance = 1000000; } + + 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> distance; + + if (distance == -1) { distance = 1000000; } + + 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;ierase(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; +} + diff --git a/readphylip.h b/readphylip.h new file mode 100644 index 0000000..eab0df4 --- /dev/null +++ b/readphylip.h @@ -0,0 +1,29 @@ +#ifndef READPHYLIP_H +#define READPHYLIP_H +/* + * readphylip.h + * Mothur + * + * Created by Sarah Westcott on 4/21/09. + * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. + * + */ + +#include "readmatrix.hpp" + +/******************************************************/ + +class ReadPhylipMatrix : public ReadMatrix { + +public: + ReadPhylipMatrix(string); + ~ReadPhylipMatrix(); + void read(NameAssignment*); +private: + ifstream fileHandle; + string distFile; +}; + +/******************************************************/ + +#endif \ No newline at end of file diff --git a/sharedcommand.cpp b/sharedcommand.cpp index a797d54..c29d549 100644 --- a/sharedcommand.cpp +++ b/sharedcommand.cpp @@ -38,7 +38,7 @@ int SharedCommand::execute(){ globaldata = GlobalData::getInstance(); //read in listfile - read = new ReadPhilFile(globaldata->inputFileName); + read = new ReadOTUFile(globaldata->inputFileName); read->read(&*globaldata); input = globaldata->ginput; SharedList = globaldata->gSharedList; diff --git a/sharedcommand.h b/sharedcommand.h index 20e2ddb..b3506cd 100644 --- a/sharedcommand.h +++ b/sharedcommand.h @@ -13,7 +13,7 @@ #include "sharedlistvector.h" #include "inputdata.h" #include "shared.h" -#include "readmatrix.hpp" +#include "readotu.h" /* The shared() command: The shared command can only be executed after a successful read.shared command. @@ -34,7 +34,7 @@ public: private: void printSharedData(); GlobalData* globaldata; - ReadMatrix* read; + ReadOTUFile* read; SharedListVector* SharedList; InputData* input; Shared* shared; diff --git a/summarycommand.cpp b/summarycommand.cpp index 05fc6e8..8632ad4 100644 --- a/summarycommand.cpp +++ b/summarycommand.cpp @@ -101,7 +101,7 @@ int SummaryCommand::execute(){ openOutputFile(outputFileName, outputFileHandle); outputFileHandle << "label"; - read = new ReadPhilFile(globaldata->inputFileName); + read = new ReadOTUFile(globaldata->inputFileName); read->read(&*globaldata); for(int i=0;i sumCalculators; InputData* input; ValidCalculators* validCalculator; diff --git a/summarysharedcommand.cpp b/summarysharedcommand.cpp index 05a5f7e..eea7b25 100644 --- a/summarysharedcommand.cpp +++ b/summarysharedcommand.cpp @@ -123,14 +123,14 @@ int SummarySharedCommand::execute(){ if (sumCalculators.size() == 0) { return 0; } if (format == "sharedfile") { - read = new ReadPhilFile(globaldata->inputFileName); + read = new ReadOTUFile(globaldata->inputFileName); read->read(&*globaldata); input = globaldata->ginput; order = input->getSharedOrderVector(); }else { //you are using a list and a groupfile - read = new ReadPhilFile(globaldata->inputFileName); + read = new ReadOTUFile(globaldata->inputFileName); read->read(&*globaldata); input = globaldata->ginput; diff --git a/summarysharedcommand.h b/summarysharedcommand.h index 9e4a8c8..e87e75e 100644 --- a/summarysharedcommand.h +++ b/summarysharedcommand.h @@ -14,7 +14,7 @@ #include "sharedrabundvector.h" #include "inputdata.h" #include "calculator.h" -#include "readmatrix.hpp" +#include "readotu.h" #include "sharedlistvector.h" #include "validcalculator.h" #include "sharedutilities.h" @@ -45,7 +45,7 @@ public: private: GlobalData* globaldata; - ReadMatrix* read; + ReadOTUFile* read; SharedUtil* util; vector sumCalculators; InputData* input; diff --git a/treegroupscommand.cpp b/treegroupscommand.cpp index 6cc64fe..6393684 100644 --- a/treegroupscommand.cpp +++ b/treegroupscommand.cpp @@ -85,14 +85,14 @@ int TreeGroupCommand::execute(){ if (treeCalculators.size() == 0) { return 0; } if (format == "sharedfile") { - read = new ReadPhilFile(globaldata->inputFileName); + read = new ReadOTUFile(globaldata->inputFileName); read->read(&*globaldata); input = globaldata->ginput; order = input->getSharedOrderVector(); }else { //you are using a list and a groupfile - read = new ReadPhilFile(globaldata->inputFileName); + read = new ReadOTUFile(globaldata->inputFileName); read->read(&*globaldata); input = globaldata->ginput; diff --git a/treegroupscommand.h b/treegroupscommand.h index 4c3b842..3c40eff 100644 --- a/treegroupscommand.h +++ b/treegroupscommand.h @@ -15,7 +15,7 @@ #include "sharedlistvector.h" #include "inputdata.h" #include "groupmap.h" -#include "readmatrix.hpp" +#include "readotu.h" #include "validcalculator.h" #include "tree.h" #include "treemap.h" @@ -41,7 +41,7 @@ private: GlobalData* globaldata; SharedUtil* util; - ReadMatrix* read; + ReadOTUFile* read; TreeMap* tmap; Tree* t; vector treeCalculators; diff --git a/venncommand.cpp b/venncommand.cpp index e305f22..5357c25 100644 --- a/venncommand.cpp +++ b/venncommand.cpp @@ -95,14 +95,14 @@ int VennCommand::execute(){ if (format == "sharedfile") { //you have groups - read = new ReadPhilFile(globaldata->inputFileName); + read = new ReadOTUFile(globaldata->inputFileName); read->read(&*globaldata); input = globaldata->ginput; order = input->getSharedOrderVector(); }else if (format == "shared") { //you are using a list and a groupfile - read = new ReadPhilFile(globaldata->inputFileName); + read = new ReadOTUFile(globaldata->inputFileName); read->read(&*globaldata); input = globaldata->ginput; @@ -110,7 +110,7 @@ int VennCommand::execute(){ order = SharedList->getSharedOrderVector(); }else if (format == "list") { //you are using just a list file and have only one group - read = new ReadPhilFile(globaldata->inputFileName); + read = new ReadOTUFile(globaldata->inputFileName); read->read(&*globaldata); ordersingle = globaldata->gorder; diff --git a/venncommand.h b/venncommand.h index 30ff74e..063b8af 100644 --- a/venncommand.h +++ b/venncommand.h @@ -11,7 +11,7 @@ #include "command.hpp" #include "inputdata.h" -#include "readmatrix.hpp" +#include "readotu.h" #include "sharedlistvector.h" #include "venn.h" #include "validcalculator.h" @@ -30,7 +30,7 @@ public: private: GlobalData* globaldata; - ReadMatrix* read; + ReadOTUFile* read; SharedUtil* util; InputData* input; SharedListVector* SharedList; -- 2.39.2