Thanks,
I'll try using bedtools. I was only trying R as I thought it might be simpler there.
I have a maf file with snps in the human genome. How can I calculate average mutation rate per Mb per chromosome in R? I need to compare these with genomic features.
Take your MAF file, and filter to low frequency SNPs with a subset() command. Then filter to windows of about 1MB, and count the variants in each one.
You could use bedtools to make a window file, and intersectBed to get quick counts.
But you said it has to be in R, so it sounds more like a homework problem and you should figure out how to do the programming.
Thanks,
I'll try using bedtools. I was only trying R as I thought it might be simpler there.
Sure there might be an R package to do this kind of analysis, but in my experience you're better off doing something simple and fully understanding the method.
Bedtools is made to analyse position files. All you need is its window command to make a BED of 1MB blocks, then bedtools intersect command to see how many entries of your MAF file fall within each block.
You might want to first use AWK (and see Heng Li's BioAwk) to reduce the MAF file so high frequency snps aren't included, because I guess mutation rate should only include rare/new stuff, not inherited common alleles.
Log in to answer this question.