# Working with aggregate functions

Giulia Pais1*

1San Raffaele Telethon Institute for Gene Therapy - SR-Tiget, Via Olgettina 60, 20132 Milano - Italia

*giuliapais1@gmail.com, calabria.andrea@hsr.it

#### 8 April 2021

#### Package

ISAnalytics 1.0.11

# 1 Introduction

In this vignette we’re going to explain in detail how to use functions of the aggregate family, namely:

1. `aggregate_metadata`
2. `aggregate_values_by_key`

## 1.1 How to install ISAnalytics

To install the package run the following code:

    ## For release version
    if (!requireNamespace("BiocManager", quietly = TRUE)) {
          install.packages("BiocManager")
      }
    BiocManager::install("ISAnalytics")

    ## For devel version
    if (!requireNamespace("BiocManager", quietly = TRUE)) {
          install.packages("BiocManager")
      }
    # The following initializes usage of Bioc devel
    BiocManager::install(version = "devel")
    BiocManager::install("ISAnalytics")

To install from GitHub:

    # For release version
    if (!require(devtools)) {
        install.packages("devtools")
    }
    devtools::install_github("calabrialab/ISAnalytics",
        ref = "RELEASE_3_12",
        dependencies = TRUE,
        build_vignettes = TRUE
    )

    ## Safer option for vignette building issue
    devtools::install_github("calabrialab/ISAnalytics",
        ref = "RELEASE_3_12"
    )

    # For devel version
    if (!require(devtools)) {
        install.packages("devtools")
    }
    devtools::install_github("calabrialab/ISAnalytics",
        ref = "master",
        dependencies = TRUE,
        build_vignettes = TRUE
    )

    ## Safer option for vignette building issue
    devtools::install_github("calabrialab/ISAnalytics",
        ref = "master"
    )

    library(ISAnalytics)
    #> Loading required package: magrittr

## 1.2 Setting options

`ISAnalytics` has a verbose option that allows some functions to print additional information to the console while they’re executing. To disable this feature do:

    # DISABLE
    options("ISAnalytics.verbose" = FALSE)

    # ENABLE
    options("ISAnalytics.verbose" = TRUE)

Some functions also produce report in a user-friendly HTML format, to set this feature:

    # DISABLE HTML REPORTS
    options("ISAnalytics.widgets" = FALSE)

    # ENABLE HTML REPORTS
    options("ISAnalytics.widgets" = TRUE)

# 2 Aggregating metadata

We refer to information contained in the association file as “metadata”: sometimes it’s useful to obtain collective information based on a certain group of variables we’re interested in. The function `aggregate_metadata` does just that, according to the grouping variables, meaning the names of the columns in the association file to perform a `group_by` operation with, creates a summary which includes:

- `FusionPrimerPCRDate_min` - The minimum date in the group for this variable
- `LinearPCRDate_min` - The minimum date in the group for this variable
- `VCN_avg` - The mean of “VCN” column for each group
- `DNAngUsed_avg` - The mean of “DNAngUsed”column for each group
- `Kapa_avg` - The mean of “Kapa” column for each group
- `DNAngUsed_sum` - The sum of “DNAngUsed” column for each group
- `ulForPool_sum` - The sum of “ulForPool” column for each group
- `AggregateMeta_sum` - A string obtained by concatenation of all of the grouping variables separated by “_"

## 2.1 Typical workflow

Import the association file via `import_assocition_file`. If you need more information on import function please view the vignette “How to use import functions”.

    withr::with_options(list(ISAnalytics.widgets = FALSE), {
        path_AF <- system.file("extdata", "ex_association_file.tsv",
            package = "ISAnalytics"
        )

        root_correct <- system.file("extdata", "fs.zip",
            package = "ISAnalytics"
        )
        root_correct <- unzip_file_system(root_correct, "fs")
        association_file <- import_association_file(path_AF, root_correct)
    })
    #> *** Association file import summary ***
    #> i For detailed report please set option 'ISAnalytics.widgets' to TRUE
    #> * Parsing problems detected: TRUE
    #> * Date parsing problems: TRUE
    #> * Column problems detected: TRUE
    #> * NAs found in important columns: TRUE
    #> * File system alignment: no problems detected

Perform aggregation:

    aggregated_meta <- aggregate_metadata(association_file,
        grouping_keys = c(
            "SubjectID",
            "CellMarker",
            "Tissue", "TimePoint"
        ),
        import_stats = FALSE
    )

