Skip to content

Commit 0b36db9

Browse files
author
Hermann Romanek
committed
#531 - fixed reference reading
1 parent 2fcff67 commit 0b36db9

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/sniffles/result.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ def store_calls(self, svcalls):
171171

172172
with open(self.tmpfile_name, 'a') as f:
173173
vcf = VCF(SnifflesConfig.GLOBAL, f)
174+
vcf.open_reference(generate_index=False)
174175
for call in svcalls[offset:]:
175176
vcf.write_call(call)
176177

src/sniffles/vcf.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,18 @@ def __init__(self, config: SnifflesConfig, handle):
9898
self.reference_handle = None
9999
self.header_str = ""
100100

101-
def open_reference(self):
101+
def open_reference(self, generate_index: bool = True):
102102
if self.config.reference is None:
103103
return
104104

105-
if not os.path.exists(self.config.reference + ".fai") and not os.path.exists(self.config.reference + ".gzi"):
106-
print(f"Info: Fasta index for {self.config.reference} not found. Generating with pysam.faidx "
107-
f"(this may take a while)")
105+
if not os.path.exists(self.config.reference + ".fai") and not os.path.exists(self.config.reference + ".gzi") and generate_index:
106+
log.warning(f"Fasta index for {self.config.reference} not found. Generating with pysam.faidx (this may take a while)")
108107
pysam.faidx(self.config.reference)
109-
self.reference_handle = pysam.FastaFile(self.config.reference)
108+
109+
try:
110+
self.reference_handle = pysam.FastaFile(self.config.reference)
111+
except:
112+
log.error(f'Unable to open reference file {self.config.reference}')
110113

111114
def write_header(self, contigs_lengths):
112115
self.write_header_line("fileformat=VCFv4.2")

0 commit comments

Comments
 (0)