Skip to content

Instantly share code, notes, and snippets.

@dododas dododas/computeDmle.R
Last active Feb 2, 2016

Embed
What would you like to do?
Maximum likelihood diffusion coefficient calculation for single particle tracks
# Estimate per-step and per-trajectory diffusion coefficients from SPT data
#
# Created by: Raibatak Das
# Jan 2016
library(readxl)
library(dplyr)
# Function to compute per-step diffusion coefficients
singlestepDmle = function(frame, x, y, pxl, dt){
# Compute Dmle for each step in a track
gaps = diff(frame)
dx = pxl*diff(x)
dy = pxl*diff(y)
sqdisp = dx^2 + dy^2
return( c(0, sqdisp/(gaps*4*dt)) )
}
# Acquisition parameters
pixelsize = 0.064 # pixel size in microns
delta_t = 0.03 # time step in seconds (= 1/frame rate)
# Import tracks - Change filename below
tracks = read_excel("Cbx7-PGK12-1-30ms.xlsx")
# Estimate per step maximum likelihood diffusion coefficients
perstepDmle = tracks %>%
group_by(ExptID, Cell, Track) %>%
transmute(singlestepDmle = singlestepDmle(Frame, x, y, pixelsize, delta_t)) %>%
filter(singlestepDmle != 0)
# Compute per-track and first-step diffusion coefficients
pertrackDmle = perstepDmle %>%
summarise(steps = n(),
firststepDmle = first(singlestepDmle),
trackDmle = mean(singlestepDmle))
# Save output - change filenames below
write.csv(perstepDmle, file="Cbx7-PGK12-1-30ms-per-step.csv", row.names=F) # per-step estimates
write.csv(pertrackDmle, file="Cbx7-PGK12-1-30ms-per-track.csv", row.names=F) # per-track estimates
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.