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

removal of RESCRIPt RNA types, etc.. #102

Merged
merged 5 commits into from
Apr 21, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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 rescript/get_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import qiime2
from urllib.request import urlretrieve
from urllib.error import HTTPError
from .types._format import RNAFASTAFormat
from q2_types.feature_data import RNAFASTAFormat


def get_silva_data(ctx,
Expand Down
14 changes: 5 additions & 9 deletions rescript/plugin_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
filter_taxa)
from .orient import orient_seqs
from q2_types.feature_data import (FeatureData, Taxonomy, Sequence,
AlignedSequence)
AlignedSequence, RNASequence)
from q2_types.tree import Phylogeny, Rooted
from q2_feature_classifier.classifier import (_parameter_descriptions,
_classify_parameters)
Expand All @@ -39,8 +39,8 @@
from rescript._utilities import _rank_handles
from rescript.types._format import (
SILVATaxonomyFormat, SILVATaxonomyDirectoryFormat, SILVATaxidMapFormat,
SILVATaxidMapDirectoryFormat, RNAFASTAFormat, RNASequencesDirectoryFormat)
from rescript.types._type import SILVATaxonomy, SILVATaxidMap, RNASequence
SILVATaxidMapDirectoryFormat)
from rescript.types._type import SILVATaxonomy, SILVATaxidMap
from rescript.types.methods import reverse_transcribe
from rescript.ncbi import get_ncbi_data, _default_ranks, _allowed_ranks

Expand Down Expand Up @@ -858,17 +858,13 @@
)

# Registrations
plugin.register_semantic_types(SILVATaxonomy, SILVATaxidMap, RNASequence)
plugin.register_semantic_types(SILVATaxonomy, SILVATaxidMap)
plugin.register_semantic_type_to_format(
FeatureData[SILVATaxonomy],
artifact_format=SILVATaxonomyDirectoryFormat)
plugin.register_semantic_type_to_format(
FeatureData[SILVATaxidMap],
artifact_format=SILVATaxidMapDirectoryFormat)
plugin.register_semantic_type_to_format(
FeatureData[RNASequence],
artifact_format=RNASequencesDirectoryFormat)
plugin.register_formats(SILVATaxonomyFormat, SILVATaxonomyDirectoryFormat,
SILVATaxidMapFormat, SILVATaxidMapDirectoryFormat,
RNAFASTAFormat, RNASequencesDirectoryFormat)
SILVATaxidMapFormat, SILVATaxidMapDirectoryFormat)
importlib.import_module('rescript.types._transformer')
3 changes: 1 addition & 2 deletions rescript/tests/test_screenseq.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@

import qiime2
from qiime2.plugin.testing import TestPluginBase
from q2_types.feature_data import DNAFASTAFormat, DNAIterator
from q2_types.feature_data import DNAFASTAFormat, DNAIterator, RNAFASTAFormat

from rescript.screenseq import cull_seqs
from rescript.types._format import RNAFASTAFormat


import_data = qiime2.Artifact.import_data
Expand Down
8 changes: 3 additions & 5 deletions rescript/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@
# ----------------------------------------------------------------------------

from ._format import (SILVATaxonomyFormat, SILVATaxonomyDirectoryFormat,
SILVATaxidMapFormat, SILVATaxidMapDirectoryFormat,
RNAFASTAFormat, RNASequencesDirectoryFormat)
from ._type import SILVATaxonomy, SILVATaxidMap, RNASequence
SILVATaxidMapFormat, SILVATaxidMapDirectoryFormat)
from ._type import SILVATaxonomy, SILVATaxidMap


__all__ = ['SILVATaxonomyFormat', 'SILVATaxonomyDirectoryFormat',
'SILVATaxidMapFormat', 'SILVATaxidMapDirectoryFormat',
'SILVATaxonomy', 'SILVATaxidMap', 'RNAFASTAFormat',
'RNASequencesDirectoryFormat', 'RNASequence']
'SILVATaxonomy', 'SILVATaxidMap']
22 changes: 0 additions & 22 deletions rescript/types/_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@
# The full license is in the file LICENSE, distributed with this software.
# ----------------------------------------------------------------------------

import itertools

import qiime2.plugin.model as model
from qiime2.plugin import ValidationError

from rescript._utilities import _read_rna_fasta


def _validate_record_len(cells, current_line_number, exp_len):
if len(cells) != exp_len:
Expand Down Expand Up @@ -128,21 +124,3 @@ def _validate_(self, level):
SILVATaxidMapDirectoryFormat = model.SingleFileDirectoryFormat(
'SILVATaxidMapDirectoryFormat', 'silva_taxmap.tsv',
SILVATaxidMapFormat)


class RNAFASTAFormat(model.TextFileFormat):
def _validate(self, n_records=None):
generator = _read_rna_fasta(str(self))
if n_records is not None:
generator = itertools.islice(generator, n_records)
# just loop over contents with skbio generator
# skbio will raise an error if any record is not an RNA sequence
[i for i in generator]

def _validate_(self, level):
record_count_map = {'min': 5, 'max': None}
self._validate(record_count_map[level])


