Skip to content

Instantly share code, notes, and snippets.

@radaniba
Created November 29, 2012 17:23
Show Gist options
  • Save radaniba/4170544 to your computer and use it in GitHub Desktop.
Save radaniba/4170544 to your computer and use it in GitHub Desktop.
This script calls the program bigWigSummary to extract enrichment from a bunch of bigWig files (they can be a lot of Chip-Seq experiments for example) for a set of intervals stored in a bed file. You need to files to run the script, a bed file containing
# author : Radhouane Aniba
#!/usr/bin/perl -w
@files = <FOLDER_FOR_BigWigs/*.bigWig>;
# For this example we have 4 bigwig files
open(BEDFILE, "FILENAME");
while(<BEDFILE>)
{
# Good practice to store $_ value because
# subsequent operations may change it.
my($line) = $_;
# Good practice to always strip the trailing
# newline from the line.
chomp($line);
# Convert the line to upper case.
#$line =~ tr/[a-z]/[A-Z]/;
# Print the line to the screen and add a newline
my @coord = split(/\t/, $line);
my $a = $coord[1];
my $b = $coord[2];
print "$coord[0] \t $a \t $b \t $coord[3] \t $coord[4] \t";
my $i = 0;
# in the while loop you have to always put as limit (#of files -1)
while($i <= 3) {
$tmp1 = getIntervalScore($files[$i],$coord[0],$a,$b,1);
chomp($tmp1);
if($i == 3){
print "$tmp1 \n";
}else{print "$tmp1 \t";}
$i++;
}
}
close (BEDFILE);
sub getIntervalScore {
($bwfile, $chr, $start, $end, $step) = @_;
@score = `./bigWigSummary $bwfile $chr $start $end $step 2>&1`;
#print "RawData/bigWigSummary $bwfile $chr $start $end $step 2>&1";
$scoreval = $score[0];
if ($scoreval =~ m/no/){$scoreval = 0;}
return $scoreval;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment