Mercurial > repos > jbrayet > extractcentralregions_1_0_docker
comparison extractCentralRegions.pl @ 1:eaf2e2b19e41 draft
Uploaded
author | jbrayet |
---|---|
date | Tue, 05 Jan 2016 09:13:56 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:1953d57c6941 | 1:eaf2e2b19e41 |
---|---|
1 #!/usr/bin/perl -w | |
2 use strict; | |
3 | |
4 #creats a BED file with central area of peaks | |
5 | |
6 | |
7 my $usage = qq{ | |
8 $0 | |
9 | |
10 ----------------------------- | |
11 mandatory parameters: | |
12 | |
13 -f filename file with sites in BED format | |
14 -l value length of the cental regions | |
15 | |
16 ----------------------------- | |
17 optional parameters: | |
18 -v for verbose | |
19 -head 1/0 if there is a header | |
20 -o filename output file | |
21 }; | |
22 | |
23 if(scalar(@ARGV) <2){ | |
24 print $usage; | |
25 exit(0); | |
26 } | |
27 | |
28 my $flank = 0; | |
29 my $ResFilename = ""; | |
30 my $file = ""; | |
31 my $header = 0; | |
32 my $verbose = 0; | |
33 | |
34 while(scalar(@ARGV) > 0){ | |
35 my $this_arg = shift @ARGV; | |
36 if ( $this_arg eq '-h') {print "$usage\n"; exit; } | |
37 elsif ( $this_arg eq '-f') {$file = shift @ARGV;} | |
38 elsif ( $this_arg eq '-v') {$verbose = 1;} | |
39 elsif ( $this_arg eq '-head') {$header = shift @ARGV;} | |
40 elsif ( $this_arg eq '-o') {$ResFilename = shift @ARGV;} | |
41 elsif ( $this_arg eq '-l') {$flank = shift @ARGV;$flank /=2;} | |
42 elsif ( $this_arg =~ m/^-/ ) { print "unknown flag: $this_arg\n";} | |
43 } | |
44 | |
45 | |
46 | |
47 | |
48 my $count = 0; | |
49 my %hash; | |
50 | |
51 open (FILE, "<$file") or die "Cannot open file $file!!!!: $!"; | |
52 open (OUT, ">$ResFilename") or die "Cannot open file $ResFilename!!!!: $!"; | |
53 | |
54 if ($header) { | |
55 <FILE>; | |
56 } | |
57 | |
58 while (<FILE>) { | |
59 s/\R//g; | |
60 next if (/^#/); | |
61 next if (/track/); | |
62 next if (/summit/); | |
63 my @a = split /\s/; | |
64 my $chr = $a[0]; | |
65 my $maxPos = $a[3]; | |
66 my $score = $a[4]; | |
67 if ($maxPos=~/\D/) { | |
68 $maxPos = int(($a[1]+$a[2])/2); | |
69 } elsif ($maxPos < $a[1]){ #MACS intervals | |
70 $maxPos = $a[1]+$a[4]; | |
71 $score = $a[5]; | |
72 } | |
73 my $firstPos = $maxPos-$flank; | |
74 my $lastPos = $maxPos+$flank; | |
75 | |
76 my $ID=$chr.":".$firstPos."_".$lastPos."_".$score ; | |
77 unless (exists($hash{$ID})) { | |
78 $hash{$ID}=1; | |
79 $count++; | |
80 print OUT "$chr\t$firstPos\t$lastPos\t$score\n"; | |
81 } | |
82 } | |
83 | |
84 #print "$file\t$count\n"; | |
85 close FILE; | |
86 close OUT; | |
87 |