forked from scfurl/viewmaster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExample_Code.Rmd
108 lines (91 loc) · 3.72 KB
/
Example_Code.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
---
title: "BM HCA MPAL transfer label"
output: html_document
author: OW
editor_options:
chunk_output_type: console
---
This vignette will show basic functions provided by viewmaster
```{r warning=FALSE,message=FALSE,warning=FALSE,echo=F}
graphics.off()
rm(list=ls())
knitr::opts_chunk$set(fig.width=8, fig.height=6,dpi=300,
echo=TRUE, warning=FALSE, message=FALSE)
knitr::opts_chunk$set(dev.args=list(bg="transparent"))
xfun::pkg_load2(c('base64enc', 'htmltools', 'mime'))
#Load neccessary packages
suppressPackageStartupMessages({
library(monocle3)
library(dplyr)
library(Matrix)
library(ggplot2)
library(parallel)
library(doMC)
library(glmnet)
library(xfun)
library(pals)
library(RColorBrewer)
library(Seurat)
library(ggplot2)
library(pheatmap)
library(parallel)
library(SeuratObject)
library(SeuratDisk)
library(pbmcapply)
library(ArchR)
library(viewmaster)
})
```
load greenleaf MPAL dataset into monocle3
```{r}
mpal<-readRDS(file ="/Volumes/fh/fast/furlan_s/grp/data/ddata/BM_data/healthy_bone_marrow_greenleaf.rds")
save(mpal, file="data/healthy_bone_marrow_greenleaf.RData")
plot_cells(mpal, color_cells_by = "BioClassification", label_cell_groups = F)+scale_color_manual(values = sfc(n = 26))
```
load hca bone marrow seurat object, convert to monocle using viewmaster's helpful function
```{r}
hca<-readRDS(file = "/Volumes/fh/fast/furlan_s/grp/data/ddata/BM_data/palantir_bm_r1.rds")
save(hca, file="data/palantir_bone_marrow.RData")
hca<-seurat_to_monocle3(hca, seu_rd = "tsne")
plot_cells(hca , color_cells_by = "cell_annotation", label_cell_groups = F)+scale_color_manual(values = sfc(10, scramble = F))
```
Detect common variant genes between two cell data sets
```{r}
vg<-common_variant_genes(mpal, hca, top_n = 5000)
```
Use softmax regression for viewmaster. We will use the Greenleaf lab's MPAL healthy bone marrow cell annotations and transfer them to Human Cell Atals of bone marrow
```{r}
view<-viewmaster(ref_cds = mpal, query_cds = hca, ref_celldata_col = "BioClassification", selected_genes = vg, verbose=T, FUNC = "softmax_regression", tf_idf = F)
plot_cells(view, color_cells_by = "smr_celltype", label_cell_groups = F)+scale_color_manual(values = sfc(11))
```
logistic regression matrix
```{r}
hca_seu<-monocle3_to_seurat(hca)
mpal_seu<-monocle3_to_seurat(mpal, mon_rd = "UMAP")
log_mat<-log_reg_matrix(trainDat = mpal_seu, testDat = hca_seu, trainClass = "BioClassification", testClass = "cell_annotation", downsample = 500)
testDat<- loadTrainingData(hca_seu)
clusterPreds = apply(log_mat,2,function(e) sapply(split(e,testDat$mDat[["cell_annotation"]]),mean))
#Convet to percentages
clusterPreds = (1+exp(-clusterPreds))**-1
pheatmap(clusterPreds, cluster_cols=T,cluster_rows = T ,col = ArchR::paletteContinuous("coolwarm", n=10, reverse = F), border_color = "black")
```
#humanize
```{r}
ROOT_DIR<-"~/Fred Hutchinson Cancer Research Center"
stem<-"Myeloma Exhaustion - General/mm2"
CDS_DIR <- file.path(ROOT_DIR, stem, "cds")
#Seurat Object
mm2<- readRDS(file.path(CDS_DIR, "120621_mm2_seurat.rds"))
library(Seurat)
library(viewmaster)
mm2$test<-mm2$sample
mm2$test[sample(mm2$test, size = 1000)]<-"test1"
mm2$test[sample(mm2$test, size = 1000)]<-"test2"
DimPlot(mm2, group.by = "cluster_3d")+scale_color_manual(values = sfc(n=10))+theme_viewmastr()
DimPlot(mm2, group.by = "cluster_3d")+scale_color_manual(values =pal_continuous(set = "acidRain", n =12) %>% sample(size = 10))+theme_viewmastr()
DimPlot(mm2, group.by = "cluster_3d")+scale_color_manual(values =pal_continuous(set = "fallDay", n =10) %>% sample(size = 10))+theme_viewmastr()
DimPlot(mm2, group.by = "cluster_3d")+scale_color_manual(values =pal_continuous(set = "springTime", n =10))+theme_viewmastr()
```
```{r}
session_info()
```