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

MAINT: add threads/jobs primitives #80

Merged
merged 2 commits into from
Feb 13, 2024
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
30 changes: 19 additions & 11 deletions q2_quality_control/_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import shutil
import tempfile

from qiime2.plugin import get_available_cores
from q2_types.feature_data import DNAFASTAFormat
from q2_types.bowtie2 import Bowtie2IndexDirFmt
from q2_types.per_sample_sequences import (
Expand Down Expand Up @@ -42,8 +43,12 @@
}


def bowtie2_build(sequences: DNAFASTAFormat,
n_threads: str = 1) -> Bowtie2IndexDirFmt:
def bowtie2_build(
sequences: DNAFASTAFormat, n_threads: int = 1
) -> Bowtie2IndexDirFmt:
if n_threads == 0:
n_threads = get_available_cores()

database = Bowtie2IndexDirFmt()
build_cmd = ['bowtie2-build', '--threads', str(n_threads),
str(sequences), str(database.path / 'db')]
Expand All @@ -52,15 +57,18 @@ def bowtie2_build(sequences: DNAFASTAFormat,


def filter_reads(
demultiplexed_sequences: CasavaOneEightSingleLanePerSampleDirFmt,
database: Bowtie2IndexDirFmt,
n_threads: int = _filter_defaults['n_threads'],
mode: str = _filter_defaults['mode'],
sensitivity: str = _filter_defaults['sensitivity'],
ref_gap_open_penalty: str = _filter_defaults['ref_gap_open_penalty'],
ref_gap_ext_penalty: str = _filter_defaults['ref_gap_ext_penalty'],
exclude_seqs: str = _filter_defaults['exclude_seqs']) \
-> CasavaOneEightSingleLanePerSampleDirFmt:
demultiplexed_sequences: CasavaOneEightSingleLanePerSampleDirFmt,
database: Bowtie2IndexDirFmt,
n_threads: int = _filter_defaults['n_threads'],
mode: str = _filter_defaults['mode'],
sensitivity: str = _filter_defaults['sensitivity'],
ref_gap_open_penalty: str = _filter_defaults['ref_gap_open_penalty'],
ref_gap_ext_penalty: str = _filter_defaults['ref_gap_ext_penalty'],
exclude_seqs: str = _filter_defaults['exclude_seqs']
) -> CasavaOneEightSingleLanePerSampleDirFmt:
if n_threads == 0:
n_threads = get_available_cores()

filtered_seqs = CasavaOneEightSingleLanePerSampleDirFmt()
df = demultiplexed_sequences.manifest
fastq_paths = [record[1:] for record in df.itertuples()]
Expand Down
12 changes: 6 additions & 6 deletions q2_quality_control/plugin_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import importlib
import q2_quality_control
from qiime2.plugin import (Str, Plugin, Choices, Range, Float, Int, Bool,
MetadataColumn, Visualization,
Threads, MetadataColumn, Visualization,
Categorical, Citations, TypeMap,
TypeMatch, Metadata, Collection)
from q2_types.feature_data import FeatureData, Sequence, Taxonomy
Expand Down Expand Up @@ -66,7 +66,7 @@
filter_output = {'filtered_sequences': 'The resulting filtered sequences.'}

filter_parameters = {
'n_threads': Int % Range(1, None),
'n_threads': Threads,
'mode': Str % Choices(['local', 'global']),
'sensitivity': Str % Choices([
'very-fast', 'fast', 'sensitive', 'very-sensitive']),
Expand Down Expand Up @@ -100,7 +100,7 @@
'perc_identity': Float % Range(0.0, 1.0, inclusive_end=True),
'evalue': Float,
'perc_query_aligned': Float,
'threads': Int % Range(1, None),
'threads': Threads,
'left_justify': P_left_justify,
},
outputs=[('sequence_hits', FeatureData[Sequence]),
Expand All @@ -118,7 +118,7 @@
'Percent of query sequence that must align to reference in order '
'to be accepted as a hit.'),
'threads': (
'Number of jobs to execute. Only applies to vsearch method.'),
'Number of threads to use. Only applies to vsearch method.'),
'left_justify': ('Reject match if the pairwise alignment begins with '
'gaps'),
},
Expand Down Expand Up @@ -294,11 +294,11 @@
plugin.methods.register_function(
function=bowtie2_build,
inputs={'sequences': FeatureData[Sequence]},
parameters={'n_threads': Int % Range(1, None)},
parameters={'n_threads': Threads},
outputs=[('database', Bowtie2Index)],
input_descriptions={
'sequences': 'Reference sequences used to build bowtie2 index.'},
parameter_descriptions={'n_threads': 'Number of threads to launch'},
parameter_descriptions={'n_threads': 'Number of threads to launch.'},
output_descriptions={'database': 'Bowtie2 index.'},
name='Build bowtie2 index from reference sequences.',
description='Build bowtie2 index from reference sequences.',
Expand Down
2 changes: 1 addition & 1 deletion q2_quality_control/quality_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
def exclude_seqs(query_sequences: DNAFASTAFormat,
reference_sequences: DNAFASTAFormat, method: str = 'blast',
perc_identity: float = 0.97, evalue: float = None,
perc_query_aligned: float = 0.97, threads: str = 1,
perc_query_aligned: float = 0.97, threads: int = 1,
left_justify: bool = False,
) -> (pd.Series, pd.Series):

Expand Down
Loading