---
title: "Code comparison with Seurat"
author: "Stefano Mangiola"
date: "`r Sys.Date()`"
package: tidyseurat
output:
  html_vignette:
    toc_float: true
vignette: >
  %\VignetteEngine{knitr::knitr}
  %\VignetteIndexEntry{Code comparison with Seurat}
  %\usepackage[UTF-8]{inputenc}
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

Just as a quick example, we show how to filter cells based on sample size (number of cells) and UMAP location. You can imagine a similar example with more meaningful criteria.

tidyseurat

```{r}
library(dplyr)
library(Seurat)
library(tidyseurat)

tidy_object = pbmc_small %>% tidy()
seurat_object = pbmc_small

```


```{r}
tidy_object %>%
  add_count(file) %>%
  filter(PC_1 > 0 & n > 40)
```

Seurat

```{r}
pca_emb = Embeddings(object = seurat_object, reduction = "pca")
cell_pca = rownames(pca_emb[pca_emb[,1]>0,])
n =
  seurat_object@meta.data %>%
  add_count(file) %>%
  pull(n)
seurat_object = AddMetaData( object = seurat_object, metadata = n, col.name = 'n')
seurat_object %>%
  subset(cells = cell_pca) %>%
  subset( n < 40)

```