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(phylotaR) | |
data("yeasts") | |
# not all info is stored on the seq object | |
str(yeasts@sqs@sqs[[1]]) | |
# but the accession can be used to download extra info | |
accssn <- yeasts@sqs@sqs[[1]]@id | |
library(rentrez) | |
smmry_obj <- entrez_summary(db = 'nucleotide', id = accssn) | |
str(smmry_obj) | |
# e.g. getting country |
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
# Libs ---- | |
# devtools::install_github('ropensci/phylotaR', ref = 'multiple_ids') | |
library(phylotaR) | |
library(taxize) | |
# Txids ---- | |
# look-up random selection of 60 aedes and culex spp | |
# 7158 -- Aedes genus | |
aedes_spp <- downstream(x = '7158', db = 'ncbi', downto = 'species') | |
# 7174 -- Culex genus |
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
# http://genomicsclass.github.io/book/pages/dplyr_tutorial.html | |
# Libs ---- | |
library(dplyr) | |
# Data ---- | |
url <- "https://raw.githubusercontent.com/genomicsclass/dagdata/master/inst/extdata/msleep_ggplot2.csv" | |
filename <- "msleep_ggplot2.csv" | |
if (!file.exists(filename)) downloader::download(url,filename) | |
# forget head! Just make use it is a "tibble" | |
msleep <- as_tibble(read.csv("msleep_ggplot2.csv")) |
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
# Installed | |
already_installed <- installed.packages() | |
# CRAN packages | |
cran_deps <- c("ape", "reshape2", "phangorn", "stringi", "stringr") | |
cran_deps <- cran_deps[!cran_deps %in% already_installed] | |
for (dep in cran_deps) { | |
install.packages(dep) | |
} |
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
# LIBS | |
library(rentrez) | |
# FUNCTIONS | |
connect_safely <- function(fnctn, args, wt_tms) { | |
res <- NULL | |
for (wt_tm in wt_tms) { | |
query <- try(R.utils::withTimeout(do.call(fnctn, args), | |
timeout = 3600), | |
silent = 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
# 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 |
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(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
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
# 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 |
NewerOlder