Skip to content

Commit

Permalink
Bug fix in filtering plot when only one criterion is available.
Browse files Browse the repository at this point in the history
  • Loading branch information
csoneson committed Aug 1, 2023
1 parent 874151c commit 84d9639
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 12 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ importFrom(stringdist,amatch)
importFrom(stringr,str_extract)
importFrom(tibble,rownames_to_column)
importFrom(tidyr,gather)
importFrom(tidyr,pivot_longer)
importFrom(tidyr,pivot_wider)
importFrom(tidyr,separate_rows)
importFrom(tidyr,unnest)
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# einprot 0.7.6

* Bug fix in filtering plot when only one criterion is available

# einprot 0.7.5

* Move QC plot function
Expand Down
45 changes: 33 additions & 12 deletions R/doFilter.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
#' @keywords internal
#' @noRd
#'
#' @importFrom ggplot2 ggplot aes geom_col labs
#' @importFrom cowplot theme_cowplot
#' @importFrom tidyr pivot_longer
#' @importFrom dplyr summarize everything
#' @importFrom ComplexUpset upset
#'
.makeFilterPlot <- function(filtdf, plotUpset) {
if (plotUpset && any(rowSums(filtdf) > 0)) {
if (ncol(filtdf) > 1) {
print(ComplexUpset::upset(filtdf[rowSums(filtdf) > 0, , drop = FALSE],
intersect = colnames(filtdf)))
} else {
print(ggplot2::ggplot(
data = filtdf %>%
dplyr::summarize(across(dplyr::everything(),
function(x) length(which(x > 0)))) %>%
tidyr::pivot_longer(cols = dplyr::everything(),
names_to = "criterion", values_to = "number"),
ggplot2::aes(x = criterion, y = number)) +
ggplot2::geom_col() +
cowplot::theme_cowplot() +
ggplot2::labs(x = "", y = "Number of excluded features")
)
}
}
}

#' Filter out features in MaxQuant data
#'
#' Exclude features with 'Score' below \code{minScore}, 'Peptides' below
Expand Down Expand Up @@ -108,10 +138,7 @@ filterMaxQuant <- function(sce, minScore, minPeptides, plotUpset = TRUE,
"different sizes")
#nocov end
}
if (plotUpset && any(rowSums(filtdf) > 0)) {
print(ComplexUpset::upset(filtdf[rowSums(filtdf) > 0, , drop = FALSE],
intersect = colnames(filtdf)))
}
.makeFilterPlot(filtdf = filtdf, plotUpset = plotUpset)

if (!is.null(exclFile)) {
write.table(exclude, file = exclFile, quote = FALSE, sep = "\t",
Expand Down Expand Up @@ -385,10 +412,7 @@ filterPDTMT <- function(sce, inputLevel, minScore = 0, minPeptides = 0,
stop("Something went wrong in the filtering - filtdf and sce are of ",
"different sizes")
}
if (plotUpset && any(rowSums(filtdf) > 0)) {
print(ComplexUpset::upset(filtdf[rowSums(filtdf) > 0, , drop = FALSE],
intersect = colnames(filtdf)))
}
.makeFilterPlot(filtdf = filtdf, plotUpset = plotUpset)

if (!is.null(exclFile)) {
write.table(exclude, file = exclFile, quote = FALSE, sep = "\t",
Expand Down Expand Up @@ -494,10 +518,7 @@ filterFragPipe <- function(sce, minPeptides, plotUpset = TRUE,
"different sizes")
#nocov end
}
if (plotUpset && any(rowSums(filtdf) > 0)) {
print(ComplexUpset::upset(filtdf[rowSums(filtdf) > 0, , drop = FALSE],
intersect = colnames(filtdf)))
}
.makeFilterPlot(filtdf = filtdf, plotUpset = plotUpset)

if (!is.null(exclFile)) {
write.table(exclude, file = exclFile, quote = FALSE, sep = "\t",
Expand Down
38 changes: 38 additions & 0 deletions tests/testthat/test-doFilter.R
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,20 @@ test_that("filtering works (MaxQuant)", {
)))
expect_equal(nrow(out), 112L)

## Only one column present
tmp <- sce_mq_final
rowData(tmp)$Score <- NULL
rowData(tmp)$Only.identified.by.site <- NULL
rowData(tmp)$Peptides <- NULL
rowData(tmp)$Reverse <- NULL
out <- filterMaxQuant(tmp, minScore = 7, minPeptides = 1,
plotUpset = TRUE, exclFile = NULL)
expect_equal(nrow(out), length(which(
(rowData(sce_mq_final)$Potential.contaminant == "" |
is.na(rowData(sce_mq_final)$Potential.contaminant))
)))
expect_equal(nrow(out), 112L)

## Missing columns - Potential.contaminant
tmp <- sce_mq_final
rowData(tmp)$Potential.contaminant <- NULL
Expand Down Expand Up @@ -318,6 +332,30 @@ test_that("filtering works (PD/TMT - proteins)", {
)))
expect_equal(nrow(out), 30L) ## same test as above, just with precomputed answer

## Only one column present
tmp <- sce_pd_final
rowData(tmp)$Number.of.Peptides <- NULL
rowData(tmp)$Contaminant <- NULL
out <- filterPDTMT(tmp, inputLevel = "Proteins", minScore = 10,
minPeptides = 3, minDeltaScore = 0, minPSMs = 1,
masterProteinsOnly = FALSE, plotUpset = TRUE,
exclFile = NULL)
expect_equal(nrow(out), length(which(
rowData(sce_pd_final)$Score.Sequest.HT.Sequest.HT >= 10
)))
expect_equal(nrow(out), 30L) ## same test as above, just with precomputed answer

## Only one column present, but no features excluded (should not plot)
tmp <- sce_pd_final
rowData(tmp)$Number.of.Peptides <- NULL
rowData(tmp)$Score.Sequest.HT.Sequest.HT <- NULL
out <- filterPDTMT(tmp, inputLevel = "Proteins", minScore = 10,
minPeptides = 3, minDeltaScore = 0, minPSMs = 1,
masterProteinsOnly = FALSE, plotUpset = TRUE,
exclFile = NULL)
expect_equal(nrow(out), nrow(tmp))
expect_equal(nrow(out), 70L) ## same test as above, just with precomputed answer

## Missing columns - Master
tmp <- sce_pd_final
rowData(tmp)$Master <- NULL
Expand Down

0 comments on commit 84d9639

Please sign in to comment.