/
bio-alignment_spec.rb
95 lines (85 loc) · 3.26 KB
/
bio-alignment_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
require 'bio-alignment'
require 'bigbio' # for the FastaReader
include Bio::BioAlignment # Namespace
describe "BioAlignment::CodonSequence" do
it "should support different codon tables" do
seq = CodonSequence.new("test", "atgcccagacgattgg")
seq[0].to_aa.should == "M"
seq[2].to_s.should == "aga"
seq[2].to_aa.should == "R"
seq5 = CodonSequence.new("test", "atgcccagacgattgg", :codon_table => 5)
seq5[2].codon_table.should == 5
seq5[0].to_aa.should == "M"
seq5[2].to_s.should == "aga"
seq5[2].to_aa.should == "S"
seq2 = CodonSequence.new("test", "atgcccagacgattgg", :codon_table => 2)
seq2[2].codon_table.should == 2
seq2[0].to_aa.should == "M"
seq2[2].to_aa.should == "*"
end
end
describe "BioAlignment::Alignment" do
it "should allow for adding FastaRecords that contain and id and seq" do
aln = Alignment.new
fasta = FastaReader.new('test/data/fasta/codon/codon-alignment.fa')
fasta.each do | rec |
aln.sequences << rec
end
aln.sequences.first.id.should == "ZK909.2e"
aln.sequences.first.seq[0..15].should == "atgcccactcgattgg"
end
it "should allow CodonSequence as an input" do
aln = Alignment.new
fasta = FastaReader.new('test/data/fasta/codon/codon-alignment.fa')
fasta.each do | rec |
aln.sequences << CodonSequence.new(rec.id, rec.seq)
end
aln.sequences.first.id.should == "ZK909.2e"
aln.sequences.first.to_s[0..46].should == "atg ccc act cga ttg gat att gtt gga aac ctt cag"
# sequence, however, is no String!
aln.sequences.first.seq[2] == Codon.new('act')
# and elements may carry a pay load, here an amino acid value
aln.sequences.first.seq[0].to_aa.should == "M"
aln.sequences.first.seq[2].to_aa.should == "T"
end
end
describe "BioAlignment::DelBridges" do
require 'bio-alignment/edit/del_bridges'
string =
"""
----SNSFSRPTIIFSGCSTACSGK--SELVCGFRSFMLSDV
SSIISNSFSRPTIIFSGCSTACSGK--SEQVCGFR---LSDV
SSIISNSFSRPTIIFSGCSTACSGKLTSEQVCGFR---LSDV
----PKLFSRPTIIFSGCSTACSGK--SEPVCGFRSFMLSDV
----------PTIIFSGCSKACSGKGLSELVCGFRSFMLSDV
----------PTIIFSGCSKACSGK-----FRSFRSFMLSAV
----------PTIIFSGCSKACSGK-----VCGIFHAVRSFM
----------PTIIFSGCSKACSGK--SELVCGFRSFMLSAV
-------------IFHAVR-TC-HP-----------------
"""
aln = Alignment.new(string.split(/\n/))
print aln.to_s,"\n"
columns = aln.columns
columns.should_not == nil
columns.should_not == []
columns.size.should == 42
# make sure we are using the same columns
aln.columns.should == columns
aln.extend DelBridges
aln2 = aln.mark_bridges
print aln2.to_s,"\n"
columns2 = aln2.columns
columns2.should_not == nil
columns2.should_not == []
columns2.count { |col| col.state.deleted? }.should == 6
aln2.columns[0].state.should == columns2[0].state
aln2.columns[0].state.should_not == columns[0].state
aln2.rows.first.to_s.should == "----SNSFSRPTIIFSGCSTACSGK--SELVCGFRSFMLSDV"
# now write out the alignment with deleted columns removed
aln3 = aln2.columns_where { |col| !col.state.deleted? }
print aln3.to_s,"\n"
aln3.rows.first.to_s.should == "SNSFSRPTIIFSGCSTACSGKSELVCGFRSFMLSDV"
# We are going to do the same for a codon alignment
test == false
end