Skip to content

Commit

Permalink
addproperty -> addproperties
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonOresten committed Oct 10, 2024
1 parent 729d13e commit 5693494
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ julia> propertynames(chain)
(:id, :atoms, :sequence, :numbering)
```
To store additional properties, `addproperty` can be used to attach persistent chain-level properties or indexable residue-level properties:
To store additional properties, `addproperties` can be used to attach persistent chain-level properties or indexable residue-level properties:
```julia
julia> chain = structure["A"]
256-residue ProteinChain{Float64, @NamedTuple{}} (A)

julia> new_chain = addproperty(chain; taxid=PersistentProperty(83332))
julia> new_chain = addproperties(chain; taxid=PersistentProperty(83332))
256-residue ProteinChain{Float64, @NamedTuple{taxid::PersistentProperty{Int64}}} (A)

julia> new_chain = addproperty(new_chain; some_residue_property=IndexableProperty(rand(3,256))) # last dimension gets indexed
julia> new_chain = addproperties(new_chain; some_residue_property=IndexableProperty(rand(3,256))) # last dimension gets indexed
256-residue ProteinChain{Float64, @NamedTuple{taxid::PersistentProperty{Int64}, some_residue_property::IndexableProperty{Matrix{Float64}}}} (A)

julia> new_chain[1:100].some_residue_property
Expand Down
2 changes: 1 addition & 1 deletion src/ProteinChains.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export Atom

include("properties.jl")
export PersistentProperty, IndexableProperty
export addproperty
export addproperties
@compat public (AbstractProperty, NamedProperties)

include("chain.jl")
Expand Down
14 changes: 7 additions & 7 deletions src/chain.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
ProteinChain{T<:Real,Ps<:NamedProperties}
Represents a protein chain with a basic set of fields from which some other properties might be derived.
The [`addproperty`](@ref) function can be used to instantiate new chains with additional properties.
The [`addproperties`](@ref) function can be used to instantiate new chains with additional properties.
## Fields
- `id::String`: Identifier for the protein chain.
Expand All @@ -11,7 +11,7 @@ The [`addproperty`](@ref) function can be used to instantiate new chains with ad
- `numbering::Vector{Int32}`: Residue numbering.
- `properties::Ps`: Named properties associated with the chain.
See also [`addproperty`](@ref), [`PersistentProperty`](@ref), [`IndexableProperty`](@ref).
See also [`addproperties`](@ref), [`PersistentProperty`](@ref), [`IndexableProperty`](@ref).
```
"""
struct ProteinChain{T<:Real,Ps<:NamedProperties}
Expand Down Expand Up @@ -55,7 +55,7 @@ function Base.getindex(chain::ProteinChain, i::AbstractVector)
end

"""
addproperty(chain::ProteinChain; properties...)
addproperties(chain::ProteinChain; properties...)
Creates a new `ProteinChain` instance with the added properties.
Indexing behavior of property values can be specified by wrapping
Expand All @@ -65,7 +65,7 @@ Values get wrapped by `PersistentProperty` by default.
See also [`PersistentProperty`](@ref), [`IndexableProperty`](@ref)
"""
function addproperty(chain::ProteinChain; properties...)
function addproperties(chain::ProteinChain; properties...)
properties = map(p -> p isa AbstractProperty ? p : PersistentProperty(p), NamedTuple(properties))
return ProteinChain(chain.id, chain.atoms, chain.sequence, chain.numbering, merge(chain.properties, properties))
end
Expand Down Expand Up @@ -133,12 +133,12 @@ end
using AssigningSecondaryStructure: assign_secondary_structure

"""
addproperty(chain::ProteinChain, names::Symbol...)
addproperty(chain::ProteinStructure, names::Symbol...)
addproperties(chain::ProteinChain, names::Symbol...)
addproperties(chain::ProteinStructure, names::Symbol...)
Add predefined properties to a chain or chains of a structure.
"""
addproperty(chain::ProteinChain, names::Symbol...) = addproperty(chain; NamedTuple{names}(calculate_property(chain, name) for name in names)...)
addproperties(chain::ProteinChain, names::Symbol...) = addproperties(chain; NamedTuple{names}(calculate_property(chain, name) for name in names)...)

calculate_property(x, name::Symbol, args...) = calculate_property(x, Val(name), args...)

Expand Down
6 changes: 3 additions & 3 deletions src/properties.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Base.getindex(p::AbstractProperty) = p.value
A property of arbitrary type that persists after residue indexing of a chain.
```jldoctest
julia> chain = addproperty(pdb"1ASS"A; x=PersistentProperty(1));
julia> chain = addproperties(pdb"1ASS"A; x=PersistentProperty(1));
julia> chain.x == chain[1:10].x
true
Expand All @@ -31,7 +31,7 @@ residue indexing of the chain being propagated to the last dimension of the arra
```jldoctest
julia> chain = pdb"1ASS"A;
julia> chain = addproperty(pdb"1ASS"A; y=IndexableProperty(rand(2,152)));
julia> chain = addproperties(pdb"1ASS"A; y=IndexableProperty(rand(2,152)));
julia> chain.y == chain[1:10].y
false
Expand All @@ -48,4 +48,4 @@ Base.getindex(p::IndexableProperty, i::AbstractVector) = selectdim(p.value, ndim

const NamedProperties{names} = NamedTuple{names,<:Tuple{Vararg{AbstractProperty}}}

function addproperty end
function addproperties end
4 changes: 2 additions & 2 deletions src/structure.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ function map_atoms!(f::Function, structure::ProteinStructure, args...)
return structure
end

addproperty(structure::ProteinStructure, names::Symbol...) =
ProteinStructure(structure.name, structure.atoms, addproperty.(structure.chains, names...))
addproperties(structure::ProteinStructure, names::Symbol...) =
ProteinStructure(structure.name, structure.atoms, addproperties.(structure.chains, names...))
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ using Test
@testset "store" begin
mktempdir() do dir
filename = joinpath(dir, "store.h5")
structures = [addproperty(pdb"1EYE", :backbone), addproperty(pdb"3HFM", :backbone, :bond_lengths)]
structures = [addproperties(pdb"1EYE", :backbone), addproperties(pdb"3HFM", :backbone, :bond_lengths)]
ProteinChains.serialize(filename, structures)
structures_copy = ProteinChains.deserialize(filename)
@test structures == structures_copy
Expand Down

2 comments on commit 5693494

@AntonOresten
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register

Release notes:

  • Remove dynamic AnnotatedProteinChain type in favor of the immutable ProteinChain type, with properties now bound to the type with a type parameter.
  • Add PersistentProperty and IndexableProperty wrappers for properties of ProteinChains, defining indexing behavior.
  • Add addproperties function for adding properties to chains.
  • Add public (but not exported) serialize and deserialize functions for writing/reading vectors of ProteinStructures to HDF5 files.
  • Add ProteinStructureStore type that acts as a dictionary to bring HDF5-serialized structures into memory and vice versa.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/117009

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.3.0 -m "<description of version>" 5693494b13d629e3d7a79dab34ed4999e167432d
git push origin v0.3.0

Please sign in to comment.