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

updates to artifact class registration #283

Merged
merged 5 commits into from
Oct 28, 2022
Merged
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: 1 addition & 1 deletion q2_types/distance_matrix/_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
plugin.register_semantic_types(DistanceMatrix)
plugin.register_semantic_type_to_format(
DistanceMatrix,
artifact_format=DistanceMatrixDirectoryFormat
directory_format=DistanceMatrixDirectoryFormat
)
20 changes: 10 additions & 10 deletions q2_types/feature_data/_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,33 +59,33 @@

plugin.register_semantic_type_to_format(
FeatureData[Taxonomy],
artifact_format=TSVTaxonomyDirectoryFormat)
directory_format=TSVTaxonomyDirectoryFormat)
plugin.register_semantic_type_to_format(
FeatureData[Sequence],
artifact_format=DNASequencesDirectoryFormat)
directory_format=DNASequencesDirectoryFormat)
plugin.register_semantic_type_to_format(
FeatureData[RNASequence],
artifact_format=RNASequencesDirectoryFormat)
directory_format=RNASequencesDirectoryFormat)
plugin.register_semantic_type_to_format(
FeatureData[PairedEndSequence],
artifact_format=PairedDNASequencesDirectoryFormat)
directory_format=PairedDNASequencesDirectoryFormat)
plugin.register_semantic_type_to_format(
FeatureData[PairedEndRNASequence],
artifact_format=PairedRNASequencesDirectoryFormat)
directory_format=PairedRNASequencesDirectoryFormat)
plugin.register_semantic_type_to_format(
FeatureData[AlignedSequence],
artifact_format=AlignedDNASequencesDirectoryFormat)
directory_format=AlignedDNASequencesDirectoryFormat)
plugin.register_semantic_type_to_format(
FeatureData[AlignedRNASequence],
artifact_format=AlignedRNASequencesDirectoryFormat)
directory_format=AlignedRNASequencesDirectoryFormat)
plugin.register_semantic_type_to_format(
FeatureData[Differential], DifferentialDirectoryFormat)
plugin.register_semantic_type_to_format(
FeatureData[ProteinSequence],
artifact_format=ProteinSequencesDirectoryFormat)
directory_format=ProteinSequencesDirectoryFormat)
plugin.register_semantic_type_to_format(
FeatureData[AlignedProteinSequence],
artifact_format=AlignedProteinSequencesDirectoryFormat)
directory_format=AlignedProteinSequencesDirectoryFormat)
plugin.register_semantic_type_to_format(
FeatureData[BLAST6],
artifact_format=BLAST6DirectoryFormat)
directory_format=BLAST6DirectoryFormat)
2 changes: 1 addition & 1 deletion q2_types/feature_table/_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@
FeatureTable[Frequency | RelativeFrequency |
PresenceAbsence | Balance | Composition |
PercentileNormalized | Design],
artifact_format=BIOMV210DirFmt
directory_format=BIOMV210DirFmt
)
22 changes: 19 additions & 3 deletions q2_types/feature_table/tests/test_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,25 @@ def test_balance_semantic_type_registration(self):

def test_feature_table_semantic_type_to_v210_format_registration(self):
self.assertSemanticTypeRegisteredToFormat(
FeatureTable[Frequency | RelativeFrequency | PresenceAbsence |
Composition | Balance | PercentileNormalized |
Design],
FeatureTable[Frequency],
BIOMV210DirFmt)
self.assertSemanticTypeRegisteredToFormat(
FeatureTable[RelativeFrequency],
BIOMV210DirFmt)
self.assertSemanticTypeRegisteredToFormat(
FeatureTable[PresenceAbsence],
BIOMV210DirFmt)
self.assertSemanticTypeRegisteredToFormat(
FeatureTable[Composition],
BIOMV210DirFmt)
self.assertSemanticTypeRegisteredToFormat(
FeatureTable[Balance],
BIOMV210DirFmt)
self.assertSemanticTypeRegisteredToFormat(
FeatureTable[PercentileNormalized],
BIOMV210DirFmt)
self.assertSemanticTypeRegisteredToFormat(
FeatureTable[Design],
BIOMV210DirFmt)


Expand Down
4 changes: 2 additions & 2 deletions q2_types/multiplexed_sequences/_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@

plugin.register_semantic_type_to_format(
MultiplexedSingleEndBarcodeInSequence,
artifact_format=MultiplexedSingleEndBarcodeInSequenceDirFmt
directory_format=MultiplexedSingleEndBarcodeInSequenceDirFmt
)
plugin.register_semantic_type_to_format(
MultiplexedPairedEndBarcodeInSequence,
artifact_format=MultiplexedPairedEndBarcodeInSequenceDirFmt,
directory_format=MultiplexedPairedEndBarcodeInSequenceDirFmt,
)
4 changes: 2 additions & 2 deletions q2_types/ordination/_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
plugin.register_semantic_types(PCoAResults, ProcrustesStatistics)
plugin.register_semantic_type_to_format(
PCoAResults,
artifact_format=OrdinationDirectoryFormat
directory_format=OrdinationDirectoryFormat
)

