Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: print multiple hashes as multiple columns

by dulwar (Scribe)
on Jun 29, 2012 at 23:17 UTC ( #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"; }


Comment on Re: print multiple hashes as multiple columns
Select or Download Code
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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (13)
As of 2014-12-18 20:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (61 votes), past polls