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 ¶
- func Adjacent(alpha Bed, beta Bed) bool
- func AllAreEqual(a []Bed, b []Bed) bool
- func Compare(a Bed, b Bed) int
- func CompareChromEnd(a Bed, b Bed) int
- func CompareChromEndByChrom(a Bed, b Bed) int
- func CompareSize(a Bed, b Bed) int
- func Equal(a Bed, b Bed) bool
- func GoReadToChan(filename string) <-chan Bed
- func IsSelfOverlapping(b []Bed, verbose int) bool
- func MinimumDistance(a Bed, b Bed) (n int, err error)
- func Overlap(alpha Bed, beta Bed) bool
- func OverlapCount(a []Bed, b []Bed) int
- func OverlapLength(a Bed, b Bed) int
- func OverlapLengthSum(a []Bed, b []Bed) int
- func ReadToChan(file *fileio.EasyReader, data chan<- Bed, wg *sync.WaitGroup)
- func SortByChromEndByChrom(bedFile []Bed)
- func SortByCoord(bedFile []Bed)
- func SortBySize(bedFile []Bed)
- func ToString(bunk Bed, fields int) string
- func TotalSize(b []Bed) int
- func TrimSlice(b []Bed, trimLeft int, trimRight int)
- func Write(filename string, records []Bed)
- func WriteBed(file io.Writer, input Bed)
- func WriteToFileHandle(file io.Writer, rec Bed)
- type Bed
- func FillSpaceHiddenValue(records []Bed, genome map[string]chromInfo.ChromInfo) []Bed
- func FillSpaceNoHiddenValue(records []Bed, genome map[string]chromInfo.ChromInfo) []Bed
- func InvertRegions(beds []Bed, chromLen int) []Bed
- func MergeBeds(bedFile []Bed) []Bed
- func MergeBedsIfNamesMatch(bedFile []Bed) []Bed
- func MergeBedsKeepNamesAndAnnotations(bedFile []Bed) []Bed
- func MergeHighMem(records []Bed, mergeAdjacent bool, keepAllNames bool) []Bed
- func MultiFaUngappedRegions(records []fasta.Fasta, chromName string, seqName string) []Bed
- func NextBed(reader *fileio.EasyReader) (Bed, bool)
- func Read(filename string) []Bed
- func ToMidpoint(b Bed) Bed
- func ToTss(b Bed) Bed
- func Trim(b Bed, trimLeft int, trimRight int) Bed
- func UngappedRegionsAllFromFa(records []fasta.Fasta) []Bed
- func UngappedRegionsFromFa(fa fasta.Fasta) []Bed
- type Strand
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Adjacent ¶
Adjacent returns true if two input Bed entries are adjacent (one immediately follows the other).
func AllAreEqual ¶
AllAreEqual returns true if two input slices of Beds contain Bed entries that all return true for Equal.
func Compare ¶
Compare returns zero for equal beds and otherwise returns the ordering of the two Bed entries. Used for SortByCoord.
func CompareChromEnd ¶
CompareChromEnd returns zero for beds with an equal ChromEnd position and otherwise returns the ordering of the two Bed entries by chromEnd.
func CompareChromEndByChrom ¶
CompareChromEndByChrom compares beds by chromosome and then by chromEnd, but not by chromStart.
func CompareSize ¶
CompareSize returns zero for beds with an equal length (ChromEnd - ChromStart) and otherwise returns the ordering of the two Bed structs.
func Equal ¶
Equal returns true if two input Bed entries have the same Chrom, ChromStart, and ChromEnd. False otherwise.
func GoReadToChan ¶
GoReadToChan reads Bed entries from an input filename to a <-chan Bed.
func IsSelfOverlapping ¶
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 ¶
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 OverlapCount ¶
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 ¶
OverlapLength returns the number of bases for which two Bed entries overlap.
func OverlapLengthSum ¶
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 ¶
ToString converts a Bed struct into a BED file format string. Useful for writing to files or printing.
func TrimSlice ¶ added in v1.0.1
TrimSlice trims each element in a slice of bed entries by an input left and right amount.
func WriteToFileHandle ¶
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 ¶
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 ¶
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 ¶
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 ¶
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
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
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 ¶
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
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 ToMidpoint ¶
ToMidpoint edits an input bed struct so that its coordinates correspond to its midpoint.
func ToTss ¶
ToTss edits an input bed struct so that its coordinates corresponds to the start position, strand-sensitive.
func Trim ¶
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 ¶
UngappedRegionsAllFromFa finds ungapped regions or bases that do not contain Ns. Returns a slice of bed records.
func UngappedRegionsFromFa ¶
UngappedRegionsFromFa finds all regions outside gaps in a given fasta record.
func (Bed) GetChromEnd ¶
GetChromEnd returns the end coordinates of the bed struct.
func (Bed) GetChromStart ¶
GetChromStart returns the starting coordinates of the bed struct.
func (Bed) String ¶
String converts a Bed struct to a string so it will be automatically formatted when printing with the fmt package.
func (Bed) UpdateCoord ¶
UpdateCoord will return a copy of the bed with the modified coordinates.
func (Bed) WriteToFileHandle ¶
WriteToFileHandle will write a bed struct to the io.Writer.