knitr::opts_chunk$set(echo = TRUE)
When trying to re-analyze single-cell [RNA-seq] data that has previously been annotated, the same cell-types are not usually labeled in the same way (e.g. "Purkinje cells" vs. "purkinje neurons" vs. "pkj_neurons"). This makes harmonizing data across multiple source quite challenging. One solution is to re-annotate all cells yourself. Alternatively, you can re-use the existing cell-type labels with natural language processing (NLP).
Term frequency–inverse document frequency (tf-idf) is an NLP technique to identify words or phrases that are enriched in one document relative to some other larger set of documents.
In our case, our words are within the non-standardized cell labels and our "documents" are the clusters. The goals is to find words that are enriched in each cluster relative to all the other clusters. This can be thought of as an NLP equivalent of finding gene markers for each cluster.
Another use case is to identify whether certain metadata attributes (e.g. dataset, species, brain region) are over-represented in some clusters relative to others This is a quantitative way to assess whether, for example, two or more datasets have successfully been integrated (i.e. are well-"mixed"), or whether some clusters are more representative of a particular anatomical region.
library(scNLP) data("pseudo_seurat")
seurat_tfidf
will run tf-idf on each cluster and put the results in the enriched_words and tf_idf cols of the meta.data
.
pseudo_seurat <- run_tfidf(obj = pseudo_seurat, reduction = "UMAP", cluster_var = "cluster", label_var = "celltype") head(pseudo_seurat@meta.data)
You can also plot the results in reduced dimensional space (e.g. UMAP).
plot_tfidf()
will produce a list with three items.
data
: The processed data used to create the plot. tfidf_df
: The full per-cluster TF-IDF enrichment results.plot
: The ggplot
. Seurat
inputres <- plot_tfidf(obj = pseudo_seurat, label_var = "celltype", cluster_var = "cluster", show_plot = TRUE)
utils::sessionInfo()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.