Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development into main #89

Merged
merged 11 commits into from
Jan 14, 2025
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
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 2.1.3
current_version = 2.1.4
commit = True
tag = True
files = DESCRIPTION README.md README.Rmd
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: MetaProViz
Type: Package
Title: METabolomics pre-PRocessing, functiOnal analysis and VIZualisation
Version: 2.1.3
Version: 2.1.4
Authors@R: c(
person("Christina", "Schmidt", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0002-3867-0881")),
Expand Down
11 changes: 2 additions & 9 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Generated by roxygen2: do not edit by hand

export(AddInfo)
export(CleanMapping)
export(ClusterORA)
export(DMA)
export(LoadGaude)
export(LoadHallmarks)
export(LoadKEGG)
export(LoadMetalinks)
export(LoadRAMP)
export(MCA_2Cond)
export(MCA_CoRe)
export(MCA_rules)
Expand All @@ -27,11 +27,6 @@ export(VizHeatmap)
export(VizPCA)
export(VizSuperplot)
export(VizVolcano)
importFrom(magrittr,"%>%")
importFrom(magrittr,extract2)
importFrom(readr,cols)
importFrom(readr,read_csv)
importFrom(tibble,column_to_rownames)
export(metaproviz_config_path)
export(metaproviz_load_config)
export(metaproviz_reset_config)
Expand Down Expand Up @@ -170,8 +165,6 @@ importFrom(tidyr,replace_na)
importFrom(tidyr,separate)
importFrom(tidyr,separate_rows)
importFrom(tidyr,unite)
importFrom(tidyselect,everything)
importFrom(tidyselect,starts_with)
importFrom(tidyselect,all_of)
importFrom(utils,combn)
importFrom(utils,head)
Expand Down
126 changes: 115 additions & 11 deletions R/GetPriorKnoweldge.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,6 @@ LoadKEGG <- function(){
KEGG_Metabolite <- readRDS(File_path)
message("Cached file loaded from: ", File_path)
}else{# load from KEGG
RequiredPackages <- c("KEGGREST", "tidyverse")
new.packages <- RequiredPackages[!(RequiredPackages %in% installed.packages()[,"Package"])]
if(length(new.packages)) install.packages(new.packages)

suppressMessages(library(KEGGREST))
suppressMessages(library(tidyverse))

#--------------------------------------------------------------------------------------------
# 1. Make a list of all available human pathways in KEGG
Pathways_H <- as.data.frame(keggList("pathway", "hsa")) # hsa = human

Expand Down Expand Up @@ -126,10 +118,10 @@ LoadKEGG <- function(){
### ### ### Load Hallmark prior knowledge ### ### ###
##########################################################################################
#'
#' @title Toy Data Import
#' @description Import and process .csv file to create toy data.
#' @title Prior Knowledge Import
#' @description Import and process .csv file to create Prior Knowledge.
#' @importFrom utils read.csv
#' @return A data frame containing the toy data.
#' @return A data frame containing the Prior Knowledge.
#' @export
#'
LoadHallmarks <- function() {
Expand All @@ -144,6 +136,118 @@ LoadHallmarks <- function() {
assign("Hallmark_Pathways", Hallmark, envir=.GlobalEnv)
}

##########################################################################################
### ### ### Load Gaude Metabolic Signature prior knowledge ### ### ###
##########################################################################################
#'
#' @title Prior Knowledge Import
#' @description Import and process .csv file to create Prior Knowledge.
#' @importFrom utils read.csv
#' @return A data frame containing the Prior Knowledge.
#' @export
#'
LoadGaude <- function() {
## ------------ Create log file ----------- ##
MetaProViz_Init()

# Read the .csv files
MetabolicSig <- system.file("data", "Compilled_MetabolicSig_2025-01-07.csv", package = "MetaProViz")
MetabolicSig <- read.csv(MetabolicSig, check.names=FALSE)

# Return into environment
assign("Gaude_Pathways", MetabolicSig, envir=.GlobalEnv)
}

##########################################################################################
### ### ### Load RaMP prior knowledge ### ### ###
##########################################################################################
#'
#' @title Prior Knowledge Import
#' @param version \emph{Optional: } Version of the RaMP database loaded from OmniPathR. \strong{default: "2.5.4"}
#' @param SaveAs_Table \emph{Optional: } File types for the analysis results are: "csv", "xlsx", "txt". \strong{Default = "csv"}
#' @param FolderPath {Optional:} String which is added to the resulting folder name \strong{default: NULL}

#' @description Import and process file to create Prior Knowledge.
#'
#' @importFrom OmnipathR ramp_table
#' @importFrom rappdirs user_cache_dir
#' @importFrom dplyr filter select group_by summarise mutate
#' @importFrom stringr str_remove
#'
#' @return A data frame containing the Prior Knowledge.
#'
#' @examples
#' ChemicalClass <- MetaProViz::LoadRAMP()
#'
#' @export
#'
LoadRAMP <- function(version = "2.5.4",
SaveAs_Table="csv",
FolderPath=NULL){
## ------------ Create log file ----------- ##
MetaProViz_Init()

## ------------ Folder ----------- ##
if(is.null(SaveAs_Table)==FALSE){
Folder <- SavePath(FolderName= "PriorKnowledge",
FolderPath=FolderPath)

SubFolder <- file.path(Folder, "MetaboliteSet")
if (!dir.exists(SubFolder)) {dir.create(SubFolder)}
}


######################################################
#Get the directory and filepath of cache results of R
directory <- rappdirs::user_cache_dir()#get chache directory
File_path <-paste(directory, "/RaMP-ChemicalClass_Metabolite.rds", sep="")

if(file.exists(File_path)==TRUE){# First we will check the users chache directory and weather there are rds files with KEGG_pathways already:
HMDB_ChemicalClass <- readRDS(File_path)
message("Cached file loaded from: ", File_path)
}else{# load from OmniPath
# Get RaMP via OmnipathR and extract ClassyFire classes
Structure <- OmnipathR::ramp_table( "metabolite_class" , version = version)
Class <- OmnipathR::ramp_table( "chem_props" , version = version)

HMDB_ChemicalClass <- merge(Structure, Class[,c(1:3,10)], by="ramp_id", all.x=TRUE)%>%
dplyr::filter(stringr::str_starts(class_source_id, "hmdb:"))%>% # Select HMDB only!
dplyr::filter(stringr::str_starts(chem_source_id, "hmdb:"))%>% # Select HMDB only!
dplyr::select(-c("chem_data_source", "chem_source_id"))%>%
tidyr::pivot_wider(
names_from = class_level_name, # Use class_level_name as the new column names
values_from = class_name, # Use class_name as the values for the new columns
values_fn = list(class_name = ~paste(unique(.), collapse = ", ")) # Combine duplicate values
)%>%
dplyr::group_by(across(-common_name))%>%
dplyr::summarise(
common_name = paste(unique(common_name), collapse = "; "), # Combine all common names into one
.groups = "drop" # Ungroup after summarising
)%>%
dplyr::mutate(class_source_id = stringr::str_remove(class_source_id, "^hmdb:"))%>% # Remove 'hmdb:' prefix
dplyr::select(class_source_id, common_name, ClassyFire_class, ClassyFire_super_class, ClassyFire_sub_class) # Reorder columns

#Save the results as an RDS file in the Cache directory of R
if(!dir.exists(directory)) {dir.create(directory)}
saveRDS(HMDB_ChemicalClass, file = paste(directory, "/RaMP-ChemicalClass_Metabolite.rds", sep=""))

}

##-------------- Save and return
DF_List <- list("ChemicalClass_MetabSet"=HMDB_ChemicalClass)
suppressMessages(suppressWarnings(
SaveRes(InputList_DF= DF_List,#This needs to be a list, also for single comparisons
InputList_Plot= NULL,
SaveAs_Table=SaveAs_Table,
SaveAs_Plot=NULL,
FolderPath= SubFolder,
FileName= "ChemicalClass",
CoRe=FALSE,
PrintPlot=FALSE)))

# Return into environment
assign("ChemicalClass_MetabSet", HMDB_ChemicalClass, envir=.GlobalEnv)
}


##########################################################################################
Expand Down
6 changes: 5 additions & 1 deletion R/ToyData.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,16 @@
#' \item{\code{"Tissue_DMA"}: }
#' \item{\code{"Tissue_DMA_Old"}: }
#' \item{\code{"Tissue_DMA_Young"}: }
#' \item{\code{"Tissue_TvN_Proteomics"}: }
#' \item{\code{"Tissue_TvN_RNAseq"}: }
#' }
#'
#' @return A data frame containing the toy data.
#'
#' @description Import and process .csv file to create toy data DF.
#'
#' @examples
#' Intra <- ToyData("IntraCells_Raw")
#' Intra <- MetaProViz::ToyData("IntraCells_Raw")
#'
#' @importFrom readr read_csv cols
#' @importFrom magrittr %>% extract2
Expand All @@ -66,6 +68,8 @@ ToyData <- function(Dataset) {
Tissue_DMA = "Hakimi_ccRCC-Tissue_DMA_TvsN.csv",
Tissue_DMA_Old ="Hakimi_ccRCC-Tissue_DMA_TvsN-Old.csv",
Tissue_DMA_Young ="Hakimi_ccRCC-Tissue_DMA_TvsN-Young.csv",
Tissue_TvN_Proteomics ="ccRCC-Tissue_TvN_Proteomics.csv",
Tissue_TvN_RNAseq = "ccRCC-Tissue_TvN_RNAseq.csv",
AlaninePathways = "AlaninePathways.csv"
)

Expand Down
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ GNU GENERAL PUBLIC LICENSE, Version 3, 29 June 2007
title = {MetaProViz: METabolomics pre-PRocessing, functiOnal analysis and VIZualisation},
author = {Christina Schmidt, Dimitrios Prymidis, Macabe Daley, Denes Turei, Julio Saez-Rodriguez and Christian Frezza},
year = {2023},
note = {R package version 2.1.3},
note = {R package version 2.1.4},
}
```

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,5 +160,5 @@ GNU GENERAL PUBLIC LICENSE, Version 3, 29 June 2007
title = {MetaProViz: METabolomics pre-PRocessing, functiOnal analysis and VIZualisation},
author = {Christina Schmidt, Dimitrios Prymidis, Macabe Daley, Denes Turei, Julio Saez-Rodriguez and Christian Frezza},
year = {2023},
note = {R package version 2.1.3},
note = {R package version 2.1.4},
}
Loading
Loading