From c63935337ec92edb5510ad061c296a9773790c8f Mon Sep 17 00:00:00 2001 From: Aaron <aaronquinlan@gmail.com> Date: Wed, 31 Aug 2011 18:16:48 -0400 Subject: [PATCH] fifo support add'l --- src/utils/bedFilePE/bedFilePE.cpp | 43 ++++++------------------- src/utils/bedGraphFile/bedGraphFile.cpp | 41 +++++------------------ 2 files changed, 17 insertions(+), 67 deletions(-) diff --git a/src/utils/bedFilePE/bedFilePE.cpp b/src/utils/bedFilePE/bedFilePE.cpp index e1b84b3f..adc447cd 100644 --- a/src/utils/bedFilePE/bedFilePE.cpp +++ b/src/utils/bedFilePE/bedFilePE.cpp @@ -29,41 +29,16 @@ void BedFilePE::Open(void) { _bedStream = &cin; } else { - size_t foundPos; - foundPos = bedFile.find_last_of(".gz"); - // is this a GZIPPED BED file? - if (foundPos == bedFile.size() - 1) { - igzstream beds(bedFile.c_str(), ios::in); - if ( !beds ) { - cerr << "Error: The requested bedpe file (" << bedFile << ") could not be opened. Exiting!" << endl; - exit (1); - } - else { - // if so, close it (this was just a test) - beds.close(); - // now set a pointer to the stream so that we - // can read the file later on. - // Thank God for Josuttis, p. 631! - _bedStream = new igzstream(bedFile.c_str(), ios::in); - } - } - // not GZIPPED. - else { + _bedStream = new ifstream(bedFile.c_str(), ios::in); - ifstream beds(bedFile.c_str(), ios::in); - // can we open the file? - if ( !beds ) { - cerr << "Error: The requested bed file (" << bedFile << ") could not be opened. Exiting!" << endl; - exit (1); - } - else { - // if so, close it (this was just a test) - beds.close(); - // now set a pointer to the stream so that we - // can read the file later on. - // Thank God for Josuttis, p. 631! - _bedStream = new ifstream(bedFile.c_str(), ios::in); - } + if (isGzipFile(_bedStream) == true) { + delete _bedStream; + _bedStream = new igzstream(bedFile.c_str(), ios::in); + } + // can we open the file? + if ( !(_bedStream->good()) ) { + cerr << "Error: The requested bed file (" << bedFile << ") could not be opened. Exiting!" << endl; + exit (1); } } } diff --git a/src/utils/bedGraphFile/bedGraphFile.cpp b/src/utils/bedGraphFile/bedGraphFile.cpp index df73d8c5..f3df5402 100644 --- a/src/utils/bedGraphFile/bedGraphFile.cpp +++ b/src/utils/bedGraphFile/bedGraphFile.cpp @@ -29,45 +29,20 @@ BedGraphFile::~BedGraphFile() { void BedGraphFile::Open() { if (bedGraphFile == "stdin" || bedGraphFile == "-") { _bedGraphStream = &cin; - return; } - // unzipped, regular - else if ((isGzipFile(bedGraphFile) == false) && (isRegularFile(bedGraphFile) == true)) { + else { _bedGraphStream = new ifstream(bedGraphFile.c_str(), ios::in); - // open an ifstream - ifstream bedg(bedGraphFile.c_str(), ios::in); - + if (isGzipFile(_bedGraphStream) == true) { + delete _bedGraphStream; + _bedGraphStream = new igzstream(bedGraphFile.c_str(), ios::in); + } // can we open the file? - if ( !bedg ) { - cerr << "Error: The requested bedgraph file (" << bedGraphFile << ") could not be opened. Exiting!" << endl; - exit (1); - } - else { - // if so, close it (this was just a test) - bedg.close(); - // now set a pointer to the stream so that we - _bedGraphStream = new ifstream(bedGraphFile.c_str(), ios::in); - } - } - else if ((isGzipFile(bedGraphFile) == true) && (isRegularFile(bedGraphFile) == true)) { - - igzstream bedg(bedGraphFile.c_str(), ios::in); - if ( !bedg ) { - cerr << "Error: The requested bedgraph file (" << bedGraphFile << ") could not be opened. Exiting!" << endl; + if ( !(_bedGraphStream->good()) ) { + cerr << "Error: The requested bed file (" << bedGraphFile << ") could not be opened. Exiting!" << endl; exit (1); } - else { - // if so, close it (this was just a test) - bedg.close(); - // now set a pointer to the stream so that we - _bedGraphStream = new igzstream(bedGraphFile.c_str(), ios::in); - } - } - else { - cerr << "Error: Unexpected file type (" << bedGraphFile << "). Exiting!" << endl; - exit(1); - } + } } -- GitLab