Skip to content

Commit

Permalink
replace SystemExit with sys.exit(1) (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
rvhonorato committed Jun 27, 2024
1 parent 0327152 commit 9adcacf
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 15 deletions.
8 changes: 4 additions & 4 deletions src/whiscy/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def main():

if not len(converted_surface):
logger.error("No surface residues")
raise SystemExit
sys.exit(1)

logger.info("Initializing score calculation...")
try:
Expand All @@ -88,7 +88,7 @@ def main():
)
except Exception as err:
logger.error(str(err))
raise SystemExit
sys.exit(1)

logger.info("Calculating scores...")
realsum = 0
Expand All @@ -98,7 +98,7 @@ def main():
totlist.append(r)
if r.nr > seqlen or r.nr < 1:
logger.error("Surface residue out of range")
raise SystemExit
sys.exit(1)
posnr, distances, scores = pam_calc_similarity(
converted_surface[n] - 1, seqnr, sequences, seq_distances
)
Expand All @@ -109,7 +109,7 @@ def main():

if realsum == 0:
logger.error("No sequence information for any surface residues")
raise SystemExit
sys.exit(1)

logger.info("Subtracting average value ...")

Expand Down
6 changes: 3 additions & 3 deletions src/whiscy/cli_consadjust.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def main():

if not os.path.exists(args.cons_file):
logger.error("Conservation file {} does not exist".format(args.cons_file))
raise SystemExit
sys.exit(1)

logger.info("Reading input files")

Expand All @@ -65,15 +65,15 @@ def main():
logger.error(
"All identical values in conservation file {}".format(args.cons_file)
)
raise SystemExit
sys.exit(1)

zcalc = [(res.score - mean) / stddev for res in residues]

# Load Z-matrix
z_values = np.array(load_z_table(ZTABLE_FILE))
if len(z_values) != 25000:
logger.error("Reading error in Z-table {}".format(args.cons_file))
raise SystemExit
sys.exit(1)

for n in range(consnr):
pscore = 0.0
Expand Down
2 changes: 1 addition & 1 deletion src/whiscy/cli_parasmooth.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def main():
res_sur = calculate_parasmooth(res_sur, res_lac, resdist, par)
except Exception as err:
logger.error(str(err))
raise SystemExit
sys.exit(1)

# If output to file
if args.output_file:
Expand Down
10 changes: 5 additions & 5 deletions src/whiscy/cli_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def main():
pdbutil.download_pdb_structure(pdb_code, input_pdb_file)
except Exception as err:
logger.error(str(err))
raise SystemExit
sys.exit(1)
else:
logger.warning(
"PDB structure already exists ({0}), no need to download it again".format(
Expand All @@ -164,7 +164,7 @@ def main():

if not os.path.exists(input_pdb_file):
logger.error("PDB structure file {0} not found".format(input_pdb_file))
raise SystemExit
sys.exit(1)

# Check if chain belongs to this PDB
pdb_parser = PDBParser(PERMISSIVE=True, QUIET=True)
Expand All @@ -173,14 +173,14 @@ def main():
chain_id = args.chain_id.upper()
if len(chain_id) > 1:
logger.error("Wrong chain id {0}".format(chain_id))
raise SystemExit
sys.exit(1)
if chain_id not in chain_ids:
logger.error(
"Chain {0} provided not in available chains: {1}".format(
chain_id, str(chain_ids)
)
)
raise SystemExit
sys.exit(1)

# Save only the given chain and discard residues with alternative positions
io = PDBIO()
Expand Down Expand Up @@ -302,7 +302,7 @@ def main():

if not os.path.exists(phylip_file):
logger.error("PHYLIP sequence file {0} not found".format(phylip_file))
raise SystemExit
sys.exit(1)

# Calculate protdist
protdist_output_file = "{0}_{1}.out".format(filename, chain_id)
Expand Down
7 changes: 5 additions & 2 deletions src/whiscy/modules/pdbutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import os
import re
import sys

from Bio import AlignIO
from Bio.PDB import PDBList
Expand Down Expand Up @@ -77,13 +78,15 @@ def map_protein_to_sequence_alignment(
# Check if sequence is the same
pdb_seq = "".join([mapping[k] for k in sorted(mapping.keys())])
if pdb_seq != sequence:
raise SystemExit("ERROR: PDB sequence doest not match sequence alignment")
print("ERROR: PDB sequence doest not match sequence alignment")
sys.exit(1)

# Account for gaps in phylipseq file
# alignment = list(AlignIO.parse(phylip_file, format='phylip-sequential'))[0]
# master_phylip = alignment[0].seq
# if str(master_phylip.ungap('-')) != pdb_seq:
# raise SystemExit("ERROR: PDB sequence doest not match sequence alignment in phylip file")
# print("ERROR: PDB sequence doest not match sequence alignment in phylip file")
# sys.exit(1)

with open(output_file_name, "w") as output_handle:
output_handle.write(
Expand Down

0 comments on commit 9adcacf

Please sign in to comment.