in reply to Re^3: Sort array using a ranking system from separate hash
in thread Sort array using a ranking system from separate hash
Sorry, I didn't include all my code, because it is long and not very good!
Just in case you think I am not trying to do it myself see the attached
#!/usr/bin/perl use strict; use warnings; use HBV; my $machine="PC"; my ($inputDataPath, $outputDataPath,$inPathForScript,$outPathForScript +) = HBV::PathFinder($machine); my $origfile = $outputDataPath. qw(individualAlleles\HLA-A-1_HBe_Analy +sis.txt); # HLA-A-1_HBe_Analysis.txt open (IN, $origfile) or die "cannot open $origfile"; my @columns; my $count = 0; my @genotypeAndAllele; my @binders; my @lineCount; my $bitBinder; my @bitBinder; my @copybinders; while (my $line = <IN>){ chomp $line; if ($line =~/^([A-Z]{9}).*(IOH.{7}).*([1-9].?).*(HLA.{8})/){ push @genotypeAndAllele,$4.' '.$2; push @lineCount,$3; } if ($line =~/^([A-Z]{9})/){ push @binders, $1; @copybinders = @binders; } } foreach my $el (@lineCount){ for (my $i=0; $i <$el; $i++){ my $bit = $binders[$i]; $bitBinder .= $bit." "; } push @bitBinder, $bitBinder; $bitBinder=''; splice @binders,0,$el; } my %alleleProtein; foreach my $item (@genotypeAndAllele){ $alleleProtein{$item}++; } my %bindersHash; foreach my $item (@copybinders){ $bindersHash{$item}++; } my %genoBinderAlleleHash; @genoBinderAlleleHash{@genotypeAndAllele} = +@bitBinder; foreach my $keys (sort {$a cmp $b} keys (%genoBinderAlleleHash)){ print "$keys \($alleleProtein{$keys}\) = $genoBinderAlleleHash{$keys}\ +n"; } foreach my $keys (sort {$bindersHash{$b} <=> $bindersHash{$a}} (keys ( +%bindersHash))){ print "$keys = $bindersHash{$keys}\n"; }
Sorry to have bothered you
|
|---|