Mercurial > repos > prog > lcmsmatching
comparison MsFileDb.R @ 5:fb9c0409d85c draft
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit 608d9e59a0d2dcf85a037968ddb2c61137fb9bce
author | prog |
---|---|
date | Wed, 19 Apr 2017 10:00:05 -0400 |
parents | 20d69a062da3 |
children |
comparison
equal
deleted
inserted
replaced
4:b34c14151f25 | 5:fb9c0409d85c |
---|---|
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 = ', '), ".")) |
393 # Filter on columns | 393 # Filter on columns |
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 db <- db[db[[MSDB.TAG.COLRT]] >= rt.low & db[[MSDB.TAG.COLRT]] <= rt.high, ] | 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]] * scale <= rt.high, ] | |
401 } | |
400 | 402 |
401 # Remove retention times and column information | 403 # Remove retention times and column information |
402 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)) { |
403 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))] |
404 | 406 |
406 db <- db[ ! duplicated(db), ] | 408 db <- db[ ! duplicated(db), ] |
407 } | 409 } |
408 | 410 |
409 # Filter on mz | 411 # Filter on mz |
410 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, ] |
411 | |
412 # Rename database fields | |
413 # conv <- c( mz = 'mztheo', rt = 'colrt') # solving mismatch of field names between database and output | |
414 # cols <- colnames(db) | |
415 # for (db.field in names(.self$.fields)) { | |
416 # output.field <- if (db.field %in% names(conv)) conv[[db.field]] else db.field | |
417 # if (.self$.fields[[db.field]] %in% cols && output.field %in% names(.self$.output.fields)) | |
418 # cols[cols %in% .self$.fields[[db.field]]] <- .self$.output.fields[[output.field]] | |
419 # } | |
420 # colnames(db) <- cols | |
421 | |
422 # Remove unwanted columns | |
423 # db <- db[, colnames(db) %in% .self$.output.fields] | |
424 | 413 |
425 return(db) | 414 return(db) |
426 }) | 415 }) |
427 | 416 |
428 ################# | 417 ################# |
485 for (col in cols) { | 474 for (col in cols) { |
486 colrts <- db[db[[MSDB.TAG.COL]] %in% col, MSDB.TAG.COLRT] | 475 colrts <- db[db[[MSDB.TAG.COL]] %in% col, MSDB.TAG.COLRT] |
487 rt[col] <- list(colrts) | 476 rt[col] <- list(colrts) |
488 } | 477 } |
489 | 478 |
479 if (.self$getRtUnit() == MSDB.RTUNIT.MIN) | |
480 rt <- 60 * rt | |
481 | |
490 return(rt) | 482 return(rt) |
491 }) | 483 }) |
492 | 484 |
493 } # end of load safe guard | 485 } # end of load safe guard |