comparison spectral_matching.R @ 0:fe7d7cc95ca5 draft

planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2e847122cf605951c334858455fc1d3ebdb189e9-dirty
author tomnl
date Tue, 27 Mar 2018 06:03:50 -0400
parents
children 1a88758357ed
comparison
equal deleted inserted replaced
-1:000000000000 0:fe7d7cc95ca5
1 library(msPurity)
2 library(optparse)
3
4 option_list <- list(
5 make_option(c("-o", "--out_dir"), type="character"),
6 make_option("--target_db_pth", type="character"),
7 make_option("--library_db_pth", type="character"),
8 make_option("--ra_thres_l", default=0),
9 make_option("--ra_thres_t", default=2),
10 make_option("--cores", default=1),
11 make_option("--pol", default='positive'),
12 make_option("--ppm_tol_prod", default=10),
13 make_option("--ppm_tol_prec", default=5),
14 make_option("--score_thres", default=0.6),
15 make_option("--instrument_types", type='character'),
16 make_option("--library_sources", type='character'),
17 make_option("--scan_ids", default=NA),
18 make_option("--topn", default=NA),
19 make_option("--mzML_files", type="character"),
20 make_option("--galaxy_names", type="character"),
21 make_option("--create_new_database", action="store_true")
22
23 )
24
25 # store options
26 opt<- parse_args(OptionParser(option_list=option_list))
27
28
29
30 if (!is.null(opt$create_new_database)){
31 target_db_pth <- file.path(opt$out_dir, 'db_with_spectral_matching.sqlite')
32 file.copy(opt$target_db_pth, target_db_pth)
33 }else{
34 target_db_pth <- opt$target_db_pth
35 }
36
37
38 if (opt$instrument_types=='None'){
39 instrument_types <- NA
40 }else{
41 instrument_types <- trimws(strsplit(opt$instrument_types, ',')[[1]])
42 }
43 if (opt$library_sources=='None'){
44 library_sources <- NA
45 }else{
46 library_sources <- trimws(strsplit(opt$library_sources, ',')[[1]])
47 }
48
49
50 if (!is.na(opt$scan_ids)){
51 scan_ids <- trimws(strsplit(opt$scan_ids, ',')[[1]])
52 scan_ids <- scan_ids[scan_ids != ""]
53 }else{
54 scan_ids <- NA
55 }
56
57
58 print(instrument_types)
59 print(library_sources)
60 print(scan_ids)
61
62 result <- msPurity::spectral_matching(
63 target_db_pth =target_db_pth ,
64 library_db_pth = opt$library_db_pth,
65 ra_thres_l = opt$ra_thres_l,
66 ra_thres_t = opt$ra_thres_t,
67 cores = opt$cores,
68 pol = opt$pol,
69 ppm_tol_prod = opt$ppm_tol_prod,
70 ppm_tol_prec = opt$ppm_tol_prec,
71 score_thres = opt$score_thres,
72 out_dir = opt$out_dir,
73 topn = opt$topn,
74 grp_peaklist = NA,
75
76 instrument_types = instrument_types,
77 library_sources = library_sources,
78 scan_ids = scan_ids)
79
80 print(file.path(result$result_db_pth))
81
82 write.table(result$xcms_summary_df, file.path(opt$out_dir, 'xcms_hits.tsv'), row.names=FALSE, sep='\t')
83
84 con <- DBI::dbConnect(RSQLite::SQLite(), file.path(result$result_db_pth))
85 # con <- DBI::dbConnect(RSQLite::SQLite(), file.path(opt$out_dir, 'result.sqlite'))
86
87 cmd <- paste('SELECT * FROM matches
88 LEFT JOIN library_meta ON matches.lid=library_meta.lid
89 LEFT JOIN s_peak_meta ON matches.pid=s_peak_meta.pid
90 LEFT JOIN fileinfo ON s_peak_meta.fileid=fileinfo.fileid
91 WHERE matches.score >= ', opt$score_thres)
92 print(cmd)
93 scan_hits <- DBI::dbGetQuery(con, cmd)
94
95 write.table(scan_hits, file.path(opt$out_dir, 'scan_hits.tsv'), row.names=FALSE, sep='\t')