Skip to content
This repository has been archived by the owner on Sep 24, 2019. It is now read-only.

Commit

Permalink
Merge branch 'next'; Fixes #90 and #91
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthony Bargnesi committed Dec 21, 2015
2 parents 3f77265 + 208d7f0 commit 9d9448f
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 30 deletions.
12 changes: 6 additions & 6 deletions bin/bel_upgrade.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def initialize(content, change_log)
BEL::Script.parse(content) do |obj|
# redefine namespace based on change log's `redefine` blocik
# use 'namespaces' block, if available
if obj.is_a? NamespaceDefinition
if obj.is_a? BEL::Namespace::NamespaceDefinition
if @change_log.has_key? 'redefine'
redefine = @change_log['redefine']['namespaces']
if not redefine
Expand All @@ -116,7 +116,7 @@ def initialize(content, change_log)
entry = redefine[obj.prefix.to_s]
new_keyword = entry['new_keyword'].to_sym
new_url = entry['new_url']
obj = NamespaceDefinition.new(new_keyword, new_url)
obj = BEL::Namespace::NamespaceDefinition.new(new_keyword, new_url)
end
end

Expand All @@ -128,21 +128,21 @@ def initialize(content, change_log)
end

# update annotation definitions
if obj.is_a? AnnotationDefinition and obj.type.eql? :url
if obj.is_a? BEL::Language::AnnotationDefinition and obj.type.eql? :url
if @redefine_annotations
old_url = obj.value
if @annotation_url_map.has_key? old_url.to_s
kw = obj.prefix
new_url = @annotation_url_map[old_url]['new_url']
prefix = @annotation_url_map[old_url]['prefix']
obj = AnnotationDefinition.new(:url, kw, new_url)
obj = BEL::Language::AnnotationDefinition.new(:url, kw, new_url)
@annotation_keyword_map[kw] = prefix # map bel doc annotation kw to set of changelog prefixes
end
end
end

# evidence always needs quoting; backwards-compatibility
if obj.is_a? Annotation
if obj.is_a? BEL::Language::Annotation
if obj.name == 'Evidence'
ev = obj.to_s
ev.gsub!(EvidenceMatcher, 'SET Evidence = "\1"')
Expand Down Expand Up @@ -207,7 +207,7 @@ def initialize(content, change_log)
if redefinition
new_prefix = redefinition['new_keyword']
new_url = redefinition['new_url']
obj.ns = NamespaceDefinition.new(new_prefix, new_url)
obj.ns = BEL::Namespace::NamespaceDefinition.new(new_prefix, new_url)

# ...and replace value using new namespace prefix
replacements = @change_log[new_prefix]
Expand Down
1 change: 1 addition & 0 deletions gem.deps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
gem 'rdf', '~> 1.1'
gem 'rdf-turtle', '~> 1.1'
gem 'uuid', '~> 2.3'
gem 'rdf-mongo', '1.99.0'

# Platform-specific example.
# platform(:jruby) {
Expand Down
14 changes: 11 additions & 3 deletions lib/bel/namespace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ module Namespace
],
GOBP: [
LATEST_PREFIX + 'namespace/go-biological-process.belns',
'http://www.openbel.org/bel/namespace/go-biological-processes'
'http://www.openbel.org/bel/namespace/go-biological-process'
],
GOBPID: [
LATEST_PREFIX + 'namespace/go-biological-process-ids.belns',
'http://www.openbel.org/bel/namespace/go'
'http://www.openbel.org/bel/namespace/go-biological-process'
],
GOCC: [
LATEST_PREFIX + 'namespace/go-cellular-component.belns',
Expand All @@ -68,6 +68,14 @@ module Namespace
LATEST_PREFIX + 'namespace/mesh-cellular-structures-ids.belns',
'http://www.openbel.org/bel/namespace/mesh-cellular-structures'
],
MECHC: [
LATEST_PREFIX + 'namespace/mesh-chemicals.belns',
'http://www.openbel.org/bel/namespace/mesh-chemicals'
],
MECHCID: [
LATEST_PREFIX + 'namespace/mesh-chemicals-ids.belns',
'http://www.openbel.org/bel/namespace/mesh-chemicals'
],
MESHD: [
LATEST_PREFIX + 'namespace/mesh-diseases.belns',
'http://www.openbel.org/bel/namespace/mesh-diseases',
Expand Down Expand Up @@ -114,7 +122,7 @@ module Namespace
],
SPID: [
LATEST_PREFIX + 'namespace/swissprot-ids.belns',
'http://www.openbel.org/bel/namespace/swissprot-ids'
'http://www.openbel.org/bel/namespace/swissprot'
]
}

Expand Down
2 changes: 1 addition & 1 deletion lib/bel/translator/plugins/rdf/monkey_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def to_rdf(graph_name = nil)
@arguments.find_all{ |x|
x.is_a? ::BEL::Model::Parameter and x.ns != nil
}.each do |param|
concept_uri = param.ns.to_uri + param.value.to_s
concept_uri = "#{param.ns.to_uri}/#{param.value}"
statements << ::RDF::Statement.new(uri, BEL::RDF::BELV.hasConcept, BEL::RDF::RDF::URI(URI.encode(concept_uri)), :graph_name => graph_name)
end

Expand Down
2 changes: 1 addition & 1 deletion spec/integration/belrdf_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
BEL.translate(bel_file, :bel, :rdf, writer)

rdf_triples = writer.string
expect(rdf_triples.each_line.count).to eql(301)
expect(rdf_triples.each_line.count).to eql(372)
end
end

