annotate scripts/cluster.R @ 9:a6821f856a1e draft default tip

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 82a18e57158136e265a26f27feb40f8dc13437bf
author iuc
date Wed, 24 Aug 2022 18:10:56 +0000
parents c8434a623268
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
e0e9b24d76aa 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
c8434a623268 "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
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
3
9
a6821f856a1e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 82a18e57158136e265a26f27feb40f8dc13437bf
iuc
parents: 6
diff changeset
4 args <- commandArgs(trailingOnly = TRUE)
0
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
5
6
c8434a623268 "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
e0e9b24d76aa 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))
e0e9b24d76aa 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")
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
9 }
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
10
e0e9b24d76aa 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
c8434a623268 "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
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
13 source(args[1])
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
14
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
15
6
c8434a623268 "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
c8434a623268 "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
e0e9b24d76aa 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
e0e9b24d76aa 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
c8434a623268 "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
c8434a623268 "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
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
22 }
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
23
e0e9b24d76aa 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))
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
25
e0e9b24d76aa 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
c8434a623268 "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)))
c8434a623268 "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))
c8434a623268 "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))))
c8434a623268 "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
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
31
6
c8434a623268 "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) {
c8434a623268 "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
4164c0da0a5d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit d94b3b8a4c7cf8c604279eb1eea24d32b3868922
iuc
parents: 2
diff changeset
34 }
4164c0da0a5d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit d94b3b8a4c7cf8c604279eb1eea24d32b3868922
iuc
parents: 2
diff changeset
35
0
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
36 br <- 50
6
c8434a623268 "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))
c8434a623268 "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"))
c8434a623268 "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"))
c8434a623268 "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"))
c8434a623268 "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
5156383d3a5d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 1d6e79ba92ce98c7c91f0c4076c9ca5e4e3f3a20
iuc
parents: 1
diff changeset
42 print(tmp)
5156383d3a5d 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
c8434a623268 "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)
c8434a623268 "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) {
c8434a623268 "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)
c8434a623268 "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,
c8434a623268 "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",
c8434a623268 "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
7967b3d036d1 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 71e6b205841c83391ea8fc69e10eac03f212f4d6
iuc
parents: 0
diff changeset
50 }
7967b3d036d1 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 71e6b205841c83391ea8fc69e10eac03f212f4d6
iuc
parents: 0
diff changeset
51
6
c8434a623268 "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) {
c8434a623268 "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
e0e9b24d76aa 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))
9
a6821f856a1e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 82a18e57158136e265a26f27feb40f8dc13437bf
iuc
parents: 6
diff changeset
55 print(plotdimsat(sc, change = TRUE))
a6821f856a1e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 82a18e57158136e265a26f27feb40f8dc13437bf
iuc
parents: 6
diff changeset
56 print(plotdimsat(sc, change = FALSE))
0
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
57 }
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
58 return(sc)
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
59 }
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
60
6
c8434a623268 "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
e0e9b24d76aa 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))
e0e9b24d76aa 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
c8434a623268 "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) {
9
a6821f856a1e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 82a18e57158136e265a26f27feb40f8dc13437bf
iuc
parents: 6
diff changeset
65 print(plotsaturation(sc, disp = FALSE))
a6821f856a1e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 82a18e57158136e265a26f27feb40f8dc13437bf
iuc
parents: 6
diff changeset
66 print(plotsaturation(sc, disp = TRUE))
0
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
67 }
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
68 print(plotjaccard(sc))
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
69 return(sc)
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
70 }
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
71
6
c8434a623268 "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
e0e9b24d76aa 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
c8434a623268 "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
e0e9b24d76aa 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))
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
76 }
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
77 print(plotbackground(sc))
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
78 print(plotsensitivity(sc))
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
79 print(plotoutlierprobs(sc))
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
80 ## Heatmaps
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
81 test1 <- list()
6
c8434a623268 "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
c8434a623268 "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
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
84
6
c8434a623268 "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)
c8434a623268 "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)))
c8434a623268 "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)
c8434a623268 "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
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
89 return(sc)
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
90 }
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
91
6
c8434a623268 "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
e0e9b24d76aa 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))
e0e9b24d76aa 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
c8434a623268 "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
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
96 return(sc)
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
97 }
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
98
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
99
6
c8434a623268 "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
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
101 ## Layout
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
102 test <- list()
6
c8434a623268 "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
c8434a623268 "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
c8434a623268 "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
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
106
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
107 df <- c()
e0e9b24d76aa 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
c8434a623268 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
109 plot.new()
c8434a623268 "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) {
c8434a623268 "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
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
112
6
c8434a623268 "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, ]
c8434a623268 "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)
c8434a623268 "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
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
116
6
c8434a623268 "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)
c8434a623268 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
iuc
parents: 4
diff changeset
118
0
e0e9b24d76aa 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
c8434a623268 "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 = " ")
c8434a623268 "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)))
c8434a623268 "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
c8434a623268 "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)))
c8434a623268 "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
c8434a623268 "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 > ",
c8434a623268 "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
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
127 })
9
a6821f856a1e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 82a18e57158136e265a26f27feb40f8dc13437bf
iuc
parents: 6
diff changeset
128 write.table(df, file = out.genelist, sep = "\t", quote = FALSE)
0
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
129 }
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
130
4
86e2358cf273 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 5d7c4cd914295a81d42bf8baaad4981c23a83059"
iuc
parents: 3
diff changeset
131
6
c8434a623268 "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
86e2358cf273 "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
86e2358cf273 "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,
86e2358cf273 "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),
86e2358cf273 "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,
86e2358cf273 "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,
86e2358cf273 "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)
86e2358cf273 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 5d7c4cd914295a81d42bf8baaad4981c23a83059"
iuc
parents: 3
diff changeset
139
6
c8434a623268 "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",
9
a6821f856a1e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 82a18e57158136e265a26f27feb40f8dc13437bf
iuc
parents: 6
diff changeset
141 quote = FALSE, row.names = FALSE)
4
86e2358cf273 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 5d7c4cd914295a81d42bf8baaad4981c23a83059"
iuc
parents: 3
diff changeset
142 }
86e2358cf273 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 5d7c4cd914295a81d42bf8baaad4981c23a83059"
iuc
parents: 3
diff changeset
143
86e2358cf273 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 5d7c4cd914295a81d42bf8baaad4981c23a83059"
iuc
parents: 3
diff changeset
144
0
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
145 pdf(out.pdf)
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
146
6
c8434a623268 "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
e0e9b24d76aa 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
c8434a623268 "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),
c8434a623268 "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)))
c8434a623268 "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))),
c8434a623268 "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
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
153 message(paste(" :: ",
6
c8434a623268 "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(
c8434a623268 "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)),
c8434a623268 "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,",
c8434a623268 "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(
c8434a623268 "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)),
c8434a623268 "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"))
c8434a623268 "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,
9
a6821f856a1e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 82a18e57158136e265a26f27feb40f8dc13437bf
iuc
parents: 6
diff changeset
161 row.names = TRUE, sep = "\t", quote = FALSE)
0
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
162 }
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
163
6
c8434a623268 "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) {
c8434a623268 "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
e0e9b24d76aa 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)
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
167
6
c8434a623268 "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
e0e9b24d76aa 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)
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
170
6
c8434a623268 "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
e0e9b24d76aa 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)
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
173
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
174 mkgenelist(sc)
4
86e2358cf273 "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
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
176 }
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
177
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
178 dev.off()
e0e9b24d76aa planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
179
e0e9b24d76aa 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)