I have a dataset of this form:
chrX posX labelX
chrX refers to the chromosome number,
posX refers to location, and
labelX is a categorical variable with 3 labels.
chr1 3223 1 chr1 3200 2 chr1 3100 1 chr1 1000 2 chr2 1000 1 chr1 3210 3
I want to be cluster these data with certain constraints (thus, this is no longer what 'clustering' typically is), such that, for each chromosome, the sites which are within, say $\pm 30$ positions are together, the constraint being they should have unique labels.
For example, an expected output would be:
chr1 : 3223(1) 3200(2) 3210(3) Notice how sites like
chr1 3100 1 are not part of the 'cluster'.
One approach would be to simply calculate pairwise differences between all such sites, and grow the cluster taking care of unique labels.
Are there more elegant approaches to solve such problems?