import logging

import click


import mitty.simulation.readgen as rgen


@click.group()
@click.version_option()
def cli():
  """A genomic data simulator for testing and debugging bio-informatics tools"""
  logging.basicConfig(level=logging.WARNING)
  pass


def print_qname(ctx, param, value):
  if not value or ctx.resilient_parsing:
    return
  click.echo(rgen.__qname_format_details__)
  ctx.exit()


@cli.command(short_help='Generate simulated reads.')
@click.argument('reffasta')
@click.argument('paramfile')
@click.option('--qname', is_flag=True, callback=print_qname, expose_value=False, is_eager=True, help='Print documentation for information encoded in qname')
@click.option('--seed', default=7, help='Seed for RNG')
@click.option('--reference-reads-only', is_flag=True, help='If this is set, only reference reads will be generated')
@click.option('--sample-name', '-s', type=str, help='Name of sample to put in reads')
@click.option('--vcf', type=click.Path(exists=True), help='Path to vcf file representing sample')
@click.option('--bed', type=click.Path(exists=True), help='Bed file restricting regions reads are taken from')
def reads(reffasta, paramfile, sample_name, vcf, bed, reference_reads_only):
  """Generate simulated reads and write them to stdout"""
  pass


@cli.command(short_help='PE -> SE')
def unpair_fastq(fastq):
  """Rewrite qnames from interleaved PE FASTQ so file can be run as SE. Output to stdout"""
  pass


@cli.command(short_help='Interleaved PE 3> PE_1 4> PE_2')
@click.argument('fastq')
def uninterleave_fastq(fastq):
  """Given an interleaved paired-end FASTQ, split it out into two FASTQ files, written to streams 3 and 4"""
  pass


@cli.command()
def genomes():
  """Functions for sample/population simulations"""
  pass



@@ -7,16 +7,26 @@
  logging
+%0Aimport os
 %0A%0Aimport
@@ -74,16 +74,48 @@
 as rgen%0A
+import mitty.empirical.bq as bbq
 %0A%0A@click
@@ -151,16 +151,61 @@
 n()%0A
+@click.option('-v', '--verbose', count=True)%0A
 def cli(
 ):%0A 
@@ -200,16 +200,23 @@
 def cli(
+verbose
 ):%0A  %22%22%22
@@ -297,57 +297,892 @@
 %22%0A  
-logging.basicConfig(level=logging.WARNING)%0A  pass
+if verbose == 1:%0A    logging.basicConfig(level=logging.ERROR)%0A  elif verbose == 2:%0A    logging.basicConfig(level=logging.WARNING)%0A  elif verbose == 3:%0A    logging.basicConfig(level=logging.INFO)%0A  elif verbose %3E= 4:%0A    logging.basicConfig(level=logging.DEBUG)%0A%0A%0A@cli.command('sample-fastq-base-quality')%0A@click.argument('fastq', type=click.File('r'))%0A@click.argument('out', type=click.File('wb'))  # Opening as ASCII borks numpy for stdout%0A@click.option('-t', '--threads', type=int, default=1, help='Threads to use')%0A@click.option('--max-reads', type=int, help='Maximum reads to process')%0Adef sample_bq(fastq, out, threads, max_reads):%0A  %22%22%22FASTQ -%3E base-quality-distribution.csv%22%22%22%0A  bbq.base_quality(fastq_fp=fastq, out_fp=out, threads=threads, f_size=None, max_reads=max_reads)%0A%0A%0A@cli.command()%0Adef qname():%0A  %22%22%22Display qname format%22%22%22%0A  click.echo(rgen.__qname_format_details__)
 %0A%0A%0Ad
@@ -1332,32 +1332,50 @@
 %0A%0A%0A@cli.command(
+'generate-reads', 
 short_help='Gene
@@ -2084,16 +2084,25 @@
 m')%0Adef 
+generate_
 reads(re
@@ -2238,32 +2238,195 @@
 %0A%0A%0A@cli.command(
+'corrupt-reads', short_help='Apply corruption model to FASTQ file of reads')%0Adef read_corruption():%0A  pass%0A%0Adef read_bias():%0A  pass%0A%0A%0A@cli.command('unpair-fastq', 
 short_help='PE -
@@ -2571,16 +2571,38 @@
 command(
+'uninterleave-fastq', 
 short_he
@@ -2892,19 +2892,16 @@
 ations%22%22%22%0A  pass
-%0A%0A%0A

Add BQ computer to cli