Skip to content

Commit

Permalink
upgrade to Julia v0.7/1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
alyst authored and maximsch2 committed Sep 12, 2018
1 parent e5afbeb commit 4c84576
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 28 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
language: julia
julia:
- 0.6
- 0.7
- 1.0
- nightly
notifications:
email: false
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1 +1 @@
julia 0.6
julia 0.7
4 changes: 2 additions & 2 deletions src/OBOParse.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
__precompile__()

module OBOParse

export
Expand All @@ -14,6 +12,8 @@ export
parents, children,
descendants, ancestors, relationship

using Printf: @printf, @sprintf

include("term.jl")
include("typedef.jl")
include("parser.jl")
Expand Down
14 changes: 7 additions & 7 deletions src/ontology.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,21 @@ Base.length(ontology::Ontology) = length(ontology.terms)
parents(ontology::Ontology, term::Term, rel::Symbol = :is_a) = ontology[relationship(term, rel)]
children(ontology::Ontology, term::Term, rel::Symbol = :is_a) = ontology[rev_relationship(term, rel)]

const VecOrTuple{T} = Union{Vector{T}, Tuple{Vararg{T}}}
const VecOrTuple{T} = Union{Vector{T}, Tuple{Vararg{T}}} where T

# return the set of all nodes of the ontology DAG that could be visited from `term`
# node when traveling along `rels` edges using `rev` direction
function transitive_closure{T}(ontology::Ontology, term::Term,
rels::VecOrTuple{Symbol},
rev::Type{Val{T}} = Val{false})
function transitive_closure(ontology::Ontology, term::Term,
rels::VecOrTuple{Symbol},
rev::Bool = false)
# TODO: check if transitive & non-cyclical before doing so?
res = Set{TermId}()
frontier_ids = Set{TermId}((term.id,))
while true
new_ids = Set{TermId}()
for f_id in frontier_ids, rel in rels
f_term = ontology[f_id]
f_rel_ids = T ? rev_relationship(f_term, rel) : relationship(f_term, rel)
f_rel_ids = rev ? rev_relationship(f_term, rel) : relationship(f_term, rel)
union!(new_ids, f_rel_ids)
end
frontier_ids = setdiff!(new_ids, res)
Expand All @@ -65,9 +65,9 @@ function transitive_closure{T}(ontology::Ontology, term::Term,
return res
end

descendants(ontology::Ontology, term::Term, rels::VecOrTuple{Symbol}) = ontology[transitive_closure(ontology, term, rels, Val{true})]
descendants(ontology::Ontology, term::Term, rels::VecOrTuple{Symbol}) = ontology[transitive_closure(ontology, term, rels, true)]
descendants(ontology::Ontology, term::Term, rel::Symbol = :is_a) = descendants(ontology, term, (rel,))
ancestors(ontology::Ontology, term::Term, rels::VecOrTuple{Symbol}) = ontology[transitive_closure(ontology, term, rels, Val{false})]
ancestors(ontology::Ontology, term::Term, rels::VecOrTuple{Symbol}) = ontology[transitive_closure(ontology, term, rels, false)]
ancestors(ontology::Ontology, term::Term, rel::Symbol = :is_a) = ancestors(ontology, term, (rel,))

function satisfies(ontology::Ontology, term1::Term, rel::Symbol, term2::Term)
Expand Down
30 changes: 16 additions & 14 deletions src/parser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@ struct OBOParseException <: Exception
end

function find_first_nonescaped(s, ch)
i = searchindex(s, ch)
while i > 0
i = findfirst(isequal(ch), s)
while i !== nothing
numescapes = 0
@inbounds for j in i-1:-1:1
(s[j] == '\\') || break
numescapes += 1
end
iseven(numescapes) && return i # this is not escaped
i = searchindex(s, ch, i+1)
i = findnext(isequal(ch), s, i+1)
end
return i
end

function removecomments(line)
i = find_first_nonescaped(line, "!")
return i > 0 ? line[1:i-1] : line
i = find_first_nonescaped(line, '!')
return i !== nothing ? line[1:i-1] : line
end

const id_tag = "id"
Expand Down Expand Up @@ -84,18 +84,20 @@ end

function tagvalue(line)
# TODO: what an ad hoc parser!
i = searchindex(line, ": ")
if i == 0
i = findfirst(": ", line)
if i === nothing
# empty tag value
endswith(line, ":") && (return line, "", true)

# empty strings are dummy
return "", "", false
if endswith(line, ":")
return line, "", true
else
# empty strings are dummy
return "", "", false
end
end

j = searchindex(line, " !")
tag = line[1:i-1]
value = j==0 ? line[i+2:end] : line[i+2:j-1]
j = findfirst(" !", line)
tag = line[1:first(i)-1]
value = j === nothing ? line[first(i)+2:end] : line[first(i)+2:first(j)-1]

return tag, value, true
end
Expand Down
10 changes: 8 additions & 2 deletions src/term.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,14 @@ end


Base.isless(term1::Term, term2::Term) = isless(term1.id, term2.id)
Base.show(io::IO, term::Term) = @printf io "Term(\"%s\", \"%s\")" term.id term.name
Base.showcompact(io::IO, term::Term) = print(io, term.id)

function Base.show(io::IO, term::Term)
if get(io, :compact, false)
@printf io "Term(\"%s\", \"%s\")" term.id term.name
else
print(io, term.id)
end
end

isobsolete(term::Term) = term.obsolete

Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using OBOParse
using Base.Test
using Test

const testdir = dirname(@__FILE__)

Expand Down

0 comments on commit 4c84576

Please sign in to comment.