comparison scripts/pickUniqPairFastq_MEM.pl @ 0:28d1a6f8143f draft

planemo upload for repository https://github.com/portiahollyoak/Tools commit 132bb96bba8e7aed66a102ed93b7744f36d10d37-dirty
author portiahollyoak
date Mon, 25 Apr 2016 13:08:56 -0400
parents
children ca36262102d8
comparison
equal deleted inserted replaced
-1:000000000000 0:28d1a6f8143f
1 #!/share/bin/perl
2 use Bio::Seq;
3
4 die "perl $0 <sam> <output prefix>\n" if @ARGV<1;
5
6 open m1,">$ARGV[1].1.fastq";
7 open m2,">$ARGV[1].2.fastq";
8
9 open in,$ARGV[0];
10 my %pe;
11 while(<in>)
12 {
13 chomp;
14 my @f=split/\t/,$_,12;
15 ## read number 1 or 2
16 my ($rnum)=$f[1]=~/(\d)$/;
17
18 ## XT:A:*
19 my $xt="";
20 my @a=split(/\s+/, $_);
21 my $as=0;
22 my $xs=0;
23 for my $i (11..$#a) {
24 if ($a[$i] =~ /^AS:i:/) {
25 $a[$i] =~ s/AS:i://;
26 $as=$a[$i];
27 }
28 elsif ($a[$i] =~ /^XS:i:/) {
29 $a[$i] =~ s/XS:i://;
30 $xs=$a[$i];
31 }
32 if (($xs > 0) && ($as-$xs <= $ARGV[2])) {$xt="R";}
33 else {$xt="U";}
34 }
35
36 ## revcom the read mapped to the reverse strand
37 if($f[1]=~/r/)
38 {
39 my $seq=Bio::Seq->new(-seq=>$f[9]);
40 $f[9]=$seq->revcom->seq;
41 $f[10]=reverse $f[10];
42 }
43 if (($rnum == 1) || ($rnum == 2))
44 {
45 ${$pe{$f[0]}}[$rnum-1]=[$xt,$f[9],$f[10]];
46 }
47 }
48 close in;
49
50 foreach my $id (keys %pe)
51 {
52 my @rid=@{$pe{$id}};
53 if (($rid[0][1] ne "") && ($rid[1][1] ne "") && (($rid[0][0] eq "U" || $rid[1][0] eq "U")))
54 {
55 print m2 "@"."$id/2","\n",$rid[1][1],"\n","+$id/2","\n",$rid[1][2],"\n";
56 print m1 "@"."$id/1","\n",$rid[0][1],"\n","+$id/1","\n",$rid[0][2],"\n";
57 }
58 }
59 close m1;
60 close m2;