## ----include = FALSE----------------------------------------------------------
library(knitr)
knitr::opts_chunk$set(
    collapse = TRUE,
    comment = "#>",
    cache = TRUE
)

## ----install, eval=FALSE------------------------------------------------------
#  BiocManager::install("HoloFoodR")

## ----load_package-------------------------------------------------------------
library(HoloFoodR)

## ----search_animals-----------------------------------------------------------
animals <- doQuery("animals", max.hits = 100)
animals <- animals[ animals[["histological"]], ]

colnames(animals) |> head()

## ----get_animal_data----------------------------------------------------------
animal_data <- getData(
    accession.type = "animals", accession = animals[["accession"]])

## ----get_samples1-------------------------------------------------------------
samples <- animal_data[["samples"]]

colnames(samples) |> head()

## ----get_samples2-------------------------------------------------------------
sample_ids <- unique(samples[["accession"]])

## ----get_mae------------------------------------------------------------------
mae <- getResult(sample_ids)
mae

## ----show_mae-----------------------------------------------------------------
mae[[1]]

## ----search_analyses1, eval = FALSE-------------------------------------------
#  library(MGnifyR)
#  
#  mg <- MgnifyClient(useCache = TRUE)
#  
#  # Get those samples that are metagenomic samples
#  metagenomic_samples <- samples[
#      samples[["sample_type"]] == "metagenomic_assembly", ]
#  
#  # Get analysis IDs based on sample IDs
#  analysis_ids <- searchAnalysis(
#      mg, type = "samples", metagenomic_samples[["accession"]])

## ----search_analyses2, include = FALSE----------------------------------------
path <- system.file("extdata", "analysis_ids.rds", package = "HoloFoodR")
analysis_ids <- readRDS(path)

## ----search_analyses3---------------------------------------------------------
head(analysis_ids)

## ----get_metagenomic_data1, eval = FALSE--------------------------------------
#  mae_metagenomic <- MGnifyR::getResult(mg, analysis_ids)

## ----get_metagenomic_data2, include = FALSE-----------------------------------
path <- system.file("extdata", "mae_metagenomic.rds", package = "HoloFoodR")
mae_metagenomic <- readRDS(path)

## ----get_metagenomic_data3----------------------------------------------------
mae_metagenomic

## ----combine_data, eval = FALSE-----------------------------------------------
#  # Get experiments from metagenomic data
#  exps <- experiments(mae_metagenomic)
#  # Convert analysis names to sample names
#  exps <- lapply(exps, function(x){
#      # Get corresponding sample ID
#      sample_id <- names(analysis_ids)[ match(colnames(x), analysis_ids) ]
#      # Replace analysis ID with sample ID
#      colnames(x) <- sample_id
#      return(x)
#  })
#  
#  # Add to original MultiAssayExperiment
#  mae <- c(experiments(mae), exps)
#  mae

## ----get_metabolomics, eval=FALSE---------------------------------------------
#  # Get untargeted metabolomic samples
#  samples <- doQuery("samples", sample_type = "metabolomic")
#  # Get the data
#  metabolomic <- getMetaboLights(samples[["metabolomics_url"]])
#  
#  # Show names of data.frames
#  names(metabolomic)

## ----session_info-------------------------------------------------------------
sessionInfo()

