Version: v0.1.17 Latest Latest

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

Go to latest
Published: Nov 18, 2021 License: MIT Imports: 2 Imported by: 0



Package sequtil provides functions for processing genetic sequences.

Data Type For Sequences

In this repository, sequences are represented as byte slices. This is meant to keep them familiar and predictable. This design favors having a buffet of functions for manipulating basic types, over having a dedicated sequence type with methods.

Mutating Sequences

Mutations can be made using basic slice operations.

// Substitution
seq[4] = 'G'

// Deletion of bases 10-12 (including 12)
copy(seq[10:], seq[13:])
seq = seq[:len(seq)-3]

// Insertion at position 4
insert := []byte{...}
seq = append(append(append([]byte{}, seq[:4]...), insert...), seq[4:]...)

The U Nucleotide

This package currently ignores the existence of uracil. Adding support for uracil means increasing the complexity of the API without adding new capabilities. The current solution is to substitute U's with T's before calling this package.

This may change in the future, keeping backward compatibility.



View Source
const (
	// AminoAcids holds the single-letter amino acid symbols.
	// These are the valid inputs to AminoName.


This section is empty.


func AminoName added in v0.1.10

func AminoName(aa byte) (string, string)

AminoName returns the 3-letter code and the full name of the amino acid with the given letter. Input may be uppercase or lowercase.

func DNAFrom2Bit

func DNAFrom2Bit(dst, src []byte) []byte

DNAFrom2Bit appends to dst the nucleotides represented in 2-bit in src and returns the new dst. Only outputs characters in "ACGT".

func DNATo2Bit

func DNATo2Bit(dst, src []byte) []byte

DNATo2Bit appends to dst the 2-bit representation of the DNA sequence in src, and returns the new dst. Characters not in "aAcCgGtT" will cause a panic.

func Iton

func Iton(num int) byte

Iton converts an int to a nucleotide character. 0:A 1:C 2:G 3:T. Other values return N.

func Ntoi

func Ntoi(nuc byte) int

Ntoi converts a nucleotide to an int. Aa:0 Cc:1 Gg:2 Tt:3. Other values return -1.

func ReverseComplement

func ReverseComplement(dst, src []byte) []byte

ReverseComplement appends to dst the reverse complement of src and returns the new dst. Characters not in "aAcCgGtTnN" will cause a panic.

func ReverseComplementString

func ReverseComplementString(s string) string

ReverseComplementString returns the reverse complement of s. Characters not in "aAcCgGtTnN" will cause a panic.

func Translate added in v0.1.10

func Translate(dst, src []byte) []byte

Translate translates the nucleotides in src to amino acids, appends the result to dst and returns the new slice. Nucleotides should be in "aAcCgGtT". Length of src should be a multiple of 3.

func TranslateReadingFrames added in v0.1.10

func TranslateReadingFrames(seq []byte) [3][]byte

TranslateReadingFrames returns the translation of the 3 reading frames of seq. Nucleotides should be in "aAcCgGtT". seq can be of any length.


This section is empty.

Jump to

Keyboard shortcuts

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