Class: Bio::DAS

Inherits:
Object show all
Defined in:
lib/bio/io/das.rb,
lib/bio/shell/plugin/das.rb

Defined Under Namespace

Classes: DNA, DSN, ENTRY_POINT, FEATURE, GFF, GROUP, LINK, SEGMENT, SEQUENCE, TARGET, TYPE, TYPES

Instance Method Summary collapse

Constructor Details

#initialize(url = 'http://www.wormbase.org:80/db/') ⇒ DAS

Specify DAS server to connect



31
32
33
# File 'lib/bio/io/das.rb', line 31

def initialize(url = 'http://www.wormbase.org:80/db/')
  @server = url.chomp('/')
end

Instance Method Details

#dna(dsn, entry_point, start, stop) ⇒ Object



35
36
37
38
# File 'lib/bio/io/das.rb', line 35

def dna(dsn, entry_point, start, stop)
  seg = Bio::DAS::SEGMENT.region(entry_point, start, stop)
  self.get_dna(dsn, seg).first.sequence
end

#features(dsn, entry_point, start, stop) ⇒ Object



40
41
42
43
# File 'lib/bio/io/das.rb', line 40

def features(dsn, entry_point, start, stop)
  seg = Bio::DAS::SEGMENT.region(entry_point, start, stop)
  self.get_features(dsn, seg)
end

#get_dna(dsn, segments) ⇒ Object

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



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/bio/io/das.rb', line 103

def get_dna(dsn, segments)
  ary = []

  dsn = dsn.source if dsn.instance_of?(DSN)
  segments = [segments] if segments.instance_of?(SEGMENT)

  opts = []
  segments.each do |s|
    opts << "segment=#{s.entry_id}:#{s.start},#{s.stop}"
  end

  result = Bio::Command.post_form("#{@server}/das/#{dsn}/dna", opts)
  doc = REXML::Document.new(result.body)
  doc.elements.each('/descendant::SEQUENCE') do |e|
    sequence = DNA.new
    sequence.entry_id = e.attributes['id']
    sequence.start = e.attributes['start']
    sequence.stop = e.attributes['stop']
    sequence.version = e.attributes['version']
    e.elements.each do |el|
      sequence.sequence = Bio::Sequence::NA.new(el.text)
      sequence.length = el.attributes['length'].to_i
    end
    ary << sequence
  end
  ary
end

#get_dsnObject

Returns an Array of Bio::DAS::DSN



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/bio/io/das.rb', line 47

def get_dsn
  ary = []
  result = Bio::Command.post_form("#{@server}/das/dsn")
  doc = REXML::Document.new(result.body)
  doc.elements.each('/descendant::DSN') do |ee|
    dsn = DSN.new
    ee.elements.each do |e|
      case e.name
      when 'SOURCE'
        dsn.source = e.text
        dsn.source_id = e.attributes['id']
        dsn.source_version = e.attributes['version']
      when 'MAPMASTER'
        dsn.mapmaster = e.text
      when 'DESCRIPTION'
        dsn.description = e.text
        dsn.description_href = e.attributes['href']
      end
    end
    ary << dsn
  end
  ary
end

#get_entry_points(dsn) ⇒ Object

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



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/bio/io/das.rb', line 73

def get_entry_points(dsn)
  entry_point = ENTRY_POINT.new
  if dsn.instance_of?(Bio::DAS::DSN)
    src = dsn.source 
  else
    src = dsn
  end
  result = Bio::Command.post_form("#{@server}/das/#{src}/entry_points")
  doc = REXML::Document.new(result.body)
  doc.elements.each('/descendant::ENTRY_POINTS') do |ee|
    entry_point.href = ee.attributes['href']
    entry_point.version = ee.attributes['version']
    ee.elements.each do |e|
      segment = SEGMENT.new
      segment.entry_id = e.attributes['id']
      segment.start = e.attributes['start']
      segment.stop = e.attributes['stop'] || e.attributes['size']
      segment.orientation = e.attributes['orientation']
      segment.subparts = e.attributes['subparts']
      segment.description = e.text
      entry_point.segments << segment
    end
  end
  entry_point
end

#get_features(dsn, segments = [], categorize = false, feature_ids = [], group_ids = []) ⇒ Object

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



213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
# File 'lib/bio/io/das.rb', line 213

