# MACSQuantifyR - Step-by-step analysis

# Introduction

This is an example of how to run MACSQuantifyR with combination drug analysis. To know more about the package, have a look at the introduction vignette

In this vignette we will run the MACSQuantifyR package on the example given in the introduction of the previous vignette. More precisely, this experiment corresponds to the screening of the combination effects of two drugs on human cells.

Here is the plate template chosen by the user that represents drugs alone (up part of the well plate) and combinations (low part of the well plate).

# Pipeline

Load the packages

    library(MACSQuantifyR)
    library(knitr)
    library(grid)
    library(gridExtra)
    library(ggplot2)
    library(tools)
    library(readxl)
    library(lattice)
    library(latticeExtra)

    ##
    ## Attaching package: 'latticeExtra'

    ## The following object is masked from 'package:ggplot2':
    ##
    ##     layer

    suppressMessages(library(R.utils))

## Create a new object MACSQuant: new_class_MQ()

This function allows the user to create a new object of class MACSQuant.

This will allow the user to set specific options regarding the experiment and the output of some functions before running other functions.

- Create the MACSQuant object:

    MACSQuant <- new_class_MQ(path = "output_path")

- Define experiment name:

    slot(MACSQuant, "experiment_name") <- "Combo drug1-drug2 HC line 101"

- Define output path:

`slot(MACSQuant,"param.output")$path`

## Import your data: load_MACSQuant()

Once the excel file has been generated by miltenyi MACSQuantify software. The user can load the data with the following function.

It will generate a variable called my_data, necessary for the next steps of the analysis.

Load the data:

    filepath <- system.file("extdata", "drugs.xlsx",
        package = "MACSQuantifyR")
    MACSQuant <- load_MACSQuant(filepath,
        sheet_name = "combo_drugs",
        MACSQuant.obj = MACSQuant)

    ## ok

    ## --> Done: data loaded

    ## --> Done: data stored in variable MACSQuant@my_data

    ## ...You can now run on_plate_selection(MACSQuant,num_replicates,number_of_conditions) with your replicates and conditions numbers...

## Sort your replicates: on_plate_selection()

By calling the function on_plate_selection() with the number of conditions in the experiment and the number of replicates by conditions, the user will be asked to select sequentially the replicates for each conditions.

Before running the function, the user can define one of the experiment parameters called c_names in which condition names are stored.

Experiment parameters are:

- c_names: condition names to plot

`slot(MACSQuant,"param.experiment")$c_names`

- doses: colors for the barplots

`slot(MACSQuant,"param.experiment")$doses`

    # this line is used to created c_names variable
    # for this experiment according to selection
    slot(MACSQuant, "param.experiment")$c_names <-
        c(sprintf("Drug1_c%d", 1:4), # DRUG1 ALONE
            sprintf("Drug2_c%d", 1:3), # DRUG2 ALONE
            sprintf("D2[1]_D1[%d]", 1:4), # DRUG2_C1 + DRUG1_Cs
            sprintf("D2[2]_D1[%d]", 1:4), # DRUG2_C2 + DRUG1_Cs
            sprintf("D2[3]_D1[%d]", 1:4)) # DRUG2_C3 + DRUG1_Cs

    # custom colors can be defined (with control if selected)
    plt.col <- c(heat.colors(length(slot(MACSQuant, "param.experiment")$c_names)),
        1)

    # dose vector of concentration each condition
    slot(MACSQuant, "param.experiment")$doses <-
        c(1, 3, 5, 10, # DRUG1 ALONE
            0, 0, 0,                  # DRUG2 ALONE
            1, 3, 5, 10, # DRUG2_C1 ++ DRUG1_Cs
            1, 3, 5, 10, # DRUG2_C2 + DRUG1_Cs
            1, 3, 5, 10  # DRUG2_C3 + DRUG1_Cs
        )
    slot(MACSQuant, "param.experiment")$doses.alt <-
        c(0, 0, 0, 0,                # DRUG1 ALONE
            10, 50, 100,              # DRUG2 ALONE
            10, 10, 10, 10,            # DRUG2_C1 + DRUG1_Cs
            50, 50, 50, 50,            # DRUG2_C2 ++ DRUG1_Cs
            100, 100, 100, 100          # DRUG2_C3 ++ DRUG1_Cs
        )

The function is ready to run:

    MACSQuant <- on_plate_selection(MACSQuant,
        number_of_replicates = 3,
        number_of_conditions = 19,
        control = TRUE,
        save.files = TRUE)

Once the replicates of all conditions have been identified by the user, the on_plate_selection function will automatically reorder the data stored in the variable my_data into a new variable called my_data_sorted.

During the process of sorting replicates basic statistical analysis for each condition is done (mean and standard deviation of replicates).

This will generate a new variable called statistics necessary for the next part of the pipeline.

