Skip to content

Commit

Permalink
check reference fasta and index files exist at start of run #121
Browse files Browse the repository at this point in the history
  • Loading branch information
timothymillar committed Jun 6, 2019
1 parent 18a5b4d commit 34bc3da
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tefingerprint/_applications/extract_informative.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ def run(self):
# check if samtools and bwa are available
check_programs_installed('bwa', 'samtools')

# check reference exists and is indexed
check_reference_fasta(self.reference_fasta)

# create temp dir for intermediate files if requested
if self.use_temp_dir:
self.temp_dir = mkdtemp()
Expand Down Expand Up @@ -535,6 +538,24 @@ def reverse_complement(sequence):
for base in reversed(sequence.upper()))


def check_reference_fasta(path):
"""Check reference fasta path is a valid file path and that the
`.pac` and `.sa` index files are valid file paths.
This is a simple check to save ambiguous errors after the initial fastq
is generated which can take some time.
This does not check that the reference and index files are correct,
just that they exist.
"""
if not os.path.isfile(path):
raise FileNotFoundError("Reference file not found: '{0}'".format(path))
for suffix in ['.pac', '.sa']:
idx_path = path + suffix
if not os.path.isfile(idx_path):
message = "Reference index file not found: '{0}'".format(idx_path)
raise FileNotFoundError(message)


def check_programs_installed(*args):
"""
Check if a program exists on the users path.
Expand Down

0 comments on commit 34bc3da

Please sign in to comment.