class BioInterchange::Genomics::GFF3FeatureSet

A GFF3 feature set, which encapsules information of a single GFF3 file.

Public Class Methods

new() click to toggle source

Create a new instance of a Generic Feature Format Version 3 (GFF3) feature set. A feature set can contain multiple GFF3 features.

# File lib/biointerchange/genomics/gff3_feature_set.rb, line 10
def initialize
  # Features are stored as the keys of a hash map to increase performance:
  @set = {}
  # Pragmas, i.e. feature meta-information, are stored as named mappings. Many
  # pragmas are simple key/value assignments, but others permit multiple values
  # whose ordering does matter. In that case, an array is used to store the
  # various values.
  @pragmas = {}
end

Public Instance Methods

add(feature) click to toggle source

Adds a feature to the feature set.

feature

feature instance that is added to the contents of this feature set

# File lib/biointerchange/genomics/gff3_feature_set.rb, line 53
def add(feature)
  @set[feature] = true
end
contents() click to toggle source

Returns the contents of the feature set – excluding pragma meta-data.

# File lib/biointerchange/genomics/gff3_feature_set.rb, line 21
def contents
  @set.keys
end
pragma(name) click to toggle source

Returns information stored for a named pragma, or nil if there is no information stored for it.

name

a string representing the name of the pragma whose value we are interested in

# File lib/biointerchange/genomics/gff3_feature_set.rb, line 29
def pragma(name)
  return nil unless name
  # TODO Should throw exception if name is not a string.
  return nil unless name.kind_of?(String)
  @pragmas[name]
end
pragmas() click to toggle source

Returns the names of all the pragmas for which some information has been recorded.

# File lib/biointerchange/genomics/gff3_feature_set.rb, line 37
def pragmas
  @pragmas.keys
end
prune() click to toggle source

Removes all features from the set, but keeps the pragmas. This enables batched processing, since the URI for the set is only determined by the pragma statement contents.

# File lib/biointerchange/genomics/gff3_feature_set.rb, line 69
def prune
  @set.clear
end
set_pragma(name, value) click to toggle source

Sets the value for named pragma meta-data.

name

a string representing the unique name of the pragma

value

on object representing the value of the pragma assignment

# File lib/biointerchange/genomics/gff3_feature_set.rb, line 61
def set_pragma(name, value)
  # TODO Should throw exception if name is not a string.
  @pragmas[name] = value
end
uri() click to toggle source

Returns an URI for this particular feature set, which is a SHA1 hash over the pragma's concatenated properties.

# File lib/biointerchange/genomics/gff3_feature_set.rb, line 42
def uri
  clob = ''
  pragmas.each { |pragma_name|
    clob << "#{pragma_name}\t#{pragma(pragma_name).to_s}\n"
  }
  "biointerchange://gff3/featureset/self/#{Digest::SHA1.hexdigest(clob)}"
end