Documentation ¶
Overview ¶
Package align implements NeedlemanWunsch pairwise alignment.
This implementation of the Needleman and Wunsch alignment algorithm aims to be accurate and easy to understand. It's goal is Not to be the fastest, though it's quite fast.
https://en.wikipedia.org/wiki/Needleman%E2%80%93Wunsch_algorithm
Example (FuzzyMatchWithCompare) ¶
package main import ( "fmt" "github.com/gregoryv/align" ) func main() { a := "GCATGCUAAAAAAA" b := "GATTACAAAAAAAABBB" if align.Compare(a, b) > 0.7 { fmt.Println("similar enough") } }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Compare ¶
Compare returns 1.0 if equal otherwise the value of matching characters.
Example ¶
package main import ( "fmt" "github.com/gregoryv/align" ) func main() { fmt.Println( align.Compare( "GCATGCUAAAAAAA", "GATTACAAAAAAAABBB", ), ) fmt.Println( align.Compare( "ABC", "ABC", ), ) }
Output: 0.78571427 1
Types ¶
type Result ¶
type Result struct {
// contains filtered or unexported fields
}
func NeedlemanWunsch ¶
NeedlemanWunsch aligns sequences a and b with simple scores 1, -1, -1 and -1. Start gap is no different from extending the gap.
func NeedlemanWunschCustom ¶
NeedlemanWunschCustom calculates the score matrix using custom scores match, missmatch, insert/delete and extended gap. Sequences a and b must not be empty.
func (*Result) Alignments ¶
func (result *Result) Alignments() []alignment
Alignments returns all possible alignments with max score
func (*Result) PrintAlignment ¶
Example ¶
package main import ( "os" "github.com/gregoryv/align" ) func main() { a := []rune("GCATGCU") b := []rune("GATTACA") result := align.NeedlemanWunsch(a, b) result.PrintAlignment(os.Stdout) }
Output: GCA-TGCU G-ATTACA GCAT-GCU G-ATTACA GCATG-CU G-ATTACA
func (*Result) PrintOrigins ¶
PrintOrigins writes out the score origins for each score. 0 = None(top row and first column), 1 = Diagonal, 2 = Left and 4 = Top Eg. 5 = diagonal or top
Example ¶
Origin arrows are represented using three bits, 0 = No origin, 1 = diagonal, 2 = left and 4 is top.
package main import ( "os" "github.com/gregoryv/align" ) func main() { a := []rune("GCATGCU") b := []rune("GATTACA") result := align.NeedlemanWunsch(a, b) result.PrintOrigins(os.Stdout) }
Output: G C A T G C U 0 0 0 0 0 0 0 0 G 0 1 2 2 2 3 2 2 A 0 4 1 1 2 2 2 2 T 0 4 5 4 1 2 2 2 T 0 4 5 4 5 1 3 3 A 0 4 5 1 4 5 1 3 C 0 4 1 4 4 5 1 2 A 0 4 4 1 6 5 4 1
func (*Result) PrintScoreMatrix ¶
PrintScoreMatrix writes out the sequences and their calculated score as shown on wikipedia.
Example ¶
package main import ( "os" "github.com/gregoryv/align" ) func main() { a := []rune("GCATGCU") b := []rune("GATTACA") result := align.NeedlemanWunsch(a, b) result.PrintScoreMatrix(os.Stdout) }
Output: G C A T G C U 0 -1 -2 -3 -4 -5 -6 -7 G -1 1 0 -1 -2 -3 -4 -5 A -2 0 0 1 0 -1 -2 -3 T -3 -1 -1 0 2 1 0 -1 T -4 -2 -2 -1 1 1 0 -1 A -5 -3 -3 -1 0 0 0 -1 C -6 -4 -2 -2 -1 -1 1 0 A -7 -5 -3 -1 -2 -2 0 0
Example (Global) ¶
package main import ( "os" "github.com/gregoryv/align" ) func main() { a := []rune("GCATGCU") b := []rune("GAT") result := align.NeedlemanWunsch(a, b) result.PrintScoreMatrix(os.Stdout) }
Output: G C A T G C U 0 -1 -2 -3 -4 -5 -6 -7 G -1 1 0 -1 -2 -3 -4 -5 A -2 0 0 1 0 -1 -2 -3 T -3 -1 -1 0 2 1 0 -1