How to compute percentage of overlap in R

Kryo

I am trying to compute the percentage of overlap between two datasets with genomic coordinates, satisfying certain criteria.

seg2

ID   chrom loc.start   loc.end num.mark seg.mean
AB    1   3010000 173490000     8430   0.0039
AB    1 173510000 173590000        5  -17.738
AB    1 173610000 173830000       12    0.011
AB    1 173850000 173970000        6  -16.121
AB    2   3090000 181990000     8434    0.011
BB   12   3090000  68990000     2950   -0.2022
BB   12  69010000  87790000      889    0.0267
BB   12  88010000  98550000      507   -0.3337
BB   12  98570000 115090000      800    0.0586
BB   12 115110000 119350000      197   -0.2031
BB   12 119370000 119430000        4   -20.671

over

 chr     start   end    CNA      sample.ID
  1  68580000  68640000 loss    1-68580000-68640000
  3  15360000  16000000 loss    3-15360000-16000000
  4 122660000 123500000 gain   4-122660000-123500000
  7  48320000  48400000 loss    7-48320000-48400000
  12 115860000 115980000 loss  12-115860000-115980000
 12 113560000 114920000 gain   12-113560000-114920000

expected output

ID   chrom loc.start   loc.end num.mark seg.mean  lm(percentage of overlap)
AB    1   3010000 173490000     8430   0.0039         %
AB    1 173510000 173590000        5  -17.738     
AB    1 173610000 173830000       12    0.011     
AB    1 173850000 173970000        6  -16.121     
AB    2   3090000 181990000     8434    0.011     
BB   12   3090000  68990000     2950   -0.2022     
BB   12  69010000  87790000      889    0.0267
BB   12  88010000  98550000      507   -0.3337
BB   12  98570000 115090000      800    0.0586
BB   12 115110000 119350000      197   -0.2031
BB   12 119370000 119430000        4   -20.671

I tried this script, but it's not working.

for (i in 1:now(seg2)) { 
    seg2$lm <- if((seg2$chrom[i] == over$chr[i]) |
    (seg2$loc.start[i] <= over$start[i] & seg2$loc.end[i] >= over$end[i]) |
    (over$seg.mean[i] >= 0.459 & seg2$CNA[i] == "gain") |
    (over$seg.mean[i] <= -0.678 & seg2$CNA[i] == "loss"), 
    (over$end[i]-over$start[i])/(seg2$loc.end[i]-seg2$loc.start[i])*100)
    }

I am aware of the GenomicRanges package, but would be grateful for suggestions.

Veerendra Gadekar

I would strongly suggest you to use GenomicFeatures to do this efficiently. If you are already aware of creating your own Granges objects then you need to do following two steps to get the length of overlap

# to find overlaps
overlappin.index = findOverlaps(object1, object2)

# to get the overlap length 
width(ranges(overlapping.index, ranges(object1),ranges(object2)))

Where, "object1" and "object2" are the GRanges objects with coordinates, and "overlappin.index" is the indexes of the objects which are in overlap. Once you have the length you can easily get the percentages.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to compute percentage of overlap in R

From Dev

In R, how do I compute factors' percentage given on different variable?

From Dev

How to compute percentage of correctly classified for a categorical variable in R?

From Dev

How to compute percentage using SQL(postgresql)?

From Dev

SQL - How to compute percentage and add to query result

From Dev

How to get percentage of how much do two body overlap?

From Dev

How to compute the Topological Overlap Measure [TOM] for a weighted adjacency matrix in Python?

From Dev

How to compute summation in r

From Dev

In CSS, how to compute the percentage height within a `height:auto` parent?

From Dev

how to compute percentage of similarity between histograms (feature vector)

From Dev

How to compute in a binary matrix in R

From Dev

R: How to partially overlap maps using layout()

From Dev

How to aggregate a binary raster into percentage in R

From Dev

How to know the percentage of occurence of a value in a raster in R?

From Dev

How to tag the Term with the highest percentage of the class in R

From Dev

R How to visualize this categorical percentage data?

From Dev

How to convert all percentage data in R to decimal?

From Dev

How to tag the Term with the highest percentage of the class in R

From Dev

How to compute the overall mean for several files in R?

From Dev

How to compute a check digit for a large number in R?

From Dev

How to compute modulo of md5 in R?

From Dev

How to compute distances along a network in shapefile? in R

From Dev

How to compute a check digit for a large number in R?

From Dev

How to compute modulo of md5 in R?

From Dev

How to use lubridate to compute time difference in R

From Dev

How can I make the label not overlap the point in R?

From Dev

How to combine columns in a data frame so that they overlap in R?

From Dev

How can I make the label not overlap the point in R?

From Dev

How to combine columns in a data frame so that they overlap in R?

Related Related

  1. 1

    How to compute percentage of overlap in R

  2. 2

    In R, how do I compute factors' percentage given on different variable?

  3. 3

    How to compute percentage of correctly classified for a categorical variable in R?

  4. 4

    How to compute percentage using SQL(postgresql)?

  5. 5

    SQL - How to compute percentage and add to query result

  6. 6

    How to get percentage of how much do two body overlap?

  7. 7

    How to compute the Topological Overlap Measure [TOM] for a weighted adjacency matrix in Python?

  8. 8

    How to compute summation in r

  9. 9

    In CSS, how to compute the percentage height within a `height:auto` parent?

  10. 10

    how to compute percentage of similarity between histograms (feature vector)

  11. 11

    How to compute in a binary matrix in R

  12. 12

    R: How to partially overlap maps using layout()

  13. 13

    How to aggregate a binary raster into percentage in R

  14. 14

    How to know the percentage of occurence of a value in a raster in R?

  15. 15

    How to tag the Term with the highest percentage of the class in R

  16. 16

    R How to visualize this categorical percentage data?

  17. 17

    How to convert all percentage data in R to decimal?

  18. 18

    How to tag the Term with the highest percentage of the class in R

  19. 19

    How to compute the overall mean for several files in R?

  20. 20

    How to compute a check digit for a large number in R?

  21. 21

    How to compute modulo of md5 in R?

  22. 22

    How to compute distances along a network in shapefile? in R

  23. 23

    How to compute a check digit for a large number in R?

  24. 24

    How to compute modulo of md5 in R?

  25. 25

    How to use lubridate to compute time difference in R

  26. 26

    How can I make the label not overlap the point in R?

  27. 27

    How to combine columns in a data frame so that they overlap in R?

  28. 28

    How can I make the label not overlap the point in R?

  29. 29

    How to combine columns in a data frame so that they overlap in R?

HotTag

Archive