comparison spectral_matching.R @ 5:f2683ec717fe draft default tip

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