Debian Codegraph @

seq/quality/solexa.go

raw
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 quality
6
7 import (
8 "github.com/biogo/biogo/alphabet"
9 "github.com/biogo/biogo/seq"
10 )
11
12 // A slice of quality scores that satisfies the alphabet.Slice interface.
13 type Qsolexas []alphabet.Qsolexa
14
15 func (q Qsolexas) Make(len, cap int) alphabet.Slice { return make(Qsolexas, len, cap) }
16 func (q Qsolexas) Len() int { return len(q) }
17 func (q Qsolexas) Cap() int { return cap(q) }
18 func (q Qsolexas) Slice(start, end int) alphabet.Slice { return q[start:end] }
19 func (q Qsolexas) Append(a alphabet.Slice) alphabet.Slice {
20 return append(q, a.(Qsolexas)...)
21 }
22 func (q Qsolexas) Copy(a alphabet.Slice) int { return copy(q, a.(Qsolexas)) }
23
24 type Solexa struct {
25 seq.Annotation
26 Qual Qsolexas
27 Encode alphabet.Encoding
28 }
29
30 // Create a new scoring type.
31 func NewSolexa(id string, q []alphabet.Qsolexa, encode alphabet.Encoding) *Solexa {
32 return &Solexa{
33 Annotation: seq.Annotation{ID: id},
34 Qual: append([]alphabet.Qsolexa(nil), q...),
35 Encode: encode,
36 }
37 }
38
39 // Returns the underlying quality score slice.
40 func (q *Solexa) Slice() alphabet.Slice { return q.Qual }
41
42 // Set the underlying quality score slice.
43 func (q *Solexa) SetSlice(sl alphabet.Slice) { q.Qual = sl.(Qsolexas) }
44
45 // Append to the scores.
46 func (q *Solexa) Append(a ...alphabet.Qsolexa) { q.Qual = append(q.Qual, a...) }
47
48 // Return the raw score at position pos.
49 func (q *Solexa) At(i int) alphabet.Qsolexa { return q.Qual[i-q.Offset] }
50
51 // Return the error probability at position pos.
52 func (q *Solexa) EAt(i int) float64 { return q.Qual[i-q.Offset].ProbE() }
53
54 // Set the raw score at position pos to qual.
55 func (q *Solexa) Set(i int, qual alphabet.Qsolexa) error { q.Qual[i-q.Offset] = qual; return nil }
56
57 // Set the error probability to e at position pos.
58 func (q *Solexa) SetE(i int, e float64) error {
59 q.Qual[i-q.Offset] = alphabet.Esolexa(e)
60 return nil
61 }
62
63 // Encode the quality at position pos to a letter based on the sequence Encode setting.
64 func (q *Solexa) QEncode(i int) byte {
65 return q.Qual[i-q.Offset].Encode(q.Encode)
66 }
67
68 // Decode a quality letter to a phred score based on the sequence Encode setting.
69 func (q *Solexa) QDecode(l byte) alphabet.Qsolexa { return q.Encode.DecodeToQsolexa(l) }
70
71 // Return the quality Encode type.
72 func (q *Solexa) Encoding() alphabet.Encoding { return q.Encode }
73
74 // Set the quality Encode type to e.
75 func (q *Solexa) SetEncoding(e alphabet.Encoding) error { q.Encode = e; return nil }
76
77 // Return the length of the score sequence.
78 func (q *Solexa) Len() int { return len(q.Qual) }
79
80 // Return the start position of the score sequence.
81 func (q *Solexa) Start() int { return q.Offset }
82
83 // Return the end position of the score sequence.
84 func (q *Solexa) End() int { return q.Offset + q.Len() }
85
86 // Return a copy of the quality sequence.
87 func (q *Solexa) Copy() seq.Quality {
88 c := *q
89 c.Qual = append([]alphabet.Qsolexa(nil), q.Qual...)
90
91 return &c
92 }
93
94 // Reverse the order of elements in the sequence.
95 func (q *Solexa) Reverse() {
96 l := q.Qual
97 for i, j := 0, len(l)-1; i < j; i, j = i+1, j-1 {
98 l[i], l[j] = l[j], l[i]
99 }
100 }
101
102 func (q *Solexa) String() string {
103 qs := make([]byte, 0, len(q.Qual))
104 for _, s := range q.Qual {
105 qs = append(qs, s.Encode(q.Encode))
106 }
107 return string(qs)
108 }