I'm following the Gene Density example but modifying it to show SNP density across the genome. I found this post for getting a VCF file into the GRanges format, but when I follow it, I get this warning at the last step:
toGRanges(tmp.vcf.data)
Warning: NAs introduced by coercionError in .new_IRanges_from_start_end(start, end) :
'start' or 'end' cannot contain NAs
If I ignore the warning or run tmp.vcf.data %>% drop_na() before making the plot I get this error message:
kp <- plotKaryotype(genome = custom.genome)
kp <- kpPlotDensity(kp, tmp.vcf.data)
Error in kpPlotDensity(kp, tmp.vcf.data) :
In kpPlotDensity: 'data' must be a valid 'GRanges' object
How do I process my VCF file into a GRanges object for kpPlotDensity() ?
My custom genome (I only want to plot the chromosomes and ignore unplaced scaffolds):
custom.genome <- toGRanges(data.frame(chr=c("Chromosome1", "ptg000009l", "ptg000006l","Chromosome4", "Chromosome5", "Chromosome6", "Chromosome7", "Chromosome8"), start=c(0, 0, 0, 0, 0, 0, 0, 0), end=c(185090896, 133334114, 131385308, 127816055, 128169929, 101006030, 125626, 6859227)))