Hello,

I need your help. I want to compare two dataframes with genomic features like this:

More precisely, frame 2 compared to frame 1

    chr start end name        chr start end   name  
    1    2    5   A           1    1    3       AA
    2   10    15  B           2    9    16      BB
    3   27    30  C           3    28   29      CC

As a result I want this:

1. Completely overlapping:
   
   ```
   chr start end name    chr start end name
   2   10    15   B       2    9    16    BB
   ```

2. Partial overlap:
   
   ```
   chr start end  name    chr start end   name 
   1    2    5    A        1    1    3    AA
   ```

3. and within the range:
   
   ```
   chr start end name        chr start end   name 
   3   27    30  C            3    28   29    CC
   ```

Are the R packages `IRanges` and `GenomicRanges` suitable for such analysis? Or do I have to write some > < commands?

<p>Using the GenomicRanges library in R:</p>

<pre>
library(GenomicRanges)
x1 = read.table(text=&quot;chr start end name  
1    2    5   A
2   10    15  B
3   27    30  C&quot;,header=T)

x2 = read.table(text=&quot;chr start end   name  
1   1    1    3       AA
2   2    9    16      BB
3   3    28   29      CC&quot;,header=T)

# Make GRanges object
gr1 = with(x1, GRanges(chr, IRanges(start = start, end = end, names = name)))
gr2 = with(x2, GRanges(chr, IRanges(start = start, end = end, names = name)))

# Completely overlapping
type1 = findOverlaps(query = gr1, subject = gr2, type = &quot;within&quot;)
type1.df = data.frame(x1[queryHits(type1),], x2[subjectHits(type1),])
type1.df
  chr start end name chr.1 start.1 end.1 name.1
2   2    10  15    B     2       9    16     BB

# Within range
type3 = findOverlaps(query = gr2, subject = gr1, type = &quot;within&quot;)
type3.df = data.frame(x1[subjectHits(type3),], x2[queryHits(type3),])
type3.df
  chr start end name chr.1 start.1 end.1 name.1
3   3    27  30    C     3      28    29     CC

# Partial Overlaps only (no complete overlaps or within range overlaps)
type2 = findOverlaps(query = gr1, subject = gr2, type = &#39;any&#39;)
type2.df = data.frame(x1[queryHits(type2),], x2[subjectHits(type2),])
x = rbind(type1.df, type2.df, type3.df)
type2.df = x[!(duplicated(x) | duplicated(x, fromLast = TRUE)), ]
type2.df
   chr start end name chr.1 start.1 end.1 name.1
21   1     2   5    A     1       1     3     AA</pre>

<p>You will get three different data frames as per your question. Based on your example, I am assuming type 1 and type 3 are opposites.</p>
