bio 1.5.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +35 -36
  3. data/ChangeLog +911 -2554
  4. data/{gemfiles/Gemfile.travis-ruby2.2 → Gemfile} +0 -3
  5. data/KNOWN_ISSUES.rdoc +10 -13
  6. data/LEGAL +0 -10
  7. data/README.rdoc +40 -96
  8. data/README_DEV.rdoc +5 -5
  9. data/RELEASE_NOTES.rdoc +118 -234
  10. data/Rakefile +13 -43
  11. data/appveyor.yml +29 -0
  12. data/bioruby.gemspec +18 -81
  13. data/bioruby.gemspec.erb +8 -28
  14. data/doc/ChangeLog-1.5.0 +2919 -0
  15. data/doc/RELEASE_NOTES-1.5.0.rdoc +285 -0
  16. data/doc/Tutorial.rd +6 -108
  17. data/doc/Tutorial.rd.html +19 -98
  18. data/gemfiles/Gemfile.travis-jruby1.8 +3 -5
  19. data/gemfiles/Gemfile.travis-jruby1.9 +0 -3
  20. data/gemfiles/Gemfile.travis-rbx +0 -3
  21. data/gemfiles/Gemfile.travis-ruby1.8 +3 -5
  22. data/gemfiles/Gemfile.travis-ruby1.9 +0 -3
  23. data/gemfiles/Gemfile.windows +6 -0
  24. data/gemfiles/prepare-gemspec.rb +4 -0
  25. data/lib/bio.rb +0 -10
  26. data/lib/bio/appl/blast/genomenet.rb +4 -4
  27. data/lib/bio/appl/blast/report.rb +40 -8
  28. data/lib/bio/appl/fasta/format10.rb +2 -1
  29. data/lib/bio/command.rb +10 -0
  30. data/lib/bio/data/codontable.rb +99 -3
  31. data/lib/bio/db/aaindex.rb +74 -5
  32. data/lib/bio/db/gff.rb +3 -1
  33. data/lib/bio/db/kegg/common.rb +14 -0
  34. data/lib/bio/db/kegg/genes.rb +26 -0
  35. data/lib/bio/db/kegg/pathway.rb +5 -11
  36. data/lib/bio/db/soft.rb +2 -2
  37. data/lib/bio/io/flatfile/autodetection.rb +5 -0
  38. data/lib/bio/io/togows.rb +5 -5
  39. data/lib/bio/map.rb +4 -4
  40. data/lib/bio/sequence/format.rb +1 -0
  41. data/lib/bio/util/restriction_enzyme/range/sequence_range/calculated_cuts.rb +1 -1
  42. data/lib/bio/util/sirna.rb +2 -0
  43. data/lib/bio/version.rb +6 -8
  44. data/sample/color_scheme_aa.rb +82 -0
  45. data/sample/color_scheme_na.rb +5 -6
  46. data/sample/fastq2html.cwl +23 -0
  47. data/sample/fastq2html.rb +94 -0
  48. data/sample/fastq2html.testdata.yaml +5 -0
  49. data/sample/na2aa.cwl +23 -0
  50. data/sample/na2aa.rb +11 -25
  51. data/sample/na2aa.testdata.yaml +7 -0
  52. data/sample/rev_comp.cwl +23 -0
  53. data/sample/rev_comp.rb +20 -0
  54. data/sample/rev_comp.testdata.yaml +7 -0
  55. data/sample/test_restriction_enzyme_long.rb +1 -1
  56. data/test/network/bio/db/kegg/test_genes_hsa7422.rb +91 -0
  57. data/test/unit/bio/appl/blast/test_report.rb +4 -4
  58. data/test/unit/bio/data/test_codontable.rb +3 -0
  59. data/test/unit/bio/db/test_gff.rb +5 -0
  60. data/test/unit/bio/test_alignment.rb +2 -2
  61. metadata +20 -77
  62. data/bin/bioruby +0 -47
  63. data/bin/br_biofetch.rb +0 -71
  64. data/bin/br_bioflat.rb +0 -293
  65. data/bin/br_biogetseq.rb +0 -45
  66. data/bin/br_pmfetch.rb +0 -422
  67. data/lib/bio/appl/blast/xmlparser.rb +0 -236
  68. data/lib/bio/db/biosql/biosql_to_biosequence.rb +0 -78
  69. data/lib/bio/db/biosql/sequence.rb +0 -444
  70. data/lib/bio/db/phyloxml/phyloxml.xsd +0 -582
  71. data/lib/bio/db/phyloxml/phyloxml_elements.rb +0 -1197
  72. data/lib/bio/db/phyloxml/phyloxml_parser.rb +0 -1001
  73. data/lib/bio/db/phyloxml/phyloxml_writer.rb +0 -227
  74. data/lib/bio/io/biosql/ar-biosql.rb +0 -257
  75. data/lib/bio/io/biosql/biosql.rb +0 -39
  76. data/lib/bio/io/biosql/config/database.yml +0 -21
  77. data/lib/bio/io/sql.rb +0 -79
  78. data/lib/bio/shell.rb +0 -44
  79. data/lib/bio/shell/core.rb +0 -578
  80. data/lib/bio/shell/demo.rb +0 -146
  81. data/lib/bio/shell/interface.rb +0 -217
  82. data/lib/bio/shell/irb.rb +0 -94
  83. data/lib/bio/shell/object.rb +0 -71
  84. data/lib/bio/shell/plugin/blast.rb +0 -42
  85. data/lib/bio/shell/plugin/codon.rb +0 -218
  86. data/lib/bio/shell/plugin/das.rb +0 -58
  87. data/lib/bio/shell/plugin/emboss.rb +0 -23
  88. data/lib/bio/shell/plugin/entry.rb +0 -137
  89. data/lib/bio/shell/plugin/flatfile.rb +0 -101
  90. data/lib/bio/shell/plugin/midi.rb +0 -430
  91. data/lib/bio/shell/plugin/ncbirest.rb +0 -68
  92. data/lib/bio/shell/plugin/obda.rb +0 -45
  93. data/lib/bio/shell/plugin/psort.rb +0 -56
  94. data/lib/bio/shell/plugin/seq.rb +0 -248
  95. data/lib/bio/shell/plugin/togows.rb +0 -40
  96. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/bioruby_generator.rb +0 -29
  97. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/_classes.rhtml +0 -4
  98. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/_log.rhtml +0 -27
  99. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/_methods.rhtml +0 -11
  100. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/_modules.rhtml +0 -4
  101. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/_variables.rhtml +0 -7
  102. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby-bg.gif +0 -0
  103. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby-gem.png +0 -0
  104. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby-link.gif +0 -0
  105. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby.css +0 -368
  106. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby.rhtml +0 -47
  107. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby_controller.rb +0 -144
  108. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby_helper.rb +0 -47
  109. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/commands.rhtml +0 -8
  110. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/history.rhtml +0 -10
  111. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/index.rhtml +0 -26
  112. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/spinner.gif +0 -0
  113. data/lib/bio/shell/script.rb +0 -25
  114. data/lib/bio/shell/setup.rb +0 -108
  115. data/lib/bio/shell/web.rb +0 -102
  116. data/sample/test_phyloxml_big.rb +0 -205
  117. data/setup.rb +0 -1600
  118. data/test/data/phyloxml/apaf.xml +0 -666
  119. data/test/data/phyloxml/bcl_2.xml +0 -2097
  120. data/test/data/phyloxml/made_up.xml +0 -144
  121. data/test/data/phyloxml/ncbi_taxonomy_mollusca_short.xml +0 -65
  122. data/test/data/phyloxml/phyloxml_examples.xml +0 -415
  123. data/test/unit/bio/db/biosql/tc_biosql.rb +0 -114
  124. data/test/unit/bio/db/biosql/ts_suite_biosql.rb +0 -8
  125. data/test/unit/bio/db/test_phyloxml.rb +0 -821
  126. data/test/unit/bio/db/test_phyloxml_writer.rb +0 -334
  127. data/test/unit/bio/shell/plugin/test_seq.rb +0 -187
  128. data/test/unit/bio/test_shell.rb +0 -20
