Last active
February 2, 2016 17:36
-
-
Save dododas/fb34dc8d9ee5f7d30ebc to your computer and use it in GitHub Desktop.
Maximum likelihood diffusion coefficient calculation for single particle tracks
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
# 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