annotate scripts/cluster.R @ 6:a4b734cd253b draft

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
author iuc
date Thu, 15 Apr 2021 18:58:21 +0000
parents ee0bbc160cb1
children 0bff0ee0683a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
4ea021bd7513 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
a4b734cd253b "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
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
3
6
a4b734cd253b "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
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
5
6
a4b734cd253b "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
4ea021bd7513 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))
4ea021bd7513 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")
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
9 }
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
10
4ea021bd7513 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
a4b734cd253b "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
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
13 source(args[1])
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
14
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
15
6
a4b734cd253b "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
a4b734cd253b "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
4ea021bd7513 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
4ea021bd7513 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
a4b734cd253b "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
a4b734cd253b "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
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
22 }
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
23
4ea021bd7513 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))
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
25
4ea021bd7513 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
a4b734cd253b "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)))
a4b734cd253b "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))
a4b734cd253b "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))))
a4b734cd253b "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
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
31
6
a4b734cd253b "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) {
a4b734cd253b "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
d4646ce659b4 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit d94b3b8a4c7cf8c604279eb1eea24d32b3868922
iuc
parents: 2
diff changeset
34 }
d4646ce659b4 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit d94b3b8a4c7cf8c604279eb1eea24d32b3868922
iuc
parents: 2
diff changeset
35
0
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
36 br <- 50
6
a4b734cd253b "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))
a4b734cd253b "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"))
a4b734cd253b "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"))
a4b734cd253b "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"))
a4b734cd253b "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
528a43b1cbcf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 1d6e79ba92ce98c7c91f0c4076c9ca5e4e3f3a20
iuc
parents: 1
diff changeset
42 print(tmp)
528a43b1cbcf 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
a4b734cd253b "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)
a4b734cd253b "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) {
a4b734cd253b "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)
a4b734cd253b "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,
a4b734cd253b "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",
a4b734cd253b "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
89ee61bcc310 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 71e6b205841c83391ea8fc69e10eac03f212f4d6
iuc
parents: 0
diff changeset
50 }
89ee61bcc310 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 71e6b205841c83391ea8fc69e10eac03f212f4d6
iuc
parents: 0
diff changeset
51
6
a4b734cd253b "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) {
a4b734cd253b "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
4ea021bd7513 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
a4b734cd253b "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))
a4b734cd253b "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
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
57 }
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
58 return(sc)
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
59 }
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
60
6
a4b734cd253b "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
4ea021bd7513 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))
4ea021bd7513 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
a4b734cd253b "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) {
a4b734cd253b "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))
a4b734cd253b "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
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
67 }
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
68 print(plotjaccard(sc))
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
69 return(sc)
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
70 }
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
71
6
a4b734cd253b "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
4ea021bd7513 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
a4b734cd253b "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
4ea021bd7513 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))
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
76 }
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
77 print(plotbackground(sc))
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
78 print(plotsensitivity(sc))
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
79 print(plotoutlierprobs(sc))
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
80 ## Heatmaps
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
81 test1 <- list()
6
a4b734cd253b "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
a4b734cd253b "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
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
84
6
a4b734cd253b "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)
a4b734cd253b "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)))
a4b734cd253b "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)
a4b734cd253b "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
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
89 return(sc)
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
90 }
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
91
6
a4b734cd253b "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
4ea021bd7513 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))
4ea021bd7513 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
a4b734cd253b "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
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
96 return(sc)
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
97 }
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
98
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
99
6
a4b734cd253b "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
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
101 ## Layout
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
102 test <- list()
6
a4b734cd253b "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
a4b734cd253b "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
a4b734cd253b "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
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
106
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
107 df <- c()
4ea021bd7513 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
a4b734cd253b "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
109 plot.new()
a4b734cd253b "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) {
a4b734cd253b "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
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
112
6
a4b734cd253b "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, ]
a4b734cd253b "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)
a4b734cd253b "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
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
116
6
a4b734cd253b "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)
a4b734cd253b "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
118
0
4ea021bd7513 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
a4b734cd253b "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 = " ")
a4b734cd253b "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)))
a4b734cd253b "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
a4b734cd253b "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)))
a4b734cd253b "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
a4b734cd253b "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 > ",
a4b734cd253b "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
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
127 })
6
a4b734cd253b "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
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
129 }
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
130
4
ee0bbc160cb1 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 5d7c4cd914295a81d42bf8baaad4981c23a83059"
iuc
parents: 3
diff changeset
131
6
a4b734cd253b "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
ee0bbc160cb1 "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
ee0bbc160cb1 "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,
ee0bbc160cb1 "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),
ee0bbc160cb1 "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,
ee0bbc160cb1 "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,
ee0bbc160cb1 "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)
ee0bbc160cb1 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 5d7c4cd914295a81d42bf8baaad4981c23a83059"
iuc
parents: 3
diff changeset
139
6
a4b734cd253b "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",
a4b734cd253b "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
ee0bbc160cb1 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 5d7c4cd914295a81d42bf8baaad4981c23a83059"
iuc
parents: 3
diff changeset
142 }
ee0bbc160cb1 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 5d7c4cd914295a81d42bf8baaad4981c23a83059"
iuc
parents: 3
diff changeset
143
ee0bbc160cb1 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 5d7c4cd914295a81d42bf8baaad4981c23a83059"
iuc
parents: 3
diff changeset
144
0
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
145 pdf(out.pdf)
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
146
6
a4b734cd253b "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
4ea021bd7513 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
a4b734cd253b "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),
a4b734cd253b "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)))
a4b734cd253b "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))),
a4b734cd253b "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
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
153 message(paste(" :: ",
6
a4b734cd253b "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(
a4b734cd253b "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)),
a4b734cd253b "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,",
a4b734cd253b "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(
a4b734cd253b "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)),
a4b734cd253b "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"))
a4b734cd253b "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,
a4b734cd253b "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
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
162 }
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
163
6
a4b734cd253b "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) {
a4b734cd253b "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
4ea021bd7513 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)
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
167
6
a4b734cd253b "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
4ea021bd7513 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)
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
170
6
a4b734cd253b "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
4ea021bd7513 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)
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
173
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
174 mkgenelist(sc)
4
ee0bbc160cb1 "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
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
176 }
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
177
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
178 dev.off()
4ea021bd7513 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
179
4ea021bd7513 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)