\section{Testing}
Our testing program has hooks for imports and the testing logic.
package pal
import (
"testing"
//<<Testing imports>>
)
//<<Testing>>
Testing is divided in two parts, first we test the \ty{ScoreMatrix},
then the various types of alignment.
func TestScoreMatrix(t *testing.T) {
//<<Test \ty{ScoreMatrix}>>
}
func TestAlignment(t *testing.T) {
//<<Test alignment>>
}
\subsection{\ty{ScoreMatrix}}
We run the tests for \ty{ScoreMatrix} and store the results we
get. Then we store the results we want and compare the two.
get := make([]string, 0)
want := make([]string, 0)
//<<Store what we get for \ty{ScoreMatrix}>>
//<<Store what we want for \ty{ScoreMatrix}>>
for i, g := range get {
w := want[i]
//<<Compare \ty{ScoreMatrix} results>>
}
We construct a new \ty{ScoreMatrix} and read the BLOSUM matrix.
sm := NewScoreMatrix(1, -3)
get = append(get, sm.String())
bf := "./doc/blosum62.txt"
f, err := os.Open(bf)
if err != nil {
t.Errorf("can't open %q", bf)
}
defer f.Close()
sm = ReadScoreMatrix(f)
get = append(get, sm.String())
We also test scoring a pair of matched bytes and a pair of mismatched
bytes.
sm = NewByteScoreMatrix(1, -3)
s1 := int(sm.Score(byte('_'), byte('_')))
s2 := int(sm.Score(byte('_'), byte('%')))
get = append(get, strconv.Itoa(s1))
get = append(get, strconv.Itoa(s2))
For each of the four results we get, we read the result we want from
files \ty{sm1.txt}, \ty{sm2.txt}, and so on.
for i, _ := range get {
f := "data/sm" + strconv.Itoa(i+1) + ".txt"
b, err := ioutil.ReadFile(f)
if err != nil {
t.Errorf("can't open %q", f)
}
want = append(want, string(b))
}
We import \ty{strconv} and \ty{ioutil}.
We compare what we get with what we want.
if g != w {
t.Errorf("get:\n%s\nwant:\n%s", g, w)
}
\subsection{\ty{Alignment}}
We store the results we get when testing alignment.
get := make([]string, 0)
want := make([]string, 0)
//<<Store what we get for alignment>>
//<<Store what we want for alignment>>
for i, g := range get {
w := want[i]
//<<Compare alignment results>>
}
The first test is the global alignment of two short peptides shown in
Figure~\ref{fig:al}.
bf := "./doc/blosum62.txt"
f, err := os.Open(bf)
if err != nil {
t.Errorf("can't open %q", bf)
}
defer f.Close()
sm := ReadScoreMatrix(f)
q := fasta.NewSequence("Q", []byte("MKFLALF"))
s := fasta.NewSequence("S", []byte("MKYLILLF"))
a := NewGlobalAlignment(q, s, sm, -5, -2)
a.Align()
get = append(get, a.String() + "\n")
"github.com/evolbioinf/fasta"
The second test is the overlap alignment of two DNA sequences.
s1 := "CATTGGGATGATGCACCTATATTGTGAGGTCTGTTACACTG" +
"TCGTTCCGCAGATCGAGCAATCCCGTATCCTTTACATAT" +
"TGCCGTGTGGGGTAAGGTGC"
s2 := "TTGTGAGGTCTGTTACACTGTCCGCAGATCGAGCAATCC" +
"CGTATCCTTTACATATTGCCGTGTGGGGTAAGGTGCC" +
"ATTGGGATGATGCACCTATA"
q = fasta.NewSequence("Q", []byte(s1))
s = fasta.NewSequence("S", []byte(s2))
sm = NewScoreMatrix(1, -3)
o := NewOverlapAlignment(q, s, sm, -5, -2)
o.Align()
get = append(get, o.String() + "\n")
In the third test we compute the first two local alignments
of two \emph{Adh} sequences from \emph{Drosophila}.
//<<Read query \emph{Adh} sequence>>
//<<Read subject \emph{Adh} sequence>>
//<<Calculate two local alignments>>
The query \emph{Adh} sequence is contained in \ty{dmAdhAdhdup.fasta}.
fn := "data/dmAdhAdhdup.fasta"
f, err = os.Open(fn)
if err != nil {
t.Errorf("can't open %q", fn)
}
defer f.Close()
sc := fasta.NewScanner(f)
sc.ScanSequence()
q = sc.Sequence()
The subject \emph{Adh} sequence is contained in \ty{dgAdhAdhdup.fasta}.
fn = "data/dgAdhAdhdup.fasta"
f, err = os.Open(fn)
if err != nil {
t.Errorf("can't open %q", fn)
}
defer f.Close()
sc = fasta.NewScanner(f)
sc.ScanSequence()
s = sc.Sequence()
We concatenate the first two alignments of the two \emph{Adh}
sequences.
l := NewLocalAlignment(q, s, sm, -5, -2)
l.Align()
str := l.String()
l.Align()
str += "\n" + l.String() + "\n"
get = append(get, str)
In the fourth test we test printing of the programming matrix.
str = a.PrintMatrix('v')
get = append(get, str)
In the fifth and final test we print the trace back of the programming
matrix.
str = a.PrintMatrix('t')
get = append(get, str)
The results we want are contained in files \ty{a1.txt}, \ty{a2.txt},...,
\ty{a5.txt}.
for i, _ := range get {
f := "data/a" + strconv.Itoa(i+1) + ".txt"
b, err := ioutil.ReadFile(f)
if err != nil {
t.Errorf("can't open %q", f)
}
want = append(want, string(b))
}
We compare what we get with what we want.
if g != w {
t.Errorf("get:\n%s\nwant:\n%s", g, w)
}