karyoploteR SNP density
1
0
Entering edit mode
8 months ago
Kip • 0

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() ?


VCF file

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)))
SNP VCF karyoploteR • 525 views
ADD COMMENT
0
Entering edit mode
8 months ago

Adding a comment to the answer I gave in the post you mentioned would have been a better option so I could have been notified of your issue. In the answer I wrote some years ago, OP was implying a BED12 format with specifically 12 columns in the vcf file.

You should replace this line :

tmp.vcf.data <- tmp.vcf.data[, c(1,2,12, 3:11)]

with a more generic one,

tmp.vcf.data <- tmp.vcf.data[, c(1,2,ncol(tmp.vcf.data), 3:(ncol(tmp.vcf.data)-1))]
ADD COMMENT

Login before adding your answer.

Traffic: 2364 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6