Subcellular localization - veeninglab/BactMAP GitHub Wiki

Go to:

  1. createPlotList
  2. plotObjects
  3. plotOverlay
  4. plotTrack

createPlotList

Function to create descriptive plots of spot localization per group of cells

Description

createPlotList() is a plotting function which combines detected fluorescent spot localization with mesh outline information to plot demographs, projections, histograms and a data summary in one go. These functions are all combined because they need similar data preparation. The idea is that after using this function, you have a good overview of the localization of your protein inside the cells. Sometimes this analysis can be sufficient to show where a protein localizes, but in other cases (when proteins are very mobile or localize heterogeneously, for instance), this may rather serve as a starting point for more detailed analysis. Therefore, the data generated to make these plots is also returned by the function.

Usage

createPlotList <- function(spotdata,
                            meshdata
                            groups=4,
                            colorpalette="GreenYellow",
                            mag="No_PixelCorrection",
                            AllPlot=T,
                            Xm="X",
                            Ym="Y",
                            viridis=FALSE,
                            showPlot=TRUE,
                            getData=FALSE,
                            getSummary=TRUE)

Arguments

Argument Description
spotdata Data frame containing -at least- column with spot x-localizations (x), y-localizations (y) and frame number (frame). When the variable meshdata is not given, additional required columns are cell ID, relative x-localization (l or Lmid) and relative y-localization (d or Dum).
meshdata Data frame containing -at least- the x and y coordinates of the cell meshes (X and Y unless indicated otherwise), the maximum cell width max.width, maximum cell length max.length, cell ID and frame. Optional.
groups Number of groups the data will be divided in. Default = 4.
colorpalette Color palette the heatmap plots will be plotted in. Default is "GreenYellow". Check which palettes are loaded by showColorPalletes() and add your own palette using addPallete().
mag The name of the conversion factor for pixel to micrometer. Default is "No_PixelCorrection" which is 1. Check getPixels2um() for the loaded conversionfactors and use addPixels2um("ConversionName", conversionfactor) to add a conversion factor to the list.
AllPlot When TRUE, the output x/y plots will have sideplots with histograms of the spot localization. When FALSE, only the x/y plots will be plotted.
Xm and Ym By default, the column names of the x/y coordinates in the MESH data frames are "X" and "Y". When this is not the case, one can tell the function by using Xm and Ym. Enter a character string with the name of the x-coordinate column for Xm, and the name of the y-coordinate column for Ym.
viridis when viridis==TRUE, the colorpalette needs to be one of the viridis color palettes (“A”, “B”, “C”, “D”, “E”, “magma”, “cividis”, “viridis”, “plasma” or “inferno”).
showPlot when showPlot==TRUE, a menu will be shown after the function is finished, which enables the user to view the plot output of the function.
getData when getData==TRUE, the output list will include the input dataframes spotdata and (if given) meshdata, which include the quantile classification and the relative localization of the spots (see below).
getSummary when getSummary==TRUE, the output list will include the data_summary (see below).

Value

A list consisting of the following items:

Value Description
$lengthplot Heatmap histogram plot of the length-axis localizations of the spots ordered by the length of the cell.
$widthplot Heatmap histogram plot of the width-axis localizations of the spots ordered by the length of the cell.
$qplots If the outlines of the cell are not added to the function (dataframe MESH not indicated), the output will be a list of plots of length inp, with relative x/y coordinates of the spots plotted as a density function. The data is grouped by the variable bycol, which is length by default.If the outlines of the cells are added to the function (dataframe MESH indicated), the average cell outline of each group will be overlayed on top of each plot. If AllPlot==TRUE, histograms of the x and y coordinates of the spots will be added as sideplots.
$plottotal Relative x/y coordinates of all spots with average cell outline overlayed. If AllPlot==TRUE, the x/y coordinates will be plotted as histograms on the x and y axis of the plot.
$histograms 1D density plots of the spot localization on the length axis of the cells, grouped by bycol in the amount of groups defined by groups.
$spotdata data frame containing the groups, relative x/y localizations of the spots and cell length/width
$meshdata if MESH is included, the function returns a dataframe including the rotated meshes and groups.
$data_summary a character vector, or when groups>1, a list of character vectors summarizing the most important data features of each size group and the full dataset.

Note

This function is meant to give an overview of the data. It is possible to modify each individual plot using ggplot commands or convert it to a plotly object using ggplotly. Check the tutorial on localization plotting for examples.

References

These plotting functions were developed for:

Renske van Raaphorst, Morten Kjos and Jan-Willem Veening. “Chromosome segregation drives division site selection in Streptococcus pneumoniae.” Proceedings of the National Academy of Sciences 114.29 (2017): E5959-E5968.

Examples

##use data from example dataset: https://veeninglab.com/f/example_datasets.zip
library(bactMAP)

load("DnaX_tracks.rda")
load("DnaX_mesh.rda")

