rosalind/gc.rb
Code:
# Rosalind Problem GC: Computing GC Content
# https://rosalind.info/problems/gc/
require_relative './helpers.rb'
def parse(dataset)
chunks = []
for line in dataset do
line[0] == '>' ? chunks.push([line, '']) : chunks.last[1] += line
end
return chunks
end
def solve(dataset)
max = ['', 0]
parse(dataset).each do |set, dna|
perc = 100 * (dna.count('G') + dna.count('C')) / dna.size.to_f
max = [set, perc] if max[1] < perc
end
return max
end
puts solve(get_dataset(problem: 'GC', sample: true))
puts solve(get_dataset(problem: 'GC'))
Output:
>Rosalind_0808
60.91954022988506
>Rosalind_3716
54.37636761487965