Mercurial > repos > portiahollyoak > temp
comparison scripts/pickOverlapPair.in.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 | 9672fe07a232 |
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 <input.insertion.refined.bp> <fragment size>\n" if @ARGV<1; | |
| 6 | |
| 7 my $title=$ARGV[0]; | |
| 8 $title =~ s/insertion.refined.bp/sorted.bam/; | |
| 9 my $frag=$ARGV[1]; | |
| 10 | |
| 11 open (input, "<$ARGV[0]") or die "Can't open $ARGV[0] since $!\n"; | |
| 12 print "Chr\tStart\tEnd\tTransposonName\tTransposonDirection\tClass\tVariantSupport\tFrequency\tJunction1\tJunction1Support\tJunction2\tJunction2Support\t5\'_Support\t3\'_Support\n"; | |
| 13 while (my $line=<input>) { | |
| 14 chomp($line); | |
| 15 my @a=split(/\t/, $line); | |
| 16 | |
| 17 my @b=split(/\(/, $a[6]); | |
| 18 my @c=split(/\(/, $a[7]); | |
| 19 my $terminal="5\'"; | |
| 20 my $reverse=0; | |
| 21 my $positive=$b[0]; | |
| 22 my $negative=$c[0]; | |
| 23 if ($b[0] > $c[0]) { | |
| 24 $terminal="3\'"; | |
| 25 $reverse=1; | |
| 26 my $swap=$b[0]; | |
| 27 $b[0]=$c[0]; | |
| 28 $c[0]=$swap; | |
| 29 } | |
| 30 my $lower=$b[0]-$frag; | |
| 31 my $upper=$c[0]+$frag; | |
| 32 system("samtools view -Xf 0x2 $title $a[0]\:$lower\-$upper > temp.sam"); | |
| 33 | |
| 34 open in,"temp.sam"; | |
| 35 my %ps=(); | |
| 36 my %me=(); | |
| 37 my $ref_sup=0; | |
| 38 my $soft_clip=0; | |
| 39 while(<in>) | |
| 40 { | |
| 41 chomp; | |
| 42 my @f=split/\t/,$_,12; | |
| 43 ## read number 1 or 2 | |
| 44 my ($rnum)=$f[1]=~/(\d)$/; | |
| 45 | |
| 46 ## XT:A:* | |
| 47 my ($xt)=$f[11]=~/XT:A:(.)/; | |
| 48 | |
| 49 ## Coordinate | |
| 50 if ($f[1]=~/r/) | |
| 51 { | |
| 52 my (@cigar_m)=$f[5]=~/(\d+)M/g; | |
| 53 my (@cigar_d)=$f[5]=~/(\d+)D/g; | |
| 54 my (@cigar_s)=$f[5]=~/(\d+)S/g; | |
| 55 my (@cigar_i)=$f[5]=~/(\d+)I/g; | |
| 56 my $aln_ln=sum(@cigar_m,@cigar_d); | |
| 57 $me{$f[0]}=$f[3]+$aln_ln-1; | |
| 58 } | |
| 59 else | |
| 60 { | |
| 61 $ps{$f[0]}=$f[3]; | |
| 62 } | |
| 63 | |
| 64 # ${$pe{$f[0]}}[$rnum-1]=[$xt,$coor]; | |
| 65 } | |
| 66 close in; | |
| 67 | |
| 68 | |
| 69 foreach my $id (keys %ps) | |
| 70 { | |
| 71 if (defined $me{$id}) | |
| 72 { | |
| 73 if (((($ps{$id}+5)<=$positive)&&($me{$id}>$negative)) || ((($me{$id}-5)>=$negative)&&($ps{$id}<$positive))) { | |
| 74 # if (((($ps{$id}+5)<=$b[0])&&($me{$id}>$c[0])) || ((($me{$id}-5)>=$c[0])&&($ps{$id}<$b[0]))) { | |
| 75 $ref_sup++; | |
| 76 # print "$id\n"; | |
| 77 } | |
| 78 } | |
| 79 } | |
| 80 | |
| 81 my $variant=$a[8]+$a[9]+$a[10]+$a[11]; | |
| 82 my $ratio=sprintf("%.4f", $variant/($variant+$ref_sup)); | |
| 83 if (($a[0] =~ /^\d{1,2}$/) || ($a[0] eq "X") || ($a[0] eq "Y")) {$a[0]="chr$a[0]";} | |
| 84 if ($reverse == 0) { | |
| 85 print "$a[0]\t$a[1]\t$a[2]\t$a[3]\t$a[4]\t$a[5]\t$variant\t$ratio\t$b[0]\t$a[8]\t$c[0]\t$a[9]\t$a[10]\t$a[11]\n"; | |
| 86 } | |
| 87 elsif ($reverse == 1) { | |
| 88 print "$a[0]\t$a[1]\t$a[2]\t$a[3]\t$a[4]\t$a[5]\t$variant\t$ratio\t$b[0]\t$a[9]\t$c[0]\t$a[8]\t$a[10]\t$a[11]\n"; | |
| 89 } | |
| 90 system("rm temp.sam"); | |
| 91 } | |
| 92 |
