|
@ -1,18 +1,34 @@ |
|
|
|
|
|
# Copyright (C) 2021-2021 Juni Christopher Kim |
|
|
|
|
|
# This script is free software: you can redistribute it and/or modify |
|
|
|
|
|
# it under the terms of the GNU General Public License as published by |
|
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or |
|
|
|
|
|
# (at your option) any later version. |
|
|
|
|
|
# |
|
|
|
|
|
# This script is distributed in the hope that it will be useful, |
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
|
|
|
# GNU General Public License for more details. |
|
|
|
|
|
# |
|
|
|
|
|
# You should have received a copy of the GNU General Public License |
|
|
|
|
|
# along with Copyright Header. If not, see <http://www.gnu.org/licenses/>. |
|
|
|
|
|
|
|
|
library("nontarget") |
|
|
library("nontarget") |
|
|
library("enviPat") |
|
|
library("enviPat") |
|
|
library("stringr") |
|
|
library("stringr") |
|
|
library("parallel") |
|
|
library("parallel") |
|
|
|
|
|
|
|
|
# Configurations ############################################################# |
|
|
# Configurations ############################################################# |
|
|
|
|
|
|
|
|
# file to read from |
|
|
# file to read from |
|
|
input.filename <- " " |
|
|
input.filename <- " " |
|
|
# separator to use (\t for tabs, "," for CSV) |
|
|
# separator to use (\t for tabs, "," for CSV) |
|
|
input.sep <- "," |
|
|
input.sep <- "," |
|
|
|
|
|
|
|
|
# All isotopes to check for |
|
|
|
|
|
|
|
|
# All isotopes to check for in search |
|
|
check_isos <- c("37Cl", "81Br") |
|
|
check_isos <- c("37Cl", "81Br") |
|
|
|
|
|
|
|
|
# Minimum size of a cluster |
|
|
|
|
|
|
|
|
# Minimum size of a cluster (clusters smaller than this size will not |
|
|
|
|
|
# be accepted) |
|
|
min_cluster_size <- 2 |
|
|
min_cluster_size <- 2 |
|
|
|
|
|
|
|
|
# Number of cores to be used in pattern.search evaluation |
|
|
# Number of cores to be used in pattern.search evaluation |
|
@ -21,8 +37,7 @@ use_cores <- 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Table name configuration |
|
|
# Table name configuration |
|
|
|
|
|
|
|
|
# Column name for m/z |
|
|
|
|
|
|
|
|
# Column name for m/z values |
|
|
columns.mz <- "mz" |
|
|
columns.mz <- "mz" |
|
|
# Column name for time in gc |
|
|
# Column name for time in gc |
|
|
columns.time <- "time" |
|
|
columns.time <- "time" |
|
@ -36,13 +51,13 @@ columns.spectra <- "Spectra_Number" |
|
|
# Number of highest intensities to display in output |
|
|
# Number of highest intensities to display in output |
|
|
output.intensities <- 5 |
|
|
output.intensities <- 5 |
|
|
|
|
|
|
|
|
# Verbose output |
|
|
|
|
|
verbose.enable <- TRUE |
|
|
|
|
|
|
|
|
# Verbose output (dumping all output into a file) |
|
|
|
|
|
verbose.enable <- FALSE |
|
|
# output directory must already exist. |
|
|
# output directory must already exist. |
|
|
verbose.outputdir <- "" |
|
|
verbose.outputdir <- "" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Script ##################################################################### |
|
|
|
|
|
|
|
|
# Variables/Functions ######################################################## |
|
|
|
|
|
|
|
|
## Defining/setting variables ################################################ |
|
|
## Defining/setting variables ################################################ |
|
|
|
|
|
|
|
@ -67,7 +82,7 @@ use_cores = min(use_cores, detectCores() - 1) |
|
|
minint <- rep(0, fragments) |
|
|
minint <- rep(0, fragments) |
|
|
# upper bound of indices per fragment |
|
|
# upper bound of indices per fragment |
|
|
maxint <- rep(0, fragments) |
|
|
maxint <- rep(0, fragments) |
|
|
# memoizes as to |
|
|
|
|
|
|
|
|
# memoizes what clusters are usable (exist and enough data sets) |
|
|
usable <- rep(FALSE, fragments) |
|
|
usable <- rep(FALSE, fragments) |
|
|
|
|
|
|
|
|
# initialize isotopes. |
|
|
# initialize isotopes. |
|
@ -139,7 +154,9 @@ derive.fragment <- function(result) { |
|
|
|
|
|
|
|
|
derive.iso <- function(result) { |
|
|
derive.iso <- function(result) { |
|
|
res <- result$`Counts of isotopes` |
|
|
res <- result$`Counts of isotopes` |
|
|
return (res[res$"isotope" %in% check_isos, c("isotope", "group counts")]) |
|
|
|
|
|
|
|
|
res <- |
|
|
|
|
|
res[res$"isotope" %in% check_isos, c("isotope", "group counts")] |
|
|
|
|
|
return(res) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
derive.intensity <- function(result) { |
|
|
derive.intensity <- function(result) { |
|
@ -162,7 +179,7 @@ derive.frame <- function(result) { |
|
|
derive.average(result) |
|
|
derive.average(result) |
|
|
) |
|
|
) |
|
|
names(res) <- |
|
|
names(res) <- |
|
|
c("Fragment_ID", "Peaks", "Intensities", "Average_time") |
|
|
|
|
|
|
|
|
c("Fragment_ID", "Isotopes", "Intensities", "Average_time") |
|
|
return(res) |
|
|
return(res) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -195,6 +212,8 @@ for (i in 1:fragments) { |
|
|
usable[i] <- FALSE |
|
|
usable[i] <- FALSE |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
## Run pattern.search function ############################################## |
|
|
|
|
|
|
|
|
# Filter all usable fragments |
|
|
# Filter all usable fragments |
|
|
use <- Filter(function(x) |
|
|
use <- Filter(function(x) |
|
|
usable[x], 1:fragments) |
|
|
usable[x], 1:fragments) |
|
@ -205,7 +224,7 @@ results <- mclapply(use, diagnostics, mc.cores = use_cores) |
|
|
results.positive <- Filter(function(x) |
|
|
results.positive <- Filter(function(x) |
|
|
positive(x), results) |
|
|
positive(x), results) |
|
|
|
|
|
|
|
|
# print to files if verbose output requested |
|
|
|
|
|
|
|
|
## Verbose output handling ################################################## |
|
|
|
|
|
|
|
|
if (verbose.enable) { |
|
|
if (verbose.enable) { |
|
|
if (!dir.exists(verbose.outputdir)) { |
|
|
if (!dir.exists(verbose.outputdir)) { |
|
@ -232,6 +251,8 @@ if (verbose.enable) { |
|
|
lapply(results.positive, verbose.dump) |
|
|
lapply(results.positive, verbose.dump) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
## Data Analysis/Evaluation :################################################ |
|
|
|
|
|
|
|
|
result.frame <- lapply(results.positive, derive.frame) |
|
|
result.frame <- lapply(results.positive, derive.frame) |
|
|
result.fragment <- lapply(results.positive, derive.fragment) |
|
|
result.fragment <- lapply(results.positive, derive.fragment) |
|
|
result.iso <- lapply(results.positive, derive.iso) |
|
|
result.iso <- lapply(results.positive, derive.iso) |
|
|