## 2D/3D data representation: barplot_data()

This function allows the user to generate 2D and 3D plots corresponding to two flavours (cell counts, percentages).

Before running the function, the user can define one of the experiment parameters

flavours are:

- `counts`: cell count

- `percent`: fluorochrome positive cell percentage

Output.parameters are:

are:

- plt.title: Barplot title

`slot(MACSQuant,"param.output")$plt.title` this will be used as subtitle for the Word document.

- plt.labels: Barplot labels

`slot(MACSQuant,"param.output")$plt.labels`

- the user can also load specific colors:

    plt.col <-
        c(
            heat.colors(length(slot(MACSQuant, "param.experiment")$c_names)), 1)

    plt.labels <- c(slot(MACSQuant, "param.experiment")$c_names, "Control")

    slot(MACSQuant, "param.output")$plt.title <- "Custom title example"

The barplot_data() function is ready to run

    flav <- "counts"
    p_counts <- barplot_data(MACSQuant,
        plt.col = plt.col,
        plt.flavour = flav,
        plt.labels = plt.labels,
        plt.combo = TRUE,
        xlab = "Drug1",
        ylab = "Drug2")

    ## Warning in geom_bar(position = position_dodge(), stat = "identity", colour =
    ## "black", : Ignoring unknown parameters: `size`

    grid.arrange(p_counts)

    flav <- "percent"
    p_percent <- barplot_data(MACSQuant,
        plt.col = plt.col,
        plt.flavour = flav,
        plt.labels = plt.labels,
        plt.combo = TRUE,
        xlab = "Drug1",
        ylab = "Drug2")

    ## Warning in geom_bar(position = position_dodge(), stat = "identity", colour =
    ## "black", : Ignoring unknown parameters: `size`

    grid.arrange(p_percent)

Save the generated plots else they will not appear in the excel document:

    # flav='counts'
    ggsave(paste(MACSQuant@param.output$path,
        "/outputMQ/barplot_", flav, ".png", sep = ""),
    width = 31.75, height = 15.875,
    units = "cm", p_counts)
    # flav='percent'
    ggsave(paste(MACSQuant@param.output$path,
        "/outputMQ/barplot_", flav, ".png", sep = ""),
    width = 31.75, height = 15.875,
    units = "cm", p_percent)

## Combination index computation: combination_index()

This function allows the user to compute combination index as computed by Chou TC, Pharmacol Rev. 20061.

Four plots are generated by this function:

- The dose response plot for drugs alone
- The median effect plot (log dose vs log(response/1-response))
- The normalized isobologram with synergism decision
- The 3D barplot with synergy corresponding color code

    MACSQuant <- combination_index(MACSQuant)

    ## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
    ## ℹ Please use `linewidth` instead.
    ## ℹ The deprecated feature was likely used in the MACSQuantifyR package.
    ##   Please report the issue to the authors.
    ## This warning is displayed once per session.
    ## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
    ## generated.

    ## Warning: The `size` argument of `element_line()` is deprecated as of ggplot2 3.4.0.
    ## ℹ Please use the `linewidth` argument instead.
    ## ℹ The deprecated feature was likely used in the MACSQuantifyR package.
    ##   Please report the issue to the authors.
    ## This warning is displayed once per session.
    ## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
    ## generated.

    ## Warning: Use of `dose_rep_df$dataset` is discouraged.
    ## ℹ Use `dataset` instead.

    ## Warning: Use of `dose_rep_df$dataset` is discouraged.
    ## ℹ Use `dataset` instead.

    ## Warning: Use of `dose_rep_df$dataset` is discouraged.
    ## ℹ Use `dataset` instead.

    ## `geom_smooth()` using formula = 'y ~ x'

    ## Warning: Use of `CI_df$Decision` is discouraged.
    ## ℹ Use `Decision` instead.

## Report generation: generate_report()

This function uses all the files saved during the analysis (argument save.files=T).

The save.files option creates a folder called outputMQ in your current directory (default) or at specified path and save:

- The well plate template image (plate_template.png)
- The sorted_replicates data table (sorted_table.txt)
- The statistic table (statistics.txt)
- Plots barplot_counts, barplot_percent
- Any other generated plots

Be careful to avoid overriding data, content of existing outputMQ folder could be erased.

You can run generate_report at any steps of the pipeline to generate the Word document named results.docx.

    generate_report(MACSQuant)

# Links

- You can find an example of the report generated by the step-by-step analysis() at this address: https://github.com/Peyronlab/MACSQuantifyR

- Also a version of this package is available as an excel macro at this address: https://github.com/Peyronlab/MACSQuantifyXL

# Reference

1.
Chou, T.-C. Theoretical basis, experimental design, and computerized simulation of synergism and antagonism in drug combination studies. Pharmacological reviews 58, 621–681 (2006).