comparison Seurat.R @ 1:7319f83ae734 draft

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/seurat commit 88cf23c767023f71b4ea1e72aac568cc694cc34a"
author iuc
date Mon, 09 Dec 2019 14:32:16 -0500
parents
children 321bdd834266
comparison
equal deleted inserted replaced
0:8d8412d35247 1:7319f83ae734
1 #' ---
2 #' title: "Seurat Analysis"
3 #' author: "Performed using Galaxy"
4 #' params:
5 #' counts: ""
6 #' min_cells: ""
7 #' min_genes: ""
8 #' low_thresholds: ""
9 #' high_thresholds: ""
10 #' numPCs: ""
11 #' cells_use: ""
12 #' resolution: ""
13 #' min_pct: ""
14 #' logfc_threshold: ""
15 #' showcode: ""
16 #' warn: ""
17 #' varstate: ""
18 #' vlnfeat: ""
19 #' featplot: ""
20 #' PCplots: ""
21 #' tsne: ""
22 #' heatmaps: ""
23 #' ---
24
25 #+ echo=F, warning = F, message=F
26 options( show.error.messages=F, error = function () { cat( geterrmessage(), file=stderr() ); q( "no", 1, F ) } )
27 showcode <- as.logical(params$showcode)
28 warn <- as.logical(params$warn)
29 varstate <- as.logical(params$varstate)
30 vlnfeat <- as.logical(params$vlnfeat)
31 featplot <- as.logical(params$featplot)
32 PCplots <- as.logical(params$PCplots)
33 tsne <- as.logical(params$tsne)
34 heatmaps <- as.logical(params$heatmaps)
35
36 # we need that to not crash galaxy with an UTF8 error on German LC settings.
37 loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8")
38
39
40 #+ echo = F, warning = `warn`, include =`varstate`
41 min_cells <- as.integer(params$min_cells)
42 min_genes <- as.integer(params$min_genes)
43 low_thresholds <- as.integer(params$low_thresholds)
44 high_thresholds <- as.integer(params$high_thresholds)
45 numPCs <- as.integer(params$numPCs)
46 cells_use <- as.integer(params$cells_use)
47 resolution <- as.double(params$resolution)
48 min_pct <- as.double(params$min_pct)
49 logfc_threshold <- as.double(params$logfc_thresh)
50 print(paste0("Minimum cells: ", min_cells))
51 print(paste0("Minimum features: ", min_genes))
52 print(paste0("Umi low threshold: ", low_thresholds))
53 print(paste0("Umi high threshold: ", high_thresholds))
54 print(paste0("Number of principal components: ", numPCs))
55 print(paste0("Resolution: ", resolution))
56 print(paste0("Minimum percent of cells", min_pct))
57 print(paste0("Logfold change threshold", logfc_threshold))
58
59 #+ echo = FALSE
60 if(showcode == TRUE){print("Read in data, generate inital Seurat object")}
61 #+ echo = `showcode`, warning = `warn`, message = F
62 counts <- read.delim(params$counts, row.names=1)
63 seuset <- Seurat::CreateSeuratObject(counts = counts, min.cells = min_cells, min.features = min_genes)
64
65 #+ echo = FALSE
66 if(showcode == TRUE && vlnfeat == TRUE){print("Raw data vizualization")}
67 #+ echo = `showcode`, warning = `warn`, include=`vlnfeat`
68 Seurat::VlnPlot(object = seuset, features = c("nFeature_RNA", "nCount_RNA"), axis="v")
69 Seurat::FeatureScatter(object = seuset, feature1 = "nCount_RNA", feature2 = "nFeature_RNA")
70
71 #+ echo = FALSE
72 if(showcode == TRUE){print("Filter and normalize for UMI counts")}
73 #+ echo = `showcode`, warning = `warn`
74 seuset <- subset(seuset, subset = `nCount_RNA` > low_thresholds & `nCount_RNA` < high_thresholds)
75 seuset <- Seurat::NormalizeData(seuset, normalizeation.method = "LogNormalize", scale.factor = 10000)
76
77 #+ echo = FALSE
78 if(showcode == TRUE && featplot == TRUE){print("Variable Genes")}
79 #+ echo = `showcode`, warning = `warn`, include = `featplot`
80 seuset <- Seurat::FindVariableFeatures(object = seuset, selection.method = "mvp")
81 Seurat::VariableFeaturePlot(seuset, cols = c("black", "red"), selection.method = "disp")
82 seuset <- Seurat::ScaleData(object = seuset, vars.to.regress = "nCount_RNA")
83
84 #+ echo = FALSE
85 if(showcode == TRUE && PCplots == TRUE){print("PCA Visualization")}
86 #+ echo = `showcode`, warning = `warn`, include = `PCplots`
87 seuset <- Seurat::RunPCA(seuset, npcs=numPCs)
88 Seurat::VizDimLoadings(seuset, dims = 1:2)
89 Seurat::DimPlot(seuset, dims = c(1,2), reduction="pca")
90 Seurat::DimHeatmap(seuset, dims=1:numPCs, nfeatures=30, reduction="pca")
91 seuset <- Seurat::JackStraw(seuset, dims=numPCs, reduction = "pca", num.replicate = 100)
92 seuset <- Seurat::ScoreJackStraw(seuset, dims = 1:numPCs)
93 Seurat::JackStrawPlot(seuset, dims = 1:numPCs)
94 Seurat::ElbowPlot(seuset, ndims = numPCs, reduction = "pca")
95
96 #+ echo = FALSE
97 if(showcode == TRUE && tsne == TRUE){print("tSNE")}
98 #+ echo = `showcode`, warning = `warn`, include = `tsne`
99 seuset <- Seurat::FindNeighbors(object = seuset)
100 seuset <- Seurat::FindClusters(object = seuset)
101 seuset <- Seurat::RunTSNE(seuset, dims = 1:numPCs, resolution = resolution)
102 Seurat::DimPlot(seuset, reduction="tsne")
103
104 #+ echo = FALSE
105 if(showcode == TRUE && heatmaps == TRUE){print("Marker Genes")}
106 #+ echo = `showcode`, warning = `warn`, include = `heatmaps`
107 markers <- Seurat::FindAllMarkers(seuset, only.pos = TRUE, min.pct = min_pct, logfc.threshold = logfc_threshold)
108 top10 <- dplyr::group_by(markers, cluster)
109 top10 <- dplyr::top_n(top10, 10, avg_logFC)
110 Seurat::DoHeatmap(seuset, features = top10$gene)