blib/lib/Bio/ViennaNGS/Util.pm

filter: Statementstmt 20.3% 45 / 221 Branchbran 0.0% 0 / 110 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 61.9% 13 / 21 Podpod 100% 8 / 8 totaltotal 18.0% 66 / 365 CC 63 SCAR 50.4
CC
63
Cov
13%
bed_or_bam2bw
420.0
sortbed
156.0
bed2bigBed
110.0
CRAP 154.7
« blib/lib/Bio/ViennaNGS/UCSC.pm ↑ Summary blib/lib/Bio/ViennaNGS/FeatureIO.pm »
1 # -*-CPerl-*-
2 # Last changed Time-stamp: <2017-06-10 19:12:00 michl>
3  
4 package Bio::ViennaNGS::Util;
5  
6 1 ▶use Bio::ViennaNGS;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use File::Basename qw(fileparse basename);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use IPC::Cmd qw(can_run run);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Path::Class qw(dir file);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use File::Path qw(make_path remove_tree);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Math::Round;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Env qw(HOME);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use version; our $VERSION = version->declare("$Bio::ViennaNGS::VERSION");
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 1 our @ISA = qw(Exporter);
21 1 our @EXPORT = ();
22  
23 1 our @EXPORT_OK = qw ( bed_or_bam2bw sortbed bed2bigBed unique_array
24 kmer_enrichment fetch_chrom_sizes mkdircheck rmdircheck);
25  
26  
27 #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^#
28 #^^^^^^^^^^ Variables ^^^^^^^^^^^#
29 #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^#
30  
31 1 my %unique = ();
32  
33 #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^#
34 #^^^^^^^^^^^ Subroutines ^^^^^^^^^^#
35 #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^#
36  
37 sub bed_or_bam2bw {
38 0 ▶ my ($type,$infile,$chromsizes,$strand,$dest,$want_norm,$size,$scale,$log) = @_;
Subroutine bed_or_bam2bw: not called CC=20 SCAR=60.4
Pod documented
39 0 my ($fn_bg_tmp,$fn_bg,$fn_bw,$fn,$bn,$path,$ext,$cmd);
40 0 my @processed_files = ();
41 0 my $factor = 1.;
42 0 my $this_function = (caller(0))[3];
43  
44 0 ▶ croak "ERROR [$this_function] \$type is '$type', however it is expected to be either 'bam' or 'bed'\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $type eq "bam" or $type eq "bed" 0 0 0
Condition0%0/3
$type eq "bam" or $type eq "bed"
l!l&&r!l&&!r
000
MC/DC0%0/2
$type eq "bam" or $type eq "bed"
$type eq "bam" $type eq "bed"
Truth table0%0/3
A or B
A= $type eq "bam"B= $type eq "bed"
ABresult
1X1
011
000
45 unless ($type eq "bam") || ($type eq "bed");
46  
47 0 ▶ my $genomeCoverageBed = can_run('genomeCoverageBed') or
Branch: 1 branch
BranchTrueFalseTotal
my $genomeCoverageBed = can_run("genomeCoverageBed") or croak("ERROR [$this_function] genomeCoverageBed utility not found") 0 0 0
48 croak "ERROR [$this_function] genomeCoverageBed utility not found";
49 0 ▶ my $bedGraphToBigWig = can_run('bedGraphToBigWig') or
Branch: 1 branch
BranchTrueFalseTotal
my $bedGraphToBigWig = can_run("bedGraphToBigWig") or croak("ERROR [$this_function] bedGraphToBigWig utility not found") 0 0 0
50 croak "ERROR [$this_function] bedGraphToBigWig utility not found";
51 0 ▶ my $awk = can_run('awk') or
Branch: 1 branch
BranchTrueFalseTotal
my $awk = can_run("awk") or croak("ERROR [$this_function] awk utility not found") 0 0 0
52 croak "ERROR [$this_function] awk utility not found";
53  
54 0 ▶ if(defined $log){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $log) 0 0 0
55 0 ▶ open(LOG, ">>", $log) or croak $!;
Branch: 1 branch
BranchTrueFalseTotal
open LOG, ">>", $log or croak($!) 0 0 0
56 0 print LOG "LOG [$this_function] \$infile: $infile\n";
57 0 print LOG "LOG [$this_function] \$dest: $dest\n";
58 0 print LOG "LOG [$this_function] \$chromsizes: $chromsizes\n";
59 }
60  
61 0 ▶ croak "ERROR [$this_function] Cannot find $infile\n"
Branch: 1 branch
BranchTrueFalseTotal
unless -e $infile 0 0 0
62 unless (-e $infile);
63 0 ▶ croak "ERROR [$this_function] $dest does not exist\n"
Branch: 1 branch
BranchTrueFalseTotal
unless -d $dest 0 0 0
64 unless (-d $dest);
65 0 ▶ croak "ERROR [$this_function] Cannot find $chromsizes\n"
Branch: 1 branch
BranchTrueFalseTotal
unless -e $chromsizes 0 0 0
66 unless (-e $chromsizes);
67  
68 0 ▶ if ($want_norm == 1){
Branch: 1 branch
BranchTrueFalseTotal
if ($want_norm == 1) 0 0 0
69 0 $factor = $scale/$size;
70 0 ▶ print LOG "LOG [$this_function] normalization: $factor = ($scale/$size)\n"
Branch: 1 branch
BranchTrueFalseTotal
if defined $log 0 0 0
71 if(defined $log);
72 }
73  
74 0 ▶ if ($type eq "bam"){$ext = ".bam";}
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'bam') { } 0 0 0
75 0 else{$ext = ".bed";}
76 0 $bn = basename($infile,$ext);
77 0 $fn = fileparse($infile);
78  
79 0 $fn_bg_tmp = file($dest,$fn.".tmp.bg");
80 0 $fn_bg = file($dest,$bn.".bg");
81 0 ▶ if($strand eq "+"){
Branch: 1 branch
BranchTrueFalseTotal
if ($strand eq '+') { } 0 0 0
82 0 $fn_bw = file($dest,$bn.".pos.bw");
83 }
84 else {
85 0 $fn_bw = file($dest,$bn.".neg.bw");
86 }
87  
88 0 $cmd = "$genomeCoverageBed -bg -scale $factor -split ";
89 0 ▶ if ($type eq "bed"){ $cmd .= "-i $infile -g $chromsizes"; } # chrom.sizes only required for processing BED
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'bed') { } 0 0 0
90 0 else { $cmd .= "-ibam $infile "; }
91 0 $cmd .= " > $fn_bg_tmp";
92  
93 0 ▶ if($strand eq "-"){
Branch: 1 branch
BranchTrueFalseTotal
if ($strand eq '-') { } 0 0 0
94 0 $cmd .= " && cat $fn_bg_tmp | $awk \'{ \$4 = - \$4 ; print \$0 }\' > $fn_bg";
95 }
96 else{
97 0 $fn_bg = $fn_bg_tmp;
98 }
99 0 $cmd .= " && $bedGraphToBigWig $fn_bg $chromsizes $fn_bw";
100  
101 0 ▶ if (defined $log){ print LOG "LOG [$this_function] $cmd\n";}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $log) 0 0 0
102  
103 0 my( $success, $error_message, $full_buf, $stdout_buf, $stderr_buf ) =
104 run( command => $cmd, verbose => 0 );
105  
106 0 ▶ if( !$success ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($success) 0 0 0
107 0 print STDERR "ERROR [$this_function] External command call unsuccessful\n";
108 0 print STDERR "ERROR: this is what the command printed:\n";
109 0 print join "", @$full_buf;
110 0 croak $!;
111 }
112 0 ▶ if (defined $log){ close(LOG); }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $log) 0 0 0
113  
114 0 unlink ($fn_bg_tmp);
115 0 unlink ($fn_bg);
116 0 return $fn_bw;
117 }
118  
119 sub bed2bigBed {
120 0 ▶ my ($infile,$chromsizes,$dest,$log) = @_;
Subroutine bed2bigBed: not called CC=10 SCAR=47.0
Pod documented
121 0 my ($bn,$path,$ext,$cmd,$outfile);
122 0 my $this_function = (caller(0))[3];
123 0 ▶ my $bed2bigBed = can_run('bedToBigBed') or
Branch: 1 branch
BranchTrueFalseTotal
my $bed2bigBed = can_run("bedToBigBed") or croak("ERROR [$this_function] bedToBigBed utility not found") 0 0 0
124 croak "ERROR [$this_function] bedToBigBed utility not found";
125  
126 0 ▶ if (defined $log){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $log) 0 0 0
127 0 ▶ open(LOG, ">>", $log) or croak $!;
Branch: 1 branch
BranchTrueFalseTotal
open LOG, ">>", $log or croak($!) 0 0 0
128 0 print LOG "LOG [$this_function] \$infile: $infile -- \$chromsizes: $chromsizes --\$dest: $dest\n";
129 }
130  
131 0 ▶ croak "ERROR [$this_function] Cannot find $infile"
Branch: 1 branch
BranchTrueFalseTotal
unless -e $infile 0 0 0
132 unless (-e $infile);
133 0 ▶ croak "ERROR [$this_function] Cannot find $chromsizes"
Branch: 1 branch
BranchTrueFalseTotal
unless -e $chromsizes 0 0 0
134 unless (-e $chromsizes);
135 0 ▶ croak "ERROR [$this_function] $dest does not exist"
Branch: 1 branch
BranchTrueFalseTotal
unless -d $dest 0 0 0
136 unless (-d $dest);
137  
138 # .bed6 .bed12 extensions are replaced by .bb
139 0 ($bn,$path,$ext) = fileparse($infile, qr /\.bed[126]?/);
140 0 $outfile = file($dest, "$bn.bb");
141  
142 0 $cmd = "$bed2bigBed $infile -extraIndex=name -tab $chromsizes $outfile";
143 0 ▶ if (defined $log){ print LOG "LOG [$this_function] $cmd\n"; }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $log) 0 0 0
144 0 my( $success, $error_message, $full_buf, $stdout_buf, $stderr_buf ) =
145 run( command => $cmd, verbose => 0 );
146  
147 0 ▶ if( !$success ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($success) 0 0 0
148 0 print STDERR "ERROR [$this_function] Call to $bed2bigBed unsuccessful\n";
149 0 print STDERR "ERROR: this is what the command printed:\n";
150 0 print join "", @$full_buf;
151 0 croak $!;
152 }
153  
154 0 ▶ if (defined $log){ close(LOG); }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $log) 0 0 0
155  
156 0 return $outfile;
157 }
158  
159 sub sortbed {
160 0 ▶ my ($infile,$dest,$outfile,$rm_orig,$log) = @_;
Subroutine sortbed: not called CC=12 SCAR=50.5
Pod documented
161 0 my ($cmd,$out);
162 0 my $this_function = (caller(0))[3];
163 0 ▶ my $bedtools = can_run('bedtools') or
Branch: 1 branch
BranchTrueFalseTotal
my $bedtools = can_run("bedtools") or croak("ERROR [$this_function] bedtools utility not found") 0 0 0
164 croak "ERROR [$this_function] bedtools utility not found";
165  
166 0 ▶ croak "ERROR [$this_function] Cannot find $infile"
Branch: 1 branch
BranchTrueFalseTotal
unless -e $infile 0 0 0
167 unless (-e $infile);
168 0 ▶ croak "ERROR [$this_function] $dest does not exist"
Branch: 1 branch
BranchTrueFalseTotal
unless -d $dest 0 0 0
169 unless (-d $dest);
170 0 ▶ if (defined $log){open(LOG, ">>", $log) or croak $!;}
Branch: 2 branches
BranchTrueFalseTotal
if (defined $log) 0 0 0
open LOG, ">>", $log or croak($!) 0 0 0
171  
172 0 $out = file($dest,$outfile);
173 0 $cmd = "$bedtools sort -i $infile > $out";
174 0 ▶ if (defined $log){ print LOG "LOG [$this_function] $cmd\n"; }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $log) 0 0 0
175 0 my ( $success, $error_message, $full_buf, $stdout_buf, $stderr_buf ) =
176 run( command => $cmd, verbose => 0 );
177 0 ▶ if( !$success ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($success) 0 0 0
178 0 print STDERR "ERROR [$this_function] Call to $bedtools unsuccessful\n";
179 0 print STDERR "ERROR: this is what the command printed:\n";
180 0 print join "", @$full_buf;
181 0 croak $!;
182 }
183  
184 0 ▶ if($rm_orig){
Branch: 1 branch
BranchTrueFalseTotal
if ($rm_orig) 0 0 0
185 0 ▶ unlink($infile) or
Branch: 1 branch
BranchTrueFalseTotal
unlink $infile or carp("WARN [$this_function] Could not unlink $infile") 0 0 0
186 carp "WARN [$this_function] Could not unlink $infile";
187 0 ▶ if (defined $log){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $log) 0 0 0
188 0 print LOG "[$this_function] removed $infile $!\n";
189 }
190 }
191  
192 0 ▶ if (defined $log){ close(LOG); }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $log) 0 0 0
193 }
194  
195 sub unique_array{
196  
197 0 ▶ my $arrayref = shift;
Subroutine unique_array: not called CC=2 SCAR=17.9
Pod documented
198 0 my @array = @{$arrayref};
199  
200 0 foreach my $item (@array)
201 {
202 0 $unique{$item} ++;
203 }
204 0 my @arrayuid = sort {$a cmp $b} keys %unique;
205  
206 0 return(\@arrayuid);
207 }
208  
209 sub kmer_enrichment{
210  
211 0 ▶ my @seqs = @{$_[0]};
Subroutine kmer_enrichment: not called CC=4 SCAR=30.0
Pod documented
212 0 my $klen = $_[1];
213 # my @seq = split( //, $read_tmp );
214 0 my $kstring ='';
215 #return variables
216 0 my %km;
217 0 foreach my $sequences (@seqs){
218 # print STDERR $sequences,"\n";
219 0 my @seq = split( //, $sequences );
220 0 ▶ for ( my $seq_pos = 0; $seq_pos <= $#seq-$klen ; $seq_pos++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seq_pos <= $#seq - $klen) 0 0 0
221 0 ▶ for (my $i=$seq_pos;$i<=$seq_pos+($klen-1);$i++){
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $seq_pos + ($klen - 1)) 0 0 0
222 0 $kstring .= $seq[$i];
223 }
224 0 $km{$kstring}++;
225 0 $kstring = "";
226 }
227 }
228 0 return( \%km );
229 }
230  
231 sub fetch_chrom_sizes{
232 0 ▶ my $species = shift;
Subroutine fetch_chrom_sizes: not called CC=7 SCAR=40.3
Pod documented
233 0 my %sizes;
234 my @chromsize;
235 0 my $this_function = (caller(0))[3];
236  
237 0 ▶ my $test_fetchChromSizes = can_run('fetchChromSizes') or
Branch: 1 branch
BranchTrueFalseTotal
my $test_fetchChromSizes = can_run("fetchChromSizes") or croak("ERROR [$this_function] fetchChromSizes utility not found") 0 0 0
238 croak "ERROR [$this_function] fetchChromSizes utility not found";
239  
240 0 my $cmd = "fetchChromSizes $species";
241 0 my( $success, $error_message, $full_buf, $stdout_buf, $stderr_buf ) =
242 run(command => $cmd, verbose => 0);
243 0 ▶ if ($success){
Branch: 1 branch
BranchTrueFalseTotal
if ($success) { } 0 0 0
244 0 @chromsize = @{$stdout_buf};
245 }
246 else{
247 0 carp "WARN [$this_function] Using UCSCs fetchChromSizes failed, trying alternative mysql fetch!\n";
248 0 ▶ my $test_fetchChromSizes = can_run('mysql') or
Branch: 1 branch
BranchTrueFalseTotal
my $test_fetchChromSizes = can_run("mysql") or croak("ERROR [$this_function] mysql utility not found") 0 0 0
249 croak "ERROR [$this_function] mysql utility not found";
250 0 $cmd = "mysql --user=genome --host=genome-mysql.cse.ucsc.edu -A -e \"select chrom, size from $species.chromInfo\""; ### Alternative to UCSC fetchChromSizes, has mysql dependency
251 0 my( $success, $error_message, $full_buf, $stdout_buf, $stderr_buf ) =
252 run(command => $cmd, verbose => 0);
253 0 ▶ if ($success){
Branch: 1 branch
BranchTrueFalseTotal
if ($success) { } 0 0 0
254 0 @chromsize = @{$stdout_buf};
255 }
256 else{
257 0 carp "ERROR [$this_function] External command call unsuccessful\n";
258 0 carp "ERROR [$this_function] this is what the command printed:\n";
259 0 print join "", @$full_buf;
260 0 confess "Fetching of chromosome sizes failed, please either download fetchChromSizes from the UCSC script collection, or install mysql!\n";
261 }
262 }
263  
264 0 foreach (@chromsize){
265 0 chomp($_);
266 0 foreach (split(/\n/,$_)){
267 0 my ($chr,$size)=split (/\t/,$_);
268 0 $sizes{$chr}=$size;
269 }
270 }
271  
272 0 return(\%sizes);
273 }
274  
275 sub mkdircheck {
276 0 ▶ my @dirstocreate=();
Subroutine mkdircheck: not called CC=8 SCAR=42.8
Pod documented
277 0 my $this_function = (caller(0))[3];
278 0 ▶ while(@_){
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
279 0 push @dirstocreate, shift(@_);
280 }
281 0 foreach (@dirstocreate){
282 0 my @total = split(/[\/\\]/,$_);
283 0 ▶ if ($total[0] eq '~'){
Branch: 1 branch
BranchTrueFalseTotal
if ($total[0] eq "~") 0 0 0
284 0 $total[0]=$HOME;
285 0 carp "WARNING [$this_function] replacing \'~\' in path with \'$HOME\'";
286 }
287 0 my $dir;
288 0 ▶ while(@total){
Branch: 1 branch
BranchTrueFalseTotal
if (@total) 0 0 0
289 0 ▶ $dir = dir(shift(@total)) unless (defined $dir);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $dir 0 0 0
290 0 $dir = dir($dir,shift(@total));
291 }
292 0 my $check = $dir->stringify();
293 0 ▶ return if (-d $check);
Branch: 1 branch
BranchTrueFalseTotal
if -d $check 0 0 0
294 0 ▶ make_path($dir,{ verbose => 0 }) or
Branch: 1 branch
BranchTrueFalseTotal
make_path($dir, {"verbose", 0}) or croak("ERROR [$this_function] Cannot create directory $check") 0 0 0
295 croak "ERROR [$this_function] Cannot create directory $check";
296 }
297 }
298  
299 sub rmdircheck {
300 0 ▶ my @dirstorm=();
Subroutine rmdircheck: not called CC=7 SCAR=40.3
Pod documented
301 0 my $this_function = (caller(0))[3];
302 0 ▶ while(@_){
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
303 0 push @dirstorm, shift(@_);
304 }
305 0 foreach (@dirstorm){
306 0 my @total = split(/[\/\\]/,$_);
307 0 my $dir;
308 0 ▶ while(@total){
Branch: 1 branch
BranchTrueFalseTotal
if (@total) 0 0 0
309 0 ▶ $dir = dir(shift(@total)) unless (defined $dir);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $dir 0 0 0
310 0 $dir = dir($dir,shift(@total));
311 }
312 0 my $check = $dir->stringify();
313 0 ▶ return if (!-d $check);
Branch: 1 branch
BranchTrueFalseTotal
unless -d $check 0 0 0
314 0 ▶ remove_tree($dir,{ verbose => 0 }) or
Branch: 1 branch
BranchTrueFalseTotal
remove_tree($dir, {"verbose", 0}) or croak("ERROR [$this_function] Cannot remove directory $check") 0 0 0
315 croak "ERROR [$this_function] Cannot remove directory $check";
316 }
317 }
318  
319 1 1;
320 __END__
321  
322  
323 =head1 NAME
324  
325 Bio::ViennaNGS::Util - Utility routines for Next-Generation Sequencing data
326 analysis
327  
328 =head1 SYNOPSIS
329  
330 use Bio::ViennaNGS::Util;
331  
332 # make bigWig from BED or BAM
333 $type = "bam";
334 $strand = "+";
335 $bwfile = bed_or_bam2bw($type,$infile,$cs_in,$strand,$destdir,$wantnorm,$size_p,$scale,$logfile);
336  
337 # make bigBed from BED
338 my $bb = bed2bigBed($bed_in,$cs_in,$destdir,$logfile);
339  
340 # sort a BED file
341 sortbed($bed_in,$destdir,$bed_out,$rm_orig,$logfile)
342  
343 =head1 DESCRIPTION
344  
345 Bio::ViennaNGS::Util is a collection of utility subroutines for
346 building efficient Next-Generation Sequencing (NGS) data analysis
347 pipelines.
348  
349 =head2 ROUTINES
350  
351 =over
352  
353 =item bed_or_bam2bw($type,$infile,$chromsizes,$strand,$dest,$want_norm,$size,$scale,$log)
354  
355 Creates stranded, normalized BigWig coverage profiles from
356 strand-specific BAM or BED files (provided via C<$infile>). The
357 routine expects a file type 'bam' or 'bed' via the C<$type>
358 argument. C<$chromsizes> is the chromosome.sizes files, C<$strand> is
359 either "+" or "-" and C<$dest> contains the output path for
360 results. For normlization of bigWig profiles, additional attributes
361 are required: C<$want_norm> triggers normalization with values 0 or
362 1. C<$size> is the number of fragments/elements in the BAM or BED file
363 and C<$scale> gives the number to which data is normalized (ie. every
364 bedGraph entry is multiplied by a factor (C<$scale>/C<$size>). C<$log>
365 is expected to contain either the full path and file name of log file
366 or 'undef'. The routine returns the full file name of the newly
367 generated bigWig file.
368  
369 While this routine can handle non-straned BAM/BED files (in which case
370 C<$strand> should be set to "+" and hence all coverage profiles will
371 be created with a positive sign, even if they map to the negative
372 strand), usage of strand-specific data is highly recommended. For BAM
373 file, this is easily achieved by calling the L<bam_split> routine (see
374 above) prior to this one, thus creating dedicated BAM files containing
375 exclusively reads mapped to the positive or negative strand,
376 respectively.
377  
378 It is important to know that this routine B<does not extract> reads
379 mapped to either strand from a non-stranded BAM/BED file if the
380 C<$strand> argument is given. It rather adjusts the sign of B<all>
381 mapped reads/features in a BAM/BED file and then creates bigWig
382 files. See the L<split_bam> routine for extracting reads mapped to
383 either strand.
384  
385 Stranded bigWigs can easily be visualized via
386 L<TrackHubs|http://genome.ucsc.edu/goldenPath/help/hgTrackHubHelp.html>
387 in the UCSC Genome Browser. Internally, the conversion from BAM/BED to
388 bigWig is accomplished via two third-party applications:
389 L<genomeCoverageBed|http://bedtools.readthedocs.org/en/latest/content/tools/genomecov.html>
390 and
391 L<bedGraphToBigWig|http://hgdownload.cse.ucsc.edu/admin/exe/>. Intermediate
392 bedGraph files are removed automatically once the bigWig files are
393 ready.
394  
395 =item sortbed($infile,$dest,$outfile,$rm_orig,$log)
396  
397 Sorts BED file C<$infile> with F<bedtools sort>. C<$dest> and
398 C<outfile> name path and filename of the resulting sorted BED
399 file. C<$rm_infile> is either 1 or 0 and indicated whether the
400 original C<$infile> should be deleted. C<$log> holds path and name of
401 log file.
402  
403 =item bed2bigBed($infile,$chromsizes,$dest,$log)
404  
405 Creates an indexed bigBed file from a BED file. C<$infile> is the BED
406 file to be transformed, C<$chromsizes> is the chromosome.sizes file
407 and C<$dest> contains the output path for results. C<$log> is the name
408 of a log file, or undef if no logging is reuqired. A '.bed', '.bed6'
409 or '.bed12' suffix in C<$infile> will be replaced by '.bb' in the
410 output. Else, the name of the output bigBed file will be the value of
411 C<$infile> plus '.bb' appended.
412  
413 The conversion from BED to bigBed is done by a third-party utility
414 (bedToBigBed), which is executed by L<IPC::Cmd>.
415  
416  
417 =item unique_array($arrayref)
418  
419 Takes a reference to an array and uniques entries via hash copy.
420 Returns a reference to an array containing unique values.
421  
422 =item kmer_enrichment($seqs,$klen)
423  
424 Takes a reference to a sequence array and the length of the desired
425 kmer. Counts occurences of kmers of given length and returns a
426 reference to a hash containing the kmer as key and occurences as
427 value.
428  
429 =item fetch_chrom_sizes($species)
430  
431 Takes the name of the desired species (e.g. hg19, mm9, ..) and
432 retrieves annotated chromosomes and their sizes from UCSC. This
433 methods returns a reference to a hash containing chromosomes as kays
434 and their corresponding size as value. Either uses the fetchChromSizes
435 util of the UCSC bin collection or alternatively and if mysql is
436 available via a mysql command.
437  
438 =item mkdircheck(@dirs)
439  
440 Takes the path to one or more directories, converts them to an OS
441 specific path and creates directories.
442  
443 =item rmdircheck(@dirs)
444  
445 Takes the path to one or more directories, converts them to an OS
446 specific path and removes directories.
447  
448 =back
449  
450 =head1 DEPENDENCIES
451  
452 =over
453  
454 =item L<Bio::Perl> >= 1.00690001
455  
456 =item L<File::Basename>
457  
458 =item L<File::Path>
459  
460 =item L<Path::Class>
461  
462 =item L<IPC::Cmd>
463  
464 =item L<Math::Round>
465  
466 =item L<Carp>
467  
468 =back
469  
470 L<Bio::ViennaNGS> uses third-party tools for computing intersections
471 of BED files: F<bedtools intersect> from the
472 L<BEDtools|http://bedtools.readthedocs.org/en/latest/content/tools/intersect.html>
473 suite is used to compute overlaps and F<bedtools sort> is used to sort
474 BED output files. Make sure that those third-party utilities are
475 available on your system, and that hey can be found and executed by
476 the Perl interpreter. We recommend installing the latest version of
477 L<BEDtools|https://github.com/arq5x/bedtools2> on your system.
478  
479 Examples for using most of the provided methods can be found at L<ViennaNGS::Tutorial>.
480  
481 =head1 AUTHORS
482  
483 =over
484  
485 =item Michael T. Wolfinger E<lt>michael@wolfinger.euE<gt>
486  
487 =item Joerg Fallmann E<lt>fall@tbi.univie.ac.atE<gt>
488  
489 =back
490  
491 =head1 COPYRIGHT AND LICENSE
492  
493 Copyright (C) 2015-2017 Michael T. Wolfinger E<lt>michael@wolfinger.euE<gt>
494  
495 This library is free software; you can redistribute it and/or modify
496 it under the same terms as Perl itself, either Perl version 5.10.0 or,
497 at your option, any later version of Perl 5 you may have available.
498  
499 This software is distributed in the hope that it will be useful, but
500 WITHOUT ANY WARRANTY; without even the implied warranty of
501 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
502  
503 =cut
« blib/lib/Bio/ViennaNGS/UCSC.pm ↑ Summary blib/lib/Bio/ViennaNGS/FeatureIO.pm »