comparison MsFileDb.R @ 6:b8f70d8216b3 draft

planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit b3a4e34cf9356447ae3507cc6fe2ff6a1f24afbc-dirty
author prog
date Mon, 27 Mar 2017 06:27:29 -0400
parents 1ba222315fd5
children
comparison
equal deleted inserted replaced
5:18254e8d1b72 6:b8f70d8216b3
80 MsFileDb$methods( .init.db = function() { 80 MsFileDb$methods( .init.db = function() {
81 81
82 if (is.null(.self$.db)) { 82 if (is.null(.self$.db)) {
83 83
84 # Load database 84 # Load database
85 .db <<- read.table(.self$.file, sep = "\t", quote = "\"", header = TRUE, stringsAsFactors = FALSE, row.names = NULL) 85 .db <<- read.table(.self$.file, sep = "\t", quote = "\"", header = TRUE, stringsAsFactors = FALSE, row.names = NULL, check.names = FALSE, comment.char = '')
86 86
87 # Check that colnames are unique 87 # Check that colnames are unique
88 dupcol <- duplicated(colnames(.self$.db)) 88 dupcol <- duplicated(colnames(.self$.db))
89 if (any(dupcol)) 89 if (any(dupcol))
90 stop(paste("Database header contains duplicated names: ", paste(unique(colnames(.self$.db)[dupcol]), collapse = ', '), ".")) 90 stop(paste("Database header contains duplicated names: ", paste(unique(colnames(.self$.db)[dupcol]), collapse = ', '), "."))
394 if ( ! is.null(col) && ! is.na(col)) 394 if ( ! is.null(col) && ! is.na(col))
395 db <- db[db[[MSDB.TAG.COL]] %in% col,] 395 db <- db[db[[MSDB.TAG.COL]] %in% col,]
396 396
397 # Filter on retention time 397 # Filter on retention time
398 if ( ! is.null(rt.low) && ! is.na(rt.low) && ! is.null(rt.high) && ! is.na(rt.high)) { 398 if ( ! is.null(rt.low) && ! is.na(rt.low) && ! is.null(rt.high) && ! is.na(rt.high)) {
399 scale <- if (.self$.rt.unit == MSDB.RTUNIT.MIN) 60 else 1 399 scale <- if (.self$getRtUnit() == MSDB.RTUNIT.MIN) 60 else 1
400 db <- db[db[[MSDB.TAG.COLRT]] * scale >= rt.low & db[[MSDB.TAG.COLRT]] <= rt.high, ] 400 db <- db[db[[MSDB.TAG.COLRT]] * scale >= rt.low & db[[MSDB.TAG.COLRT]] * scale <= rt.high, ]
401 } 401 }
402 402
403 # Remove retention times and column information 403 # Remove retention times and column information
404 if (is.null(col) || is.na(col) || is.null(rt.low) || is.na(rt.low) || is.null(rt.high) || is.na(rt.high)) { 404 if (is.null(col) || is.na(col) || is.null(rt.low) || is.na(rt.low) || is.null(rt.high) || is.na(rt.high)) {
405 db <- db[, ! (colnames(db) %in% c(MSDB.TAG.COL, MSDB.TAG.COLRT))] 405 db <- db[, ! (colnames(db) %in% c(MSDB.TAG.COL, MSDB.TAG.COLRT))]
408 db <- db[ ! duplicated(db), ] 408 db <- db[ ! duplicated(db), ]
409 } 409 }
410 410
411 # Filter on mz 411 # Filter on mz
412 db <- db[db[[MSDB.TAG.MZTHEO]] >= mz.low & db[[MSDB.TAG.MZTHEO]] <= mz.high, ] 412 db <- db[db[[MSDB.TAG.MZTHEO]] >= mz.low & db[[MSDB.TAG.MZTHEO]] <= mz.high, ]
413
414 # Rename database fields
415 # conv <- c( mz = 'mztheo', rt = 'colrt') # solving mismatch of field names between database and output
416 # cols <- colnames(db)
417 # for (db.field in names(.self$.fields)) {
418 # output.field <- if (db.field %in% names(conv)) conv[[db.field]] else db.field
419 # if (.self$.fields[[db.field]] %in% cols && output.field %in% names(.self$.output.fields))
420 # cols[cols %in% .self$.fields[[db.field]]] <- .self$.output.fields[[output.field]]
421 # }
422 # colnames(db) <- cols
423
424 # Remove unwanted columns
425 # db <- db[, colnames(db) %in% .self$.output.fields]
426 413
427 return(db) 414 return(db)
428 }) 415 })
429 416
430 ################# 417 #################
487 for (col in cols) { 474 for (col in cols) {
488 colrts <- db[db[[MSDB.TAG.COL]] %in% col, MSDB.TAG.COLRT] 475 colrts <- db[db[[MSDB.TAG.COL]] %in% col, MSDB.TAG.COLRT]
489 rt[col] <- list(colrts) 476 rt[col] <- list(colrts)
490 } 477 }
491 478
492 if (.self$.rt.unit == MSDB.RTUNIT.MIN) 479 if (.self$getRtUnit() == MSDB.RTUNIT.MIN)
493 rt <- 60 * rt 480 rt <- 60 * rt
494 481
495 return(rt) 482 return(rt)
496 }) 483 })
497 484