biogo: github.com/biogo/biogo/alphabet Index | Examples | Files

package alphabet

import "github.com/biogo/biogo/alphabet"

Package alphabet describes biological sequence letters, including quality scores.

Code:

fmt.Println(DNA.AllValid([]Letter("acgatcgatatagctatnagcatgc")))

Output:

false 17

Code:

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

Examples

Package Files

alphabet.go letters.go

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.

func LettersToBytes Uses

func LettersToBytes(l []Letter) []byte

LettersToBytes converts a []Letter to a []byte.

type Alphabet Uses

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 Uses

func Must(a Alphabet, err error) Alphabet

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 Uses

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 Uses

type Columns [][]Letter

A Columns is a slice of []Letter that satisfies the alphabet.Slice interface.

func (Columns) Append Uses

func (lc Columns) Append(a Slice) Slice

func (Columns) Cap Uses

func (lc Columns) Cap() int

func (Columns) Copy Uses

func (lc Columns) Copy(a Slice) int

func (Columns) Len Uses

func (lc Columns) Len() int

func (Columns) Make Uses

func (lc Columns) Make(len, cap int) Slice

Make makes a QColumns with the cap and len for each column set to the number of rows of the receiver.

func (Columns) MakeRows Uses

func (lc Columns) MakeRows(len, cap int) Slice

MakeRows makes a column with len and cap for each column of the receiver and returns the receiver.

func (Columns) Rows Uses

func (lc Columns) Rows() int

Rows returns the number of positions in each column.

func (Columns) Slice Uses

func (lc Columns) Slice(start, end int) Slice

type Complementor Uses

type Complementor interface {
    Alphabet
    Complement(Letter) (Letter, bool)
    ComplementTable() []Letter
}

A Complementor is an Alphabet that describes the complementation relationships between letters.

func MustComplement Uses

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 Uses

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 Uses

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
const (
    None        Encoding = iota - 1 // All letters are decoded as scores with p(Error) = NaN.
    Sanger                          // Phred+33
    Solexa                          // Solexa+64
    Illumina1_3                     // Phred+64
    Illumina1_5                     // Phred+64 0,1=unused, 2=Read Segment Quality Control Indicator (Ḇ)
    Illumina1_8                     // Phred+33
    Illumina1_9                     // Phred+33
)

func (Encoding) DecodeToQphred Uses

func (e Encoding) DecodeToQphred(q byte) Qphred

DecodeToPhred interprets the byte q as an e encoded quality and returns the corresponding Phred score.

func (Encoding) DecodeToQsolexa Uses

func (e Encoding) DecodeToQsolexa(q byte) Qsolexa

DecodeToPhred interprets the byte q as an e encoded quality and returns the corresponding Solexa score.

type Index Uses

type Index *[256]int

Type Index is a pointer to an index table.

type Letter Uses

type Letter byte

A Letter represents a sequence letter.

func BytesToLetters Uses

func BytesToLetters(b []byte) []Letter

BytesToLetters converts a []byte to a []Letter.

func (Letter) Repeat Uses

func (l Letter) Repeat(count int) []Letter

Repeat a Letter count times.

type Letters Uses

type Letters []Letter

A Letters is a slice of Letter that satisfies the Slice interface.

func (Letters) Append Uses

func (l Letters) Append(src Slice) Slice

func (Letters) Cap Uses

func (l Letters) Cap() int

func (Letters) Copy Uses

func (l Letters) Copy(src Slice) int

func (Letters) Len Uses

func (l Letters) Len() int

func (Letters) Make Uses

func (l Letters) Make(len, cap int) Slice

func (Letters) Slice Uses

func (l Letters) Slice(start, end int) Slice

func (Letters) String Uses

func (l Letters) String() string

type Pairing Uses

type Pairing struct {
    // contains filtered or unexported fields
}

A Pairing provides a lookup table between a letter and its complement.

func MustPair Uses

func MustPair(p *Pairing, err error) *Pairing

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 Uses

func NewPairing(s, c string) (*Pairing, error)

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 Uses

func (p *Pairing) Complement(l Letter) (c Letter, ok bool)

Returns the complement of a letter and true if the complement is a valid letter otherwise unchanged and false.

