about appending GRANGES
2
0
Entering edit mode
Bogdan ▴ 670
@bogdan-2367
Last seen 6 months ago
Palo Alto, CA, USA

Hi ; I would appreciate a piece of advice on the following ;

I would like to append a GRange object "interactions" that is initially EMPTY ;

interactions <- append(interactions, interactions_chr[k])

how do I initialize a GRange object "initeractions" that is EMPTY at the very beginning ?

 

thanks ,

 

bogdan

 

GRanges • 3.5k views
ADD COMMENT
1
Entering edit mode
@herve-pages-1542
Last seen 4 hours ago
Seattle, WA, United States

Hi Bodgan,

You create an empty GRanges object by calling GRanges().

Note that growing an object in a loop with something like

interactions <- GRanges()
for (i in seq_len(N)) {
    gr <- ... make some GRanges object ...    
    interactions <- append(interactions, gr)
}

is generally very inefficient and should be avoided.

If you know in advance how many iterations you're going to do, it is a lot more efficient to do:

interactions <- vector(mode="list", length=N)
for (i in seq_len(N)) {
    gr <- ... make some GRanges object ...   
    interactions[[i]] <- gr
}
interactions <- do.call(c, interactions)

Alternatively, you can replace the for loop by a call to lapply() which is more elegant but does basically the same.

H.

ADD COMMENT
0
Entering edit mode
Bogdan ▴ 670
@bogdan-2367
Last seen 6 months ago
Palo Alto, CA, USA

Dear Herve,

many thanks for your reply: it is very helpful. happy weekend !

 

-- bogdan

ADD COMMENT

Login before adding your answer.

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