@@ -1,78 +0,0 @@
1
- #
2
- # = bio/db/biosql/biosql_to_biosequence.rb - Bio::SQL::Sequence to Bio::Sequence adapter module
3
- #
4
- # Copyright:: Copyright (C) 2008
5
- # Naohisa Goto <ng@bioruby.org>,
6
- # Raoul Jean Pierre Bonnal
7
- # License:: The Ruby License
8
- #
9
- # $Id:$
10
- #
11
-
12
- require 'bio/sequence'
13
- require 'bio/sequence/adapter'
14
- require 'bio/sequence/dblink'
15
-
16
- # Internal use only. Normal users should not use this module.
17
- #
18
- # Bio::SQL::Sequence to Bio::Sequence adapter module.
19
- # It is internally used in Bio::SQL::Sequence#to_biosequence.
20
- #
21
- module Bio::Sequence::Adapter::BioSQL
22
-
23
- extend Bio::Sequence::Adapter
24
-
25
- private
26
-
27
- def_biosequence_adapter :seq
28
-
29
- def_biosequence_adapter :entry_id
30
-
31
- def_biosequence_adapter :primary_accession
32
-
33
- def_biosequence_adapter :secondary_accessions
34
-
35
- def_biosequence_adapter :molecule_type
36
-
37
- #--
38
- #TODO: identify where is stored data_class in biosql
39
- #++
40
-
41
- def_biosequence_adapter :data_class
42
-
43
- def_biosequence_adapter :definition, :description
44
-
45
- def_biosequence_adapter :topology
46
-
47
- def_biosequence_adapter :date_created
48
-
49
- def_biosequence_adapter :date_modified
50
- #do |bs|
51
- # Date.parse(bs.date_modified.to_s).strftime("%d-%b-%Y").upcase
52
- # end
53
-
54
- def_biosequence_adapter :division
55
-
56
- def_biosequence_adapter :sequence_version
57
-
58
- def_biosequence_adapter :keywords
59
-
60
- def_biosequence_adapter :species
61
-
62
- def_biosequence_adapter :classification, :taxonomy
63
-
64
- def_biosequence_adapter :references
65
-
66
- def_biosequence_adapter :features
67
-
68
- def_biosequence_adapter :comments
69
-
70
- def_biosequence_adapter :other_seqids do |orig|
71
- orig.identifier.split(',').collect do |dblink|
72
- database, id = dblink.split(':')
73
- Bio::Sequence::DBLink.new(database,id)
74
- end
75
- end
76
-
77
- end #module Bio::Sequence::Adapter::BioSQL
78
-
@@ -1,444 +0,0 @@
1
-
2
- #TODO save on db reading from a genbank or embl object
3
- module Bio
4
- class SQL
5
-
6
-
7
-
8
- class Sequence
9
- private
10
- # example
11
- # bioentry_qualifier_anchor :molecule_type, :synonym=>'mol_type'
12
- # this function creates other 3 functions, molecule_type, molecule_type=, molecule_type_update
13
- #molecule_type => return an array of strings, where each string is the value associated with the qualifier, ordered by rank.
14
- #molecule_type=value add a bioentry_qualifier value to the table
15
- #molecule_type_update(value, rank) update an entry of the table with an existing rank
16
- #the method inferr the qualifier term from the name of the first symbol, or you can specify a synonym to use
17
-
18
- #creating an object with to_biosql is transaction safe.
19
-
20
- #TODO: implement setting for more than a qualifier-vale.
21
- def self.bioentry_qualifier_anchor(sym, *args)
22
- options = args.first || Hash.new
23
- #options.assert_valid_keys(:rank,:synonym,:multi)
24
- method_reader = sym.to_s.to_sym
25
- method_writer_operator = (sym.to_s+"=").to_sym
26
- method_writer_modder = (sym.to_s+"_update").to_sym
27
- synonym = options[:synonym].nil? ? sym.to_s : options[:synonym]
28
-
29
- #DELETE #Bio::SQL::Term.create(:name=>synonym, :ontology=> Bio::SQL::Ontology.find_by_name('Annotation Tags')) unless Bio::SQL::Term.exists?(:name =>synonym)
30
- send :define_method, method_reader do
31
- #return an array of bioentry_qualifier_values
32
- begin
33
- #DELETE ontology_annotation_tags = Ontology.find_or_create({:name=>'Annotation Tags'})
34
- term = Term.first(:conditions=>["name = ?",synonym]) || Term.create({:name => synonym, :ontology=> Ontology.first(:conditions=>["name = ?",'Annotation Tags'])})
35
- bioentry_qualifier_values = @entry.bioentry_qualifier_values.all(:conditions=>["term_id = ?",term.term_id])
36
- data = bioentry_qualifier_values.map{|row| row.value} unless bioentry_qualifier_values.nil?
37
- begin
38
- # this block try to check if the data retrived is a
39
- # Date or not and change it according to GenBank/EMBL format
40
- # in that case return a string
41
- # otherwise the []
42
- Date.parse(data.to_s).strftime("%d-%b-%Y").upcase
43
- rescue ArgumentError, TypeError, NoMethodError, NameError
44
- data
45
- end
46
- rescue Exception => e
47
- puts "Reader Error: #{synonym} #{e.message}"
48
- end
49
- end
50
-
51
- send :define_method, method_writer_operator do |value|
52
- begin
53
- #DELETE ontology_annotation_tags = Ontology.find_or_create({:name=>'Annotation Tags'})
54
- term = Term.first(:conditions=>["name = ?",synonym]) || Term.create({:name => synonym, :ontology=> Ontology.first(:conditions=>["name = ?",'Annotation Tags'])})
55
- datas = @entry.bioentry_qualifier_values.all(:conditions=>["term_id = ?",term.term_id])
56
- #add an element incrementing the rank or setting the first to 1
57
- be_qu_va=@entry.bioentry_qualifier_values.build({:term=>term, :rank=>(datas.empty? ? 1 : datas.last.rank.succ), :value=>value})
58
- be_qu_va.save
59
- rescue Exception => e
60
- puts "WriterOperator= Error: #{synonym} #{e.message}"
61
- end
62
- end
63
-
64
- send :define_method, method_writer_modder do |value, rank|
65
- begin
66
- #DELETE ontology_annotation_tags = Ontology.find_or_create({:name=>'Annotation Tags'})
67
- term = Term.first(:conditions=>["name = ?",synonym]) || Term.create({:name => synonym, :ontology=> Ontology.first(:conditions=>["name = ?",'Annotation Tags'])})
68
- data = @entry.bioentry_qualifier_values.all(:term_id=>term.term_id, :rank=>rank)
69
- if data.nil?
70
- send method_writer_operator, value
71
- else
72
- data.value=value
73
- data.save
74
- end
75
- rescue Exception => e
76
- puts "WriterModder Error: #{synonym} #{e.message}"
77
- end
78
- end
79
-
80
- end
81
-
82
- public
83
- attr_reader :entry
84
-
85
- def delete
86
- #TODO: check is references connected to this bioentry are leaf or not.
87
- #actually I think it should be more sofisticated, check if there are
88
- #other bioentries connected to references; if not delete 'em
89
- @entry.references.each { |ref| ref.delete if ref.bioentries.size==1}
90
- @entry.destroy
91
- end
92
-
93
- def get_seqfeature(sf)
94
-
95
- #in seqfeature BioSQL class
96
- locations_str = sf.locations.map{|loc| loc.to_s}.join(',')
97
- #pp sf.locations.inspect
98
- locations_str = "join(#{locations_str})" if sf.locations.count>1
99
- Bio::Feature.new(sf.type_term.name, locations_str,sf.seqfeature_qualifier_values.collect{|sfqv| Bio::Feature::Qualifier.new(sfqv.term.name,sfqv.value)})
100
- end
101
-
102
- def length=(len)
103
- @entry.biosequence.length=len
104
- end
105
-
106
- def initialize(options={})
107
- #options.assert_valid_keys(:entry, :biodatabase,:biosequence)
108
- return @entry = options[:entry] unless options[:entry].nil?
109
-
110
- return to_biosql(options[:biosequence], options[:biodatabase]) unless options[:biosequence].nil? or options[:biodatabase].nil?
111
-
112
- end
113
-
114
- def to_biosql(bs,biodatabase)
115
- #DELETE #Transcaction works greatly!!!
116
- begin
117
- #DELETE Bioentry.transaction do
118
- @entry = biodatabase.bioentries.build({:name=>bs.entry_id})
119
-
120
- puts "primary" if $DEBUG
121
- self.primary_accession = bs.primary_accession
122
-
123
- puts "def" if $DEBUG
124
- self.definition = bs.definition unless bs.definition.nil?
125
-
126
- puts "seqver" if $DEBUG
127
- self.sequence_version = bs.sequence_version || 0
128
-
129
- puts "divi" if $DEBUG
130
- self.division = bs.division unless bs.division.nil?
131
-
132
- puts "identifier" if $DEBUG
133
- self.identifier = bs.other_seqids.collect{|dblink| "#{dblink.database}:#{dblink.id}"}.join(';') unless bs.other_seqids.nil?
134
- @entry.save
135
- puts "secacc" if $DEBUG
136
-
137
- bs.secondary_accessions.each do |sa|
138
- puts "#{sa}" if $DEBUG
139
- #write as qualifier every secondary accession into the array
140
- self.secondary_accessions = sa
141
- end unless bs.secondary_accessions.nil?
142
-
143
-
144
- #to create the sequence entry needs to exists
145
- puts "seq" if $DEBUG
146
- puts bs.seq if $DEBUG
147
- self.seq = bs.seq unless bs.seq.nil?
148
- puts "mol" if $DEBUG
149
-
150
- self.molecule_type = bs.molecule_type unless bs.molecule_type.nil?
151
- puts "dc" if $DEBUG
152
-
153
- self.data_class = bs.data_class unless bs.data_class.nil?
154
- puts "top" if $DEBUG
155
- self.topology = bs.topology unless bs.topology.nil?
156
- puts "datec" if $DEBUG
157
- self.date_created = bs.date_created unless bs.date_created.nil?
158
- puts "datemod" if $DEBUG
159
- self.date_modified = bs.date_modified unless bs.date_modified.nil?
160
- puts "key" if $DEBUG
161
-
162
- bs.keywords.each do |kw|
163
- #write as qualifier every secondary accessions into the array
164
- self.keywords = kw
165
- end unless bs.keywords.nil?
166
-
167
- puts "spec" if $DEBUG
168
- #self.species = bs.species unless bs.species.nil?
169
- self.species = bs.species unless bs.species.empty?
170
- puts "Debug: #{bs.species}" if $DEBUG
171
- puts "Debug: feat..start" if $DEBUG
172
-
173
- bs.features.each do |feat|
174
- self.feature=feat
175
- end unless bs.features.nil?
176
-
177
- puts "Debug: feat...end" if $DEBUG
178
- bs.references.each do |reference|
179
- self.reference=reference
180
- end unless bs.references.nil?
181
-
182
- bs.comments.each do |comment|
183
- self.comment=comment
184
- end unless bs.comments.nil?
185
-
186
- #DELETE end #transaction
187
- return self
188
- rescue Exception => e
189
- puts "to_biosql exception: #{e}"
190
- puts $!
191
- end #rescue
192
- end #to_biosql
193
-
194
-
195
- def name
196
- @entry.name
197
- end
198
- alias entry_id name
199
-
200
- def name=(value)
201
- @entry.name=value
202
- end
203
- alias entry_id= name=
204
-
205
- def primary_accession
206
- @entry.accession
207
- end
208
-
209
- def primary_accession=(value)
210
- @entry.accession=value
211
- end
212
-
213
- #TODO def secondary_accession
214
- # @entry.bioentry_qualifier_values
215
- # end
216
-
217
- def organism
218
- @entry.taxon.nil? ? "" : "#{@entry.taxon.taxon_scientific_name.name}"+ (@entry.taxon.taxon_genbank_common_name ? "(#{@entry.taxon.taxon_genbank_common_name.name})" : '')
219
- end
220
- alias species organism
221
-
222
- def organism=(value)
223
- #FIX there is a shortcut
224
- taxon_name=TaxonName.first(:conditions=>["name = ? and name_class = ?",value.gsub(/\s+\(.+\)/,''),'scientific name'])
225
- if taxon_name.nil?
226
- puts "Error value doesn't exists in taxon_name table with scientific name constraint."
227
- else
228
- @entry.taxon_id=taxon_name.taxon_id
229
- @entry.save
230
- end
231
- end
232
- alias species= organism=
233
-
234
- def database
235
- @entry.biodatabase.name
236
- end
237
-
238
- def database_desc
239
- @entry.biodatabase.description
240
- end
241
-
242
- def version
243
- @entry.version
244
- end
245
- alias sequence_version version
246
-
247
- def version=(value)
248
- @entry.version=value
249
- end
250
- alias sequence_version= version=
251
-
252
- def division
253
- @entry.division
254
- end
255
-
256
- def division=(value)
257
- @entry.division=value
258
- end
259
-
260
- def description
261
- @entry.description
262
- end
263
- alias definition description
264
-
265
- def description=(value)
266
- @entry.description=value
267
- end
268
- alias definition= description=
269
-
270
- def identifier
271
- @entry.identifier
272
- end
273
- alias other_seqids identifier
274
-
275
- def identifier=(value)
276
- @entry.identifier=value
277
- end
278
-
279
- bioentry_qualifier_anchor :data_class
280
- bioentry_qualifier_anchor :molecule_type, :synonym=>'mol_type'
281
- bioentry_qualifier_anchor :topology
282
- bioentry_qualifier_anchor :date_created
283
- bioentry_qualifier_anchor :date_modified, :synonym=>'date_changed'
284
- bioentry_qualifier_anchor :keywords, :synonym=>'keyword'
285
- bioentry_qualifier_anchor :secondary_accessions, :synonym=>'secondary_accession'
286
-
287
- def features
288
- @entry.seqfeatures.collect do |sf|
289
- self.get_seqfeature(sf)
290
- end
291
- end
292
-
293
- def feature=(feat)
294
- #ToDo: avoid Ontology find here, probably more efficient create class variables
295
- #DELETE type_term_ontology = Ontology.find_or_create({:name=>'SeqFeature Keys'})
296
- puts "feature:type_term = #{feat.feature}" if $DEBUG
297
- type_term = Term.first(:conditions=>["name = ?", feat.feature]) || Term.create({:name=>feat.feature, :ontology=>Ontology.first(:conditions=>["name = ?",'SeqFeature Keys'])})
298
- #DELETE source_term_ontology = Ontology.find_or_create({:name=>'SeqFeature Sources'})
299
- puts "feature:source_term" if $DEBUG
300
- source_term = Term.first(:conditions=>["name = ?",'EMBLGenBankSwit'])
301
- puts "feature:seqfeature" if $DEBUG
302
- seqfeature = @entry.seqfeatures.build({:source_term=>source_term, :type_term=>type_term, :rank=>@entry.seqfeatures.count.succ, :display_name=>''})
303
- seqfeature.save
304
- puts "feature:location" if $DEBUG
305
- feat.locations.each do |loc|
306
- location = seqfeature.locations.build({:seqfeature=>seqfeature, :start_pos=>loc.from, :end_pos=>loc.to, :strand=>loc.strand, :rank=>seqfeature.locations.count.succ})
307
- location.save
308
- end
309
-
310
- #DELETE qual_term_ontology = Ontology.find_or_create({:name=>'Annotation Tags'})
311
-
312
- puts "feature:qualifier" if $DEBUG
313
- feat.each do |qualifier|
314
- #DELETE qual_term = Term.find_or_create({:name=>qualifier.qualifier}, {:ontology=>qual_term_ontology})
315
- qual_term = Term.first(:conditions=>["name = ?", qualifier.qualifier]) || Term.create({:name=>qualifier.qualifier, :ontology=>Ontology.first(:conditions=>["name = ?", 'Annotation Tags'])})
316
- qual = seqfeature.seqfeature_qualifier_values.build({:seqfeature=>seqfeature, :term=>qual_term, :value=>qualifier.value.to_s, :rank=>seqfeature.seqfeature_qualifier_values.count.succ})
317
- qual.save
318
-
319
- end
320
- end
321
-
322
- #return the seqfeature mapped from BioSQL with a type_term like 'CDS'
323
- def cdsfeatures
324
- @entry.cdsfeatures
325
- end
326
-
327
- # Returns the sequence.
328
- # Returns a Bio::Sequence::Generic object.
329
-
330
- def seq
331
- s = @entry.biosequence
332
- Bio::Sequence::Generic.new(s ? s.seq : '')
333
- end
334
-
335
- def seq=(value)
336
- #TODO: revise this piece of code.
337
- #chk which type of alphabet is, NU/NA/nil
338
- if @entry.biosequence.nil?
339
- #DELETE puts "intoseq1"
340
- @entry.biosequence = Biosequence.new(:seq=>value)
341
- # biosequence = @entry.biosequence.build({:seq=>value})
342
- @entry.biosequence.save
343
- # biosequence.save
344
- else
345
- @entry.biosequence.seq=value
346
- end
347
- self.length=value.length
348
- #DELETE #@entry.biosequence.length=value.length
349
- #DELETE #break
350
- @entry.save
351
- end
352
-
353
- #report parents and exclude info with "no rank". Now I report rank == class but ... Question ? Have to be reported taxonomy with rank=="class"?
354
- def taxonomy
355
- tax = []
356
- taxon = Taxon.first(:conditions=>["taxon_id = ?",@entry.taxon.parent_taxon_id])
357
- while taxon and taxon.taxon_id != taxon.parent_taxon_id and taxon.node_rank!='no rank'
358
- tax << taxon.taxon_scientific_name.name if taxon.node_rank!='class'
359
- #Note: I don't like this call very much, correct with a relationship in the ref class.
360
- taxon = Taxon.first(:conditions=>["taxon_id = ?",taxon.parent_taxon_id])
361
- end
362
- tax.reverse
363
- end
364
-
365
- def length
366
- @entry.biosequence.length
367
- end
368
-
369
- def references
370
- #return and array of hash, hash has these keys ["title", "dbxref_id", "reference_id", "authors", "crc", "location"]
371
- #probably would be better to d a class refrence to collect these informations
372
- @entry.bioentry_references.collect do |bio_ref|
373
- hash = Hash.new
374
- hash['authors'] = bio_ref.reference.authors.gsub(/\.\s/, "\.\s\|").split(/\|/) if (bio_ref.reference and bio_ref.reference.authors)
375
-
376
- hash['sequence_position'] = "#{bio_ref.start_pos}-#{bio_ref.end_pos}" if (bio_ref.start_pos and bio_ref.end_pos)
377
- hash['title'] = bio_ref.reference.title
378
- hash['embl_gb_record_number'] = bio_ref.rank
379
- #TODO: solve the problem with specific comment per reference.
380
- #TODO: get dbxref
381
- #take a look when location is build up in def reference=(value)
382
-
383
- bio_ref.reference.location.split('|').each do |element|
384
- key,value=element.split('=')
385
- hash[key]=value
386
- end unless bio_ref.reference.location.nil?
387
-
388
- hash['xrefs'] = bio_ref.reference.dbxref ? "#{bio_ref.reference.dbxref.dbname}; #{bio_ref.reference.dbxref.accession}." : ''
389
- Bio::Reference.new(hash)
390
- end
391
- end
392
-
393
- def comments
394
- @entry.comments.map do |comment|
395
- comment.comment_text
396
- end
397
- end
398
-
399
- def reference=(value)
400
- locations=Array.new
401
- locations << "journal=#{value.journal}" unless value.journal.empty?
402
- locations << "volume=#{value.volume}" unless value.volume.empty?
403
- locations << "issue=#{value.issue}" unless value.issue.empty?
404
- locations << "pages=#{value.pages}" unless value.pages.empty?
405
- locations << "year=#{value.year}" unless value.year.empty?
406
- locations << "pubmed=#{value.pubmed}" unless value.pubmed.empty?
407
- locations << "medline=#{value.medline}" unless value.medline.empty?
408
- locations << "doi=#{value.doi}" unless value.doi.nil?
409
- locations << "abstract=#{value.abstract}" unless value.abstract.empty?
410
- locations << "url=#{value.url}" unless value.url.nil?
411
- locations << "mesh=#{value.mesh}" unless value.mesh.empty?
412
- locations << "affiliations=#{value.affiliations}" unless value.affiliations.empty?
413
- locations << "comments=#{value.comments.join('~')}"unless value.comments.nil?
414
- start_pos, end_pos = value.sequence_position ? value.sequence_position.gsub(/\s*/,'').split('-') : [nil,nil]
415
- reference= Reference.first(:conditions=>["title = ?",value.title]) || Reference.create({:title=>value.title,:authors=>value.authors.join(' '), :location=>locations.join('|')})
416
- bio_reference=@entry.bioentry_references.build({:reference=>reference,:rank=>value.embl_gb_record_number, :start_pos=>start_pos, :end_pos=>end_pos})
417
- bio_reference.save
418
- end
419
-
420
- def comment=(value)
421
- #DELETE comment=Comment.new({:bioentry=>@entry, :comment_text=>value, :rank=>@entry.comments.count.succ})
422
- comment = @entry.comments.build({:comment_text=>value, :rank=>@entry.comments.count.succ})
423
- comment.save
424
- end
425
-
426
- def save
427
- #I should add chks for SQL errors
428
- @entry.biosequence.save
429
- @entry.save
430
- end
431
- def to_fasta
432
- ">" + accession + "\n" + seq.gsub(Regexp.new(".{1,#{60}}"), "\\0\n")
433
- end
434
-
435
- def to_fasta_reverse_complememt
436
- ">" + accession + "\n" + seq.reverse_complement.gsub(Regexp.new(".{1,#{60}}"), "\\0\n")
437
- end
438
-
439
- def to_biosequence
440
- Bio::Sequence.adapter(self,Bio::Sequence::Adapter::BioSQL)
441
- end
442
- end #Sequence
443
- end #SQL
444
- end #Bio