Skip to content

Instantly share code, notes, and snippets.

@ShaiberAlon
Created November 8, 2016 03:27
Show Gist options
  • Save ShaiberAlon/c7ee0e1cf94a3aa30363fdf1c2a6ffde to your computer and use it in GitHub Desktop.
Save ShaiberAlon/c7ee0e1cf94a3aa30363fdf1c2a6ffde to your computer and use it in GitHub Desktop.
Generate a newick formatted tree with numerical order
#!/usr/bin/env python
# -*- coding: utf-8
__author__ = "Alon Shaiber"
__copyright__ = ""
__credits__ = []
__license__ = ""
__version__ = 1
__maintainer__ = "Alon Shaiber"
__email__ = "alon.shaiber@gmail.com"
import argparse
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Generate a newick formatted tree in which the nodes are ordered according to numerical order from 0 to N-1')
parser.add_argument(metavar='N',dest='N',type=int,help='Number of nodes for the tree')
args = parser.parse_args()
N=args.N
A=''
for i in range(2,N,1):
A=A+'('+str(i)+':0.1,'
B=''
for i in range(N,(N-1)*2):
B='Int'+str(i)+':0.1)'+B
tree=A+'(1:0.1,0:0.1)'+B+';'
print tree
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment