comparison scripts/make.bp.bed.pl @ 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 28d1a6f8143f
children
comparison
equal deleted inserted replaced
20:6e02b9179a24 21:9672fe07a232
16 my $j=$i+1; 16 my $j=$i+1;
17 my $k=$i+2; 17 my $k=$i+2;
18 my $l=$i+3; 18 my $l=$i+3;
19 system("cut -f7,4,6,$j,$k,$l $ARGV[0] > temp"); 19 system("cut -f7,4,6,$j,$k,$l $ARGV[0] > temp");
20 open (input, "<temp") or die "Can't open temp since $!\n"; 20 open (input, "<temp") or die "Can't open temp since $!\n";
21 open (output, ">>$name.insertion.bp.bed") or die "Can't open $name.insertion.bp.bed since $!\n"; 21 open (output, ">$name.insertion.bp.bed") or die "Can't open $name.insertion.bp.bed since $!\n";
22 my $header=<input>; 22 my $header=<input>;
23 while (my $line=<input>) { 23 while (my $line=<input>) {
24 chomp($line); 24 chomp($line);
25 my @b=split(/\t/, $line); 25 my @b=split(/\t/, $line);
26 if (($b[4] ne "0")||($b[5] ne "0")) { 26 if (($b[4] ne "0")||($b[5] ne "0")) {
27 my @c=split(/\:/, $b[2]); 27 my @c=split(/\:/, $b[2]);
28 my @d=split(/\./, $c[1]); 28 my @d=split(/\./, $c[1]);
29 if ($c[0] eq "P") {next;}
29 if ($d[0] > $d[1]) { 30 if ($d[0] > $d[1]) {
30 my $temp=$d[0]; 31 my $temp=$d[0];
31 $d[0]=$d[1]; 32 $d[0]=$d[1];
32 $d[1]=$temp; 33 $d[1]=$temp;
33 } 34 }
34 my $lower=$d[0]; 35 my $lower=$d[0];
35 my $upper=$d[1]; 36 my $upper=$d[1];
36 if (($lower >= 0) && ($upper >= 0)) { 37 if (($lower >= 0) && ($upper >= 0)) {
37 print output "$c[0]\t$lower\t$upper\t$b[0]\t$b[1]\t$b[3]\t$b[4]\t$b[5]\n"; 38 print output "$c[0]\t$lower\t$upper\t$b[0]\t$b[1]\t$b[3]\t$b[4]\t$b[5]\n";
38 } 39 }
39 $chrs{$c[0]}=1; 40 $chrs{$c[0]}=1;
40 } 41 }
41 } 42 }
42 close input; 43 close input;
43 close output; 44 close output;
83 close input; 84 close input;
84 close output; 85 close output;
85 } 86 }
86 87
87 if (-s "tmp2") { 88 if (-s "tmp2") {
88 system("bedtools subtract -a tmp -b tmp2 -f 1.0 > tmp3"); 89 my %to_filter=();
89 open (input, "<tmp3") or die "Can't open tmp3 since $!\n"; 90 open (input, "<tmp2") or die "Can't open tmp2 since $!\n";
91 while (my $line=<input>) {
92 chomp($line);
93 my @a=split(/\t/, $line);
94 $to_filter{"$a[0]\:$a[1]\:$a[2]\:$a[3]\:$a[5]"}=1;
95 }
96 close input;
97 open (input, "<tmp") or die "Can't open tmp since $!\n";
90 open (output, ">$name.insertion.bp.bed") or die "Can't open $name.insertion.bp.bed since $!\n"; 98 open (output, ">$name.insertion.bp.bed") or die "Can't open $name.insertion.bp.bed since $!\n";
91 while (my $line=<input>) { 99 while (my $line=<input>) {
92 chomp($line); 100 chomp($line);
93 my @a=split(/\t/, $line); 101 my @a=split(/\t/, $line);
94 my $direction="sense"; 102 if (!defined $to_filter{"$a[0]\:$a[1]\:$a[2]\:$a[3]\:$a[5]"}) {
95 if ($a[5] eq "-") {$direction="antisense";} 103 my $direction="sense";
96 my $chr_num=$a[0]; 104 if ($a[5] eq "-") {$direction="antisense";}
97 $chr_num =~ s/chr//; 105 my $chr_num=$a[0];
98 if (($chrs{$a[0]} == 1) && (! defined $chrs{$chr_num})) {$chr_num=$a[0];} 106 $chr_num =~ s/chr//;
99 print output "$chr_num\t$a[1]\t$a[2]\t$a[3]\t$direction\t$a[6]\t$a[7]\t$a[8]\n"; 107 if (($chrs{$a[0]} == 1) && (! defined $chrs{$chr_num})) {$chr_num=$a[0];}
108 print output "$chr_num\t$a[1]\t$a[2]\t$a[3]\t$direction\t$a[6]\t$a[7]\t$a[8]\n";
109 }
100 } 110 }
101 close input; 111 close input;
102 close output; 112 close output;
103 } 113 }
114
115 system("rm tmp*");
116
104 } 117 }
105
106 system("rm tmp*");
107 118
108 } 119 }
109 } 120 }
110 121