Class: GTF

Inherits:
HashTable show all
Extended by:
GermDefault
Includes:
IntervalList
Defined in:
lib/gtf.rb,
lib/gtf/gene.rb

Defined Under Namespace

Classes: Feature, Gene, Transcript

Constant Summary

Constants included from GermDefault

GermDefault::CACHE

Instance Attribute Summary

Attributes inherited from HashTable

#header, #types

Class Method Summary collapse

Instance Method Summary collapse

Methods included from GermDefault

cache, cache_load, default, has_default, method_missing

Methods included from IntervalList

#add_interval, #flatten, #interval_set, #nearest, #overlap, #present

Methods inherited from HashTable

#<<, #[], #concat, #each, #formatted_header, header_off, header_on, #idx, #idx_keys, line_class, line_type, #output, #preamble, #sample, #select!, #sort_by!, #sum, #update_index, #use_header?, use_header?, #wrap

Methods included from HashTableAux

#load_file

Methods included from Printer

#print, #write

Constructor Details

#initialize(file, opts = nil) ⇒ GTF

Returns a new instance of GTF.



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/gtf.rb', line 47

def initialize file, opts=nil
  opts = { :comment => "#", :sep => " "}.merge(opts || {})

  @sep = opts[:sep]

  @genes = {}

  super file, :comment => opts[:comment], :idx => opts[:idx],
    :header => [ :seqname, :source, :feature, :start, :stop, :score, :strand, :frame, :attribute ],
    :types => { :start => :int, :stop => :int, :score => :int, :frame =>
                :int, :attribute => [ ";", @sep ] }
end

Class Method Details

.default_create(file, idx = nil) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/gtf.rb', line 13

def self.default_create file, idx=nil
  if idx
    new file, :idx => idx
  else
    new file
  end
end

Instance Method Details

#add_line(hash) ⇒ Object



68
69
70
# File 'lib/gtf.rb', line 68

def add_line hash
  add_interval(super)
end

#fastaObject



64
65
66
# File 'lib/gtf.rb', line 64

def fasta
  @opts[:fasta] || Fasta.default
end

#gene(name) ⇒ Object



2
3
4
5
# File 'lib/gtf/gene.rb', line 2

def gene name
  intervals = idx(:gene_name,name)
  @genes[name] ||= GTF::Gene.new intervals if intervals
end

#inspectObject



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

def inspect
  "#<#{self.class}:0x#{'%x' % (object_id << 1)} @lines=#{@lines.count}>"
end

#promotersObject



7
8
9
10
11
12
13
14
15
# File 'lib/gtf/gene.rb', line 7

def promoters
  @promoters ||= begin
    promoters = []
    idx_keys(:gene_name).each do |name|
      promoters.concat gene(name).transcripts.map(&:transcript_start)
    end
    wrap promoters
  end
end