Mercurial > repos > tomnl > lcms_interval_scheduling
comparison topn.R @ 0:21a76537a900 draft
planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
| author | tomnl |
|---|---|
| date | Tue, 27 Mar 2018 06:53:12 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:21a76537a900 |
|---|---|
| 1 library(XCMSwrapper) | |
| 2 library(optparse) | |
| 3 | |
| 4 | |
| 5 option_list <- list( | |
| 6 make_option("--sample_metadata", type="character"), | |
| 7 make_option("--out_dir", type="character"), | |
| 8 make_option("--class", type="character"), | |
| 9 make_option("--file_include", type="character"), | |
| 10 make_option("--cores", type="character"), | |
| 11 make_option("--scan_dens", type="numeric"), | |
| 12 make_option("--n", type="numeric"), | |
| 13 make_option("--ppm", type="numeric"), | |
| 14 make_option("--snthr", type="numeric"), | |
| 15 make_option("--minfrac", type="numeric"), | |
| 16 make_option("--polarity", type="character"), | |
| 17 make_option("--time_window_choice", type="character"), | |
| 18 make_option("--files", type="character"), | |
| 19 make_option("--galaxy_files", type="character") | |
| 20 | |
| 21 ) | |
| 22 | |
| 23 # store options | |
| 24 opt<- parse_args(OptionParser(option_list=option_list)) | |
| 25 | |
| 26 | |
| 27 time_window_choice<- trimws(strsplit(opt$time_window_choice, ';')[[1]]) | |
| 28 time_window_choice <- time_window_choice[time_window_choice != ""] | |
| 29 tdf <- plyr::ldply(time_window_choice, function(x){trimws(strsplit(x, ',')[[1]])}) | |
| 30 colnames(tdf) <- c('min', 'max') | |
| 31 tdf$min <- as.numeric(tdf$min) | |
| 32 tdf$max <- as.numeric(tdf$max) | |
| 33 | |
| 34 # Nearline processing | |
| 35 params <- list( | |
| 36 topn.class = opt$class, | |
| 37 topn.class.files = opt$file_include, | |
| 38 topn.msPurity = TRUE, | |
| 39 topn.cores = opt$cores, | |
| 40 topn.scanDens = opt$scan_dens, # for scan range x to y, take every 'n' scan (i.e. x, x+n, x+2n ... y) | |
| 41 topn.timeRange = tdf, | |
| 42 topn.chunks = NULL, #list(c = 3, timeWin = c(0,1800)), # e.g. list(c = 3, timeWin = c(0,1800)) #chunk time range 0-1800 in to 3. | |
| 43 topn.n = opt$n, # number of peaks to take per window | |
| 44 topn.ppm = opt$ppm, | |
| 45 topn.snthr = opt$snthr, | |
| 46 topn.minfrac= opt$minfrac, | |
| 47 topn.clustType = 'hc', | |
| 48 topn.camera_xcms = '', | |
| 49 faahKO=FALSE | |
| 50 ) | |
| 51 | |
| 52 | |
| 53 # | |
| 54 sample_metadata <- read.table(opt$sample_metadata, sep='\t', stringsAsFactors=FALSE) | |
| 55 | |
| 56 filepaths <- trimws(strsplit(opt$files, ',')[[1]]) | |
| 57 filepaths <- filepaths[filepaths != ""] | |
| 58 filepaths_wo_suffix <- unlist(lapply(filepaths, function(x){tools::file_path_sans_ext(basename(x))})) | |
| 59 | |
| 60 galaxy_files <- trimws(strsplit(opt$galaxy_files, ',')[[1]]) | |
| 61 galaxy_files <- galaxy_files[galaxy_files != ""] | |
| 62 | |
| 63 if(!is.null(opt$class)){ | |
| 64 # print(sample_metadata[,1]) | |
| 65 file_select <- sample_metadata[,1][sample_metadata[,2]==opt$class] | |
| 66 chosen_files <- galaxy_files[filepaths_wo_suffix %in% file_select] | |
| 67 }else{ | |
| 68 chosen_files <- galaxy_files | |
| 69 } | |
| 70 print(chosen_files) | |
| 71 | |
| 72 if(!is.null(opt$file_include)){ | |
| 73 file_include <- trimws(strsplit(opt$file_include, ',')[[1]]) | |
| 74 file_include <- as.numeric(file_include[file_include != ""]) | |
| 75 print(file_include) | |
| 76 chosen_files <- chosen_files[file_include] | |
| 77 } | |
| 78 print(chosen_files) | |
| 79 params$topn.filenames = chosen_files | |
| 80 | |
| 81 topn = getTopn(obj=NULL, params) | |
| 82 colnames(topn) = c('mzmed', 'rtmin', 'rtmax') | |
| 83 topn = create_incl(grps = topn, incl_in = NULL, write_file = F, posneg = opt$polarity, comments='topn') | |
| 84 | |
| 85 | |
| 86 print('HEAD ROWS OF TOPN') | |
| 87 print(head(topn)) | |
| 88 write.table(topn, file.path(opt$out_dir, 'topn_peaklist.tsv'), row.names=FALSE, sep='\t') |
