Mercurial > repos > tomnl > lcms_interval_scheduling
comparison cameradims.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 | ac50ece6573e |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:21a76537a900 |
|---|---|
| 1 library(optparse) | |
| 2 library(cameraDIMS) | |
| 3 | |
| 4 option_list <- list( | |
| 5 make_option(c("-i", "--in_file"), type="character"), | |
| 6 make_option(c("-o", "--out_dir"), type="character"), | |
| 7 make_option("--ppm_iso", default=5), | |
| 8 make_option("--ppm_adduct", default=5), | |
| 9 make_option("--maxiso", default=4), | |
| 10 make_option("--mzabs_iso", default=0.015), | |
| 11 make_option("--mzabs_adduct", default=0.015), | |
| 12 make_option("--maxcharge", default=3), | |
| 13 make_option("--maxmol", default=3), | |
| 14 make_option("--polarity", default='pos'), | |
| 15 make_option("--rule_path"), | |
| 16 make_option("--rule_type"), | |
| 17 make_option("--export_ruleset", action="store_true"), | |
| 18 make_option("--intensity_filter", default=0) | |
| 19 ) | |
| 20 | |
| 21 | |
| 22 # store options | |
| 23 opt<- parse_args(OptionParser(option_list=option_list)) | |
| 24 | |
| 25 print(sessionInfo()) | |
| 26 print(opt) | |
| 27 | |
| 28 df <- read.table(opt$in_file, header = TRUE, sep='\t', stringsAsFactors=FALSE) | |
| 29 | |
| 30 print('IN DATA') | |
| 31 print(nrow(df)) | |
| 32 print(head(df)) | |
| 33 | |
| 34 devppm_adduct <- opt$ppm_adduct / 1000000 | |
| 35 devppm_iso <- opt$ppm_iso / 1000000 | |
| 36 | |
| 37 paramiso <- list("ppm"=opt$ppm_iso, | |
| 38 "filter"=TRUE, | |
| 39 "maxcharge"=opt$maxcharge, | |
| 40 "maxiso"=opt$maxiso, | |
| 41 "mzabs"=opt$mzabs_iso, | |
| 42 "intval"='maxo', | |
| 43 "minfrac"=0.5, | |
| 44 'IM'=NULL, | |
| 45 'devppm'=devppm_iso) | |
| 46 | |
| 47 paramadduct <- list("maxCharge"= opt$maxcharge, | |
| 48 "maxMol"= opt$maxmol, | |
| 49 'devppm'=devppm_adduct, | |
| 50 "mzabs"=opt$mzabs_adduct, | |
| 51 'IM'=NULL, | |
| 52 "filter"=TRUE, | |
| 53 'ppm'=opt$ppm_adduct, | |
| 54 "quasimolion"= c(1, 6, 8), | |
| 55 'polarity'=opt$polarity) | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 if(is.null(opt$export_ruleset)){ | |
| 61 rule_export <- FALSE | |
| 62 }else{ | |
| 63 rule_export <- TRUE | |
| 64 } | |
| 65 | |
| 66 df$mz <- as.numeric(df$mz) | |
| 67 | |
| 68 print(head(df$mz)) | |
| 69 | |
| 70 if ('intensity' %in% colnames(df)){ | |
| 71 colnames(df)[colnames(df)=='intensity'] = 'i' | |
| 72 } | |
| 73 | |
| 74 if (!'peakID' %in% colnames(df)){ | |
| 75 df <- cbind('peakID'=1:nrow(df), df) | |
| 76 } | |
| 77 | |
| 78 df$i <- as.numeric(df$i) | |
| 79 | |
| 80 df <- df[df$i>opt$intensity_filter,] | |
| 81 | |
| 82 cameraOut <- cameraDIMS(data=df, | |
| 83 params_iso=paramiso, | |
| 84 params_adduct=paramadduct, | |
| 85 rule_type=opt$rule_type, | |
| 86 rule_pth=opt$rule_path, | |
| 87 rule_sep='\t', | |
| 88 rule_export=rule_export) | |
| 89 | |
| 90 | |
| 91 print(head(cameraOut[[1]])) | |
| 92 print(head(cameraOut[[2]])) | |
| 93 | |
| 94 | |
| 95 out_file1 <- file.path(opt$out_dir, 'camera_annotated_peaklist.txt') | |
| 96 out_file2 <- file.path(opt$out_dir, 'camera_annotated_map.txt') | |
| 97 out_file3 <- file.path(opt$out_dir, 'ruleset.txt') | |
| 98 | |
| 99 write.table(cameraOut[[1]], out_file1, row.names=FALSE, sep='\t') | |
| 100 write.table(cameraOut[[2]], out_file2, row.names=FALSE, sep='\t') | |
| 101 | |
| 102 if (rule_export){ | |
| 103 write.table(cameraOut[[3]], out_file3, row.names=FALSE, sep='\t') | |
| 104 } |
