Skip to content

Instantly share code, notes, and snippets.

@ipurusho
Last active November 12, 2015 17:27
Show Gist options
  • Save ipurusho/db932aa92a0a89811e66 to your computer and use it in GitHub Desktop.
Save ipurusho/db932aa92a0a89811e66 to your computer and use it in GitHub Desktop.
UCSC binning scheme ported to Scala (http://genomewiki.ucsc.edu/index.php/Bin_indexing_system)
import scala.collection.mutable.ArrayBuffer
def binFromRange(start: Int, end: Int): ArrayBuffer[Int] ={
val bin_offsets = Array(512+64+8+1,64+8+1,8+1,0)
val binFirstShift = 17
val binNextShift = 3
var startBin = start >> binFirstShift
var endBin = (end -1) >> binFirstShift
var binArray = ArrayBuffer[Int]()
for(i<-bin_offsets){
val bin = i + startBin
binArray += bin
startBin >>= binNextShift
endBin >>= binNextShift
}
return binArray
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment