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