Skip to content
Sonia Keys edited this page Dec 19, 2015 · 25 revisions

Bio

A bioinformatics package in Go.

Routines here were initially inspired by lessons from online bioinformatics courses and exercises. The current purpose of the code is still simply for the author to explore bioinformatics in Go. Yet, the collection of implemented algorithms is growing and so the purpose of this document is to provide organizing documentation beyond the godoc comments in the source.

Outside this library, the author has other repositories useful for bioinformatics.

Status of this library.

It's a mess, and very incomplete. Many functions retain quirks of their originating programming assignments. Some functions have duplicate implementations, generally originating from assignments in different courses that cover the same topic. It is a goal though, to move code away from the specific requirements of course assignments and toward more consistent, more general functionality using more standard terminology. So, someday it should have some direction towards some new goals. It's not really time yet.

Some parts of the library are about efficiency and comparing the efficiency of different algorithms. To continue in that direction, more routines should have time or space complexity documented, more should be benchmarked to support the documented claims.

Source organization

One big package! Perhaps it can be split along some logical lines in the future but for now everything is in package bio. Well except for the package bio/logo, mentioned later.

Theme

The general theme is to use very simple types with the goal of performance.

Sequence types

Type Seq []byte is the most general sequence type and a number of functions will operate on this type. Also some functions simply treat []byte or string as sequences. These functions will generally implement some string algorithm that is not specific to DNA or peptides. These functions treat each byte as a separate symbol and generally perform case sensitive symbol comparisons.

A number of types are defined as named types for byte slices and are intended to hold data restricted to some symbol set. These are named with some indication of the expected symbol set and are documented with a list or description of the symbols. Methods on the type will assume the symbol set. For example the type DNA8 holds the eight symbols [ACTGactg], the type AA20 holds the twenty IUPAC proteinogenic amino acid symbols.

Bit twiddling and base order

This library usually works with bases in the order ACTG and ACUG. In this order, bits 1 and 2 of the ASCII representations are 00, 01, 10, and 11, allowing indexes 0, 1, 2, 3 to be directly obtained from the ASCII. Yes, T and U are the same, 10. In some cases this bit pattern is exploited for efficiency, in other cases this base order is maintained just for consistency within the library.

Functionality

Go doc's alphabetical presentation is a little messy for this package. Here are some topic groupings. Only the tersest descriptions are given here; see the go doc for full documentation.

Basic sequence operations

Sequence types defined simply as []byte are Seq, DNA, DNA8, RNA, RNA8, AA, AA20. These types have no constructor functions; simply use a type conversion from []byte or string. They all have stringers which are simple string type conversions. Also a number of functions work directly on string values.

As a term, a kmer is a sequence of a certain number (k) symbols. There is no separate type defined for a single kmer value but the list type Kmers []DNA8 carries the assumption that all list elements are the same length. In contrast elements of DNA8List []DNA8 may or may not be all the same length, depending on context.

Errors and panics

It's kinda panicky currently. For performance, you might want to say in a lot of cases that arguments have to be as expected or else it's a programmer error and it's fair to panic. It's not very nice though and probably lots of places where panics can currently happen should have a little added code to return errors if arguments are invalid.

IO

  • ReadFASTA
  • ReadFASTAFile,
  • FASTAReader.ReadSeq
  • FASTASeq.ID, FASTASeq.Desc

Simple transformations

  • ASCII case conversion: Seq.ToLower, Seq.ToUpper,
  • Delete sub-sequences: Splice(string)
  • DNA to RNA: DNA.Transcribe, DNA8.Transcribe
  • Reverse, Complement: Seq.Reverse, DNA8Complement, DNA8.ReverseComplement
  • With IUPAC ambiguity: DNAComplement, DNA.ReverseComplement
  • Constants and variables: CodonTable, DNAStart, RNAStart, AAStop, GapSymbol
  • Translation: CodonIndex, TranslateCodon, IsStartCodon, DNA8.Translate, DNA8.TranslateORF

Simple tests and statistics

  • Data validation: Kmers.Uniform, DistanceMatrix.Validate, DistanceMatrix.Additive
  • Hamming distance: Seq.Hamming, DNA8.Hamming
  • Symbol counts: Seq.Freq, Seq.FreqMap, DNA.BaseFreq, DNA8.BaseFreq, RNA8.BaseFreq, DNA.GCContent, DNA8.GCContent
  • GCSkew, TiTvRatio(DNA), TiTvRatio(DNA8)
  • Determine leader board cut index: Cut(sort.Interface)
  • Float64s: NearestFloat64, ParseFloats, Quantize

Motif logos

In a separate packge bio/logo for namespace reasons, generates motif logos in the SVG format.

  • Motif generates the SVG
  • A raft of configuration functions control Motif.

Combinatorial

  • Enumerate all kmers in a sequence: KmerComposition(string)
  • Enumerate all variants of a single kmer, DNA8.HammingVariants
  • Enumerate all possible kmers for a given k: DNA8.Inc
  • Compute all possible for a given k: NumSubPepLinear, NumSubPepCyclic

