Mercurial > repos > azomics > flowviz_density_plots
comparison FCSflowViz.R @ 0:23c0af6be9a7 draft default tip
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowviz_density_plots commit 8645b278253fe79de4a23fd3e54e397bca2a9919"
author | azomics |
---|---|
date | Mon, 22 Jun 2020 20:48:47 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:23c0af6be9a7 |
---|---|
1 #!/usr/bin/Rscript | |
2 # Stacked 1D Density Plot Module for Galaxy | |
3 # flowviz | |
4 ###################################################################### | |
5 # Copyright (c) 2016 Northrop Grumman. | |
6 # All rights reserved. | |
7 ###################################################################### | |
8 # | |
9 # Version 1 | |
10 # Cristel Thomas | |
11 # | |
12 # | |
13 | |
14 library(flowViz) | |
15 library(methods) | |
16 | |
17 generateStackedPlots <- function(fs, chans=list(), output="", flag_pdf=FALSE) { | |
18 h <- 800 | |
19 w <- 1200 | |
20 if (length(fs@colnames)>8){ | |
21 h <- 1200 | |
22 w <- 1600 | |
23 } | |
24 channels_to_plot <- fs@colnames | |
25 if (length(chans) > 0){ | |
26 channels_to_plot <- fs@colnames[chans] | |
27 } | |
28 | |
29 if (flag_pdf) { | |
30 pdf(output, useDingbats=FALSE, onefile=TRUE) | |
31 print({ | |
32 densityplot(~., fs, channels = channels_to_plot) | |
33 }) | |
34 dev.off() | |
35 } else { | |
36 png(output, type="cairo", height=h, width=w) | |
37 print({ | |
38 densityplot(~., fs, channels = channels_to_plot) | |
39 }) | |
40 dev.off() | |
41 } | |
42 } | |
43 | |
44 checkFlowSet <- function(fcsfiles, newnames, channels=list(), out_file ="", | |
45 flag_pdf=FALSE) { | |
46 | |
47 isValid <- F | |
48 markerCheck <- T | |
49 | |
50 for (i in 1:length(fcsfiles)){ | |
51 is_file_valid <- F | |
52 tryCatch({ | |
53 fcs <- read.FCS(fcsfiles[i], transformation=FALSE) | |
54 is_file_valid <- T | |
55 }, error = function(ex) { | |
56 print(paste(ex)) | |
57 }) | |
58 if (i == 1) { | |
59 m1 <- as.vector(pData(parameters(fcs))$desc) | |
60 } else { | |
61 m2 <- as.vector(pData(parameters(fcs))$desc) | |
62 if (is.na(all(m1==m2))) { | |
63 mm1 <- is.na(m1) | |
64 mm2 <- is.na(m2) | |
65 if (all(mm1==mm2)){ | |
66 if (!all(m1==m2, na.rm=TRUE)){ | |
67 markerCheck <- F | |
68 } | |
69 } else { | |
70 markerCheck <- F | |
71 } | |
72 } else if (!all(m1==m2)) { | |
73 markerCheck <- F | |
74 } | |
75 } | |
76 } | |
77 if (markerCheck) { | |
78 isValid <- T | |
79 } else { | |
80 quit(save = "no", status = 12, runLast = FALSE) | |
81 } | |
82 | |
83 if (isValid) { | |
84 fs <- read.flowSet(files=fcsfiles, transformation=FALSE) | |
85 fs@phenoData@data$name <- newnames | |
86 generateStackedPlots(fs, channels, out_file, flag_pdf) | |
87 } else { | |
88 quit(save = "no", status = 12, runLast = FALSE) | |
89 } | |
90 } | |
91 | |
92 args <- commandArgs(trailingOnly = TRUE) | |
93 channels <- list() | |
94 flag_pdf <- FALSE | |
95 | |
96 if (args[1]=="None") { | |
97 flag_default <- TRUE | |
98 } else { | |
99 if (args[1] == "i.e.:1,3,4"){ | |
100 flag_default <- TRUE | |
101 } else { | |
102 channels <- as.numeric(strsplit(args[1], ",")[[1]]) | |
103 for (channel in channels){ | |
104 if (is.na(channel)){ | |
105 quit(save = "no", status = 11, runLast = FALSE) | |
106 } | |
107 } | |
108 } | |
109 } | |
110 | |
111 if (args[3] == "PDF"){ | |
112 flag_pdf <- TRUE | |
113 } | |
114 | |
115 nb_files <- (length(args) - 3) / 2 | |
116 fcsfiles <- character(nb_files) | |
117 newnames <- character(nb_files) | |
118 j <- 1 | |
119 ## get files and file names | |
120 for (i in 4:length(args)) { | |
121 if (!i%%2){ | |
122 fcsfiles[[j]] <- args[i] | |
123 newnames[[j]] <- args[i+1] | |
124 j <- j + 1 | |
125 } | |
126 } | |
127 | |
128 checkFlowSet(fcsfiles, newnames, channels, args[2], flag_pdf) |