# Path: covest/constants.py
# DEFAULT_K = 21
# 
# Path: covest/data.py
# def sample_reads(src_reads_file, dest_reads_file, factor):
#     prob = 1.0 / factor
#     with open(dest_reads_file, 'w') as f:
#         for read_id, read in load_reads(src_reads_file):
#             if random.random() < prob:
#                 f.write('>{}\n'.format(read_id))
#                 f.write('{}\n'.format(read))
# 
# def count_reads_stats(fname):
#     s = n = 0
#     for _, read in load_reads(fname):
#         s += len(read)
#         n += 1
# 
#     ar = round(s / n) if n else 0
#     return ar, s
# 
# Path: covest/utils.py
# def run(command, shell=False, output=None, verbose=False):
#     if verbose:
#         print(command, file=sys.stderr)
#     f = open(output, 'w') if output else None
#     if not shell:
#         command = command.split()
#     return subprocess.call(command, shell=shell, stdout=f)


import argparse
import json
import os
import shutil
import sys
from pathlib import Path
from tempfile import mkstemp
from covest.constants import DEFAULT_K
from covest.data import sample_reads as _sample_reads, count_reads_stats
from covest.utils import run
#!/usr/bin/env python3



READS_FILE_NAME_TEMPLATE = 'reads{}'
CONFIG_FILENAME = 'config.json'
HISTOGRAM_FILENAME = 'reads.hist'
RUNSCRIPT_FILENAME = 'run'
CURRENT_DIR = Path(__file__).parent


def mkdir(dest_dir, force=False):
    if not force and dest_dir.exists():
        print('Path already exists. Use --force to use it.', file=sys.stderr)
        exit(1)
    try:
        dest_dir.mkdir()
    except FileExistsError:
        pass


def get_reads_from_sequence(src_file, dest_dir, coverage, use_art=False):
    src = str(src_file.resolve())
    print('Generating reads file...', file=sys.stderr)
    dest = dest_dir / READS_FILE_NAME_TEMPLATE.format('.fq' if use_art else '.fa')
    if dest.exists():
        dest.unlink()

    if use_art:
        dst = str(dest.parent / dest.stem)

# Path: covest/constants.py
# DEFAULT_K = 21
# 
# Path: covest/data.py
# def sample_reads(src_reads_file, dest_reads_file, factor):
#     prob = 1.0 / factor
#     with open(dest_reads_file, 'w') as f:
#         for read_id, read in load_reads(src_reads_file):
#             if random.random() < prob:
#                 f.write('>{}\n'.format(read_id))
#                 f.write('{}\n'.format(read))
# 
# def count_reads_stats(fname):
#     s = n = 0
#     for _, read in load_reads(fname):
#         s += len(read)
#         n += 1
# 
#     ar = round(s / n) if n else 0
#     return ar, s
# 
# Path: covest/utils.py
# def run(command, shell=False, output=None, verbose=False):
#     if verbose:
#         print(command, file=sys.stderr)
#     f = open(output, 'w') if output else None
#     if not shell:
#         command = command.split()
#     return subprocess.call(command, shell=shell, stdout=f)


# Path: tools/prepare_experiment.py
import argparse
import json
import os
import shutil
import sys
from pathlib import Path
from tempfile import mkstemp
from covest.constants import DEFAULT_K
from covest.data import sample_reads as _sample_reads, count_reads_stats
from covest.utils import run

#!/usr/bin/env python3



READS_FILE_NAME_TEMPLATE = 'reads{}'
CONFIG_FILENAME = 'config.json'
HISTOGRAM_FILENAME = 'reads.hist'
RUNSCRIPT_FILENAME = 'run'
CURRENT_DIR = Path(__file__).parent


def mkdir(dest_dir, force=False):
    if not force and dest_dir.exists():
        print('Path already exists. Use --force to use it.', file=sys.stderr)
        exit(1)
    try:
        dest_dir.mkdir()
    except FileExistsError:
        pass


def get_reads_from_sequence(src_file, dest_dir, coverage, use_art=False):
    src = str(src_file.resolve())
    print('Generating reads file...', file=sys.stderr)
    dest = dest_dir / READS_FILE_NAME_TEMPLATE.format('.fq' if use_art else '.fa')
    if dest.exists():
        dest.unlink()

    if use_art:
        dst = str(dest.parent / dest.stem)

        run(