AggregateMeta | SubjectID | CellMarker | Tissue | TimePoint | FusionPrimerPCRDate_min | LinearPCRDate_min | VCN_avg | DNAngUsed_avg | Kapa_avg | DNAngUsed_sum | ulForPool_sum
--- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | ---
VA2020-mix10_NA_NA_0000 | VA2020-mix10 | NA | NA | 0000 | NA | NA | 0.70 | 100 | 26.54667 | 300 | 25.70
VA2020-mix11_NA_NA_0000 | VA2020-mix11 | NA | NA | 0000 | NA | NA | 2.80 | 100 | 59.81000 | 300 | 12.29
VA2020-mix12_NA_NA_0000 | VA2020-mix12 | NA | NA | 0000 | NA | NA | 4.30 | 100 | 79.80333 | 300 | 7.98
VA2020-mix13_NA_NA_0000 | VA2020-mix13 | NA | NA | 0000 | NA | NA | 9.89 | 100 | 85.87000 | 300 | 7.46
VA2020-mix14_NA_NA_0000 | VA2020-mix14 | NA | NA | 0000 | NA | NA | NaN | NaN | NaN | 0 | 0.00

As you can see there is an additional parameter you can set, `import_stats`: if set to `TRUE`, the function will automatically look into the file system you provided as root when you imported the association file and will try to locate first the `iss` folder for each project and then all Vispa2 “stats” files.
Vispa2 stats contain useful information that is not included in the association file and is linked to the single Vispa2 run. In some cases it’s useful to perform aggregation on those info too. If you set the parameter to `TRUE`, besides the columns mentioned before you will also have:

- `BARCODE_MUX_sum` - The sum of the “BARCODE_MUX” column for the group
- `TRIMMING_FINAL_LTRLC_sum` - The sum of the “TRIMMING_FINAL_LTRLC” column for the group
- `LV_MAPPED_sum` - The sum of the “LV_MAPPED” column for the group
- `BWA_MAPPED_OVERALL_sum` - The sum of the “BWA_MAPPED_OVERALL” column for the group
- `ISS_MAPPED_PP_sum` - The sum of the “ISS_MAPPED_PP” column for the group

    withr::with_options(list(ISAnalytics.widgets = FALSE), {
        aggregated_meta <- aggregate_metadata(association_file,
            grouping_keys = c(
                "SubjectID", "CellMarker",
                "Tissue", "TimePoint"
            ),
            import_stats = TRUE
        )
    })
    #> [1] "--- REPORT IMPORT VISPA2STATS: FILES IMPORTED ---"
    #> # A tibble: 4 x 4
    #>   ProjectID
    #>   <chr>
    #> 1 CLOEXP
    #> 2 PROJECT1100
    #> 3 PROJECT1100
    #> 4 PROJECT1101
    #>   stats_path
    #>   <fs::path>
    #> 1 C:/Users/biocbuild/bbs-3.12-bioc/tmpdir/RtmpMJAXdJ/fs/VA/CLOEXP/iss/POOL6-1
    #> 2 C:/Users/biocbuild/bbs-3.12-bioc/tmpdir/RtmpMJAXdJ/fs/PROJECT1100/iss/ABX-LR-~
    #> 3 C:/Users/biocbuild/bbs-3.12-bioc/tmpdir/RtmpMJAXdJ/fs/PROJECT1100/iss/ABX-LR-~
    #> 4 C:/Users/biocbuild/bbs-3.12-bioc/tmpdir/RtmpMJAXdJ/fs/PROJECT1101/iss/ABY-LR-~
    #>   stats_files
    #>   <fs::path>
    #> 1 C:/Users/biocbuild/bbs-3.12-bioc/tmpdir/RtmpMJAXdJ/fs/VA/CLOEXP/iss/POOL6-1/s~
    #> 2 C:/Users/biocbuild/bbs-3.12-bioc/tmpdir/RtmpMJAXdJ/fs/PROJECT1100/iss/ABX-LR-~
    #> 3 C:/Users/biocbuild/bbs-3.12-bioc/tmpdir/RtmpMJAXdJ/fs/PROJECT1100/iss/ABX-LR-~
    #> 4 C:/Users/biocbuild/bbs-3.12-bioc/tmpdir/RtmpMJAXdJ/fs/PROJECT1101/iss/ABY-LR-~
    #>   Imported
    #>   <lgl>
    #> 1 TRUE
    #> 2 TRUE
    #> 3 TRUE
    #> 4 TRUE

