myGrid-taverna-t2flow 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENCE ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
data/README ADDED
@@ -0,0 +1,80 @@
1
+ = Taverna[http://taverna.sourceforge.net] 2 Interaction Gem
2
+
3
+ Author:: Emmanuel Tagarira
4
+ Version:: 0.0.0
5
+ Contact:: mailto:emmanuel.tagarira@student.manchester.ac.uk
6
+ URL:: http://taverna.sourceforge.net/
7
+ Licence:: LGPL 3 (See LICENCE or http://www.gnu.org/licenses/lgpl.html)
8
+ Copyright:: (c) 2008-2009 University of Manchester, UK
9
+
10
+
11
+
12
+ == Synopsis
13
+
14
+ This is a Ruby library to support the interaction with Taverna[http://taverna.sourceforge.net] version 2 workflows (T2Flows). This relies on the functionality provided by the libxml library. To be able to utilise this gem to its full potential, you will need to have the following installed on your system.
15
+ - GraphViz[http://www.graphviz.org/Download.php] (a graph visualization package)
16
+ - Rdoc gem
17
+ - Darkfish-Rdoc gem
18
+
19
+
20
+
21
+ == The T2Flow Model Implementation
22
+
23
+ Much like the Taverna[http://taverna.sourceforge.net] 1 Scufl model, T2Flows contain Processors, Sinks, and Sources. T2Flows however, encapsulate these elements within Dataflow objects. A Dataflow objects is the container for all the different elements present within the Taverna[http://taverna.sourceforge.net] 2 workflows, hence a single T2Flow may have one or more dataflows. WorkflowDescriptions and Links, from the original Taverna[http://taverna.sourceforge.net] 1 workflows (Scufl), have been renamed in T2Flows to DataflowAnnotations and Datalinks respectively. DataflowAnnotations, however, allow for multiple titles, authors, and descriptions, as opposed to the single value attributes held for Scufls.
24
+
25
+
26
+
27
+ == Installation
28
+ To install the gems required by the Taverna 2 gem library, type into your command prompt:
29
+ [sudo] gem install libxml-ruby
30
+ [sudo] gem install rdoc
31
+ [sudo] gem install darkfish-rdoc
32
+
33
+ When you have the required gems on your system, you may install this gem using the following commands:
34
+ gem sources -a http://gems.github.com
35
+ [sudo] gem install myGrid-taverna-t2flow
36
+
37
+
38
+
39
+ == Usage
40
+
41
+ To be able to generate at least a T2Flow model using the gem, you need to include in your ruby code the following lines:
42
+ require "t2flow/model.rb"
43
+ require "t2flow/parser.rb"
44
+
45
+ To generate the model you can then use the gem as follows:
46
+ foo = File.new("path/to/workflow/file", "r")
47
+ bar = T2Flow::Parser.new.parse(foo)
48
+
49
+ Alternatively:
50
+ foo = File.new("path/to/workflow/file", "r").read
51
+ bar = T2Flow::Parser.new.parse(foo)
52
+
53
+ You will then be able to use your T2Flow model to retrieve information about the workflow by invoking the different methods and attributes.
54
+ bar.INVOKED
55
+ ... where INVOKED is the method or attribute required.
56
+
57
+ You can also interact with remote workflows.
58
+ require "open-uri"
59
+
60
+ foo = Uri.parse("xxxx://uri_to_workflow").read
61
+ bar = T2Flow::Parser.new.parse(foo)
62
+
63
+ To be enable you to draw images of the T2Flow, you need to include:
64
+ require "t2flow/dot.rb"
65
+
66
+ To be able to use any functionality included in "t2flow/dot.rb", you need to have GraphViz[http://www.graphviz.org/Download.php] installed on your system. Once this package has been installed, you may use the gem to draw an image showing the structure of the T2Flow as follows.
67
+ out_file = File.new("path/to/file/you/want/the/dot/script/to/be/written", "w+")
68
+ T2Flow::Dot.new.write_dot(out_file, bar)
69
+ `dot -Tpng -o"path/to/the/output/image" #{out_file.path}`
70
+ The last line draws a PNG image using +out_file+. To learn more about dot, try typing into your command prompt:
71
+ % man dot
72
+ or
73
+ % dot -h
74
+
75
+
76
+
77
+ == References
78
+
79
+ [1] http://taverna.sourceforge.net
80
+ [2] http://www.graphviz.org
data/lib/t2flow/dot.rb ADDED
@@ -0,0 +1,250 @@
1
+ module T2Flow
2
+
3
+ # This class enables you to write the script will will be used by dot
4
+ # (which is part of GraphViz[http://www.graphviz.org/Download.php])
5
+ # to generate the image showing the structure of a given model.
6
+ # To get started quickly, you could try:
7
+ # out_file = File.new("path/to/file/you/want/the/dot/script/to/be/written", "w+")
8
+ # workflow = File.new("path/to/workflow/file", "r").read
9
+ # model = T2Flow::Parser.new.parse(workflow)
10
+ # T2Flow::Dot.new.write_dot(out_file, model)
11
+ # `dot -Tpng -o"path/to/the/output/image" #{out_file.path}`
12
+ class Dot
13
+
14
+ @@processor_colours = {
15
+ 'apiconsumer' => 'palegreen',
16
+ 'beanshell' => 'burlywood2',
17
+ 'biomart' => 'lightcyan2',
18
+ 'local' => 'mediumorchid2',
19
+ 'biomobywsdl' => 'darkgoldenrod1',
20
+ 'biomobyobject' => 'gold',
21
+ 'biomobyparser' => 'white',
22
+ 'inferno' => 'violetred1',
23
+ 'notification' => 'mediumorchid2',
24
+ 'rdfgenerator' => 'purple',
25
+ 'rserv' => 'lightgoldenrodyellow',
26
+ 'seqhound' => '#836fff',
27
+ 'soaplabwsdl' => 'lightgoldenrodyellow',
28
+ 'stringconstant' => 'lightsteelblue',
29
+ 'talisman' => 'plum2',
30
+ 'bsf' => 'burlywood2',
31
+ 'abstractprocessor' => 'lightgoldenrodyellow',
32
+ 'rshell' => 'lightgoldenrodyellow',
33
+ 'arbitrarywsdl' => 'darkolivegreen3',
34
+ 'workflow' => 'crimson'}
35
+
36
+ @@fill_colours = %w{white aliceblue antiquewhite beige}
37
+
38
+ @@ranksep = '0.22'
39
+ @@nodesep = '0.05'
40
+
41
+ # Creates a new dot object for interaction.
42
+ def initialize
43
+ # @port_style IS CURRENTLY UNUSED. IGNORE!!!
44
+ @port_style = 'none' # 'all', 'bound' or 'none'
45
+ end
46
+
47
+ # Writes to the given stream (File, StringIO, etc) the script to generate
48
+ # the image showing the internals of the given workflow model.
49
+ # === Usage
50
+ # stream = File.new("path/to/file/you/want/the/dot/script/to/be/written", "w+")
51
+ # workflow = .......
52
+ # model = T2Flow::Parser.new.parse(workflow)
53
+ # T2Flow::Dot.new.write_dot(stream, model)
54
+ def write_dot(stream, model)
55
+ @t2flow_model = model
56
+ stream.puts 'digraph t2flow_graph {'
57
+ stream.puts ' graph ['
58
+ stream.puts ' style=""'
59
+ stream.puts ' labeljust="left"'
60
+ stream.puts ' clusterrank="local"'
61
+ stream.puts " ranksep=\"#@@ranksep\""
62
+ stream.puts " nodesep=\"#@@nodesep\""
63
+ stream.puts ' ]'
64
+ stream.puts
65
+ stream.puts ' node ['
66
+ stream.puts ' fontname="Helvetica",'
67
+ stream.puts ' fontsize="10",'
68
+ stream.puts ' fontcolor="black", '
69
+ stream.puts ' shape="box",'
70
+ stream.puts ' height="0",'
71
+ stream.puts ' width="0",'
72
+ stream.puts ' color="black",'
73
+ stream.puts ' fillcolor="lightgoldenrodyellow",'
74
+ stream.puts ' style="filled"'
75
+ stream.puts ' ];'
76
+ stream.puts
77
+ stream.puts ' edge ['
78
+ stream.puts ' fontname="Helvetica",'
79
+ stream.puts ' fontsize="8",'
80
+ stream.puts ' fontcolor="black",'
81
+ stream.puts ' color="black"'
82
+ stream.puts ' ];'
83
+ write_dataflow(stream, model.top_level)
84
+ stream.puts '}'
85
+
86
+ stream.flush
87
+ end
88
+
89
+ def write_dataflow(stream, dataflow, prefix="", name="", depth=0) # :nodoc:
90
+ if name != ""
91
+ stream.puts "subgraph cluster_#{prefix}#{name} {"
92
+ stream.puts " label=\"#{name}\""
93
+ stream.puts ' fontname="Helvetica"'
94
+ stream.puts ' fontsize="10"'
95
+ stream.puts ' fontcolor="black"'
96
+ stream.puts ' clusterrank="local"'
97
+ stream.puts " fillcolor=\"#{@@fill_colours[depth % @@fill_colours.length]}\""
98
+ stream.puts ' style="filled"'
99
+ end
100
+ dataflow.processors.each {|processor| write_processor(stream, processor, prefix, depth)}
101
+ write_source_cluster(stream, dataflow.sources, prefix)
102
+ write_sink_cluster(stream, dataflow.sinks, prefix)
103
+ dataflow.datalinks.each {|link| write_link(stream, link, dataflow, prefix)}
104
+ dataflow.coordinations.each {|coordination| write_coordination(stream, coordination, dataflow, prefix)}
105
+ if name != ""
106
+ stream.puts '}'
107
+ end
108
+ end
109
+
110
+ def write_processor(stream, processor, prefix, depth) # :nodoc:
111
+ # nested workflows
112
+ if "#{processor.type}" == "workflow"
113
+ dataflow = @t2flow_model.dataflow(processor.dataflow_id)
114
+ write_dataflow(stream, dataflow, prefix + dataflow.annotations.name, dataflow.annotations.name, depth.next)
115
+ else
116
+ stream.puts " \"#{prefix}#{processor.name}\" ["
117
+ stream.puts " fillcolor=\"#{get_colour processor.type}\","
118
+ stream.puts ' shape="box",'
119
+ stream.puts ' style="filled",'
120
+ stream.puts ' height="0",'
121
+ stream.puts ' width="0",'
122
+ stream.puts " label=\"#{processor.name}\""
123
+ stream.puts ' ];'
124
+ end
125
+ end
126
+
127
+ def write_source_cluster(stream, sources, prefix) # :nodoc:
128
+ if sources.length > 0
129
+ stream.puts " subgraph cluster_#{prefix}sources {"
130
+ stream.puts ' style="dotted"'
131
+ stream.puts ' label="Workflow Inputs"'
132
+ stream.puts ' fontname="Helvetica"'
133
+ stream.puts ' fontsize="10"'
134
+ stream.puts ' fontcolor="black"'
135
+ stream.puts ' rank="same"'
136
+ stream.puts " \"#{prefix}WORKFLOWINTERNALSOURCECONTROL\" ["
137
+ stream.puts ' shape="triangle",'
138
+ stream.puts ' width="0.2",'
139
+ stream.puts ' height="0.2",'
140
+ stream.puts ' fillcolor="brown1"'
141
+ stream.puts ' label=""'
142
+ stream.puts ' ]'
143
+ sources.each {|source| write_source(stream, source, prefix)}
144
+ stream.puts ' }'
145
+ end
146
+ end
147
+
148
+ def write_source(stream, source, prefix) # :nodoc:
149
+ stream.puts " \"#{prefix}WORKFLOWINTERNALSOURCE_#{source.name}\" ["
150
+ stream.puts ' shape="box",'
151
+ stream.puts " label=\"#{source.name}\""
152
+ stream.puts ' width="0",'
153
+ stream.puts ' height="0",'
154
+ stream.puts ' fillcolor="skyblue"'
155
+ stream.puts ' ]'
156
+ end
157
+
158
+ def write_sink_cluster(stream, sinks, prefix) # :nodoc:
159
+ if sinks.length > 0
160
+ stream.puts " subgraph cluster_#{prefix}sinks {"
161
+ stream.puts ' style="dotted"'
162
+ stream.puts ' label="Workflow Outputs"'
163
+ stream.puts ' fontname="Helvetica"'
164
+ stream.puts ' fontsize="10"'
165
+ stream.puts ' fontcolor="black"'
166
+ stream.puts ' rank="same"'
167
+ stream.puts " \"#{prefix}WORKFLOWINTERNALSINKCONTROL\" ["
168
+ stream.puts ' shape="invtriangle",'
169
+ stream.puts ' width="0.2",'
170
+ stream.puts ' height="0.2",'
171
+ stream.puts ' fillcolor="chartreuse3"'
172
+ stream.puts ' label=""'
173
+ stream.puts ' ]'
174
+ sinks.each {|sink| write_sink(stream, sink, prefix)}
175
+ stream.puts ' }'
176
+ end
177
+ end
178
+
179
+ def write_sink(stream, sink, prefix) # :nodoc:
180
+ stream.puts " \"#{prefix}WORKFLOWINTERNALSINK_#{sink.name}\" ["
181
+ stream.puts ' shape="box",'
182
+ stream.puts " label=\"#{sink.name}\""
183
+ stream.puts ' width="0",'
184
+ stream.puts ' height="0",'
185
+ stream.puts ' fillcolor="lightsteelblue2"'
186
+ stream.puts ' ]'
187
+ end
188
+
189
+ def write_link(stream, link, dataflow, prefix) # :nodoc:
190
+ if dataflow.sources.select{|s| s.name == link.source} != []
191
+ stream.write " \"#{prefix}WORKFLOWINTERNALSOURCE_#{link.source}\""
192
+ else
193
+ processor = dataflow.processors.select{|p| p.name == link.source.split(':')[0]}[0]
194
+ if "#{processor.type}" == "workflow"
195
+ df = @t2flow_model.dataflow(processor.dataflow_id)
196
+ stream.write " \"#{prefix}#{df.annotations.name}WORKFLOWINTERNALSINK_#{link.source.split(':')[1]}\""
197
+ else
198
+ stream.write " \"#{prefix}#{processor.name}\""
199
+ end
200
+ end
201
+ stream.write '->'
202
+ if dataflow.sinks.select{|s| s.name == link.sink} != []
203
+ stream.write "\"#{prefix}WORKFLOWINTERNALSINK_#{link.sink}\""
204
+ else
205
+ processor = dataflow.processors.select{|p| p.name == link.sink.split(':')[0]}[0]
206
+ if "#{processor.type}" == "workflow"
207
+ df = @t2flow_model.dataflow(processor.dataflow_id)
208
+ stream.write "\"#{prefix}#{df.annotations.name}WORKFLOWINTERNALSOURCE_#{link.sink.split(':')[1]}\""
209
+ else
210
+ stream.write "\"#{prefix}#{processor.name}\""
211
+ end
212
+ end
213
+ stream.puts ' ['
214
+ stream.puts ' ];'
215
+ end
216
+
217
+ def write_coordination(stream, coordination, dataflow, prefix) # :nodoc:
218
+ stream.write " \"#{prefix}#{coordination.control}"
219
+ processor = dataflow.processors.select{|p| p.name == coordination.control}[0]
220
+
221
+ stream.write 'WORKFLOWINTERNALSINKCONTROL' if "#{processor.type}" == "workflow"
222
+ stream.write '"->"'
223
+ stream.write "#{prefix}#{coordination.target}"
224
+ processor = dataflow.processors.select{|p| p.name == coordination.target}[0]
225
+ stream.write 'WORKFLOWINTERNALSOURCECONTROL' if "#{processor.type}" == "workflow"
226
+ stream.write "\""
227
+ stream.puts ' ['
228
+ stream.puts ' color="gray",'
229
+ stream.puts ' arrowhead="odot",'
230
+ stream.puts ' arrowtail="none"'
231
+ stream.puts ' ];'
232
+ end
233
+
234
+ def get_colour(processor_name) # :nodoc:
235
+ colour = @@processor_colours[processor_name]
236
+ if colour
237
+ colour
238
+ else
239
+ 'white'
240
+ end
241
+ end
242
+
243
+ # Returns true if the given name is a processor; false otherwise
244
+ def Dot.is_processor?(processor_name)
245
+ true if @@processor_colours[processor_name]
246
+ end
247
+
248
+ end
249
+
250
+ end
@@ -0,0 +1,245 @@
1
+ # This is the module containing the T2Flow model implementation i.e. the model structure/definition and all its internals.
2
+
3
+ module T2Flow # :nodoc:
4
+
5
+ # The model for a given Taverna 2 workflow.
6
+ class Model
7
+ # The list of all the dataflows that make up the workflow.
8
+ attr_accessor :dataflows
9
+
10
+ # The list of any dependencies that have been found inside the workflow.
11
+ attr_accessor :dependencies
12
+
13
+ # Creates an empty model for a Taverna 2 workflow.
14
+ def initialize
15
+ @dataflows = []
16
+ end
17
+
18
+ # Retrieve the top-level dataflow ie the MAIN (containing) dataflow
19
+ def top_level
20
+ @dataflows[0]
21
+ end
22
+
23
+ # Retrieve the dataflow with the given ID
24
+ def dataflow(df_id)
25
+ df = @dataflows.select { |x| x.dataflow_id == df_id }
26
+ return df[0]
27
+ end
28
+
29
+ # Retrieve ALL the processors containing beanshells within the workflow.
30
+ def beanshells
31
+ beanshells = []
32
+ @dataflows.each { |dataflow|
33
+ dataflow.beanshells.each { |bean|
34
+ beanshells << bean
35
+ }
36
+ }
37
+ return beanshells
38
+ end
39
+
40
+ # Retrieve ALL the datalinks within the workflow
41
+ def datalinks
42
+ links = []
43
+ @dataflows.each { |dataflow|
44
+ dataflow.datalinks.each { |link|
45
+ links << link
46
+ }
47
+ }
48
+ return links
49
+ end
50
+
51
+ # Retrieve the annotations within the workflow.
52
+ # In the event that the workflow is nested,
53
+ # retrieve the top-level annotations.
54
+ def annotations
55
+ @dataflows[0].annotations
56
+ end
57
+
58
+ # Retrieve ALL the processors within the workflow
59
+ def processors
60
+ procs =[]
61
+ @dataflows.each { |dataflow|
62
+ dataflow.processors.each { |proc|
63
+ procs << proc
64
+ }
65
+ }
66
+ return procs
67
+ end
68
+
69
+ # Retrieve ALL the sources within the workflow
70
+ def sources
71
+ sources =[]
72
+ @dataflows.each { |dataflow|
73
+ dataflow.sources.each { |source|
74
+ sources << source
75
+ }
76
+ }
77
+ return sources
78
+ end
79
+
80
+ # Retrieve ALL the sinks within the workflow
81
+ def sinks
82
+ sinks =[]
83
+ @dataflows.each { |dataflow|
84
+ dataflow.sinks.each { |sink|
85
+ sinks << sink
86
+ }
87
+ }
88
+ return sinks
89
+ end
90
+
91
+ # Retrieve ALL the coordinations within the workflow
92
+ def coordinations
93
+ coordinations =[]
94
+ @dataflows.each { |dataflow|
95
+ dataflow.coordinations.each { |coordination|
96
+ coordinations << coordination
97
+ }
98
+ }
99
+ return coordinations
100
+ end
101
+
102
+ # Retrieve the unique dataflow ID for the top level dataflow.
103
+ def dataflow_id
104
+ @dataflows[0].dataflow_id
105
+ end
106
+ end
107
+
108
+
109
+
110
+ # The entities within the Taverna 2 mdoel which contains the different
111
+ # elements of the workflows; processors, sinks, sources, etc...
112
+ class Dataflow
113
+ # This returns a DataflowAnnotation object.
114
+ attr_reader :annotations
115
+
116
+ # Retrieve the list of processors specific to the dataflow.
117
+ attr_reader :processors
118
+
119
+ # Retrieve the list of datalinks specific to the dataflow.
120
+ attr_reader :datalinks
121
+
122
+ # Retrieve the list of sources specific to the dataflow.
123
+ attr_reader :sources
124
+
125
+ # Retrieve the list of sinks specific to the dataflow.
126
+ attr_reader :sinks
127
+
128
+ # Retrieve the list of coordinations specific to the dataflow.
129
+ attr_reader :coordinations
130
+
131
+ # The unique identifier of the dataflow.
132
+ attr_accessor :dataflow_id
133
+
134
+ # Creates a new Dataflow object.
135
+ def initialize
136
+ @annotations = DataflowAnnotation.new
137
+ @processors = []
138
+ @datalinks = []
139
+ @sources = []
140
+ @sinks = []
141
+ @coordinations = []
142
+ end
143
+
144
+ # Retrieve beanshell processors specific to this dataflow.
145
+ def beanshells
146
+ @processors.select { |x| x.type == "beanshell" }
147
+ end
148
+ end
149
+
150
+
151
+
152
+ # This is the (shim) object within the workflow. This can be a beanshell,
153
+ # a webservice, a workflow, etc...
154
+ class Processor
155
+ # A string containing name of the processor.
156
+ attr_accessor :name
157
+
158
+ # A string containing the description of the processor if available.
159
+ # Returns nil otherwise.
160
+ attr_accessor :description
161
+
162
+ # A string for the type of processor, e.g. beanshell, workflow, webservice, etc...
163
+ attr_accessor :type
164
+
165
+ # For processors that have type == "dataflow", this is the the reference
166
+ # to the dataflow. For all other processor types, this is nil.
167
+ attr_accessor :dataflow_id
168
+
169
+ # This only has a value in beanshell processors. This is the actual script
170
+ # embedded with the processor which does all the "work"
171
+ attr_accessor :script
172
+
173
+ # This is a list of inputs that the processor can take in.
174
+ attr_accessor :inputs
175
+
176
+ # This is a list of outputs that the processor can produce.
177
+ attr_accessor :outputs
178
+ end
179
+
180
+
181
+
182
+ # This is the annotation object specific to the dataflow it belongs to.
183
+ # A DataflowAnnotation contains metadata about a given dataflow element.
184
+ class DataflowAnnotation
185
+ # The name used of the dataflow
186
+ attr_accessor :name
187
+
188
+ # A list of titles that have been assigned to the dataflow.
189
+ attr_accessor :titles
190
+
191
+ # A list ot descriptive strings about the dataflow.
192
+ attr_accessor :descriptions
193
+
194
+ # A list of authors of the dataflow
195
+ attr_accessor :authors
196
+ end
197
+
198
+
199
+
200
+ # This represents a connection between any of the following pair of entities:
201
+ # {processor -> processor}, {workflow -> workflow}, {workflow -> processor},
202
+ # and {processor -> workflow}.
203
+ class Datalink
204
+ # The name of the source (the starting point of the connection).
205
+ attr_accessor :source
206
+
207
+ # The name of the sink (the endpoint of the connection).
208
+ attr_accessor :sink
209
+ end
210
+
211
+
212
+
213
+ # This is a representation of the 'Run after...' function in Taverna
214
+ # where the selected processor or workflow is set to run after another.
215
+ class Coordination
216
+ # The name of the processor/workflow which is to run first.
217
+ attr_accessor :control
218
+
219
+ # The name of the processor/workflow which is to run after the control.
220
+ attr_accessor :target
221
+ end
222
+
223
+
224
+
225
+ # This is the start node of a Datalink. Each source has a name and a port
226
+ # which is seperated by a colon; ":".
227
+ # This is represented as "source of a processor:port_name".
228
+ # A string that does not contain a colon can often be returned, signifiying
229
+ # a workflow source as opposed to that of a processor.
230
+ class Source
231
+ attr_accessor :name
232
+ end
233
+
234
+
235
+
236
+ # This is the start node of a Datalink. Each sink has a name and a port
237
+ # which is seperated by a colon; ":".
238
+ # This is represented as "sink of a processor:port_name".
239
+ # A string that does not contain a colon can often be returned, signifiying
240
+ # a workflow sink as opposed to that of a processor.
241
+ class Sink
242
+ attr_accessor :name
243
+ end
244
+
245
+ end
@@ -0,0 +1,192 @@
1
+ require "libxml"
2
+
3
+ module T2Flow
4
+
5
+ class Parser
6
+ # Returns the model for the given t2flow_file.
7
+ # The method accepts objects of classes File and String only.
8
+ # ===Usage
9
+ # foo = ... # stuff to initialize foo here
10
+ # bar = T2Flow::Parser.new.parse(foo)
11
+ def parse(t2flow)
12
+ case t2flow.class.to_s
13
+ when /string/i: document = LibXML::XML::Parser.string(t2flow).parse
14
+ when /file/i: document = LibXML::XML::Parser.string(t2flow.read).parse
15
+ else raise "Error parsing file."
16
+ end
17
+
18
+ root = document.root
19
+ raise "Doesn't appear to be a workflow!" if root.name != "workflow"
20
+ version = root["version"]
21
+
22
+ create_model(root, version)
23
+ end
24
+
25
+ def create_model(element, version) # :nodoc:
26
+ model = Model.new
27
+
28
+ local_depends = element.find("//localDependencies")
29
+ if local_depends
30
+ local_depends.each do |dependency|
31
+ dependency.each do |dep|
32
+ model.dependencies = [] if model.dependencies.nil?
33
+ model.dependencies << dep.content unless dep.content =~ /^\s*$/
34
+ end
35
+ end
36
+ model.dependencies.uniq! if model.dependencies
37
+ end
38
+
39
+ element.each do |dataflow|
40
+ dataflow_obj = Dataflow.new
41
+ dataflow_obj.dataflow_id = dataflow["id"]
42
+
43
+ dataflow.each do |elt|
44
+ case elt.name
45
+ when "name"
46
+ dataflow_obj.annotations.name = elt.content
47
+ when "inputPorts"
48
+ elt.each { |port| add_source(dataflow_obj, port) }
49
+ when "outputPorts"
50
+ elt.each { |port| add_sink(dataflow_obj, port) }
51
+ when "processors"
52
+ elt.each { |proc| add_processor(dataflow_obj, proc) }
53
+ when "datalinks"
54
+ elt.each { |link| add_link(dataflow_obj, link) }
55
+ when "conditions"
56
+ elt.each { |coord| add_coordination(dataflow_obj, coord) }
57
+ when "annotations"
58
+ elt.each { |ann| add_annotation(dataflow_obj, ann) }
59
+ end # case elt.name
60
+ end # dataflow.each
61
+
62
+ model.dataflows << dataflow_obj
63
+ end # element.each
64
+
65
+ temp = model.processors.select { |x| x.type == "workflow" }
66
+ temp.each do |proc|
67
+ df = model.dataflow(proc.dataflow_id)
68
+ df.annotations.name = proc.name
69
+ end
70
+
71
+ return model
72
+ end
73
+
74
+ def add_source(dataflow, port) # :nodoc:
75
+ source = Source.new
76
+
77
+ port.each do |elt|
78
+ case elt.name
79
+ when "name": source.name = elt.content
80
+ end
81
+ end
82
+
83
+ dataflow.sources << source
84
+ end
85
+
86
+ def add_sink(dataflow, port) # :nodoc:
87
+ sink = Sink.new
88
+
89
+ port.each do |elt|
90
+ case elt.name
91
+ when "name": sink.name = elt.content
92
+ end
93
+ end
94
+
95
+ dataflow.sinks << sink
96
+ end
97
+
98
+ def add_processor(dataflow, element) # :nodoc:
99
+ processor = Processor.new
100
+
101
+ element.each do |elt|
102
+ case elt.name
103
+ when "name"
104
+ processor.name = elt.content
105
+ when "activities" # a processor can only have one kind of activity
106
+ activity = elt.child
107
+ activity.each do |node|
108
+ if node.name == "configBean"
109
+ activity_node = node.child
110
+
111
+ if node["encoding"] == "dataflow"
112
+ processor.dataflow_id = activity_node["ref"]
113
+ processor.type = "workflow"
114
+ else
115
+ processor.type = activity_node.name.split(".")[-2]
116
+
117
+ activity_node.each do |value_node|
118
+ case value_node.name
119
+ when "script"
120
+ processor.script = value_node.content
121
+ when "inputs"
122
+ value_node.each { |input|
123
+ input.each { |x|
124
+ processor.inputs = [] if processor.inputs.nil?
125
+ processor.inputs << x.content if x.name == "name"
126
+ }
127
+ }
128
+ when "outputs"
129
+ value_node.each { |output|
130
+ output.each { |x|
131
+ processor.outputs = [] if processor.outputs.nil?
132
+ processor.outputs << x.content if x.name == "name"
133
+ }
134
+ }
135
+ end # case value_node.name
136
+ end # activity_node.each
137
+ end # if else node["encoding"] == "dataflow"
138
+ end # if node.name == "configBean"
139
+ end # activity.each
140
+ end # case elt.name
141
+ end # element.each
142
+
143
+ dataflow.processors << processor
144
+ end
145
+
146
+ def add_link(dataflow, link) # :nodoc:
147
+ datalink = Datalink.new
148
+
149
+ link.each do |sink_source|
150
+ case sink_source.name
151
+ when "sink"
152
+ datalink.sink = sink_source.first.content
153
+ datalink.sink += ":" + sink_source.last.content if sink_source["type"] == "processor"
154
+ when "source"
155
+ datalink.source = sink_source.first.content
156
+ datalink.source += ":" + sink_source.last.content if sink_source["type"] == "processor"
157
+ end
158
+ end
159
+
160
+ dataflow.datalinks << datalink
161
+ end
162
+
163
+ def add_coordination(dataflow, condition) # :nodoc:
164
+ coordination = Coordination.new
165
+
166
+ coordination.control = condition["control"]
167
+ coordination.target = condition["target"]
168
+
169
+ dataflow.coordinations << coordination
170
+ end
171
+
172
+ def add_annotation(dataflow, annotation) # :nodoc:
173
+ node = LibXML::XML::Parser.string("#{annotation}").parse
174
+ content_node = node.find_first("//annotationBean")
175
+ content = content_node.child.next.content
176
+
177
+ case content_node["class"]
178
+ when /freetextdescription/i
179
+ dataflow.annotations.descriptions = [] unless dataflow.annotations.descriptions
180
+ dataflow.annotations.descriptions << content
181
+ when /descriptivetitle/i
182
+ dataflow.annotations.titles = [] unless dataflow.annotations.titles
183
+ dataflow.annotations.titles << content
184
+ when /author/i
185
+ dataflow.annotations.authors = [] unless dataflow.annotations.authors
186
+ dataflow.annotations.authors << content
187
+ end # case
188
+ end
189
+
190
+ end
191
+
192
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: myGrid-taverna-t2flow
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Emmanuel Tagarira
8
+ autorequire: t2flow
9
+ bindir: bin
10
+ cert_chain:
11
+ date: 2009-08-18 00:00:00 -07:00
12
+ default_executable:
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: libxml-ruby
16
+ type: :runtime
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.1.3
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: rdoc
26
+ type: :runtime
27
+ version_requirement:
28
+ version_requirements: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 2.4.3
33
+ version:
34
+ - !ruby/object:Gem::Dependency
35
+ name: darkfish-rdoc
36
+ type: :runtime
37
+ version_requirement:
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 1.1.5
43
+ version:
44
+ description: This a gem developed by myGrid for the purpose of interacting with Taverna 2 workflows. An example use would be the image genaration for the model representing Taverna 2 workflows as used in myExperiment.
45
+ email: emmanuel.tagarira@student.manchester.ac.uk
46
+ executables: []
47
+
48
+ extensions: []
49
+
50
+ extra_rdoc_files:
51
+ - README
52
+ - LICENCE
53
+ files:
54
+ - lib/t2flow
55
+ - lib/t2flow/dot.rb
56
+ - lib/t2flow/model.rb
57
+ - lib/t2flow/parser.rb
58
+ - README
59
+ - LICENCE
60
+ has_rdoc: true
61
+ homepage: http://www.mygrid.org.uk/
62
+ licenses:
63
+ post_install_message:
64
+ rdoc_options:
65
+ - -N
66
+ - --tab-width=2
67
+ - --main=README
68
+ - --exclude='scufl.gemspec|test'
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 1.0.1
76
+ version:
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: "0"
82
+ version:
83
+ requirements: []
84
+
85
+ rubyforge_project:
86
+ rubygems_version: 1.3.5
87
+ signing_key:
88
+ specification_version: 1
89
+ summary: Support for interacting with the Taverna 2 workflow system (T2Flow).
90
+ test_files: []
91
+