File: sam_add_rg.pl

package info (click to toggle)
freebayes 1.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 5,628 kB
  • sloc: cpp: 121,209; ansic: 3,925; sh: 911; python: 455; asm: 271; makefile: 213; perl: 27
file content (36 lines) | stat: -rw-r--r-- 763 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env perl
#


$argc = @ARGV;
if ($argc == 0) {
    print "usage: cat aln1.sam | sam_add_rg.pl <read group id> <sample name>\n";
    print "changes all alignments to have RG tags matching the new sample name.\n";
    print "prints SAM format out stdout\n";
    exit(0);
}

$ID = $ARGV[0];
$SM = $ARGV[1];

$in_header = 1;

while (<STDIN>) {
    if ($_ =~ /^@/) {
        print $_;
        next;
    } else {
        # add the new RG group to the end of the header
        if ($in_header) {
            print "\@RG\tID:$ID\tSM:$SM\n";
            $in_header = 0;
        }
        if ($_ =~ /\tRG:Z:(.+?)/) {
            $_ =~ s/\tRG:Z:.+?([\t\n])/\tRG:Z:$ID$1/;
        } else {
            $_ =~ s/\n/\tRG:Z:$ID\n/;
        }
        print $_;
    }
}