Documentation ¶
Overview ¶
Package to find intersections between intervals or sort intervals.
Index ¶
- Constants
- Variables
- type Interval
- func (self *Interval) Chromosome() string
- func (self *Interval) Contain(i *Interval, slop int, r chan<- *Interval)
- func (self *Interval) End() int
- func (self *Interval) Flatten(r chan *Interval, tolerance int) (flat []*Interval, rich [][]*Interval)
- func (self *Interval) GobDecode(b []byte) (err error)
- func (self *Interval) GobEncode() (b []byte, err error)
- func (self *Interval) Insert(i *Interval) (root *Interval)
- func (self *Interval) Intersect(i *Interval, overlap int, r chan<- *Interval)
- func (self *Interval) Left() *Interval
- func (self *Interval) LeftMost() (n *Interval)
- func (self *Interval) Line() int
- func (self *Interval) Parent() *Interval
- func (self *Interval) Range() (int, int)
- func (self *Interval) Remove() (root, removed *Interval)
- func (self *Interval) Right() *Interval
- func (self *Interval) RightMost() (n *Interval)
- func (self *Interval) ScanLeft() (n *Interval)
- func (self *Interval) ScanRight() (n *Interval)
- func (self *Interval) Start() int
- func (self *Interval) String() string
- func (self *Interval) Traverse(r chan<- *Interval)
- func (self *Interval) Within(i *Interval, slop int, r chan<- *Interval)
- type Tree
- func (self Tree) AdjustRange(chromosome string)
- func (self Tree) Contain(i *Interval, slop int) (result chan *Interval)
- func (self Tree) FastRemove(i *Interval) (removed *Interval)
- func (self Tree) Flatten(i *Interval, overlap, tolerance int) (flat []*Interval, rich [][]*Interval)
- func (self Tree) FlattenContaining(i *Interval, slop, tolerance int) (flat []*Interval, rich [][]*Interval)
- func (self Tree) FlattenWithin(i *Interval, slop, tolerance int) (flat []*Interval, rich [][]*Interval)
- func (self Tree) Insert(i *Interval)
- func (self Tree) Intersect(i *Interval, overlap int) (result chan *Interval)
- func (self Tree) Merge(i *Interval, overlap int) (inserted, replaced []*Interval)
- func (self Tree) Range(chromosome string) (min, max int)
- func (self Tree) Remove(i *Interval) (removed *Interval)
- func (self Tree) Traverse(chromosome string) (result chan *Interval)
- func (self Tree) TraverseAll() (result chan *Interval)
- func (self Tree) Within(i *Interval, slop int) (result chan *Interval)
Examples ¶
Constants ¶
const Version int = 1
Variables ¶
var StringFunc = defaultStringFunc
Default function for String method
Functions ¶
This section is empty.
Types ¶
type Interval ¶
type Interval struct { Meta interface{} // contains filtered or unexported fields }
Interval type stores start and end of interval and meta data in line and Meta (meta may be used to link to a feat.Feature).
func (*Interval) Chromosome ¶
Return the chromosome identifier for an Interval node.
func (*Interval) Contain ¶
Find Intervals completely containing the query (search is recursive inorder), and pass results on provided channel. The slop parameter determines how much slop is allowed:
slop < 0 query must be within interval by slop slop = 0 intervals may completely coincide slop > 0 query may extend beyond interval by slop
func (*Interval) Flatten ¶
func (self *Interval) Flatten(r chan *Interval, tolerance int) (flat []*Interval, rich [][]*Interval)
Merge a range of intervals provided by r. Returns merged intervals in a slice and intervals contributing to merged intervals groups in a slice of slices.
func (*Interval) Insert ¶
Insert an Interval into a tree returning the new root. Receiver should be the root of the tree.
func (*Interval) Intersect ¶
Find Intervals that intersect with the query (search is recursive inorder), and pass results on provided channel. The overlap parameter determines how much overlap is required:
overlap < 0 intervals can be up to overlap away overlap = 0 intervals abut overlap > 0 intervals must overlap by overlap
func (*Interval) Line ¶
Return the line number of an Interval node - not used except for reference to file.
func (*Interval) Remove ¶
Remove an interval. Returns the new root of the subtree and the removed interval.
func (*Interval) Traverse ¶
Traverse all intervals accessible from the current Interval in tree order and pass results on provided channel.
func (*Interval) Within ¶
Find Intervals completely within with the query (search is recursive inorder), and pass results on provided channel. The slop parameter determines how much slop is allowed:
slop < 0 intervals must be within query by slop slop = 0 intervals may completely coincide slop > 0 intervals may extend beyond query by slop
type Tree ¶
Tree type will store a collection of intervals. While this is not necessary for interval tree searching, a Tree stores intervals in a hash based on the chromosome name, reducing search time and easing coding.
func (Tree) AdjustRange ¶
func (Tree) Contain ¶
Find all intervals in Tree that entirely contain query. Return a channel that will convey results.
Example ¶
tree := CreateExampleTree("example", [][]int{{0, 4}, {8, 12}, {2, 3}, {5, 10}, {3, 7}, {-22, 6}, {34, 61}}) if i, err := New("example", 4, 6, 0, nil); err == nil { for s := range tree.Contain(i, 0) { fmt.Printf("%s\n", s) } }
Output: "example":[-22, 6) "example":[3, 7)
func (Tree) FastRemove ¶
Remove an interval, returning the removed interval. Does not adjust ranges within tree.
func (Tree) Flatten ¶
func (self Tree) Flatten(i *Interval, overlap, tolerance int) (flat []*Interval, rich [][]*Interval)
Flatten a range of intervals intersecting i so that only one interval covers any given location. Intervals less than tolerance positions apart are merged into a single new flattened interval. Return flattened intervals and all intervals originally in intersected region. No metadata is transfered to flattened intervals.
Example ¶
tree := CreateExampleTree("example", [][]int{{0, 4}, {8, 12}, {2, 3}, {5, 10}, {3, 7}, {27, 61}}) start, end := tree.Range("example") if i, err := New("example", start, end, 0, nil); err == nil { flat, original := tree.Flatten(i, 0, 0) fmt.Printf("flattened: %v\noriginal: %v\n", flat, original) }
Output: flattened: ["example":[0, 12) "example":[27, 61)] original: [["example":[0, 4) "example":[2, 3) "example":[3, 7) "example":[5, 10) "example":[8, 12)] ["example":[27, 61)]]
func (Tree) FlattenContaining ¶
func (self Tree) FlattenContaining(i *Interval, slop, tolerance int) (flat []*Interval, rich [][]*Interval)
Flatten a range of intervals containing i so that only one interval covers any given location. Return flattened intervals and all intervals originally in containing region. No metadata is transfered to flattened intervals.
func (Tree) FlattenWithin ¶
func (self Tree) FlattenWithin(i *Interval, slop, tolerance int) (flat []*Interval, rich [][]*Interval)
Flatten a range of intervals within i so that only one interval covers any given location. Return flattened intervals and all intervals originally in contained region. No metadata is transfered to flattened intervals.
Example ¶
tree := CreateExampleTree("example", [][]int{{0, 4}, {8, 12}, {2, 3}, {5, 10}, {3, 7}, {-22, 6}, {34, 61}}) if i, err := New("example", 2, 7, 0, nil); err == nil { flat, original := tree.FlattenWithin(i, 0, 0) fmt.Printf("flattened: %v\noriginal: %v\n", flat, original) }
Output: flattened: ["example":[2, 7)] original: [["example":[2, 3) "example":[3, 7)]]
func (Tree) Insert ¶
Insert an Interval into the Tree.
Example ¶
tree := NewTree() chromosome := "example" segments := [][]int{{0, 4}, {8, 12}, {2, 3}, {5, 10}, {3, 7}, {-22, 6}, {34, 61}} for _, s := range segments { if i, err := New(chromosome, s[0], s[1], 0, nil); err == nil { tree.Insert(i) } else { fmt.Println(err) } } PrintAll(tree)
Output: "example":[-22, 6), "example":[0, 4), "example":[2, 3), "example":[3, 7), "example":[5, 10), "example":[8, 12), "example":[34, 61)
func (Tree) Intersect ¶
Find all intervals in Tree that overlap query. Return a channel that will convey results.
Example ¶
tree := CreateExampleTree("example", [][]int{{0, 4}, {8, 12}, {2, 3}, {5, 10}, {3, 7}, {-22, 6}, {34, 61}}) if i, err := New("example", -15, -2, 0, nil); err == nil { for s := range tree.Intersect(i, 0) { fmt.Printf("%s\n", s) } }
Output: "example":[-22, 6)
func (Tree) Merge ¶
Merge an Interval into the Tree.
Example ¶
tree := CreateExampleTree("example", [][]int{{0, 4}, {8, 12}, {2, 3}, {5, 10}, {3, 7}, {34, 61}}) chromosome := "example" segments := [][]int{{0, 1}, {27, 42}} inserted := []*Interval{} replaced := []*Interval{} for _, s := range segments { if i, err := New(chromosome, s[0], s[1], 0, nil); err == nil { n, o := tree.Merge(i, 0) inserted = append(inserted, n...) replaced = append(replaced, o...) } else { fmt.Println(err) } } fmt.Println("Inserted") for _, s := range inserted { fmt.Printf("%s\n", s) } fmt.Println("Replaced") for _, s := range replaced { fmt.Printf("%s\n", s) } PrintAll(tree)
Output: Inserted "example":[0, 4) "example":[27, 61) Replaced "example":[0, 4) "example":[34, 61) "example":[0, 4), "example":[2, 3), "example":[3, 7), "example":[5, 10), "example":[8, 12), "example":[27, 61)
func (Tree) Remove ¶
Remove an interval, returning the removed interval with all pointers set to nil.
Example ¶
tree := CreateExampleTree("example", [][]int{{0, 4}, {8, 12}, {2, 3}, {5, 10}, {3, 7}, {-22, 6}, {34, 61}}) if i, err := New("example", -15, -2, 0, nil); err == nil { for s := range tree.Intersect(i, 0) { r := tree.Remove(s) fmt.Println(r, r.Left(), r.Right(), r.Parent()) } } PrintAll(tree)
Output: "example":[-22, 6) <nil> <nil> <nil> "example":[0, 4), "example":[2, 3), "example":[3, 7), "example":[5, 10), "example":[8, 12), "example":[34, 61)
func (Tree) Traverse ¶
Traverse all intervals for a chromosome in Tree in order. Return a channel that will convey results.
func (Tree) TraverseAll ¶
Traverse all intervals in Tree in order (chromosomes in hash order). Return a channel that will convey results.
Example ¶
tree := CreateExampleTree("example", [][]int{{0, 4}, {8, 12}, {2, 3}, {5, 10}, {3, 7}, {27, 61}}) segs := []string{} for i := range tree.TraverseAll() { segs = append(segs, i.String()) } fmt.Println(strings.Join(segs, ", "))
Output: "example":[0, 4), "example":[2, 3), "example":[3, 7), "example":[5, 10), "example":[8, 12), "example":[27, 61)
func (Tree) Within ¶
Find all intervals in Tree that are entirely contained by query. Return a channel that will convey results.
Example ¶
tree := CreateExampleTree("example", [][]int{{0, 4}, {8, 12}, {2, 3}, {5, 10}, {3, 7}, {-22, 6}, {34, 61}}) if i, err := New("example", 1, 5, 0, nil); err == nil { for s := range tree.Within(i, 0) { fmt.Printf("%s\n", s) } }
Output: "example":[2, 3)