Ranges in ruby are pretty cool.
I end up with arrays such as this:
geneRanges = [(234..25), (500..510), (1640..1653)]
And subsequently have to remove bits of them. For that I:
genePositions = geneRanges.collect {|range| range.entries }.flatten
=> [500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 1640, 1641, 1642, 1643, 1644, 1645, 1646, 1647, 1648, 1649, 1650, 1651, 1652, 1653]
They get manipulated, so some numbers get excluded, and others may be added. I may end up with this:
[505, 506, 507, 600, 601, 602, 603, 1643, 1644, 1645, 1646, 1647, 1648, 1649, 1650, 1651, 1652, 1653, 1654]
How can I convert this back into a compact array of ranges? It seems that the inverse function should exist? I would expect it to return something like this:
[(505..507), (600..603), (1643..1654)]
Thanks!
See Question&Answers more detail:
os