Skip to content

Commit

Permalink
Added some plots to the vignette, not all exported or shown, but good…
Browse files Browse the repository at this point in the history
… QC for us.
  • Loading branch information
ChristinaSchmidt1 committed Jan 31, 2025
1 parent 4f79350 commit d842fb5
Showing 1 changed file with 112 additions and 14 deletions.
126 changes: 112 additions & 14 deletions vignettes/CoRe Metabolomics.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ library(dplyr)
library(tibble)
library(rlang)
library(ggfortify)
library(stringr)
#Please install the Biocmanager Dependencies:
#BiocManager::install("clusterProfiler")
Expand Down Expand Up @@ -403,14 +404,26 @@ Regulatory rules:\
\
```{r}
#Example of all possible flows:
MCA_CORE <- MetaProViz::MCA_rules(Method="CoRe")
MCA_CoRe <- MetaProViz::MCA_rules(Method="CoRe")
```
```{r, echo=FALSE}
# Check how our data looks like:
MCA_CORE[,1:6]%>%
MCA_CoRe[,1:6]%>%
kableExtra::kbl(caption ="Metabolite Clustering Analysis: CoRe.", row.names=FALSE) %>%
kableExtra::kable_classic(full_width = F, html_font = "Cambria", font_size = 12)
```
```{r, eval=FALSE, include=FALSE}
# Alluvial plot of the rules:
Plot<- easyalluvial::alluvial_wide(MCA_CoRe[,c(1:3,5,6)], fill_by = 'last_variable' )+
ggplot2::ggtitle("Regulatory rules resulting in the regulatory clusters that are based on signifcant change") +
ggplot2::theme_classic() +
ggplot2::theme(axis.text.y=ggplot2::element_blank(), #remove y axis labels
axis.ticks.y=ggplot2::element_blank(), #remove y axis ticks
axis.title.y=ggplot2::element_blank(),
axis.text.x = ggplot2::element_text(angle = 90, vjust = 0.5, hjust=1))
#ggplot2::ggsave("AlluvialOverview_RG3SignificantChange2.svg", plot=Plot, width=8, height=15)
```
\
Now we can load the corresponding pre-processed intracellular example data for the comparison of 786M-1A versus HK2 (For the detailed pre-processing please see the vignette "Standard Metabolomics").
```{r}
Expand Down Expand Up @@ -442,6 +455,78 @@ ClusterSummary[-c(1:26),] %>%
kableExtra::kable_classic(full_width = F, html_font = "Cambria", font_size = 12)
```

```{r, echo=FALSE}
#Create some summary Bargraphs:
ClusterSummary_RG2 <- ClusterSummary%>%
filter(`Regulation Grouping`=="RG2_Significant")%>%
filter(!`SiRCle cluster Name`=="Background = FALSE")
ClusterSummary_RG3 <- ClusterSummary%>%
filter(`Regulation Grouping`=="RG3_Change")%>%
filter(!`SiRCle cluster Name`=="Background = FALSE")
#Barplot for RG2:
Plot_RG2 <- ggplot2::ggplot(ClusterSummary_RG2 , ggplot2::aes(fill=`SiRCle cluster Name`, y=`Number of Features`, x=`SiRCle cluster Name`)) +
ggplot2::geom_bar(stat="identity")+
ggplot2::theme_classic()+
ggplot2::scale_fill_manual(values = c("None"="grey" , "Both_UP (Released/Consumed)" = "#9F0162", "Both_DOWN (Released/Consumed)"= "#006384", "Opposite (Consumed DOWN)"="#00735C", "Opposite (Released UP)"="#00422E", "Both_DOWN (Consumed)"= "blue", "CoRe_DOWN (Released/Consumed)"= "lightblue", "CoRe_UP (Released/Consumed)"= "#d03293", "CoRe_UP (Released)"="#630026", "CoRe_DOWN (Consumed)"= "darkblue" ))+
ggplot2::ggtitle("SiRCle cluster for RG2_Significant")+
ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 90, hjust = 1),
legend.position = "none")+
ggplot2::labs(x = "SiRCle cluster", y = "Number of Metabolites")
Plot_Sized <- MetaProViz:::plotGrob_Superplot(InputPlot=Plot_RG2, SettingsInfo=c(Conditions="Conditions"), SettingsFile_Sample=ClusterSummary_RG2%>%dplyr::rename("Conditions"="SiRCle cluster Name"), PlotName = "SiRCle cluster for RG2_Significant", Subtitle = NULL, PlotType="Bar")
PlotHeight <- grid::convertUnit(Plot_Sized$height, 'cm', valueOnly = TRUE)
PlotWidth <- grid::convertUnit(Plot_Sized$width, 'cm', valueOnly = TRUE)
Plot_Sized %<>%
{ggplot2::ggplot() + ggplot2::annotation_custom(.)} %>%
magrittr::add(ggplot2::theme(panel.background = ggplot2::element_rect(fill = "transparent")))
Plot_Sized_RG2 <- Plot_Sized
#ggplot2::ggsave(filename = "Plot_RG2.svg", plot = Plot_Sized_RG2, width = PlotWidth, height = PlotHeight, unit="cm")
#Barplot for RG3:
Plot_RG3 <- ggplot2::ggplot(ClusterSummary_RG3 , ggplot2::aes(fill=`SiRCle cluster Name`, y=`Number of Features`, x=`SiRCle cluster Name`)) +
ggplot2::geom_bar(stat="identity")+
ggplot2::theme_classic()+
ggplot2::scale_fill_manual(values = c("None"="grey" , "Both_UP (Released/Consumed)" = "#9F0162", "Both_DOWN (Released/Consumed)"= "#006384", "Opposite (Consumed DOWN)"="#00735C", "Opposite (Released UP)"="#00422E", "Both_DOWN (Consumed)"= "blue", "CoRe_DOWN (Released/Consumed)"= "lightblue", "CoRe_UP (Released/Consumed)"= "#d03293", "CoRe_UP (Released)"="#630026", "CoRe_DOWN (Consumed)"= "darkblue" ))+
ggplot2::ggtitle("SiRCle cluster for RG3_Change")+
ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 90, hjust = 1),
legend.position = "none")+
ggplot2::labs(x = "SiRCle cluster", y = "Number of Metabolites")
Plot_Sized <- MetaProViz:::plotGrob_Superplot(InputPlot=Plot_RG3, SettingsInfo=c(Conditions="Conditions"), SettingsFile_Sample=ClusterSummary_RG3%>%dplyr::rename("Conditions"="SiRCle cluster Name"), PlotName = "SiRCle cluster for RG3_Change", Subtitle = NULL, PlotType="Bar")
PlotHeight <- grid::convertUnit(Plot_Sized$height, 'cm', valueOnly = TRUE)
PlotWidth <- grid::convertUnit(Plot_Sized$width, 'cm', valueOnly = TRUE)
Plot_Sized %<>%
{ggplot2::ggplot() + ggplot2::annotation_custom(.)} %>%
magrittr::add(ggplot2::theme(panel.background = ggplot2::element_rect(fill = "transparent")))
Plot_Sized_RG3 <- Plot_Sized
#ggplot2::ggsave(filename = "Plot_RG3.svg", plot = Plot_Sized_RG3 , width = PlotWidth, height = PlotHeight, unit="cm")
gridExtra::grid.arrange(Plot_Sized_RG2, Plot_Sized_RG3, ncol=2)
```

