taxoniumtools 2.0.115__tar.gz → 2.0.117__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. {taxoniumtools-2.0.115 → taxoniumtools-2.0.117}/PKG-INFO +1 -1
  2. {taxoniumtools-2.0.115 → taxoniumtools-2.0.117}/src/taxoniumtools/_version.py +2 -2
  3. {taxoniumtools-2.0.115 → taxoniumtools-2.0.117}/src/taxoniumtools/usher_to_taxonium.py +33 -21
  4. {taxoniumtools-2.0.115 → taxoniumtools-2.0.117}/src/taxoniumtools/utils.py +41 -3
  5. {taxoniumtools-2.0.115 → taxoniumtools-2.0.117}/src/taxoniumtools.egg-info/PKG-INFO +1 -1
  6. {taxoniumtools-2.0.115 → taxoniumtools-2.0.117}/README.md +0 -0
  7. {taxoniumtools-2.0.115 → taxoniumtools-2.0.117}/pyproject.toml +0 -0
  8. {taxoniumtools-2.0.115 → taxoniumtools-2.0.117}/setup.cfg +0 -0
  9. {taxoniumtools-2.0.115 → taxoniumtools-2.0.117}/src/taxoniumtools/__init__.py +0 -0
  10. {taxoniumtools-2.0.115 → taxoniumtools-2.0.117}/src/taxoniumtools/__main__.py +0 -0
  11. {taxoniumtools-2.0.115 → taxoniumtools-2.0.117}/src/taxoniumtools/newick_to_taxonium.py +0 -0
  12. {taxoniumtools-2.0.115 → taxoniumtools-2.0.117}/src/taxoniumtools/parsimony_pb2.py +0 -0
  13. {taxoniumtools-2.0.115 → taxoniumtools-2.0.117}/src/taxoniumtools/ushertools.py +0 -0
  14. {taxoniumtools-2.0.115 → taxoniumtools-2.0.117}/src/taxoniumtools/view_taxonium.py +0 -0
  15. {taxoniumtools-2.0.115 → taxoniumtools-2.0.117}/src/taxoniumtools.egg-info/SOURCES.txt +0 -0
  16. {taxoniumtools-2.0.115 → taxoniumtools-2.0.117}/src/taxoniumtools.egg-info/dependency_links.txt +0 -0
  17. {taxoniumtools-2.0.115 → taxoniumtools-2.0.117}/src/taxoniumtools.egg-info/entry_points.txt +0 -0
  18. {taxoniumtools-2.0.115 → taxoniumtools-2.0.117}/src/taxoniumtools.egg-info/requires.txt +0 -0
  19. {taxoniumtools-2.0.115 → taxoniumtools-2.0.117}/src/taxoniumtools.egg-info/top_level.txt +0 -0
  20. {taxoniumtools-2.0.115 → taxoniumtools-2.0.117}/test_data/hu1.gb +0 -0
  21. {taxoniumtools-2.0.115 → taxoniumtools-2.0.117}/test_data/mpox.pb +0 -0
  22. {taxoniumtools-2.0.115 → taxoniumtools-2.0.117}/test_data/mpox_ref.fasta +0 -0
  23. {taxoniumtools-2.0.115 → taxoniumtools-2.0.117}/test_data/test.nwk +0 -0
  24. {taxoniumtools-2.0.115 → taxoniumtools-2.0.117}/test_data/test_config.json +0 -0
  25. {taxoniumtools-2.0.115 → taxoniumtools-2.0.117}/test_data/tfci.meta.tsv.gz +0 -0
  26. {taxoniumtools-2.0.115 → taxoniumtools-2.0.117}/test_data/tfci.pb +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: taxoniumtools
3
- Version: 2.0.115
3
+ Version: 2.0.117
4
4
  Summary: Generate files for taxonium
5
5
  Home-page: https://github.com/theosanderson/taxonium
6
6
  Author: Theo Sanderson
@@ -12,5 +12,5 @@ __version__: str
12
12
  __version_tuple__: VERSION_TUPLE
