Check the code below if it's useful.
# Install the development version of dartR.base from GitHub
# (only needs to be run once, or whenever you want to update)
devtools::install_github("green-striped-gecko/dartR.base")
# Load the dartRverse package (which includes dartR.base)
library(dartRverse)
# Specify the path to your reference genome FASTA file
RefGenome <- "GCF_004115215.2_mOrnAna1.pri.v4_genomic.fna"
# Load your input genlight object (here using the built-in
platypus.gl dataset)
t1 <-
platypus.gl# Perform BLAST of each locus in t1 against the reference genome
# This annotates each locus with alignment metrics in t2$other$loc.metrics
t2 <- gl.blast(t1, ref_genome = RefGenome)
# Extract the chromosome accession (sacc) from the BLAST results
# and store it as a factor in a new column ‘chromosome’
t2$chromosome <- as.factor(t2$other$loc.metrics$sacc)
# Compute the absolute SNP position by adding the BLAST start coordinate (sstart)
# to the original relative position in the locus object
t2$position <- t2$other$loc.metrics$sstart + t2$position
# Inspect the names (IDs) of the markers
locNames(t2)
# Inspect the chromosome assignments
t2$chromosome
# Inspect the computed SNP positions
t2$position
# Combine marker names, chromosome, and position into a single data frame
all_info <- data.frame(
LocNames = locNames(t2),
Chr = as.character(t2$chromosome),
Pos = t2$position
)
# Write the combined SNP information to a CSV file
# (set row.names = FALSE to avoid writing an extra column)
write.csv(all_info, "all_info.csv", row.names = FALSE)
# Create a SNP density plot using dartR.base’s internal plotting function
# - bin.size: window size in base pairs (1 Mb here)
# - min.snps: only plot bins with at least this many SNPs
# - min.length: minimum chromosome length to include
# - color.palette: function to generate colors (using viridis here)
# -
chr.info: show chromosome information
# - plot.title: title of the plot
p1 <- dartR.base:::gl.plot.snp.density(
x = t2,
bin.size = 1e+06,
min.snps = 50,
min.length = 1e+06,
color.palette = viridis::viridis,
chr.info = TRUE,
plot.title = "SNP density"
)
# Save the SNP density plot to a PDF file
# - width/height: dimensions in inches
ggsave(
filename = "SNP_density.pdf",
plot = p1,
width = 8,
height = 6,
units = "in"
)