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
#==============================================================================# | |
# 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: |
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
#==============================================================================# | |
# 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" |
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
#' 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 |
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
#==============================================================================# | |
# 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
# 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 |
OlderNewer