Introduction and basic pipeline

The goal of fcoex is to provide a simple and intuitive way to generate co-expression nets and modules for single cell data. It is based in 3 steps:

First of all, we will a already preprocessed single cell dataset from 10XGenomics ( preprocessed according to the OSCA pipeline, 14/08/2019). It contains peripheral blood mononuclear cells and the most variable genes.

library(fcoex, quietly = TRUE)
## Warning: replacing previous import 'Matrix::head' by 'utils::head' when loading
## 'fcoex'
library(SingleCellExperiment, quietly = TRUE)
data("mini_pbmc3k")

This is the single cell object we will explore in this vignette:

mini_pbmc3k
## class: SingleCellExperiment 
## dim: 1700 600 
## metadata(0):
## assays(2): counts logcounts
## rownames(1700): LYZ S100A9 ... ALG10 LLGL1
## rowData names(3): ENSEMBL_ID Symbol_TENx Symbol
## colnames(600): V1 V2 ... V599 V600
## colData names(14): Sample Barcode ... mod_FCER1G mod_CD3D
## reducedDimNames(2): PCA UMAP
## mainExpName: NULL
## altExpNames(0):

Creating the fcoex object

Now let’s use the normalized data and the cluster labels to build the co-expresison networks. The labels were obtained by louvain clustering on a graph build from nearest neighbours. That means that these labels are a posteriori, and this depends on the choice of the analyst.

The fcoex object is created from 2 different pieces: a previously normalized expression table (genes in rows) and a target factor with classes for the cells.

target <- colData(mini_pbmc3k)
target <- target$clusters
exprs <- as.data.frame(assay(mini_pbmc3k, 'logcounts'))

fc <- new_fcoex(data.frame(exprs),target)

The first step is the conversion of the count matrix into a discretized dataframe. The standar of fcoex is a simple binarization that works as follows:

For each gene, the maximum and minimum values are stored. This range is divided in n bins of equal width (parameter to be set). The first bin is assigned to the class “low” and all the others to the class “high”.

fc <- discretize(fc, number_of_bins = 8)

Getting the modules

Note that many other discretizations are avaible, from the implementations in the FCBF Bioconductor package. This step affects the final results in many ways. However, we found empirically that the default parameter often yields interesting results.

After the discretization, we proceed to constructing a network and extracting modules. The co-expression adjacency matriz generated is modular in its inception. All correlations used are calculated via Symmetrical Uncertainty. Three steps are present:

1 - Selection of n genes to be considered, ranked by correlation to the target variable.

2 - Detection of predominantly correlated genes, a feature selection approach defined in the FCBF algorithm

3 - Building of modules around selected genes. Correlations between two genes are kept if they are more correlated to each other than to the target lables

You can choose either to have a non-parallel processing, with a progress bar, or a faster parallel processing without progress bar. Up to you.

