Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for persisting IndexedReads index to disk #1037

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion pysam/libcalignmentfile.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ from pysam.libcutils cimport force_bytes, force_str, charptr_to_str
from pysam.libcutils cimport encode_filename, from_string_and_size
from pysam.libcalignedsegment cimport makeAlignedSegment, makePileupColumn
from pysam.libchtslib cimport HTSFile, hisremote

import json
if PY_MAJOR_VERSION >= 3:
from io import StringIO
else:
Expand Down Expand Up @@ -2918,6 +2918,14 @@ cdef class IndexedReads:
self.htsfile = self.samfile.htsfile
self.header = samfile.header
self.owns_samfile = False

def store(self, filename):
with open(filename, 'w') as f:
json.dump(self.index, f)

def load(self, filename):
with open(filename) as f:
self.index = json.load(f)

def build(self):
'''build the index.'''
Expand Down