# perturbatr cookbook

Simon Dirmeier

#### 2020-04-27

# 1 Introduction

`perturbatr` does stage-wise analysis of large-scale genetic perturbation screens for integrated data sets consisting of multiple screens. For multiple integrated perturbation screens a hierarchical model that considers the variance between different biological conditions is fitted. That means that we first estimate relative effect sizes for all genes. The resulting hit lists is then further extended using a network propagation algorithm to correct for false negatives.

Here we show an example data analysis using a pan-pathogenic data set of three RNAi screening studies. The data set consists of two kinome and a druggable genome wide RNAi screen and have been published in Reiss et al. (2011) (HCV) and Wilde et al. (2015) (SARS).

# 2 Data analysis tutorial

This tutorial walks you to the basic functionality of `perturbatr`.

## 2.1 Creating a `PerturbationData` object

You supposedly start with something like a `data.frame` or `tibble`:

      head(rnaiscreen)

    ## # A tibble: 6 x 9
    ##   Condition Replicate GeneSymbol Perturbation Readout Control Design ScreenType
    ##   <chr>         <int> <chr>      <chr>          <dbl>   <int> <chr>  <chr>
    ## 1 SARS              1 aak1       D-005300-01…   0.699       0 pooled E/R
    ## 2 SARS              1 aatk       D-005301-02…   0.713       0 pooled E/R
    ## 3 SARS              1 cerk       D-004061-01…  -0.446       0 pooled E/R
    ## 4 SARS              1 rapgef4    D-009511-01…  -0.398       0 pooled E/R
    ## 5 SARS              1 chek1      D-003255-06…   0.670       0 pooled E/R
    ## 6 SARS              1 chek2      D-003256-05…   1.12        0 pooled E/R
    ## # … with 1 more variable: Screen <chr>

In order to start your analysis you need to create a perturbation data set first.For this you only need to call the `as` method on your `data.frame`:

      rnaiscreen <- methods::as(rnaiscreen, "PerturbationData")

Coercing your `data.frame` to `PerturbationData` will automatically warn you if your table is formatted wrongly. You need at least the following column names order to be able to do analysis of perturbation screens using `perturbatr`:

- Condition: an identifier that best describes the respective screen. For instance this can be the name of a virus for pathogen screens, the name of a cell line, organoid or the like. The condition describes a single data set, i.e. if you want to integrate multiple different data sets, make sure to give each a different condition.
- Replicate: an integer representing the replicate number of a screen.
- GeneSymbol: the HUGO identifier, ENTREZ id, etc. as character.
- Perturbation: a siRNA id or gRNA id that describes the knockout/knockdown for the gene.
- Readout: a normalized readout like a log-fold change for gRNAs, a GFP signal, etc.
- Control: vector of integers representing perturbations that have been used as negative or positive controls. A negative control is marked with ‘-1’, a positive control with ‘1’ and a normal sample with ‘0’.

Depending on how you want to model the readout using the hierarchical model, you might want to add additional columns. For the sake of simplicity this suffices though.

## 2.2 Working with `PerturbationData` S4 objects

