hmm2pcov.pl 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. my (@cols,$total,$total_read,$nline);
  5. my $hmmf=shift;
  6. my $out=shift;
  7. my $sam=$hmmf;
  8. $sam=~s/\..+$//;
  9. open my $hfh, '<' , $hmmf or die "Cannot open file:$hmmf \n$!";
  10. while(<$hfh>){
  11. chomp;
  12. if(/^space\s+/){
  13. my @conts=split /\t/;
  14. for my $i (0..$#conts){
  15. push @cols ,$i if $conts[$i] eq 'space' or $conts[$i] eq 'start'
  16. or $conts[$i] eq 'end' or $conts[$i] eq 'gene'
  17. or $conts[$i] eq 'cor.gc' or $conts[$i] eq 'reads';
  18. }
  19. next;
  20. }
  21. my ($chr,$start,$end,$reads,$gene,$val)=(split /\t/)[@cols];
  22. $total += $val if $val=~/\d+\.?\d*$/;
  23. $total_read+=$reads;
  24. $nline++;
  25. }
  26. close($hfh);
  27. open $hfh, '<' , $hmmf or die "Cannot open file:$hmmf \n$!";
  28. open my $wfh , '>', $out or die "Cannot write file:$!\n";
  29. print $wfh join("\t",'contig','start','stop','name',$sam),"\n";
  30. while(<$hfh>){
  31. chomp;
  32. next if /^space\s+/;
  33. my ($chr,$start,$end,$reads,$gene,$val)=(split /\t/)[@cols];
  34. my $pval;
  35. if($val=~/\d+\.?\d*$/){
  36. $pval=sprintf("%.9f",$val/$total);
  37. }else{
  38. $pval=sprintf("%.9f",$reads/$total_read);
  39. }
  40. print $wfh join("\t",$chr,$start,$end,$gene,$pval ),"\n";
  41. }