Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions R/PCA_Plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#'
#' @param D \strong{data.frame} \cr
#' The data set containing intensities of the sample.
#' @param id \strong{data.frame} \cr
#' The corresponding ID columns for the parameter D e.g. containing further columns like protein or gene names
#' @param groupvar1 \strong{character vector} \cr
#' The variable used for colors.
#' @param groupvar2 \strong{character vector} \cr
Expand Down Expand Up @@ -49,6 +51,7 @@
#'

PCA_Plot <- function(D,
id = NULL,
groupvar1 = NULL, groupvar2 = NULL,

impute = FALSE, impute_method = "mean", propNA = 0,
Expand All @@ -67,7 +70,9 @@ PCA_Plot <- function(D,

mess = ""

filtered_D <- filter_PCA_data(D = D, impute = impute, impute_method = impute_method, propNA = propNA)
filtered_data <- filter_PCA_data(D = D, id = id, impute = impute, impute_method = impute_method, propNA = propNA)
filtered_D <- filtered_data$D
filtered_id <- filtered_data$id

if(is.null(filtered_D)){
mess <- paste0(mess, "All rows were filtered out. \n")
Expand Down Expand Up @@ -142,7 +147,12 @@ PCA_Plot <- function(D,

message(mess)

return(list("plot" = pl, "D_PCA_plot" = cbind(D_PCA, "Sample" = colnames(D)),
"pca" = pca, "message" = mess, "filtered_D" = filtered_D, "loadings" = pca$rotation))
Loadings <- as.data.frame(pca$rotation)
if (!is.null(filtered_id)) {
Loadings <- cbind(filtered_id, Loadings)
}

return(list("D_PCA_plot" = cbind(D_PCA, "Sample" = colnames(D)),
"pca" = pca, "message" = mess, "filtered_D" = filtered_D, "loadings" = Loadings, "plot" = pl))
}

12 changes: 9 additions & 3 deletions R/PCA_helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#'
#' @param D \strong{data.frame} \cr
#' The data set containing intensities of the sample.
#' @param id \strong{data.frame} \cr
#' The corresponding ID columns for the parameter D e.g. containing further columns like protein or gene names
#' @param impute \strong{logical} \cr
#' If \code{TRUE}, missing values will be imputed.
#' @param impute_method \strong{character} \cr
Expand All @@ -17,13 +19,17 @@
#'
#'

filter_PCA_data <- function(D, impute = FALSE, impute_method = "mean", propNA = 0){
filter_PCA_data <- function(D, id = NULL, impute = FALSE, impute_method = "mean", propNA = 0){

# proportion if missing values per protein
mean_NA <- apply(D, 1, function(x) mean(is.na(x)))

### remove rows with too many missing values
D <- D[mean_NA <= propNA, ]
index_to_keep <- mean_NA <= propNA
D <- D[index_to_keep, ]
if (!is.null(id)) {
id <- id[index_to_keep, ]
}

if (nrow(D) == 0){
return(NULL)
Expand Down Expand Up @@ -52,7 +58,7 @@ filter_PCA_data <- function(D, impute = FALSE, impute_method = "mean", propNA =
ind_zeroVar <- which(v < 1e-25)
if (length(ind_zeroVar) > 0) D <- D[-ind_zeroVar,]

return(D)
return(list(D = D, id = id))
}


Expand Down