A `PerturbationData` object consists of a single slot that stores your data. We bundled your data into an `S4` object such that dispatch is easier to handle and to make sure that your data set has the correct columns:

      rnaiscreen

    ## A perturbation data set
    ##
    ##   Condition GeneSymbol    Readout
    ## 1       HCV       copb -4.4024144
    ## 2       HCV     pik3cg -3.0625215
    ## 3      SARS       tlk1  0.5420844
    ## 4      SARS       brdt  0.1117111

      dataSet(rnaiscreen)

    ## # A tibble: 215,427 x 9
    ##    Condition Replicate GeneSymbol Perturbation Readout Control Design ScreenType
    ##    <chr>         <int> <chr>      <chr>          <dbl>   <int> <chr>  <chr>
    ##  1 SARS              1 aak1       D-005300-01…   0.699       0 pooled E/R
    ##  2 SARS              1 aatk       D-005301-02…   0.713       0 pooled E/R
    ##  3 SARS              1 cerk       D-004061-01…  -0.446       0 pooled E/R
    ##  4 SARS              1 rapgef4    D-009511-01…  -0.398       0 pooled E/R
    ##  5 SARS              1 chek1      D-003255-06…   0.670       0 pooled E/R
    ##  6 SARS              1 chek2      D-003256-05…   1.12        0 pooled E/R
    ##  7 SARS              1 chka       D-006704-01…   1.76        0 pooled E/R
    ##  8 SARS              1 chkb       D-006705-01…  -0.343       0 pooled E/R
    ##  9 SARS              1 chrm1      D-005462-01…   0.878       0 pooled E/R
    ## 10 SARS              1 chuk       D-003473-03…  -0.511       0 pooled E/R
    ## # … with 215,417 more rows, and 1 more variable: Screen <chr>

`PerturbationData` has some basic `filter` and `rbind` functionality. Similar to `dplyr::filter` you can select rows by some predicate(s). In the example below we extract all rows from the data set that have a positive readout.

      perturbatr::filter(rnaiscreen, Readout > 0)

    ## A perturbation data set
    ##
    ##   Condition GeneSymbol    Readout
    ## 1       HCV     adam33 0.07790559
    ## 2       HCV     znf557 0.49426067
    ## 3      SARS      mark3 1.07325900
    ## 4      SARS    eif2ak3 0.38118756

Filtering on multiple rows works by just adding predicates:

      perturbatr::filter(rnaiscreen, Readout > 0, Replicate == 2)

    ## A perturbation data set
    ##
    ##   Condition GeneSymbol    Readout
    ## 1       HCV   kiaa0663 2.25709897
    ## 2       HCV      aebp2 0.02666081
    ## 3      SARS   mgc16169 1.28244465
    ## 4      SARS      galk2 1.41124248

If you want to combine data sets you can call `rbind`, which will automatically dispatch on `PerturbationData` object:

      dh <- perturbatr::filter(rnaiscreen, Readout > 0, Replicate == 2)
      rbind(dh, dh)

    ## A perturbation data set
    ##
    ##   Condition GeneSymbol   Readout
    ## 1       HCV     znf397 0.4607309
    ## 2       HCV     pla2g6 0.1196677
    ## 3      SARS      trpm7 1.7816536
    ## 4      SARS      akap7 0.2252257

## 2.3 Data analysis using a hierarchical model and network diffusion

Finally, after having set up the data set, we analyse it using a hierarchical model and network diffusion.

We expect you already normalized the data sets accordingly. As noted above, if you want to analyse multiple data sets, make sure that every data set corresponds to a unique `Condition`.

First, let’s have a rough look at the data set that we are using:

      plot(rnaiscreen)

We have roughly the same number of replicates per gene, but the HCV screen has less genes than the SARS data set. That is no problem however, because we automatically filter such that the genes are same. We also automatically remove positive controls for obvious reasons.

Next we rank the genes using a hierarchical model which requires explicitely modelling the readout of our data set using an R `formula`. Let’s look at the data in more detail first:

      dataSet(rnaiscreen) %>% str()

    ## tibble [215,427 × 9] (S3: tbl_df/tbl/data.frame)
    ##  $ Condition   : chr [1:215427] "SARS" "SARS" "SARS" "SARS" ...
    ##  $ Replicate   : int [1:215427] 1 1 1 1 1 1 1 1 1 1 ...
    ##  $ GeneSymbol  : chr [1:215427] "aak1" "aatk" "cerk" "rapgef4" ...
    ##  $ Perturbation: chr [1:215427] "D-005300-01,D-005300-02,D-005300-03,D-005300-04" "D-005301-02,D-005301-03,D-005301-04,D-005301-05" "D-004061-01,D-004061-02,D-004061-03,D-004061-04" "D-009511-01,D-009511-02,D-009511-03,D-009511-04" ...
    ##  $ Readout     : num [1:215427] 0.699 0.713 -0.446 -0.398 0.67 ...
    ##  $ Control     : int [1:215427] 0 0 0 0 0 0 0 0 0 0 ...
    ##  $ Design      : chr [1:215427] "pooled" "pooled" "pooled" "pooled" ...
    ##  $ ScreenType  : chr [1:215427] "E/R" "E/R" "E/R" "E/R" ...
    ##  $ Screen      : chr [1:215427] "Kinome" "Kinome" "Kinome" "Kinome" ...

