0
|
1 #!/usr/bin/perl
|
|
2 ##############################################
|
|
3 #### Shifts minus strand reads by read length
|
|
4 #### Perl script
|
|
5 #############################################
|
|
6
|
|
7
|
|
8
|
|
9 use feature qw(say);
|
|
10
|
|
11
|
|
12 # ==================
|
|
13 # Parsing Arguments
|
|
14 # ==================
|
|
15
|
|
16 #initialize to NULL
|
|
17 my $bed_file = NULL; #bed file
|
|
18 my $shift_size = NULL; #shift size
|
|
19 my $read_length = NULL; #read length
|
|
20
|
|
21 #Parse the arguments
|
|
22 $bed_file = $ARGV[0]; #bed file
|
|
23 $shift_size = $ARGV[1]; #shift size
|
|
24 $read_length = $ARGV[2]; #read length
|
|
25
|
|
26 #=======================> DONE!
|
|
27
|
|
28
|
|
29
|
|
30 # ========================================
|
|
31 # Parse the bed file and extend the reads
|
|
32 # ========================================
|
|
33
|
|
34 #open the file
|
|
35 open(DATA, $bed_file) || die("Can't open the bed file, probably you gave me the wrong path!");
|
|
36
|
|
37 #loop through the rest of the file line by line (To do: look for a faster way)
|
|
38 while (<DATA>) {
|
|
39 my ($start, $strand) = split(/\t/,$_,2);
|
|
40 $strand =~ s/\015?\012?$//;
|
|
41
|
|
42
|
|
43
|
|
44 #plus strand
|
|
45 if ($strand eq '+') {
|
|
46 #do nothing
|
|
47 }
|
|
48 #minus strand
|
|
49 elsif ($strand eq '-') {
|
|
50 $start = $start - $shift_size + $read_length; #difference between $start and $end should be equal to fragment length ($shift_size)
|
|
51 }
|
|
52 #bad format
|
|
53 else {
|
|
54 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!");
|
|
55 }
|
|
56 if ($start >= 0) {
|
|
57 #Now write the new line
|
|
58 say join "\t", $start, $strand;
|
|
59 }
|
|
60 }
|
|
61 #=======================> DONE!
|