Skip to content

Commit aba502e

Browse files
committed
subset and filter method
1 parent 17607bd commit aba502e

File tree

2 files changed

+102
-3
lines changed

2 files changed

+102
-3
lines changed

q2_qsip2/plugin_setup.py

+55-3
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88

99
import importlib
1010

11-
from qiime2.plugin import Citations, List, Metadata, Plugin, Str
11+
from qiime2.plugin import Citations, Int, List, Metadata, Plugin, Str
1212
from q2_types.feature_table import FeatureTable, Frequency
1313

1414
from q2_qsip2 import __version__
15-
from q2_qsip2.workflow import standard_workflow, create_qsip_data
1615
from q2_qsip2.types import QSIP2Data, Unfiltered, Filtered, EAF
16+
from q2_qsip2.workflow import (
17+
standard_workflow, create_qsip_data, subset_and_filter
18+
)
1719
from q2_qsip2.visualizers._visualizers import (
1820
plot_weighted_average_densities, plot_sample_curves, plot_density_outliers,
1921
show_comparison_groups
@@ -78,7 +80,9 @@
7880
outputs=[
7981
('qsip_data', QSIP2Data[Unfiltered])
8082
],
81-
input_descriptions={},
83+
input_descriptions={
84+
'table': 'The qSIP feature table.'
85+
},
8286
parameter_descriptions={
8387
'sample_metadata': 'The sample-level metadata.',
8488
'source_metadata': 'The source-level metadata.',
@@ -98,6 +102,54 @@
98102
)
99103
)
100104

105+
plugin.methods.register_function(
106+
function=subset_and_filter,
107+
inputs={
108+
'qsip_data': QSIP2Data[Unfiltered]
109+
},
110+
parameters={
111+
'unlabeled_sources': List[Str],
112+
'labeled_sources': List[Str],
113+
'min_unlabeled_sources': Int,
114+
'min_labeled_sources': Int,
115+
'min_unlabeled_fractions': Int,
116+
'min_labeled_fractions': Int
117+
},
118+
outputs=[
119+
('filtered_qsip_data', QSIP2Data[Filtered])
120+
],
121+
input_descriptions={
122+
'qsip_data': 'Your unfiltered qSIP2 data.'
123+
},
124+
parameter_descriptions={
125+
'unlabeled_sources': 'The IDs of the unlabeled sources to retain.',
126+
'labeled_sources': 'The IDs of the labeled sources to retain.',
127+
'min_unlabeled_sources': (
128+
'The minimum number of unlabeled sources a feature must be '
129+
'present in to be retained.'
130+
),
131+
'min_labeled_sources': (
132+
'The minimum number of labeled sources a feature must be present '
133+
'in to be retained.'
134+
),
135+
'min_unlabeled_fractions': (
136+
'The minimum number of fractions a feature must be present in '
137+
'to be considered present in an unlabeled source.'
138+
),
139+
'min_labeled_fractions': (
140+
'The minimum number of fractions a feature must be present in '
141+
'to be considered present in a labeled source.'
142+
)
143+
},
144+
output_descriptions={
145+
'filtered_qsip_data': 'Your subsetted and filtered qSIP2 data.'
146+
},
147+
name='Subset sources and filter features to prepare for comparison.',
148+
description=(
149+
'Placeholder.'
150+
)
151+
)
152+
101153
plugin.visualizers.register_function(
102154
function=plot_weighted_average_densities,
103155
inputs={

q2_qsip2/workflow.py

+47
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,50 @@ def create_qsip_data(
122122
)
123123

124124
return R_qsip_obj
125+
126+
def subset_and_filter(
127+
qsip_data: RS4,
128+
unlabeled_sources: list[str],
129+
labeled_sources: list[str],
130+
min_unlabeled_sources: int,
131+
min_labeled_sources: int,
132+
min_unlabeled_fractions: int,
133+
min_labeled_fractions: int
134+
) -> RS4:
135+
'''
136+
Subsets the qsip data object to include only those sources listed in
137+
`unlabeled_sources` and `labeled_sources`, and to include only those
138+
features that pass the minimum prevalence parameters.
139+
140+
Parameters
141+
----------
142+
qsip_data : RS4
143+
The "qsip_data" object.
144+
unlabeled_sources : list[str]
145+
The IDs of the unlabeled sources to retain.
146+
labeled_sources : list[str]
147+
The IDs of the labeled sources to retain.
148+
min_unlabeled_sources : int
149+
The minimum number of unlabeled sources a feature must be present in
150+
to be retained.
151+
min_labeled_sources : int
152+
The minimum number of labeled sources a feature must be present in
153+
to be retained.
154+
min_unlabeled_fractions : int
155+
The minimum number of fractions a feature must be present in
156+
to be considered present in an unlabeled source.
157+
min_labeled_fractions : int
158+
The minimum number of fractions a feature must be present in
159+
to be considered present in a labeled source.
160+
'''
161+
filtered_qsip_data = qsip2.run_feature_filter(
162+
qsip_data,
163+
unlabeled_source_mat_ids=unlabeled_sources,
164+
labeled_source_mat_ids=labeled_sources,
165+
min_unlabeled_sources=min_unlabeled_sources,
166+
min_labeled_sources=min_labeled_sources,
167+
min_unlabeled_fractions=min_unlabeled_fractions,
168+
min_labeled_fractions=min_labeled_fractions
169+
)
170+
171+
return filtered_qsip_data

0 commit comments

Comments
 (0)