```{r, eval=FALSE}
MCA_res_select <- MCA_res %>%
filter(stringr::str_detect(RG2_Significant, "Opposite"))%>%
select("Metabolite")
MetaProViz:::VizSuperplot(InputData =Input_Superplot[,c(1:6)],#We just plot six metabolites
SettingsFile_Sample =MetaData_Sample,
SettingsInfo = c(Conditions="Conditions", Superplot = "Biological_Replicates"),
PlotType = "Bar", #Bar, Box, Violin
PlotConditions = c("HK2", "786-O", "786-M1A", "786-M2A", "OSRC2", "OSLM1B", "RFX631"),#sets the order in which the samples should be plotted
StatComparisons = list(c(1,2),c(1,4)))#Stat comparisons to be included on the plot
```

### ORA on each metabolite cluster
As explained in detail above, Over Representation Analysis (ORA) is a pathway enrichment analysis (PEA) method. As ORA is based on the Fishers exact test it is perfect to test if a set of features (=metabolic pathways) are over-represented in the selection of features (= clusters of metabolites) from the data in comparison to all measured features (all metabolites). In detail, `MC_ORA()` will perform ORA on each of the metabolite clusters using all metabolites as the background.
```{r, echo=FALSE}
Expand All @@ -463,14 +548,11 @@ MC_ORA_result<- MetaProViz::ClusterORA(InputData=MCA_CoRe_res[["MCA_CoRe_Results
minGSSize=3,
maxGSSize=1000 ,
SaveAs_Table= "csv")
#Lets check how the results look like:
Both_UP_Released <- MC_ORA_result[["DF"]][["Both_UP (Released)"]]
```
```{r, echo=FALSE}
# Check how our data looks like:
Both_UP_Released[c(1:3,7),]%>%
kableExtra::kbl(caption ="MetaProViz::MC_ORA results for the RG2_Significant cluster `Both_UP (Released)`.", row.names=FALSE) %>%
MC_ORA_result[["DF"]][["Both_DOWN (Consumed)"]][c(1:3,7),]%>%
kableExtra::kbl(caption ="MetaProViz::MC_ORA results for the RG2_Significant cluster `Both_DOWN (Consumed)`.", row.names=FALSE) %>%
kableExtra::kable_classic(full_width = F, html_font = "Cambria", font_size = 12)
```
\
Expand Down Expand Up @@ -562,8 +644,11 @@ MetaProViz::VizPCA(SettingsInfo= c(color="Status"),
Clustered heatmaps can be useful to understand the patterns in the data, which will be showcased on different examples.\
As input, we need a DF that contains the samples as rownames and the features (=metabolites) as column names:\
```{r}
Input_Heatmap <- Media_Preprocessed[,-c(1:4)] #remove columns that include Metadata such as cell type,...
Input_Heatmap <- Media_Preprocessed[,-c(1:6)] #remove columns that include Metadata such as cell type,...
# Add consumption-release information of each cell type:
MetaData_Metab <- DMA_Annova[["Feature_Metadata"]]%>%
column_to_rownames("Metabolite")
```
```{r, echo=FALSE}
# Check how our data looks like:
Expand All @@ -590,8 +675,9 @@ Moreover, we can also add metabolite metadata information:\
```{r, fig.align="left",fig.width=12, fig.height=14, fig.cap="Colour for metabolite metadata."}
MetaProViz::VizHeatmap(InputData = Input_Heatmap,
SettingsFile_Sample = MetaData_Sample,
SettingsInfo = c(color_Metab = list("Pathway")),
SettingsFile_Metab = MappingInfo,
SettingsInfo = c(color_Metab = list("Pathway", "CoRe_786-M1A", "CoRe_HK2", "CoRe_786-M2A", "CoRe_786-O", "CoRe_OSLM1B", "CoRe_OSRC2", "CoRe_RFX631"),
color_Sample = list("Conditions","Biological_Replicates", "Status")),
SettingsFile_Metab = MetaData_Metab,
PlotName = "Colour Metabolites")
```
\
Expand All @@ -602,7 +688,7 @@ MetaProViz::VizHeatmap(InputData = Input_Heatmap,
SettingsFile_Sample = MetaData_Sample,
SettingsInfo = c(individual_Metab = "Pathway",
color_Sample = list("Conditions","Biological_Replicates"),
color_Metab = list("Pathway")),
color_Metab = list("CoRe_786-M1A", "CoRe_HK2", "CoRe_786-M2A", "CoRe_786-O", "CoRe_OSLM1B", "CoRe_OSRC2", "CoRe_RFX631")),
SettingsFile_Metab = MetaData_Metab,
PlotName = "Pathway")
Expand All @@ -613,7 +699,7 @@ MetaProViz::VizHeatmap(InputData = Input_Heatmap,
SettingsFile_Sample = MetaData_Sample,
SettingsInfo = c(individual_Metab = "Pathway",
color_Sample = list("Conditions","Biological_Replicates"),
color_Metab = list("Pathway")),
color_Metab = list("CoRe_786-M1A", "CoRe_HK2", "CoRe_786-M2A", "CoRe_786-O", "CoRe_OSLM1B", "CoRe_OSRC2", "CoRe_RFX631")),
SettingsFile_Metab = MetaData_Metab,
PlotName = "Pathway")
Expand All @@ -622,6 +708,7 @@ MetaProViz::VizHeatmap(InputData = Input_Heatmap,
\
\
\

You can also choose to make individual plots for any Sample Metadata using `individual_Sample` (e.g. in patients you may want to plot male and female separately). Moreover, you can also use both at the same time.

### Superplots
Expand All @@ -639,7 +726,13 @@ Input_Superplot[,1:7]%>%
We also need the Metadata as we will need to know which conditions to plot for together. If you have further information such as replicates or patient ID, we can use this for the colour of the plotted samples per condition as in the superplots style as described in by Lord et al [@Lord2020]. \
\
```{r, eval=FALSE}
MetaProViz:::VizSuperplot(InputData =Input_Superplot[,c(1:6)],#We just plot six metabolites
#Lets select metabolites to plot
metabolite_list <- MCA_res %>%
filter(stringr::str_detect(RG2_Significant, "Opposite"))%>%
pull(Metabolite)
MetaProViz::VizSuperplot(InputData =Input_Superplot%>% select(any_of(metabolite_list)),#We just plot selected metabolites
SettingsFile_Sample =MetaData_Sample,
SettingsInfo = c(Conditions="Conditions", Superplot = "Biological_Replicates"),
PlotType = "Bar", #Bar, Box, Violin
Expand All @@ -650,7 +743,12 @@ MetaProViz:::VizSuperplot(InputData =Input_Superplot[,c(1:6)],#We just plot six

<div class="vscroll-plot">
```{r, echo=FALSE, warning=FALSE, fig.align="left", fig.width=7, fig.height=5}
MetaProViz:::VizSuperplot(InputData =Input_Superplot[,c(1:6)],#We just plot six metabolites
metabolite_list <- MCA_res %>%
filter(stringr::str_detect(RG2_Significant, "Opposite"))%>%
pull(Metabolite)
MetaProViz::VizSuperplot(InputData =Input_Superplot%>% select(any_of(metabolite_list)),#We just plot selected metabolites
SettingsFile_Sample =MetaData_Sample,
SettingsInfo = c(Conditions="Conditions", Superplot = "Biological_Replicates"),
PlotType = "Bar", #Bar, Box, Violin
Expand Down

0 comments on commit d842fb5

Please sign in to comment.