bio-publisci 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -0
  3. data/Rakefile +1 -1
  4. data/examples/prov_dsl.prov +2 -1
  5. data/examples/safe_gen.rb +7 -0
  6. data/examples/visualization/primer.prov +66 -0
  7. data/examples/visualization/prov_viz.rb +140 -0
  8. data/examples/visualization/viz.rb +35 -0
  9. data/features/metadata_steps.rb +2 -4
  10. data/features/orm_steps.rb +4 -4
  11. data/features/reader_steps.rb +1 -1
  12. data/features/store_steps.rb +1 -1
  13. data/features/writer.feature +1 -1
  14. data/features/writer_steps.rb +1 -1
  15. data/lib/bio-publisci.rb +10 -2
  16. data/lib/bio-publisci/analyzer.rb +4 -4
  17. data/lib/bio-publisci/{spira.rb → datacube_model.rb} +4 -5
  18. data/lib/bio-publisci/dataset/ORM/data_cube_orm.rb +12 -12
  19. data/lib/bio-publisci/dataset/ORM/observation.rb +1 -1
  20. data/lib/bio-publisci/dataset/configuration.rb +31 -0
  21. data/lib/bio-publisci/dataset/data_cube.rb +28 -17
  22. data/lib/bio-publisci/dataset/dataset.rb +11 -0
  23. data/lib/bio-publisci/dataset/dataset_for.rb +19 -9
  24. data/lib/bio-publisci/dataset/interactive.rb +1 -1
  25. data/lib/bio-publisci/dsl/config.rb +34 -0
  26. data/lib/bio-publisci/dsl/dataset_dsl.rb +91 -0
  27. data/lib/bio-publisci/dsl/dsl.rb +69 -0
  28. data/lib/bio-publisci/dsl/metadata_dsl.rb +85 -0
  29. data/lib/bio-publisci/{metadata/prov/dsl.rb → dsl/prov_dsl.rb} +30 -6
  30. data/lib/bio-publisci/metadata/generator.rb +323 -0
  31. data/lib/bio-publisci/metadata/metadata.rb +3 -314
  32. data/lib/bio-publisci/metadata/prov/activity.rb +3 -1
  33. data/lib/bio-publisci/metadata/prov/agent.rb +1 -1
  34. data/lib/bio-publisci/metadata/prov/association.rb +2 -2
  35. data/lib/bio-publisci/metadata/prov/config.rb +34 -0
  36. data/lib/bio-publisci/metadata/prov/derivation.rb +7 -2
  37. data/lib/bio-publisci/metadata/prov/element.rb +2 -2
  38. data/lib/bio-publisci/metadata/prov/entity.rb +1 -22
  39. data/lib/bio-publisci/metadata/prov/model/prov_models.rb +8 -9
  40. data/lib/bio-publisci/metadata/prov/plan.rb +1 -1
  41. data/lib/bio-publisci/metadata/prov/prov.rb +23 -21
  42. data/lib/bio-publisci/metadata/prov/role.rb +1 -1
  43. data/lib/bio-publisci/metadata/prov/usage.rb +1 -1
  44. data/lib/bio-publisci/metadata/publisher.rb +25 -0
  45. data/lib/bio-publisci/mixins/dereferencable.rb +1 -1
  46. data/lib/bio-publisci/mixins/registry.rb +27 -0
  47. data/lib/bio-publisci/output.rb +1 -1
  48. data/lib/bio-publisci/parser.rb +1 -1
  49. data/lib/bio-publisci/query/query_helper.rb +14 -14
  50. data/lib/bio-publisci/r_client.rb +5 -5
  51. data/lib/bio-publisci/readers/arff.rb +5 -5
  52. data/lib/bio-publisci/readers/csv.rb +3 -3
  53. data/lib/bio-publisci/readers/dataframe.rb +3 -3
  54. data/lib/bio-publisci/readers/r_cross.rb +4 -4
  55. data/lib/bio-publisci/readers/r_matrix.rb +3 -3
  56. data/lib/bio-publisci/store.rb +3 -3
  57. data/lib/bio-publisci/writers/arff.rb +6 -6
  58. data/lib/bio-publisci/writers/dataframe.rb +5 -5
  59. data/scripts/islet_mlratio.rb +1 -1
  60. data/scripts/scan_islet.rb +1 -1
  61. data/scripts/update_reference.rb +2 -2
  62. data/spec/ORM/data_cube_orm_spec.rb +2 -2
  63. data/spec/ORM/prov_model_spec.rb +19 -0
  64. data/spec/analyzer_spec.rb +7 -7
  65. data/spec/data_cube_spec.rb +13 -13
  66. data/spec/dataset_for_spec.rb +11 -4
  67. data/spec/dsl_spec.rb +90 -0
  68. data/spec/generators/csv_spec.rb +4 -4
  69. data/spec/generators/dataframe_spec.rb +6 -6
  70. data/spec/generators/r_cross_spec.rb +2 -2
  71. data/spec/generators/r_matrix_spec.rb +2 -2
  72. data/spec/metadata/metadata_dsl_spec.rb +68 -0
  73. data/spec/prov/activity_spec.rb +4 -4
  74. data/spec/prov/agent_spec.rb +3 -4
  75. data/spec/prov/association_spec.rb +1 -2
  76. data/spec/prov/config_spec.rb +28 -0
  77. data/spec/prov/derivation_spec.rb +30 -0
  78. data/spec/prov/entity_spec.rb +3 -4
  79. data/spec/prov/role_spec.rb +1 -2
  80. data/spec/prov/usage_spec.rb +1 -2
  81. data/spec/r_builder_spec.rb +3 -3
  82. data/spec/turtle/bacon +20 -4
  83. data/spec/turtle/reference +20 -4
  84. metadata +37 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 89e183556979b5f6ddcdd98d3a88c990d352eaea
