Skip to content

Commit

Permalink
Robustness tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonOresten committed Aug 13, 2024
1 parent dd18fe0 commit bd998d2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ProtPlot"
uuid = "77b3afcc-388a-4e14-926d-b99c82d1a01f"
authors = ["Anton Oresten <anton.oresten42@gmail.com>"]
version = "0.4.5"
version = "0.4.6"

[deps]
AssigningSecondaryStructure = "8ed43e74-60fb-4e11-99b9-91deed37aef7"
Expand Down
5 changes: 3 additions & 2 deletions src/Ribbon/Ribbon.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@recipe(Ribbon, chains) do scene
Attributes(
keepers = nothing,
secondary_structures = nothing,
colors = nothing,
colormap = :jet,
Expand Down Expand Up @@ -28,14 +29,14 @@ include("render.jl")
# TODO: observe chains and re-render when they change
function Makie.plot!(ribbon::Ribbon{<:Tuple{<:AbstractVector{<:AbstractArray{T,3}}}}) where T<:Real
chain_backbones = convert.(Array{T,3}, collect(ribbon[1][]))
filter!(c -> size(c, 3) > 1, chain_backbones)
isnothing(ribbon.secondary_structures[]) && (ribbon.secondary_structures[] = _assign_secondary_structure(chain_backbones))
isnothing(ribbon.colors[]) && (ribbon.colors[] = [range(0, 1, size(chain_backbone, 3)) for chain_backbone in chain_backbones])
isnothing(ribbon.colors[]) && (ribbon.colors[] = [range(0, !isone(L), L) for L in size.(chain_backbones, 3)])
render!(ribbon, chain_backbones)
return ribbon
end

Makie.convert_arguments(::Type{<:Ribbon}, chain_backbone::AbstractArray{T,3}) where T<:Real = ([coords],)
Makie.convert_arguments(R::Type{<:Ribbon}) = Makie.convert_arguments(R, Array{Float64,3}(undef, 3, 3, 0))

import Backboner

Expand Down
7 changes: 4 additions & 3 deletions src/Ribbon/render.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ end
function render!(ribbon::Ribbon, chain_backbones::Vector{Array{T,3}}) where T<:Real
secondary_structures = ribbon.secondary_structures[]
colors = ribbon.colors[]
length(chain_backbones) == length(colors) || throw(ArgumentError("Chains and colors must have the same length"))
for (chain_backbone, secondary_structure, color) in zip(chain_backbones, secondary_structures, colors)
length(chain_backbones) == length(secondary_structures) || throw(ArgumentError("Chains and secondary structures vector must have the same length"))
length(chain_backbones) == length(colors) || throw(ArgumentError("Chains and colors vector must have the same length"))
keepers = findall(c -> size(c, 3) > 1, chain_backbones)
for (chain_backbone, secondary_structure, color) in zip(chain_backbones[keepers], secondary_structures[keepers], colors[keepers])
chain_length = size(chain_backbone, 3)
chain_length > 1 || throw(ArgumentError("Chain must have at least 2 residues"))
chain_length == length(secondary_structure) || throw(ArgumentError("coordinates and secondary structure size must match"))
chain_length == length(color) || throw(ArgumentError("Chain and color must have the same length"))

Expand Down

0 comments on commit bd998d2

Please sign in to comment.