modified: Makefile
[GalaxyCodeBases.git] / projects / radseq / novogene / pickR1XTUreadsV2.pl
blob2d35bdbe8445048f448e26b479a686c75fb4d703
1 #!/usr/bin/env perl
2 use strict;
3 use warnings;
5 die "Usage: $0 <in sam.gz> <out sam.gz>\n" if @ARGV<2;
7 my $in=shift;
8 my $out=shift;
10 open I, '-|', "/bin/gzip -dc $in" or die "Error opening $in: $!\n";
11 open O, '|-', "/bin/gzip -9c >$out" or die "Error opening $out: $!\n";
12 open LOG, '>>', 'pickR1XTUreads.log1';
14 while (<I>) {
15 if (/^@/) {
16 print O;
17 next;
19 my $r1 = $_;
20 my @r1 = split /\t/, $r1;
21 my $r2 = <I>;
22 my @r2 = split /\t/, $r2;
23 if (($r1[1] & 0x40) and ($r2[1] & 0x80) and ($r1[0] eq $r2[0])) {
24 print O $r1,$r2 if (grep /XT:A:U/, @r1);
25 } else {
26 print LOG "Error!\t$in\t$r1[0]\t$r1[1]\t$r2[0]\t$r2[1]\n";
27 exit;
31 print LOG "Complete!\t$in\t$out\n";
33 close I;
34 close O;
35 close LOG;