I have been creating rainfall plots following the tutorial from [https://bernatgel.github.io/karyoploter_tutorial//Examples/Rainfall/Rainfall.html][1]

Does anyone know how I could extract only mutations with a high degree of spatial clustering from the GRanges object? For example if I want to create a new object which is a list of all mutations that are within 1kb of another mutation. The output would be in this format for input into another program:

    Chr start end ref alt
    1 10 10 A T
    1 50 50 C G
    2 181 181 A T
    2 280 280 T A

I also have the raw list of all variants in the format above that becomes a GRanges object, so it might be easier just to use a function that works directly on that to find clustered variants? I imagine a tool must already exist to identify variants that are spatially clustered in the genome, but I have not yet found one.

Thanks in advance for suggestions.

  [1]: https://bernatgel.github.io/karyoploter_tutorial//Examples/Rainfall/Rainfall.html
Hi Rubai,

If you are already using `kpPlotRainfall` you can take advatage of the distances it computes. You should call it and assign the result to kp again

    kp <- kpPlotRainfall(kp, data=your.data, [...])

and then you can get the distances with

    distances <- kp$latest.plot$computed.values$distances

The distances are in log10, so if you want just the variants that are closer than 1kb to the next variant you should 

    your.data[distances<3,]

And that should do it. 

Hope this helps