Mercurial > repos > geert-vandeweyer > bamtools_wrappers
view SplitOnRg.pl @ 2:2572b6f85654 draft default tip
added samtools requirement to splitonrg
author | geert-vandeweyer |
---|---|
date | Mon, 12 May 2014 02:06:26 -0400 |
parents | afa51021226c |
children |
line wrap: on
line source
#!/usr/bin/perl use Getopt::Std; getopts('i:o:O:k:p:', \%opts) ; # split $prefix = "primary_$opts{'O'}"."_"; $command = "cd $opts{'p'} && bamtools split -in $opts{'i'} -tag RG -tagPrefix '$prefix' -stub $opts{'p'}/data" ; #print $command ."\n"; system($command); chdir($opts{'p'}); # rename to correct format. my @ls = `ls data.primary_$opts{'O'}_RG_*`; open OUT, ">$opts{'o'}"; $idx = 0; foreach(@ls) { chomp(); my $from = $_; $from =~ m/(.*_RG_)(.*)(\.bam)/; my $rg = $2; # remove data_ my $to = substr($from,5,-4); $to .= "_visible_bam_$opts{'k'}"; $to =~ s/RG_//; $to =~ m/primary_(\d+)_(.*)_visible.*/; $rgreplace = $2; $rgreplace =~ s/\.|-|_//g; $to =~ s/(primary_\d+_)(.*)(_visible.*)/$1$rgreplace$3/; system("mv $from $to"); $idx++; print OUT "File $idx : $to : ReadGroup: $rg\n"; } close OUT; exit;