annotate [APliBio]Nebula tools suite/Nebula/ExtractCentralRegions/extractCentralRegions.pl @ 4:0b8b39c2ce01 draft default tip

Uploaded
author alermine
date Wed, 14 Nov 2012 06:04:04 -0500
parents 2ec3ba0e9e70
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
1 #:t:::::::::::::::::g@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
2 #:t::::::::::::::;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
3 #:::::::::::::z;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
4 #::::::::::::i@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
5 #::::::::::::@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@$@@@@
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
6 #:::::::::::3@@@@@@@@@@@@@@@@@@@@@@@@@B@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
7 #::::::::::3@@@@@@@@@@@@@@@@@@@@@BEEESSE5EEEEBBM@@@@@@@@@@@@@@@@@@@@@@@@@@
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
8 #::::::::::3@@@@@@@@@@@@@@@@@@@@BEEEEEE35EE55E2355E5SBMB@@@@@@@@@@@@@@@@@$
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
9 #::::::::::@@@@@@@@@@@@@@@@@@@EEEE55533t3tttt::::::!!!!7755E755SBBMMM@@@MM
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
10 #::::::::::3@@@@@@@@@@@@@@@@@@EEEE2t3ttttt:::::::::::::::::::::::!7?5225EE
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
11 #::::::::::3@@@@@@@@@@@@@@@@@@EEEEE31t::::::::::::::::::::::::::::::::3E5@
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
12 #::::::::::3@@@@@@@@@@@@@@@@@@EEEEEEtt:::::::::::::::::::::::::::::::::353
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
13 #::::::::::3@@@@@@@@@@@@@@@@@@EEEEEE1ttz::::::::::::::::::::::::::::::::35
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
14 #:::::::::::@@@@@@@@@@@@@@@@@@EEEEEEEtz1::::::::::::::::::::::::::::::::t:
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
15 #:::::::::!3@@@@@@@@@@@@@@@@@@@EEEEEttt::::::::::::::::::::::::::::::::;zz
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
16 #::::::::::@@@@@@@@@@@@@@@@@@@@EEEEEttt:::::z;z:::::::::::::::::::::::::13
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
17 #::::::::::3B@@@@@@@@@@@@@@@@@@EEEEEEE3tt:czzztti;:::::::::::::::::::::::3
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
18 #::::ttt::::3@@@@@@@@@@@@@@@@EEEEE5EE25Ezt1EEEz5Etzzz;;;;:::::::::::::::::
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
19 #:::::::::::I9@@@@@@@@@@@@@@@@@@@@@@@@@@EEEEEE@@@@@@@@@@@@@@Ez;:::::::::::
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
20 #:::::::::::::E@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@Ez::::::
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
21 #::::::::::::::E@@@@@@@@@@@@@@@@@@@@@@@@@@@@@BE5EBB@@@@@@@@@@@@@@@EEE:::::
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
22 #:::::::::::::::@@@@@@@@@@@@@@@@@@@@@@@@@@@@E1::35@@@@@@@@@@ME3MMME2::::::
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
23 #:::::::::::::::?@@@@@@@@@@@@@@@@@@M@@@@@@@EE:::::3SB@@BBESEEt::::::::::::
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
24 #::::::::::::::::J$@@@@@@@B@@@@@@@@@@@@@@@@EE:::::::!35E33t:::::::::::::::
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
25 #:::::::::::::::::3@E@@@EE5EESE5EESE@@@@@@@Et::::::::::::tz:::::::::::::::
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
26 #:::::::::::::::::J@E$@EEE5133555SE@@@@@@@@Et:::::::::::::::::::::::::::::
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
27 #::::::::::::::::::E@E@EEEEtt3523EEE@@@@@@@E::::::::::::::::::::::::::::::
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
28 #:t::::::::::::::::JEE3@@@EEEEEEEEEE@@@@@@@E:::::::::t;:::::::::::::::::::
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
29 #:t:::::::::::::::::!5ES@EEEEEEEEES@@@@@@@@@E;:::;;;:3Ez::::::::::::::::::
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
30 #:t::::::::::::::::::::JE@@EEEEEEE@@@@@@@@@@@@@@@@ME!:::;:::::::::::::::::
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
31 #:tz::::::::::::::::::::JE@@@EEEE@@@@@@@@@@@@@@EE!:::::::t::::::::::::::::
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
32 #:t::::::::::::::::::::::3@@@@@@@@@@@@@@@@@@ESBE::::::::::::::::::::::::::
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
33 #:::::::::::::::::::::::::Q@@@@@@@@@@@@@@@@EE3EE;:::::zzzz::::::::::::::::
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
34 #:::::::::::::::::::::::::3@@@@@@@@@@@@@@@@@@@@@@NN@@@@@@Ez:::::::::::::::
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
35 #:zt:::::::::::::::::::::::3@@@@EE@@@@@@@@@@EEEEt::;z113E5t:::::::::::::::
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
36 #::tt:::::::::::::::::::::::3@@@E@@@@@@@@@@@@@@@@BEt::::::::::::::::t:::::
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
37 #:tt:t:::::::::::::::::::::::?S@@@@@@@@@@@BBEEE51!::::::::::::::zzzEt:::::
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
38 #::::::::::::::::::::::::::::::3Q@@@@@@@BEEEEEt:::::::::::::;zz@@@EE::::::
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
39 #::::::::::::::::::::::::::::::::75B@@@@@EEEtt;:::::::::;zz@@@@BEEEtz:::::
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
40 #::::::::::::::::::::::::::::::::::::?9@@@@@@@@@@@E2Ezg@@@@@B@@@EEEE1t::::
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
41 #:::::::::::::::::::::::::::::::::::::::3@@@@@@@@@@@@@@@@@@@E@EEEEEEEzzz::
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
42 #::::::::::::::::::::::::::::::::::::;@@@@@@@@@@@@@@@@@@@@@@@EEEEEEE5ttttt
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
43 #:::::::::::::::::::::::::::::::;g@@@@@@@@@@@@@@@@@@@@@@@@@@EEEEEEEEEEEtzt
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
44 #::::::::::::::::::::::::::::;@@@@@@@@@@@@@@@@@@@@@@@@@@E@@EEEEEEEEEEEE@@@
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
45 #::::::::::::::::::::::::::g@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@EEEE3EEEE@@@@@@@
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
46 #:::::::::::::::::::::;;g@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@EEEt33@@@@@@@@@@
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
47 #:::::::::::::::::;g@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@E@@@@@@EEEtg@@@@@@@@@@@@
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
48 #::::::::::::::;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@EEEE@@@@@@@@@@@@@@@@@@@@@@@@
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
49 #:::::::::::::@@@@@@@@@@@@@@@@@$@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
50 #::::::::::;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
51 #
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
52 # Copyleft ↄ⃝ 2012 Institut Curie
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
53 # Author(s): Valentina Boeva, Alban Lermine (Institut Curie) 2012
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
54 # Contact: valentina.boeva@curie.fr, alban.lermine@curie.fr
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
55 # This software is distributed under the terms of the GNU General
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
56 # Public License, either Version 2, June 1991 or Version 3, June 2007
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
57
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
58 #!/usr/bin/perl -w
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
59 use strict;
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
60
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
61 #creats a BED file with central area of peaks
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
62
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
63
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
64 my $usage = qq{
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
65 $0
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
66
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
67 -----------------------------
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
68 mandatory parameters:
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
69
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
70 -f filename file with sites in BED format
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
71 -l value length of the cental regions
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
72
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
73 -----------------------------
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
74 optional parameters:
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
75 -v for verbose
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
76 -head 1/0 if there is a header
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
77 -o filename output file
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
78 };
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
79
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
80 if(scalar(@ARGV) <2){
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
81 print $usage;
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
82 exit(0);
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
83 }
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
84
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
85 my $flank = 0;
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
86 my $ResFilename = "";
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
87 my $file = "";
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
88 my $header = 0;
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
89 my $verbose = 0;
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
90
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
91 while(scalar(@ARGV) > 0){
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
92 my $this_arg = shift @ARGV;
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
93 if ( $this_arg eq '-h') {print "$usage\n"; exit; }
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
94 elsif ( $this_arg eq '-f') {$file = shift @ARGV;}
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
95 elsif ( $this_arg eq '-v') {$verbose = 1;}
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
96 elsif ( $this_arg eq '-head') {$header = shift @ARGV;}
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
97 elsif ( $this_arg eq '-o') {$ResFilename = shift @ARGV;}
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
98 elsif ( $this_arg eq '-l') {$flank = shift @ARGV;$flank /=2;}
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
99 elsif ( $this_arg =~ m/^-/ ) { print "unknown flag: $this_arg\n";}
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
100 }
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
101
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
102
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
103
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
104
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
105 my $count = 0;
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
106 my %hash;
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
107
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
108 open (FILE, "<$file") or die "Cannot open file $file!!!!: $!";
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
109 open (OUT, ">$ResFilename") or die "Cannot open file $ResFilename!!!!: $!";
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
110
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
111 if ($header) {
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
112 <FILE>;
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
113 }
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
114
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
115 while (<FILE>) {
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
116 chomp;
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
117 next if (/^#/);
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
118 next if (/track/);
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
119 my @a = split /\s/;
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
120 my $chr = $a[0];
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
121 my $maxPos = $a[3];
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
122 my $score = $a[4];
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
123 if ($maxPos=~/\D/) {
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
124 $maxPos = int(($a[1]+$a[2])/2);
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
125 } elsif ($maxPos < $a[1]){ #MACS intervals
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
126 $maxPos = $a[1]+$a[4];
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
127 $score = $a[5];
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
128 }
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
129 my $firstPos = $maxPos-$flank;
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
130 my $lastPos = $maxPos+$flank;
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
131
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
132 my $ID=$chr.":".$firstPos."_".$lastPos."_".$score ;
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
133 unless (exists($hash{$ID})) {
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
134 $hash{$ID}=1;
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
135 $count++;
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
136 print OUT "$chr\t$firstPos\t$lastPos\t$score\n";
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
137 }
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
138 }
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
139
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
140 #print "$file\t$count\n";
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
141 close FILE;
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
142 close OUT;
2ec3ba0e9e70 Uploaded
alermine
parents:
diff changeset
143