Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restructure parsing in augur export v2 #752

Merged
merged 1 commit into from
Jul 27, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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