Rosalind problem "Consensus and Profile"
I am going to ignore all the file reading code, which is extraneous to the problem, and focus just on simplifying the code to find the consensus.  It can be done in essentially a single a line, the one beginning consensus = ....  Everything else is just setting up the sample data.

transpose gets us the columns, and max_by ... count get us the most frequently occurring nucleotide:

matrix = &lt;&lt;EOS
A T C C A G C T
G G G C A A C T
A T G G A T C T
A A G C A A C C
T T G G A A C T
A T G C C A T T
A T G G C A C T
EOS
.split("\n").map{|x| x.split(' ')}

nucleotides = %w(A C G T)

consensus = matrix.transpose.map {|x| nucleotides.max_by {|n| x.count(n)}}

p consensus #=&gt; ["A", "T", "G", "C", "A", "A", "C", "T"]