-# Copyright (C) 2007-2011 Martin A. Hansen.
+# Copyright (C) 2007-2012 Martin A. Hansen.
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
self.seq.scan(regex).size
end
+ # Method to remove indels from seq and qual if qual.
+ def indels_remove
+ if self.qual.nil?
+ self.seq.delete!(Regexp.escape(INDELS.join('')))
+ else
+ na_seq = NArray.to_na(self.seq, "byte")
+ na_qual = NArray.to_na(self.qual, "byte")
+ mask = NArray.byte(self.length)
+
+ INDELS.each do |c|
+ mask += na_seq.eq(c.ord)
+ end
+
+ mask = mask.eq(0)
+
+ self.seq = na_seq[mask].to_s
+ self.qual = na_qual[mask].to_s
+ end
+
+ self
+ end
+
# Method that returns true is a given sequence type is DNA.
def is_dna?
self.type == 'dna'
assert_equal("ghhhhhg", @entry.qual)
end
+ def test_Seq_indels_remove_without_qual_returns_correctly
+ @entry.seq = "A-T.CG~CG"
+ @entry.qual = nil
+ assert_equal("ATCGCG", @entry.indels_remove.seq)
+ end
+
+ def test_Seq_indels_remove_with_qual_returns_correctly
+ @entry.seq = "A-T.CG~CG"
+ @entry.qual = "a@b@cd@fg"
+ assert_equal("ATCGCG", @entry.indels_remove.seq)
+ assert_equal("abcdfg", @entry.indels_remove.qual)
+ end
+
def test_Seq_composition_returns_correctly
@entry.seq = "AAAATTTCCG"
assert_equal(4, @entry.composition["A"])