Skip to content

Commit

Permalink
Add lazy delete! method
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonOresten committed Feb 17, 2025
1 parent 8ad654e commit 4f0fdc3
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ProteinChains"
uuid = "b8e8f2a5-48d3-44f1-ba0d-c71cb7726ff8"
authors = ["Anton Oresten <anton.oresten42@gmail.com> and contributors"]
version = "0.6.3"
version = "0.6.4"

[deps]
Backboner = "9ac9c2a2-1cfe-46d3-b3fd-6fa470ea56a7"
Expand Down
25 changes: 23 additions & 2 deletions examples/examples.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# # Examples

# ## Basic chain usage
# ## ProteinStructure and ProteinChain

using ProteinChains

Expand Down Expand Up @@ -79,9 +79,30 @@ size(frames.rotations)
#-
size(frames.translations)

# ## MMCIF utilities

# MMCIF files contain a lot of information that is not present in PDB files.
# The `mapmmcif` function can be used to map one MMCIF field to another.

mmcifdict = mmcifdict"3HFM";
#-
mapmmcif(mmcifdict, "_atom_site.auth_asym_id" => "_atom_site.label_entity_id")
#-
mapmmcif(mmcifdict, "_entity_src_gen.entity_id" => "_entity_src_gen.pdbx_gene_src_ncbi_taxonomy_id")
#-
chainid_to_taxonomyid = mapmmcif(mmcifdict,
"_atom_site.auth_asym_id" => "_atom_site.label_entity_id",
"_entity_src_gen.entity_id" => "_entity_src_gen.pdbx_gene_src_ncbi_taxonomy_id")
#-
structure = pdb"3HFM"
for chain in structure
chain.taxonomy_id = chainid_to_taxonomyid[chain.id]
println("Set taxonomy_id of chain $(chain.id) to $(chain.taxonomy_id)")
end

# ## ProteinStructureStore

# The `ProteinStructureStore <: AbstractDict{String, ProteinStructure}` type is a lazy wrapper for a disk-based storage of `ProteinStructure`s.
# The `ProteinStructureStore <: AbstractDict{String, ProteinStructure}` type is a lazy wrapper for a file-based storage of `ProteinStructure`s.

dir = mktempdir();
store = ProteinStructureStore(joinpath(dir, "structures.pss"));
Expand Down
4 changes: 4 additions & 0 deletions src/store/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ function readproperty(lazy::Lazy, ::Val{name}) where name
return f(value)
end

function deleteproperty(lazy::Lazy, ::Val{name}) where name
haskey(lazy.group, string(name)) && HDF5.delete_object(lazy.group, string(name))
end

function writeproperty(lazy::Lazy, ::Val{name}, property::AbstractProperty) where name
HDF5.attributes(lazy.group)[string(name)] = string(typeof(property))
write(lazy.group, string(name), unwrap(property))
Expand Down
16 changes: 12 additions & 4 deletions src/store/store.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ Base.getproperty(lazy::Lazy, property::Symbol) =
Base.setproperty!(lazy::Lazy, property::Symbol, value) =
property == :group ? setfield!(lazy, property, value) : writeproperty(lazy, Val(property), value)

Base.delete!(lazy::Lazy, property::Symbol) =
property == :group ? error("group is immutable") : deleteproperty(lazy, Val(property))

include("utils.jl")
include("io.jl")

Expand Down Expand Up @@ -174,11 +177,16 @@ Base.getindex(structure::Lazy{ProteinStructure{T}}, index::Integer) where T =

Base.length(chain::Lazy{<:ProteinChain}) = read(HDF5.attributes(chain.group)["n_residues"])

# v0.5 compat
function Base.getproperty(lazy::Lazy{T}, property::Symbol) where T<:Union{ProteinStructure,ProteinChain}
if property == :group || haskey(lazy.group, string(property))
property == :group && return getfield(lazy, :group)
if haskey(lazy.group, "properties")
if property in fieldnames(T)
return invoke(getproperty, Tuple{Lazy,Symbol}, lazy, property)
else
return getproperty(readproperty(lazy, Val(:properties)), property)
end
else
return invoke(getproperty, Tuple{Lazy,Symbol}, lazy, property)
elseif haskey(lazy.group, "properties")
# v0.5 compat
return getproperty(readproperty(lazy, Val(:properties)), property)
end
end

2 comments on commit 4f0fdc3

@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
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/125295

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

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.6.4 -m "<description of version>" 4f0fdc37f5e4bfa80ce1004241bb9d3338e162a6
git push origin v0.6.4

Please sign in to comment.