annotate dimsPredictPuritySingle.R @ 15:b71677d4f958 draft default tip

planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
author tomnl
date Wed, 27 Nov 2019 12:31:10 +0000
parents ca0ac330f1a4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
1 library(msPurity)
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
2 library(optparse)
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
3 print(sessionInfo())
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
4
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
5 option_list <- list(
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
6 make_option(c("--mzML_file"), type="character"),
15
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
7 make_option(c("--mzML_files"), type="character"),
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
8 make_option(c("--mzML_filename"), type="character", default=''),
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
9 make_option(c("--mzML_galaxy_names"), type="character", default=''),
0
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
10 make_option(c("--peaks_file"), type="character"),
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
11 make_option(c("-o", "--out_dir"), type="character"),
15
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
12 make_option("--minoffset", default=0.5),
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
13 make_option("--maxoffset", default=0.5),
0
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
14 make_option("--ilim", default=0.05),
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
15 make_option("--ppm", default=4),
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
16 make_option("--dimspy", action="store_true"),
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
17 make_option("--sim", action="store_true"),
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
18 make_option("--remove_nas", action="store_true"),
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
19 make_option("--iwNorm", default="none", type="character"),
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
20 make_option("--file_num_dimspy", default=1),
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
21 make_option("--exclude_isotopes", action="store_true"),
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
22 make_option("--isotope_matrix", type="character")
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
23 )
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
24
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
25 # store options
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
26 opt<- parse_args(OptionParser(option_list=option_list))
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
27
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
28 print(sessionInfo())
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
29 print(opt)
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
30
15
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
31 print(opt$mzML_files)
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
32 print(opt$mzML_galaxy_names)
0
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
33
15
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
34 str_to_vec <- function(x){
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
35 print(x)
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
36 x <- trimws(strsplit(x, ',')[[1]])
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
37 return(x[x != ""])
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
38 }
0
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
39
15
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
40 find_mzml_file <- function(mzML_files, galaxy_names, mzML_filename){
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
41 mzML_filename <- trimws(mzML_filename)
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
42 mzML_files <- str_to_vec(mzML_files)
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
43 galaxy_names <- str_to_vec(galaxy_names)
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
44 if (mzML_filename %in% galaxy_names){
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
45 return(mzML_files[galaxy_names==mzML_filename])
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
46 }else{
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
47 stop(paste("mzML file not found - ", mzML_filename))
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
48 }
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
49 }
0
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
50
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
51
15
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
52 if (is.null(opt$dimspy)){
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
53 df <- read.table(opt$peaks_file, header = TRUE, sep='\t')
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
54 if (file.exists(opt$mzML_file)){
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
55 mzML_file <- opt$mzML_file
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
56 }else if (!is.null(opt$mzML_files)){
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
57 mzML_file <- find_mzml_file(opt$mzML_files, opt$mzML_galaxy_names,
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
58 opt$mzML_filename)
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
59 }else{
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
60 mzML_file <- file.path(opt$mzML_file, filename)
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
61 }
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
62 }else{
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
63 indf <- read.table(opt$peaks_file,
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
64 header = TRUE, sep='\t', stringsAsFactors = FALSE)
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
65
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
66 filename <- colnames(indf)[8:ncol(indf)][opt$file_num_dimspy]
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
67 print(filename)
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
68 # check if the data file is mzML or RAW (can only use mzML currently) so
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
69 # we expect an mzML file of the same name in the same folder
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
70 indf$i <- indf[,colnames(indf)==filename]
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
71 indf[,colnames(indf)==filename] <- as.numeric(indf[,colnames(indf)==filename])
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
72
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
73 filename = sub("raw", "mzML", filename, ignore.case = TRUE)
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
74 print(filename)
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
75
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
76
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
77 if (file.exists(opt$mzML_file)){
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
78 mzML_file <- opt$mzML_file
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
79 }else if (!is.null(opt$mzML_files)){
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
80 mzML_file <- find_mzml_file(opt$mzML_files, opt$mzML_galaxy_names, filename)
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
81 }else{
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
82 mzML_file <- file.path(opt$mzML_file, filename)
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
83 }
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
84
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
85 # Update the dimspy output with the correct information
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
86 df <- indf[4:nrow(indf),]
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
87 if ('blank_flag' %in% colnames(df)){
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
88 df <- df[df$blank_flag==1,]
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
89 }
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
90 colnames(df)[colnames(df)=='m.z'] <- 'mz'
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
91
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
92 if ('nan' %in% df$mz){
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
93 df[df$mz=='nan',]$mz <- NA
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
94 }
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
95 df$mz <- as.numeric(df$mz)
0
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
96 }
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
97
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
98 if (!is.null(opt$remove_nas)){
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
99 df <- df[!is.na(df$mz),]
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
100 }
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
101
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
102 if (is.null(opt$isotope_matrix)){
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
103 im <- NULL
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
104 }else{
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
105 im <- read.table(opt$isotope_matrix,
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
106 header = TRUE, sep='\t', stringsAsFactors = FALSE)
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
107 }
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
108
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
109 if (is.null(opt$exclude_isotopes)){
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
110 isotopes <- FALSE
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
111 }else{
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
112 isotopes <- TRUE
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
113 }
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
114
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
115 if (is.null(opt$sim)){
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
116 sim=FALSE
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
117 }else{
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
118 sim=TRUE
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
119 }
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
120
15
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
121 minOffset = as.numeric(opt$minoffset)
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
122 maxOffset = as.numeric(opt$maxoffset)
0
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
123
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
124 if (opt$iwNorm=='none'){
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
125 iwNorm = FALSE
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
126 iwNormFun = NULL
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
127 }else if (opt$iwNorm=='gauss'){
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
128 iwNorm = TRUE
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
129 iwNormFun = msPurity::iwNormGauss(minOff=-minOffset, maxOff=maxOffset)
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
130 }else if (opt$iwNorm=='rcosine'){
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
131 iwNorm = TRUE
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
132 iwNormFun = msPurity::iwNormRcosine(minOff=-minOffset, maxOff=maxOffset)
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
133 }else if (opt$iwNorm=='QE5'){
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
134 iwNorm = TRUE
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
135 iwNormFun = msPurity::iwNormQE.5()
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
136 }
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
137
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
138 print('FIRST ROWS OF PEAK FILE')
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
139 print(head(df))
15
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
140 print(mzML_file)
0
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
141 predicted <- msPurity::dimsPredictPuritySingle(df$mz,
15
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
142 filepth=mzML_file,
0
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
143 minOffset=minOffset,
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
144 maxOffset=maxOffset,
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
145 ppm=opt$ppm,
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
146 mzML=TRUE,
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
147 sim = sim,
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
148 ilim = opt$ilim,
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
149 isotopes = isotopes,
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
150 im = im,
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
151 iwNorm = iwNorm,
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
152 iwNormFun = iwNormFun
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
153 )
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
154 predicted <- cbind(df, predicted)
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
155
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
156 print(head(predicted))
ca0ac330f1a4 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
157 print(file.path(opt$out_dir, 'dimsPredictPuritySingle_output.tsv'))
15
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
158
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
159 write.table(predicted,
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
160 file.path(opt$out_dir, 'dimsPredictPuritySingle_output.tsv'),
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
161 row.names=FALSE, sep='\t')
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
162
b71677d4f958 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
163