view SplitOnRg.pl @ 1:76aff7bca1b2 draft

Uploaded
author geert-vandeweyer
date Tue, 18 Feb 2014 05:06:20 -0500
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;