RNASequencesDirectoryFormat = model.SingleFileDirectoryFormat(
'RNASequencesDirectoryFormat', 'rna-sequences.fasta', RNAFASTAFormat)
4 changes: 2 additions & 2 deletions rescript/types/_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

import pandas as pd
from q2_types.feature_data import (
DNAFASTAFormat, DNAIterator, AlignedDNAFASTAFormat)
DNAFASTAFormat, DNAIterator, AlignedDNAFASTAFormat, RNAFASTAFormat)

from ..plugin_setup import plugin
from ._format import SILVATaxonomyFormat, SILVATaxidMapFormat, RNAFASTAFormat
from ._format import SILVATaxonomyFormat, SILVATaxidMapFormat
from rescript._utilities import (
_rna_to_dna, _read_dna_fasta, _dna_iterator_to_aligned_fasta)

Expand Down
2 changes: 0 additions & 2 deletions rescript/types/_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,3 @@
'SILVATaxonomy', variant_of=FeatureData.field['type'])
SILVATaxidMap = SemanticType(
'SILVATaxidMap', variant_of=FeatureData.field['type'])

RNASequence = SemanticType('RNASequence', variant_of=FeatureData.field['type'])
4 changes: 1 addition & 3 deletions rescript/types/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
# The full license is in the file LICENSE, distributed with this software.
# ----------------------------------------------------------------------------

from q2_types.feature_data import DNAFASTAFormat

from rescript.types._format import RNAFASTAFormat
from q2_types.feature_data import DNAFASTAFormat, RNAFASTAFormat
from rescript._utilities import _rna_to_dna


Expand Down
33 changes: 4 additions & 29 deletions rescript/types/tests/test_types_formats_transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@
from qiime2.plugin import ValidationError
from qiime2.plugin.testing import TestPluginBase
from q2_types.feature_data import (
FeatureData, DNAFASTAFormat, DNAIterator,
AlignedDNAFASTAFormat, AlignedDNAIterator)
FeatureData, DNAIterator, AlignedDNAFASTAFormat, AlignedDNAIterator,
DNAFASTAFormat, RNAFASTAFormat)

from rescript._utilities import _read_dna_fasta, _read_dna_alignment_fasta
from rescript.types import (SILVATaxonomyFormat, SILVATaxonomyDirectoryFormat,
SILVATaxidMapFormat, SILVATaxidMapDirectoryFormat,
SILVATaxonomy, SILVATaxidMap,
RNAFASTAFormat, RNASequencesDirectoryFormat,
RNASequence)
SILVATaxonomy, SILVATaxidMap)


class RescriptTypesTestPluginBase(TestPluginBase):
Expand Down Expand Up @@ -151,9 +149,6 @@ def test_silva_taxonomy_semantic_type_registration(self):
def test_silva_taxid_map_type_registration(self):
self.assertRegisteredSemanticType(SILVATaxidMap)

def test_rna_sequence_type_registration(self):
self.assertRegisteredSemanticType(RNASequence)

def test_silva_taxonomy_semantic_type_to_format_registration(self):
self.assertSemanticTypeRegisteredToFormat(
FeatureData[SILVATaxonomy], SILVATaxonomyDirectoryFormat)
Expand All @@ -162,10 +157,6 @@ def test_silva_taxid_map_semantic_type_to_format_registration(self):
self.assertSemanticTypeRegisteredToFormat(
FeatureData[SILVATaxidMap], SILVATaxidMapDirectoryFormat)

def test_rna_sequence_semantic_type_to_format_registration(self):
self.assertSemanticTypeRegisteredToFormat(
FeatureData[RNASequence], RNASequencesDirectoryFormat)


class TestSILVATransformers(RescriptTypesTestPluginBase):

Expand Down Expand Up @@ -211,23 +202,6 @@ def test_silva_taxidmap_format_to_pd_dataframe(self):
pdt.assert_frame_equal(self.taxmap, obs[:1], check_dtype=False)


class TestRNAFASTAFormat(RescriptTypesTestPluginBase):

def test_rna_fasta_format_validate_positive(self):
filepath = self.get_data_path('derep-test-rna.fasta')
format = RNAFASTAFormat(filepath, mode='r')
# These should both just succeed
format.validate('min')
format.validate('max')

def test_rna_fasta_format_validate_negative_is_dna(self):
filepath = pkg_resources.resource_filename(
'rescript.tests', 'data/derep-test.fasta')
with self.assertRaisesRegex(ValueError, 'Invalid character.*\'T\''):
format = RNAFASTAFormat(filepath, mode='r')
format.validate('min')


class TestRNATransformers(RescriptTypesTestPluginBase):

def setUp(self):
Expand Down Expand Up @@ -257,6 +231,7 @@ def test_rna_fasta_format_to_dna_iterator(self):
self.assertEqual(observed, expected)



class TestDNAIteratorTransformers(RescriptTypesTestPluginBase):
mikerobeson marked this conversation as resolved.
Show resolved Hide resolved
def setUp(self):
super().setUp()
Expand Down