##1. detected peaks:
peaks <- DnaX_tracks


##2. mesh outlines:
mesh <- DnaX_mesh


##create list of plots, ordered by length, grouped in 6 groups.
GFPlist <- createPlotList(peaks, mesh, groups=6,  colorpalette="GreenYellow", AllPlot=T, showPlot=FALSE)

#have a look at the "plottotal" plot
plot(GFPlist$plottotal)

#save PDF of the 6 grouped plots (qplots)
ggplot2::ggsave(GFPlist$qplots, filename="GroupPlots.PDF")

#see summary:
GFPlist$data_summary$Full_dataset
## $Total_amount_of_cells
## [1] 3890
## 
## $Spot_distance_from_midcell_length_axis
##     Min.  1st Qu.   Median     Mean  3rd Qu.     Max.     NA's 
## -14.6329  -0.9614   1.9133   1.8945   5.2385  17.0349      433 
## 
## $Spot_distance_from_midcell_width_axis
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
## -6.3754 -1.9099 -0.3906 -0.4696  0.9774  5.5524     433 
## 
## $Cell_length
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##   11.75   23.82   28.41   28.41   32.83   45.96     433 
## 
## $Cell_width
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##   10.83   13.08   13.78   13.73   14.46   15.55     433 
## 
## $Distribution_spots_per_cell
##    0    1    2    3    4 
##  433 2554  804   90    9

PlotObjects

Create plots similar to createPlotList using intracellular object outlines instead of points.

Description

Plot projection of fluorescent objects inside cells in one or more cell groups based on cell length.

Usage

plotObjects(obdat,
            meshdat,
            groups = 1,
            cellcolor = "black",
            objectcolor = "green",
            transparency = 0.1,
            getdata = FALSE)

Arguments

Argument Description
obdat Object dataset object_relative as it is extracted using one of the extr_-functions.
meshdat A mesh dataset as it is extracted using one of the extr_-functions (optional).
groups The amount of groups to devide the cell projections in (by cell length). Default = 1.
cellcolor The color of the cells in the cell projections. Default = "black".
objectcolor The color of the objects in the projections. Default = "green".
transparency The transparency of the objects and cells in the overlay. Default = 0.1. When analyzing ~1000 cells, it is advised to set this number to ~0.02 or less.
getdata When getdata==TRUE, the function returns a dataset with the grouped cells next to the plot. Default is set to FALSE.

Value

A ggplot of cell and object projections showing the relative localization of the intracellular objects, grouped by cell length.

Examples

#get objects & meshes from WT D39 cells stained with Van-FL, analyzed with oufti.
#downlaod example dataset from https://veeninglab.com/f/example_datasets.zip

library(bactMAP)

load("VanFL_objWT.rda")
load("VanFL_meshWT.rda")

objects <- VanFL_objWT
meshes <- VanFL_meshWT

#plot objects

plotObjects(objects, meshes, groups=4, transparency=0.1)

#change colors/layout; this example requires the packages "ggdark" and "ggplot2"

library(ggdark)
library(ggplot2)
plotObjects(objects, meshes, groups=4, transparency=0.1, cellcolor="grey40", objectcolor="magenta") + ggdark::dark_theme_minimal()

PlotOverlay

Display spot- and/or object-localization of different color channels and/or experimental conditions in one plot.

Usage

plotOverlay(meshdata,
            spotdata,
            objectdata,
            by = "both",
            type = "all",
            quantiles = 1,
            quantiles_by = "max.length",
            mag,
            objectcolor = c("#E69F00", "#56B4E9", "#009E73", "#F0E442"),
            spotcolor = c("#0072B2", "#D55E00", "#CC79A7", "000000"),
            histogram_outline = NA,
            his_scales = "free")

Arguments

Argument Description
meshdata A mesh dataframe generated by combining dataframes with the function combineDataframes. Optional.
spotdata A spot dataframe generated by combining dataframes with the function combineDataframes. Optional.
objectdata A object dataframe generated by combining dataframes with the function combineDataframes. Optional.
by Either "both", "channel" or "condition", indicating which variables are to be plotted.
type The type of output plot. Options are: "histogram", "length", "width", "projection" or "all". Examples of each plot are given below.
quantiles and quantiles_by When "projection" or "all" is chosen, the cells can be split into groups by quantiles_by: one of the other columns existing in each dataset (default = max.length). Default for quantiles = 1, so no grouping.
mag magnification convertion factor, needed when cell values are not yet converted to microns. See [getPixels2um](Pixels2um).
objectcolor Indicates the color(s) of the objects (if included). Default colorset is a range of 4 colors ("#E69F00", "#56B4E9", "#009E73", "#F0E442").
spotcolor Indicates the color(s) of the spot data (if included). Default colorset is a range of 4 colors ("#0072B2", "#D55E00", "#CC79A7", "000000").
histogram_outline By default, the histograms displayed have no outlines. Indicate a hex value or a colorname to change this.
his_scales Inherited from ggplot2::geom_facet_grid(): when cells are grouped into different groups, by default, the histograms y-axis is scaled free per group. Settinghis_scales to"fixed" will make the scale the same for each group.

