comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:dfcd8b6c1bda
1 /*****************************************************************************
2 bedGraphFile.cpp
3
4 (c) 2010 - Assaf Gordon
5 Hall Laboratory
6 Department of Biochemistry and Molecular Genetics
7 University of Virginia
8 aaronquinlan@gmail.com
9
10 Licenced under the GNU General Public License 2.0 license.
11 ******************************************************************************/
12 #include "bedGraphFile.h"
13 #include <sstream>
14
15 // Constructor
16 BedGraphFile::BedGraphFile(string &_file) :
17 bedGraphFile(_file),
18 _bedGraphStream(NULL)
19 {}
20
21
22 // Destructor
23 BedGraphFile::~BedGraphFile() {
24 Close();
25 }
26
27
28 // Open the BEDGRAPH file
29 void BedGraphFile::Open() {
30 if (bedGraphFile == "stdin" || bedGraphFile == "-") {
31 _bedGraphStream = &cin;
32 }
33 else {
34 _bedGraphStream = new ifstream(bedGraphFile.c_str(), ios::in);
35
36 if (isGzipFile(_bedGraphStream) == true) {
37 delete _bedGraphStream;
38 _bedGraphStream = new igzstream(bedGraphFile.c_str(), ios::in);
39 }
40 // can we open the file?
41 if ( !(_bedGraphStream->good()) ) {
42 cerr << "Error: The requested bed file (" << bedGraphFile << ") could not be opened. Exiting!" << endl;
43 exit (1);
44 }
45 }
46 }
47
48
49 // Close the BEDGRAPH file
50 void BedGraphFile::Close() {
51 if (bedGraphFile != "stdin" && bedGraphFile != "-") {
52 if (_bedGraphStream) {
53 delete _bedGraphStream;
54 _bedGraphStream = NULL ;
55 }
56 }
57 }
58