Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions .github/workflows/run_propeller.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Propeller compositional analysis

on:
push:
branches: [main]
paths:
- '04_compositional/propeller.qmd'
pull_request:
branches: [main]
paths:
- '04_compositional/propeller.qmd'
workflow_dispatch:

jobs:
r-propeller:
runs-on: ubuntu-22.04

env:
RENV_PATHS_ROOT: ~/.local/share/renv # persistent cache location

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install pandoc
run: sudo apt-get update && sudo apt-get install -y pandoc

- name: Set up R
uses: r-lib/actions/setup-r@v2

- name: Install system dependencies for R packages
run: |
sudo apt-get update
sudo apt-get install -y build-essential libcurl4-openssl-dev libssl-dev libxml2-dev libgit2-dev libmagick++-dev libharfbuzz-dev libfribidi-dev libglpk-dev
shell: bash

- name: Cache R packages (renv)
uses: actions/cache@v4
with:
path: ${{ env.RENV_PATHS_ROOT }}
key: ${{ runner.os }}-renv-${{ hashFiles('04_compositional/renv.lock') }}
restore-keys: |
${{ runner.os }}-renv-

- name: Set repositories
run: Rscript ubuntu.R

- name: Restore environment from renv.lock
run: |
install.packages("renv", repos = "https://cloud.r-project.org")
renv::restore(prompt = FALSE, lockfile = "04_compositional/renv.lock")
shell: Rscript {0}

- name: Set up Quarto
uses: quarto-dev/quarto-actions/setup@v2

- name: Run propeller report
id: render_qmd
run: |
cd 04_compositional
quarto render propeller.qmd
shell: bash

- name: Deploy HTML to gh-pages
if: success()
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git fetch origin gh-pages || git checkout --orphan gh-pages
git switch gh-pages || git checkout -b gh-pages
git add 04_compositional/propeller.html
git commit -m "Deploy propeller.html [skip ci]" || echo "No changes to commit"
git push origin gh-pages
shell: bash
194 changes: 194 additions & 0 deletions 04_compositional/propeller.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
---
title: "Celltype composition with Propeller"
author: "Harvard Chan Bioinformatics Core"
date: "`r Sys.Date()`"
format:
html:
number-sections: false
default-image-extension: svg
lightbox: true
callout-icon: false
format-links: true
toc: true
theme: sandstone
echo: true
eval: true
message: false
warning: false
code-copy: true
code-overflow: wrap
code-fold: true
code-line-numbers: true
embed-resources: true
standalone: true
html-math-method: katex
grid:
sidebar-width: 250px
body-width: 900px
margin-width: 300px
comments:
hypothesis: true
params:
project_file: ../information.R
knitr:
opts_chunk:
audodep: true
cache: false
cache.lazy: false
error: true
echo: false
fig-height: 5
fig.retina: 2
fig-width: 11
message: false
tidy: true
warning: false
---

```{r }
#| message: false
#| warning: false
stopifnot(R.version$major >= 4) # requires R4
if (compareVersion(R.version$minor, "3.1") < 0) warning("We recommend >= R4.3.1")
stopifnot(compareVersion(as.character(BiocManager::version()), "3.18") >= 0)
stopifnot(compareVersion(as.character(packageVersion("Seurat")), "5.0.0") >= 0)
```

This code is in this ![](https://img.shields.io/badge/status-draft-grey) revision.


```{r setup}
#| cache: false
#| message: false
#| warning: false
#| echo: false
# knitr::opts_chunk$set(echo = TRUE)
# Load libraries
library(knitr)
library(rmarkdown)

library(Seurat)
library(SummarizedExperiment)
library(SingleCellExperiment)
library(DEGreport)
library(pheatmap)
library(limma)

library(tidyverse)
library(data.table)
library(DT)
library(patchwork)

library(ggprism)
library(grafify)

library(future)
library(speckle)
# Set seed for reproducibility
set.seed(1454944673L)

ggplot2::theme_set(theme_prism(base_size = 12))
# https://grafify-vignettes.netlify.app/colour_palettes.html
# NOTE change colors here if you wish
scale_colour_discrete <- function(...) {
scale_colour_manual(..., values = as.vector(grafify:::graf_palettes[["kelly"]]))
}

if (future::supportsMulticore()) {
future::plan(future::multicore)
} else {
future::plan(future::multisession)
}
```

```{r sanitize_datatable}
sanitize_datatable <- function(df, ...) {
# remove dashes which cause wrapping
DT::datatable(df, ...,
rownames = gsub("-", "_", rownames(df)),
colnames = gsub("-", "_", colnames(df)),
options = list(scrollX = TRUE, ...)
)
}
```

## Load object and subset
Read in the full dataset Seurat object and subset to keep only cells from the conditions of interest (cold7 vs TN).

```{r load-data}
library(sccomp)
data("seurat_obj")
subset_seurat <- subset(x = seurat_obj, subset = sample %in% c("10x_6K", "SCP424_pbmc1", "SI-GA-G6", "SI-GA-H3"))
Idents(object = subset_seurat) <- "cell_group"
DefaultAssay(subset_seurat) <- "RNA"

# Create metadata df and factor celltype
meta <- subset_seurat@meta.data
meta$cell_group <- factor(meta$cell_group)
```

## Check count numbers of cells

```{r cellnumbers}
meta$type_sample <- paste0(meta$type, "_", meta$sample)
table(meta$type_sample, meta$cell_group)
```

## Run propeller

```{r run-propeller}
# working code; takes into account cell numbers
# NOTE adapt with your variables of interest
propres <- propeller(subset_seurat,
sample = subset_seurat$sample,
clusters = subset_seurat$cell_group,
group = subset_seurat$type
)

sanitize_datatable(propres)
```

## Proportions of cells table

To understand discordance with sccomp results, let's evaluate proportions and variability within group.


```{r}
props <- getTransformedProps(meta$cell_group,
meta$type_sample,
transform = "logit"
)

props$Proportions
```

```{r extracode}
#| eval: false
meta_propeller <- meta %>%
group_by(type, sample) %>%
distinct(sample)

designAS <- model.matrix(~ meta_propeller$type)
colnames(designAS) <- c("cancer", "healthy")

fit <- lmFit(props$TransformedProps, designAS)
fit <- eBayes(fit, robust = TRUE)

topTable(fit)
```
# Resources

* [Speckle vignette](http://127.0.0.1:29356/library/speckle/doc/speckle.html#finding-significant-differences-in-cell-type-proportions-using-propeller)
* [Application to mouse PBMC scRNA](https://phipsonlab.github.io/propeller-paper-analysis/RealDataAnalysis.html#Young_vs_Old)

# Conclusion

# R session

List and version of tools used for the QC report generation.

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


Loading