changeset 0:164cd5384f1d draft

Uploaded
author immport-devteam
date Mon, 27 Feb 2017 12:52:20 -0500
parents
children 413f3e610295
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
diffstat 7 files changed, 199 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/fcs_scatterplot/getDensityPlots.R	Mon Feb 27 12:52:20 2017 -0500
@@ -0,0 +1,128 @@
+# 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)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/fcs_scatterplot/getDensityPlots.xml	Mon Feb 27 12:52:20 2017 -0500
@@ -0,0 +1,71 @@
+<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>
Binary file fcs_scatterplot/static/images/flowtools/densityplots.png has changed
Binary file fcs_scatterplot/test-data/graph.pdf has changed
Binary file fcs_scatterplot/test-data/graph.png has changed
Binary file fcs_scatterplot/test-data/graph2.png has changed
Binary file fcs_scatterplot/test-data/testfcs1.fcs has changed