diff MsFileDb.R @ 2:20d69a062da3 draft

planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
author prog
date Thu, 02 Mar 2017 08:55:00 -0500
parents e66bb061af06
children fb9c0409d85c
line wrap: on
line diff
--- a/MsFileDb.R	Sat Sep 03 17:02:01 2016 -0400
+++ b/MsFileDb.R	Thu Mar 02 08:55:00 2017 -0500
@@ -84,6 +84,16 @@
 			# Load database
 			.db <<- read.table(.self$.file, sep = "\t", quote = "\"", header = TRUE, stringsAsFactors = FALSE, row.names = NULL)
 
+			# Check that colnames are unique
+			dupcol <- duplicated(colnames(.self$.db))
+			if (any(dupcol))
+				stop(paste("Database header contains duplicated names: ", paste(unique(colnames(.self$.db)[dupcol]), collapse = ', '), "."))
+
+			# Check that columns names supplied through field map are unique
+			dupfields <- duplicated(.self$.fields)
+			if (any(dupfields))
+				stop(paste("Some db column names supplied are duplicated: ", paste(unique(.self$.fields[dupfields]), collapse = ', '), "."))
+
 			# Rename columns
 			colnames(.self$.db) <- vapply(colnames(.self$.db), function(c) if (c %in% .self$.fields) names(.self$.fields)[.self$.fields %in% c] else c, FUN.VALUE = '')
 		}
@@ -151,7 +161,7 @@
 	# GET MOLECULE IDS #
 	####################
 	
-	MsFileDb$methods( getMoleculeIds = function() {
+	MsFileDb$methods( getMoleculeIds = function(max.results = NA_integer_) {
 	
 		# Init db
 		.self$.init.db()
@@ -161,6 +171,10 @@
 		mol.ids <- mol.ids[ ! duplicated(mol.ids)]
 		mol.ids <- sort(mol.ids)
 
+		# Cut results
+		if ( ! is.na(max.results) && length(mol.ids) > max.results)
+			mol.ids <- mol.ids[1:max.results]
+
 		return(mol.ids)
 	})
 
@@ -416,7 +430,7 @@
 	#################
 	
 	# Returns a numeric vector of all masses stored inside the database.
-	MsFileDb$methods( getMzValues = function(mode = NULL) {
+	MsFileDb$methods( getMzValues = function(mode = NULL, max.results = NA_integer_) {
 
 		# Init db
 		.self$.init.db()
@@ -435,6 +449,10 @@
 		# Remove duplicates
 		mz <- mz[ ! duplicated(mz)]
 
+		# Apply cut-off
+		if ( ! is.na(max.results))
+			mz <- mz[1:max.results]
+
 		return(mz)
 	})