fc <- find_cbf_modules(fc,n_genes_selected_in_first_step = 200, verbose = FALSE, is_parallel = FALSE)
## [1] 0.1
## [1] "Number of features features =  1700"
## [1] "Number of prospective features =  199"
## [1] "Number of final features =  28"
## [1] "FCER1G"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "TYROBP"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "CD3D"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "HLA-DRB1"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "LGALS2"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "FCN1"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "IL32"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "AIF1"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "HLA-DRB5"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "CFD"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "LST1"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "CST3"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "IFITM3"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "S100A9"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "S100A8"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "TYMP"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "LGALS1"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "SERPINA1"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "HLA-DPA1"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "IFI30"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "HLA-DRA"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "CD79A"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "CST7"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "LTB"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "MS4A6A"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "CD68"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "SPI1"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "MS4A1"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "HLA-DQA1"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "NKG7"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "GZMA"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "LGALS3"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "CD79B"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "RP11-290F20-3"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "CTSW"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "CFP"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "CD3E"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "HLA-DPB1"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "CD14"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "GZMB"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "GRN"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "S100A11"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "CPVL"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "CDA"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "BRI3"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "CTSS"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "S100A4"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "TCL1A"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "FCGR3A"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "CEBPD"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "FGFBP2"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "HLA-DMA"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "APOBEC3A"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "CCL5"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "PTPRCAP"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "LY86"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "PILRA"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "HLA-DQB1"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "PRF1"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "CSF3R"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "NCF2"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "FAM26F"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "MS4A7"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "CD7"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "LINC00926"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "PYCARD"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "LYZ"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "COTL1"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "GPX1"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "GZMH"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "LDHB"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "SAT1"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "PSAP"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "SRGN"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "BLVRB"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "NPC2"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "GABARAP"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "GNLY"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "TKT"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "GSTP1"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "TIMP1"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "CEBPB"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "PLBD1"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "IL7R"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "MAFB"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "HLA-DQA2"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "TNFSF13B"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "ANXA2"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "VPREB3"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "ALDH2"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "GZMM"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "CD2"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "C1orf162"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "AP2S1"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "RGS2"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "HLA-DMB"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "STXBP2"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "CD247"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "AP1S2"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "RAC1"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "HOPX"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "ASGR1"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "RAB32"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "CCL4"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "GPBAR1"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "S100A6"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "FPR1"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "FCGRT"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "XCL2"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "RHOC"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "BANK1"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "CCL3"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "CTSZ"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "IGFBP7"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "STX11"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "ANXA1"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "S100A12"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "PRKCQ-AS1"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "LYN"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "PRELID1"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "MEF2C"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "GZMK"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "VSTM1"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "NEAT1"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "IFI6"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "CD8A"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "FCER2"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "RBP7"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "MPEG1"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "NUP214"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "CD74"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "LILRA3"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "FCRLA"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "KLRD1"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "IL1B"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "ISG15"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "GIMAP5"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "CD63"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "HVCN1"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "SPON2"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "VIM"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "MATK"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "GIMAP7"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "HCST"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "CLIC3"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "CD69"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "NOSIP"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "FOLR3"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "AKR1C3"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "CD19"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "MT2A"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "S100A10"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "CD3G"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "TSPAN13"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "ID2"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "IL8"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "APMAP"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "RHOB"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "SCPEP1"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "RNASE6"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "RGCC"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "BLK"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "GPR56"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "CD27"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "PRSS23"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "MT-CO2"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "CD72"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "HLA-DOB"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "CD8B"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "YBX3"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "LINC00936"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "TTC38"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "KIAA0125"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "SOD2"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "PDLIM1"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "CD99"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "H2AFY"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "IFITM1"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "G0S2"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "CXCR4"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "LAMTOR2"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "STK17A"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "SH3BGRL3"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "SPOCK2"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "FCGR2B"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "TNFSF10"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "TNFRSF4"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "CHST12"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "GAPT"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "ZFP36L2"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "TIGIT"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "XCL1"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "HAVCR2"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "RETN"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "CYBA"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "KLRG1"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "ARPC1B"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "MARCH1"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "SUPT4H1"
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
## [1] "FCER1G"
## [1] "CD3D"
## [1] "HLA-DRB1"
## [1] "AIF1"
## [1] "CST3"
## [1] "CD79A"
## [1] "CST7"
## [1] "CTSS"
## [1] "FCGR3A"
## [1] "CD7"
## [1] "COTL1"
## [1] "SAT1"
## [1] "GZMM"
## [1] "CD247"
## [1] "S100A6"
## [1] "ANXA1"
## [1] "NEAT1"
## [1] "VIM"
## [1] "CD69"
## [1] "NOSIP"
## [1] "RGCC"
## [1] "MT-CO2"
## [1] "CD99"
## [1] "IFITM1"
## [1] "CXCR4"
## [1] "STK17A"
## [1] "TNFRSF4"
## [1] "ZFP36L2"

The get_nets function takes the modules and plot networks. The visualizations it generates were heavily inspired by the CEMiTool package, as much of the code in fcoex was.

We will take a look at the first two networks

fc <- get_nets(fc)

# Taking a look at the first two networks: 
show_net(fc)[["CD79A"]]