# crisprverse/crisprdesign architecture

> Architecture diagram of the GitHub repository crisprverse/crisprdesign, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/crisprverse/crisprdesign
- Repository: https://github.com/crisprverse/crisprdesign

## Overview

#### Purpose and Entry Points
`crisprDesign` is a Bioconductor R package for designing and annotating CRISPR guide RNAs across DNA- and RNA-targeting modalities: knockout, activation/interference, base editing, knockdown, paired guides, and optical pooled screening. Public workflows start with `findSpacers()` or `findSpacerPairs()`, then enrich and rank returned guide objects. Package exports and S4 generics are organized in `R/AllGenerics.R`; core APIs reside under `R/`.

#### Core Domain Model
`GuideSet` is the central mutable analysis artifact: an S4 genomic-range-derived guide collection containing protospacer/PAM coordinates, spacer sequence, nuclease metadata, and progressively added annotations. `PairedGuideSet` represents paired `GuideSet` entries plus pair-level geometry.
- `R/GuideSet-class.R`
- `R/PairedGuideSet-class.R`
- `R/GuideSet2DataFrames.R`

#### Target Preparation and Candidate Discovery
Targets enter as genomic `GRanges` plus a reference genome, or as custom DNA/RNA sequences. Transcript databases can be transformed and queried into target regions. `findSpacers()` enumerates nuclease-compatible protospacer/PAM candidates; `completeSpacers()` supports completion/extension flows. This boundary separates reference sequence and nuclease definitions (provided by `crisprBase`) from package-owned guide objects.
- `R/findSpacers.R`
- `R/TxDb2GRangesList.R`
- `R/queryTxObject.R`

#### Alignment and Specificity Pipeline
Candidate guides can be aligned to genomic, transcriptomic, or custom-sequence targets. Alignment results are retained as per-guide `GRangesList` data and summarized as mismatch/context counts. `addSpacerAlignments()` dispatches to external Bowtie/BWA integrations or Biostrings matching; repeat annotation can remove or flag low-specificity candidates. Off-target scores consume these stored alignments, making alignment a required upstream stage.
- `R/addSpacerAlignments.R`
- `R/addOffTargetScores.R`
- `R/addRepeats.R`

#### Annotation and Scoring Enrichment
The pipeline decorates a `GuideSet` rather than producing separate tables. Sequence features, PAM quality, restriction sites, gene/isoform context, TSS distance, repeats, SNPs, conservation, and other genomic attributes become metadata columns. On-target scoring delegates prediction algorithms to `crisprScore`; composite and specificity-proxy stages combine annotations for selection.
- `R/addSequenceFeatures.R`
- `R/addGeneAnnotation.R`
- `R/addOnTargetScores.R`

#### Modality-Specific Branches
Base-editing workflows calculate editing sites and combinatorial predicted alleles against transcript-derived nucleotide/amino-acid tables. RNA targeting obtains mRNA sequences and uses transcript-level alignment semantics. Paired-guide design forms candidate guide pairs and records PAM orientation, distance, and cut length.
- `R/addEditedAlleles.R`
- `R/getMrnaSequence.R`
- `R/findSpacerPairs.R`

#### Selection and Library Outputs
Users may directly subset enriched `GuideSet` objects, while `rankSpacers()` applies recommended nuclease-aware prioritization. OPS-related functionality is represented in the published interface and supporting utilities/examples, providing barcode-distance and library-design workflows adjacent to core guide selection.
- `R/rankSpacers.R`
- `R/removeMultiGeneTargeting.R`
- `inst/examples/ops.R`

#### Runtime and External Boundaries
Runtime is R/Bioconductor using S4 genomic data structures (`GenomicRanges`, `Biostrings`, `BSgenome`, transcript/VCF ecosystems). `crisprBase` supplies `CrisprNuclease`/`BaseEditor` specifications; `crisprBowtie` and `crisprBwa` connect to indexed external aligners, while `crisprScore` provides scoring models. Inputs include BSgenome/custom sequences, TxDb-like annotations, Bowtie/BWA indexes, repeat ranges, and VCFs; bundled examples include FASTA and indexed VCF fixtures.
- `inst/fasta/chr12.fa`
- `inst/extdata/common_snps_dbsnp151_example.vcf.gz`
- `DESCRIPTION`

