Created
March 12, 2012 23:01
-
-
Save mjclark/2025264 to your computer and use it in GitHub Desktop.
Extract a specific ratio of reads from a BAM file
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 is probably not the best way to go about this, but it basically works. | |
#Keep in mind that PERL's "rand()" function isn't really random, but for this purpose it doesn't really matter. | |
#Suggested usage: samtools view -h <in.bam> | perl random_line_extraction.using_ratio.pl <ratio in decimal form> | samtools view -bS - > <out.bam> | |
$num=shift; | |
while($line=<STDIN>) { | |
chomp($line); | |
if($line =~ m/^@/) { | |
print "$line\n"; | |
} | |
else { | |
my $rnum = rand(); | |
if($rnum<=$num) { | |
print "$line\n"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment