Skip to content

Commit

Permalink
Missing residue handling adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonOresten committed Apr 5, 2024
1 parent de673e8 commit 1e9ec07
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/ribbon/render.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ function render!(
protein::AbstractVector{Protein.Chain};
colorscheme::ColorScheme = default_colorscheme,
color_vectors::AbstractVector{<:AbstractVector{<:RGB}} = [colorscheme[LinRange(0, 1, length(chain))] for chain in protein],
missing_residue_color = colorant"gray",
plots = nothing,
kwargs...
)
Expand All @@ -121,8 +122,9 @@ function render!(
# draw lines between start and ends of subchains
for (i, j) in zip(1:length(subchains)-1, 2:length(subchains))
startpoint, endpoint = subchains[i].backbone[end], subchains[j].backbone[begin]
xs, ys, zs = [LinRange(startpoint[i], endpoint[i], 16) for i in 1:3]
p = linesegments!(container, xs, ys, zs; linewidth=3, color=colorant"white", transparency=true)
n_segments = trunc(Int, norm(endpoint - startpoint) / 0.8)
xs, ys, zs = [LinRange(startpoint[i], endpoint[i], 2*n_segments) for i in 1:3]
p = linesegments!(container, xs, ys, zs; linewidth=2, color=missing_residue_color, transparency=true)
!isnothing(plots) && push!(plots, p)
end
end
Expand Down
7 changes: 4 additions & 3 deletions src/ribbon/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ function Base.getindex(chain::Protein.Chain, r::UnitRange{<:Integer})
end

# split a chain into subchains if there is a gap in the residue numbering
function split_by_resnum(chain::Protein.Chain)
split_indices = findall(diff(chain.resnums) .!= 1)
function split_by_resnum(chain::Protein.Chain, cn_distance_tolerance = 2)
resnum_splits = diff(chain.resnums) .!= 1
backbone_splits = Protein.carbonyl_nitrogen_distances(chain) .> cn_distance_tolerance
split_indices = findall(resnum_splits .| backbone_splits)
if isempty(split_indices)
return [chain]
end

ranges = UnitRange{Int}[]
start_idx = 0
for idx in split_indices
Expand Down

0 comments on commit 1e9ec07

Please sign in to comment.