Skip to content

Commit 149d6fb

Browse files
Merge pull request #92 from rigdenlab/conkit_plot-patch
Fix conkit-plot cmap
2 parents 9ee7f76 + 8927c6e commit 149d6fb

File tree

7 files changed

+81
-9
lines changed

7 files changed

+81
-9
lines changed

conkit/command_line/conkit_plot.py

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848

4949
import conkit.command_line
5050
import conkit.io
51+
from conkit.io import DISTANCE_FILE_PARSERS
5152
import conkit.plot
5253
import conkit.plot.tools
5354

@@ -325,6 +326,8 @@ def main(argv=None):
325326

326327
seq = conkit.io.read(args.seqfile, args.seqformat)[0]
327328
con = conkit.io.read(args.confile, args.conformat)[0]
329+
if args.conformat in DISTANCE_FILE_PARSERS.keys():
330+
con = con.as_contactmap()
328331

329332
con.sequence = seq
330333
con.set_sequence_register()
@@ -335,6 +338,8 @@ def main(argv=None):
335338

336339
if args.otherfile:
337340
other = conkit.io.read(args.otherfile, args.otherformat)[0]
341+
if args.otherformat in DISTANCE_FILE_PARSERS.keys():
342+
other = other.as_contactmap()
338343
other.sequence = seq
339344
other.set_sequence_register()
340345
other.remove_neighbors(min_distance=args.dtn, inplace=True)
@@ -344,15 +349,18 @@ def main(argv=None):
344349
other_sliced = None
345350

346351
if args.reffile:
352+
if args.refformat not in ["pdb", "mmcif"]:
353+
msg = "The provided format {0} is not yet implemented for the reference flag".format(args.refformat)
354+
raise RuntimeError(msg)
355+
347356
if args.refid:
348357
reference = conkit.io.read(args.reffile, args.refformat)[args.refid]
349358
else:
350359
reference = conkit.io.read(args.reffile, args.refformat)[0]
351360

352-
if args.refformat not in ["pdb", "mmcif"]:
353-
msg = "The provided format {0} is not yet implemented for the reference flag".format(args.refformat)
354-
raise RuntimeError(msg)
355-
361+
reference = reference.as_contactmap()
362+
reference.sequence = seq
363+
reference.set_sequence_register()
356364
con_matched = con_sliced.match(reference, match_other=True, renumber=True, remove_unmatched=True)
357365
if other_sliced:
358366
other_matched = other_sliced.match(reference, renumber=True, remove_unmatched=True)
@@ -393,6 +401,8 @@ def altloc_remove(cmap):
393401

394402
seq = conkit.io.read(args.seqfile, args.seqformat)[0]
395403
con = conkit.io.read(args.confile, args.conformat)[0]
404+
if args.conformat in DISTANCE_FILE_PARSERS:
405+
con = con.as_contactmap()
396406

397407
con.sequence = seq
398408
con.set_sequence_register()
@@ -407,9 +417,13 @@ def altloc_remove(cmap):
407417
elif args.which == "covariance_validation":
408418
if args.pdbformat != 'pdb':
409419
raise ValueError('Model file format can only be PDB')
420+
elif args.distformat not in DISTANCE_FILE_PARSERS.keys():
421+
raise ValueError('Prediction file format can only be a distance file')
422+
410423
sequence = conkit.io.read(args.seqfile, args.seqformat)[0]
411424
if len(sequence) < 5:
412425
raise ValueError('Cannot validate a model with less than 5 residues')
426+
413427
prediction = conkit.io.read(args.distfile, args.distformat)[0]
414428
model = conkit.io.read(args.pdbfile, args.pdbformat)[0]
415429
p = PDBParser()
@@ -420,12 +434,17 @@ def altloc_remove(cmap):
420434
figure_aspect_ratio = None
421435

422436
elif args.which == "distogram_heatmap":
437+
if args.distformat not in DISTANCE_FILE_PARSERS.keys():
438+
raise ValueError('Prediction file format can only be a distance file')
439+
423440
sequence = conkit.io.read(args.seqfile, args.seqformat)[0]
424441
distogram = conkit.io.read(args.distfile, args.distformat)[0]
425442
distogram.sequence = sequence
426443
distogram.set_sequence_register()
427444

428445
if args.otherfile:
446+
if args.otherformat not in DISTANCE_FILE_PARSERS.keys():
447+
raise ValueError('Other prediction file format can only be a distance file')
429448
other = conkit.io.read(args.otherfile, args.otherformat)[0]
430449
other.sequence = sequence
431450
other.set_sequence_register()
@@ -439,12 +458,16 @@ def altloc_remove(cmap):
439458

440459
seq = conkit.io.read(args.seqfile, args.seqformat)[0]
441460
con = conkit.io.read(args.confile, args.conformat)[0]
461+
if args.conformat in DISTANCE_FILE_PARSERS:
462+
con = con.as_contactmap()
442463

443464
con.sequence = seq
444465
con.set_sequence_register()
445466

446467
if args.otherfile:
447468
other = conkit.io.read(args.otherfile, args.otherformat)[0]
469+
if args.otherformat in DISTANCE_FILE_PARSERS:
470+
other = other.as_contactmap()
448471
other.sequence = seq
449472
other.set_sequence_register()
450473
else:
@@ -460,6 +483,8 @@ def altloc_remove(cmap):
460483

461484
seq = conkit.io.read(args.seqfile, args.seqformat)[0]
462485
con = conkit.io.read(args.confile, args.conformat)[0]
486+
if args.conformat in DISTANCE_FILE_PARSERS:
487+
con = con.as_contactmap()
463488

