Class: Sequence

Inherits:
String
  • Object
show all
Defined in:
lib/parse_fasta/sequence.rb

Overview

Provide some methods for dealing with common tasks regarding nucleotide sequences.

Instance Method Summary collapse

Instance Method Details

#gc ⇒ 0, Float

Calculates GC content

Calculates GC content by dividing count of G + C divided by count of G + C + T + A + U. If there are both T's and U's in the Sequence, things will get weird, but then again, that wouldn't happen, now would it!

Examples:

Get GC of a Sequence

Sequence.new('ACTg').gc #=> 0.5

Using with FastaFile#each_record

FastaFile.open('reads.fna', 'r').each_record do |header, sequence|
  puts [header, sequence.gc].join("\t")
end

Returns:

  • (0) —

    if the Sequence is empty or there are no A, C, T, G or U present

  • (Float) —

    if the GC content is defined for the Sequence



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/parse_fasta/sequence.rb', line 40

def gc
  s = self.downcase
  c = s.count('c')
  g = s.count('g')
  t = s.count('t')
  a = s.count('a')
  u = s.count('u')
  
  return 0 if c + g + t + a + u == 0
  return (c + g).quo(c + g + t + a + u).to_f
end