Sequence searching

  • Linear search: Seq.AllIndex, Seq.AllCount, Seq.HammingAllIndex
  • Count only: Seq.AllCount
  • Knuth Morris Pratt: KMP.Index, KMP.AllIndex
  • Burrows-Wheeler: BWT.AllIndex
  • Search reading frames: DNA8.AAFindAllIndex, DNA8.AAFindAllIndex3RC
  • Find most frequent: ModalKmers(string), DNA8.ModalHammingKmers, DNA8.ModalHammingKmersRC
  • Find clustered repeats: KmerClumps(string)
  • Find best match: Seq.KmersNearestMotif, DNA8.KmersNearestMotif
  • Distance of best match DNA8.MotifHamming, DNA8List.MotifHamming
  • Replication origin: MinGCSkew
  • Find complement-palindromes: DNA8.PalFindAllIndex
  • Find motifs common to each sequence in a list: DNA8List.HammingMotifs, DNA8List.MedianMotifs, DNA8List.GreedyMotifSearch, DNA8List.RandomMotifSearch, DNA8List.GibbsMotifSearch

Profile and consensus

A CountProfile object holds integer counts, a FracProfile normalizes these to float64 values <= 1.0.

  • DNAConsensus([]DNA) computes consensus and "match" score directly from sequences without constructing profile
  • Kmers.Consensus as above, but for DNA8
  • Kmers.ConsensusHamming computes cumulative hamming distance ("mismatch") directly from kmers without constructing profile
  • Kmers.Entropy computes Entropy -- "mismatch" sense like hamming but better
  • Kmers.EntropyContributions individual entropy terms
  • Kmers.CountProfile, CountProfile.Add construct a profile
  • CountProfile.Consensus returns DNA consensus and "match" score
  • Kmers.FracProfile, Kmers.LaplaceProfile construct
  • FracProfile.Entropy, FracProfile.CrossEntropy, FracProfile.RelativeEntropy
  • FracProfile.KmerProbability compute probability of a given kmer
  • FracProfile.MostProbKmer, FracProfile.MostProbKmers` construct the most probable kmers

Sequence alignment

  • Pairwise: AlignGlobal, AlignLocal, AlignPair, AlignGlobalAffine, AlignGlobalLS(),
  • Substitution Matrixes: PAM250, Blosum62
  • Scores: LinearGap, ConstantGap

Sequence assembly

  • DeBruijn stuff: Adjacency, Overlap, DeBruijn, DeBruijnK
  • AlignLong([]string),

Sequence mapping

  • Restriction sites: SolvePartialDigest

Protein mass spectrometry

Associated types are AAMass, MassSpec Mass lookup: AA20MonoisotopicMass, AA20MonoisotopicMassTable Compute mass: AA20.Weight Other constants, values: AA20Alphabet, AA20Lightest, AA20Heaviest, ProtonMass, WaterMassAverage, WaterMassMonoisotopic Convert to float64 sequence: AA20.MonoisotopicMass

  • Synthesize spectrum for sequence: AAMass.LinearSpec, AAMass.CyclicSpec, AA20.PrefixSpectrum
  • Compare spectra: MassSpec.Overlap
  • Sequence cyclic peptides from spectrum: MassSpec.SeqCyclic20

Reflecting the introductory course material, algorithms are first developed with the simplification of integer masses. Associated types are AAInt, AA18Int, IntSpec, MassCounts, AAInt

  • Mass lookup: AA20IntegerMass, AA20IntegerMassTable
  • Identify amino acid: AA20NearestMass
  • Convert to an integer sequence: AA20.Int
  • Histogram: IntSpec.Counts
  • Compare spectra: IntSpec.Equal
  • Compare to spectrum: AAInt.CyclicCommonCounts, AAInt.LinearCommonCounts
  • Synthesize spectrum for sequence: AAInt.LinearSpec, AAInt.CyclicSpec
  • Sequence cyclic peptides from spectrum: IntSpec.SeqCyclicTheo, IntSpec.SeqCyclicExp, IntSpec.SeqCyclic18Exp
  • Convolution: IntSpec.Convolve, ConvolveSpectra

Phylogenetics

  • Distance matrix: DNA8List.DistanceMatrix, StrList.DistanceMatrix, DNA8List.KCompositionDistMat, StrList.KCompositionDistMat
  • Distance metrics: DNA8.PDistance, Seq.PDistance, Str.PDistance, Str.KCompositionDist
  • Max parsimony: DNA8MaxParsimonyRooted, DNA8MaxParsimonyUnooted
  • Trees: ParseNewick, PhyloList.RootedTree, PhyloList.PathLen, PhyloList.Distance, PhyloRootedTree.Newick
  • CharacterTables: PhyloRootedTree.CharacterTable,StrKmers.CharacterTable