bed

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

Documentation

Overview

Package bed provides functions for reading, writing, and manipulating Browser Extensible Data (BED) format files. More information on the BED file format can be found at https://genome.ucsc.edu/FAQ/FAQformat.html#format1

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Adjacent

func Adjacent(alpha Bed, beta Bed) bool

Adjacent returns true if two input Bed entries are adjacent (one immediately follows the other).

func AllAreEqual

func AllAreEqual(a []Bed, b []Bed) bool

AllAreEqual returns true if two input slices of Beds contain Bed entries that all return true for Equal.

func Compare

func Compare(a Bed, b Bed) int

Compare returns zero for equal beds and otherwise returns the ordering of the two Bed entries. Used for SortByCoord.

func CompareChromEnd

func CompareChromEnd(a Bed, b Bed) int

CompareChromEnd returns zero for beds with an equal ChromEnd position and otherwise returns the ordering of the two Bed entries by chromEnd.

func CompareChromEndByChrom

func CompareChromEndByChrom(a Bed, b Bed) int

CompareChromEndByChrom compares beds by chromosome and then by chromEnd, but not by chromStart.

func CompareSize

func CompareSize(a Bed, b Bed) int

CompareSize returns zero for beds with an equal length (ChromEnd - ChromStart) and otherwise returns the ordering of the two Bed structs.

func Equal

func Equal(a Bed, b Bed) bool

Equal returns true if two input Bed entries have the same Chrom, ChromStart, and ChromEnd. False otherwise.

func GoReadToChan

func GoReadToChan(filename string) <-chan Bed

GoReadToChan reads Bed entries from an input filename to a <-chan Bed.

func IsSelfOverlapping

func IsSelfOverlapping(b []Bed, verbose int) bool

IsSelfOverlapping returns true if any elements in a Bed slice overlap another element in the same slice. False otherwise. b must be presorted with SortByCoord. Verbose > 0 reveals debug prints.

func MinimumDistance

func MinimumDistance(a Bed, b Bed) (n int, err error)

MinimumDistance compares beds by chromStart and chromEnd and returns the minimum distance between the two beds. return options; -1 (different chromosomes, no distance calculated), 0 (overlap, minimum distance is 0), >=0 is the minimum distance.

func Overlap

func Overlap(alpha Bed, beta Bed) bool

Overlap returns true if two input Bed entries have an overlap of any kind.

func OverlapCount

func OverlapCount(a []Bed, b []Bed) int

OverlapCount returns the number of elements from list one that have any overlap with list two. Answers range from 0 to len(a). Input bed slices must be presorted with SortByCoord.

func OverlapLength

func OverlapLength(a Bed, b Bed) int

OverlapLength returns the number of bases for which two Bed entries overlap.

func OverlapLengthSum

func OverlapLengthSum(a []Bed, b []Bed) int

OverlapLengthSum calculates the total number of overlapping bases between two sets of bed elements. Input bed slices must be presorted with SortByCoord.

func ReadToChan

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

ReadToChan reads from a fileio.EasyReader to send Bed structs to a chan<- Bed.

func SortByChromEndByChrom

func SortByChromEndByChrom(bedFile []Bed)

SortByChromEndByChrom sorts in place a slice of Bed structs by their chrom, and then by chromEnd, but not by chromStart.

func SortByCoord

func SortByCoord(bedFile []Bed)

SortByCoord sorts in place a slice of Bed structs by their genomic position.

func SortBySize

func SortBySize(bedFile []Bed)

SortBySize sorts in place a slice of Bed structs by their size from low to high.

func ToString

func ToString(bunk Bed, fields int) string

ToString converts a Bed struct into a BED file format string. Useful for writing to files or printing.

func TotalSize

func TotalSize(b []Bed) int

TotalSize gives back to total region covered by bed entry.

func TrimSlice added in v1.0.1

func TrimSlice(b []Bed, trimLeft int, trimRight int)

TrimSlice trims each element in a slice of bed entries by an input left and right amount.

func Write

func Write(filename string, records []Bed)

Write writes a slice of Bed structs to a specified filename.

func WriteBed

func WriteBed(file io.Writer, input Bed)

WriteBed writes an input Bed struct to an io.Writer.

func WriteToFileHandle

func WriteToFileHandle(file io.Writer, rec Bed)

WriteToFileHandle writes an input Bed struct to an io.Writer.

Types

type Bed

type Bed struct {
	Chrom             string
	ChromStart        int
	ChromEnd          int
	Name              string
	Score             int
	Strand            Strand
	FieldsInitialized int      //number of fields that are initialized, used for smart writing.
	Annotation        []string //long form for extra fields
}

Bed stores information about genomic regions, including their location, name, score, strand, and other annotations.

func FillSpaceHiddenValue

func FillSpaceHiddenValue(records []Bed, genome map[string]chromInfo.ChromInfo) []Bed

