saezlab / MetaProViz

R-package to perform metabolomics pre-processing, differential metabolite analysis, metabolite clustering and custom visualisations.
https://saezlab.github.io/MetaProViz/
GNU General Public License v3.0
10 stars 0 forks source link

Functional analysis: PCA-Metadata analysis #52

Closed ChristinaSchmidt1 closed 1 month ago

ChristinaSchmidt1 commented 1 year ago

Here we can perform PCA analysis (not plotting) and assign metadata such as age, gender,... as being significantly separated on a PC. Next we can extract the metabolites of this PC that are the separators. The output will be a DF that the user can then use further (e.g. for plotting the results).

This is from the VizPCA function, which now does not produce a DF output anymore.

#Prepare output DF
  loading_data <- prcomp(as.matrix(Input_data_m, scale. = as.logical(Scaling)))
  loading_data_table <-as.data.frame(loading_data$rotation)
  loading_data_table <- loading_data_table
  loading_data_table <- tibble::rownames_to_column(loading_data_table, "Metabolite")

  # Save output
  if(OutputPlotName ==""){
    write.csv(loading_data_table, paste(Results_folder_plots_PCA_folder,"/Loadings.csv", sep=""))
  }else{
    write.csv(loading_data_table, paste(Results_folder_plots_PCA_folder,"/", OutputPlotName, "_Loadings.csv", sep=""))
  }

  if (Save_as_Results == "xlsx"){
    if(OutputPlotName ==""){
      xlsPCA <-  paste(Results_folder_plots_PCA_folder,"/Loadings.xlsx", sep="")
      writexl::write_xlsx(loading_data_table,xlsPCA, col_names = TRUE)
    }else{
      xlsPCA <-  paste(Results_folder_plots_PCA_folder,"/", OutputPlotName, "_Loadings.xlsx", sep="")
      writexl::write_xlsx(loading_data_table,xlsPCA, col_names = TRUE)
    }
  }else if (Save_as_Results == "csv"){
    if(OutputPlotName ==""){
      csvPCA <-  paste(Results_folder_plots_PCA_folder,"/Loadings.csv", sep="")
      write.csv(loading_data_table,csvPCA)
    }else{
      csvPCA <-  paste(Results_folder_plots_PCA_folder,"/", OutputPlotName, "_Loadings.csv", sep="")
      write.csv(loading_data_table,csvPCA)
    }
  }else if (Save_as_Results == "txt"){
    if(OutputPlotName ==""){
      txtPCA <-  paste(Results_folder_plots_PCA_folder,"/Loadings.txt", sep="")
      write.csv(loading_data_table,txtPCA)
    }else{
      txtPCA <-  paste(Results_folder_plots_PCA_folder,"/", OutputPlotName, "_Loadings.txt", sep="")
      write.csv(loading_data_table,txtPCA)
    }
  }
ChristinaSchmidt1 commented 1 month ago

Functions and vignette added to latest release v.2.1.0