Class: Bio::DB::Fasta::Region
- Inherits:
-
Object
- Object
- Bio::DB::Fasta::Region
- Defined in:
- lib/bio/db/fastadb.rb
Overview
Class to wrap a region of a chromosome
Constant Summary collapse
- BASE_COUNT_ZERO =
{:A => 0, :C => 0, :G => 0, :T => 0}
Instance Attribute Summary collapse
-
#average_coverage ⇒ Object
Returns the value of attribute average_coverage.
-
#base_ratios ⇒ Object
Returns the value of attribute base_ratios.
-
#bases ⇒ Object
Returns the value of attribute bases.
-
#called ⇒ Object
Returns the value of attribute called.
-
#consensus ⇒ Object
Returns the value of attribute consensus.
-
#coverages ⇒ Object
Returns the value of attribute coverages.
-
#end ⇒ Object
Returns the value of attribute end.
-
#entry ⇒ Object
Returns the value of attribute entry.
-
#orientation ⇒ Object
Returns the value of attribute orientation.
-
#pileup ⇒ Object
Returns the value of attribute pileup.
-
#reference ⇒ Object
Returns the value of attribute reference.
-
#start ⇒ Object
Returns the value of attribute start.
-
#total_cov ⇒ Object
Returns the value of attribute total_cov.
Class Method Summary collapse
-
.parse_region(reg_str) ⇒ Object
Returns a region object from a string in form “name:start-end”.
Instance Method Summary collapse
-
#base_ratios_for_base(base) ⇒ Object
TODO: Debug, as it hasnt been tested in the actual code.
-
#calculate_stats_from_pile(opts = {}) ⇒ Object
Calculates the concensus, base ratios, coverages and total coverages in the region * min_cov minimum coverage to make a call (default 0) * min_per minimum representation to make make a call.
-
#size ⇒ Object
(also: #length)
Length of the region.
- #to_s ⇒ Object
Instance Attribute Details
#average_coverage ⇒ Object
Returns the value of attribute average_coverage.
72 73 74 |
# File 'lib/bio/db/fastadb.rb', line 72 def average_coverage @average_coverage end |
#base_ratios ⇒ Object
Returns the value of attribute base_ratios.
72 73 74 |
# File 'lib/bio/db/fastadb.rb', line 72 def base_ratios @base_ratios end |
#bases ⇒ Object
Returns the value of attribute bases.
72 73 74 |
# File 'lib/bio/db/fastadb.rb', line 72 def bases @bases end |
#called ⇒ Object
Returns the value of attribute called.
72 73 74 |
# File 'lib/bio/db/fastadb.rb', line 72 def called @called end |
#consensus ⇒ Object
Returns the value of attribute consensus.
72 73 74 |
# File 'lib/bio/db/fastadb.rb', line 72 def consensus @consensus end |
#coverages ⇒ Object
Returns the value of attribute coverages.
72 73 74 |
# File 'lib/bio/db/fastadb.rb', line 72 def coverages @coverages end |
#end ⇒ Object
Returns the value of attribute end.
71 72 73 |
# File 'lib/bio/db/fastadb.rb', line 71 def end @end end |
#entry ⇒ Object
Returns the value of attribute entry.
71 72 73 |
# File 'lib/bio/db/fastadb.rb', line 71 def entry @entry end |
#orientation ⇒ Object
Returns the value of attribute orientation.
71 72 73 |
# File 'lib/bio/db/fastadb.rb', line 71 def orientation @orientation end |
#pileup ⇒ Object
Returns the value of attribute pileup.
72 73 74 |
# File 'lib/bio/db/fastadb.rb', line 72 def pileup @pileup end |
#reference ⇒ Object
Returns the value of attribute reference.
72 73 74 |
# File 'lib/bio/db/fastadb.rb', line 72 def reference @reference end |
#start ⇒ Object
Returns the value of attribute start.
71 72 73 |
# File 'lib/bio/db/fastadb.rb', line 71 def start @start end |
#total_cov ⇒ Object
Returns the value of attribute total_cov.
72 73 74 |
# File 'lib/bio/db/fastadb.rb', line 72 def total_cov @total_cov end |
Class Method Details
.parse_region(reg_str) ⇒ Object
Returns a region object from a string in form “name:start-end”
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/bio/db/fastadb.rb', line 130 def self.parse_region(reg_str) string = reg_str.delete("'") fields_1 = string.split(":") fields_2 = fields_1[1].split("-") raise FastaDBException.new(), "Invalid region. #{string}" if fields_1.length != 2 || fields_2.length != 2 reg = Region.new reg.entry = fields_1[0] reg.start = fields_2[0].to_i reg.end = fields_2[1].to_i if reg.end < reg.start reg.orientation = :reverse else reg.orientation = :forward end reg end |
Instance Method Details
#base_ratios_for_base(base) ⇒ Object
TODO: Debug, as it hasnt been tested in the actual code.
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/bio/db/fastadb.rb', line 75 def base_ratios_for_base(base) @all_ratios = Hash.new unless @all_ratios unless @all_ratios[base] ratios = Array.new for i in (0..region.size-1) ratios << @base_ratios[i][base] end @all_ratios[base] = ratios end @all_ratios[base] end |
#calculate_stats_from_pile(opts = {}) ⇒ Object
Calculates the concensus, base ratios, coverages and total coverages in the region
-
min_cov minimum coverage to make a call (default 0)
-
min_per minimum representation to make make a call. If more than one base
can be called, the IUAPC ambiguity code is returned
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/bio/db/fastadb.rb', line 91 def calculate_stats_from_pile(opts={}) min_cov = opts[:min_cov] ? opts[:min_cov] : 0 min_per = opts[:min_per] ? opts[:min_per] : 0.20 self.called = 0 reference = self.reference.downcase self.base_ratios = Array.new(self.size, BASE_COUNT_ZERO) self.bases = Array.new(self.size, BASE_COUNT_ZERO) self.coverages = Array.new(self.size, 0) self.total_cov = 0 self.pileup.each do | pile | if pile.coverage > min_cov self.base_ratios[pile.pos - self.start ] = pile.base_ratios reference[pile.pos - self.start ] = pile.consensus_iuap(min_per).upcase self.coverages[pile.pos - self.start ] = pile.coverage.to_i self.bases[pile.pos - self.start ] = pile.bases self.called += 1 end #puts "#{pile.pos}\t#{bef}\t#{reference[pile.pos - region.start - 1 ]} " self.total_cov += pile.coverage end self.consensus = Bio::Sequence.new(reference) self.consensus.na if self.orientation == :reverse self.consensus.reverse_complement!() end self.average_coverage = self.total_cov.to_f/self.size.to_f self end |
#size ⇒ Object Also known as: length
Length of the region
150 151 152 |
# File 'lib/bio/db/fastadb.rb', line 150 def size @end - @start end |
#to_s ⇒ Object
124 125 126 127 |
# File 'lib/bio/db/fastadb.rb', line 124 def to_s string = @entry + ":" + @start.to_s + "-" + @end.to_s string end |