Load Data

Directories

RNA-seq

Open aggregated expression matrices from previous notebook. It contains cell-type-based gene expressions as the fraction of single cells with non-zero counts.

Metadata

Generate metadata for samples

Ligand-Receptor Pairs

Change annotations of protein complexes: Use all capital letters for names of proteins and separate subunits by "&".

For example, complex composed by ProteinX and ProteinY would be PROTEINX&PROTEINY

Specify columns containing ligands and receptors

Remove bidirectionality in the list of ligand-receptor pairs. That is, remove repeated interactions where both interactions are the same but in different order:

From this list:

Ligand Receptor
Protein A Protein B
Protein B Protein A

We will have:

Ligand Receptor
Protein A Protein B

Generate a dictionary with function info for each LR pairs. Keys are LIGAND_NAME^RECEPTOR_NAME and values are the function in the annotation column in the dataframe containing ligand-receptor pairs.

Data Preprocessing

Generate list of gene expression matrices, sorted by severity group. Expression here is the cell fraction of non-zero counts for each cell type

Context Names for each of the rnaseq_matrices. Positions in this list are exactly the same as the one above

Run Analysis

Tensor Factorization

Build 4D-Communication Tensor

how='inner' is used to keep only cell types that are across all samples/patients.

complex_sep='&' is used to specify that the list of ligand-receptor pairs contains protein complexes and that subunits are separated by '&'. If the list does not have complexes, use complex_sep=None instead.

Generate a list containing metadata for each tensor order/dimension - Later used for coloring factor plots

Elbow analysis for selecting Rank for Tensor-Factorization

Perform tensor factorization

Export Tensor and Metadata

Plot Factors

Colors for metadatas

Top-5 LR pairs for each factor

Export All Loadings

Correlation between sample loadings and severity in each factor

Evaluate correlation

Evaluate loading differences

Gene Expression

Explore changes in macrophage gene expression given severity

Gini Coefficients of joint distribution of cell loadings