Skip to content

Commit

Permalink
save timetrees and divtrees for all relevant methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ktmeaton committed Feb 26, 2021
1 parent 0723ae4 commit 7ea625a
Show file tree
Hide file tree
Showing 9 changed files with 6,219 additions and 852 deletions.
2 changes: 1 addition & 1 deletion docs/notes/Notes_Development.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Development

1. Update coord_x and coord_y in clock_model.
1. Save an output divergence tree from clock_model.
1. Save timetrees and divtrees for all relevant methods.
8 changes: 8 additions & 0 deletions results/clock_model/clock_model_divtree.nexus

Large diffs are not rendered by default.

4,264 changes: 4,264 additions & 0 deletions results/clock_model/clock_model_divtree.xml

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes.
File renamed without changes.
177 changes: 122 additions & 55 deletions workflow/notebooks/2_clock_model.py.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3867,26 +3867,18 @@
},
{
"cell_type": "markdown",
"id": "defined-sculpture",
"id": "sitting-saying",
"metadata": {},
"source": [
"## Divergence coord_x and coord_y"
]
},
{
"cell_type": "code",
"execution_count": 60,
"id": "lasting-realtor",
"execution_count": 64,
"id": "honest-rendering",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"DEPRECATED: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above.\n",
"\n"
]
},
{
"data": {
"text/html": [
Expand Down Expand Up @@ -4552,7 +4544,7 @@
"[1065 rows x 34 columns]"
]
},
"execution_count": 60,
"execution_count": 64,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -4589,10 +4581,18 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 65,
"id": "overhead-extent",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"DEPRECATED: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above.\n",
"\n"
]
},
{
"name": "stdout",
"output_type": "stream",
Expand Down Expand Up @@ -4659,10 +4659,19 @@
},
{
"cell_type": "code",
"execution_count": 57,
"execution_count": 66,
"id": "scheduled-chambers",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"DEPRECATED: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above.\n",
"\n"
]
}
],
"source": [
"metadata_to_comment(tt.tree, tree_df)"
]
Expand All @@ -4681,13 +4690,46 @@
"id": "thousand-austin",
"metadata": {},
"source": [
"## Dataframe and Trees"
"## Dataframe"
]
},
{
"cell_type": "code",
"execution_count": 58,
"id": "foster-works",
"execution_count": 71,
"id": "precious-webmaster",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"DEPRECATED: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above.\n",
"\n"
]
}
],
"source": [
"# Dataframe\n",
"out_path_df = os.path.join(outdir, SCRIPT_NAME + \".tsv\" )\n",
"out_path_pickle_df = os.path.join(outdir, SCRIPT_NAME + \".df.obj\" )\n",
"\n",
"tree_df.to_csv(out_path_df, sep=\"\\t\")\n",
"with open(out_path_pickle_df,\"wb\") as outfile:\n",
" dill.dump(tree_df, outfile)"
]
},
{
"cell_type": "markdown",
"id": "liberal-observer",
"metadata": {},
"source": [
"## Timetrees"
]
},
{
"cell_type": "code",
"execution_count": 74,
"id": "residential-faith",
"metadata": {},
"outputs": [
{
Expand All @@ -4696,46 +4738,80 @@
"1"
]
},
"execution_count": 58,
"execution_count": 74,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Dataframe\n",
"out_path_df = os.path.join(outdir, SCRIPT_NAME + \".tsv\" )\n",
"out_path_pickle_df = os.path.join(outdir, SCRIPT_NAME + \".df.obj\" )\n",
"\n",
"tree_df.to_csv(out_path_df, sep=\"\\t\")\n",
"with open(out_path_pickle_df,\"wb\") as outfile:\n",
" dill.dump(tree_df, outfile)\n",
"\n",
"# Phyloxml\n",
"out_path_xml = os.path.join(outdir, SCRIPT_NAME + \".xml\" )\n",
"Phylo.write(tt.tree, out_path_xml, 'phyloxml')\n",
"tt_copy = copy.deepcopy(tt)\n",
"out_path_xml = os.path.join(outdir, SCRIPT_NAME + \"_timetree.xml\" )\n",
"Phylo.write(tt_copy.tree, out_path_xml, 'phyloxml')\n",
"\n",
"# Nexus\n",
"out_path_nexus = os.path.join(outdir, SCRIPT_NAME + \".nexus\" )\n",
"Phylo.write(tt.tree, out_path_nexus, 'nexus', format_branch_length='%1.{}f'.format(BRANCH_LEN_SIG_DIG))\n",
"out_path_nexus = os.path.join(outdir, SCRIPT_NAME + \"_timetree.nexus\" )\n",
"Phylo.write(tt_copy.tree, out_path_nexus, 'nexus', format_branch_length='%1.{}f'.format(BRANCH_LEN_SIG_DIG))\n",
"\n",
"# Dill object\n",
"out_path_dill_tree = os.path.join(outdir, SCRIPT_NAME + \".treetime.obj\" )\n",
"out_path_dill_tree = os.path.join(outdir, SCRIPT_NAME + \"_timetree.treetime.obj\" )\n",
"with open(out_path_dill_tree,\"wb\") as outfile:\n",
" dill.dump(tt, outfile)\n",
" dill.dump(tt_copy, outfile)\n",
" \n",
"# Newick (remove comments)\n",
"tt_copy = copy.deepcopy(tt)\n",
"for c in tt_copy.tree.find_clades(): c.comment = None\n",
" \n",
"# Newick Timetree\n",
"out_path_nwk = os.path.join(outdir, SCRIPT_NAME + \".nwk\" )\n",
"Phylo.write(tt_copy.tree, out_path_nwk, 'newick', format_branch_length='%1.{}f'.format(BRANCH_LEN_SIG_DIG))\n",
"\n",
"# Newick Divergence\n",
"out_path_nwk = os.path.join(outdir, SCRIPT_NAME + \"_timetree.nwk\" )\n",
"Phylo.write(tt_copy.tree, out_path_nwk, 'newick', format_branch_length='%1.{}f'.format(BRANCH_LEN_SIG_DIG))\n"
]
},
{
"cell_type": "markdown",
"id": "continuing-thong",
"metadata": {},
"source": [
"## Divtrees"
]
},
{
"cell_type": "code",
"execution_count": 75,
"id": "foster-works",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1"
]
},
"execution_count": 75,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"tt_copy = copy.deepcopy(tt)\n",
"# Convert to divtree\n",
"for n in tt_copy.tree.find_clades():\n",
" n.branch_length=n.mutation_length\n",
"out_path_div_nwk = os.path.join(outdir, SCRIPT_NAME + \"_divtree.nwk\" )\n",
"Phylo.write(tt_copy.tree, out_path_div_nwk, 'newick', format_branch_length='%1.{}f'.format(BRANCH_LEN_SIG_DIG))"
"\n",
"# Phyloxml\n",
"out_path_xml = os.path.join(outdir, SCRIPT_NAME + \"_divtree.xml\" )\n",
"Phylo.write(tt_copy.tree, out_path_xml, 'phyloxml')\n",
"\n",
"# Nexus\n",
"out_path_nexus = os.path.join(outdir, SCRIPT_NAME + \"_divtree.nexus\" )\n",
"Phylo.write(tt_copy.tree, out_path_nexus, 'nexus', format_branch_length='%1.{}f'.format(BRANCH_LEN_SIG_DIG))\n",
"\n",
"# Dill object\n",
"out_path_dill_tree = os.path.join(outdir, SCRIPT_NAME + \"_divtree.treetime.obj\" )\n",
"with open(out_path_dill_tree,\"wb\") as outfile:\n",
" dill.dump(tt_copy, outfile)\n",
" \n",
"# Newick (remove comments)\n",
"for c in tt_copy.tree.find_clades(): c.comment = None\n",
"out_path_nwk = os.path.join(outdir, SCRIPT_NAME + \"_divtree.nwk\" )\n",
"Phylo.write(tt_copy.tree, out_path_nwk, 'newick', format_branch_length='%1.{}f'.format(BRANCH_LEN_SIG_DIG))"
]
},
{
Expand All @@ -4748,19 +4824,10 @@
},
{
"cell_type": "code",
"execution_count": 51,
"execution_count": 68,
"id": "proper-hollow",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"DEPRECATED: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above.\n",
"\n"
]
}
],
"outputs": [],
"source": [
"import importlib\n",
"import sys\n",
Expand All @@ -4770,7 +4837,7 @@
},
{
"cell_type": "code",
"execution_count": 52,
"execution_count": 69,
"id": "structural-amount",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -4816,7 +4883,7 @@
},
{
"cell_type": "code",
"execution_count": 53,
"execution_count": 70,
"id": "recent-silicon",
"metadata": {},
"outputs": [
Expand Down
Loading

0 comments on commit 7ea625a

Please sign in to comment.