Skip to content

Commit

Permalink
Adds ability to write compressed files in get.seqs
Browse files Browse the repository at this point in the history
  • Loading branch information
mothur-westcott committed Dec 14, 2021
1 parent 07713e0 commit 457517b
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 22 deletions.
15 changes: 7 additions & 8 deletions source/commands/getseqscommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,14 +349,14 @@ void GetSeqsCommand::readGZFastq(string fastqfile){
if (outputdir == "") { thisOutputDir += util.hasPath(fastqfile); }
map<string, string> variables;
variables["[filename]"] = thisOutputDir + util.getRootName(util.getSimpleName(fastqfile));
variables["[extension]"] = util.getExtension(fastqfile);
variables["[extension]"] = ".fastq" + util.getExtension(fastqfile);
string outputFileName = getOutputFileName("fastq", variables);

ifstream in; boost::iostreams::filtering_istream inBoost;
util.openInputFileBinary(fastqfile, in, inBoost);

ofstream out; boost::iostreams::filtering_ostream outBoost;
util.openOutputFileBinary(fastqfile, out, outBoost);
ofstream file; ostream* out; boost::iostreams::filtering_streambuf<boost::iostreams::output> outBoost;
util.openOutputFileBinary(outputFileName, file, out, outBoost);

bool wroteSomething = false; int selectedCount = 0; set<string> uniqueNames;

Expand All @@ -375,7 +375,7 @@ void GetSeqsCommand::readGZFastq(string fastqfile){
if (uniqueNames.count(name) == 0) { //this name hasn't been seen yet
wroteSomething = true;
selectedCount++;
fread.printFastq(out);
fread.printFastq(*out);
uniqueNames.insert(name);
}else {
m->mothurOut("[WARNING]: " + name + " is in your fastq file more than once. Mothur requires sequence names to be unique. I will only add it once.\n");
Expand All @@ -384,10 +384,9 @@ void GetSeqsCommand::readGZFastq(string fastqfile){
}
util.gobble(inBoost);
}
in.close();
out.close();
inBoost.pop();
outBoost.pop();
in.close(); inBoost.pop();
boost::iostreams::close(outBoost);
file.close(); delete out;

if (m->getControl_pressed()) { util.mothurRemove(outputFileName); return; }

Expand Down
1 change: 0 additions & 1 deletion source/datastructures/fastqread.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ class FastqRead {
Sequence getSequence();
QualityScores getQuality();


private:
MothurOut* m;
Utils util;
Expand Down
17 changes: 7 additions & 10 deletions source/refchimeratest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,6 @@ int RefChimeraTest::analyzeUnalignedQuery(string queryName, string querySeq, str
/**************************************************************************************************/

double RefChimeraTest::alignQueryToReferences(string query, string reference, string& qAlign, string& rAlign, double& length){


try {
double GAP = -5;
double MATCH = 1;
Expand Down Expand Up @@ -414,7 +412,7 @@ double RefChimeraTest::alignQueryToReferences(string query, string reference, st
rAlign = reference.substr(0, j) + rAlign;
}

if (length == 0) { diffs = MAXINT; }
if (length == 0) { diffs = MOTHURMAX; }

return diffs;
}
Expand All @@ -423,7 +421,6 @@ double RefChimeraTest::alignQueryToReferences(string query, string reference, st
exit(1);
}
}

/**************************************************************************************************/

int RefChimeraTest::getUnalignedDiffs(string qAlign, string rAlign, vector<int>& leftDiffs, vector<int>& leftMap, vector<int>& rightDiffs, vector<int>& rightMap){
Expand Down Expand Up @@ -491,7 +488,7 @@ int RefChimeraTest::getUnalignedDiffs(string qAlign, string rAlign, vector<int>&

int RefChimeraTest::getAlignedMismatches(string& querySeq, vector<vector<int> >& left, vector<vector<int> >& right, int& bestRefSeq){

int bestSequenceMismatch = MAXINT;
int bestSequenceMismatch = MOTHURMAX;

for(int i=0;i<numRefSeqs;i++){

Expand Down Expand Up @@ -525,7 +522,7 @@ int RefChimeraTest::getAlignedMismatches(string& querySeq, vector<vector<int> >&

int RefChimeraTest::getChimera(vector<vector<int> >& left, vector<vector<int> >& right, int& leftParent, int& rightParent, int& breakPoint, vector<int>& singleLeft, vector<int>& bestLeft, vector<int>& singleRight, vector<int>& bestRight){

singleLeft.resize(alignLength, MAXINT);
singleLeft.resize(alignLength, MOTHURMAX);
bestLeft.resize(alignLength, -1);

for(int l=0;l<alignLength;l++){
Expand All @@ -537,7 +534,7 @@ int RefChimeraTest::getChimera(vector<vector<int> >& left, vector<vector<int> >&
}
}

singleRight.resize(alignLength, MAXINT);
singleRight.resize(alignLength, MOTHURMAX);
bestRight.resize(alignLength, -1);

for(int l=0;l<alignLength;l++){
Expand All @@ -549,7 +546,7 @@ int RefChimeraTest::getChimera(vector<vector<int> >& left, vector<vector<int> >&
}
}

int bestChimeraMismatches = MAXINT;
int bestChimeraMismatches = MOTHURMAX;
leftParent = -1;
rightParent = -1;
breakPoint = -1;
Expand All @@ -571,7 +568,7 @@ int RefChimeraTest::getChimera(vector<vector<int> >& left, vector<vector<int> >&

int RefChimeraTest::getTrimera(vector<vector<int> >& left, vector<vector<int> >& right, int& leftParent, int& middleParent, int& rightParent, int& breakPointA, int& breakPointB, vector<int>& singleLeft, vector<int>& bestLeft, vector<int>& singleRight, vector<int>& bestRight){

int bestTrimeraMismatches = MAXINT;
int bestTrimeraMismatches = MOTHURMAX;

leftParent = -1;
middleParent = -1;
Expand All @@ -584,7 +581,7 @@ int RefChimeraTest::getTrimera(vector<vector<int> >& left, vector<vector<int> >&
vector<vector<int> > minDeltaSeq; minDeltaSeq.resize(alignLength);

for(int i=0;i<alignLength;i++){
minDelta[i].assign(alignLength, MAXINT);
minDelta[i].assign(alignLength, MOTHURMAX);
minDeltaSeq[i].assign(alignLength, -1);
}

Expand Down
6 changes: 4 additions & 2 deletions source/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1114,16 +1114,18 @@ bool Utils::openInputFileBinary(string fileName, ifstream& file, boost::iostream
}
}
/***********************************************************************/
bool Utils::openOutputFileBinary(string fileName, ofstream& file, boost::iostreams::filtering_ostream& outBoost){
bool Utils::openOutputFileBinary(string fileName, ofstream& file, ostream*& out, boost::iostreams::filtering_streambuf<boost::iostreams::output>& outBoost){
try {
string completeFileName = getFullPathName(fileName);

file.open(completeFileName, ios_base::out | ios_base::binary | ios_base::trunc);

if(!file) { return false; }
else { //check for blank file
outBoost.push(boost::iostreams::gzip_compressor());
outBoost.push(boost::iostreams::gzip_compressor(boost::iostreams::gzip_params(9)));
outBoost.push(file);

out = new ostream(&outBoost);
return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion source/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class Utils {
#ifdef USE_BOOST
bool openInputFileBinary(string, ifstream&, boost::iostreams::filtering_istream&);
bool openInputFileBinary(string, ifstream&, boost::iostreams::filtering_istream&, string);
bool openOutputFileBinary(string, ofstream&, boost::iostreams::filtering_ostream&);
bool openOutputFileBinary(string fileName, ofstream& file, ostream*& out, boost::iostreams::filtering_streambuf<boost::iostreams::output>& outBoost);
string getline(boost::iostreams::filtering_istream& fileHandle);
#endif

Expand Down

0 comments on commit 457517b

Please sign in to comment.