Skip to content

Commit

Permalink
Merge pull request #57 from ICGC-TCGA-PanCancer/dev
Browse files Browse the repository at this point in the history
Roll 1.3.0
  • Loading branch information
keiranmraine committed Feb 5, 2015
2 parents 7cb9d0a + 8078ad6 commit b00b28f
Show file tree
Hide file tree
Showing 10 changed files with 172 additions and 59 deletions.
2 changes: 1 addition & 1 deletion MYMETA.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"unknown"
],
"dynamic_config" : 0,
"generated_by" : "ExtUtils::MakeMaker version 6.68, CPAN::Meta::Converter version 2.142690",
"generated_by" : "ExtUtils::MakeMaker version 6.68, CPAN::Meta::Converter version 2.131560",
"license" : [
"gpl_2"
],
Expand Down
46 changes: 23 additions & 23 deletions MYMETA.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,38 @@ abstract: unknown
author:
- unknown
build_requires:
ExtUtils::MakeMaker: '0'
ExtUtils::MakeMaker: 0
configure_requires:
ExtUtils::MakeMaker: '0'
ExtUtils::MakeMaker: 0
dynamic_config: 0
generated_by: 'ExtUtils::MakeMaker version 6.68, CPAN::Meta::Converter version 2.142690'
generated_by: 'ExtUtils::MakeMaker version 6.68, CPAN::Meta::Converter version 2.131560'
license: gpl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: '1.4'
version: 1.4
name: PCAP
no_index:
directory:
- t
- inc
requires:
Bio::DB::Sam: '1.39'
Bio::Root::Version: '1.006923'
Capture::Tiny: '0.24'
Const::Fast: '0.014'
Data::UUID: '1.219'
Devel::Cover: '1.09'
File::Which: '0.05'
GD: '2.52'
IPC::System::Simple: '1.25'
List::Util: '1.38'
Math::Gradient: '0.04'
Module::Build: '0.42'
Pod::Coverage: '0.23'
Proc::ProcessTable: '0.5'
Sub::Exporter::Progressive: '0.001011'
Term::UI: '0.42'
Test::Fatal: '0.013'
Try::Tiny: '0.19'
XML::Simple: '2.2'
Bio::DB::Sam: 1.39
Bio::Root::Version: 1.006923
Capture::Tiny: 0.24
Const::Fast: 0.014
Data::UUID: 1.219
Devel::Cover: 1.09
File::Which: 0.05
GD: 2.52
IPC::System::Simple: 1.25
List::Util: 1.38
Math::Gradient: 0.04
Module::Build: 0.42
Pod::Coverage: 0.23
Proc::ProcessTable: 0.5
Sub::Exporter::Progressive: 0.001011
Term::UI: 0.42
Test::Fatal: 0.013
Try::Tiny: 0.19
XML::Simple: 2.2
version: v1.2.3
55 changes: 49 additions & 6 deletions bin/bam_stats.pl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ BEGIN
use File::Spec;
use Try::Tiny;
use Pod::Usage qw(pod2usage);
use Config; # so we can see if threads are enabled
use Data::Dumper;

BEGIN {
if($Config{useithreads}) {
require threads;
}
};

use PCAP::Bam::Stats;

Expand All @@ -52,14 +60,39 @@ BEGIN
}

