---
title: "Processing Kotliarov-2020 CITEseq data (used in dsb paper)"
author: "Stephany Orjuela"
date: "August 27, 2020"
output: 
 BiocStyle::html_document:
    titlecaps: false
    toc_float: true
bibliography: ../ref.bib
---

```{r setup, echo=FALSE, results='hide', message=FALSE}
library(BiocStyle)
knitr::opts_chunk$set(error=FALSE, message=FALSE, warning=FALSE)
```

# Download the data

We obtain a single-cell RNA sequencing dataset of the human PBMCs from @kotliarov2020citeseq.
Counts for endogenous genes and antibody-derived tags (ADTs) are available from [figshare](https://nih.figshare.com/collections/Data_and_software_code_repository_for_Broad_immune_activation_underlies_shared_set_point_signatures_for_vaccine_responsiveness_in_healthy_individuals_and_disease_activity_in_patients_with_lupus_Kotliarov_Y_Sparks_R_et_al_Nat_Med_DOI_https_d/4753772).

Code used to analyze the data is available in the same link.

Of particular interest is the `H1_day0_demultilexed_singlets.RDS` file, 
which is a Seurat object that contains demultiplexed counts (filtered for singlets). 
Demultiplexing was performed with HTO counts and verified with demuxlet. 
Counts available have not been filtered by QC or normalized.

```{r}
library(BiocFileCache)
bfc <- BiocFileCache("raw_data", ask = FALSE)
contents <- bfcrpath(bfc,
    "https://nih.figshare.com/ndownloader/files/20706642")

seuratObj <- readRDS(contents)
```

# Extract elements from Seurat object

First we extract the RNA counts:

```{r}
library(S4Vectors)
rna.mat <- seuratObj@data
dim(rna.mat)

coldata <- DataFrame(seuratObj@meta.data)
nrow(coldata)
colnames(coldata)
```

Then the ADT counts:

```{r}
adt.mat <- seuratObj@assay$CITE@raw.data
dim(adt.mat)
```

# Save for upload
 
We now save all of the relevant components to file for upload to `r Biocpkg("ExperimentHub")`.

```{r}
repath <- file.path("scRNAseq", "kotliarov-pbmc", "2.4.0")
dir.create(repath, showWarnings=FALSE, recursive=TRUE)
saveRDS(coldata, file=file.path(repath, "coldata.rds"))
saveRDS(rna.mat, file=file.path(repath, "counts-rna.rds"))
saveRDS(adt.mat, file=file.path(repath, "counts-adt.rds"))
```

# Session info

```{r}
sessionInfo()
```

# References
