---
title: "ECCITEseq Peripheral Blood"
author: "Dario Righelli"
date: "`r format(Sys.time(), '%d %B, %Y')`"
output:
    BiocStyle::html_document:
      toc_float: true
vignette: >
    %\VignetteIndexEntry{ECCITEseq Peripheral Blood}
    %\VignetteEncoding{UTF-8}
    %\VignetteEngine{knitr::rmarkdown}
package: SingleCellMultiModal
bibliography: ../inst/REFERENCES.bib
editor_options:
  chunk_output_type: console
---

# Installation 

```{r,eval=FALSE}
if (!requireNamespace("BiocManager", quietly = TRUE))
    install.packages("BiocManager")

BiocManager::install("SingleCellMultiModal")
```


# Load libraries

```{r, include=TRUE, results="hide", message=FALSE, warning=FALSE}

library(MultiAssayExperiment)
library(SingleCellMultiModal)
library(SingleCellExperiment)

```


# ECCITE-seq dataset

ECCITE-seq data are an evolution of the CITE-seq data 
(see also [CITE-seq vignette](CITEseq.html) for more details)
by extending the CITE-seq original data types with a third one always extracted
from the same cell.
Indeed, in addition to the CITE-seq providing scRNA-seq and antibody-derived tags
(ADT), it provides around ten Hashtagged Oligo (HTO).
In particular this dataset is provided by @mimitou2019multiplexed.

## Downloading datasets

The user can see the available dataset by using the default options through the
CITE-seq function.

```{r}

CITEseq(DataType="peripheral_blood", modes="*", dry.run=TRUE, version="1.0.0")

```

Or simply by setting `dry.run = FALSE` it downloads the data and by default 
creates the `MultiAssayExperiment` object.

In this example, we will use one of the two available datasets `scADT_Counts`:

```{r message=FALSE}

mae <- CITEseq(DataType="peripheral_blood", modes="*", dry.run=FALSE, version="1.0.0")
mae
```

Example with actual data:

```{r}
experiments(mae)
```

Additionally, we stored into the object metedata 

## Exploring the data structure

Check row annotations:

```{r}
rownames(mae)
```

Take a peek at the `sampleMap`:

```{r}
sampleMap(mae)
```


## scRNA-seq data

The scRNA-seq data are accessible with the name `scRNAseq`, which returns a
*matrix* object.

```{r}
head(experiments(mae)$scRNA)[, 1:4]
```

## scADT data

The scADT data are accessible with the name `scADT`, which returns a
**matrix** object.

```{r}
head(experiments(mae)$scADT)[, 1:4]
```

## CTCL/CTRL conditions

The dataset has two different conditions (CTCL and CTRL) which samples can be identified with the `colData` accessor.

CTCL stands for cutaneous T-cell lymphoma while CTRL for control.

For example, if we want only the CTCL samples, we can run:

```{r}
(ctclMae <- mae[,colData(mae)$condition == "CTCL",])
```

And if you're interested into the common samples across all the modalities
you can use the `complete.cases` funtion.

```{r}
ctclMae[,complete.cases(ctclMae),]
```

 
## sgRNAs CRISPR pertubation data

The CRISPR perturbed scRNAs data are stored in a different spot 
to keep their original long format.

They can be accessed with the `metadata` accessors which, in this case returns a named `list` of `data.frame`s.

```{r}
sgRNAs <- metadata(mae)
names(sgRNAs)
```

There are four different sgRNAs datasets, one per each condition and family receptors combination.

TCR stands for T-Cell Receptor, while a,b,g,d stand for alpha, beta, gamma and delta respectively.

To look into the TCRab, simply run:

```{r}
head(sgRNAs$CTCL_TCRab)
```

# SingleCellExperiment object conversion

Because of already large use of some methodologies (such as
in the [SingleCellExperiment vignette][1] or [CiteFuse Vignette][2] where the
`SingleCellExperiment` object is used for CITE-seq data,
we provide a function for the conversion of our CITE-seq `MultiAssayExperiment`
object into a `SingleCellExperiment` object with scRNA-seq data as counts and
scADT data as `altExp`s.


```{r message=FALSE}
sce <- CITEseq(DataType="peripheral_blood", modes="*", dry.run=FALSE, 
               version="1.0.0", DataClass="SingleCellExperiment")
sce
```

# Session Info

```{r, tidy=TRUE}
sessionInfo()
```

# Additional References

https://www.bioconductor.org/packages/release/bioc/vignettes/SingleCellExperiment/inst/doc/intro.html#5_adding_alternative_feature_sets
http://www.bioconductor.org/packages/release/bioc/vignettes/CiteFuse/inst/doc/CiteFuse.html

# References