13
13
  version_tuple: VERSION_TUPLE
14
14
 
15
- __version__ = version = '2.0.115'
16
- __version_tuple__ = version_tuple = (2, 0, 115)
15
+ __version__ = version = '2.0.117'
16
+ __version_tuple__ = version_tuple = (2, 0, 117)
@@ -28,6 +28,7 @@ def do_processing(input_file,
28
28
  chronumental_date_output=None,
29
29
  chronumental_tree_output=None,
30
30
  chronumental_reference_node=None,
31
+ chronumental_add_inferred_date=None,
31
32
  config_file=None,
32
33
  title=None,
33
34
  overlay_html=None,
@@ -82,7 +83,10 @@ def do_processing(input_file,
82
83
  metadata_file=metadata_file,
83
84
  chronumental_steps=chronumental_steps,
84
85
  chronumental_date_output=chronumental_date_output,
85
- chronumental_tree_output=chronumental_tree_output)
86
+ chronumental_tree_output=chronumental_tree_output,
87
+ chronumental_add_inferred_date=chronumental_add_inferred_date,
88
+ metadata_dict=metadata_dict,
89
+ metadata_cols=metadata_cols)
86
90
 
87
91
  print("Ladderizing tree..")
88
92
  mat.tree.ladderize(ascending=False)
@@ -236,6 +240,12 @@ def get_parser():
236
240
  help=
237
241
  "A reference node to be used for Chronumental. This should be earlier in the outbreak and have a good defined date. If not set the oldest sample will be automatically picked by Chronumental.",
238
242
  default=None)
243
+ parser.add_argument(
244
+ "--chronumental_add_inferred_date",
245
+ type=str,
246
+ help=
247
+ "A new metadata-column-like name to be added for display with the value of Chronumental's inferred date for each sample.",
248
+ default=None)
239
249
  parser.add_argument(
240
250
  '-j',
241
251
  "--config_json",
@@ -304,26 +314,28 @@ def main():
304
314
  parser = get_parser()
305
315
 
306
316
  args = parser.parse_args()
307
- do_processing(args.input,
308
- args.output,
309
- metadata_file=args.metadata,
310
- genbank_file=args.genbank,
311
- chronumental_enabled=args.chronumental,
312
- chronumental_steps=args.chronumental_steps,
313
- columns=args.columns,
314
- chronumental_date_output=args.chronumental_date_output,
315
- chronumental_tree_output=args.chronumental_tree_output,
316
- chronumental_reference_node=args.chronumental_reference_node,
317
- config_file=args.config_json,
318
- title=args.title,
319
- overlay_html=args.overlay_html,
320
- remove_after_pipe=args.remove_after_pipe,
321
- clade_types=args.clade_types,
322
- name_internal_nodes=args.name_internal_nodes,
323
- shear=args.shear,
324
- shear_threshold=args.shear_threshold,
325
- only_variable_sites=args.only_variable_sites,
326
- key_column=args.key_column)
317
+ do_processing(
318
+ args.input,
319
+ args.output,
320
+ metadata_file=args.metadata,
321
+ genbank_file=args.genbank,
322
+ chronumental_enabled=args.chronumental,
323
+ chronumental_steps=args.chronumental_steps,
324
+ columns=args.columns,
325
+ chronumental_date_output=args.chronumental_date_output,
326
+ chronumental_tree_output=args.chronumental_tree_output,
327
+ chronumental_reference_node=args.chronumental_reference_node,
328
+ chronumental_add_inferred_date=args.chronumental_add_inferred_date,
329
+ config_file=args.config_json,
330
+ title=args.title,
331
+ overlay_html=args.overlay_html,
332
+ remove_after_pipe=args.remove_after_pipe,
333
+ clade_types=args.clade_types,
334
+ name_internal_nodes=args.name_internal_nodes,
335
+ shear=args.shear,
336
+ shear_threshold=args.shear_threshold,
337
+ only_variable_sites=args.only_variable_sites,
338
+ key_column=args.key_column)
327
339
 
328
340
 
329
341
  if __name__ == "__main__":
@@ -1,7 +1,7 @@
1
1
  from alive_progress import alive_it, alive_bar
2
2
  import pandas as pd
3
3
  import warnings
4
- import os, tempfile, sys
4
+ import os, tempfile, sys, errno
5
5
  import treeswift
6
6
  import shutil
7
7
  from . import ushertools
@@ -25,6 +25,7 @@ def read_metadata(metadata_file, columns, key_column):
25
25
  usecols=cols_of_interest)
