Sélection | |
---|---|
project | Demonstration on ChKV |
rds | demochkv.rds |
path | /home/lohmann/immunopanc_jg/12_demochkv_sg/11_concat/ |
adcode | TRUE |
analyse_type | QC |
min_cells | 5 |
min_samples | 1 |
p_value | 0.001 |
cluster_id | cluster_id |
conditions | cond |
batch | acqdate |
individuals | patient_id |
ncells | Freq |
sorted | 1 |
log_bar | 1 |
cluster_column_id | marker |
id_mfi | shared_col |
Analysis Type : QC report
This document has been formated using knitr
(Xie 2015) and quarto
(Allaire 2022).
1 Features summary
Sample table with information on conditions (cond), batch (acqdate), individuals (patient_id), ncells (Freq)
Information on metaclusters is grouped in this table with the number of cells and the corresponding description.
A total of 39 markers are included in this analysis report.
The exhaustive list of markers is as follows: Bi209Di, Dy161Di, Dy162Di, Dy163Di, Dy164Di, Er166Di, Er167Di, Er168Di, Er170Di, Eu151Di, Eu153Di, Gd155Di, Gd156Di, Gd158Di, Gd160Di, Ho165Di, In113Di, In115Di, Lu175Di, Nd142Di, Nd143Di, Nd144Di, Nd145Di, Nd146Di, Nd148Di, Nd150Di, Pt194Di, Pt198Di, Sm147Di, Sm149Di, Sm152Di, Sm154Di, Tb159Di, Tm169Di, Yb171Di, Yb172Di, Yb173Di, Yb174Di, Yb176Di.
2 Number of cells Barplot
Check the number of cells in each fcs.
Controls the possible association with a batch effect.
Bars are sorted by conditions. Annotations columns are added on the barplot’s top to control possible batch effects.
3 MFI’s Heatmap
- Check or help annotate clusters.
The input is the MFI cluster x marker array. The MFI is already transformed (typically using asinh(intensity/cofactor)).
Heatmap of the MFI with clusters in rows and markers in columns.
A barplot shows the number of cells in each metacluster.
The first heatmap covers all fcs.
4 Mfi x Abundance Heatmap
Heatmap grouping the MFI of each marker per cluster and cluster abundance per fcs.
MFIs are normalized per line between 0 and 1 to give a comparable distribution of marker expression per cluster.
Markers are grouped hierarchically to facilitate cluster reading/interpretation.
Relative abundances shown on the second heat map are transformed abundances relative to the cluster mean. The green-purple color scale applies to the entire matrix.
5 Abundance Heatmap
Visualize samples organized according to hierarchical grouping or by condition.
Check that sample states are homogeneous; identify outliers or gender effects.
Check whether conditions have already been separated.
Percentage heatmap with samples in columns and clusters in rows.
By default, clusters and samples are grouped using hierarchical clustering. It is also possible to classify samples by condition, gender or patient, and to give clusters as an ordered vector.
Group abundance is shown in the right-hand barplot with log values.
6 PCA (or NMDS) of samples using percentages per cluster
Visualize samples in a reduced space.
Check that sample states are homogeneous; identify outliers or gender effects.
Check whether conditions can already be separated.
Input is the percentages table sample x cluster. Percentages are previously transformed with asinh(%+cte) with cte = 0.03 and centered by cluster.
6.1 Barplot of variance of each PC
- check that the first 2 or 3 components retains the main information
3 graphs as below ; points are samples. Overimpose conditions or Genders on each points using color and shape.
7 Plots of variables in order to identify their contribution to each PC
PCA (or NMDS) of samples using MFI per cluster Similar to Nowicka et al., but at the clustering level (not the cell level).
View the samples in a reduced space.
Verify that States of samples are homogeneous; identify outliers or Gender effects.
Check if the conditions could already be separated.
Input is the MFI table sample x cluster. MFI are previously transformed.
Code
Code
# css: www/custom.css
# js: www/script.js
#| include=F
library(R.AnalytiCyte)
library(readr)
library(dplyr)
library(SummarizedExperiment)
library(diffcyt)
library(ComplexHeatmap)
library(RColorBrewer)
library(randomcoloR)
library(colorRamp2)
library(data.table)
library(tidyr)
library(ggplot2)
library(ggrepel)
library(grid)
library(kableExtra)
library(tibble)
library(plotly)
library(reactable)
# parameters set
<- dataSE$SE_abundance
se rowData(se) |>
as.data.frame() %>%
mutate(cluster_id = factor(cluster_id, levels = rownames(se))) %>%
arrange(cluster_id) -> rowData(se)
<- 10 # Adjust the
desired_width <- 10 # Adjust the coefficient to control the scaling
desired_height
::opts_chunk$set(
knitrfig.width = desired_width,
fig.height = desired_height
)
<- dataSE$SE_mfi
se_mfi <- "median"
applied_fct_plot <- "meta"
t_metadata <- "perCellCounts"
perCellCounts <- "shared_col"
id <- "scaled_MFI"
scaled_MFI
<- params$conditions
Conditions <- params$batch
batch
<- params$individuals
patient <- params$ncells
size_
<- Conditions
col_interest <- size_
col_cell <- Conditions
separator_ <- Conditions
col_ <- Conditions
shape_
<- rowData(se) |>
r_order as.data.frame() |>
::arrange(desc(n_cells)) |>
dplyrrownames()
<- params$cluster_column_id # : "ftr (sec)"
cluster_column_id <- params$id_mfi # : "file"
id_mfi
<- params$sorted
sorted <- params$log_bar
log_bar
if (params$analyse_type == "DA" | params$analyse_type == "DS") {
<- "none"
trend_method_ <- params$min_cells
min_cells_ <- params$samples
min_samples_ <- FALSE
normalize_ <- "TMM"
norm_factors_ <- params$cluster_id
c_id <- params$p_value
pval
}
::create_dt(colData(se) %>%
R.AnalytiCyteas.data.frame(), length = 10, filter = "top")
::create_dt(rowData(se) %>%
R.AnalytiCyteas.data.frame(), length = 10, filter = "top")
<- names(assays(se_mfi))
markers
<- knitr::all_labels()
labs
::barplot_n_cells(
R.AnalytiCytese = se,
t_metadata = t_metadata,
counts = size_,
Conditions = Conditions,
id = id,
sorted = sorted,
col_interest = col_interest,
col_cell = col_cell,
batch = batch
)::heatmap_median_mfi_like_catalyst(
R.AnalytiCyte# ajouter la possibilité de trier les colonnes, rows
se = se,
id = id,
exprs = "counts",
se_mfi = se_mfi,
subset_marker = NULL, # reduction of marker of interest, order of the heatmap if clustr F
subset_cluster = NULL, # reduction of clusters of interest, order of the heatmap if clustc F
clustr = T,
clustc = T,
margin_ = 2,
t_metadata = t_metadata,
split_heat = NULL,
q_ = 0.1,
fontsize_ = 8,
round_ = 8,
applied_fct = "mean",
log_bar = 0,
title = "All Samples"
)#
#
#
#
# Let's say our group comparison is based on the metadata column `r col_interest`, the different groups are : `r unique(metadata(se)[[t_metadata]][[col_interest]])`
#
<- unique(metadata(se)[[t_metadata]][[col_interest]])
subgroup <- FALSE
second_plot <- names(assays(se_mfi))
markers_list <- names(se_mfi)
cluster_list for (sub_el in subgroup) {
::heatmap_median_mfi_like_catalyst(
R.AnalytiCyte# ajouter la possibilité de trier les colonnes, rows
se = se,
id = id,
exprs = "counts", # perCellCounts
se_mfi = se_mfi,
subset_marker = {
if (second_plot) markers_list[new_order_c] else markers_list
# reduction of marker of interest, order of the heatmap if clustC F
}, subset_cluster = {
if (second_plot) cluster_list[new_order_r] else cluster_list
# reduction of clusters of interest, order of the heatmap if clustR
}, clustr = {
if (second_plot) F else T
},clustc = {
if (second_plot) F else T
},margin_ = 2,
t_metadata = t_metadata,
split_heat = c(separator_, sub_el),
q_ = 0.1,
fontsize_ = 8,
round_ = 8,
applied_fct = "mean",
log_bar = 1,
title = sub_el
-> plot
) # |> ComplexHeatmap::draw(
# column_title = sub_el,
# column_title_gp = grid::gpar(fontsize = 16)
# )
<- TRUE
second_plot <- ComplexHeatmap::column_order(plot)
new_order_c <- ComplexHeatmap::row_order(plot)
new_order_r
}
::heatmap_like_cytofast(
R.AnalytiCytese = se, # se=dataSE$SE_abundance
exprs = "counts", # assays name reference in se -> counts
id = id, # sample id accross metadata "shared_col"
se_mfi = se_mfi, # a SummarizedExperiment (se) object with mfi info se_mfi=dataSE$SE_mfi
scaled_MFI = scaled_MFI, # Name of metadata, if the SE scaled_MFI data
clust_id = cluster_column_id, # name of the cluster column name
metadata_sub = c("acqdate", "Gender", "patient_id"),
id_mfi = "shared_col",
t_metadata = t_metadata,
metadata_sort = NULL,
clustr = T,
clustc = F,
fontsize_ = 8,
subset_patient = NULL, # reduction of patients of interest, order of the heatmap if clustr F
subset_marker = NULL, # reduction of marker of interest, order of the heatmap if clustr F
subset_cluster = NULL, # reduction of clusters of interest, order of the heatmap if clustc F
round_ = 8,
applied_fct = "mean" # applied_fct_plot
)
::heatmap_abundance_like_catalyst(
R.AnalytiCyte# ajouter la possibilité de trier les colonnes, rows
se = se,
exprs = "counts",
t_metadata = t_metadata,
separator_ = separator_,
metadata_sub = c("acqdate", "patient_id", "cond"),
patient = patient,
id = id,
metadata_sort = "cond",
clustr = T,
clustc = T,
margin_ = 1,
q_ = 0.01,
round_ = 8,
fontsize_ = 8,
subset_patient = NULL, # reduction of patients of interest, order of the heatmap if clustr F
subset_cluster = NULL, # reduction of clusters of interest, order of the heatmap if clustc F
log_bar = 1
)<- R.AnalytiCyte::pca_plot(
PCA_SE se = se,
pca = T,
pcX = "PC1",
pcY = "PC2",
exprs = "perCellCountsNorm",
t_metadata = t_metadata,
id = "shared_col",
round_ = 8,
col_ = col_,
shape_ = shape_,
size_ = size_,
scaled_MFI = NULL
)$eigen
PCA_SE::pca_plot(
R.AnalytiCytese = se,
pca = T,
pcX = "PC1",
pcY = "PC2",
exprs = "perCellCountsNorm",
t_metadata = t_metadata,
id = "shared_col",
round_ = 8,
col_ = col_,
shape_ = shape_,
size_ = size_,
scaled_MFI = NULL
$pca
)
::pca_plot(
R.AnalytiCytese = se,
pca = T,
pcX = "PC3",
pcY = "PC2",
exprs = "perCellCountsNorm",
t_metadata = t_metadata,
id = "shared_col",
round_ = 8,
col_ = col_,
shape_ = shape_,
size_ = size_,
scaled_MFI = NULL
$pca
)
::pca_plot(
R.AnalytiCytese = se,
pca = T,
pcX = "PC1",
pcY = "PC3",
exprs = "perCellCountsNorm",
t_metadata = t_metadata,
id = "shared_col",
round_ = 8,
col_ = col_,
shape_ = shape_,
size_ = size_,
scaled_MFI = NULL
$pca
)
::pca_plot(
R.AnalytiCytese = se,
pca = T,
pcX = "PC1",
pcY = "PC2",
exprs = "perCellCountsNorm",
t_metadata = t_metadata,
id = "shared_col",
round_ = 8,
col_ = col_,
shape_ = shape_,
size_ = size_,
scaled_MFI = NULL
$biplot
)
::pca_plot(
R.AnalytiCytese = se,
pca = T,
pcX = "PC3",
pcY = "PC2",
exprs = "perCellCountsNorm",
t_metadata = t_metadata,
id = "shared_col",
round_ = 8,
col_ = col_,
shape_ = shape_,
size_ = size_,
scaled_MFI = NULL
$biplot
)
::pca_plot(
R.AnalytiCytese = se,
pca = T,
pcX = "PC1",
pcY = "PC3",
exprs = "perCellCountsNorm",
t_metadata = t_metadata,
id = "shared_col",
round_ = 8,
col_ = col_,
shape_ = shape_,
size_ = size_,
scaled_MFI = NULL
$biplot
)
<- R.AnalytiCyte::pca_plot(
PCA_MFI se = se_mfi,
pca = T,
pcX = "PC1",
pcY = "PC2",
exprs = "counts",
t_metadata = t_metadata,
id = "shared_col",
round_ = 8,
col_ = col_,
shape_ = shape_,
size_ = size_,
scaled_MFI = scaled_MFI
)$eigen
PCA_MFI# PCA_MFI$pca
::pca_plot(
R.AnalytiCytese = se_mfi,
pca = T,
pcX = "PC1",
pcY = "PC2",
exprs = "counts",
t_metadata = t_metadata,
id = "shared_col",
round_ = 8,
col_ = col_,
shape_ = shape_,
size_ = size_,
scaled_MFI = scaled_MFI
$pca
)
::pca_plot(
R.AnalytiCytese = se_mfi,
pca = T,
pcX = "PC3",
pcY = "PC2",
exprs = "counts",
t_metadata = t_metadata,
id = "shared_col",
round_ = 8,
col_ = col_,
shape_ = shape_,
size_ = size_,
scaled_MFI = scaled_MFI
$pca
)
::pca_plot(
R.AnalytiCytese = se_mfi,
pca = T,
pcX = "PC1",
pcY = "PC3",
exprs = "counts",
t_metadata = t_metadata,
id = "shared_col",
round_ = 8,
col_ = col_,
shape_ = shape_,
size_ = size_,
scaled_MFI = scaled_MFI
$pca
)
::pca_plot(
R.AnalytiCytese = se_mfi,
pca = T,
pcX = "PC1",
pcY = "PC2",
exprs = "counts",
t_metadata = t_metadata,
id = "shared_col",
round_ = 8,
col_ = col_,
shape_ = shape_,
size_ = size_,
scaled_MFI = scaled_MFI
$biplot
)
::pca_plot(
R.AnalytiCytese = se_mfi,
pca = T,
pcX = "PC3",
pcY = "PC2",
exprs = "counts",
t_metadata = t_metadata,
id = "shared_col",
round_ = 8,
col_ = col_,
shape_ = shape_,
size_ = size_,
scaled_MFI = scaled_MFI
$biplot
)
::pca_plot(
R.AnalytiCytese = se_mfi,
pca = T,
pcX = "PC1",
pcY = "PC3",
exprs = "counts",
t_metadata = t_metadata,
id = "shared_col",
round_ = 8,
col_ = col_,
shape_ = shape_,
size_ = size_,
scaled_MFI = scaled_MFI
$biplot )