diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 467eb039..2410cc51 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -15,7 +15,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macos-latest, windows-latest] - python-version: [3.6, 3.7, 3.8, 3.9] + python-version: [3.7, 3.8, 3.9] steps: - uses: actions/checkout@v1 diff --git a/conkit/command_line/conkit_plot.py b/conkit/command_line/conkit_plot.py index 40bdc951..a2d3d1e2 100644 --- a/conkit/command_line/conkit_plot.py +++ b/conkit/command_line/conkit_plot.py @@ -516,10 +516,12 @@ def altloc_remove(cmap): con.sort("raw_score", reverse=True, inplace=True) if args.pdbchain: - pdb = conkit.io.read(args.pdbfile, "pdb")[args.pdbchain] + pdb = conkit.io.read(args.pdbfile, args.pdbformat)[args.pdbchain] else: - pdb = conkit.io.read(args.pdbfile, "pdb")[0] + pdb = conkit.io.read(args.pdbfile, args.pdbformat)[0] + pdb.sequence = seq + pdb.set_sequence_register() pdb = pdb.as_contactmap() con_matched = con.match(pdb, renumber=True, remove_unmatched=True) diff --git a/conkit/command_line/conkit_precision.py b/conkit/command_line/conkit_precision.py index c27b5484..cfa580d0 100644 --- a/conkit/command_line/conkit_precision.py +++ b/conkit/command_line/conkit_precision.py @@ -79,9 +79,14 @@ def main(): pdb = conkit.io.read(args.pdbfile, args.pdbformat)[args.pdbchain] else: pdb = conkit.io.read(args.pdbfile, args.pdbformat)[0] + seq = conkit.io.read(args.seqfile, args.seqformat)[0] - con = conkit.io.read(args.confile, args.conformat)[0] + pdb.sequence = seq + pdb.set_sequence_register() + pdb = pdb.as_contactmap() + + con = conkit.io.read(args.confile, args.conformat)[0] con.sequence = seq con.set_sequence_register() diff --git a/conkit/command_line/conkit_predict.py b/conkit/command_line/conkit_predict.py index 39055eb6..1a8bd100 100644 --- a/conkit/command_line/conkit_predict.py +++ b/conkit/command_line/conkit_predict.py @@ -177,7 +177,7 @@ def main(argl=None): conkit.io.convert(a3m_fname, "a3m", jon_fname, "jones") else: - raise RuntimeError("Should never get to here") + raise RuntimeError("Error reading cli arguments - please report this bug") # CCMpred requires alignments to be in the *jones* format - i.e. the format created # and used by David Jones in PSICOV diff --git a/conkit/core/contactmap.py b/conkit/core/contactmap.py index a83f62cb..0292ca4c 100644 --- a/conkit/core/contactmap.py +++ b/conkit/core/contactmap.py @@ -530,6 +530,8 @@ def set_sequence_register(self, altloc=False): if self.sequence is None: raise ValueError("No sequence defined") + seq_len = len(self.sequence) + for c in self: if altloc: res1_index = c.res1_altseq @@ -537,8 +539,11 @@ def set_sequence_register(self, altloc=False): else: res1_index = c.res1_seq res2_index = c.res2_seq - c.res1 = self.sequence.seq[res1_index - 1] - c.res2 = self.sequence.seq[res2_index - 1] + if res1_index <= seq_len and res2_index <= seq_len: + c.res1 = self.sequence.seq[res1_index - 1] + c.res2 = self.sequence.seq[res2_index - 1] + else: + raise ValueError('Contact {} is out of sequence bounds'.format(c.id)) @deprecate("0.11", msg="Use get_jaccard_index instead.") def calculate_jaccard_index(self, other): @@ -826,7 +831,7 @@ def match( else: contact_map1[_id].status = ContactMatchState.false_positive else: - raise RuntimeError("Error matching two contact maps - this should never happen") + raise RuntimeError("Error matching two contact maps - please report this bug") # ================================================================ # 3. Add false negatives @@ -1159,6 +1164,6 @@ def _renumber(contact_map, self_keymap, other_keymap): contact.res2_seq = other_residue.res_seq contact.res2_chain = other_residue.res_chain else: - raise ValueError("Should never get here") + raise ValueError("Error renumbering contact map - please report this bug") return contact_map diff --git a/conkit/core/tests/test_contactmap.py b/conkit/core/tests/test_contactmap.py index 49c3a5f0..ad93c470 100644 --- a/conkit/core/tests/test_contactmap.py +++ b/conkit/core/tests/test_contactmap.py @@ -432,6 +432,22 @@ def test_set_sequence_register_2(self): [("A", "E"), ("B", "F"), ("A", "D"), ("C", "F"), ("B", "E")], [(c.res1, c.res2) for c in contact_map1] ) + def test_set_sequence_register_3(self): + contact_map1 = ContactMap("1") + for comb in [(1, 5, 1.0), (2, 6, 1.0), (1, 4, 1.0), (3, 6, 1.0), (2, 5, 1.0)]: + contact_map1.add(Contact(*comb)) + contact_map1.sequence = Sequence("foo", "ABCDE") + with self.assertRaises(ValueError): + contact_map1.set_sequence_register() + + def test_set_sequence_register_4(self): + contact_map1 = ContactMap("1") + for comb in [(1, 5, 1.0), (6, 3, 1.0), (1, 4, 1.0), (3, 2, 1.0), (2, 5, 1.0)]: + contact_map1.add(Contact(*comb)) + contact_map1.sequence = Sequence("foo", "ABCDE") + with self.assertRaises(ValueError): + contact_map1.set_sequence_register() + def test_match_1(self): contact_map1 = ContactMap("foo") for params in [(1, 5, 1.0), (1, 6, 1.0), (2, 7, 1.0), (3, 5, 1.0), (2, 8, 1.0)]: