Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
lmiq authored Feb 12, 2025
2 parents 7aed458 + a2e3fa0 commit 37ecff7
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# BioStructures.jl release notes

## v4.3.0 - Nov 2024

* Selection strings are made much faster.

## v4.2.1 - Oct 2024

* Change compatibility bounds for new MetaGraphs.jl release.
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "BioStructures"
uuid = "de9282ab-8554-53be-b2d6-f6c222edabfc"
authors = ["Joe G Greener <[email protected]>"]
version = "4.2.1"
version = "4.3.0"

[deps]
BioGenerics = "47718e42-2ac5-11e9-14af-e5595289c2ea"
Expand Down
16 changes: 12 additions & 4 deletions src/select.jl
Original file line number Diff line number Diff line change
Expand Up @@ -436,10 +436,19 @@ allselector(el) = true

# Acts as a function when used within typical julia filtering functions
# by converting a string selection into a query call
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)")""")

#
# Parse selection string allowing interpolation in sel macro:
Expand Down Expand Up @@ -467,7 +476,6 @@ macro sel_str(s)
return esc(ex)
end


const operators = (
"=" => (x, y) -> isequal(x, y),
"<" => (x, y) -> isless(x, y),
Expand Down
11 changes: 8 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -942,9 +942,14 @@ end
@test length(collectmodels(struc, sel"model 1")) == 1
@test length(collectmodels(struc, sel"model 2")) == 0

@test_throws ArgumentError collectatoms(struc, sel"abc") # Invalid selection syntax
@test_throws ArgumentError collectatoms(struc, sel"index = A") # Invalid value type
@test_throws ArgumentError collectatoms(struc, sel"resnum C")
@test_throws ArgumentError collectatoms(struc, BioStructures.Select("abc")) # Invalid selection syntax
@test_throws ArgumentError collectatoms(struc, BioStructures.Select("index = A")) # Invalid value type
@test_throws ArgumentError collectatoms(struc, BioStructures.Select("resnum C"))

# Test show method for @sel_str
buff = IOBuffer()
show(buff, MIME"text/plain"(), sel"name CA and resnum 1")
@test String(take!(buff)) == """Select("name CA and resnum 1")"""
end

@testset "PDB reading" begin
Expand Down

0 comments on commit 37ecff7

Please sign in to comment.