Skip to content

Instantly share code, notes, and snippets.

#! /usr/bin/env python
import dendropy
from dendropy.calculate import popgenstat
d = dendropy.DnaCharacterMatrix.get_from_path(
"data/primates.chars.nexus", "nexus")
print("num_segregating_sites = {}".format(popgenstat.num_segregating_sites(d, True)))
print("num_segregating_sites = {}".format(popgenstat.num_segregating_sites(d, False)))
@jeetsukumaran
jeetsukumaran / DisableNonCountedBasicMotions.vim
Last active January 25, 2019 12:06
Disable Basic Motions if not Preceded By a Count
" Notes:
" (1) To enhance the ergonomics of this sufficiently to make it practical, at
" least, until your brain grows a new lobe dedicated to counting line offsets
" in the background while you work, you should either make sure you have
" something like the following in your `~/.vimrc`:
"
" set number
" if has('autocmd')
" augroup vimrc_linenumbering
" autocmd!
@jeetsukumaran
jeetsukumaran / Python_Golf_2015-03-01.py
Last active August 29, 2015 14:16
Exactly One Matching Element
#! /usr/bin/env python
"""
Python Golf
An expression that takes predicate function object and an iterable,
and returns True if the predicate function evaluates True once and exactly once
when applied to all the elements in the iterable.
Expression with the minimum number of non-whitespace characters wins.
@jeetsukumaran
jeetsukumaran / smartcase-dict-complete.vim
Last active August 29, 2015 13:58
Smart (`infercase`) Dictionary Completions in Vim Without Otherwise Messing with Your `ignorecase` Settings
function! s:_setup_cidictcompletion()
let g:_old_ignorecase_state=&ignorecase
inoremap <C-X><C-K> <ESC>:let g:_old_ignorecase_state=&ignorecase<CR>:set ignorecase<CR>:set infercase<CR>a<C-X><C-K>
" inoremap <expr> <CR> pumvisible() ? "\<C-y><ESC>:set noignorecase<CR>a" : "\<C-g>u\<CR>"
" inoremap <expr> <C-J> pumvisible() ? "\<C-y><ESC>:set noignorecase<CR>a" : "\<C-g>u\<C-J>"
let restore=' pumvisible() ? "\<C-y><ESC>:let &ignorecase=g:_old_ignorecase_state<CR>'
for key in ["<CR>", "<C-J>", "<C-Y>"]
execute "inoremap <expr> " . key . restore . 'a" : "\<C-g>u\<CR>"'
endfor
for key in ["<ESC>", "<C-C>"]
#! /bin/bash
cd venvs
virtualenv -p /opt/python/Python-2.7.6/bin/python2 dendropy4-python2.7 && cd ../dendropy && . ../venvs/dendropy4-python2.7/bin/activate && python setup.py develop && deactivate && cd -
virtualenv -p /opt/python/Python-3.2.5/bin/python3 dendropy4-python3.2 && cd ../dendropy && . ../venvs/dendropy4-python3.2/bin/activate && python setup.py develop && deactivate && cd -
virtualenv -p /opt/python/Python-3.3.4/bin/python3 dendropy4-python3.3 && cd ../dendropy && . ../venvs/dendropy4-python3.3/bin/activate && python setup.py develop && deactivate && cd -
virtualenv -p /opt/python/Python-3.4.0/bin/python3 dendropy4-python3.4 && cd ../dendropy && . ../venvs/dendropy4-python3.4/bin/activate && python setup.py develop && deactivate && cd -
virtualenv -p /opt/python/Python-2.6.9/bin/python2 dendropy3-python2.6 && cd ../dendropy3 && . ../venvs/dendropy4-python2.6/bin/activate && python setup.py develop && deactivate && cd -
"""A caseless dictionary implementation."""
from collections import MutableMapping
class CaselessDictionary(MutableMapping):
"""
A dictionary-like object which ignores but preserves the case of strings.
@jeetsukumaran
jeetsukumaran / phylodynamaster-generate.py
Last active August 29, 2015 13:56
Generate configuration files for Vaughn's MASTER to generate viral phylogenies under different phylodynamic regimes
#! /usr/bin/env python
__version__ = "1.0.0"
from time import strftime
import random
import sys
import os
import argparse
@jeetsukumaran
jeetsukumaran / describe-python.py
Created December 13, 2013 18:46
Provides information about your Python installation(s).
#! /usr/bin/env python
import subprocess
import optparse
import os
import sys
__version__ = "1.0.0"
__author__ = "Jeet Sukumaran"
@jeetsukumaran
jeetsukumaran / Open Vim Buffer.scpt
Created June 10, 2013 22:21
Open new MacVim buffer using AppleScript. Bind to a hot-key using FastScripts, and good to go!
on run
do shell script "/Applications/MacVim.app/Contents/MacOS/Vim -g > /dev/null 2>&1"
end run
# INSTRUCTIONS: save as ~/.gdbinit
# REVISION : 6.1
# CONTRIBUTORS: mammon_, elaine, pusillus, mong
# NOTES: 'help user' in gdb will list the commands/descriptions in this file
# 'context on' now enables auto-display of context screen
#
# CHANGELOG:
# Version 6.1
# fixed filename in step_to_call so it points to /dev/null
# changed location of logfiles from /tmp to ~