kmerindex

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

Documentation

Overview

Package kmerindex performs Kmer indexing package based on Bob Edgar and Gene Meyers' approach used in PALS.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrKTooLarge      = errors.New("kmerindex: k too large")
	ErrKTooSmall      = errors.New("kmerindex: k too small")
	ErrShortSeq       = errors.New("kmerindex: sequence to short for k")
	ErrBadAlphabet    = errors.New("kmerindex: alphabet size != 4")
	ErrBadKmer        = errors.New("kmerindex: kmer out of range")
	ErrBadKmerTextLen = errors.New("kmerindex: kmertext length != k")
	ErrBadKmerText    = errors.New("kmerindex: kmertext contains illegal character")
)
View Source
var (
	MinKmerLen = 4 // default minimum

	// MaxKmerLen is the maximum Kmer length that can be used.
	// It is 16 on 64 bit architectures and 14 on 32 bit architectures.
	MaxKmerLen = 16 - offset
)

Constraints on Kmer length.

View Source
var Debug = false // Set Debug to true to prevent recovering from panics in ForEachKmer f Eval function.

Functions

func Distance

func Distance(a, b map[Kmer]float64) (dist float64)

Return the Euclidean distance between two sequences measured by abolsolute kmer frequencies.

func Format

func Format(kmer Kmer, k int, alpha alphabet.Alphabet) (string, error)

Convert a Kmer into a string of bases

func GCof

func GCof(k int, kmer Kmer) float64

Return the GC fraction of a Kmer of len k

Types

type Eval

type Eval func(index *Index, j, kmer int)

errors should be handled through a panic which will be recovered by ForEachKmerOf

type Index

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

Kmer index type

func New

func New(k int, s *linear.Seq) (*Index, error)

Create a new Kmer Index with a word size k based on sequence

func (*Index) Build

func (ki *Index) Build()

Build the Kmer position table destructively replacing Kmer frequencies

func (*Index) Check

func (ki *Index) Check() (ok bool, found int)

Confirm that a Build() is correct. Returns boolean indicating this and the number of kmers indexed.

func (*Index) ComplementOf

func (ki *Index) ComplementOf(kmer Kmer) (c Kmer)

Reverse complement a Kmer. Complementation is performed according to letter index:

0, 1, 2, 3 = 3, 2, 1, 0

func (*Index) Finger

func (ki *Index) Finger() (f []Kmer)

Return a copy of the internal finger slice.

func (*Index) FingerAt

func (ki *Index) FingerAt(p int) int

Returns the value of the finger slice at p. This signifies the absolute kmer frequency of the Kmer(p) if called before Build() and points to the relevant position lookup if called after.

func (*Index) ForEachKmerOf

func (ki *Index) ForEachKmerOf(s *linear.Seq, start, end int, f Eval) (err error)

Applies the f Eval func to all kmers in s from start to end. Returns any panic raised by f as an error.

func (*Index) Format

func (ki *Index) Format(kmer Kmer) string

Convert a Kmer into a string of bases

func (*Index) GCof

func (ki *Index) GCof(kmer Kmer) float64

Return the GC fraction of a Kmer

func (*Index) K

func (ki *Index) K() int

Return the Kmer length of the Index.

func (*Index) KmerFrequencies

func (ki *Index) KmerFrequencies() (map[Kmer]int, bool)

Return a map containing absolute Kmer frequencies and true if called before Build(). If called after Build returns a nil map and false.

func (*Index) KmerIndex

func (ki *Index) KmerIndex() (map[Kmer][]int, bool)

Returns a Kmer-keyed map containing slices of kmer positions and true if called after Build, otherwise nil and false.

func (*Index) KmerOf

func (ki *Index) KmerOf(kmertext string) (kmer Kmer, err error)

Convert a string of bases into a Kmer, returns an error if string length does not match word length

func (*Index) KmerPositions

func (ki *Index) KmerPositions(kmer Kmer) (positions []int, err error)

Return an array of positions for the Kmer kmer

func (*Index) KmerPositionsString

func (ki *Index) KmerPositionsString(kmertext string) (positions []int, err error)

Return an array of positions for the Kmer string kmertext

func (*Index) NormalisedKmerFrequencies

func (ki *Index) NormalisedKmerFrequencies() (map[Kmer]float64, bool)

Return a map containing relative Kmer frequencies and true if called before Build(). If called after Build returns a nil map and false.

func (*Index) Pos

func (ki *Index) Pos() (p []int)

Return a copy of the internal pos slice.

func (*Index) PosAt

func (ki *Index) PosAt(p int) int

Returns the value of the pos slice at p. This signifies the position of the pth kmer if called after Build(). Not valid before Build() - will panic.

func (*Index) Seq

func (ki *Index) Seq() *linear.Seq

Returns a pointer to the indexed seq.Seq.

func (*Index) StringKmerIndex

func (ki *Index) StringKmerIndex() (map[string][]int, bool)

Returns a string-keyed map containing slices of kmer positions and true if called after Build, otherwise nil and false.

type Kmer

type Kmer uint32 // Sensible size for word type uint64 will double the size of the index (already large for high k)

2-bit per base packed word

func ComplementOf

func ComplementOf(k int, kmer Kmer) (c Kmer)

Reverse complement a Kmer of len k. Complementation is performed according to letter index:

0, 1, 2, 3 = 3, 2, 1, 0

func KmerOf

func KmerOf(k int, lookUp alphabet.Index, kmertext string) (kmer Kmer, err error)

Convert a string of bases into a len k Kmer, returns an error if string length does not match k. lookUp is an index lookup table as returned by alphabet.Alphabet.LetterIndex().

Jump to

Keyboard shortcuts

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