[med-svn] [Git][med-team/q2-types][upstream] New upstream version 2023.9.0
Andreas Tille (@tille)
gitlab at salsa.debian.org
Mon Jan 29 17:53:53 GMT 2024
Andreas Tille pushed to branch upstream at Debian Med / q2-types
Commits:
598bdd65 by Andreas Tille at 2024-01-29T18:44:05+01:00
New upstream version 2023.9.0
- - - - -
15 changed files:
- q2_types/__init__.py
- q2_types/_version.py
- + q2_types/feature_map/__init__.py
- + q2_types/feature_map/_format.py
- + q2_types/feature_map/_transformer.py
- + q2_types/feature_map/_type.py
- + q2_types/feature_map/tests/__init__.py
- + q2_types/feature_map/tests/data/mag-to-contigs-empty-list.json
- + q2_types/feature_map/tests/data/mag-to-contigs-invalid-ids.json
- + q2_types/feature_map/tests/data/mag-to-contigs-invalid-values.json
- + q2_types/feature_map/tests/data/mag-to-contigs-valid.json
- + q2_types/feature_map/tests/test_format.py
- + q2_types/feature_map/tests/test_transformer.py
- + q2_types/feature_map/tests/test_type.py
- setup.py
Changes:
=====================================
q2_types/__init__.py
=====================================
@@ -17,6 +17,7 @@ del get_versions
# import.
importlib.import_module('q2_types.multiplexed_sequences')
importlib.import_module('q2_types.feature_data')
+importlib.import_module('q2_types.feature_map')
importlib.import_module('q2_types.feature_table')
importlib.import_module('q2_types.distance_matrix')
importlib.import_module('q2_types.tree')
=====================================
q2_types/_version.py
=====================================
@@ -23,9 +23,9 @@ def get_keywords():
# setup.py/versioneer.py will grep for the variable names, so they must
# each be defined on a line of their own. _version.py will just call
# get_keywords().
- git_refnames = " (tag: 2023.7.0, Release-2023.7)"
- git_full = "24e144ed3abe2e2133c3e848a0c8277607eec64b"
- git_date = "2023-08-17 16:46:27 +0000"
+ git_refnames = " (tag: 2023.9.0, Release-2023.9)"
+ git_full = "e351bb6b89217f1d5b8d384db674ce21193eb221"
+ git_date = "2023-10-03 22:05:44 +0000"
keywords = {"refnames": git_refnames, "full": git_full, "date": git_date}
return keywords
=====================================
q2_types/feature_map/__init__.py
=====================================
@@ -0,0 +1,19 @@
+# ----------------------------------------------------------------------------
+# Copyright (c) 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 importlib
+
+from ._format import MAGtoContigsFormat, MAGtoContigsDirFmt
+
+from ._type import FeatureMap, MAGtoContigs
+
+__all__ = [
+ "FeatureMap", "MAGtoContigs", "MAGtoContigsFormat", "MAGtoContigsDirFmt"
+]
+
+importlib.import_module("q2_types.feature_map._transformer")
=====================================
q2_types/feature_map/_format.py
=====================================
@@ -0,0 +1,54 @@
+# ----------------------------------------------------------------------------
+# Copyright (c) 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 uuid import UUID
+
+from qiime2.core.exceptions import ValidationError
+from qiime2.plugin import model
+
+from ..plugin_setup import plugin
+
+
+class MAGtoContigsFormat(model.TextFileFormat):
+ def _validate_(self, level):
+ with self.path.open("r") as fh:
+ data = json.load(fh)
+
+ level_map = {"min": 1, "max": len(data)}
+ max_entries = level_map[level]
+
+ # assert keys are proper UUIDs and dict values are lists
+ # with at least one contig
+ for _id, contigs in list(data.items())[:max_entries]:
+ try:
+ UUID(_id, version=4)
+ except ValueError:
+ raise ValidationError(
+ "MAG IDs must be valid UUID version 4 sequences. "
+ f'Found "{_id}", which is invalid.'
+ )
+
+ if not isinstance(contigs, list):
+ raise ValidationError(
+ "Values corresponding to MAG IDs must be lists of "
+ f'contigs. Found "{type(contigs)}" for MAG "{_id}".'
+ )
+
+ if len(contigs) == 0:
+ raise ValidationError(
+ "Only non-empty MAGs are allowed. The list of "
+ f'contigs for MAG "{_id}" is empty.'
+ )
+
+
+MAGtoContigsDirFmt = model.SingleFileDirectoryFormat(
+ "MAGtoContigsDirFmt", "mag-to-contigs.json", MAGtoContigsFormat
+)
+
+plugin.register_formats(MAGtoContigsFormat, MAGtoContigsDirFmt)
=====================================
q2_types/feature_map/_transformer.py
=====================================
@@ -0,0 +1,28 @@
+# ----------------------------------------------------------------------------
+# Copyright (c) 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 . import MAGtoContigsFormat
+
+from ..plugin_setup import plugin
+
+
+ at plugin.register_transformer
+def _1(fp: MAGtoContigsFormat) -> dict:
+ with fp.open() as fh:
+ data = json.load(fh)
+ return data
+
+
+ at plugin.register_transformer
+def _2(data: dict) -> MAGtoContigsFormat:
+ fp = MAGtoContigsFormat()
+ with fp.open() as fh:
+ json.dump(data, fh)
+ return fp
=====================================
q2_types/feature_map/_type.py
=====================================
@@ -0,0 +1,22 @@
+# ----------------------------------------------------------------------------
+# Copyright (c) 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.
+# ----------------------------------------------------------------------------
+
+from qiime2.core.type import SemanticType
+
+from ._format import MAGtoContigsDirFmt
+from ..plugin_setup import plugin
+
+FeatureMap = SemanticType("FeatureMap", field_names="type")
+MAGtoContigs = SemanticType(
+ "MAGtoContigs", variant_of=FeatureMap.field["type"]
+)
+
+plugin.register_semantic_types(FeatureMap, MAGtoContigs)
+plugin.register_semantic_type_to_format(
+ FeatureMap[MAGtoContigs], artifact_format=MAGtoContigsDirFmt
+)
=====================================
q2_types/feature_map/tests/__init__.py
=====================================
@@ -0,0 +1,7 @@
+# ----------------------------------------------------------------------------
+# Copyright (c) 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.
+# ----------------------------------------------------------------------------
=====================================
q2_types/feature_map/tests/data/mag-to-contigs-empty-list.json
=====================================
@@ -0,0 +1,15 @@
+{
+ "23c5b64e-3f3e-4688-9862-e9dae4fa0f5b": [
+ "contig1",
+ "contig2"
+ ],
+ "70c5a728-96a6-4eed-b9f9-9a73153c1385": [
+ "contig3",
+ "contig4"
+ ],
+ "7e2a749a-a19a-4b62-8195-0ee601b5fdfb": [
+ "contig1",
+ "contig3"
+ ],
+ "6232c7e1-8ed7-47c8-9bdb-b94706a26931": []
+ }
=====================================
q2_types/feature_map/tests/data/mag-to-contigs-invalid-ids.json
=====================================
@@ -0,0 +1,18 @@
+{
+ "23c5b64e-3f3e-4688-9862-e9dae4fa0f5b": [
+ "contig1",
+ "contig2"
+ ],
+ "70c5a728-96a6-4eed-b9f9-9a73153c1385": [
+ "contig3",
+ "contig4"
+ ],
+ "7e2a749a-a19a-4b62-8195-0ee601b5fdfb": [
+ "contig1",
+ "contig3"
+ ],
+ "6232c7e1": [
+ "contig2",
+ "contig5"
+ ]
+ }
=====================================
q2_types/feature_map/tests/data/mag-to-contigs-invalid-values.json
=====================================
@@ -0,0 +1,15 @@
+{
+ "23c5b64e-3f3e-4688-9862-e9dae4fa0f5b": [
+ "contig1",
+ "contig2"
+ ],
+ "70c5a728-96a6-4eed-b9f9-9a73153c1385": [
+ "contig3",
+ "contig4"
+ ],
+ "7e2a749a-a19a-4b62-8195-0ee601b5fdfb": [
+ "contig1",
+ "contig3"
+ ],
+ "6232c7e1-8ed7-47c8-9bdb-b94706a26931": "abc"
+ }
=====================================
q2_types/feature_map/tests/data/mag-to-contigs-valid.json
=====================================
@@ -0,0 +1,18 @@
+{
+ "23c5b64e-3f3e-4688-9862-e9dae4fa0f5b": [
+ "contig1",
+ "contig2"
+ ],
+ "70c5a728-96a6-4eed-b9f9-9a73153c1385": [
+ "contig3"
+ ],
+ "7e2a749a-a19a-4b62-8195-0ee601b5fdfb": [
+ "contig1",
+ "contig3",
+ "contig4"
+ ],
+ "6232c7e1-8ed7-47c8-9bdb-b94706a26931": [
+ "contig2",
+ "contig5"
+ ]
+ }
=====================================
q2_types/feature_map/tests/test_format.py
=====================================
@@ -0,0 +1,58 @@
+# ----------------------------------------------------------------------------
+# Copyright (c) 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 unittest
+
+from qiime2.core.exceptions import ValidationError
+from qiime2.plugin.testing import TestPluginBase
+
+from .._format import MAGtoContigsFormat
+
+
+class TestFormats(TestPluginBase):
+ package = "q2_types.feature_map.tests"
+
+ def test_mag_to_contigs_valid_min(self):
+ fp = self.get_data_path("mag-to-contigs-valid.json")
+ fmt = MAGtoContigsFormat(fp, mode="r")
+ fmt.validate(level="min")
+
+ def test_mag_to_contigs_valid_max(self):
+ fp = self.get_data_path("mag-to-contigs-valid.json")
+ fmt = MAGtoContigsFormat(fp, mode="r")
+ fmt.validate(level="max")
+
+ def test_mag_to_contigs_has_invalid_ids(self):
+ fp = self.get_data_path("mag-to-contigs-invalid-ids.json")
+ fmt = MAGtoContigsFormat(fp, mode="r")
+ with self.assertRaisesRegex(
+ ValidationError, 'Found "6232c7e1", which is invalid.'
+ ):
+ fmt.validate(level="max")
+
+ def test_mag_to_contigs_has_invalid_values(self):
+ fp = self.get_data_path("mag-to-contigs-invalid-values.json")
+ fmt = MAGtoContigsFormat(fp, mode="r")
+ with self.assertRaisesRegex(
+ ValidationError,
+ 'Found "<class \'str\'>" for MAG '
+ '"6232c7e1-8ed7-47c8-9bdb-b94706a26931".',
+ ):
+ fmt.validate(level="max")
+
+ def test_mag_to_contigs_has_no_contigs(self):
+ fp = self.get_data_path("mag-to-contigs-empty-list.json")
+ fmt = MAGtoContigsFormat(fp, mode="r")
+ with self.assertRaisesRegex(
+ ValidationError,
+ 'MAG "6232c7e1-8ed7-47c8-9bdb-b94706a26931" is empty.',
+ ):
+ fmt.validate(level="max")
+
+
+if __name__ == "__main__":
+ unittest.main()
=====================================
q2_types/feature_map/tests/test_transformer.py
=====================================
@@ -0,0 +1,49 @@
+# ----------------------------------------------------------------------------
+# Copyright (c) 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
+import unittest
+
+from qiime2.plugin.testing import TestPluginBase
+
+from .._format import MAGtoContigsFormat
+
+
+class TestTransformers(TestPluginBase):
+ package = "q2_types.feature_map.tests"
+
+ def setUp(self):
+ super().setUp()
+ self.valid_contig_map = {
+ "23c5b64e-3f3e-4688-9862-e9dae4fa0f5b": ["contig1", "contig2"],
+ "70c5a728-96a6-4eed-b9f9-9a73153c1385": ["contig3"],
+ "7e2a749a-a19a-4b62-8195-0ee601b5fdfb": [
+ "contig1", "contig3", "contig4"
+ ],
+ "6232c7e1-8ed7-47c8-9bdb-b94706a26931": ["contig2", "contig5"],
+ }
+
+ def test_contig_map_to_dict(self):
+ transformer = self.get_transformer(MAGtoContigsFormat, dict)
+ _input = MAGtoContigsFormat(
+ self.get_data_path("mag-to-contigs-valid.json"), "r"
+ )
+
+ obs = transformer(_input)
+ self.assertDictEqual(self.valid_contig_map, obs)
+
+ def test_dict_to_contig_map(self):
+ transformer = self.get_transformer(dict, MAGtoContigsFormat)
+ obs_fp = transformer(self.valid_contig_map)
+
+ with obs_fp.open() as obs_fh:
+ obs = json.load(obs_fh)
+ self.assertDictEqual(self.valid_contig_map, obs)
+
+
+if __name__ == "__main__":
+ unittest.main()
=====================================
q2_types/feature_map/tests/test_type.py
=====================================
@@ -0,0 +1,32 @@
+# ----------------------------------------------------------------------------
+# Copyright (c) 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 unittest
+
+from qiime2.plugin.testing import TestPluginBase
+
+from .._type import (FeatureMap, MAGtoContigs)
+from .._format import MAGtoContigsDirFmt
+
+
+class TestTypes(TestPluginBase):
+ package = "q2_types.feature_map.tests"
+
+ def test_feature_map_semantic_type_registration(self):
+ self.assertRegisteredSemanticType(FeatureMap)
+
+ def test_feature_map_mag_to_contigs_semantic_type_registration(self):
+ self.assertRegisteredSemanticType(MAGtoContigs)
+
+ def test_feature_map_to_dir_fmt_registration(self):
+ self.assertSemanticTypeRegisteredToFormat(
+ FeatureMap[MAGtoContigs], MAGtoContigsDirFmt
+ )
+
+
+if __name__ == "__main__":
+ unittest.main()
=====================================
setup.py
=====================================
@@ -29,6 +29,7 @@ setup(
'q2_types.tests': ['data/*'],
'q2_types.distance_matrix.tests': ['data/*'],
'q2_types.feature_data.tests': ['data/*', 'data/taxonomy/*'],
+ 'q2_types.feature_map.tests': ['data/*'],
'q2_types.feature_table.tests': ['data/*'],
'q2_types.metadata.tests': ['data/*'],
'q2_types.multiplexed_sequences.tests': ['data/*'],
View it on GitLab: https://salsa.debian.org/med-team/q2-types/-/commit/598bdd65896bc8927701800f403967fc9e033794
--
View it on GitLab: https://salsa.debian.org/med-team/q2-types/-/commit/598bdd65896bc8927701800f403967fc9e033794
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/debian-med-commit/attachments/20240129/e15fa5a2/attachment-0001.htm>
More information about the debian-med-commit
mailing list