Skip to content

Instantly share code, notes, and snippets.

Avatar
🐈‍⬛

Zhian N. Kamvar zkamvar

🐈‍⬛
View GitHub Profile
@zkamvar
zkamvar / columncombiner.r
Created Mar 28, 2013
A function that will print out a function for OpenOffice spreadsheet or excel which can be used to concatenate cells with a common separator
View columncombiner.r
################################################################################
# A by-column concatenator for excel through R.
#
# Arguments:
# row - indicate the row you wish to concatenate.
# cell - the first cell containing the information you want to concatenate.
# lastcell - the last cell containing the information you want to concatenate.
#
# Usage: combine_excel(row = 1, cell = "A", lastcell = "D")
#
@zkamvar
zkamvar / getfile.r
Last active Dec 16, 2015
Function from the package [poppr](https://github.com/poppr/poppr) that serves as a wrapper for `file.choose()`, `file.path()`, and `list.files()`. It will allow the user to grab multiple files for import into R with their gui.
View getfile.r
#==============================================================================#
# Usage:
# x <- getfile() # for a single file.
# x <- getfile(multi = TRUE) # for multiple files
# x <- getfile(multi = TRUE, pattern = "^.+?csv$") # grabs all *.csv files.
# setwd(x$path)
# read.csv(x$files)
#==============================================================================#
getfile <- function(multi=FALSE, pattern=NULL, combine=TRUE){
@zkamvar
zkamvar / poppr_stats.r
Last active Dec 18, 2015
Statistics for poppr installations.
View poppr_stats.r
if (!require('devtools')) install.packages('devtools'); require('devtools')
if (!require('data.table')) install.packages('data.table'); require('data.table')
install_github('installr', 'talgalili') # get the latest installr R package
# or run the code from here:
# https://github.com/talgalili/installr/blob/master/R/RStudio_CRAN_data.r
require(installr)
if(!require(ISOcodes)) install.packages("ISOcodes", repos = "http://cran.at.r-project.org"); require(ISOcodes)
@zkamvar
zkamvar / hapmap2df.r
Created Oct 16, 2013
A function for converting hapmap formatted files to data frames for the purpose of importing them into adegenet's genlight object.
View hapmap2df.r
#==============================================================================#
# hapmap2df.r Convert hapmap files to a data frame.
#
# Author: Zhian N. Kamvar
# License: GPLv3
# Year: 2013
# Waranty: NONE
#
# This function will read in hapmap formatted files and convert them to a data
# frame for the purposes of importing them to genlight objects. Example:
@zkamvar
zkamvar / pic.r
Last active Dec 27, 2015
Polymorphic Information Content
View pic.r
pic <- function(gid){
if (gid@type != "PA"){
gid_loc <- seploc(gid)
return(vapply(gid_loc, pic_loc, 1))
}
else{
return(vapply(1:nLoc(gid), function(x) pic_loc(gid[, x]), 1))
}
}
@zkamvar
zkamvar / insert_sep.r
Created Apr 27, 2014
Insert a separator into a character vector containing two pieces of information where one piece has a constant width.
View insert_sep.r
#==============================================================================#
# insert_sep.r Insert a separator into a character vector containing two pieces
# of information where one piece has a constant width.
#
# Author: Zhian N. Kamvar
# License: GPLv3
# Year: 2014
# Waranty: NONE
#
# Arguments:
@zkamvar
zkamvar / lazierLoad.R
Last active Sep 11, 2015
Does a lazy load across all files when provided a knitr cache directory.
View lazierLoad.R
#' Performs lazy load on a directory
#'
#' @param path a filepath containing the necessary files for lazy loading
#' @return NULL
#'
#' @details This function will go into a directory, search for all the files
#' that seem like they can be lazily loaded and attempt to load them.
#'
lazierLoad <- function(path){
files <- dir(path)
View inkscape_pdf_font.pl
#!/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 / my_MLG_table.R
Last active Aug 29, 2015
A function for printing the genotypes in the MLG table from the package "poppr"
View my_MLG_table.R
#==============================================================================#
# Function to print genotypes in the MLG table created from a genind or genclone
# object. This allows for quick identification for small numbers of loci.
#
# Requirements: the R package "poppr"
#
# usage: my.mlg.table(genind_object)
#
# arguments:
# ... arguments passed on to "mlg.table"
@zkamvar
zkamvar / fix_replen.R
Last active Aug 29, 2015
A set of functions to detect potential issues with repeat length specifications for use with Bruvo's distance in poppr
View fix_replen.R
#' Test repeat length consistency.
#'
#' This function will test for consistency in the sense that all alleles are
#' able to be represented as discrete units after division and rounding.
#' @param gid a genind object
#' @param replen a numeric vector of repeat motif lengths.
#' @return a logical vector indicating whether or not the repeat motif length is
#' consistent.
#'
#' @details This function is modified from the version used in