Class: Bix::Gtf
- Inherits:
-
Object
- Object
- Bix::Gtf
- Defined in:
- lib/bix/gtf.rb
Instance Attribute Summary collapse
-
#chr ⇒ Object
Returns the value of attribute chr.
-
#feature ⇒ Object
Returns the value of attribute feature.
-
#frame ⇒ Object
Returns the value of attribute frame.
-
#prog ⇒ Object
Returns the value of attribute prog.
-
#props ⇒ Object
Returns the value of attribute props.
-
#score ⇒ Object
Returns the value of attribute score.
-
#start ⇒ Object
Returns the value of attribute start.
-
#stop ⇒ Object
Returns the value of attribute stop.
-
#strand ⇒ Object
Returns the value of attribute strand.
Class Method Summary collapse
-
.get_all(io, feature_regex = //) ⇒ Object
E.g.
- .get_all_by_prop(io, prop_key, feature_regex = //) ⇒ Object
Instance Method Summary collapse
Instance Attribute Details
#chr ⇒ Object
Returns the value of attribute chr.
5 6 7 |
# File 'lib/bix/gtf.rb', line 5 def chr @chr end |
#feature ⇒ Object
Returns the value of attribute feature.
5 6 7 |
# File 'lib/bix/gtf.rb', line 5 def feature @feature end |
#frame ⇒ Object
Returns the value of attribute frame.
5 6 7 |
# File 'lib/bix/gtf.rb', line 5 def frame @frame end |
#prog ⇒ Object
Returns the value of attribute prog.
5 6 7 |
# File 'lib/bix/gtf.rb', line 5 def prog @prog end |
#props ⇒ Object
Returns the value of attribute props.
5 6 7 |
# File 'lib/bix/gtf.rb', line 5 def props @props end |
#score ⇒ Object
Returns the value of attribute score.
5 6 7 |
# File 'lib/bix/gtf.rb', line 5 def score @score end |
#start ⇒ Object
Returns the value of attribute start.
5 6 7 |
# File 'lib/bix/gtf.rb', line 5 def start @start end |
#stop ⇒ Object
Returns the value of attribute stop.
5 6 7 |
# File 'lib/bix/gtf.rb', line 5 def stop @stop end |
#strand ⇒ Object
Returns the value of attribute strand.
5 6 7 |
# File 'lib/bix/gtf.rb', line 5 def strand @strand end |
Class Method Details
.get_all(io, feature_regex = //) ⇒ Object
E.g. to get all exons
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/bix/gtf.rb', line 42 def self.get_all(io, feature_regex=//) gtfs = [] for line in io g = Gtf.new g.from_line(line) if g.feature =~ feature_regex gtfs << g end end return gtfs end |
.get_all_by_prop(io, prop_key, feature_regex = //) ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/bix/gtf.rb', line 54 def self.get_all_by_prop(io, prop_key, feature_regex=//) gtfs = get_all(io, feature_regex) gtfs_by_key = {} for g in gtfs gtfs_by_key[g.props[prop_key]] ||= [] gtfs_by_key[g.props[prop_key]] << g end return gtfs_by_key end |
Instance Method Details
#from_line(line) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/bix/gtf.rb', line 7 def from_line(line) f = line.chomp.rstrip.split("\t", -1) @chr = f[0] @prog = f[1] @feature = f[2] @start = f[3].to_i raise if @start < 1 @stop = f[4].to_i raise if @stop < 1 @score = f[5] @strand = f[6] raise if @strand.size > 1 @frame = f[7] group = f[8] group.gsub!(/; /, " ") # Remove semicolons group.gsub!(/;$/, "") # Remove semicolons f = CSV::parse_line(group, :col_sep => ' ') raise "Unexpected number of fields in group: '#{f[7]}'" unless f.size % 2 == 0 @props = {} while f.size > 0 key = f.shift value = f.shift @props[key] = value end end |
#size ⇒ Object
37 38 39 |
# File 'lib/bix/gtf.rb', line 37 def size return @stop - @start + 1 end |
#to_s ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/bix/gtf.rb', line 64 def to_s propstr = "" i = 0 for key, value in @props if i > 0 propstr << " " end if value.include?(" ") propstr << "#{key} \"#{value}\";" else propstr << "#{key} #{value};" end i += 1 end return [@chr, @prog, @feature, @start, @stop, @score, @strand, @frame, propstr].join("\t") end |