Skip to content

Plots using TIFFs

Veening lab edited this page Aug 7, 2019 · 2 revisions

Go to:

  1. extr_OriginalStack()
  2. plotRaw()
  3. bactKymo()
  4. prepForKymo()

The functions below use the original TIFF images (or stacks) imported into BactMAP using extr_OriginalStack() combined with cell outline data, spot data and/or object data. plotRaw() is primarily meant to explore the segmentation output, while bactKymo() can serve to quickly observe time-lapse data of single-cells or to make demographs of cells imaged at one time-point.

plotRaw()

Plot TIFF, cell contours and/or spot localization on the original x/y space.

Description

To check segmentation, view TIFF images and/or show the localization of spots inside cells. plotRaw() is ggplot2-based, so other geoms and theme layers can be added.

Usage

plotRaw(tiffdata, 
        meshdata, 
        spotdata, 
        frameN = 1, 
        xrange, 
        yrange, 
        viridisoption = "inferno", 
        meshcolor = "white", 
        spotcolor = "yellow", 
        valuerange
       )

Arguments

  • tiffdata (list of) dataframe(s) containing x and y coordinates of pixels and their values. Can be generated by loading a TIFF into R using bactMAP::extr_OriginalData()

  • meshdata dataframe containing (at least) X and Y coordinates of cells outlines, the frame number of the image and cell numbers.

  • spotdata dataframe containing (at least) x and y coordinates of spots and the frame number of the image.

  • frameN number of the frame to be displayed. default = 1.

  • xrange vector with minimum and maximum x coordinates to be displayed (by default all is shown).

  • yrange vector with minimum and maximum y coordinates to be displayed (by default all is shown).

  • viridisoption one of the viridis color scale options (default = “inferno”) for the displayed TIFF. options: “magma”, “viridis”, “cividis”, “plasma” and “inferno”

  • meshcolor color of the cell outlines. default = “white”

  • spotcolor color for displayed spots. default = “yellow”

  • valuerange vector with minumum and maximum pixel values to show TIFF, use this option to increase contrast

Value

A plot showing either a TIFF, mesh outlines, spot coordinates or a combination of the three.

Examples

Find more examples in the localization tutorial and the segmentation comparison tutorial

#load TIF image 

TIF_image <- file.choose()

#use extr_-function to turn into list of dataframes

TIF_df <- bactMAP::extr_OriginalStack(TIF_image)

#plot image
plotRaw(TIF_image)

#zoom in and add title
plotRaw(TIF_image, xrange=(c(200,500)), yrange=c(400,600)) + ggplot2::ggtitle("This is a TIF image")

bactKymo()

Creates kymographs or demographs from pixel values & cell dimensions.

Description

bactKymo() takes the output of extr_OriginalCells() and makes kymographs or demographs of them, depending on the chosen options. By default, all cells are used to make a demograph where the average fluorescence over the length axis of each cell is plotted, where all cells are ordered by cell length.

When timeD is set to TRUE, bactKymo() makes kymographs of single cells. However, when ‘percDiv’ is set to true as well, bactKymo will make a kymograph of the average of all cell’s fluorescence over their length axis, binning cells by the moment of division they are in (see perc_Division()).

Other settings which can be changed are the bin size (in how many groups is the average fluorescence intensity over the cell length calculated), whether the Y-axis should represent cell size (sizeAV=TRUE, takes more computing time) or a stretched range from cell pole to cell pole (sizeAV=FALSE), and finally, when plotting a demograph, whether the extreme values should be removed (cutoff_demograph).

The output will standardly be in the “viridis” color scale of the viridis package. However, this can be overwritten manually by adding a fill color scale to the plot.

To make computing time shorter while playing with the settings, it is possible to first prepare the kymographs using prepForKymo(). This is generally not necessary, but recommended when plotting single cell kymographs one by one.

Usage

