Class: BioInterchange::Genomics::GFF3FeatureSet

Inherits:
Model
  • Object
show all
Defined in:
lib/biointerchange/genomics/gff3_feature_set.rb

Overview

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

Direct Known Subclasses

GVFFeatureSet, VCFFeatureSet

Instance Method Summary collapse

Constructor Details

#initializeGFF3FeatureSet

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



10
11
12
13
14
15
16
17
18
# 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

Instance Method Details

#add(feature) ⇒ Object

Adds a feature to the feature set.

feature

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



53
54
55
# File 'lib/biointerchange/genomics/gff3_feature_set.rb', line 53

def add(feature)
  @set[feature] = true
end

#contentsObject

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



21
22
23
# File 'lib/biointerchange/genomics/gff3_feature_set.rb', line 21

def contents
  @set.keys
end

#pragma(name) ⇒ Object

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



29
30
31
32
33
34
# 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

#pragmasObject

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



37
38
39
# File 'lib/biointerchange/genomics/gff3_feature_set.rb', line 37

def pragmas
  @pragmas.keys
end

#pruneObject

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.



69
70
71
# File 'lib/biointerchange/genomics/gff3_feature_set.rb', line 69

def prune
  @set.clear
end

#set_pragma(name, value) ⇒ Object

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



61
62
63
64
# 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

#uriObject

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



42
43
44
45
46
47
48
# 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