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.

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

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

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

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.

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

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

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

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

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:

Matrixof interactions,Bed fileof coordinates with names. Ouput: Matrix with names with summed interaction of reads of which s coordinates overlapping to input matrix coordinatesIf 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

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.

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

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

`rowSums`

?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