{ "cells": [ { "cell_type": "markdown", "id": "9c945170", "metadata": {}, "source": [ "# S3A. Score Consistency\n", "\n", "Here, we briefly demonstrate the similarities and discrepancies in the pipeline outputs." ] }, { "cell_type": "code", "execution_count": 1, "id": "c122940a", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "../../data/liana-outputs/ already exists.\n" ] } ], "source": [ "import os\n", "import functools\n", "\n", "import pandas as pd\n", "import scipy\n", "\n", "import scanpy as sc\n", "\n", "import cell2cell as c2c\n", "from liana.method.sc._rank_aggregate import AggregateClass, _rank_aggregate_meta\n", "from liana.method.sc import cellphonedb, natmi, singlecellsignalr\n", "\n", "data_path = '../../data/'\n", "output_folder = os.path.join(data_path, 'liana-outputs/')\n", "c2c.io.directories.create_directory(output_folder)" ] }, { "cell_type": "markdown", "id": "517e0ca9", "metadata": {}, "source": [ "## S3-A1. Comparison with R output:\n", "\n", "There are minor differences with the LIANA implementation in R that lead to outputs not being identical\n", "\n", "- SingleCellSignalR Magnitude (lrscore): precision - slightly different after 3rd decimal place\n", "- LogFC Specificity (lr_logfc): similar relative differences but different exact values\n", "- CellPhoneDB Specificity (cellphone_pvals): similar relative differences but different exact values\n", "- CellChat: not run by default in R\n", "\n", "Let's check the consistency in the magnitude aggregate rank score when running the different methods that report magnitude (excluding CellChat, which is not present by default in R). " ] }, { "cell_type": "code", "execution_count": 2, "id": "e7d48386", "metadata": {}, "outputs": [], "source": [ "adata = sc.read_h5ad(os.path.join(data_path, 'processed.h5ad'))\n", "sadata = adata[adata.obs['sample']=='C100']" ] }, { "cell_type": "code", "execution_count": 3, "id": "0d512811", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Using `.X`!\n", "/home/hratch/miniconda3/envs/ccc_protocols/lib/python3.10/site-packages/anndata/_core/anndata.py:522: FutureWarning: The dtype argument is deprecated and will be removed in late 2024.\n", "5580 features of mat are empty, they will be removed.\n", "/home/hratch/miniconda3/envs/ccc_protocols/lib/python3.10/site-packages/pandas/core/indexing.py:1819: ImplicitModificationWarning: Trying to modify attribute `.obs` of view, initializing view as actual.\n", "/home/hratch/miniconda3/envs/ccc_protocols/lib/python3.10/site-packages/liana/method/_pipe_utils/_pre.py:142: FutureWarning: The default of observed=False is deprecated and will be changed to True in a future version of pandas. Pass observed=False to retain current behavior or observed=True to adopt the future default and silence this warning.\n", "The following cell identities were excluded: Plasma\n", "Using resource `consensus`.\n", "0.33 of entities in the resource are missing from the data.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Generating ligand-receptor stats for 2548 samples and 19218 features\n", "Running CellPhoneDB\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "100%|██████████████████████████████████████| 1000/1000 [00:04<00:00, 249.89it/s]\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Running NATMI\n", "Running SingleCellSignalR\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "/home/hratch/miniconda3/envs/ccc_protocols/lib/python3.10/site-packages/liana/method/sc/_rank_aggregate.py:144: ImplicitModificationWarning: Trying to modify attribute `._uns` of view, initializing view as actual.\n" ] } ], "source": [ "# make rank_aggregate function that only runs on methods of choice and only for Magnitude\n", "rank_aggregate_partial = AggregateClass(_rank_aggregate_meta, methods=[cellphonedb, natmi, singlecellsignalr])\n", "rank_aggregate_partial(adata = sadata, \n", " groupby='celltype', \n", " use_raw = False, # run on log- and library-normalized counts\n", " verbose = True, \n", " inplace = True\n", " )" ] }, { "cell_type": "code", "execution_count": 4, "id": "07975809", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | source | \n", "target | \n", "ligand_complex | \n", "receptor_complex | \n", "magnitude_rank | \n", "
---|---|---|---|---|---|
67 | \n", "B | \n", "B | \n", "ACTR2 | \n", "ADRB2 | \n", "0.405892 | \n", "
17 | \n", "B | \n", "B | \n", "ADAM17 | \n", "ITGB1 | \n", "0.081878 | \n", "
54 | \n", "B | \n", "B | \n", "ADAM17 | \n", "RHBDF2 | \n", "0.334024 | \n", "
23 | \n", "B | \n", "B | \n", "ADAM28 | \n", "ITGA4 | \n", "0.403503 | \n", "
8 | \n", "B | \n", "B | \n", "APOC2 | \n", "LRP1 | \n", "1.000000 | \n", "