class Bio::DAS

Public Class Methods

new(url = 'http://www.wormbase.org:80/db/') click to toggle source

Specify DAS server to connect

   # File lib/bio/io/das.rb
31 def initialize(url = 'http://www.wormbase.org:80/db/')
32   @server = url.chomp('/')
33 end

Public Instance Methods

dna(dsn, entry_point, start, stop) click to toggle source
   # File lib/bio/io/das.rb
35 def dna(dsn, entry_point, start, stop)
36   seg = Bio::DAS::SEGMENT.region(entry_point, start, stop)
37   self.get_dna(dsn, seg).first.sequence
38 end
features(dsn, entry_point, start, stop) click to toggle source
   # File lib/bio/io/das.rb
40 def features(dsn, entry_point, start, stop)
41   seg = Bio::DAS::SEGMENT.region(entry_point, start, stop)
42   self.get_features(dsn, seg)
43 end
get_dna(dsn, segments) click to toggle source

Returns an Array of Bio::DAS::DNA. The 'dsn' can be a String or a Bio::DAS::DSN object. The 'segments' can be a Bio::DAS::SEGMENT object or an Array of Bio::DAS::SEGMENT

    # File lib/bio/io/das.rb
103 def get_dna(dsn, segments)
104   ary = []
105 
106   dsn = dsn.source if dsn.instance_of?(DSN)
107   segments = [segments] if segments.instance_of?(SEGMENT)
108 
109   opts = []
110   segments.each do |s|
111     opts << "segment=#{s.entry_id}:#{s.start},#{s.stop}"
112   end
113 
114   result = Bio::Command.post_form("#{@server}/das/#{dsn}/dna", opts)
115   doc = REXML::Document.new(result.body)
116   doc.elements.each('/descendant::SEQUENCE') do |e|
117     sequence = DNA.new
118     sequence.entry_id = e.attributes['id']
119     sequence.start = e.attributes['start']
120     sequence.stop = e.attributes['stop']
121     sequence.version = e.attributes['version']
122     e.elements.each do |el|
123       sequence.sequence = Bio::Sequence::NA.new(el.text)
124       sequence.length = el.attributes['length'].to_i
125     end
126     ary << sequence
127   end
128   ary
129 end
get_dsn() click to toggle source

Returns an Array of Bio::DAS::DSN

   # File lib/bio/io/das.rb
47 def get_dsn
48   ary = []
49   result = Bio::Command.post_form("#{@server}/das/dsn")
50   doc = REXML::Document.new(result.body)
51   doc.elements.each('/descendant::DSN') do |ee|
52     dsn = DSN.new
53     ee.elements.each do |e|
54       case e.name
55       when 'SOURCE'
56         dsn.source = e.text
57         dsn.source_id = e.attributes['id']
58         dsn.source_version = e.attributes['version']
59       when 'MAPMASTER'
60         dsn.mapmaster = e.text
61       when 'DESCRIPTION'
62         dsn.description = e.text
63         dsn.description_href = e.attributes['href']
64       end
65     end
66     ary << dsn
67   end
68   ary
69 end
get_entry_points(dsn) click to toggle source

Returns Bio::DAS::ENTRY_POINT. The 'dsn' can be a String or a Bio::DAS::DSN object.

   # File lib/bio/io/das.rb
73 def get_entry_points(dsn)
74   entry_point = ENTRY_POINT.new
75   if dsn.instance_of?(Bio::DAS::DSN)
76     src = dsn.source 
77   else
78     src = dsn
79   end
80   result = Bio::Command.post_form("#{@server}/das/#{src}/entry_points")
81   doc = REXML::Document.new(result.body)
82   doc.elements.each('/descendant::ENTRY_POINTS') do |ee|
83     entry_point.href = ee.attributes['href']
84     entry_point.version = ee.attributes['version']
85     ee.elements.each do |e|
86       segment = SEGMENT.new
87       segment.entry_id = e.attributes['id']
88       segment.start = e.attributes['start']
89       segment.stop = e.attributes['stop'] || e.attributes['size']
90       segment.orientation = e.attributes['orientation']
91       segment.subparts = e.attributes['subparts']
92       segment.description = e.text
93       entry_point.segments << segment
94     end
95   end
96   entry_point
97 end
get_features(dsn, segments = [], categorize = false, feature_ids = [], group_ids = []) click to toggle source

Returns a Bio::DAS::GFF object. The 'dsn' can be a String or a Bio::DAS::DSN object. The 'segments' is optional and can be a Bio::DAS::SEGMENT object or an Array of Bio::DAS::SEGMENT

    # File lib/bio/io/das.rb
