Skip to content

Instantly share code, notes, and snippets.

View jhcepas's full-sized avatar

Jaime Huerta-Cepas jhcepas

View GitHub Profile
@jhcepas
jhcepas / Newick2FastTreeConstraints.py
Last active August 29, 2015 14:23
Converts a tree in newick format into a FastTree-compatible constraint alignment. It allows for multifurcated nodes.
#!/usr/bin/env python
import sys
from collections import defaultdict
from ete2 import Tree
try:
t = Tree(sys.argv[1])
except IndexError:
print >>sys.stderr, 'you need to provide a newick tree file as first argument\n\n'
print >>sys.stderr, 'Usage: Newick2FastTreeConstraints.py tree.nw > constraints.fa'
sys.exit(1)
@jhcepas
jhcepas / print_table.py
Last active June 6, 2020 18:20
nice table printing in python
def print_table(items, header=None, wrap=True, max_col_width=20, wrap_style="wrap", row_line=False, fix_col_width=False):
''' Prints a matrix of data as a human readable table. Matrix
should be a list of lists containing any type of values that can
be converted into text strings.
Two different column adjustment methods are supported through
the *wrap_style* argument:
wrap: it will wrap values to fit max_col_width (by extending cell height)
cut: it will strip values to max_col_width