Combine regions of an interaction matrix
2
0
Entering edit mode
8.4 years ago

Hello, Given I have a matrix of rows and columns of genomic coordinates and their interactions as a non symmetric matrix elements given by number of reads. I would like to combine the genomic intervals(along with their reads by summing them up) which intersect with particular enhancer regions that I have in a bed file to make a matrix of enhancers x enhancers.

Interaction matrix enhancers sequencing next-gen • 1.9k views
ADD COMMENT
0
Entering edit mode
8.4 years ago
russhh 5.7k

Could you post some info about your datastructure? This is quite simple in R. Suppose you have a list gc containing - an nxn matrix, gc$mat, - an associated n-row GenomicRanges object, gc$ranges; and a GenomicRanges containing your bed-data, bed

subset_GRanges_Intxn <- function(gc, bed){
  require(GenomicRanges)
  # tests
  ol <- findOverlaps(query = gc$ranges, subject = bed)
  new.gc <- list(
    mat = gc$mat[ol, ol],
    ranges = gc$ranges[ol, ]
    )
  new.gc
  }

I hope, I haven't tested it

ADD COMMENT
0
Entering edit mode

........GC1.GC2.GC3.GC4.GC5

  • (GC1) 1 1 3 5 9
  • (GC2) 3 4 4 5 6

This is an example of the matrix. If i wanted to add all the rows/columns which intersect with enhancer coordinates. Also does the matrix have to be symmetric? NxM matrix with P-row bed file. I would input the following: Matrix of interactions, Bed file of coordinates with names. Ouput: Matrix with names with summed interaction of reads of which s coordinates overlapping to input matrix coordinates

ADD REPLY
0
Entering edit mode

If your matrix isn't symmetric, could you update your post to make that explicit. If the names in your bed file match the row names in your interaction matrix, then the solution to your question is trivial (in R at least), just pull out the relevant rows.

Could I ask what the entries in your matrix represent (given that they contain real numbers rather than just binaries), I typically just represent interactions as 0-1

ADD REPLY
0
Entering edit mode

The matrix entities are read counts representing the interaction of the primers with each others. I would like to add up the rows which have coordinates(matrix column and row header) overlapping with the coordinates of the enhancers(bed file). I have extracted the overlapping rows alone. I just need to sum up all the rows which intersect a specific enhancer, hence finally giving me a matrix with enhancers interactions.

ADD REPLY
0
Entering edit mode

Hello, In the code mentioned above can we add a function to sum up the matrix rows that are obtained after the overlap? i.e add the rows of the matrix which have common overlaps with the bed file. Thank You

ADD REPLY
0
Entering edit mode

what's the current version of your code - please post it? Do you just subset your matrix and call rowSums?

ADD REPLY
0
Entering edit mode

Hello, I am sorry. I am just a beginner to R. I used the same code as mentioned by you above. In the code mentioned above I just get a subset of overlapping regions. But I basically need to "bin" the data of all the regions overlapping with the enhancers i.e add rows correspondong to only one enhancer. I hope it is understandable. Thank You

ADD REPLY
0
Entering edit mode
8.3 years ago
 for (i in 1:length(b))
{
      for(val1 in b[i,2])
        for (val2 in b[i,3])
        { 
          for (j in 1:length(d)) 
            {if(val1 < d[i,2])
              if (val2 > d[i,3])
            df=d[j-1,4:164] + d[j,4:164]
            listofdf[[i]]= df
          }
      }
      return= listofdf
    }

Hello, This is something i tried putting together. Here d is the matrix with ranges(col 1,2,3 are chr no., start, end respectively) as row headers and b is the bed file. Does this make much sense? It gives an error of data.frame of varying size. What changes do i need to make. Thank You very much for your time

ADD COMMENT

Login before adding your answer.

Traffic: 1807 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