diff --git a/pvactools/tools/pvacvector/run.py b/pvactools/tools/pvacvector/run.py index 1b5ea2a40..ebf52c9e7 100644 --- a/pvactools/tools/pvacvector/run.py +++ b/pvactools/tools/pvacvector/run.py @@ -257,6 +257,10 @@ def create_distance_matrix(Paths): return distance_matrix def find_optimal_path(graph, distance_matrix, seq_dict, base_output_dir, junctions_file, args): + (valid, error) = check_graph_valid(graph, seq_dict) + if not valid: + raise Exception("Invalid graph passed to find_optimal_path: {}".format(error)) + init_state = sorted(graph.nodes()) if not os.environ.get('TEST_FLAG') or os.environ.get('TEST_FLAG') == '0': random.shuffle(init_state) diff --git a/tests/test_pvacvector.py b/tests/test_pvacvector.py index 62b2a50d0..be239d551 100644 --- a/tests/test_pvacvector.py +++ b/tests/test_pvacvector.py @@ -464,6 +464,29 @@ def test_pvacvector_remove_peptides(self): output_dir.cleanup() + def test_find_optimal_path_raises_on_invalid_graph(self): + with tempfile.TemporaryDirectory() as output_dir: + seq_dict = {"MT.TEST.1": "SYFPEITHI"} + graph = run.initialize_graph(seq_dict.keys()) + distance_matrix = run.create_distance_matrix(graph) + junctions_file = run.write_junctions_file(graph, output_dir) + args = argparse.Namespace( + spacers=["None"], + sample_name="single_peptide_no_edges", + ) + + with self.assertRaises(Exception) as context: + run.find_optimal_path( + graph, + distance_matrix, + seq_dict, + output_dir, + junctions_file, + args, + ) + + self.assertIn("Invalid graph passed to find_optimal_path", str(context.exception)) + def test_prevent_clipping_best_peptide(self): output_dir = tempfile.TemporaryDirectory() input_file = os.path.join(self.test_data_dir, 'Test.vector.prevent_clipping_best_peptide.input.fa')