From 4bbbe7c0d9c7dd05a4de1e22d7463bdbdc36c980 Mon Sep 17 00:00:00 2001 From: "yi.hsiao" Date: Thu, 23 Apr 2026 13:59:37 -0400 Subject: [PATCH] add filter options from FragPipe-Analyst --- DESCRIPTION | 2 +- NAMESPACE | 38 ++++++++++++++++++++++++++++++++++++++ R/filter.R | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 R/filter.R diff --git a/DESCRIPTION b/DESCRIPTION index 4ba3bac..2254668 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -55,5 +55,5 @@ Suggests: testthat (>= 3.0.0) biocViews: Software Config/testthat/edition: 3 -RoxygenNote: 7.3.2 +RoxygenNote: 7.3.3 VignetteBuilder: knitr diff --git a/NAMESPACE b/NAMESPACE index 5d20205..c619529 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -18,8 +18,10 @@ export(average_samples) export(bar_number) export(colData) export(consensus_clustering_analysis) +export(filter_by_condition) export(get_cluster_heatmap) export(get_density) +export(global_filter) export(glycoPSM_barplot) export(impute) export(make_se_customized) @@ -68,12 +70,22 @@ importFrom(SNFtool,spectralClustering) importFrom(SNFtool,standardNormalization) importFrom(SummarizedExperiment,"assay<-") importFrom(SummarizedExperiment,"colData<-") +importFrom(SummarizedExperiment,"metadata<-") importFrom(SummarizedExperiment,"rowData<-") importFrom(SummarizedExperiment,SummarizedExperiment) importFrom(SummarizedExperiment,assay) importFrom(SummarizedExperiment,colData) +importFrom(SummarizedExperiment,metadata) importFrom(SummarizedExperiment,rowData) +importFrom(assertthat,assert_that) +importFrom(circlize,colorRamp2) +importFrom(cluster,daisy) importFrom(clusterProfiler,GSEA) +importFrom(clusterProfiler,bitr) +importFrom(clusterProfiler,gseGO) +importFrom(clusterProfiler,gseKEGG) +importFrom(clusterProfiler,read.gmt) +importFrom(clusterProfiler,setReadable) importFrom(cmapR,GCT) importFrom(cmapR,ids) importFrom(cmapR,mat) @@ -85,11 +97,14 @@ importFrom(data.table,melt.data.table) importFrom(data.table,setDT) importFrom(dplyr,all_of) importFrom(dplyr,arrange) +importFrom(dplyr,ends_with) importFrom(dplyr,filter) importFrom(dplyr,group_by) +importFrom(dplyr,if_all) importFrom(dplyr,left_join) importFrom(dplyr,mutate) importFrom(dplyr,n) +importFrom(dplyr,pull) importFrom(dplyr,recode) importFrom(dplyr,rename) importFrom(dplyr,select) @@ -100,6 +115,7 @@ importFrom(dplyr,summarize) importFrom(fdrtool,fdrtool) importFrom(ggplot2,aes) importFrom(ggplot2,aes_string) +importFrom(ggplot2,annotate) importFrom(ggplot2,coord_fixed) importFrom(ggplot2,element_blank) importFrom(ggplot2,element_line) @@ -110,8 +126,11 @@ importFrom(ggplot2,geom_boxplot) importFrom(ggplot2,geom_col) importFrom(ggplot2,geom_histogram) importFrom(ggplot2,geom_jitter) +importFrom(ggplot2,geom_line) importFrom(ggplot2,geom_point) importFrom(ggplot2,geom_text) +importFrom(ggplot2,geom_text_repel) +importFrom(ggplot2,geom_violin) importFrom(ggplot2,geom_vline) importFrom(ggplot2,ggplot) importFrom(ggplot2,ggplot_build) @@ -128,9 +147,18 @@ importFrom(ggplot2,scale_x_continuous) importFrom(ggplot2,scale_y_continuous) importFrom(ggplot2,theme) importFrom(ggplot2,theme_bw) +importFrom(ggplot2,theme_classic) +importFrom(ggplot2,theme_void) +importFrom(ggplot2,xlab) +importFrom(ggplot2,ylab) +importFrom(ggplotify,as.ggplot) importFrom(ggrepel,geom_text_repel) importFrom(grDevices,colorRampPalette) +importFrom(grDevices,dev.off) +importFrom(grDevices,png) importFrom(grid,gpar) +importFrom(grid,grid.rect) +importFrom(grid,grid.text) importFrom(grid,unit) importFrom(httr,GET) importFrom(limma,contrasts.fit) @@ -145,10 +173,20 @@ importFrom(plotly,layout) importFrom(plotly,plot_ly) importFrom(purrr,map_df) importFrom(readr,parse_factor) +importFrom(scales,percent) +importFrom(stats,complete.cases) +importFrom(stats,cor) +importFrom(stats,kmeans) +importFrom(stats,lm) +importFrom(stats,mad) +importFrom(stats,median) +importFrom(stats,prcomp) importFrom(stringr,str_count) importFrom(tibble,column_to_rownames) +importFrom(tibble,is_tibble) importFrom(tibble,rownames_to_column) importFrom(tidyr,gather) +importFrom(tidyr,replace_na) importFrom(tidyr,spread) importFrom(tidyr,unite) importFrom(vsn,predict) diff --git a/R/filter.R b/R/filter.R new file mode 100644 index 0000000..b506972 --- /dev/null +++ b/R/filter.R @@ -0,0 +1,48 @@ +#' Filter proteins by missing values globally +#' +#' \code{global_filter} removes proteins that have missing values in more than +#' a given percentage of all samples. +#' +#' @param se SummarizedExperiment, proteomics data. +#' @param percentage Numeric, maximum percentage of missing values allowed +#' across all samples (0-100). Default is 50. +#' @return A filtered SummarizedExperiment object. +#' @examples +#' data("ccrcc", package = "FragPipeAnalystR") +#' filtered <- global_filter(ccrcc, percentage = 50) +#' +#' @export +global_filter <- function(se, percentage=50){ + percentage <- percentage / 100 + ridx <- rowSums(is.na(assay(se))) / ncol(assay(se)) <= percentage + se <- se[ridx,] + return(se) +} + +#' Filter proteins by missing values per condition +#' +#' \code{filter_by_condition} retains proteins that are observed in at least +#' \code{min_percentage} of samples in at least one condition. +#' +#' @param se SummarizedExperiment, proteomics data. Must have a \code{condition} +#' column in \code{colData}. +#' @param min_percentage Numeric, minimum percentage of non-missing values +#' required within at least one condition (0-100). Default is 50. +#' @return A filtered SummarizedExperiment object. +#' @examples +#' data("ccrcc", package = "FragPipeAnalystR") +#' filtered <- filter_by_condition(ccrcc, min_percentage = 50) +#' +#' @export +filter_by_condition <- function(se, min_percentage=50) { + min_percentage <- min_percentage / 100 + conditions <- unique(colData(se)$condition) + row_ids <- rep(0, nrow(assay(se))) + for (c in conditions){ + se_c <- se[,colData(se)$condition == c] + ridx <- rowSums(!is.na(assay(se_c))) / ncol(assay(se_c)) >= min_percentage + row_ids <- row_ids + ridx + } + se <- se[row_ids > 0,] + return(se) +}