-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #269 from RoanKanninga/master
added small comments
- Loading branch information
Showing
4 changed files
with
90 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#!/usr/bin/perl -w | ||
use strict; | ||
use warnings; | ||
use diagnostics; | ||
use Getopt::Long; | ||
use List::Util qw(first); | ||
use POSIX; | ||
|
||
my ($help, $inputbed, $output, $outputfolder); | ||
|
||
#### get options | ||
GetOptions( | ||
"h" => \$help, | ||
"input=s" => \$inputbed, | ||
"output=s" => \$output, | ||
"outputfolder=s" => \$outputfolder, | ||
); | ||
usage() and exit(1) if $help; | ||
# mandatory args | ||
usage() and exit(1) unless $inputbed; | ||
usage() and exit(1) unless $output; | ||
usage() and exit(1) unless $outputfolder; | ||
|
||
chomp $inputbed; | ||
chomp $output; | ||
chomp $outputfolder; | ||
|
||
|
||
#Open input and output files | ||
open (INPUT, "<", $inputbed ) or die $!; | ||
|
||
#Read bed file | ||
my $number=0; | ||
my $regnum = 1; | ||
my $binSize= 1; | ||
while (my $lines=<INPUT>){ | ||
chomp $lines; | ||
if ($lines !~ m/^track.+/gs) { | ||
#print $lines . "\n"; | ||
#Remove chr before chrNumber and substitute M with MT | ||
$lines =~ s/^chr//i; | ||
$lines =~ s/^M\t/MT\t/i; | ||
#Split line | ||
my @array = split("\t", $lines); | ||
my $chr = $array[0]; | ||
my $start = $array[1]; | ||
my $stop = $array[2]; | ||
my $gene = $array[3]; | ||
my $region = ($stop-$start); | ||
#Iterate over region and create bins | ||
open (OUTPUT, ">>", "$outputfolder/$output.per_base.bed" ) or die $!; | ||
for (my $i=($start); $i<$stop; $i=($i+$binSize)){ | ||
print OUTPUT "$chr\t" . $i . "\t" . $i . "\t+\t$gene\n"; | ||
} | ||
close(OUTPUT); | ||
|
||
$regnum++; | ||
}else{ | ||
#Negative check | ||
#print "$lines\n"; | ||
} | ||
} | ||
sub usage { | ||
print <<EOF; | ||
######################################################################################### | ||
This script splits a bed file in regions of a length specified by the user. | ||
######################################################################################### | ||
Usage: ./create_per_base_bed.pl | ||
\t-input\t\t\tInput bed file. | ||
\t-output\t\t\tOutput prefix | ||
\t-outputfolder\t\tOutputfolder | ||
Example usage: perl create_per_base_bed.pl -input target_exons.bed -output exonIntervals | ||
######################################################################################### | ||
EOF | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters