#!/usr/bin/env python
# main
import sys
import textwrap
import traceback
import multiprocessing

# Do not remove these imports
# Crucial for pyinstaller (as of v2.0)
from telomerecat.bam2length import Bam2Length
from telomerecat.bam2telbam import Bam2Telbam
from telomerecat.telbam2length import Telbam2Length
from telomerecat.csv2length import Csv2Length
from telomerecat import __version__

import parabam


def handle_input():
  command_map = {
    "bam2length": Bam2Length,
    "bam2telbam": Bam2Telbam,
    "telbam2length": Telbam2Length,
    "csv2length": Csv2Length,
  }

  help_text = get_help_text()

  cmd_interface = parabam.core.CmdLineInterface(program_name="telomerecat")
  cmd_interface.handle(command_map, help_text)


def get_help_text():
  help_text = (
    textwrap.dedent(
      """\

    telomerecat
    -----------------------------------------------------------------------------

    About: 
      Telomere Computational Analysis Tool

    Version:
      %s

    Usage:
      telomerecat <command> [options] input:{BAM/TELBAM}

    Quick Start Example:

      telomerecat bam2length -p8 { path_to_bamfile(s) }

      The above genereates a CSV file containing an estimation of average 
      telomere length for BAM files provided.

    More:
      Users may wish to segregate the heavy lifting process of creating
      a telbam (essentially a subset of telomeric reads in a BAM file) 
      from the reletively quick process of generating the length estimation.

      Generating telbams first, (with the command `bam2telbam`) allows
      users to run multiple analysis on the same file without having to 
      run the entire process multiple times. Type `telomerecat bam2telbam`
      for more information.

      If you have already generated a set of telbams and just want to 
      run length estimation on these files type `telomerecat telbam2length`
      for more information.

    Commands:
      bam2length      Estimate telomere length within BAM files
      bam2telbam      Create telbams from BAM files
      telbam2length   Estimate telomere length within TELBAMs
    """.expandtabs()
    )
    % (__version__,)
  )
  return help_text


if __name__ == "__main__":
  handle_input()
