DNA Chisel

repository·master·Indexed 42 days ago

https://github.com/edinburgh-genome-foundry/dnachisel

A Python library for optimizing DNA sequences under constraints. Version 3.2.16 allows users to satisfy specific rules—such as avoiding restriction sites, preventing hairpins, or tuning GC content—while maximizing objectives like codon optimization (e.g., MaximizeCAI, MatchTargetCodonUsage, and HarmonizeRCA). It features a core DnaOptimizationProblem solver, a biotools module for sequence manipulation, and support for GenBank files via a CLI.

Tokens
11K
Snippets
41
Records
61
Agent score
54%

What's inside DNA Chisel

  1. Explore DNA Chisel code organization

    master

    The DNA Chisel repository is organized into several functional modules:

    • biotools/: Biology-related methods and data tables for sequence manipulation.
    • builtin_specifications/: A collection of ready-to-use Specification subclasses (e.g., CodonOptimize, EnforceGCContent).
    • DnaOptimizationProblem/: Contains the core solver logic, organized into mixins to manage the complexity of the DnaOptimizationProblem class.
    • MutationSpace/: Implementation of mutation management logic.
    • reports/: Tools for generating plots and PDF reports summarizing optimization results.
    • Specification/: Core implementation of the Specification and SpecEvaluation classes.
    • utils/: Generic utility functions, such as random_compatible_dna_sequence() for generating sequences that satisfy specific constraints.
    • Location_py and SequencePattern_py: Core implementations for sequence segments and pattern matching.
  2. Understand the Bio data files in dnachisel

    master

    The dnachisel/biotools/data directory contains CSV files used for nucleotide mapping and pattern matching. These files define how IUPAC notation is handled during sequence optimization:

    • complements.csv: Maps nucleotides to their reverse complements. This includes support for degenerate IUPAC notation (e.g., M maps to K, R maps to Y).
    • iupac_notation.csv: Maps each IUPAC character to the specific ATGC nucleotides it represents (e.g., B maps to CGT).
    • nucleotide_to_regexpr.csv: Maps each IUPAC character to a regular expression string representing all possible matching characters in the IUPAC alphabet (e.g., W maps to [ATW]).
  3. How DNA Chisel works

    master

    DNA Chisel is a Python library designed for optimizing DNA sequences. It works by allowing users to compose over 15 classes of sequence specifications. These specifications can be used to:

    • Codon-optimize genes.
    • Meet specific constraints of commercial DNA providers.
    • Avoid homologies between sequences.
    • Tune GC content.

    Users can define problems programmatically in Python or by annotating Genbank files.

  4. Available Codon Optimization specifications

    master

    DNAChisel provides several classes to implement different codon optimization strategies found in literature. You can choose a specific class or use the generic CodonOptimize class with a mode parameter to select one of the following behaviors:

    • MaximizeCAI: Attempts to replace every codon with the "best synonymous codon" (the most frequent codon in the target species).
    • MatchTargetCodonUsage: Optimizes the sequence so its codon usage frequency profile matches that of the target species.
    • HarmonizeRCA: Ensures that codons that were rare in the original sequence's species remain rare in the final sequence for the target species (codon usage harmonization).

    CRITICAL USAGE NOTE: When using these specifications, you must always use them in conjunction with an EnforceTranslation constraint defined over the same location. This ensures that the optimization process preserves the original amino acid sequence.

  5. Use SequencePattern classes in Specifications

    master

    When using specifications like AvoidPattern or EnforcePatternOccurence, you must provide a pattern. You can provide these patterns either as a specific class instance or as a shorthand string.

    NamePattern ClassAs string
    Restriction siteEnzymeSitePattern('BsmBI')'BsmBI_site'
    HomopolymerHomopolymerPattern("A", 6)'6xA'
    Direct repeatsRepeatedKmerPattern(3, 2)'3x2mer'
    DNA notationDnaNotationPattern('ANNKA')'ANNKA'
    Regular ExpressionSequencePattern('A[CG]*A')'A[CG]*A'
  6. Understand the relationship between Optimization Problems, Specifications, and Evaluations

    master

    The optimization workflow follows this hierarchy:

    1. DnaOptimizationProblem: The top-level object containing the sequence and goals.
    2. Specification: A rule or constraint (e.g., 'avoid this pattern') added to the problem.
    3. SpecEvaluation: The result of applying a Specification to the sequence.

    Evaluations are grouped into SpecEvaluations, which consist of:

    • Objective evaluations: How well the sequence meets the optimization goal.
    • Constraints evaluations: Whether the sequence satisfies the required constraints.
  7. Understand the core classes in DNA Chisel

    master

    DNA Chisel is built around a few central abstractions that define how sequence optimization problems are structured and solved:

    • DnaOptimizationProblem: The primary class used to define and solve optimization problems. It manages Constraints (rules that must be met), Objectives (goals to optimize towards), and a MutationSpace (the set of allowed sequence changes).
    • CircularDnaOptimizationProblem: A specialized version of DnaOptimizationProblem designed for sequences that are circular.
    • Specification: Represents a design rule (e.g., GC content, codon optimization). Specifications can be used as constraints or objectives. They use a Location to define where they apply and can involve a SequencePattern (e.g., searching for a specific restriction site).
    • SpecificationSet: A grouping class that allows you to treat multiple Specification objects as a single unit.
    • Location: Defines a segment of a sequence. It is used by specifications to target specific regions and by evaluations to report where constraints were breached.
    • SpecEvaluation: The result of applying a Specification to a DnaOptimizationProblem. It contains a score, status messages, and the Location of any sub-optimal regions.
    • SequencePattern: A class for representing and finding specific patterns (like BsmBI_site) within a sequence.
    • MutationSpace: Defines the possible mutations available at different locations. It is composed of MutationChoice objects, which map a location to a set of allowed sequence choices.