try{
my $stats = new PCAP::Bam::Stats(-path => $opts->{'input'}, -qscoring => defined $plots_dir);
my $stats;
if($opts->{'threads'} > 1 && $Config{useithreads}) {
for my $thread(0..($opts->{'threads'}-1)) {
my ($thr) = threads->create(\&stat_thread, $opts, $thread);
}
sleep 2 while(threads->list(threads::running) > 0);
my @bas_objs;
for my $thr(threads->list(threads::joinable)) {
push @bas_objs, $thr->join;
if(my $err = $thr->error) { die "Thread error: $err\n"; }
}
# something to merge the stats into a single element of the object
$stats = PCAP::Bam::Stats->new(-path => $opts->{'input'},
-no_proc => 1);
$stats->merge_json_stats(\@bas_objs);
}
else {
$stats = PCAP::Bam::Stats->new(-path => $opts->{'input'},
-qscoring => defined $plots_dir);
$stats->fqplots($plots_dir) if($plots_dir);
}
$stats->bas($output);
$stats->fqplots($plots_dir) if($plots_dir);
}catch{
} catch{
die 'Reading: |'.$opts->{'input'}."| Writing to: |$out_location| Error: $_";
}finally{
} finally{
close $output or die "Unable to close |".$opts->{'output'}."|: $!" if($opts->{'output'});
}
};
}

sub stat_thread {
my ($opts, $thread) = @_;
my $stats = PCAP::Bam::Stats->new(-path => $opts->{'input'}, -mod => $opts->{'threads'}, -rem => $thread);
return $stats->json_stats;
}