464489
con.sequence = seq
465490
con.set_sequence_register()
@@ -482,6 +507,8 @@ def altloc_remove(cmap):
482507

483508
seq = conkit.io.read(args.seqfile, args.seqformat)[0]
484509
con = conkit.io.read(args.confile, args.conformat)[0]
510+
if args.conformat in DISTANCE_FILE_PARSERS:
511+
con = con.as_contactmap()
485512

486513
con.sequence = seq
487514
con.set_sequence_register()
@@ -492,6 +519,8 @@ def altloc_remove(cmap):
492519
pdb = conkit.io.read(args.pdbfile, "pdb")[args.pdbchain]
493520
else:
494521
pdb = conkit.io.read(args.pdbfile, "pdb")[0]
522+
523+
pdb = pdb.as_contactmap()
495524
con_matched = con.match(pdb, renumber=True, remove_unmatched=True)
496525

497526
figure = conkit.plot.PrecisionEvaluationFigure(

conkit/core/distance.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,23 @@ class Distance(Contact):
6262
6363
"""
6464

65-
__slots__ = ["distance_bins", "distance_scores"]
65+
__slots__ = [
66+
"_distance_bound",
67+
"raw_score",
68+
"_res1",
69+
"_res2",
70+
"res1_chain",
71+
"res2_chain",
72+
"_res1_seq",
73+
"_res2_seq",
74+
"_res1_altseq",
75+
"_res2_altseq",
76+
"scalar_score",
77+
"_status",
78+
"weight",
79+
"distance_bins",
80+
"distance_scores"
81+
]
6682

6783
def __init__(self, res1_seq, res2_seq, distance_scores, distance_bins, raw_score=None, distance_bound=(0, 8)):
6884
"""Initialize a generic distance residue pair
@@ -202,6 +218,29 @@ def _reshape_bins(self, new_bins):
202218
self.distance_bins = tuple(new_bins)
203219
self.distance_scores = tuple(new_distance_scores)
204220

221+
def as_contact(self, distance_cutoff):
222+
"""Create a :obj:`~conkit.core.contact.Contact` instance with the information in this
223+
:obj:`~conkit.core.distance.Distance` instance.
224+
225+
Parameters
226+
----------
227+
distance_cutoff : int, float
228+
The distance cutoff used to consider a residue pair within contact of each other
229+
230+
Returns
231+
-------
232+
:obj:`~conkit.core.contact.Contact`
233+
A contact with the information present in this distance instance.
234+
"""
235+
if self.predicted_distance > distance_cutoff:
236+
contact = Contact(self.res1_seq, self.res2_seq, 0, distance_bound=(0, distance_cutoff))
237+
else:
238+
contact = Contact(self.res1_seq, self.res2_seq, self.raw_score, distance_bound=(0, distance_cutoff))
239+
for attr in self.__slots__:
240+
if hasattr(contact, attr):
241+
setattr(contact, attr, getattr(self, attr))
242+
return contact
243+
205244
@staticmethod
206245
def _assert_valid_bins(distance_bins):
207246
"""Determine whether a set of distance bins is valid. Valid distance bins must follow these rules:

conkit/core/distancefile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class DistanceFile(ContactFile):
6565
6666
"""
6767

68-
__slots__ = ["_original_file_format"]
68+
__slots__ = ["author", "target", "_method", "_remark", "_original_file_format"]
6969

7070
def __init__(self, id):
7171
"""Initialise a new distance file"""

conkit/core/distogram.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class Distogram(ContactMap):
6464
6565
"""
6666

67-
__slots__ = ["_original_file_format"]
67+
__slots__ = ["_original_file_format", "_sequence"]
6868

6969
def __init__(self, id):
7070
self._original_file_format = None
@@ -228,8 +228,10 @@ def as_contactmap(self, distance_cutoff=8):
228228
contactmap = ContactMap("map_1")
229229
for dist in self:
230230
if dist.predicted_distance <= distance_cutoff:
231-
contact = Contact(dist.res1_seq, dist.res2_seq, dist.raw_score, distance_bound=(0, distance_cutoff))
231+
contact = dist.as_contact(distance_cutoff)
232232
contactmap.add(contact)
233+
if self.sequence is not None:
234+
contactmap.sequence = self.sequence._inplace(False)
233235

234236
return contactmap
235237

conkit/plot/contactmap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,4 +286,4 @@ def color_selector(contact):
286286
else:
287287
return ColorDefinitions.GENERAL
288288

289-
return [color_selector(contact) for contact in h]
289+
return [color_selector(contact) for contact in h if Gap.IDENTIFIER not in (contact.res1_seq, contact.res2_seq)]

docs/examples/code/plot_map_reference.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
# Now we need to compare it to our reference structure
4040
pdb_file = "toxd/toxd.pdb"
4141
pdb = conkit.io.read(pdb_file, "pdb").top
42+
pdb = pdb.as_contactmap()
4243
# The two keywords do the following:
4344
# - match_other : renumber the pdb to match gaps in target
4445
# - remove_unmatched : remove contacts absent from the pdb_file

docs/examples/rst/python_analyse_conpred.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ In ConKit, this functionality is provided via the :attr:`~conkit.core.contactmap
6565
.. code-block:: python
6666
6767
>>> pdb = conkit.io.read("toxd/toxd.pdb", "pdb").top_map
68+
>>> pdb = pdb.as_contactmap()
6869
>>> conpred.remove_neighbors(inplace=True)
6970
>>> conpred.sort("raw_score", reverse=True, inplace=True)
7071
>>> conpred.match(pdb, inplace=True)

0 commit comments

Comments
 (0)