Reading and exploring inForm tables

Kent Johnson

2018-01-23

inForm tables

PerkinElmer’s inForm® software exports a variety of tabular data including information about cells and tissue categories. Tables are exported as tab-delimited text files with file names derived from the name of the source image by adding a suffix. Some of the suffixes, and the data contained in the files, are

cell_seg_data.txt - Detailed information about each cell in a field, including location, size, expression data for each component and possibly the phenotype and the containing tissue category.

cell_seg_data_summary.txt - Summary information about the cells in a field, including cell counts (stratified by phenotype and tissue category, if available) and summary size and expression data.

tissue_seg_data.txt - Detailed information about each tissue category region in the field, including size, centroid and expression data.

Cell segmentation data

phenoptr is primarily concerned with loading and processing cell_seg_data.txt files created by inForm. In the package documentation, these files are called cell seg data files and the data within them is referred to as cell seg data. Most examples use a variable named csd to contain cell seg data.

Reading cell segmentation data files

The read_cell_seg_data function reads cell seg data files and does useful cleanup on the result including removing empty columns, converting pixels to microns and simplifying column names.

# Load librarieslibrary(tidyverse)
library(phenoptr)
# sample_cell_seg_path gives the path to a sample file included with phenoptr.# Change this to be the path to your data. For example you might use# path <- 'C:/data/my_experiment/my_image_cell_seg_data.txt'
path <-sample_cell_seg_path()
# Read the data file
csd <-read_cell_seg_data(path)
# Show some nicely shortened names# The suffix "(Normalized Counts, Total Weighting)" has been removed.grep('Nucleus.*Mean', names(csd), value=TRUE)

Notice that column names containing spaces or other special characters, such as Tissue Category in the example above, generally must be enclosed in backticks (`) in code. If you are editing in RStudio (highly recommended), tab-completion will often include the backticks for you.

Reading cell segmentation summary files

read_cell_seg_data is also useful for reading cell_seg_data_summary.txt files. The same cleanup done for cell seg files is helpful for summary files.

Creating new columns

The dplyr::mutate function makes it very easy to add new columns to your data. This example adds a column for PDL1 positivity and counts cells in each phenotype stratified by positivity.

The pipe operator %>%

These examples make extensive use of the pipe operator (%>%) to combine operations. If you are not familiar with this operator, you may want to read this introduction.

Aggregating data

The functions dplyr::group_by and dplyr::summarize can be used to aggregate data within groups. dplyr::filter removes unwanted values. This example computes the mean PDL1 expression for each phenotype, omitting other cells.

Further reading and examples

The examples here only scratch the surface of what dplyr, ggplot2 and other functions in the tidyverse can do. If you’d like to learn more about the tidyverse, a good place to start is Garrett Grolemund and Hadley Wickham’s book, available free online at R for data science. The Data transformation chapter introduces the dplyr functions used in this tutorial.

The Tutorials included with the phenoptrExamples package include examples of reading data from multiple fields and aggregating across fields. That package includes more extensive sample data which can be used for practice.