def create_domain_sequence(domains, keep_unknown=True, fmt_fn=lambda x: x):
    """
    We can pass a <fmt_fn> to reformat domain names (e.g. turn PF07005.14
    into PF07005). By default, the identity function is used, which just
    returns the input as is.

    If <keep_unknown>, all ORFs w/o domain calls are turned into "unknown"
    domains, 1 per ORF.
    """
    from collections import defaultdict
    from nanotext.utils import split_orf_uid
    d = defaultdict(list)
    for i in domains:
        d[split_orf_uid(i.fields[0])].append(fmt_fn(i.fields[3]))
    result = defaultdict(list)
    cache_orf = 0
    cache_contig = ''
    for k, v in sorted(d.items()):
        contig, orf = k
        if cache_contig != contig:
            cache_contig = contig
            cache_orf = 0
        if keep_unknown and cache_orf + 1 != orf:
            result[contig].extend(['unknown'] * (orf - cache_orf - 1))
        result[contig].extend(v)
        cache_orf = orf
    return result
