---
title: "Data Loading and Transformation"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Data Loading and Transformation}
  %\VignetteEncoding{UTF-8}
  %\VignetteEngine{knitr::rmarkdown}
editor_options: 
  markdown: 
    wrap: 72
---

```{r setup, warning=FALSE, message=FALSE}
library(cyCONDOR)
```

# How to load data

`cyCONDOR` provides an integrated function to prepare a `condor` object (flow cytometry dataset) starting from the input files in either `.fcs` or `.csv` format. All files should be saved in a single directory which path should be stated in `data_path`. The user can define the number of (cells) to process from each file within 'max_cell'. If the input type is `.csv` the `useCSV` setting should be set to `TRUE`. Is important to keep in mind that currently all files in the `data_path` folder are loaded independently from which are also included in the annotation table, this can induce slight differences in auto-logicle transformation, to avoid this only include in the `data_path` the files you plan to analyse.

For data transformation `cyCONDOR` provides different options:

- `auto_logi`: For HDFC and Spectral Flow data (recommended, auto-logicle transformation). This transformation gives good results also with cyTOF data, especially if you are experiencing a lot of noise with `arcsinh` due to negative values. auto-logicle transformation is inherited from the `Cytofkit` package [Chen er al. 2016](https://pubmed.ncbi.nlm.nih.gov/27662185/).
- `clr`: Recommended for CITE-seq data (centered log ratio transformation)
- `arcsinh`: arcsinh transformation, common transformation for CyTOF data. By default a co-factor of 5 is used (optimal setting for most CyTOF dataset), for conventional cytometry a co-factor of 150 is usually suggested. For spectral data higher co-factors might be needed and need to be tested in individual cases.

The last important piece to build a `condor` object is the annotation table. The annotation table should contain all necessary metadata used for analysis as well a column containing the names of the input files and should be supplied as `.csv` file. The column containing the file names should be stated in 'filename_col'. Below an exemplary metadata table is shown.

```{r}
read.csv("../.test_files/metadata.csv")
```

Unwanted parameters that are not important for the downstream analysis (e.g. Time) and should be removed can be listed in `remove_param`. In the `prep_fcd` function we also set a `seed` for reproducibility since the subsetting to `max_cell` is otherwise randomized.

```{r}
condor <- prep_fcd(data_path = "../.test_files/fcs/", 
                   max_cell = 1000, 
                   useCSV = FALSE, 
                   transformation = "auto_logi", 
                   remove_param = c("FSC-H", "SSC-H", "FSC-W", "SSC-W", "Time"), 
                   anno_table = "../.test_files/metadata.csv", 
                   filename_col = "filename",
                   seed = 91)
```

# Session Info
```{r}
info <- sessionInfo()

info
```

