-
Notifications
You must be signed in to change notification settings - Fork 29
Open
Description
I would like to add a SNP annotation track to my plotgardener plot. I am able to do so using annoHighlight(), however I want to add ~2,000 SNPs which is unrealistic to do one-by-one and takes a long time in a for loop. Is there a way to plot many SNPs at once? I have also tried using plotRanges(), however only a few lines show up and they are too thin to see on the rest of my plot which is about 700kb. Here is my code so far:
library(plotgardener)
library(AnnotationHub)
library(TxDb.Hsapiens.UCSC.hg38.knownGene)
library(org.Hs.eg.db)
tagSNPs <- read.delim("allTagSNPs_forPlot.txt", header = T, stringsAsFactors = F)
pageCreate(
width = 6, height = 3, default.units = "inches",
showGuides = FALSE, xgrid = 0, ygrid = 0
)
ideogramPlot <- plotIdeogram(
chrom = "chr17", assembly = "hg38",
orientation = "h",
x = 0.25, y = 0.25, width = 5.75, height = 0.3, just = "left"
)
region <- pgParams(chrom = "chr17", chromstart = 45578810, chromend = 46277280)
H4 <- pgParams(chrom = "chr17", chromstart = 45637307, chromend = 45637307)
H5 <- pgParams(chrom = "chr17", chromstart = 46095849, chromend = 46095849)
H6 <- pgParams(chrom = "chr17", chromstart = 45593653, chromend = 45593653)
H8 <- pgParams(chrom = "chr17", chromstart = 45588844, chromend = 45588844)
annoHighlight(
plot = ideogramPlot, params = region,
fill = "red",
y = 0.05, height = 0.4, just = c("left", "top"), default.units = "inches"
)
annoZoomLines(
plot = ideogramPlot, params = region,
y0 = 0.5, x1 = c(0.25, 6), y1 = 1.25, default.units = "inches"
)
genes <- plotGenes(
assembly = "hg38",
chrom = "chr17", chromstart = 45578810, chromend = 46277280,
y = 1.5, x = 0.3, width = 5.5, just = c("left", "top")
)
plotGenomeLabel(
chrom = "chr17",
chromstart = 45578810, chromend = 46277280,
assembly = "hg38",
scale = "Mb",
x = 0.3, y = 2.5, length = 5.5, default.units = "inches"
)
for (i in 1:nrow(tagSNPs)) {
# Extract the chrom, chromstart, and chromend for the current SNP
chrom <- tagSNPs$chrom[i]
chromstart <- as.numeric(tagSNPs$start[i])
chromend <- as.numeric(tagSNPs$end[i]-1)
# Create the region using pgParams() for the current SNP
SNP <- pgParams(chrom = chrom, chromstart = chromstart, chromend = chromend)
# Create fill color
fill_color <- ifelse(tagSNPs$haplotype[i] == "H4", "#40004B",
ifelse(tagSNPs$haplotype[i] == "H5", "#A6DBA0",
ifelse(tagSNPs$haplotype[i] == "H6", "#762A83", "#D9F0D3")))
# Apply annoHighlight for this SNP region
annoHighlight(
plot = genes, params = SNP,
fill = fill_color,
y = 2.1, height = 0.1, just = c("left", "top"), default.units = "inches"
)
}
# plotRanges(
# data = tagSNPs, chrom = "chr17",
# chromstart = 45578800, chromend = 46277280,
# assembly = "hg38",
# order = "random",
# collapse = TRUE,
# fill = colorby("haplotype", palette =
# colorRampPalette(c("#40004B", "#A6DBA0", "#762A83", "#D9F0D3"))),
# x = 0.5, y = 0.25, width = 5.5, height = 0.1,
# just = c("left", "top"), default.units = "inches"
# )
[allTagSNPs_forPlot.txt](https://github.com/user-attachments/files/18578918/allTagSNPs_forPlot.txt)
Metadata
Metadata
Assignees
Labels
No labels