Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to make relation between two variables linked by one using perl,similar to metabolic networks

Tags:

perl

Lets say i have generated some random alphabets and random numbers

A 1
Z 2
C 3
L 2
E 4

and similarly another set

1 K
4 I
2 P
5 R
6 S
7 U

Now we can find 2 is linked to Z and L in the first case and similarly 2 is linked to P in the second set from this we can say Z and L are connected to P so intially i have generated the first two steps. I am a little confused how to proceed with rest?

like image 683
Bio_Ram Avatar asked Dec 21 '25 04:12

Bio_Ram


2 Answers

Just to recommend a wildly different approach that may be easier to think about if you are more familiar with SQL than perl, you can look into DBD::CSV. You can then accomplish what you want with a simple join statement. Just follow the example on the linked page. If you don't know SQL than you are probably better off with a hash of arrays as already posted. I'll post actual code when I get to a machine that has DBD::CSV installed...

like image 146
frankc Avatar answered Dec 22 '25 21:12

frankc


Perhaps what you need is all the relationships like the one you have shown us?

Here is an example program which does that. Please explain if you need something different.

use strict;
use warnings;

my %data1 = qw(
  A 1
  Z 2
  C 3
  L 2
  E 4
);

my %data2 = qw(
  1 K
  4 I
  2 P
  5 R
  6 S
  7 U
);

#  Convert to arrays indexed by the numbers
#
my @data1;
push @{ $data1[$data1{$_}] }, $_ for keys %data1;

my @data2;
push @{ $data2[$_] }, $data2{$_} for keys %data2;

# Find all the mappings between the datasets
#
for my $i (0 .. $#data1) {
  my $data1 = $data1[$i] or next;
  my $data2 = $data2[$i] or next;
  print "@$data1 => @$data2\n";
}

output

A => K
Z L => P
E => I
like image 43
Borodin Avatar answered Dec 22 '25 22:12

Borodin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!