bactKymo(originalCells,
          timeD = FALSE,
          dimension = "length",
          bins = 25,
          sizeAV = FALSE,
          cells = "all",
          prep = TRUE,
          percDiv = FALSE,
          cutoff_demograph = 0.975)

Arguments

  • originalCells The output of extr_OriginalCells, which combines TIFF data with mesh data.

  • timeD if timeD==TRUE, the resulting kymographs will be sorted by time, not by cell length and will be made of single cells.

  • dimension default="length", but when put to "width" the kymographs will average over cell width.

  • bins the amount of bins the fluorescence intensity will be averaged over (per cell/time point)

  • sizeAV when sizeAV==TRUE, the kymographs will reflect the cell length (or width) on the y axes. Default to FALSE because the computing time is faster when there is no sizing.

  • cells default = "all". cells is a numeric vector OR the word “all”. When set to “all” ,all cells will be processed into a demograph (when timeD==FALSE) or a kymograph will be made of all cells (when timeD==TRUE). When a numeric vector of length 1 or more, the cells identified with the cell numbers in these vector will be processed into a demograph (when timeD == FALSE), or a kymograph will be made of all single cells (when timeD==TRUE). Finally, when only 1 cell number is identified, a kymograph will be made of this cell (when timeD == TRUE). It is not possible to make a plot of a single cell without time dimension.

  • prep default = TRUE. Inside the function, the data will be prepared so it is possible to plot kymographs. Sometimes, when you want to run bactKymo() multiple times on the same dataset, it can save time to prepare the dataset only once. For this you can use the function prepForKymo() first and use the as the argument originalCells, while setting prep to FALSE.

  • percDiv this will call for perc_Division() and bin the average fluorescence over cell length (or width) in 10 groups, from just divided to almost dividing. It will, by default, plot all cells and only works with timelapse data.

  • cutoff_demograph to make it easier to look at demographs of all cells, the highest 2.5 percent of the intensity values are removed from the demograph. set the cutoff to 1 to not remove anything, or put it lower to remove more values.

  • mag magnification converter (see Pixels2um)

Details

Many options are possible within bactKymo(). Make sure you set the time dimension & cells correctly!

Note that when you have an output of many plots, it is useful to use gridExtra::grid.arrange() to save all plots in a PDF, this makes the plots easier to investigate and saves loading time in between.

Value

One or multiple demographs/kymographs (see the details in arguments).

Examples

Find more examples in the TimeLapse Tutorial. In the example dataset folder you can find the file "TurnedCell4.Rda" which is used below:

#to plot a timelapse demograph of 1 cell using the example set TurnedCell4 :
load("TurnedCell4.Rda")

kymo_cell4 <- bactKymo(TurnedCell4, timeD=TRUE, sizeAV=TRUE)

#to change the color scheme:
OrangeHot <- getPalette("OrangeHot")
kymo_cell4 + scale_fill_gradient2(low=OrangeHot[1], mid=OrangeHot[2], high=OrangeHot[3])

prepForKymo()

Prepare whole dataset for single cell kymographs.

Description

Extension from bactKymo, this function prepares a dataset for kymograph plotting. Recommended if you plan to plot a lot of kymographs from one dataset one by one; this will speed up the process. If you don’t plan to do this, use bactKymo immediately.

Usage

prepForKymo(turnedCells, dimension = "length", bins = 25, sizeAV = FALSE)

Arguments

  • turnedCells Output from extr_OriginalCells, which includes the pixel values (of the fluorescence signal) in each cell.

  • dimension Default = “length”, “width” is also possible. This decides on which dimension the kymograph will be calculated.

  • bins Default = 25. The amount of bins in which the average fluorescence over length or width will be calculated.

  • sizeAV
    When sizeAV == TRUE, the bins are placed along the y axis of the plot according to cell size. This takes more computation time.

  • Value A dataframe suitable for bactKymo().

Value

A dataframe which can be used as input for bactKymo.

Clone this wiki locally