# HG changeset patch # User immport-devteam # Date 1488215804 18000 # Node ID d3957a51cc519051175c6f63dd12e9066ecf5034 Uploaded diff -r 000000000000 -r d3957a51cc51 check_fcs_headers/getFCSheader.R --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/check_fcs_headers/getFCSheader.R Mon Feb 27 12:16:44 2017 -0500 @@ -0,0 +1,43 @@ +# 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]) diff -r 000000000000 -r d3957a51cc51 check_fcs_headers/getFCSheaders.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/check_fcs_headers/getFCSheaders.py Mon Feb 27 12:16:44 2017 -0500 @@ -0,0 +1,81 @@ +#!/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) diff -r 000000000000 -r d3957a51cc51 check_fcs_headers/getFCSheaders.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/check_fcs_headers/getFCSheaders.xml Mon Feb 27 12:16:44 2017 -0500 @@ -0,0 +1,73 @@ + + in FCS files. + + r + bioconductor-flowcore + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 000000000000 -r d3957a51cc51 check_fcs_headers/test-data/input1.fcs Binary file check_fcs_headers/test-data/input1.fcs has changed diff -r 000000000000 -r d3957a51cc51 check_fcs_headers/test-data/input2.fcs Binary file check_fcs_headers/test-data/input2.fcs has changed diff -r 000000000000 -r d3957a51cc51 check_fcs_headers/test-data/input3.fcs Binary file check_fcs_headers/test-data/input3.fcs has changed diff -r 000000000000 -r d3957a51cc51 check_fcs_headers/test-data/output.tabular --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/check_fcs_headers/test-data/output.tabular Mon Feb 27 12:16:44 2017 -0500 @@ -0,0 +1,6 @@ +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