Class: Bio::Feature

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

Defined Under Namespace

Classes: Qualifier

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(feature, position, qualifiers = [], parent = nil, subfeatures = []) ⇒ Feature

Returns a new instance of Feature.


3
4
5
6
7
8
# File 'lib/feature.rb', line 3

def initialize(feature, position, qualifiers = [], parent = nil, subfeatures = [])
  @feature, @position, @qualifiers, @parent = feature, position, qualifiers, parent
  @subfeatures = Array.new
  subfeatures.each {|sf| add_subfeature(sf) }
  @locations = Bio::Locations.new(@position)
end

Instance Attribute Details

#featureObject

Returns type of feature in String (e.g 'CDS', 'gene')


11
12
13
# File 'lib/feature.rb', line 11

def feature
  @feature
end

#locationsObject

Returns position of the feature as a Bio::Locations object


17
18
19
# File 'lib/feature.rb', line 17

def locations
  @locations
end

#parentObject

Returns parent of Bio::Feature is it is a subfeature of another one


23
24
25
# File 'lib/feature.rb', line 23

def parent
  @parent
end

#positionObject

Returns position of the feature in String (e.g. 'complement(123..146)')


14
15
16
# File 'lib/feature.rb', line 14

def position
  @position
end

#qualifiersObject

Returns an Array of Qualifier objects.


20
21
22
# File 'lib/feature.rb', line 20

def qualifiers
  @qualifiers
end

#subfeaturesObject

Returns an Array of Bio::Feature objects


26
27
28
# File 'lib/feature.rb', line 26

def subfeatures
  @subfeatures
end

Instance Method Details

#add_qualifier(a) ⇒ Object Also known as: append_qualifier

Adds a Qualifier object to the Feature.

Arguments:

  • (required) qualifier: Bio::Feature::Qualifier object

Returns

Bio::Feature object


43
44
45
46
# File 'lib/feature.rb', line 43

def add_qualifier(a)
  @qualifiers.push(a) if a.is_a? Qualifier
  return self
end

#add_subfeature(sf) ⇒ Object

Adds a Bio::Feature as a subfeature. Arguments:

  • (required) feature: Bio::Feature object

Returns

Bio::Feature object


32
33
34
35
36
# File 'lib/feature.rb', line 32

def add_subfeature(sf)
  sf.parent = self
  @subfeatures.push(sf)
  return self
end

#each_qualifier(arg = nil) ⇒ Object

Iterates on each qualifer object.

Arguments:

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


65
66
67
68
69
70
# File 'lib/feature.rb', line 65

def each_qualifier(arg = nil)
  @qualifiers.each do |x|
    next if arg and x.qualifier != arg
    yield x
  end
end

#each_subfeature(arg = nil) ⇒ Object Also known as: each

Iterates on each subfeature object.

Arguments:

  • (optional) key: if specified, only iterates over subfeatures of this type


53
54
55
56
57
58
# File 'lib/feature.rb', line 53

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