4
- data.tar.gz: c4497bc982cb6452d648066dc1bb642bdd6ab315
3
+ metadata.gz: 84c3e7a1f4ffe93284a75856a424d4f86624032f
4
+ data.tar.gz: 834eb95f1ef0e2353d3aab93bcf4d9c35f34a1d4
5
5
  SHA512:
6
- metadata.gz: 10abfdbb88cf57d251f784e4106ea9f42b1fbe56fd75fcddc02dd329a32e0b1b3ac130f152aaf4d8d7d3e3f7a98a56236d27a5f444f695401a6281c8d9ecc488
7
- data.tar.gz: f1c4888880e431f668f47e80786855953acb1edd61395f3c32135a063ed583ef5dde9002433fe338462034af17863bf58377da5aba8fe99f74e5ae83d55bf56b
6
+ metadata.gz: b1c7a7e6f43f26f089a871fffafc10b0f6eb35b6367dde310e1e2df09c9ab40d725048d6291c5e67c12d32454d36a5539342f71130a90121bd4dd19946050f2b
7
+ data.tar.gz: 91a1bf68f52d3477d5fa5a89762619cdf7b038d3af49042cf34ce1b6f90e833324cea537bc60e9c6afc23c86163f44855f739e1838266cf0b905f5c20b2a9679
data/Gemfile CHANGED
@@ -14,6 +14,7 @@ group :development do
14
14
  gem "bio", ">= 1.4.2"
15
15
  gem "rdoc", "~> 3.12"
16
16
  gem "spoon"
17
+ gem "spira"
17
18
  end
18
19
 
19
20
 
data/Rakefile CHANGED
@@ -21,7 +21,7 @@ Jeweler::Tasks.new do |gem|
21
21
  gem.description = %Q{A toolkit for publishing scientific results and datasets using RDF, OWL, and related technologies }
22
22
  gem.email = "wstrinz@gmail.com"
23
23
  gem.authors = ["Will Strinz"]
24
- gem.version = "0.0.6"
24
+ gem.version = "0.0.7"
25
25
 
26
26
  # dependencies defined in Gemfile
27
27
  end
@@ -81,4 +81,5 @@ activity :use_R do
81
81
  associated_with :Will
82
82
  end
83
83
 