26
26
  # Enable again
27
27
  warnings.filterwarnings("default")
28
+ metadata[key_column] = metadata[key_column].astype(str)
28
29
  metadata.set_index(key_column, inplace=True)
29
30
  # convert metadata to dict of rows
30
31
  if not metadata.index.is_unique:
@@ -33,7 +34,7 @@ def read_metadata(metadata_file, columns, key_column):
33
34
  )
34
35
 
35
36
  metadata_dict = metadata.to_dict("index")
36
- metadata_cols = metadata.columns
37
+ metadata_cols = metadata.columns.tolist()
37
38
  del metadata
38
39
  print("Metadata loaded")
39
40
  return metadata_dict, metadata_cols
@@ -45,7 +46,8 @@ def read_metadata(metadata_file, columns, key_column):
45
46
 
46
47
  def do_chronumental(mat, chronumental_reference_node, metadata_file,
47
48
  chronumental_steps, chronumental_date_output,
48
- chronumental_tree_output):
49
+ chronumental_tree_output, chronumental_add_inferred_date,
50
+ metadata_dict, metadata_cols):
49
51
  chronumental_is_available = os.system(
50
52
  "which chronumental > /dev/null") == 0
51
53
  if not chronumental_is_available:
@@ -92,6 +94,42 @@ def do_chronumental(mat, chronumental_reference_node, metadata_file,
92
94
  del time_tree
93
95
  del time_tree_iter
94
96
 
97
+ if chronumental_add_inferred_date:
98
+ print(
99
+ f"Adding chronumental inferred date as metadata-like item {chronumental_add_inferred_date}"
100
+ )
101
+ if chronumental_date_output:
102
+ date_output_filename = chronumental_date_output
103
+ else:
104
+ metadata_dir = os.path.dirname(metadata_file)
105
+ metadata_base = os.path.basename(metadata_file)
106
+ date_output_filename = f"chronumental_dates_{metadata_base}.tsv"
107
+ if metadata_dir:
108
+ date_output_filename = metadata_dir + "/" + date_output_filename
109
+ if not os.path.exists(date_output_filename):
110
+ raise FileNotFoundError(
111
+ errno.ENOENT,
112
+ f"Can't find default date output file in the expected location (try specifying a file name with --chronumental_date_output)",
113
+ date_output_filename)
114
+ metadata_cols.append(chronumental_add_inferred_date)
115
+ inferred_dates = pd.read_csv(
116
+ date_output_filename,
117
+ sep="\t" if metadata_file.endswith(".tsv")
118
+ or metadata_file.endswith(".tsv.gz") else ",",
119
+ usecols=['strain', 'predicted_date'])
120
+ for idx, row in inferred_dates.iterrows():
121
+ node_name = row['strain']
122
+ inferred_date = row['predicted_date']
123
+ # Add inferred_date even if a node (e.g. internal node) has no metadata
124
+ if node_name not in metadata_dict:
125
+ metadata_dict[node_name] = {
126
+ col: ""
127
+ for col in metadata_cols
128
+ }
129
+ metadata_dict[node_name][
130
+ chronumental_add_inferred_date] = inferred_date
131
+ del inferred_dates
132
+
95
133
 
96
134
  def set_x_coords(root, chronumental_enabled):
97
135
  """ Set x coordinates for the tree"""
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: taxoniumtools
3
- Version: 2.0.115
3
+ Version: 2.0.117
4
4
  Summary: Generate files for taxonium
5
5
  Home-page: https://github.com/theosanderson/taxonium
6
6
  Author: Theo Sanderson