This is a test version of Biostars. For the public version, visit https://www.biostars.org.
look for SNPs that span segments with R

I have a file with SNPs positions and IDs:

chr    pos       dbsnp
1      909419    rs28548431
1      1120307   rs7539911

And another file with segments:

chr    start    end         logR
1      62908    8165619     0.0518
1      8165719  10573304    -0.0406

I have to look for SNPs positions (in table 1) that span within each segment (given by start and end in table 2) and I should use R code.

Any suggestion?

snp r

1 answer

Create GRanges objects of each and then use findOverlaps or %over%.

library(GenomicRanges)
snpDat = read.delim('SNPFILENAME')
regionDat = read.delim("REGIONFILENAME")
snpGR = GRanges(seqnames=snpDat[,1],ranges=IRanges(start=snpDat[,2],end=snpDat[,2]))
regionGR = GRanges(seqnames=regionDat[,1],ranges=IRanges(start=regionDat[,2],end=regionDat[,3]))
snpOverlapGR = snpGR[snpGR %over% regionGR]

Untested, but that should be close.

Log in to answer this question.