Mercurial > repos > azomics > ggcyto_1d_density_plots
comparison FCS1Dplotggcyto.R @ 0:b73fc4860906 draft default tip
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/ggcyto_1d_density_plots commit b32c86c02e138aa291c869b31351c4970300fbb4"
author | azomics |
---|---|
date | Mon, 22 Jun 2020 17:53:11 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:b73fc4860906 |
---|---|
1 #!/usr/bin/Rscript | |
2 # 1D Density Plot Module for Galaxy | |
3 # ggcyto | |
4 ###################################################################### | |
5 # Copyright (c) 2016 Northrop Grumman. | |
6 # All rights reserved. | |
7 ###################################################################### | |
8 # | |
9 # Version 1 | |
10 # Cristel Thomas | |
11 # | |
12 # | |
13 | |
14 library(ggcyto) | |
15 | |
16 generate1Dplot <- function(input, output, flag_pdf=FALSE, trans_method="None", | |
17 factor="", log_w=0.5, log_t=262144, log_m=4.5) { | |
18 fcsfs <- read.flowSet(input, transformation=F) | |
19 h <- 800 | |
20 w <- 1200 | |
21 if ("colnames" %in% names(attributes(fcsfs)) && length(fcsfs@colnames)>12){ | |
22 h <- 1200 | |
23 w <- 1600 | |
24 } | |
25 p <- autoplot(fcsfs[[1]]) | |
26 if (trans_method == "arcsinh") { | |
27 p <- p + scale_x_flowCore_fasinh(a = 0, b = factor, c = 0) + geom_density(fill="steelblue", alpha=0.5) | |
28 } else if (trans_method == "logicle") { | |
29 p <- p + scale_x_logicle(w=log_w, t=log_t, m=log_m) + geom_density(fill="paleturquoise", alpha=0.5) | |
30 } | |
31 | |
32 if (flag_pdf) { | |
33 pdf(output, useDingbats=FALSE, onefile=TRUE) | |
34 print({ | |
35 p | |
36 }) | |
37 dev.off() | |
38 } else { | |
39 png(output, type="cairo", height=h, width=w) | |
40 print({ | |
41 p | |
42 }) | |
43 dev.off() | |
44 } | |
45 } | |
46 | |
47 checkFCS <- function(input_file, output_file, flag_pdf=FALSE, trans_met="None", | |
48 factor="", w=0.5, t=262144, m=4.5) { | |
49 isValid <- F | |
50 # Check file beginning matches FCS standard | |
51 tryCatch({ | |
52 isValid <- isFCSfile(input_file) | |
53 }, error = function(ex) { | |
54 print (paste(" ! Error in isFCSfile", ex)) | |
55 }) | |
56 | |
57 if (isValid) { | |
58 generate1Dplot(input_file, output_file, flag_pdf, trans_met, | |
59 factor, w, t, m) | |
60 } else { | |
61 print (paste(input_file, "does not meet FCS standard")) | |
62 } | |
63 } | |
64 | |
65 args <- commandArgs(trailingOnly = TRUE) | |
66 flag_pdf <- FALSE | |
67 trans_method <- "None" | |
68 scaling_factor <- 1 / 150 | |
69 w <- 0.5 | |
70 t <- 262144 | |
71 m <- 4.5 | |
72 | |
73 if (args[3] == "PDF"){ | |
74 flag_pdf <- TRUE | |
75 } | |
76 | |
77 if (args[4]!="None"){ | |
78 trans_method <- args[4] | |
79 if (args[4] == "arcsinh"){ | |
80 scaling_factor <- 1 / as.numeric(args[5]) | |
81 } else if (args[4] == "logicle"){ | |
82 w <- args[5] | |
83 t <- args[6] | |
84 m <- args[7] | |
85 } | |
86 } | |
87 | |
88 checkFCS(args[1], args[2], flag_pdf, trans_method, scaling_factor, w, t, m) |