-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add AnnotatedProteinChain, cache PDB downloads, include disordered at…
…oms/residues
- Loading branch information
1 parent
738d3e6
commit 51c3c32
Showing
13 changed files
with
266 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 <[email protected]> and contributors"] | ||
version = "0.1.1" | ||
version = "0.2.0" | ||
|
||
[deps] | ||
AssigningSecondaryStructure = "8ed43e74-60fb-4e11-99b9-91deed37aef7" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
@dynamic mutable struct AnnotatedProteinChain{T} <: AbstractProteinChain{T} | ||
id::String | ||
sequence::String | ||
backbone::Array{T,3} | ||
numbering::Vector{Int64} | ||
atoms::Vector{Vector{Atom{T}}} | ||
indexable_properties::Vector{Symbol} | ||
|
||
function AnnotatedProteinChain( | ||
id::AbstractString, sequence::AbstractString, backbone::AbstractArray{T,3}, | ||
numbering::AbstractVector{<:Integer}, atoms::Vector{Vector{Atom{T}}}, | ||
indexable_properties=Symbol[]; kwargs... | ||
) where T | ||
@assert length(sequence) == size(backbone, 3) == length(atoms) == length(numbering) | ||
AnnotatedProteinChain{T}(id, sequence, backbone, atoms, numbering, indexable_properties; kwargs...) | ||
end | ||
end | ||
|
||
ProteinChain(chain::AbstractProteinChain) = ProteinChain(chain.id, chain.sequence, chain.backbone, chain.numbering, chain.atoms) | ||
AnnotatedProteinChain(chain::AbstractProteinChain) = AnnotatedProteinChain(chain.id, chain.sequence, chain.backbone, chain.numbering, chain.atoms) | ||
|
||
function Base.getindex(chain::AnnotatedProteinChain, i::AbstractVector{<:Integer}) | ||
properties = Dict{Symbol,Any}() | ||
for name in getproperties(chain; fields=false) | ||
value = getproperty(chain, name) | ||
properties[name] = name in chain.indexable_properties ? collect(selectdim(value, ndims(value), i)) : value | ||
end | ||
return annotate(ProteinChain(chain)[i]; properties...) | ||
end | ||
|
||
function annotate_indexable!(chain::AnnotatedProteinChain; annotations...) | ||
for (name, value) in annotations | ||
@assert value isa AbstractArray | ||
@assert size(value)[end] == length(chain) | ||
push!(chain.indexable_properties, name) | ||
setproperty!(chain, name, value) | ||
end | ||
return chain | ||
end | ||
|
||
annotate_indexable(chain::AnnotatedProteinChain; annotations...) = annotate_indexable!(deepcopy(chain); annotations...) | ||
annotate_indexable(chain::ProteinChain; annotations...) = annotate_indexable!(AnnotatedProteinChain(chain); annotations...) | ||
|
||
function annotate!(chain::AnnotatedProteinChain; annotations...) | ||
for (name, value) in annotations | ||
setproperty!(chain, name, value) | ||
end | ||
return chain | ||
end | ||
|
||
annotate(chain::AnnotatedProteinChain; annotations...) = annotate(deepcopy(chain); annotations...) | ||
annotate(chain::ProteinChain; annotations...) = annotate!(AnnotatedProteinChain(chain); annotations...) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using Base.Filesystem | ||
|
||
const MAX_CACHE_ENTRIES = Ref{Int}(4) | ||
const CACHE_DIR = Ref{Union{String, Nothing}}(nothing) | ||
|
||
function initialize_cache_dir() | ||
if CACHE_DIR[] === nothing | ||
CACHE_DIR[] = mktempdir(prefix="pdb_cache_") | ||
atexit(() -> rm(CACHE_DIR[], recursive=true)) | ||
end | ||
end | ||
|
||
function manage_cache() | ||
entries = readdir(CACHE_DIR[]) | ||
while length(entries) > MAX_CACHE_ENTRIES[] | ||
oldest_entry = entries[argmin([mtime(joinpath(CACHE_DIR[], entry)) for entry in entries])] | ||
rm(joinpath(CACHE_DIR[], oldest_entry)) | ||
entries = readdir(CACHE_DIR[]) | ||
end | ||
end | ||
|
||
function pdbentry(pdbid::AbstractString; format=BioStructures.MMCIFFormat, kwargs...) | ||
initialize_cache_dir() | ||
path = BioStructures.downloadpdb(pdbid; dir=CACHE_DIR[], format=format, kwargs...) | ||
manage_cache() | ||
return read(path, ProteinStructure, format) | ||
end | ||
|
||
macro pdb_str(pdbid::AbstractString) | ||
:(pdbentry($(esc(pdbid)))) | ||
end | ||
|
||
macro pdb_str(pdbid::AbstractString, chain::AbstractString) | ||
:(pdbentry($(esc(pdbid)))[$chain]) | ||
end | ||
|
||
macro pdb_str(pdbid::AbstractString, ba_number::Integer) | ||
:(pdbentry($(esc(pdbid)), ba_number=$ba_number)) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
51c3c32
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
Release notes:
pdbentry
function or@pdb_str
macro.51c3c32
There was a problem hiding this comment.
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/115010
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: