comparison 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
comparison
equal deleted inserted replaced
0:dc00746654dc 1:1d5e530c8a5e
1 #!/usr/bin/env Rscript
2 # ImmPort FCSKeywords
3 ######################################################################
4 # Copyright (c) 2016 Northrop Grumman.
5 # All rights reserved.
6 ######################################################################
7 #
8 # Converts the FCS file to text without transformaton
9 # To run in R
10 # 1) library(flowCore)
11 # 2) source("FCSKeyword.R")
12 # 3) transformFCS("filename")
13 #
14 # Version 1.4.1
15 # March 2016 -- added lines to run directly from command line
16 #
17
18 library(flowCore)
19
20 #
21 # Starting function for processing a FCS file
22 #
23 extractKeywords <- function(input_file, keyword_file="", debug=FALSE) {
24 #
25 # Generate the file names for the output_file and keyword_file
26 #
27 pieces <- unlist(strsplit(input_file, .Platform$file.sep))
28 filename <- pieces[length(pieces)]
29
30 if (keyword_file == "") {
31 filepieces <- unlist(strsplit(filename, '\\.'))
32 #replace .fcs with .keyword; append .keyword if not ending in .fcs
33 if (filepieces[length(filepieces)] == 'fcs') {
34 filepieces[length(filepieces)] = 'keyword'
35 } else {
36 filepieces[length(filepieces)+1] = 'keyword'
37 }
38 keyword_file <- paste(filepieces, collapse = '.')
39 }
40
41 if (debug) {
42 print (paste("Converting file: ", input_file))
43 print (paste("Original file name: ", filename))
44 print (paste("Output file name: ", output_file))
45 print (paste("Keyword file name: ", keyword_file))
46 }
47 fcs <- read.FCS(input_file, transformation=F)
48 keywords <- keyword(fcs)
49 write.table(as.matrix(keywords), file=keyword_file, quote=F,
50 row.names=T, col.names=F, sep='=', append=F)
51 }
52
53 # Extract Keywords
54 # @param input_file FCS file to be transformed
55 # @param keyword_file FCS file keywords ".keywords" extension"
56 transformFCS <- function(input_file, keyword_file="", debug=FALSE) {
57 isValid <- F
58 # Check file beginning matches FCS standard
59 tryCatch({
60 isValid = isFCSfile(input_file)
61 }, error = function(ex) {
62 print (paste(" ! Error in isFCSfile", ex))
63 })
64
65 if (isValid) {
66 extractKeywords(input_file, keyword_file, debug)
67 } else {
68 print (paste(input_file, "does not meet FCS standard"))
69 }
70 }
71
72 args <- commandArgs(TRUE)
73 transformFCS(args[1], args[2])