Mercurial > repos > computational-metabolomics > mspurity_createdatabase
comparison filterFragSpectra.R @ 8:efd14b326007 draft
planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 7e1748612a9f9dce11a9e54ff36752b600e7aea3
| author | computational-metabolomics |
|---|---|
| date | Wed, 12 Jun 2024 16:05:01 +0000 |
| parents | 0cc6b67dccb8 |
| children |
comparison
equal
deleted
inserted
replaced
| 7:0cc6b67dccb8 | 8:efd14b326007 |
|---|---|
| 7 option_list <- list( | 7 option_list <- list( |
| 8 make_option("--out_rdata", type = "character"), | 8 make_option("--out_rdata", type = "character"), |
| 9 make_option("--out_peaklist_prec", type = "character"), | 9 make_option("--out_peaklist_prec", type = "character"), |
| 10 make_option("--out_peaklist_frag", type = "character"), | 10 make_option("--out_peaklist_frag", type = "character"), |
| 11 make_option("--pa", type = "character"), | 11 make_option("--pa", type = "character"), |
| 12 | |
| 13 make_option("--ilim", default = 0.0), | 12 make_option("--ilim", default = 0.0), |
| 14 make_option("--plim", default = 0.0), | 13 make_option("--plim", default = 0.0), |
| 15 | |
| 16 make_option("--ra", default = 0.0), | 14 make_option("--ra", default = 0.0), |
| 17 make_option("--snr", default = 0.0), | 15 make_option("--snr", default = 0.0), |
| 18 | |
| 19 make_option("--rmp", action = "store_true"), | 16 make_option("--rmp", action = "store_true"), |
| 20 make_option("--snmeth", default = "median", type = "character"), | 17 make_option("--snmeth", default = "median", type = "character"), |
| 21 make_option("--allfrag", action = "store_true") | 18 make_option("--allfrag", action = "store_true") |
| 22 ) | 19 ) |
| 23 | 20 |
| 24 opt <- parse_args(OptionParser(option_list = option_list)) | 21 opt <- parse_args(OptionParser(option_list = option_list)) |
| 25 print(opt) | 22 print(opt) |
| 26 | 23 |
| 27 | 24 |
| 28 loadRData <- function(rdata_path, name) { | 25 loadRData <- function(rdata_path, name) { |
| 29 #loads an RData file, and returns the named xset object if it is there | 26 # loads an RData file, and returns the named xset object if it is there |
| 30 load(rdata_path) | 27 load(rdata_path) |
| 31 return(get(ls()[ls() %in% name])) | 28 return(get(ls()[ls() %in% name])) |
| 32 } | 29 } |
| 33 | 30 |
| 34 # Requires | 31 # Requires |
| 35 pa <- loadRData(opt$pa, "pa") | 32 pa <- loadRData(opt$pa, "pa") |
| 36 | 33 |
| 37 if (is.null(opt$rmp)) { | 34 if (is.null(opt$rmp)) { |
| 38 opt$rmp <- FALSE | 35 opt$rmp <- FALSE |
| 39 }else{ | 36 } else { |
| 40 opt$rmp <- TRUE | 37 opt$rmp <- TRUE |
| 41 } | 38 } |
| 42 | 39 |
| 43 if (is.null(opt$allfrag)) { | 40 if (is.null(opt$allfrag)) { |
| 44 opt$allfrag <- FALSE | 41 opt$allfrag <- FALSE |
| 45 }else{ | 42 } else { |
| 46 opt$allfrag <- TRUE | 43 opt$allfrag <- TRUE |
| 47 } | 44 } |
| 48 | 45 |
| 49 pa <- filterFragSpectra(pa, | 46 pa <- filterFragSpectra(pa, |
| 50 ilim = opt$ilim, | 47 ilim = opt$ilim, |
| 51 plim = opt$plim, | 48 plim = opt$plim, |
| 52 ra = opt$ra, | 49 ra = opt$ra, |
| 53 snr = opt$snr, | 50 snr = opt$snr, |
| 54 rmp = opt$rmp, | 51 rmp = opt$rmp, |
| 55 allfrag = opt$allfrag, | 52 allfrag = opt$allfrag, |
| 56 snmeth = opt$snmeth) | 53 snmeth = opt$snmeth |
| 54 ) | |
| 57 | 55 |
| 58 print(pa) | 56 print(pa) |
| 59 save(pa, file = opt$out_rdata) | 57 save(pa, file = opt$out_rdata) |
| 60 | 58 |
| 61 # get the msms data for grpid from the purityA object | 59 # get the msms data for grpid from the purityA object |
| 80 } | 78 } |
| 81 | 79 |
| 82 | 80 |
| 83 | 81 |
| 84 if (length(pa) > 0) { | 82 if (length(pa) > 0) { |
| 85 | |
| 86 if (length(pa@grped_ms2) == 0) { | 83 if (length(pa@grped_ms2) == 0) { |
| 87 message("No spectra available") | 84 message("No spectra available") |
| 88 } else { | 85 } else { |
| 89 | |
| 90 # get group ids | 86 # get group ids |
| 91 grpids <- unique(as.character(pa@grped_df$grpid)) | 87 grpids <- unique(as.character(pa@grped_df$grpid)) |
| 92 | 88 |
| 93 # loop through all the group ids | 89 # loop through all the group ids |
| 94 df_fragments <- plyr::adply(grpids, 1, msmsgrp, pa = pa) | 90 df_fragments <- plyr::adply(grpids, 1, msmsgrp, pa = pa) |
| 95 df_fragments <- merge(df_fragments, pa@puritydf[, c("pid", "acquisitionNum", "precursorScanNum")], by = "pid") | 91 df_fragments <- merge(df_fragments, pa@puritydf[, c("pid", "acquisitionNum", "precursorScanNum")], by = "pid") |
| 96 df_fragments <- df_fragments[order(df_fragments$grpid, df_fragments$pid, df_fragments$mz), ] | 92 df_fragments <- df_fragments[order(df_fragments$grpid, df_fragments$pid, df_fragments$mz), ] |
| 97 #select and reorder columns | 93 # select and reorder columns |
| 98 df_fragments <- df_fragments[, c("grpid", "pid", "precursorScanNum", "acquisitionNum", "fileid", "mz", "i", "snr", "ra", "purity_pass_flag", "intensity_pass_flag", "ra_pass_flag", "snr_pass_flag", "pass_flag")] | 94 df_fragments <- df_fragments[, c("grpid", "pid", "precursorScanNum", "acquisitionNum", "fileid", "mz", "i", "snr", "ra", "purity_pass_flag", "intensity_pass_flag", "ra_pass_flag", "snr_pass_flag", "pass_flag")] |
| 99 | 95 |
| 100 pa@grped_df$filename <- sapply(pa@grped_df$fileid, function(x) names(pa@fileList)[as.integer(x)]) | 96 pa@grped_df$filename <- sapply(pa@grped_df$fileid, function(x) names(pa@fileList)[as.integer(x)]) |
| 101 | 97 |
| 102 print(head(pa@grped_df)) | 98 print(head(pa@grped_df)) |