AggregateMeta | SubjectID | CellMarker | Tissue | TimePoint | FusionPrimerPCRDate_min | LinearPCRDate_min | VCN_avg | DNAngUsed_avg | Kapa_avg | DNAngUsed_sum | ulForPool_sum | BARCODE_MUX_sum | TRIMMING_FINAL_LTRLC_sum | LV_MAPPED_sum | BWA_MAPPED_OVERALL_sum | ISS_MAPPED_PP_sum
--- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | ---
VA2020-mix10_NA_NA_0000 | VA2020-mix10 | NA | NA | 0000 | NA | NA | 0.70 | 100 | 26.54667 | 300 | 25.70 | 19489792 | 19455728 | 8457580 | 10476016 | 9544692
VA2020-mix11_NA_NA_0000 | VA2020-mix11 | NA | NA | 0000 | NA | NA | 2.80 | 100 | 59.81000 | 300 | 12.29 | 34294696 | 34199968 | 13941856 | 19007548 | 14986620
VA2020-mix12_NA_NA_0000 | VA2020-mix12 | NA | NA | 0000 | NA | NA | 4.30 | 100 | 79.80333 | 300 | 7.98 | 23364272 | 23274392 | 11694244 | 10524788 | 7752560
VA2020-mix13_NA_NA_0000 | VA2020-mix13 | NA | NA | 0000 | NA | NA | 9.89 | 100 | 85.87000 | 300 | 7.46 | 24345956 | 24249196 | 9936136 | 13188028 | 9321144
VA2020-mix14_NA_NA_0000 | VA2020-mix14 | NA | NA | 0000 | NA | NA | NaN | NaN | NaN | 0 | 0.00 | 1161066 | 1156914 | 484480 | 620925 | 438088

If you have the option `ISAnalytics.widgets` set to TRUE, this will produce a report in HTML format that tells you which stats files were imported. To avoid this, you can set the option to FALSE.

# 3 Aggregation of values by key

`ISAnalytics` contains useful functions to aggregate the values contained in your imported matrices based on a key, aka a single column or a combination of columns contained in the association file that are related to the samples.

## 3.1 Typical workflow

