# Path: covest/data.py
# def load_reads(fname):
#     _, ext = path.splitext(fname)
#     fmt = 'fasta'
#     if ext == '.fq' or ext == '.fastq':
#         fmt = 'fastq'
#     try:
#         with open(fname, "rU") as f:
#             for read in SeqIO.parse(f, fmt):
#                 yield read.id, read.seq
#     except FileNotFoundError as e:
#         verbose_print(e)


import random
import argparse
from os import path
from Bio import SeqIO
from covest.data import load_reads
        'W': ('A', 'T'),
        'S': ('C', 'G'),
        'M': ('A', 'C'),
        'K': ('G', 'T'),
        'R': ('A', 'G'),
        'Y': ('C', 'T'),
        'B': ('C', 'G', 'T'),
        'D': ('A', 'G', 'T'),
        'H': ('A', 'C', 'T'),
        'V': ('A', 'C', 'G'),
        'N': ('A', 'C', 'G', 'T'),
    }

    def subst(ch):
        if ch in BASES:
            return ch
        else:
            return random.choice(subst_table[ch])

    return ''.join(
        subst(ch) for ch in sequence
    )


def main(fname, genome_file, read_length, error_rate, coverage, error_free_fname=None,
         substitude_nucleotides=False):
    total_genome_size = 0
    with open(fname, 'w') as f:
        if error_free_fname:
            eff = open(error_free_fname, 'w')

# Path: covest/data.py
# def load_reads(fname):
#     _, ext = path.splitext(fname)
#     fmt = 'fasta'
#     if ext == '.fq' or ext == '.fastq':
#         fmt = 'fastq'
#     try:
#         with open(fname, "rU") as f:
#             for read in SeqIO.parse(f, fmt):
#                 yield read.id, read.seq
#     except FileNotFoundError as e:
#         verbose_print(e)


# Path: tools/simulator/read_simulator.py
import random
import argparse
from os import path
from Bio import SeqIO
from covest.data import load_reads

        'W': ('A', 'T'),
        'S': ('C', 'G'),
        'M': ('A', 'C'),
        'K': ('G', 'T'),
        'R': ('A', 'G'),
        'Y': ('C', 'T'),
        'B': ('C', 'G', 'T'),
        'D': ('A', 'G', 'T'),
        'H': ('A', 'C', 'T'),
        'V': ('A', 'C', 'G'),
        'N': ('A', 'C', 'G', 'T'),
    }

    def subst(ch):
        if ch in BASES:
            return ch
        else:
            return random.choice(subst_table[ch])

    return ''.join(
        subst(ch) for ch in sequence
    )


def main(fname, genome_file, read_length, error_rate, coverage, error_free_fname=None,
         substitude_nucleotides=False):
    total_genome_size = 0
    with open(fname, 'w') as f:
        if error_free_fname:
            eff = open(error_free_fname, 'w')

        for genome_id, genome in load_reads(genome_file):