84
- generate_n3 true
84
+ generate_n3
85
+ # generate_n3 true
@@ -0,0 +1,7 @@
1
+ require 'bio-publisci'
2
+
3
+ str = IO.read(ARGV[0])
4
+ str.untaint
5
+ $SAFE=4
6
+ runner = PubliSci::Prov::DSL::Instance.new
7
+ puts runner.instance_eval(str,ARGV[0])
@@ -0,0 +1,66 @@
1
+ # Provenance generation code for primer example at
2
+ # http://www.w3.org/TR/prov-primer/images/agents.png
3
+
4
+ # Set the base url
5
+ base_url "http://example.org"
6
+
7
+ # Elements can be created with an options hash
8
+ entity :chart1, attributed_to: :derek
9
+
10
+ # entity => http://www.w3.org/TR/prov-o/#Entity
11
+ entity :composition1
12
+ entity :regionList1
13
+
14
+ # Elements can also be defined using a block
15
+ #
16
+ # agent => http://www.w3.org/TR/prov-o/#Agent
17
+ agent :derek do
18
+
19
+ # name => foaf:name
20
+ name "Derek"
21
+
22
+ # on_behalf_of => http://www.w3.org/TR/prov-o/#actedOnBehalfOf
23
+ on_behalf_of :chartgen
24
+ end
25
+
26
+ # Some methods are just wrappers with argument generation
27
+ # "organization" is short for agent :chartgen, type: "organization"
28
+ #
29
+ # organization => http://www.w3.org/TR/prov-o/#Organization
30
+ organization :chartgen
31
+
32
+
33
+ # An element of the correct type will be looked up for any
34
+ # method whose argument is a symbol
35
+ activity :illustrate do
36
+
37
+ # generated => http://www.w3.org/TR/prov-o/#generated
38
+ generated :chart1
39
+
40
+ # associated_with => http://www.w3.org/TR/prov-o/#wasAssociatedWith
41
+ associated_with :derek
42
+
43
+ # used => http://www.w3.org/TR/prov-o/#used
44
+ used :composition1
45
+
46
+ end
47
+
48
+ activity :compose1 do
49
+ generated :composition1
50
+ associated_with :derek
51
+ used :regionList1
52
+
53
+ # Since symbols are lazy loaded (only when looked up by generate_n3)
54
+ # you can call used here before declaring dataSet1
55
+ used :dataSet1
56
+ end
57
+
58
+ # data is aliased to entity
59
+ data :dataSet1
60
+
61
+ # Returns the turtle form of each element
62
+ generate_n3
63
+
64
+ # Can return abbreviated form by passing true
65
+ # (easier to read, some prefixes not yet included so may not work w/ triple stores)
66
+ # generate_n3(true)
@@ -0,0 +1,140 @@
1
+ require 'bio-publisci'
2
+ require 'graphviz'
3
+
4
+ def entity_node(label)
5
+ ent = @g.add_nodes(label)
6
+ ent.color = "#F3F781"
7
+ ent.style = "filled"
8
+ ent
9
+ end
10
+
11
+ def agent_node(label)
12
+ ag = @g.add_nodes(label)
13
+ ag.color = "#FE9A2E"
14
+ ag.style = "filled"
15
+ ag.shape = "box"
16
+ ag
17
+ end
18
+
19
+ def activity_node(label)
20
+ act = @g.add_nodes(label)
21
+ act.color = "#5858FA"
22
+ act.style = "filled"
23
+ act.shape = "box"
24
+ act
25
+ end
26
+
27
+ def generic_node(label)
28
+ act = @g.add_nodes(label)
29
+ # act.color = "#5858FA"
30
+ # act.style = "filled"
31
+ act.shape = "box"
32
+ act
33
+ end
34
+
35
+ def make_edges(from_obj,to_class,predicate)
36
+ # from_class.enum_for.to_a.map{|from_obj|
37
+ raise "Unknown From Node: #{from_obj.subject}" unless @nodemap[from_obj.subject]
38
+ relation = from_obj.send(predicate)
39
+ if relation
40
+ if relation.is_a? Array
41
+ relation.map{|r|
42
+ other = to_class.for(r)
43
+ raise "Unknown To Node: #{other.subject}" unless @nodemap[other.subject]
44
+ @g.add_edges(@nodemap[from_obj.subject],@nodemap[other.subject]).label=predicate.to_s
45
+ }
46
+ else
47
+ other = to_class.for(relation)
48
+ raise "Unknown To Node: #{other.subject}" unless @nodemap[other.subject]
49
+ @g.add_edges(@nodemap[from_obj.subject],@nodemap[other.subject]).label=predicate.to_s
50
+ end
51
+ end
52
+ # }
53
+ end
54
+
55
+ @nodemap={}
56
+ @g = GraphViz.new(:G, type: :digraph)
57
+ infile = ARGV[0] || 'primer.prov'
58
+ runner = PubliSci::Prov::DSL::Instance.new
59
+ runner.instance_eval(IO.read(infile),infile)
60
+ repo = runner.to_repository
61
+ Spira.add_repository :default, repo
62
+
63
+ include PubliSci::Prov::Model
64
+
65
+ Entity.enum_for.to_a.map{|e|
66
+ @nodemap[e.subject]=entity_node(e.label)
67
+ }
68
+
69
+ Agent.enum_for.to_a.map{|agent|
70
+ @nodemap[agent.subject]=agent_node(agent.label)
71
+ }
72
+
73
+ Activity.enum_for.to_a.map{|act|
74
+ @nodemap[act.subject]=activity_node(act.label)
75
+ }
76
+
77
+ Association.enum_for.to_a.map{|association|
78
+ @nodemap[association.subject]=generic_node(association.label)
79
+ }
80
+
81
+ Plan.enum_for.to_a.map{|plan|
82
+ @nodemap[plan.subject]=generic_node(plan.label)
83
+ }
84
+
85
+
86
+ # Derivation.enum_for.to_a.map{|deriv|
87
+ # @nodemap[deriv.subject]=generic_node(deriv.label)
88
+ # }
89
+
90
+ Entity.enum_for.to_a.map{|e|
91
+ attribs ={
92
+ "wasAttributedTo" => Agent,
93
+ "wasGeneratedBy" => Activity,
94
+ "wasDerivedFrom" => Entity,
95
+ }
96
+ attribs.each{|predicate,range| make_edges(e,range,predicate)}
97
+ }
98
+
99
+ Activity.enum_for.to_a.map{|act|
100
+ attribs ={
101
+ "generated" => Entity,
102
+ "used" => Entity,
103
+ "wasAssociatedWith" => Agent,
104
+ "qualifiedAssociation" => Agent,
105
+ }
106
+ attribs.each{|predicate,range| make_edges(act,range,predicate)}
107
+ }
108
+
109
+ Agent.enum_for.to_a.map{|agent|
110
+ attribs = {
111
+ "actedOnBehalfOf" => Agent
112
+ }
113
+ attribs.each{|predicate,range| make_edges(agent,range,predicate)}
114
+ }
115
+
116
+ Association.enum_for.to_a.map{|assoc|
117
+ attribs ={
118
+ "agent" => Agent,
119
+ "hadPlan" => Plan
120
+ }
121
+ attribs.each{|predicate,range| make_edges(assoc,range,predicate)}
122
+ }
123
+
124
+ # Association.enum_for.to_a.map{|assoc|
125
+ # attribs ={
126
+ # "agent" => Agent
127
+ # "hadPlan" => Plan
128
+ # }
129
+ # attribs.each{|predicate,range| make_edges(assoc,range,predicate)}
130
+ # }
131
+
132
+ # Derivation.enum_for.to_a.map{|assoc|
133
+ # attribs ={
134
+ # "agent" => Entity
135
+ # }
136
+ # attribs.each{|predicate,range| make_edges(assoc,range,predicate)}
137
+ # }
138
+
139
+ @g.output(png: "out.png")
140
+ begin `eog out.png` rescue nil end
@@ -0,0 +1,35 @@
1
+ require 'graphviz'
2
+
3
+ def entity_node(label)
4
+ ent = @g.add_nodes(label)
5
+ ent.color = "#F3F781"
6
+ ent.style = "filled"
7
+ ent
8
+ end
9
+
10
+ def agent_node(label)
11
+ ag = @g.add_nodes(label)
12
+ ag.color = "#FE9A2E"
13
+ ag.style = "filled"
14
+ ag.shape = "box"
15
+ ag
16
+ end
17
+
18
+ def activity_node(label)
19
+ act = @g.add_nodes(label)
20
+ act.color = "#5858FA"
21
+ act.style = "filled"
22
+ act.shape = "box"
23
+ act
24
+ end
25
+
26
+ @g = GraphViz.new(:G, type: :digraph)
27
+ g = @g
28
+
29
+ ent_n = entity_node("entity") #g.add_nodes("entity")
30
+ ag_n = activity_node("activity")
31
+
32
+ g.add_edges(ent_n,ag_n).label="attributed"
33
+
34
+ g.output(png: "out.png")
35
+ `eog out.png`
@@ -1,8 +1,6 @@
1
1
  Given(/^a class which includes the Metadata module$/) do
