-
Notifications
You must be signed in to change notification settings - Fork 0
crispr
The CRISPR class simulates CRISPR-Cas9 genome editing operations. It provides methods for finding target sequences, cutting DNA, inserting, deleting, and replacing sequences, as well as simulating off-target effects.
class CRISPR:
def __init__(self, guide_rna: str):
"""
Initialize a new CRISPR object.
:param guide_rna: The guide RNA sequence used to target specific DNA sequences
"""
...| Attribute | Type | Description |
|---|---|---|
guide_rna |
str |
The guide RNA sequence used to target specific DNA sequences. |
-
__init__(self, guide_rna: str)Initializes a newCRISPRinstance with the specified guide RNA sequence.
-
find_target_sequence(self, dna: DNA) -> List[int]Finds all occurrences of the target sequence in the DNA.-
Parameters:
-
dna: The DNA object to search in.
-
-
Returns: A list of starting indices of the target sequence.
-
-
cut_dna(self, dna: DNA, index: int) -> Tuple[DNA, DNA]Simulates cutting the DNA at the specified index.-
Parameters:
-
dna: The DNA object to cut. -
index: The index at which to cut the DNA.
-
-
Returns: Two DNA objects representing the cut fragments.
-
-
insert_sequence(self, dna: DNA, insert_seq: str, index: int) -> DNAInserts a sequence into the DNA at the specified index.-
Parameters:
-
dna: The DNA object to modify. -
insert_seq: The sequence to insert. -
index: The index at which to insert the sequence.
-
-
Returns: A new DNA object with the inserted sequence.
-
-
delete_sequence(self, dna: DNA, start: int, end: int) -> DNADeletes a sequence from the DNA between the specified indices.-
Parameters:
-
dna: The DNA object to modify. -
start: The starting index of the sequence to delete. -
end: The ending index of the sequence to delete.
-
-
Returns: A new DNA object with the sequence deleted.
-
-
replace_sequence(self, dna: DNA, replacement: str, start: int, end: int) -> DNAReplaces a sequence in the DNA with a new sequence.-
Parameters:
-
dna: The DNA object to modify. -
replacement: The replacement sequence. -
start: The starting index of the sequence to replace. -
end: The ending index of the sequence to replace.
-
-
Returns: A new DNA object with the replaced sequence.
-
-
edit_genome(self, dna: DNA, edit_type: str, *args) -> DNAPerforms a CRISPR edit on the DNA.-
Parameters:
-
dna: The DNA object to edit. -
edit_type: The type of edit to perform ('insert','delete', or'replace'). -
*args: Additional arguments specific to the edit type.
-
-
Returns: A new DNA object with the edit applied.
-
Raises:
ValueErrorif the edit type is invalid.
-
-
simulate_off_target_effects(self, dna: DNA, mutation_rate: float = 0.1) -> DNASimulates off-target effects of CRISPR editing.-
Parameters:
-
dna: The DNA object to potentially modify. -
mutation_rate: The probability of an off-target mutation occurring.
-
-
Returns: A potentially modified DNA object.
-
# Initialize a DNA object
dna = DNA(sequence="ATGCGATCGATCGATCGATCGATCGATCG")
# Initialize a CRISPR object with a guide RNA
guide_rna = "GATC"
crisp = CRISPR(guide_rna)
# Find target sequences
target_sites = crisp.find_target_sequence(dna)
print(f"Target sites: {target_sites}")
# Edit the genome by inserting a sequence
edited_dna = crisp.edit_genome(dna, 'insert', "TTTT")
print(f"Edited DNA sequence: {edited_dna.sequence}")
# Edit the genome by deleting a sequence
edited_dna = crisp.edit_genome(dna, 'delete', 4)
print(f"Edited DNA sequence: {edited_dna.sequence}")
# Edit the genome by replacing a sequence
edited_dna = crisp.edit_genome(dna, 'replace', "AAAA")
print(f"Edited DNA sequence: {edited_dna.sequence}")
# Simulate off-target effects
mutated_dna = crisp.simulate_off_target_effects(dna)
print(f"Mutated DNA sequence: {mutated_dna.sequence}")Target sites: [2, 8, 14, 20, 26]
Edited DNA sequence: ATGCGATTTTTTCGATCGATCGATCGATCGATCG
Edited DNA sequence: ATGCGAT
Edited DNA sequence: ATGCAAACGATCGATCGATCGATCGATCG
Off-target mutation occurred at position 12
Mutated DNA sequence: ATGCGATCGATAGATCGATCGATCGATCG
-
random: For simulating random off-target effects and selecting target sites. -
DNA: Class representing DNA sequences.
- The
edit_genomemethod raises aValueErrorif an invalid edit type is provided. - The
find_target_sequencemethod returns an empty list if no target sites are found.
- The
CRISPRclass is designed to simulate basic CRISPR-Cas9 genome editing operations. - The
edit_genomemethod supports three types of edits: insert, delete, and replace. - The
simulate_off_target_effectsmethod simulates potential unintended mutations that can occur during CRISPR editing.