213 def get_features(dsn, segments = [], categorize = false, feature_ids = [], group_ids = [])
214   # arguments 'type' and 'category' are deprecated
215   gff = GFF.new
216 
217   dsn = dsn.source if dsn.instance_of?(DSN)
218   segments = [segments] if segments.instance_of?(SEGMENT)
219 
220   opts = []
221   segments.each do |s|
222     opts << "segment=#{s.entry_id}:#{s.start},#{s.stop}"
223   end
224   if categorize
225     opts << "categorize=yes"  # default is 'no'
226   end
227   feature_ids.each do |fid|
228     opts << "feature_id=#{fid}"
229   end
230   group_ids.each do |gid|
231     opts << "group_id=#{gid}"
232   end
233 
234   result = Bio::Command.post_form("#{@server}/das/#{dsn}/features", opts)
235   doc = REXML::Document.new(result.body)
236   doc.elements.each('/descendant::GFF') do |elem|
237     gff.version = elem.attributes['version']
238     gff.href = elem.attributes['href']
239     elem.elements.each('SEGMENT') do |ele|
240       segment = SEGMENT.new
241       segment.entry_id = ele.attributes['id']
242       segment.start = ele.attributes['start']
243       segment.stop = ele.attributes['stop']
244       segment.version = ele.attributes['version']
245       segment.label = ele.attributes['label']
246       ele.elements.each do |el|
247         feature = FEATURE.new
248         feature.entry_id = el.attributes['id']
249         feature.label = el.attributes['label']
250         el.elements.each do |e|
251           case e.name
252           when 'TYPE'
253             type = TYPE.new
254             type.entry_id = e.attributes['id']
255             type.category = e.attributes['category']
256             type.reference = e.attributes['referrence']
257             type.label = e.text
258             feature.types << type
259           when 'METHOD'
260             feature.method_id = e.attributes['id']
261             feature.method = e.text
262           when 'START'
263             feature.start = e.text
264           when 'STOP', 'END'
265             feature.stop = e.text
266           when 'SCORE'
267             feature.score = e.text
268           when 'ORIENTATION'
269             feature.orientation = e.text
270           when 'PHASE'
271             feature.phase = e.text
272           when 'NOTE'
273             feature.notes << e.text
274           when 'LINK'
275             link = LINK.new
276             link.href = e.attributes['href']
277             link.text = e.text
278             feature.links << link
279           when 'TARGET'
280             target = TARGET.new
281             target.entry_id = e.attributes['id']
282             target.start = e.attributes['start']
283             target.stop = e.attributes['stop']
284             target.name = e.text
285             feature.targets << target
286           when 'GROUP'
287             group = GROUP.new
288             group.entry_id = e.attributes['id']
289             group.label = e.attributes['label']
290             group.type = e.attributes['type']
291             e.elements.each do |ee|
292               case ee.name
293               when 'NOTE'             # in GROUP
294                 group.notes << ee.text
295               when 'LINK'             # in GROUP
296                 link = LINK.new
297                 link.href = ee.attributes['href']
298                 link.text = ee.text
299                 group.links << link
300               when 'TARGET'           # in GROUP
301                 target = TARGET.new
302                 target.entry_id = ee.attributes['id']
303                 target.start = ee.attributes['start']
304                 target.stop = ee.attributes['stop']
305                 target.name = ee.text
306                 group.targets << target
307               end
308             end
309             feature.groups << group
310           end
311         end
312         segment.features << feature
313       end
314       gff.segments << segment
315     end
316   end
317   gff
318 end
get_sequence(dsn, segments) click to toggle source

Returns an Array of Bio::DAS::SEQUENCE. The 'dsn' can be a String or a Bio::DAS::DSN object. The 'segments' can be a Bio::DAS::SEGMENT object or an Array of Bio::DAS::SEGMENT

    # File lib/bio/io/das.rb
135 def get_sequence(dsn, segments)
136   ary = []
137 
138   dsn = dsn.source if dsn.instance_of?(DSN)
139   segments = [segments] if segments.instance_of?(SEGMENT)
140 
141   opts = []
142   segments.each do |s|
143     opts << "segment=#{s.entry_id}:#{s.start},#{s.stop}"
144   end
145 
146   result = Bio::Command.post_form("#{@server}/das/#{dsn}/sequence", opts)
147   doc = REXML::Document.new(result.body)
148   doc.elements.each('/descendant::SEQUENCE') do |e|
149     sequence = SEQUENCE.new
150     sequence.entry_id = e.attributes['id']
151     sequence.start = e.attributes['start']
152     sequence.stop = e.attributes['stop']
153     sequence.moltype = e.attributes['moltype']
154     sequence.version = e.attributes['version']
155     case sequence.moltype
156     when /dna|rna/i           # 'DNA', 'ssRNA', 'dsRNA'
157       sequence.sequence = Bio::Sequence::NA.new(e.text)
158     when /protein/i           # 'Protein
159       sequence.sequence = Bio::Sequence::AA.new(e.text)
160     else
161       sequence.sequence = e.text
162     end
163     ary << sequence
164   end
165   ary
166 end
get_types(dsn, segments = []) click to toggle source

Returns a Bio::DAS::TYPES object. The 'dsn' can be a String or a Bio::DAS::DSN object. The 'segments' is optional and can be a Bio::DAS::SEGMENT object or an Array of Bio::DAS::SEGMENT

    # File lib/bio/io/das.rb
172 def get_types(dsn, segments = [])     # argument 'type' is deprecated
173   types = TYPES.new
174 
175   dsn = dsn.source if dsn.instance_of?(DSN)
176   segments = [segments] if segments.instance_of?(SEGMENT)
177 
178   opts = []
179   segments.each do |s|
180     opts << "segment=#{s.entry_id}:#{s.start},#{s.stop}"
181   end
182 
183   result = Bio::Command.post_form("#{@server}/das/#{dsn}/types", opts)
184   doc = REXML::Document.new(result.body)
185   doc.elements.each('/descendant::GFF') do |ee|
186     types.version = ee.attributes['version']
187     types.href = ee.attributes['href']
188     ee.elements.each do |e|
189       segment = SEGMENT.new
190       segment.entry_id = e.attributes['id']
191       segment.start = e.attributes['start']
192       segment.stop = e.attributes['stop']
193       segment.version = e.attributes['version']
194       segment.label = e.attributes['label']
195       e.elements.each do |el|
196         t = TYPE.new
197         t.entry_id = el.attributes['id']
198         t.method = el.attributes['method']
199         t.category = el.attributes['category']
200         t.count = el.text.to_i
201         segment.types << t
202       end
203       types.segments << segment
204     end
205   end
206   types
207 end