alphabet

package
v1.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2021 License: BSD-3-Clause Imports: 7 Imported by: 171

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

Examples

Constants

View Source
const (
	CaseSensitive = true
)

Variables

View Source
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

func LettersToBytes(l []Letter) []byte

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

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

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) Append

func (lc Columns) Append(a Slice) Slice

func (Columns) Cap

func (lc Columns) Cap() int

func (Columns) Copy

func (lc Columns) Copy(a Slice) int

func (Columns) Len

func (lc Columns) Len() int

func (Columns) Make

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

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

func (lc Columns) Rows() int

Rows returns the number of positions in each column.

func (Columns) Slice

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

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
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

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

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

type Index *[256]int

Type Index is a pointer to an index table.

type Letter

type Letter byte

A Letter represents a sequence letter.

func BytesToLetters

func BytesToLetters(b []byte) []Letter

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

func (Letter) Repeat

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

Repeat a Letter count times.

type Letters

type Letters []Letter

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

func (Letters) Append

func (l Letters) Append(src Slice) Slice

func (Letters) Cap

func (l Letters) Cap() int

func (Letters) Copy

func (l Letters) Copy(src Slice) int

func (Letters) Len

func (l Letters) Len() int

func (Letters) Make

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

func (Letters) Slice

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

func (Letters) String

func (l Letters) String() string

type Pairing

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

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

func MustPair

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

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

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

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

type QColumns [][]QLetter

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

func (QColumns) Append

func (qc QColumns) Append(a Slice) Slice

func (QColumns) Cap

func (qc QColumns) Cap() int

func (QColumns) Copy

func (qc QColumns) Copy(a Slice) int

func (QColumns) Len

func (qc QColumns) Len() int

func (QColumns) Make

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

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

func (qc QColumns) Rows() int

Rows returns the number of positions in each column.

func (QColumns) Slice

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

type QLetter

type QLetter struct {
	L Letter
	Q Qphred
}

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

func (QLetter) Repeat

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

Repeat a QLetter count times.

func (QLetter) String added in v1.0.2

func (ql QLetter) String() string

type QLetters

type QLetters []QLetter

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

func (QLetters) Append

func (ql QLetters) Append(src Slice) Slice

func (QLetters) Cap

func (ql QLetters) Cap() int

func (QLetters) Copy

func (ql QLetters) Copy(src Slice) int

func (QLetters) Len

func (ql QLetters) Len() int

func (QLetters) Make

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

func (QLetters) Slice

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

type Qphred

type Qphred byte

A Qphred represents a Phred quality score.

func Ephred

func Ephred(p float64) Qphred

Ephred returns the Qphred for a error probability p.

func (Qphred) Encode

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

func (qp Qphred) ProbE() float64

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

func (Qphred) Qsolexa

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

func (qp Qphred) String() string

type Qscore

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

A Qscore represents a quality score.

type Qsolexa

type Qsolexa int8

A Qsolexa represents a Solexa quality score.

func Esolexa

func Esolexa(p float64) Qsolexa

Esolexa returns the Qsolexa for a error probability p.

func (Qsolexa) Encode

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

func (qs Qsolexa) ProbE() float64

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

func (Qsolexa) Qphred

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

func (qs Qsolexa) String() string

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL