Class: Bio::Features

Inherits:
Object
  • Object
show all
Defined in:
lib/feature.rb

Overview

DESCRIPTION

Container for a list of Feature objects.

USAGE

# First, create some Bio::Feature objects
feature1 = Bio::Feature.new('intron','3627..4059')
feature2 = Bio::Feature.new('exon','4060..4236')
feature3 = Bio::Feature.new('intron','4237..4426')
feature4 = Bio::Feature.new('CDS','join(2538..3626,4060..4236)',
                 [ Bio::Feature::Qualifier.new('gene', 'CYP2D6'),
                   Bio::Feature::Qualifier.new('translation','MGXXTVMHLL...')
                 ])

# And create a container for them
feature_container = Bio::Features.new([ feature1, feature2, feature3, feature4 ])

# Iterate over all features and print
feature_container.each do |feature|
  puts feature.feature + "\t" + feature.position
  feature.each do |qualifier|
    puts "- " + qualifier.qualifier + ": " + qualifier.value
  end
end

# Iterate only over CDS features and extract translated amino acid sequences
features.each("CDS") do |feature|
  hash = feature.to_hash
  name = hash["gene"] || hash["product"] || hash["note"] 
  aaseq  = hash["translation"]
  pos  = feature.position
  if name and seq
    puts ">#{gene} #{feature.position}"
    puts aaseq
  end
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ary = []) ⇒ Features

Create a new Bio::Features object.

Arguments:

  • (optional) list of features: list of Bio::Feature objects

Returns

Bio::Features object



161
162
163
# File 'lib/feature.rb', line 161

def initialize(ary = [])
  @features = ary
end

Instance Attribute Details

#featuresObject

Returns an Array of Feature objects.



166
167
168
# File 'lib/feature.rb', line 166

def features
  @features
end

Instance Method Details

#[](*arg) ⇒ Object

Short cut for the Features#features



190
191
192
# File 'lib/feature.rb', line 190

def [](*arg)
  @features[*arg]
end

#append(a) ⇒ Object

Appends a Feature object to Features.

Arguments:

  • (required) feature: Bio::Feature object

Returns

Bio::Features object



173
174
175
176
# File 'lib/feature.rb', line 173

def append(a)
  @features.push(a) if a.is_a? Feature
  return self
end

#each(arg = nil) ⇒ Object

Iterates on each feature object.

Arguments:

  • (optional) key: if specified, only iterates over features with this key



182
183
184
185
186
187
# File 'lib/feature.rb', line 182

def each(arg = nil)
  @features.each do |x|
    next if arg and x.feature != arg
    yield x
  end
end

#firstObject

Short cut for the Features#features.first



195
196
197
# File 'lib/feature.rb', line 195

def first
  @features.first
end

#lastObject

Short cut for the Features#features.last



200
201
202
# File 'lib/feature.rb', line 200

def last
  @features.last
end