#!/usr/bin/perl -w use strict; use warnings; use Getopt::Std; use IO::File; use File::Spec; my %opts = (); getopts('s:h', \%opts); if (exists $opts{'h'}) { usage(); exit 1; } #my $score_file = $ARGV[0] || ''; # Takes the score file from matrix_comparison.pl as input my $score_file = $opts{'s'}; my $score_fh = IO::File->new("<$score_file") or die("can't open $score_file!\n$!"); #open( IN, $score_file ) or die "Can't open '$score_file'"; my $motif; while ( defined( my $score_line = $score_fh->getline() ) ) { chomp $score_line; my $number; my $score; if ( $score_line =~ /^(MOTIF_\d+)/ ) { $motif = $1; next; } else { # ( $number, $score ) = split( /\s+/, $score_line ); ( $number, $score ) = split( /\b\s/, $score_line ); } if ( !( defined $motif && defined $number && defined $score ) ) { die "Wierdness!"; } my $motif_path = sprintf "%d/%s", $number, $motif; # open( F, $motif_path ) or die "Can't open '$motif_path'"; my $motif_path_fh = IO::File->new("<$motif_path") or die("can't open $motif_path!\n$!"); my $less_count = 0; my $tot_count = 0; # while ( my $perm_line = ) { while ( defined( my $perm_line = $motif_path_fh->getline() ) ) { chomp $perm_line; ++$tot_count; ++$less_count if ( $perm_line < $score ); } $motif_path_fh->close(); # close(F); my $summary_file = $motif . '_hits.list'; open( MOTIF, ">>$summary_file" ) or die( "No summary!" ); printf MOTIF "%s\t%.4f\t%4d\t%.3f\n", $motif_path, $score, $less_count, $less_count / $tot_count; close(MOTIF); } $score_fh->close(); #close(IN); # Usage sub usage { print STDERR <