cigar

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: BSD-3-Clause Imports: 7 Imported by: 2

Documentation

Overview

Package cigar contains functions to manipulate cigar data in the SAM file format. More information on cigars can be found in http://samtools.github.io/hts-specs/SAMv1.pdf

Index

Constants

View Source
const (
	Match     byte = 'M'
	Insertion byte = 'I'
	Deletion  byte = 'D'
	N         byte = 'N'
	SoftClip  byte = 'S'
	HardClip  byte = 'H'
	Padded    byte = 'P'
	Equal     byte = '='
	Mismatch  byte = 'X'
	Unknown   byte = '*'
)

Defined const for byte cigar.

Variables

This section is empty.

Functions

func ByteCigarToString

func ByteCigarToString(cigar []ByteCigar) string

ByteCigarToString will process the cigar byte struct and parse and/or convert the data into a string.

func ByteCigarToUint32

func ByteCigarToUint32(cigar []ByteCigar) []uint32

ByteCigarToUint32 will convert a slice of []ByteCigar to a slice of []uint32.

func ByteMatrixTrace

func ByteMatrixTrace(a int64, b int64, c int64) (int64, byte)

ByteMatrixTrace will trace smith-waterman matrix alignment and return one of 3 cigar Op's. M: matches or mismatches, I: insertions, D: for deletions.

func ConsumesQuery

func ConsumesQuery(r rune) bool

ConsumesQuery returns true for input runes that match query consuming characters for Cigars.

func ConsumesReference

func ConsumesReference(r rune) bool

ConsumesReference returns true of the rune matches an operation character that is reference consuming for Cigars.

func IsValidCigar

func IsValidCigar(op byte) bool

IsValidCigar will perform a check to make sure op is a valid byte.

func MatchLength

func MatchLength(c []Cigar) int

MatchLength returns the number of bases in a Cigar slice that align to the reference.

func MatrixSetup

func MatrixSetup(size int) ([][]int64, [][]byte)

MatrixSetup will allocate memory for smith-waterman matrix to be used with byte cigar opertations and trace back.

func NumDeletions

func NumDeletions(input []Cigar) int

NumDeletions calculates the number of deletions relative to a reference genome for an input Cigar slice.

func NumInsertions

func NumInsertions(input []Cigar) int

NumInsertions calculates the number of inserted bases relative to a reference genome for an input Cigar slice.

func QueryLength

func QueryLength(c []Cigar) int

QueryLength calculates the length of the query read from a slice of Cigar structs.

func QueryRunLen

func QueryRunLen(c []ByteCigar) int

QueryLength calculates the length of the query read from a slice of Cigar structs.

func ReferenceLength

func ReferenceLength(c []Cigar) int

ReferenceLength calculates the number of reference positions that a Cigar slice spans.

func ReverseBytesCigar

func ReverseBytesCigar(alpha []ByteCigar)

ReverseBytesCigar cigar will reverse the order of a cigar slice. Typically performed after matrix traceback from a local alignment.

func ToString

func ToString(c []Cigar) string

ToString converts a slice of Cigar structs to a string for producing readable outputs for files or standard out.

Types

type ByteCigar

type ByteCigar struct {
	RunLen uint16
	Op     byte
}

ByteCigar struct encodes sequence comparison operations and includes run length info.

func AddCigarByte

func AddCigarByte(cigs []ByteCigar, newCig ByteCigar) []ByteCigar

AddCigarByte will add append a cigar byte to an existing slice. The function will perform a check on the tail of the slice and incurment the run length if the cigar Op values are the same.

func CatByteCigar

func CatByteCigar(cigs []ByteCigar, newCigs []ByteCigar) []ByteCigar

CatByteCigar will concatenate two cigar slices into one merged.

func ReadToBytesCigar

func ReadToBytesCigar(cigar []byte) []ByteCigar

ReadToBytesCigar will process a byte slice and define a small.

func Uint32ToByteCigar

func Uint32ToByteCigar(cigar []uint32) []ByteCigar

Uint32ToByteCigar will process a uint32 slice and decode each number into a byte cigar struct. CIGAR operation lengths are limited to 2^28-1 in the current sam/bam formats.

type Cigar

type Cigar struct {
	RunLength int
	Op        rune
}

Cigar contains information on the runLength, operation, and DNA sequence associated with a particular cigar character.

func AddCigar

func AddCigar(cigs []Cigar, newCig Cigar) []Cigar

AddCigar adds a cigar struct to the end of a slice, but is smart about checking to see if the addition is the same operation that is present at the end of the existing slice and just increasing the run length of that entry.

func CatCigar

func CatCigar(cigs []Cigar, newCigs []Cigar) []Cigar

CatCigar cats two cigars together, but is smart about checking to see if the last element of the first slice is the same operation as the first element of the second slice. In this case it will compress that struct into a single element with a longer run length.

func FromString

func FromString(input string) []Cigar

FromString parses an input string into a slice of Cigar structs.

Jump to

Keyboard shortcuts

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