-
Notifications
You must be signed in to change notification settings - Fork 0
/
grep-fastq
executable file
·63 lines (49 loc) · 961 Bytes
/
grep-fastq
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
#! /usr/bin/env perl
use strict;
use warnings;
use Getopt::Std;
our $opt_H;
our $opt_h;
our $opt_s;
our $opt_v;
sub usage {
print STDERR "Usage: $0 [-h] [-v] REGEXP < INPUT.fastq > OUTPUT.fastq\n";
print STDERR "-H - grep header instead of sequence\n";
print STDERR "-h - print help\n";
print STDERR "-s - print summary stats\n";
print STDERR "-v - invert search\n";
exit(@_);
}
my $stat = getopts('Hhsv');
if (!$stat) {
usage(1);
}
if ($opt_h) {
usage();
}
if ( $#ARGV != 0) {
usage(1);
}
my ($raw_re) = @ARGV;
my $re = qr/$raw_re/i;
my @lines;
my $grep_line = 1;
if ($opt_H) {
$grep_line = 0;
}
my $num_in = 0;
my $num_out = 0;
while (<STDIN>) {
push @lines, $_;
if ( $#lines < 3 ) { next; }
$num_in++;
my $found = ( $lines[$grep_line] =~ /$re/ );
if ($found && !$opt_v || !$found && $opt_v) {
$num_out++;
print @lines;
}
@lines = ();
}
if ($opt_s) {
print STDERR "### found $num_out of $num_in\n";
}