Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: print multiple hashes as multiple columns

by dulwar (Monk)
on Jun 29, 2012 at 23:17 UTC ( [id://979191]=note: print w/replies, xml ) Need Help??

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
    Thankyou, this (well both posts) were very helpfull

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://979191]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2024-04-17 14:37 GMT
Find Nodes?
    Voting Booth?

    No recent polls found