On Jan 24, 2013, at 10:16 AM, Bert Gunter wrote:

> You need to get familiar with BioConductoR and post on that list.
> Almost certainly you are trying to reinvent the wheel, and may even be
> constructing it square.
> 
> Cheers,
> Bert
> 
> On Thu, Jan 24, 2013 at 8:25 AM, Benjamin Ward (ENV) <b.w...@uea.ac.uk> wrote:
>> Dear all,
>> 
>> I'm trying to write a function, that will take as an argument, some aligned 
>> genome sequences, and using a sliding window, do pairwise comparisons of 
>> sequence similarity. Coding the sliding window I think I can manage but what 
>> I'm trying to get to grips with is getting it so as every pairwise 
>> comparison is made, no matter how many genomes are added, from 3 to N.
>> 
>> So if I had four genome sequences, G1, G2, G3, G4 the comparisons would be:
>> 
>> G1:G1
>> G1:G2
>> G1:G3
>> G1:G4
>> G2:G2
>> G2:G3
>> G2:G4
>> G3:G3
>> G3:G4
>> G4:G4

Are you looking for:

> grps <- c( 'G1', 'G2', 'G3', 'G4')
> combn(grps, 2)
     [,1] [,2] [,3] [,4] [,5] [,6]
[1,] "G1" "G1" "G1" "G2" "G2" "G3"
[2,] "G2" "G3" "G4" "G3" "G4" "G4"

Bert's point still holds, but I thought answering the specific question about 
assembling the pairwise groupings might be useful, too.

-- 
David.

>> 
>> I can think of a way this might be done with a very complicated loop, which 
>> would take the region in the window of each genome and then make all 
>> possible combination/comparrisons: So the loop would take G1, and then in 
>> turn compare against G2, G3, G4. Then it would take G2, and start again and 
>> pair it with everything from G1 to G4, then it would take G3 and compare 
>> with everything from G1 to G4, and then finally would take G4, and compare 
>> it with everything from G1 to G4.
>> 
>> This is a wasteful way of doing it however, because for example, by the time 
>> the loop gets around to dealing with G4 as it's first argument I.e. the 
>> G4:GN comparisons, all comparisons with G4 in apart from G4:G4 have already 
>> been made – I.e. G4:G1 is just G1: G4 backwards. So it's really wasteful and 
>> computing stuff that isn't necessary.
>> 
>> So my question is, how can someone do pairwise comparisons in R this way, 
>> and ensure all combinations are compared, but it's not as wasteful as my 
>> obvious shotgun approach which computers many redundant comparisons?
>> 
>> Ben W.
> 


David Winsemius
Alameda, CA, USA

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to