Skip to content

Instantly share code, notes, and snippets.

View lwaldron's full-sized avatar

Levi Waldron lwaldron

View GitHub Profile
@lwaldron
lwaldron / lefser_pathwayab.R
Last active March 18, 2024 10:34
lefser on pathway abundances using ZellerG_2014 from cMD
suppressPackageStartupMessages({
library(lefser)
library(curatedMetagenomicData)
})
zeller <-
curatedMetagenomicData("ZellerG_2014.pathway_abundance",
counts = TRUE,
dryrun = FALSE)[[1]]
zeller <- zeller[, zeller$study_condition != "adenoma"]
zeller <- relativeAb(zeller)
@lwaldron
lwaldron / metaphlanToPhyloseq.R
Last active March 11, 2024 14:16
Import a table of MetaPhlAn taxonomic abundances into phyloseq
metaphlanToPhyloseq <- function(
metaphlandir,
metadat=NULL,
simplify=TRUE){
## tax is a matrix or data.frame with the table of taxonomic abundances, rows are taxa, columns are samples
## metadat is an optional data.frame of specimen metadata, rows are samples, columns are variables
## if simplify=TRUE, use only the most detailed level of taxa names in the final object
## metaphlanToPhyloseq("~/Downloads/metaphlan_bugs_list")
.getMetaphlanTree <- function(removeGCF=TRUE, simplify=TRUE){
if (!requireNamespace("ape")) {
@lwaldron
lwaldron / gist:edea48dfda3c9db34b80a326f50fc5d1
Last active February 24, 2024 21:23
Select some UniRef IDs from curatedMetagenomicData studies, join, write to file
suppressPackageStartupMessages({
library(curatedMetagenomicData)
library(mia)
library(dplyr)
library(purrr)
})
datasets <- sampleMetadata |>
group_by(study_name) |>
count() |>
@lwaldron
lwaldron / openai_analyzecomments.R
Last active February 14, 2024 13:45
Simple use of openai package for sentiment analysis of written teaching evaluation comments
Before using this script you need to create an OpenAI API key (https://platform.openai.com/api-keys)
and put it in ~/.Renviron:
OPENAI_API_KEY='my_key_here'
# libraries used
library(openai)
library(dplyr)
library(stringr)
@lwaldron
lwaldron / alphadiversity.R
Last active November 13, 2023 02:40
Analyze alpha diversity by year from bugsigdb.org
library(bugsigdbr)
bsdb <- importBugSigDB(version = "devel")
# Create a stacked barplot of the proportion of Pielou, Shannon, Chao1, Simpson, Inverse Simpson, and Richness as a function of year
library(tidyverse)
bsdb_by_year <- bsdb |>
filter(Year > 2014) |>
dplyr::group_by(Year) |>
dplyr::summarize(
Pielou = sum(!is.na(Pielou)) / n(),
@lwaldron
lwaldron / stepwise_treadmill_test.Rmd
Created September 17, 2023 09:34
Analysis of Garmin tcx heart rate data from a stepwise treadmill test to identify lactate threshold
---
title: "Stepwise treadmill test"
author: "Levi Waldron"
date: "`r Sys.Date()`"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
@lwaldron
lwaldron / useProbeInfo.Rnw
Created July 14, 2023 10:02
Rnw vignette from the `annotate` package
% \VignetteIndexEntry{Using Affymetrix Probe Level Data}
% \VignetteDepends{hgu95av2.db, rae230a.db, rae230aprobe, Biostrings}
% \VignetteKeywords{Annotation}
%\VignettePackage{annotate}
\documentclass{article}
\newcommand{\Rfunction}[1]{{\texttt{#1}}}
\newcommand{\Rmethod}[1]{{\texttt{#1}}}
@lwaldron
lwaldron / testlefsercounts
Created July 3, 2023 09:40
Compare lefser output with relab and counts
suppressPackageStartupMessages(library(curatedMetagenomicData))
zeller <- curatedMetagenomicData::curatedMetagenomicData("Zeller.+relative_abundance", counts = FALSE, dryrun = FALSE)[[1]]
zellercounts <- curatedMetagenomicData::curatedMetagenomicData("Zeller.+relative_abundance", counts = TRUE, dryrun = FALSE)[[1]]
zeller <- zeller[, zeller$study_condition != "adenoma"]
zellercounts <- zellercounts[, zellercounts$study_condition != "adenoma"]
suppressPackageStartupMessages(library(lefser))
res_group <- lefser(zeller, groupCol = "study_condition")
res_group_counts <- lefser(zellercounts, groupCol = "study_condition")
@lwaldron
lwaldron / cmdErr.R
Created November 23, 2022 15:26
identify cMD datasets producing error
suppressPackageStartupMessages(library(curatedMetagenomicData))
sampleMetadata[sampleMetadata$study_name == "FengQ_2015", ] |>
returnSamples("relative_abundance", rownames = "NCBI")
allstudies <- unique(sampleMetadata$study_name)
allres <- sapply(allstudies, function(study) {
message(study)
try(
suppressMessages(sampleMetadata[sampleMetadata$study_name == study,] |>
@lwaldron
lwaldron / NYC_CHS20.Rmd
Last active September 14, 2022 12:55
Demo of importing, recoding, creating survey, and logistic regression on CHS20 survey data
---
title: "NYC CHS import"
author: "Levi Waldron"
date: "`r Sys.Date()`"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, message = FALSE)
```