File: _transformer.py

package info (click to toggle)
q2-fragment-insertion 2024.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 776 kB
  • sloc: python: 2,004; makefile: 32; sh: 13
file content (26 lines) | stat: -rw-r--r-- 741 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# ----------------------------------------------------------------------------
# Copyright (c) 2016-2023, QIIME 2 development team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file LICENSE, distributed with this software.
# ----------------------------------------------------------------------------

import json

from .plugin_setup import plugin
from ._format import PlacementsFormat


@plugin.register_transformer
def _1(data: dict) -> PlacementsFormat:
    ff = PlacementsFormat()
    with open(str(ff), 'w') as fp:
        fp.write(json.dumps(data))
    return ff


@plugin.register_transformer
def _2(ff: PlacementsFormat) -> dict:
    with ff.open() as fh:
        return json.load(fh)