Skip to content

Commit

Permalink
Merge pull request #130 from epifluidlab/fix-wps-cli
Browse files Browse the repository at this point in the history
Fix wps cli
  • Loading branch information
ravibandaru-lab authored Dec 19, 2024
2 parents 0563635 + b4be59f commit 03ea6d3
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 21 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ The format is based on
and this project adheres to
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.10.1] - 2024-12-18
## [0.10.1] - 2024-12-19

### Fixed
- Added missing `-n` arg to `end-motifs`.
- Fixed incorrect `ValueError` regarding the `negative_strand` arg.
- Incorrect function name for `wps` leading to errors when called from CLI.

### Added
- Additional tests for the CLI lazy loading implementation

## [0.10.0] - 2024-12-18

Expand Down
32 changes: 16 additions & 16 deletions src/finaletoolkit/cli/main_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def main_cli_parser():
action='store_true',
help='Enable verbose mode to display detailed processing information.')
cli_coverage.set_defaults(
module='..frag._coverage', func='coverage')
module='finaletoolkit.frag._coverage', func='coverage')

# frag-length-bins
cli_frag_length_bins = subparsers.add_parser(
Expand Down Expand Up @@ -186,7 +186,7 @@ def main_cli_parser():
default=0,
help='Enable verbose mode to display detailed processing '
'information.')
cli_frag_length_bins.set_defaults(module='..frag._frag_length', func='frag_length_bins')
cli_frag_length_bins.set_defaults(module='finaletoolkit.frag._frag_length', func='frag_length_bins')

# frag-length-intervals
cli_frag_length_intervals = subparsers.add_parser(
Expand Down Expand Up @@ -250,7 +250,7 @@ def main_cli_parser():
action='count',
help='Enable verbose mode to display detailed processing '
'information.')
cli_frag_length_intervals.set_defaults(module='..frag._frag_length', func='frag_length_intervals')
cli_frag_length_intervals.set_defaults(module='finaletoolkit.frag._frag_length', func='frag_length_intervals')

# cleavage-profile
cli_cleavage_profile = subparsers.add_parser(
Expand Down Expand Up @@ -337,7 +337,7 @@ def main_cli_parser():
default=0,
action='count',
help='Enable verbose mode to display detailed processing information.')
cli_cleavage_profile.set_defaults(module='..frag._cleavage_profile', func='multi_cleavage_profile')
cli_cleavage_profile.set_defaults(module='finaletoolkit.frag._cleavage_profile', func='multi_cleavage_profile')

# wps
cli_wps = subparsers.add_parser(
Expand Down Expand Up @@ -426,7 +426,7 @@ def main_cli_parser():
action='count',
default=0,
help='Enable verbose mode to display detailed processing information.')
cli_wps.set_defaults(module='..frag', func='_multi_wps')
cli_wps.set_defaults(module='finaletoolkit.frag', func='multi_wps')

# adjust wps
cli_adjust_wps = subparsers.add_parser(
Expand Down Expand Up @@ -508,7 +508,7 @@ def main_cli_parser():
'--verbose',
action='count',
help='Enable verbose mode to display detailed processing information.')
cli_adjust_wps.set_defaults(module='..frag._adjust_wps', func='adjust_wps')
cli_adjust_wps.set_defaults(module='finaletoolkit.frag._adjust_wps', func='adjust_wps')

# delfi
cli_delfi = subparsers.add_parser(
Expand Down Expand Up @@ -599,7 +599,7 @@ def main_cli_parser():
action='count',
default=0,
help='Enable verbose mode to display detailed processing information.')
cli_delfi.set_defaults(module='..frag._delfi', func='delfi')
cli_delfi.set_defaults(module='finaletoolkit.frag._delfi', func='delfi')

# delfi-gc-correct
cli_delfi_gc = subparsers.add_parser(
Expand Down Expand Up @@ -630,7 +630,7 @@ def main_cli_parser():
'--verbose',
action='count',
help='Enable verbose mode to display detailed processing information.')
cli_delfi_gc.set_defaults(module='..frag._delfi_gc_correct', func='cli_delfi_gc_correct')
cli_delfi_gc.set_defaults(module='finaletoolkit.frag._delfi_gc_correct', func='cli_delfi_gc_correct')

# end-motifs
cli_motifs = subparsers.add_parser(
Expand Down Expand Up @@ -700,7 +700,7 @@ def main_cli_parser():
default=0,
action='count',
help='Enable verbose mode to display detailed processing information.')
cli_motifs.set_defaults(module='..frag._end_motifs', func='end_motifs')
cli_motifs.set_defaults(module='finaletoolkit.frag._end_motifs', func='end_motifs')

