'Uses a Table of Contents dict, parsed from an FQTOC file, to come up with a set of
shell commands that will extract the parts necessary
>>> three_sections=[dict(start=0, end=74, sequences=10), dict(start=74, end=148, sequences=10), dict(start=148, end=148+76, sequences=10)]
>>> Sequence.get_split_commands_with_toc(\'./input.gz\', \'./output.gz\', dict(sections=three_sections), start_sequence=0, sequence_count=10)
[\'dd bs=1 skip=0 count=74 if=./input.gz 2> /dev/null >> ./output.gz\']
>>> Sequence.get_split_commands_with_toc(\'./input.gz\', \'./output.gz\', dict(sections=three_sections), start_sequence=1, sequence_count=5)
[\'(dd bs=1 skip=0 count=74 if=./input.gz 2> /dev/null )| zcat | ( tail -n +5 2> /dev/null) | head -20 | gzip -c >> ./output.gz\']
>>> Sequence.get_split_commands_with_toc(\'./input.gz\', \'./output.gz\', dict(sections=three_sections), start_sequence=0, sequence_count=20)
[\'dd bs=1 skip=0 count=148 if=./input.gz 2> /dev/null >> ./output.gz\']
>>> Sequence.get_split_commands_with_toc(\'./input.gz\', \'./output.gz\', dict(sections=three_sections), start_sequence=5, sequence_count=10)
[\'(dd bs=1 skip=0 count=74 if=./input.gz 2> /dev/null )| zcat | ( tail -n +21 2> /dev/null) | head -20 | gzip -c >> ./output.gz\', \'(dd bs=1 skip=74 count=74 if=./input.gz 2> /dev/null )| zcat | ( tail -n +1 2> /dev/null) | head -20 | gzip -c >> ./output.gz\']
>>> Sequence.get_split_commands_with_toc(\'./input.gz\', \'./output.gz\', dict(sections=three_sections), start_sequence=10, sequence_count=10)
[\'dd bs=1 skip=74 count=74 if=./input.gz 2> /dev/null >> ./output.gz\']
>>> Sequence.get_split_commands_with_toc(\'./input.gz\', \'./output.gz\', dict(sections=three_sections), start_sequence=5, sequence_count=20)
[\'(dd bs=1 skip=0 count=74 if=./input.gz 2> /dev/null )| zcat | ( tail -n +21 2> /dev/null) | head -20 | gzip -c >> ./output.gz\', \'dd bs=1 skip=74 count=74 if=./input.gz 2> /dev/null >> ./output.gz\', \'(dd bs=1 skip=148 count=76 if=./input.gz 2> /dev/null )| zcat | ( tail -n +1 2> /dev/null) | head -20 | gzip -c >> ./output.gz\']'

def get_split_commands_with_toc(input_name, output_name, toc_file, start_sequence, sequence_count):

    sections = toc_file['sections']
    result = []
    current_sequence = long(0)
    i = 0
    while ((i < len(sections)) and (start_sequence >= (current_sequence + long(sections[i]['sequences'])))):
        current_sequence += long(sections[i]['sequences'])
        i += 1
    if (i == len(sections)):
        raise Exception(('No    FQTOC    section    contains    starting    sequence    %s' % start_sequence))
    start_chunk = long((-1))
    end_chunk = long((-1))
    copy_chunk_cmd = 'dd    bs=1    skip=%s    count=%s    if=%s    2>    /dev/null    >>    %s'
    while ((sequence_count > 0) and (i < len(sections))):
        sequences = long(sections[i]['sequences'])
        skip_sequences = (start_sequence - current_sequence)
        sequences_to_extract = min(sequence_count, (sequences - skip_sequences))
        start_copy = long(sections[i]['start'])
        end_copy = long(sections[i]['end'])
        if (sequences_to_extract < sequences):
            if (start_chunk > (-1)):
                result.append((copy_chunk_cmd % (start_chunk, (end_chunk - start_chunk), input_name, output_name)))
                start_chunk = (-1)
            result.append(('(dd    bs=1    skip=%s    count=%s    if=%s    2>    /dev/null    )|    zcat    |    (    tail    -n    +%s    2>    /dev/null)    |    head    -%s    |    gzip    -c    >>    %s' % (start_copy, (end_copy - start_copy), input_name, ((skip_sequences * 4) + 1), (sequences_to_extract * 4), output_name)))
        else:
            if (start_chunk == (-1)):
                start_chunk = start_copy
            end_chunk = end_copy
        sequence_count -= sequences_to_extract
        start_sequence += sequences_to_extract
        current_sequence += sequences
        i += 1
    if (start_chunk > (-1)):
        result.append((copy_chunk_cmd % (start_chunk, (end_chunk - start_chunk), input_name, output_name)))
    if (sequence_count > 0):
        raise Exception(('%s    sequences    not    found    in    file' % sequence_count))
    return result
