augur.utils module

augur.utils.ambiguous_date_to_date_range(mydate, fmt, min_max_year=None)
augur.utils.annotate_parents_for_tree(tree)

Annotate each node in the given tree with its parent.

augur.utils.available_cpu_cores(fallback: int = 1) → int

Returns the number (an int) of CPU cores available to this process, if determinable, otherwise the number of CPU cores available to the computer, if determinable, otherwise the fallback number (which defaults to 1).

augur.utils.first_line(text)

Returns the first line of the given text, ignoring leading and trailing whitespace.

augur.utils.get_numerical_dates(meta_dict, name_col=None, date_col='date', fmt=None, min_max_year=None)
augur.utils.get_parent_name_by_child_name_for_tree(tree)

Return dictionary mapping child node names to parent node names

augur.utils.json_to_tree(json_dict, root=True)

Returns a Bio.Phylo tree corresponding to the given JSON dictionary exported by tree_to_json.

Assigns links back to parent nodes for the root of the tree.

>>> import json
>>> json_fh = open("tests/data/json_tree_to_nexus/flu_h3n2_ha_3y_tree.json", "r")
>>> json_dict = json.load(json_fh)
>>> tree = json_to_tree(json_dict)
>>> tree.name
'NODE_0002020'
>>> len(tree.clades)
2
>>> tree.clades[0].name
'NODE_0001489'
>>> hasattr(tree, "attr")
True
>>> "dTiter" in tree.attr
True
>>> tree.clades[0].parent.name
'NODE_0002020'
augur.utils.load_features(reference, feature_names=None)
augur.utils.myopen(fname, mode)
augur.utils.nthreads_value(value)

Argument value validation and casting function for –nthreads.

augur.utils.read_colors(overrides=None, use_defaults=True)
augur.utils.read_config(fname)
augur.utils.read_lat_longs(overrides=None, use_defaults=True)
augur.utils.read_metadata(fname)
augur.utils.read_node_data(fnames, tree=None)

parse the “nodes” field of the given JSONs and join the data together

augur.utils.run_shell_command(cmd, raise_errors=False, extra_env=None)

Run the given command string via the shell with error checking.

Returns True if the command exits normally. Returns False if the command exits with failure and “raise_errors” is False (the default). When “raise_errors” is True, exceptions are rethrown.

If an extra_env mapping is passed, the provided keys and values are overlayed onto the default subprocess environment.

augur.utils.write_VCF_translation(prot_dict, vcf_file_name, ref_file_name)

Writes out a VCF-style file (which seems to be minimally handleable by vcftools and pyvcf) of the AA differences between sequences and the reference. This is a similar format created/used by read_in_vcf except that there is one of these dicts (with sequences, reference, positions) for EACH gene.

Also writes out a fasta of the reference alignment.

EBH 12 Dec 2017

augur.utils.write_json(data, file_name, indent=1)

Write data as JSON to the given file_name, creating parent directories if necessary.

By default, an indent of 1 is passed to json.dumps(). If the environment variable AUGUR_MINIFY_JSON is defined with a truthy value, the default indent is instead None.