2
- class Meta
3
- include R2RDF::Metadata
4
- end
5
- @klass = Meta
2
+
3
+ @klass = Class.new {include PubliSci::Metadata::Generator}
6
4
  end
7
5
 
8
6
  Given(/^the source object (\{.+\})$/) do |fields|
@@ -1,7 +1,7 @@
1
1
  require_relative '../lib/bio-publisci.rb'
2
2
 
3
3
  Given /^an ORM::DataCube entitled "(.*?)"$/ do |name|
4
- @cube = R2RDF::ORM::DataCube.new(name: name)
4
+ @cube = PubliSci::ORM::DataCube.new(name: name)
5
5
  end
6
6
 
7
7
  Given /^an ORM::DataCube entitled "(.*?)" with the following options:$/ do |name, opts|
@@ -18,7 +18,7 @@ Given /^an ORM::DataCube entitled "(.*?)" with the following options:$/ do |name
18
18
 
19
19
  options_hash[k] = v
20
20
  }
21
- @cube = R2RDF::ORM::DataCube.new(options_hash)
21
+ @cube = PubliSci::ORM::DataCube.new(options_hash)
22
22
  end
23
23
 
24
24
  Given(/^a turtle string from file (.*)$/) do |file|
@@ -30,7 +30,7 @@ Given(/^the URI string "(.*?)"$/) do |uri|
30
30
  end
