Mercurial > repos > tomnl > track_rt_raw
comparison create_sqlite_db.R @ 11:86e37ad9ff31 draft
planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 4116082655a03d3007a49e4a4b00fc6ad4698412-dirty
| author | tomnl |
|---|---|
| date | Mon, 07 May 2018 12:00:04 -0400 |
| parents | 26fd52ed6d21 |
| children | 291c9c7f63da |
comparison
equal
deleted
inserted
replaced
| 10:e9026031dab3 | 11:86e37ad9ff31 |
|---|---|
| 55 make_option("--cores", default=4), | 55 make_option("--cores", default=4), |
| 56 make_option("--mzML_files", type="character"), | 56 make_option("--mzML_files", type="character"), |
| 57 make_option("--galaxy_names", type="character"), | 57 make_option("--galaxy_names", type="character"), |
| 58 make_option("--grp_peaklist", type="character"), | 58 make_option("--grp_peaklist", type="character"), |
| 59 make_option("--db_name", type="character", default='lcms_data.sqlite'), | 59 make_option("--db_name", type="character", default='lcms_data.sqlite'), |
| 60 make_option("--raw_rt_columns", action="store_true") | 60 make_option("--raw_rt_columns", action="store_true"), |
| 61 make_option("--metfrag_result", type="character"), | |
| 62 make_option("--sirius_csifingerid_result", type="character") | |
| 61 ) | 63 ) |
| 64 | |
| 62 | 65 |
| 63 # store options | 66 # store options |
| 64 opt<- parse_args(OptionParser(option_list=option_list)) | 67 opt<- parse_args(OptionParser(option_list=option_list)) |
| 65 | 68 |
| 66 loadRData <- function(rdata_path, name){ | 69 loadRData <- function(rdata_path, name){ |
| 73 print(opt$xset) | 76 print(opt$xset) |
| 74 print(opt$xcms_camera_option) | 77 print(opt$xcms_camera_option) |
| 75 # Requires | 78 # Requires |
| 76 pa <- loadRData(opt$pa, 'pa') | 79 pa <- loadRData(opt$pa, 'pa') |
| 77 | 80 |
| 78 print('TESTETSTESTETE') | 81 |
| 79 print(pa@fileList) | 82 print(pa@fileList) |
| 80 | 83 |
| 81 | 84 |
| 82 if (opt$xcms_camera_option=='xcms'){ | 85 if (opt$xcms_camera_option=='xcms'){ |
| 83 xset <- loadRData(opt$xset, 'xset') | 86 xset <- loadRData(opt$xset, 'xset') |
| 124 px <- msPurity::purityX(xset, saveEIC = TRUE, | 127 px <- msPurity::purityX(xset, saveEIC = TRUE, |
| 125 cores=opt$cores, sqlitePth=db_pth, | 128 cores=opt$cores, sqlitePth=db_pth, |
| 126 rtrawColumns = rtrawColumns) | 129 rtrawColumns = rtrawColumns) |
| 127 } | 130 } |
| 128 | 131 |
| 132 con <- DBI::dbConnect(RSQLite::SQLite(), db_pth) | |
| 133 | |
| 134 add_extra_table <- function(name, pth){ | |
| 135 | |
| 136 print('CHECK1') | |
| 137 print(name) | |
| 138 print(pth) | |
| 139 if (!is.null(pth)){ | |
| 140 print('CHECK2') | |
| 141 print(pth) | |
| 142 df <- read.table(pth, header = TRUE, sep='\t', stringsAsFactors = FALSE, comment.char = "") | |
| 143 # bug for repeating headers | |
| 144 df <- df[!df$UID=='UID',] | |
| 145 | |
| 146 # get peakid, an scan id | |
| 147 df_ids <- stringr::str_split_fixed(df$UID, '-', 3) | |
| 148 colnames(df_ids) <- c('grp_id', 'file_id', 'peak_id') | |
| 149 df <- cbind(df_ids, df) | |
| 150 # export to database | |
| 151 | |
| 152 | |
| 153 DBI::dbWriteTable(con, name=name, value=df, row.names=FALSE) | |
| 154 | |
| 155 } | |
| 156 | |
| 157 } | |
| 158 | |
| 159 add_extra_table('metfrag_results', opt$metfrag_result) | |
| 160 add_extra_table('sirius_csifingerid_results', opt$sirius_csifingerid_result) | |
| 129 | 161 |
| 130 | 162 |
| 131 con <- DBI::dbConnect(RSQLite::SQLite(), db_pth) | |
| 132 | 163 |
| 133 cmd <- paste('SELECT cpg.grpid, cpg.mz, cpg.mzmin, cpg.mzmax, cpg.rt, cpg.rtmin, cpg.rtmax, c_peaks.cid, ', | 164 cmd <- paste('SELECT cpg.grpid, cpg.mz, cpg.mzmin, cpg.mzmax, cpg.rt, cpg.rtmin, cpg.rtmax, c_peaks.cid, ', |
| 134 'c_peaks.mzmin AS c_peak_mzmin, c_peaks.mzmax AS c_peak_mzmax, ', | 165 'c_peaks.mzmin AS c_peak_mzmin, c_peaks.mzmax AS c_peak_mzmax, ', |
| 135 'c_peaks.rtmin AS c_peak_rtmin, c_peaks.rtmax AS c_peak_rtmax, s_peak_meta.*, fileinfo.filename, fileinfo.nm_save ', | 166 'c_peaks.rtmin AS c_peak_rtmin, c_peaks.rtmax AS c_peak_rtmax, s_peak_meta.*, fileinfo.filename, fileinfo.nm_save ', |
| 136 'FROM c_peak_groups AS cpg ', | 167 'FROM c_peak_groups AS cpg ', |
