diff MassbankSpectrum.R @ 1:253d531a0193 draft

planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit 36c9d8099c20a1ae848f1337c16564335dd8fb2b
author prog
date Sat, 03 Sep 2016 17:02:01 -0400
parents e66bb061af06
children
line wrap: on
line diff
--- a/MassbankSpectrum.R	Tue Jul 12 12:02:37 2016 -0400
+++ b/MassbankSpectrum.R	Sat Sep 03 17:02:01 2016 -0400
@@ -21,13 +21,13 @@
 
 		# Define fields regex
 		regex <- character()
-		regex[[RBIODB.ACCESSION]] <- "^ACCESSION: (.+)$"
-		regex[[RBIODB.MSDEV]] <- "^AC\\$INSTRUMENT: (.+)$"
-		regex[[RBIODB.MSDEVTYPE]] <- "^AC\\$INSTRUMENT_TYPE: (.+)$"
-		regex[[RBIODB.MSTYPE]] <- "^AC\\$MASS_SPECTROMETRY: MS_TYPE (.+)$"
-		regex[[RBIODB.MSPRECMZ]] <- "^MS\\$FOCUSED_ION: PRECURSOR_M/Z (.+)$"
-		regex[[RBIODB.NB.PEAKS]] <- "^PK\\$NUM_PEAK: ([0-9]+)$"
-		regex[[RBIODB.MSPRECANNOT]] <- "^MS\\$FOCUSED_ION: PRECURSOR_TYPE (.+)$"
+		regex[[BIODB.ACCESSION]] <- "^ACCESSION: (.+)$"
+		regex[[BIODB.MSDEV]] <- "^AC\\$INSTRUMENT: (.+)$"
+		regex[[BIODB.MSDEVTYPE]] <- "^AC\\$INSTRUMENT_TYPE: (.+)$"
+		regex[[BIODB.MSTYPE]] <- "^AC\\$MASS_SPECTROMETRY: MS_TYPE (.+)$"
+		regex[[BIODB.MSPRECMZ]] <- "^MS\\$FOCUSED_ION: PRECURSOR_M/Z (.+)$"
+		regex[[BIODB.NB.PEAKS]] <- "^PK\\$NUM_PEAK: ([0-9]+)$"
+		regex[[BIODB.MSPRECANNOT]] <- "^MS\\$FOCUSED_ION: PRECURSOR_TYPE (.+)$"
 
 		for (text in contents) {
 
@@ -54,7 +54,7 @@
 				# MS MODE
 				g <- str_match(s, "^AC\\$MASS_SPECTROMETRY: ION_MODE (.+)$")
 				if ( ! is.na(g[1,1])) {
-					spectrum$setField(RBIODB.MSMODE, if (g[1,2] == 'POSITIVE') RBIODB.MSMODE.POS else RBIODB.MSMODE.NEG)
+					spectrum$setField(BIODB.MSMODE, if (g[1,2] == 'POSITIVE') BIODB.MSMODE.POS else BIODB.MSMODE.NEG)
 					next
 				}
 
@@ -67,13 +67,13 @@
 		}
 
 		# Replace elements with no accession id by NULL
-		spectra <- lapply(spectra, function(x) if (is.na(x$getField(RBIODB.ACCESSION))) NULL else x)
+		spectra <- lapply(spectra, function(x) if (is.na(x$getField(BIODB.ACCESSION))) NULL else x)
 
 		# Set associated compounds
 		compounds <- createMassbankCompoundFromTxt(contents)
 		for (i in seq(spectra))
 			if ( ! is.null(spectra[[i]]))
-				spectra[[i]]$setField(RBIODB.COMPOUND, compounds[[i]])
+				spectra[[i]]$setField(BIODB.COMPOUND, compounds[[i]])
 
 		# If the input was a single element, then output a single object
 		if (drop && length(contents) == 1)
@@ -88,26 +88,26 @@
 
 	.parse.peak.line <- function(spectrum, line) {
 
-		peaks <- RBIODB.PEAK.DF.EXAMPLE
+		peaks <- BIODB.PEAK.DF.EXAMPLE
 		
 		# Annotation
 		g <- str_match(line, "^\\s+([0-9][0-9.]*) ([A-Z0-9+-]+) ([0-9]+) ([0-9][0-9.]*) ([0-9][0-9.]*)$")
 		if ( ! is.na(g[1,1]))
-			peaks[1, c(RBIODB.PEAK.MZ, RBIODB.PEAK.FORMULA, RBIODB.PEAK.FORMULA.COUNT, RBIODB.PEAK.MASS, RBIODB.PEAK.ERROR.PPM)] <- list(as.double(g[1,2]), g[1,3], as.integer(g[1,4]), as.double(g[1,5]), as.double(g[1,6]))
+			peaks[1, c(BIODB.PEAK.MZ, BIODB.PEAK.FORMULA, BIODB.PEAK.FORMULA.COUNT, BIODB.PEAK.MASS, BIODB.PEAK.ERROR.PPM)] <- list(as.double(g[1,2]), g[1,3], as.integer(g[1,4]), as.double(g[1,5]), as.double(g[1,6]))
 
 		# Peak
 		g <- str_match(line, "^\\s+([0-9][0-9.]*) ([0-9][0-9.]*) ([0-9]+)$")
 		if ( ! is.na(g[1,1]))
-			peaks[1, c(RBIODB.PEAK.MZ, RBIODB.PEAK.INTENSITY, RBIODB.PEAK.RELATIVE.INTENSITY)] <- list(as.double(g[1,2]), as.double(g[1,3]), as.integer(g[1,4]))
+			peaks[1, c(BIODB.PEAK.MZ, BIODB.PEAK.INTENSITY, BIODB.PEAK.RELATIVE.INTENSITY)] <- list(as.double(g[1,2]), as.double(g[1,3]), as.integer(g[1,4]))
 
 		if (nrow(peaks) > 0) {
 
 			# Get curent peaks and merge with new peaks
-			current.peaks <- spectrum$getField(RBIODB.PEAKS)
+			current.peaks <- spectrum$getField(BIODB.PEAKS)
 			if ( ! is.null(current.peaks))
 				peaks <- rbind(current.peaks, peaks)
 
-			spectrum$setField(RBIODB.PEAKS, peaks)
+			spectrum$setField(BIODB.PEAKS, peaks)
 
 			return(TRUE)
 		}