annotate anticipated_purity_lcms.R @ 14:088f318b2944 draft default tip

planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 1800a3818988f21ef129e500818c9a087fce5875
author tomnl
date Wed, 18 Jul 2018 05:57:15 -0400
parents cb8dce9812ff
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
1 library(msPurity)
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
2 library(optparse)
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
3 print(sessionInfo())
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
4
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
5 option_list <- list(
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
6 make_option(c("--xset_path"), type="character"),
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
7 make_option(c("-o", "--out_dir"), type="character"),
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
8 make_option(c("--mzML_path"), type="character"),
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
9 make_option("--minOffset", default=0.5),
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
10 make_option("--maxOffset", default=0.5),
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
11 make_option("--ilim", default=0.05),
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
12 make_option("--iwNorm", default="none", type="character"),
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
13 make_option("--exclude_isotopes", action="store_true"),
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
14 make_option("--isotope_matrix", type="character"),
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
15 make_option("--purityType", default="purityFWHMmedian"),
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
16 make_option("--singleFile", default=0),
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
17 make_option("--cores", default=4),
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
18 make_option("--xgroups", type="character"),
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
19 make_option("--rdata_name", default='xset'),
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
20 make_option("--camera_xcms", default='xset'),
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
21 make_option("--files", type="character"),
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
22 make_option("--galaxy_files", type="character"),
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
23 make_option("--choose_class", type="character"),
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
24 make_option("--ignore_files", type="character"),
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
25 make_option("--rtraw_columns", action="store_true")
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
26 )
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
27
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
28 # store options
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
29 opt<- parse_args(OptionParser(option_list=option_list))
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
30
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
31 print(sessionInfo())
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
32 print(opt)
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
33
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
34 if (!is.null(opt$xgroups)){
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
35 xgroups = as.numeric(strsplit(opt$xgroups, ',')[[1]])
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
36 }else{
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
37 xgroups = NULL
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
38 }
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
39
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
40
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
41
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
42 print(xgroups)
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
43
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
44 if (!is.null(opt$remove_nas)){
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
45 df <- df[!is.na(df$mz),]
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
46 }
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
47
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
48 if (is.null(opt$isotope_matrix)){
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
49 im <- NULL
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
50 }else{
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
51 im <- read.table(opt$isotope_matrix,
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
52 header = TRUE, sep='\t', stringsAsFactors = FALSE)
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
53 }
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
54
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
55 if (is.null(opt$exclude_isotopes)){
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
56 isotopes <- FALSE
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
57 }else{
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
58 isotopes <- TRUE
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
59 }
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
60
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
61 if (is.null(opt$rtraw_columns)){
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
62 rtraw_columns <- FALSE
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
63 }else{
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
64 rtraw_columns <- TRUE
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
65 }
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
66
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
67 loadRData <- function(rdata_path, xset_name){
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
68 #loads an RData file, and returns the named xset object if it is there
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
69 load(rdata_path)
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
70 print(ls())
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
71 return(get(ls()[ls() == xset_name]))
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
72 }
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
73
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
74 target_obj <- loadRData(opt$xset_path, opt$rdata_name)
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
75
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
76 if (opt$camera_xcms=='camera'){
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
77 xset <- target_obj@xcmsSet
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
78 }else{
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
79 xset <- target_obj
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
80 }
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
81
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
82 print(xset)
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
83
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
84 minOffset = as.numeric(opt$minOffset)
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
85 maxOffset = as.numeric(opt$maxOffset)
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
86
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
87
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
88 if (opt$iwNorm=='none'){
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
89 iwNorm = FALSE
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
90 iwNormFun = NULL
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
91 }else if (opt$iwNorm=='gauss'){
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
92 iwNorm = TRUE
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
93 iwNormFun = msPurity::iwNormGauss(minOff=-minOffset, maxOff=maxOffset)
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
94 }else if (opt$iwNorm=='rcosine'){
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
95 iwNorm = TRUE
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
96 iwNormFun = msPurity::iwNormRcosine(minOff=-minOffset, maxOff=maxOffset)
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
97 }else if (opt$iwNorm=='QE5'){
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
98 iwNorm = TRUE
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
99 iwNormFun = msPurity::iwNormQE.5()
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
100 }
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
101
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
102 print(xset@filepaths)
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
103
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
104
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
105
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
106 if (!is.null(opt$files)){
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
107 updated_filepaths <- trimws(strsplit(opt$files, ',')[[1]])
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
108 updated_filepaths <- updated_filepaths[updated_filepaths != ""]
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
109 print(updated_filepaths)
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
110 updated_filenames = basename(updated_filepaths)
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
111 original_filenames = basename(xset@filepaths)
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
112 update_idx = match(updated_filenames, original_filenames)
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
113
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
114 if (!is.null(opt$galaxy_files)){
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
115 galaxy_files <- trimws(strsplit(opt$galaxy_files, ',')[[1]])
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
116 galaxy_files <- galaxy_files[galaxy_files != ""]
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
117 xset@filepaths <- galaxy_files[update_idx]
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
118 }else{
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
119 xset@filepaths <- updated_filepaths[update_idx]
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
120 }
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
121 }
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
122
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
123 if (!is.null(opt$choose_class)){
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
124 classes <- trimws(strsplit(opt$choose_class, ',')[[1]])
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
125
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
126
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
127 ignore_files_class <- which(!as.character(xset@phenoData$class) %in% classes)
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
128
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
129 print('choose class')
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
130 print(ignore_files_class)
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
131 }else{
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
132 ignore_files_class <- NA
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
133 }
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
134
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
135 if (!is.null(opt$ignore_files)){
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
136 ignore_files_string <- trimws(strsplit(opt$ignore_files, ',')[[1]])
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
137 filenames <- rownames(xset@phenoData)
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
138 ignore_files <- which(filenames %in% ignore_files_string)
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
139
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
140 ignore_files <- unique(c(ignore_files, ignore_files_class))
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
141 ignore_files <- ignore_files[ignore_files != ""]
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
142 }else{
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
143 if (anyNA(ignore_files_class)){
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
144 ignore_files <- NULL
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
145 }else{
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
146 ignore_files <- ignore_files_class
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
147 }
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
148
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
149 }
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
150
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
151 print('ignore_files')
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
152 print(ignore_files)
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
153
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
154
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
155 ppLCMS <- msPurity::purityX(xset=xset,
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
156 offsets=c(minOffset, maxOffset),
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
157 cores=opt$cores,
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
158 xgroups=xgroups,
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
159 purityType=opt$purityType,
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
160 ilim = opt$ilim,
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
161 isotopes = isotopes,
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
162 im = im,
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
163 iwNorm = iwNorm,
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
164 iwNormFun = iwNormFun,
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
165 singleFile = opt$singleFile,
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
166 fileignore = ignore_files,
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
167 rtrawColumns=rtraw_columns)
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
168
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
169
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
170 dfp <- ppLCMS@predictions
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
171
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
172 # to make compatable with deconrank
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
173 colnames(dfp)[colnames(dfp)=='grpid'] = 'peakID'
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
174 colnames(dfp)[colnames(dfp)=='median'] = 'medianPurity'
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
175 colnames(dfp)[colnames(dfp)=='mean'] = 'meanPurity'
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
176 colnames(dfp)[colnames(dfp)=='sd'] = 'sdPurity'
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
177 colnames(dfp)[colnames(dfp)=='stde'] = 'sdePurity'
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
178 colnames(dfp)[colnames(dfp)=='RSD'] = 'cvPurity'
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
179 colnames(dfp)[colnames(dfp)=='pknm'] = 'pknmPurity'
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
180 if(sum(is.na(dfp$medianPurity))>0){
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
181 dfp[is.na(dfp$medianPurity),]$medianPurity = 0
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
182 }
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
183
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
184 print('saving tsv')
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
185 print(head(dfp))
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
186 write.table(dfp, file.path(opt$out_dir, 'anticipated_purity_lcms.tsv'), row.names=FALSE, sep='\t')
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
187 print('saving RData')
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
188 save.image(file.path(opt$out_dir, 'anticipated_purity_lcms.RData'))