bio 1.5.2 → 1.6.0.pre.20181210
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +12 -11
- data/ChangeLog +14 -3106
- data/{gemfiles/Gemfile.travis-ruby2.2 → Gemfile} +0 -1
- data/KNOWN_ISSUES.rdoc +0 -5
- data/README.rdoc +11 -18
- data/RELEASE_NOTES.rdoc +34 -291
- data/Rakefile +13 -9
- data/appveyor.yml +21 -0
- data/bioruby.gemspec +7 -78
- data/bioruby.gemspec.erb +8 -27
- data/doc/ChangeLog-1.5.0 +2919 -0
- data/doc/RELEASE_NOTES-1.5.0.rdoc +285 -0
- data/doc/Tutorial.rd +6 -108
- data/doc/Tutorial.rd.html +19 -98
- data/gemfiles/Gemfile.travis-jruby1.8 +3 -5
- data/gemfiles/Gemfile.travis-jruby1.9 +0 -3
- data/gemfiles/Gemfile.travis-rbx +0 -1
- data/gemfiles/Gemfile.travis-ruby1.8 +4 -4
- data/gemfiles/Gemfile.travis-ruby1.9 +0 -1
- data/gemfiles/prepare-gemspec.rb +4 -0
- data/lib/bio.rb +0 -10
- data/lib/bio/data/codontable.rb +99 -3
- data/lib/bio/io/togows.rb +5 -5
- data/lib/bio/version.rb +6 -8
- data/sample/test_restriction_enzyme_long.rb +1 -1
- data/test/unit/bio/data/test_codontable.rb +3 -0
- metadata +11 -77
- data/bin/bioruby +0 -47
- data/bin/br_biofetch.rb +0 -71
- data/bin/br_bioflat.rb +0 -293
- data/bin/br_biogetseq.rb +0 -45
- data/bin/br_pmfetch.rb +0 -422
- data/lib/bio/db/biosql/biosql_to_biosequence.rb +0 -78
- data/lib/bio/db/biosql/sequence.rb +0 -444
- data/lib/bio/db/phyloxml/phyloxml.xsd +0 -582
- data/lib/bio/db/phyloxml/phyloxml_elements.rb +0 -1197
- data/lib/bio/db/phyloxml/phyloxml_parser.rb +0 -1001
- data/lib/bio/db/phyloxml/phyloxml_writer.rb +0 -227
- data/lib/bio/io/biosql/ar-biosql.rb +0 -257
- data/lib/bio/io/biosql/biosql.rb +0 -39
- data/lib/bio/io/biosql/config/database.yml +0 -21
- data/lib/bio/io/sql.rb +0 -79
- data/lib/bio/shell.rb +0 -44
- data/lib/bio/shell/core.rb +0 -578
- data/lib/bio/shell/demo.rb +0 -146
- data/lib/bio/shell/interface.rb +0 -217
- data/lib/bio/shell/irb.rb +0 -94
- data/lib/bio/shell/object.rb +0 -71
- data/lib/bio/shell/plugin/blast.rb +0 -42
- data/lib/bio/shell/plugin/codon.rb +0 -218
- data/lib/bio/shell/plugin/das.rb +0 -58
- data/lib/bio/shell/plugin/emboss.rb +0 -23
- data/lib/bio/shell/plugin/entry.rb +0 -137
- data/lib/bio/shell/plugin/flatfile.rb +0 -101
- data/lib/bio/shell/plugin/midi.rb +0 -430
- data/lib/bio/shell/plugin/ncbirest.rb +0 -68
- data/lib/bio/shell/plugin/obda.rb +0 -45
- data/lib/bio/shell/plugin/psort.rb +0 -56
- data/lib/bio/shell/plugin/seq.rb +0 -248
- data/lib/bio/shell/plugin/togows.rb +0 -40
- data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/bioruby_generator.rb +0 -29
- data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/_classes.rhtml +0 -4
- data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/_log.rhtml +0 -27
- data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/_methods.rhtml +0 -11
- data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/_modules.rhtml +0 -4
- data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/_variables.rhtml +0 -7
- data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby-bg.gif +0 -0
- data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby-gem.png +0 -0
- data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby-link.gif +0 -0
- data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby.css +0 -368
- data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby.rhtml +0 -47
- data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby_controller.rb +0 -144
- data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby_helper.rb +0 -47
- data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/commands.rhtml +0 -8
- data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/history.rhtml +0 -10
- data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/index.rhtml +0 -26
- data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/spinner.gif +0 -0
- data/lib/bio/shell/script.rb +0 -25
- data/lib/bio/shell/setup.rb +0 -108
- data/lib/bio/shell/web.rb +0 -102
- data/sample/test_phyloxml_big.rb +0 -205
- data/test/data/phyloxml/apaf.xml +0 -666
- data/test/data/phyloxml/bcl_2.xml +0 -2097
- data/test/data/phyloxml/made_up.xml +0 -144
- data/test/data/phyloxml/ncbi_taxonomy_mollusca_short.xml +0 -65
- data/test/data/phyloxml/phyloxml_examples.xml +0 -415
- data/test/unit/bio/db/biosql/tc_biosql.rb +0 -114
- data/test/unit/bio/db/biosql/ts_suite_biosql.rb +0 -8
- data/test/unit/bio/db/test_phyloxml.rb +0 -821
- data/test/unit/bio/db/test_phyloxml_writer.rb +0 -334
- data/test/unit/bio/shell/plugin/test_seq.rb +0 -187
- data/test/unit/bio/test_shell.rb +0 -20
@@ -1,1197 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# = bio/db/phyloxml_elements.rb - PhyloXML Element classes
|
3
|
-
#
|
4
|
-
# Copyright:: Copyright (C) 2009
|
5
|
-
# Diana Jaunzeikare <latvianlinuxgirl@gmail.com>
|
6
|
-
# License:: The Ruby License
|
7
|
-
#
|
8
|
-
#
|
9
|
-
# == Description
|
10
|
-
#
|
11
|
-
# This file containts the classes to represent PhyloXML elements.
|
12
|
-
#
|
13
|
-
# == References
|
14
|
-
#
|
15
|
-
# * http://www.phyloxml.org
|
16
|
-
#
|
17
|
-
# * https://www.nescent.org/wg_phyloinformatics/PhyloSoC:PhyloXML_support_in_BioRuby
|
18
|
-
|
19
|
-
require 'bio/tree'
|
20
|
-
require 'bio/sequence'
|
21
|
-
require 'bio/reference'
|
22
|
-
|
23
|
-
# Autoload definition
|
24
|
-
module Bio
|
25
|
-
module PhyloXML
|
26
|
-
autoload :Parser, 'bio/db/phyloxml/phyloxml_parser'
|
27
|
-
autoload :Writer, 'bio/db/phyloxml/phyloxml_writer'
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
require 'libxml'
|
32
|
-
|
33
|
-
module Bio
|
34
|
-
|
35
|
-
# This is general Taxonomy class.
|
36
|
-
|
37
|
-
class Taxonomy
|
38
|
-
#pattern = [a-zA-Z0-9_]{2,10} Can refer to any code/abbreviation/mnemonic, such as Bsu for Bacillus subtilis.
|
39
|
-
attr_accessor :code
|
40
|
-
|
41
|
-
# String.
|
42
|
-
attr_accessor :scientific_name
|
43
|
-
# An array of strings
|
44
|
-
attr_accessor :common_names
|
45
|
-
|
46
|
-
# value comes from list: domain kingdom, subkingdom, branch, infrakingdom,
|
47
|
-
# superphylum, phylum, subphylum, infraphylum, microphylum, superdivision,
|
48
|
-
# division, subdivision, infradivision, superclass, class, subclass,
|
49
|
-
# infraclass, superlegion, legion, sublegion, infralegion, supercohort,
|
50
|
-
# cohort, subcohort, infracohort, superorder, order, suborder,
|
51
|
-
# superfamily, family, subfamily, supertribe, tribe, subtribe, infratribe,
|
52
|
-
# genus, subgenus, superspecies, species, subspecies, variety, subvariety,
|
53
|
-
# form, subform, cultivar, unknown, other
|
54
|
-
attr_accessor :rank
|
55
|
-
|
56
|
-
# is used to keep the authority, such as 'J. G. Cooper, 1863', associated with the 'scientific_name'.
|
57
|
-
attr_accessor :authority
|
58
|
-
|
59
|
-
# An array of strings. Holds synonyms for scientific names or common names.
|
60
|
-
attr_accessor :synonyms
|
61
|
-
|
62
|
-
|
63
|
-
def initialize
|
64
|
-
@common_names = []
|
65
|
-
@synonyms = []
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
module PhyloXML
|
70
|
-
|
71
|
-
|
72
|
-
# Taxonomy class
|
73
|
-
class Taxonomy < Bio::Taxonomy
|
74
|
-
# String. Unique identifier of a taxon.
|
75
|
-
attr_accessor :taxonomy_id
|
76
|
-
#Used to link other elements to a taxonomy (on the xml-level)
|
77
|
-
attr_accessor :id_source
|
78
|
-
# Uri object
|
79
|
-
attr_accessor :uri
|
80
|
-
|
81
|
-
# Array of Other objects. Used to save additional information from other than
|
82
|
-
# PhyloXML namspace.
|
83
|
-
attr_accessor :other
|
84
|
-
|
85
|
-
def initialize
|
86
|
-
super
|
87
|
-
@other = []
|
88
|
-
end
|
89
|
-
|
90
|
-
# Converts elements to xml representation. Called by PhyloXML::Writer class.
|
91
|
-
def to_xml
|
92
|
-
taxonomy = LibXML::XML::Node.new('taxonomy')
|
93
|
-
taxonomy["type"] = @type if (defined? @type) && @type
|
94
|
-
taxonomy["id_source"] = @id_source if (defined? @id_source) && @id_source
|
95
|
-
|
96
|
-
PhyloXML::Writer.generate_xml(taxonomy, self, [[:complex, 'id', (defined? @taxonomy_id) ? @taxonomy_id : nil],
|
97
|
-
[:pattern, 'code', (defined? @code) ? @code : nil, Regexp.new("^[a-zA-Z0-9_]{2,10}$")],
|
98
|
-
[:simple, 'scientific_name', (defined? @scientific_name) ? @scientific_name : nil],
|
99
|
-
[:simple, 'authority', (defined? @authority) ? @authority : nil],
|
100
|
-
[:simplearr, 'common_name', (defined? @common_names) ? @common_names : nil],
|
101
|
-
[:simplearr, 'synonym', (defined? @synonyms) ? @synonyms : nil],
|
102
|
-
[:simple, 'rank', (defined? @rank) ? @rank : nil],
|
103
|
-
[:complex, 'uri',(defined? @uri) ? @uri : nil]])
|
104
|
-
#@todo anything else
|
105
|
-
|
106
|
-
|
107
|
-
return taxonomy
|
108
|
-
end
|
109
|
-
|
110
|
-
end
|
111
|
-
|
112
|
-
# Object to hold one phylogeny element (and its subelements.) Extended version of Bio::Tree.
|
113
|
-
class Tree < Bio::Tree
|
114
|
-
# String. Name of tree (name subelement of phylogeny element).
|
115
|
-
attr_accessor :name
|
116
|
-
|
117
|
-
# Id object.
|
118
|
-
attr_accessor :phylogeny_id
|
119
|
-
|
120
|
-
# String. Description of tree.
|
121
|
-
attr_accessor :description
|
122
|
-
|
123
|
-
# Boolean. Can be used to indicate that the phylogeny is not allowed to be rooted differently (i.e. because it is associated with root dependent data, such as gene duplications).
|
124
|
-
attr_accessor :rerootable
|
125
|
-
|
126
|
-
# Boolean. Required element.
|
127
|
-
attr_accessor :rooted
|
128
|
-
|
129
|
-
# Array of Property object. Allows for typed and referenced properties from external resources to be attached.
|
130
|
-
attr_accessor :properties
|
131
|
-
|
132
|
-
# CladeRelation object. This is used to express a typed relationship between two clades. For example it could be used to describe multiple parents of a clade.
|
133
|
-
attr_accessor :clade_relations
|
134
|
-
|
135
|
-
# SequenceRelation object. This is used to express a typed relationship between two sequences. For example it could be used to describe an orthology.
|
136
|
-
attr_accessor :sequence_relations
|
137
|
-
|
138
|
-
# Array of confidence object
|
139
|
-
attr_accessor :confidences
|
140
|
-
|
141
|
-
# String.
|
142
|
-
attr_accessor :branch_length_unit
|
143
|
-
|
144
|
-
# String. Indicate the type of phylogeny (i.e. 'gene tree').
|
145
|
-
attr_accessor :type
|
146
|
-
|
147
|
-
# String. Date
|
148
|
-
attr_accessor :date
|
149
|
-
|
150
|
-
# Array of Other objects. Used to save additional information from other than
|
151
|
-
# PhyloXML namspace.
|
152
|
-
attr_accessor :other
|
153
|
-
|
154
|
-
def initialize
|
155
|
-
super
|
156
|
-
@sequence_relations = []
|
157
|
-
@clade_relations = []
|
158
|
-
@confidences = []
|
159
|
-
@properties = []
|
160
|
-
@other = []
|
161
|
-
end
|
162
|
-
|
163
|
-
end
|
164
|
-
|
165
|
-
|
166
|
-
# == Description
|
167
|
-
# Class to hold clade element of phyloXML.
|
168
|
-
class Node
|
169
|
-
|
170
|
-
# Events at the root node of a clade (e.g. one gene duplication).
|
171
|
-
attr_accessor :events
|
172
|
-
|
173
|
-
# String. Used to link other elements to a clade (node) (on the xml-level).
|
174
|
-
attr_accessor :id_source
|
175
|
-
|
176
|
-
# String. Name of the node.
|
177
|
-
attr_accessor :name
|
178
|
-
|
179
|
-
# Float. Branch width for this node (including parent branch). Applies for the whole clade unless overwritten in sub-clades.
|
180
|
-
attr_reader :width
|
181
|
-
|
182
|
-
def width=(str)
|
183
|
-
@width = str.to_f
|
184
|
-
end
|
185
|
-
|
186
|
-
# Array of Taxonomy objects. Describes taxonomic information for a clade.
|
187
|
-
attr_accessor :taxonomies
|
188
|
-
|
189
|
-
# Array of Confidence objects. Indicates the support for a clade/parent branch.
|
190
|
-
attr_accessor :confidences
|
191
|
-
|
192
|
-
# BranchColor object. Apply for the whole clade unless overwritten in sub-clade.
|
193
|
-
attr_accessor :color
|
194
|
-
|
195
|
-
# Id object
|
196
|
-
attr_accessor :node_id
|
197
|
-
|
198
|
-
# Array of Sequence objects. Represents a molecular sequence (Protein, DNA, RNA) associated with a node.
|
199
|
-
attr_accessor :sequences
|
200
|
-
|
201
|
-
# BinaryCharacters object. The names and/or counts of binary characters present, gained, and lost at the root of a clade.
|
202
|
-
attr_accessor :binary_characters
|
203
|
-
|
204
|
-
# Array of Distribution objects. The geographic distribution of the items of a clade (species, sequences), intended for phylogeographic applications.
|
205
|
-
attr_accessor :distributions
|
206
|
-
|
207
|
-
# Date object. A date associated with a clade/node.
|
208
|
-
attr_accessor :date
|
209
|
-
|
210
|
-
#Array of Reference objects. A literature reference for a clade.
|
211
|
-
attr_accessor :references
|
212
|
-
|
213
|
-
#An array of Property objects, for example depth for sea animals.
|
214
|
-
attr_accessor :properties
|
215
|
-
|
216
|
-
# Array of Other objects. Used to save additional information from other than
|
217
|
-
# PhyloXML namspace.
|
218
|
-
attr_accessor :other
|
219
|
-
|
220
|
-
def initialize
|
221
|
-
@confidences = []
|
222
|
-
@sequences = []
|
223
|
-
@taxonomies = []
|
224
|
-
@distributions = []
|
225
|
-
@references = []
|
226
|
-
@properties = []
|
227
|
-
@other = []
|
228
|
-
end
|
229
|
-
|
230
|
-
|
231
|
-
# Converts to a Bio::Tree::Node object. If it contains several taxonomies
|
232
|
-
# Bio::Tree::Node#scientific name will get the scientific name of the first
|
233
|
-
# taxonomy.
|
234
|
-
#
|
235
|
-
# If there are several confidence values, the first with bootstrap type will
|
236
|
-
# be returned as Bio::Tree::Node#bootstrap
|
237
|
-
#
|
238
|
-
# tree = phyloxmlparser.next_tree
|
239
|
-
#
|
240
|
-
# node = tree.get_node_by_name("A").to_biotreenode
|
241
|
-
#
|
242
|
-
# ---
|
243
|
-
# *Returns*:: Bio::Tree::Node
|
244
|
-
def to_biotreenode
|
245
|
-
node = Bio::Tree::Node.new
|
246
|
-
node.name = @name
|
247
|
-
node.scientific_name = @taxonomies[0].scientific_name if not @taxonomies.empty?
|
248
|
-
#@todo what if there are more?
|
249
|
-
node.taxonomy_id = @taxonomies[0].taxononmy_id if @taxonomies[0] != nil
|
250
|
-
|
251
|
-
if not @confidences.empty?
|
252
|
-
@confidences.each do |confidence|
|
253
|
-
if confidence.type == "bootstrap"
|
254
|
-
node.bootstrap = confidence.value
|
255
|
-
break
|
256
|
-
end
|
257
|
-
end
|
258
|
-
end
|
259
|
-
return node
|
260
|
-
end
|
261
|
-
|
262
|
-
# Extracts the relevant information from node (specifically taxonomy and
|
263
|
-
# sequence) to create Bio::Sequence object. Node can have several sequences,
|
264
|
-
# so parameter to this method is to specify which sequence to extract.
|
265
|
-
#
|
266
|
-
# ---
|
267
|
-
# *Returns*:: Bio::Sequence
|
268
|
-
def extract_biosequence(seq_i=0)
|
269
|
-
|
270
|
-
seq = @sequences[seq_i].to_biosequence
|
271
|
-
seq.classification = []
|
272
|
-
@taxonomies.each do |t|
|
273
|
-
seq.classification << t.scientific_name
|
274
|
-
if t.rank == "species"
|
275
|
-
seq.species = t.scientific_name
|
276
|
-
end
|
277
|
-
end
|
278
|
-
|
279
|
-
#seq.division => .. http://www.ebi.ac.uk/embl/Documentation/User_manual/usrman.html#3_2
|
280
|
-
# It doesn't seem there is anything in PhyloXML corresponding to this.
|
281
|
-
|
282
|
-
return seq
|
283
|
-
end
|
284
|
-
|
285
|
-
# Converts elements to xml representation. Called by PhyloXML::Writer class.
|
286
|
-
def to_xml(branch_length, write_branch_length_as_subelement)
|
287
|
-
clade = LibXML::XML::Node.new('clade')
|
288
|
-
|
289
|
-
PhyloXML::Writer.generate_xml(clade, self, [[:simple, 'name', (defined? @name) ? @name : nil]])
|
290
|
-
|
291
|
-
if branch_length != nil
|
292
|
-
if write_branch_length_as_subelement
|
293
|
-
clade << LibXML::XML::Node.new('branch_length', branch_length.to_s)
|
294
|
-
else
|
295
|
-
clade["branch_length"] = branch_length.to_s
|
296
|
-
end
|
297
|
-
end
|
298
|
-
|
299
|
-
#generate all elements, except clade
|
300
|
-
PhyloXML::Writer.generate_xml(clade, self, [
|
301
|
-
[:attr, "id_source"],
|
302
|
-
[:objarr, 'confidence', 'confidences'],
|
303
|
-
[:simple, 'width', (defined? @width) ? @width : nil],
|
304
|
-
[:complex, 'branch_color', (defined? @branch_color) ? @branch_color : nil],
|
305
|
-
[:simple, 'node_id', (defined? @node_id) ? @node_id : nil],
|
306
|
-
[:objarr, 'taxonomy', 'taxonomies'],
|
307
|
-
[:objarr, 'sequence', 'sequences'],
|
308
|
-
[:complex, 'events', (defined? @events) ? @events : nil],
|
309
|
-
[:complex, 'binary_characters', (defined? @binary_characters) ? @binary_characters : nil],
|
310
|
-
[:objarr, 'distribution', 'distributions'],
|
311
|
-
[:complex, 'date', (defined? @date) ? @date : nil],
|
312
|
-
[:objarr, 'reference', 'references'],
|
313
|
-
[:objarr, 'propery', 'properties']])
|
314
|
-
|
315
|
-
return clade
|
316
|
-
end
|
317
|
-
|
318
|
-
end #Node
|
319
|
-
|
320
|
-
# == Description
|
321
|
-
# Events at the root node of a clade (e.g. one gene duplication).
|
322
|
-
class Events
|
323
|
-
#value comes from list: transfer, fusion, speciation_or_duplication, other, mixed, unassigned
|
324
|
-
attr_reader :type
|
325
|
-
|
326
|
-
# Integer
|
327
|
-
attr_reader :duplications, :speciations, :losses
|
328
|
-
|
329
|
-
# Confidence object
|
330
|
-
attr_reader :confidence
|
331
|
-
|
332
|
-
#---
|
333
|
-
#def confidence=(type, value)
|
334
|
-
# @confidence = Confidence.new(type, value)
|
335
|
-
#end
|
336
|
-
#+++
|
337
|
-
|
338
|
-
# Confidence object
|
339
|
-
def confidence=(conf)
|
340
|
-
@confidence = conf
|
341
|
-
end
|
342
|
-
|
343
|
-
# Integer
|
344
|
-
def duplications=(str)
|
345
|
-
@duplications = str.to_i
|
346
|
-
end
|
347
|
-
|
348
|
-
# Integer
|
349
|
-
def losses=(str)
|
350
|
-
@losses = str.to_i
|
351
|
-
end
|
352
|
-
|
353
|
-
# Integer
|
354
|
-
def speciations=(str)
|
355
|
-
@speciations=str.to_i
|
356
|
-
end
|
357
|
-
|
358
|
-
#value comes from list: transfer, fusion, speciation_or_duplication, other, mixed, unassigned
|
359
|
-
def type=(str)
|
360
|
-
@type = str
|
361
|
-
#@todo add unit test for this
|
362
|
-
if not ['transfer','fusion','speciation_or_duplication','other','mixed', 'unassigned'].include?(str)
|
363
|
-
raise "Warning #{str} is not one of the allowed values"
|
364
|
-
end
|
365
|
-
end
|
366
|
-
|
367
|
-
# Converts elements to xml representation. Called by PhyloXML::Writer class.
|
368
|
-
def to_xml
|
369
|
-
#@todo add unit test
|
370
|
-
events = LibXML::XML::Node.new('events')
|
371
|
-
PhyloXML::Writer.generate_xml(events, self, [
|
372
|
-
[:simple, 'type', (defined? @type) ? @type : nil],
|
373
|
-
[:simple, 'duplications', (defined? @duplications) ? @duplications : nil],
|
374
|
-
[:simple, 'speciations', (defined? @speciations) ? @speciations : nil],
|
375
|
-
[:simple, 'losses', (defined? @losses) ? @losses : nil],
|
376
|
-
[:complex, 'confidence', (defined? @confidence) ? @confidence : nil]])
|
377
|
-
return events
|
378
|
-
end
|
379
|
-
|
380
|
-
end
|
381
|
-
|
382
|
-
# A general purpose confidence element. For example this can be used to express
|
383
|
-
# the bootstrap support value of a clade (in which case the 'type' attribute
|
384
|
-
# is 'bootstrap').
|
385
|
-
class Confidence
|
386
|
-
# String. The type of confidence measure, for example, bootstrap.
|
387
|
-
attr_accessor :type
|
388
|
-
# Float. The value of confidence measure.
|
389
|
-
attr_accessor :value
|
390
|
-
|
391
|
-
def initialize(type, value)
|
392
|
-
@type = type
|
393
|
-
@value = value.to_f
|
394
|
-
end
|
395
|
-
|
396
|
-
# Converts elements to xml representation. Called by PhyloXML::Writer class.
|
397
|
-
def to_xml
|
398
|
-
if @type == nil
|
399
|
-
raise "Type is a required attribute for confidence."
|
400
|
-
else
|
401
|
-
confidence = LibXML::XML::Node.new('confidence', @value.to_s)
|
402
|
-
confidence["type"] = @type
|
403
|
-
return confidence
|
404
|
-
end
|
405
|
-
end
|
406
|
-
end
|
407
|
-
|
408
|
-
# == Description
|
409
|
-
#
|
410
|
-
# The geographic distribution of the items of a clade (species, sequences),
|
411
|
-
# intended for phylogeographic applications.
|
412
|
-
class Distribution
|
413
|
-
# String. Free text description of location.
|
414
|
-
attr_accessor :desc
|
415
|
-
# Array of Point objects. Holds coordinates of the location.
|
416
|
-
attr_accessor :points
|
417
|
-
# Array of Polygon objects.
|
418
|
-
attr_accessor :polygons
|
419
|
-
|
420
|
-
def initialize
|
421
|
-
@points = []
|
422
|
-
@polygons = []
|
423
|
-
end
|
424
|
-
|
425
|
-
|
426
|
-
# Converts elements to xml representation. Called by PhyloXML::Writer class.
|
427
|
-
def to_xml
|
428
|
-
distr = LibXML::XML::Node.new('distribution')
|
429
|
-
PhyloXML::Writer.generate_xml(distr, self, [
|
430
|
-
[:simple, 'desc', @desc],
|
431
|
-
[:objarr, 'point', 'points'],
|
432
|
-
[:objarr, 'polygon', 'polygons']])
|
433
|
-
return distr
|
434
|
-
end
|
435
|
-
|
436
|
-
end #Distribution class
|
437
|
-
|
438
|
-
|
439
|
-
# == Description
|
440
|
-
#
|
441
|
-
# The coordinates of a point with an optional altitude. Required attribute
|
442
|
-
# 'geodetic_datum' is used to indicate the geodetic datum (also called
|
443
|
-
# 'map datum'), for example Google's KML uses 'WGS84'.
|
444
|
-
class Point
|
445
|
-
# Float. Latitude
|
446
|
-
attr_reader :lat
|
447
|
-
|
448
|
-
# Float. Longitute
|
449
|
-
attr_reader :long
|
450
|
-
|
451
|
-
# Float. Altitude
|
452
|
-
attr_reader :alt
|
453
|
-
|
454
|
-
# String. Altitude unit.
|
455
|
-
attr_accessor :alt_unit
|
456
|
-
|
457
|
-
# Geodedic datum / map datum
|
458
|
-
attr_accessor :geodetic_datum
|
459
|
-
|
460
|
-
# Float. Latitude
|
461
|
-
def lat=(str)
|
462
|
-
@lat = str.to_f unless str.nil?
|
463
|
-
end
|
464
|
-
|
465
|
-
# Float. Longitute
|
466
|
-
def long=(str)
|
467
|
-
@long = str.to_f unless str.nil?
|
468
|
-
end
|
469
|
-
|
470
|
-
# Float. Altitude
|
471
|
-
def alt=(str)
|
472
|
-
@alt = str.to_f unless str.nil?
|
473
|
-
end
|
474
|
-
|
475
|
-
# Converts elements to xml representation. Called by PhyloXML::Writer class.
|
476
|
-
def to_xml
|
477
|
-
raise "Geodedic datum is a required attribute of Point element." if @geodetic_datum.nil?
|
478
|
-
|
479
|
-
p = LibXML::XML::Node.new('point')
|
480
|
-
p["geodetic_datum"] = @geodetic_datum
|
481
|
-
p["alt_unit"] = @alt_unit if @alt_unit != nil
|
482
|
-
PhyloXML::Writer.generate_xml(p, self, [
|
483
|
-
[:simple, 'lat', @lat],
|
484
|
-
[:simple, 'long', @long],
|
485
|
-
[:simple, 'alt', @alt]])
|
486
|
-
return p
|
487
|
-
#@todo check if characters are correctly generated, like Zuric
|
488
|
-
end
|
489
|
-
|
490
|
-
end
|
491
|
-
|
492
|
-
|
493
|
-
# == Description
|
494
|
-
#
|
495
|
-
# A polygon defined by a list of Points objects.
|
496
|
-
class Polygon
|
497
|
-
# Array of Point objects.
|
498
|
-
attr_accessor :points
|
499
|
-
|
500
|
-
def initialize
|
501
|
-
@points = []
|
502
|
-
end
|
503
|
-
|
504
|
-
|
505
|
-
# Converts elements to xml representation. Called by PhyloXML::Writer class.
|
506
|
-
def to_xml
|
507
|
-
if @points.length > 2
|
508
|
-
pol = LibXML::XML::Node.new('polygon')
|
509
|
-
@points.each do |p|
|
510
|
-
pol << p.to_xml
|
511
|
-
end
|
512
|
-
return pol
|
513
|
-
end
|
514
|
-
end
|
515
|
-
|
516
|
-
|
517
|
-
end
|
518
|
-
|
519
|
-
# == Description
|
520
|
-
# Element Sequence is used to represent a molecular sequence (Protein, DNA,
|
521
|
-
# RNA) associated with a node.
|
522
|
-
class Sequence
|
523
|
-
# Type of sequence (rna, dna, protein)
|
524
|
-
attr_accessor :type
|
525
|
-
|
526
|
-
# Full name (e.g. muscle Actin )
|
527
|
-
attr_accessor :name
|
528
|
-
|
529
|
-
# String. Used to link with other elements.
|
530
|
-
attr_accessor :id_source
|
531
|
-
|
532
|
-
# String. One intended use for 'id_ref' is to link a sequence to a taxonomy
|
533
|
-
# (via the taxonomy's 'id_source') in the case of multiple sequences and taxonomies per node.
|
534
|
-
attr_accessor :id_ref
|
535
|
-
|
536
|
-
# short (maximal ten characters) symbol of the sequence (e.g. 'ACTM')
|
537
|
-
attr_accessor :symbol
|
538
|
-
# Accession object. Holds source and identifier for the sequence.
|
539
|
-
attr_accessor :accession
|
540
|
-
# String. Location of a sequence on a genome/chromosome
|
541
|
-
attr_accessor :location
|
542
|
-
# String. The actual sequence is stored here.
|
543
|
-
attr_reader :mol_seq
|
544
|
-
|
545
|
-
# Boolean. used to indicated that this molecular sequence is aligned with
|
546
|
-
# all other sequences in the same phylogeny for which 'is aligned' is true
|
547
|
-
# as well (which, in most cases, means that gaps were introduced, and that
|
548
|
-
# all sequences for which 'is aligned' is true must have the same length)
|
549
|
-
attr_reader :is_aligned
|
550
|
-
|
551
|
-
# Uri object
|
552
|
-
attr_accessor :uri
|
553
|
-
# Array of Annotation objects. Annotations of molecular sequence.
|
554
|
-
attr_accessor :annotations
|
555
|
-
# DomainArchitecture object. Describes domain architecture of a protein.
|
556
|
-
attr_accessor :domain_architecture
|
557
|
-
|
558
|
-
# Array of Other objects. Used to save additional information from other than
|
559
|
-
# PhyloXML namspace.
|
560
|
-
attr_accessor :other
|
561
|
-
|
562
|
-
def initialize
|
563
|
-
@annotations = []
|
564
|
-
@other = []
|
565
|
-
end
|
566
|
-
|
567
|
-
def is_aligned=(str)
|
568
|
-
if str=='true'
|
569
|
-
@is_aligned=true
|
570
|
-
elsif str=='false'
|
571
|
-
@is_aligned = false
|
572
|
-
else
|
573
|
-
@is_aligned = nil
|
574
|
-
end
|
575
|
-
end
|
576
|
-
|
577
|
-
def is_aligned?
|
578
|
-
@is_aligned
|
579
|
-
end
|
580
|
-
|
581
|
-
def mol_seq=(str)
|
582
|
-
if str =~ /^[a-zA-Z\.\-\?\*_]+$/
|
583
|
-
@mol_seq = str
|
584
|
-
else
|
585
|
-
raise "mol_seq element of Sequence does not follow the pattern."
|
586
|
-
end
|
587
|
-
end
|
588
|
-
|
589
|
-
# Converts elements to xml representation. Called by PhyloXML::Writer class.
|
590
|
-
def to_xml
|
591
|
-
|
592
|
-
seq = LibXML::XML::Node.new('sequence')
|
593
|
-
if (defined? @type) && @type
|
594
|
-
if ["dna", "rna", "protein"].include?(@type)
|
595
|
-
seq["type"] = @type
|
596
|
-
else
|
597
|
-
raise "Type attribute of Sequence has to be one of dna, rna or a."
|
598
|
-
end
|
599
|
-
end
|
600
|
-
|
601
|
-
PhyloXML::Writer.generate_xml(seq, self, [
|
602
|
-
[:attr, 'id_source'],
|
603
|
-
[:attr, 'id_ref'],
|
604
|
-
[:pattern, 'symbol', (defined? @symbol) ? @symbol : nil, Regexp.new("^\\S{1,10}$")],
|
605
|
-
[:complex, 'accession', (defined? @accession) ? @accession : nil],
|
606
|
-
[:simple, 'name', (defined? @name) ? @name : nil],
|
607
|
-
[:simple, 'location', (defined? @location) ? @location : nil]])
|
608
|
-
|
609
|
-
if (defined? @mol_seq) && @mol_seq
|
610
|
-
molseq = LibXML::XML::Node.new('mol_seq', @mol_seq)
|
611
|
-
molseq["is_aligned"] = @is_aligned.to_s if (defined? @is_aligned) && @is_aligned != nil
|
612
|
-
seq << molseq
|
613
|
-
end
|
614
|
-
|
615
|
-
PhyloXML::Writer.generate_xml(seq, self, [
|
616
|
-
#[:pattern, 'mol_seq', @mol_seq, Regexp.new("^[a-zA-Z\.\-\?\*_]+$")],
|
617
|
-
[:complex, 'uri', (defined? @uri) ? @uri : nil],
|
618
|
-
[:objarr, 'annotation', 'annotations'],
|
619
|
-
[:complex, 'domain_architecture', (defined? @domain_architecture) ? @domain_architecture : nil]])
|
620
|
-
#@todo test domain_architecture
|
621
|
-
#any
|
622
|
-
return seq
|
623
|
-
end
|
624
|
-
|
625
|
-
# converts Bio::PhyloXML:Sequence to Bio::Sequence object.
|
626
|
-
# ---
|
627
|
-
# *Returns*:: Bio::Sequence
|
628
|
-
def to_biosequence
|
629
|
-
#type is not a required attribute in phyloxml (nor any other Sequence
|
630
|
-
#element) it might not hold any value, so we will not check what type it is.
|
631
|
-
seq = Bio::Sequence.auto(@mol_seq)
|
632
|
-
|
633
|
-
seq.id_namespace = @accession.source
|
634
|
-
seq.entry_id = @accession.value
|
635
|
-
# seq.primary_accession = @accession.value could be this
|
636
|
-
seq.definition = @name
|
637
|
-
#seq.comments = @name //this one?
|
638
|
-
if (defined? @uri) && @uri
|
639
|
-
h = {'url' => @uri.uri,
|
640
|
-
'title' => @uri.desc }
|
641
|
-
ref = Bio::Reference.new(h)
|
642
|
-
seq.references << ref
|
643
|
-
end
|
644
|
-
seq.molecule_type = 'RNA' if @type == 'rna'
|
645
|
-
seq.molecule_type = 'DNA' if @type == 'dna'
|
646
|
-
|
647
|
-
#@todo deal with the properties. There might be properties which look
|
648
|
-
#like bio sequence attributes or features
|
649
|
-
return seq
|
650
|
-
end
|
651
|
-
|
652
|
-
end
|
653
|
-
|
654
|
-
# == Description
|
655
|
-
# Element Accession is used to capture the local part in a sequence
|
656
|
-
# identifier.
|
657
|
-
class Accession
|
658
|
-
#String. Source of the accession id. Example: "UniProtKB"
|
659
|
-
attr_accessor :source
|
660
|
-
|
661
|
-
#String. Value of the accession id. Example: "P17304"
|
662
|
-
attr_accessor :value
|
663
|
-
|
664
|
-
# Converts elements to xml representation. Called by PhyloXML::Writer class.
|
665
|
-
def to_xml
|
666
|
-
raise "Source attribute is required for Accession object." if @source == nil
|
667
|
-
accession = LibXML::XML::Node.new('accession', @value)
|
668
|
-
accession['source'] = @source
|
669
|
-
return accession
|
670
|
-
end
|
671
|
-
|
672
|
-
end
|
673
|
-
|
674
|
-
# A uniform resource identifier. In general, this is expected to be an URL
|
675
|
-
# (for example, to link to an image on a website, in which case the 'type'
|
676
|
-
# attribute might be 'image' and 'desc' might be 'image of a California
|
677
|
-
# sea hare')
|
678
|
-
class Uri
|
679
|
-
# String. Description of the uri. For example, image of a California sea hare'
|
680
|
-
attr_accessor :desc
|
681
|
-
# String. For example, image.
|
682
|
-
attr_accessor :type
|
683
|
-
# String. URL of the resource.
|
684
|
-
attr_accessor :uri
|
685
|
-
|
686
|
-
# Converts elements to xml representation. Called by PhyloXML::Writer class.
|
687
|
-
def to_xml
|
688
|
-
if @uri != nil
|
689
|
-
xml_node = LibXML::XML::Node.new('uri', @uri)
|
690
|
-
Writer.generate_xml(xml_node, self, [
|
691
|
-
[:attr, 'desc'],
|
692
|
-
[:attr, 'type']])
|
693
|
-
return xml_node
|
694
|
-
end
|
695
|
-
end
|
696
|
-
end
|
697
|
-
|
698
|
-
# == Description
|
699
|
-
#
|
700
|
-
# The annotation of a molecular sequence. It is recommended to annotate by
|
701
|
-
# using the optional 'ref' attribute (some examples of acceptable values
|
702
|
-
# for the ref attribute: 'GO:0008270', 'KEGG:Tetrachloroethene degradation',
|
703
|
-
# 'EC:1.1.1.1').
|
704
|
-
class Annotation
|
705
|
-
# String. For example, 'GO:0008270', 'KEGG:Tetrachloroethene degradation',
|
706
|
-
# 'EC:1.1.1.1'
|
707
|
-
attr_accessor :ref
|
708
|
-
# String
|
709
|
-
attr_accessor :source
|
710
|
-
# String. evidence for a annotation as free text (e.g. 'experimental')
|
711
|
-
attr_accessor :evidence
|
712
|
-
# String. Type of the annotation.
|
713
|
-
attr_accessor :type
|
714
|
-
# String. Free text description.
|
715
|
-
attr_accessor :desc
|
716
|
-
# Confidence object. Type and value of support for a annotation.
|
717
|
-
attr_accessor :confidence
|
718
|
-
# Array of Property objects. Allows for further, typed and referenced
|
719
|
-
# annotations from external resources
|
720
|
-
attr_accessor :properties
|
721
|
-
# Uri object.
|
722
|
-
attr_accessor :uri
|
723
|
-
|
724
|
-
def initialize
|
725
|
-
#@todo add unit test for this, since didn't break anything when changed from property to properties
|
726
|
-
@properties = []
|
727
|
-
end
|
728
|
-
|
729
|
-
# Converts elements to xml representation. Called by PhyloXML::Writer class.
|
730
|
-
def to_xml
|
731
|
-
annot = LibXML::XML::Node.new('annotation')
|
732
|
-
annot["ref"] = @ref if (defined? @ref) && @ref
|
733
|
-
PhyloXML::Writer.generate_xml(annot, self, [[:simple, 'desc', (defined? @desc) ? @desc : nil],
|
734
|
-
[:complex, 'confidence', (defined? @confidence) ? @confidence : nil],
|
735
|
-
[:objarr, 'property', 'properties'],
|
736
|
-
[:complex, 'uri', (defined? @uri) ? @uri : nil]])
|
737
|
-
return annot
|
738
|
-
end
|
739
|
-
end
|
740
|
-
|
741
|
-
class Id
|
742
|
-
# The provider of Id, for example, NCBI.
|
743
|
-
attr_accessor :provider
|
744
|
-
# The value of Id.
|
745
|
-
attr_accessor :value
|
746
|
-
|
747
|
-
# Converts elements to xml representation. Called by PhyloXML::Writer class.
|
748
|
-
def to_xml
|
749
|
-
xml_node = LibXML::XML::Node.new('id', @value)
|
750
|
-
xml_node["provider"] = @provider if @provider != nil
|
751
|
-
return xml_node
|
752
|
-
end
|
753
|
-
end
|
754
|
-
|
755
|
-
# == Description
|
756
|
-
# This indicates the color of a node when rendered (the color applies
|
757
|
-
# to the whole node and its children unless overwritten by the
|
758
|
-
# color(s) of sub clades).
|
759
|
-
class BranchColor
|
760
|
-
#Integer
|
761
|
-
attr_reader :red, :green, :blue
|
762
|
-
|
763
|
-
def red=(str)
|
764
|
-
@red = str.to_i
|
765
|
-
end
|
766
|
-
|
767
|
-
def green=(str)
|
768
|
-
@green = str.to_i
|
769
|
-
end
|
770
|
-
|
771
|
-
def blue=(str)
|
772
|
-
@blue = str.to_i
|
773
|
-
end
|
774
|
-
|
775
|
-
# Converts elements to xml representation. Called by PhyloXML::Writer class.
|
776
|
-
def to_xml
|
777
|
-
#@todo add unit test
|
778
|
-
if @red == nil
|
779
|
-
raise "Subelement red of BranchColor element should not be nil"
|
780
|
-
elsif @green == nil
|
781
|
-
raise "Subelement green of BranchColor element should not be nil"
|
782
|
-
elsif @blue == nil
|
783
|
-
raise "Subelement blue of BranchColor element should not be nil"
|
784
|
-
end
|
785
|
-
|
786
|
-
c = LibXML::XML::Node.new('branch_color')
|
787
|
-
PhyloXML::Writer.generate_xml(c, self, [
|
788
|
-
[:simple, 'red', @red],
|
789
|
-
[:simple, 'green', @green],
|
790
|
-
[:simple, 'blue', @blue]])
|
791
|
-
return c
|
792
|
-
end
|
793
|
-
|
794
|
-
end
|
795
|
-
|
796
|
-
# == Description
|
797
|
-
# A date associated with a clade/node. Its value can be numerical by
|
798
|
-
# using the 'value' element and/or free text with the 'desc' element'
|
799
|
-
# (e.g. 'Silurian'). If a numerical value is used, it is recommended to
|
800
|
-
# employ the 'unit' attribute to indicate the type of the numerical
|
801
|
-
# value (e.g. 'mya' for 'million years ago').
|
802
|
-
class Date
|
803
|
-
# String. Units in which value is stored.
|
804
|
-
attr_accessor :unit
|
805
|
-
|
806
|
-
# Free text description of the date.
|
807
|
-
attr_accessor :desc
|
808
|
-
|
809
|
-
# Integer. Minimum and maximum of the value.
|
810
|
-
attr_reader :minimum, :maximum
|
811
|
-
|
812
|
-
# Integer. Value of the date.
|
813
|
-
attr_reader :value
|
814
|
-
|
815
|
-
def minimum=(str)
|
816
|
-
@minimum = str.to_i
|
817
|
-
end
|
818
|
-
|
819
|
-
def maximum=(str)
|
820
|
-
@maximum = str.to_i
|
821
|
-
end
|
822
|
-
|
823
|
-
def value= (str)
|
824
|
-
@value = str.to_i
|
825
|
-
end
|
826
|
-
|
827
|
-
# Returns value + unit, for exampe "7 mya"
|
828
|
-
def to_s
|
829
|
-
return "#{value} #{unit}"
|
830
|
-
end
|
831
|
-
|
832
|
-
# Converts elements to xml representation. Called by PhyloXML::Writer class.
|
833
|
-
def to_xml
|
834
|
-
date = LibXML::XML::Node.new('date')
|
835
|
-
PhyloXML::Writer.generate_xml(date, self, [
|
836
|
-
[:attr, 'unit'],
|
837
|
-
[:simple, 'desc', (defined? @desc) ? @desc : nil],
|
838
|
-
[:simple, 'value', (defined? @value) ? @value : nil],
|
839
|
-
[:simple, 'minimum', (defined? @minimum) ? @minimum : nil],
|
840
|
-
[:simple, 'maximum', (defined? @maximum) ? @maximum : nil]])
|
841
|
-
return date
|
842
|
-
end
|
843
|
-
|
844
|
-
end
|
845
|
-
|
846
|
-
# == Description
|
847
|
-
# This is used describe the domain architecture of a protein. Attribute
|
848
|
-
# 'length' is the total length of the protein
|
849
|
-
class DomainArchitecture
|
850
|
-
# Integer. Total length of the protein
|
851
|
-
attr_reader :length
|
852
|
-
|
853
|
-
# Array of ProteinDomain objects.
|
854
|
-
attr_reader :domains
|
855
|
-
|
856
|
-
# Integer. Total length of the protein
|
857
|
-
def length=(str)
|
858
|
-
@length = str.to_i
|
859
|
-
end
|
860
|
-
|
861
|
-
def initialize
|
862
|
-
@domains = []
|
863
|
-
end
|
864
|
-
|
865
|
-
# Converts elements to xml representation. Called by PhyloXML::Writer class.
|
866
|
-
def to_xml
|
867
|
-
xml_node = LibXML::XML::Node.new('domain_architecture')
|
868
|
-
PhyloXML::Writer.generate_xml(xml_node, self,[
|
869
|
-
[:attr, 'length'],
|
870
|
-
[:objarr, 'domain', 'domains']])
|
871
|
-
return xml_node
|
872
|
-
end
|
873
|
-
end
|
874
|
-
|
875
|
-
|
876
|
-
# == Description
|
877
|
-
# To represent an individual domain in a domain architecture. The
|
878
|
-
# name/unique identifier is described via the 'id' attribute.
|
879
|
-
class ProteinDomain
|
880
|
-
#Float, for example to store E-values 4.7E-14
|
881
|
-
attr_reader :confidence
|
882
|
-
|
883
|
-
# String
|
884
|
-
attr_accessor :id, :value
|
885
|
-
|
886
|
-
# Integer. Beginning of the domain.
|
887
|
-
attr_reader :from
|
888
|
-
|
889
|
-
# Integer. End of the domain.
|
890
|
-
attr_reader :to
|
891
|
-
|
892
|
-
# Integer. Beginning of the domain.
|
893
|
-
def from=(str)
|
894
|
-
@from = str.to_i
|
895
|
-
end
|
896
|
-
|
897
|
-
# Integer. End of the domain.
|
898
|
-
def to=(str)
|
899
|
-
@to = str.to_i
|
900
|
-
end
|
901
|
-
|
902
|
-
#Float, for example to store E-values 4.7E-14
|
903
|
-
def confidence=(str)
|
904
|
-
@confidence = str.to_f
|
905
|
-
end
|
906
|
-
|
907
|
-
# Converts elements to xml representation. Called by PhyloXML::Writer class.
|
908
|
-
def to_xml
|
909
|
-
if @from == nil
|
910
|
-
raise "from attribute of ProteinDomain class is required."
|
911
|
-
elsif @to == nil
|
912
|
-
raise "to attribute of ProteinDomain class is required."
|
913
|
-
else
|
914
|
-
xml_node = LibXML::XML::Node.new('domain', @value)
|
915
|
-
xml_node["from"] = @from.to_s
|
916
|
-
xml_node["to"] = @to.to_s
|
917
|
-
xml_node["id"] = @id if (defined? @id) && @id
|
918
|
-
xml_node["confidence"] = @confidence.to_s
|
919
|
-
|
920
|
-
return xml_node
|
921
|
-
end
|
922
|
-
|
923
|
-
end
|
924
|
-
|
925
|
-
end
|
926
|
-
|
927
|
-
|
928
|
-
#Property allows for typed and referenced properties from external resources
|
929
|
-
#to be attached to 'Phylogeny', 'Clade', and 'Annotation'. The value of a
|
930
|
-
#property is its mixed (free text) content. Attribute 'datatype' indicates
|
931
|
-
#the type of a property and is limited to xsd-datatypes (e.g. 'xsd:string',
|
932
|
-
#'xsd:boolean', 'xsd:integer', 'xsd:decimal', 'xsd:float', 'xsd:double',
|
933
|
-
#'xsd:date', 'xsd:anyURI'). Attribute 'applies_to' indicates the item to
|
934
|
-
#which a property applies to (e.g. 'node' for the parent node of a clade,
|
935
|
-
#'parent_branch' for the parent branch of a clade). Attribute 'id_ref' allows
|
936
|
-
#to attached a property specifically to one element (on the xml-level).
|
937
|
-
#Optional attribute 'unit' is used to indicate the unit of the property.
|
938
|
-
#An example: <property datatype="xsd:integer" ref="NOAA:depth" applies_to="clade" unit="METRIC:m"> 200 </property>
|
939
|
-
class Property
|
940
|
-
# String
|
941
|
-
attr_accessor :ref, :unit, :id_ref, :value
|
942
|
-
|
943
|
-
# String
|
944
|
-
attr_reader :datatype, :applies_to
|
945
|
-
|
946
|
-
def datatype=(str)
|
947
|
-
#@todo add unit test or maybe remove, if assume that xml is valid.
|
948
|
-
unless ['xsd:string','xsd:boolean','xsd:decimal','xsd:float','xsd:double',
|
949
|
-
'xsd:duration','xsd:dateTime','xsd:time','xsd:date','xsd:gYearMonth',
|
950
|
-
'xsd:gYear','xsd:gMonthDay','xsd:gDay','xsd:gMonth','xsd:hexBinary',
|
951
|
-
'xsd:base64Binary','xsd:anyURI','xsd:normalizedString','xsd:token',
|
952
|
-
'xsd:integer','xsd:nonPositiveInteger','xsd:negativeInteger',
|
953
|
-
'xsd:long','xsd:int','xsd:short','xsd:byte','xsd:nonNegativeInteger',
|
954
|
-
'xsd:unsignedLong','xsd:unsignedInt','xsd:unsignedShort',
|
955
|
-
'xsd:unsignedByte','xsd:positiveInteger'].include?(str)
|
956
|
-
raise "Warning: #{str} is not in the list of allowed values."
|
957
|
-
end
|
958
|
-
@datatype = str
|
959
|
-
end
|
960
|
-
|
961
|
-
def applies_to=(str)
|
962
|
-
unless ['phylogeny','clade','node','annotation','parent_branch','other'].include?(str)
|
963
|
-
puts "Warning: #{str} is not in the list of allowed values."
|
964
|
-
end
|
965
|
-
@applies_to = str
|
966
|
-
end
|
967
|
-
|
968
|
-
# Converts elements to xml representation. Called by PhyloXML::Writer class.
|
969
|
-
def to_xml
|
970
|
-
#@todo write unit test for this
|
971
|
-
raise "ref is an required element of property" if @ref.nil?
|
972
|
-
raise "datatype is an required element of property" if @datatype.nil?
|
973
|
-
raise "applies_to is an required element of property" if @applies_to.nil?
|
974
|
-
|
975
|
-
property = LibXML::XML::Node.new('property')
|
976
|
-
Writer.generate_xml(property, self, [
|
977
|
-
[:attr, 'ref'],
|
978
|
-
[:attr, 'unit'],
|
979
|
-
[:attr, 'datatype'],
|
980
|
-
[:attr, 'applies_to'],
|
981
|
-
[:attr, 'id_ref']])
|
982
|
-
|
983
|
-
property << @value if @value != nil
|
984
|
-
return property
|
985
|
-
end
|
986
|
-
end
|
987
|
-
|
988
|
-
# == Description
|
989
|
-
# A literature reference for a clade. It is recommended to use the 'doi'
|
990
|
-
# attribute instead of the free text 'desc' element whenever possible.
|
991
|
-
class Reference
|
992
|
-
# String. Digital Object Identifier.
|
993
|
-
attr_accessor :doi
|
994
|
-
|
995
|
-
# String. Free text description.
|
996
|
-
attr_accessor :desc
|
997
|
-
|
998
|
-
# Converts elements to xml representation. Called by PhyloXML::Writer class.
|
999
|
-
def to_xml
|
1000
|
-
ref = LibXML::XML::Node.new('reference')
|
1001
|
-
Writer.generate_xml(ref, self, [
|
1002
|
-
[:attr, 'doi'],
|
1003
|
-
[:simple, 'desc', (defined? @desc) ? @desc : nil]])
|
1004
|
-
return ref
|
1005
|
-
end
|
1006
|
-
|
1007
|
-
end
|
1008
|
-
|
1009
|
-
# == Description
|
1010
|
-
#
|
1011
|
-
# This is used to express a typed relationship between two clades.
|
1012
|
-
# For example it could be used to describe multiple parents of a clade.
|
1013
|
-
class CladeRelation
|
1014
|
-
# Float
|
1015
|
-
attr_reader :distance
|
1016
|
-
# String. Id of the referenced parents of a clade.
|
1017
|
-
attr_accessor :id_ref_0, :id_ref_1
|
1018
|
-
# String
|
1019
|
-
attr_accessor :type
|
1020
|
-
# Confidence object
|
1021
|
-
attr_accessor :confidence
|
1022
|
-
|
1023
|
-
# Float
|
1024
|
-
def distance=(str)
|
1025
|
-
@distance = str.to_f
|
1026
|
-
end
|
1027
|
-
|
1028
|
-
# Converts elements to xml representation. Called by PhyloXML::Writer class.
|
1029
|
-
def to_xml
|
1030
|
-
if @id_ref_0 == nil or @id_ref_1 == nil or @type == nil
|
1031
|
-
raise "Attributes id_ref_0, id_ref_1, type are required elements by SequenceRelation element."
|
1032
|
-
else
|
1033
|
-
cr = LibXML::XML::Node.new('clade_relation')
|
1034
|
-
Writer.generate_xml(cr, self, [
|
1035
|
-
[:attr, 'id_ref_0'],
|
1036
|
-
[:attr, 'id_ref_1'],
|
1037
|
-
[:attr, 'distance'],
|
1038
|
-
[:attr, 'type'],
|
1039
|
-
[:complex, 'confidence', (defined? @confidnece) ? @confidnece : nil]])
|
1040
|
-
|
1041
|
-
return cr
|
1042
|
-
end
|
1043
|
-
end
|
1044
|
-
|
1045
|
-
end
|
1046
|
-
|
1047
|
-
|
1048
|
-
# == Description
|
1049
|
-
# The names and/or counts of binary characters present, gained, and
|
1050
|
-
# lost at the root of a clade.
|
1051
|
-
class BinaryCharacters
|
1052
|
-
attr_accessor :bc_type, :gained, :lost, :present, :absent
|
1053
|
-
attr_reader :gained_count, :lost_count, :present_count, :absent_count
|
1054
|
-
|
1055
|
-
def gained_count=(str)
|
1056
|
-
@gained_count = str.to_i
|
1057
|
-
end
|
1058
|
-
|
1059
|
-
def lost_count=(str)
|
1060
|
-
@lost_count = str.to_i
|
1061
|
-
end
|
1062
|
-
|
1063
|
-
def present_count=(str)
|
1064
|
-
@present_count = str.to_i
|
1065
|
-
end
|
1066
|
-
|
1067
|
-
def absent_count=(str)
|
1068
|
-
@absent_count = str.to_i
|
1069
|
-
end
|
1070
|
-
|
1071
|
-
def initialize
|
1072
|
-
@gained = []
|
1073
|
-
@lost = []
|
1074
|
-
@present = []
|
1075
|
-
@absent = []
|
1076
|
-
end
|
1077
|
-
|
1078
|
-
# Converts elements to xml representation. Called by PhyloXML::Writer class.
|
1079
|
-
def to_xml
|
1080
|
-
bc = LibXML::XML::Node.new('binary_characters')
|
1081
|
-
bc['type'] = @bc_type
|
1082
|
-
PhyloXML::Writer.generate_xml(bc, self, [
|
1083
|
-
[:attr, 'gained_count'],
|
1084
|
-
[:attr, 'lost_count'],
|
1085
|
-
[:attr, 'present_count'],
|
1086
|
-
[:attr, 'absent_count']])
|
1087
|
-
|
1088
|
-
if not @gained.empty?
|
1089
|
-
gained_xml = LibXML::XML::Node.new('gained')
|
1090
|
-
PhyloXML::Writer.generate_xml(gained_xml, self, [[:simplearr, 'bc', @gained]])
|
1091
|
-
bc << gained_xml
|
1092
|
-
end
|
1093
|
-
|
1094
|
-
if not @lost.empty?
|
1095
|
-
lost_xml = LibXML::XML::Node.new('lost')
|
1096
|
-
PhyloXML::Writer.generate_xml(lost_xml, self, [[:simplearr, 'bc', @lost]])
|
1097
|
-
bc << lost_xml
|
1098
|
-
end
|
1099
|
-
|
1100
|
-
if not @present.empty?
|
1101
|
-
present_xml = LibXML::XML::Node.new('present')
|
1102
|
-
PhyloXML::Writer.generate_xml(present_xml, self, [[:simplearr, 'bc', @present]])
|
1103
|
-
bc << present_xml
|
1104
|
-
end
|
1105
|
-
|
1106
|
-
if not @absent.empty?
|
1107
|
-
absent_xml = LibXML::XML::Node.new('absent')
|
1108
|
-
PhyloXML::Writer.generate_xml(absent_xml, self, [[:simplearr, 'bc', @absent]])
|
1109
|
-
bc << absent_xml
|
1110
|
-
end
|
1111
|
-
|
1112
|
-
return bc
|
1113
|
-
end
|
1114
|
-
|
1115
|
-
|
1116
|
-
end
|
1117
|
-
|
1118
|
-
# == Description
|
1119
|
-
# This is used to express a typed relationship between two sequences.
|
1120
|
-
# For example it could be used to describe an orthology (in which case
|
1121
|
-
# attribute 'type' is 'orthology').
|
1122
|
-
class SequenceRelation
|
1123
|
-
# String
|
1124
|
-
attr_accessor :id_ref_0, :id_ref_1
|
1125
|
-
|
1126
|
-
# String. Allowed values: "orthology", "one_to_one_orthology",
|
1127
|
-
# "super_orthology", "paralogy", "ultra_paralogy", "xenology",
|
1128
|
-
# "unknown", "other"
|
1129
|
-
attr_reader :type
|
1130
|
-
|
1131
|
-
# Float
|
1132
|
-
attr_reader :distance
|
1133
|
-
|
1134
|
-
#@todo it has Confidences objects.
|
1135
|
-
|
1136
|
-
def distance=(str)
|
1137
|
-
@distance = str.to_f if str != nil
|
1138
|
-
end
|
1139
|
-
|
1140
|
-
# String. Allowed values: "orthology", "one_to_one_orthology",
|
1141
|
-
# "super_orthology", "paralogy", "ultra_paralogy", "xenology",
|
1142
|
-
# "unknown", "other"
|
1143
|
-
def type=(str)
|
1144
|
-
#@todo do warning instead?
|
1145
|
-
#@todo do validation at actually writing xml
|
1146
|
-
allowed_values = ["orthology", "one_to_one_orthology", "super_orthology", "paralogy",
|
1147
|
-
"ultra_paralogy", "xenology", "unknown", "other"]
|
1148
|
-
if not allowed_values.include? str
|
1149
|
-
raise "SequenceRelation#type has to be one one of #{allowed_values.join("; ")}"
|
1150
|
-
else
|
1151
|
-
@type = str
|
1152
|
-
end
|
1153
|
-
end
|
1154
|
-
|
1155
|
-
# Converts elements to xml representation. Called by PhyloXML::Writer class.
|
1156
|
-
def to_xml
|
1157
|
-
if @id_ref_0 == nil or @id_ref_1 == nil or @type == nil
|
1158
|
-
raise "Attributes id_ref_0, id_ref_1, type are required elements by SequenceRelation element."
|
1159
|
-
else
|
1160
|
-
sr = LibXML::XML::Node.new('sequence_relation')
|
1161
|
-
sr['id_ref_0'] = @id_ref_0
|
1162
|
-
sr['id_ref_1'] = @id_ref_1
|
1163
|
-
sr['distance'] = @distance.to_s if (defined? @distance) && @distance
|
1164
|
-
sr['type'] = @type
|
1165
|
-
return sr
|
1166
|
-
end
|
1167
|
-
end
|
1168
|
-
|
1169
|
-
end
|
1170
|
-
|
1171
|
-
class Other
|
1172
|
-
attr_accessor :element_name, :attributes, :children, :value
|
1173
|
-
|
1174
|
-
def initialize
|
1175
|
-
@children = []
|
1176
|
-
@attributes = Hash.new
|
1177
|
-
end
|
1178
|
-
|
1179
|
-
# Converts elements to xml representation. Called by PhyloXML::Writer class.
|
1180
|
-
def to_xml
|
1181
|
-
o = LibXML::XML::Node.new(@element_name)
|
1182
|
-
@attributes.each do |key, value|
|
1183
|
-
o[key] = value
|
1184
|
-
end
|
1185
|
-
o << value if value != nil
|
1186
|
-
children.each do |child_node|
|
1187
|
-
o << child_node.to_xml
|
1188
|
-
end
|
1189
|
-
return o
|
1190
|
-
end
|
1191
|
-
|
1192
|
-
end
|
1193
|
-
|
1194
|
-
|
1195
|
-
end #module PhyloXML
|
1196
|
-
|
1197
|
-
end #end module Bio
|