import re


def get_daligner_job_descriptions(run_jobs_stream, db_prefix, single=False):
    """Return a dict of job-desc-tuple -> HPCdaligner bash-job.

    Comments are ignored.

    E.g., each item will look like:
      ('.2', '.1', '.2', '.3'): 'daligner

    Rationale
    ---------
    For i/o efficiency, we want to daligner calls with LAsort/LAmerge lines. But
    Gene has done this himself too. So now, we only want the daligner calls here.

    Later, we will do the extra LAmerge lines, grouped by A-read.
    """
    re_block_dali = re.compile(r'%s(\.\d+|)' % db_prefix)

    def blocks_dali(line):
        """Return ['.1', '.2', ...]
        Can return [''] if only 1 block.
        """
        return [mo.group(1) for mo in re_block_dali.finditer(line)]
    # X == blocks[0]; A/B/C = blocks[...]

    lines = [line.strip() for line in run_jobs_stream]
    # in case caller passed filename, not stream
    assert any(len(l) > 1 for l in lines), repr('\n'.join(lines))

    lines_dali = [l for l in lines if l.startswith(
        'daligner')]  # could be daligner_p
    result = {}
    for dali in lines_dali:
        id = tuple(blocks_dali(dali))
        early_checks = [
            "LAcheck -v {db_prefix} *.las".format(db_prefix=db_prefix)]
        script = '\n'.join([dali] + early_checks) + '\n'
        result[id] = script
    return result