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
@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]
@zkamvar
zkamvar / find_chromosome_region.py
Created November 1, 2017 21:07
Find chromosome regions for given SSR GenBank IDs
#!/usr/bin/env python3
#
# This script will BLAST a series of GenBank IDs representing SSR sequences from
# Sirjusingh, C., Kohn, L.M., 2001. Characterization of microsatellites in the
# fungal plant pathogen, Sclerotinia sclerotiorum. Molecular Ecology 1, 267e269.
#
# This uses biopython to download the XML, save it to a file in the working
# directory, and then looks for matches that have Sclerotinia chromosome in the
# title and has a score of > 100. If there's a better way to do this, I would
# like to know it. Currently, it can download a few results at a time and then
@zkamvar
zkamvar / silly-emoji-copy.sh
Created October 11, 2017 22:53
silly emoji for bash commands
# shruggie
# Source: https://twitter.com/climagic/status/672862397015658496
function shrug(){ echo -n "¯\_(ツ)_/¯" | pbcopy;echo "¯\_(ツ)_/¯ copied to your clipboard"; }
export -f shrug
# strollie
function stroll(){ echo -n "ᕕ( ᐛ )ᕗ" | pbcopy; echo "ᕕ( ᐛ )ᕗ copied to your clipboard"; }
export -f stroll
# flippy
@zkamvar
zkamvar / purr_mc.R
Created October 4, 2017 15:22
@drob's purrr MC
# This is from @drob on twitter:
#
# https://twitter.com/drob/status/915378838078722048
#
library("purrr")
transition_mc <- function(steps, start, mat){
i <- seq_len(nrow(mat))
transition <- ~ sample(i, prob = (i == .) %*% mat)
accumulate(seq_len(steps), transition, .init = start)
}
@zkamvar
zkamvar / pastena.R
Last active September 14, 2017 16:43
Paste function that replaces NA characters with blanks
#' paste function that replaces NA characters with blanks
#'
#' All arguments are passed to paste.
#'
#' Usage:
#' pastena(letters, sample(c(1:10, NA), 26, replace = TRUE))
pastena <- function(..., collapse = NULL, sep = " ") {
dots <- list(...)
dots <- lapply(dots, function(i) ifelse(is.na(i), "", i))
res <- do.call("paste", c(dots, list(collapse = collapse, sep = sep)))
@zkamvar
zkamvar / gvcf2csv.sh
Created September 8, 2017 20:43
create csv from gvcf
#!/usr/bin/env bash
# This ridiculous script will take in a file as input and spit out comma-separated text for easier parsing.
# Usage:
# $ gvcf2csv.sh GVCF.err | column -t -s,
grep ProgressMeter $1 | \
awk -F" - " '{print $2}' | \
tail -n +2 | \
sed -E 's/[ ]\|[ ]/,/g' | \
sed -E "s/([0-9hmsw%])[ ]{3,}([0-9])/\1,\2/g"
@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
@zkamvar
zkamvar / doi2coi-list.R
Created June 12, 2017 22:29
Conflict of Interest List
# This will take a list of dois and convert them
# to a table containing the names of coauthers to
# populate a conflict of interest list.
#
# It's not perfect, but it's better than nothing.
#
library("rcrossref")
library("tidyverse")
#
# Change these to YOUR dois.
@zkamvar
zkamvar / update_cran_packages.R
Created April 25, 2017 21:00
Script for updating CRAN packages
# Note: this assumes that you have a custom library at the top of your .libPaths()
fields <- c("Package", "LibPath", "Version", "Priority", "Depends", "Imports", "LinkingTo", "Suggests", "Enhances", "OS_type", "Built", "RemoteSha", "Packaged", "biocViews")
x <- installed.packages(.libPaths()[1], fields = fields)
needs_update <- x[x[, "Built"] != "3.4.0", ]
bicond <- !is.na(needs_update[, "biocViews"])
ghub <- !is.na(needs_update[, "RemoteSha"])
remote <- !is.na(needs_update[, "Packaged"])
bioconductor <- needs_update[bicond, ]
cran <- needs_update[!bicond & !ghub & remote, ]
install.packages(rownames(cran))