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



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

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

Instance Method Details

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



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

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



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

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



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
130
# File 'lib/bio/io/das.rb', line 104

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 |e|
      sequence.sequence = Bio::Sequence::NA.new(e.text)
      sequence.length = e.attributes['length'].to_i
    end
    ary << sequence
  end
  ary
end

#get_dsnObject

Returns an Array of Bio::DAS::DSN



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

def get_dsn
  ary = []
  result = Bio::Command.post_form("#{@server}/das/dsn")
  doc = REXML::Document.new(result.body)
  doc.elements.each('/descendant::DSN') do |e|
    dsn = DSN.new
    e.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.



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

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 |e|
    entry_point.href = e.attributes['href']
    entry_point.version = e.attributes['version']
    e.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



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
319
# File 'lib/bio/io/das.rb', line 214

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 |e|
    gff.version = e.attributes['version']
    gff.href = e.attributes['href']
    e.elements.each('SEGMENT') 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 |e|
        feature = FEATURE.new
        feature.entry_id = e.attributes['id']
        feature.label = e.attributes['label']
        e.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 |e|
              case e.name
              when 'NOTE'		# in GROUP
                group.notes << e.text
              when 'LINK'		# in GROUP
                link = LINK.new
                link.href = e.attributes['href']
                link.text = e.text
                group.links << link
              when 'TARGET'		# in GROUP
                target = TARGET.new
                target.entry_id = e.attributes['id']
                target.start = e.attributes['start']
                target.stop = e.attributes['stop']
                target.name = e.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



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
167
# File 'lib/bio/io/das.rb', line 136

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



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
208
# File 'lib/bio/io/das.rb', line 173

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 |e|
    types.version = e.attributes['version']
    types.href = e.attributes['href']
    e.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 |e|
        t = TYPE.new
        t.entry_id = e.attributes['id']
        t.method = e.attributes['method']
        t.category = e.attributes['category']
        t.count = e.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