Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I have an array containing pairs of numbers. I then have three other arrays containing the original numbers. I simply want to find out which array each half of the pair came from. I have this code but wondered if there was a better way of doing it?
Hope you can help!
# @gene_pairs contains the pairs of numbers e.g, 1304 1509 # @rep1_pids, @rep2_pids and @rep3_pids are where the numbers came fro +m. foreach my $pair (@gene_pairs) { my @pair = $pair; my $p = join ('', @pair); @pair = split (/\t/, $pair); + + + for (my $i=0; $i<@rep1_pids; $i++) { if ($pair[0] == $rep1_pids[$i]) { push @locations, "rep1 "; push @new_gp, "$rep1_pids[$i] "; } + + if ($pair[1] == $rep1_pids[$i]) { push @locations, "rep1 "; push @new_gp, "$rep1_pids[$i] "; } } for (my $i=0; $i<@rep2_pids; $i++) { if ($pair[0] == $rep2_pids[$i]) { push @locations, "rep2 "; push @new_gp, "$rep2_pids[$i] "; } if ($pair[1] == $rep2_pids[$i]) { push @locations, "rep2 "; push @new_gp, "$rep2_pids[$i] "; } } for (my $i=0; $i<@rep3_pids; $i++) { if ($pair[0] == $rep3_pids[$i]) { push @locations, "rep3 "; push @new_gp, "$rep3_pids[$i] "; } if ($pair[1] == $rep3_pids[$i]) { push @locations, "rep3 "; push @new_gp, "$rep3_pids[$i] "; } } } print "@new_gp\n"; my (@paired_genes1, @paired_genes2); my @pairs2 = @new_gp; print "@pairs2\n"; while (my ($one, $two) = splice(@pairs2,0,2)) { #print "$one ---- $two\n"; push @paired_genes1, "$one "; push @paired_genes2, "$two "; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: extracting information from arrays
by Roy Johnson (Monsignor) on Mar 11, 2005 at 12:29 UTC | |
|
Re: extracting information from arrays
by reneeb (Chaplain) on Mar 11, 2005 at 12:22 UTC | |
|
Re: extracting information from arrays
by graff (Chancellor) on Mar 13, 2005 at 04:37 UTC |