Skip to content

Commit

Permalink
Initiate log file at the beginning of exported functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristinaSchmidt1 committed Oct 31, 2024
1 parent 5d1941c commit 94d345c
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 33 deletions.
31 changes: 31 additions & 0 deletions R/DifferentialMetaboliteAnalysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ DMA <-function(InputData,
FolderPath = NULL
){

## ------------ Create log file ----------- ##
MetaProViz_Init()

logger::log_info("DMA: Differential metabolite analysis.")

## ------------ Check Input files ----------- ##
# HelperFunction `CheckInput`
CheckInput(InputData=InputData,
Expand Down Expand Up @@ -363,6 +368,9 @@ Log2FC_fun <-function(InputData,
CoRe,
Transform
){
## ------------ Create log file ----------- ##
MetaProViz_Init()

if("Denominator" %in% names(SettingsInfo)==FALSE & "Numerator" %in% names(SettingsInfo) ==FALSE){
# all-vs-all: Generate all pairwise combinations
conditions = SettingsFile_Sample[[SettingsInfo[["Conditions"]]]]
Expand Down Expand Up @@ -641,6 +649,8 @@ DMA_Stat_single <- function(InputData,
Log2FC_table,
StatPval,
StatPadj){
## ------------ Create log file ----------- ##
MetaProViz_Init()

## ------------ Check Missingness ------------- ##
Num <- InputData %>%#Are sample numbers enough?
Expand Down Expand Up @@ -758,6 +768,9 @@ AOV <-function(InputData,
SettingsInfo,
Log2FC_table){

## ------------ Create log file ----------- ##
MetaProViz_Init()

## ------------ Denominator/numerator ----------- ##
# Denominator and numerator: Define if we compare one_vs_one, one_vs_all or all_vs_all.
if("Denominator" %in% names(SettingsInfo)==FALSE & "Numerator" %in% names(SettingsInfo) ==FALSE){
Expand Down Expand Up @@ -888,6 +901,9 @@ Kruskal <-function(InputData,
StatPadj
){

## ------------ Create log file ----------- ##
MetaProViz_Init()

## ------------ Denominator/numerator ----------- ##
# Denominator and numerator: Define if we compare one_vs_one, one_vs_all or all_vs_all.
if("Denominator" %in% names(SettingsInfo)==FALSE & "Numerator" %in% names(SettingsInfo) ==FALSE){
Expand Down Expand Up @@ -1007,6 +1023,9 @@ Welch <-function(InputData,
SettingsInfo,
Log2FC_table
){
## ------------ Create log file ----------- ##
MetaProViz_Init()

## ------------ Denominator/numerator ----------- ##
# Denominator and numerator: Define if we compare one_vs_one, one_vs_all or all_vs_all.
if("Denominator" %in% names(SettingsInfo)==FALSE & "Numerator" %in% names(SettingsInfo) ==FALSE){
Expand Down Expand Up @@ -1126,6 +1145,9 @@ DMA_Stat_limma <- function(InputData,
CoRe,
Transform){

## ------------ Create log file ----------- ##
MetaProViz_Init()

## ------------ Denominator/numerator ----------- ##
# Denominator and numerator: Define if we compare one_vs_one, one_vs_all or all_vs_all.
if("Denominator" %in% names(SettingsInfo)==FALSE & "Numerator" %in% names(SettingsInfo) ==FALSE){
Expand Down Expand Up @@ -1381,6 +1403,9 @@ Shapiro <-function(InputData,
QQplots=TRUE
){

## ------------ Create log file ----------- ##
MetaProViz_Init()

## ------------ Setup and installs ----------- ##
RequiredPackages <- c("tidyverse", "gtools")
new.packages <- RequiredPackages[!(RequiredPackages %in% installed.packages()[,"Package"])]
Expand Down Expand Up @@ -1614,6 +1639,9 @@ Bartlett <-function(InputData,
SettingsFile_Sample,
SettingsInfo){

## ------------ Create log file ----------- ##
MetaProViz_Init()

## ------------ Setup and installs ----------- ##
RequiredPackages <- c("tidyverse")
new.packages <- RequiredPackages[!(RequiredPackages %in% installed.packages()[,"Package"])]
Expand Down Expand Up @@ -1669,6 +1697,9 @@ Bartlett <-function(InputData,

vst <- function(InputData){

## ------------ Create log file ----------- ##
MetaProViz_Init()

# model the mean and variance relationship on the data
suppressMessages(melted <- reshape2::melt(InputData))
het.data <- melted %>% group_by(variable) %>% # make a dataframe to save the values
Expand Down
30 changes: 16 additions & 14 deletions R/GetPriorKnoweldge.R
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,10 @@ InspectID <- function(Input_DataFrame,
#'
#'
LoadKEGG <- function(){
#Get the package:
RequiredPackages <- c("rappdirs")
new.packages <- RequiredPackages[!(RequiredPackages %in% installed.packages()[,"Package"])]
if(length(new.packages)) install.packages(new.packages)
## ------------ Create log file ----------- ##
MetaProViz_Init()

logger::log_info("Load KEGG.")

#------------------------------------------------------------------
#Get the directory and filepath of cache results of R
Expand Down Expand Up @@ -444,6 +444,9 @@ LoadKEGG <- function(){
#' @export
#'
LoadHallmarks <- function() {
## ------------ Create log file ----------- ##
MetaProViz_Init()

# Read the .csv files
Hallmark <- system.file("data", "Hallmarks.csv", package = "MetaProViz")
Hallmark <- read.csv(Hallmark, check.names=FALSE)
Expand Down Expand Up @@ -474,11 +477,10 @@ Make_GeneMetabSet <- function(Input_GeneSet,
SaveAs_Table = "csv",
FolderPath = NULL){

## ------------ Setup and installs ----------- ##
RequiredPackages <- c("tidyverse","cosmosR")
new.packages <- RequiredPackages[!(RequiredPackages %in% installed.packages()[,"Package"])]
if(length(new.packages)) install.packages(new.packages)
suppressMessages(library(tidyverse))
## ------------ Create log file ----------- ##
MetaProViz_Init()

logger::log_info("Make_GeneMetabSet.")

## ------------ Check Input files ----------- ##
# 1. The input data:
Expand Down Expand Up @@ -586,11 +588,11 @@ LoadMetalinks <- function(types = NULL,
uniprot_ids = NULL,
SaveAs_Table="csv",
FolderPath=NULL){
#------------------------------------------------------------------
#Get the package:
RequiredPackages <- c("rappdirs")
new.packages <- RequiredPackages[!(RequiredPackages %in% installed.packages()[,"Package"])]
if(length(new.packages)) install.packages(new.packages)
## ------------ Create log file ----------- ##
MetaProViz_Init()

logger::log_info("MetaLinksDB.")


#------------------------------------------------------------------
if((any(c(types, cell_location, tissue_location, biospecimen_location, disease, pathway, hmdb_ids, uniprot_ids)=="?"))==FALSE){
Expand Down
3 changes: 1 addition & 2 deletions R/HelperLog.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ MPV_trace <- function() {#MPV=MetaProViz
#'
MetaProViz_Init <- function(){
# Only run the first time a MetaProViz function is used in an environment --> Creates log file
if(!is.null(metaproviz.env$init)){
print("We want to see you!")
if(is.null(metaproviz.env$init)){
#Initial log
OmnipathR:::init_config(pkg = "MetaProViz")
OmnipathR:::init_log(pkg = "MetaProViz")
Expand Down
15 changes: 5 additions & 10 deletions R/MetaDataAnalysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,8 @@ MetaAnalysis <- function(InputData,

){

## ------------ Setup and installs ----------- ##
RequiredPackages <- c("tidyverse")
new.packages <- RequiredPackages[!(RequiredPackages %in% installed.packages()[,"Package"])]
if(length(new.packages)) install.packages(new.packages)
suppressMessages(library(tidyverse))
## ------------ Create log file ----------- ##
MetaProViz_Init()

################################################################################################################################################################################################
## ------------ Check Input files ----------- ##
Expand Down Expand Up @@ -304,11 +301,9 @@ MetaPK <- function(InputData,
SaveAs_Table = "csv",
FolderPath = NULL){

## ------------ Setup and installs ----------- ##
RequiredPackages <- c("tidyverse")
new.packages <- RequiredPackages[!(RequiredPackages %in% installed.packages()[,"Package"])]
if(length(new.packages)) install.packages(new.packages)
suppressMessages(library(tidyverse))
## ------------ Create log file ----------- ##
MetaProViz_Init()


################################################################################################################################################################################################
## ------------ Check Input files ----------- ##
Expand Down
15 changes: 8 additions & 7 deletions R/MetaboliteClusteringAnalysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -438,13 +438,8 @@ MCA_CoRe <- function(InputData_Intra,
FolderPath=NULL
){

## ------------ Setup and installs ----------- ##
RequiredPackages <- c("tidyverse")
new.packages <- RequiredPackages[!(RequiredPackages %in% installed.packages()[,"Package"])]
if(length(new.packages)>0){
install.packages(new.packages)
}
suppressMessages(library(tidyverse))
## ------------ Create log file ----------- ##
MetaProViz_Init()

################################################################################################################################################################################################
## ------------ Check Input files ----------- ##
Expand Down Expand Up @@ -1032,6 +1027,9 @@ MCA_CoRe <- function(InputData_Intra,
#' @export
#'
MCA_rules<- function(Method){
## ------------ Create log file ----------- ##
MetaProViz_Init()

# Read the .csv files
Cond <- system.file("data", "MCA_2Cond.csv", package = "MetaProViz")
Cond<- read.csv( Cond, check.names=FALSE)
Expand Down Expand Up @@ -1089,6 +1087,9 @@ CheckInput_MCA <- function(InputData_C1,
FeatureID,
SaveAs_Table
){
## ------------ Create log file ----------- ##
MetaProViz_Init()

#------------- InputData
if(is.null(InputData_C1)==FALSE){
if(class(InputData_C1) != "data.frame"| class(InputData_C2) != "data.frame"){
Expand Down
8 changes: 8 additions & 0 deletions R/OverRepresentationAnalysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ ClusterORA <- function(InputData,
maxGSSize=1000 ,
SaveAs_Table= "csv",
FolderPath = NULL){
## ------------ Create log file ----------- ##
MetaProViz_Init()


## ------------ Check Input files ----------- ##
Pathways <- CheckInput_ORA(InputData=InputData,
SettingsInfo=SettingsInfo,
Expand Down Expand Up @@ -185,6 +189,10 @@ StandardORA <- function(InputData,
FolderPath = NULL

){
## ------------ Create log file ----------- ##
MetaProViz_Init()


## ------------ Check Input files ----------- ##
Pathways <- CheckInput_ORA(InputData=InputData,
SettingsInfo=SettingsInfo,
Expand Down
6 changes: 6 additions & 0 deletions R/Processing.R
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ ReplicateSum <- function(InputData,
SettingsInfo = c(Conditions="Conditions", Biological_Replicates="Biological_Replicates", Analytical_Replicates="Analytical_Replicates"),
SaveAs_Table = "csv",
FolderPath = NULL){
## ------------ Create log file ----------- ##
MetaProViz_Init()

## ------------------ Check Input ------------------- ##
# HelperFunction `CheckInput`
Expand Down Expand Up @@ -623,6 +625,10 @@ FeatureFiltering <-function(InputData,
CoRe=FALSE,
FeatureFilt="Modified",
FeatureFilt_Value=0.8){
## ------------ Create log file ----------- ##
MetaProViz_Init()


## ------------------ Prepare the data ------------------- ##
feat_filt_data <- as.data.frame(replace(InputData, InputData==0, NA))

Expand Down
3 changes: 3 additions & 0 deletions R/ToyData.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
#' @export
#'
ToyData <- function(Dataset) {
## ------------ Create log file ----------- ##
MetaProViz_Init()

#Available Datasets:
datasets <- list(
IntraCells_Raw = "MS55_RawPeakData.csv",
Expand Down
2 changes: 2 additions & 0 deletions R/VizHeatmap.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ VizHeatmap <- function(InputData,
PrintPlot=TRUE,
FolderPath = NULL
){
## ------------ Create log file ----------- ##
MetaProViz_Init()

## ------------ Check Input files ----------- ##
# HelperFunction `CheckInput`
Expand Down
2 changes: 2 additions & 0 deletions R/VizVolcano.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ VizVolcano <- function(PlotSettings="Standard",
FolderPath = NULL,
Features="Metabolites",
PrintPlot=TRUE){
## ------------ Create log file ----------- ##
MetaProViz_Init()

## ------------ Check Input files ----------- ##
# HelperFunction `CheckInput`
Expand Down

0 comments on commit 94d345c

Please sign in to comment.