my $maxBits=60; # hash reference - gave error message below
my %maxBits=60; # wrong
%maxBits=map {$_=>60} ; #?
####
Can't use string ("60") as a HASH ref while "strict refs" in use at flagginscript_Flag1.pl line 58, line 1.
####
############### read in blast table and parse #######
my $in_blast_tab=$ARGV[0];
open(IN,$in_blast_tab) or die "cannot open $in_blast_tab\n";
my $HoFlg1={}; my $HoFlg2={};
my $maxBits=60;
#%maxBits=map {$_=>60} ; # or intialize all values to be 60 using map
print "maxBits after intialization\n";
print Dumper($maxBits);
while (my $line=) {
next if ($line =~ /^#/);
next unless ($line =~ /\S/);
chomp $line;
my ($Query_id,$strand,$Subj_id,$Perc_iden,$align_len,$num_mm,$gap,$q_start,$q_end,$s_start,$s_end,$e_value,$bit_score)=split("\t",$line); # extra field of strand
next if ($bit_score <60);
if ($bit_score > $maxBits->{$Query_id}){
$maxBits->{$Query_id}=$bit_score;
}
my ($Flag1, $Flag2 ) = &Flag( $Subj_id, \%proph_prots, \%euk_prots, \%vir_prots );
$HoFlg1->{$Query_id}->{$Flag1}->{$bit_score}++;
$HoFlg2->{$Query_id}->{$Flag2}->{$bit_score}++;
print join("\t",$Query_id,$Subj_id,"bit",$bit_score,"F1",$Flag1,"F2",$Flag2,"maxBits{Query}",$maxBits->{$Query_id})."\n";
}
#print "Hash HoFlg1\n";
#print Dumper($HoFlg1)."\n";
#print "Hash maxBits\n";
#print Dumper(%maxBits)."\n";
sub Flag {
my ( $Subj_id, $proph_prots, $euk_prots, $vir_prots ) = @_;
return "Proph", "Phage" if exists $$proph_prots{$Subj_id};
return "Euk", "Euk" if exists $$euk_prots{$Subj_id};
return "Vir", "Phage" if exists $$vir_prots{$Subj_id};
return "Bact", "Bact";
} ## end sub Flag
my $bits_perc=$ARGV[1]; # consider hits within this percent of top hit
my $outfile="$in_blast_tab.$bits_perc.FlagTab";
open(OUT,">",$outfile);
print OUT "# this file was generate by $0 on".localtime(time)."\n";
print OUT "# these are the counts of hits for each Flag that are within $bits_perc of the top bit_score\n";
print OUT "#".join("\t",qw(Query count_Proph count_Euk count_Vir count_Bact))."\n";
my @flag_list2=("Phage","Euk","Bact");
my @flag_list1=("Proph","Euk","Vir","Bact");
foreach my $q (keys %{$HoFlg1}){
print OUT "$q\t";
for my $flag (@flag_list1){
my $count={};
if (! exists $HoFlg1->{$q}->{$flag}){
$count->{$flag}=0;
}
else {
for my $b (keys %{$HoFlg1->{$q}->{$flag}}){
if ($b > $bits_perc*$maxBits->{$q}){
$count->{$flag} += $HoFlg1->{$q}->{$flag}->{$b};
}
}
}
if (! defined $count->{$flag}){
$count->{$flag}=0;
}
print OUT "$count->{$flag}\t";
}
print OUT "\n";
}