in reply to print multiple hashes as multiple columns
$Euk is not initilized in your code before being used in:
$count_Euk{$Euk} ++ ;but I assume it was supposed to be:
$count_Euk{$contig} ++ ;Then the following, slightly modified script should do roughly what you want:
use strict; use warnings; my $infile=$ARGV[0]; open (IN,$infile) or die "cannot open $infile"; my %count_Bact; my %count_undef; my %count_ProphVir; my %count_Euk; my %processed; while (my $line=<IN>) { chomp $line; next if ($line =~/^#/) ; my ($geneid,$cons_flag)=split(/\t/,$line); my @geneid_columns=split(/_/,$geneid); my $contig=join("_",$geneid_columns[0],$geneid_columns[1],$gen +eid_columns[2],$geneid_columns[3]); if ($cons_flag eq "Bact"){ $count_Bact{$contig} ++; } if ($cons_flag eq "undef"){ $count_undef{$contig} ++; } if ($cons_flag eq "Proph_Vir" || $cons_flag eq "Vir" || $cons_ +flag eq "Proph"){ $count_ProphVir{$contig} ++; } if ($cons_flag eq "Euk"){ $count_Euk{$contig} ++ ; } $processed{$contig}++; } close (IN); my @counts = (\%count_Bact, \%count_undef, \%count_ProphVir, \%count_E +uk); for my $contig (keys %processed) { print join (' ', $contig, map { $_->{$contig} || 0} @counts) + , "\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: print multiple hashes as multiple columns
by AWallBuilder (Beadle) on Jul 04, 2012 at 08:58 UTC |