Class Bio::DAS
In: lib/bio/io/das.rb  (CVS)
lib/bio/shell/plugin/das.rb  (CVS)
Parent: Object

Methods

Classes and Modules

Class Bio::DAS::DNA
Class Bio::DAS::DSN
Class Bio::DAS::ENTRY_POINT
Class Bio::DAS::FEATURE
Class Bio::DAS::GFF
Class Bio::DAS::GROUP
Class Bio::DAS::LINK
Class Bio::DAS::SEGMENT
Class Bio::DAS::SEQUENCE
Class Bio::DAS::TARGET
Class Bio::DAS::TYPE
Class Bio::DAS::TYPES

Public Class methods

Specify DAS server to connect

[Source]

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

Public Instance methods

[Source]

# 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

[Source]

# 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

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

[Source]

# 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

Returns an Array of Bio::DAS::DSN

[Source]

# 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

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

[Source]

# 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

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

[Source]

# 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

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

[Source]

# 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

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

[Source]

# 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

[Source]

# 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

[Validate]