chain

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: 14 Imported by: 0

Documentation

Overview

Package chain declares the Chain struct that describes an alignment block and contains functions that operates on chain structs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllToAxt

func AllToAxt(ch []Chain, target map[string][]dna.Base, query map[string][]dna.Base) []axt.Axt

AllToAxt converts a slice of chain structs into a slice of axt structs, taking in the target and query faMaps.

func ChainToBed

func ChainToBed(ch Chain, useTarget bool) bed.Bed

ChainToBed converts a chain into a bed region equal to the target bases covered by the chain, or the query bases if useTarget is false.

func Equal

func Equal(a []Chain, b []Chain) bool

Equal returns true if the values in the chain slices are identical to each other.

func IsChainFile

func IsChainFile(filename string) bool

IsChainFile will check the filename suffix and determine if the file input is a chain.

func OverlapChainBed

func OverlapChainBed(alpha Chain, beta bed.Bed, checkTarget bool) bool

OverlapChainBed returns true if the provided chain and bed overlap in genomic coordinates. If check target is true, this calculation is done on the chain's target, and otherwise on the chain's query.

func Read

func Read(filename string) ([]Chain, HeaderComments)

Read processes an input file and returns a header stuct and a slice of chain alignments.

func ReadToChan

func ReadToChan(file *fileio.EasyReader, data chan<- Chain, wg *sync.WaitGroup)

ReadToChan processes a chain text file to a channel of chains.

func SortByCoordinates

func SortByCoordinates(align []Chain, useTarget bool)

SortByCoordinates will sort a slice of chain by genomic location. If useTarget is true then this sort will be based on the target coordinates, and will otherwise be the query coordinates.

func TPosToQPos

func TPosToQPos(c Chain, TPos int) (int, bool)

TPosToQPos converts a target position in a chain to the corresponding query position. The bool returns true if the returned TPos was found in a (Size) section of a Chain, and false otherwise, as in when the TPos fell in TBases.

func ToAxt

func ToAxt(ch Chain, target []dna.Base, query []dna.Base) axt.Axt

ToAxt converts a chain struct to an axt struct, taking in the target and query chromosome sequences.

func ToString

func ToString(ch Chain) string

ToString will convert a chain struct to a string.

func Write

func Write(filename string, chaining []Chain, comments HeaderComments)

Write will write a chain slice and any given comments to the top of the file.

func WriteChain

func WriteChain(file *fileio.EasyWriter, ch Chain)

WriteChain processes a chain struct and writes the data to a file.

func WriteHeaderComments

func WriteHeaderComments(file *fileio.EasyWriter, comments HeaderComments)

WriteHeaderComments will take the HeaderComment struct and write to file.

func WriteToFile

func WriteToFile(filename string, chaining <-chan Chain, comments HeaderComments, wg *sync.WaitGroup)

WriteToFile will process a chain channel and writes the data to a file. Once WriteToFile finishes ranging over the channel, it will call Done() on the waitGroup. WaitGroup must be set up beforehand.

func WriteToFileHandle

func WriteToFileHandle(file io.Writer, rec Chain)

WriteToFileHandle writes a chain record to an io.Writer

Types

type BaseStats

type BaseStats struct {
	Size   int
	TBases int
	QBases int
}

BaseStats is a cigar-like info for alignment block: First number is the length/size of bases, then number of target gaps and finally query gaps.

type Chain

type Chain struct {
	Score     int
	TName     string
	TSize     int
	TStrand   bool
	TStart    int
	TEnd      int
	QName     string
	QSize     int
	QStrand   bool
	QStart    int
	QEnd      int
	Alignment []BaseStats
	Id        int
}

Chain represents an alignment block based on the UCSC file format for chain

func AxtToChain

func AxtToChain(align *axt.Axt, tLen int, qLen int, id int) Chain

AxtToChain converts an Axt alignment into chain format. The lengths of the target and query are needed for the conversion and an id for the chain is also needed as input.

func NewChain

func NewChain(text string, reader *fileio.EasyReader) Chain

NewChain will process text into chain data fields. It will read the first line of the file and assign to header fields and use a reader to read and process the additional lines of the alignment.

func NextChain

func NextChain(reader *fileio.EasyReader) (Chain, bool)

NextChain will read lines from an EasyReader and return one chain record at a time and also a bool, which will be true once it has reached the end of the file and has nothing left to return.

func SwapBoth

func SwapBoth(ch Chain) Chain

SwapBoth swaps the target and query fields.

func (Chain) GetChrom

func (ch Chain) GetChrom() string

GetChrom returns the name of the target chromosome

func (Chain) GetChromEnd

func (ch Chain) GetChromEnd() int

GetChromEnd returns the ending position on the target chromosome

func (Chain) GetChromStart

func (ch Chain) GetChromStart() int

GetChromStart returns the starting position on the target chromosome

func (Chain) SwapBoth

func (ch Chain) SwapBoth() Chain

SwapBoth swaps the target and query and returns the chain after the swap

func (Chain) WriteToFileHandle

func (ch Chain) WriteToFileHandle(file io.Writer)

WriteToFileHandle writes the chain to the io.Writer This methods helps to implement the Interval and Lift interfaces.

type HeaderComments

type HeaderComments struct {
	HashTag []string
}

HeaderComments stores the comment lines at the beginning of chain alignments into a struct.

func GoReadToChan

func GoReadToChan(filename string) (<-chan Chain, HeaderComments)

GoReadToChan takes a chain filename and launches a go routine to read that file and place the alignments into the channel it returns along with header comments.

func ReadHeaderComments

func ReadHeaderComments(er *fileio.EasyReader) HeaderComments

ReadHeaderComments will process header comments that sometimes appear at the beginning of chain file and returns a struct.

type SeqChain

type SeqChain struct {
	Chains chan Chain
	TSeq   map[string][]dna.Base
	QSeq   map[string][]dna.Base
}

SeqChain is a data structure that wraps over a chain channel. The struct also includes target and query sequences implemented as a hash, mapping seqeuence names to []dna.Base.

func GoReadSeqChain

func GoReadSeqChain(filename string, target []fasta.Fasta, query []fasta.Fasta) SeqChain

GoReadSeqChain will wrap a chain file with target and query fasta sequences into the SeqChain struct.

Jump to

Keyboard shortcuts

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