[BiO BB] A question about the perl code

T.D. Houfek tdhoufek at unity.ncsu.edu
Fri Aug 19 21:49:41 EDT 2005


Hi all,

The formulation of this problem was slightly ambiguous, but from Alex's 
list of excluded pairs I guessed he only wanted to exclude pairs which 
had an identical nucleotide in the same position as the sample.  Roger's 
solution seems appropriate if instead Alex wishes to exclude pairs with 
any nucleotides in common, irregardless of position.  (Or, and I have 
had this happen, some crucial punctuation marks were stripped when 
cutting-and-pasting code into my mail client's window --  villainous 
HTML emails ...) 

Double-check me.  It's Friday night, so this little program -- though 
based on Roger's -- is the product of collaboration between me, Gin, and 
Tonic.

Which I suppose should be written ' collaboration among Gin, Tonic, and 
I', but it just doesn't sound the same, does it?

Cheers,
T.D. Houfek
senior bioinformatics developer
Plant Nematode Genetics Group,
North Carolina State University

============== sample code follows ============================

#!/usr/bin/perl
use strict;

my @group = qw(AA AC AG AT
                  CA CC CG CT
                  GA GC GG GT
                  TA TC TG TT);
my $rand     = $group[rand(scalar @group)];

## Uncomment to force the 'AC' sample example:
## $rand = 'AC';

print "\n\nRandom Number: $rand\n";
print "\n\nMethod #1: remove all pairs with at least one nucleotide in 
the same position as in the sample:\n";

my @unfiltered = grep { $_ !~ /^[A.]|[.C]$/ } @group;
my @filtered = grep { $_ =~ /^[A.]|[.C]$/ } @group;
print "Removed:\n";
print join("\t", @filtered);
print "\n";
print "Remaining:\n";
print join("\t", @unfiltered);
print "\n";

my @unfiltered2 = grep { $_ !~ /[$rand]/ } @group;
my @filtered2 = grep { $_ =~ /[$rand]/ } @group;
print "\nMethod #2: remove all pairs sharing at least one nucleotide 
with sample:\n";
print "Removed:\n";
print join("\t", @filtered2);
print "\n";
print "Remaining:\n";
print join("\t", @unfiltered2);
print "\n";




Roger Pettett wrote:

> On Tue, 16 Aug 2005, Alex Zhang wrote:
>
>> Dear All,
>>
>> I made a group A which includes 16 combinations of any
>> two nucleotides like: AA,AC,AG,AT,
>> CA,CC,CG,CT,
>> GA,GC,GG,GT,
>> TA,TC,TG,TT
>>
>> If  I randomly got a pair like AC, I want to exclude
>> AC, AT, AG, AA, TC, CC, GC. In other words, I want to
>> exclude the pairs in group A which has the same
>> nucleotide with the pair randomly selected. Can
>> anybody suggest me how to approach this using Perl?
>
>
> How about something like this?
>
> my @group    = qw(AA AC AG AT
>                   CA CC CG CT
>                   GA GC GG GT
>                   TA TC TG TT);
> my $rand     = $group[rand(scalar @group)];
> my @filtered = grep { $_ !~ /[$rand]/ } @group;
>
> print join("\n", @filtered);
>
>




More information about the BBB mailing list