Skip to content

Commit

Permalink
Merge branch 'development' of github.com:saezlab/MetaProViz into deve…
Browse files Browse the repository at this point in the history
…lopment
  • Loading branch information
deeenes committed Oct 28, 2024
2 parents 2f0ef89 + 0542660 commit d33f868
Show file tree
Hide file tree
Showing 15 changed files with 350 additions and 110 deletions.
7 changes: 7 additions & 0 deletions .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[bumpversion]
current_version = 2.1.1
commit = True
tag = True
files = DESCRIPTION README.md README.Rmd
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)
serialize = {major}.{minor}.{patch}
38 changes: 38 additions & 0 deletions .github/workflows/Build_gh-pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples and adapted
on:
push:
branches: [main]

name: Build_gh-pages.yml #shown when action is run

jobs:
pkgdown:
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} #to push results to gh-pages branch!
steps: #Series of steps that is executed sequencially: https://github.com/r-lib/actions/
- uses: actions/checkout@v4 # goes to gh-pages branch to work there

- uses: r-lib/actions/setup-pandoc@v2 #installs pandoc

- uses: r-lib/actions/setup-r@v2 #installs R
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::pkgdown, local::.
needs: website

- name: Build site
run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
shell: Rscript {0}

- name: Deploy to GitHub pages 🚀
if: github.event_name != 'pull_request'
uses: JamesIves/[email protected]
with:
clean: false
branch: gh-pages
folder: docs
47 changes: 47 additions & 0 deletions .github/workflows/Test_Package-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
# This workflow tests if the package can be installed from github from within
# a github action.
on:
push:
branches: [development, main]

name: R-CMD-check

jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.os }} (${{ matrix.config.r }})

strategy:
fail-fast: false
matrix:
config:
- {os: macos-latest, r: 'release'}
- {os: ubuntu-latest, r: 'release'}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v2

- name: Install libglpk40
if: ${{ matrix.config.os == 'ubuntu-latest' }}
run: sudo apt-get install -y libglpk40

- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}
use-public-rspm: true

- name: Install pak
run: Rscript -e 'install.packages("pak")'

