0
|
1 #!/usr/bin/perl
|
|
2
|
|
3 use Getopt::Std;
|
|
4 getopts('i:o:O:k:p:', \%opts) ;
|
|
5
|
|
6
|
|
7 # split
|
|
8 $prefix = "primary_$opts{'O'}"."_";
|
|
9 $command = "cd $opts{'p'} && bamtools split -in $opts{'i'} -tag RG -tagPrefix '$prefix' -stub $opts{'p'}/data" ;
|
|
10 #print $command ."\n";
|
|
11 system($command);
|
|
12 chdir($opts{'p'});
|
|
13 # rename to correct format.
|
|
14 my @ls = `ls data.primary_$opts{'O'}_RG_*`;
|
|
15 open OUT, ">$opts{'o'}";
|
|
16 $idx = 0;
|
|
17 foreach(@ls) {
|
|
18 chomp();
|
|
19 my $from = $_;
|
|
20 $from =~ m/(.*_RG_)(.*)(\.bam)/;
|
|
21 my $rg = $2;
|
|
22 # remove data_
|
|
23 my $to = substr($from,5,-4);
|
|
24 $to .= "_visible_bam_$opts{'k'}";
|
|
25 $to =~ s/RG_//;
|
|
26 $to =~ m/primary_(\d+)_(.*)_visible.*/;
|
|
27 $rgreplace = $2;
|
|
28 $rgreplace =~ s/\.|-|_//g;
|
|
29 $to =~ s/(primary_\d+_)(.*)(_visible.*)/$1$rgreplace$3/;
|
|
30 system("mv $from $to");
|
|
31 $idx++;
|
|
32 print OUT "File $idx : $to : ReadGroup: $rg\n";
|
|
33 }
|
|
34 close OUT;
|
|
35 exit;
|
|
36
|
|
37
|