31
31
 
32
32
  When(/^I call the ORM::DataCube class method load on it$/) do
33
- @cube = R2RDF::ORM::DataCube.load(@string)
33
+ @cube = PubliSci::ORM::DataCube.load(@string)
34
34
  end
35
35
 
36
36
  When /^I add a "(.*?)" dimension$/ do |dim|
@@ -70,5 +70,5 @@ Then /^the to_n3 method should return a string with a "(.*?)"$/ do |search|
70
70
  end
71
71
 
72
72
  Then(/^I should receive an ORM::DataCube object$/) do
73
- @cube.is_a?(R2RDF::ORM::DataCube).should == true
73
+ @cube.is_a?(PubliSci::ORM::DataCube).should == true
74
74
  end
@@ -1,7 +1,7 @@
1
1
  require_relative '../lib/bio-publisci.rb'
2
2
 
3
3
  Given /^a (.*) generator$/ do |generator|
4
- @generator = R2RDF::Reader.const_get(generator).new
4
+ @generator = PubliSci::Reader.const_get(generator).new
5
5
  end
6
6
 
7
7
  When /^I ask for its methods$/ do
@@ -1,7 +1,7 @@
1
1
  require_relative '../lib/bio-publisci.rb'
2
2
 
3
3
  Given /a store of type (.*?)$/ do |type|
4
- @store = R2RDF::Store.new(type: :"#{type}")
4
+ @store = PubliSci::Store.new(type: :"#{type}")
5
5
  end
6
6
 
7
7
  When /^I call the stores add method with the turtle file (.*?) and an RDF::(.*?)$/ do |file,graph|
@@ -1,7 +1,7 @@
1
1
  Feature: export to various formats using writers
2
2
 
3
3
  In order to use RDF encoded data in other applications
4
- I want to export domain objects using an R2RDF::Writer object
4
+ I want to export domain objects using an PubliSci::Writer object
5
5
 
6
6
  Scenario: write to ARFF format
7
7
  Given a ARFF writer
@@ -1,5 +1,5 @@
1
1
  Given(/^a (.*) writer$/) do |type|