Import your association file (see previous section) and then import your matrices:

    withr::with_options(list(ISAnalytics.widgets = FALSE), {
        matrices <- import_parallel_Vispa2Matrices_auto(
            association_file = association_file, root = NULL,
            quantification_type = c("fragmentEstimate", "seqCount"),
            matrix_type = "annotated", workers = 2, patterns = NULL,
            matching_opt = "ANY", multi_quant_matrix = FALSE
        )
    })
    #> [1] "--- REPORT: FILES IMPORTED ---"
    #> # A tibble: 8 x 5
    #>   ProjectID   concatenatePoolIDSeqRun Quantification_type
    #>   <chr>       <chr>                   <chr>
    #> 1 CLOEXP      POOL6-1                 fragmentEstimate
    #> 2 PROJECT1100 ABX-LR-PL5-POOL14-1     fragmentEstimate
    #> 3 PROJECT1100 ABX-LR-PL6-POOL15-1     fragmentEstimate
    #> 4 PROJECT1101 ABY-LR-PL4-POOL54-2     fragmentEstimate
    #> 5 CLOEXP      POOL6-1                 seqCount
    #> 6 PROJECT1100 ABX-LR-PL5-POOL14-1     seqCount
    #> 7 PROJECT1100 ABX-LR-PL6-POOL15-1     seqCount
    #> 8 PROJECT1101 ABY-LR-PL4-POOL54-2     seqCount
    #>   Files_chosen
    #>   <fs::path>
    #> 1 C:/Users/biocbuild/bbs-3.12-bioc/tmpdir/RtmpMJAXdJ/fs/VA/CLOEXP/quantificatio~
    #> 2 C:/Users/biocbuild/bbs-3.12-bioc/tmpdir/RtmpMJAXdJ/fs/PROJECT1100/quantificat~
    #> 3 C:/Users/biocbuild/bbs-3.12-bioc/tmpdir/RtmpMJAXdJ/fs/PROJECT1100/quantificat~
    #> 4 C:/Users/biocbuild/bbs-3.12-bioc/tmpdir/RtmpMJAXdJ/fs/PROJECT1101/quantificat~
    #> 5 C:/Users/biocbuild/bbs-3.12-bioc/tmpdir/RtmpMJAXdJ/fs/VA/CLOEXP/quantificatio~
    #> 6 C:/Users/biocbuild/bbs-3.12-bioc/tmpdir/RtmpMJAXdJ/fs/PROJECT1100/quantificat~
    #> 7 C:/Users/biocbuild/bbs-3.12-bioc/tmpdir/RtmpMJAXdJ/fs/PROJECT1100/quantificat~
    #> 8 C:/Users/biocbuild/bbs-3.12-bioc/tmpdir/RtmpMJAXdJ/fs/PROJECT1101/quantificat~
    #>   Imported
    #>   <lgl>
    #> 1 TRUE
    #> 2 TRUE
    #> 3 TRUE
    #> 4 TRUE
    #> 5 TRUE
    #> 6 TRUE
    #> 7 TRUE
    #> 8 TRUE
    #> [1] "--- SUMMARY OF FILES CHOSEN FOR IMPORT ---"
    #> # A tibble: 8 x 4
    #>   ProjectID   concatenatePoolIDSeqRun Quantification_type
    #>   <chr>       <chr>                   <chr>
    #> 1 CLOEXP      POOL6-1                 fragmentEstimate
    #> 2 CLOEXP      POOL6-1                 seqCount
    #> 3 PROJECT1100 ABX-LR-PL5-POOL14-1     fragmentEstimate
    #> 4 PROJECT1100 ABX-LR-PL5-POOL14-1     seqCount
    #> 5 PROJECT1100 ABX-LR-PL6-POOL15-1     fragmentEstimate
    #> 6 PROJECT1100 ABX-LR-PL6-POOL15-1     seqCount
    #> 7 PROJECT1101 ABY-LR-PL4-POOL54-2     fragmentEstimate
    #> 8 PROJECT1101 ABY-LR-PL4-POOL54-2     seqCount
    #>   Files_chosen
    #>   <fs::path>
    #> 1 C:/Users/biocbuild/bbs-3.12-bioc/tmpdir/RtmpMJAXdJ/fs/VA/CLOEXP/quantificatio~
    #> 2 C:/Users/biocbuild/bbs-3.12-bioc/tmpdir/RtmpMJAXdJ/fs/VA/CLOEXP/quantificatio~
    #> 3 C:/Users/biocbuild/bbs-3.12-bioc/tmpdir/RtmpMJAXdJ/fs/PROJECT1100/quantificat~
    #> 4 C:/Users/biocbuild/bbs-3.12-bioc/tmpdir/RtmpMJAXdJ/fs/PROJECT1100/quantificat~
    #> 5 C:/Users/biocbuild/bbs-3.12-bioc/tmpdir/RtmpMJAXdJ/fs/PROJECT1100/quantificat~
    #> 6 C:/Users/biocbuild/bbs-3.12-bioc/tmpdir/RtmpMJAXdJ/fs/PROJECT1100/quantificat~
    #> 7 C:/Users/biocbuild/bbs-3.12-bioc/tmpdir/RtmpMJAXdJ/fs/PROJECT1101/quantificat~
    #> 8 C:/Users/biocbuild/bbs-3.12-bioc/tmpdir/RtmpMJAXdJ/fs/PROJECT1101/quantificat~
    #> [1] "--- INTEGRATION MATRICES FOUND REPORT ---"
    #> # A tibble: 8 x 5
    #>   ProjectID   concatenatePoolIDSeqRun Anomalies Quantification_type
    #>   <chr>       <chr>                   <lgl>     <chr>
    #> 1 CLOEXP      POOL6-1                 FALSE     fragmentEstimate
    #> 2 CLOEXP      POOL6-1                 FALSE     seqCount
    #> 3 PROJECT1100 ABX-LR-PL5-POOL14-1     FALSE     fragmentEstimate
    #> 4 PROJECT1100 ABX-LR-PL5-POOL14-1     FALSE     seqCount
    #> 5 PROJECT1100 ABX-LR-PL6-POOL15-1     FALSE     fragmentEstimate
    #> 6 PROJECT1100 ABX-LR-PL6-POOL15-1     FALSE     seqCount
    #> 7 PROJECT1101 ABY-LR-PL4-POOL54-2     FALSE     fragmentEstimate
    #> 8 PROJECT1101 ABY-LR-PL4-POOL54-2     FALSE     seqCount
    #>   Files_found
    #>   <fs::path>
    #> 1 C:/Users/biocbuild/bbs-3.12-bioc/tmpdir/RtmpMJAXdJ/fs/VA/CLOEXP/quantificatio~
    #> 2 C:/Users/biocbuild/bbs-3.12-bioc/tmpdir/RtmpMJAXdJ/fs/VA/CLOEXP/quantificatio~
    #> 3 C:/Users/biocbuild/bbs-3.12-bioc/tmpdir/RtmpMJAXdJ/fs/PROJECT1100/quantificat~
    #> 4 C:/Users/biocbuild/bbs-3.12-bioc/tmpdir/RtmpMJAXdJ/fs/PROJECT1100/quantificat~
    #> 5 C:/Users/biocbuild/bbs-3.12-bioc/tmpdir/RtmpMJAXdJ/fs/PROJECT1100/quantificat~
    #> 6 C:/Users/biocbuild/bbs-3.12-bioc/tmpdir/RtmpMJAXdJ/fs/PROJECT1100/quantificat~
    #> 7 C:/Users/biocbuild/bbs-3.12-bioc/tmpdir/RtmpMJAXdJ/fs/PROJECT1101/quantificat~
    #> 8 C:/Users/biocbuild/bbs-3.12-bioc/tmpdir/RtmpMJAXdJ/fs/PROJECT1101/quantificat~

