-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MS2:MS1 Ratio per precursor. Log2 Scale.
- Loading branch information
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
modules/dia-nn/020_Ion_Sampling/instrument_20_DIA_MS1_MS2_Ratio.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
init <- function() { | ||
|
||
type <- 'plot' | ||
box_title <- 'MS2/MS1 Intensity Ratio per precursor' | ||
help_text <- 'Plotting the MS2/MS1 Intensity Ratio for all precursors.' | ||
source_file <- 'report' | ||
|
||
.validate <- function(data, input) { | ||
validate(need(data()[['report']], paste0('Upload report.txt'))) | ||
validate(need((nrow(data()[['report']]) > 1), paste0('No Rows selected'))) | ||
|
||
} | ||
|
||
.plotdata <- function(data, input) { | ||
plotdata <- data()[['report']][,c('Raw.file', 'Ms1.Area', 'Precursor.Quantity', 'Precursor.Id')] | ||
plotdata$Ms1.Area <- as.numeric(plotdata$Ms1.Area) | ||
plotdata$Precursor.Quantity <- as.numeric(plotdata$Precursor.Quantity) | ||
|
||
plotdata <- plotdata %>% | ||
group_by(Raw.file, Precursor.Id) %>% | ||
mutate(Ms2.Ms1.Ratio = Precursor.Quantity / Ms1.Area) | ||
|
||
plotdata <- dplyr::filter(plotdata, Ms2.Ms1.Ratio>0) | ||
plotdata$Ms2.Ms1.Ratio <- log2(plotdata$Ms2.Ms1.Ratio) | ||
# Thresholding data at 1 and 99th percentiles | ||
ceiling <- quantile(plotdata$Ms2.Ms1.Ratio, probs=.99, na.rm = TRUE) | ||
floor <- quantile(plotdata$Ms2.Ms1.Ratio, probs=.01, na.rm = TRUE) | ||
|
||
plotdata <- dplyr::filter(plotdata, is.finite(Ms2.Ms1.Ratio)) | ||
if(nrow(plotdata) > 0){ | ||
plotdata[plotdata$Ms2.Ms1.Ratio >= ceiling, 2] <- ceiling | ||
plotdata[plotdata$Ms2.Ms1.Ratio <= floor, 2] <- floor | ||
} | ||
return(plotdata) | ||
} | ||
|
||
.plot <- function(data, input) { | ||
.validate(data, input) | ||
plotdata <- .plotdata(data, input) | ||
validate(need((nrow(plotdata) > 1), paste0('No Rows selected'))) | ||
|
||
|
||
medianData = plotdata %>% group_by(Raw.file) %>% | ||
summarise(median = median(Ms2.Ms1.Ratio), .groups = "drop") | ||
|
||
|
||
ggplot(plotdata, aes(Ms2.Ms1.Ratio)) + | ||
facet_wrap(~Raw.file, nrow = 1, scales = "free_x") + | ||
geom_histogram(bins=50, fill=custom_colors[[6]]) + | ||
coord_flip() + | ||
labs(x=expression(bold('Log'[2]*' Precursor Ratio')), y='Number of Precursors') + | ||
theme_diann(input=input, show_legend=T) | ||
} | ||
|
||
return(list( | ||
type=type, | ||
box_title=box_title, | ||
help_text=help_text, | ||
source_file=source_file, | ||
validate_func=.validate, | ||
plotdata_func=.plotdata, | ||
plot_func=.plot, | ||
dynamic_width=200, | ||
dynamic_width_base=50 | ||
)) | ||
} |