Source code for py_crispr_analyser.search

# Copyright (C) 2025-2026 Genome Research Ltd.

import getopt
import numpy as np
import sys

from .utils import (
    FILE_VERSION,
    HEADER_SIZE,
    METADATA_SIZE,
    check_file_header,
    get_guides,
    get_file_metadata,
    print_metadata,
    sequence_to_binary_encoding,
    reverse_complement,
)






[docs] def run(argv=sys.argv[1:]) -> None: """Run the search command from the command line. :param argv: The command line arguments :return: None """ inputfile = "" sequence = "" def usage() -> None: print( """Usage: crispr_analyser_search [options...] -h, --help Print this help message -i, --ifile <file> The input binary guides file -s, --sequence <str> The guide sequence to search for """ ) try: opts, _ = getopt.getopt( argv, "hi:s:", [ "help", "ifile=", "sequence=", ], ) except getopt.GetoptError as err: print(err) usage() sys.exit(2) for opt, arg in opts: if opt in ("-h", "--help"): usage() sys.exit() elif opt in ("-i", "--ifile"): inputfile = arg elif opt in ("-s", "--sequence"): sequence = arg if inputfile == "" or sequence == "": usage() sys.exit(2) with open(inputfile, "rb") as in_file: check_file_header(in_file.read(HEADER_SIZE)) print(f"Version is {FILE_VERSION}", file=sys.stderr) metadata = get_file_metadata(in_file.read(METADATA_SIZE)) print_metadata(metadata) guides = get_guides(in_file, verbose=True) print(f"Loaded {guides.size} sequences", file=sys.stderr) indices = search( guides=guides, sequence=sequence, ) print(f"Found {len(indices)} exact matches", file=sys.stderr) print("Found the following matches:", file=sys.stderr) for idx in indices: print(f"\t{idx + metadata.offset}")