rangeset

package
v0.0.0-...-19f838f Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2018 License: MIT, MIT Imports: 2 Imported by: 0

README

GoDoc

Documentation

Overview

Package rangeset has set operations on ranges: Union, Intersect and Difference

Example
package main

import (
	"fmt"

	"github.com/brentp/go-athenaeum/rangeset"
)

func main() {

	chromLength := 1000
	genes, _ := rangeset.New(0, chromLength)
	genes.SetRange(100, 200)
	genes.SetRange(250, 350)
	genes.SetRange(900, 950)

	regions, _ := rangeset.New(0, chromLength)
	regions.SetRange(150, 250)
	regions.SetRange(500, 925)

	fmt.Println("genes          :", genes.Ranges())
	fmt.Println("regions        :", regions.Ranges())
	fmt.Println("genes ∩ regions:", rangeset.Intersection(genes, regions).Ranges())
	fmt.Println("genes ∪ regions:", rangeset.Union(genes, regions).Ranges())
	fmt.Println("genes - regions:", rangeset.Difference(genes, regions).Ranges())
	fmt.Println("regions - genes:", rangeset.Difference(regions, genes).Ranges())

}
Output:

genes          : [Range(100-200) Range(250-350) Range(900-950)]
regions        : [Range(150-250) Range(500-925)]
genes ∩ regions: [Range(150-200) Range(900-925)]
genes ∪ regions: [Range(100-350) Range(500-950)]
genes - regions: [Range(100-150) Range(250-350) Range(925-950)]
regions - genes: [Range(200-250) Range(500-900)]

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Range

type Range struct {
	Start, End int
}

Range is 0-based half-open.

func (Range) String

func (i Range) String() string

type RangeSet

type RangeSet struct {
	// contains filtered or unexported fields
}

RangeSet acts like a bitvector where the interval values for true can be extracted.

func Difference

func Difference(a, b *RangeSet) *RangeSet

Difference returns a new RangeSet with regions in a that are absent from b.

func Intersection

func Intersection(a, b *RangeSet) *RangeSet

Intersection returns a new RangeSet with intersecting regions from a and b.

func New

func New(start, end int) (*RangeSet, error)

New returns a new RangeSet

func Union

func Union(a, b *RangeSet) *RangeSet

Union returns a new RangeSet with the union of regions from a and b.

func (*RangeSet) ClearRange

func (b *RangeSet) ClearRange(start, end int)

ClearRange sets the values between start and end to false.

func (*RangeSet) Ranges

func (b *RangeSet) Ranges() []Range

Ranges returns the intervals that are set to true in the RangeSet.

func (*RangeSet) SetRange

func (b *RangeSet) SetRange(start, end int)

SetRange sets the values between start and end to true.

Jump to

Keyboard shortcuts

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