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
# R script for splitting grid space | |
# Variables: | |
# obs_lat = vector of observed lats | |
# obs_lon = vector of observed lons | |
# lats = vector of lists for the max and min values of each grid in lat-space | |
# lons = vector of lists for the max and min values of each grid in lon-space | |
# gird = matrix of indexes pointing to the lists in =lats and lons | |
# res = vector of indexes referring to indexes in grid | |
# Steps: |
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
# Libraries | |
library(MoreTreeTools) # package in dev, install via github: https://github.com/DomBennett/MoreTreeTools | |
library(doMC) # use doSNOW if using Windows | |
# find out how many cores you have | |
n <- detectCores() | |
# set-up | |
registerDoMC(cores=n) | |
# example tree | |
tree <- rtree(1000) | |
# find all internal nodes in tree |
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
getGroups <- function(tree) { | |
getCnnctngEdges <- function(edge) { | |
nd <- tree$edge[edge, 1] | |
edge <- which(tree$edge[ ,2] == nd) | |
if(length(edge) > 0) { | |
edge <- c(edge, getCnnctngEdges(edge)) | |
} | |
edge | |
} | |
.fillInEdgeTips <- function(i) { |
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
# PREDICTS AND DPLYR | |
# D. Bennett & L. Graham | |
# BRIEF: | |
# PREDICTS is a large dataset of multiple ecological studies that | |
# have sampled (through counting, trapping, sighting... etc.) a given | |
# taxonomic group. | |
# Each study contains information regarding the number of samples taken, | |
# the taxonomy of the group, the study area etc. | |
# Here we will read in a small example dataset of PREDICTS and demonstrate |
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
# PLOTTING WITH HIGHLIGHTED TIPS | |
# LIB | |
library(ape) | |
# FUNCTIONS FROM MoreTreeTools | |
getEdges <- function (tree, node = NULL, tips = NULL, type = 1) | |
{ | |
if (!is.null(node)) { | |
edges <- c() |
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
# EXAMPLE TEXT DISTANCES | |
# FUNCTIONS | |
justText <- function(txt) { | |
# converts text to its readable form by removing punctuation and numbers | |
gsub("[^a-zA-Z ]", "", txt) | |
} | |
calcStrDst <- function(txts) { | |
# calculate the distance between vector of texts |
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
getGroups <- function(tree, get_edges=TRUE) { | |
.fillInRes <- function(i) { | |
res <- vector('list', length=2) | |
names(res) <- c('g1', 'g2') | |
res[['g1']] <- which(edge.tips[i, ] == 1) | |
res[['g2']] <- which(edge.tips[i, ] == 0) | |
res | |
} | |
.addEdges <- function(i) { | |
res[[i]][['edglngth']] <<- edglngths[[i]] |
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
# LIB | |
library(treeman) | |
library(doMC) | |
library(foreach) | |
# FUNCTION | |
randTreeList <- function(n) { | |
res <- vector(mode='list', length=n) | |
for(i in 1:n) { | |
res[[i]] <- randTree(20, wndmtrx=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
# Take sequences from fasta file and write as separate files | |
# FUNCTION | |
readSqs <- function(fl) { | |
all_data <- readLines(fl) | |
sqs <- list() | |
for(i in seq_along(all_data)) { | |
bit <- all_data[[i]] | |
if(grepl(pattern='^>', x=bit)) { | |
nm <- sub(pattern='^>', '', x=bit) |
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
# LIB | |
library(ape) | |
# DATA | |
# tree string produced by `RAxML -J ` arg | |
trstr <- "(A,B,(C,((D,((E,F):1.0[80],((G,H):1.0[100],(I,J):1.0[100]):1.0[67]):1.0[58]):1.0[98],(K,(L,(M,N):1.0[89]):1.0[91]):1.0[100]):1.0[97]):1.0[97]);" | |
# FAIL | |
tree <- read.tree(text=trstr) | |
# node.label = NULL |
OlderNewer