Skip to content

Instantly share code, notes, and snippets.

@lwaldron
Created July 19, 2025 14:15
Show Gist options
  • Save lwaldron/18d534a462c79d51c3fd0fd8196085f6 to your computer and use it in GitHub Desktop.
Save lwaldron/18d534a462c79d51c3fd0fd8196085f6 to your computer and use it in GitHub Desktop.
Parkinson's curated metagenomic studies.
---
title: "pMDstudies"
author: "Levi Waldron"
date: "`r Sys.Date()`"
output: html_document
---
```{r, message=FALSE, warning=FALSE, echo=FALSE}
library(parkinsonsMetagenomicData)
library(dplyr)
library(gt)
```
```{r, echo=FALSE, warning=FALSE, message=FALSE}
pd <- select(parkinsonsMetagenomicData::sampleMetadata, c("study_name", "BioProject", "target_condition", "body_site", "host_species", "age", "age_unit", "sex"))
study_summary <- pd %>%
group_by(study_name) %>%
summarise(
BioProject = paste(unique(na.omit(BioProject)), collapse = ", "),
host_species = paste(unique(na.omit(host_species)), collapse = ", "),
body_site = paste(unique(na.omit(body_site)), collapse = ", "),
number_of_samples = n(),
age_range = if(all(is.na(age))) NA_character_ else paste(min(age, na.rm = TRUE), max(age, na.rm = TRUE), sep = " - "),
age_unit = paste(unique(na.omit(age_unit)), collapse = ", "),
sex_distribution = paste0(
"M: ", sum(sex == 'Male', na.rm = TRUE), " | ",
"F: ", sum(sex == 'Female', na.rm = TRUE), " | ",
"NA: ", sum(is.na(sex) | sex == "")
),
.groups = 'drop' # Ungroup for subsequent steps
)
gt_table <- study_summary %>%
gt() %>%
tab_header(
title = md("**Study-Level Metadata Summary**"),
subtitle = "A summary of aggregated data for each study"
) %>%
cols_label(
study_name = "Study Name",
BioProject = "NCBI BioProject",
host_species = "Host Species",
body_site = "Body Site",
number_of_samples = "Sample Count",
age_range = "Age Range",
age_unit = "Age Unit",
sex_distribution = "Sex Distribution (M | F | NA)"
) %>%
sub_missing(
columns = everything(),
missing_text = "Not Available"
) %>%
tab_source_note(
source_note = md("Data source: `sampleMetadata`")
) %>%
tab_options(
table.border.top.color = "black",
table.border.top.width = px(3),
column_labels.border.bottom.color = "black",
column_labels.border.bottom.width = px(2),
table_body.hlines.color = "#f2f2f2"
) %>%
cols_align(
align = "center",
columns = number_of_samples
)
gtsave(gt_table, filename = "~/Downloads/pMD_sampleMetadata.html")
```
```{r, results='asis'}
print(gt_table)
```
@lwaldron
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment