Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Refactor q2-types to avoid circular imports #341

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions q2_types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@
importlib.import_module('q2_types.per_sample_sequences')
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')
importlib.import_module('q2_types.ordination')
importlib.import_module('q2_types.sample_data')
importlib.import_module('q2_types.bowtie2')
importlib.import_module('q2_types.metadata')
importlib.import_module('q2_types.multiplexed_sequences')
importlib.import_module('q2_types.kraken2')
Expand Down
5 changes: 0 additions & 5 deletions q2_types/bowtie2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,4 @@
from ._formats import (Bowtie2IndexFileFormat, Bowtie2IndexDirFmt)
from ._types import Bowtie2Index

from ..plugin_setup import plugin, citations

plugin.register_views(Bowtie2IndexDirFmt,
citations=[citations['langmead2012fast']])

__all__ = ['Bowtie2IndexFileFormat', 'Bowtie2IndexDirFmt', 'Bowtie2Index']
26 changes: 26 additions & 0 deletions q2_types/bowtie2/_deferred_setup/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,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.
# ----------------------------------------------------------------------------

from qiime2.plugin import Citations

from .. import Bowtie2IndexDirFmt
from .. import Bowtie2Index

from ...plugin_setup import plugin

citations = Citations.load('citations.bib', package='q2_types.bowtie2')
plugin.register_views(Bowtie2IndexDirFmt,
citations=[citations['langmead2012fast']])

plugin.register_semantic_types(Bowtie2Index)

plugin.register_artifact_class(
Bowtie2Index,
directory_format=Bowtie2IndexDirFmt,
description='An index of sequences for Bowtie 2 to search against.'
)
5 changes: 0 additions & 5 deletions q2_types/bowtie2/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,9 @@
# ----------------------------------------------------------------------------

from qiime2.plugin import SemanticType
from . import Bowtie2IndexDirFmt
from ..plugin_setup import plugin


# Technically there is a bit more to this, for instance the ref sequences may
# or may not be present in an index, or may be the only thing in an index,
# but let's not worry about that just yet.
Bowtie2Index = SemanticType('Bowtie2Index')

plugin.register_semantic_types(Bowtie2Index)
plugin.register_artifact_class(Bowtie2Index, Bowtie2IndexDirFmt)
10 changes: 10 additions & 0 deletions q2_types/bowtie2/citations.bib
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@article{langmead2012fast,
title={Fast gapped-read alignment with Bowtie 2},
author={Langmead, Ben and Salzberg, Steven L},
journal={Nature methods},
volume={9},
number={4},
pages={357},
year={2012},
publisher={Nature Publishing Group}
}
11 changes: 0 additions & 11 deletions q2_types/citations.bib
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,3 @@ @InProceedings{ mckinney-proc-scipy-2010
year = { 2010 },
editor = { St{\'e}fan van der Walt and Jarrod Millman }
}

@article{langmead2012fast,
title={Fast gapped-read alignment with Bowtie 2},
author={Langmead, Ben and Salzberg, Steven L},
journal={Nature methods},
volume={9},
number={4},
pages={357},
year={2012},
publisher={Nature Publishing Group}
}
8 changes: 2 additions & 6 deletions q2_types/distance_matrix/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
# The full license is in the file LICENSE, distributed with this software.
# ----------------------------------------------------------------------------

import importlib

from ._format import LSMatFormat, DistanceMatrixDirectoryFormat
from ._type import DistanceMatrix
from ._formats import LSMatFormat, DistanceMatrixDirectoryFormat
from ._types import DistanceMatrix

__all__ = ['LSMatFormat', 'DistanceMatrixDirectoryFormat', 'DistanceMatrix']

importlib.import_module('q2_types.distance_matrix._transformer')
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@
# The full license is in the file LICENSE, distributed with this software.
# ----------------------------------------------------------------------------

from qiime2.plugin import SemanticType
import importlib

from ..plugin_setup import plugin
from . import DistanceMatrixDirectoryFormat
from .. import LSMatFormat, DistanceMatrixDirectoryFormat
from .. import DistanceMatrix

from ...plugin_setup import plugin

DistanceMatrix = SemanticType('DistanceMatrix')
plugin.register_formats(LSMatFormat, DistanceMatrixDirectoryFormat)

plugin.register_semantic_types(DistanceMatrix)

plugin.register_artifact_class(
DistanceMatrix,
directory_format=DistanceMatrixDirectoryFormat,
description="A symmetric matrix representing distances between entities."
)

importlib.import_module('._transformers', __name__)
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

import skbio

from ..plugin_setup import plugin
from . import LSMatFormat
from .. import LSMatFormat

from ...plugin_setup import plugin


@plugin.register_transformer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import skbio.io
import qiime2.plugin.model as model

from ..plugin_setup import plugin


class LSMatFormat(model.TextFileFormat):
def sniff(self):
Expand All @@ -20,6 +18,3 @@ def sniff(self):

DistanceMatrixDirectoryFormat = model.SingleFileDirectoryFormat(
'DistanceMatrixDirectoryFormat', 'distance-matrix.tsv', LSMatFormat)


plugin.register_formats(LSMatFormat, DistanceMatrixDirectoryFormat)
12 changes: 12 additions & 0 deletions q2_types/distance_matrix/_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# ----------------------------------------------------------------------------
# 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.
# ----------------------------------------------------------------------------

from qiime2.plugin import SemanticType


DistanceMatrix = SemanticType('DistanceMatrix')
6 changes: 5 additions & 1 deletion q2_types/plugin_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
# The full license is in the file LICENSE, distributed with this software.
# ----------------------------------------------------------------------------

import importlib

import pandas as pd

import qiime2.plugin
import qiime2.sdk

Expand All @@ -26,4 +29,5 @@
plugin.register_views(pd.Series, pd.DataFrame,
citations=[citations['mckinney-proc-scipy-2010']])

# __init__.py loads first and imports all of the subpackages.
importlib.import_module('q2_types.bowtie2._deferred_setup')
importlib.import_module('q2_types.distance_matrix._deferred_setup')
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
package_data={
'q2_types': ['citations.bib'],
'q2_types.tests': ['data/*'],
'q2_types.bowtie2': ['citations.bib'],
'q2_types.distance_matrix.tests': ['data/*'],
'q2_types.feature_data.tests': ['data/*',
'data/taxonomy/*',
Expand Down
Loading