2
- @writer = R2RDF::Writer.const_get(type).new
2
+ @writer = PubliSci::Writer.const_get(type).new
3
3
  end
4
4
 
5
5
  When(/^I call its from_turtle method on the file (.*)$/) do |file|
data/lib/bio-publisci.rb CHANGED
@@ -7,6 +7,11 @@ require 'rserve'
7
7
  require 'sparql'
8
8
  require 'sparql/client'
9
9
  require 'rdf/turtle'
10
+ begin
11
+ require 'spira'
12
+ rescue LoadError
13
+ puts "can't load spira; orm unavailable"
14
+ end
10
15
 
11
16
  def load_folder(folder)
12
17
  Dir.foreach(File.dirname(__FILE__) + "/#{folder}") do |file|
@@ -27,11 +32,14 @@ load File.dirname(__FILE__) + '/bio-publisci/analyzer.rb'
27
32
  load File.dirname(__FILE__) + '/bio-publisci/store.rb'
28
33
  load File.dirname(__FILE__) + '/bio-publisci/dataset/data_cube.rb'
29
34
  load File.dirname(__FILE__) + '/bio-publisci/dataset/dataset_for.rb'
35
+ load File.dirname(__FILE__) + '/bio-publisci/dataset/configuration.rb'
36
+ load File.dirname(__FILE__) + '/bio-publisci/dataset/dataset.rb'
30
37
  load File.dirname(__FILE__) + '/bio-publisci/output.rb'
31
- load File.dirname(__FILE__) + '/bio-publisci/metadata/prov/prov.rb'
32
38
  load File.dirname(__FILE__) + '/bio-publisci/metadata/prov/element.rb'
39
+ load File.dirname(__FILE__) + '/bio-publisci/metadata/prov/prov.rb'
33
40
 
34
41
 
42
+ load_folder('bio-publisci/dsl')
35
43
  load_folder('bio-publisci/metadata')
36
44
  load_folder('bio-publisci/metadata/prov')
37
45
  load_folder('bio-publisci/metadata/prov/model')
@@ -42,4 +50,4 @@ load_folder('bio-publisci/dataset/ORM')
42
50
  # unless file == "." or file == ".."
43
51
  # load File.dirname(__FILE__) + '/generators/' + file
44
52
  # end
45
- # end
53
+ # end
@@ -1,5 +1,5 @@
1
- module R2RDF
2
-
1
+ module PubliSci
2
+
3
3
  #handles analysis of R expression to extract properties and recognize potential
4
4
  #ambiguity
5
5
  module Analyzer
@@ -13,10 +13,10 @@ module R2RDF
13
13
  data.map{|datum|
14
14
  return true if dirty?(datum)
15
15
  }
16
- else
16
+ else
17
17
  dirty_characters = [".",' ']
18
18
  if data.to_s.scan(/./) & dirty_characters
19
- true
19
+ true
20
20
  else
21
21
  false
22
22
  end
@@ -1,7 +1,6 @@
1
1
  require 'rdf/4store'
2
- require 'spira'
3
2
 
4
- module R2RDF
3
+ module PubliSci
5
4
  module ORM
6
5
 
7
6
  # class Person < Spira::Base
@@ -53,7 +52,7 @@ module R2RDF
53
52
  end
54
53
 
55
54
  def observation
56
- unless R2RDF::ORM.const_defined?("Observation")
55
+ unless PubliSci::ORM.const_defined?("Observation")
57
56
  obs = Class.new(Spira::Base) do
58
57
  type RDF::URI.new('http://purl.org/linked-data/cube#Observation')
59
58
 
@@ -63,13 +62,13 @@ module R2RDF
63
62
  property strip_uri(component.subject.to_s), predicate: component.subject
64
63
  }
65
64
  end
66
- R2RDF::ORM.const_set("Observation",obs)
65
+ PubliSci::ORM.const_set("Observation",obs)
67
66
  end
68
67
  Observation
69
68
  end
70
69
 
71
70
  def reload_observation
72
- R2RDF::ORM.send(:remove_const, "Observation")
71
+ PubliSci::ORM.send(:remove_const, "Observation")
73
72
  observation
74
73
  end
75
74