SnapGeneFileReader icon indicating copy to clipboard operation
SnapGeneFileReader copied to clipboard

How do I re-write data into a snapgene file?

Open li1311139481 opened this issue 9 months ago • 1 comments

from snapgene_reader import snapgene_file_to_dict, snapgene_file_to_seqrecord
from Bio.Seq import Seq

file_path = "/cluster/facility/hlhuang/zifeng001/snapgene/LMB.dna"
dictionary = snapgene_file_to_dict(file_path)
seqrecord = snapgene_file_to_seqrecord(file_path)

for i, value in dictionary.items():
    # print(value)
    if isinstance(value, list):
        # print(value)
        for anno in value:
            # print(anno)
            if anno["name"] == "sgRNA":
                # print(anno["name"])
                start = anno["start"]
                end = anno["end"]

dictionary["seq"] = dictionary["seq"].replace(
    dictionary["seq"][start:end], new_sgRNA_sequence
)

I used this code to find and replace the sequence. Then I want to regenerate the snapgene file. What should I do?

li1311139481 avatar Apr 23 '25 13:04 li1311139481