annotate scripts/cluster.R @ 0:9fec5dd8fbb9 draft

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
author iuc
date Thu, 22 Nov 2018 04:45:41 -0500
parents
children 64c5c1bbbdbe
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
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
2 VERSION = "0.2"
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
3
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
4 args = commandArgs(trailingOnly = T)
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
5
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
6 if (length(args) != 1){
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)))
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
12 suppressWarnings(suppressPackageStartupMessages(require(scran)))
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
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
16 do.filter <- function(sc){
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
17 if (!is.null(filt.lbatch.regexes)){
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)
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
20 filt$LBatch <- lapply(1:length(lar), function(m){ return( nn[grep(lar[[m]], nn)] ) })
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
21 }
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 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
24
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
25 ## Get histogram metrics for library size and number of features
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
26 raw.lib <- log(colSums(as.matrix(sc@expdata)))
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
27 raw.feat <- log(rowSums(as.matrix(sc@expdata)))
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
28 filt.lib <- log(colSums(getfdata(sc)))
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
29 filt.feat <- log(rowSums(getfdata(sc)))
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
30
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
31 br <- 50
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
32 ## Determine limits on plots based on the unfiltered data
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
33 ## (doesn't work, R rejects limits and norm data is too different to compare to exp data
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
34 ## so let them keep their own ranges)
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
35
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
36 ## betterrange <- function(floatval){
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
37 ## return(10 * (floor(floatval / 10) + 1))
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
38 ## }
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
39
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
40 ## tmp.lib <- hist(raw.lib, breaks=br, plot=F)
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
41 ## tmp.feat <- hist(raw.feat, breaks=br, plot=F)
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
42
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
43 ## lib.y_lim <- c(0,betterrange(max(tmp.lib$counts)))
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
44 ## lib.x_lim <- c(0,betterrange(max(tmp.lib$breaks)))
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
45
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
46 ## feat.y_lim <- c(0,betterrange(max(tmp.feat$counts)))
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
47 ## feat.x_lim <- c(0,betterrange(max(tmp.feat$breaks)))
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
48
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
49 par(mfrow=c(2,2))
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
50 print(hist(raw.lib, breaks=br, main="ExpData Log(LibSize)")) # , xlim=lib.x_lim, ylim=lib.y_lim)
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
51 print(hist(raw.feat, breaks=br, main="ExpData Log(NumFeat)")) #, xlim=feat.x_lim, ylim=feat.y_lim)
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
52 print(hist(filt.lib, breaks=br, main="FiltData Log(LibSize)")) # , xlim=lib.x_lim, ylim=lib.y_lim)
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
53 print(hist(filt.feat, breaks=br, main="FiltData Log(NumFeat)")) # , xlim=feat.x_lim, ylim=feat.y_lim)
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
54
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
55 if (filt.use.ccorrect){
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
56 par(mfrow=c(2,2))
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
57 sc <- do.call(CCcorrect, c(sc, filt.ccc))
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
58 print(plotdimsat(sc, change=T))
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
59 print(plotdimsat(sc, change=F))
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
60 }
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
61 return(sc)
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
62 }
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
63
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
64 do.cluster <- function(sc){
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
65 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
66 sc <- do.call(clustexp, c(sc, clust.clustexp))
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
67 if (clust.clustexp$sat){
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
68 print(plotsaturation(sc, disp=F))
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
69 print(plotsaturation(sc, disp=T))
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 print(plotjaccard(sc))
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
72 return(sc)
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
73 }
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
74
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
75 do.outlier <- function(sc){
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
76 sc <- do.call(findoutliers, c(sc, outlier.findoutliers))
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
77 if (outlier.use.randomforest){
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
78 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
79 }
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
80 print(plotbackground(sc))
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
81 print(plotsensitivity(sc))
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
82 print(plotoutlierprobs(sc))
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
83 ## Heatmaps
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
84 test1 <- list()
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
85 test1$side = 3
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
86 test1$line = 0 #1 #3
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
87
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
88 x <- clustheatmap(sc, final=FALSE)
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
89 print(do.call(mtext, c(paste("(Initial)"), test1))) ## spacing is a hack
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
90 x <- clustheatmap(sc, final=TRUE)
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
91 print(do.call(mtext, c(paste("(Final)"), test1))) ## spacing is a hack
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
92 return(sc)
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
93 }
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
94
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
95 do.clustmap <- function(sc){
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
96 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
97 sc <- do.call(compfr, c(sc, cluster.compfr))
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
98 return(sc)
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
99 }
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
100
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
101
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
102 mkgenelist <- function(sc){
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
103 ## Layout
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
104 test <- list()
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
105 test$side = 3
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
106 test$line = 0 #1 #3
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
107 test$cex = 0.8
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
108
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
109 df <- c()
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
110 options(cex = 1)
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
111 lapply(unique(sc@cpart), function(n){
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
112 dg <- clustdiffgenes(sc, cl=n, pvalue=genelist.pvalue)
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
113
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
114 dg.goi <- dg[dg$fc > genelist.foldchange,]
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
115 dg.goi.table <- head(dg.goi, genelist.tablelim)
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
116 df <<- rbind(df, cbind(n, dg.goi.table))
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
117
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
118 goi <- head(rownames(dg.goi.table), genelist.plotlim)
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))
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
120 print(do.call(mtext, c(paste(" Cluster ",n), test))) ## spacing is a hack
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
121 test$line=-1
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
122 print(do.call(mtext, c(paste(" Sig. Genes"), test))) ## spacing is a hack
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
123 test$line=-2
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
124 print(do.call(mtext, c(paste(" (fc > ", genelist.foldchange,")"), test))) ## spacing is a hack
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
125
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
126 })
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
127 write.table(df, file=out.genelist, sep="\t", quote=F)
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
128 }
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 pdf(out.pdf)
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
131
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
132 if (use.filtnormconf){
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
133 sc <- do.filter(sc)
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
134 message(paste(" - Source:: genes:",nrow(sc@expdata),", cells:",ncol(sc@expdata)))
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
135 message(paste(" - Filter:: genes:",nrow(sc@ndata),", cells:",ncol(sc@ndata)))
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
136 message(paste(" :: ",
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
137 sprintf("%.1f", 100 * nrow(sc@ndata)/nrow(sc@expdata)), "% of genes remain,",
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
138 sprintf("%.1f", 100 * ncol(sc@ndata)/ncol(sc@expdata)), "% of cells remain"))
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
139 }
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
140
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
141 if (use.cluster){
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
142 par(mfrow=c(2,2))
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
143 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
144
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
145 par(mfrow=c(2,2))
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
146 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
147
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
148 par(mfrow=c(2,2), mar=c(1,1,6,1))
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
149 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
150
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
151 mkgenelist(sc)
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
152 }
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
153
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
154 dev.off()
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
155
9fec5dd8fbb9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit f880060c478d42202df5b78a81329f8af56b1138
iuc
parents:
diff changeset
156 saveRDS(sc, out.rdat)