Question: How to sort set of GRanges object in the list by increasing order?
0
3.2 years ago by
Chicago, IL, USA
Jurat Shahidin70 wrote:

Dear all:

I am seeking any efficient way that sorting set of GRanges objects in the list by increasing order. I know sort method from GenomicRangs do this task, but it is very generic. The case that I faced bit of different, and using sort method won't effective to solve my problems. Does anyone knows how to accomplish this task more efficiently? Many thanks

# example

grs.li <- list(gr1, gr2, gr3, gr4, ...)

# desired output that after sorting

out_1 <-  list(gr1, gr2, gr3, gr4)   # the very beginning, no need to sort
out_2 <-  list(gr2, gr1, gr3, gr4)   # first sorting
out_3 <-  list(gr3, gr1, gr2, gr4)   # second sorting
out_4 <-  list(gr4, gr1, gr2, gr3)   # third sorting

according to the format of desired format that proposed, how can I get this kind of sorting more efficiently. I mean, carrying out this kind of sort operation is also appreciated. Thanks

Best regards:

JS

modified 3.2 years ago • written 3.2 years ago by Jurat Shahidin70
Answer: How to sort set of GRanges object in the list by increasing order?
2
3.2 years ago by
Chicago, IL, USA
Jurat Shahidin70 wrote:

Regarding the issue that I asked, I figured out my own solution as follows:

out_1 <- grs.li[seq_len(length(grs.li))]
out_2 <- grs.li[c(2, seq_len(length(grs.li))[-2])]
out_3 <- grs.li[c(3, seq_len(length(grs.li))[-3])]
out_4 <- grs.li[c(4, seq_len(length(grs.li))[-4])]

this solution is bit of generic, but it works pretty well if user need to permute set of GRanges object in the list. Cheers.

JS

I see. You just wanted to permute the elements of a list. This has nothing to do with sorting them by increasing order. There is also nothing specific to GRanges objects here.

I admit my post was confused readers and question was not clearly motivated. I will do my best in my further post. Cheers.

JS

Answer: How to sort set of GRanges object in the list by increasing order?
1
3.2 years ago by
Hervé Pagès ♦♦ 14k
United States
Hervé Pagès ♦♦ 14k wrote:

Hi Jurat,

Unfortunately, it's again very hard to help you. The code you're showing doesn't make much sense. Before you can sort a set of things you need to be able to compare these things between each other. More precisely, given 2 things in the set, you need to be able to tell which one is greater than the other one. So in your case, your final order (what you call third sorting) is gr4, gr1, gr2, gr3. But what is your criteria for deciding that gr3 is greater than gr2, gr2 greater than gr1, and gr1 greater than gr4? You're not saying anything about what makes a GRanges object greater than another! Once we know this, we might be able to help you sort a set of GRanges objects.

Thanks,

H.

Dear Herve:

Thanks for your respond. The reason I raised this question on this sites, I had unexpected bug when I ran unit testing on my own developed packages - MSPC, and I aware that it possibly caused by order of GRanges object in the list if multiple testing happens. It is just my guess work and try to do this kind of sorting. However, I got my own possible solution how to carry out this kind of sorting. Thanks again for your supporting.

JS