modules.cli

  1import argparse
  2
  3'''
  4cli.py, handles argument parsing
  5'''
  6
  7def build_parser() -> argparse.ArgumentParser:
  8    '''
  9    Build CLI arg parser for the main script
 10
 11    Args:
 12        None
 13
 14    Outputs:
 15        argparse.ArgumentParser: parser object
 16    '''
 17    parser = argparse.ArgumentParser(
 18        prog="Slipper",
 19        description='''
 20        Extract soft clipped bases from BAM. For output description see repo's
 21        README.md
 22        ''', epilog="M.Hryc (2025)"
 23    )
 24
 25    subparsers = parser.add_subparsers(dest='command')
 26
 27    # === the 'extract' subcommand ===
 28
 29    extract = subparsers.add_parser(
 30        "extract", help='''
 31        Extract soft clipped bases from BAM
 32        '''
 33    )
 34    extract.add_argument(
 35        "-i", "--input",
 36        required=True,
 37        type=str, help='''
 38    Path to the input BAM file (needs an index)'''
 39    )
 40    extract.add_argument(
 41        "-o", "--output",
 42        required=True,
 43        type=str, help='''
 44    Path to the output file (without file extensions)'''
 45    )
 46    extract.add_argument(
 47        "-g", "--gzip",
 48        action="store_true",
 49        help='''
 50    Output to gzip compressed file'''
 51    )
 52    extract.add_argument(
 53        "-c", "--compress-level", metavar="LEVEL",
 54        required=False, default=1, type=int,
 55        help='''
 56    Gzip compression level (default=2)'''
 57    )
 58    extract.add_argument(
 59        "-s", "--with-sequence",
 60        required=False, action="store_true",
 61        help='''
 62    Store the whole read sequence (SEQ) in the last column. Default is off
 63    (fill with "NA")'''
 64    )
 65
 66    # === the 'analyse' subcommand
 67
 68    analyse = subparsers.add_parser(
 69        "analyse", help='''
 70        Analyse the output of 'Slipper extract'
 71        '''
 72    )
 73    analyse.add_argument(
 74        "-i", "--input",
 75        required=True,
 76        type=str, help='''
 77        Path to the input TSV produced by 'Slipper extract'
 78        '''
 79    )
 80    analyse.add_argument(
 81        "--short-output", action="store_true",
 82        help='''
 83        Skip the lines with 'no_tail' in the output
 84        '''
 85    )
 86    analyse.add_argument(
 87        "-o", "--output",
 88        required=True,
 89        type=str, help='''
 90        Path to the output file (without file extensions)
 91        '''
 92    )
 93
 94    # === the 'plot' subcommand ===
 95
 96    plot = subparsers.add_parser(
 97        "plot", help='''
 98        Make plots from 'Slipper analyse' output
 99        '''
100    )
101    plot.add_argument(
102        "-i", "--input",
103        required=True, type=str, 
104        nargs='+', help='''
105        Path to the input TSVs produced by 'Slipper analyse'
106        '''
107    )
108    plot.add_argument(
109        "-o", "--outdir",
110        default="slipper_plots",
111        type=str, help='''
112        Path to directory, where plots will be saved. Defaults to slipper_plots/
113        '''
114    )
115
116    return parser
def build_parser() -> argparse.ArgumentParser:
  8def build_parser() -> argparse.ArgumentParser:
  9    '''
 10    Build CLI arg parser for the main script
 11
 12    Args:
 13        None
 14
 15    Outputs:
 16        argparse.ArgumentParser: parser object
 17    '''
 18    parser = argparse.ArgumentParser(
 19        prog="Slipper",
 20        description='''
 21        Extract soft clipped bases from BAM. For output description see repo's
 22        README.md
 23        ''', epilog="M.Hryc (2025)"
 24    )
 25
 26    subparsers = parser.add_subparsers(dest='command')
 27
 28    # === the 'extract' subcommand ===
 29
 30    extract = subparsers.add_parser(
 31        "extract", help='''
 32        Extract soft clipped bases from BAM
 33        '''
 34    )
 35    extract.add_argument(
 36        "-i", "--input",
 37        required=True,
 38        type=str, help='''
 39    Path to the input BAM file (needs an index)'''
 40    )
 41    extract.add_argument(
 42        "-o", "--output",
 43        required=True,
 44        type=str, help='''
 45    Path to the output file (without file extensions)'''
 46    )
 47    extract.add_argument(
 48        "-g", "--gzip",
 49        action="store_true",
 50        help='''
 51    Output to gzip compressed file'''
 52    )
 53    extract.add_argument(
 54        "-c", "--compress-level", metavar="LEVEL",
 55        required=False, default=1, type=int,
 56        help='''
 57    Gzip compression level (default=2)'''
 58    )
 59    extract.add_argument(
 60        "-s", "--with-sequence",
 61        required=False, action="store_true",
 62        help='''
 63    Store the whole read sequence (SEQ) in the last column. Default is off
 64    (fill with "NA")'''
 65    )
 66
 67    # === the 'analyse' subcommand
 68
 69    analyse = subparsers.add_parser(
 70        "analyse", help='''
 71        Analyse the output of 'Slipper extract'
 72        '''
 73    )
 74    analyse.add_argument(
 75        "-i", "--input",
 76        required=True,
 77        type=str, help='''
 78        Path to the input TSV produced by 'Slipper extract'
 79        '''
 80    )
 81    analyse.add_argument(
 82        "--short-output", action="store_true",
 83        help='''
 84        Skip the lines with 'no_tail' in the output
 85        '''
 86    )
 87    analyse.add_argument(
 88        "-o", "--output",
 89        required=True,
 90        type=str, help='''
 91        Path to the output file (without file extensions)
 92        '''
 93    )
 94
 95    # === the 'plot' subcommand ===
 96
 97    plot = subparsers.add_parser(
 98        "plot", help='''
 99        Make plots from 'Slipper analyse' output
100        '''
101    )
102    plot.add_argument(
103        "-i", "--input",
104        required=True, type=str, 
105        nargs='+', help='''
106        Path to the input TSVs produced by 'Slipper analyse'
107        '''
108    )
109    plot.add_argument(
110        "-o", "--outdir",
111        default="slipper_plots",
112        type=str, help='''
113        Path to directory, where plots will be saved. Defaults to slipper_plots/
114        '''
115    )
116
117    return parser

Build CLI arg parser for the main script

Args: None

Outputs: argparse.ArgumentParser: parser object