Skip to content

Commit 861f127

Browse files
authored
IMP: collate contig-maps (#405)
<!-- PR guidance and examples: https://github.com/rachis-org/governance/blob/main/pr_template_guidelines.md --> <!-- rachis Generative AI Policy: https://github.com/rachis-org/governance/blob/main/ai_policy.md --> # Description <!-- REQUIRED: Briefly describe this PR, or link the issue it closes. --> This PR adds function to collate contig-maps. Related to [#14](bokulich-lab/q2-mag#14) # AI Disclosure <!-- REQUIRED: Check exactly one option. --> - [] NO AI USED. - [x] AI USED. # AI Usage Details Claude (Sonnet 5) was used to generate descriptors in plugin_setup.py.
1 parent 0449881 commit 861f127

4 files changed

Lines changed: 60 additions & 1 deletion

File tree

‎q2_types/feature_map/__init__.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
from ._types import (
1515
FeatureMap, MAGtoContigs, TaxonomyToContigs, FunctionToContigs
1616
)
17+
from ._methods import collate_contig_maps
1718

1819
__all__ = [
1920
"FeatureMap", "MAGtoContigs", "MAGtoContigsFormat", "MAGtoContigsDirFmt",
2021
"TaxonomyToContigs", "FeatureMapFormat",
21-
"FeatureMapDirFmt", "FunctionToContigs"
22+
"FeatureMapDirFmt", "FunctionToContigs", "collate_contig_maps"
2223
]

‎q2_types/feature_map/_methods.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# ----------------------------------------------------------------------------
2+
# Copyright (c) 2026, QIIME 2 development team.
3+
#
4+
# Distributed under the terms of the Modified BSD License.
5+
#
6+
# The full license is in the file LICENSE, distributed with this software.
7+
# ----------------------------------------------------------------------------
8+
9+
10+
def collate_contig_maps(contig_maps: dict) -> dict:
11+
collated_contig_maps = {}
12+
for contig_map in contig_maps:
13+
collated_contig_maps.update(contig_map)
14+
15+
return collated_contig_maps
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# ----------------------------------------------------------------------------
2+
# Copyright (c) 2026, QIIME 2 development team.
3+
#
4+
# Distributed under the terms of the Modified BSD License.
5+
#
6+
# The full license is in the file LICENSE, distributed with this software.
7+
# ----------------------------------------------------------------------------
8+
from qiime2.plugin.testing import TestPluginBase
9+
10+
from q2_types.feature_map import collate_contig_maps
11+
12+
13+
class TestCollateContigMaps(TestPluginBase):
14+
package = "q2_types.feature_map.tests"
15+
16+
def test_collate_contig_maps(self):
17+
contig_maps = [
18+
{"mag1": ["contig1", "contig2"]},
19+
{"mag2": ["contig3"], "mag3": ["contig4", "contig5"]},
20+
]
21+
22+
obs = collate_contig_maps(contig_maps)
23+
24+
exp = {
25+
"mag1": ["contig1", "contig2"],
26+
"mag2": ["contig3"],
27+
"mag3": ["contig4", "contig5"],
28+
}
29+
self.assertDictEqual(exp, obs)

‎q2_types/plugin_setup.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
PairedEndSequencesWithQuality, Contigs
2626
)
2727
from q2_types.feature_data import FeatureData, Sequence
28+
from q2_types.feature_map import FeatureMap, MAGtoContigs, collate_contig_maps
2829
from q2_types.genome_data import (
2930
Orthologs, GenomeData, NOG, Loci, DNASequence, Genes, Proteins
3031
)
@@ -249,6 +250,19 @@
249250
"and collates them into a single artifact.",
250251
)
251252

253+
plugin.methods.register_function(
254+
function=collate_contig_maps,
255+
inputs={"contig_maps": List[FeatureMap[MAGtoContigs]]},
256+
parameters={},
257+
outputs={"collated_contig_maps": FeatureMap[MAGtoContigs]},
258+
input_descriptions={
259+
"contig_maps": "A collection of MAG-to-contig maps to be collated."
260+
},
261+
name="Collate MAG-to-contig maps",
262+
description="Takes a collection of FeatureMap[MAGtoContigs]s "
263+
"and collates them into a single artifact.",
264+
)
265+
252266
KRAKEN2_REPORTS = TypeMatch([
253267
SampleData[Kraken2Reports % Properties('reads')],
254268
SampleData[Kraken2Reports % Properties('contigs')],

0 commit comments

Comments
 (0)