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
# test file
sample_chunk <- "
```{r hello, testing=as.logical(1), another=1 + 1}
x <- 1 + 1 # this evaluates to two
```
the value of x is `r x`"
file = "sample.Rmd"
writeLines(sample_chunk, con = file)
# delete temp Rmd file
on.exit(unlink(file))
@zkamvar
zkamvar / Makefile
Last active March 18, 2020 15:15
Example SLURM script that records memory, time, and job id
FILES := file1.out \
file2.out \
file3.out \
file4.out \
file5.out \
file6.out \
file7.out \
file8.out \
file9.out
#!/usr/bin/perl
#
# This script was created because I had a problem with inkscape not recognizing
# fonts generated by R's pdf generator. This will go through and make these fonts
# scaleable.
#
# Workflow: Generate PDF > open in inkscape > save as svg > run this script
#
# Usage: perl -i inkscape_pdf_font.pl <my_file.svg>
#
@zkamvar
zkamvar / git_prompt.sh
Last active June 17, 2019 09:42
Command prompt functions to go in .bashrc or .bash_profile that will color the command line if there is a git repository.
#
#
#
#
#
#
#
#
# THIS IS NOW LOCATED AT https://raw.githubusercontent.com/zkamvar/config-files/master/.bash_prompt
#
@zkamvar
zkamvar / render-demo.R
Last active August 23, 2018 13:33
Render an R demo
#!/usr/bin/env Rscript
args <- commandArgs(trailingOnly = TRUE)
if (length(args) != 2) {
msg <- "
usage:
render-demo.R <demo> <package>
This utility will render the code and figures from a given package as a PDF
and place them into a directory called `<demo>-generated_files`. This requires
knitr, rmarkdown and LaTeX to be installed on your system.
@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 / bootstrap-genet-dist.md
Last active August 21, 2018 09:55
Generating a bootstrap dendrogram with hierfstat's genet.dist
title author date
Generating a bootstrap dendrogram with hierfstat's genet.dist
Zhian N. Kamvar
2018-08-21

This short tutorial is an answer to the question posed on the poppr forum: https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg/poppr/vEQ8vb2oObQ/RjTsndaCEQAJ

My ultimate goal when asking the previous question was to employ aboot in order to create a bootstraped dendrogram based on distances offered by the genet.dist function in hierfstat. That's why I was trying to create a tree based on Nei's distance this way - to verify that it worked! Unfortunately even after reading the aboot documentation, I still fail to understand how to do this. I would be grateful if someone could provide an example of using aboot in combination with genet.dist.

@zkamvar
zkamvar / gen2polysat.R
Last active February 12, 2018 20:49
Convert a genind object to a genambig object from polsay
gen2polysat <- function(gen, newploidy = gen@ploidy){
if (!require(polysat)){
stop("User needs polysat installed")
}
gen <- recode_polyploids(gen, newploidy)
gendf <- genind2df(gen, sep = "/", usepop = FALSE)
gendf <- lapply(gendf, strsplit, "/")
gendf <- lapply(gendf, lapply, as.numeric)
ambig <- new("genambig", samples = indNames(gen), loci = locNames(gen))
for (i in names(gendf)){
@zkamvar
zkamvar / guide_generator.R
Created January 5, 2018 20:13
Generate guides for making a poster in inkscape
#' Get the size of a single panel
#'
#' @param n the number of panels
#' @param len the overall length of the side
#' @param margin the outer margin width (will be multiplied by 2)
#' @param gutter the space between panels
#'
#' @return a numeric value specifying the panel width/length
#'
#' @examples
@zkamvar
zkamvar / statphi.R
Last active December 18, 2017 17:46
Get Phi statistics from amova object from either pegas or ade4
ade4phi <- function(sig){
n <- length(sig)
f <- rep(0, n - 1)
if (length(sig) == 3) {
f <- rep(0, 1)
}
f[1] <- (sig[n] - sig[n - 1]) / sig[n]
if (length(f) > 1) {
s1 <- cumsum(sig[(n - 1):2])[-1]