#!/usr/bin/env ruby
+$:.unshift File.join(File.dirname(__FILE__), '..', '..')
+
+# Copyright (C) 2011 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
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+# http://www.gnu.org/copyleft/gpl.html
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+# This software is part of the Biopieces framework (www.biopieces.org).
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
require 'maasha/seq'
require 'test/unit'
-require 'pp'
+require 'test/helper'
class TestSeq < Test::Unit::TestCase
def setup
@entry = Seq.new
end
- # def test_Seq# autoremoves whitespace, newlines, and carriage returns
- # dna = Seq.new
- # dna.seq = "A\tT\r\tC\nG "
- # assert_equal(dna.seq, "ATCG")
- # end
-
- def test_Seq_new_bp_returns_correctly
- record = {:SEQ_NAME => "test", :SEQ => "ATCG", :SEQ_TYPE => "dna", :SCORES => "hhhh"}
+ test "Seq.new_bp returns correctly" do
+ record = {:SEQ_NAME => "test", :SEQ => "ATCG", :SEQ_TYPE => :dna, :SCORES => "hhhh"}
seq = Seq.new_bp(record)
assert_equal("test", seq.seq_name)
assert_equal("ATCG", seq.seq)
- assert_equal("dna", seq.type)
+ assert_equal(:dna, seq.type)
assert_equal("hhhh", seq.qual)
end
- def test_Seq_is_dna_with_no_sequence_type_returns_false
+ test "#is_dna? with no sequence type returns false" do
assert(@entry.is_dna? == false)
end
- def test_Seq_is_dna_with_dna_sequence_type_returns_true
- @entry.type = 'dna'
+ test "#is_dna? with dna sequence type returns true" do
+ @entry.type = :dna
assert(@entry.is_dna? == true)
end
- def test_Seq_is_rna_with_no_sequence_type_returns_false
+ test "#is_rna? with no sequence type returns false" do
assert(@entry.is_rna? == false)
end
- def test_Seq_is_rna_with_rna_sequence_type_returns_true
- @entry.type = 'rna'
+ test "#is_rna? with rna sequence type returns true" do
+ @entry.type = :rna
assert(@entry.is_rna? == true)
end
- def test_Seq_is_protein_with_no_sequence_type_returns_false
+ test "#is_protein? with no sequence type returns false" do
assert(@entry.is_protein? == false)
end
- def test_Seq_is_protein_with_protein_sequence_type_returns_true
- @entry.type = 'protein'
+ test "#is_protein? with protein sequence type returns true" do
+ @entry.type = :protein
assert_equal(true, @entry.is_protein?)
end
- def test_Seq_type_guess_without_sequence_raises
+ test "#type_guess without sequence raises" do
assert_raise(SeqError) { @entry.type_guess }
end
- def test_Seq_type_guess_with_protein_returns_protein
+ test "#type_guess with protein returns protein" do
@entry.seq = 'atcatcrFgatcg'
- assert_equal('protein', @entry.type_guess)
+ assert_equal(:protein, @entry.type_guess)
end
- def test_Seq_type_guess_with_rna_returns_rna
+ test "#type_guess with rna returns rna" do
@entry.seq = 'atcatcrUgatcg'
- assert_equal('rna', @entry.type_guess)
+ assert_equal(:rna, @entry.type_guess)
end
- def test_Seq_type_guess_with_dna_returns_dna
+ test "#type_guess with dna returns dna" do
@entry.seq = 'atcatcgatcg'
- assert_equal('dna', @entry.type_guess)
+ assert_equal(:dna, @entry.type_guess)
end
- def test_Seq_type_guess_EM_without_sequence_raises
+ test "#type_guess! without sequence raises" do
assert_raise(SeqError) { @entry.type_guess! }
end
- def test_Seq_type_guess_EM_with_protein_returns_protein
+ test "#type_guess! with protein returns protein" do
@entry.seq = 'atcatcrFgatcg'
@entry.type_guess!
- assert_equal('protein', @entry.type)
+ assert_equal(:protein, @entry.type)
end
- def test_Seq_type_guess_EM_with_rna_returns_rna
+ test "#type_guess! with rna returns rna" do
@entry.seq = 'atcatcrUgatcg'
@entry.type_guess!
- assert_equal('rna', @entry.type)
+ assert_equal(:rna, @entry.type)
end
- def test_Seq_type_guess_EM_with_dna_returns_dna
+ test "#type_guess! with dna returns dna" do
@entry.seq = 'atcatcgatcg'
@entry.type_guess!
- assert_equal('dna', @entry.type)
+ assert_equal(:dna, @entry.type)
end
- def test_Seq_length_is_correct
+ test "#length returns corretly" do
@entry.seq = 'ATCG'
assert_equal(4, @entry.length)
end
- def test_Seq_indels_is_correct
+ test "#indels returns correctly" do
@entry.seq = 'ATCG.-~_'
assert_equal(4, @entry.indels)
end
- def test_Seq_to_rna_raises_if_no_sequence
- @entry.type = 'dna'
+ test "#to_rna with no sequence raises" do
+ @entry.type = :dna
assert_raise(SeqError) { @entry.to_rna }
end
- def test_Seq_to_rna_raises_on_bad_type
+ test "#to_rna with bad type raises" do
@entry.seq = 'ATCG'
- @entry.type = 'rna'
+ @entry.type = :rna
assert_raise(SeqError) { @entry.to_rna }
end
- def test_Seq_to_rna_transcribes_correctly
+ test "#to_rna transcribes correctly" do
@entry.seq = 'ATCGatcg'
- @entry.type = 'dna'
+ @entry.type = :dna
assert_equal("AUCGaucg", @entry.to_rna)
end
- def test_Seq_to_rna_changes_entry_type_to_rna
+ test "#to_rna changes entry type to rna" do
@entry.seq = 'ATCGatcg'
- @entry.type = 'dna'
+ @entry.type = :dna
@entry.to_rna
- assert_equal("rna", @entry.type)
+ assert_equal(:rna, @entry.type)
end
- def test_Seq_to_dna_raises_if_no_sequence
- @entry.type = 'rna'
+ test "#to_dna with no sequence raises" do
+ @entry.type = :rna
assert_raise(SeqError) { @entry.to_dna }
end
- def test_Seq_to_dna_raises_on_bad_type
+ test "#to_dna with bad type raises" do
@entry.seq = 'AUCG'
- @entry.type = 'dna'
+ @entry.type = :dna
assert_raise(SeqError) { @entry.to_dna }
end
- def test_Seq_to_dna_transcribes_correctly
+ test "#to_dna transcribes correctly" do
@entry.seq = 'AUCGaucg'
- @entry.type = 'rna'
+ @entry.type = :rna
assert_equal("ATCGatcg", @entry.to_dna)
end
- def test_Seq_to_dna_changes_entry_type_to_dna
+ test "#to_dna changes entry type to dna" do
@entry.seq = 'AUCGaucg'
- @entry.type = 'rna'
+ @entry.type = :rna
@entry.to_dna
- assert_equal("dna", @entry.type)
+ assert_equal(:dna, @entry.type)
end
- def test_Seq_to_bp_returns_correct_record
+ test "#to_bp returns correct record" do
@entry.seq_name = 'test'
@entry.seq = 'ATCG'
assert_equal({:SEQ_NAME=>"test", :SEQ=>"ATCG", :SEQ_LEN=>4}, @entry.to_bp)
end
- def test_Seq_to_bp_raises_on_missing_seq_name
+ test "#to_bp with missing seq_name raises" do
@entry.seq = 'ATCG'
assert_raise(SeqError) { @entry.to_bp }
end
- def test_Seq_to_bp_raises_on_missing_sequence
+ test "#to_bp with missing sequence raises" do
@entry.seq_name = 'test'
assert_raise(SeqError) { @entry.to_bp }
end
- def test_Seq_to_fasta_raises_on_missing_seq_name
+ test "#to_fasta with missing seq_name raises" do
@entry.seq = 'ATCG'
assert_raise(SeqError) { @entry.to_fasta }
end
- def test_Seq_to_fasta_raises_on_empty_seq_name
+ test "#to_fasta with empty seq_name raises" do
@entry.seq_name = ''
@entry.seq = 'ATCG'
assert_raise(SeqError) { @entry.to_fasta }
end
- def test_Seq_to_fasta_raises_on_missing_seq
+ test "#to_fasta with missing seq raises" do
@entry.seq_name = 'test'
assert_raise(SeqError) { @entry.to_fasta }
end
- def test_Seq_to_fasta_raises_on_empty_seq
+ test "#to_fasta with empty seq raises" do
@entry.seq_name = 'test'
@entry.seq = ''
assert_raise(SeqError) { @entry.to_fasta }
end
- def test_Seq_to_fasta_returns_correct_entry
+ test "#to_fasta returns correct entry" do
@entry.seq_name = 'test'
@entry.seq = 'ATCG'
assert_equal(">test\nATCG\n", @entry.to_fasta)
end
- def test_Seq_to_fasta_wraps_correctly
+ test "#to_fasta wraps correctly" do
entry = Seq.new("test", "ATCG")
assert_equal(">test\nAT\nCG\n", entry.to_fasta(2))
end
- def test_Seq_to_fastq_returns_correct_entry
+ test "#to_fastq returns correct entry" do
@entry.seq_name = 'test'
@entry.seq = 'ATCG'
@entry.qual = 'hhhh'
assert_equal("@test\nATCG\n+\nhhhh\n", @entry.to_fastq)
end
- def test_Seq_to_key_with_bad_residue_raises
+ test "#to_key with bad residue raises" do
entry = Seq.new("test", "AUCG")
assert_raise(SeqError) { entry.to_key }
end
- def test_Seq_to_key_returns_correctly
+ test "#to_key returns correctly" do
entry = Seq.new("test", "ATCG")
assert_equal(54, entry.to_key)
end
- def test_Seq_reverse_returns_correctly
+ test "#reverse returns correctly" do
@entry.seq = "ATCG"
- assert_equal("GCTA", @entry.reverse.seq)
+ new_entry = @entry.reverse
+ assert_equal("GCTA", new_entry.seq)
+ assert_equal("ATCG", @entry.seq)
end
- def test_Seq_complement_raises_if_no_sequence
- @entry.type = 'dna'
+ test "#reverse! returns correctly" do
+ @entry.seq = "ATCG"
+ @entry.reverse!
+ assert_equal("GCTA", @entry.seq)
+ end
+
+ test "#complement with no sequence raises" do
+ @entry.type = :dna
assert_raise(SeqError) { @entry.complement }
end
- def test_Seq_complement_raises_on_bad_type
+ test "#complement with bad type raises" do
@entry.seq = 'ATCG'
- @entry.type = 'protein'
+ @entry.type = :protein
assert_raise(SeqError) { @entry.complement }
end
- def test_Seq_complement_for_DNA_is_correct
+ test "#complement for DNA is correct" do
@entry.seq = 'ATCGatcg'
- @entry.type = 'dna'
- assert_equal("TAGCtagc", @entry.complement)
+ @entry.type = :dna
+ comp = @entry.complement
+ assert_equal("TAGCtagc", comp.seq)
+ assert_equal("ATCGatcg", @entry.seq)
end
- def test_Seq_complement_for_RNA_is_correct
+ test "#complement for RNA is correct" do
@entry.seq = 'AUCGaucg'
- @entry.type = 'rna'
- assert_equal("UAGCuagc", @entry.complement)
+ @entry.type = :rna
+ comp = @entry.complement
+ assert_equal("UAGCuagc", comp.seq)
+ assert_equal("AUCGaucg", @entry.seq)
end
- def test_Seq_reverse_complement_for_DNA_is_correct
+ test "#complement! with no sequence raises" do
+ @entry.type = :dna
+ assert_raise(SeqError) { @entry.complement! }
+ end
+
+ test "#complement! with bad type raises" do
+ @entry.seq = 'ATCG'
+ @entry.type = :protein
+ assert_raise(SeqError) { @entry.complement! }
+ end
+
+ test "#complement! for DNA is correct" do
@entry.seq = 'ATCGatcg'
- @entry.type = 'dna'
- assert_equal("cgatCGAT", @entry.reverse_complement.seq)
+ @entry.type = :dna
+ assert_equal("TAGCtagc", @entry.complement!.seq)
end
- def test_Seq_reverse_complement_for_RNA_is_correct
+ test "#complement! for RNA is correct" do
@entry.seq = 'AUCGaucg'
- @entry.type = 'rna'
- assert_equal("cgauCGAU", @entry.reverse_complement.seq)
+ @entry.type = :rna
+ assert_equal("UAGCuagc", @entry.complement!.seq)
end
- def test_Seq_hamming_distance_returns_correctly
+
+ test "#hamming distance returns correctly" do
seq1 = Seq.new("test1", "ATCG")
seq2 = Seq.new("test2", "atgg")
assert_equal(1, seq1.hamming_distance(seq2))
end
- def test_Seq_generate_with_length_lt_1_raises
- assert_raise(SeqError) { @entry.generate(-10, "dna") }
- assert_raise(SeqError) { @entry.generate(0, "dna") }
+ test "#generate with length < 1 raises" do
+ assert_raise(SeqError) { @entry.generate(-10, :dna) }
+ assert_raise(SeqError) { @entry.generate(0, :dna) }
end
- def test_Seq_generate_with_bad_type_raises
+ test "#generate with bad type raises" do
assert_raise(SeqError) { @entry.generate(10, "foo") }
end
- def test_Seq_generate_with_ok_type_dont_raise
- %w[dna DNA rna RNA protein Protein].each do |type|
- assert_nothing_raised { @entry.generate(10, type) }
+ test "#generate with ok type dont raise" do
+ %w[dna rna protein].each do |type|
+ assert_nothing_raised { @entry.generate(10, type.to_sym) }
end
end
- def test_Seq_subseq_with_start_lt_0_raises
- @entry.seq = "ATCG"
- assert_raise(SeqError) { @entry.subseq(-1, 1) }
+ test "#shuffle returns correctly" do
+ orig = "actgactgactgatcgatcgatcgatcgtactg"
+ @entry.seq = "actgactgactgatcgatcgatcgatcgtactg"
+ entry_shuf = @entry.shuffle
+ assert_equal(orig, @entry.seq)
+ assert_not_equal(@entry.seq, entry_shuf.seq)
+ end
+
+ test "#shuffle! returns correctly" do
+ @entry.seq = "actgactgactgatcgatcgatcgatcgtactg"
+ assert_not_equal(@entry.seq, @entry.shuffle!.seq)
+ end
+
+ test "#<< with different types raises" do
+ @entry.seq = "atcg"
+ assert_raise(SeqError) { @entry << Seq.new("test", "atcg", :dna) }
+ end
+
+ test "#<< with missing qual in one entry raises" do
+ @entry.seq = "atcg"
+ @entry.type = :dna
+ assert_raise(SeqError) { @entry << Seq.new("test", "atcg", :dna, "IIII") }
+ @entry.qual = "IIII"
+ assert_raise(SeqError) { @entry << Seq.new("test", "atcg", :dna) }
+ end
+
+ test "#<< with nil qual in both entries dont raise" do
+ @entry.seq = "atcg"
+ assert_nothing_raised { @entry << Seq.new("test", "atcg") }
end
- def test_Seq_subseq_with_length_lt_1_raises
+ test "#<< with qual in both entries dont raise" do
+ @entry.seq = "atcg"
+ @entry.type = :dna
+ @entry.qual = "IIII"
+ assert_nothing_raised { @entry << Seq.new("test", "atcg", :dna, "IIII") }
+ end
+
+ test "#<< without qual returns correctly" do
+ @entry.seq = "atcg"
+ @entry << Seq.new("test", "ATCG")
+ assert_equal("atcgATCG", @entry.seq)
+ end
+
+ test "#<< with qual returns correctly" do
+ @entry.seq = "atcg"
+ @entry.type = :dna
+ @entry.qual = "HHHH"
+ @entry << Seq.new("test", "ATCG", :dna, "IIII")
+ assert_equal("atcgATCG", @entry.seq)
+ assert_equal("HHHHIIII", @entry.qual)
+ end
+
+ test "#[] with qual returns correctly" do
+ entry = Seq.new("test", "atcg", :dna, "FGHI")
+
+ e = entry[2]
+
+ assert_equal("test", e.seq_name)
+ assert_equal("c", e.seq)
+ assert_equal(:dna, e.type)
+ assert_equal("H", e.qual)
+ assert_equal("atcg", entry.seq)
+ assert_equal("FGHI", entry.qual)
+ end
+
+ test "#[] without qual returns correctly" do
+ entry = Seq.new("test", "atcg")
+
+ e = entry[2]
+
+ assert_equal("test", e.seq_name)
+ assert_equal("c", e.seq)
+ assert_nil(e.qual)
+ assert_equal("atcg", entry.seq)
+ end
+
+ test "[]= with qual returns correctly" do
+ entry = Seq.new("test", "atcg", :dna, "FGHI")
+
+ entry[0] = Seq.new("foo", "T", :dna, "I")
+
+ assert_equal("test", entry.seq_name)
+ assert_equal("Ttcg", entry.seq)
+ assert_equal(:dna, entry.type)
+ assert_equal("IGHI", entry.qual)
+ end
+
+ test "[]= without qual returns correctly" do
+ entry = Seq.new("test", "atcg")
+
+ entry[0] = Seq.new("foo", "T")
+
+ assert_equal("test", entry.seq_name)
+ assert_equal("Ttcg", entry.seq)
+ end
+
+ test "#subseq with start < 0 raises" do
@entry.seq = "ATCG"
- assert_raise(SeqError) { @entry.subseq(0, 0) }
+ assert_raise(SeqError) { @entry.subseq(-1, 1) }
end
- def test_Seq_subseq_with_start_plus_length_gt_seq_raises
+ test "#subseq with start plus length gt seq raises" do
@entry.seq = "ATCG"
assert_raise(SeqError) { @entry.subseq(0, 5) }
end
- def test_Seq_subseq_returns_correct_sequence
+ test "#subseq returns correct sequence" do
@entry.seq = "ATCG"
assert_equal("AT", @entry.subseq(0, 2).seq)
assert_equal("CG", @entry.subseq(2, 2).seq)
end
- def test_Seq_subseq_without_len_returns_correct_sequence
+ test "#subseq without length returns correct sequence" do
@entry.seq = "ATCG"
assert_equal("ATCG", @entry.subseq(0).seq)
assert_equal("CG", @entry.subseq(2).seq)
end
- def test_Seq_subseq_returns_correct_qual
+ test "#subseq returns correct qual" do
@entry.seq = "ATCG"
@entry.qual = "abcd"
assert_equal("ab", @entry.subseq(0, 2).qual)
assert_equal("cd", @entry.subseq(2, 2).qual)
end
- def test_Seq_subseq_without_len_returns_correct_qual
+ test "#subseq without length returns correct qual" do
@entry.seq = "ATCG"
@entry.qual = "abcd"
assert_equal("abcd", @entry.subseq(0).qual)
assert_equal("cd", @entry.subseq(2).qual)
end
- def test_Seq_subseq_bang_with_start_lt_0_raises
+ test "#subseq! with start < 0 raises" do
@entry.seq = "ATCG"
assert_raise(SeqError) { @entry.subseq!(-1, 1) }
end
- def test_Seq_subseq_bang_with_length_lt_1_raises
- @entry.seq = "ATCG"
- assert_raise(SeqError) { @entry.subseq!(0, 0) }
- end
-
- def test_Seq_subseq_bang_with_start_plus_length_gt_seq_raises
+ test "#subseq! with start plus length > seq.length raises" do
@entry.seq = "ATCG"
assert_raise(SeqError) { @entry.subseq!(0, 5) }
end
- def test_Seq_subseq_bang_returns_correct_sequence
+ test "#subseq! returns correct sequence" do
@entry.seq = "ATCG"
@entry.subseq!(0, 2)
assert_equal("AT", @entry.seq)
assert_equal("CG", @entry.seq)
end
- def test_Seq_subseq_bang_without_len_returns_correct_sequence
+ test "#subseq! without length returns correct sequence" do
@entry.seq = "ATCG"
@entry.subseq!(0)
assert_equal("ATCG", @entry.seq)
assert_equal("CG", @entry.seq)
end
- def test_Seq_subseq_bang_with_pos_and_len_returns_correct_qual
+ test "#subseq! with pos and length returns correct qual" do
@entry.seq = "ATCG"
@entry.qual = "abcd"
@entry.subseq!(0, 2)
assert_equal("cd", @entry.qual)
end
- def test_Seq_subseq_bang_with_pos_returns_correct_qual
+ test "#subseq! with pos returns correct qual" do
@entry.seq = "ATCG"
@entry.qual = "abcd"
@entry.subseq!(0)
assert_equal("cd", @entry.qual)
end
- def test_Seq_subseq_rand_returns_correct_sequence
+ test "#subseq_rand returns correct sequence" do
@entry.seq = "ATCG"
assert_equal("ATCG", @entry.subseq_rand(4).seq)
end
- def test_Seq_quality_trim_right_with_missing_seq_raises
- @entry.qual = "hhhh"
- assert_raise(SeqError) { @entry.quality_trim_right(20) }
+ test "#indels_remove without qual returns correctly" do
+ @entry.seq = "A-T.CG~CG"
+ @entry.qual = nil
+ assert_equal("ATCGCG", @entry.indels_remove.seq)
end
- def test_Seq_quality_trim_right_with_missing_qual_raises
- @entry.seq = "ATCG"
- assert_raise(SeqError) { @entry.quality_trim_right(20) }
+ test "#indels_remove with qual returns correctly" do
+ @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_quality_trim_right_with_bad_min_raises
- @entry.seq = "ATCG"
- @entry.qual = "hhhh"
+ test "#composition returns correctly" do
+ @entry.seq = "AAAATTTCCG"
+ assert_equal(4, @entry.composition["A"])
+ assert_equal(3, @entry.composition["T"])
+ assert_equal(2, @entry.composition["C"])
+ assert_equal(1, @entry.composition["G"])
+ assert_equal(0, @entry.composition["X"])
+ end
- [-1, 41].each do |min|
- assert_raise(SeqError) { @entry.quality_trim_right(min) }
- end
+ test "#homopol_max returns 0 with empty sequence" do
+ @entry.seq = ""
+ assert_equal(0, @entry.homopol_max)
end
- def test_Seq_quality_trim_right_with_ok_min_dont_raise
- @entry.seq = "ATCG"
- @entry.qual = "hhhh"
+ test "#homopol_max returns 0 with nil sequence" do
+ @entry.seq = nil
+ assert_equal(0, @entry.homopol_max)
+ end
- [0, 40].each do |min|
- assert_nothing_raised { @entry.quality_trim_right(min) }
- end
+ test "#homopol_max returns 0 when not found" do
+ @entry.seq = "AtTcCcGggGnnNnn"
+ assert_equal(0, @entry.homopol_max(6))
end
- def test_Seq_quality_trim_right_returns_correctly
- @entry.seq = "AAAAATCG"
- @entry.qual = "hhhhhgfe"
- @entry.quality_trim_right(38)
- assert_equal("AAAAAT", @entry.seq)
- assert_equal("hhhhhg", @entry.qual)
+ test "#homopol_max returns correctly" do
+ @entry.seq = "AtTcCcGggGnnNnn"
+ assert_equal(5, @entry.homopol_max(3))
end
- def test_Seq_quality_trim_left_with_missing_seq_raises
- @entry.qual = "hhhh"
- assert_raise(SeqError) { @entry.quality_trim_left(20) }
+ test "#hard_mask returns correctly" do
+ @entry.seq = "--AAAANn"
+ assert_equal(33.33, @entry.hard_mask)
end
- def test_Seq_quality_trim_left_with_missing_qual_raises
- @entry.seq = "ATCG"
- assert_raise(SeqError) { @entry.quality_trim_left(20) }
+ test "#soft_mask returns correctly" do
+ @entry.seq = "--AAAa"
+ assert_equal(25.00, @entry.soft_mask)
end
- def test_Seq_quality_trim_left_with_bad_min_raises
- @entry.seq = "ATCG"
- @entry.qual = "hhhh"
+ test "#mask_seq_hard! with nil seq raises" do
+ @entry.seq = nil
+ @entry.qual = ""
- [-1, 41].each do |min|
- assert_raise(SeqError) { @entry.quality_trim_left(min) }
- end
+ assert_raise(SeqError) { @entry.mask_seq_hard!(20) }
end
- def test_Seq_quality_trim_left_with_ok_min_dont_raise
+ test "#mask_seq_hard! with nil qual raises" do
+ @entry.seq = ""
+ @entry.qual = nil
+
+ assert_raise(SeqError) { @entry.mask_seq_hard!(20) }
+ end
+
+ test "#mask_seq_hard! with bad cutoff raises" do
+ assert_raise(SeqError) { @entry.mask_seq_hard!(-1) }
+ assert_raise(SeqError) { @entry.mask_seq_hard!(41) }
+ end
+
+ test "#mask_seq_hard! with OK cutoff dont raise" do
@entry.seq = "ATCG"
- @entry.qual = "hhhh"
+ @entry.qual = "RSTU"
- [0, 40].each do |min|
- assert_nothing_raised { @entry.quality_trim_left(min) }
- end
+ assert_nothing_raised { @entry.mask_seq_hard!(0) }
+ assert_nothing_raised { @entry.mask_seq_hard!(40) }
end
- def test_Seq_quality_trim_left_returns_correctly
- @entry.seq = "GCTAAAAA"
- @entry.qual = "efghhhhh"
- @entry.quality_trim_left(38)
- assert_equal("TAAAAA", @entry.seq)
- assert_equal("ghhhhh", @entry.qual)
+ test "#mask_seq_hard! returns correctly" do
+ @entry.seq = "-ATCG"
+ @entry.qual = "33456"
+
+ assert_equal("-NNCG", @entry.mask_seq_hard!(20).seq)
end
- def test_Seq_quality_trim_returns_correctly
- @entry.seq = "GCTAAAAAGTG"
- @entry.qual = "efghhhhhgfe"
- @entry.quality_trim(38)
- assert_equal("TAAAAAG", @entry.seq)
- assert_equal("ghhhhhg", @entry.qual)
+ test "#mask_seq_soft! with nil seq raises" do
+ @entry.seq = nil
+ @entry.qual = ""
+
+ assert_raise(SeqError) { @entry.mask_seq_soft!(20) }
end
- def test_Seq_indels_remove_without_qual_returns_correctly
- @entry.seq = "A-T.CG~CG"
+ test "#mask_seq_soft! with nil qual raises" do
+ @entry.seq = ""
@entry.qual = nil
- assert_equal("ATCGCG", @entry.indels_remove.seq)
+
+ assert_raise(SeqError) { @entry.mask_seq_soft!(20) }
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)
+ test "#mask_seq_soft! with bad cutoff raises" do
+ assert_raise(SeqError) { @entry.mask_seq_soft!(-1) }
+ assert_raise(SeqError) { @entry.mask_seq_soft!(41) }
end
- def test_Seq_composition_returns_correctly
- @entry.seq = "AAAATTTCCG"
- assert_equal(4, @entry.composition["A"])
- assert_equal(3, @entry.composition["T"])
- assert_equal(2, @entry.composition["C"])
- assert_equal(1, @entry.composition["G"])
- assert_equal(0, @entry.composition["X"])
+ test "#mask_seq_soft! with OK cutoff dont raise" do
+ @entry.seq = "ATCG"
+ @entry.qual = "RSTU"
+
+ assert_nothing_raised { @entry.mask_seq_soft!(0) }
+ assert_nothing_raised { @entry.mask_seq_soft!(40) }
end
- def test_Seq_homopol_max_returns_0_with_empty_sequence
- @entry.seq = ""
- assert_equal(0, @entry.homopol_max)
+ test "#mask_seq_soft! returns correctly" do
+ @entry.seq = "-ATCG"
+ @entry.qual = "33456"
+
+ assert_equal("-atCG", @entry.mask_seq_soft!(20).seq)
end
- def test_Seq_homopol_max_returns_0_with_nil_sequence
- @entry.seq = nil
- assert_equal(0, @entry.homopol_max)
+ # qual score detection
+
+ test "#qual_base33? returns correctly" do
+ # self.qual.match(/[!-:]/)
+ @entry.qual = '!"#$%&\'()*+,-./0123456789:'
+ assert_equal(true, @entry.qual_base33? )
+ @entry.qual = 32.chr
+ assert_equal(false, @entry.qual_base33? )
+ @entry.qual = 59.chr
+ assert_equal(false, @entry.qual_base33? )
end
- def test_Seq_homopol_max_returns_0_when_not_found
- @entry.seq = "AtTcCcGggGnnNnn"
- assert_equal(0, @entry.homopol_max(6))
+ test "#qual_base64? returns correctly" do
+ # self.qual.match(/[K-h]/)
+ @entry.qual = 'KLMNOPQRSTUVWXYZ[\]^_`abcdefgh'
+ assert_equal(true, @entry.qual_base64? )
+ @entry.qual = 74.chr
+ assert_equal(false, @entry.qual_base64? )
+ @entry.qual = 105.chr
+ assert_equal(false, @entry.qual_base64? )
end
- def test_Seq_homopol_max_returns_correctly
- @entry.seq = "AtTcCcGggGnnNnn"
- assert_equal(5, @entry.homopol_max(3))
+ test "#qual_valid? with nil qual raises" do
+ assert_raise(SeqError) { @entry.qual_valid?(:base_33) }
+ assert_raise(SeqError) { @entry.qual_valid?(:base_64) }
end
- def test_Seq_hard_mask_returns_correctly
- @entry.seq = "--AAAANn"
- assert_equal(33.33, @entry.hard_mask)
+ test "#qual_valid? with bad encoding raises" do
+ @entry.qual = "abc"
+ assert_raise(SeqError) { @entry.qual_valid?("foobar") }
end
- def test_Seq_soft_mask_returns_correctly
- @entry.seq = "--AAAa"
- assert_equal(25.00, @entry.soft_mask)
+ test "#qual_valid? with OK range returns correctly" do
+ @entry.qual = ((Seq::SCORE_MIN + 33).chr .. (Seq::SCORE_MAX + 33).chr).to_a.join
+ assert_equal(true, @entry.qual_valid?(:base_33))
+ @entry.qual = ((Seq::SCORE_MIN + 64).chr .. (Seq::SCORE_MAX + 64).chr).to_a.join
+ assert_equal(true, @entry.qual_valid?(:base_64))
end
-end
+ test "#qual_valid? with bad range returns correctly" do
+ @entry.qual = ((Seq::SCORE_MIN + 33 - 1).chr .. (Seq::SCORE_MAX + 33).chr).to_a.join
+ assert_equal(false, @entry.qual_valid?(:base_33))
+ @entry.qual = ((Seq::SCORE_MIN + 33).chr .. (Seq::SCORE_MAX + 33 + 1).chr).to_a.join
+ assert_equal(false, @entry.qual_valid?(:base_33))
-__END__
+ @entry.qual = ((Seq::SCORE_MIN + 64 - 1).chr .. (Seq::SCORE_MAX + 64).chr).to_a.join
+ assert_equal(false, @entry.qual_valid?(:base_64))
+ @entry.qual = ((Seq::SCORE_MIN + 64).chr .. (Seq::SCORE_MAX + 64 + 1).chr).to_a.join
+ assert_equal(false, @entry.qual_valid?(:base_64))
+ end
+
+ # convert sanger to ...
+
+ test "#qual_convert! from base33 to base33 returns OK" do
+ @entry.qual = 'BCDEFGHI'
+ assert_equal('BCDEFGHI', @entry.qual_convert!(:base_33, :base_33).qual)
+ end
+
+ test "#qual_convert! from base33 to base64 returns OK" do
+ @entry.qual = 'BCDEFGHI'
+ assert_equal('abcdefgh', @entry.qual_convert!(:base_33, :base_64).qual)
+ end
+
+ test "#qual_convert! from base64 to base64 returns OK" do
+ @entry.qual = 'BCDEFGHI'
+ assert_equal('BCDEFGHI', @entry.qual_convert!(:base_64, :base_64).qual)
+ end
+
+ test "#qual_convert! from base64 to base33 returns OK" do
+ @entry.qual = 'abcdefgh'
+ assert_equal('BCDEFGHI', @entry.qual_convert!(:base_64, :base_33).qual)
+ end
+
+ test "#qual_coerce! returns correctly" do
+ @entry.qual = ('!' .. '~').to_a.join
+ assert_equal("!\"\#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII", @entry.qual_coerce!(:base_33).qual)
+ @entry.qual = ('!' .. '~').to_a.join
+ assert_equal("!\"\#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZh\\h^_`abcdefghhhhhhhhhhhhhhhhhhhhhhh", @entry.qual_coerce!(:base_64).qual)
+ end
+
+ test "#scores_mean without qual raises" do
+ @entry.qual = nil
+ assert_raise(SeqError) { @entry.scores_mean }
+ end
+
+ test "#scores_mean returns correctly" do
+ @entry.qual = '!!II'
+ assert_equal(20.0, @entry.scores_mean)
+ end
+end