Browse files

Added seek() and rewind() methods to IntervalFile.

  • Loading branch information...
1 parent c342998 commit ab2b88762577b2fb9f5fb67ddea9d5ece37e3c40 @arq5x arq5x committed Sep 10, 2011
Showing with 36 additions and 0 deletions.
  1. +2 −0 pybedtools/cbedtools.pxd
  2. +19 −0 pybedtools/cbedtools.pyx
  3. +9 −0 src/bedFile.cpp
  4. +6 −0 src/bedFile.h
View
2 pybedtools/cbedtools.pxd
@@ -66,6 +66,8 @@ cdef extern from "bedFile.h":
cdef cppclass BedFile:
BedFile(string)
void Open()
+ void Rewind()
+ void Seek(unsigned long offset)
void Close()
BED GetNextBed()
void loadBedFileIntoMap()
View
19 pybedtools/cbedtools.pyx
@@ -556,6 +556,25 @@ cdef class IntervalFile:
self.intervalFile_ptr.loadBedFileIntoMap()
self._loaded = 1
+ def rewind(self):
+ """
+ Jump to the beginning of the file.
+ """
+ if not self._open:
+ self.intervalFile_ptr.Open()
+ self._open = 1
+ self.intervalFile_ptr.Rewind()
+
+ def seek(self, offset):
+ """
+ Jump to a specific byte offset in the file
+ """
+ if not self._open:
+ self.intervalFile_ptr.Open()
+ self._open = 1
+ self.intervalFile_ptr.Seek(offset)
+
+
def all_hits(self, Interval interval, bool same_strand=False, float overlap=0.0):
"""
:Signature: `IntervalFile.all_hits(interval, same_strand=False, overlap=0.0)`
View
9 src/bedFile.cpp
@@ -67,6 +67,15 @@ void BedFile::Open(void) {
}
}
+// Rewind the pointer back to the beginning of the file
+void BedFile::Rewind(void) {
+ _bedStream->seekg(0, ios::beg);
+}
+
+// Jump to a specific byte in the file
+void BedFile::Seek(unsigned long offset) {
+ _bedStream->seekg(offset);
+}
// Close the BED file
void BedFile::Close(void) {
View
6 src/bedFile.h
@@ -274,6 +274,12 @@ class BedFile {
// Open a BED file for reading (creates an istream pointer)
void Open(void);
+
+ // Rewind the pointer back to the beginning of the file
+ void Rewind(void);
+
+ // Jump to a specific byte in the file
+ void Seek(unsigned long offset);
// Close an opened BED file.
void Close(void);

0 comments on commit ab2b887

Please sign in to comment.