Skip to content

crispr_analysis_utils.gem_mapper.build_gem_index

crispr_analysis_utils.gem_mapper.build_gem_index

build_gem_index(reference_fasta: str | Path, index_prefix: str | Path, *, threads: int | None = None, gem_indexer_bin: str = 'gem-indexer', log_path: str | Path | None = None) -> str

Build a GEM index from a reference FASTA.

Source code in src/crispr_analysis_utils/gem_mapper.py
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
def build_gem_index(
    reference_fasta: str | Path,
    index_prefix: str | Path,
    *,
    threads: int | None = None,
    gem_indexer_bin: str = "gem-indexer",
    log_path: str | Path | None = None,
) -> str:
    """Build a GEM index from a reference FASTA."""
    cmd = [
        gem_indexer_bin,
        "-i",
        str(reference_fasta),
        "-o",
        str(index_prefix),
    ]
    if threads is not None:
        cmd.extend(["-t", str(threads)])
    cmd_str = " ".join(shlex.quote(token) for token in cmd)
    if log_path is not None:
        cmd_str = f"{cmd_str} > {shlex.quote(str(log_path))} 2>&1"
    return run_shell_cmd(cmd_str)