1
|
1 ########################################################################
|
|
2 # JAMMv1.0.7rev1 is a peak finder for joint analysis of NGS replicates.
|
|
3 # Copyright (C) 2014-2015 Mahmoud Ibrahim
|
|
4 #
|
|
5 # This program is free software: you can redistribute it and/or modify
|
|
6 # it under the terms of the GNU General Public License as published by
|
|
7 # the Free Software Foundation, either version 3 of the License, or
|
|
8 # (at your option) any later version.
|
|
9 #
|
|
10 # This program is distributed in the hope that it will be useful,
|
|
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 # GNU General Public License for more details.
|
|
14 #
|
|
15 # You should have received a copy of the GNU General Public License
|
|
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17 #
|
|
18 # Contact: mahmoud.ibrahim@mdc-berlin.de
|
|
19 ########################################################################
|
0
|
20
|
|
21
|
|
22
|
|
23 use feature qw(say);
|
|
24
|
|
25
|
|
26 # ==================
|
|
27 # Parsing Arguments
|
|
28 # ==================
|
|
29
|
|
30 #initialize to NULL
|
|
31 my $bed_file = NULL; #bed file
|
|
32 my $shift_size = NULL; #shift size
|
|
33 my $read_length = NULL; #read length
|
|
34
|
|
35 #Parse the arguments
|
|
36 $bed_file = $ARGV[0]; #bed file
|
|
37 $shift_size = $ARGV[1]; #shift size
|
|
38 $read_length = $ARGV[2]; #read length
|
|
39
|
|
40 #=======================> DONE!
|
|
41
|
|
42
|
|
43
|
|
44 # ========================================
|
|
45 # Parse the bed file and extend the reads
|
|
46 # ========================================
|
|
47
|
|
48 #open the file
|
|
49 open(DATA, $bed_file) || die("Can't open the bed file, probably you gave me the wrong path!");
|
|
50
|
|
51 #loop through the rest of the file line by line (To do: look for a faster way)
|
|
52 while (<DATA>) {
|
|
53 my ($start, $strand) = split(/\t/,$_,2);
|
|
54 $strand =~ s/\015?\012?$//;
|
|
55
|
|
56
|
|
57
|
|
58 #plus strand
|
|
59 if ($strand eq '+') {
|
|
60 #do nothing
|
|
61 }
|
|
62 #minus strand
|
|
63 elsif ($strand eq '-') {
|
|
64 $start = $start - $shift_size + $read_length; #difference between $start and $end should be equal to fragment length ($shift_size)
|
|
65 }
|
|
66 #bad format
|
|
67 else {
|
|
68 die("It appears the bed file is not formatted properly. Specifically, I expect to find either + or - in the second column, but I found something else!");
|
|
69 }
|
|
70 if ($start >= 0) {
|
|
71 #Now write the new line
|
|
72 say join "\t", $start, $strand;
|
|
73 }
|
|
74 }
|
|
75 #=======================> DONE!
|