func (*Pairing) ComplementTable Uses

func (p *Pairing) ComplementTable() []Letter

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 Uses

type QColumns [][]QLetter

A QColumns is a slice of []QLetter that satisfies the Slice interface.

func (QColumns) Append Uses

func (qc QColumns) Append(a Slice) Slice

func (QColumns) Cap Uses

func (qc QColumns) Cap() int

func (QColumns) Copy Uses

func (qc QColumns) Copy(a Slice) int

func (QColumns) Len Uses

func (qc QColumns) Len() int

func (QColumns) Make Uses

func (qc QColumns) Make(len, cap int) Slice

Make makes a QColumns with the cap and len for each column set to the number of rows of the receiver.

func (QColumns) MakeRows Uses

func (qc QColumns) MakeRows(len, cap int) Slice

MakeRows makes a column with len and cap for each column of the receiver and returns the receiver.

func (QColumns) Rows Uses

func (qc QColumns) Rows() int

Rows returns the number of positions in each column.

func (QColumns) Slice Uses

func (qc QColumns) Slice(start, end int) Slice

type QLetter Uses

type QLetter struct {
    L   Letter
    Q   Qphred
}

A QLetter represents a sequence letter with an associated quality score.

func (QLetter) Repeat Uses

func (ql QLetter) Repeat(count int) []QLetter

Repeat a QLetter count times.

func (QLetter) String Uses

func (ql QLetter) String() string

type QLetters Uses

type QLetters []QLetter

A QLetters is a slice of QLetter that satisfies the Slice interface.

func (QLetters) Append Uses

func (ql QLetters) Append(src Slice) Slice

func (QLetters) Cap Uses

func (ql QLetters) Cap() int

func (QLetters) Copy Uses

func (ql QLetters) Copy(src Slice) int

func (QLetters) Len Uses

func (ql QLetters) Len() int

func (QLetters) Make Uses

func (ql QLetters) Make(len, cap int) Slice

func (QLetters) Slice Uses

func (ql QLetters) Slice(start, end int) Slice

type Qphred Uses

type Qphred byte

A Qphred represents a Phred quality score.

func Ephred Uses

func Ephred(p float64) Qphred

Ephred returns the Qphred for a error probability p.

func (Qphred) Encode Uses

func (qp Qphred) Encode(e Encoding) (q byte)

Encode encodes the receiver's Phred score to a byte based on the specified encoding.

func (Qphred) ProbE Uses

func (qp Qphred) ProbE() float64

ProbE returns the error probability for the receiver's Phred value.

func (Qphred) Qsolexa Uses

func (qp Qphred) Qsolexa() Qsolexa

Qsolexa converts the quality value from Phred to Solexa. This conversion is lossy and should be avoided; the epsilon on the E value associated with a converted Qsolexa is bounded approximately by math.Pow(10, 1e-4-float64(qp)/10) over the range 0 < qp < 127.

func (Qphred) String Uses

func (qp Qphred) String() string

type Qscore Uses

type Qscore interface {
    ProbE() float64
    Encode(Encoding) byte
    String() string
}

A Qscore represents a quality score.

type Qsolexa Uses

type Qsolexa int8

A Qsolexa represents a Solexa quality score.

func Esolexa Uses

func Esolexa(p float64) Qsolexa

Esolexa returns the Qsolexa for a error probability p.

func (Qsolexa) Encode Uses

func (qs Qsolexa) Encode(e Encoding) (q byte)

Encode encodes the receiver's Solexa score to a byte based on the specified encoding.

func (Qsolexa) ProbE Uses

func (qs Qsolexa) ProbE() float64

ProbE returns the error probability for the receiver's Phred value.

func (Qsolexa) Qphred Uses

func (qs Qsolexa) Qphred() Qphred

Qphred converts the quality value from Solexa to Phred. This conversion is lossy and should be avoided; the epsilon on the E value associated with a converted Qphred is bounded approximately by math.Pow(10, 1e-4-float64(qs)/10) over the range 0 < qs < 127.

func (Qsolexa) String Uses

func (qs Qsolexa) String() string

type Slice Uses

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.

Package alphabet imports 7 packages (graph) and is imported by 128 packages. Updated 2018-05-15. Refresh now. Tools for package owners.