Skip to content

Instantly share code, notes, and snippets.

View cromanpa94's full-sized avatar
:octocat:
Working on `autogradeR` and `phruta`

Cristian Román Palacios cromanpa94

:octocat:
Working on `autogradeR` and `phruta`
View GitHub Profile
@cromanpa94
cromanpa94 / polygonizer_mac.R
Last active August 19, 2019 22:06 — forked from johnbaums/polygonizer.R
Convert raster data to a ESRI polygon shapefile and (optionally) a SpatialPolygonsDataFrame
polygonizer <- function(x, outshape=NULL, pypath=NULL, readpoly=TRUE,
fillholes=FALSE, aggregate=FALSE,
quietish=TRUE) {
# x: an R Raster layer, or the file path to a raster file recognised by GDAL
# outshape: the path to the output shapefile (if NULL, a temporary file will
# be created)
# pypath: the path to gdal_polygonize.py or OSGeo4W.bat (if NULL, the function
# will attempt to determine the location)
# readpoly: should the polygon shapefile be read back into R, and returned by
# this function? (logical)
@cromanpa94
cromanpa94 / patchify_polygonize_linux.r
Last active January 28, 2020 01:47
Patchify and Polygonize for Linux (when python is installed using anaconda)
##Not my functions but slighly mod for my use
patchify2<-function(x, distance, p4s, givedist=TRUE) {
# x: a binary Raster layer (0 or NA for background, and 1 for areas to be clumped)
# distance: the neighbourhood distance. Patches that occur within this distance of
# one another will be clumped. This should be in the units of the CRS given
# in p4s. If this is zero, the function will identify patches defined by
# 8-connectivity (i.e. queen's case).
# p4s: an equal-area projection appropriate for the region. This will be used when
@cromanpa94
cromanpa94 / missings_jags.R
Created August 7, 2020 15:59 — forked from richarddmorey/missings_jags.R
Using JAGS to sample missing values in both DVs and IVs in Bayesian regression
set.seed(123) # make reproducible
M = 10000 # Number of posterior samples
N = 20
# sample the IV
x = rnorm(N, 10, 5)
# regression model for DVs
y = 100 + 3*x + rnorm(N,0,10)
## Delete missing data (3 in each)
@cromanpa94
cromanpa94 / example.R
Created August 10, 2020 15:57 — forked from dgrapov/example.R
Example of a shiny app with data upload and different plot options
#initialize
library(shiny)
library(ggplot2)
library(purrr)
library(dplyr)
#example data
data(iris)
@cromanpa94
cromanpa94 / Read_NewickNexusPhylogenies
Created May 26, 2021 15:48
This scripts helps to read phylogenetic trees in newick or nexus automatically
library(phytools)
# fullNew = path to tree files
trees<-lapply(seq_along(fullNew), function(x){
cat(x,'_',fullNew[x], '\n')
k<-grep('#NEXUS', readLines(fullNew[x]))
@cromanpa94
cromanpa94 / TreeToConstraints.R
Created July 27, 2021 16:45
TreeToConstraints.R
#Fasttree tree constraint in R
#http://www.microbesonline.org/fasttree/constrained.html
#Packages
library(ape)
library(phylobase)
library(adephylo)
library(bio3d)
library(pbapply)
annotate_rainbow_letters<-function(ggbasePlot, string, initialx, y, letterDistance,
wordDistance,uppcaseadditionalDistance){
spup<-strsplit(string, split = "")[[1]]
uppLett<-grepl("^[[:upper:]]+$", spup)
dostanceVector<-ifelse(spup == " ", wordDistance, letterDistance)
if(any(uppLett)){
for(i in 1:length(which(uppLett))){
Instructions from Brian (https://github.com/bomeara/phydocker/blob/master/Dockerfile)
cd /usr/local/
sudo mkdir pathd8download
cd pathd8download
sudo wget http://www2.math.su.se/PATHd8/PATHd8.zip
sudo unzip PATHd8.zip
sudo cc PATHd8.c -O3 -lm -o PATHd8
sudo cp PATHd8 /usr/local/bin/PATHd8
@cromanpa94
cromanpa94 / constrainttree
Created August 2, 2021 15:49
Generate a constraint tree based on taxonomy
library(taxize)
library(ape)
gen<-unique(unlist(lapply(strsplit(GenBank_Accession_Table$Taxon,' '), function(x)x[[1]][1])))
taxonomy<-do.call(rbind,pblapply(gen, function(x){
tryCatch({
tax_name(query = x, get = c('family',"superfamily"), db = "ncbi")
}, error=function(e){})