denseclass 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
denseclass/__init__.py ADDED
@@ -0,0 +1,12 @@
1
+ """Signal classification for nanopore reads.
2
+
3
+ Split out of the ``densecall`` basecaller into this standalone package. Nothing
4
+ here imports ``densecall``: the only helper that was shared
5
+ (``convert_base_name``) is vendored in ``base_util.py``.
6
+
7
+ Pipeline: label -> split -> gendata -> train -> predict -> evaluate
8
+ """
9
+
10
+ from denseclass.cli import __version__, argparser, main, subcommands
11
+
12
+ __all__ = ['main', 'argparser', 'subcommands', '__version__']
denseclass/__main__.py ADDED
@@ -0,0 +1,4 @@
1
+ from denseclass.cli import main
2
+
3
+ if __name__ == '__main__':
4
+ main()
@@ -0,0 +1,41 @@
1
+ """Base-name to IUPAC regular-expression helpers.
2
+
3
+ Vendored from ``densecall.mod_util`` so this package has no dependency on the
4
+ basecaller. Only ``convert_base_name`` was ever used here; the rest of
5
+ ``mod_util`` pulls in remora/mappy, which this package does not need.
6
+ """
7
+
8
+ # IUPAC degenerate codes expanded into character classes.
9
+ _MERGE_BASES = {
10
+ "A": "A",
11
+ "C": "C",
12
+ "G": "G",
13
+ "T": "T",
14
+ "M": "[AC]",
15
+ "V": "[ACG]",
16
+ "R": "[AG]",
17
+ "H": "[ACT]",
18
+ "W": "[AT]",
19
+ "D": "[AGT]",
20
+ "S": "[CG]",
21
+ "B": "[CGT]",
22
+ "Y": "[CT]",
23
+ "N": "[ACGT]",
24
+ "K": "[GT]",
25
+ }
26
+
27
+
28
+ def convert_base_name(base_name):
29
+ """Expand a base string into a regular expression pattern.
30
+
31
+ Args:
32
+ base_name (str): Input base string to be converted, e.g. ``"NAY"``.
33
+
34
+ Returns:
35
+ str: Regular expression pattern equivalent to the input, e.g.
36
+ ``"[ACGT]A[CT]"``.
37
+ """
38
+ pattern = ""
39
+ for base in base_name:
40
+ pattern += _MERGE_BASES.get(base, base)
41
+ return pattern
denseclass/cli.py ADDED
@@ -0,0 +1,76 @@
1
+ """Command-line namespace for signal classification.
2
+
3
+ ``argparser()`` builds the subcommand tree for introspection and library use;
4
+ ``main()`` is the console entry point. Both share the same leaf registration,
5
+ and ``main`` mirrors DenseCall's two-level layout (leaves hang directly off the
6
+ top parser) so that ``denseclass <cmd> --help`` shows the leaf's help.
7
+ """
8
+
9
+ from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
10
+
11
+ __version__ = '0.1.0'
12
+
13
+ subcommands = [
14
+ 'label', 'split', 'gendata', 'train', 'predict',
15
+ 'precision', 'evaluation', 'comparison'
16
+ ]
17
+
18
+ __all__ = ['argparser', 'main', 'subcommands', '__version__']
19
+
20
+ _DESCRIPTION = ('Signal classification: label map -> split -> gendata -> '
21
+ 'train -> predict -> evaluate')
22
+
23
+
24
+ def _leaves():
25
+ """Yield (name, module) for each subcommand."""
26
+ for name in subcommands:
27
+ mod = __import__(f"denseclass.{name}", fromlist=['argparser', 'main'])
28
+ yield name, mod
29
+
30
+
31
+ def _add_subparsers(parser):
32
+ """Attach every subcommand to ``parser`` as a real subparser."""
33
+ sub = parser.add_subparsers(
34
+ title='subcommands', description='valid commands',
35
+ help='additional help', dest='subcommand'
36
+ )
37
+ sub.required = True
38
+ for name, mod in _leaves():
39
+ p = sub.add_parser(name, parents=[mod.argparser()])
40
+ p.set_defaults(func=mod.main)
41
+ return sub
42
+
43
+
44
+ def argparser():
45
+ """The subcommand namespace on its own (``add_help=False``, since each leaf
46
+ carries its own ``-h``)."""
47
+ parser = ArgumentParser(
48
+ "denseclass",
49
+ formatter_class=ArgumentDefaultsHelpFormatter,
50
+ description=_DESCRIPTION,
51
+ add_help=False,
52
+ )
53
+ parser.add_argument(
54
+ '-v', '--version', action='version',
55
+ version='%(prog)s {}'.format(__version__)
56
+ )
57
+ _add_subparsers(parser)
58
+ return parser
59
+
60
+
61
+ def main(args=None):
62
+ """Console entry point: leaves hang off the top parser so
63
+ ``denseclass <cmd> --help`` reaches the leaf."""
64
+ parser = ArgumentParser(
65
+ 'denseclass',
66
+ formatter_class=ArgumentDefaultsHelpFormatter,
67
+ description=_DESCRIPTION,
68
+ )
69
+ parser.add_argument(
70
+ '-v', '--version', action='version',
71
+ version='%(prog)s {}'.format(__version__)
72
+ )
73
+ _add_subparsers(parser)
74
+
75
+ parsed = parser.parse_args(args)
76
+ parsed.func(parsed)