
sessmurda
Novice
Jan 5, 2011, 12:20 PM
Post #1 of 2
(516 views)
|
|
Accessing hash of array of arrays
|
Can't Post
|
|
Hey all, I posted this question in a more complicated form before and got no responses. After taking care of a few other things earlier this week I'm back at trying to finish this script. What I want to do is take the data below, and for each hash key, if there are multiple lines where column 4 is equal, and if in those same lines column 5 is equal (both instances also want to set a wobble of + or - 5). If for a hash, there are say 3 instances where the 2 columns give the same values (within the wobble range), then I want to exclude those. Basically I need to know the syntax to access specific elements of a hash of arrays of arrays. The file format is below. TC356967 Scaffold4333 89.7818599311137 6443 7354 1 TC356967 Scaffold463974 89.3333333333333 7554 8067 -1 TC356967 Scaffold93112 89.3203883495146 7760 8068 1 TC356967 Scaffold174194 89.2733564013841 7781 8068 1 TC356967 Scaffold407210 89.0243902439024 7973 8054 1 TC356967 Scaffold13981 88.9487870619946 7553 8084 1 TC356967 Scaffold363276 88.8888888888889 7760 8083 1 TC356967 Scaffold214368 88.5844748858447 7554 8083 -1 TC356967 Scaffold299965 88.5245901639344 7781 8084 -1 TC356967 Scaffold221597 88.4615384615385 7554 8083 -1 TC356967 Scaffold192663 88.4507042253521 7729 8083 1 TC356967 Scaffold48509 88.4488448844885 7781 8083 1 TC356967 Scaffold88696 88.3668903803132 7554 8083 1 TC356967 Scaffold99960 88.2618510158014 7554 8083 1 TC356967 Scaffold1551 88.1944444444444 7551 8063 -1 TC356967 Scaffold14356 88.1481481481482 7554 8083 -1 TC356967 Scaffold148662 88.0733944954129 7760 8085 1 Code below.
use warnings; use Data::Dumper; open (IN, "$ARGV[0]") || die "nope\n"; my %data; while(<IN>) { chomp; my $line = $_; my ($key, $scaf, $perc, $start, $stop, $strand) = (split/\t/, $line); push @{ $data{$key} }, $line; #foreach $key (keys %data) #{ # my ($scaf1, $perc1, $start1, $stop1, $strand1) = @{$data{$name}}; #unless ( #} } print Dumper(\%data); Data Dumper prints output like: 'TC383408' => [ 'TC383408 Scaffold293195 100 1 132 1', 'TC383408 Scaffold45175 100 130 816 1' ], Meaning that I am creating the hash of array of arrays fine, but I am unsure how to access the specific elements. Any leads on how to compare specific elements of a hash of arrays of arrays? Thanks
|