Skip to content

Instantly share code, notes, and snippets.

@jamesthompson
Created July 18, 2012 22:20
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jamesthompson/3139297 to your computer and use it in GitHub Desktop.
Tracking class
package Spots
import collection.mutable.ArrayBuffer
/**
* Track class
* Author: James R. Thompson, D.Phil
* Date: 7/16/12
* Time: 9:31 AM
* USC Mork Family Dept. of Chem. Eng. & Mat. Sci.
*/
class Track(val inputSpots:IndexedSeq[Array[(Double, Double)]], rangeThreshold:Double, minNumFrames:Int) {
lazy val spots : IndexedSeq[Spot] = for(frame<-inputSpots;spot<-frame) yield new Spot(spot,inputSpots.indexOf(frame))
def printSpots = println(spots.map(_.fancyString).mkString("\n"))
def doTracking = spots.map(spot => trackSpot(spot, spots, ArrayBuffer[Spot](spot))).filter(_.length >= minNumFrames)
def trackSpot(checkSpot:Spot, spotList:IndexedSeq[Spot], track:ArrayBuffer[Spot]) : ArrayBuffer[Spot] = {
checkSpot.frame < spotList.map(_.frame).max && checkSpot.notTracked match {
case true => {
val nextLinkedSpot = spotList.filter(_.frame == checkSpot.frame + 1).sortWith(_.distanceTo(checkSpot) < _.distanceTo(checkSpot)).head
if(nextLinkedSpot.distanceTo(checkSpot) < rangeThreshold) {
track += nextLinkedSpot
trackSpot(nextLinkedSpot, spotList, track)
} else {
track.map(_.gotTracked)
track
}
}
case false => {
track.map(_.gotTracked)
track
}
}
}
}
@jamesthompson
Copy link
Author

Tracking class, computes nearest neighbour spots in subsequent single molecule TIRF microscopy images.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment