Skip to content

Commit

Permalink
Merge branch 'hotfix/2.3.4'
Browse files Browse the repository at this point in the history
* RG tags are converted to shell safe strings before passing to Star. partially resolve #30.
  • Loading branch information
Yaobo Xu committed Aug 27, 2019
2 parents 2c0cd9a + 0b9725d commit e77fc1d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGES

## 2.3.4

* RG tags are converted to shell safe strings before passing to Star. partially resolve #30.

## 2.3.3

* fixed verison numbers
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ FROM ubuntu:16.04

LABEL maintainer="[email protected]" \
uk.ac.sanger.cgp="Cancer, Ageing and Somatic Mutation, Wellcome Trust Sanger Institute" \
version="2.3.3" \
version="2.3.4" \
description="cgpRna docker"

RUN apt-get -yq update
Expand Down
2 changes: 1 addition & 1 deletion perl/lib/Sanger/CGP/CgpRna.pm
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use strict;
use Const::Fast qw(const);
use base 'Exporter';

our $VERSION = '2.3.3';
our $VERSION = '2.3.4';
our @EXPORT = qw($VERSION);

1;
20 changes: 17 additions & 3 deletions perl/lib/Sanger/CGP/Star/Implement.pm
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,14 @@ sub format_rg_tags {

push @rg_header, 'LB:'.$options->{'LB'} if(exists $options->{'LB'});
# Quotes need to be around the description (DS:) tag text
push @rg_header, '"DS:'.$options->{'DS'}.'"' if(exists $options->{'DS'});
push @rg_header, 'DS:'.$options->{'DS'} if(exists $options->{'DS'});
push @rg_header, 'PL:'.$options->{'PL'} if(exists $options->{'PL'});
push @rg_header, 'PU:'.$options->{'PU'} if(exists $options->{'PU'});

foreach my $r(@rg_tags){
unless($r eq '@RG' || $r =~ /^ID/){
my @tag = split ':', $r;
if(!exists $options->{$tag[0]}){
$r = '"'.$r.'"' if($r =~ /DS:/);
push @rg_header, $r;
}
# Once the RG tag has been formatted correctly for the CGP mapped BAM, add any pre-existing tags to a comment line to store what was in the BAM RG tags previously
Expand All @@ -226,7 +225,9 @@ sub format_rg_tags {

$options->{'commentfile'} = $comment_file unless($first_file->fastq);

$options->{'rgline'} = join(" ",@rg_header);
# convert tags to shell safe tags before passing them to star in command line
my @shell_safe_rg_header = map { _to_commandline_safe_tag_for_star($_) } @rg_header;
$options->{'rgline'} = join(" ", @shell_safe_rg_header);

return 1;
}
Expand Down Expand Up @@ -598,6 +599,19 @@ sub _which {
return $path;
}

sub _to_commandline_safe_tag_for_star {
# according to this: https://unix.stackexchange.com/a/398649
# preserving tag values is complicated
my $tag = shift;
# first escape backslashes
$tag =~ s/\\/\\\\/g;
# then escape other needed-to-escape characters.
# this will inevitably introduce an extra backslash into the tag if there's an '!', but for now no other way to escape '!' to prevent bash history expansion.
$tag =~ s/([`"!\$])/\\$1/g;
# double quoted it
return sprintf q{"%s"}, $tag;
}

1;

__END__

0 comments on commit e77fc1d

Please sign in to comment.