| 1 | // Copyright ©2011-2012 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 alphabetscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/ |
| 6 | |
| 7 | import ( |
| 8 | "mathscip-go gomod github.com/golang/go/src go1.14 math/" |
| 9 | "unsafescip-go gomod github.com/golang/go/src go1.14 unsafe/" |
| 10 | ) |
| 11 | |
| 12 | // The Slice interface reflects the built-in slice type behavior. |
| 13 | type Slicescip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Slice# interface { |
| 14 | // Make makes a Slice with the same concrete type as the receiver. Make will |
| 15 | // panic if len or cap are less than zero or cap is less than len. |
| 16 | Makescip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Slice#Make.(len, cap int) Slicescip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Slice# |
| 17 | |
| 18 | // Len returns the length of the Slice. |
| 19 | Lenscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Slice#Len.() int |
| 20 | |
| 21 | // Cap returns the capacity of the Slice. |
| 22 | Capscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Slice#Cap.() int |
| 23 | |
| 24 | // Slice returns a slice of the Slice. The returned slice may be backed by |
| 25 | // the same array as the receiver. |
| 26 | Slicescip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Slice#Slice.(start, end int) Slicescip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Slice# |
| 27 | |
| 28 | // Append appends src... to the receiver and returns the resulting slice. If the append |
| 29 | // results in a grow slice the receiver will not reflect the appended slice, so the |
| 30 | // returned Slice should always be stored. Append should panic if src and the receiver |
| 31 | // are not the same concrete type. |
| 32 | Appendscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Slice#Append.(src Slicescip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Slice#) Slicescip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Slice# |
| 33 | |
| 34 | // Copy copies elements from src into the receiver, returning the number of elements |
| 35 | // copied. Copy should panic if src and the receiver are not the same concrete type. |
| 36 | Copyscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Slice#Copy.(src Slicescip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Slice#) int |
| 37 | } |
| 38 | |
| 39 | // An Encoding represents a quality score encoding scheme. |
| 40 | // Q-range |
| 41 | // |
| 42 | // Sanger !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHI··· 0 - 40 |
| 43 | // Solexa ··;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefgh··· -5 - 40 |
| 44 | // Illumina 1.3+ @ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefgh··· 0 - 40 |
| 45 | // Illumina 1.5+ xxḆCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefgh··· 3 - 40 |
| 46 | // Illumina 1.8+ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJ··· 0 - 40 |
| 47 | // |
| 48 | // !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefgh··· ···{|}~ |
| 49 | // | | | | | | |
| 50 | // 33 59 64 73 104 126 |
| 51 | // |
| 52 | // Q-range for typical raw reads |
| 53 | type Encodingscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Encoding# int8 |
| 54 | |
| 55 | const ( |
| 56 | Nonescip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/None. Encodingscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Encoding# = iota - 1 // All letters are decoded as scores with p(Error) = NaN. |
| 57 | Sangerscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Sanger. // Phred+33 |
| 58 | Solexascip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Solexa. // Solexa+64 |
| 59 | Illumina1_3scip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Illumina1_3. // Phred+64 |
| 60 | Illumina1_5scip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Illumina1_5. // Phred+64 0,1=unused, 2=Read Segment Quality Control Indicator (Ḇ) |
| 61 | Illumina1_8scip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Illumina1_8. // Phred+33 |
| 62 | Illumina1_9scip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Illumina1_9. // Phred+33 |
| 63 | ) |
| 64 | |
| 65 | // DecodeToPhred interprets the byte q as an e encoded quality and returns the corresponding Phred score. |
| 66 | func (e Encodingscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Encoding#) DecodeToQphredscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Encoding#DecodeToQphred().(q byte) Qphredscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Qphred# { |
| 67 | switch e { |
| 68 | case Sangerscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Sanger., Illumina1_8scip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Illumina1_8., Illumina1_9scip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Illumina1_9.: |
| 69 | return Qphredscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Qphred#(q) - 33 |
| 70 | case Illumina1_3scip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Illumina1_3., Illumina1_5scip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Illumina1_5.: |
| 71 | return Qphredscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Qphred#(q) - 64 |
| 72 | case Solexascip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Solexa.: |
| 73 | return (Qsolexascip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Qsolexa#(q) - 64).Qphredscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Qsolexa#Qphred().() |
| 74 | case Nonescip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/None.: |
| 75 | return 0xff |
| 76 | default: |
| 77 | panic("alphabet: illegal encoding") |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | // DecodeToPhred interprets the byte q as an e encoded quality and returns the corresponding Solexa score. |
| 82 | func (e Encodingscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Encoding#) DecodeToQsolexascip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Encoding#DecodeToQsolexa().(q byte) Qsolexascip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Qsolexa# { |
| 83 | switch e { |
| 84 | case Sangerscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Sanger., Illumina1_8scip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Illumina1_8., Illumina1_9scip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Illumina1_9.: |
| 85 | return (Qphredscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Qphred#(q) - 33).Qsolexascip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Qphred#Qsolexa().() |
| 86 | case Illumina1_3scip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Illumina1_3., Illumina1_5scip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Illumina1_5.: |
| 87 | return (Qphredscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Qphred#(q) - 64).Qsolexascip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Qphred#Qsolexa().() |
| 88 | case Solexascip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Solexa.: |
| 89 | return Qsolexascip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Qsolexa#(q) - 64 |
| 90 | case Nonescip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/None.: |
| 91 | return -128 |
| 92 | default: |
| 93 | panic("alphabet: illegal encoding") |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | // A Letter represents a sequence letter. |
| 98 | type Letterscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Letter# byte |
| 99 | |
| 100 | const logThreshLscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/logThreshL. = 2e2 // Approximate count where range loop becomes slower than copy |
| 101 | |
| 102 | // Repeat a Letter count times. |
| 103 | func (l Letterscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Letter#) Repeatscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Letter#Repeat().(count int) []Letterscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Letter# { |
| 104 | r := make([]Letterscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Letter#, count) |
| 105 | switch { |
| 106 | case count == 0: |
| 107 | case count < logThreshLscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/logThreshL.: |
| 108 | for i := range r { |
| 109 | r[i] = l |
| 110 | } |
| 111 | default: |
| 112 | r[0] = l |
| 113 | for i := 1; i < len(r); { |
| 114 | i += copy(r[i:], r[:i]) |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | return r |
| 119 | } |
| 120 | |
| 121 | // BytesToLetters converts a []byte to a []Letter. |
| 122 | func BytesToLettersscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/BytesToLetters().(b []byte) []Letterscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Letter# { return *(*[]Letterscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Letter#)(unsafescip-go gomod github.com/golang/go/src go1.14 unsafe/.Pointer(&b)) } |
| 123 | |
| 124 | // LettersToBytes converts a []Letter to a []byte. |
| 125 | func LettersToBytesscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/LettersToBytes().(l []Letterscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Letter#) []byte { return *(*[]byte)(unsafescip-go gomod github.com/golang/go/src go1.14 unsafe/.Pointer(&l)) } |
| 126 | |
| 127 | // A Letters is a slice of Letter that satisfies the Slice interface. |
| 128 | type Lettersscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Letters# []Letterscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Letter# |
| 129 | |
| 130 | func (l Lettersscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Letters#) Makescip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Letters#Make().(len, cap int) Slicescip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Slice# { return make(Lettersscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Letters#, len, cap) } |
| 131 | func (l Lettersscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Letters#) Lenscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Letters#Len().() int { return len(l) } |
| 132 | func (l Lettersscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Letters#) Capscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Letters#Cap().() int { return cap(l) } |
| 133 | func (l Lettersscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Letters#) Slicescip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Letters#Slice().(start, end int) Slicescip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Slice# { return l[start:end] } |
| 134 | func (l Lettersscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Letters#) Appendscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Letters#Append().(src Slicescip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Slice#) Slicescip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Slice# { return append(l, src.(Lettersscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Letters#)...) } |
| 135 | func (l Lettersscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Letters#) Copyscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Letters#Copy().(src Slicescip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Slice#) int { return copy(l, src.(Lettersscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Letters#)) } |
| 136 | func (l Lettersscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Letters#) Stringscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Letters#String().() string { return string(LettersToBytesscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/LettersToBytes().(l)) } |
| 137 | |
| 138 | // A Columns is a slice of []Letter that satisfies the alphabet.Slice interface. |
| 139 | type Columnsscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Columns# [][]Letterscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Letter# |
| 140 | |
| 141 | // Make makes a QColumns with the cap and len for each column set to the number of rows of the |
| 142 | // receiver. |
| 143 | func (lc Columnsscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Columns#) Makescip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Columns#Make().(len, cap int) Slicescip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Slice# { |
| 144 | r := lc.Rowsscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Columns#Rows().() |
| 145 | return make(Columnsscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Columns#, len, cap).MakeRowsscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Columns#MakeRows().(r, r) |
| 146 | } |
| 147 | |
| 148 | // MakeRows makes a column with len and cap for each column of the receiver and returns the receiver. |
| 149 | func (lc Columnsscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Columns#) MakeRowsscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Columns#MakeRows().(len, cap int) Slicescip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Slice# { |
| 150 | for i := range lc { |
| 151 | lc[i] = make([]Letterscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Letter#, len, cap) |
| 152 | } |
| 153 | return lc |
| 154 | } |
| 155 | |
| 156 | // Rows returns the number of positions in each column. |
| 157 | func (lc Columnsscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Columns#) Rowsscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Columns#Rows().() int { return len(lc[0]) } |
| 158 | |
| 159 | func (lc Columnsscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Columns#) Lenscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Columns#Len().() int { return len(lc) } |
| 160 | func (lc Columnsscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Columns#) Capscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Columns#Cap().() int { return cap(lc) } |
| 161 | func (lc Columnsscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Columns#) Slicescip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Columns#Slice().(start, end int) Slicescip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Slice# { return lc[start:end] } |
| 162 | func (lc Columnsscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Columns#) Appendscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Columns#Append().(a Slicescip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Slice#) Slicescip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Slice# { |
| 163 | // TODO deep copy the columns. |
| 164 | return append(lc, a.(Columnsscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Columns#)...) |
| 165 | } |
| 166 | func minscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/min().(a, b int) int { |
| 167 | if a < b { |
| 168 | return a |
| 169 | } |
| 170 | return b |
| 171 | } |
| 172 | func (lc Columnsscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Columns#) Copyscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Columns#Copy().(a Slicescip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Slice#) int { |
| 173 | ac := a.(Columnsscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Columns#) |
| 174 | var n int |
| 175 | for i, src := range ac[:minscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/min().(len(lc), len(ac))] { |
| 176 | n += copy(lc[i], src) |
| 177 | } |
| 178 | return n |
| 179 | } |
| 180 | |
| 181 | // A QLetter represents a sequence letter with an associated quality score. |
| 182 | type QLetterscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/QLetter# struct { |
| 183 | Lscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/QLetter#L. Letterscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Letter# |
| 184 | Qscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/QLetter#Q. Qphredscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Qphred# |
| 185 | } |
| 186 | |
| 187 | const logThreshQLscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/logThreshQL. = 1e2 // Approximate count where range loop becomes slower than copy |
| 188 | |
| 189 | // Repeat a QLetter count times. |
| 190 | func (ql QLetterscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/QLetter#) Repeatscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/QLetter#Repeat().(count int) []QLetterscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/QLetter# { |
| 191 | r := make([]QLetterscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/QLetter#, count) |
| 192 | switch { |
| 193 | case count == 0: |
| 194 | case count < logThreshQLscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/logThreshQL.: |
| 195 | for i := range r { |
| 196 | r[i] = ql |
| 197 | } |
| 198 | default: |
| 199 | r[0] = ql |
| 200 | for i := 1; i < len(r); { |
| 201 | i += copy(r[i:], r[:i]) |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | return r |
| 206 | } |
| 207 | |
| 208 | func (ql QLetterscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/QLetter#) Stringscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/QLetter#String().() string { return string(ql.Lscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/QLetter#L.) } |
| 209 | |
| 210 | // A QLetters is a slice of QLetter that satisfies the Slice interface. |
| 211 | type QLettersscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/QLetters# []QLetterscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/QLetter# |
| 212 | |
| 213 | func (ql QLettersscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/QLetters#) Makescip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/QLetters#Make().(len, cap int) Slicescip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Slice# { return make(QLettersscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/QLetters#, len, cap) } |
| 214 | func (ql QLettersscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/QLetters#) Lenscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/QLetters#Len().() int { return len(ql) } |
| 215 | func (ql QLettersscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/QLetters#) Capscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/QLetters#Cap().() int { return cap(ql) } |
| 216 | func (ql QLettersscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/QLetters#) Slicescip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/QLetters#Slice().(start, end int) Slicescip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Slice# { return ql[start:end] } |
| 217 | func (ql QLettersscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/QLetters#) Appendscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/QLetters#Append().(src Slicescip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Slice#) Slicescip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Slice# { return append(ql, src.(QLettersscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/QLetters#)...) } |
| 218 | func (ql QLettersscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/QLetters#) Copyscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/QLetters#Copy().(src Slicescip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Slice#) int { return copy(ql, src.(QLettersscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/QLetters#)) } |
| 219 | |
| 220 | // A QColumns is a slice of []QLetter that satisfies the Slice interface. |
| 221 | type QColumnsscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/QColumns# [][]QLetterscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/QLetter# |
| 222 | |
| 223 | // Make makes a QColumns with the cap and len for each column set to the number of rows of the |
| 224 | // receiver. |
| 225 | func (qc QColumnsscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/QColumns#) Makescip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/QColumns#Make().(len, cap int) Slicescip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Slice# { |
| 226 | r := qc.Rowsscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/QColumns#Rows().() |
| 227 | return make(QColumnsscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/QColumns#, len, cap).MakeRowsscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/QColumns#MakeRows().(r, r) |
| 228 | } |
| 229 | |
| 230 | // MakeRows makes a column with len and cap for each column of the receiver and returns the receiver. |
| 231 | func (qc QColumnsscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/QColumns#) MakeRowsscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/QColumns#MakeRows().(len, cap int) Slicescip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Slice# { |
| 232 | for i := range qc { |
| 233 | qc[i] = make([]QLetterscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/QLetter#, len, cap) |
| 234 | } |
| 235 | return qc |
| 236 | } |
| 237 | |
| 238 | // Rows returns the number of positions in each column. |
| 239 | func (qc QColumnsscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/QColumns#) Rowsscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/QColumns#Rows().() int { return len(qc[0]) } |
| 240 | |
| 241 | func (qc QColumnsscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/QColumns#) Lenscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/QColumns#Len().() int { return len(qc) } |
| 242 | func (qc QColumnsscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/QColumns#) Capscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/QColumns#Cap().() int { return cap(qc) } |
| 243 | func (qc QColumnsscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/QColumns#) Slicescip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/QColumns#Slice().(start, end int) Slicescip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Slice# { return qc[start:end] } |
| 244 | func (qc QColumnsscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/QColumns#) Appendscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/QColumns#Append().(a Slicescip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Slice#) Slicescip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Slice# { |
| 245 | // TODO deep copy the columns. |
| 246 | return append(qc, a.(QColumnsscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/QColumns#)...) |
| 247 | } |
| 248 | |
| 249 | func (qc QColumnsscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/QColumns#) Copyscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/QColumns#Copy().(a Slicescip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Slice#) int { |
| 250 | ac := a.(QColumnsscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/QColumns#) |
| 251 | var n int |
| 252 | for i, src := range ac[:minscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/min().(len(qc), len(ac))] { |
| 253 | n += copy(qc[i], src) |
| 254 | } |
| 255 | return n |
| 256 | } |
| 257 | |
| 258 | // A Qscore represents a quality score. |
| 259 | type Qscorescip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Qscore# interface { |
| 260 | ProbEscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Qscore#ProbE.() float64 |
| 261 | Encodescip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Qscore#Encode.(Encodingscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Encoding#) byte |
| 262 | Stringscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Qscore#String.() string |
| 263 | } |
| 264 | |
| 265 | var nanscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/nan. = mathscip-go gomod github.com/golang/go/src go1.14 math/.NaNscip-go gomod github.com/golang/go/src go1.14 math/NaN().() |
| 266 | |
| 267 | // A Qphred represents a Phred quality score. |
| 268 | type Qphredscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Qphred# byte |
| 269 | |
| 270 | // Ephred returns the Qphred for a error probability p. |
| 271 | func Ephredscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Ephred().(p float64) Qphredscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Qphred# { |
| 272 | if p == 0 { |
| 273 | return 254 |
| 274 | } |
| 275 | if mathscip-go gomod github.com/golang/go/src go1.14 math/.IsNaNscip-go gomod github.com/golang/go/src go1.14 math/IsNaN().(p) { |
| 276 | return 255 |
| 277 | } |
| 278 | Q := -10 * mathscip-go gomod github.com/golang/go/src go1.14 math/.Log10scip-go gomod github.com/golang/go/src go1.14 math/Log10().(p) |
| 279 | Q += 0.5 |
| 280 | if Q > 254 { |
| 281 | Q = 254 |
| 282 | } |
| 283 | return Qphredscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Qphred#(Q) |
| 284 | } |
| 285 | |
| 286 | // ProbE returns the error probability for the receiver's Phred value. |
| 287 | func (qp Qphredscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Qphred#) ProbEscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Qphred#ProbE().() float64 { |
| 288 | return phredETablescip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/phredETable.[qp] |
| 289 | } |
| 290 | |
| 291 | // phredETable holds a lookup for phred E values. |
| 292 | var phredETablescip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/phredETable. = func() [256]float64 { |
| 293 | t := [256]float64{254: 0, 255: nanscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/nan.} |
| 294 | for q := range t[:254] { |
| 295 | t[q] = mathscip-go gomod github.com/golang/go/src go1.14 math/.Powscip-go gomod github.com/golang/go/src go1.14 math/Pow().(10, -(float64(q) / 10)) |
| 296 | } |
| 297 | return t |
| 298 | }() |
| 299 | |
| 300 | // Qsolexa converts the quality value from Phred to Solexa. This conversion is lossy and |
| 301 | // should be avoided; the epsilon on the E value associated with a converted Qsolexa is |
| 302 | // bounded approximately by math.Pow(10, 1e-4-float64(qp)/10) over the range 0 < qp < 127. |
| 303 | func (qp Qphredscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Qphred#) Qsolexascip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Qphred#Qsolexa().() Qsolexascip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Qsolexa# { return phredSolexaTablescip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/phredSolexaTable.[qp] } |
| 304 | |
| 305 | // phredSolexaTable holds a lookup for the near equivalent solexa score of a phred score. |
| 306 | var phredSolexaTablescip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/phredSolexaTable. = func() [256]Qsolexascip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Qsolexa# { |
| 307 | t := [256]Qsolexascip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Qsolexa#{254: 127, 255: -128} |
| 308 | for q := range t[:254] { |
| 309 | Q := 10 * mathscip-go gomod github.com/golang/go/src go1.14 math/.Log10scip-go gomod github.com/golang/go/src go1.14 math/Log10().(mathscip-go gomod github.com/golang/go/src go1.14 math/.Powscip-go gomod github.com/golang/go/src go1.14 math/Pow().(10, float64(q)/10)-1) |
| 310 | if Q > 0 { |
| 311 | Q += 0.5 |
| 312 | } else { |
| 313 | Q -= 0.5 |
| 314 | } |
| 315 | if Q > 127 { |
| 316 | Q = 127 |
| 317 | } |
| 318 | t[q] = Qsolexascip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Qsolexa#(Q) |
| 319 | } |
| 320 | return t |
| 321 | }() |
| 322 | |
| 323 | // Encode encodes the receiver's Phred score to a byte based on the specified encoding. |
| 324 | func (qp Qphredscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Qphred#) Encodescip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Qphred#Encode().(e Encodingscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Encoding#) (q byte) { |
| 325 | if qp == 254 { |
| 326 | return '~' |
| 327 | } |
| 328 | if qp == 255 { |
| 329 | return ' ' |
| 330 | } |
| 331 | switch e { |
| 332 | case Sangerscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Sanger., Illumina1_8scip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Illumina1_8., Illumina1_9scip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Illumina1_9.: |
| 333 | q = byte(qp) |
| 334 | if q <= 93 { |
| 335 | q += 33 |
| 336 | } |
| 337 | case Illumina1_3scip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Illumina1_3.: |
| 338 | q = byte(qp) |
| 339 | if q <= 62 { |
| 340 | q += 64 |
| 341 | } |
| 342 | case Illumina1_5scip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Illumina1_5.: |
| 343 | q = byte(qp) |
| 344 | if q <= 62 { |
| 345 | q += 64 |
| 346 | } |
| 347 | if q < 'B' { |
| 348 | q = 'B' |
| 349 | } |
| 350 | return q |
| 351 | case Solexascip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Solexa.: |
| 352 | q = byte(qp.Qsolexascip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Qphred#Qsolexa().()) |
| 353 | if q <= 62 { |
| 354 | q += 64 |
| 355 | } |
| 356 | case Nonescip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/None.: |
| 357 | return ' ' |
| 358 | } |
| 359 | |
| 360 | return |
| 361 | } |
| 362 | |
| 363 | func (qp Qphredscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Qphred#) Stringscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Qphred#String().() string { |
| 364 | if qp < 254 { |
| 365 | return string([]byte{byte(qp)}) |
| 366 | } else if qp == 255 { |
| 367 | return " " |
| 368 | } |
| 369 | return "\u221e" |
| 370 | } |
| 371 | |
| 372 | // A Qsolexa represents a Solexa quality score. |
| 373 | type Qsolexascip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Qsolexa# int8 |
| 374 | |
| 375 | // Esolexa returns the Qsolexa for a error probability p. |
| 376 | func Esolexascip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Esolexa().(p float64) Qsolexascip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Qsolexa# { |
| 377 | if p == 0 { |
| 378 | return 127 |
| 379 | } |
| 380 | if mathscip-go gomod github.com/golang/go/src go1.14 math/.IsNaNscip-go gomod github.com/golang/go/src go1.14 math/IsNaN().(p) { |
| 381 | return -128 |
| 382 | } |
| 383 | Q := -10 * mathscip-go gomod github.com/golang/go/src go1.14 math/.Log10scip-go gomod github.com/golang/go/src go1.14 math/Log10().(p/(1-p)) |
| 384 | if Q > 0 { |
| 385 | Q += 0.5 |
| 386 | } else { |
| 387 | Q -= 0.5 |
| 388 | } |
| 389 | return Qsolexascip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Qsolexa#(Q) |
| 390 | } |
| 391 | |
| 392 | // ProbE returns the error probability for the receiver's Phred value. |
| 393 | func (qs Qsolexascip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Qsolexa#) ProbEscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Qsolexa#ProbE().() float64 { return solexaETablescip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/solexaETable.[int(qs)+128] } |
| 394 | |
| 395 | // solexaETable holds a translated lookup table for solexa E values. Since solexa |
| 396 | // scores can extend into negative territory, the table is shifted 128 into the |
| 397 | // positive. |
| 398 | var solexaETablescip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/solexaETable. = func() [256]float64 { |
| 399 | t := [256]float64{0: nanscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/nan., 255: 0} |
| 400 | for q := range t[1:255] { |
| 401 | pq := mathscip-go gomod github.com/golang/go/src go1.14 math/.Powscip-go gomod github.com/golang/go/src go1.14 math/Pow().(10, -(float64(q-127) / 10)) |
| 402 | t[q+1] = pq / (1 + pq) |
| 403 | } |
| 404 | return t |
| 405 | }() |
| 406 | |
| 407 | // Qphred converts the quality value from Solexa to Phred. This conversion is lossy and |
| 408 | // should be avoided; the epsilon on the E value associated with a converted Qphred is |
| 409 | // bounded approximately by math.Pow(10, 1e-4-float64(qs)/10) over the range 0 < qs < 127. |
| 410 | func (qs Qsolexascip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Qsolexa#) Qphredscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Qsolexa#Qphred().() Qphredscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Qphred# { return solexaPhredTablescip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/solexaPhredTable.[int(qs)+128] } |
| 411 | |
| 412 | // solexaPhredTable holds a lookup for the near equivalent phred score of a solexa |
| 413 | // score. Since solexa scores can extend into negative territory, the table is |
| 414 | // shifted 128 into the positive. |
| 415 | var solexaPhredTablescip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/solexaPhredTable. = func() [256]Qphredscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Qphred# { |
| 416 | t := [256]Qphredscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Qphred#{0: 255, 255: 0} |
| 417 | for q := range t[1:255] { |
| 418 | qs := q - 127 |
| 419 | Q := Qphredscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Qphred#(10*mathscip-go gomod github.com/golang/go/src go1.14 math/.Log10scip-go gomod github.com/golang/go/src go1.14 math/Log10().(mathscip-go gomod github.com/golang/go/src go1.14 math/.Powscip-go gomod github.com/golang/go/src go1.14 math/Pow().(10, float64(qs)/10)) + 0.5) |
| 420 | if Q > 254 { |
| 421 | Q = 254 |
| 422 | } |
| 423 | t[q+1] = Q |
| 424 | } |
| 425 | return t |
| 426 | }() |
| 427 | |
| 428 | // Encode encodes the receiver's Solexa score to a byte based on the specified encoding. |
| 429 | func (qs Qsolexascip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Qsolexa#) Encodescip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Qsolexa#Encode().(e Encodingscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Encoding#) (q byte) { |
| 430 | if qs == 127 { |
| 431 | return '~' |
| 432 | } |
| 433 | if qs == -128 { |
| 434 | return ' ' |
| 435 | } |
| 436 | switch e { |
| 437 | case Sangerscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Sanger., Illumina1_8scip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Illumina1_8.: |
| 438 | q = byte(qs.Qphredscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Qsolexa#Qphred().()) |
| 439 | if q <= 93 { |
| 440 | q += 33 |
| 441 | } |
| 442 | case Illumina1_3scip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Illumina1_3.: |
| 443 | q = byte(qs.Qphredscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Qsolexa#Qphred().()) |
| 444 | if q <= 62 { |
| 445 | q += 64 |
| 446 | } |
| 447 | case Illumina1_5scip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Illumina1_5.: |
| 448 | q = byte(qs.Qphredscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Qsolexa#Qphred().()) |
| 449 | if q <= 62 { |
| 450 | q += 64 |
| 451 | } |
| 452 | if q < 'B' { |
| 453 | q = 'B' |
| 454 | } |
| 455 | case Solexascip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Solexa.: |
| 456 | q = byte(qs) |
| 457 | if q <= 62 { |
| 458 | q += 64 |
| 459 | } |
| 460 | case Nonescip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/None.: |
| 461 | return ' ' |
| 462 | } |
| 463 | |
| 464 | return |
| 465 | } |
| 466 | |
| 467 | func (qs Qsolexascip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Qsolexa#) Stringscip-go gomod github.com/biogo/biogo . `github.com/biogo/biogo/alphabet`/Qsolexa#String().() string { |
| 468 | if qs < 127 && qs != -128 { |
| 469 | return string([]byte{byte(qs)}) |
| 470 | } else if qs == -128 { |
| 471 | return " " |
| 472 | } |
| 473 | return "\u221e" |
| 474 | } |