annotate dimsPredictPuritySingle.R @ 15:42bfb67c3b62 draft default tip

planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
author tomnl
date Wed, 27 Nov 2019 12:33:15 +0000
parents b82a7c818839
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
1 library(msPurity)
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
2 library(optparse)
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
3 print(sessionInfo())
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
4
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
5 option_list <- list(
b82a7c818839 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
42bfb67c3b62 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"),
42bfb67c3b62 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=''),
42bfb67c3b62 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
b82a7c818839 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"),
b82a7c818839 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
42bfb67c3b62 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),
42bfb67c3b62 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
b82a7c818839 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),
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
15 make_option("--ppm", default=4),
b82a7c818839 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"),
b82a7c818839 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"),
b82a7c818839 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"),
b82a7c818839 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"),
b82a7c818839 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),
b82a7c818839 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"),
b82a7c818839 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")
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
23 )
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
24
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
25 # store options
b82a7c818839 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))
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
27
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
28 print(sessionInfo())
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
29 print(opt)
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
30
15
42bfb67c3b62 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
31 print(opt$mzML_files)
42bfb67c3b62 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
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
33
15
42bfb67c3b62 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
34 str_to_vec <- function(x){
42bfb67c3b62 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
35 print(x)
42bfb67c3b62 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
36 x <- trimws(strsplit(x, ',')[[1]])
42bfb67c3b62 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
37 return(x[x != ""])
42bfb67c3b62 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
38 }
0
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
39
15
42bfb67c3b62 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){
42bfb67c3b62 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
41 mzML_filename <- trimws(mzML_filename)
42bfb67c3b62 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)
42bfb67c3b62 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)
42bfb67c3b62 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){
42bfb67c3b62 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])
42bfb67c3b62 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
46 }else{
42bfb67c3b62 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))
42bfb67c3b62 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
48 }
42bfb67c3b62 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
49 }
0
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
50
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
51
15
42bfb67c3b62 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
52 if (is.null(opt$dimspy)){
42bfb67c3b62 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')
42bfb67c3b62 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)){
42bfb67c3b62 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
55 mzML_file <- opt$mzML_file
42bfb67c3b62 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)){
42bfb67c3b62 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,
42bfb67c3b62 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
58 opt$mzML_filename)
42bfb67c3b62 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
59 }else{
42bfb67c3b62 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)
42bfb67c3b62 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
61 }
42bfb67c3b62 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
62 }else{
42bfb67c3b62 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,
42bfb67c3b62 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)
42bfb67c3b62 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
65
42bfb67c3b62 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]
42bfb67c3b62 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
67 print(filename)
42bfb67c3b62 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
42bfb67c3b62 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
42bfb67c3b62 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]
42bfb67c3b62 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])
42bfb67c3b62 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
72
42bfb67c3b62 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)
42bfb67c3b62 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
74 print(filename)
42bfb67c3b62 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
75
42bfb67c3b62 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
76
42bfb67c3b62 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)){
42bfb67c3b62 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
78 mzML_file <- opt$mzML_file
42bfb67c3b62 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)){
42bfb67c3b62 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)
42bfb67c3b62 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
81 }else{
42bfb67c3b62 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)
42bfb67c3b62 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
83 }
42bfb67c3b62 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
84
42bfb67c3b62 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
42bfb67c3b62 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
86 df <- indf[4:nrow(indf),]
42bfb67c3b62 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)){
42bfb67c3b62 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,]
42bfb67c3b62 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
89 }
42bfb67c3b62 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'
42bfb67c3b62 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
91
42bfb67c3b62 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
92 if ('nan' %in% df$mz){
42bfb67c3b62 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
42bfb67c3b62 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
94 }
42bfb67c3b62 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
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
96 }
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
97
b82a7c818839 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)){
b82a7c818839 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),]
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
100 }
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
101
b82a7c818839 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)){
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
103 im <- NULL
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
104 }else{
b82a7c818839 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,
b82a7c818839 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)
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
107 }
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
108
b82a7c818839 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)){
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
110 isotopes <- FALSE
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
111 }else{
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
112 isotopes <- TRUE
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
113 }
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
114
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
115 if (is.null(opt$sim)){
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
116 sim=FALSE
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
117 }else{
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
118 sim=TRUE
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
119 }
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
120
15
42bfb67c3b62 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
121 minOffset = as.numeric(opt$minoffset)
42bfb67c3b62 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
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
123
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
124 if (opt$iwNorm=='none'){
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
125 iwNorm = FALSE
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
126 iwNormFun = NULL
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
127 }else if (opt$iwNorm=='gauss'){
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
128 iwNorm = TRUE
b82a7c818839 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)
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
130 }else if (opt$iwNorm=='rcosine'){
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
131 iwNorm = TRUE
b82a7c818839 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)
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
133 }else if (opt$iwNorm=='QE5'){
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
134 iwNorm = TRUE
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
135 iwNormFun = msPurity::iwNormQE.5()
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
136 }
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
137
b82a7c818839 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')
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
139 print(head(df))
15
42bfb67c3b62 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
140 print(mzML_file)
0
b82a7c818839 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
42bfb67c3b62 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
142 filepth=mzML_file,
0
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
143 minOffset=minOffset,
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
144 maxOffset=maxOffset,
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
145 ppm=opt$ppm,
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
146 mzML=TRUE,
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
147 sim = sim,
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
148 ilim = opt$ilim,
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
149 isotopes = isotopes,
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
150 im = im,
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
151 iwNorm = iwNorm,
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
152 iwNormFun = iwNormFun
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
153 )
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
154 predicted <- cbind(df, predicted)
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
155
b82a7c818839 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
tomnl
parents:
diff changeset
156 print(head(predicted))
b82a7c818839 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
42bfb67c3b62 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
158
42bfb67c3b62 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
159 write.table(predicted,
42bfb67c3b62 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'),
42bfb67c3b62 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
161 row.names=FALSE, sep='\t')
42bfb67c3b62 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
162
42bfb67c3b62 planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc
tomnl
parents: 0
diff changeset
163