Documentation ¶
Overview ¶
Package alphabet describes biological sequence letters, including quality scores.
Example (AllValid) ¶
fmt.Println(DNA.AllValid([]Letter("acgatcgatatagctatnagcatgc")))
Output: false 17
Example (Complement) ¶
var ( c Letter ok bool ) c, ok = DNA.Complement('a') fmt.Printf("%c %v\n", c, ok) c, ok = DNA.Complement('n') fmt.Printf("%c %v\n", c, ok) c, ok = RNA.Complement('a') fmt.Printf("%c %v\n", c, ok) c, ok = RNA.Complement('t') fmt.Printf("%c %v\n", c, ok)
Output: t true n true u true t false
Index ¶
- Constants
- Variables
- func LettersToBytes(l []Letter) []byte
- type Alphabet
- type Columns
- type Complementor
- type Encoding
- type Index
- type Letter
- type Letters
- type Pairing
- type QColumns
- func (qc QColumns) Append(a Slice) Slice
- func (qc QColumns) Cap() int
- func (qc QColumns) Copy(a Slice) int
- func (qc QColumns) Len() int
- func (qc QColumns) Make(len, cap int) Slice
- func (qc QColumns) MakeRows(len, cap int) Slice
- func (qc QColumns) Rows() int
- func (qc QColumns) Slice(start, end int) Slice
- type QLetter
- type QLetters
- type Qphred
- type Qscore
- type Qsolexa
- type Slice
Examples ¶
Constants ¶
const (
CaseSensitive = true
)
Variables ¶
var ( DNA = MustComplement(NewComplementor( "acgt", feat.DNA, MustPair(NewPairing("acgtnxACGTNX-", "tgcanxTGCANX-")), '-', 'n', !CaseSensitive, )) DNAgapped = MustComplement(NewComplementor( "-acgt", feat.DNA, MustPair(NewPairing("acgtnxACGTNX-", "tgcanxTGCANX-")), '-', 'n', !CaseSensitive, )) DNAredundant = MustComplement(NewComplementor( "-acmgrsvtwyhkdbn", feat.DNA, MustPair(NewPairing("acmgrsvtwyhkdbnxACMGRSVTWYHKDBNX-", "tgkcysbawrdmhvnxTGKCYSBAWRDMHVNX-")), '-', 'n', !CaseSensitive, )) RNA = MustComplement(NewComplementor( "acgu", feat.RNA, MustPair(NewPairing("acgunxACGUNX-", "ugcanxUGCANX-")), '-', 'n', !CaseSensitive, )) RNAgapped = MustComplement(NewComplementor( "-acgu", feat.RNA, MustPair(NewPairing("acgunxACGUNX-", "ugcanxUGCANX-")), '-', 'n', !CaseSensitive, )) RNAredundant = MustComplement(NewComplementor( "-acmgrsvuwyhkdbn", feat.RNA, MustPair(NewPairing("acmgrsvuwyhkdbnxACMGRSVUWYHKDBNX-", "ugkcysbawrdmhvnxUGKCYSBAWRDMHVNX-")), '-', 'n', !CaseSensitive, )) Protein = Must(NewAlphabet( "-abcdefghijklmnpqrstvwxyz*", feat.Protein, '-', 'x', !CaseSensitive, )) )
Package alphabet provides default Alphabets for DNA, RNA and Protein. These alphabets are case insensitive and for the non-redundant nucleic acid alphabets satisfy the condition that the index of a letter is equal to the bitwise-complement of the index of the base-complement, modulo 4.
Functions ¶
func LettersToBytes ¶
LettersToBytes converts a []Letter to a []byte.
Types ¶
type Alphabet ¶
type Alphabet interface { // IsValid reports whether a letter conforms to the alphabet. IsValid(Letter) bool // AllValid reports whether a slice of bytes conforms to the alphabet. // It returns the index of the first invalid byte, // or a negative int if all bytes are valid. AllValid([]Letter) (ok bool, pos int) // AllValidQLetter reports whether a slice of bytes conforms to the alphabet. // It returns the index of the first invalid byte, // or a negative int if all bytes are valid. AllValidQLetter([]QLetter) (ok bool, pos int) // Len returns the number of distinct valid letters in the alphabet. Len() int // IndexOf returns the index of a given letter. IndexOf(Letter) int // Letter returns the letter corresponding to the given index. Letter(int) Letter // LetterIndex returns a pointer to the internal array specifying // letter to index conversion. The returned index should not be altered. LetterIndex() Index // Letters returns a string of letters conforming to the alphabet in index // order. In case insensitive alphabets, both cases are presented. Letters() string // ValidLetters returns a slice of the internal []bool indicating valid // letters. The returned slice should not be altered. ValidLetters() []bool // Gap returns the gap character used by the alphabet. Gap() Letter // Ambiguous returns the character representing an ambiguous letter. Ambiguous() Letter // Moltype returns the molecule type of the alphabet. Moltype() feat.Moltype // IsCased returns whether the alphabet is case sensitive. IsCased() bool }
An Alphabet describes valid single character letters within a sequence.
func Must ¶
Must is a helper that wraps a call to a function returning (Alphabet, error) and panics if the error is non-nil. It is intended for use in variable initializations.
func NewAlphabet ¶
func NewAlphabet(letters string, molType feat.Moltype, gap, ambiguous Letter, caseSensitive bool) (Alphabet, error)
NewAlphabet returns a new Alphabet based on the provided definitions. Index values for letters reflect order of the letters parameter. Letters must be within the ASCII range. No check is performed to determine whether letters appear more than once, the index of a letter will be the position of the last occurrence of that letter in the letters parameter.
type Columns ¶
type Columns [][]Letter
A Columns is a slice of []Letter that satisfies the alphabet.Slice interface.
func (Columns) Make ¶
Make makes a QColumns with the cap and len for each column set to the number of rows of the receiver.
func (Columns) MakeRows ¶
MakeRows makes a column with len and cap for each column of the receiver and returns the receiver.
type Complementor ¶
type Complementor interface { Alphabet Complement(Letter) (Letter, bool) ComplementTable() []Letter }
A Complementor is an Alphabet that describes the complementation relationships between letters.
func MustComplement ¶
func MustComplement(c Complementor, err error) Complementor
MustComplement is a helper that wraps a call to a function returning (Complementor, error) and panics if the error is non-nil. It is intended for use in variable initializations.
func NewComplementor ¶
func NewComplementor(letters string, molType feat.Moltype, pairs *Pairing, gap, ambiguous Letter, caseSensitive bool) (Complementor, error)
NewComplementor returns a complementing alphabet. The Complement table is checked for validity and an error is returned if an invalid complement pair is found. Pairings that result in no change but would otherwise be invalid are allowed. Letter parameter handling is the same as for NewAlphabet.
type Encoding ¶
type Encoding int8
An Encoding represents a quality score encoding scheme.
Q-range Sanger !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHI··· 0 - 40 Solexa ··;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefgh··· -5 - 40 Illumina 1.3+ @ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefgh··· 0 - 40 Illumina 1.5+ xxḆCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefgh··· 3 - 40 Illumina 1.8+ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJ··· 0 - 40 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefgh··· ···{|}~ | | | | | | 33 59 64 73 104 126 Q-range for typical raw reads
func (Encoding) DecodeToQphred ¶
DecodeToPhred interprets the byte q as an e encoded quality and returns the corresponding Phred score.
func (Encoding) DecodeToQsolexa ¶
DecodeToPhred interprets the byte q as an e encoded quality and returns the corresponding Solexa score.
type Letter ¶
type Letter byte
A Letter represents a sequence letter.
func BytesToLetters ¶
BytesToLetters converts a []byte to a []Letter.
type Letters ¶
type Letters []Letter
A Letters is a slice of Letter that satisfies the Slice interface.
type Pairing ¶
type Pairing struct {
// contains filtered or unexported fields
}
A Pairing provides a lookup table between a letter and its complement.
func MustPair ¶
MustPair is a helper that wraps a call to a function returning (*Pairing, error) and panics if the error is non-nil. It is intended for use in variable initializations.
func NewPairing ¶
NewPairing create a new Pairing from a pair of strings. Pairing definitions must be a bijection and must contain only ASCII characters.
func (*Pairing) Complement ¶
Returns the complement of a letter and true if the complement is a valid letter otherwise unchanged and false.
func (*Pairing) ComplementTable ¶
Returns a complementation table based on the internal representation. Invalid pairs hold a value outside the ASCII range. The caller must not modify the returned table.
type QColumns ¶
type QColumns [][]QLetter
A QColumns is a slice of []QLetter that satisfies the Slice interface.
func (QColumns) Make ¶
Make makes a QColumns with the cap and len for each column set to the number of rows of the receiver.
func (QColumns) MakeRows ¶
MakeRows makes a column with len and cap for each column of the receiver and returns the receiver.
type QLetters ¶
type QLetters []QLetter
A QLetters is a slice of QLetter that satisfies the Slice interface.
type Qphred ¶
type Qphred byte
A Qphred represents a Phred quality score.
func (Qphred) Encode ¶
Encode encodes the receiver's Phred score to a byte based on the specified encoding.
type Qsolexa ¶
type Qsolexa int8
A Qsolexa represents a Solexa quality score.
func (Qsolexa) Encode ¶
Encode encodes the receiver's Solexa score to a byte based on the specified encoding.
type Slice ¶
type Slice interface { // Make makes a Slice with the same concrete type as the receiver. Make will // panic if len or cap are less than zero or cap is less than len. Make(len, cap int) Slice // Len returns the length of the Slice. Len() int // Cap returns the capacity of the Slice. Cap() int // Slice returns a slice of the Slice. The returned slice may be backed by // the same array as the receiver. Slice(start, end int) Slice // Append appends src... to the receiver and returns the resulting slice. If the append // results in a grow slice the receiver will not reflect the appended slice, so the // returned Slice should always be stored. Append should panic if src and the receiver // are not the same concrete type. Append(src Slice) Slice // Copy copies elements from src into the receiver, returning the number of elements // copied. Copy should panic if src and the receiver are not the same concrete type. Copy(src Slice) int }
The Slice interface reflects the built-in slice type behavior.