def get_features(dsn, segments = [], categorize = false, feature_ids = [], group_ids = [])
  # arguments 'type' and 'category' are deprecated
  gff = GFF.new

  dsn = dsn.source if dsn.instance_of?(DSN)
  segments = [segments] if segments.instance_of?(SEGMENT)

  opts = []
  segments.each do |s|
    opts << "segment=#{s.entry_id}:#{s.start},#{s.stop}"
  end
  if categorize
    opts << "categorize=yes"	# default is 'no'
  end
  feature_ids.each do |fid|
    opts << "feature_id=#{fid}"
  end
  group_ids.each do |gid|
    opts << "group_id=#{gid}"
  end

  result = Bio::Command.post_form("#{@server}/das/#{dsn}/features", opts)
  doc = REXML::Document.new(result.body)
  doc.elements.each('/descendant::GFF') do |elem|
    gff.version = elem.attributes['version']
    gff.href = elem.attributes['href']
    elem.elements.each('SEGMENT') do |ele|
      segment = SEGMENT.new
      segment.entry_id = ele.attributes['id']
      segment.start = ele.attributes['start']
      segment.stop = ele.attributes['stop']
      segment.version = ele.attributes['version']
      segment.label = ele.attributes['label']
      ele.elements.each do |el|
        feature = FEATURE.new
        feature.entry_id = el.attributes['id']
        feature.label = el.attributes['label']
        el.elements.each do |e|
          case e.name
          when 'TYPE'
            type = TYPE.new
            type.entry_id = e.attributes['id']
            type.category = e.attributes['category']
            type.reference = e.attributes['referrence']
            type.label = e.text
            feature.types << type
          when 'METHOD'
            feature.method_id = e.attributes['id']
            feature.method = e.text
          when 'START'
            feature.start = e.text
          when 'STOP', 'END'
            feature.stop = e.text
          when 'SCORE'
            feature.score = e.text
          when 'ORIENTATION'
            feature.orientation = e.text
          when 'PHASE'
            feature.phase = e.text
          when 'NOTE'
            feature.notes << e.text
          when 'LINK'
            link = LINK.new
            link.href = e.attributes['href']
            link.text = e.text
            feature.links << link
          when 'TARGET'
            target = TARGET.new
            target.entry_id = e.attributes['id']
            target.start = e.attributes['start']
            target.stop = e.attributes['stop']
            target.name = e.text
            feature.targets << target
          when 'GROUP'
            group = GROUP.new
            group.entry_id = e.attributes['id']
            group.label = e.attributes['label']
            group.type = e.attributes['type']
            e.elements.each do |ee|
              case ee.name
              when 'NOTE'		# in GROUP
                group.notes << ee.text
              when 'LINK'		# in GROUP
                link = LINK.new
                link.href = ee.attributes['href']
                link.text = ee.text
                group.links << link
              when 'TARGET'		# in GROUP
                target = TARGET.new
                target.entry_id = ee.attributes['id']
                target.start = ee.attributes['start']
                target.stop = ee.attributes['stop']
                target.name = ee.text
                group.targets << target
              end
            end
            feature.groups << group
          end
        end
        segment.features << feature
      end
      gff.segments << segment
    end
  end
  gff
end

#get_sequence(dsn, segments) ⇒ Object

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



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/bio/io/das.rb', line 135

def get_sequence(dsn, segments)
  ary = []

  dsn = dsn.source if dsn.instance_of?(DSN)
  segments = [segments] if segments.instance_of?(SEGMENT)

  opts = []
  segments.each do |s|
    opts << "segment=#{s.entry_id}:#{s.start},#{s.stop}"
  end

  result = Bio::Command.post_form("#{@server}/das/#{dsn}/sequence", opts)
  doc = REXML::Document.new(result.body)
  doc.elements.each('/descendant::SEQUENCE') do |e|
    sequence = SEQUENCE.new
    sequence.entry_id = e.attributes['id']
    sequence.start = e.attributes['start']
    sequence.stop = e.attributes['stop']
    sequence.moltype = e.attributes['moltype']
    sequence.version = e.attributes['version']
    case sequence.moltype
    when /dna|rna/i		# 'DNA', 'ssRNA', 'dsRNA'
      sequence.sequence = Bio::Sequence::NA.new(e.text)
    when /protein/i		# 'Protein
      sequence.sequence = Bio::Sequence::AA.new(e.text)
    else
      sequence.sequence = e.text
    end
    ary << sequence
  end
  ary
end

#get_types(dsn, segments = []) ⇒ Object

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



172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/bio/io/das.rb', line 172

def get_types(dsn, segments = [])	# argument 'type' is deprecated
  types = TYPES.new

  dsn = dsn.source if dsn.instance_of?(DSN)
  segments = [segments] if segments.instance_of?(SEGMENT)

  opts = []
  segments.each do |s|
    opts << "segment=#{s.entry_id}:#{s.start},#{s.stop}"
  end

  result = Bio::Command.post_form("#{@server}/das/#{dsn}/types", opts)
  doc = REXML::Document.new(result.body)
  doc.elements.each('/descendant::GFF') do |ee|
    types.version = ee.attributes['version']
    types.href = ee.attributes['href']
    ee.elements.each do |e|
      segment = SEGMENT.new
      segment.entry_id = e.attributes['id']
      segment.start = e.attributes['start']
      segment.stop = e.attributes['stop']
      segment.version = e.attributes['version']
      segment.label = e.attributes['label']
      e.elements.each do |el|
        t = TYPE.new
        t.entry_id = el.attributes['id']
        t.method = el.attributes['method']
        t.category = el.attributes['category']
        t.count = el.text.to_i
        segment.types << t
      end
      types.segments << segment
    end
  end
  types
end

#list_sequencesObject



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/bio/shell/plugin/das.rb', line 14

def list_sequences
  result = ""
  self.get_dsn.each do |dsn|
    src = dsn.source_id
    self.get_entry_points(src).each do |ep|
      data = [src, ep.entry_id, ep.start.to_i, ep.stop.to_i, "# #{ep.description}"].join("\t") + "\n"
      puts data
      result += data
    end
  end
  return result
end