knitr::opts_chunk$set(fig.cap = NULL, fig.path = params$output_figure)

library(data.table)
library(ggplot2)
library(ggrepel)
library(GGally)
library(umap)
library(FactoMineR)
library(factoextra)
library(corrplot)
library(viridis)
library(ggpubr)
library(Hmisc)
library(plotly)
library(stringr)
library(bit64)

num_files <- expdes[, .N]
run_per_condition <- expdes[, .(countRepMax = .N), by = .(experiment)]
setnames(run_per_condition, "experiment", "condition")

# for fractions, create file name from mqExperiment and Fraction
if (!("file_name" %in% colnames(expdes))){
  expdes$file_name = paste(expdes$experiment, " - ", expdes$Replicate)
}


if (!protein_only){
  mod_pept_int_rep <- merge(
    run_per_condition,
    mod_pept_int[Imputed == 0, .(Repcount = .N), by = .(id, condition)],
    by = c("condition")
  )
  mod_pept_int_rep[, repPC := Repcount/countRepMax]
  mod_pept_id_in_a_cond <- mod_pept_int_rep[repPC >= 0.5, unique(id)]
  mod_pept_int[, Valid := 0L]
  mod_pept_int[id %in% mod_pept_id_in_a_cond, Valid := 1L]
  rm(mod_pept_id_in_a_cond, mod_pept_int_rep)

  pept_int_rep <- merge(
    run_per_condition,
    pept_int[Imputed == 0, .(Repcount = .N), by = .(id, condition)],
    by = c("condition")
  )
  pept_int_rep[, repPC := Repcount/countRepMax]
  pept_id_in_a_cond <- pept_int_rep[repPC >= 0.5, unique(id)]
  pept_int[, Valid := 0L]
  pept_int[id %in% pept_id_in_a_cond, Valid := 1L]
  rm(pept_id_in_a_cond, pept_int_rep)

}

prot_int_rep <- merge(
  run_per_condition,
  prot_int[Imputed == 0, .(Repcount = .N), by = .(id, condition)],
  by = c("condition")
)
prot_int_rep[, repPC := Repcount/countRepMax]
prot_id_in_a_cond <- prot_int_rep[repPC >= 0.5, unique(id)]
prot_int[, Valid := 0L]
prot_int[id %in% prot_id_in_a_cond, Valid := 1L]
rm(prot_id_in_a_cond, prot_int_rep)
dt <- prot_int[Imputed == 0, .(`% measured values` = .N/prot_int[, length(unique(id))]), by = .(run_id, condition, Replicate)]
dt[, Run := str_c(condition, Replicate, sep = " - ")]

dt[, `% measured values` := 100*(round(`% measured values`, 2))]

p<- ggplot(dt, aes(y = `% measured values`, x = Run, 
                   color = condition, fill = condition)) +
  geom_bar(stat ="identity", position = "dodge")+
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 90, vjust = 0.2),
        panel.grid.major.y = element_blank(),
        panel.border = element_blank(),
        axis.ticks.y = element_blank()
  ) +
  scale_x_discrete("Condition - Replicate") +
  ggtitle("Proteins - Data completedness by samples")

ggplotly(p, tooltip = c("x","y")) %>% config(displayModeBar = T, 
                                               modeBarButtons = list(list('toImage')),
                                               displaylogo = F)


MassDynamics/lfq_processing documentation built on May 4, 2023, 11:20 p.m.