# Path: crumbs/utils/optional_modules.py
# MSG = 'A python package to run this executable is required,'
# BIO = 'biopython'
# BIO_BGZF = 'biopython with Bgzf support'
#     NCBIXML = create_fake_class(MSG + BIO)
#     NCBIWWW = create_fake_class(MSG + BIO)
# def create_fake_class(msg):
#         def __init__(self, *args, **kwargs):
# def create_fake_funct(msg):
#     def FakeRequiredfunct(*args, **kwargs):
#     class FakePythonRequiredClass(object):
# 
# Path: crumbs/utils/tags.py
# SEQITEM = 'seqitem'
# 
# SEQRECORD = 'seqrecord'
# 
# ILLUMINA_QUALITY = 'fastq-illumina'
# 
# SANGER_QUALITY = 'fastq'
# 
# SANGER_FASTQ_FORMATS = ('fastq-sanger', 'fastq')
# 
# ILLUMINA_FASTQ_FORMATS = ('fastq-illumina',)


from copy import deepcopy
from collections import namedtuple
from crumbs.utils.optional_modules import SeqRecord
from crumbs.utils.tags import (SEQITEM, SEQRECORD, ILLUMINA_QUALITY,
                               SANGER_QUALITY, SANGER_FASTQ_FORMATS,
                               ILLUMINA_FASTQ_FORMATS)


SANGER_STRS = {i - 33: chr(i)  for i in range(33, 127)}
ILLUMINA_STRS = {i - 64: chr(i) for i in range(64, 127)}


def _int_quals_to_str_quals(int_quals, out_format):
    if out_format == SANGER_QUALITY:
        quals_map = SANGER_STRS
    elif out_format == ILLUMINA_QUALITY:
        quals_map = ILLUMINA_STRS
    else:
        msg = 'Unknown or not supported quality format'
        raise ValueError(msg)
    return ''.join([quals_map[int_quality] for int_quality in int_quals])


def get_str_qualities(seq, out_format=None):
    if out_format is None:
        out_format = seq.file_format
    if out_format in SANGER_FASTQ_FORMATS:
        out_format = SANGER_QUALITY
    elif out_format in ILLUMINA_FASTQ_FORMATS:
        out_format = ILLUMINA_QUALITY

    seq_class = seq.kind
    if seq_class == SEQITEM:
        in_format = seq.file_format
        if 'fasta' in in_format:
            raise ValueError('A fasta file has no qualities')

# Path: crumbs/utils/optional_modules.py
# MSG = 'A python package to run this executable is required,'
# BIO = 'biopython'
# BIO_BGZF = 'biopython with Bgzf support'
#     NCBIXML = create_fake_class(MSG + BIO)
#     NCBIWWW = create_fake_class(MSG + BIO)
# def create_fake_class(msg):
#         def __init__(self, *args, **kwargs):
# def create_fake_funct(msg):
#     def FakeRequiredfunct(*args, **kwargs):
#     class FakePythonRequiredClass(object):
# 
# Path: crumbs/utils/tags.py
# SEQITEM = 'seqitem'
# 
# SEQRECORD = 'seqrecord'
# 
# ILLUMINA_QUALITY = 'fastq-illumina'
# 
# SANGER_QUALITY = 'fastq'
# 
# SANGER_FASTQ_FORMATS = ('fastq-sanger', 'fastq')
# 
# ILLUMINA_FASTQ_FORMATS = ('fastq-illumina',)


# Path: crumbs/seq/seq.py
from copy import deepcopy
from collections import namedtuple
from crumbs.utils.optional_modules import SeqRecord
from crumbs.utils.tags import (SEQITEM, SEQRECORD, ILLUMINA_QUALITY,
                               SANGER_QUALITY, SANGER_FASTQ_FORMATS,
                               ILLUMINA_FASTQ_FORMATS)



SANGER_STRS = {i - 33: chr(i)  for i in range(33, 127)}
ILLUMINA_STRS = {i - 64: chr(i) for i in range(64, 127)}


def _int_quals_to_str_quals(int_quals, out_format):
    if out_format == SANGER_QUALITY:
        quals_map = SANGER_STRS
    elif out_format == ILLUMINA_QUALITY:
        quals_map = ILLUMINA_STRS
    else:
        msg = 'Unknown or not supported quality format'
        raise ValueError(msg)
    return ''.join([quals_map[int_quality] for int_quality in int_quals])


def get_str_qualities(seq, out_format=None):
    if out_format is None:
        out_format = seq.file_format
    if out_format in SANGER_FASTQ_FORMATS:
        out_format = SANGER_QUALITY
    elif out_format in ILLUMINA_FASTQ_FORMATS:
        out_format = ILLUMINA_QUALITY

    seq_class = seq.kind
    if seq_class == SEQITEM:
        in_format = seq.file_format
        if 'fasta' in in_format:
            raise ValueError('A fasta file has no qualities')

        if in_format in SANGER_FASTQ_FORMATS: