Question: Combine regions of an interaction matrix
0
gravatar for bharath.mh24
3.3 years ago by
bharath.mh240 wrote:

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.

ADD COMMENTlink modified 3.2 years ago • written 3.3 years ago by bharath.mh240
0
gravatar for russhh
3.3 years ago by
russhh4.7k
UK, U. Glasgow
russhh4.7k wrote:

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 COMMENTlink written 3.3 years ago by russhh4.7k

........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 REPLYlink modified 3.3 years ago • written 3.3 years ago by bharath.mh240

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 REPLYlink modified 3.3 years ago • written 3.3 years ago by russhh4.7k

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 REPLYlink written 3.3 years ago by bharath.mh240

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 REPLYlink written 3.2 years ago by bharath.mh240

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

ADD REPLYlink written 3.2 years ago by russhh4.7k

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 REPLYlink written 3.2 years ago by bharath.mh240
0
gravatar for bharath.mh24
3.2 years ago by
bharath.mh240 wrote:
 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 COMMENTlink modified 3.2 years ago • written 3.2 years ago by bharath.mh240
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1760 users visited in the last hour