Skip to content

Commit

Permalink
API: allow specifying an ASV to use as a control
Browse files Browse the repository at this point in the history
  • Loading branch information
wasade committed Jan 16, 2024
1 parent 104c2f7 commit fd2d484
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
16 changes: 13 additions & 3 deletions q2_katharoseq/_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
'o__Rhodobacterales;f__Rhodobacteraceae;g__Paracoccus'],
'single': [
'd__Bacteria;p__Proteobacteria;c__Gammaproteobacteria;'
'o__Burkholderiales;f__Comamonadaceae;g__Variovorax']
'o__Burkholderiales;f__Comamonadaceae;g__Variovorax'],
'asv': ''
}


Expand Down Expand Up @@ -103,7 +104,13 @@ def read_count_threshold(
positive_control_column: qiime2.CategoricalMetadataColumn,
cell_count_column: qiime2.NumericMetadataColumn,
table: pd.DataFrame,
control: str) -> None:
control: str,
asv: str=None) -> None:
if control == 'asv':
if asv is None:
raise ValueError("Control type set to asv but no asv provided")
if asv not in table.columns:
raise ValueError("asv not found in the feature table")

# CONVERSIONS
positive_control_column = positive_control_column.to_series()
Expand Down Expand Up @@ -146,7 +153,10 @@ def read_count_threshold(
df['asv_reads'] = df.sum(axis=1)

# NUMBER READS ALIGNING TO MOCK COMMUNITY INPUT
df['control_reads'] = df[control_type[control]].sum(axis=1)
if control == 'asv':
df['control_reads'] = df[asv]
else:
df['control_reads'] = df[control_type[control]].sum(axis=1)

# PERCENT CORRECTLY ASSIGNED
df['correct_assign'] = df['control_reads'] / df['asv_reads']
Expand Down
5 changes: 5 additions & 0 deletions q2_katharoseq/plugin_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
'positive_control_value': Str,
'positive_control_column': MetadataColumn[Categorical],
'cell_count_column': MetadataColumn[Numeric],
'asv': Str,
},
input_descriptions={
'table': (
Expand All @@ -63,6 +64,10 @@
'The column in the sample metadata that describes which samples '
'are and are not controls.'
),
'asv': (
'Specify an exact ASV to use for a control. If the features are '
'hashed, please use the feature hash'
),
},
name='Methods for the application of the KatharoSeq protocol',
description='KatharoSeq is high-throughput protocol combining laboratory '
Expand Down
15 changes: 15 additions & 0 deletions q2_katharoseq/tests/test_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,21 @@ def setUp(self):
folder = '../../example'
self.fp = join(dirname(abspath(getfile(currentframe()))), folder)

def test_specify_asv_as_control(self):
with tempfile.TemporaryDirectory() as output_dir:
read_count_threshold(
output_dir,
self.threshold,
self.positive_control_value,
self.positive_control_column,
self.cell_count_column,
self.table,
'asv',
'f4')

index_fp = os.path.join(output_dir, 'index.html')
self.assertTrue(os.path.exists(index_fp))

def test_outputs_index(self):
with tempfile.TemporaryDirectory() as output_dir:
read_count_threshold(
Expand Down

0 comments on commit fd2d484

Please sign in to comment.