This folder contains a CLI for predicting CRISPR array direction. It is based on a finetuned version of the Carbon-500m model, which was finetuned on the predictions of CRISPR-evOr.
It is intended for inference only.
Recommended: create a dedicated virtual environment first.
Conda:
conda create -n crispr-evOr-direction python=3.12 -y
conda activate crispr-evOr-direction
pip install -r requirements.txt
For the first run you can test, if everything works on your end with this example array:
python predict_direction.py \
--input_file example_array.json \
--allow_downloads
After the first run it can be run without the --allow_downloads flag, as it downloads base model weights to model_params/base_model_cache and resuses them from there.
The tool will:
prediction_result.json next to the input file.Lookup is optional and runs only when you pass --lookup.
When enabled, the CLI looks up your query array in the bundled train/val DB and reports:
The lookup uses spacers + repeats for exact match and spacer similarity for nearest-neighbor reporting.
The lookup DB path is lookup/array_lookup_db.json.
Enable lookup explicitly with --lookup:
python predict_direction.py \
--input_file example_array.json \
--lookup
Default behavior:
Overrides:
--cpu forces CPU.--gpu forces GPU and errors if CUDA is unavailable.--allow_downloads allows first-run download of base model weights when local full weights are
missing.Important for first run:
--allow_downloads if model_params/base_model_cache does not already contain full base weights.Example object:
{
"array_name":"my_array",
"repeats": ["..."],
"spacers": ["..."]
}
Here spacers and repeats have to be in order and there have to be multiple repeats. If only one repeat occurs, still provide that #spacers+1 times, like in the provided example_array.json. If any are missing, that degrades the quality of the prediction.
Notes:
--ccf)You can pass Results from CRISPRCasFinder directly, for that only the result.json file is used.
Example:
python predict_direction.py \
--input_file Result_XXX/result.json \
--ccf
If multiple entries exist, select which one to predict:
python predict_direction.py \
--input_file Result_XXX/result.json \
--ccf \
--ccf_sequence_index 0 \
--ccf_crispr_index 0
CCF extraction mapping used by the script:
Sequences[i].Crisprs[j].Regions entries with Type=DR -> repeatsType=Spacer -> spacersType=LeftFLANK / Type=RightFLANK -> flanksDR_Consensus is used as fallbackAlways text summary, for example:
Predicted direction is "Forward" with probability 0.991 (99.1%).
Alternative direction "Reverse" has probability 0.009 (0.9%).
Input summary: repeats=31, spacers=30, tokens=367.
Array name: NZ_CP123870_1
Input file: <project-root>/test_out/Result_XXX/result.json
Saved result JSON to: <project-root>/test_out/Result_XXX/prediction_result.json
Location:
<input_file_directory>/prediction_result.json--result_file path/to/result.jsonCore fields in output JSON:
input_mode (standard or ccf)input_filemodel_dirbase_modeldevicearray_name, cas_subtype (if provided in input)predicted_label_id, predicted_labelprob_reverse, prob_forwardtoken_countlookup block (only when --lookup is used), containing exact train/val presence or nearest similaritiesccf metadata block (present only with --ccf)Label mapping:
1 = Forward0 = Reversepython predict_direction.py --input_file PATH [options]
Options:
--input_file PATH (required): Input JSON or JSONL.--ccf: Interpret input as CRISPRCasFinder result.json.--ccf_sequence_index N: CCF Sequences index (default 0).--ccf_crispr_index M: CCF Crisprs index within the selected sequence (default 0).--model_dir PATH: Model directory (default: Standalone/model_params).--max_length N: Tokenizer truncation length (default 256).--cpu: Force CPU.--gpu: Force GPU (fails if CUDA is unavailable).--result_file PATH: Custom output JSON path.--allow_downloads: Allow online fallback if local assets are missing.--lookup: Enable lookup against bundled train/val DB (off by default for faster inference).LoRA runtime notes:
adapter_config.json and adapter_model.safetensors exist in model_params, the adapter is
loaded automatically.peft is not installed, install it with:pip install peft
Custom JSON:
python predict_direction.py \
--input_file my_array.json
Force CPU and custom result path:
python predict_direction.py \
--input_file my_array.json \
--cpu \
--result_file my_array_prediction.json
Predictor script: predict_direction.py
LoRA adapter + tokenizer assets: model_params
Bundled train/val lookup DB: lookup/array_lookup_db.json
If full base weights are already cached in model_params/base_model_cache, they are reused.
If full weights are missing, the script downloads it from Hugging Face on first run,
and stores the weights in model_params/base_model_cache.
If adapter files are present (adapter_config.json + adapter_model.safetensors), LoRA is
applied automatically on top of the cached base model.
--gpu was requested, but CUDA is not available:
--cpu.FileNotFoundError: No full model weights found:
Input validation errors:
repeats and spacers are lists of strings and the file has enough repeats in the list.Sequences -> Crisprs -> Regions.Unexpected downloads:
--allow_downloads when offline-only behavior is required.Tranformers warning:
Key | Status | -------------+---------+- score.weight | MISSING |
6 commits
Python
100.0%
This folder contains a CLI for predicting CRISPR array direction. It is based on a finetuned version of the Carbon-500m model, which was finetuned on the predictions of CRISPR-evOr.
It is intended for inference only.
Recommended: create a dedicated virtual environment first.
Conda:
conda create -n crispr-evOr-direction python=3.12 -y
conda activate crispr-evOr-direction
pip install -r requirements.txt
For the first run you can test, if everything works on your end with this example array:
python predict_direction.py \
--input_file example_array.json \
--allow_downloads
After the first run it can be run without the --allow_downloads flag, as it downloads base model weights to model_params/base_model_cache and resuses them from there.
The tool will:
prediction_result.json next to the input file.Lookup is optional and runs only when you pass --lookup.
When enabled, the CLI looks up your query array in the bundled train/val DB and reports:
The lookup uses spacers + repeats for exact match and spacer similarity for nearest-neighbor reporting.
The lookup DB path is lookup/array_lookup_db.json.
Enable lookup explicitly with --lookup:
python predict_direction.py \
--input_file example_array.json \
--lookup
Default behavior:
Overrides:
--cpu forces CPU.--gpu forces GPU and errors if CUDA is unavailable.--allow_downloads allows first-run download of base model weights when local full weights are
missing.Important for first run:
--allow_downloads if model_params/base_model_cache does not already contain full base weights.Example object:
{
"array_name":"my_array",
"repeats": ["..."],
"spacers": ["..."]
}
Here spacers and repeats have to be in order and there have to be multiple repeats. If only one repeat occurs, still provide that #spacers+1 times, like in the provided example_array.json. If any are missing, that degrades the quality of the prediction.
Notes:
--ccf)You can pass Results from CRISPRCasFinder directly, for that only the result.json file is used.
Example:
python predict_direction.py \
--input_file Result_XXX/result.json \
--ccf
If multiple entries exist, select which one to predict:
python predict_direction.py \
--input_file Result_XXX/result.json \
--ccf \
--ccf_sequence_index 0 \
--ccf_crispr_index 0
CCF extraction mapping used by the script:
Sequences[i].Crisprs[j].Regions entries with Type=DR -> repeatsType=Spacer -> spacersType=LeftFLANK / Type=RightFLANK -> flanksDR_Consensus is used as fallbackAlways text summary, for example:
Predicted direction is "Forward" with probability 0.991 (99.1%).
Alternative direction "Reverse" has probability 0.009 (0.9%).
Input summary: repeats=31, spacers=30, tokens=367.
Array name: NZ_CP123870_1
Input file: <project-root>/test_out/Result_XXX/result.json
Saved result JSON to: <project-root>/test_out/Result_XXX/prediction_result.json
Location:
<input_file_directory>/prediction_result.json--result_file path/to/result.jsonCore fields in output JSON:
input_mode (standard or ccf)input_filemodel_dirbase_modeldevicearray_name, cas_subtype (if provided in input)predicted_label_id, predicted_labelprob_reverse, prob_forwardtoken_countlookup block (only when --lookup is used), containing exact train/val presence or nearest similaritiesccf metadata block (present only with --ccf)Label mapping:
1 = Forward0 = Reversepython predict_direction.py --input_file PATH [options]
Options:
--input_file PATH (required): Input JSON or JSONL.--ccf: Interpret input as CRISPRCasFinder result.json.--ccf_sequence_index N: CCF Sequences index (default 0).--ccf_crispr_index M: CCF Crisprs index within the selected sequence (default 0).--model_dir PATH: Model directory (default: Standalone/model_params).--max_length N: Tokenizer truncation length (default 256).--cpu: Force CPU.--gpu: Force GPU (fails if CUDA is unavailable).--result_file PATH: Custom output JSON path.--allow_downloads: Allow online fallback if local assets are missing.--lookup: Enable lookup against bundled train/val DB (off by default for faster inference).LoRA runtime notes:
adapter_config.json and adapter_model.safetensors exist in model_params, the adapter is
loaded automatically.peft is not installed, install it with:pip install peft
Custom JSON:
python predict_direction.py \
--input_file my_array.json
Force CPU and custom result path:
python predict_direction.py \
--input_file my_array.json \
--cpu \
--result_file my_array_prediction.json
Predictor script: predict_direction.py
LoRA adapter + tokenizer assets: model_params
Bundled train/val lookup DB: lookup/array_lookup_db.json
If full base weights are already cached in model_params/base_model_cache, they are reused.
If full weights are missing, the script downloads it from Hugging Face on first run,
and stores the weights in model_params/base_model_cache.
If adapter files are present (adapter_config.json + adapter_model.safetensors), LoRA is
applied automatically on top of the cached base model.
--gpu was requested, but CUDA is not available:
--cpu.FileNotFoundError: No full model weights found:
Input validation errors:
repeats and spacers are lists of strings and the file has enough repeats in the list.Sequences -> Crisprs -> Regions.Unexpected downloads:
--allow_downloads when offline-only behavior is required.Tranformers warning:
Key | Status | -------------+---------+- score.weight | MISSING |
6 commits
Python
100.0%