Mercurial > repos > immport-devteam > extract_fcs_keywords
diff FCSKeyword.R @ 1:1d5e530c8a5e draft default tip
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/extract_fcs_keywords commit f0a40d58aec0a657b60df338c79dc1ee8e510aa0"
author | azomics |
---|---|
date | Mon, 22 Jun 2020 17:22:21 -0400 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/FCSKeyword.R Mon Jun 22 17:22:21 2020 -0400 @@ -0,0 +1,73 @@ +#!/usr/bin/env Rscript +# ImmPort FCSKeywords +###################################################################### +# Copyright (c) 2016 Northrop Grumman. +# All rights reserved. +###################################################################### +# +# Converts the FCS file to text without transformaton +# To run in R +# 1) library(flowCore) +# 2) source("FCSKeyword.R") +# 3) transformFCS("filename") +# +# Version 1.4.1 +# March 2016 -- added lines to run directly from command line +# + +library(flowCore) + +# +# Starting function for processing a FCS file +# +extractKeywords <- function(input_file, keyword_file="", debug=FALSE) { + # + # Generate the file names for the output_file and keyword_file + # + pieces <- unlist(strsplit(input_file, .Platform$file.sep)) + filename <- pieces[length(pieces)] + + if (keyword_file == "") { + filepieces <- unlist(strsplit(filename, '\\.')) + #replace .fcs with .keyword; append .keyword if not ending in .fcs + if (filepieces[length(filepieces)] == 'fcs') { + filepieces[length(filepieces)] = 'keyword' + } else { + filepieces[length(filepieces)+1] = 'keyword' + } + keyword_file <- paste(filepieces, collapse = '.') + } + + if (debug) { + print (paste("Converting file: ", input_file)) + print (paste("Original file name: ", filename)) + print (paste("Output file name: ", output_file)) + print (paste("Keyword file name: ", keyword_file)) + } + fcs <- read.FCS(input_file, transformation=F) + keywords <- keyword(fcs) + write.table(as.matrix(keywords), file=keyword_file, quote=F, + row.names=T, col.names=F, sep='=', append=F) +} + +# Extract Keywords +# @param input_file FCS file to be transformed +# @param keyword_file FCS file keywords ".keywords" extension" +transformFCS <- function(input_file, keyword_file="", debug=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) { + extractKeywords(input_file, keyword_file, debug) + } else { + print (paste(input_file, "does not meet FCS standard")) + } +} + +args <- commandArgs(TRUE) +transformFCS(args[1], args[2])