comparison scripts/pickUniqPairFastq_MEM.pl.orig @ 21:9672fe07a232 draft default tip

planemo upload for repository https://github.com/portiahollyoak/Tools commit 0fea84d05f8976b8360a8b4943ecb01b87e3ade0-dirty
author mvdbeek
date Mon, 05 Dec 2016 09:58:47 -0500
parents
children
comparison
equal deleted inserted replaced
20:6e02b9179a24 21:9672fe07a232
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 elsif ($as > 0) {$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], -alphabet => 'dna');
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;