1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
|
#!/usr/bin/env perl
use strict;
use warnings;
use Getopt::Long qw(:config no_ignore_case bundling pass_through);
my $usage = <<__EOUSAGE__;
###############################################################################
#
# Required:
#
# --left <string> left.fq.stats
# --right <string> right.fq.stats
#
# Optional
#
# --sorted flag indicating that entries are lexically sorted
# (this can account for differences in representation by
# reads in either file)
# Unpaired entries are ignored.
#
################################################################################
__EOUSAGE__
;
my $left_stats_file;
my $right_stats_file;
my $sorted_flag = 0;
&GetOptions( 'left=s' => \$left_stats_file,
'right=s' => \$right_stats_file,
'sorted' => \$sorted_flag,
);
unless ($left_stats_file && $right_stats_file) {
die $usage;
}
main: {
my ($left_fh, $right_fh);
print STDERR "-opening $left_stats_file\n";
if ($left_stats_file =~ /\.gz$/) {
open ($left_fh, "gunzip -c $left_stats_file | ") or die $!;
} elsif ($left_stats_file =~ /\.xz$/) {
open(${left_fh}, "xz -cd ${left_stats_file} | ") or die $!;
}
else {
open ($left_fh, $left_stats_file) or die $!;
}
print STDERR "-opening $right_stats_file\n";
if ($right_stats_file =~ /\.gz$/) {
open ($right_fh, "gunzip -c $right_stats_file | ") or die $!;
} elsif ($right_stats_file =~ /\.xz$/) {
open (${right_fh}, "xz -dc ${right_stats_file} | ") or die $!;
}
else {
open ($right_fh, $right_stats_file) or die $!;
}
print STDERR "-done opening files.\n";
my $left_text = <$left_fh>;
my $right_text = <$right_fh>;
while (1) {
#print STDERR "$left_text\n$right_text\n\n";
if ( (! $left_text) || (! $right_text)) {
last;
}
chomp $left_text;
chomp $right_text;
my ($left_median, $left_avg, $left_stdev, $left_pct, $left_acc, $left_cov) = split(/\t/, $left_text);
my ($right_median, $right_avg, $right_stdev, $right_pct, $right_acc, $right_cov) = split(/\t/, $right_text);
my $core_acc = $left_acc;
if ($left_acc =~ /^(\S+)\/\d$/) {
$core_acc = $1;
}
my $right_core = $right_acc;
if ($right_acc =~ /^(\S+)\/\d$/) {
$right_core = $1;
}
#print STDERR "$core_acc\t$right_core";
#if ($core_acc eq $right_core) { print STDERR "\tYES\n";} else { print STDERR "\n"; }
unless ($right_core eq $core_acc) {
if ($sorted_flag) {
if ($left_acc lt $right_acc) {
$left_text = <$left_fh>; # advance left
}
else {
# advance right
$right_text = <$right_fh>;
}
next;
}
else {
die "Error, core accs are not equivalent: [$core_acc] vs. [$right_core] reads, and --sorted flag wasn't used here.";
}
}
my $median_pair_cov = int( ($left_median+$right_median)/2 + 0.5);
my $avg_pair_cov = int ( ($left_avg + $right_avg)/2 + 0.5);
my $avg_stdev = int( ($left_stdev + $right_stdev)/2 + 0.5);
if ($median_pair_cov != 0) {
## ignore bad reads.
my $avg_pair_pct = int( ($left_pct + $right_pct) / 2 + 0.5);
print join("\t", $median_pair_cov, $avg_pair_cov, $avg_stdev, $avg_pair_pct, $core_acc) . "\n";
}
## advance next entries.
$left_text = <$left_fh>;
$right_text = <$right_fh>;
}
exit(0);
}
|