diff --git a/transvar/config.py b/transvar/config.py index cf1ed99..778836a 100644 --- a/transvar/config.py +++ b/transvar/config.py @@ -55,7 +55,7 @@ def gunzip(fn): cfg_fns = [os.path.join(os.path.dirname(__file__), 'transvar.cfg'), - os.path.expanduser('~/.transvar.cfg')] + os.path.expanduser(os.getenv('TRANSVAR_CFG', '~/.transvar.cfg'))] downloaddirs = [os.path.join(os.path.dirname(__file__), 'transvar.download'), os.path.expanduser('~/.transvar.download')] diff --git a/transvar/faidx.py b/transvar/faidx.py index 349043f..165eefc 100755 --- a/transvar/faidx.py +++ b/transvar/faidx.py @@ -1,6 +1,8 @@ """ faidx python code adapted from Allen Yu http://www.allenyu.info/item/24-quickly-fetch-sequence-from-samtools-faidx-indexed-fasta-sequences.html """ import sys +import mmap + from err import * from utils import * @@ -10,8 +12,10 @@ def __init__(self, fasta_file): self.faidx = {} self.fasta_file=fasta_file + try: - self.fasta_handle=open(fasta_file) + self.fasta_fd = open(fasta_file) + self.fasta_handle = mmap.mmap(self.fasta_fd.fileno(), 0, access=mmap.ACCESS_READ) except IOError: print "Reference sequence doesn't exist" @@ -83,6 +87,7 @@ def fetch_sequence(self, chrom, start, end): def __exit__(self, type, value, traceback): self.fasta_handle.close() + self.fasta_fd.close() self.faidx_handle.close() def chrm2len(self, chrm):