5 die "\nAdd HEADER and TAG of READ GROUP to bam file.\nAuther: Woody\nUsage: $0 <in.bam> <out.bam>\n\n" if @ARGV<2;
14 open I
, "-|", "samtools view -h $in";
15 open HEAD
, ">", "$op.header.sam";
16 open READ
, "|-", "samtools view -bS - >$op.reads.bam";
18 warn "Adding TAG...\n";
27 my @b = split /:/, $a[0];
28 my $rg = "${ip}_$b[2]_$b[3]";
30 print READ
"$_\tRG:Z:$rg\n";
37 foreach (sort keys %RG) {
38 print HEAD
"\@RG\tID:$_\tPL:ILLUMINA\tSM:$ip\n";
41 warn "Printing HEADER...\n";
42 my $time = localtime();
43 print HEAD
"\@CO\tHEADER and TAG of READ GROUP added at $time. ID: FilePre_FlowId_LaneNum, SM: FilePre.\n";
46 warn "Reheadering...\n";
47 system "samtools reheader $op.header.sam $op.reads.bam >$op.bam";
49 warn "Removing $op.header.sam $op.reads.bam...\n";
50 system "rm $op.header.sam $op.reads.bam";