@entry = Seq.new
end
+ test "Seq.new with differnet length SEQ and SCORES raises" do
+ assert_raise(SeqError) { Seq.new(seq_name: "test", seq: "ATCG", type: :dna, qual: "hhh") }
+ end
+
test "Seq.new_bp returns correctly" do
- record = {:SEQ_NAME => "test", :SEQ => "ATCG", :SEQ_TYPE => "dna", :SCORES => "hhhh"}
+ 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
end
test "#is_dna? with dna sequence type returns true" do
- @entry.type = 'dna'
+ @entry.type = :dna
assert(@entry.is_dna? == true)
end
end
test "#is_rna? with rna sequence type returns true" do
- @entry.type = 'rna'
+ @entry.type = :rna
assert(@entry.is_rna? == true)
end
end
test "#is_protein? with protein sequence type returns true" do
- @entry.type = 'protein'
+ @entry.type = :protein
assert_equal(true, @entry.is_protein?)
end
test "#type_guess with protein returns protein" do
@entry.seq = 'atcatcrFgatcg'
- assert_equal('protein', @entry.type_guess)
+ assert_equal(:protein, @entry.type_guess)
end
test "#type_guess with rna returns rna" do
@entry.seq = 'atcatcrUgatcg'
- assert_equal('rna', @entry.type_guess)
+ assert_equal(:rna, @entry.type_guess)
end
test "#type_guess with dna returns dna" do
@entry.seq = 'atcatcgatcg'
- assert_equal('dna', @entry.type_guess)
+ assert_equal(:dna, @entry.type_guess)
end
test "#type_guess! without sequence raises" do
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
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
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
test "#length returns corretly" do
end
test "#to_rna with no sequence raises" do
- @entry.type = 'dna'
+ @entry.type = :dna
assert_raise(SeqError) { @entry.to_rna }
end
test "#to_rna with bad type raises" do
@entry.seq = 'ATCG'
- @entry.type = 'rna'
+ @entry.type = :rna
assert_raise(SeqError) { @entry.to_rna }
end
test "#to_rna transcribes correctly" do
@entry.seq = 'ATCGatcg'
- @entry.type = 'dna'
+ @entry.type = :dna
assert_equal("AUCGaucg", @entry.to_rna)
end
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
test "#to_dna with no sequence raises" do
- @entry.type = 'rna'
+ @entry.type = :rna
assert_raise(SeqError) { @entry.to_dna }
end
test "#to_dna with bad type raises" do
@entry.seq = 'AUCG'
- @entry.type = 'dna'
+ @entry.type = :dna
assert_raise(SeqError) { @entry.to_dna }
end
test "#to_dna transcribes correctly" do
@entry.seq = 'AUCGaucg'
- @entry.type = 'rna'
+ @entry.type = :rna
assert_equal("ATCGatcg", @entry.to_dna)
end
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
test "#to_bp returns correct record" do
end
test "#to_fasta wraps correctly" do
- entry = Seq.new("test", "ATCG")
+ entry = Seq.new(seq_name: "test", seq: "ATCG")
assert_equal(">test\nAT\nCG\n", entry.to_fasta(2))
end
end
test "#to_key with bad residue raises" do
- entry = Seq.new("test", "AUCG")
+ entry = Seq.new(seq_name: "test", seq: "AUCG")
assert_raise(SeqError) { entry.to_key }
end
test "#to_key returns correctly" do
- entry = Seq.new("test", "ATCG")
+ entry = Seq.new(seq_name: "test", seq: "ATCG")
assert_equal(54, entry.to_key)
end
end
test "#complement with no sequence raises" do
- @entry.type = 'dna'
+ @entry.type = :dna
assert_raise(SeqError) { @entry.complement }
end
test "#complement with bad type raises" do
@entry.seq = 'ATCG'
- @entry.type = 'protein'
+ @entry.type = :protein
assert_raise(SeqError) { @entry.complement }
end
test "#complement for DNA is correct" do
@entry.seq = 'ATCGatcg'
- @entry.type = 'dna'
+ @entry.type = :dna
comp = @entry.complement
assert_equal("TAGCtagc", comp.seq)
assert_equal("ATCGatcg", @entry.seq)
test "#complement for RNA is correct" do
@entry.seq = 'AUCGaucg'
- @entry.type = 'rna'
+ @entry.type = :rna
comp = @entry.complement
assert_equal("UAGCuagc", comp.seq)
assert_equal("AUCGaucg", @entry.seq)
end
test "#complement! with no sequence raises" do
- @entry.type = 'dna'
+ @entry.type = :dna
assert_raise(SeqError) { @entry.complement! }
end
test "#complement! with bad type raises" do
@entry.seq = 'ATCG'
- @entry.type = 'protein'
+ @entry.type = :protein
assert_raise(SeqError) { @entry.complement! }
end
test "#complement! for DNA is correct" do
@entry.seq = 'ATCGatcg'
- @entry.type = 'dna'
+ @entry.type = :dna
assert_equal("TAGCtagc", @entry.complement!.seq)
end
test "#complement! for RNA is correct" do
@entry.seq = 'AUCGaucg'
- @entry.type = 'rna'
+ @entry.type = :rna
assert_equal("UAGCuagc", @entry.complement!.seq)
end
+ test "#hamming_distance returns correctly" do
+ seq1 = Seq.new(seq: "ATCG")
+ seq2 = Seq.new(seq: "atgg")
+ assert_equal(1, seq1.hamming_distance(seq2))
+ end
+
+ test "#hamming_distance with ambiguity codes return correctly" do
+ seq1 = Seq.new(seq: "ATCG")
+ seq2 = Seq.new(seq: "atng")
- test "#hamming distance returns correctly" do
- seq1 = Seq.new("test1", "ATCG")
- seq2 = Seq.new("test2", "atgg")
assert_equal(1, seq1.hamming_distance(seq2))
+ assert_equal(0, seq1.hamming_distance(seq2, ambiguity: true))
+ end
+
+ test "#edit_distance returns correctly" do
+ seq1 = Seq.new(seq: "ATCG")
+ seq2 = Seq.new(seq: "tgncg")
+ assert_equal(2, seq1.edit_distance(seq2))
end
test "#generate with length < 1 raises" do
- assert_raise(SeqError) { @entry.generate(-10, "dna") }
- assert_raise(SeqError) { @entry.generate(0, "dna") }
+ assert_raise(SeqError) { @entry.generate(-10, :dna) }
+ assert_raise(SeqError) { @entry.generate(0, :dna) }
end
test "#generate with bad type raises" do
end
test "#generate with ok type dont raise" do
- %w[dna DNA rna RNA protein Protein].each do |type|
- assert_nothing_raised { @entry.generate(10, type) }
+ %w[dna rna protein].each do |type|
+ assert_nothing_raised { @entry.generate(10, type.to_sym) }
end
end
assert_not_equal(@entry.seq, @entry.shuffle!.seq)
end
+ test "#+ without qual returns correctly" do
+ entry = Seq.new(seq_name: "test1", seq: "at") + Seq.new(seq_name: "test2", seq: "cg")
+ assert_nil(entry.seq_name)
+ assert_equal("atcg", entry.seq)
+ assert_nil(entry.type)
+ assert_nil(entry.qual)
+ end
+
+ test "#+ with qual returns correctly" do
+ entry = Seq.new(seq_name: "test1", seq: "at", type: :dna, qual: "II") + Seq.new(seq_name: "test2", seq: "cg", type: :dna, qual: "JJ")
+ assert_nil(entry.seq_name)
+ assert_equal("atcg", entry.seq)
+ assert_equal(:dna, entry.type)
+ assert_equal("IIJJ", entry.qual)
+ end
+
+ test "#<< with different types raises" do
+ @entry.seq = "atcg"
+ assert_raise(SeqError) { @entry << Seq.new(seq_name: "test", seq: "atcg", type: :dna) }
+ end
+
+ test "#<< with missing qual in one entry raises" do
+ @entry.seq = "atcg"
+ @entry.type = :dna
+ assert_raise(SeqError) { @entry << Seq.new(seq_name: "test", seq: "atcg", type: :dna, qual: "IIII") }
+ @entry.qual = "IIII"
+ assert_raise(SeqError) { @entry << Seq.new(seq_name: "test", seq: "atcg", type: :dna) }
+ end
+
+ test "#<< with nil qual in both entries dont raise" do
+ @entry.seq = "atcg"
+ assert_nothing_raised { @entry << Seq.new(seq_name: "test", seq: "atcg") }
+ end
+
+ test "#<< with qual in both entries dont raise" do
+ @entry.seq = "atcg"
+ @entry.type = :dna
+ @entry.qual = "IIII"
+ assert_nothing_raised { @entry << Seq.new(seq_name: "test", seq: "atcg", type: :dna, qual: "IIII") }
+ end
+
+ test "#<< without qual returns correctly" do
+ @entry.seq = "atcg"
+ @entry << Seq.new(seq_name: "test", seq: "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(seq_name: "test", seq: "ATCG", type: :dna, qual: "IIII")
+ assert_equal("atcgATCG", @entry.seq)
+ assert_equal("HHHHIIII", @entry.qual)
+ end
+
+ test "#[] with qual returns correctly" do
+ entry = Seq.new(seq_name: "test", seq: "atcg", type: :dna, qual: "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(seq_name: "test", seq: "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(seq_name: "test", seq: "atcg", type: :dna, qual: "FGHI")
+
+ entry[0] = Seq.new(seq_name: "foo", seq: "T", type: :dna, qual: "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(seq_name: "test", seq: "atcg")
+
+ entry[0] = Seq.new(seq_name: "foo", seq: "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(-1, 1) }
assert_equal(0, @entry.composition["X"])
end
- test "#homopol_max returns 0 with empty sequence" do
- @entry.seq = ""
- assert_equal(0, @entry.homopol_max)
- end
-
- test "#homopol_max returns 0 with nil sequence" do
- @entry.seq = nil
- assert_equal(0, @entry.homopol_max)
- end
-
- test "#homopol_max returns 0 when not found" do
- @entry.seq = "AtTcCcGggGnnNnn"
- assert_equal(0, @entry.homopol_max(6))
- end
-
- test "#homopol_max returns correctly" do
- @entry.seq = "AtTcCcGggGnnNnn"
- assert_equal(5, @entry.homopol_max(3))
- end
-
test "#hard_mask returns correctly" do
@entry.seq = "--AAAANn"
assert_equal(33.33, @entry.hard_mask)