Coder Social home page Coder Social logo

kimberle9 / rfca Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 1.0 158.69 MB

R package: {rfca} Random forest-based cell annotation methods for scRNAseq analysis. {rfca} contains methods which identifies cell types using machine learning trained on a diversity of cell types, without the need for a labelled training dataset. It also allows you to train your own cell prediction models with your own labels (cell type, subtype, cell state, cluster number etc). This package is best suited for researchers who want to annotate their datasets in a quick and unbiased way, phenotype their datasets based on cell identity proportions, and discover common cell states across different datasets and disease models.

Home Page: https://kimberle9.github.io/rfca/articles/vignette.html

R 100.00%
machine-learning 10x-genomics 10x random-forest scrnaseq-datasets scrna-seq scrna-seq-analysis seurat

rfca's Introduction

rfca

This package contains functions that trains a Random Forest Model with a labelled Seurat Object, for predicting cell types/states in unlabelled datasets. It also contains a pre-trained Random Forest model, as well as example datasets.

Introduction

Manual cell annotation of scRNAseq datasets, typically based on marker genes, can be time-consuming and biased. Being able to automatically predict cell types/states in a cell-by-cell and cluster-unbiased way is useful for fast and accurate phenotyping.

In addition, despite the increasing amounts of scRNAseq datasets being generated, thorough analysis of these datasets is lagging, and/or done in silos. This package comes with a preloaded Random Forest model based on different datasets and cell types/states, that will be constantly updated.

Installation

You can install this package from GitHub with devtools::install_github("kimberle9/rfca")

Manual

View the manual here: https://kimberle9.github.io/rfca/articles/vignette.html

Examples

Example 1: Creating a Seurat Object

# Load the rfca and Seurat libraries, as well as example datasets
library(rfca)
library(Seurat)

# Create Seurat Object with PCA and UMAP calculated
# Cell ranger raw data ("/filtered_feature_bc_matrix" directory) is required for this step
mySeuratObject <- createSeuratObjectPipeline(data.dir = "~/filtered_feature_bc_matrix", 
                                             nFeature_RNA_lower = 500, 
                                             nFeature_RNA_upper = 5000, 
                                             percent.mt = 5, 
                                             nfeatures = 2000, 
                                             dims = 20, 
                                             clusterResolution = 0.8)

# Assign cell type Idents to mySeuratObject manually, if you want to use it as a training dataset

Example 2: Using Random Forest to train and predict cell types

library(rfca)
library(Seurat)
data("exampleSeuratObjectUnlabelled")
data("exampleSeuratObjectLabelled")

# Create Random Forest Model with your labelled Seurat Object
myRandomForestModel <- createRFModel(exampleSeuratObjectLabelled)
## 
## Call:
##  randomForest(formula = V1 ~ ., data = merged, importance = TRUE,      proximity = TRUE, na.action = na.roughfix) 
##                Type of random forest: classification
##                      Number of trees: 500
## No. of variables tried at each split: 13
## 
##         OOB estimate of  error rate: 3.96%
## Confusion matrix:
##                  Astrocytes Endothelial Microglia Neurons Oligodendrocytes OPCs
## Astrocytes               46           0         0       0                1    0
## Endothelial               0          53         1       0                0    0
## Microglia                 0           0        47       0                0    0
## Neurons                   1           0         0      47                1    2
## Oligodendrocytes          0           0         0       1               46    0
## OPCs                      0           0         1       1                1   47
## Tcells                    0           0         2       0                0    0
## VSMCs                     1           0         1       0                0    0
##                  Tcells VSMCs class.error
## Astrocytes            0     0  0.02127660
## Endothelial           0     0  0.01851852
## Microglia             0     0  0.00000000
## Neurons               1     0  0.09615385
## Oligodendrocytes      0     0  0.02127660
## OPCs                  1     0  0.07843137
## Tcells               50     0  0.03846154
## VSMCs                 0    52  0.03703704
# Create marker gene list from random forest model
markerGeneList <- createGeneLists(myRandomForestModel)
## [1] "Adding gene list for Astrocytes"
## [1] "Adding gene list for Endothelial"
## [1] "Adding gene list for Microglia"
## [1] "Adding gene list for Neurons"
## [1] "Adding gene list for Oligodendrocytes"
## [1] "Adding gene list for OPCs"
## [1] "Adding gene list for Tcells"
## [1] "Adding gene list for VSMCs"
# Visualize Feature Plot based on marker gene list
myPlot <- cellMarkerPlots(exampleSeuratObjectLabelled, geneList = markerGeneList)
## [1] "Calculating average expression of genes in Astrocytes list."
## [1] "Calculating average expression of genes in Endothelial list."
## [1] "Calculating average expression of genes in Microglia list."
## [1] "Calculating average expression of genes in Neurons list."
## [1] "Calculating average expression of genes in Oligodendrocytes list."
## [1] "Calculating average expression of genes in OPCs list."
## [1] "Calculating average expression of genes in Tcells list."
## [1] "Calculating average expression of genes in VSMCs list."
myPlot

# Predict cells based on your own Random Forest Model created above
autoLabelledSeuratObject <- predictCells(exampleSeuratObjectUnlabelled, myRandomForestModel)
## 
##       Astrocytes      Endothelial        Microglia          Neurons 
##               56               45               59               43 
## Oligodendrocytes             OPCs           Tcells            VSMCs 
##               54               49               47               43
# Predict cells based on my pre-loaded and pre-trained Random Forest Model
# With no model passed in, default model used is mouseBrain.
# See documentation for available tissue types. 
autoLabelledSeuratObject <- predictCells(exampleSeuratObjectUnlabelled)
## 
##       Astrocytes      Endothelial        Microglia          Neurons 
##               53               46               53               48 
## Oligodendrocytes             OPCs           Tcells            VSMCs 
##               53               49               48               46
# Visualize autoLabelledSeuratObject
DimPlot(autoLabelledSeuratObject)

Example 3: Defining microglia subtypes

library(rfca)
library(Seurat)

# Create Seurat object (microglia-only data)
microglia <- createSeuratObjectPipeline(data.dir = "~/filtered_feature_bc_matrix") 

# Define microglia subtypes based on cluster numbers
DimPlot(microglia)

# Build Random Forest Model with cluster number as labels
microgliaModel <- createRFModel(microglia)

# Phenotype subtype proportion for different mouse models
mouseModel1 <- predictCells(mouseModel1, microgliaModel)
mouseModel2 <- predictCells(mouseModel2, microgliaModel)
mouseModel3 <- predictCells(mouseModel3, microgliaModel)

rfca's People

Contributors

kimberle9 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

abhijeetrpatil

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.