-
Notifications
You must be signed in to change notification settings - Fork 1
/
Example_Code2.Rmd
116 lines (99 loc) · 4.26 KB
/
Example_Code2.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
108
109
110
111
112
113
114
115
116
---
title: "BM HCA MPAL transfer label"
output: html_notebook
editor_options:
chunk_output_type: console
---
This is an [R Markdown](http://rmarkdown.rstudio.com) Notebook. When you execute code within the notebook, the results appear beneath the code.
Try executing this chunk by clicking the *Run* button within the chunk or by placing your cursor inside it and pressing *Cmd+Shift+Enter*.
```{r}
rm(list=ls())
#Load neccessary packages
suppressPackageStartupMessages({
library(monocle3)
library(reticulate)
library(dplyr)
library(Matrix)
library(ggplot2)
library(xfun)
library(pals)
library(RColorBrewer)
library(Seurat)
library(ggplot2)
library(parallel)
library(scCustomize)
library(SeuratObject)
#library(SeuratDisk)
library(tibble)
library(pbmcapply)
library(viridis)
})
#Sys.setenv('R_MAX_VSIZE'=32000000000)
#Sys.getenv()
library(viewmaster)
```
#load MPAL healthy bone marrow data set and Satija bmcite dataset
```{r}
# load("/Users/sfurlan/teamsrepo/Furlan_Lab - General/datasets/bmcite/data/bmcite.rda")
#
#
# DefaultAssay(bmcite) <- 'RNA'
# bmcite <- NormalizeData(bmcite) %>% FindVariableFeatures() %>% ScaleData() %>% RunPCA()
# DefaultAssay(bmcite) <- 'ADT'
# VariableFeatures(bmcite) <- rownames(bmcite[["ADT"]])
# bmcite <- NormalizeData(bmcite, normalization.method = 'CLR', margin = 2) %>%
# ScaleData() %>% RunPCA(reduction.name = 'apca')
# bmcite <- FindMultiModalNeighbors(
# bmcite, reduction.list = list("pca", "apca"),
# dims.list = list(1:30, 1:18), modality.weight.name = "RNA.weight")
# bmcite <- RunUMAP(bmcite, nn.name = "weighted.nn", reduction.name = "wnn.umap", reduction.key = "wnnUMAP_")
# bmcite <- FindClusters(bmcite, graph.name = "wsnn", algorithm = 3, resolution = 2, verbose = FALSE)
# DimPlot(bmcite, reduction = 'wnn.umap', label = TRUE, repel = TRUE, label.size = 2.5) + NoLegend()
#
# DimPlot(bmcite, group.by = "celltype.l2")+scale_color_manual(values=viewmaster::sfc(28))
#
# bmcite<-viewmaster::seurat_to_monocle3(bmcite, seu_rd = "wnn.umap")
#
#
#
# rna<-readRDS(file.path("~/computation/Analysis/ddata/MPAL/cds", "200604_cds_RNA.RDS"))
# plot_cells(rna, color_cells_by = "BioClassification", label_cell_groups = F, cell_size = 0.4)+scale_color_manual(values=rna@metadata$colorMap$classification)
#
# vg<-common_variant_genes(bmcite, rna, top_n = 5000)
# cds<-viewmaster(bmcite, rna, ref_celldata_col = "BioClassification", selected_genes = vg, verbose=T, FUNC = "softmax_regression", tf_idf = F)
#
# plot_cells(cds, label_cell_groups = F, color_cells_by = "smr_celltype", cell_size = 0.6)+scale_color_manual(values = as.character(pals::polychrome()))
# plot_cells(bmcite, color_cells_by = "celltype.l2")
#
# saveRDS(cds, file.path("/Users/sfurlan/teamsrepo/Furlan_Lab - General/datasets/bmcite/data/bmcite_cds.RDS"))
```
```{r}
bmcite<-readRDS(file.path("/Users/sfurlan/teamsrepo/Furlan_Lab - General/datasets/bmcite/data/bmcite_cds.RDS"))
plot_cells(bmcite, color_cells_by = "celltype.l2")+scale_color_manual(values=viewmaster::sfc(28))
mpal<-readRDS(file.path("~/computation/Analysis/ddata/MPAL/cds", "200604_cds_RNA.RDS"))
plot_cells(mpal, color_cells_by = "BioClassification", label_cell_groups = F, cell_size = 0.4)+scale_color_manual(values=mpal@metadata$colorMap$classification)
vg<-common_variant_genes(bmcite, mpal, top_n = 5000)
bmcite<-viewmaster(bmcite, mpal, ref_celldata_col = "BioClassification", selected_genes = vg, verbose=T, FUNC = "softmax_regression", tf_idf = F)
plot_cells(bmcite, label_cell_groups = F, color_cells_by = "smr_celltype", cell_size = 0.6)+scale_color_manual(values = mpal@metadata$colorMap$classification)
bmcite2<-viewmaster(bmcite, mpal, ref_celldata_col = "BioClassification", selected_genes = vg, verbose=T, FUNC = "softmax_regression", tf_idf = F, threshold = 0.8)
plot_cells(bmcite2, label_cell_groups = F, color_cells_by = "smr_celltype", cell_size = 0.6)+scale_color_manual(values = mpal@metadata$colorMap$classificatio)
pData(bmcite2)$smr_celltype
query_cds = bmcite
ref_cds = mpal
ref_celldata_col="BioClassification"
query_celldata_col=NULL
FUNC=c("softmax_regression")
selected_genes=vg
train_frac = 0.8
tf_idf=F
hidden_layers = c(500,100)
learning_rate = 2.0
batch_size = 100
max_epochs = 250
max_error = 0.5
lambda = 1.0
iterations = 1000
LSImethod=1
verbose = T
threshold = 0.8
```