Skip to content

Commit

Permalink
added collate_ortholog_annotations from moshpit
Browse files Browse the repository at this point in the history
  • Loading branch information
VinzentRisch committed Sep 3, 2024
1 parent b9992c1 commit 2139199
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 4 deletions.
5 changes: 3 additions & 2 deletions q2_types/genome_data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
from ._types import (
GenomeData, Genes, Proteins, Loci, Orthologs, DNASequence, NOG
)
from ._methods import collate_orthologs, partition_orthologs
from ._methods import collate_orthologs, partition_orthologs, \
collate_ortholog_annotations

__all__ = [
'GenomeData', 'Genes', 'Proteins', 'Loci', 'GFF3Format',
'GenesDirectoryFormat', 'ProteinsDirectoryFormat', 'LociDirectoryFormat',
'IntervalMetadataIterator', 'OrthologFileFmt', 'Orthologs',
'SeedOrthologDirFmt', 'GenomeSequencesDirectoryFormat', 'DNASequence',
'OrthologAnnotationDirFmt', 'NOG',
'collate_orthologs', 'partition_orthologs',
'collate_orthologs', 'partition_orthologs', "collate_ortholog_annotations"
]
16 changes: 15 additions & 1 deletion q2_types/genome_data/_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import numpy as np
from qiime2.util import duplicate

from q2_types.genome_data import SeedOrthologDirFmt
from q2_types.genome_data import SeedOrthologDirFmt, OrthologAnnotationDirFmt


def collate_orthologs(orthologs: SeedOrthologDirFmt) -> SeedOrthologDirFmt:
Expand Down Expand Up @@ -72,3 +72,17 @@ def partition_orthologs(
partitioned_orthologs[i] = result

return partitioned_orthologs


def collate_ortholog_annotations(
ortholog_annotations: OrthologAnnotationDirFmt
) -> OrthologAnnotationDirFmt:
# Init output
collated_annotations = OrthologAnnotationDirFmt()

# Copy annotations into output
for anno in ortholog_annotations:
for fp in anno.path.iterdir():
duplicate(fp, collated_annotations.path / fp.name)

return collated_annotations
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
21 changes: 20 additions & 1 deletion q2_types/genome_data/tests/test_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
#
# The full license is in the file LICENSE, distributed with this software.
# ----------------------------------------------------------------------------
import filecmp
import os

from qiime2.plugin.testing import TestPluginBase

from q2_types.genome_data import SeedOrthologDirFmt, collate_orthologs, \
partition_orthologs
partition_orthologs, OrthologAnnotationDirFmt, collate_ortholog_annotations


class TestOrthologsPartitionCollating(TestPluginBase):
Expand Down Expand Up @@ -52,3 +53,21 @@ def test_partition_orthologs_warning_message(self):
UserWarning, "You have requested a number of.*5.*2.*2"
):
partition_orthologs(orthologs, 5)

def test_collate_ortholog_annotations(self):
p = self.get_data_path("ortholog-annotations-collating")
annotations = [
OrthologAnnotationDirFmt(f"{p}/{letter}", mode="r")
for letter in ["a", "b", "c"]
]
collated_annotations = collate_ortholog_annotations(annotations)

# assert that all files are there
compare = filecmp.dircmp(
collated_annotations.path,
self.get_data_path("ortholog-annotations-collating/collated")
)
self.assertListEqual(
compare.common,
[f"{letter}.annotations" for letter in ["a", "b", "c"]]
)

0 comments on commit 2139199

Please sign in to comment.