# MACSQuantifyR - Automatic pipeline

# Requirements

1. Four columns MACSQuantify miltenyi Excel output file with P1 and P1//P2 gates namely

- `Full path`

- `WID`

- `%-#`

- `Count/mL`

2. Up to date version of R is recommended

# Running the pipeline() function

This function will sequentially:

1. Load the Excel file from the provided path
2. Display a graphical interface on which the user can easily select his replicates
3. Compute basic statistics on the replicates
4. Generate graphical representations
5. Save all intermediate files in the default output folder
6. Generate a Word report for the user

## Load the packages to make the function available

    library(MACSQuantifyR)
    library(knitr)
    library(grid)
    library(gridExtra)
    library(png)
    suppressMessages(library(R.utils))

This is an example file loaded with the package:

    file <- system.file("extdata", "drugs.xlsx",
        package = "MACSQuantifyR")

    ## [1] "drugs.xlsx"

This is what the beginning of the file looks like:

Full path | WID | %-# | Count/mL
--- | --- | --- | ---
drug1_drug2.00011 | A2 | 97.65 | 1808170.53
drug1_drug2.000112+ | A2 | 0.19 | 3162.50
drug1_drug2.00021 | B2 | 98.34 | 1604562.87
drug1_drug2.000212+ | B2 | 1.63 | 24065.21
drug1_drug2.00031 | C2 | 98.29 | 1546340.58
drug1_drug2.000312+ | C2 | 1.70 | 24367.10

## Run the function

This line will generate a plot on which the user has to manually select the replicates.

Once the replicates of all conditions have been identified by the user, the on_plate_selection function will automatically reorder the data and process them.

In the following example, the user is screening for the effect of two drugs on human cell lines at different concentrations.

Each of the 8 conditions contain 3 replicates. (`number_of_replicates = 3`, `number_of_conditions = 8`)

(i.e: Drug1_c1 is the concentration for drug1 at concentration c1 and the replicates are B2, C2 ,D2).

One can specify `control=T` if a control condition needs to be processed.

    MACSQuant <- pipeline(filepath = file,
        sheet_name = NULL, # optional
        number_of_replicates = 3,
        number_of_conditions = 8,
        control = T)

The user is notified as the function goes along its tasks.

    ## ...To quit press ESC...
    ##  ...You can now select your conditions replicates (without control condition replicates)...
    ##      --> 18 conditions:...1...2...3...4...5...6...7...8...OK
    ##      --> Done: replicates identified
    ##      --> Done: statistics on each condition replicates
    ##  ...You can now select your control replicates...
    ##      --> 1 control: ...OK...
    ##      --> Done: statistics on each control replicates
    ##  --> Done: replicates stored in variable my_replicates_sorted

The user may encounter warnings:

    ## Warning: In order_data(sorted_matrix_final, my_data, save.files = save.files) :
    ##  !!! A2 not selected and will be ignored

This warning tells the user that there were some conditions that were not selected. Here A2 stands for the calibration well and should not be used in this analysis.

## Access the results

The function will create a folder called outputMQ in your current directory and save:

- The well plate template image (plate_template.png)
- The sorted_replicates data table (sorted_table.txt)
- The statistic table (statistics.txt)

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

The results presented below can be found in the generated report file (results.docx)

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

### Statistics

During the process of sorting replicates basic statistical analysis for each condition is done (mean and standard deviation of replicates). A statistic table will be generated.

This is the statistic table for this example:

Full.path.first | WID.first | Fluo.percent.plus | Fluo.percent.minus | sd_percent | Cell.count.minus | sd_count
--- | --- | --- | --- | --- | --- | ---
drug1_drug2.0002 | B2 | 0.0167 | 0.9833 | 0.0004 | 1597223.65 | 84858.585
drug1_drug2.0010 | D3 | 0.0191 | 0.9809 | 0.0007 | 1589819.85 | 63798.371
drug1_drug2.0014 | B4 | 0.0206 | 0.9794 | 0.0024 | 1684061.45 | 70797.925
drug1_drug2.0022 | D5 | 0.0221 | 0.9779 | 0.0016 | 1596081.11 | 81344.714
drug1_drug2.0026 | B6 | 0.0369 | 0.9631 | 0.0010 | 1439527.91 | 66097.999
drug1_drug2.0034 | D7 | 0.0727 | 0.9273 | 0.0143 | 889007.26 | 43727.045
drug1_drug2.0038 | B8 | 0.2518 | 0.7482 | 0.0133 | 531432.84 | 18746.118
drug1_drug2.0046 | D9 | 0.4110 | 0.5890 | 0.0197 | 361538.77 | 43531.464
drug1_drug2.0050 | B10 | 0.8340 | 0.1660 | 0.0122 | 80131.12 | 5136.872

In this table the user will find for each conditions:

- the name (full path) and the WID of the first replicate
- the mean of percentage over replicates of cells that incorporated the fluorochrome: Fluo.percent.plus and Fluo.percent.minus (here mortality experiment with DAPI gates)
- the standard variation for the aforementioned percentages over replicates
- the mean of cell counts over replicates
- the standard deviation of cell count over replicates

### Graphical representations

After computing the statistics table, the function starts to generate graphical representations and provides the user with two plots

# Define output and experimental parameters (optional)

In order to define more parameters and to have more exhaustive graphical representations such as:

- experiment name
- condition names
- custom colors
- names label
- doses labels
- …

please have a look to the step-by-step analysis vignette

# Links

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