Mercurial > repos > immport-devteam > fcs_scatterplot
changeset 1:413f3e610295 draft default tip
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/fcs_scatterplot commit 82365bd2b90a783f84f497afbb29b435cd25cf9d"
author | azomics |
---|---|
date | Thu, 16 Jul 2020 08:00:52 -0400 |
parents | 164cd5384f1d |
children | |
files | fcs_scatterplot/getDensityPlots.R fcs_scatterplot/getDensityPlots.xml fcs_scatterplot/static/images/flowtools/densityplots.png fcs_scatterplot/test-data/graph.pdf fcs_scatterplot/test-data/graph.png fcs_scatterplot/test-data/graph2.png fcs_scatterplot/test-data/testfcs1.fcs getDensityPlots.R getDensityPlots.xml static/images/flowtools/densityplots.png test-data/graph.pdf test-data/graph2.png test-data/testfcs1.fcs |
diffstat | 13 files changed, 206 insertions(+), 199 deletions(-) [+] |
line wrap: on
line diff
--- a/fcs_scatterplot/getDensityPlots.R Mon Feb 27 12:52:20 2017 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,128 +0,0 @@ -# Density Plot Module for Galaxy -# FlowDensity -###################################################################### -# Copyright (c) 2016 Northrop Grumman. -# All rights reserved. -###################################################################### -# -# Version 1 -# Cristel Thomas -# -# - -library(flowCore) -library(flowDensity) - -generateGraph <- function(input, channels, output, plot_default, flag_pdf, pdf_out) { - fcs <- read.FCS(input, transformation=F) - ## marker names - markers <- colnames(fcs) - print_markers <- as.vector(pData(parameters(fcs))$desc) - # Update print_markers if the $P?S not in the FCS file - for (i in 1:length(print_markers)) { - if (is.na(print_markers[i])) { - print_markers[i] <- markers[i] - } - } - - if (plot_default) { - channels <- c(grep(colnames(fcs), pattern="Forward scatter", ignore.case=TRUE), - grep(colnames(fcs), pattern="Side scatter", ignore.case=TRUE)) - if (length(channels) == 0){ - channels <- c(grep(colnames(fcs), pattern="FSC"), - grep(colnames(fcs), pattern="SSC")) - if (length(channels) > 2) { - #get first FSC and corresponding SSC - channels <- c(grep(colnames(fcs), pattern="FSC-A"), - grep(colnames(fcs), pattern="SSC-A")) - if (length(channels) == 0) { - channels <- c(grep(colnames(fcs), pattern="FSC-H"), - grep(colnames(fcs), pattern="SSC-H")) - if (length(channels) == 0) { - channels <- c(grep(colnames(fcs), pattern="FSC-W"), - grep(colnames(fcs), pattern="SSC-W")) - } - } - } - } - if (length(channels) == 0) { - warning('No forward/side scatter channels found, no plots will be generated.') - quit(save = "no", status = 10, runLast = FALSE) - } - } - - nb_markers <- length(channels) - for (j in nb_markers) { - if (channels[j] > length(markers)){ - warning('Please indicate markers between 1 and ', length(markers)) - quit(save = "no", status = 10, runLast = FALSE) - } - } - png(output, type="cairo", height=600, width=600) - par(mfrow=c(2,2)) - for (m in 1:(nb_markers - 1)) { - for (n in (m+1):nb_markers) { - plotDens(fcs, c(channels[m],channels[n]), xlab = print_markers[channels[m]], ylab = print_markers[channels[n]]) - } - } - dev.off() - - if (flag_pdf) { - pdf(pdf_out, useDingbats=FALSE, onefile=TRUE) - par(mfrow=c(2,2)) - for (m in 1:(nb_markers - 1)) { - for (n in (m+1):nb_markers) { - plotDens(fcs, c(channels[m],channels[n]), xlab = print_markers[channels[m]], ylab = print_markers[channels[n]]) - } - } - dev.off() - } -} - -checkFCS <- function(input_file, channels, output_file, plot_default, flag_pdf, pdf_out) { - isValid <- F - # Check file beginning matches FCS standard - tryCatch({ - isValid = isFCSfile(input_file) - }, error = function(ex) { - print (paste(" ! Error in isFCSfile", ex)) - }) - - if (isValid) { - generateGraph(input_file, channels, output_file, plot_default, flag_pdf, pdf_out) - } else { - print (paste(input_file, "does not meet FCS standard")) - } -} - -args <- commandArgs(trailingOnly = TRUE) -channels <- "" -flag_default <- FALSE -flag_pdf <- FALSE -pdf_output <- "" - -if (args[3]=="None") { - flag_default <- TRUE -} else { - if (args[3] == "i.e.:1,3,4"){ - flag_default <- TRUE - } else { - channels <- as.numeric(strsplit(args[3], ",")[[1]]) - for (channel in channels){ - if (is.na(channel)){ - quit(save = "no", status = 11, runLast = FALSE) - } - } - if (length(channels) == 1){ - warning('Please indicate more than one marker to plot.') - quit(save = "no", status = 10, runLast = FALSE) - } - } -} - -if (args[5] == "TRUE"){ - pdf_output <- args[6] - flag_pdf <- TRUE -} - -checkFCS(args[2], channels, args[4], flag_default, flag_pdf, pdf_output)
--- a/fcs_scatterplot/getDensityPlots.xml Mon Feb 27 12:52:20 2017 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,71 +0,0 @@ -<tool id="gen_density_plots" name="Generate scatter plots" version="1.0"> - <description>for any given markers in FCS file.</description> - <requirements> - <requirement type="package" version="3.3.0">r</requirement> - <requirement type="package" version="1.38.2">bioconductor-flowcore</requirement> - <requirement type="package" version="1.6.0">bioconductor-flowdensity</requirement> - </requirements> - <stdio> - <exit_code range="10" level="fatal" description="Please provide a comma separated list of channels to plot" /> - <exit_code range="11" level="fatal" description="Please provide numeric values for the list of channels to plot" /> - </stdio> - <command><![CDATA[ - Rscript --slave --vanilla $__tool_directory__/getDensityPlots.R --args "${input}" "${channels}" "${outpng}" $outformat "${outpdf}" - ]]> - </command> - <inputs> - <param format="fcs" name="input" type="data" label="FCS file"/> - <param name="channels" type="text" label="Markers to plot:" value="i.e.:1,3,4" help="By default, will plot FSC vs SSC if the channels are found."/> - <param name="outformat" type="select" label="Output PDF?"> - <option value="FALSE">No, thank you</option> - <option value="TRUE">Yes, please</option> - </param> - </inputs> - <outputs> - <data format="pdf" name="outpdf" label="Scatter Plots of ${channels} from ${input.name}"> - <filter>outformat=="TRUE"</filter> - </data> - <data format="png" name="outpng" label="Scatter Plots of ${channels} from ${input.name}"/> - </outputs> - <tests> - <test> - <param name="input" value="testfcs1.fcs"/> - <param name="channels" value="1,3"/> - <param name="outformat" value="TRUE"/> - <output name="outpdf" file="graph.pdf" compare="sim_size"/> - <output name="outpng" file="graph.png" compare="sim_size"/> - </test> - <test> - <param name="input" value="testfcs1.fcs"/> - <param name="channels" value="i.e.:1,3,4"/> - <param name="outformat" value="FALSE"/> - <output name="outpng" file="graph2.png" compare="sim_size"/> - </test> - </tests> - <help><![CDATA[ - This tool allows generation of density scatter plots using flowDensity. - ------ - -**Input files** - -This tool takes valid FCS files as input. - -**Output files** - -This tool generates a scatter plot for each marker combination in a single png file. A pdf file can optionally be generated. - ------ - -**Example** - -*Output*: - -.. image:: static/images/densityplots.png - ]]> - </help> - <citations> - <citation type="doi">10.1093/bioinformatics/btu677</citation> - <citation type="doi">10.1186/1471-2105-10-106</citation> - </citations> -</tool>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/getDensityPlots.R Thu Jul 16 08:00:52 2020 -0400 @@ -0,0 +1,130 @@ +#!/usr/bin/Rscript --vanilla +# Density Plot Module for Galaxy +# FlowDensity +###################################################################### +# Copyright (c) 2016 Northrop Grumman. +# All rights reserved. +###################################################################### +# +# Version 1 +# Cristel Thomas +# +# + +library(flowCore) +library(flowDensity) + +generateGraph <- function(input, channels, output, plot_default=TRUE, + flag_pdf=FALSE) { + fcs <- read.FCS(input, transformation=F) + ## marker names + markers <- colnames(fcs) + print_markers <- as.vector(pData(parameters(fcs))$desc) + # Update print_markers if the $P?S not in the FCS file + for (i in 1:length(print_markers)) { + if (is.na(print_markers[i])) { + print_markers[i] <- markers[i] + } + } + + if (plot_default) { + channels <- c(grep(colnames(fcs), pattern="Forward scatter", ignore.case=TRUE), + grep(colnames(fcs), pattern="Side scatter", ignore.case=TRUE)) + if (length(channels) == 0){ + channels <- c(grep(colnames(fcs), pattern="FSC"), + grep(colnames(fcs), pattern="SSC")) + if (length(channels) > 2) { + #get first FSC and corresponding SSC + channels <- c(grep(colnames(fcs), pattern="FSC-A"), + grep(colnames(fcs), pattern="SSC-A")) + if (length(channels) == 0) { + channels <- c(grep(colnames(fcs), pattern="FSC-H"), + grep(colnames(fcs), pattern="SSC-H")) + if (length(channels) == 0) { + channels <- c(grep(colnames(fcs), pattern="FSC-W"), + grep(colnames(fcs), pattern="SSC-W")) + } + } + } + } + if (length(channels) == 0) { + warning('No forward/side scatter channels found, no plots will be generated.') + quit(save = "no", status = 10, runLast = FALSE) + } + } + + nb_markers <- length(channels) + if (nb_markers == 1) { + warning('There is only one marker selected to plot.') + quit(save = "no", status = 12, runLast = FALSE) + } + for (j in nb_markers) { + if (channels[j] > length(markers)){ + warning('Please indicate markers between 1 and ', length(markers)) + quit(save = "no", status = 10, runLast = FALSE) + } + } + nb_rows <- ceiling(((nb_markers-1)*nb_markers)/4) + h <- 400 * nb_rows + if (flag_pdf) { + pdf(output, useDingbats=FALSE, onefile=TRUE) + par(mfrow=c(2,2)) + for (m in 1:(nb_markers - 1)) { + for (n in (m+1):nb_markers) { + plotDens(fcs, c(channels[m],channels[n]), xlab = print_markers[channels[m]], ylab = print_markers[channels[n]]) + } + } + dev.off() + } else { + png(output, type="cairo", height=h, width=800) + par(mfrow=c(nb_rows,2)) + for (m in 1:(nb_markers - 1)) { + for (n in (m+1):nb_markers) { + plotDens(fcs, c(channels[m],channels[n]), xlab = print_markers[channels[m]], ylab = print_markers[channels[n]]) + } + } + dev.off() + } +} + +checkFCS <- function(input_file, channels, output_file, plot_default=TRUE, + flag_pdf=FALSE){ + isValid <- F + # Check file beginning matches FCS standard + tryCatch({ + isValid <- isFCSfile(input_file) + }, error = function(ex) { + print (paste(" ! Error in isFCSfile", ex)) + }) + + if (isValid) { + generateGraph(input_file, channels, output_file, plot_default, flag_pdf) + } else { + print (paste(input_file, "does not meet FCS standard")) + } +} + +args <- commandArgs(trailingOnly = TRUE) +channels <- list() +flag_default <- FALSE +flag_pdf <- FALSE + +if (args[2]=="None" || args[2]== "" || args[2] == "i.e.:1,3,4") { + flag_default <- TRUE +} else { + channels <- as.numeric(strsplit(args[2], ",")[[1]]) + for (channel in channels){ + if (is.na(channel)){ + quit(save = "no", status = 11, runLast = FALSE) + } + } + if (length(channels) == 1){ + warning('Please indicate more than one marker to plot.') + quit(save = "no", status = 10, runLast = FALSE) + } +} + +if (args[4] == "PDF"){ + flag_pdf <- TRUE +} +checkFCS(args[1], channels, args[3], flag_default, flag_pdf)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/getDensityPlots.xml Thu Jul 16 08:00:52 2020 -0400 @@ -0,0 +1,76 @@ +<tool id="gen_density_plots" name="Generate scatter plots" version="1.0+galaxy0"> + <description>for any given markers in FCS file</description> + <requirements> + <requirement type="package" version="1.10.0">bioconductor-flowdensity</requirement> + </requirements> + <stdio> + <exit_code range="1:9" level="fatal" /> + <exit_code range="10" level="fatal" description="Please provide a comma separated list of channels to plot" /> + <exit_code range="11" level="fatal" description="Please provide numeric values for the list of channels to plot" /> + <exit_code range="12" level="fatal" description="Please provide more than one channel to plot" /> + <exit_code range="13:" level="fatal" /> + </stdio> + <command><![CDATA[ + Rscript --slave --vanilla '$__tool_directory__/getDensityPlots.R' '${input}' '${channels}' '${output}' '${outformat}' + ]]> + </command> + <inputs> + <param format="fcs" name="input" type="data" label="FCS file"/> + <param name="channels" type="text" label="Markers to plot:" value="i.e.:1,3,4" help="By default, will plot FSC vs SSC if the channels are found."/> + <param name="outformat" type="select" label="Output Format" help="PDF will be larger files that may take some time to load."> + <option value="PNG">PNG</option> + <option value="PDF">PDF</option> + </param> + </inputs> + <outputs> + <data format="png" name="output" label="Scatter Plots of ${channels} from ${input.name} in ${outformat}"> + <change_format> + <when input="outformat" value="PDF" format="pdf" /> + </change_format> + </data> + </outputs> + <tests> + <test> + <param name="input" value="testfcs1.fcs"/> + <param name="channels" value="1,3"/> + <param name="outformat" value="PDF"/> + <output name="output" file="graph.pdf" compare="sim_size" delta="1000000"/> + </test> + <test> + <param name="input" value="testfcs1.fcs"/> + <param name="channels" value="i.e.:1,3,4"/> + <param name="outformat" value="PNG"/> + <output name="output" file="graph2.png" compare="sim_size" delta="1000000"/> + </test> + </tests> + <help><![CDATA[ + This tool allows generation of density scatter plots using flowDensity. + +----- + +**Input files** + +This tool takes valid FCS files as input. + +**Output files** + +This tool generates a scatter plot for each marker combination in a single png file. A pdf file can optionally be generated. + +class:: warningmark + +PDF are larger files that may take some time to load. It might be faster to download the PDF output once generated to open it locally. + +----- + +**Example** + +*Output*: + +.. image:: ./static/images/flowtools/densityplots.png + ]]> + </help> + <citations> + <citation type="doi">10.1093/bioinformatics/btu677</citation> + <citation type="doi">10.1186/1471-2105-10-106</citation> + </citations> +</tool>