library(SMoLR)
library(pander)
library(EBImage)
library(plyr)

The SMoLR package consists of a set of functions dedicated to the quantitive analysis of Single Molecule Localization data in R.

Import of localization data

Using SMOLR_IMPORT, different types of data can be imported into R from a folder. The localizations from different ROIs or images are sorted in a list of data.frame's. Different profiles are available to load different types of data.

SMOLR_IMPORT(folder="../test_data",profile = "roiloc")
SMOLR_LOAD(folder="../test_data")

Example of localizations data.frame

pander(head(smolrdata, 10))

\newpage

Visualization

The localizations can be plotted by individual Gaussians distributions using the SMOLR function. This can also be applied to a list of data.frame's. This will create an list of super resolution images. In this example a data.frame is the input. The plot function can be applied to the SMOLR_image object. This will return images of all channels in gray scale.

img <- SMOLR(smolrdata)
plot(img)

Alternatively an RGB image can be plotted.

plot(img,rgb=TRUE)

Instead of using the image in R it is also possible to export an image as tiff.

SMOLR(smolrdata,output = "tiff",file="image.tif")

Using subsetting only certain channels can be plotted.

plot(SMOLR(subset(smolrdata,Channel==1)))

Using the SMOLR_PLOT function, localizations can be plotted in a scatter plot

par(mar=c(2,2,2,2))
SMOLR_PLOT(smolrdata)

Plotting channels separately

par(mar=c(2,2,2,2))
SMOLR_PLOT(smolrdata,split_ch = T)

The color and size of the points in the plot can be related to column in the data.frame. In this example the color represents the Frame in which the localization is detected, while the size is by default equal to the localization precision.

par(mar=c(2,2,2,2))
SMOLR_PLOT(smolrdata,split_ch = T,color = smolrdata$First_Frame)

An overlay can be added as well:

overlay <- SMOLR(smolrdata)
SMOLR_PLOT(smolrdata,overlay=overlay,alpha = 0.2,size="off",,color_scale = adjustcolor(c("red","green","blue")),px=0.5)

\newpage

Clustering

A threshold applied to a kernel density estimation, can be used to cluster groups of localizations.

plot(SMOLR_KDE(smolrdata))

Alternatively the DBSCAN Algorithm can be used. Visualization of DBSCAN clustering. The colors indicate the assigned cluster, while the red localizations are considered background.

plot(SMOLR_DBSCAN(smolrdata,eps=50,MinPts=5))

Features

From the data image features can be calculated, using the SMOLR_FEATURES function. This function can be applied to a data.frame, but also to a list of data.frame's.

features <- SMOLR_FEATURES(SMOLR_KDE(smolrdata))
pander(head(features$channel_1[,1:9], 10))

Alternatively instead of using the image-based features, features based on the localization data can be calculated.

point_features <- SMOLR_POINT_FEATURES(SMOLR_DBSCAN(smolrdata,eps=50,MinPts=5))
pander(head(point_features[,1:10], 10))

An example how rotational alignment can be used:

pixelsize=5 #nm
test_kde <- SMOLR_KDE(smolrdata2, px=pixelsize, xlim=c(0,1000),ylim=c(0,1000))
test_features <- SMOLR_FEATURES(test_kde,"x.0.s.area",500)

par(mfrow=c(3,1))
plot(test_kde[[1]])
plot(test_kde[[2]])
plot(test_kde[[3]])


rotated_data <- list()

#do for al items in the list

for(i in 1:length(test_kde)){


  #determine filtered feature

  id <- test_features[[i]]$parameters$filtered_features_id
  id <- as.numeric(id)

  #determine center of filtered cluster

  x <- test_features[[i]]$channel_1[id,"x.0.m.cx"]*pixelsize
  y <- test_features[[i]]$channel_1[id,"x.0.m.cy"]*pixelsize

  #determine center of non filtered cluster

  x2 <- test_features[[i]]$channel_1[-id,"x.0.m.cx"]*pixelsize
  y2 <- test_features[[i]]$channel_1[-id,"x.0.m.cy"]*pixelsize

  #determine angle between two clusters

  angle <- atan2(y-y2,x-x2)

  #rotate around the center of the first cluster so that the second cluster is on top
  #translate so that the cluster is at coordinate 400,300

  rotated_data[[i]] <- SMOLR_ROTATE(smolrdata2[[i]],center=c(x,y) ,type = "radial", angle = angle+(pi/2), translate = c(400-x,300-y))


}
#plot rotated images

plot(SMOLR(rotated_data[[1]],xlim=c(0,800), ylim=c(0,800)))
plot(SMOLR(rotated_data[[2]],xlim=c(0,800), ylim=c(0,800)))
plot(SMOLR(rotated_data[[3]],xlim=c(0,800), ylim=c(0,800)))

#add all localizations to single list to make a summed image

summed_rotated_data <- ldply(rotated_data)

#plot the summed image

plot(SMOLR(summed_rotated_data,xlim=c(0,800), ylim=c(0,800)))


ErasmusOIC/SMoLR documentation built on Aug. 20, 2024, 8:50 p.m.