sub setup{
Expand All @@ -70,6 +103,7 @@ sub setup{
'v|version' => \$opts{'v'},
'i|input=s' => \$opts{'input'},
'o|output=s' => \$opts{'output'},
't|threads=i' => \$opts{'threads'},
'p|plots=s' => \$opts{'plots'},
'<>' => sub{push(@random_args,shift(@_));}
) or pod2usage(2);
Expand All @@ -88,6 +122,15 @@ sub setup{
pod2usage(-message => "\nERROR: i|input must be defined.\n", -verbose => 1, -output => \*STDERR) unless($opts{'input'});
pod2usage(-message => "\nERROR: i|input |".$opts{'input'}."| must be a valid file.\n", -verbose => 1, -output => \*STDERR) unless(-f $opts{'input'});

# technically can be done but not a priority
pod2usage(-message => "\nERROR: '-p' and '-t' cannot be used together\n", -verbose => 1, -output => \*STDERR) if(defined $opts{'plots'} && defined $opts{'threads'});

$opts{'threads'} = 1 unless(defined $opts{'threads'});
if(!$Config{useithreads} && $opts{'threads'} > 1) {
warn qq{\nNOTE: Perl not compiled with threads enabled, running un-threaded\n};
$opts{'threads'} = 1;
}

return \%opts;
}

Expand All @@ -114,7 +157,7 @@ =head1 SYNOPSIS
-version -v Prints the version number.
bam_stats.pl -i my.bam -o my.bam.bas
cat my.bam | bam_stats.pl > my.bam.bas
bam_stats.pl -i my.bam > my.bam.bas
=head1 OPTIONS
Expand Down
6 changes: 3 additions & 3 deletions bin/build_biobambam_relocatable.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#! /bin/bash
LIBMAUSVERSION=0.0.167-release-20140917101853
BIOBAMBAMVERSION=0.0.171-release-20140917102804
LIBMAUSVERSION=0.0.191-release-20150129231009
BIOBAMBAMVERSION=0.0.185-release-20150116094537
SNAPPYVERSION=1.1.2
IOLIBVERSION=1.13.7
IOLIBVERSION=1.13.9
CHRPATHVERSION=0.16
BUILDDIR=${PWD}
INSTALLDIR=${BUILDDIR}/install-dir
Expand Down
31 changes: 24 additions & 7 deletions bin/diff_bams.pl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ BEGIN

use Bio::DB::Sam;

my ($file_a, $file_b, $skip_z) = setup();
my ($file_a, $file_b, $skip_z, $count_flag_diff) = setup();

my $bam_a = Bio::DB::Bam->open($file_a);
my $bam_b = Bio::DB::Bam->open($file_b);
Expand All @@ -59,6 +59,7 @@ BEGIN
print "Reference sequence order passed\n";

my ($align_a, $align_b, $count);
my $flag_diffs = 0;
$|++;
while(1) {
$count++;
Expand All @@ -74,19 +75,34 @@ BEGIN
die "Files have different number of records\n" if((!defined $align_a && defined $align_b) || (defined $align_a && !defined $align_b));

die sprintf "Files differ at record $count (qname) a=%s b=%s\n", $align_a->qname, $align_b->qname if($align_a->qname ne $align_b->qname);
die sprintf "Files differ at record $count (flags) a=%s b=%s\n", $align_a->qname, $align_b->qname if($align_a->flag ne $align_b->flag);
if($align_a->flag ne $align_b->flag) {
if($count_flag_diff) {
$flag_diffs++;
print $align_a->pos."\n";
}
else {
die sprintf "Files differ at record $count (flags) a=%s b=%s\n", $align_a->qname, $align_b->qname
}
}

if($count % 100_000 == 0) {
my $message = "Matching records: $count";
$message .= "\t(flag mismatch: $flag_diffs)"if($count_flag_diff);
print $message."\r";
}

print "Matching records: $count\r" if($count % 100_000 == 0);
}
print "Matching records: $count\n";
print "Files match\n";
print "Flag mismatches: $flag_diffs\n";
#print "Files match\n";

sub setup {
my %opts;
GetOptions( 'h|help' => \$opts{'h'},
'm|man' => \$opts{'m'},
'a|bam_a=s' => \$opts{'a'},
'b|bam_b=s' => \$opts{'b'},
'c|count' => \$opts{'c'},
's|skip' => \$opts{'s'},
) or pod2usage(2);

Expand All @@ -95,19 +111,19 @@ sub setup {

my $defined = 0;
for(keys %opts) { $defined++ if(defined $opts{$_}); }
if(@ARGV == 2) {
if($defined == 0 && @ARGV == 2) {
$opts{'a'} = shift @ARGV;
$opts{'b'} = shift @ARGV;
$defined = 2;
}
pod2usage(-msg => "\nERROR: Options 'a' & 'b' must be defined.\n", -verbose => 1, -output => \*STDERR) unless($defined == 2);
pod2usage(-msg => "\nERROR: Options 'a' & 'b' must be defined.\n", -verbose => 1, -output => \*STDERR) unless($defined >= 2);

die pod2usage(-msg => "\nERROR: bam_a and bam_b cannot be the same file\n", -verbose => 1, -output => \*STDERR) if($opts{'a'} eq $opts{'b'});

PCAP::Cli::file_for_reading('bam_a', $opts{'a'});
PCAP::Cli::file_for_reading('bam_a', $opts{'b'});

return ($opts{'a'}, $opts{'b'}, $opts{'s'});
return ($opts{'a'}, $opts{'b'}, $opts{'s'}, $opts{'c'});
}

__END__
Expand All @@ -134,6 +150,7 @@ =head1 SYNOPSIS
-bam_b -b The second BAM file.
Other:
-count -c Count flag differences
-skipz -s Don't include reads with MAPQ=0 in comparison
-help -h Brief help message.
-man -m Full documentation.
Expand Down
Binary file modified docs.tar.gz
Binary file not shown.
7 changes: 4 additions & 3 deletions lib/PCAP.pm
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ const my %UPGRADE_PATH => ( '0.1.0' => 'biobambam,bwa,samtools',
'1.1.0' => 'biobambam,bwa,samtools',
'1.1.1' => 'biobambam,bwa,samtools',
'1.1.2' => 'biobambam,bwa,samtools',
'1.2.0' => '', # if later versions have new versions then all preceding need that tool listing
'1.2.1' => '',
'1.2.2' => '',
'1.2.0' => 'biobambam', # if later versions have new versions then all preceding need that tool listing
'1.2.1' => 'biobambam',
'1.2.2' => 'biobambam',
'1.3.0' => '',
);

sub license {
Expand Down
Loading

0 comments on commit b00b28f

Please sign in to comment.