Hi Monks,
Could I pick your brains regarding some array wrangling?
I have an input file that looks something like:
Family lacM taba mori glyB gly4 OG_1 1 0 1 0 0 OG_2 0 1 0 1 0
and I would like to know, for each family, which two members are '1', possibly storing them as a hash in which the key = family (eg OG_1) and the value = 'lacM mori' or something similar...
I am able to manipulate this such that I can get the name of the first incidence of '1', by using (the input file has been read into the array @COUNT):
my $a=shift @COUNT; my @families=split(/\s+/,$a); my %participants; foreach (@COUNT) { my @a=split(/\s+/,$_); my $og=$a[0]; my $search_for="1"; ## search for participants in that OG my ( $index )= grep { $a[$_] eq $search_for } 0..$#a; $participants{$og}=$index; } my %og_to_gid; foreach my $k (keys %participants) { $og_to_gid{$k}=$families[$participants{$k}]; }
which gives, within the %og_to_gid hash, a result whereby the key = OG_1 and the value = lacM, in this case (sorry about the weird variable names; I'm a genome biologist (and genome biologists are weird anyway)), which was fine for a previous script but now I really need to know the names of BOTH the members for each family.
Any ideas would be most welcome! Is there something within for example List::Utils that could do it? I had a look but I couldn't see anything...
Thanks once again,
Reuben
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |