From d65489703b0129f7da7e36762ac672cb9d24b146 Mon Sep 17 00:00:00 2001
From: Aaron <aaronquinlan@gmail.com>
Date: Wed, 31 Aug 2011 22:39:21 -0400
Subject: [PATCH] Need to rewind to start of file after Gzip check.

---
 src/utils/Fasta/Fasta.cpp               | 4 ++--
 src/utils/Fasta/Fasta.h                 | 4 ++--
 src/utils/bedFile/bedFile.cpp           | 3 +++
 src/utils/bedFilePE/bedFilePE.cpp       | 4 ++++
 src/utils/bedGraphFile/bedGraphFile.cpp | 4 ++++
 5 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/src/utils/Fasta/Fasta.cpp b/src/utils/Fasta/Fasta.cpp
index 447eab8b..bd0c7009 100644
--- a/src/utils/Fasta/Fasta.cpp
+++ b/src/utils/Fasta/Fasta.cpp
@@ -286,7 +286,7 @@ string FastaReference::sequenceNameStartingWith(string seqnameStart) {
     }
 }
 
-string FastaReference::getSubSequence(const string &seqname, int start, int length) {
+string FastaReference::getSubSequence(string seqname, int start, int length) {
     FastaIndexEntry entry = index->entry(seqname);
     if (start < 0 || length < 1) {
         cerr << "Error: cannot construct subsequence with negative offset or length < 1" << endl;
@@ -318,7 +318,7 @@ string FastaReference::getSubSequence(const string &seqname, int start, int leng
     return s;
 }
 
-long unsigned int FastaReference::sequenceLength(const string &seqname) {
+long unsigned int FastaReference::sequenceLength(string seqname) {
     FastaIndexEntry entry = index->entry(seqname);
     return entry.length;
 }
diff --git a/src/utils/Fasta/Fasta.h b/src/utils/Fasta/Fasta.h
index 9bebae04..f9e3a7f5 100644
--- a/src/utils/Fasta/Fasta.h
+++ b/src/utils/Fasta/Fasta.h
@@ -70,9 +70,9 @@ class FastaReference {
         string getSequence(string seqname);
         // potentially useful for performance, investigate
         // void getSequence(string seqname, string& sequence);
-        string getSubSequence(const string &seqname, int start, int length);
+        string getSubSequence(string seqname, int start, int length);
         string sequenceNameStartingWith(string seqnameStart);
-        long unsigned int sequenceLength(const string &seqname);
+        long unsigned int sequenceLength(string seqname);
 };
 
 #endif
diff --git a/src/utils/bedFile/bedFile.cpp b/src/utils/bedFile/bedFile.cpp
index 4b7bdc63..f296b429 100644
--- a/src/utils/bedFile/bedFile.cpp
+++ b/src/utils/bedFile/bedFile.cpp
@@ -139,6 +139,9 @@ void BedFile::Open(void) {
             delete _bedStream;
             _bedStream = new igzstream(bedFile.c_str(), ios::in);
         }
+        // bytes were consumed.  rewind.
+        _bedStream->seekg(0);
+        
         // can we open the file?
         if ( !(_bedStream->good()) ) {
             cerr << "Error: The requested bed file (" << bedFile << ") could not be opened. Exiting!" << endl;
diff --git a/src/utils/bedFilePE/bedFilePE.cpp b/src/utils/bedFilePE/bedFilePE.cpp
index adc447cd..08f8a456 100644
--- a/src/utils/bedFilePE/bedFilePE.cpp
+++ b/src/utils/bedFilePE/bedFilePE.cpp
@@ -35,6 +35,10 @@ void BedFilePE::Open(void) {
             delete _bedStream;
             _bedStream = new igzstream(bedFile.c_str(), ios::in);
         }
+        
+        // bytes were consumed.  rewind.
+        _bedStream->seekg(0);
+        
         // can we open the file?
         if ( !(_bedStream->good()) ) {
             cerr << "Error: The requested bed file (" << bedFile << ") could not be opened. Exiting!" << endl;
diff --git a/src/utils/bedGraphFile/bedGraphFile.cpp b/src/utils/bedGraphFile/bedGraphFile.cpp
index f3df5402..d9e618f7 100644
--- a/src/utils/bedGraphFile/bedGraphFile.cpp
+++ b/src/utils/bedGraphFile/bedGraphFile.cpp
@@ -37,6 +37,10 @@ void BedGraphFile::Open() {
             delete _bedGraphStream;
             _bedGraphStream = new igzstream(bedGraphFile.c_str(), ios::in);
         }
+        
+        // bytes were consumed.  rewind.
+        _bedGraphStream->seekg(0);
+        
         // can we open the file?
         if ( !(_bedGraphStream->good()) ) {
             cerr << "Error: The requested bed file (" << bedGraphFile << ") could not be opened. Exiting!" << endl;
-- 
GitLab