- name: Install MetaProViz from git by pak
run: Rscript -e 'pak::pkg_install("saezlab/MetaProViz")' #we install from GitHub as if we are a random user
10 changes: 9 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: MetaProViz
Title: METabolomics pre-PRocessing, functiOnal analysis and VIZualisation
Version: 2.1.0
Version: 2.1.1
Authors@R: c(
person("Christina", "Schmidt", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0002-3867-0881")),
Expand Down Expand Up @@ -31,16 +31,24 @@ Depends:
R (>= 4.4.1),
ggplot2 (>= 3.3.5)
Imports:
clusterProfiler,
cosmosR,
dplyr,
EnhancedVolcano,
factoextra,
ggbeeswarm,
ggfortify,
ggplot2,
ggupset,
ggVennDiagram,
grid,
gridExtra,
gtools,
hash,
inflection,
kableExtra,
KEGGREST,
limma,
logger,
magrittr,
OmnipathR,
Expand Down
185 changes: 130 additions & 55 deletions R/Processing.R

Large diffs are not rendered by default.

112 changes: 87 additions & 25 deletions R/VizHeatmap.R
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ VizHeatmap <- function(InputData,
# Make the plot
if(nrow(t(data_path))>= 2){
set.seed(1234)

heatmap <- pheatmap::pheatmap(t(data_path),
show_rownames = as.logical(show_rownames),
show_colnames = as.logical(show_colnames),
Expand All @@ -193,16 +194,17 @@ VizHeatmap <- function(InputData,
fontsize_row= 10,
fontsize_col = 10,
fontsize=9,
main = paste(PlotName, " Metabolites: ", i, sep=" " ))
main = paste(PlotName, " Metabolites: ", i, sep=" " ),
silent = TRUE)

## Store the plot in the 'plots' list
cleaned_i <- gsub("[[:space:],/\\\\]", "-", i)#removes empty spaces and replaces /,\ with -
PlotList[[cleaned_i]] <- heatmap

#Width and height according to Sample and metabolite number
Plot_Sized <- PlotGrob_Heatmap(InputPlot=heatmap, SettingsInfo=SettingsInfo, PlotName= cleaned_i)
PlotHeight <- as.numeric(Plot_Sized$height)
PlotWidth <- as.numeric(Plot_Sized$width)
Plot_Sized <- PlotGrob_Heatmap(InputPlot=heatmap, SettingsInfo=SettingsInfo, SettingsFile_Sample=SettingsFile_Sample, SettingsFile_Metab=SettingsFile_Metab, PlotName= cleaned_i)
PlotHeight <- grid::convertUnit(Plot_Sized$height, 'cm', valueOnly = TRUE)
PlotWidth <- grid::convertUnit(Plot_Sized$width, 'cm', valueOnly = TRUE)
Plot_Sized %<>%
{ggplot2::ggplot() + annotation_custom(.)} %>%
add(theme(panel.background = element_rect(fill = "transparent")))
Expand Down Expand Up @@ -316,6 +318,7 @@ VizHeatmap <- function(InputData,
# Make the plot
if(nrow(t(data_path))>= 2){
set.seed(1234)

heatmap <- pheatmap::pheatmap(t(data_path),
show_rownames = as.logical(show_rownames),
show_colnames = as.logical(show_colnames),
Expand All @@ -330,16 +333,17 @@ VizHeatmap <- function(InputData,
fontsize_row= 10,
fontsize_col = 10,
fontsize=9,
main = paste(PlotName," Samples: ", i, sep=" " ))
main = paste(PlotName," Samples: ", i, sep=" " ),
silent = TRUE)

#----- Save
cleaned_i <- gsub("[[:space:],/\\\\]", "-", i)#removes empty spaces and replaces /,\ with -
PlotList[[cleaned_i]] <- heatmap

#Width and height according to Sample and metabolite number
Plot_Sized <- PlotGrob_Heatmap(InputPlot=heatmap, SettingsInfo=SettingsInfo, PlotName= cleaned_i)
PlotHeight <- as.numeric(Plot_Sized$height)
PlotWidth <- as.numeric(Plot_Sized$width)
Plot_Sized <- PlotGrob_Heatmap(InputPlot=heatmap, SettingsInfo=SettingsInfo, SettingsFile_Sample=SettingsFile_Sample, SettingsFile_Metab=SettingsFile_Metab, PlotName= cleaned_i)
PlotHeight <- grid::convertUnit(Plot_Sized$height, 'cm', valueOnly = TRUE)
PlotWidth <- grid::convertUnit(Plot_Sized$width, 'cm', valueOnly = TRUE)
Plot_Sized %<>%
{ggplot2::ggplot() + annotation_custom(.)} %>%
add(theme(panel.background = element_rect(fill = "transparent")))
Expand Down Expand Up @@ -474,6 +478,7 @@ VizHeatmap <- function(InputData,
# Make the plot
if(nrow(t(data_path))>= 2){
set.seed(1234)

heatmap <- pheatmap::pheatmap(t(data_path),
show_rownames = as.logical(show_rownames),
show_colnames = as.logical(show_colnames),
Expand All @@ -488,7 +493,8 @@ VizHeatmap <- function(InputData,
fontsize_row= 10,
fontsize_col = 10,
fontsize=9,
main = paste(PlotName," Metabolites: ", i, " Sample:", s, sep="" ))
main = paste(PlotName," Metabolites: ", i, " Sample:", s, sep="" ),
silent = TRUE)

## Store the plot in the 'plots' list
cleaned_i <- gsub("[[:space:],/\\\\]", "-", i)#removes empty spaces and replaces /,\ with -
Expand All @@ -498,9 +504,9 @@ VizHeatmap <- function(InputData,
#-------- Plot width and heights
#Width and height according to Sample and metabolite number
PlotName <- paste(cleaned_i,cleaned_s, sep="_")
Plot_Sized <- PlotGrob_Heatmap(InputPlot=heatmap, SettingsInfo=SettingsInfo, PlotName= PlotName)
PlotHeight <- as.numeric(Plot_Sized$height)
PlotWidth <- as.numeric(Plot_Sized$width)
Plot_Sized <- PlotGrob_Heatmap(InputPlot=heatmap, SettingsInfo=SettingsInfo, SettingsFile_Sample=SettingsFile_Sample, SettingsFile_Metab=SettingsFile_Metab, PlotName= PlotName)
PlotHeight <- grid::convertUnit(Plot_Sized$height, 'cm', valueOnly = TRUE)
PlotWidth <- grid::convertUnit(Plot_Sized$width, 'cm', valueOnly = TRUE)
Plot_Sized %<>%
{ggplot2::ggplot() + annotation_custom(.)} %>%
add(theme(panel.background = element_rect(fill = "transparent")))
Expand Down Expand Up @@ -589,6 +595,7 @@ VizHeatmap <- function(InputData,
#Make the plot:
if(nrow(t(data))>= 2){
set.seed(1234)

heatmap <- pheatmap::pheatmap(t(data),
show_rownames = as.logical(show_rownames),
show_colnames = as.logical(show_colnames),
Expand All @@ -603,16 +610,17 @@ VizHeatmap <- function(InputData,
fontsize_row= 10,
fontsize_col = 10,
fontsize=9,
main = PlotName)
main = PlotName,
silent = TRUE)

## Store the plot in the 'plots' list
PlotList[[PlotName]] <- heatmap

#-------- Plot width and heights
#Width and height according to Sample and metabolite number
Plot_Sized <- PlotGrob_Heatmap(InputPlot=heatmap, SettingsInfo=SettingsInfo, PlotName= PlotName)
PlotHeight <- as.numeric(Plot_Sized$height)
PlotWidth <- as.numeric(Plot_Sized$width)
Plot_Sized <- PlotGrob_Heatmap(InputPlot=heatmap, SettingsInfo=SettingsInfo, SettingsFile_Sample=SettingsFile_Sample, SettingsFile_Metab=SettingsFile_Metab, PlotName= PlotName)
PlotHeight <- grid::convertUnit(Plot_Sized$height, 'cm', valueOnly = TRUE)
PlotWidth <- grid::convertUnit(Plot_Sized$width, 'cm', valueOnly = TRUE)
Plot_Sized %<>%
{ggplot2::ggplot() + annotation_custom(.)} %>%
add(theme(panel.background = element_rect(fill = "transparent")))
Expand All @@ -630,7 +638,7 @@ VizHeatmap <- function(InputData,
CoRe=FALSE,
PrintPlot=PrintPlot,
PlotHeight=PlotHeight,
PlotWidth=PlotHeight,
PlotWidth=PlotWidth,
PlotUnit="cm")))


Expand All @@ -649,12 +657,14 @@ VizHeatmap <- function(InputData,

#' @param InputPlot This is the ggplot object generated within the VizHeatmap function.
#' @param SettingsInfo Passed to VizHeatmap
#' @param SettingsFile_Sample Passed to VizHeatmap
#' @param SettingsFile_Metab Passed to VizHeatmap
#' @param PlotName Passed to VizHeatmap
#'
#' @keywords Heatmap helper function
#' @noRd

PlotGrob_Heatmap <- function(InputPlot, SettingsInfo, PlotName){
PlotGrob_Heatmap <- function(InputPlot, SettingsInfo, SettingsFile_Sample, SettingsFile_Metab, PlotName){

# Set the parameters for the plot we would like to use as a basis, before we start adjusting it:
HEAT_PARAM <- list(
Expand All @@ -666,19 +676,71 @@ PlotGrob_Heatmap <- function(InputPlot, SettingsInfo, PlotName){
)
)

#If we plot feature names on the x-axis, we need to adjust the height of the plot:
#if(as.logical(show_rownames)==TRUE){
# Rows <- nrow(t(data))
#}

#Adjust the parameters:
Input <- InputPlot$gtable

Plot_Sized <- Input %>%
withCanvasSize(width = 12, height = 11) %>%
adjust_layout(HEAT_PARAM) #%>%
#adjust_title(c(PlotName)) %>%
#adjust_legend(
# Input,
# sections = c("color_Sample", "color_Metab"),#How can we do this as here we have multiple once!
# SettingsInfo = SettingsInfo
#)
adjust_layout(HEAT_PARAM) %>%
adjust_title(c(PlotName))

#Extract legend information and adjust:
color_entries <- grep("^color", names(SettingsInfo), value = TRUE)
if(length(color_entries)>0){#We need to adapt the plot Hights and widths
if(sum(grepl("color_Sample", names(SettingsInfo)))>0){
names <- SettingsInfo[grepl("color_Sample", names(SettingsInfo))]
colour_names <- NULL
legend_names <- NULL
for (x in 1:length(names)){
names_sel <- names[[x]]
legend_names[x] <- names_sel
colour_names[x] <- SettingsFile_Sample[names[[x]]]
}
}else{
colour_names <- NULL
legend_names <- NULL
}

if(sum(grepl("color_Metab", names(SettingsInfo)))>0){
names <- SettingsInfo[grepl("color_Metab", names(SettingsInfo))]
colour_names_M <- NULL
legend_names_M <- NULL
for (x in 1:length(names)){
names_sel <- names[[x]]
legend_names_M[x] <- names_sel
colour_names_M[x] <- SettingsFile_Metab[names[[x]]]
}
}else{
colour_names_M <- NULL
legend_names_M <- NULL
}

legend_head <- c(legend_names, legend_names_M)
longest_name <- legend_head[which.max(nchar(legend_head[[1]]))]
character_count_head <- nchar(longest_name)+4#This is the length of the legend title name

legend_names <- c(unlist(colour_names), unlist(colour_names_M))
longest_name <- legend_names[which.max(nchar(legend_names[[1]]))]
character_count <- nchar(longest_name)#This is the length of the legend colour names

legendWidth <- unit(((max(character_count_head, character_count))*0.3), "cm")#legend space

# Sum up total heights:
Plot_Sized$width %<>% add(legendWidth)

legendHeights <- unit((sum(length(unique(legend_names_M))+length(unique(colour_names_M))+length(unique(legend_names))+length(unique(colour_names)))), "cm")

Plot_Sized$width %<>% add(legendWidth)
if((grid::convertUnit(legendHeights, 'cm', valueOnly = TRUE))>(grid::convertUnit(Plot_Sized$height, 'cm', valueOnly = TRUE))){
Plot_Sized$height <- legendHeights
}

}

Output <- Plot_Sized

Expand Down
6 changes: 3 additions & 3 deletions R/VizSuperplots.R
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,8 @@ VizSuperplot <- function(InputData,

# Make plot into nice format:
Plot_Sized <- MetaProViz:::plotGrob_Superplot(InputPlot=Plot, SettingsInfo=SettingsInfo, SettingsFile_Sample=SettingsFile_Sample, PlotName = PlotName, Subtitle = i, PlotType=PlotType)
PlotHeight <- as.numeric(Plot_Sized$height)
PlotWidth <- as.numeric(Plot_Sized$width)
PlotHeight <- grid::convertUnit(Plot_Sized$height, 'cm', valueOnly = TRUE)
PlotWidth <- grid::convertUnit(Plot_Sized$width, 'cm', valueOnly = TRUE)
Plot_Sized %<>%
{ggplot2::ggplot() + annotation_custom(.)} %>%
add(theme(panel.background = element_rect(fill = "transparent")))
Expand Down Expand Up @@ -412,7 +412,7 @@ plotGrob_Superplot <- function(InputPlot,
PlotType){
# Set the parameters for the plot we would like to use as a basis, before we start adjusting it:
X_Con <- SettingsFile_Sample%>%
dplyr::distinct(!!sym(SettingsInfo[["Conditions"]]))
dplyr::distinct(Conditions)

X_Tick <- unit(X_Con[[1]] %>% char2cm %>% max * 0.6, "cm")

Expand Down
8 changes: 4 additions & 4 deletions R/VizVolcano.R
Original file line number Diff line number Diff line change
Expand Up @@ -562,8 +562,8 @@ VizVolcano_Standard <- function(InputData,

#Set the total heights and widths
Plot_Sized <- MetaProViz:::plotGrob_Volcano(InputPlot=Plot, SettingsInfo=SettingsInfo, PlotName = PlotName, Subtitle = Subtitle)
PlotHeight <- as.numeric(Plot_Sized$height)
PlotWidth <- as.numeric(Plot_Sized$width)
PlotHeight <- grid::convertUnit(Plot_Sized$height, 'cm', valueOnly = TRUE)
PlotWidth <- grid::convertUnit(Plot_Sized$width, 'cm', valueOnly = TRUE)
Plot_Sized %<>%
{ggplot2::ggplot() + annotation_custom(.)} %>%
add(theme(panel.background = element_rect(fill = "transparent")))
Expand Down Expand Up @@ -926,8 +926,8 @@ VizVolcano_Compare <- function(InputData,
PlotList[["Plot"]] <- Plot

Plot_Sized <- MetaProViz:::plotGrob_Volcano(InputPlot=Plot, SettingsInfo=SettingsInfo, PlotName = PlotName, Subtitle = Subtitle)
PlotHeight <- as.numeric(Plot_Sized$height)
PlotWidth <- as.numeric(Plot_Sized$width)
PlotHeight <- grid::convertUnit(Plot_Sized$height, 'cm', valueOnly = TRUE)
PlotWidth <- grid::convertUnit(Plot_Sized$width, 'cm', valueOnly = TRUE)
Plot_Sized %<>%
{ggplot2::ggplot() + annotation_custom(.)} %>%
add(theme(panel.background = element_rect(fill = "transparent")))
Expand Down
Loading

0 comments on commit d33f868

Please sign in to comment.