| 1 |
// Copyright ©2011-2013 The bíogo Authors. All rights reserved. |
| 2 |
// Use of this source code is governed by a BSD-style |
| 3 |
// license that can be found in the LICENSE file. |
| 4 |
|
| 5 |
package align |
| 6 |
|
| 7 |
import ( |
| 8 |
"github.com/biogo/biogo/alphabet" |
| 9 |
"github.com/biogo/biogo/seq/linear" |
| 10 |
|
| 11 |
"fmt" |
| 12 |
) |
| 13 |
|
| 14 |
func ExampleNW_Align() { |
| 15 |
nwsa := &linear.Seq{Seq: alphabet.BytesToLetters([]byte("AGACTAGTTA"))} |
| 16 |
nwsa.Alpha = alphabet.DNAgapped |
| 17 |
nwsb := &linear.Seq{Seq: alphabet.BytesToLetters([]byte("GACAGACG"))} |
| 18 |
nwsb.Alpha = alphabet.DNAgapped |
| 19 |
|
| 20 |
// Query letter |
| 21 |
// - A C G T |
| 22 |
// - 0 -5 -5 -5 -5 |
| 23 |
// A -5 10 -3 -1 -4 |
| 24 |
// C -5 -3 9 -5 0 |
| 25 |
// G -5 -1 -5 7 -3 |
| 26 |
// T -5 -4 0 -3 8 |
| 27 |
needle := NW{ |
| 28 |
{0, -5, -5, -5, -5}, |
| 29 |
{-5, 10, -3, -1, -4}, |
| 30 |
{-5, -3, 9, -5, 0}, |
| 31 |
{-5, -1, -5, 7, -3}, |
| 32 |
{-5, -4, 0, -3, 8}, |
| 33 |
} |
| 34 |
|
| 35 |
aln, err := needle.Align(nwsa, nwsb) |
| 36 |
if err == nil { |
| 37 |
fmt.Printf("%s\n", aln) |
| 38 |
fa := Format(nwsa, nwsb, aln, '-') |
| 39 |
fmt.Printf("%s\n%s\n", fa[0], fa[1]) |
| 40 |
} |
| 41 |
// Output: |
| 42 |
//[[0,1)/-=-5 [1,4)/[0,3)=26 [4,5)/-=-5 [5,10)/[3,8)=12] |
| 43 |
// AGACTAGTTA |
| 44 |
// -GAC-AGACG |
| 45 |
} |
| 46 |
|
| 47 |
func ExampleNWAffine_Align() { |
| 48 |
nwsa := &linear.Seq{Seq: alphabet.BytesToLetters([]byte("ATAGGAAG"))} |
| 49 |
nwsa.Alpha = alphabet.DNAgapped |
| 50 |
nwsb := &linear.Seq{Seq: alphabet.BytesToLetters([]byte("ATTGGCAATG"))} |
| 51 |
nwsb.Alpha = alphabet.DNAgapped |
| 52 |
|
| 53 |
// Query letter |
| 54 |
// - A C G T |
| 55 |
// - 0 -1 -1 -1 -1 |
| 56 |
// A -1 1 -1 -1 -1 |
| 57 |
// C -1 -1 1 -1 -1 |
| 58 |
// G -1 -1 -1 1 -1 |
| 59 |
// T -1 -1 -1 -1 1 |
| 60 |
// |
| 61 |
// Gap open: -5 |
| 62 |
needle := NWAffine{ |
| 63 |
Matrix: Linear{ |
| 64 |
{0, -1, -1, -1, -1}, |
| 65 |
{-1, 1, -1, -1, -1}, |
| 66 |
{-1, -1, 1, -1, -1}, |
| 67 |
{-1, -1, -1, 1, -1}, |
| 68 |
{-1, -1, -1, -1, 1}, |
| 69 |
}, |
| 70 |
GapOpen: -5, |
| 71 |
} |
| 72 |
|
| 73 |
aln, err := needle.Align(nwsa, nwsb) |
| 74 |
if err == nil { |
| 75 |
fmt.Printf("%s\n", aln) |
| 76 |
fa := Format(nwsa, nwsb, aln, '-') |
| 77 |
fmt.Printf("%s\n%s\n", fa[0], fa[1]) |
| 78 |
} |
| 79 |
// Output: |
| 80 |
// [[0,7)/[0,7)=3 -/[7,9)=-7 [7,8)/[9,10)=1] |
| 81 |
// ATAGGAA--G |
| 82 |
// ATTGGCAATG |
| 83 |
} |