blib/script/bam_uniq.pl untested

filter: Statementstmt 0.0% 0 / 53 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 3 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod n/a totaltotal 0.0% 0 / 76 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/bin/env perl
2 # -*-CPerl-*-
3 # Last changed Time-stamp: <2016-02-25 17:57:46 mtw>
4 #
5 # ***********************************************************************
6 # * Copyright notice
7 # *
8 # * Copyright 2016 Michael T. Wolfinger <michael@wolfinger.eu>
9 # * All rights reserved
10 # *
11 # * This program is free software: you can redistribute it and/or modify
12 # * it under the terms of the GNU General Public License as published by
13 # * the Free Software Foundation, either version 3 of the License, or
14 # * (at your option) any later version.
15 # *
16 # * This program is distributed in the hope that it will be useful,
17 # * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # * GNU General Public License for more details.
20 # *
21 # * You should have received a copy of the GNU General Public License},
22 # * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 # *
24 # * This copyright notice MUST APPEAR in all copies of the script!
25 # ***********************************************************************
26  
27 use strict;
28 use warnings;
29 use Getopt::Long qw( :config posix_default bundling no_ignore_case );
30 use Pod::Usage;
31 use Path::Class;
32 use File::Basename;
33 use Bio::ViennaNGS::Bam qw(uniquify_bam uniquify_bam2);
34 use Bio::ViennaNGS::Util qw(mkdircheck);
35 use Cwd;
36 use Data::Dumper;
37  
38 #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^#
39 #^^^^^^^^^^ Variables ^^^^^^^^^^^#
40 #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^#
41  
42 my ($bam_in,$cwd,$lf,$basename,$bamdir,$bamext);
43 my $logext = ".bam_uniq.log";
44 my $outdir = getcwd();
45 my @result = ();
46 my $band = 0;
47  
48 #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^#
49 #^^^^^^^^^^^^^^ Main ^^^^^^^^^^^^^#
50 #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^#
51  
52 Getopt::Long::config('no_ignore_case');
53 pod2usage(-verbose => 1) unless GetOptions("bam=s" => \$bam_in,
54 "band" => sub{$band = 1},
55 "o|out=s" => \$outdir,
56 "l|log=s" => \$logext,
57 "man" => sub{pod2usage(-verbose => 2)},
58 "help|h" => sub{pod2usage(1)}
59 );
60  
61 unless (-f $bam_in){
62 warn "Could not find input file $bam_in given via -bam option";
63 pod2usage(-verbose => 0);
64 }
65 $cwd = getcwd();
66 unless ($bam_in =~ /^\// || $bam_in =~ /\.\//) {$bam_in = file($cwd,$bam_in);}
67 unless (-d $outdir){mkdircheck($outdir)};
68  
69 ($basename,$bamdir,$bamext) = fileparse($bam_in,qr/\.bam/);
70 $lf = file($outdir,$basename.$logext);
71  
72 if ($band == 1){@result = uniquify_bam2($bam_in,$outdir,$lf)}
73 else {@result = uniquify_bam($bam_in,$outdir,$lf)}
74  
75 __END__
76  
77  
78 =head1 NAME
79  
80 bam_uniq.pl - Deconvolute BAM files into unique and multi mappers
81  
82 =head1 SYNOPSIS
83  
84 bam_uniq.pl [--bam I<FILE>] [-o I<DIR>]
85 [options]
86  
87 =head1 DESCRIPTION
88  
89 This program extracts uniquely and multiply mapping reads from BAM
90 files acoording to the NH:i SAM attribute and creates separate BAM
91 files for unique and multi mappers, respectively.
92  
93 =head1 OPTIONS
94  
95 =over
96  
97 =item B<--bam>
98  
99 BAM file to extract unique and multi mappers from
100  
101 =item B<--band>
102  
103 Process bands of (supposedly paired-end) reads sharing the same
104 name/id from a B<name-sorted BAM file>. The reads of band are
105 considered unique mappers if and only if I<all> of them are unique
106 mappers. In all other cases, all reads of a band are considered multi
107 mappers. In a paired-end context this means that e.g. a read map
108 uniquely, but its mate is a multi-mapper, both will be consideres
109 multi-mappers.
110  
111 =item B<--out -o>
112  
113 Output path
114  
115 =item B<--help -h>
116  
117 Print short help
118  
119 =item B<--man>
120  
121 Prints the manual page and exits
122  
123 =back
124  
125 =head1 AUTHOR
126  
127 Michael T. Wolfinger E<lt>michael@wolfinger.euE<gt>
128  
129 =cut
130