Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

manipulate GenomicInteractions object #5

Open
mjko1210 opened this issue Apr 6, 2020 · 3 comments
Open

manipulate GenomicInteractions object #5

mjko1210 opened this issue Apr 6, 2020 · 3 comments

Comments

@mjko1210
Copy link

mjko1210 commented Apr 6, 2020

Hi,

I'm wondering if I can modify GenomicInteractions object.

For example,
data <- makeGenomicInteractionsFromFile(f, type="bedpe")

GenomicInteractions object with 65 interactions and 1 metadata column:
seqnames1 ranges1 seqnames2 ranges2 | counts
|
[1] chr13 63039538-63039537 --- chr17 22147340-22147339 | 10
[2] chr6 76245070-76245069 --- chr13 65568744-65568743 | 10
[3] chr13 65720196-65720195 --- chr21 9851052-9851051 | 10
[4] chr13 60977697-60977696 --- chr22 46771901-46771900 | 10
[5] chr6 76245101-76245100 --- chr13 65568774-65568773 | 10
... ... ... ... ... ... . ...
[61] chr13 49147000-49146999 --- chr13 66195900-66195899 | 10
[62] chr13 59255135-59255134 --- chr13 59476455-59476454 | 10
[63] chr13 59263605-59263604 --- chr13 63699832-63699831 | 10
[64] chr13 59475210-59475209 --- chr13 61920391-61920390 | 10
[65] chr13 63043465-63043464 --- chr17 22143270-22143269 | 10

I was able to access counts via data$counts, however not for any other columns (such as seqnames and ranges).

I've tried converting object to data frame using as.data.frame(data). However, I'm not sure how to convert it back to GenomicInteractions object after the modification.

Your advice will be appreciated!

Thanks!

@liz-is
Copy link
Collaborator

liz-is commented Apr 7, 2020

Hi,

The GenomicInteractions object stores region information as a GRanges object, along with information about which regions are interacting with each other, and counts and other metadata stored in metadata columns. You can read more about how the object is structured in the vignette, or the InteractionSet vignette (as we inherit from InteractionSet objects), and that might help understand how to manipulate it.

We don't recommend modifying a GenomicInteractions object in place, but if you want to create a new GenomicInteractions object I would probably suggest using this approach:

new_gi <- GenomicInteractions(anchor_one_granges, anchor_two_granges, counts, metadata)

You can easily create GRanges from a data frame using the makeGRangesfromDataFrame function, changing the start.field and end.field arguments as appropriate if you're storing information for more than one genome region in the same data frame.

@mjko1210
Copy link
Author

mjko1210 commented Apr 7, 2020

Thank you for your comments.
I've tried making GenomicInteractions object following your advice.
It works fine with anchor_one_granges, anchor_two_granges, counts but not with metadata.

anchor_one = data[,c(1:3,9)]
anchor_two = data[,c(4:6,10)]
colnames(anchor_one) = c('chr','start','end','strand')
colnames(anchor_two) = c('chr','start','end','strand')

anchor_one_granges = makeGRangesFromDataFrame(anchor_one)
anchor_two_granges = makeGRangesFromDataFrame(anchor_two)
counts = data[,8]
metadata = data[,11] #contains types
new_gi <- GenomicInteractions(anchor_one_granges, anchor_two_granges, counts, metadata)

Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function 'GInteractions' for signature '"GRanges", "GRanges", "character"

I've also tried by making both counts and types as metadata

metadata = DataFrame(counts = data[,8], types = data[,11])

However, I'm still getting error:

new_gi <- GenomicInteractions(anchor_one_granges, anchor_two_granges, metadata)
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function 'GInteractions' for signature '"GRanges", "GRanges", "DFrame"'

I'm not sure how other column can be added as metadata except counts here.

Thanks!

@liz-is
Copy link
Collaborator

liz-is commented Apr 8, 2020

Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function 'GInteractions' for signature '"GRanges", "GRanges", "character"

Is your "counts" column encoded as character by any chance? try as.numeric(counts) first. You can see all the possible ways of constructing a GenomicInteractions object by looking at ?GenomicInteractions.

If that doesn't solve it, please provide a reproducible example with an example BEDPE file and/or an example of what your data object looks like, e.g. by using dput().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants