From 18948efab25be397f3bd08cd164173b822618808 Mon Sep 17 00:00:00 2001 From: rishu2403 Date: Thu, 26 Aug 2021 14:05:44 +0530 Subject: [PATCH] Added support for persisting IndexedReads index to disk --- pysam/libcalignmentfile.pyx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pysam/libcalignmentfile.pyx b/pysam/libcalignmentfile.pyx index 6858985a..bcbb5f4e 100644 --- a/pysam/libcalignmentfile.pyx +++ b/pysam/libcalignmentfile.pyx @@ -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: @@ -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.'''