annotate metacyto_histogram.R @ 0:f5526d97056c draft default tip

"planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
author azomics
date Thu, 29 Jul 2021 22:15:11 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
1 #!/usr/bin/env Rscript
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
2 ######################################################################
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
3 # Copyright (c) 2018 Northrop Grumman.
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
4 # All rights reserved.
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
5 ######################################################################
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
6 #
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
7 # Version 1 - January 2018
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
8 # Author: Cristel Thomas
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
9 #
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
10 #
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
11
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
12 library(flowCore)
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
13 library(MetaCyto)
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
14
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
15 check_cluster_def <- function(cl_def) {
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
16 if (cl_def == "" || cl_def == "None") {
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
17 quit(save = "no", status = 12, runLast = FALSE)
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
18 } else {
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
19 tmp <- gsub(" ", "", cl_def, fixed = TRUE)
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
20 clean_def <- gsub(",", "|", tmp, fixed = TRUE)
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
21 return(clean_def)
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
22 }
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
23 }
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
24
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
25 generate_plots <- function(fpath = "", fname = "", gates = vector(), outdir = "", uc = "",
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
26 flag_pdf = F) {
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
27 dir.create(outdir)
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
28 ff <- read.FCS(fpath, truncate_max_range = F)
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
29 markers <- markerFinder(ff)
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
30 colnames(ff@exprs) <- markers
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
31
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
32 sc <- searchCluster(fcsFrame = ff, clusterLabel = gates)
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
33
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
34 if (length(gates) == length(sc$clusterList)) {
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
35 sink(uc)
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
36 cat("All provided cluster definition were used.")
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
37 sink()
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
38 } else {
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
39 unused_cluster <- setdiff(gates, names(sc$clusterList))
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
40 write.table(unused_cluster, uc, quote = F, row.names = F, col.names = F)
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
41 }
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
42
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
43 groupname <- unlist(strsplit(fname, ".fcs"))[[1]]
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
44 extension <- if (flag_pdf) "plot.pdf" else "plot.png"
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
45 for (i in seq_len(length(sc$clusterList))) {
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
46 gate <- gsub("|", "", names(sc$clusterList[i]), fixed = T)
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
47 plotname <- paste(c(groupname, gate, extension), collapse = "_")
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
48 outplot <- file.path(outdir, plotname)
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
49 if (flag_pdf) {
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
50 pdf(outplot, useDingbats = F, onefile = T)
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
51 par(mfrow = c(2, 2))
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
52 for (j in seq_len(length(markers))) {
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
53 if (markers[[j]] != "SAMPLE_ID" && markers[[j]] != "TIME") {
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
54 plot_title <- paste0(markers[[j]], ", cluster definition:\n", gate)
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
55 x_all <- ff@exprs[, markers[[j]]]
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
56 b <- seq(min(x_all), max(x_all), ((max(x_all) - min(x_all)) / 100))
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
57 subset <- ff@exprs[sc$clusterList[[i]], markers[[j]]]
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
58 hist(x_all, col = rgb(0, 0, 0), xlab = markers[[j]], breaks = b, freq = T,
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
59 border = F, main = plot_title)
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
60 hist(subset, add = T, breaks = b, col = rgb(1, 0, 0), freq = T, border = F)
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
61 if (markers[[j]] %in% names(sc$cutoff)) {
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
62 abline(v = sc$cutoff[markers[[j]]])
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
63 }
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
64 }
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
65 }
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
66 dev.off()
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
67 } else {
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
68 markers_ct <- length(markers) - length(grep(x = markers, pattern = "SAMPLE_ID|TIME"))
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
69 nb_rows <- ceiling(markers_ct / 2)
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
70 h <- nb_rows * 400
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
71 png(outplot, type = "cairo", height = h, width = 800)
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
72 par(mfrow = c(nb_rows, 2))
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
73 for (j in seq_len(length(markers))) {
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
74 if (markers[[j]] != "SAMPLE_ID" && markers[[j]] != "TIME") {
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
75 plot_title <- paste0(markers[[j]], ", cluster definition:\n", gate)
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
76 x_all <- ff@exprs[, markers[[j]]]
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
77 b <- seq(min(x_all), max(x_all), ((max(x_all) - min(x_all)) / 100))
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
78 subset <- ff@exprs[sc$clusterList[[i]], markers[[j]]]
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
79 hist(x_all, col = rgb(0, 0, 0), xlab = markers[[j]], breaks = b, freq = T,
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
80 border = F, main = plot_title)
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
81 hist(subset, add = T, breaks = b, col = rgb(1, 0, 0), freq = T, border = F)
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
82 if (markers[[j]] %in% names(sc$cutoff)) {
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
83 abline(v = sc$cutoff[markers[[j]]])
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
84 }
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
85 }
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
86 }
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
87 dev.off()
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
88 }
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
89 }
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
90 }
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
91
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
92 check_fcs_file <- function(inputf="", inputn="", clusters=vector(),
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
93 output_dir = "", unused = "", flag = F) {
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
94 is_valid <- FALSE
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
95 tryCatch({
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
96 is_valid <- isFCSfile(inputf)
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
97 }, error = function(ex) {
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
98 print(paste("Input file is not a valid FCS file.", ex))
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
99 })
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
100 if (is_valid) {
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
101 generate_plots(inputf, inputn, clusters, output_dir, unused, flag)
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
102 } else {
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
103 quit(save = "no", status = 12, runLast = FALSE)
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
104 }
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
105 }
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
106
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
107 ################################################################################
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
108 ################################################################################
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
109 args <- commandArgs(trailingOnly = TRUE)
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
110
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
111 gates <- vector()
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
112 if (args[6] == "F") {
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
113 ## obvs deal with it if file
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
114 cluster_file <- read.table(args[7], header = F, colClasses = "character")
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
115 gates <- unlist(cluster_file)
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
116 } else {
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
117 cl_df <- args[7:length(args)]
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
118 gates <- sapply(cl_df, check_cluster_def)
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
119 }
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
120
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
121 flag_pdf <- if (args[5] == "PDF") TRUE else FALSE
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
122 gate_list <- toupper(gates)
f5526d97056c "planemo upload for repository https://github.com/AstraZeneca-Omics/immport-galaxy-tools/tree/master/flowtools/metacyto_histogram commit cb978232e32b64f7b0ff3c1852e708361045d268"
azomics
parents:
diff changeset
123 check_fcs_file(args[1], args[2], gate_list, args[3], args[4], flag_pdf)