Created
April 1, 2019 06:54
-
-
Save gtsambos/d20f85954fd9325b94af548e7eda7051 to your computer and use it in GitHub Desktop.
Shows an error I get when I try to use load_text in tskit.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import tskit\n", | |
"import six" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"small_tree_ex_nodes = \"\"\"\\\n", | |
"id is_sample population time\n", | |
"0 1 0 0 0.00000000000000\n", | |
"1 1 0 0 0.00000000000000\n", | |
"2 1 0 0 0.00000000000000\n", | |
"3 1 0 0 0.00000000000000\n", | |
"4 1 0 0 0.00000000000000\n", | |
"5 0 0 0 0.14567111023387\n", | |
"6 0 0 1 0.21385545626353\n", | |
"7 0 0 2 0.43508024345063\n", | |
"8 0 0 3 1.60156352971203\n", | |
"\"\"\"\n", | |
"small_tree_ex_edges = \"\"\"\\\n", | |
"id left right parent child\n", | |
"0 0.00000000 1.00000000 5 0\n", | |
"1 0.00000000 1.00000000 5 1\n", | |
"2 0.00000000 1.00000000 6 2\n", | |
"3 0.00000000 1.00000000 6 3\n", | |
"4 0.00000000 1.00000000 7 4\n", | |
"5 0.00000000 1.00000000 7 5\n", | |
"6 0.00000000 1.00000000 8 6\n", | |
"7 0.00000000 1.00000000 8 7\n", | |
"\"\"\"\n", | |
"small_tree_ex_populations = \"\"\"\\\n", | |
"id metadata\n", | |
"0\n", | |
"1\n", | |
"2\n", | |
"3\n", | |
"\"\"\"" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"ename": "IndexError", | |
"evalue": "list index out of range", | |
"output_type": "error", | |
"traceback": [ | |
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", | |
"\u001b[0;31mIndexError\u001b[0m Traceback (most recent call last)", | |
"\u001b[0;32m<ipython-input-3-d37165d6a2b6>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0medges\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0msix\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mStringIO\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msmall_tree_ex_edges\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mpopulations\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0msix\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mStringIO\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msmall_tree_ex_populations\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 5\u001b[0;31m strict=False)\n\u001b[0m", | |
"\u001b[0;32m/usr/local/opt/python3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tskit/trees.py\u001b[0m in \u001b[0;36mload_text\u001b[0;34m(nodes, edges, sites, mutations, individuals, populations, sequence_length, strict, encoding, base64_metadata)\u001b[0m\n\u001b[1;32m 1624\u001b[0m parse_populations(\n\u001b[1;32m 1625\u001b[0m \u001b[0mpopulations\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mstrict\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mstrict\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mencoding\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mencoding\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1626\u001b[0;31m base64_metadata=base64_metadata, table=tc.populations)\n\u001b[0m\u001b[1;32m 1627\u001b[0m \u001b[0mtc\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msort\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1628\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mtc\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtree_sequence\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", | |
"\u001b[0;32m/usr/local/opt/python3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tskit/trees.py\u001b[0m in \u001b[0;36mparse_populations\u001b[0;34m(source, strict, encoding, base64_metadata, table)\u001b[0m\n\u001b[1;32m 1515\u001b[0m \u001b[0mtokens\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mline\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msplit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msep\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1516\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtokens\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m>=\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1517\u001b[0;31m \u001b[0mmetadata\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtokens\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mmetadata_index\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mencode\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mencoding\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1518\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mbase64_metadata\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1519\u001b[0m \u001b[0mmetadata\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mbase64\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mb64decode\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmetadata\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", | |
"\u001b[0;31mIndexError\u001b[0m: list index out of range" | |
] | |
} | |
], | |
"source": [ | |
"ts0 = tskit.load_text(\n", | |
" nodes=six.StringIO(small_tree_ex_nodes),\n", | |
" edges=six.StringIO(small_tree_ex_edges),\n", | |
" populations=six.StringIO(small_tree_ex_populations),\n", | |
" strict=False)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"I'm also getting a (different) error when I don't include the population table." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"ename": "LibraryError", | |
"evalue": "time[parent] must be greater than time[child]", | |
"output_type": "error", | |
"traceback": [ | |
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", | |
"\u001b[0;31mLibraryError\u001b[0m Traceback (most recent call last)", | |
"\u001b[0;32m<ipython-input-4-53c0b9e3dcac>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0medges\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0msix\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mStringIO\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msmall_tree_ex_edges\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;31m# populations=six.StringIO(small_tree_ex_populations),\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 5\u001b[0;31m strict=False)\n\u001b[0m", | |
"\u001b[0;32m/usr/local/opt/python3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tskit/trees.py\u001b[0m in \u001b[0;36mload_text\u001b[0;34m(nodes, edges, sites, mutations, individuals, populations, sequence_length, strict, encoding, base64_metadata)\u001b[0m\n\u001b[1;32m 1625\u001b[0m \u001b[0mpopulations\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mstrict\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mstrict\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mencoding\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mencoding\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1626\u001b[0m base64_metadata=base64_metadata, table=tc.populations)\n\u001b[0;32m-> 1627\u001b[0;31m \u001b[0mtc\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msort\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1628\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mtc\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtree_sequence\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1629\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", | |
"\u001b[0;32m/usr/local/opt/python3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tskit/tables.py\u001b[0m in \u001b[0;36msort\u001b[0;34m(self, edge_start)\u001b[0m\n\u001b[1;32m 1726\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mdefault\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m;\u001b[0m \u001b[0mmust\u001b[0m \u001b[0mbe\u001b[0m \u001b[0;34m<=\u001b[0m \u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0medges\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1727\u001b[0m \"\"\"\n\u001b[0;32m-> 1728\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mll_tables\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msort\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0medge_start\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1729\u001b[0m \u001b[0;31m# TODO add provenance\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1730\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", | |
"\u001b[0;31mLibraryError\u001b[0m: time[parent] must be greater than time[child]" | |
] | |
} | |
], | |
"source": [ | |
"ts0 = tskit.load_text(\n", | |
" nodes=six.StringIO(small_tree_ex_nodes),\n", | |
" edges=six.StringIO(small_tree_ex_edges),\n", | |
"# populations=six.StringIO(small_tree_ex_populations),\n", | |
" strict=False)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.6.8" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think you have an extra column in the node table, in between is_sample and population. Either remove it or give it a heading value. Looks fine to me otherwise.