Here, variables like `Replicate`, `Plate`, `RowIdx/ColIdx` should not be associated with a change in the response `Readout` as we normalized the data and corrected for batch effects. However, the `Readout`s should definitely have been different between `ScreenType`s:

      dataSet(rnaiscreen) %>% pull(ScreenType) %>% unique()

    ## [1] "E/R" "A/R"

where `E/R` represents that the screen has measured the effect of a gene knockdown during the entry and replication stages of the viral lifecycle while `A/R` repesents the gene knockdown’s effect having been measures during the assembly and release stages of the lifecycle. In the life cycle of positive-sense RNA viruses we know that viruses make use of different host factors during their life cycle. That means while some genes are required during entry and replication, others might play a role in assembly and release of the virions. So we have reason to believe that the stage of the infection also introduces a clustering effect. In that case we would need to add a random effect for the stage of the infection.

A model selection using the Bayesian information criterion indeed suggests the following hierarchical random intercept model:

\[y_{cgtp} \mid\gamma_g, \delta_{cg}, \zeta_t , \xi_{ct} \sim \mathcal{N}(x_c \beta + \gamma_g + \delta_{cg} + \zeta_t + \xi_{ct}, \sigma^2),\] where \(y_{cgtp}\) is the readout of virus \(c\), gene \(g\), stage of the viral lifecycle \(t\) (`E/R` vs `A/R`) and \(p\) is the perturbation (siRNA) used for gene \(g\). We estimate the parameters of the model using `lme4` (Bates et al. 2015):

      frm <- Readout ~ Condition +
                       (1|GeneSymbol) + (1|Condition:GeneSymbol) +
                       (1|ScreenType) + (1|Condition:ScreenType)
      res.hm <- hm(rnaiscreen, formula = frm)

Note that for your own data different effects might be visible. Thus, before modelling you need to exploratorily detect possible effects.

Let’s take the last result and plot them. This yields a list of multiple plots. The first plot shows the first 25 strongest gene effects ranked by their absolute effect sizes. Most of the genes are colored in blue which represents that a gene knockdown leads to an inhibition of viral growth on a pan-viral level. Bars colored in red represent genes for which a knockdown results in increased viral viability. If you are interested in the complete ranking of genes, use `geneEffects(res.hm)`.

      pl <- plot(res.hm)
      pl[[1]]

The second plots shows the nested gene effects, i.e. the estimated effects of a gene knockdown for a single virus. The genes shown here are the same as in the first plot, so it might be possible that there are nested gene effects that are stronger which are just not plotted. You can get all nested gene effects using `nestedGeneEffects(res.hm)`.

      pl[[2]]

Next we might want to smooth the effect from the hierarchical model using network diffusion, by that possibly reduce the number of some false negatives. For that we need to supply a graph as a `data.frame` and call the `diffuse` function:

      graph <- readRDS(
        system.file("extdata", "graph_small.rds",package = "perturbatr"))
      diffu <- diffuse(res.hm, graph=graph, r=0.3)

If we plot the results we get a list of reranked genes. Note that the ranking uses the network diffusion computes a stationary distribution of a Markov random walk with restarts.

      plot(diffu)

Further note that we used a very small network here. You might want to redo this analysis with the full graph which is located in `system.file("extdata", "graph_full.rds",package = "perturbatr")`.

