Commit 3c08df96 authored by Adelene Lai's avatar Adelene Lai

add MS2 intTresh, other WIP

parent c16af080
File added
...@@ -322,18 +322,20 @@ RMB_EIC_prescreen_df <- function (wd, RMB_mode, FileList, cmpd_list, ...@@ -322,18 +322,20 @@ RMB_EIC_prescreen_df <- function (wd, RMB_mode, FileList, cmpd_list,
row.names = F) row.names = F)
} }
preProc <- function (fnFileTab,fnDest=paste(stripext(fnFileTab),"_candidate.csv",sep=''),noiseFac=3,rtDelta=0.5,intTresh=1e5) { preProc <- function (fnFileTab,fnDest=paste(stripext(fnFileTab),"_candidate.csv",sep=''),noiseFac=3,rtDelta=0.5,ms1_intTresh=1e5,ms2_intTresh=1e4,MS1peakWi=0.3) {
## read in .csv file as file ## read in .csv file as file
ftable <- read.csv(file = fnFileTab, header = T, sep=",", stringsAsFactors = F) ftable <- read.csv(file = fnFileTab, header = T, sep=",", stringsAsFactors = F)
getWidth <- function(maxid) {log10(maxid)+1} getWidth <- function(maxid) {log10(maxid)+1}
ids <- as.numeric(levels(factor(ftable$ID))) ids <- as.numeric(levels(factor(ftable$ID))
##is MS1 intensity high enough?)
id_field_width <- getWidth(max(ids)) id_field_width <- getWidth(max(ids))
fn_out<- function(id,suff) {paste(formatC(id,width=id_field_width,flag=0),suff,".csv",sep='')} fn_out<- function(id,suff) {paste(formatC(id,width=id_field_width,flag=0),suff,".csv",sep='')}
## for loop through dataframe called file to set tresholds ## for loop through dataframe called file to set tresholds
ftable[c("MS1","MS2","Alignment","Intensity","AboveNoise")] <- T ftable[c("MS1","MS2","Alignment","MS1Intensity","AboveNoise","MS2Intensity","MS1peakWidth")] <- T
ftable$Comments <- "" ftable$Comments <- ""
for (ind in 1:nrow(ftable)) { for (ind in 1:nrow(ftable)) {
wd <- ftable$wd[ind] wd <- ftable$wd[ind]
...@@ -342,36 +344,57 @@ preProc <- function (fnFileTab,fnDest=paste(stripext(fnFileTab),"_candidate.csv" ...@@ -342,36 +344,57 @@ preProc <- function (fnFileTab,fnDest=paste(stripext(fnFileTab),"_candidate.csv"
fn_eic <- file.path(wd,fn_out(id,".eic")) fn_eic <- file.path(wd,fn_out(id,".eic"))
eic <- NULL eic <- NULL
maxInt <- NULL maxInt <- NULL
eicExists <- F eicExists <- T
if(!file.exists(fn_eic)) {
##does MS1 exist?
if(!file.exists(fn_eic)) {
ftable[ind,"MS1"] = FALSE ftable[ind,"MS1"] = FALSE
eicExists <- T eicExists <- F
} }
else { else {
eic <- read.csv(fn_eic, sep = ",", stringsAsFactors = F) eic <- read.csv(fn_eic, sep = ",", stringsAsFactors = F)
maxInt <- max(eic$intensity) maxInt <- max(eic$intensity)
if (maxInt < intTresh) {
ftable[ind,"Intensity"] = FALSE ##is MS1 intensity high enough?
if (maxInt < ms1_intTresh) {
ftable[ind,"MS1Intensity"] = FALSE
} }
## Detect noisy signal. This is a naive implementation, so careful. ##Detect noisy signal. This is a naive implementation, so careful.
mInt <- mean(eic$intensity) mInt <- mean(eic$intensity)
if (maxInt < noiseFac*mInt) ftable[ind,"AboveNoise"] <- F if (maxInt < noiseFac*mInt) ftable[ind,"AboveNoise"] <- F
##Is MS1 peak a proper peak, or just a spike? Check peakwidth.
MS1peakWi
} }
#####MS2 checks
fn_kids <- file.path(wd,fn_out(id,".kids")) fn_kids <- file.path(wd,fn_out(id,".kids"))
##does MS2 exist? Regardless of quality/alignment.
if(!file.exists(fn_kids)) { if(!file.exists(fn_kids)) {
ftable[ind,"MS2"] = FALSE ftable[ind,"MS2"] = FALSE
ftable[ind,"MS2Intensity"] = NA #moot
ftable[ind,"Alignment"] = NA #moot
} else { } else {
## Detect RT shifts. Naive implementation, so careful. ## Detect RT shifts. Naive implementation, so careful.
if (eicExists) { if (eicExists) { ################WHY THIS IF CONDITIONAL?? If MS2 exists, then eic MUST exist, no? Seems redundant.
rtInd <- match(maxInt,eic$intensity) ##Is MS2 intensity high enough?
rtMax <- eic$rt[rtInd] ms2maxInt <- max(msms@intensity)
msms <- read.csv(fn_kids, sep = ",", stringsAsFactors = F) if (ms2maxInt > ms2_intTresh){
whc <- msms$rt > rtMax - rtDelta rtInd <- match(maxInt,eic$intensity) #returns position of first match in eic$intensity
whc <- whc < rtMax + rtDelta rtMax <- eic$rt[rtInd] #fetch the rtmax value (RT with highest int;seconds) using above index
ints <- msms$intensity[whc] msms <- read.csv(fn_kids, sep = ",", stringsAsFactors = F)
if (! any(ints>0)) ftable[ind,"Alignment"] = FALSE whc <- msms$rt > rtMax - rtDelta #T/F vector: are RT vals of ms2 above rtMax within Delta? Good peaks=TRUE;rt must be retentionTime!!!
} whc <- whc < rtMax + rtDelta #T/F vector: are RT vals of ms2 above rtMax within Delta?
#Overwrites whc! In any case, cannot use this as both must be T to give final whc of T (i.e. fall within the window).
ints <- msms$intensity[whc] #builds ints vector with intensities which fall in window
if (! any(ints>0)) ftable[ind,"Alignment"] = FALSE #if none of ints larger than 0, Alignment <-F
} else {
ftable[ind,"MS2Intensity"] = FALSE
ftable[ind,"Alignment"] = NA #neither T or F, the MS2 was not of decent intensity in first place, alignment moot.
}
}
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment