gdb.init_examples()
# Create a "donor" DB with different sequence (all T's)
donor_fasta <- tempfile(fileext = ".fa")
cat(">chr1\n", paste(rep("T", 500000), collapse = ""), "\n",
">chr2\n", paste(rep("T", 300000), collapse = ""), "\n",
file = donor_fasta, sep = ""
)
donor_db <- tempfile()
gdb.create(donor_db, fasta = donor_fasta, verbose = FALSE)
# Export the current DB as the target FASTA
gdb.init_examples()
ref_fasta <- tempfile(fileext = ".fa")
gdb.export_fasta(ref_fasta)
# Transplant donor sequence into positions 100-200 of chr1
intervals <- data.frame(chrom = "chr1", start = 100, end = 200)
out <- tempfile(fileext = ".fa")
trackdb <- tempfile()
ggenome.transplant(intervals,
source_genome = donor_db,
target_genome = ref_fasta,
output = out,
create_trackdb = TRUE,
trackdb_path = trackdb
)
# Verify: positions 100-200 should now be all T's
gdb.init(trackdb)
gseq.extract(data.frame(chrom = "chr1", start = 100, end = 200))
# Clean up
unlink(
c(
donor_fasta, donor_db, ref_fasta, out,
paste0(out, ".fai"), trackdb
),
recursive = TRUE
)
Run the code above in your browser using DataLab