Skip to content

Commit

Permalink
Restructures parsing of node_data and metadata files to individually …
Browse files Browse the repository at this point in the history
…catch missing file errors. Modifies the parser to take loaded files as input
  • Loading branch information
benjaminotter committed Jul 26, 2021
1 parent 653079e commit 967896a
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions augur/export_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -907,12 +907,7 @@ def set_description(data_json, cmd_line_description_file):
except FileNotFoundError:
fatal("Provided desciption file {} does not exist".format(cmd_line_description_file))

def parse_node_data_and_metadata(T, node_data_files, metadata_file):
node_data = read_node_data(node_data_files) # node_data_files is an array of multiple files (or a single file)
if metadata_file is not None:
metadata, _ = read_metadata(metadata_file)
else:
metadata = {}
def parse_node_data_and_metadata(T, node_data, metadata):
node_data_names = set()
metadata_names = set()

Expand Down Expand Up @@ -958,13 +953,25 @@ def run_v2(args):
configure_warnings()
data_json = {"version": "v2", "meta": {"updated": time.strftime('%Y-%m-%d')}}

# parse input files
T = Phylo.read(args.tree, 'newick')
#load input files
try:
node_data, node_attrs, node_data_names, metadata_names = parse_node_data_and_metadata(T, args.node_data, args.metadata)
node_data_file = read_node_data(args.node_data) # node_data_files is an array of multiple files (or a single file)
except FileNotFoundError:
print(f"ERROR: meta data file ({args.metadata}) does not exist")
print(f"ERROR: node data file ({args.node_data}) does not exist")
sys.exit(2)

if args.metadata is not None:
try:
metadata_file, _ = read_metadata(args.metadata)
except FileNotFoundError:
print(f"ERROR: meta data file ({args.metadata}) does not exist")
sys.exit(2)
else:
metadata_file = {}

# parse input files
T = Phylo.read(args.tree, 'newick')
node_data, node_attrs, node_data_names, metadata_names = parse_node_data_and_metadata(T, node_data_file, metadata_file)
config = get_config(args)

# set metadata data structures
Expand Down

0 comments on commit 967896a

Please sign in to comment.