Main entry points: [`R/GuideSet-class.R`](https://github.com/crisprverse/crisprdesign/blob/devel/R/GuideSet-class.R) (GuideSet), [`R/findSpacers.R`](https://github.com/crisprverse/crisprdesign/blob/devel/R/findSpacers.R) (Spacer discovery), [`R/addSpacerAlignments.R`](https://github.com/crisprverse/crisprdesign/blob/devel/R/addSpacerAlignments.R) (Spacer alignments), [`R/rankSpacers.R`](https://github.com/crisprverse/crisprdesign/blob/devel/R/rankSpacers.R) (Guide ranking)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_discovery["Targeting &amp; Discovery"]
  node_public_api["Public APIs &amp; S4 generics<br/>R API<br/>[AllGenerics.R]"]
  node_target_regions["Target region preparation<br/>R transformation<br/>[TxDb2GRangesList.R]"]
  node_guide_set["GuideSet<br/>S4 guide collection<br/>[GuideSet-class.R]"]
  node_spacer_discovery["Spacer discovery<br/>R workflow<br/>[findSpacers.R]"]
end

subgraph group_enrichment["Annotation &amp; Specificity"]
  node_alignments["Spacer alignments<br/>GuideSet annotation"]
  node_specificity["Repeats &amp; off-target scores<br/>GuideSet annotation"]
  node_feature_annotation["Sequence &amp; gene annotation<br/>GuideSet annotation"]
  node_on_target["On-target scoring<br/>scoring integration"]
end

subgraph group_modalities["Specialized Design"]
  node_paired_guide_set["PairedGuideSet<br/>S4 paired guides"]
  node_pair_design["Paired-guide design<br/>R workflow<br/>[findSpacerPairs.R]"]
  node_edited_alleles["Base-edit allele prediction<br/>base-edit workflow<br/>[addEditedAlleles.R]"]
  node_mrna["mRNA sequence retrieval<br/>RNA-targeting workflow<br/>[getMrnaSequence.R]"]
end

subgraph group_selection["Selection &amp; Library"]
  node_ranking["Guide ranking<br/>selection workflow<br/>[rankSpacers.R]"]
  node_selected_guides["Selected GuideSet<br/>analysis output"]
  node_ops["OPS library design<br/>library workflow<br/>[ops.R]"]
end

subgraph group_external["Runtime Boundaries"]
  node_targets[("Genome, sequences &amp; annotations<br/>input data")]
  node_nucleases{{"crisprBase specifications<br/>dependency"}}
  node_aligners{{"Bowtie/BWA &amp; Biostrings<br/>alignment boundary"}}
  node_crispr_score{{"crisprScore models<br/>dependency"}}
end

node_public_api -->|"starts"| node_spacer_discovery
node_public_api -->|"starts"| node_pair_design
node_targets -->|"annotations"| node_target_regions
node_targets -->|"reference sequences"| node_spacer_discovery
node_nucleases -->|"PAM/editing rules"| node_spacer_discovery
node_target_regions -->|"target regions"| node_spacer_discovery
node_spacer_discovery -->|"candidate guides"| node_guide_set
node_guide_set -->|"pair candidates"| node_pair_design
node_pair_design -->|"guide pairs"| node_paired_guide_set
node_guide_set -->|"guides"| node_alignments
node_targets -->|"indexes/custom targets"| node_aligners
node_aligners -->|"alignment hits"| node_alignments
node_alignments -->|"stored off-targets"| node_specificity
node_guide_set -->|"decorate"| node_feature_annotation
node_guide_set -->|"sequence features"| node_on_target
node_crispr_score -->|"prediction models"| node_on_target
node_feature_annotation -->|"context features"| node_ranking
node_specificity -->|"specificity metrics"| node_ranking
node_on_target -->|"activity scores"| node_ranking
node_ranking -->|"prioritized guides"| node_selected_guides
node_guide_set -->|"base-editor guides"| node_edited_alleles
node_targets -->|"transcript annotations"| node_mrna
node_mrna -.->|"RNA targets"| node_alignments
node_selected_guides -->|"library candidates"| node_ops

click node_public_api "https://github.com/crisprverse/crisprdesign/blob/devel/R/AllGenerics.R"
click node_target_regions "https://github.com/crisprverse/crisprdesign/blob/devel/R/TxDb2GRangesList.R"
click node_guide_set "https://github.com/crisprverse/crisprdesign/blob/devel/R/GuideSet-class.R"
click node_spacer_discovery "https://github.com/crisprverse/crisprdesign/blob/devel/R/findSpacers.R"
click node_paired_guide_set "https://github.com/crisprverse/crisprdesign/blob/devel/R/PairedGuideSet-class.R"
click node_pair_design "https://github.com/crisprverse/crisprdesign/blob/devel/R/findSpacerPairs.R"
click node_alignments "https://github.com/crisprverse/crisprdesign/blob/devel/R/addSpacerAlignments.R"
click node_specificity "https://github.com/crisprverse/crisprdesign/blob/devel/R/addOffTargetScores.R"
click node_feature_annotation "https://github.com/crisprverse/crisprdesign/blob/devel/R/addGeneAnnotation.R"
click node_on_target "https://github.com/crisprverse/crisprdesign/blob/devel/R/addOnTargetScores.R"
click node_edited_alleles "https://github.com/crisprverse/crisprdesign/blob/devel/R/addEditedAlleles.R"
click node_mrna "https://github.com/crisprverse/crisprdesign/blob/devel/R/getMrnaSequence.R"
click node_ranking "https://github.com/crisprverse/crisprdesign/blob/devel/R/rankSpacers.R"
click node_selected_guides "https://github.com/crisprverse/crisprdesign/blob/devel/R/removeMultiGeneTargeting.R"
click node_ops "https://github.com/crisprverse/crisprdesign/blob/devel/inst/examples/ops.R"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_public_api,node_target_regions,node_guide_set,node_spacer_discovery toneBlue
class node_alignments,node_specificity,node_feature_annotation,node_on_target toneAmber
class node_paired_guide_set,node_pair_design,node_edited_alleles,node_mrna toneMint
class node_ranking,node_selected_guides,node_ops toneRose
class node_targets,node_nucleases,node_aligners,node_crispr_score toneIndigo
```

## Components

### Targeting & Discovery

- [Public APIs & S4 generics](https://github.com/crisprverse/crisprdesign/blob/devel/R/AllGenerics.R): R API · Exports organize the guide-design workflows. · `R/AllGenerics.R`
- [Target region preparation](https://github.com/crisprverse/crisprdesign/blob/devel/R/TxDb2GRangesList.R): R transformation · Converts and queries transcript annotations into target regions. · `R/TxDb2GRangesList.R`
- [GuideSet](https://github.com/crisprverse/crisprdesign/blob/devel/R/GuideSet-class.R): S4 guide collection · Mutable genomic-range guide artifact with accumulated annotations. · `R/GuideSet-class.R`
- [Spacer discovery](https://github.com/crisprverse/crisprdesign/blob/devel/R/findSpacers.R): R workflow · Enumerates or completes nuclease-compatible protospacer/PAM candidates. · `R/findSpacers.R`

### Annotation & Specificity

- [Spacer alignments](https://github.com/crisprverse/crisprdesign/blob/devel/R/addSpacerAlignments.R): GuideSet annotation · Stores per-guide GRangesList hits and mismatch/context summaries. · `R/addSpacerAlignments.R`
- [Repeats & off-target scores](https://github.com/crisprverse/crisprdesign/blob/devel/R/addOffTargetScores.R): GuideSet annotation · Flags repetitive targeting and scores stored off-target alignments. · `R/addOffTargetScores.R`
- [Sequence & gene annotation](https://github.com/crisprverse/crisprdesign/blob/devel/R/addGeneAnnotation.R): GuideSet annotation · Adds sequence, PAM, genomic, gene, isoform, and TSS features. · `R/addGeneAnnotation.R`
- [On-target scoring](https://github.com/crisprverse/crisprdesign/blob/devel/R/addOnTargetScores.R): scoring integration · Delegates guide activity prediction to crisprScore. · `R/addOnTargetScores.R`

### Specialized Design

- [PairedGuideSet](https://github.com/crisprverse/crisprdesign/blob/devel/R/PairedGuideSet-class.R): S4 paired guides · Stores paired guides and pair-level geometry. · `R/PairedGuideSet-class.R`
- [Paired-guide design](https://github.com/crisprverse/crisprdesign/blob/devel/R/findSpacerPairs.R): R workflow · Forms pairs with PAM orientation, distance, and cut length. · `R/findSpacerPairs.R`
- [Base-edit allele prediction](https://github.com/crisprverse/crisprdesign/blob/devel/R/addEditedAlleles.R): base-edit workflow · Calculates editing sites and predicted transcript alleles. · `R/addEditedAlleles.R`
- [mRNA sequence retrieval](https://github.com/crisprverse/crisprdesign/blob/devel/R/getMrnaSequence.R): RNA-targeting workflow · Obtains transcript sequences for RNA-targeting semantics. · `R/getMrnaSequence.R`

### Selection & Library

- [Guide ranking](https://github.com/crisprverse/crisprdesign/blob/devel/R/rankSpacers.R): selection workflow · Applies nuclease-aware prioritization to enriched guides. · `R/rankSpacers.R`
- [Selected GuideSet](https://github.com/crisprverse/crisprdesign/blob/devel/R/removeMultiGeneTargeting.R): analysis output · Users can subset or filter guides for downstream use. · `R/removeMultiGeneTargeting.R`
- [OPS library design](https://github.com/crisprverse/crisprdesign/blob/devel/inst/examples/ops.R): library workflow · Provides barcode-distance and optical pooled screening utilities. · `inst/examples/ops.R`

### Runtime Boundaries

- **Genome, sequences & annotations**: input data
- **crisprBase specifications**: dependency · Provides nuclease and base-editor definitions.
- **Bowtie/BWA & Biostrings**: alignment boundary · External indexed aligners or in-process sequence matching.
- **crisprScore models**: dependency

## Connections

- Public APIs & S4 generics → Spacer discovery: starts
- Public APIs & S4 generics → Paired-guide design: starts
- Genome, sequences & annotations → Target region preparation: annotations
- Genome, sequences & annotations → Spacer discovery: reference sequences
- crisprBase specifications → Spacer discovery: PAM/editing rules
- Target region preparation → Spacer discovery: target regions
- Spacer discovery → GuideSet: candidate guides
- GuideSet → Paired-guide design: pair candidates
- Paired-guide design → PairedGuideSet: guide pairs
- GuideSet → Spacer alignments: guides
- Genome, sequences & annotations → Bowtie/BWA & Biostrings: indexes/custom targets
- Bowtie/BWA & Biostrings → Spacer alignments: alignment hits
- Spacer alignments → Repeats & off-target scores: stored off-targets
- GuideSet → Sequence & gene annotation: decorate
- GuideSet → On-target scoring: sequence features
- crisprScore models → On-target scoring: prediction models
- Sequence & gene annotation → Guide ranking: context features
- Repeats & off-target scores → Guide ranking: specificity metrics
- On-target scoring → Guide ranking: activity scores
- Guide ranking → Selected GuideSet: prioritized guides
- GuideSet → Base-edit allele prediction: base-editor guides
- Genome, sequences & annotations → mRNA sequence retrieval: transcript annotations
- mRNA sequence retrieval → Spacer alignments: RNA targets
- Selected GuideSet → OPS library design: library candidates
