Mercurial > repos > tomnl > create_sqlite_db
comparison create_sqlite_db.R @ 21:7f57d501badb draft
planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 04023134d8f28e85927ca293373c506484149ead-dirty
author | tomnl |
---|---|
date | Fri, 01 Jun 2018 13:44:38 -0400 |
parents | 74917d0e89cc |
children | 5d47dd174435 |
comparison
equal
deleted
inserted
replaced
20:74917d0e89cc | 21:7f57d501badb |
---|---|
136 rtrawColumns = rtrawColumns) | 136 rtrawColumns = rtrawColumns) |
137 } | 137 } |
138 | 138 |
139 con <- DBI::dbConnect(RSQLite::SQLite(), db_pth) | 139 con <- DBI::dbConnect(RSQLite::SQLite(), db_pth) |
140 | 140 |
141 add_extra_table_elucidation <- function(name, pth, db_con, filter_Score=NA, filter_Rank=NA){ | 141 add_extra_table_elucidation <- function(name, pth, db_con){ |
142 if (is.null(pth)){ | 142 if (is.null(pth)){ |
143 return(0) | 143 return(0) |
144 } | 144 } |
145 | |
146 | |
145 DBI::dbWriteTable(conn=db_con, name=name, value=pth, sep='\t', header=T) | 147 DBI::dbWriteTable(conn=db_con, name=name, value=pth, sep='\t', header=T) |
146 | 148 |
147 | 149 |
148 } | 150 } |
149 | 151 |
160 colnames(df_ids) <- c('grp_id', 'file_id', 'pid') | 162 colnames(df_ids) <- c('grp_id', 'file_id', 'pid') |
161 df <- cbind(df_ids, df) | 163 df <- cbind(df_ids, df) |
162 DBI::dbWriteTable(db_con, name=name, value=df, row.names=FALSE, append=append) | 164 DBI::dbWriteTable(db_con, name=name, value=df, row.names=FALSE, append=append) |
163 } | 165 } |
164 | 166 |
165 add_probmetab <- function(pth, con){ | 167 add_probmetab <- function(pth, xset, con){ |
166 if (!is.null(pth)){ | 168 if (!is.null(pth)){ |
167 | 169 |
168 df <- read.table(pth, header = TRUE, sep='\t', stringsAsFactors = FALSE, comment.char = "") | 170 df <- read.table(pth, header = TRUE, sep='\t', stringsAsFactors = FALSE, comment.char = "") |
169 df$grp_id <- 1:nrow(df) | 171 df$grp_id <- match(df$name, xcms::groupnames(xset)) |
170 start <- T | 172 start <- T |
171 for (i in 1:nrow(df)){ | 173 for (i in 1:nrow(df)){ |
172 | 174 |
173 x <- df[i,] | 175 x <- df[i,] |
174 | 176 |
205 | 207 |
206 } | 208 } |
207 | 209 |
208 add_extra_table_elucidation('metfrag_results', opt$metfrag_result, con, filter_Score=0.6, filter_Rank=NA) | 210 add_extra_table_elucidation('metfrag_results', opt$metfrag_result, con, filter_Score=0.6, filter_Rank=NA) |
209 add_extra_table_elucidation('sirius_csifingerid_results', opt$sirius_csifingerid_result, con, filter_Score=NA, filter_Rank=5) | 211 add_extra_table_elucidation('sirius_csifingerid_results', opt$sirius_csifingerid_result, con, filter_Score=NA, filter_Rank=5) |
210 add_probmetab(opt$probmetab_result, con) | 212 |
211 | 213 |
212 if (is.null(xset)){ | 214 if (is.null(xset)){ |
213 DBI::dbWriteTable(con, name='xset_classes', value=xa@xcmsSet@phenoData, row.names=TRUE) | 215 DBI::dbWriteTable(con, name='xset_classes', value=xa@xcmsSet@phenoData, row.names=TRUE) |
216 add_probmetab(opt$probmetab_result, xset, con) | |
214 }else{ | 217 }else{ |
215 | 218 |
216 DBI::dbWriteTable(con, name='xset_classes', value=xset@phenoData, row.names=TRUE) | 219 DBI::dbWriteTable(con, name='xset_classes', value=xset@phenoData, row.names=TRUE) |
220 add_probmetab(opt$probmetab_result, xset, con) | |
217 | 221 |
218 } | 222 } |
219 | 223 |
220 cmd <- paste('SELECT cpg.grpid, cpg.mz, cpg.mzmin, cpg.mzmax, cpg.rt, cpg.rtmin, cpg.rtmax, c_peaks.cid, ', | 224 cmd <- paste('SELECT cpg.grpid, cpg.mz, cpg.mzmin, cpg.mzmax, cpg.rt, cpg.rtmin, cpg.rtmax, c_peaks.cid, ', |
221 'c_peaks.mzmin AS c_peak_mzmin, c_peaks.mzmax AS c_peak_mzmax, ', | 225 'c_peaks.mzmin AS c_peak_mzmin, c_peaks.mzmax AS c_peak_mzmax, ', |