Skip to content

Commit

Permalink
fixup! fixup! FIX: error out when running estimate_bracken on OSX
Browse files Browse the repository at this point in the history
  • Loading branch information
misialq committed Jan 16, 2025
1 parent c14d183 commit eb07924
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 80 deletions.
49 changes: 9 additions & 40 deletions q2_annotate/kraken2/tests/test_bracken.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# The full license is in the file LICENSE, distributed with this software.
# ----------------------------------------------------------------------------
import os
import platform
import shutil
import tempfile
import unittest
Expand Down Expand Up @@ -204,48 +205,16 @@ def test_estimate_bracken_with_unclassified(self, p1, p2, p3):
assert_frame_equal(obs_table, exp_table)
assert_frame_equal(obs_taxonomy, exp_taxonomy)
self.assertIsInstance(obs_reports, Kraken2ReportDirectoryFormat)

@patch('platform.system', return_value='Darwin')
def test_estimate_bracken_osx(self, mock_platform):
with self.assertRaisesRegex(
RuntimeError,
"The estimate_bracken action is currently not supported on macOS"
):
estimate_bracken(
kraken_reports=MagicMock(),
bracken_db=MagicMock(),
)

@patch('platform.system', return_value='Linux')
@patch('q2_annotate.kraken2.bracken._run_bracken_one_sample')
def test_estimate_bracken_linux(self, p1, p2):
def test_estimate_bracken_linux_vs_osx(self):
from qiime2.plugins import annotate
try:
kraken_reports = Kraken2ReportDirectoryFormat(
self.get_data_path('reports-mags'), 'r'
)
bracken_db = BrackenDBDirectoryFormat()

tables = [
pd.read_csv(
self.get_data_path('bracken-report/sample1.table.csv'),
index_col=0
),
pd.read_csv(
self.get_data_path('bracken-report/sample2.table.csv'),
index_col=0
)
]
p1.side_effect = tables

_estimate_bracken(
kraken_reports=kraken_reports,
bracken_db=bracken_db,
threshold=self.kwargs['threshold'],
read_len=self.kwargs['read_len'],
level=self.kwargs['level'],
)
except RuntimeError:
self.fail("evaluate_busco raised RuntimeError unexpectedly on Linux")
annotate.methods.estimate_bracken
except AttributeError:
if platform.system() == "Darwin":
pass
else:
raise


if __name__ == "__main__":
Expand Down
82 changes: 42 additions & 40 deletions q2_annotate/plugin_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# The full license is in the file LICENSE, distributed with this software.
# ----------------------------------------------------------------------------
import importlib
import platform

from q2_quality_control.plugin_setup import (
filter_parameters, filter_parameter_descriptions
Expand Down Expand Up @@ -284,46 +285,47 @@
description="Collates kraken2 outputs"
)

plugin.methods.register_function(
function=q2_annotate.kraken2.bracken.estimate_bracken,
inputs={
"kraken_reports": SampleData[Kraken2Reports % Properties('reads')],
"bracken_db": BrackenDB
},
parameters={
'threshold': Int % Range(0, None),
'read_len': Int % Range(0, None),
'level': Str % Choices(['D', 'P', 'C', 'O', 'F', 'G', 'S']),
'include_unclassified': Bool
},
outputs=[
('reports', SampleData[Kraken2Reports % Properties('bracken')]),
('taxonomy', FeatureData[Taxonomy]),
('table', FeatureTable[Frequency])
],
input_descriptions={
"kraken_reports": "Reports produced by Kraken2.",
"bracken_db": "Bracken database."
},
parameter_descriptions={
'threshold': 'Bracken: number of reads required PRIOR to abundance '
'estimation to perform re-estimation.',
'read_len': ('Bracken: read length to get all classifications for. '
'For paired end data (e.g., 2x150) this should be set '
'to the length of the single-end reads (e.g., 150).'),
'level': 'Bracken: taxonomic level to estimate abundance at.',
'include_unclassified': 'Bracken does not include the unclassified '
'read counts in the feature table. Set this '
'to True to include those regardless.'
},
output_descriptions={
'reports': 'Reports modified by Bracken.',
},
name='Perform read abundance re-estimation using Bracken.',
description='This method uses Bracken to re-estimate read abundances. '
'Only available on Linux platforms.',
citations=[citations["wood2019"]]
)
if platform.system() != "Darwin":
plugin.methods.register_function(
function=q2_annotate.kraken2.bracken.estimate_bracken,
inputs={
"kraken_reports": SampleData[Kraken2Reports % Properties('reads')],
"bracken_db": BrackenDB
},
parameters={
'threshold': Int % Range(0, None),
'read_len': Int % Range(0, None),
'level': Str % Choices(['D', 'P', 'C', 'O', 'F', 'G', 'S']),
'include_unclassified': Bool
},
outputs=[
('reports', SampleData[Kraken2Reports % Properties('bracken')]),
('taxonomy', FeatureData[Taxonomy]),
('table', FeatureTable[Frequency])
],
input_descriptions={
"kraken_reports": "Reports produced by Kraken2.",
"bracken_db": "Bracken database."
},
parameter_descriptions={
'threshold': 'Bracken: number of reads required PRIOR to abundance '
'estimation to perform re-estimation.',
'read_len': ('Bracken: read length to get all classifications for. '
'For paired end data (e.g., 2x150) this should be set '
'to the length of the single-end reads (e.g., 150).'),
'level': 'Bracken: taxonomic level to estimate abundance at.',
'include_unclassified': 'Bracken does not include the unclassified '
'read counts in the feature table. Set this '
'to True to include those regardless.'
},
output_descriptions={
'reports': 'Reports modified by Bracken.',
},
name='Perform read abundance re-estimation using Bracken.',
description='This method uses Bracken to re-estimate read abundances. '
'Only available on Linux platforms.',
citations=[citations["wood2019"]]
)

plugin.methods.register_function(
function=q2_annotate.kraken2.build_kraken_db,
Expand Down

0 comments on commit eb07924

Please sign in to comment.