Skip to content

Commit

Permalink
catch all exceptions
Browse files Browse the repository at this point in the history
Add outer most broad exception chatchin to stop crash tracebac propagation
  • Loading branch information
SchwarzMarek committed Jul 24, 2019
1 parent 74f215b commit 38d5143
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 21 deletions.
53 changes: 34 additions & 19 deletions rna_blast_analyze/BA.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,27 +385,42 @@ def check_if_rfam_needed(inargs):


def main():

# outer envelope for the script
# ========= perform argument parsing =========

if download_name in sys.argv and not ('-q' in sys.argv or '--blast_query' in sys.argv):
# run download rfam here
# do not run, if given with normal run request
from rna_blast_analyze.BR_core.config import tools_paths, CONFIG
from rna_blast_analyze.BR_core import cmalign
if cfg_name in sys.argv:
CONFIG.override(tools_paths(config_file=sys.argv[sys.argv.index(cfg_name) + 1]))
cmalign.download_cmmodels_file()
# rfam database downloaded
try:
# outer envelope for the script
# ========= perform argument parsing =========

if download_name in sys.argv and not ('-q' in sys.argv or '--blast_query' in sys.argv):
# run download rfam here
# do not run, if given with normal run request
from rna_blast_analyze.BR_core.config import tools_paths, CONFIG
from rna_blast_analyze.BR_core import cmalign
if cfg_name in sys.argv:
CONFIG.override(tools_paths(config_file=sys.argv[sys.argv.index(cfg_name) + 1]))
cmalign.download_cmmodels_file()
# rfam database downloaded
sys.exit(0)

args = f_parser()

_ = lunch_with_args(args)

# if we reach here, exit with 0
sys.exit(0)
except Exception as e:
print('Something went wrong.')
try:
import traceback
print(
'The error traceback is written to rboAnalyzer.log . '
'Please send it along with the query file and BLAST input to the developers.'
)

args = f_parser()

_ = lunch_with_args(args)

# if we reach here, exit with 0
sys.exit(0)
with open('rboAnalyzer.log', 'w') as fd:
fd.write(str(e))
fd.write(traceback.format_exc())
except:
pass
sys.exit(1)


def lunch_with_args(args):
Expand Down
4 changes: 2 additions & 2 deletions test_func/test_infer_homology.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ def clean_object(self):
self.data.query.annotations = dict()
for h in self.data.hits:
h.extension.annotations = dict()
self.data.args.blast_query = os.path.join(fwd, test_dir, 'RF00001.fasta')
self.data.cm_file = os.path.join(fwd, test_dir, 'RF00001.cm')

def test_simple(self):
self.clean_object()
Expand All @@ -29,15 +31,13 @@ def test_simple(self):
def test_rfam(self):
self.clean_object()
self.data.args.use_rfam = True
self.data.args.blast_query = os.path.join(fwd, test_dir, 'RF00001.fasta')
cm_file, _ = infer_homology.find_and_extract_cm_model(self.data.args, self.data)
pred, sel, cmfile = infer_homology.infer_homology(self.data, self.data.args, cm_file)
os.remove(cmfile)

def test_with_cm_file(self):
self.clean_object()
self.data.args.use_rfam = False
self.data.cm_file = os.path.join(fwd, test_dir, 'RF00001.cm')
cm_file, _ = infer_homology.find_and_extract_cm_model(self.data.args, self.data)
pred, sel, _ = infer_homology.infer_homology(self.data, self.data.args, cm_file)

Expand Down

0 comments on commit 38d5143

Please sign in to comment.