Skip to content

Commit

Permalink
parse query on Select construction
Browse files Browse the repository at this point in the history
  • Loading branch information
lmiq committed Nov 22, 2024
1 parent 4fccee3 commit 532cda6
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/select.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,34 @@ julia> filter(Select("name CA and residue 1"), atoms)
```
"""
struct Select <: Function
sel::String
struct Select{Q} <: Function
query_string::String
query::Q
end
(s::Select)(at) = apply_query(parse_query(s.sel), at)
function Select(query_string::AbstractString)
query = parse_query(query_string)
return Select(query_string, query)
end
(s::Select)(at) = apply_query(s.query, at)
Base.show(io::IO, ::MIME"text/plain", s::Select) = print(io, """Select("$(s.query_string)")""")

macro sel_str(str)
Select(str)
end
# Function that returns true for all atoms: the default selection
all(atoms) = true

@testitem "Select and sel_str show" begin
using PDBTools
atoms = read_pdb(PDBTools.TESTPDB, "protein")
sel = Select("name CA and residue 1")
buff = IOBuffer()
show(buff, MIME"text/plain"(), sel)
@test String(take!(buff)) == """Select("name CA and residue 1")"""
show(buff, MIME"text/plain"(), sel"name CA and residue 1")
@test String(take!(buff)) == """Select("name CA and residue 1")"""
end

"""
select(atoms::AbstractVector{<:Atom}, by::String)
Expand Down

0 comments on commit 532cda6

Please sign in to comment.