Value

A plot or a list of plots:

Value Description
histogram Histogram plot of the localization distribution, if quantiles are set, grouped by by_quantiles.
length Dotplot showing the localization of the spots and/or objects on the cell’s length axis on the y-axis, and the cells ordered by cell length on the x-axis.
width Dotplot showing the localization of the spots and/or objects on the cell’s width axis on the y-axis, and the cells ordered by cell length on the x-axis.
projection Cell projections showing the relative object localization, spot localization and cell shape; if quantiles are set, grouped by by_quantiles.

Examples

##get data from BactMAP examples: https://veeninglab.com/f/example_datasets.zip

load("VanFL_objWT.rda")
load("VanFL_objDM.rda")
load("VanFL_meshWT.rda")
load("VanFL_meshDM.rda")

#condition one: wild type
WT_objects <- VanFL_objWT
WT_mesh <- VanFL_meshWT

#condition 2: dmapZ
DM_objects <- VanFL_objDM
DM_mesh <- VanFL_meshDM

comboMesh <- combineDataframes(list(WT_mesh, DM_mesh), listofconditions=list("WildType", "DeltaMapZ"))
comboObjects <- combineDataframes(list(WT_objects, DM_objects), listofconditions=list("WildType", "DeltaMapZ"))

plotOverlay(meshdata=comboMesh$finalframe,
            objectdata=comboObjects$finalframe,
            by="condition",
            quantiles=4,
            type="projection")

plotTracks

Plot tracked spots and/or objects over time in 1 or 2 dimensions.

Usage

plotTracks( meshdata,
            spotdata,
            objectdata,
            tracks = TRUE,
            ignore_singles = FALSE,
            movie = "none",
            timepalette_lines = "viridis",
            timepalette_fill = "magma",
            dimension = c("length", "width"),
            turn_cells = TRUE,
            mag,
            cell = "all",
            transparency = 0.2
            )

Arguments

Argument Description
meshdata A mesh dataframe containing cell outlines.
spotdata A spot dataframe containing spot localizations.
objectdata A object dataframe containing fluorescent object outlines.
tracks When tracks == TRUE, the track of individual spots over time will be shown. When tracks == FALSE, only the spots will be shown.
ignore_singles When ignore_singles == FALSE, all detected spots will be shown. When ignore_singles ==TRUE, only those spots will be shown which are tracked over time.
movie When movie=="none" (default), the output will be a static plot. When movie == "gganimate", gganimate (version => 1.0.3) will be used to make a GIF animation. Finally, when movie = "plotly", plotly will be used to make an interactive HTML-based animation.
timepalette_lines A viridis palette for both the spots & tracks as the outlines of the meshes, where color indicates the time in frames. Default = “viridis”.
timepalette_fill A viridis palette for the fill of the objects, where color indicates the time in frames. Default = "magma".
dimension Either "length", "width", or c("length", "width")(default). Indicates the dimensions which will be plotted next to time (frames).
turn_cells When cell projections are plotted (both cell length & width), it is possible to plot cells with their original x/y coordinates, or turn them so their length axis is parallel to the x-axis with mid-cell at 0. When plotting only one cell dimension, this command is ignored and cells are turned by default.
mag The magnification converter (see pixels2um).
cell The cell number or numbers as a numeric vector (e.g. c(1,2,10)), or (default) "all". When more then one cell are indicated, the function returns a plot faceted by cell number.
transparency Transparency of both the objects as the cell polygons. The cell polygons are set to be 5 times more transparent than the object polygons.

Value

A plot or a faceted plot of the trajectory of the cell shape, fluorescent spots and/or the localization of detected fluorescent objects in the cell over time. The plots can either by location on the length-axis over time, location on the width-axis over time, or x/y location and shape over time.

Examples

  ##Get example data: https://veeninglab.com/f/example_datasets.zip
  
  load("FtsZ_tracks.rda")
  load("DnaX_mesh.rda")

  ##tracked FtsZ
  FtsZ <- FtsZ_tracks

  ##and corresponding meshes
  meshes <- DnaX_mesh

  #plot FtsZ on length axis/time
  plotTracks(meshdata=meshes, spotdata=FtsZ_tracks, dimension="length", mag="100x_DVMolgen", tracks=TRUE, cell=4)

  #or plot FtsZ over both length/width axis
  
  plotTracks(meshdata=meshes, spotdata=FtsZ_tracks, dimension=c("length","width"), mag="100x_DVMolgen", tracks=TRUE, cell=4)

⚠️ **GitHub.com Fallback** ⚠️