Hello, all.

I need to merge two files according a id list in each file.  What I am
trying to do is to have a sub routine that get the id from data file 1 as
key for a hash, a second sub routine to put the value from data file 1 into
the hash, then while reading in the data file 2 using the while loop, match
the hash key to the id for each line, if it match print the $_ and $key =>
$value from the hash.

I am not sure whether my logic is right or not here and am having trouble in
achieving my second goal -- fill data into hash--.  Could anyone see what is
wrong?

Thanks,

#!usr/local/bin/perl

use strict;
use warnings;



while(<Data1>)
        {
my $mykey;
my $myvalue;
my @a;

my %Hash = ();
next unless /^SNP/;
@a = getkeyvalue();
$mykey = $a[0];
$myvalue = $a[1];
#print "a0 $mykey, a1 $myvalue \n";
%Hash=($mykey,$myvalue);
print "Hash: $mykey is $myvalue";
return %Hash
}


sub getkeyvalue 
{
my $line ;
my @line = ();
my $value;
my $col;

@line = split('\t', $_);

#print @line;

$col = $line[0];

chomp $col;
#print "key = $col, $line[0]";
$value = join("\t", @line[1..2]);
#print "value =: $value";
return ($col, $value);
}
__DATA1__

ids     chro_num        Location
SNP_A-1509443   1       2672921
SNP_A-1518557   3       3776202
SNP_A-1516024   1       4798845
SNP_A-1514538   5       5350951
SNP_A-1516403   1       5483872
SNP_A-1518687   2       6493017
SNP_A-1509959   1       6541536
SNP_A-1512212   4       7021969
SNP_A-1513560   1       7032377
SNP_A-1519671   5       7507831
[snip]  

__DATA2__
SNP ID  dbSNP RS ID     Chromosome      Physical Position       TSC ID
A172_Call       A172_Call Zone
7085    SNP_A-1509443   rs1393064       1       2882121 TSC0565952      AA
0.02861
4900    SNP_A-1518557   rs966321        1       3985402 TSC0273278      AA
0.152388
8258    SNP_A-1517286   rs1599169       1       4804829 TSC0694296      BB
0.538696
10947   SNP_A-1516024   rs580309        1       4982250 TSC1478148      AA
0.569713
7794    SNP_A-1514538   rs1414379       1       5468765 TSC0609730      AA
0.299872
9130    SNP_A-1516403   rs1890191       1       5596686 TSC0913001      AA
0.221319
7214    SNP_A-1518687   rs1396904       1       6605831 TSC0574502      BB
0.040226
526     SNP_A-1509959   rs950493        1       6654350 TSC0042354      BB
0.123611
4345    SNP_A-1515791   rs845263        1       7133863 TSC0218512
NoCall  0.814947
7914    SNP_A-1512212   rs1418490       1       7134783 TSC0617931      BB
0.077556
4470    SNP_A-1513560   rs705695        1       7145191 TSC0246331      AA
0.700697
8386    SNP_A-1519671   rs228651        1       7620645 TSC0730553      AA
0.09444
4854    SNP_A-1515942   rs966134        1       8082754 TSC0272985      BB
0.212891
637     SNP_A-1509129   rs205474        1       10542407        TSC0043572
BB      0.122514
9481    SNP_A-1512107   rs1281034       1       10706737        TSC0984465
NoCall  10
432     SNP_A-1514390   rs718206        1       11004020        TSC0041639
BB      0.66461
10471   SNP_A-1518041   rs2206321       1       12221853        TSC1262794
AA      0.058009
[snip]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to