Skip to content

Commit

Permalink
Merge branch 'release/v3.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
keiranmraine committed Jun 19, 2015
2 parents 8fca233 + 550a469 commit 0cf6e9d
Show file tree
Hide file tree
Showing 12 changed files with 677 additions and 20 deletions.
2 changes: 2 additions & 0 deletions perl/MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ bin/brassI_filter.pl
bin/brassI_np_in.pl
bin/brassI_pre_filter.pl
bin/brassI_prep_bam.pl
bin/combineResults.pl
bin/findbp
bin/findbp-all
bin/make-repeat-file
Expand All @@ -21,6 +22,7 @@ lib/Graph/Reader/Velvet.pm
lib/Sanger/CGP/Brass/Implement.pm
lib/Sanger/CGP/BrassFilter/BlatFlag.pm
lib/Sanger/CGP/BrassFilter/BrassMarkedGroups.pm
lib/Sanger/CGP/BrassFilter/Cleanup.pm
lib/Sanger/CGP/BrassFilter/CnFlag.pm
lib/Sanger/CGP/BrassFilter/OccursFlag.pm
lib/Sanger/CGP/BrassFilter/TransFlag.pm
Expand Down
2 changes: 1 addition & 1 deletion perl/MYMETA.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@
}
},
"release_status" : "stable",
"version" : "v2.2.0"
"version" : "v3.0.0"
}
2 changes: 1 addition & 1 deletion perl/MYMETA.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ requires:
Pod::Coverage: '0.23'
Template: '2.26'
Test::Fatal: '0.013'
version: v2.2.0
version: v3.0.0
1 change: 1 addition & 0 deletions perl/Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ WriteMakefile(
bin/brassI_pre_filter.pl
bin/brassI_prep_bam.pl
bin/brass.pl
bin/combineResults.pl
bin/findbp
bin/findbp-all
bin/make-repeat-file
Expand Down
10 changes: 8 additions & 2 deletions perl/bin/brass.pl
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,20 @@
sub cleanup {
my $options = shift;
my $tmpdir = $options->{'tmp'};
system("cp $tmpdir/*.brm.bam $options->{outdir}/.");
move(File::Spec->catdir($tmpdir, 'logs'), File::Spec->catdir($options->{'outdir'}, 'logs')) || die $!;
my $basefile = File::Spec->catfile($options->{'outdir'}, $options->{'safe_tumour_name'}.'_vs_'.$options->{'safe_normal_name'});

unlink "$basefile.groups";
unlink "$basefile.groups.filtered.bedpe";
unlink "$basefile.assembled.bedpe";
unlink $basefile.'_ann.assembled.vcf';
unlink $basefile.'_ann.assembled.bedpe';
unlink "$basefile.annot.vcf";
unlink "$basefile.annot.vcf.srt";
unlink $basefile.'_ann.groups.filtered.vcf';
unlink $basefile.'_ann.groups.filtered.bedpe';

system("cp $tmpdir/*.brm.bam $options->{outdir}/.");
move(File::Spec->catdir($tmpdir, 'logs'), File::Spec->catdir($options->{'outdir'}, 'logs')) || die $!;

remove_tree $tmpdir if(-e $tmpdir);
return 0;
Expand Down
21 changes: 19 additions & 2 deletions perl/bin/brassI_filter.pl
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@

use strict;
use warnings FATAL => 'all';
use File::Copy qw(move);

use Sanger::CGP::BrassFilter::BrassMarkedGroups;
use Sanger::CGP::BrassFilter::TransFlag;
use Sanger::CGP::BrassFilter::OccursFlag;
use Sanger::CGP::BrassFilter::CnFlag;
use Sanger::CGP::BrassFilter::BlatFlag;
use Sanger::CGP::BrassFilter::Cleanup;

use File::Which;
use Getopt::Long;
Expand Down Expand Up @@ -163,7 +165,10 @@
if ($rblat_only) { $do_process = 0; $do_trans = 0; $do_occurrences = 0; $do_copynumber = 0; $do_range_blat = 1; }

# process core information and print to outfile
if ($do_process) { process($infile, $outfile, $tumour); }
if ($do_process) {
process($infile, $outfile, $tumour);
cleanup($outfile);
}

# check for translocations
if ($do_trans) { update_translocations($outfile, $bal_trans_field, $inv_field, $bal_distance, $inv_distance); }
Expand All @@ -177,7 +182,6 @@
# check for L v H range blat scores
if ($do_range_blat) { update_blat($outfile, $blat_field, $blat_script, $ref, $minIdentity); }

#-----------------------------------------------------------------------------#
#-----------------------------------------------------------------------------#
sub process {
my ($infile, $outfile, $tumour) = @_;
Expand Down Expand Up @@ -205,6 +209,19 @@ sub process {
print "finished printing to $outfile at $date";
}
}

#-----------------------------------------------------------------------------#
sub cleanup {
my ($outfile) = @_;
$outfile = "$outfile.bedpe" unless($outfile =~ m/\.bedpe$/);
my $new_out = "$outfile.tmp";

my $cleanup = Sanger::CGP::BrassFilter::Cleanup->new(-infile => $outfile,
-outfile => $new_out);
$cleanup->process();
move($new_out, $outfile) || die $!;
}

#------------------------------------------------------------------------------------------------#

sub update_translocations {
Expand Down
210 changes: 210 additions & 0 deletions perl/bin/combineResults.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
#!/usr/bin/perl

use strict;
use warnings FATAL => 'all';
use autodie;
use Const::Fast qw(const);

const my @NEW_BEDPE_HEADER => ('# chr1','start1','end1','chr2','start2','end2','id/name','brass_score','assembly_score','strand1','strand2','sample','readpair names','readpair count','bal_trans','inv','occL','occH','copynumber_flag','range_blat','Brass Notation','non-template','micro-homology','assembled readnames','assembled read count','gene','gene_id','transcript_id','strand','end_phase','region','region_number','total_region_count','first/last','gene','gene_id','transcript_id','strand','phase','region','region_number','total_region_count','first/last','fusion_flag');

if(scalar @ARGV != 3) {
warn "USAGE: combineResults.pl X_ann.groups X_ann.assembled X.final\n";
warn "\tX.final is a prefix, relevant suffixes will be added for VCF and BEDPE outputs\n";
exit 1;
}
my ($groups_prefix, $assembled_prefix, $final_prefix) = @ARGV;


mergeVcf($groups_prefix, $assembled_prefix, $final_prefix);
mergeBedpe($groups_prefix, $assembled_prefix, $final_prefix);

sub mergeVcf {
my ($groups_prefix, $assembled_prefix, $final_prefix) = @_;

my $assembled_vcf = "$assembled_prefix.vcf";
my $phaseI_vcf = "$groups_prefix.vcf";

my $final_vcf = "$final_prefix.vcf";

my %orig_data;
open my $ORIG, '<', $assembled_vcf;
while(my $line = <$ORIG>) {
next if($line =~ m/^#/);
chomp $line;
my @bits = split /\t/, $line;
my $id = $bits[2];
$orig_data{$id} = \@bits;
}
close $ORIG;

my $new_info = q{##INFO=<ID=BAS,Number=.,Type=Integer,Description="Brass Assembly Score:A maximum score of 100 indicates a perfect pattern of 5 vertices in Velvet's de Bruijn graph">}
.qq{\n}
.q{##INFO=<ID=SVCLASS,Number=.,Type=String,Description="basic SV class, deletion, inversion, tandem-duplication">};
my $new_format = q{##FORMAT=<ID=PS,Number=1,Type=Integer,Description="Count of pairs that span this breakpoint">};

my $info_found = 0;
my $format_found = 0;

open my $FINAL, '>', $final_vcf;
open my $FIXED, '<', $phaseI_vcf;

my @ends;

while(my $line = <$FIXED>) {
if(@ends == 2) {
svclass(\@ends);
print $FINAL join("\t",@{$ends[0]}), "\n";
print $FINAL join("\t",@{$ends[1]}), "\n";
@ends = ();
}
if($line =~ m/^#/) {
if($info_found == 0 && $line =~ m/^##INFO/) {
print $FINAL $new_info,"\n";
$info_found = 1;
}
if($format_found == 0 && $line =~ m/^##FORMAT/) {
print $FINAL $new_format,"\n";
$format_found = 1;
}
print $FINAL $line;
next;
}
chomp $line;
my @bits = split /\t/, $line;
my $id = $bits[2];
if(!exists $orig_data{$id}) {
$bits[-3] .= ':PS';
$bits[-2] = '0:'.$bits[-2]; # normal is always 0:0
$bits[-1] = '0:'.$bits[-1];

push @ends, \@bits;
next;
}
else {
my $old_info = $orig_data{$id}->[7];
my ($tsrds) = $bits[7] =~ m/(TSRDS=[^;]+)/;

$bits[7] = $old_info.';'.$tsrds;
$bits[7] .= ';BAS='.$orig_data{$id}->[5];
$bits[5] = q{.};
$bits[-3] .= ':PS';
$bits[-2] = '0:'.$bits[-2]; # normal is always 0:0
$bits[-1] = $orig_data{$id}->[-1].':'.$bits[-1];

$bits[7] =~ s/;;/;/g;

push @ends, \@bits;
next;
}
}
if(@ends == 2) {
svclass(\@ends);
print $FINAL join("\t",@{$ends[0]}), "\n";
print $FINAL join("\t",@{$ends[1]}), "\n";
}

close $FIXED;
close $FINAL;
}

sub mergeBedpe {
my ($groups_prefix, $assembled_prefix, $final_prefix) = @_;
my $assembled_bedpe = "$assembled_prefix.bedpe";
my $phaseI_bedpe= "$groups_prefix.bedpe";
my $final_bedpe = "$final_prefix.bedpe";

my %orig_data;
open my $ORIG, '<', $assembled_bedpe;
while(my $line = <$ORIG>) {
next if($line =~ m/^#/);
chomp $line;
my @bits = split /\t/, $line;
my $id = $bits[6];
$orig_data{$id} = \@bits;
}
close $ORIG;

open my $FINAL, '>', $final_bedpe;
open my $FIXED, '<', $phaseI_bedpe;

print $FINAL join("\t", @NEW_BEDPE_HEADER),"\n";

while(my $line = <$FIXED>) {
next if($line =~ m/^#/);
chomp $line;
my @bits = split /\t/, $line;
my $id = $bits[6];
if(index($id, ',') != -1) {
my @ids = split /,/, $id;
my @multi_record;
for(@ids) {
push @multi_record, $orig_data{$id} if(exists $orig_data{$id});
}
if(scalar @multi_record) {
warn "MULTI\n";
warn "$line\n";
warn Dumper(\@multi_record);
}
die "merged events correlate with assembled results, don't know what to do";
}
elsif(!exists $orig_data{$id}) {
my @new;
push @new, @bits[0..7]; # 1-8
push @new, q{_}; # 9
push @new, @bits[8..9]; # 10-11
push @new, $bits[16]; # 12
push @new, @bits[18..25]; # 13-20
push @new, q{_},q{_},q{_},q{_},q{_}; # 21-25
push @new, @bits[26..44]; # 26-44

print $FINAL join("\t", @new),"\n";
next;
}
else {
my @old_brass_II = @{$orig_data{$id}};
my @new;
push @new, @old_brass_II[0..6]; # 1-7
push @new, q{_}; # 8
push @new, @old_brass_II[7..10]; # 9-12
push @new, @bits[18..25]; # 13-20
push @new, @old_brass_II[11..14]; # 21-24
push @new, scalar (split /,/, $new[-1]); # 25 # assembled read count
push @new, @bits[26..44]; # 26-44

print $FINAL join("\t", @new),"\n";
next;
}
}


close $FIXED;
close $FINAL;

return;
}


sub svclass {
my ($end_a, $end_b) = @{$_[0]};
die "Record IDs out of sync at:\n",join("\t",@{$end_a}),"\n",join("\t",@{$end_b}),"\n" if($end_a->[2] !~ m/_[12]$/ || $end_b->[2] !~ m/_[12]$/);
my $class;
if($end_a->[4] =~ m/^[[:upper:]]\[/) {
# ++
$class = 'deletion';
}
elsif($end_a->[4] =~ m/^[[:upper:]]\]/ || $end_a->[4] =~ m/\[[[:upper:]]$/) {
# +- / -+
$class = 'inversion';
}
elsif($end_a->[4] =~ m/\][[:upper:]]$/) {
# --
$class = 'tandem-duplication';
}
else {
die "Unknown rearrangement syntax: $end_a->[4]\n";
}
$end_a->[7] .= ';SVCLASS='.$class;
$end_b->[7] .= ';SVCLASS='.$class;
return;
}

Binary file modified perl/docs.tar.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion perl/lib/Bio/Brass.pm
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ our @EXPORT = qw(find_breakpoints find_dusty_vertices
is_dusty get_isolated_bp_alignment get_isolated_bp_surrounding_region
$VERSION);

our $VERSION = '2.2.0';
our $VERSION = '3.0.0';

=head1 NAME
Expand Down
40 changes: 27 additions & 13 deletions perl/lib/Sanger/CGP/Brass/Implement.pm
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,36 @@ sub grass {
return 1 if PCAP::Threaded::success_exists(File::Spec->catdir($tmp, 'progress'), 0);

my $assembled = File::Spec->catfile($options->{'outdir'}, $options->{'safe_tumour_name'}.'_vs_'.$options->{'safe_normal_name'}.'.assembled.bedpe');
my $groups = File::Spec->catfile($options->{'outdir'}, $options->{'safe_tumour_name'}.'_vs_'.$options->{'safe_normal_name'}.'.groups.filtered.bedpe');
my $merge = sprintf '(cat %s/assemble/bedpe.* | sort -k1,1 -k 2,2n > %s)', $tmp, $assembled;

my $tumour = File::Spec->catfile($tmp, $options->{'safe_tumour_name'}).'.brm.bam';
my $normal = File::Spec->catfile($tmp, $options->{'safe_normal_name'}).'.brm.bam';

my $annot_phaseI_prefix = File::Spec->catfile($options->{'outdir'}, $options->{'safe_tumour_name'}.'_vs_'.$options->{'safe_normal_name'}.'_ann.groups.filtered');
my $annot_phaseII_prefix = File::Spec->catfile($options->{'outdir'}, $options->{'safe_tumour_name'}.'_vs_'.$options->{'safe_normal_name'}.'_ann.assembled');

my $final = File::Spec->catfile($options->{'outdir'}, $options->{'safe_tumour_name'}.'_vs_'.$options->{'safe_normal_name'}.'.annot');

my $combine_cmd = "$^X ";
$combine_cmd .= _which('combineResults.pl');
$combine_cmd .= ' '.$annot_phaseI_prefix;
$combine_cmd .= ' '.$annot_phaseII_prefix;
$combine_cmd .= ' '.$final;

PCAP::Threaded::external_process_handler(File::Spec->catdir($tmp, 'logs'),
[ $merge,
_grass($options, $assembled),
_grass($options, $groups),
$combine_cmd],
0);

PCAP::Threaded::touch_success(File::Spec->catdir($tmp, 'progress'), 0);
return 1;
}

sub _grass {
my ($options, $input) = @_;
my $grass_cmd = "$^X ";
$grass_cmd .= _which('grass.pl');
$grass_cmd .= sprintf $GRASS, $options->{'g_cache'},
Expand All @@ -263,19 +288,8 @@ sub grass {
$options->{'protocol'},
$options->{'tumour_name'},
$options->{'normal_name'},
$assembled;

PCAP::Threaded::external_process_handler(File::Spec->catdir($tmp, 'logs'), [$merge, $grass_cmd], 0);

my $munged_name =File::Spec->catfile($options->{'outdir'}, $options->{'safe_tumour_name'}.'_vs_'.$options->{'safe_normal_name'}.'_ann.assembled.vcf');
my $annotated = File::Spec->catfile($options->{'outdir'}, $options->{'safe_tumour_name'}.'_vs_'.$options->{'safe_normal_name'}.'.annot.vcf');
move $munged_name, $annotated || die $!;
$munged_name =~ s/vcf$/bedpe/;
$annotated =~ s/vcf$/bedpe/;
move $munged_name, $annotated || die $!;

PCAP::Threaded::touch_success(File::Spec->catdir($tmp, 'progress'), 0);
return 1;
$input;
return $grass_cmd;
}

sub split_count {
Expand Down
Loading

0 comments on commit 0cf6e9d

Please sign in to comment.