Skip to content

Instantly share code, notes, and snippets.

View joelnitta's full-sized avatar

Joel Nitta joelnitta

View GitHub Profile
@bomeara
bomeara / distances.R
Last active August 9, 2019 08:08
Solution to @joel_nitta's "Heya phylotweeps! Anybody know of the right model to use for ancestral state reconstruction on a multivariate trait when the parts of the trait must sum to 1? Thinking OU but not sure how to implement it🤔 @Lagomarsino_L @kfeilich @omearabrian"
chunks <- seq(from=0, to=1, length.out=7) # how finely we want to divide each univariate character
# 0.0000000 0.1666667 0.3333333 0.5000000 0.6666667 0.8333333 1.0000000
possible_states <- expand.grid(a=chunks, b=chunks, c=chunks) # all possible combinations (not adding up to 1).
#Doing just three chars here, you can add more: d=chunks, e=chunks....
sums <- apply(possible_states,1, sum)
possible_states <- possible_states[which(abs(sums-1)<0.00001),] # now limiting to those that add up to 1
rownames(possible_states) <- sequence(nrow(possible_states)) - 1 # state 0, 1, 2...
@benmarwick
benmarwick / rotate-axis-labels-ggplot2.R
Last active March 30, 2024 08:00
I can never remember how to rotate the x-axis labels with ggplot2: theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))
# Adapted from https://stackoverflow.com/a/7267364/1036500 by Andrie de Vries
# This is it: theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))
library(ggplot2)
td <- expand.grid(
hjust=c(0, 0.5, 1),
vjust=c(0, 0.5, 1),
angle=c(0, 45, 90),
@mossmatters
mossmatters / transcript2genome_exonerate
Last active April 26, 2017 06:12
Map transcriptome results to genome scaffolds with Exonerate.
#!/usr/bin/env python
import argparse,sys,os,subprocess,shutil,errno
from Bio import SeqIO
helptext='''
This script is intended to use the results of a BLAST search of a transcriptome
against a draft genome to conduct more specific exonerate alignments. Each transcript
is paired with its genome scaffold hit using the BioPython Indexing feature.