Class: GTF::Gene

Inherits:
Object
  • Object
show all
Includes:
Enumerable, IntervalList
Defined in:
lib/gtf/gene.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#intervalsObject (readonly)

Returns the value of attribute intervals.



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

def intervals
  @intervals
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#strandObject (readonly)

Returns the value of attribute strand.



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

def strand
  @strand
end

#transcriptsObject (readonly)

Returns the value of attribute transcripts.



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

def transcripts
  @transcripts
end

Instance Method Details

#canonicalObject



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

#eachObject



29
30
31
32
33
# File 'lib/gtf/gene.rb', line 29

def each
  @intervals.each do |int|
    yield int
  end
end

#exonsObject



51
52
53
# File 'lib/gtf/gene.rb', line 51

def exons
  @exons ||= @intervals.select{|e| e.feature == "exon"}
end

#inspectObject



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

Returns:

  • (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

#unifiedObject

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