diff SplitOnRg.pl @ 0:afa51021226c draft

Uploaded
author geert-vandeweyer
date Tue, 18 Feb 2014 04:18:08 -0500
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SplitOnRg.pl	Tue Feb 18 04:18:08 2014 -0500
@@ -0,0 +1,37 @@
+#!/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;
+	
+