The function `aggregate_values_by_key` can perform the aggregation both on the list of matrices and a single matrix.

    # Takes the whole list and produces a list in output
    aggregated_matrices <- aggregate_values_by_key(matrices, association_file)

    # Takes a single matrix and produces a single matrix as output
    aggregated_matrices_single <- aggregate_values_by_key(
        matrices$seqCount,
        association_file
    )

chr | integration_locus | strand | GeneName | GeneStrand | SubjectID | CellMarker | Tissue | TimePoint | Value_sum
--- | --- | --- | --- | --- | --- | --- | --- | --- | ---
1 | 4519734 | + | LINC01777 | + | VA2020-mix10 | NA | NA | 0000 | 8
1 | 8426336 | - | RERE | - | VA2020-mix10 | NA | NA | 0000 | 4
1 | 8884086 | - | RERE | - | VA2020-mix11 | NA | NA | 0000 | 4
1 | 11322005 | - | MTOR | - | VA2020-mix10 | NA | NA | 0000 | 4
1 | 11772847 | + | DRAXIN | + | VA2020-mix11 | NA | NA | 0000 | 52
1 | 22453532 | + | WNT4 | - | VA2020-mix10 | NA | NA | 0000 | 8

### 3.1.1 Changing parameters to obtain different results

The function has several different parameters that have default values that can be changed according to user preference.

