Mercurial > repos > aaronquinlan > multi_intersect
diff BEDTools-Version-2.14.3/src/utils/bedGraphFile/bedGraphFile.cpp @ 0:dfcd8b6c1bda
Uploaded
author | aaronquinlan |
---|---|
date | Thu, 03 Nov 2011 10:25:04 -0400 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/BEDTools-Version-2.14.3/src/utils/bedGraphFile/bedGraphFile.cpp Thu Nov 03 10:25:04 2011 -0400 @@ -0,0 +1,58 @@ +/***************************************************************************** + bedGraphFile.cpp + + (c) 2010 - Assaf Gordon + Hall Laboratory + Department of Biochemistry and Molecular Genetics + University of Virginia + aaronquinlan@gmail.com + + Licenced under the GNU General Public License 2.0 license. +******************************************************************************/ +#include "bedGraphFile.h" +#include <sstream> + +// Constructor +BedGraphFile::BedGraphFile(string &_file) : + bedGraphFile(_file), + _bedGraphStream(NULL) +{} + + +// Destructor +BedGraphFile::~BedGraphFile() { + Close(); +} + + +// Open the BEDGRAPH file +void BedGraphFile::Open() { + if (bedGraphFile == "stdin" || bedGraphFile == "-") { + _bedGraphStream = &cin; + } + else { + _bedGraphStream = new ifstream(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 ( !(_bedGraphStream->good()) ) { + cerr << "Error: The requested bed file (" << bedGraphFile << ") could not be opened. Exiting!" << endl; + exit (1); + } + } +} + + +// Close the BEDGRAPH file +void BedGraphFile::Close() { + if (bedGraphFile != "stdin" && bedGraphFile != "-") { + if (_bedGraphStream) { + delete _bedGraphStream; + _bedGraphStream = NULL ; + } + } +} +