Skip to content

Instantly share code, notes, and snippets.

View zkamvar's full-sized avatar
🍄
On Sabbatical

Zhian N. Kamvar zkamvar

🍄
On Sabbatical
View GitHub Profile
Name this damn pattern.
\binom{N}{0}, \binom{N}{1}, \binom{N}{2}, ..., \binom{N}{floor(N/2)}, ... N!
@zkamvar
zkamvar / mll.representative.R
Last active January 11, 2017 22:58
Replacing multilocus lineages with one representative sample
# Replacing multilocus lineages with one representative sample
library(poppr)
data(monpop)
mlg.filter(monpop) <- 0 + .Machine$double.eps
mondf <- genind2df(monpop, usepop = FALSE)
mid <- mlg.id(monpop)
orders <- unlist(mid, use.names = FALSE)
monpop <- monpop[orders, ]
mondif <- mondf[orders, ]
n <- vapply(mid, length, integer(1))
@zkamvar
zkamvar / mod_poppr_plot_phylo.R
Created January 10, 2017 21:33
Modify default aboot plotting function in R
# poppr.plot.phylo definition:
# https://github.com/grunwaldlab/poppr/blob/9170398f6552f27ab69b294172c97c8ee7a97ce0/R/internal.r#L1529-L1545
# You can also get it by simply typing poppr:::poppr.plot.phylo in your R console
library("ape")
library("phangorn")
poppr.plot.phylo <- function(tree, type = "nj", root = FALSE){
barlen <- min(median(tree$edge.length), 0.1)
if (barlen < 0.1) barlen <- 0.01
if (!root && type != "upgma"){
tree <- ladderize(tree)
@zkamvar
zkamvar / znk_dissertation_wordcloud.R
Last active January 5, 2024 16:26
Generate a wordcloud from my dissertation
library('rjson')
library('wordcloud')
library('viridis')
library('magrittr')
library('purrr')
library('svglite')
# Download JSON data ------------------------------------------------------
@zkamvar
zkamvar / poppr_downloads.R
Last active August 23, 2018 09:33
Plotting the cumulative number of downloads for poppr over time
library('cranlogs')
library('ggplot2')
library('ggthemes')
library('lubridate')
library('dplyr')
releases <- tibble::tribble(
~version, ~date, ~size,
"1.0.0", lubridate::ymd("2013-04-26"), "2.5M",
"1.0.1", lubridate::ymd("2013-07-03"), "2.5M",
@zkamvar
zkamvar / poppr-ds.R
Last active July 20, 2016 23:36
Diversity Stats Plot Without Boxplots
library("poppr")
library("dplyr")
library("tidyr")
library("ggplot2")
library("reshape2")
data(Pinf)
x <- diversity_ci(Pinf, n = 100L)
CI <- melt(x[[3]]) %>% spread(CI, value) %>% rename(lb = `2.5 %`, ub = `97.5 %`)
obs <- melt(x[[1]]) %>% rename(observed = value)
@zkamvar
zkamvar / gs_infuser_dossier.md
Last active January 11, 2016 01:13
Using googlesheets and infuser to create dossiers

Motivation

This is an example of how to use google sheets and infuser to create dossiers from the output of googlesheets surveys. This method is used in https://github.com/zkamvar/InspirationDisseminationSchedule.

Notes:

  • if you are accessing a private spreadsheet, set lookup = TRUE to authenticate yourself
  • I am renaming the column "long description" to "Desc" to show how you can rename columns with non-R-friendly characters
  • You can print these to a file with the "file" argument of cat()
@zkamvar
zkamvar / bibliography.bib
Created January 5, 2016 03:30
MWE for pandoc-citeproc 0.9
@misc{ref1,
author = {AuthorA},
title = {Title of a web resource},
howpublished = {\url{http://url/of/resource/}},
year = {2007}
}
@article{ref2,
author = {AuthorC},
journal = {Journal name},
We can't make this file beautiful and searchable because it's too large.
"INRA63.167","INRA63.171","INRA63.173","INRA63.175","INRA63.177","INRA63.179","INRA63.181","INRA63.183","INRA63.185","INRA5.137","INRA5.139","INRA5.141","INRA5.143","INRA5.145","INRA5.147","INRA5.149","ETH225.137","ETH225.139","ETH225.141","ETH225.143","ETH225.145","ETH225.147","ETH225.149","ETH225.151","ETH225.153","ETH225.155","ETH225.157","ETH225.159","ILSTS5.182","ILSTS5.184","ILSTS5.186","ILSTS5.190","ILSTS5.194","HEL5.149","HEL5.151","HEL5.153","HEL5.155","HEL5.157","HEL5.159","HEL5.161","HEL5.163","HEL5.165","HEL5.167","HEL5.169","HEL1.101","HEL1.103","HEL1.105","HEL1.107","HEL1.109","HEL1.111","HEL1.113","HEL1.115","HEL1.117","INRA35.102","INRA35.104","INRA35.106","INRA35.108","INRA35.110","INRA35.114","INRA35.120","ETH152.181","ETH152.187","ETH152.191","ETH152.193","ETH152.195","ETH152.197","ETH152.199","ETH152.201","ETH152.203","ETH152.205","ETH152.207","ETH152.209","INRA23.193","INRA23.197","INRA23.199","INRA23.201","INRA23.203","INRA23.205","INRA23.207","INRA23.209","INRA23.211","INRA23.213","INRA
@zkamvar
zkamvar / update_fork_git2r.R
Created December 6, 2015 18:56
Script for keeping a fork up to date with git2r
# 2015-12-06 10:55:45 PST ----------------------------------
# This script will allow you to update your fork of the
# NESCent popgenInfo page without having to interact with
# the command line. Note: you do not need to install git
# for this particular script to work, but it is necessary
# to use pull/commit/push through Rstudio.
library("git2r")
# Do this once and then open the Rproject file ------------
# clone(url = "",