Skip to content

Instantly share code, notes, and snippets.

@Ken-Kuroki
Created October 4, 2019 11:02
Show Gist options
  • Save Ken-Kuroki/30ed01f1612fc345c60e68319110bba1 to your computer and use it in GitHub Desktop.
Save Ken-Kuroki/30ed01f1612fc345c60e68319110bba1 to your computer and use it in GitHub Desktop.
Call iTOL API to draw and save a phylogenetic tree
from itolapi import Itol
def itol(tree_file: str, save_file: str, save_format: str) -> str:
if tree_file[-5:] != ".tree" and tree_file[-9:] != ".tree.txt":
raise Exception("Input tree file name must end with .tree or .tree.txt")
if save_format not in ['png', 'svg', 'eps', 'ps', 'pdf', 'nexus', 'newick']:
raise Exception("Unsupported save format")
itol_uploader = Itol()
itol_uploader.add_file(tree_file)
itol_uploader.upload()
itol_exporter = itol_uploader.get_itol_export()
itol_exporter.add_export_param_dict({"format": save_format})
itol_exporter.export(save_file)
return itol_uploader.get_webpage()
itol("mytree.tree.txt", "save.svg", "svg")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment