taxoniumtools 2.0.116__py3-none-any.whl → 2.0.117__py3-none-any.whl

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.
taxoniumtools/_version.py CHANGED
@@ -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.116'
16
- __version_tuple__ = version_tuple = (2, 0, 116)
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__":
taxoniumtools/utils.py CHANGED
@@ -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
@@ -34,7 +34,7 @@ def read_metadata(metadata_file, columns, key_column):
34
34
  )
35
35
 
36
36
  metadata_dict = metadata.to_dict("index")
37
- metadata_cols = metadata.columns
37
+ metadata_cols = metadata.columns.tolist()
38
38
  del metadata
39
39
  print("Metadata loaded")
40
40
  return metadata_dict, metadata_cols
@@ -46,7 +46,8 @@ def read_metadata(metadata_file, columns, key_column):
46
46
 
47
47
  def do_chronumental(mat, chronumental_reference_node, metadata_file,
48
48
  chronumental_steps, chronumental_date_output,
49
- chronumental_tree_output):
49
+ chronumental_tree_output, chronumental_add_inferred_date,
50
+ metadata_dict, metadata_cols):
50
51
  chronumental_is_available = os.system(
51
52
  "which chronumental > /dev/null") == 0
52
53
  if not chronumental_is_available:
@@ -93,6 +94,42 @@ def do_chronumental(mat, chronumental_reference_node, metadata_file,
93
94
  del time_tree
94
95
  del time_tree_iter
95
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
+
96
133
 
97
134
  def set_x_coords(root, chronumental_enabled):
98
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.116
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
@@ -13,10 +13,10 @@ Requires-Python: >=3.8
13
13
  Description-Content-Type: text/markdown
14
14
  Requires-Dist: treeswift
15
15
  Requires-Dist: alive-progress
16
- Requires-Dist: biopython <=1.81
16
+ Requires-Dist: biopython<=1.81
17
17
  Requires-Dist: pandas
18
18
  Requires-Dist: google-api-python-client
19
- Requires-Dist: protobuf <4
19
+ Requires-Dist: protobuf<4
20
20
  Requires-Dist: orjson
21
21
  Requires-Dist: psutil
22
22
  Requires-Dist: docker
@@ -0,0 +1,14 @@
1
+ taxoniumtools/__init__.py,sha256=iizd2XLvtBHVDz6j82ZWJ2eojVvbTmtJCWQGk5MtqhE,51
2
+ taxoniumtools/__main__.py,sha256=0-mrc1_4NaJur-6SQXV6vGrJFFDuRRFvqeQvnlOA5l4,25
3
+ taxoniumtools/_version.py,sha256=iMMP4FrmJNydED5EK5ogxaESOZO_aSCQRTPLu1wUn8A,415
4
+ taxoniumtools/newick_to_taxonium.py,sha256=05JMQgmYLEo4nZVGPB0afAlF2s93WE7Ka_jwd0kCw0A,6207
5
+ taxoniumtools/parsimony_pb2.py,sha256=hE6jWYlgTpUbTS1uTjRKwVgPNO232QIu3LqjpJUlthU,15575
6
+ taxoniumtools/usher_to_taxonium.py,sha256=fir7_p18f8CaFGX7H1tRTm5YSryMhmcuA_PlL3sY2m4,12295
7
+ taxoniumtools/ushertools.py,sha256=duMipZuWfEtfOx-NosZe-6XSIL5YdKHGWKJbM9jM-sQ,16417
8
+ taxoniumtools/utils.py,sha256=sNbadwK7CNLK-sQFf31Au8nG1rUmcrbGMKDSV7UJMJo,10477
9
+ taxoniumtools/view_taxonium.py,sha256=LYWBhaXYrmOOrIHI2bBYhqNUw-HZRtYzdvMQb6ZombI,4640
10
+ taxoniumtools-2.0.117.dist-info/METADATA,sha256=Ga_3Z1nv2drE6byceEMfHb_DgGQeSBH6HyGAXwvZtiU,2072
11
+ taxoniumtools-2.0.117.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
12
+ taxoniumtools-2.0.117.dist-info/entry_points.txt,sha256=oIcDnAw81KjfG32-ePuBFvqS_wbLXWB8NmWo61o1LW0,183
13
+ taxoniumtools-2.0.117.dist-info/top_level.txt,sha256=EEWGvODb1nR_CiPHUDxcfU4UzxtPnVN4yTywlT3Z0nE,14
14
+ taxoniumtools-2.0.117.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (71.1.0)
2
+ Generator: setuptools (75.1.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,14 +0,0 @@
1
- taxoniumtools/__init__.py,sha256=iizd2XLvtBHVDz6j82ZWJ2eojVvbTmtJCWQGk5MtqhE,51
2
- taxoniumtools/__main__.py,sha256=0-mrc1_4NaJur-6SQXV6vGrJFFDuRRFvqeQvnlOA5l4,25
3
- taxoniumtools/_version.py,sha256=syXcackkFxZ9RzJmN02y3UUyBKil9elFBwTnYNzz328,415
4
- taxoniumtools/newick_to_taxonium.py,sha256=05JMQgmYLEo4nZVGPB0afAlF2s93WE7Ka_jwd0kCw0A,6207
5
- taxoniumtools/parsimony_pb2.py,sha256=hE6jWYlgTpUbTS1uTjRKwVgPNO232QIu3LqjpJUlthU,15575
6
- taxoniumtools/usher_to_taxonium.py,sha256=RV_jUTHQlmqvIZw0TmbjYforUK0mLnN6u5VdIhgD0MA,11934
7
- taxoniumtools/ushertools.py,sha256=duMipZuWfEtfOx-NosZe-6XSIL5YdKHGWKJbM9jM-sQ,16417
8
- taxoniumtools/utils.py,sha256=2qDm4mbFZmOMsw3vLymlyHciHDSPS8LJycMJro2zTbU,8502
9
- taxoniumtools/view_taxonium.py,sha256=LYWBhaXYrmOOrIHI2bBYhqNUw-HZRtYzdvMQb6ZombI,4640
10
- taxoniumtools-2.0.116.dist-info/METADATA,sha256=LEoWTWcg70SD9CS7Dw3s_fuBQERljonrOVNxUmrWRk8,2074
11
- taxoniumtools-2.0.116.dist-info/WHEEL,sha256=Wyh-_nZ0DJYolHNn1_hMa4lM7uDedD_RGVwbmTjyItk,91
12
- taxoniumtools-2.0.116.dist-info/entry_points.txt,sha256=oIcDnAw81KjfG32-ePuBFvqS_wbLXWB8NmWo61o1LW0,183
13
- taxoniumtools-2.0.116.dist-info/top_level.txt,sha256=EEWGvODb1nR_CiPHUDxcfU4UzxtPnVN4yTywlT3Z0nE,14
14
- taxoniumtools-2.0.116.dist-info/RECORD,,