comparison scripts/pickUniqPos_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 use List::Util qw(sum);
4
5 die "perl $0 <sam>\n" if @ARGV<1;
6 open in,$ARGV[0];
7 my %pe;
8 while(<in>)
9 {
10 chomp;
11 my @f=split/\t/,$_,12;
12 ## read number 1 or 2
13 my ($rnum)=$f[1]=~/(\d)$/;
14
15 ## XT:A:*
16 my $xt="";
17 my @a=split(/\s+/, $_);
18 my $as=0;
19 my $xs=0;
20 for my $i (11..$#a) {
21 if ($a[$i] =~ /^AS:i:/) {
22 $a[$i] =~ s/AS:i://;
23 $as=$a[$i];
24 }
25 elsif ($a[$i] =~ /^XS:i:/) {
26 $a[$i] =~ s/XS:i://;
27 $xs=$a[$i];
28 }
29 if (($xs > 0) && ($as-$xs <= $ARGV[1])) {$xt="R";}
30 else {$xt="U";}
31 }
32
33 my $strand="+";
34 ## revcomp
35 if($f[1]=~/r/)
36 {
37 my $seq=Bio::Seq->new(-seq=>$f[9]);
38 $f[9]=$seq->revcom->seq;
39 $strand="-";
40 }
41
42 ## parse CIGAR
43 if($xt eq "U")
44 {
45 # CIGAR
46 my (@cigar_m)=$f[5]=~/(\d+)M/g;
47 my (@cigar_d)=$f[5]=~/(\d+)D/g;
48 my (@cigar_s)=$f[5]=~/(\d+)S/g;
49 my (@cigar_i)=$f[5]=~/(\d+)I/g;
50 my $aln_ln=sum(@cigar_m,@cigar_d);
51
52 print $f[2],"\t",$f[3]-1,"\t",$f[3]-1+$aln_ln,"\t$f[0]/$rnum\t",$f[9],"\t",$strand,"\n";
53 }
54 }
55 close in;
56