annotate spectral_matching.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(msPurityData)
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
3 library(optparse)
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
4 print(sessionInfo())
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
5
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
6
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
7 option_list <- list(
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
8 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
9 make_option("--target_db_pth", type="character"),
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
10 make_option("--library_db_pth", type="character", default=NA),
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
11 make_option("--ra_thres_l", default=0),
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
12 make_option("--ra_thres_t", default=2),
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
13 make_option("--cores", default=1),
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
14 make_option("--pol", default='positive'),
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
15 make_option("--ppm_tol_prod", default=10),
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
16 make_option("--ppm_tol_prec", default=5),
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
17 make_option("--score_thres", default=0.6),
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
18 make_option("--instrument_types", type='character'),
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
19 make_option("--library_sources", type='character'),
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
20 make_option("--scan_ids", default=NA),
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
21 make_option("--topn", default=NA),
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
22 make_option("--mzML_files", type="character"),
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
23 make_option("--galaxy_names", type="character"),
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
24 make_option("--create_new_database", action="store_true")
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
25
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
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
32
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
33 if (!is.null(opt$create_new_database)){
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
34 target_db_pth <- file.path(opt$out_dir, 'db_with_spectral_matching.sqlite')
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
35 file.copy(opt$target_db_pth, target_db_pth)
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 target_db_pth <- opt$target_db_pth
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 if (opt$instrument_types=='None'){
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
42 instrument_types <- NA
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
43 }else{
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
44 instrument_types <- trimws(strsplit(opt$instrument_types, ',')[[1]])
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
45 }
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
46 if (opt$library_sources=='None'){
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
47 library_sources <- NA
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
48 }else{
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
49 library_sources <- trimws(strsplit(opt$library_sources, ',')[[1]])
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
50 }
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
51
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
52
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
53 if (!is.na(opt$scan_ids)){
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
54 scan_ids <- trimws(strsplit(opt$scan_ids, ',')[[1]])
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
55 scan_ids <- scan_ids[scan_ids != ""]
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
56 }else{
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
57 scan_ids <- NA
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
58 }
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 print(instrument_types)
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
62 print(library_sources)
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
63 print(scan_ids)
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
64
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
65 result <- msPurity::spectral_matching(
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
66 target_db_pth =target_db_pth ,
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
67 library_db_pth = opt$library_db_pth,
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
68 ra_thres_l = opt$ra_thres_l,
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
69 ra_thres_t = opt$ra_thres_t,
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
70 cores = opt$cores,
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
71 pol = opt$pol,
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
72 ppm_tol_prod = opt$ppm_tol_prod,
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
73 ppm_tol_prec = opt$ppm_tol_prec,
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
74 score_thres = opt$score_thres,
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
75 out_dir = opt$out_dir,
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
76 topn = opt$topn,
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
77 grp_peaklist = NA,
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
78
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
79 instrument_types = instrument_types,
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
80 library_sources = library_sources,
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
81 scan_ids = scan_ids)
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
82
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
83 print(file.path(result$result_db_pth))
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
84
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
85 write.table(result$xcms_summary_df, file.path(opt$out_dir, 'xcms_hits.tsv'), row.names=FALSE, sep='\t')
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 con <- DBI::dbConnect(RSQLite::SQLite(), file.path(result$result_db_pth))
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
88 # con <- DBI::dbConnect(RSQLite::SQLite(), file.path(opt$out_dir, 'result.sqlite'))
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
89
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
90 cmd <- paste('SELECT * FROM matches
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
91 LEFT JOIN library_meta ON matches.lid=library_meta.lid
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
92 LEFT JOIN s_peak_meta ON matches.pid=s_peak_meta.pid
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
93 LEFT JOIN fileinfo ON s_peak_meta.fileid=fileinfo.fileid
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
94 WHERE matches.score >= ', opt$score_thres)
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
95 print(cmd)
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
96 scan_hits <- DBI::dbGetQuery(con, cmd)
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
97
cb8dce9812ff planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
tomnl
parents:
diff changeset
98 write.table(scan_hits, file.path(opt$out_dir, 'scan_hits.tsv'), row.names=FALSE, sep='\t')