Tracking class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tracking class, computes nearest neighbour spots in subsequent single molecule TIRF microscopy images.