<commit_before>#!/usr/bin/env python

"""
Created by: <NAME> (2017)

Description: Parses EBI genome properties assignment files.
"""

import argparse

from modules.genome_properties_longform_file_parser import parse_genome_property_longform_file

from modules.lib import sanitize_cli_path


def main(args):
    """
    Prints a human readable output of a genome properties assignment file.
    :param args: The command line arguments.
    """

    genome_property_assignment_file_path = sanitize_cli_path(args.input_genome_properties_file)

    with open(genome_property_assignment_file_path) as assignment_file:
        properties_assignment = parse_genome_property_longform_file(assignment_file)

    if properties_assignment is not None:
        print(properties_assignment)


if __name__ == '__main__':
    cli_title = """Parses a genome properties assignment file and prints its contents in a human readable format."""

    parser = argparse.ArgumentParser()
    parser.add_argument('-i', '--input_genome_properties_file', metavar='DB', required=True,
                        help='The path to the genome properties flat file.')

    cli_args = parser.parse_args()

    main(cli_args)<commit_msg>Added wrapper code for end to end tests.<commit_after>#!/usr/bin/env python

"""
Created by: <NAME> (2017)

Description: Parses EBI genome properties assignment files.
"""

import argparse

from modules.genome_properties_longform_file_parser import parse_genome_property_longform_file
from modules.genome_properties_flat_file_parser import parse_genome_property_file
from modules.genome_properties_results import GenomePropertiesResults

from modules.lib import sanitize_cli_path


def main(args):
    """
    Prints a human readable output of a genome properties assignment file.
    :param args: The command line arguments.
    """

    genome_property_flat_file_path = sanitize_cli_path(args.input_genome_properties_flat_file)
    json_output_path = sanitize_cli_path(args.output_file_path)
    assignment_file_paths = (sanitize_cli_path(path) for path in args.input_genome_properties_assignment_files)

    with open(genome_property_flat_file_path) as genome_property_file:
        genome_properties_tree = parse_genome_property_file(genome_property_file)

    assignments = []
    for path in assignment_file_paths:
        with open(path) as assignment_file:
            assignments.append(parse_genome_property_longform_file(assignment_file))

    results = GenomePropertiesResults(*assignments, genome_properties_tree=genome_properties_tree)

    with open(json_output_path, 'w') as json_file:
        results.to_json(json_file)


if __name__ == '__main__':
    cli_title = """Parses a genome properties assignment file and prints its contents in a human readable format."""

    parser = argparse.ArgumentParser()
    parser.add_argument('-d', '--input_genome_properties_flat_file', metavar='DB', required=True,
                        help='The path to the genome properties flat file.')
    parser.add_argument('-o', '--output_file_path', metavar='OUT', required=True,
                        help='The path to the genome properties flat file.')
    parser.add_argument('-i', '--input_genome_properties_assignment_files', metavar='ASSIGN', nargs='+',
                        required=True, help='The path to the genome properties flat file.')

    cli_args = parser.parse_args()

    main(cli_args)
{'fraction_non_alphanumeric': 0.08035190615835777, 'fraction_numerical': 0.002346041055718475, 'mean_word_length': 4.466346153846154, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2639229', 'n_tokens_mistral': 1022, 'n_tokens_neox': 949, 'n_words': 244}