Git Product home page Git Product logo

Comments (6)

brentp avatar brentp commented on August 14, 2024

I have just pushed a change for this. When using IRelate it would look like:

IRelate(CheckRelatedByOverlap, SelfRelations, Less, mystream) 

where SelfRelations is a constant that allows self relations. Let me know if this addresses your use-case.

from irelate.

bsipos avatar bsipos commented on August 14, 2024

Thanks! I cannot find the commit though. Did you push it on a branch?

from irelate.

brentp avatar brentp commented on August 14, 2024

:| pushed it now.

from irelate.

bsipos avatar bsipos commented on August 14, 2024

Pulled it and invoked as instructed. But I get back EOF from IRelate right away. :(

from irelate.

brentp avatar brentp commented on August 14, 2024

ok. now it's actually supported in latest commet. Here's an example:

package main

import (
	"fmt"
	"io"
	"log"

	"github.com/brentp/irelate"
	"github.com/brentp/irelate/interfaces"
)

func check(e error) {
	if e != nil {
		log.Fatal(e)
	}
}

type ri struct {
	i               int
	interval_starts []int
}

type interval struct {
	start   int
	related []interfaces.Relatable
}

func (r *ri) Next() (interfaces.Relatable, error) {
	if r.i == len(r.interval_starts) {
		return nil, io.EOF
	}
	result := &interval{start: r.interval_starts[r.i]}
	r.i++
	return result, nil
}

func (r *ri) Close() error {
	return nil
}

func (i *interval) Chrom() string {
	return "chr1"
}
func (i *interval) Start() uint32 {
	return uint32(i.start)
}
func (i *interval) End() uint32 {
	return uint32(i.start + 20)
}

func (i *interval) Related() []interfaces.Relatable {
	return i.related
}

func (i *interval) AddRelated(r interfaces.Relatable) {
	i.related = append(i.related, r)
}

func (i *interval) Source() uint32 {
	return 0
}
func (i *interval) SetSource(u uint32) {
}

func main() {
	rels := &ri{i: 0, interval_starts: []int{0, 5, 10, 15, 20, 25, 110, 115}}

	it := irelate.IRelate(irelate.CheckRelatedByOverlap, irelate.SelfRelations, irelate.Less, rels)
	for {
		interval, err := it.Next()
		if err == io.EOF {
			break
		}
		if err != nil {
			panic(err)
		}
		fmt.Printf("%s\t%d\t%d\t%d\n", interval.Chrom(), interval.Start(), interval.End(), len(interval.Related()))
	}
}

from irelate.

bsipos avatar bsipos commented on August 14, 2024

Thanks a lot! Now this almost does what I want. However, the current code gives back each relatable from the iterator with the Realted() slot filled with all other related features.
What I really want is "clusters" of related objects with no duplication (so each relatable appears only once in a cluster with all the other pairwisely related features).
I realise this might not be easy to achieve with IRelate (which would be nice), in which case I will have to roll my own code.

from irelate.

Related Issues (4)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.