Class: Bio::Feature

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

Overview

DESCRIPTION

Container for the sequence annotation.

USAGE

# Create a Bio::Feature object.
# For example: the GenBank-formatted entry in genbank for accession M33388
# contains the following feature:
#    exon     1532..1799
#             /gene="CYP2D6"
#             /note="cytochrome P450 IID6; GOO-132-127"
#             /number="1"
feature = Bio::Feature.new('exon','1532..1799')
feature.append(Bio::Feature::Qualifier.new('gene', 'CYP2D6'))
feature.append(Bio::Feature::Qualifier.new('note', 'cytochrome P450 IID6'))
feature.append(Bio::Feature::Qualifier.new('number', '1'))

# or all in one go:
feature2 = Bio::Feature.new('exon','1532..1799',
  [ Bio::Feature::Qualifier.new('gene', 'CYP2D6'),
    Bio::Feature::Qualifier.new('note', 'cytochrome P450 IID6; GOO-132-127'),
    Bio::Feature::Qualifier.new('number', '1')
  ])

# Print the feature
puts feature.feature + "\t" + feature.position
feature.each do |qualifier|
  puts "- " + qualifier.qualifier + ": " + qualifier.value
end

REFERENCES

INSD feature table definition

www.ddbj.nig.ac.jp/FT/full_index.html

Defined Under Namespace

Classes: Qualifier

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(feature = '', position = '', qualifiers = []) ⇒ Feature

Create a new Bio::Feature object. Arguments:

  • (required) feature: type of feature (e.g. “exon”)

  • (required) position: position of feature (e.g. “complement(1532..1799)”)

  • (opt) qualifiers: list of Bio::Feature::Qualifier objects (default: [])

Returns

Bio::Feature object



52
53
54
# File 'lib/bio/feature.rb', line 52

def initialize(feature = '', position = '', qualifiers = [])
  @feature, @position, @qualifiers = feature, position, qualifiers
end

Instance Attribute Details

#featureObject

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



57
58
59
# File 'lib/bio/feature.rb', line 57

def feature
  @feature
end

#positionObject

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



60
61
62
# File 'lib/bio/feature.rb', line 60

def position
  @position
end

#qualifiersObject

Returns an Array of Qualifier objects.



63
64
65
# File 'lib/bio/feature.rb', line 63

def qualifiers
  @qualifiers
end

Instance Method Details

#[](key) ⇒ Object

Short cut for the Bio::Feature#to_hash



112
113
114
# File 'lib/bio/feature.rb', line 112

def [](key)
  self.to_hash[key]
end

#append(a) ⇒ Object

Appends a Qualifier object to the Feature.

Arguments:

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

Returns

Bio::Feature object



75
76
77
78
# File 'lib/bio/feature.rb', line 75

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

#assocObject

Returns a Hash constructed from qualifier objects.



92
93
94
95
96
97
98
99
# File 'lib/bio/feature.rb', line 92

def assoc
  STDERR.puts "Bio::Feature#assoc is deprecated, use Bio::Feature#to_hash instead" if $DEBUG
  hash = Hash.new
  @qualifiers.each do |x|
    hash[x.qualifier] = x.value
  end
  return hash
end

#each(arg = nil) ⇒ Object

Iterates on each qualifier object.

Arguments:

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



84
85
86
87
88
89
# File 'lib/bio/feature.rb', line 84

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

#locationsObject

Returns a Bio::Locations object translated from the position string.



66
67
68
# File 'lib/bio/feature.rb', line 66

def locations
  Locations.new(@position)
end

#to_hashObject

Returns a Hash constructed from qualifier objects.



102
103
104
105
106
107
108
109
# File 'lib/bio/feature.rb', line 102

def to_hash
  hash = Hash.new
  @qualifiers.each do |x|
    hash[x.qualifier] ||= []
    hash[x.qualifier] << x.value
  end
  return hash
end