modified: Makefile
[GalaxyCodeBases.git] / perl / etc / justonce / readsCount_threads.pl
blob72124ccc48ff1a2e1ee984dcf0e13348de9175ec
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4 use threads;
6 my $maxthreads = 8;
8 my %file;
9 while (<>) {
10 chomp;
11 my $a = $_;
12 s/\w+\///;
13 if (open $file{$_}, "-|", "gzip -dc $a") {
14 print STDERR "open $a was succesful!\n";
15 } else {
16 print STDERR "open $a failed!\n";
19 print STDERR "Read file list complete!\n";
21 my (%thread,%count);
22 my $t = 0;
23 foreach (sort keys %file) {
24 ++$t;
25 if ($t > $maxthreads ) {
26 for (sort keys %thread) {
27 $count{$_} = $thread{$_}->join;
28 print STDERR "$t: Count $_ complete!\n";
29 delete $thread{$_};
31 $t = 0;
33 if (/sam.gz$/) {
34 $thread{$_} = threads->new(\&countsam, $file{$_});
35 } elsif (/fq.gz$/) {
36 $thread{$_} = threads->new(\&countfq, $file{$_});
40 foreach (sort keys %thread) {
41 $count{$_} = $thread{$_}->join;
42 print STDERR "Count $_ complete!\n";
45 foreach (sort keys %count) {
46 print $_, "\t", join( ',',@{$count{$_}} ), "\n";
49 sub countfq {
50 my $in = shift;
51 my ($lc,$f)=(0,0);
52 while (<$in>) {
53 ++$lc;
54 if (/^\@[^ ]+ [12]:([YN]):/) {
55 ++$f if $1 eq 'N';
58 close $in;
59 return [$lc/4,$f];
62 sub countsam {
63 my $in = shift;
64 my $lc;
65 while (<$in>) {
66 next if /^@/;
67 ++$lc;
69 close $in;
70 return [$lc/2];