1. Changing the `key` value
   You can change the value of the parameter key as you see fit. This parameter should contain one or multiple columns of the association file that you want to include in the grouping when performing the aggregation. The default value is set to `c("SubjectID", "CellMarker", "Tissue", "TimePoint")` (same default key as the `aggregate_metadata` function.

    agg1 <- aggregate_values_by_key(
        x = matrices$seqCount,
        association_file = association_file,
        key = c("SubjectID", "ProjectID")
    )

chr | integration_locus | strand | GeneName | GeneStrand | SubjectID | ProjectID | Value_sum
--- | --- | --- | --- | --- | --- | --- | ---
1 | 4519734 | + | LINC01777 | + | VA2020-mix10 | CLOEXP | 2
1 | 4519734 | + | LINC01777 | + | VA2020-mix10 | PROJECT1100 | 4
1 | 4519734 | + | LINC01777 | + | VA2020-mix10 | PROJECT1101 | 2
1 | 8426336 | - | RERE | - | VA2020-mix10 | CLOEXP | 1
1 | 8426336 | - | RERE | - | VA2020-mix10 | PROJECT1100 | 2
1 | 8426336 | - | RERE | - | VA2020-mix10 | PROJECT1101 | 1

2. Changing the `lambda` value
   The `lambda` parameter indicates the function(s) to be applied to the values for aggregation. `lambda` must be a named list of either functions or purrr-style lambdas: if you would like to specify additional parameters to the function the second option is recommended. The only important note on functions is that they should perform some kind of aggregation on numeric values: this means in practical terms they need to accept a vector of numeric/integer values as input and produce a SINGLE value as output. Valid options for this purpose might be: `sum`, `mean`, `median`, `min`, `max` and so on.

    agg2 <- aggregate_values_by_key(
        x = matrices$seqCount,
        association_file = association_file,
        key = "SubjectID",
        lambda = list(mean = ~ mean(.x, na.rm = TRUE))
    )

chr | integration_locus | strand | GeneName | GeneStrand | SubjectID | Value_mean
--- | --- | --- | --- | --- | --- | ---
1 | 4519734 | + | LINC01777 | + | VA2020-mix10 | 2
1 | 8426336 | - | RERE | - | VA2020-mix10 | 1
1 | 8884086 | - | RERE | - | VA2020-mix11 | 1
1 | 11322005 | - | MTOR | - | VA2020-mix10 | 1
1 | 11772847 | + | DRAXIN | + | VA2020-mix11 | 13
1 | 22453532 | + | WNT4 | - | VA2020-mix10 | 2

Note that, when specifying purrr-style lambdas (formulas), the first parameter needs to be set to `.x`, other parameters can be set as usual.

You can also use in `lambda` functions that produce data frames or lists. In this case all variables from the produced data frame will be included in the final data frame. For example:

    agg3 <- aggregate_values_by_key(
        x = matrices$seqCount,
        association_file = association_file,
        key = "SubjectID",
        lambda = list(describe = psych::describe)
    )

    agg3
    #> # A tibble: 1,272 x 7
    #>    chr   integration_locus strand GeneName GeneStrand SubjectID Value_describe$~
    #>    <chr>             <int> <chr>  <chr>    <chr>      <chr>                <dbl>
    #>  1 1               4519734 +      LINC017~ +          VA2020-m~                1
    #>  2 1               8426336 -      RERE     -          VA2020-m~                1
    #>  3 1               8884086 -      RERE     -          VA2020-m~                1
    #>  4 1              11322005 -      MTOR     -          VA2020-m~                1
    #>  5 1              11772847 +      DRAXIN   +          VA2020-m~                1
    #>  6 1              22453532 +      WNT4     -          VA2020-m~                1
    #>  7 1              25929388 -      MAN1C1   +          VA2020-m~                1
    #>  8 1              26950561 -      RPS6KA1  +          VA2020-m~                1
    #>  9 1              29116798 -      YTHDF2   +          VA2020-m~                1
    #> 10 1              30825358 -      LINC016~ -          VA2020-m~                1
    #> # ... with 1,262 more rows

3. Changing the `value_cols` value
   The `value_cols` parameter tells the function on which numeric columns of x the functions should be applied. NOte that every function contained in `lambda` will be applied to every column in `value_cols`: resulting columns will be named as “original name_function applied”.

    ## Obtaining multi-quantification matrix
    comp <- comparison_matrix(matrices)

    agg4 <- aggregate_values_by_key(
        x = comp,
        association_file = association_file,
        key = "SubjectID",
        lambda = list(sum = sum, mean = mean),
        value_cols = c("seqCount", "fragmentEstimate")
    )

chr | integration_locus | strand | GeneName | GeneStrand | SubjectID | seqCount_sum | seqCount_mean | fragmentEstimate_sum | fragmentEstimate_mean
--- | --- | --- | --- | --- | --- | --- | --- | --- | ---
1 | 4519734 | + | LINC01777 | + | VA2020-mix10 | 8 | 2 | 8.010711 | 2.002678
1 | 8426336 | - | RERE | - | VA2020-mix10 | 4 | 1 | 4.002137 | 1.000534
1 | 8884086 | - | RERE | - | VA2020-mix11 | 4 | 1 | 4.004477 | 1.001119
1 | 11322005 | - | MTOR | - | VA2020-mix10 | 4 | 1 | 4.002002 | 1.000501
1 | 11772847 | + | DRAXIN | + | VA2020-mix11 | 52 | 13 | 4.000695 | 1.000174
1 | 22453532 | + | WNT4 | - | VA2020-mix10 | 8 | 2 | 4.005724 | 1.001431

4. Changing the `group` value
   The `group` parameter should contain all other variables to include in the grouping besides `key`. By default this contains `c("chr", "integration_locus", "strand", "GeneName", "GeneStrand")`. You can change this grouping as you see fit, if you don’t want to add any other variable to the key, just set it to NULL.

    agg5 <- aggregate_values_by_key(
        x = matrices$seqCount,
        association_file = association_file,
        key = "SubjectID",
        lambda = list(sum = sum, mean = mean),
        group = c(mandatory_IS_vars())
    )

chr | integration_locus | strand | SubjectID | Value_sum | Value_mean
--- | --- | --- | --- | --- | ---
1 | 4519734 | + | VA2020-mix10 | 8 | 2
1 | 8426336 | - | VA2020-mix10 | 4 | 1
1 | 8884086 | - | VA2020-mix11 | 4 | 1
1 | 11322005 | - | VA2020-mix10 | 4 | 1
1 | 11772847 | + | VA2020-mix11 | 52 | 13
1 | 22453532 | + | VA2020-mix10 | 8 | 2

# 4 Reproducibility

The ISAnalytics package (calabrialab, 2021) was made possible thanks to:

- R (R Core Team, 2021)
- BiocStyle (Oles, Morgan, and Huber, 2021)
- knitcitations (Boettiger, 2021)
- knitr (Xie, 2021)
- rmarkdown (Allaire, Xie, McPherson, Luraschi, et al., 2021)
- sessioninfo (Csárdi, core, Wickham, Chang, et al., 2018)
- testthat (Wickham, 2011)

This package was developed using biocthis.

`R` session information.

    #> - Session info -------------------------------------------------------------------------------------------------------
    #>  setting  value
    #>  version  R version 4.0.5 (2021-03-31)
    #>  os       Windows Server 2012 R2 x64
    #>  system   x86_64, mingw32
    #>  ui       RTerm
    #>  language (EN)
    #>  collate  C
    #>  ctype    English_United States.1252
    #>  tz       America/New_York
    #>  date     2021-04-08
    #>
    #> - Packages -----------------------------------------------------------------------------------------------------------
    #>  package       * version date       lib source
    #>  assertthat      0.2.1   2019-03-21 [2] CRAN (R 4.0.4)
    #>  BiocManager     1.30.12 2021-03-28 [2] CRAN (R 4.0.4)
    #>  BiocParallel    1.24.1  2021-04-08 [2] Bioconductor
    #>  BiocStyle     * 2.18.1  2021-04-08 [2] Bioconductor
    #>  bookdown        0.21    2020-10-13 [2] CRAN (R 4.0.5)
    #>  bslib           0.2.4   2021-01-25 [2] CRAN (R 4.0.4)
    #>  cellranger      1.1.0   2016-07-27 [2] CRAN (R 4.0.5)
    #>  cli             2.4.0   2021-04-05 [2] CRAN (R 4.0.5)
    #>  colorspace      2.0-0   2020-11-11 [2] CRAN (R 4.0.5)
    #>  crayon          1.4.1   2021-02-08 [2] CRAN (R 4.0.4)
    #>  data.table      1.14.0  2021-02-21 [2] CRAN (R 4.0.5)
    #>  DBI             1.1.1   2021-01-15 [2] CRAN (R 4.0.4)
    #>  debugme         1.1.0   2017-10-22 [2] CRAN (R 4.0.5)
    #>  digest          0.6.27  2020-10-24 [2] CRAN (R 4.0.4)
    #>  dplyr           1.0.5   2021-03-05 [2] CRAN (R 4.0.4)
    #>  ellipsis        0.3.1   2020-05-15 [2] CRAN (R 4.0.4)
    #>  evaluate        0.14    2019-05-28 [2] CRAN (R 4.0.4)
    #>  fansi           0.4.2   2021-01-15 [2] CRAN (R 4.0.4)
    #>  forcats         0.5.1   2021-01-27 [2] CRAN (R 4.0.5)
    #>  fs              1.5.0   2020-07-31 [2] CRAN (R 4.0.4)
    #>  generics        0.1.0   2020-10-31 [2] CRAN (R 4.0.4)
    #>  ggplot2         3.3.3   2020-12-30 [2] CRAN (R 4.0.5)
    #>  ggrepel         0.9.1   2021-01-15 [2] CRAN (R 4.0.5)
    #>  glue            1.4.2   2020-08-27 [2] CRAN (R 4.0.4)
    #>  gtable          0.3.0   2019-03-25 [2] CRAN (R 4.0.5)
    #>  highr           0.8     2019-03-20 [2] CRAN (R 4.0.4)
    #>  hms             1.0.0   2021-01-13 [2] CRAN (R 4.0.5)
    #>  htmltools       0.5.1.1 2021-01-22 [2] CRAN (R 4.0.4)
    #>  htmlwidgets     1.5.3   2020-12-10 [2] CRAN (R 4.0.4)
    #>  httr            1.4.2   2020-07-20 [2] CRAN (R 4.0.4)
    #>  ISAnalytics   * 1.0.11  2021-04-08 [1] Bioconductor
    #>  jquerylib       0.1.3   2020-12-17 [2] CRAN (R 4.0.4)
    #>  jsonlite        1.7.2   2020-12-09 [2] CRAN (R 4.0.4)
    #>  knitcitations * 1.0.12  2021-01-10 [2] CRAN (R 4.0.5)
    #>  knitr           1.31    2021-01-27 [2] CRAN (R 4.0.4)
    #>  lattice         0.20-41 2020-04-02 [2] CRAN (R 4.0.5)
    #>  lifecycle       1.0.0   2021-02-15 [2] CRAN (R 4.0.4)
    #>  lubridate       1.7.10  2021-02-26 [2] CRAN (R 4.0.5)
    #>  magrittr      * 2.0.1   2020-11-17 [2] CRAN (R 4.0.4)
    #>  mnormt          2.0.2   2020-09-01 [2] CRAN (R 4.0.3)
    #>  munsell         0.5.0   2018-06-12 [2] CRAN (R 4.0.5)
    #>  nlme            3.1-152 2021-02-04 [2] CRAN (R 4.0.5)
    #>  pillar          1.5.1   2021-03-05 [2] CRAN (R 4.0.4)
    #>  pkgconfig       2.0.3   2019-09-22 [2] CRAN (R 4.0.4)
    #>  plyr            1.8.6   2020-03-03 [2] CRAN (R 4.0.5)
    #>  ps              1.6.0   2021-02-28 [2] CRAN (R 4.0.4)
    #>  psych           2.1.3   2021-03-27 [2] CRAN (R 4.0.5)
    #>  purrr           0.3.4   2020-04-17 [2] CRAN (R 4.0.4)
    #>  R6              2.5.0   2020-10-28 [2] CRAN (R 4.0.4)
    #>  Rcpp            1.0.6   2021-01-15 [2] CRAN (R 4.0.4)
    #>  reactable       0.2.3   2020-10-04 [2] CRAN (R 4.0.5)
    #>  readr           1.4.0   2020-10-05 [2] CRAN (R 4.0.5)
    #>  readxl          1.3.1   2019-03-13 [2] CRAN (R 4.0.5)
    #>  RefManageR      1.3.0   2020-11-13 [2] CRAN (R 4.0.5)
    #>  rlang           0.4.10  2020-12-30 [2] CRAN (R 4.0.4)
    #>  rmarkdown       2.7     2021-02-19 [2] CRAN (R 4.0.5)
    #>  rstudioapi      0.13    2020-11-12 [2] CRAN (R 4.0.4)
    #>  sass            0.3.1   2021-01-24 [2] CRAN (R 4.0.4)
    #>  scales          1.1.1   2020-05-11 [2] CRAN (R 4.0.5)
    #>  sessioninfo   * 1.1.1   2018-11-05 [2] CRAN (R 4.0.4)
    #>  snow            0.4-3   2018-09-14 [2] CRAN (R 4.0.4)
    #>  stringi         1.5.3   2020-09-09 [2] CRAN (R 4.0.3)
    #>  stringr         1.4.0   2019-02-10 [2] CRAN (R 4.0.4)
    #>  tibble          3.1.0   2021-02-25 [2] CRAN (R 4.0.4)
    #>  tidyr           1.1.3   2021-03-03 [2] CRAN (R 4.0.5)
    #>  tidyselect      1.1.0   2020-05-11 [2] CRAN (R 4.0.4)
    #>  tmvnsim         1.0-2   2016-12-15 [2] CRAN (R 4.0.3)
    #>  upsetjs         1.9.0   2021-02-15 [2] CRAN (R 4.0.5)
    #>  utf8            1.2.1   2021-03-12 [2] CRAN (R 4.0.4)
    #>  vctrs           0.3.7   2021-03-29 [2] CRAN (R 4.0.4)
    #>  withr           2.4.1   2021-01-26 [2] CRAN (R 4.0.4)
    #>  xfun            0.22    2021-03-11 [2] CRAN (R 4.0.4)
    #>  xml2            1.3.2   2020-04-23 [2] CRAN (R 4.0.4)
    #>  yaml            2.2.1   2020-02-01 [2] CRAN (R 4.0.4)
    #>  zip             2.1.1   2020-08-27 [2] CRAN (R 4.0.4)
    #>
    #> [1] C:/Users/biocbuild/bbs-3.12-bioc/tmpdir/RtmpCgYPdG/Rinst1cc0391c6c82
    #> [2] C:/Users/biocbuild/bbs-3.12-bioc/R/library

# 5 Bibliography

This vignette was generated using BiocStyle (Oles, Morgan, and Huber, 2021) with knitr (Xie, 2021) and rmarkdown (Allaire, Xie, McPherson, Luraschi, et al., 2021) running behind the scenes.

Citations made with knitcitations (Boettiger, 2021).

[1] J. Allaire, Y. Xie, J. McPherson, J. Luraschi, et al. rmarkdown: Dynamic Documents for R. R package version 2.7. 2021. <URL: https://github.com/rstudio/rmarkdown>.

[2] C. Boettiger. knitcitations: Citations for ‘Knitr’ Markdown Files. R package version 1.0.12. 2021. <URL: https://CRAN.R-project.org/package=knitcitations>.

[3] G. Csárdi, R. core, H. Wickham, W. Chang, et al. sessioninfo: R Session Information. R package version 1.1.1. 2018. <URL: https://CRAN.R-project.org/package=sessioninfo>.

[4] A. Oles, M. Morgan, and W. Huber. BiocStyle: Standard styles for vignettes and other Bioconductor documents. R package version 2.18.1. 2021. <URL: https://github.com/Bioconductor/BiocStyle>.

[5] R Core Team. R: A Language and Environment for Statistical Computing. R Foundation for Statistical Computing. Vienna, Austria, 2021. <URL: https://www.R-project.org/>.

[6] H. Wickham. “testthat: Get Started with Testing”. In: The R Journal 3 (2011), pp. 5-10. <URL: https://journal.r-project.org/archive/2011-1/RJournal_2011-1_Wickham.pdf>.

[7] Y. Xie. knitr: A General-Purpose Package for Dynamic Report Generation in R. R package version 1.31. 2021. <URL: https://yihui.org/knitr/>.

[8] calabrialab. Analyze gene therapy vector insertion sites data identified from genomics next generation sequencing reads for clonal tracking studies. https://github.com/calabrialab/ISAnalytics - R package version 1.0.11. 2021. DOI: 10.18129/B9.bioc.ISAnalytics. <URL: http://www.bioconductor.org/packages/ISAnalytics>.