knitr::opts_chunk$set(echo = FALSE)
require(CTraxHelper)
require(ggplot2)
lightfile<-file.choose()
lightprot<-read.table(lightfile,sep="\t", header=TRUE)

The light profile of the experiment is generated by ImageJ's Plot Z-Axis Profile and is found in the file r paste(dirname(lightfile),basename(lightfile),sep="/").

lightn<-length(lightprot$Y)
lightY<-sort(lightprot$Y)
scaledY<-(lightY-lightY[1])/(lightY[lightn]-lightY[1])
distY<-scaledY-(0:(lightn-1))/lightn
thresh<-lightY[which.max(abs(distY))] 
   ### this value is usually slightly too optimistic, so it is buffered by 1 sd 
   ### of the sub-threshold data
thresh<-thresh+sd(lightprot$Y[lightprot$Y<thresh])

The automatic threshold has been placed at r thresh. Gaps are closed with morphological closing over a 9-frame window.

timer<-mmand::closing(as.numeric(lightprot$Y>thresh),rep(1,9))

plot(lightprot$Y,type = 'b',ylim=c(thresh-0.2,thresh+0.2),pch='.',col='orange1')
points(lightprot$Y,ylim=c(thresh-0.2,thresh+0.2),pch='.', col='orange3',cex=1.5)
abline(h=thresh,col='blue')
lines(timer+thresh-0.5,col='green')
### EDIT IF UNHAPPY WITH THE AUTOTHRESHOLDING ###

autothresh<-TRUE

if (!autothresh) {
  thresh <- NA   ### Insert another value
  timer<-mmand::closing(as.numeric(lightprot$Y>thresh),rep(1,9))
}

The automatic threshold value is r if (!autothresh) {("not ")}adequate. r if (!autothresh) {(paste("It has been manually placed at ",thresh, " instead."))}

### UNCOMMENT OR EDIT ON THE BASIS OF EXPERIMENTAL PROTOCOL

# prot<-c(2,2,3,3,4,5,4,5)
# prot<-c(4,5,4,5,3,3,2,2)

This experiment's protocol section order has been r prot. This information is combined with the light protocol to generate the t timer data frame, which is saved in the file r paste(getwd(),"t.RDS",sep="/").

t<-timewriter(timer,prot)

saveRDS(t,file="t.RDS")
ggplot(tidyr::gather(t, key=protocol, value=value, -time), 
                aes(time, value, colour=protocol)) +
         geom_path() +
         facet_wrap(~protocol, ncol=1, switch="y", scales="free_y") +
         theme_classic() +
         theme(axis.title.y=element_blank())


PaolaCognigni/CTraxHelper documentation built on May 7, 2019, 11:57 p.m.