annotate FCSConvert.R @ 1:99bf034c674d draft default tip

"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
author azomics
date Mon, 22 Jun 2020 17:26:06 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
1 #!/usr/bin/env Rscript
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
2 # ImmPort FCSConvert
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
3 ######################################################################
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
4 # Copyright (c) 2016 Northrop Grumman.
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
5 # All rights reserved.
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
6 ######################################################################
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
7 #
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
8 # Converts the FCS file to text without transformaton
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
9 # To run in R
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
10 # 1) library(flowCore)
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
11 # 2) source("FCSConvert.R")
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
12 # 3) transformFCS("filename")
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
13 #
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
14 # Version 1.4.1
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
15 # March 2016 -- added lines to run directly from command line
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
16 #
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
17
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
18 library(flowCore)
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
19
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
20 convertFCS <- function(fcs,compensate=FALSE,debug=FALSE) {
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
21 # Check file type and FCS version
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
22 if (class(fcs)[1] != "flowFrame") {
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
23 print("convertFCS requires flowFrame object as input")
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
24 return(FALSE)
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
25 }
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
26
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
27 keywords <- keyword(fcs)
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
28 markers <- colnames(fcs)
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
29 print_markers <- as.vector(pData(parameters(fcs))$desc)
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
30 # Update print_markers if the $P?S not in the FCS file
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
31 for (i in 1:length(print_markers)) {
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
32 if (is.na(print_markers[i])) {
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
33 print_markers[i] <- markers[i]
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
34 }
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
35 }
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
36
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
37 if (debug) {
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
38 print("****Inside convertFCS")
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
39 print(paste(" FCS version:", keywords$FCSversion))
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
40 print(paste(" DATATYPE:", keywords['$DATATYPE']))
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
41 }
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
42
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
43 if (keywords$FCSversion == "2" ||
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
44 keywords$FCSversion == "3" ||
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
45 keywords$FCSversion == "3.1" ) {
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
46 datatype = unlist(keywords['$DATATYPE'])
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
47 if (datatype == 'F') {
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
48 # Apply compensation if available and requested
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
49 spill <- keyword(fcs)$SPILL
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
50 if (is.null(spill) == FALSE && compensate == TRUE) {
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
51 if (debug) {
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
52 print("Attempting compensation")
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
53 }
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
54 tryCatch({ fcs = compensate(fcs, spill) },
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
55 error = function(ex) { str(ex); })
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
56 }
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
57 # Process fcs expression data, using transformation
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
58 # based on category of the marker.
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
59 fcs_exprs <- exprs(fcs)
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
60 colnames(fcs_exprs) <- print_markers
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
61 } else if (datatype == 'I') {
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
62 fcs_exprs <- exprs(fcs)
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
63 colnames(fcs_exprs) = print_markers
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
64 } else {
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
65 print(paste("Data type", datatype, "in FCS 3 is not supported"))
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
66 fcs_exprs <- FALSE
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
67 }
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
68 } else {
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
69 print(paste("FCS version", keyword(fcs)$FCSversion, "is not supported"))
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
70 fcs_exprs <- FALSE
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
71 }
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
72 fcs_exprs
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
73 }
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
74
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
75
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
76 #
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
77 # Starting function for processing a FCS file
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
78 #
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
79 processFCSFile <- function(input_file, output_file="",
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
80 keyword_file="",compensate=FALSE, debug=FALSE) {
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
81
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
82 #
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
83 # Generate the file names for the output_file and keyword_file
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
84 #
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
85 pieces <- unlist(strsplit(input_file, .Platform$file.sep))
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
86 filename <- pieces[length(pieces)]
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
87
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
88 if (output_file == "") {
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
89 filepieces = unlist(strsplit(filename, '\\.'))
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
90 #replace .fcs with .txt; append .txt if not ending in .fcs
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
91 if (filepieces[length(filepieces)] == 'fcs') {
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
92 filepieces[length(filepieces)] <- 'txt'
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
93 } else {
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
94 filepieces[length(filepieces)+1] <- 'txt'
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
95 }
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
96 output_file <- paste(filepieces, collapse = '.')
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
97 }
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
98
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
99 if (keyword_file == "") {
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
100 filepieces <- unlist(strsplit(filename, '\\.'))
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
101 #replace .fcs with .keyword; append .keyword if not ending in .fcs
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
102 if (filepieces[length(filepieces)] == 'fcs') {
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
103 filepieces[length(filepieces)] <- 'keyword'
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
104 } else {
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
105 filepieces[length(filepieces)+1] <- 'keyword'
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
106 }
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
107 keyword_file <- paste(filepieces, collapse = '.')
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
108 }
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
109
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
110 if (debug) {
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
111 print (paste("Converting file: ",input_file))
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
112 print (paste("Original file name: ",filename))
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
113 print (paste("Output file name: ",output_file))
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
114 print (paste("Keyword file name: ",keyword_file))
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
115 }
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
116 fcs <- read.FCS(input_file, transformation=F)
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
117 keywords <- keyword(fcs)
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
118 write.table(as.matrix(keywords),file=keyword_file, quote=F,
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
119 row.names=T, col.names=F, sep='=', append=F)
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
120
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
121 transformed_data <- convertFCS(fcs,compensate,debug)
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
122 write.table(transformed_data, file=output_file, quote=F,
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
123 row.names=F,col.names=T, sep='\t', append=F)
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
124 }
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
125
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
126 # Convert FCS file without transformation
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
127 # @param input_file FCS file to be transformed
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
128 # @param output_file FCS file transformed ".txt" extension
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
129 # @param keyword_file FCS file keywords ".keywords" extension"
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
130 # @param compensate Flag indicating whether to apply compensation
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
131 # matrix if it exists.
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
132 transformFCS <- function(input_file, output_file="",
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
133 compensate=FALSE, keyword_file="", debug=FALSE) {
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
134
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
135 isValid <- F
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
136 # Check file beginning matches FCS standard
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
137 tryCatch({
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
138 isValid <- isFCSfile(input_file)
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
139 }, error = function(ex) {
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
140 print (paste(" ! Error in isFCSfile", ex))
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
141 })
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
142
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
143 if (isValid) {
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
144 processFCSFile(input_file, output_file, keyword_file, compensate, debug)
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
145 } else {
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
146 print (paste(input_file, "does not meet FCS standard"))
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
147 }
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
148 }
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
149
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
150 args <- commandArgs(trailingOnly = TRUE)
99bf034c674d "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/convert_fcs_to_text commit 5ac9759a4f1850b200cd7a301e6662ef8adca55d"
azomics
parents:
diff changeset
151 transformFCS(args[1], args[2], args[3])