# interval-end-motifs
cli_interval_motifs = subparsers.add_parser(
Expand Down Expand Up @@ -789,7 +789,7 @@ def main_cli_parser():
default=0,
action='count',
help='Enable verbose mode to display detailed processing information.')
cli_interval_motifs.set_defaults(module='..frag._end_motifs', func='interval_end_motifs')
cli_interval_motifs.set_defaults(module='finaletoolkit.frag._end_motifs', func='interval_end_motifs')

# mds
cli_mds = subparsers.add_parser(
Expand All @@ -814,7 +814,7 @@ def main_cli_parser():
default=0,
type=int,
help='Number of header rows to ignore. Default is 0')
cli_mds.set_defaults(module='..frag._end_motifs', func='_cli_mds')
cli_mds.set_defaults(module='finaletoolkit.frag._end_motifs', func='_cli_mds')

# interval-mds
cli_interval_mds = subparsers.add_parser(
Expand Down Expand Up @@ -844,7 +844,7 @@ def main_cli_parser():
default=0,
type=int,
help='Number of header rows to ignore. Default is 0')
cli_interval_mds.set_defaults(module='..frag._end_motifs', func='_cli_interval_mds')
cli_interval_mds.set_defaults(module='finaletoolkit.frag._end_motifs', func='_cli_interval_mds')

# filter-bam
cli_filter_bam = subparsers.add_parser(
Expand Down Expand Up @@ -911,7 +911,7 @@ def main_cli_parser():
'--verbose',
action='count',
help='Enable verbose mode to display detailed processing information.')
cli_filter_bam.set_defaults(module='..utils', func='filter_bam')
cli_filter_bam.set_defaults(module='finaletoolkit.utils', func='filter_bam')

# agg-bw
cli_agg_bw = subparsers.add_parser(
Expand Down Expand Up @@ -952,7 +952,7 @@ def main_cli_parser():
action='count',
help='Enable verbose mode to display detailed processing '
'information.')
cli_agg_bw.set_defaults(module='..utils._agg_bw', func='agg_bw')
cli_agg_bw.set_defaults(module='finaletoolkit.utils._agg_bw', func='agg_bw')

# gap-bed
cli_gap_bed = subparsers.add_parser(
Expand All @@ -972,7 +972,7 @@ def main_cli_parser():
cli_gap_bed.add_argument(
'output_file',
help='Path to write BED file to. If "-" used, writes to stdout.')
cli_gap_bed.set_defaults(module='..genome.gaps', func='_cli_gap_bed')
cli_gap_bed.set_defaults(module='finaletoolkit.genome.gaps', func='_cli_gap_bed')

return parser

Expand All @@ -991,7 +991,7 @@ def main_cli():
func_module = funcargs.pop('module')
func_name = funcargs.pop('func')

module = importlib.import_module(func_module, 'finaletoolkit.cli')
module = importlib.import_module(func_module)
function = getattr(module, func_name)

function(**funcargs)
Expand Down
1 change: 1 addition & 0 deletions src/finaletoolkit/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ def frag_generator(
"input_file is does not follow Fragmentation file format "
"accepted by FinaleToolkit. Attempting to read as a BED6 "
"file.",
UserWarning
)
bed_format = True
else:
Expand Down
12 changes: 12 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""
import os
from inspect import getfullargspec
import importlib

import pytest

Expand All @@ -17,6 +18,17 @@ class TestCLIArgs:
"""
Test if provided commandline flags match args in associated function.
"""
@pytest.mark.parametrize("name,subparser", subcommands.items())
def test_lazy_import(self, name, subparser):
# getting module and func
module = subparser._defaults['module']
func = subparser._defaults['func']

# try to see module spec
module = importlib.import_module(module)
function = getattr(module, func)
assert callable(function), f'The {func} is not a callable in {module}.'

@pytest.mark.skip(reason="Currently does not work with the lazy loading implementation")
@pytest.mark.skipif(
IN_GITHUB_ACTIONS,
Expand Down
10 changes: 6 additions & 4 deletions tests/test_frag_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"""

import numpy as np
import pytest

from finaletoolkit.utils.utils import frag_generator, frag_array, overlaps

Expand Down Expand Up @@ -58,10 +59,11 @@ def test_bed_gz(self, request):
right number of reads
"""
path = request.path.parent / 'data' / '12.3444.b37.frag.bed.gz'
frag_gen = frag_generator(
path, "12", quality_threshold=0, min_length=0, max_length=9999
)
frags = [frag for frag in frag_gen]
with pytest.warns(UserWarning):
frag_gen = frag_generator(
path, "12", quality_threshold=0, min_length=0, max_length=9999
)
frags = [frag for frag in frag_gen]

chroms = np.array([chrom for chrom, *_ in frags])
starts = np.array([start for _, start, *_ in frags])
Expand Down

0 comments on commit 03ea6d3

Please sign in to comment.