This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#==============================================================================# | |
#' INSTALLATION | |
#' | |
#' devtools::source_gist("3c3f12926de648431937") | |
#==============================================================================# | |
# | |
# | |
#==============================================================================# | |
#' Adds tip colors to tiplabels of an object of class "phylo" | |
#' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' Subset loci in a genind object by name | |
#' | |
#' @param dat a genind object | |
#' @param ... names of the loci in character format OR numeric indices of the loci. | |
#' | |
#' @return the appropriate names to use for subsetting in a genind object | |
#' @examples | |
#' library(adegenet) | |
#' data(nancycats) | |
#' # Old way: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#==============================================================================# | |
# UPDATED: 2015-07-17 | |
# | |
# USAGE/INSTALLATION: | |
# with devtools - devtools::source_gist("b64078a0d04d2452c905") | |
# downloaded - source("poppr_patches.R") | |
# | |
# UPDATES: | |
# Fix read.genalex ( see: https://github.com/grunwaldlab/poppr/issues/58 ) | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#==============================================================================# | |
# Visualize the population hierarchy of a genclone object. | |
# | |
# Packages needed (install beforehand): | |
library(poppr) | |
library(treemap) | |
#==============================================================================# | |
# Main function | |
# | |
# Inputs: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ============================================================================ # | |
# Quickly find the parameter that maximizes a likelihood function. | |
# | |
# This recursive function will take a range of n parameters within an interval | |
# and re-adjust the interval to border the maximum value and recursively call | |
# the function. Once the difference between the maximum value found and the | |
# previous maximum value is less than the error term, the parameter value is | |
# returned. This is faster than the brute force method as the range is reduced | |
# every time the function is recursed. | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Two functions to plot phylo objects from ape. | |
# | |
# Both of these functions plot their respective trees. The ... gives the user | |
# the ability to adjust things like color or font size. | |
# | |
nj_plot_phylo <- function(tree, ...){ | |
barlen <- min(median(tree$edge.length), 0.1) | |
if (barlen < 0.1) barlen <- 0.01 | |
tree <- ladderize(tree) | |
plot.phylo(tree, font = 2, adj = 0, xpd = TRUE, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
datasets <- vapply(strsplit(dir("data"), "\\."), "[", character(1), 1) | |
data_replacer <- function(x){ | |
# manipulate your data here | |
y <- old2new_genind(x, new(class(x))) | |
if ("genclone" %in% class(x)){ | |
y@mlg <- x@mlg | |
} | |
return(y) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library("stringr") | |
library("adegenet") | |
stopifnot(packageVersion("adegenet") >= 2) | |
generate_polyploid_data <- function(nind = 10, nloc = 2, maxploid = 4, sep = "/", genind = TRUE){ | |
locnames <- paste("locus", seq(nloc), sep = "_") | |
indnames <- paste("sample", seq(nind), sep = "_") | |
res <- lapply(seq(nloc), generate_locus, nind, maxploid, sep) | |
names(res) <- locnames |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# | |
# | |
# | |
# | |
# | |
# | |
# | |
# THIS IS NOW LOCATED AT https://raw.githubusercontent.com/zkamvar/config-files/master/.bash_prompt | |
# |