Class: GTF::Gene
- Inherits:
-
Object
- Object
- GTF::Gene
- Includes:
- Enumerable, IntervalList
- Defined in:
- lib/gtf/gene.rb
Instance Attribute Summary collapse
-
#intervals ⇒ Object
readonly
Returns the value of attribute intervals.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#strand ⇒ Object
readonly
Returns the value of attribute strand.
-
#transcripts ⇒ Object
readonly
Returns the value of attribute transcripts.
Instance Method Summary collapse
- #canonical ⇒ Object
- #each ⇒ Object
- #exons ⇒ Object
-
#initialize(intervals) ⇒ Gene
constructor
A new instance of Gene.
- #inspect ⇒ Object
- #method_missing(sym, *args, &block) ⇒ Object
- #respond_to_missing?(sym, include_all = false) ⇒ Boolean
- #site(pos) ⇒ Object
-
#unified ⇒ Object
compute unified intervals from the list of intervals.
Methods included from IntervalList
#add_interval, #flatten, #interval_set, #nearest, #overlap, #present
Constructor Details
#initialize(intervals) ⇒ Gene
Returns a new instance of Gene.
21 22 23 24 25 26 27 |
# File 'lib/gtf/gene.rb', line 21 def initialize intervals @intervals = intervals.sort_by &:start @gene = @intervals.find{|l| l.feature == "gene"} @name = @gene.attribute[:gene_name] @strand = @gene.strand @transcripts = build_transcripts end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object
69 70 71 |
# File 'lib/gtf/gene.rb', line 69 def method_missing sym, *args, &block @gene.send sym, *args, &block end |
Instance Attribute Details
#intervals ⇒ Object (readonly)
Returns the value of attribute intervals.
20 21 22 |
# File 'lib/gtf/gene.rb', line 20 def intervals @intervals end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
20 21 22 |
# File 'lib/gtf/gene.rb', line 20 def name @name end |
#strand ⇒ Object (readonly)
Returns the value of attribute strand.
20 21 22 |
# File 'lib/gtf/gene.rb', line 20 def strand @strand end |
#transcripts ⇒ Object (readonly)
Returns the value of attribute transcripts.
20 21 22 |
# File 'lib/gtf/gene.rb', line 20 def transcripts @transcripts end |
Instance Method Details
#canonical ⇒ Object
55 56 57 58 59 |
# File 'lib/gtf/gene.rb', line 55 def canonical # find out which transcript has the longest cds canon = @transcripts.max_by &:canonical_transcript_score canon if canon.cds_size end |
#each ⇒ Object
29 30 31 32 33 |
# File 'lib/gtf/gene.rb', line 29 def each @intervals.each do |int| yield int end end |
#exons ⇒ Object
51 52 53 |
# File 'lib/gtf/gene.rb', line 51 def exons @exons ||= @intervals.select{|e| e.feature == "exon"} end |
#inspect ⇒ Object
61 62 63 |
# File 'lib/gtf/gene.rb', line 61 def inspect "#<#{self.class.name}:#{object_id} @transcripts=#{@transcripts.count}>" end |
#respond_to_missing?(sym, include_all = false) ⇒ Boolean
65 66 67 |
# File 'lib/gtf/gene.rb', line 65 def respond_to_missing? sym, include_all = false @gene.respond_to?(sym) || super end |
#site(pos) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/gtf/gene.rb', line 35 def site pos score = { :cds => 1, :exon => 2, :utr => 3, :intron => 4, :transcript => 5, :igr => 6 } sites = @transcripts.map do |t| { :gene => name }.update(t.site pos) if t.contains? pos end.compact sites.push(:type => :igr) sites.sort_by{|s| score[s[:type]] }.first end |
#unified ⇒ Object
compute unified intervals from the list of intervals
45 46 47 48 49 |
# File 'lib/gtf/gene.rb', line 45 def unified @unified ||= exons.flatten do |unif| unif.feature = "unified" end end |