- # Method to initialize a Consensus object given a Seq object, which is added
- # to the Consensus.
- def initialize(length)
- @length = length
-
- @count = NArray.int(@length)
- @freq = NArray.int(@length, ALPH_DNA.size)
- @qual = NArray.int(@length, ALPH_DNA.size)
- @mask_A = NArray.byte(@length).fill!(BIT_A)
- @mask_T = NArray.byte(@length).fill!(BIT_T)
- @mask_C = NArray.byte(@length).fill!(BIT_C)
- @mask_G = NArray.byte(@length).fill!(BIT_G)
- @has_qual = false
- end
-
- # Method to add a Seq entry to a Consensus object.
- def add(entry)
- seq = NArray.to_na(entry.seq.downcase.tr(TR_NUC, TR_HEX), "byte")
-
- @count += seq > 0
-
- mask_A = (seq & @mask_A) > 0
- mask_T = (seq & @mask_T) > 0
- mask_C = (seq & @mask_C) > 0
- mask_G = (seq & @mask_G) > 0
-
- @freq[true, ROW_A] += mask_A
- @freq[true, ROW_T] += mask_T
- @freq[true, ROW_C] += mask_C
- @freq[true, ROW_G] += mask_G
-
- unless entry.qual.nil?
- @has_qual = true
-
- qual = NArray.to_na(entry.qual, "byte") - QUAL_BASE
-
- @qual[true, ROW_A] += mask_A * qual
- @qual[true, ROW_T] += mask_T * qual
- @qual[true, ROW_C] += mask_C * qual
- @qual[true, ROW_G] += mask_G * qual
+ # Method to initialize a Consensus object given a list of aligned Seq object.
+ def initialize(entries, options)
+ @entries = entries
+ @options = options
+
+ @cols = entries.first.seq.length
+ @rows = entries.size
+
+ @has_qual = entries.first.qual.nil? ? false : true
+
+ @na_seq = NArray.byte(@cols, @rows)
+ @na_qual = NArray.byte(@cols, @rows) if @has_qual
+
+ na_add_entries
+ consensus_calc
+ end
+
+ # Method that lowercase residues that have been removed during
+ # the determination of the consensus sequence.
+ def mask_entries!
+ na_seq = NArray.byte(@cols, @rows)
+
+ @entries.each_with_index do |entry, i|
+ na_seq[true, i] = NArray.to_na(entry.seq.upcase, "byte")
+ end
+
+ na_seq += ((na_seq.ne('-'.ord) - @na_seq.ne(0)) * ' '.ord)
+
+ @entries.each_with_index do |entry, i|
+ entry.seq = na_seq[true, i].to_s