alphabet

package
v0.0.0-...-7b6cf24 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2012 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	CaseSensitive = true
)

Variables

View Source
var (
	N        = "acgt"
	Npairing = [2]string{"acgtnxACGTNX-", "tgcanxTGCANX-"}
	R        = "acgu"
	Rpairing = [2]string{"acgunxACGUNX-", "ugcanxUGCANX-"}
	P        = "abcdefghijklmnpqrstvxyz*"
)
View Source
var (
	DNA     *Deoxyribonucleic
	RNA     *Ribonucleic
	Protein *Peptide
)

Functions

func Init

func Init() (err error)

Provide default Alphabets.

Types

type Alphabet

type Alphabet interface {
	IsValid(byte) bool
	AllValid([]byte) (bool, int)
	Len() int
	ValidLetters() []bool
	LetterIndex() []int
	String() string
}

Minimum requirements for an Alphabet.

type Complementable

type Complementable interface {
	Alphabet
	ComplementOf(byte) (byte, bool)
	ComplementTable() []byte
}

Nucleic alphabets are able to complement their values.

type Deoxyribonucleic

type Deoxyribonucleic Nucleic

Deoxyribonucleic is an alias to Nucleic to provide type restrictions.

func NewDeoxyribonucleic

func NewDeoxyribonucleic(letters string, pairs *Pairing, caseSensitive bool) (d *Deoxyribonucleic, err error)

Return a new Deoxyribonucleic alphabet.

type Generic

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

Single letter alphabet type.

func NewGeneric

func NewGeneric(letters string, caseSensitive bool) (a *Generic, err error)

Return a new alphabet. Index values for letters reflect order of the letters parameter if Generic is case sensitive, otherwise index values will reflect ASCII sort order. Letters must be within the ASCII range.

func (*Generic) AllValid

func (self *Generic) AllValid(n []byte) (valid bool, pos int)

Check that a slice of bytes conforms to the alphabet, returning false and the position of the first invalid byte if invalid and true and a negative int if valid.

Example
fmt.Println(DNA.AllValid([]byte("acgatcgatatagctatnagcatgc")))
Output:

false 17

func (*Generic) IndexOf

func (self *Generic) IndexOf(n byte) int

Return the index of a letter.

func (*Generic) IsCaseSensitive

func (self *Generic) IsCaseSensitive() bool

Return whether the alphabet is case sensitive.

func (*Generic) IsValid

func (self *Generic) IsValid(n byte) bool

Check that a byte conforms to the alphabet.

func (*Generic) Len

func (self *Generic) Len() int

Return the number of distinct valid letters in the alphabet.

func (*Generic) LetterIndex

func (self *Generic) LetterIndex() (i []int)

Return a copy of the internal []int specifying letter to index conversion.

func (*Generic) String

func (self *Generic) String() (s string)

Return a string indicating characters accepted as valid by the Validator.

func (*Generic) ValidLetters

func (self *Generic) ValidLetters() (v []bool)

Return a copy of the internal []bool indicating valid letters.

type Nucleic

type Nucleic struct {
	*Generic
	*Pairing
}

The Nucleic type incorporates a Generic alphabet with the capacity to return a complement.

func NewNucleic

func NewNucleic(letters string, pairs *Pairing, caseSensitive bool) (n *Nucleic, err error)

Create a generalised Nucleic 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. If invalid pairings are required, the Pairing should be provided after creating the Nucleic struct.

type Pairing

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

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

func NewPairing

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

Create a new Pairing from a pair of strings.

func (*Pairing) ComplementOf

func (self *Pairing) ComplementOf(l byte) (c byte, ok bool)

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

Example
var (
	c  byte
	ok bool
)

c, ok = DNA.ComplementOf('a')
fmt.Printf("%c %v\n", c, ok)
c, ok = DNA.ComplementOf('n')
fmt.Printf("%c %v\n", c, ok)
c, ok = RNA.ComplementOf('a')
fmt.Printf("%c %v\n", c, ok)
_, ok = RNA.ComplementOf('t')
fmt.Printf("%v\n", ok)
Output:

t true
n true
u true
false

func (*Pairing) ComplementTable

func (self *Pairing) ComplementTable() (t []byte)

Returns a complementation table based on the internal representation. Invalid pairs hold a value outside the ASCII range.

type Peptide

type Peptide struct {
	*Generic
}

Peptide wraps Generic to provide type restrictions.

func NewPeptide

func NewPeptide(letters string, caseSensitive bool) (p *Peptide, err error)

Return a new Peptide alphabet.

type Ribonucleic

type Ribonucleic Nucleic

Ribonucleic is an alias to Nucleic to provide type restrictions.

func NewRibonucleic

func NewRibonucleic(letters string, pairs *Pairing, caseSensitive bool) (r *Ribonucleic, err error)

Return a new Ribonucleic alphabet.

Jump to

Keyboard shortcuts

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