Learn R Programming

⚠️There's a newer version (1.0.14) of this package.Take me there.

tidygate: add gate information to your tibble

Please have a look also to - nanny for tidy high-level data analysis and manipulation - tidyHeatmap for producing heatmaps following tidy principles - tidybulk for tidy and modular transcriptomics analyses

Installation

# From Github
devtools::install_github("stemangiola/tidygate")

# From CRAN
install.package("tidygate")

It interactively or programmately labels points within custom gates on two dimensions, according to tidyverse principles. The information is added to your tibble. It is based on the package gatepoints from Wajid Jawaid.

The main benefits are

  • in interactive mode you can draw your gates on extensive ggplot-like scatter plots
  • you can draw multiple gates
  • you can save your gates and apply the programmatically.

Input (tibble)

dimension1dimension2annotations
chr or fctrnumeric

Interactive gating

The standard way to gate points in a two-dimensional plot is to - Interactively draw an arbitrary number of gates - Click “Finish” button on the top-right corner of the plot

tidygate_gate <-
  tidygate_data %>%
  mutate( gate = gate_chr( Dim1, Dim2 ) )
  

tidygate_gate

Output tibble

## # A tibble: 2,240 x 9
##    group   hierarchy `ct 1`    `ct 2`    relation cancer_ID   Dim1    Dim2 gate 
##    <chr>       <dbl> <chr>     <chr>        <dbl> <chr>      <dbl>   <dbl> <chr>
##  1 adrenal         1 endothel… epitheli…    -1    ACC       -0.874 -0.239  0    
##  2 adrenal         1 endothel… fibrobla…    -1    ACC       -0.740  0.114  1    
##  3 adrenal         1 endothel… immune_c…    -1    ACC       -0.988  0.118  0    
##  4 adrenal         1 epitheli… endothel…     1    ACC        0.851  0.261  0    
##  5 adrenal         1 epitheli… fibrobla…     1    ACC        0.839  0.320  0    
##  6 adrenal         1 epitheli… immune_c…     1    ACC        0.746  0.337  0    
##  7 adrenal         1 fibrobla… endothel…     1    ACC        0.722 -0.0696 0    
##  8 adrenal         1 fibrobla… epitheli…    -1    ACC       -0.849 -0.317  0    
##  9 adrenal         1 fibrobla… immune_c…     0.52 ACC       -0.776 -0.383  0    
## 10 adrenal         1 immune_c… endothel…     1    ACC        0.980 -0.116  0    
## # … with 2,230 more rows

Gates are saved in a temporary file for later use

## [[1]]
##            x          y
## 1 -0.9380459  0.2784375
## 2 -0.9555544 -0.1695209
## 3 -0.3310857  0.2116150
## 
## [[2]]
##             x          y
## 1  0.01324749  0.2165648
## 2 -0.31065917 -0.1026984
## 3 -0.11514794 -0.2982161
## 4  0.48013998  0.1225183

Programmatic gating

We can use previously drawn gates to programmately add the gate column

tidygate_data %>%
  mutate( gate = gate_chr(
    Dim1, Dim2,
     # Pre-defined gates
    gate_list = my_gates
  ))
## # A tibble: 2,240 x 9
##    group   hierarchy `ct 1`    `ct 2`    relation cancer_ID   Dim1    Dim2 gate 
##    <chr>       <dbl> <chr>     <chr>        <dbl> <chr>      <dbl>   <dbl> <chr>
##  1 adrenal         1 endothel… epitheli…    -1    ACC       -0.874 -0.239  0    
##  2 adrenal         1 endothel… fibrobla…    -1    ACC       -0.740  0.114  1    
##  3 adrenal         1 endothel… immune_c…    -1    ACC       -0.988  0.118  0    
##  4 adrenal         1 epitheli… endothel…     1    ACC        0.851  0.261  0    
##  5 adrenal         1 epitheli… fibrobla…     1    ACC        0.839  0.320  0    
##  6 adrenal         1 epitheli… immune_c…     1    ACC        0.746  0.337  0    
##  7 adrenal         1 fibrobla… endothel…     1    ACC        0.722 -0.0696 0    
##  8 adrenal         1 fibrobla… epitheli…    -1    ACC       -0.849 -0.317  0    
##  9 adrenal         1 fibrobla… immune_c…     0.52 ACC       -0.776 -0.383  0    
## 10 adrenal         1 immune_c… endothel…     1    ACC        0.980 -0.116  0    
## # … with 2,230 more rows

Copy Link

Version

Install

install.packages('tidygate')

Monthly Downloads

252

Version

0.4.0

License

GPL-3

Maintainer

Stefano Mangiola

Last Published

January 18th, 2021

Functions in tidygate (0.4.0)

gate_interactive_chr_int

Get points within a user drawn gate
gate_chr

Label points within a scatter plot drawing a gate
gate_chr.numeric

gate_chr
fhs

Freehand select
gate_int.numeric

gate_int
gate

DEPRECATED - use gate_chr, gate_int instead inside a dplyr::mutate() statement
gate_list

Example gate_list
gate_programmatic

Get points within a user drawn gate
add_attr

Add attribute to abject
gate_interactive

Get points within a user drawn gate
tidygate_data

Example data set
gate_programmatic_chr_int

Get points within a user drawn gate
quo_names

Convert array of quosure (e.g. c(col_a, col_b)) into character vector