annotate utils.r @ 0:cd2f3a280463 draft default tip

planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
author recetox
date Wed, 22 Jan 2025 07:44:00 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
1 # Export intermediate results
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
2 # Function to export a single assay with metadata
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
3 export_assay_with_metadata <- function(qf, assay_name) {
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
4 # Extract assay data, row metadata, and col metadata
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
5 assay_data <- SummarizedExperiment::assay(qf[[assay_name]])
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
6 row_metadata <- as.data.frame(SummarizedExperiment::rowData(qf[[assay_name]]))
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
7 col_metadata <- as.data.frame(SummarizedExperiment::colData(qf))
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
8 # Combine row metadata with assay data
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
9 export_data <- cbind(RowNames = rownames(assay_data), row_metadata, as.data.frame(assay_data))
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
10 # Save the table to a CSV file
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
11 output_file <- file.path("outputs", paste0(assay_name, "_export.txt"))
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
12 write.table(export_data, output_file, row.names = FALSE, sep = "\t", quote = F)
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
13 }
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
14
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
15 # Export all assays
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
16 export_all_assays <- function(qf) {
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
17 # Get the names of all assays
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
18 # assay_names <- names(assays(qf))
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
19 assay_names <- c("peptides", "peptides_norm", "peptides_log", "proteins", "proteins_norm", "proteins_imptd")
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
20 dir.create("outputs")
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
21 # Export each assay
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
22 for (assay_name in assay_names) {
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
23 export_assay_with_metadata(qf, assay_name)
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
24 }
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
25 }
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
26
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
27 # Plot the QC boxplots
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
28 create_boxplots <- function(scp, i, is_log2, name) {
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
29 sce <- scp[[i]]
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
30 assay_data <- as.data.frame(SummarizedExperiment::assay(sce)) |>
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
31 tibble::rownames_to_column("FeatureID")
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
32 col_data <- as.data.frame(SummarizedExperiment::colData(scp)) |>
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
33 tibble::rownames_to_column("SampleID")
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
34 long_data <- assay_data |>
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
35 tidyr::pivot_longer(
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
36 cols = -FeatureID,
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
37 names_to = "SampleID",
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
38 values_to = "Value"
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
39 )
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
40 long_data <- long_data |>
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
41 dplyr::left_join(col_data, by = "SampleID")
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
42 if (is_log2 == TRUE) {
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
43 long_data$Value <- log2(long_data$Value)
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
44 }
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
45 long_data |>
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
46 dplyr::filter(Value != "NaN") |>
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
47 ggplot2::ggplot(ggplot2::aes(x = runCol, y = Value, fill = SampleType)) +
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
48 ggplot2::geom_boxplot() +
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
49 ggplot2::theme_bw() +
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
50 ggplot2::labs(
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
51 title = name,
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
52 x = "Run",
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
53 y = "Log2 intensity"
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
54 ) +
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
55 ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 45, hjust = 1))
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
56 }
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
57
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
58 # Heatmap
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
59 plot_heatmap <- function(scp, i) {
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
60 sce <- scp[[i]]
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
61 heatmap_mat <- as.matrix(SummarizedExperiment::assay(sce))
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
62 heatmap_mat[is.na(heatmap_mat)] <- 0
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
63 heatmap_bin <- ifelse(heatmap_mat > 0, 1, 0)
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
64 colnames(heatmap_bin) <- gsub("Reporter.intensity.", "", colnames(heatmap_bin))
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
65 heatmap(heatmap_bin, scale = "none", col = c("white", "black"), labRow = FALSE, margins = c(10, 5), cexCol = 0.5)
cd2f3a280463 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/bioconductor-scp commit a0a1a3de5dd24b2aabe96ec3d6f89acdcf5e462b
recetox
parents:
diff changeset
66 }