Skip to content

Instantly share code, notes, and snippets.

View padpadpadpad's full-sized avatar
🙃

Daniel Padfield padpadpadpad

🙃
View GitHub Profile
@padpadpadpad
padpadpadpad / pres_abs_creation.R
Created February 2, 2022 14:18
Making a presence absence dataset from only presences
# load necessary packages
library(dplyr)
library(tidyr)
# create sample dataset
am_i_here <- data.frame(time_step = rep(1:5, each = 10)) %>%
group_by(time_step) %>%
mutate(individual = sample(letters, 10)) %>%
ungroup()
# look at gender balance of references
# load packages
library(tidyverse)
library(gender)
# load in dataset
# do some wrangling
d <- read.csv('path_to_refs/reference_list.csv', header = FALSE) %>%
# rename columns
@padpadpadpad
padpadpadpad / scrape_ncbi_assembly_summary.R
Last active January 15, 2021 17:49
scrape the ncbi website to get the summary table for the genome assembly of an organism
# script to grab assembly information from the NCBI website
# I found the XPath of the table I wanted by accessing a NCBI genome page using Google Chrome
# I then clicked View -> Developer -> Inspect elements
# After find where in the html the table was, I right-clicked the code and selected Copy -> Copy XPath
# load in packages ####
library(rvest)
library(tidyverse)
# example genome - Pseudomonas fluorescens SBW25
assembly_accession <- 'GCF_000009225.2'
@padpadpadpad
padpadpadpad / simple-egg-pasta.md
Created August 15, 2020 14:25
Simple yet semi-foolproof egg pasta dough

Description

This is a simple egg pasta recipe that I've been refining over the years of making fresh pasta for my family. It's based on a recipe I picked up while I was a line cook at a family Italian place about 20 years ago that has long since gone out of business; I've put it back together and adjusted it so it scales down as easily as it does up. Originally, this was made in 10kg (20+ pound) batches.

This dough isn't suitable for extruders, it is intended for rolling and cutting. That means you can make pretty much any kind of noodle, or lasagna sheet out of it. If you want to make ravioli or other stuffed pasta, you want to use a recipe with quite a bit more egg in it, and more steps for drying. If you want to make shaped pasta, such as shells, you probably want a durum wheat & water (eggless) dough recipe instead.

Yield

@padpadpadpad
padpadpadpad / samtools_flagstats.R
Last active May 12, 2020 13:25
Collate samtools flagstats into R
#-----------------------------------------#
# analysis of sequencing mapping stats ####
#-----------------------------------------#
# load packages
library(readr)
library(dplyr)
library(purrr)
library(tidyr)
library(stringr)
@padpadpadpad
padpadpadpad / ggplot2_facet_labels_plotmath.R
Last active March 17, 2020 17:29
Example of using plotmath in ggplot2 facet labels
# load in package
library(ggplot2)
data("mpg")
# create a separate column for the letter in the facet
mpg$letter <- letters[as.numeric(as.factor(mpg$class))]
# plot this
ggplot(mpg, aes(cyl, hwy)) +
# load packages
library(flextable)
library(officer)
library(webshot)
library(emmeans)
library(dplyr)
library(tidyr)
# load example data
data(fiber)
# lets do some rolling regression
# load in some packages
library(tidyverse)
library(nlsMicrobio)
library(zoo)
library(broom)
# write a function to do the rolling regression
# this will do an lm then clean up the data. it does not return the r.squared value but this would be easy to do
@padpadpadpad
padpadpadpad / get_all_combs.R
Last active May 14, 2019 12:28
get all combinations of a vector of letters
# vector
x = c('1','2','3')
# i want a vector of all combinations of these strings, but i want to be able to say I want all 2 way or three way combs
# two-way is easy
get_all_combs <- function(x){
return(expand.grid(x,x) %>%
filter(Var1 != Var2) %>%
unite(., 'y', everything(), sep = '') %>%
@padpadpadpad
padpadpadpad / example_contrast_table.R
Created March 25, 2019 12:00
example contrast table using emmeans, gt and html tools.
# load packages
library(gt)
library(htmltools)
library(emmeans)
library(dplyr)
library(tidyr)
# load example data
data(fiber)
?fiber