Skip to content

Commit

Permalink
Merge pull request #53 from m3g/rc_better_support_for_non_standard_re…
Browse files Browse the repository at this point in the history
…sidues

better support for non-protein residues in ResidueContribution plots
  • Loading branch information
lmiq authored Nov 28, 2024
2 parents 6616813 + 87699a8 commit 851fe80
Show file tree
Hide file tree
Showing 4 changed files with 96,013 additions and 3 deletions.
14 changes: 12 additions & 2 deletions ext/Plotting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,23 @@ function Plots.contourf(
tick_range = 1:step:length(rc.xticks[1])
tick_marks = rc.xticks[1][tick_range]
tick_labels = rc.xticks[2][tick_range]
tick_resnums = rc.resnums[tick_range]
warned = false
xticks = if oneletter
for i in eachindex(tick_labels)
resnum = "$(rc.resnums[i])"
resnum = "$(tick_resnums[i])"
# The following will allow custom residue names to be identified
# in the tick label string, by removing the residue number
residue_name = string(strip(tick_labels[i][1:(first(findlast(resnum, tick_labels[i]))-1)]))
tick_labels[i] = PDBTools.oneletter(residue_name) * resnum
one_letter_code = PDBTools.oneletter(residue_name)
if one_letter_code == "X"
if !warned
@warn "One-letter code for residue(s) not found. Using full residue name." _file=nothing _line=nothing
warned = true
end
one_letter_code = residue_name
end
tick_labels[i] = one_letter_code * resnum
end
(tick_marks, tick_labels)
else
Expand Down
7 changes: 6 additions & 1 deletion src/tools/residue_contributions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,12 @@ function Base.show(io::IO, ::MIME"text/plain", rc::ResidueContributions)
end
print(io, " ")
for i in 1:rstride*8:length(rc.xticks[1])
tick = "$(PDBTools.oneletter(rc.xticks[2][i][1:3]))$(rc.resnums[i])"
_tick = rc.xticks[2][i]
_resname = PDBTools.oneletter(_tick[1:min(lastindex(_tick),3)])
if _resname == "X"
_resname = _tick[1:1]
end
tick = "$_resname$(rc.resnums[i])"
tick *= repeat(" ", 8 - length(tick))
print(io, tick)
end
Expand Down
Loading

0 comments on commit 851fe80

Please sign in to comment.