## 2.4 Session info

      sessionInfo()

    ## R version 4.0.0 (2020-04-24)
    ## Platform: x86_64-pc-linux-gnu (64-bit)
    ## Running under: Ubuntu 18.04.4 LTS
    ##
    ## Matrix products: default
    ## BLAS:   /home/biocbuild/bbs-3.11-bioc/R/lib/libRblas.so
    ## LAPACK: /home/biocbuild/bbs-3.11-bioc/R/lib/libRlapack.so
    ##
    ## locale:
    ##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
    ##  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=C
    ##  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
    ##  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
    ##  [9] LC_ADDRESS=C               LC_TELEPHONE=C
    ## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
    ##
    ## attached base packages:
    ## [1] stats     graphics  grDevices utils     datasets  methods   base
    ##
    ## other attached packages:
    ## [1] perturbatr_1.8.0 tibble_3.0.1     dplyr_0.8.5      BiocStyle_2.16.0
    ##
    ## loaded via a namespace (and not attached):
    ##  [1] statmod_1.4.34       tidyselect_1.0.0     xfun_0.13
    ##  [4] purrr_0.3.4          operator.tools_1.6.3 splines_4.0.0
    ##  [7] lattice_0.20-41      colorspace_1.4-1     vctrs_0.2.4
    ## [10] htmltools_0.4.0      yaml_2.2.1           utf8_1.1.4
    ## [13] rlang_0.4.5          pillar_1.4.3         nloptr_1.2.2.1
    ## [16] glue_1.4.0           foreach_1.5.0        lifecycle_0.2.0
    ## [19] stringr_1.4.0        munsell_0.5.0        gtable_0.3.0
    ## [22] codetools_0.2-16     evaluate_0.14        labeling_0.3
    ## [25] knitr_1.28           doParallel_1.0.15    parallel_4.0.0
    ## [28] fansi_0.4.1          Rcpp_1.0.4.6         scales_1.1.0
    ## [31] BiocManager_1.30.10  magick_2.3           farver_2.0.3
    ## [34] lme4_1.1-23          ggplot2_3.3.0        digest_0.6.25
    ## [37] stringi_1.4.6        formula.tools_1.7.1  bookdown_0.18
    ## [40] grid_4.0.0           cli_2.0.2            tools_4.0.0
    ## [43] magrittr_1.5         diffusr_0.1.4        lazyeval_0.2.2
    ## [46] crayon_1.3.4         tidyr_1.0.2          pkgconfig_2.0.3
    ## [49] ellipsis_0.3.0       MASS_7.3-51.6        Matrix_1.2-18
    ## [52] assertthat_0.2.1     minqa_1.2.4          rmarkdown_2.1
    ## [55] iterators_1.0.12     R6_2.4.1             boot_1.3-25
    ## [58] igraph_1.2.5         nlme_3.1-147         compiler_4.0.0

## References

Bates, Douglas, Martin Mächler, Ben Bolker, and Steve Walker. 2015. “Fitting Linear Mixed-Effects Models Using lme4.” Journal of Statistical Software 67 (1):1–48. https://doi.org/10.18637/jss.v067.i01.

Reiss, Simon, Ilka Rebhan, Perdita Backes, Ines Romero-Brey, Holger Erfle, Petr Matula, Lars Kaderali, et al. 2011. “Recruitment and activation of a lipid kinase by hepatitis C virus NS5A is essential for integrity of the membranous replication compartment.” Cell Host & Microbe 9 (1). Elsevier:32–45.

Wilde, Adriaan H de, Kazimier F Wannee, Florine EM Scholte, Jelle J Goeman, Peter ten Dijke, Eric J Snijder, Marjolein Kikkert, and Martijn J van Hemert. 2015. “A Kinome-Wide Small Interfering Rna Screen Identifies Proviral and Antiviral Host Factors in Severe Acute Respiratory Syndrome Coronavirus Replication, Including Double-Stranded Rna-Activated Protein Kinase and Early Secretory Pathway Proteins.” Journal of Virology 89 (16). Am Soc Microbiol:8318–33.