FillSpaceHiddenValue accepts a slice of Bed structs and a reference genome as a map[string]chromInfo.ChromInfo and returns a slice of Bed structs that assigns each genomic position to the nearest feature in 3D space from the input bed, using the input bed scores to represent "hidden values", or the distance from that position to its nearest TSS in 3D space. bed that is passed here from Fill3dSpace has gene positions and bedpe positions already filled in

func FillSpaceNoHiddenValue

func FillSpaceNoHiddenValue(records []Bed, genome map[string]chromInfo.ChromInfo) []Bed

FillSpaceNoHiddenValue accepts a bed of single point tss positions and reference genome as a map[string]chromInfo.ChromInfo and returns a bed that assigns each genomic position to the nearest feature in the input bed using the Name field in the input bed. Absolute start positions of the original input bed entries are stored in the Score field of the output bed entries.

func InvertRegions

func InvertRegions(beds []Bed, chromLen int) []Bed

InvertRegions uses a set of bed regions, to return bed regions that are inverted, negated, and/or not covered by the given input. Bed entries should be sorted by chromosome position and cannot contain overlaps.

func MergeBeds

func MergeBeds(bedFile []Bed) []Bed

MergeBeds takes a slice of beds and returns a slice of beds where overlapping entries have been merged into a single entry. The input slice of beds can no longer be used as its memory will have been reused.

func MergeBedsIfNamesMatch added in v1.0.1

func MergeBedsIfNamesMatch(bedFile []Bed) []Bed

MergeBedsIfNamesMatch will take a bed struct and return a merged struct such that any records which are of overlapping coordinates and names are identical will be merged. Records with matching names must be adjacent

func MergeBedsKeepNamesAndAnnotations added in v1.0.1

func MergeBedsKeepNamesAndAnnotations(bedFile []Bed) []Bed

MergeBedsKeepNamesAndAnnotations will merge beds if overlapping and keep an index in the form of a comma separated list of the name fields of merged beds, and add the annotation fields together into a single field ([]string)

func MergeHighMem

func MergeHighMem(records []Bed, mergeAdjacent bool, keepAllNames bool) []Bed

MergeHighMem retains input Bed entries that are non-overlapping with other input bed entries and merges together overlapping bed entries. Merged bed entries will retain the maximum score in the output.

func MultiFaUngappedRegions added in v1.0.1

func MultiFaUngappedRegions(records []fasta.Fasta, chromName string, seqName string) []Bed

MultiFaUngappedRegions takes in a MultiFa format alignment and returns a bed file of all ungapped regions for a user-specified seqName. The resulting sequence is in target coordinates, and the bed chrom field can be specified by the argument 'chromName'.

func NextBed

func NextBed(reader *fileio.EasyReader) (Bed, bool)

NextBed returns a Bed struct from an input fileio.EasyReader. Returns a bool that is true when the reader is done.

func Read

func Read(filename string) []Bed

Read returns a slice of Bed structs from an input filename.

func ToMidpoint

func ToMidpoint(b Bed) Bed

ToMidpoint edits an input bed struct so that its coordinates correspond to its midpoint.

func ToTss

func ToTss(b Bed) Bed

ToTss edits an input bed struct so that its coordinates corresponds to the start position, strand-sensitive.

func Trim

func Trim(b Bed, trimLeft int, trimRight int) Bed

Trim shortens bed entries on the left and right side by an input-specified number of bases. These values must not exceed the length of the bed entry and must be non-negative.

func UngappedRegionsAllFromFa

func UngappedRegionsAllFromFa(records []fasta.Fasta) []Bed

UngappedRegionsAllFromFa finds ungapped regions or bases that do not contain Ns. Returns a slice of bed records.

func UngappedRegionsFromFa

func UngappedRegionsFromFa(fa fasta.Fasta) []Bed

UngappedRegionsFromFa finds all regions outside gaps in a given fasta record.

func (Bed) GetChrom

func (b Bed) GetChrom() string

GetChrom returns the chrom of the bed struct.

func (Bed) GetChromEnd

func (b Bed) GetChromEnd() int

GetChromEnd returns the end coordinates of the bed struct.

func (Bed) GetChromStart

func (b Bed) GetChromStart() int

GetChromStart returns the starting coordinates of the bed struct.

func (Bed) String

func (b Bed) String() string

String converts a Bed struct to a string so it will be automatically formatted when printing with the fmt package.

func (Bed) UpdateCoord

func (b Bed) UpdateCoord(c string, start int, end int) interface{}

UpdateCoord will return a copy of the bed with the modified coordinates.

func (Bed) WriteToFileHandle

func (b Bed) WriteToFileHandle(file io.Writer)

WriteToFileHandle will write a bed struct to the io.Writer.

type Strand

type Strand byte

Strand stores strand state, which can be positive, negative, or none.

const (
	Positive Strand = '+'
	Negative Strand = '-'
	None     Strand = '.'
)

func StringToStrand

func StringToStrand(s string) Strand

StringToStrand parses a bed.Strand struct from an input string.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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