Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Is overlap more tight in collision detection than contain ? #11

Open
kojix2 opened this issue May 13, 2022 · 1 comment
Open

Comments

@kojix2
Copy link

kojix2 commented May 13, 2022

I noticed a difference in behaviour when calling the contain and overlap functions.

First, adds the interval cr_add(cr, "chr1", 10, 10, 0);

overlap ("chr1", 10, 20) finds nothing.
contain ("chr1", 10, 20) finds this interval.

#include <stdio.h>
#include <stdlib.h>
#include "cgranges.h"

int main(void)
{
	cgranges_t *cr = cr_init();
	cr_add(cr, "chr1", 10, 10, 0);
	cr_index(cr);

	int64_t i, n, *b = 0, max_b = 0;
	n = cr_overlap(cr, "chr1", 10, 11, &b, &max_b);
	for (i = 0; i < n; ++i)
		printf("%d\t%d\t%d\n", cr_start(cr, b[i]), cr_end(cr, b[i]), cr_label(cr, b[i]));
	free(b);

	cr_destroy(cr);
	return 0;
}
# no output
#include <stdio.h>
#include <stdlib.h>
#include "cgranges.h"

int main(void)
{
	cgranges_t *cr = cr_init();
	cr_add(cr, "chr1", 10, 10, 0);
	cr_index(cr);

	int64_t i, n, *b = 0, max_b = 0;
	n = cr_contain(cr, "chr1", 10, 11, &b, &max_b);
	for (i = 0; i < n; ++i)
		printf("%d\t%d\t%d\n", cr_start(cr, b[i]), cr_end(cr, b[i]), cr_label(cr, b[i]));
	free(b);

	cr_destroy(cr);
	return 0;
}
10	10	0

This behaviour was somewhat surprising. Is this normal behaviour? I'm not very familiar with genomics, so I don't know exactly how it should behave.

@lh3
Copy link
Owner

lh3 commented Jun 3, 2022

This is really caused by 0-length intervals. [10,10) is zero-length. cr_overlap effectively filters out all such intervals. cr_contain uses a different algorithm and doesn't have the issue. I need to address this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants