changeset 9:e6a78f89ee07 draft

planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 74e7bfbb5e70ec6e665114fa9e9863dafd7bced5
author tomnl
date Tue, 25 Jun 2019 06:05:06 -0400
parents 736f8fd48db2
children 1dd282c0294e
files createDatabase.R spectralMatching.R test-data/createDatabase_output.sqlite test-data/createDatabase_output_eic.sqlite test-data/spectralMatching_db_with_spectral_matching.sqlite
diffstat 5 files changed, 53 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/createDatabase.R	Wed Jun 19 09:22:35 2019 -0400
+++ b/createDatabase.R	Tue Jun 25 06:05:06 2019 -0400
@@ -5,8 +5,6 @@
 print(sessionInfo())
 print('CREATING DATABASE')
 
-
-
 xset_pa_filename_fix <- function(opt, pa, xset){
 
   if (!is.null(opt$mzML_files) && !is.null(opt$galaxy_names)){
@@ -156,11 +154,15 @@
   }
 
   xset@peaks <- as.matrix(plyr::ddply(data.frame(xset@peaks), ~ sample, convert2Raw, xset=xset))
-  closeAllConnections()
+  
   # Saves the EICS into the previously created database
-  px <- msPurity::purityX(xset, saveEIC = TRUE,
-                           cores=1, sqlitePth=dbPth,
-                           rtrawColumns = TRUE)
+  xgroups <-  as.numeric(as.character(unique(pa@grped_df$grpid)))
+  px <- msPurity::purityX(xset, 
+                          saveEIC = TRUE,
+                          cores=1,
+                          sqlitePth=dbPth,
+                          rtrawColumns = TRUE, 
+                          xgroups = xgroups)
 
 }
 
--- a/spectralMatching.R	Wed Jun 19 09:22:35 2019 -0400
+++ b/spectralMatching.R	Tue Jun 25 06:05:06 2019 -0400
@@ -243,3 +243,48 @@
 
 write.table(sm$matchedResults, 'matched_results.tsv', sep = '\t', row.names = FALSE, col.names = TRUE)
 write.table(sm$xcmsMatchedResults, 'xcms_matched_results.tsv', sep = '\t', row.names = FALSE, col.names = TRUE)
+
+
+# Add extra details from library spectra in resulting database
+# First get all the ids from the l_s_peak_meta from the query database
+if(updateDb){
+  message('Adding extra details to database')
+  q_con <- DBI::dbConnect(RSQLite::SQLite(),sm$q_dbPth)
+  if (DBI::dbExistsTable(q_con, "l_s_peak_meta")){
+    l_s_peak_meta <- DBI::dbGetQuery(q_con, 'SELECT  * FROM l_s_peak_meta')
+    colnames(l_s_peak_meta)[1] <- 'pid'
+  }
+  
+  l_con <- DBI::dbConnect(RSQLite::SQLite(),l_dbPth)
+  if (DBI::dbExistsTable(q_con, "s_peaks")){
+    l_s_peaks <- DBI::dbGetQuery(q_con, sprintf("SELECT  * FROM s_peaks WHERE pid in (%s)", paste(unique(l_s_peak_meta$pid), collapse=',')))
+    
+  }else if(DBI::dbExistsTable(q_con, "library_spectra")){
+    l_s_peaks <- DBI::dbGetQuery(q_con, sprintf("SELECT  * FROM library_spectra 
+                                                WHERE library_spectra_meta_id in (%s)", paste(unique(l_s_peak_meta$pid), collapse=',')))
+  }else{
+    l_s_peaks = NULL
+  }
+  
+  if (DBI::dbExistsTable(q_con, "source")){
+    l_source <- DBI::dbGetQuery(q_con, 'SELECT  * FROM source')
+  }else if (DBI::dbExistsTable(q_con, "library_spectra_source")) {
+    l_source <- DBI::dbGetQuery(q_con, 'library_spectra_source')
+  }else{
+    l_source = NULL
+  }
+  
+  if (!is.null(l_s_peaks)){
+    DBI::dbWriteTable(q_con, name='l_s_peaks', value=l_s_peaks, row.names=FALSE, append=TRUE)
+  }
+  
+  if (!is.null(l_source)){
+    DBI::dbWriteTable(q_con, name='l_source', value=l_source, row.names=FALSE, append=TRUE)
+  }
+  
+}
+
+
+
+
+
Binary file test-data/createDatabase_output.sqlite has changed
Binary file test-data/createDatabase_output_eic.sqlite has changed
Binary file test-data/spectralMatching_db_with_spectral_matching.sqlite has changed