99import json
1010import subprocess
1111import warnings
12+ import shutil
1213from Bio import AlignIO , SeqIO
1314from Bio .Blast import NCBIWWW
1415from Bio .Align .Applications import MuscleCommandline
2930logging .basicConfig (format = '%(name)s [%(levelname)s] %(message)s' , level = logging .INFO )
3031logger = logging .getLogger ("whiscy_setup" )
3132
33+ #Some extra checks...
34+ if 'WHISCY_PATH' not in os .environ :
35+ logger .warning ("WHISCY_PATH variable not defined in the environment. Assuming the path of the script..." )
36+ os .environ ['WHISCY_PATH' ] = os .path .abspath (os .path .dirname (__file__ ))+ os .path .sep
37+ if shutil .which ("freesasa" ) is None :
38+ logger .critical ("FreeSASA not in PATH. Please set environment correctly." )
39+ raise SystemExit
3240
3341def load_config (config_file = 'etc/local.json' ):
3442 """Load Whiscy configuration"""
@@ -41,6 +49,9 @@ def muscle_msa(config, input_sequence_file, output_alignment_file):
4149 """Calculates a MSA using MUSCLE's Biopython wrapper"""
4250 muscle_bin = config ['ALIGN' ]['MUSCLE_BIN' ]
4351 muscle_cline = MuscleCommandline (muscle_bin , input = input_sequence_file , out = output_alignment_file )
52+ if not os .path .exists (muscle_bin ):
53+ logger .critical ("The path defined for the MUSCLE binary is not correct. Check the configuration file!" )
54+ raise SystemExit
4455 stdout , stderr = muscle_cline ()
4556 MultipleSeqAlignment = AlignIO .read (output_alignment_file , "fasta" )
4657 return MultipleSeqAlignment
@@ -76,8 +87,14 @@ def msa_to_phylseq(msa, master_sequence, output_file):
7687def calculate_protdist (phylip_file , protdist_output_file ):
7788 """Calculates the protdist of the given MSA"""
7889 protdist_bin = os .path .join (os .path .dirname (os .path .realpath (__file__ )), "bin" , "protdist" , "protdist" )
90+ if not os .path .exists (protdist_bin ):
91+ logger .critical ("Protdist was not compiled. Please check the installation instructions" )
92+ raise SystemExit
7993 cmd = "{0} {1} {2} > /dev/null 2>&1" .format (protdist_bin , phylip_file , protdist_output_file )
80- subprocess .run (cmd , shell = True )
94+ try :
95+ subprocess .run (cmd , shell = True )
96+ except :
97+ subprocess .check_call (cmd , shell = True )
8198
8299
83100def write_to_fasta (output_fasta_file , sequence ):
0 commit comments