Skip to content

Commit 037f78a

Browse files
committed
REF: q2-types changes
1 parent 7623c65 commit 037f78a

11 files changed

+105
-13
lines changed

q2_demux/_demux.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
SingleLanePerSampleSingleEndFastqDirFmt,
2626
SingleLanePerSamplePairedEndFastqDirFmt,
2727
FastqManifestFormat, YamlFormat)
28-
from q2_types.multiplexed_sequences import ErrorCorrectionDetailsFmt
29-
from q2_types.feature_data import (
30-
BarcodeSequenceFastqIterator, BarcodePairedSequenceFastqIterator
28+
from q2_types.multiplexed_sequences import (
29+
ErrorCorrectionDetailsFmt, BarcodeSequenceFastqIterator,
30+
BarcodePairedSequenceFastqIterator
3131
)
3232

3333
from ._ecc import GolayDecoder

q2_demux/_subsample.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
SingleLanePerSamplePairedEndFastqDirFmt,
1818
CasavaOneEightSingleLanePerSampleDirFmt)
1919

20-
from q2_types.feature_data._util import _read_fastq_seqs
20+
from ._util import read_fastq_seqs
2121

2222

2323
def subsample_single(sequences: SingleLanePerSampleSingleEndFastqDirFmt,
@@ -31,7 +31,7 @@ def subsample_single(sequences: SingleLanePerSampleSingleEndFastqDirFmt,
3131
fwd_path_in = str(sequences.path / fwd_name)
3232
fwd_path_out = str(result.path / fwd_name)
3333
with gzip.open(str(fwd_path_out), mode='w') as fwd:
34-
for fwd_rec in _read_fastq_seqs(fwd_path_in):
34+
for fwd_rec in read_fastq_seqs(fwd_path_in):
3535
if random.random() <= fraction:
3636
fwd.write(('\n'.join(fwd_rec) + '\n').encode('utf-8'))
3737

@@ -53,8 +53,8 @@ def subsample_paired(sequences: SingleLanePerSamplePairedEndFastqDirFmt,
5353
rev_path_out = str(result.path / rev_name)
5454
with gzip.open(str(fwd_path_out), mode='w') as fwd:
5555
with gzip.open(str(rev_path_out), mode='w') as rev:
56-
file_pair = zip(_read_fastq_seqs(fwd_path_in),
57-
_read_fastq_seqs(rev_path_in))
56+
file_pair = zip(read_fastq_seqs(fwd_path_in),
57+
read_fastq_seqs(rev_path_in))
5858
for fwd_rec, rev_rec in file_pair:
5959
if random.random() <= fraction:
6060
fwd.write(('\n'.join(fwd_rec) + '\n').encode('utf-8'))

q2_demux/_summarize/_visualizer.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
import seaborn as sns
1818
import numpy as np
1919

20-
from q2_types.feature_data._util import (_read_fastq_seqs, _PlotQualView)
20+
from .._util import read_fastq_seqs
21+
from ..types import _PlotQualView
2122
import q2templates
2223

2324
TEMPLATES = pkg_resources.resource_filename('q2_demux', '_summarize')
@@ -49,7 +50,7 @@ def _subsample(fastq_map):
4950
qual_sample = []
5051
min_seq_len = float('inf')
5152
for file, index in fastq_map:
52-
for i, seq in enumerate(_read_fastq_seqs(file)):
53+
for i, seq in enumerate(read_fastq_seqs(file)):
5354
if i == index[0]:
5455
min_seq_len = min(min_seq_len, len(seq[1]))
5556
qual_sample.append(_decode_qual_to_phred33(seq[3]))
@@ -126,7 +127,7 @@ def summarize(output_dir: str, data: _PlotQualView, n: int = 10000) -> None:
126127
if filename is None or np.isnan(filename):
127128
continue
128129

129-
for seq in _read_fastq_seqs(filename):
130+
for seq in read_fastq_seqs(filename):
130131
count += 1
131132
per_sample_fastq_counts[direction][sample_id] = count
132133
file_records[direction].append({

q2_demux/_tabulate.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from q2_types.per_sample_sequences import (
1515
SingleLanePerSampleSingleEndFastqDirFmt)
1616

17-
from q2_types.feature_data._util import _read_fastq_seqs
17+
from ._util import read_fastq_seqs
1818

1919

2020
def tabulate_read_counts(sequences: SingleLanePerSampleSingleEndFastqDirFmt
@@ -33,7 +33,7 @@ def tabulate_read_counts(sequences: SingleLanePerSampleSingleEndFastqDirFmt
3333
"Sample ids must be unique across inputs.")
3434
fwd_name = os.path.basename(fwd_path)
3535
fwd_path = str(e.path / fwd_name)
36-
for fwd_rec in _read_fastq_seqs(fwd_path):
36+
for fwd_rec in read_fastq_seqs(fwd_path):
3737
read_count += 1
3838
result[sample_id] = read_count
3939

q2_demux/_util.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# ----------------------------------------------------------------------------
2+
# Copyright (c) 2016-2023, 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+
import itertools
11+
import gzip
12+
13+
14+
def read_fastq_seqs(filepath):
15+
# This function is adapted from @jairideout's SO post:
16+
# http://stackoverflow.com/a/39302117/3424666
17+
fh = gzip.open(filepath, 'rt')
18+
for seq_header, seq, qual_header, qual in itertools.zip_longest(*[fh] * 4):
19+
yield (seq_header.strip(), seq.strip(), qual_header.strip(),
20+
qual.strip())

q2_demux/plugin_setup.py

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# The full license is in the file LICENSE, distributed with this software.
77
# ----------------------------------------------------------------------------
88

9+
import importlib
910

1011
from qiime2.plugin import (
1112
Plugin, Metadata, MetadataColumn, Categorical, Bool, Str, Int, Float,
@@ -317,3 +318,5 @@
317318
'with the WHERE clause, and the `exclude_ids` parameter '
318319
'allows for filtering of all samples not specified.',
319320
)
321+
322+
importlib.import_module('q2_demux.types._deferred_setup')

q2_demux/tests/test_demux.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import qiime2
2020
import numpy.testing as npt
2121

22-
from q2_types.feature_data._transformer import (
22+
from q2_types.multiplexed_sequences import (
2323
BarcodeSequenceFastqIterator,
2424
BarcodePairedSequenceFastqIterator)
2525
from qiime2.plugin.testing import TestPluginBase, assert_no_nans_in_tables

q2_demux/types/__init__.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# ----------------------------------------------------------------------------
2+
# Copyright (c) 2016-2023, 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+
from ._objects import _PlotQualView
10+
11+
__all__ = ['_PlotQualView']
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# ----------------------------------------------------------------------------
2+
# Copyright (c) 2016-2023, 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+
import importlib
10+
11+
importlib.import_module('._transformers', __name__)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# ----------------------------------------------------------------------------
2+
# Copyright (c) 2016-2023, 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+
from q2_types.per_sample_sequences import (
10+
SingleLanePerSampleSingleEndFastqDirFmt,
11+
SingleLanePerSamplePairedEndFastqDirFmt)
12+
13+
from .. import _PlotQualView
14+
15+
from ...plugin_setup import plugin
16+
17+
18+
# TODO: Remove _PlotQualView once Union works
19+
@plugin.register_transformer
20+
def _30(dirfmt: SingleLanePerSampleSingleEndFastqDirFmt) -> _PlotQualView:
21+
return _PlotQualView(dirfmt, paired=False)
22+
23+
24+
@plugin.register_transformer
25+
def _31(dirfmt: SingleLanePerSamplePairedEndFastqDirFmt) -> _PlotQualView:
26+
return _PlotQualView(dirfmt, paired=True)

q2_demux/types/_objects.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# ----------------------------------------------------------------------------
2+
# Copyright (c) 2016-2023, 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+
__all__ = ['_PlotQualView']
10+
11+
12+
# TODO: convert to a Union[...]
13+
class _PlotQualView:
14+
"""
15+
A very simple pass-through view which is made up of a single-end or
16+
paired-end directory format with a bool indicating if single or paired.
17+
"""
18+
def __init__(self, directory_format, paired):
19+
self.directory_format = directory_format
20+
self.paired = paired

0 commit comments

Comments
 (0)