Skip to content
New issue

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

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

Already on GitHub? # to your account

yaml representer #128

Closed
MatthewRalston opened this issue Mar 21, 2024 · 1 comment
Closed

yaml representer #128

MatthewRalston opened this issue Mar 21, 2024 · 1 comment
Assignees
Labels
bug Something isn't working documentation Improvements or additions to documentation
Milestone

Comments

@MatthewRalston
Copy link
Owner

The util module has a YAML representer for collections.OrderedDict that is utilized in the __init__.py to display the YAML metadata header in a convenient way when writing to disk.

This should be addressed in graph_algo by now, but I'm adding this to be sure.

@MatthewRalston MatthewRalston added bug Something isn't working documentation Improvements or additions to documentation labels Mar 21, 2024
@MatthewRalston MatthewRalston added this to the V0.7 stable? milestone Mar 21, 2024
@MatthewRalston MatthewRalston self-assigned this Mar 21, 2024
MatthewRalston added a commit that referenced this issue Mar 24, 2024
…e board, version bump to v0.7.8. In this commit, tested on Cdiff_R3.fa (in test/data), the graph subcommand produces a valid metadata header, and writes the outputs to stdout and to the .kdbg file, and correctly asserts/validates the relationship between unique k-mers, unique nullomers, and the number of theoretically possible k-mers.
@MatthewRalston MatthewRalston moved this from In review to Done in Assembly algorithm (0.7.7+) Mar 24, 2024
@MatthewRalston MatthewRalston moved this from Done to In review in Assembly algorithm (0.7.7+) Mar 24, 2024
@github-project-automation github-project-automation bot moved this from In review to Done in Assembly algorithm (0.7.7+) Mar 25, 2024
@MatthewRalston MatthewRalston changed the title config.py renamed representer for OrderedDict yaml representer Apr 3, 2024
@MatthewRalston
Copy link
Owner Author

def represent_yaml_from_collections_dot_OrderedDict(dumper, data):
    """
    Thanks to Blender and EquipDev on StackOverflow for this handy method to pass to yaml.add_representer
    https://stackoverflow.com/a/16782282

    I use this throughout the metadata representation in the bgzf specification to print out the representer, it's just awesome.

    I really like this answer. Finally got around to liking it this year, in Jan 2022 after using it for like a few years. 

    :param dumper: The OrderedDict_Representer, this faciliatates key sorting, consistent ordering of hasmap values, and can retain order during print for optimal metadata block structure.
    :type dumper: 
    :param data:
    :type data: dict
    """



import yaml

from collections import OrderedDict

def represent_ordereddict(dumper, data):
    value = []

    for item_key, item_value in data.items():
        node_key = dumper.represent_data(item_key)
        node_value = dumper.represent_data(item_value)

        value.append((node_key, node_value))

    return yaml.nodes.MappingNode(u'tag:yaml.org,2002:map', value)

yaml.add_representer(OrderedDict, represent_ordereddict)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation
Projects
Status: Done
Development

No branches or pull requests

1 participant