Repository 'check_fcs_headers'
hg clone https://toolshed.g2.bx.psu.edu/repos/immport-devteam/check_fcs_headers

Changeset 1:a5609a84ed16 (2020-07-23)
Previous changeset 0:d3957a51cc51 (2017-02-27)
Commit message:
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/check_fcs_headers commit e5be067c50262354a028bd03b77beb8369fb6fb1"
added:
getFCSheader.R
getFCSheaders.xml
test-data/input1.fcs
test-data/input2.fcs
test-data/input3.fcs
test-data/output.tabular
removed:
check_fcs_headers/getFCSheader.R
check_fcs_headers/getFCSheaders.py
check_fcs_headers/getFCSheaders.xml
check_fcs_headers/test-data/input1.fcs
check_fcs_headers/test-data/input2.fcs
check_fcs_headers/test-data/input3.fcs
check_fcs_headers/test-data/output.tabular
b
diff -r d3957a51cc51 -r a5609a84ed16 check_fcs_headers/getFCSheader.R
--- a/check_fcs_headers/getFCSheader.R Mon Feb 27 12:16:44 2017 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
[
@@ -1,43 +0,0 @@
-# FCS Headers Module for Galaxy
-# FlowCore
-######################################################################
-#                  Copyright (c) 2016 Northrop Grumman.
-#                          All rights reserved.
-######################################################################
-#
-# Version 1
-# Cristel Thomas
-#
-#
-
-library(flowCore)
-
-getFCSMarkerNames <- function(input, output) {
-  fcs <- read.FCS(input, transformation=F)
-  ## marker names
-  channels <- colnames(fcs)
-  markers <- as.vector(pData(parameters(fcs))$desc)
-  df <- data.frame(channels, markers)
-  fcs_markers <- capture.output(df)
-
-  write.table(df, output, sep="\t")
-}
-
-checkFCS <- function(input_file, output_file) {
-  isValid <- F
-  # Check file beginning matches FCS standard
-  tryCatch({
-    isValid = isFCSfile(input_file)
-  }, error = function(ex) {
-    print (paste("    ! Error in isFCSfile", ex))
-  })
-
-  if (isValid) {
-    getFCSMarkerNames(input_file, output_file)
-  } else {
-    print (paste(input_file, "does not meet FCS standard"))
-  }
-}
-
-args <- commandArgs(trailingOnly = TRUE)
-checkFCS(args[2], args[3])
b
diff -r d3957a51cc51 -r a5609a84ed16 check_fcs_headers/getFCSheaders.py
--- a/check_fcs_headers/getFCSheaders.py Mon Feb 27 12:16:44 2017 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
[
@@ -1,81 +0,0 @@
-#!/usr/bin/env python
-######################################################################
-#                  Copyright (c) 2016 Northrop Grumman.
-#                          All rights reserved.
-######################################################################
-from __future__ import print_function
-import sys
-import os
-
-from argparse import ArgumentParser
-
-
-def get_fcs_marker_list(marker_file):
-    with open(marker_file, "r") as mrkrs:
-        useless_first_line = mrkrs.readline()
-        channels = []
-        markers = []
-        for lines in mrkrs:
-            stuff = lines.strip().split("\t")
-            channels.append(stuff[1].strip("\""))
-            markers.append(stuff[2].strip("\""))
-    fcs_markers = [
-        "\t".join(channels),
-        "\t".join(markers)
-    ]
-    return(fcs_markers)
-
-
-def print_fcs_headers(files, filenames, outfile, tool_dir):
-    headers = {}
-    tool = "/".join([tool_dir, "getFCSheader.R"])
-    for eachfile in files:
-        tmp_output = "tmp_fcs_headers.txt"
-        run_command = " ". join(["Rscript --slave --vanilla", tool, "--args", eachfile, tmp_output])
-        os.system(run_command)
-        headers[eachfile] = get_fcs_marker_list(tmp_output)
-
-    with open(outfile, "w") as outf:
-        for i, flc in enumerate(files):
-            outf.write("\t".join([filenames[i], "channels", headers[flc][0]]) + "\n")
-        for j, flm in enumerate(files):
-            outf.write("\t".join([filenames[j], "markers", headers[flm][1]]) + "\n")
-    return
-
-
-if __name__ == "__main__":
-    parser = ArgumentParser(
-             prog="GetFCSHeaders",
-             description="Gets the headers of all files in given set.")
-
-    parser.add_argument(
-            '-i',
-            dest="input_files",
-            required=True,
-            action='append',
-            help="File location for the text files.")
-
-    parser.add_argument(
-            '-n',
-            dest="file_names",
-            required=True,
-            action='append',
-            help="File names.")
-
-    parser.add_argument(
-            '-t',
-            dest="tool_dir",
-            required=True,
-            help="Path to the tool directory")
-
-    parser.add_argument(
-            '-o',
-            dest="output_file",
-            required=True,
-            help="Name of the output file.")
-
-    args = parser.parse_args()
-    input_files = [f for f in args.input_files]
-    file_names = [fn for fn in args.file_names]
-    print_fcs_headers(input_files, file_names, args.output_file, args.tool_dir)
-    sys.exit(0)
b
diff -r d3957a51cc51 -r a5609a84ed16 check_fcs_headers/getFCSheaders.xml
--- a/check_fcs_headers/getFCSheaders.xml Mon Feb 27 12:16:44 2017 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
[
@@ -1,73 +0,0 @@
-<tool id="get_fcs_headers" name="Get list of markers" version="1.0">
-  <description>in FCS files.</description>
-  <requirements>
-    <requirement type="package" version="3.3.0">r</requirement>
-    <requirement type="package" version="1.38.2">bioconductor-flowcore</requirement>
-  </requirements>
-  <stdio>
-    <exit_code range="2:" level="fatal" description="See stderr for more details." />
-  </stdio>
-  <command><![CDATA[
-    python $__tool_directory__/getFCSheaders.py -o "${output_file}" -t $__tool_directory__
- #for $f in $input#
-    -i "${f}"
-    -n "${f.name}"
- #end for#
-  ]]>
-  </command>
-  <inputs>
-    <param format="fcs" name="input" type="data_collection" collection_type="list" label="FCS files Collection"/>
-  </inputs>
-  <outputs>
-    <data format="tabular" name="output_file" label="Headers of files in ${input.name}"/>
-  </outputs>
-  <tests>
-    <test>
-      <param name="input">
-        <collection type="list">
-          <element name="input1.fcs" value="input1.fcs"/>
-          <element name="input2.fcs" value="input2.fcs"/>
-          <element name="input3.fcs" value="input3.fcs"/>
-        </collection>
-      </param>
-      <output name="output_file" file="output.tabular"/>
-    </test>
-  </tests>
-  <help><![CDATA[
-  This tool returns a table of the headers of a set of FCS files.
-
------
-
-**Input files**
-
-This tool requires collections of FCS files as input.
-
-**Output file**
-
-The output file is a table listing the markers and channels for each file.
-
------
-
-**Example**
-
-*File1*::
-
-  Marker1 Marker2 Marker3
-  34      45      12
-  33      65      10
-
-*File2*::
-
-  Marker4 Marker5 Marker3
-  19      62      98
-  12      36      58
-
-*Output*::
-
-  File1 channels Channel1 Channel2 Channel3
-  File2 channels Channel4 Channel5 Channel3
-  File1 markers  Marker1  Marker2  Marker3
-  File2 markers  Marker4  Marker5  Marker3
- ]]>
-  </help>
-</tool>
b
diff -r d3957a51cc51 -r a5609a84ed16 check_fcs_headers/test-data/input1.fcs
b
Binary file check_fcs_headers/test-data/input1.fcs has changed
b
diff -r d3957a51cc51 -r a5609a84ed16 check_fcs_headers/test-data/input2.fcs
b
Binary file check_fcs_headers/test-data/input2.fcs has changed
b
diff -r d3957a51cc51 -r a5609a84ed16 check_fcs_headers/test-data/input3.fcs
b
Binary file check_fcs_headers/test-data/input3.fcs has changed
b
diff -r d3957a51cc51 -r a5609a84ed16 check_fcs_headers/test-data/output.tabular
--- a/check_fcs_headers/test-data/output.tabular Mon Feb 27 12:16:44 2017 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
b
@@ -1,6 +0,0 @@
-input3.fcs channels FSC-H SSC-H FL1-H FL2-H FL3-H FL4-H
-input1.fcs channels FSC-H SSC-H FL1-H FL2-H FL3-H FL4-H
-input2.fcs channels FSC-H SSC-H FL1-H FL2-H FL3-H FL4-H
-input3.fcs markers Forward Scatter Side Scatter FITC CD4 PE CCR3 PP CD8 APC CCR4
-input1.fcs markers Forward Scatter Side Scatter FITC CD4 PE CD25 PP CD3 APC CD45RA
-input2.fcs markers Forward Scatter Side Scatter FITC CD4 PE CXCR3 PP CD8 APC CCR5
b
diff -r d3957a51cc51 -r a5609a84ed16 getFCSheader.R
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/getFCSheader.R Thu Jul 23 08:14:29 2020 -0400
[
@@ -0,0 +1,87 @@
+#!/usr/bin/Rscript --vanilla
+# FCS Headers Module for Galaxy
+# FlowCore
+######################################################################
+#                  Copyright (c) 2016 Northrop Grumman.
+#                          All rights reserved.
+######################################################################
+#
+# Version 2
+# May 2018
+# Cristel Thomas
+#
+#
+
+library(flowCore)
+
+getFCSChannels <- function(input_fcs) {
+  fcs <- read.FCS(input_fcs, transformation=F)
+  return(colnames(fcs))
+}
+
+getFCSMarkers <- function(input_fcs){
+  ffcs <- read.FCS(input_fcs, transformation=F)
+  fmarkers <- as.vector(pData(parameters(ffcs))$desc)
+  return(fmarkers)
+}
+
+getFCSMarkerNames <- function(output_file="", file_paths=vector(),
+                              fcs_names=vector()) {
+  check_files <- sapply(file_paths, isFCSfile)
+  channels <- lapply(file_paths[check_files], getFCSChannels)
+  markers <- lapply(file_paths[check_files], getFCSMarkers)
+
+  nb_col <- max(lengths(channels))
+  nc <- lapply(channels, `length<-`, nb_col)
+  ct <- t(as.data.frame(nc))
+
+  nm <- lapply(markers, `length<-`, nb_col)
+  mt <- t(as.data.frame(nm))
+
+  nb_files <- sum(check_files)
+  Index <- rep(c("channels", "markers"), each=nb_files)
+  Filename <- rep(fcs_names[check_files], 2)
+
+  idx_nb <- seq(nb_col)
+  ttt <- rbind(ct,mt)
+  finalt <- cbind(Filename, Index, ttt)
+  colnames(finalt)[3:length(colnames(finalt))] <- idx_nb
+
+
+  if (nb_files != length(file_paths)){
+    not_fcs <- fcs_names[!check_files]
+    new_df <- cbind(not_fcs, "Not a valid FCS file")
+    empty_frame <- data.frame(matrix("", nrow=length(not_fcs), ncol=nb_col),
+                              stringsAsFactors = F)
+    not_fcs_files <- cbind(new_df, empty_frame)
+    colnames(not_fcs_files) <- colnames(finalt)
+    new_final <- rbind(finalt, not_fcs_files)
+    write.table(new_final, file=output_file, quote=F, row.names=F, col.names=T,
+                sep='\t', append=F)
+    quit(save = "no", status = 10, runLast = FALSE)
+  } else {
+    # output file
+    write.table(finalt, file=output_file, quote=F, row.names=F, col.names=T,
+                sep='\t',
+    append=F)
+  }
+}
+
+################################################################################
+################################################################################
+
+args <- commandArgs(trailingOnly = TRUE)
+
+i <- 1
+nb_files <- (length(args)-1) / 2
+fcs_files <- character(nb_files)
+fcs_names <- character(nb_files)
+for (j in 1:length(args)){
+  if (!j%%2){
+    fcs_files[[i]] <- args[[j]]
+    fcs_names[[i]]<- args[[j+1]]
+    i <- i + 1
+  }
+}
+
+getFCSMarkerNames(args[1], fcs_files, fcs_names)
b
diff -r d3957a51cc51 -r a5609a84ed16 getFCSheaders.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/getFCSheaders.xml Thu Jul 23 08:14:29 2020 -0400
[
@@ -0,0 +1,72 @@
+<tool id="get_fcs_headers" name="Get list of markers" version="2.0+galaxy0">
+  <description>in FCS files.</description>
+  <requirements>
+    <requirement type="package" version="1.42.0">bioconductor-flowcore</requirement>
+  </requirements>
+  <stdio>
+    <exit_code range="10" level="warning" description="Not all files are valid FCS files, see output for details." />
+  </stdio>
+  <command><![CDATA[
+         Rscript '$__tool_directory__/getFCSheader.R' '${output_file}'
+    #for $f in $input
+  '${f}' '${f.name}'
+    #end for
+  ]]>
+  </command>
+  <inputs>
+    <param format="fcs" name="input" type="data_collection" collection_type="list" label="FCS files Collection"/>
+  </inputs>
+  <outputs>
+      <data format="tabular" name="output_file" label="Headers of files in ${input.name}"/>
+  </outputs>
+  <tests>
+    <test>
+      <param name="input">
+        <collection type="list">
+          <element name="input1.fcs" value="input1.fcs"/>
+          <element name="input2.fcs" value="input2.fcs"/>
+          <element name="input3.fcs" value="input3.fcs"/>
+        </collection>
+      </param>
+      <output name="output_file" file="output.tabular" lines_diff="8"/>
+    </test>
+  </tests>
+  <help><![CDATA[
+  This tool returns a table of the headers of a set of FCS files.
+
+-----
+
+**Input files**
+
+This tool requires collections of FCS files as input.
+
+**Output file**
+
+The output file is a table listing the markers and channels for each file.
+
+-----
+
+**Example**
+
+*File1*::
+
+   Marker1 Marker2 Marker3
+   34      45      12
+   33      65      10
+
+*File2*::
+
+   Marker4 Marker5 Marker3
+   19      62      98
+   12      36      58
+
+*Output*::
+
+   Filename Index    1        2        3
+   File1 channels Channel1 Channel2 Channel3
+   File2 channels Channel4 Channel5 Channel3
+   File1 markers  Marker1  Marker2  Marker3
+   File2 markers  Marker4  Marker5  Marker3
+ ]]>
+  </help>
+</tool>
b
diff -r d3957a51cc51 -r a5609a84ed16 test-data/input1.fcs
b
Binary file test-data/input1.fcs has changed
b
diff -r d3957a51cc51 -r a5609a84ed16 test-data/input2.fcs
b
Binary file test-data/input2.fcs has changed
b
diff -r d3957a51cc51 -r a5609a84ed16 test-data/input3.fcs
b
Binary file test-data/input3.fcs has changed
b
diff -r d3957a51cc51 -r a5609a84ed16 test-data/output.tabular
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/output.tabular Thu Jul 23 08:14:29 2020 -0400
b
@@ -0,0 +1,7 @@
+Filename Index 1 2 3 4 5 6
+input3.fcs channels FSC-H SSC-H FL1-H FL2-H FL3-H FL4-H
+input2.fcs channels FSC-H SSC-H FL1-H FL2-H FL3-H FL4-H
+input1.fcs channels FSC-H SSC-H FL1-H FL2-H FL3-H FL4-H
+input3.fcs markers Forward Scatter Side Scatter FITC CD4 PE CCR3 PP CD8 APC CCR4
+input2.fcs markers Forward Scatter Side Scatter FITC CD4 PE CXCR3 PP CD8 APC CCR5
+input1.fcs markers Forward Scatter Side Scatter FITC CD4 PE CD25 PP CD3 APC CD45RA