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