Skip to content

Instantly share code, notes, and snippets.

# Hello, and welcome to makefile basics.
#
# You will learn why `make` is so great, and why, despite its "weird" syntax,
# it is actually a highly expressive, efficient, and powerful way to build
# programs.
#
# Once you're done here, go to
# http://www.gnu.org/software/make/manual/make.html
# to learn SOOOO much more.
wget -O /tmp/YaHei.Consolas.1.12.zip https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/uigroupcode/YaHei.Consolas.1.12.zip
unzip /tmp/YaHei.Consolas.1.12.zip
sudo mkdir -p /usr/share/fonts/consolas
sudo mv YaHei.Consolas.1.12.ttf /usr/share/fonts/consolas/
sudo chmod 644 /usr/share/fonts/consolas/YaHei.Consolas.1.12.ttf
cd /usr/share/fonts/consolas
sudo mkfontscale && sudo mkfontdir && sudo fc-cache -fv
@johnatasjmo
johnatasjmo / source_files_from_folder.R
Created January 20, 2018 16:44
R - Source all files within folder
setwd("~/rProgramming")
files.sources = list.files()
sapply(files.sources, source)
@josephwb
josephwb / get_mrca_fast.R
Last active August 26, 2020 13:52
Faster tree MRCA calculator in R (alt to APE's getMRCA)
## written by:
# Joseph W. Brown (josephwb, @j0sephwb)
# Klaus Schliep (KlausVigo, @Klaus_Schlp)
get_mrca_fast <- function(phy, tip) {
if (!inherits(phy, "phylo")) {
stop('object "phy" is not of class "phylo"');
}
if (length(tip) < 2) {
return(NULL);
}
@josephwb
josephwb / getlineSafe
Created June 4, 2014 15:53
C++ getline for when line endings are unknown
// g++ -Wall getlineSafe.cpp -o getlineSafe -O
#include <string.h>
#include <iostream>
#include <fstream>
#include <cstdlib>
std::istream& getlineSafe(std::istream& is, std::string& t) {
t.clear();
@josephwb
josephwb / subtree.induced.R
Created April 13, 2018 10:43
(R) From a larger tree, extract the subtree induced from a specified set of tips. Requires ape.
# extract subtree induced from a set of tips
subtree.induced <- function (phy, tip) {
if (!inherits(phy, "phylo")) {
stop("object \"phy\" is not of class \"phylo\"");
}
Ntip <- length(phy$tip.label);
# convert to indices if strings passed in
if (is.character(tip)) {
idx <- match(tip, phy$tip.label);
@josephwb
josephwb / check_genus_monophyly.R
Last active August 26, 2020 13:48
Check the monophyletic status of every genus in a tree
require(phangorn);
# check the monophyletic status of every genus in the tree `phy`
check_genus_monophyly <- function (phy) {
# get genera. assumes form: Genus_species_whatever
gens <- sort(unique(sub("_.*", "", phy$tip.label)));
n <- length(gens);
cat("Checking ", n, " genera for monophyly status.\n", sep="");
# the number of descendant tips of the MRCA. preallocate for monotypic genera
ndec <- rep(1, n);
@josephwb
josephwb / find_large_files.sh
Created June 7, 2018 09:10
Recursively find large files
#!/bin/bash
# report files greater than some size (default 100 MB)
# does so recursively starting at some dir (default pwd)
# to make executable, do:
# chmod +x find_large_files.sh
print_help () {
echo "Recursively find all files larger than some size"
@roblanf
roblanf / speciesplot
Last active October 24, 2018 16:04
Make a speciesplot in R
# Create a scatterplot with any species as the data points.
# To choose your species, go here: http://phylopic.org/ , then enter the name of the spp you want. Click on the image and click 'thumbnail', click on the picture, and then copy the link in the address bar of your browser. It should end with 'thumb.png' Paste it in place of the link below.
library(TeachingDemos)
library(png)
# Paste a link to a png of your favourite animal here. This will be an aardvarkplot. Make sure it ends with .thumb.png.
# If it doesn't end with .thumb.png reread the instructions above and try again.
link = "http://phylopic.org/assets/images/submissions/cfee2dca-3767-46b8-8d03-bd8f46e79e9e.thumb.png"
@carlosp420
carlosp420 / TNT_treefile_to_NEXUS
Created September 18, 2013 20:18
convert a TNT treefile to NEXUS
#!/usr/bin/perl -w
#this script converts a tree ouput from TNT to NEXUS (1 tree per file)
# Carlos Peña 2011-03-16
use strict;
use Bio::TreeIO;
my $usage = "script.pl INFILE OUTFILE\n";
my $infile = shift or die $usage;
my $outfile = shift or die $usage;