annotate scripts/cluster.R @ 8:2b0d3e2f402a draft

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 455bad7eca54164f95755174904842907846bb42"
author iuc
date Mon, 20 Dec 2021 10:13:54 +0000
parents 41f34e925bd5
children f3eb2291da05
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
1 #!/usr/bin/env R
6
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
2 VERSION <- "0.5" # nolint
0
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
3
6
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
4 args <- commandArgs(trailingOnly = T)
0
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
5
6
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
6 if (length(args) != 1) {
0
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
7 message(paste("VERSION:", VERSION))
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
8 stop("Please provide the config file")
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
9 }
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
10
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
11 suppressWarnings(suppressPackageStartupMessages(require(RaceID)))
6
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
12 ## suppressWarnings(suppressPackageStartupMessages(require(scran))) # nolint
0
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
13 source(args[1])
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
14
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
15
6
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
16 do.filter <- function(sc) { # nolint
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
17 if (!is.null(filt.lbatch.regexes)) {
0
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
18 lar <- filt.lbatch.regexes
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
19 nn <- colnames(sc@expdata)
6
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
20 filt$LBatch <- lapply(1:length(lar), function(m) { # nolint
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
21 return(nn[grep(lar[[m]], nn)])})
0
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
22 }
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
23
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
24 sc <- do.call(filterdata, c(sc, filt))
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
25
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
26 ## Get histogram metrics for library size and number of features
6
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
27 raw_lib <- log10(colSums(as.matrix(sc@expdata)))
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
28 raw_feat <- log10(colSums(as.matrix(sc@expdata) > 0))
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
29 filt_lib <- log10(colSums(as.matrix(getfdata(sc))))
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
30 filt_feat <- log10(colSums(as.matrix(getfdata(sc) > 0)))
0
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
31
6
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
32 if (filt.geqone) {
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
33 filt_feat <- log10(colSums(as.matrix(getfdata(sc) >= 1))) # nolint
3
0fa80752a314 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit d94b3b8a4c7cf8c604279eb1eea24d32b3868922
iuc
parents: 2
diff changeset
34 }
0fa80752a314 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit d94b3b8a4c7cf8c604279eb1eea24d32b3868922
iuc
parents: 2
diff changeset
35
0
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
36 br <- 50
6
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
37 par(mfrow = c(2, 2))
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
38 print(hist(raw_lib, breaks = br, main = "RawData Log10 LibSize"))
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
39 print(hist(raw_feat, breaks = br, main = "RawData Log10 NumFeat"))
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
40 print(hist(filt_lib, breaks = br, main = "FiltData Log10 LibSize"))
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
41 tmp <- hist(filt_feat, breaks = br, main = "FiltData Log10 NumFeat")
2
106718959281 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 1d6e79ba92ce98c7c91f0c4076c9ca5e4e3f3a20
iuc
parents: 1
diff changeset
42 print(tmp)
106718959281 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 1d6e79ba92ce98c7c91f0c4076c9ca5e4e3f3a20
iuc
parents: 1
diff changeset
43 ## required, for extracting midpoint
6
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
44 unq <- unique(filt_feat)
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
45 if (length(unq) == 1) {
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
46 abline(v = unq, col = "red", lw = 2)
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
47 text(tmp$mids, table(filt_feat)[[1]] - 100, pos = 1,
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
48 paste(10^unq, "\nFeatures\nin remaining\nCells",
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
49 sep = ""), cex = 0.8)
1
64c5c1bbbdbe planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 71e6b205841c83391ea8fc69e10eac03f212f4d6
iuc
parents: 0
diff changeset
50 }
64c5c1bbbdbe planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 71e6b205841c83391ea8fc69e10eac03f212f4d6
iuc
parents: 0
diff changeset
51
6
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
52 if (filt.use.ccorrect) {
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
53 par(mfrow = c(2, 2))
0
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
54 sc <- do.call(CCcorrect, c(sc, filt.ccc))
6
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
55 print(plotdimsat(sc, change = T))
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
56 print(plotdimsat(sc, change = F))
0
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
57 }
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
58 return(sc)
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
59 }
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
60
6
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
61 do.cluster <- function(sc) { # nolint
0
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
62 sc <- do.call(compdist, c(sc, clust.compdist))
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
63 sc <- do.call(clustexp, c(sc, clust.clustexp))
6
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
64 if (clust.clustexp$sat) {
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
65 print(plotsaturation(sc, disp = F))
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
66 print(plotsaturation(sc, disp = T))
0
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
67 }
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
68 print(plotjaccard(sc))
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
69 return(sc)
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
70 }
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
71
6
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
72 do.outlier <- function(sc) { # nolint
0
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
73 sc <- do.call(findoutliers, c(sc, outlier.findoutliers))
6
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
74 if (outlier.use.randomforest) {
0
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
75 sc <- do.call(rfcorrect, c(sc, outlier.rfcorrect))
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
76 }
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
77 print(plotbackground(sc))
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
78 print(plotsensitivity(sc))
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
79 print(plotoutlierprobs(sc))
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
80 ## Heatmaps
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
81 test1 <- list()
6
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
82 test1$side <- 3
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
83 test1$line <- 0 #1 #3
0
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
84
6
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
85 x <- clustheatmap(sc, final = FALSE)
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
86 print(do.call(mtext, c(paste("(Initial)"), test1)))
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
87 x <- clustheatmap(sc, final = TRUE)
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
88 print(do.call(mtext, c(paste("(Final)"), test1)))
0
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
89 return(sc)
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
90 }
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
91
6
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
92 do.clustmap <- function(sc) { # nolint
0
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
93 sc <- do.call(comptsne, c(sc, cluster.comptsne))
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
94 sc <- do.call(compfr, c(sc, cluster.compfr))
6
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
95 sc <- do.call(compumap, c(sc, cluster.compumap))
0
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
96 return(sc)
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
97 }
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
98
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
99
6
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
100 mkgenelist <- function(sc) {
0
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
101 ## Layout
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
102 test <- list()
6
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
103 test$side <- 4
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
104 test$line <- -2
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
105 test$cex <- 0.8
0
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
106
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
107 df <- c()
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
108 options(cex = 1)
6
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
109 plot.new()
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
110 lapply(unique(sc@cpart), function(n) {
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
111 dg <- clustdiffgenes(sc, cl = n, pvalue = genelist.pvalue)$dg
0
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
112
6
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
113 dg_goi <- dg[dg$fc > genelist.foldchange, ]
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
114 dg_goi_table <- head(dg_goi, genelist.tablelim)
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
115 df <<- rbind(df, cbind(n, dg_goi_table))
0
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
116
6
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
117 goi <- head(rownames(dg_goi_table), genelist.plotlim)
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
118
0
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
119 print(plotmarkergenes(sc, goi))
6
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
120 buffer <- paste(rep("", 36), collapse = " ")
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
121 print(do.call(mtext, c(paste(buffer, "Cluster ", n), test)))
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
122 test$line <- -1
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
123 print(do.call(mtext, c(paste(buffer, "Sig. Genes"), test)))
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
124 test$line <- 0
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
125 print(do.call(mtext, c(paste(buffer, "(fc > ",
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
126 genelist.foldchange, ")"), test)))
0
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
127 })
6
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
128 write.table(df, file = out.genelist, sep = "\t", quote = F)
0
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
129 }
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
130
4
20f522154663 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 5d7c4cd914295a81d42bf8baaad4981c23a83059"
iuc
parents: 3
diff changeset
131
6
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
132 writecellassignments <- function(sc) {
4
20f522154663 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 5d7c4cd914295a81d42bf8baaad4981c23a83059"
iuc
parents: 3
diff changeset
133 dat <- sc@cluster$kpart
20f522154663 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 5d7c4cd914295a81d42bf8baaad4981c23a83059"
iuc
parents: 3
diff changeset
134 tab <- data.frame(row.names = NULL,
20f522154663 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 5d7c4cd914295a81d42bf8baaad4981c23a83059"
iuc
parents: 3
diff changeset
135 cells = names(dat),
20f522154663 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 5d7c4cd914295a81d42bf8baaad4981c23a83059"
iuc
parents: 3
diff changeset
136 cluster.initial = dat,
20f522154663 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 5d7c4cd914295a81d42bf8baaad4981c23a83059"
iuc
parents: 3
diff changeset
137 cluster.final = sc@cpart,
20f522154663 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 5d7c4cd914295a81d42bf8baaad4981c23a83059"
iuc
parents: 3
diff changeset
138 is.outlier = names(dat) %in% sc@out$out)
20f522154663 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 5d7c4cd914295a81d42bf8baaad4981c23a83059"
iuc
parents: 3
diff changeset
139
6
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
140 write.table(tab, file = out.assignments, sep = "\t",
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
141 quote = F, row.names = F)
4
20f522154663 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 5d7c4cd914295a81d42bf8baaad4981c23a83059"
iuc
parents: 3
diff changeset
142 }
20f522154663 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 5d7c4cd914295a81d42bf8baaad4981c23a83059"
iuc
parents: 3
diff changeset
143
20f522154663 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 5d7c4cd914295a81d42bf8baaad4981c23a83059"
iuc
parents: 3
diff changeset
144
0
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
145 pdf(out.pdf)
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
146
6
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
147 if (use.filtnormconf) {
0
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
148 sc <- do.filter(sc)
6
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
149 message(paste(" - Source:: genes:", nrow(sc@expdata),
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
150 ", cells:", ncol(sc@expdata)))
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
151 message(paste(" - Filter:: genes:", nrow(as.matrix(getfdata(sc))),
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
152 ", cells:", ncol(as.matrix(getfdata(sc)))))
0
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
153 message(paste(" :: ",
6
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
154 sprintf("%.1f", 100 * nrow(as.matrix(
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
155 getfdata(sc))) / nrow(sc@expdata)),
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
156 "% of genes remain,",
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
157 sprintf("%.1f", 100 * ncol(as.matrix(
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
158 getfdata(sc))) / ncol(sc@expdata)),
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
159 "% of cells remain"))
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
160 write.table(as.matrix(sc@ndata), file = out.table, col.names = NA,
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
161 row.names = T, sep = "\t", quote = F)
0
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
162 }
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
163
6
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
164 if (use.cluster) {
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
165 par(mfrow = c(2, 2))
0
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
166 sc <- do.cluster(sc)
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
167
6
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
168 par(mfrow = c(2, 2))
0
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
169 sc <- do.outlier(sc)
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
170
6
41f34e925bd5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
171 par(mfrow = c(2, 2), mar = c(1, 1, 6, 1))
0
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
172 sc <- do.clustmap(sc)
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
173
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
174 mkgenelist(sc)
4
20f522154663 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 5d7c4cd914295a81d42bf8baaad4981c23a83059"
iuc
parents: 3
diff changeset
175 writecellassignments(sc)
0
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
176 }
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
177
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
178 dev.off()
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
179
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
180 saveRDS(sc, out.rdat)