plugin.register_semantic_type_to_format(
ProcrustesStatistics,

artifact_format=ProcrustesStatisticsDirFmt
directory_format=ProcrustesStatisticsDirFmt
)
26 changes: 18 additions & 8 deletions q2_types/per_sample_sequences/_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,29 @@
PairedEndSequencesWithQuality,
JoinedSequencesWithQuality)

plugin.register_semantic_type_to_format(
plugin.register_artifact_class(
SampleData[Sequences],
artifact_format=QIIME1DemuxDirFmt
directory_format=QIIME1DemuxDirFmt,
description=("Collections of sequences associated with specified samples "
"(i.e., demultiplexed sequences).")
)
plugin.register_semantic_type_to_format(
plugin.register_artifact_class(
SampleData[SequencesWithQuality],
artifact_format=SingleLanePerSampleSingleEndFastqDirFmt
directory_format=SingleLanePerSampleSingleEndFastqDirFmt,
description=("Collections of sequences with quality scores associated "
"with specified samples (i.e., demultiplexed sequences).")
)
plugin.register_semantic_type_to_format(
plugin.register_artifact_class(
SampleData[JoinedSequencesWithQuality],
artifact_format=SingleLanePerSampleSingleEndFastqDirFmt
directory_format=SingleLanePerSampleSingleEndFastqDirFmt,
description=("Collections of joined paired-end sequences with quality "
"scores associated with specified samples (i.e., "
"demultiplexed sequences).")
)
plugin.register_semantic_type_to_format(
plugin.register_artifact_class(
SampleData[PairedEndSequencesWithQuality],
artifact_format=SingleLanePerSamplePairedEndFastqDirFmt
directory_format=SingleLanePerSamplePairedEndFastqDirFmt,
description=("Collections of unjoined paired-end sequences with quality "
"scores associated with specified samples (i.e., "
"demultiplexed sequences).")
)
2 changes: 1 addition & 1 deletion q2_types/sample_data/_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@

plugin.register_semantic_type_to_format(
SampleData[AlphaDiversity],
artifact_format=AlphaDiversityDirectoryFormat
directory_format=AlphaDiversityDirectoryFormat
)
38 changes: 34 additions & 4 deletions q2_types/tree/_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@
# The full license is in the file LICENSE, distributed with this software.
# ----------------------------------------------------------------------------

from io import StringIO

from skbio import TreeNode

from qiime2.plugin import SemanticType
from qiime2.plugin.util import transform

from ..plugin_setup import plugin
from . import NewickDirectoryFormat


Phylogeny = SemanticType('Phylogeny', field_names=['type'])

Rooted = SemanticType('Rooted', variant_of=Phylogeny.field['type'])
Expand All @@ -22,8 +26,34 @@

plugin.register_semantic_types(Phylogeny, Rooted, Unrooted, Hierarchy)

plugin.register_semantic_type_to_format(Phylogeny[Rooted | Unrooted],
artifact_format=NewickDirectoryFormat)
plugin.register_artifact_class(
Phylogeny[Unrooted], NewickDirectoryFormat,
"A phylogenetic tree not containing a defined root.")


# Phylogeny[Rooted] import usage example
def phylogeny_rooted_usage(use):
def factory():
from q2_types.tree import NewickFormat

tree = TreeNode.read(StringIO(
'(SEQUENCE1:0.000000003,SEQUENCE2:0.000000003);'))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the root be trifurcating in this particular example, since that's the common-ish convention?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Or we can switch it to Phylogeny[Rooted])

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching that! I updated to Phylogeny[Rooted] and set this as ready for review.

ff = transform(tree, to_type=NewickFormat)
ff.validate()
return ff

to_import = use.init_format('my-tree', factory, ext='.tre')

use.import_from_format('tree',
semantic_type='Phylogeny[Rooted]',
variable=to_import,
view_type='NewickFormat')


plugin.register_artifact_class(
Phylogeny[Rooted], NewickDirectoryFormat,
"A phylogenetic tree containing a defined root.",
examples={'Import rooted phylogenetic tree': phylogeny_rooted_usage})

plugin.register_semantic_type_to_format(Hierarchy,
artifact_format=NewickDirectoryFormat)
directory_format=NewickDirectoryFormat)
4 changes: 3 additions & 1 deletion q2_types/tree/tests/test_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ def test_hierarchy_semantic_type_registration(self):

def test_phylogeny_rooted_unrooted_to_newick_dir_fmt_registration(self):
self.assertSemanticTypeRegisteredToFormat(
Phylogeny[Rooted | Unrooted], NewickDirectoryFormat)
Phylogeny[Rooted], NewickDirectoryFormat)
self.assertSemanticTypeRegisteredToFormat(
Phylogeny[Unrooted], NewickDirectoryFormat)

def test_hierarchy_to_newick_dir_fmt_registration(self):
self.assertSemanticTypeRegisteredToFormat(
Expand Down