Expand Down
37 changes: 18 additions & 19 deletions spec/unit/rdf_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
include BEL::Model
include BEL::Namespace

BELV = ::BEL::Translator::Plugins::Rdf::BEL::RDF::BELV

describe 'RDF functionality of BEL language objects' do

before(:all) do
Expand Down Expand Up @@ -45,19 +47,19 @@
expect(triples.size).to eq(4)
expect(
triples.count { |x|
x.object.uri? and x.object.value == ::BEL::Translator::Plugins::Rdf::BEL::RDF::BELV.AbundanceConcept
x.object.uri? and x.object.value == BELV.AbundanceConcept
}).to eq(1)
expect(
triples.count { |x|
x.object.uri? and x.object.value == ::BEL::Translator::Plugins::Rdf::BEL::RDF::BELV.GeneConcept
x.object.uri? and x.object.value == BELV.GeneConcept
}).to eq(1)
expect(
triples.count { |x|
x.object.uri? and x.object.value == ::BEL::Translator::Plugins::Rdf::BEL::RDF::BELV.RNAConcept
x.object.uri? and x.object.value == BELV.RNAConcept
}).to eq(1)
expect(
triples.count { |x|
x.object.uri? and x.object.value == ::BEL::Translator::Plugins::Rdf::BEL::RDF::BELV.ProteinConcept
x.object.uri? and x.object.value == BELV.ProteinConcept
}).to eq(1)
end

Expand All @@ -76,27 +78,27 @@
expect(term_uri).to eq(term.to_uri)
expect(rdf_statements.size).to eq(4)
expect(
rdf_statements.include? [term.to_uri, ::BEL::Translator::Plugins::Rdf::BEL::RDF::RDF.type, ::BEL::Translator::Plugins::Rdf::BEL::RDF::BELV.Term]
rdf_statements.include? [term.to_uri, RDF.type, BELV.Term]
).to be(true)
expect(
rdf_statements.include? [term.to_uri, ::BEL::Translator::Plugins::Rdf::BEL::RDF::RDF.type, term.rdf_type]
rdf_statements.include? [term.to_uri, RDF.type, term.rdf_type]
).to be(true)
expect(
rdf_statements.include? [term.to_uri, ::BEL::Translator::Plugins::Rdf::BEL::RDF::RDFS.label, term.to_s]
rdf_statements.include? [term.to_uri, RDF::RDFS.label, term.to_s]
).to be(true)
expect(
rdf_statements.include? [term.to_uri, ::BEL::Translator::Plugins::Rdf::BEL::RDF::BELV.hasConcept, term.arguments[0].to_uri]
rdf_statements.include? [term.to_uri, BELV.hasConcept, term.arguments[0].to_uri]
).to be(true)
end

it "forces term labels as UTF-8" do
(_, rdf_statements) = a(Parameter.new(CHEBI, '5α-androst-16-en-3-one')).to_rdf
_, _, label_literal = rdf_statements.find { |stmt|
stmt[1] == ::BEL::Translator::Plugins::Rdf::BEL::RDF::RDFS.label
stmt[1] == RDF::RDFS.label
}

expect(label_literal.encoding).to eql(Encoding::UTF_8)
expect(label_literal).to eql(%Q{a(CHEBI:"5α-androst-16-en-3-one")})
expect(label_literal.value.encoding).to eql(Encoding::UTF_8)
expect(label_literal).to eql(RDF::Literal.new(%Q{a(CHEBI:"5α-androst-16-en-3-one")}))
end
end

Expand All @@ -115,26 +117,23 @@
(_, rdf_statements) = statement.to_rdf

type_evidence_statements = rdf_statements.find_all { |stmt|
stmt[1] == ::BEL::Translator::Plugins::Rdf::BEL::RDF::RDF.type and stmt[2] == ::BEL::Translator::Plugins::Rdf::BEL::RDF::BELV.Evidence
stmt[1] == RDF.type and stmt[2] == BELV.Evidence
}
expect(type_evidence_statements.size).to eq(1)

evidence_resource = type_evidence_statements.first[0]
expect(evidence_resource).to be_a(::BEL::Translator::Plugins::Rdf::BEL::RDF::RDF::Node)

evidence_resource_identifier = evidence_resource.to_s.gsub(/^_:/, '')
expect(UUID.validate(evidence_resource_identifier)).to be(true)
expect(evidence_resource).to be_a(RDF::URI)
end

it "forces statement labels as UTF-8" do
(_, rdf_statements) =
(a(Parameter.new(CHEBI, '5α-androst-16-en-3-one')).association a(Parameter.new(CHEBI, 'luteolin 7-O-β-D-glucosiduronate'))).to_rdf
_, _, label_literal = rdf_statements.select { |stmt|
stmt[1] == ::BEL::Translator::Plugins::Rdf::BEL::RDF::RDFS.label
stmt[1] == RDF::RDFS.label
}.last

expect(label_literal.encoding).to eql(Encoding::UTF_8)
expect(label_literal).to eql(%Q{a(CHEBI:"5α-androst-16-en-3-one") association a(CHEBI:"luteolin 7-O-β-D-glucosiduronate")})
expect(label_literal.value.encoding).to eql(Encoding::UTF_8)
expect(label_literal).to eql(RDF::Literal.new(%Q{a(CHEBI:"5α-androst-16-en-3-one") association a(CHEBI:"luteolin 7-O-β-D-glucosiduronate")}))
end

it "forces evidence text as UTF-8" do
Expand Down

0 comments on commit 9d9448f

Please sign in to comment.