{ "cells": [ { "cell_type": "markdown", "id": "c14b3188", "metadata": {}, "source": [ "# Tutorial: Scoring with ANS in R\n", "\n", "The following tutorial shows how to score a signature with ANS in R. The jupyter notebook is heavily based on the `AddModuleScore` usage example of the Seurat method description, see [here](https://satijalab.org/seurat/reference/addmodulescore).\n", "\n", "Equally to the Seurat \n" ] }, { "cell_type": "code", "execution_count": 1, "id": "d0c66588", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Loading required package: SeuratObject\n", "\n", "Loading required package: sp\n", "\n", "The legacy packages maptools, rgdal, and rgeos, underpinning the sp package,\n", "which was just loaded, were retired in October 2023.\n", "Please refer to R-spatial evolution reports for details, especially\n", "https://r-spatial.org/r/2023/05/15/evolution4.html.\n", "It may be desirable to make the sf package available;\n", "package maintainers should consider adding sf to Suggests:.\n", "\n", "\n", "Attaching package: ‘SeuratObject’\n", "\n", "\n", "The following objects are masked from ‘package:base’:\n", "\n", " intersect, saveRDS\n", "\n", "\n", "Loading Seurat v5 beta version \n", "To maintain compatibility with previous workflows, new Seurat objects will use the previous object structure by default\n", "To use new Seurat v5 assays please run: options(Seurat.object.assay.version = 'v5')\n", "\n", "\n", "Attaching package: ‘zoo’\n", "\n", "\n", "The following objects are masked from ‘package:base’:\n", "\n", " as.Date, as.Date.numeric\n", "\n", "\n" ] } ], "source": [ "library(\"Seurat\")\n", "source('../../src_R/adjusted_neighborhood_scoring.R')" ] }, { "cell_type": "markdown", "id": "da3f23a5-c04b-4920-9f9b-2799150dee9c", "metadata": {}, "source": [ "Load small sample dataset " ] }, { "cell_type": "code", "execution_count": 2, "id": "6bacbcb9", "metadata": {}, "outputs": [], "source": [ "data(\"pbmc_small\")" ] }, { "cell_type": "markdown", "id": "57b82d3f-dc6b-4f77-9232-ca2764861338", "metadata": {}, "source": [ "Define one signature and store it in list object" ] }, { "cell_type": "code", "execution_count": 3, "id": "ac1cfeee", "metadata": {}, "outputs": [], "source": [ "cd_features <- list(c(\n", " 'CD79B',\n", " 'CD79A',\n", " 'CD19',\n", " 'CD180',\n", " 'CD200',\n", " 'CD3D',\n", " 'CD2',\n", " 'CD3E',\n", " 'CD7',\n", " 'CD8A',\n", " 'CD14',\n", " 'CD1C',\n", " 'CD68',\n", " 'CD9',\n", " 'CD247'\n", "))" ] }, { "cell_type": "markdown", "id": "0f8d7cd3-67ca-4d17-aaf4-2e74998b6b8a", "metadata": {}, "source": [ "Score with ANS. " ] }, { "cell_type": "code", "execution_count": 4, "id": "d3ec4525", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Warning message:\n", "“\u001b[1m\u001b[22m`GetAssayData()` was deprecated in SeuratObject 5.0.0.\n", "\u001b[36mℹ\u001b[39m Please use `LayerData()` instead.”\n" ] } ], "source": [ "pbmc_small <- AdjustedNeighborhoodScoring(\n", " object = pbmc_small,\n", " features = cd_features,\n", " ctrl = 5, # by default ANS uses 100 control genes per signature gene\n", " name = 'CD_scores_ANS'\n", ")" ] }, { "cell_type": "markdown", "id": "9ddef049-c6d3-47d9-88cc-8019d1122f93", "metadata": {}, "source": [ "First entries of small dataset" ] }, { "cell_type": "code", "execution_count": 5, "id": "5fd6edfb", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
orig.ident | nCount_RNA | nFeature_RNA | RNA_snn_res.0.8 | letter.idents | groups | RNA_snn_res.1 | CD_scores_ANS1 | |
---|---|---|---|---|---|---|---|---|
<fct> | <dbl> | <int> | <fct> | <fct> | <chr> | <fct> | <dbl> | |
ATGCCAGAACGACT | SeuratProject | 70 | 47 | 0 | A | g2 | 0 | 0.7791735 |
CATGGCCTGTGCAT | SeuratProject | 85 | 52 | 0 | A | g1 | 0 | 0.7931169 |
GAACCTGATGAACC | SeuratProject | 87 | 50 | 1 | B | g2 | 0 | 0.8425729 |
TGACTGGATTCTCA | SeuratProject | 127 | 56 | 0 | A | g2 | 0 | 0.6067555 |
AGTCAGACTGCACA | SeuratProject | 173 | 53 | 0 | A | g2 | 0 | 0.4678895 |
TCTGATACACGTGT | SeuratProject | 70 | 48 | 0 | A | g1 | 0 | 1.4741454 |
TGGTATCTAAACAG | SeuratProject | 64 | 36 | 0 | A | g1 | 0 | 0.5359506 |
GCAGCTCTGTTTCT | SeuratProject | 72 | 45 | 0 | A | g1 | 0 | 0.5423551 |
GATATAACACGCAT | SeuratProject | 52 | 36 | 0 | A | g1 | 0 | 1.2401691 |
AATGTTGACAGTCA | SeuratProject | 100 | 41 | 0 | A | g1 | 0 | 0.2482804 |