Hi all, I kinda solved some of that last problem I had, but have run into more... basically I'm trying to do a multiple sort on my multidimensional data structure ( a hash of arrays of arrays!).... hre's the deal
file example
##########################################################
score start end identifier
9e-63 285 1001 ENSP00000218091
3e-58 293 996 ENSP00000218091
1e-57 280 1003 ENSP00000218091
1e-42 280 1003 ENSP00000218091
1e-42 280 1003 ENSP00000218092
1e-42 284 1004 ENSP00000218092
##########################################################
code:
##########################################################
while (<IN>){
@array = ();
if(/^\d/){
chomp $_;
@fields = split(/\s+/,$_);
if ($fields[3] =~ /ENSP/ && $fields[0] < 0.0005){
push (@array, $fields[0],
$fields[1],
$fields[2],
$fields[3],);
$match = $fields[8];
push (@{$hash{$match}}, [@array]);
}#end if
}#end if
close (IN);
############################################################
This gives me a hash with each identifier as a new key. The value for each key is an array of arrays. In this case, there are 2 arrays, one holding 4 arrays (each holding individual values corresponding to the values in the file fields) for all rows that match ENSP00000218091, the other holding 2 arrays for matches to ENSP00000218092.
I'm trying to sort firstly by identifier. This works with:
############
code:
foreach $match (sort keys %hash){
print "\n\n$match: ", scalar(@{$hash{$match}}), "hits.";
}#end foreach.
######################
But I'm trying to sort by firstly identifier, and then start position. I used the following code, but it doesn't seem to work. Can anyone help me?
######################
foreach (sort {@{$hash{$match}}->[$b]->[1] <=> @{$hash{$match}}->[$a]->[1]} keys %hash){
print "\n$match: ", scalar(@{$hash{$match}}), "hits.";
}#end foreach
###########################
Is it possible to use the 'or' operator to fit both of these into one command?
Thanks
file example
##########################################################
score start end identifier
9e-63 285 1001 ENSP00000218091
3e-58 293 996 ENSP00000218091
1e-57 280 1003 ENSP00000218091
1e-42 280 1003 ENSP00000218091
1e-42 280 1003 ENSP00000218092
1e-42 284 1004 ENSP00000218092
##########################################################
code:
##########################################################
while (<IN>){
@array = ();
if(/^\d/){
chomp $_;
@fields = split(/\s+/,$_);
if ($fields[3] =~ /ENSP/ && $fields[0] < 0.0005){
push (@array, $fields[0],
$fields[1],
$fields[2],
$fields[3],);
$match = $fields[8];
push (@{$hash{$match}}, [@array]);
}#end if
}#end if
close (IN);
############################################################
This gives me a hash with each identifier as a new key. The value for each key is an array of arrays. In this case, there are 2 arrays, one holding 4 arrays (each holding individual values corresponding to the values in the file fields) for all rows that match ENSP00000218091, the other holding 2 arrays for matches to ENSP00000218092.
I'm trying to sort firstly by identifier. This works with:
############
code:
foreach $match (sort keys %hash){
print "\n\n$match: ", scalar(@{$hash{$match}}), "hits.";
}#end foreach.
######################
But I'm trying to sort by firstly identifier, and then start position. I used the following code, but it doesn't seem to work. Can anyone help me?
######################
foreach (sort {@{$hash{$match}}->[$b]->[1] <=> @{$hash{$match}}->[$a]->[1]} keys %hash){
print "\n$match: ", scalar(@{$hash{$match}}), "hits.";
}#end foreach
###########################
Is it possible to use the 'or' operator to fit both of these into one command?
Thanks