def detokenize_enzymatic_reaction_smiles(rxn: str) -> str:
    """Detokenize an enzymatic reaction SMILES in the form precursors|EC>>products.

    Args:
        rxn: a tokenized enzymatic reaction SMILES.

    Returns:
        the detokenized enzymatic reaction SMILES.
    """
    rxn = rxn.replace(" ", "")

    if "[v" in rxn and "|" not in rxn:
        pipe_index = rxn.index("[v")
        if pipe_index > -1:
            rxn = rxn[:pipe_index] + "|" + rxn[pipe_index:]

    if "[v" not in rxn and "|" in rxn:
        rxn = rxn.replace("|", "")

    if "|" not in rxn:
        return rxn

    precursor_split = rxn.split("|")

    if len(precursor_split) < 2:
        return ""

    reaction_split = precursor_split[1].split(">>")

    if len(reaction_split) < 2:
        return ""

    ec = (
        reaction_split[0]
        .replace("][", ".")
        .replace("[v", "")
        .replace("u", "")
        .replace("t", "")
        .replace("q", "")
        .replace("]", "")
    )

    return precursor_split[0] + "|" + ec + ">>" + reaction_split[1]