From faf4e99552d6fb4595ff348b1f909ddc74536da2 Mon Sep 17 00:00:00 2001 From: westcott Date: Thu, 4 Jun 2009 17:03:32 +0000 Subject: [PATCH] removed readseqs, readfasta, readnexus, readclustal, readseqsphylip and updated sequencedb to be a container that can read from a file. --- Mothur.xcodeproj/project.pbxproj | 52 ++------- aligncommand.cpp | 2 +- distancecommand.cpp | 28 ++--- distancecommand.h | 7 +- errorchecking.cpp | 90 ++------------- errorchecking.h | 3 +- filterseqscommand.h | 7 +- globaldata.cpp | 8 -- globaldata.hpp | 4 +- readclustal.cpp | 82 ------------- readclustal.h | 29 ----- readfasta.cpp | 154 ------------------------- readfasta.h | 33 ------ readnexusal.h | 36 ------ readseqs.h | 35 ------ readseqsphylip.cpp | 114 ------------------- screenseqscommand.cpp | 1 + screenseqscommand.h | 5 - seqsummarycommand.cpp | 1 + seqsummarycommand.h | 5 +- sequencedb.cpp | 190 ++++++++++++++++++++++++++++--- sequencedb.h | 15 ++- validparameter.cpp | 2 +- 23 files changed, 222 insertions(+), 681 deletions(-) delete mode 100644 readclustal.cpp delete mode 100644 readclustal.h delete mode 100644 readfasta.cpp delete mode 100644 readfasta.h delete mode 100644 readnexusal.h delete mode 100644 readseqs.h delete mode 100644 readseqsphylip.cpp diff --git a/Mothur.xcodeproj/project.pbxproj b/Mothur.xcodeproj/project.pbxproj index 2bdb5b9..fea328d 100644 --- a/Mothur.xcodeproj/project.pbxproj +++ b/Mothur.xcodeproj/project.pbxproj @@ -58,10 +58,6 @@ 377326650FAF16E0007ABB8B /* concensuscommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 377326630FAF16E0007ABB8B /* concensuscommand.cpp */; }; 378C1B030FB0644E004D63F5 /* filterseqscommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 378C1AEE0FB0644D004D63F5 /* filterseqscommand.cpp */; }; 378C1B040FB0644E004D63F5 /* goodscoverage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 378C1AF00FB0644D004D63F5 /* goodscoverage.cpp */; }; - 378C1B050FB0644E004D63F5 /* readclustal.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 378C1AF20FB0644D004D63F5 /* readclustal.cpp */; }; - 378C1B060FB0644E004D63F5 /* readfasta.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 378C1AF40FB0644D004D63F5 /* readfasta.cpp */; }; - 378C1B070FB0644E004D63F5 /* readnexus.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 378C1AF60FB0644D004D63F5 /* readnexus.cpp */; }; - 378C1B090FB0644E004D63F5 /* readseqsphylip.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 378C1AFB0FB0644D004D63F5 /* readseqsphylip.cpp */; }; 378C1B0A0FB0644E004D63F5 /* sequencedb.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 378C1AFD0FB0644D004D63F5 /* sequencedb.cpp */; }; 378C1B0B0FB0644E004D63F5 /* sharedjackknife.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 378C1AFF0FB0644D004D63F5 /* sharedjackknife.cpp */; }; 378C1B0C0FB0644E004D63F5 /* sharedmarczewski.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 378C1B010FB0644D004D63F5 /* sharedmarczewski.cpp */; }; @@ -69,7 +65,6 @@ 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 */; }; - 379643ED0FB9B5A80081FDB6 /* readseqs.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 379643EB0FB9B5A80081FDB6 /* readseqs.cpp */; }; 3799A9500FD6A58C00E33EDE /* distancedb.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3799A94C0FD6A58C00E33EDE /* distancedb.cpp */; }; 3799A9510FD6A58C00E33EDE /* seqsummarycommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3799A94E0FD6A58C00E33EDE /* seqsummarycommand.cpp */; }; 37AD4CE40F28AEA300AA2D49 /* sharedlistvector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37AD4CE30F28AEA300AA2D49 /* sharedlistvector.cpp */; }; @@ -189,8 +184,8 @@ 21E859D70FC4632E005E1A48 /* matrixoutputcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = matrixoutputcommand.cpp; sourceTree = SOURCE_ROOT; }; 370B88050F8A4EE4005AB382 /* getoturepcommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = getoturepcommand.h; sourceTree = SOURCE_ROOT; }; 370B88060F8A4EE4005AB382 /* getoturepcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = getoturepcommand.cpp; sourceTree = SOURCE_ROOT; }; - 371B30B20FD7EE67000414CA /* screenseqscommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = screenseqscommand.cpp; sourceTree = SOURCE_ROOT; }; - 371B30B30FD7EE67000414CA /* screenseqscommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = screenseqscommand.h; sourceTree = SOURCE_ROOT; }; + 371B30B20FD7EE67000414CA /* screenseqscommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = screenseqscommand.cpp; sourceTree = ""; }; + 371B30B30FD7EE67000414CA /* screenseqscommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = screenseqscommand.h; sourceTree = ""; }; 372E126E0F26365B0095CF7E /* readotucommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = readotucommand.h; sourceTree = SOURCE_ROOT; }; 372E126F0F26365B0095CF7E /* readotucommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = readotucommand.cpp; sourceTree = SOURCE_ROOT; }; 372E12940F263D5A0095CF7E /* readdistcommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = readdistcommand.h; sourceTree = SOURCE_ROOT; }; @@ -236,10 +231,10 @@ 374610820F40652400460C57 /* unweighted.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = unweighted.cpp; sourceTree = SOURCE_ROOT; }; 3746109B0F40657600460C57 /* unifracunweightedcommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = unifracunweightedcommand.h; sourceTree = SOURCE_ROOT; }; 3746109C0F40657600460C57 /* unifracunweightedcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = unifracunweightedcommand.cpp; sourceTree = SOURCE_ROOT; }; - 3749271B0FD58C840031C06B /* getsabundcommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = getsabundcommand.h; sourceTree = SOURCE_ROOT; }; - 3749271C0FD58C840031C06B /* getsabundcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = getsabundcommand.cpp; sourceTree = SOURCE_ROOT; }; - 3749273D0FD5956B0031C06B /* getrabundcommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = getrabundcommand.h; sourceTree = SOURCE_ROOT; }; - 3749273E0FD5956B0031C06B /* getrabundcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = getrabundcommand.cpp; sourceTree = SOURCE_ROOT; }; + 3749271B0FD58C840031C06B /* getsabundcommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = getsabundcommand.h; sourceTree = ""; }; + 3749271C0FD58C840031C06B /* getsabundcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = getsabundcommand.cpp; sourceTree = ""; }; + 3749273D0FD5956B0031C06B /* getrabundcommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = getrabundcommand.h; sourceTree = ""; }; + 3749273E0FD5956B0031C06B /* getrabundcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = getrabundcommand.cpp; sourceTree = ""; }; 37519A690F80E6EB00FED5E8 /* sharedanderbergs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sharedanderbergs.h; sourceTree = SOURCE_ROOT; }; 37519A6A0F80E6EB00FED5E8 /* sharedanderbergs.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sharedanderbergs.cpp; sourceTree = SOURCE_ROOT; }; 37519A9F0F810D0200FED5E8 /* venncommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = venncommand.h; sourceTree = SOURCE_ROOT; }; @@ -282,15 +277,6 @@ 378C1AEF0FB0644D004D63F5 /* filterseqscommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = filterseqscommand.h; sourceTree = SOURCE_ROOT; }; 378C1AF00FB0644D004D63F5 /* goodscoverage.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = goodscoverage.cpp; sourceTree = SOURCE_ROOT; }; 378C1AF10FB0644D004D63F5 /* goodscoverage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = goodscoverage.h; sourceTree = SOURCE_ROOT; }; - 378C1AF20FB0644D004D63F5 /* readclustal.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = readclustal.cpp; sourceTree = SOURCE_ROOT; }; - 378C1AF30FB0644D004D63F5 /* readclustal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = readclustal.h; sourceTree = SOURCE_ROOT; }; - 378C1AF40FB0644D004D63F5 /* readfasta.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = readfasta.cpp; sourceTree = SOURCE_ROOT; }; - 378C1AF50FB0644D004D63F5 /* readfasta.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = readfasta.h; sourceTree = SOURCE_ROOT; }; - 378C1AF60FB0644D004D63F5 /* readnexus.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = readnexus.cpp; sourceTree = SOURCE_ROOT; }; - 378C1AF70FB0644D004D63F5 /* readnexus.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = readnexus.h; sourceTree = SOURCE_ROOT; }; - 378C1AF80FB0644D004D63F5 /* readnexusal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = readnexusal.h; sourceTree = SOURCE_ROOT; }; - 378C1AFB0FB0644D004D63F5 /* readseqsphylip.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = readseqsphylip.cpp; sourceTree = SOURCE_ROOT; }; - 378C1AFC0FB0644D004D63F5 /* readseqsphylip.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = readseqsphylip.h; sourceTree = SOURCE_ROOT; }; 378C1AFD0FB0644D004D63F5 /* sequencedb.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sequencedb.cpp; sourceTree = SOURCE_ROOT; }; 378C1AFE0FB0644D004D63F5 /* sequencedb.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sequencedb.h; sourceTree = SOURCE_ROOT; }; 378C1AFF0FB0644D004D63F5 /* sharedjackknife.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sharedjackknife.cpp; sourceTree = SOURCE_ROOT; }; @@ -306,12 +292,10 @@ 379294880F2E258500B9034A /* parsimony.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = parsimony.h; sourceTree = SOURCE_ROOT; }; 379294890F2E258500B9034A /* parsimony.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = parsimony.cpp; sourceTree = SOURCE_ROOT; }; 3792948D0F2E271100B9034A /* treecalculator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = treecalculator.h; sourceTree = SOURCE_ROOT; }; - 379643EB0FB9B5A80081FDB6 /* readseqs.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = readseqs.cpp; sourceTree = SOURCE_ROOT; }; - 379643EC0FB9B5A80081FDB6 /* readseqs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = readseqs.h; sourceTree = SOURCE_ROOT; }; - 3799A94C0FD6A58C00E33EDE /* distancedb.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = distancedb.cpp; sourceTree = SOURCE_ROOT; }; - 3799A94D0FD6A58C00E33EDE /* distancedb.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = distancedb.hpp; sourceTree = SOURCE_ROOT; }; - 3799A94E0FD6A58C00E33EDE /* seqsummarycommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = seqsummarycommand.cpp; sourceTree = SOURCE_ROOT; }; - 3799A94F0FD6A58C00E33EDE /* seqsummarycommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = seqsummarycommand.h; sourceTree = SOURCE_ROOT; }; + 3799A94C0FD6A58C00E33EDE /* distancedb.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = distancedb.cpp; sourceTree = ""; }; + 3799A94D0FD6A58C00E33EDE /* distancedb.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = distancedb.hpp; sourceTree = ""; }; + 3799A94E0FD6A58C00E33EDE /* seqsummarycommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = seqsummarycommand.cpp; sourceTree = ""; }; + 3799A94F0FD6A58C00E33EDE /* seqsummarycommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = seqsummarycommand.h; sourceTree = ""; }; 37AD4CE20F28AEA300AA2D49 /* sharedlistvector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sharedlistvector.h; sourceTree = SOURCE_ROOT; }; 37AD4CE30F28AEA300AA2D49 /* sharedlistvector.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sharedlistvector.cpp; sourceTree = SOURCE_ROOT; }; 37AD4DB90F28E2FE00AA2D49 /* tree.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tree.h; sourceTree = SOURCE_ROOT; }; @@ -620,24 +604,13 @@ 3796441D0FB9B9650081FDB6 /* read */ = { isa = PBXGroup; children = ( - 378C1AF30FB0644D004D63F5 /* readclustal.h */, - 378C1AF20FB0644D004D63F5 /* readclustal.cpp */, 375AA1340F9E433D008EF9B8 /* readcolumn.h */, 375AA1330F9E433D008EF9B8 /* readcolumn.cpp */, - 378C1AF50FB0644D004D63F5 /* readfasta.h */, - 378C1AF40FB0644D004D63F5 /* readfasta.cpp */, 37D928130F21331F001D4494 /* readmatrix.hpp */, - 378C1AF70FB0644D004D63F5 /* readnexus.h */, - 378C1AF60FB0644D004D63F5 /* readnexus.cpp */, - 378C1AF80FB0644D004D63F5 /* readnexusal.h */, 375AA1360F9E433D008EF9B8 /* readotu.h */, 375AA1350F9E433D008EF9B8 /* readotu.cpp */, 375AA1380F9E433D008EF9B8 /* readphylip.h */, 375AA1370F9E433D008EF9B8 /* readphylip.cpp */, - 378C1AFC0FB0644D004D63F5 /* readseqsphylip.h */, - 378C1AFB0FB0644D004D63F5 /* readseqsphylip.cpp */, - 379643EB0FB9B5A80081FDB6 /* readseqs.cpp */, - 379643EC0FB9B5A80081FDB6 /* readseqs.h */, 37AD4DC80F28F3DD00AA2D49 /* readtree.h */, 37AD4DC90F28F3DD00AA2D49 /* readtree.cpp */, ); @@ -1090,15 +1063,10 @@ 377326650FAF16E0007ABB8B /* concensuscommand.cpp in Sources */, 378C1B030FB0644E004D63F5 /* filterseqscommand.cpp in Sources */, 378C1B040FB0644E004D63F5 /* goodscoverage.cpp in Sources */, - 378C1B050FB0644E004D63F5 /* readclustal.cpp in Sources */, - 378C1B060FB0644E004D63F5 /* readfasta.cpp in Sources */, - 378C1B070FB0644E004D63F5 /* readnexus.cpp in Sources */, - 378C1B090FB0644E004D63F5 /* readseqsphylip.cpp in Sources */, 378C1B0A0FB0644E004D63F5 /* sequencedb.cpp in Sources */, 378C1B0B0FB0644E004D63F5 /* sharedjackknife.cpp in Sources */, 378C1B0C0FB0644E004D63F5 /* sharedmarczewski.cpp in Sources */, 37C753CE0FB3415200DBD02E /* distancecommand.cpp in Sources */, - 379643ED0FB9B5A80081FDB6 /* readseqs.cpp in Sources */, 378DC5CF0FBDE1C8003B8607 /* aligncommand.cpp in Sources */, 373C68A40FC1C07D00137ACD /* alignment.cpp in Sources */, 373C68A50FC1C07D00137ACD /* alignmentcell.cpp in Sources */, diff --git a/aligncommand.cpp b/aligncommand.cpp index 08c291d..33c06d4 100644 --- a/aligncommand.cpp +++ b/aligncommand.cpp @@ -41,7 +41,7 @@ AlignCommand::AlignCommand(){ try { globaldata = GlobalData::getInstance(); - if(globaldata->getFastaFile() == "" && globaldata->getPhylipFile() == "" && globaldata->getNexusFile() == "" && globaldata->getClustalFile() == ""){ + if(globaldata->getFastaFile() == ""){ cout << "you forgot a template file" << endl; } openInputFile(globaldata->getCandidateFile(), in); diff --git a/distancecommand.cpp b/distancecommand.cpp index fbec46c..6eb7d57 100644 --- a/distancecommand.cpp +++ b/distancecommand.cpp @@ -24,6 +24,11 @@ DistanceCommand::DistanceCommand(){ convert(globaldata->getProcessors(), processors); convert(globaldata->getCutOff(), cutoff); + //open file + string filename = globaldata->getFastaFile(); + openInputFile(filename, in); + + int i; if (isTrue(countends) == true) { for (i=0; iEstimators.size(); i++) { @@ -67,21 +72,10 @@ DistanceCommand::DistanceCommand(){ int DistanceCommand::execute(){ try { - //read file - string filename = globaldata->inputFileName; - - if(globaldata->getFastaFile() != "") { - readSeqs = new ReadFasta(filename); } - else if(globaldata->getNexusFile() != "") { - readSeqs = new ReadNexus(filename); } - else if(globaldata->getClustalFile() != "") { - readSeqs = new ReadClustal(filename); } - else if(globaldata->getPhylipFile() != "") { - readSeqs = new ReadPhylip(filename); } - - readSeqs->read(); - seqDB = readSeqs->getDB(); - + //reads fasta file and fills sequenceDB + if(globaldata->getFastaFile() != "") { seqDB = new SequenceDB(in); } + else { cout << "Error no fasta file." << endl; return 0; } + int numSeqs = seqDB->getNumSeqs(); cutoff += 0.005; @@ -279,11 +273,11 @@ int DistanceCommand::driver(Dist* distCalculator, SequenceDB* align, int startLi for(int i=startLine;icalcDist(align->get(i), align->get(j)); + distCalculator->calcDist(*(align->get(i)), *(align->get(j))); double dist = distCalculator->getDist(); if(dist <= cutoff){ - distFile << align->get(i).getName() << ' ' << align->get(j).getName() << ' ' << dist << endl; + distFile << align->get(i)->getName() << ' ' << align->get(j)->getName() << ' ' << dist << endl; } } diff --git a/distancecommand.h b/distancecommand.h index 8bdf845..c99e5c2 100644 --- a/distancecommand.h +++ b/distancecommand.h @@ -16,11 +16,6 @@ #include "validcalculator.h" #include "dist.h" #include "sequencedb.h" -#include "readfasta.h" -#include "readnexus.h" -#include "readclustal.h" -#include "readseqsphylip.h" - class DistanceCommand : public Command { @@ -34,8 +29,8 @@ private: ValidCalculators* validCalculator; Dist* distCalculator; SequenceDB* seqDB; - ReadSeqs* readSeqs; ofstream out; + ifstream in; string outputFileName; string countends; int processors; diff --git a/errorchecking.cpp b/errorchecking.cpp index caf7f73..5f5cd1f 100644 --- a/errorchecking.cpp +++ b/errorchecking.cpp @@ -95,8 +95,6 @@ bool ErrorCheck::checkInput(string input) { if (parameter == "name" ) { namefile = value; } if (parameter == "order" ) { orderfile = value; } if (parameter == "fasta" ) { fastafile = value; } - if (parameter == "nexus" ) { nexusfile = value; } - if (parameter == "clustal" ) { clustalfile = value; } if (parameter == "tree" ) { treefile = value; } if (parameter == "group" ) { groupfile = value; } if (parameter == "shared" ) { sharedfile = value; } @@ -147,8 +145,6 @@ bool ErrorCheck::checkInput(string input) { if (parameter == "group" ) { groupfile = value; } if (parameter == "shared" ) { sharedfile = value; } if (parameter == "fasta" ) { fastafile = value; } - if (parameter == "nexus" ) { nexusfile = value; } - if (parameter == "clustal" ) { clustalfile = value; } if (parameter == "tree" ) { treefile = value; } if (parameter == "cutoff" ) { cutoff = value; } if (parameter == "precision" ) { precision = value; } @@ -284,14 +280,20 @@ bool ErrorCheck::checkInput(string input) { if (fastafile == "") { cout << "You must enter either a fasta file before you can use the filter.seqs or dist.seqs command." << endl; return false; } - validateSeqsFiles(); + validateReadFiles(); } if (commandName == "align.seqs") { if ((fastafile == "") || (candidatefile == "")) { cout << "You must enter fasta and a candidate file to use the align.seqs command." << endl; return false; } - validateSeqsFiles(); + validateReadFiles(); + + ifstream filehandle; + int ableToOpen = openInputFile(candidatefile, filehandle); + filehandle.close(); + //unable to open + if (ableToOpen == 1) { return false; } } if ((commandName == "bin.seqs")) { @@ -558,77 +560,6 @@ void ErrorCheck::validateReadPhil() { } /*******************************************************/ -/******************************************************/ -//This function checks to make sure the user entered appropriate -// format parameters on a distfile read -void ErrorCheck::validateSeqsFiles() { - try { - ifstream filehandle; - int ableToOpen; - - //checks to make sure only one file type is given - if (phylipfile != "") { - if ((nexusfile != "") || (fastafile != "") || (clustalfile != "")) { - cout << "You may enter ONLY ONE of the following: phylip, fasta, nexus or clustal." << endl; errorFree = false; } - else { - ableToOpen = openInputFile(phylipfile, filehandle); - filehandle.close(); - if (ableToOpen == 1) { //unable to open - errorFree = false; - } - } - }else if (nexusfile != "") { - if ((phylipfile != "") || (fastafile != "") || (clustalfile != "")) { - cout << "You may enter ONLY ONE of the following: phylip, fasta, nexus or clustal." << endl; errorFree = false; } - else { - ableToOpen = openInputFile(nexusfile, filehandle); - filehandle.close(); - if (ableToOpen == 1) { //unable to open - errorFree = false; - } - } - }else if (fastafile != "") { - if ((phylipfile != "") || (nexusfile != "") || (clustalfile != "")) { - cout << "You may enter ONLY ONE of the following: phylip, fasta, nexus or clustal." << endl; errorFree = false; } - else { - ableToOpen = openInputFile(fastafile, filehandle); - filehandle.close(); - if (ableToOpen == 1) { //unable to open - errorFree = false; - } - } - }else if (clustalfile != "") { - if ((phylipfile != "") || (nexusfile != "") || (fastafile != "")) { - cout << "You may enter ONLY ONE of the following: phylip, fasta, nexus or clustal." << endl; errorFree = false; } - else { - ableToOpen = openInputFile(clustalfile, filehandle); - filehandle.close(); - if (ableToOpen == 1) { //unable to open - errorFree = false; - } - } - }else if (candidatefile != "") { - ableToOpen = openInputFile(candidatefile, 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 validateSeqsFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the ErrorCheck class function validateSeqsFiles. 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 bin.seq command @@ -673,9 +604,6 @@ void ErrorCheck::validateBinFiles() { //unable to open if (ableToOpen == 1) { errorFree = false; } } - - - } catch(exception& e) { cout << "Standard Error: " << e.what() << " has occurred in the ErrorCheck class Function validateBinFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; @@ -703,8 +631,6 @@ void ErrorCheck::clear() { orderfile = ""; sharedfile = ""; fastafile = ""; - nexusfile = ""; - clustalfile = ""; candidatefile = ""; line = ""; label = ""; diff --git a/errorchecking.h b/errorchecking.h index ac09f6e..7f9e458 100644 --- a/errorchecking.h +++ b/errorchecking.h @@ -31,10 +31,9 @@ class ErrorCheck { void validateParseFiles(); void validateTreeFiles(); void validateBinFiles(); - void validateSeqsFiles(); void clear(); void refresh(); - string phylipfile, columnfile, listfile, rabundfile, sabundfile, namefile, groupfile, orderfile, fastafile, nexusfile, clustalfile, treefile, sharedfile, cutoff, format; + string phylipfile, columnfile, listfile, rabundfile, sabundfile, namefile, groupfile, orderfile, fastafile, treefile, sharedfile, cutoff, format; string precision, method, fileroot, label, line, iters, jumble, freq, single, rarefaction, shared, summary, randomtree, abund, sorted, trump, soft, filter, scale, countends, processors, size; string candidatefile, search, ksize, align, match, mismatch, gapopen, gapextend; string commandName, optionText; diff --git a/filterseqscommand.h b/filterseqscommand.h index 4b7d011..17f1b33 100644 --- a/filterseqscommand.h +++ b/filterseqscommand.h @@ -12,11 +12,7 @@ #include "command.hpp" #include "globaldata.hpp" -#include "readfasta.h" -#include "readnexus.h" -#include "readclustal.h" -#include "readseqsphylip.h" - +#include "sequence.hpp" class FilterSeqsCommand : public Command { @@ -41,6 +37,7 @@ private: GlobalData* globaldata; vector a, t, g, c, gap; + }; #endif diff --git a/globaldata.cpp b/globaldata.cpp index d7afc40..b446d67 100644 --- a/globaldata.cpp +++ b/globaldata.cpp @@ -60,8 +60,6 @@ void GlobalData::parseGlobalData(string commandString, string optionText){ if (key == "rabund" ) { rabundfile = value; inputFileName = value; fileroot = value; format = "rabund"; } if (key == "sabund" ) { sabundfile = value; inputFileName = value; fileroot = value; format = "sabund"; } if (key == "fasta" ) { fastafile = value; inputFileName = value; fileroot = value; format = "fasta"; } - if (key == "nexus" ) { nexusfile = value; inputFileName = value; fileroot = value; format = "nexus"; } - if (key == "clustal" ) { clustalfile = value; inputFileName = value; fileroot = value; format = "clustal"; } if (key == "tree" ) { treefile = value; inputFileName = value; fileroot = value; format = "tree"; } if (key == "shared" ) { sharedfile = value; inputFileName = value; fileroot = value; format = "sharedfile"; } if (key == "name" ) { namefile = value; } @@ -138,8 +136,6 @@ void GlobalData::parseGlobalData(string commandString, string optionText){ if (key == "rabund" ) { rabundfile = value; inputFileName = value; fileroot = value; format = "rabund"; } if (key == "sabund" ) { sabundfile = value; inputFileName = value; fileroot = value; format = "sabund"; } if (key == "fasta" ) { fastafile = value; inputFileName = value; fileroot = value; format = "fasta"; } - if (key == "nexus" ) { nexusfile = value; inputFileName = value; fileroot = value; format = "nexus"; } - if (key == "clustal" ) { clustalfile = value; inputFileName = value; fileroot = value; format = "clustal"; } if (key == "tree" ) { treefile = value; inputFileName = value; fileroot = value; format = "tree"; } if (key == "shared" ) { sharedfile = value; inputFileName = value; fileroot = value; format = "sharedfile"; } if (key == "name" ) { namefile = value; } @@ -303,8 +299,6 @@ string GlobalData::getOrderFile() { return orderfile; } string GlobalData::getTreeFile() { return treefile; } string GlobalData::getSharedFile() { return sharedfile; } string GlobalData::getFastaFile() { return fastafile; } -string GlobalData::getNexusFile() { return nexusfile; } -string GlobalData::getClustalFile() { return clustalfile; } string GlobalData::getCutOff() { return cutoff; } string GlobalData::getFormat() { return format; } string GlobalData::getPrecision() { return precision; } @@ -383,8 +377,6 @@ void GlobalData::clear() { groupfile = ""; orderfile = ""; fastafile = ""; - nexusfile = ""; - clustalfile = ""; treefile = ""; sharedfile = ""; candidatefile = ""; diff --git a/globaldata.hpp b/globaldata.hpp index 11422e0..af5b383 100644 --- a/globaldata.hpp +++ b/globaldata.hpp @@ -53,8 +53,6 @@ public: string getGroupFile(); string getOrderFile(); string getFastaFile(); - string getNexusFile(); - string getClustalFile(); string getTreeFile(); string getSharedFile(); string getCutOff(); @@ -123,7 +121,7 @@ public: private: - string phylipfile, columnfile, listfile, rabundfile, sabundfile, namefile, groupfile, orderfile, fastafile, nexusfile, clustalfile, treefile, sharedfile, line, label, randomtree, groups, cutoff, format, precision, method, fileroot, iters, jumble, freq, calc, abund, step, form, sorted, trump, soft, hard, scale, countends, processors, candidatefile, search, ksize, align, match, size, mismatch, gapopen, gapextend, minLength, maxLength, startPos, endPos, maxAmbig, maxHomoPolymer; + string phylipfile, columnfile, listfile, rabundfile, sabundfile, namefile, groupfile, orderfile, fastafile, treefile, sharedfile, line, label, randomtree, groups, cutoff, format, precision, method, fileroot, iters, jumble, freq, calc, abund, step, form, sorted, trump, soft, hard, scale, countends, processors, candidatefile, search, ksize, align, match, size, mismatch, gapopen, gapextend, minLength, maxLength, startPos, endPos, maxAmbig, maxHomoPolymer; static GlobalData* _uniqueInstance; diff --git a/readclustal.cpp b/readclustal.cpp deleted file mode 100644 index f42b359..0000000 --- a/readclustal.cpp +++ /dev/null @@ -1,82 +0,0 @@ -/* - * readclustal.cpp - * Mothur - * - * Created by Thomas Ryabin on 4/24/09. - * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. - * - */ - -#include "readclustal.h" -#include -#include - -/*******************************************************************************/ -ReadClustal::ReadClustal(string file) : ReadSeqs(file){ - try { - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the ReadTree class Function ReadTree. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the ReadTree class function ReadTree. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -} -/*******************************************************************************/ -ReadClustal::~ReadClustal(){ -// for(int i = 0; i < sequencedb.getNumSeqs(); i++) -// delete sequencedb.get(i); -} -/*******************************************************************************/ -void ReadClustal::read() { - string temp; - string name; - string sequence; - string firstName = ""; - for(int i = 0; i < 6; i++) - filehandle >> temp; - - int count = 0; - int numSeqs = 0; - int lastSeqLength = 0; - bool firstDone = false; - - while(!filehandle.eof()) { - filehandle >> name; - if(numSeqs != 0) { - if(count == numSeqs) - count = 0; - } - else if(!firstDone && firstName.compare("") == 0) - firstName = name; - else if(!firstDone && firstName.compare(name) == 0) { - numSeqs = count; - firstDone = true; - count = 0; - } - - if(name.find_first_of("*") == -1) { - filehandle >> sequence; - lastSeqLength = sequence.length(); - if(!firstDone) { - Sequence newSeq(name, sequence); - sequencedb.add(newSeq); - } - else - sequencedb.set(count, sequencedb.get(count).getUnaligned() + sequence); - - count++; - } - } - if(count == 1) - sequencedb.set(0, sequencedb.get(0).getUnaligned().substr(0, sequencedb.get(0).getUnaligned().length() - lastSeqLength)); - - filehandle.close(); -} - -/*********************************************************************************/ -SequenceDB* ReadClustal::getDB() { - return &sequencedb; -} diff --git a/readclustal.h b/readclustal.h deleted file mode 100644 index cedcaa7..0000000 --- a/readclustal.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef READCLUSTAL_H -#define READCLUSTAL_H - -/* - * readclustal.h - * Mothur - * - * Created by Thomas Ryabin on 4/24/09. - * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. - * - */ - -#include "readseqs.h" -#include "globaldata.hpp" -#include "sequencedb.h" -#include "mothur.h" - -/**********************************************************************************/ - -class ReadClustal : public ReadSeqs { - - public: - ReadClustal(string); - ~ReadClustal(); - void read(); - SequenceDB* getDB(); -}; - -#endif \ No newline at end of file diff --git a/readfasta.cpp b/readfasta.cpp deleted file mode 100644 index fcac6bd..0000000 --- a/readfasta.cpp +++ /dev/null @@ -1,154 +0,0 @@ -/* - * readfasta.cpp - * Mothur - * - * Created by Thomas Ryabin on 4/21/09. - * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. - * - */ - -#include "readfasta.h" -#include -#include - -/*******************************************************************************/ -ReadFasta::ReadFasta(string file) : ReadSeqs(file) {} -/*******************************************************************************/ -ReadFasta::~ReadFasta(){ - //for(int i = 0; i < sequencedb.getNumSeqs(); i++) - //delete sequencedb.get(i); -} -/*******************************************************************************/ -void ReadFasta::read() { - try { - /*string name = ""; - string sequence = ""; - string temp; - int count = 0; - - while(!filehandle.eof()){ - if(count == 0) - filehandle >> temp; - if(temp.substr(0,1).compare(">") == 0) { - if(count != 0) { - Sequence newSequence(name, sequence); - sequencedb.add(newSequence); - sequence = ""; - } - else - count++; - name = temp.substr(1,temp.length()-1); - } - else { - sequence += temp; - } - - filehandle >> temp; - gobble(filehandle); - - if(filehandle.eof()) - sequence += temp; - - } - Sequence newSequence(name, sequence); - sequencedb.add(newSequence); */ - - string name, sequence, line; - sequence = ""; - int c; - string temp; - - - //read through file - while ((c = filehandle.get()) != EOF) { - name = ""; sequence = ""; - //is this a name - if (c == '>') { - name = readName(filehandle); - sequence = readSequence(filehandle); - }else { cout << "Error fasta in your file. Please correct." << endl; } - - //input sequence info into sequencedb - Sequence newSequence(name, sequence); - sequencedb.add(newSequence); - - //takes care of white space - gobble(filehandle); - } - - filehandle.close(); - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the ReadFasta class Function read. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the ReadFasta class function read. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -} - -/*********************************************************************************/ -SequenceDB* ReadFasta::getDB() { - return &sequencedb; -} -/*******************************************************************************/ -string ReadFasta::readName(ifstream& in) { - try{ - string name = ""; - int c; - string temp; - - while ((c = in.get()) != EOF) { - //if c is not a line return - if (c != 10) { - name += c; - }else { break; } - } - - return name; - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the ReadFasta class Function readName. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the ReadFasta class function readName. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -} - -/*******************************************************************************/ -string ReadFasta::readSequence(ifstream& in) { - try{ - string sequence = ""; - string line; - int pos, c; - - while (!in.eof()) { - //save position in file in case next line is a new name. - pos = in.tellg(); - line = ""; - in >> line; - //if you are at a new name - if (line[0] == '>') { - //put file pointer back since you are now at a new name - in.seekg(pos, ios::beg); - c = in.get(); //because you put it back to a newline char - break; - }else { sequence += line; } - } - - return sequence; - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the ReadFasta class Function readSequence. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the ReadFasta class function readSequence. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -} -/*******************************************************************************/ - diff --git a/readfasta.h b/readfasta.h deleted file mode 100644 index a8e398b..0000000 --- a/readfasta.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef READFASTA_H -#define READFASTA_H - -/* - * readfasta.h - * Mothur - * - * Created by Thomas Ryabin on 4/21/09. - * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. - * - */ - -#include "readseqs.h" -#include "globaldata.hpp" -#include "sequencedb.h" -#include "mothur.h" - -/**********************************************************************************/ - -class ReadFasta : public ReadSeqs { - - public: - ReadFasta(string); - ~ReadFasta(); - void read(); - SequenceDB* getDB(); - private: - string readName(ifstream&); - string readSequence(ifstream&); - -}; - -#endif \ No newline at end of file diff --git a/readnexusal.h b/readnexusal.h deleted file mode 100644 index ea216ec..0000000 --- a/readnexusal.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef READNEXUSALN_H -#define READNEXUSALN_H - -/* - * readnexusaln.h - * Mothur - * - * Created by Thomas Ryabin on 4/22/09. - * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. - * - */ - -#include "globaldata.hpp" -#include "sequencedb.h" -//#include "utilities.hpp" - -/**********************************************************************************/ - -class ReadNexus { - - public: - ReadNexus(string); - ~ReadNexus(); - void read(); - - private: - GlobalData* globaldata; - string nexusFile; - ifstream filehandle; - SequenceDB sequencedb; - int readOk; // readOk = 0 means success, readOk = 1 means error(s). - - -}; - -#endif \ No newline at end of file diff --git a/readseqs.h b/readseqs.h deleted file mode 100644 index 1aefcc6..0000000 --- a/readseqs.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef READSEQS_H -#define READSEQS_H - -/* - * readseqs.h - * Mothur - * - * Created by Thomas Ryabin on 5/11/09. - * Copyright 2009Schloss Lab UMASS Amherst. All rights reserved. - * - */ - -#include "globaldata.hpp" -#include "sequencedb.h" -#include "mothur.h" - -/**********************************************************************************/ - -class ReadSeqs { - - public: - ReadSeqs(string); - ~ReadSeqs(); - virtual void read(); - virtual SequenceDB* getDB(); - - protected: - GlobalData* globaldata; - string seqFile; - ifstream filehandle; - SequenceDB sequencedb; - int readOk; // readOk = 0 means success, readOk = 1 means error(s). -}; - -#endif diff --git a/readseqsphylip.cpp b/readseqsphylip.cpp deleted file mode 100644 index 72c7d90..0000000 --- a/readseqsphylip.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/* - * readphylip.cpp - * Mothur - * - * Created by Thomas Ryabin on 4/24/09. - * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. - * - */ - -#include "readseqsphylip.h" -#include -#include - -/*******************************************************************************/ -bool ReadPhylip::isSeq(string seq) { - string validChars[] = {"A","G","C","T","U","N","-"}; - - for(int i = 0; i < seq.length(); i++) { - bool valid = false; - string c = seq.substr(i,1); - for(int k = 0; k < 7; k++) - if(c.compare(validChars[k]) == 0) { - valid = true; - k = 7; - } - if(!valid) - return false; - } - - return true; -} - -/*******************************************************************************/ -ReadPhylip::ReadPhylip(string file) : ReadSeqs(file) { } -/*******************************************************************************/ -ReadPhylip::~ReadPhylip(){ -// for(int i = 0; i < sequencedb.getNumSeqs(); i++) -// delete sequencedb.get(i); -} -/*******************************************************************************/ -void ReadPhylip::read() { - string temp; - string name; - string sequence; - - int count = 0; - int letterCount = 0; - int numCols = 0; - filehandle >> temp; - int numSeqs = atoi(temp.c_str()); - filehandle >> temp; - int numLetters = atoi(temp.c_str()); - - bool firstDone = false; - bool last = false; - filehandle >> name; - - while(!filehandle.eof()) { - if(!firstDone) { - sequence = ""; - if(count == 0) { - filehandle >> temp; - while(isSeq(temp)) { - sequence += temp; - numCols++; - filehandle >> temp; - } - letterCount += sequence.length(); - } - else { - for(int i = 0; i < numCols; i++) { - filehandle >> temp; - sequence += temp; - } - if(count < numSeqs-1) - filehandle >> temp; - } - Sequence newSeq(name, sequence); - sequencedb.add(newSeq); - if(count < numSeqs-1) - name = temp; - } - else { - sequence = ""; - for(int i = 0; i < numCols; i++) { - filehandle >> temp; - sequence += temp; - if(count == 0) - letterCount += temp.length(); - if(letterCount == numLetters && count == 0) { - numCols = i + 1; - i = numCols; - } - } - if(!(last && count == 0)) - sequencedb.set(count, sequencedb.get(count).getUnaligned() + sequence); - if(letterCount == numLetters && count == 0) - last = true; - } - - count++; - - if(count == numSeqs) { - firstDone = true; - count = 0; - } - } - filehandle.close(); -} - -/*********************************************************************************/ -SequenceDB* ReadPhylip::getDB() { - return &sequencedb; -} diff --git a/screenseqscommand.cpp b/screenseqscommand.cpp index 586e436..0538907 100644 --- a/screenseqscommand.cpp +++ b/screenseqscommand.cpp @@ -8,6 +8,7 @@ */ #include "screenseqscommand.h" +#include "sequence.hpp" //*************************************************************************************************************** diff --git a/screenseqscommand.h b/screenseqscommand.h index 425b473..9b98726 100644 --- a/screenseqscommand.h +++ b/screenseqscommand.h @@ -12,11 +12,6 @@ #include "mothur.h" #include "command.hpp" #include "globaldata.hpp" -#include "readfasta.h" -#include "readnexus.h" -#include "readclustal.h" -#include "readseqsphylip.h" - class ScreenSeqsCommand : public Command { diff --git a/seqsummarycommand.cpp b/seqsummarycommand.cpp index 18eddec..2f24da5 100644 --- a/seqsummarycommand.cpp +++ b/seqsummarycommand.cpp @@ -8,6 +8,7 @@ */ #include "seqsummarycommand.h" +#include "sequence.hpp" //*************************************************************************************************************** diff --git a/seqsummarycommand.h b/seqsummarycommand.h index 2334628..01dd450 100644 --- a/seqsummarycommand.h +++ b/seqsummarycommand.h @@ -13,10 +13,7 @@ #include "mothur.h" #include "command.hpp" #include "globaldata.hpp" -#include "readfasta.h" -#include "readnexus.h" -#include "readclustal.h" -#include "readseqsphylip.h" + class SeqSummaryCommand : public Command { diff --git a/sequencedb.cpp b/sequencedb.cpp index f948bf3..e0bd100 100644 --- a/sequencedb.cpp +++ b/sequencedb.cpp @@ -16,16 +16,113 @@ /***********************************************************************/ SequenceDB::SequenceDB() {} +/***********************************************************************/ +//the clear function free's the memory +SequenceDB::~SequenceDB() { clear(); } /***********************************************************************/ SequenceDB::SequenceDB(int newSize) { - data.resize(newSize); + data.resize(newSize, NULL); } /***********************************************************************/ -SequenceDB::SequenceDB(ifstream&) {} +SequenceDB::SequenceDB(ifstream& filehandle) { + try{ + string name, sequence, line; + sequence = ""; + int c; + string temp; + + + //read through file + while ((c = filehandle.get()) != EOF) { + name = ""; sequence = ""; + //is this a name + if (c == '>') { + name = readName(filehandle); + sequence = readSequence(filehandle); + }else { cout << "Error fasta in your file. Please correct." << endl; } + + //input sequence info into sequencedb + Sequence* newSequence = new Sequence(name, sequence); + data.push_back(newSequence); + + //takes care of white space + gobble(filehandle); + } + + filehandle.close(); + + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the SequenceDB class Function SequenceDB. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the SequenceDB class function SequenceDB. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } +} +/*******************************************************************************/ +string SequenceDB::readName(ifstream& in) { + try{ + string name = ""; + int c; + string temp; + + while ((c = in.get()) != EOF) { + //if c is not a line return + if (c != 10) { + name += c; + }else { break; } + } + + return name; + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the SequenceDB class Function readName. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the SequenceDB class function readName. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } +} + +/*******************************************************************************/ +string SequenceDB::readSequence(ifstream& in) { + try{ + string sequence = ""; + string line; + int pos, c; + + while (!in.eof()) { + //save position in file in case next line is a new name. + pos = in.tellg(); + line = ""; + in >> line; + //if you are at a new name + if (line[0] == '>') { + //put file pointer back since you are now at a new name + in.seekg(pos, ios::beg); + c = in.get(); //because you put it back to a newline char + break; + }else { sequence += line; } + } + + return sequence; + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the SequenceDB class Function readSequence. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the SequenceDB class function readSequence. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } +} /***********************************************************************/ @@ -36,32 +133,79 @@ int SequenceDB::getNumSeqs() { /***********************************************************************/ void SequenceDB::set(int index, string newUnaligned) { - Sequence newSeq(data[index].getName(), newUnaligned); - data[index] = newSeq; + try { + if (data[index] != NULL) { delete data[index]; } //free memory + + Sequence* newSeq = new Sequence(data[index]->getName(), newUnaligned); + data[index] = newSeq; + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the SequenceDB class Function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the SequenceDB class function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } } /***********************************************************************/ -void SequenceDB::set(int index, Sequence newSeq) { - data[index] = newSeq; +void SequenceDB::set(int index, Sequence* newSeq) { + try { + if (data[index] != NULL) { delete data[index]; } //free memory + data[index] = newSeq; + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the SequenceDB class Function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the SequenceDB class function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } } /***********************************************************************/ -Sequence SequenceDB::get(int index) { +Sequence* SequenceDB::get(int index) { return data[index]; } /***********************************************************************/ -void SequenceDB::changeSize(int newSize) { - data.resize(newSize); +void SequenceDB::resize(int newSize) { + try { + int size = data.size(); + + for (int i = size; i > newSize; i--) { delete data[i]; } + data.resize(newSize); + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the SequenceDB class Function resize. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the SequenceDB class function resize. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } } /***********************************************************************/ void SequenceDB::clear() { - data.clear(); + try { + for (int i = 0; i < data.size(); i++) { delete data[i]; } + data.clear(); + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the SequenceDB class Function clear. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the SequenceDB class function clear. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } } /***********************************************************************/ @@ -73,22 +217,36 @@ int SequenceDB::size() { /***********************************************************************/ void SequenceDB::print(ostream& out) { - for(int i = 0; i < data.size(); i++) - data[i].printSequence(out); + try { + for(int i = 0; i < data.size(); i++) { + data[i]->printSequence(out); + } + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the SequenceDB class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the SequenceDB class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } } /***********************************************************************/ -void SequenceDB::add(Sequence newSequence) { +void SequenceDB::push_back(Sequence* newSequence) { try { data.push_back(newSequence); } 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"; + cout << "Standard Error: " << e.what() << " has occurred in the SequenceDB class Function add. 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"; + cout << "An unknown error has occurred in the SequenceDB class function add. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; exit(1); } -} \ No newline at end of file +} + +/***********************************************************************/ + diff --git a/sequencedb.h b/sequencedb.h index 9ee8806..88b31e2 100644 --- a/sequencedb.h +++ b/sequencedb.h @@ -24,21 +24,24 @@ public: SequenceDB(); SequenceDB(int); //makes data that size SequenceDB(ifstream&); //reads file to fill data -// ~SequenceDB(); //loops through data and delete each sequence + SequenceDB(const SequenceDB& sdb) : data(sdb.data) {}; + ~SequenceDB(); //loops through data and delete each sequence int getNumSeqs(); void set(int, string); //unaligned - should also set length - void set(int, Sequence); //unaligned - should also set length - Sequence get(int); //returns sequence name at that location - void add(Sequence); //adds unaligned sequence - void changeSize(int); //resizes data + void set(int, Sequence*); //unaligned - should also set length + Sequence* get(int); //returns sequence name at that location + void push_back(Sequence*); //adds unaligned sequence + void resize(int); //resizes data void clear(); //clears data - remeber to loop through and delete the sequences inside or you will have a memory leak int size(); //returns datas size void print(ostream&); //loops through data using sequence class print private: - vector data; + vector data; + string readName(ifstream&); + string readSequence(ifstream&); }; diff --git a/validparameter.cpp b/validparameter.cpp index 5e401c1..c8144d0 100644 --- a/validparameter.cpp +++ b/validparameter.cpp @@ -276,7 +276,7 @@ void ValidParameters::initCommandParameters() { string filterseqsArray[] = {"fasta", "trump", "soft", "hard", "vertical"}; commandParameters["filter.seqs"] = addParameters(filterseqsArray, sizeof(filterseqsArray)/sizeof(string)); - string summaryseqsArray[] = {"fasta","phylip","clustal","nexus"}; + string summaryseqsArray[] = {"fasta"}; commandParameters["summary.seqs"] = addParameters(summaryseqsArray, sizeof(summaryseqsArray)/sizeof(string)); string screenseqsArray[] = {"fasta", "start", "end", "maxambig", "maxhomop", "minlength", "maxlength", "name", "group"}; -- 2.39.2