Bio-ViennaNGS
view release on metacpan or search on metacpan
lib/Bio/ViennaNGS/Util.pm view on Meta::CPAN
while(@_){
push @dirstorm, shift(@_);
}
foreach (@dirstorm){
my @total = split(/[\/\\]/,$_);
my $dir;
while(@total){
$dir = dir(shift(@total)) unless (defined $dir);
$dir = dir($dir,shift(@total));
}
my $check = $dir->stringify();
return if (!-d $check);
remove_tree($dir,{ verbose => 0 }) or
croak "ERROR [$this_function] Cannot remove directory $check";
}
}
1;
__END__
=head1 NAME
Bio::ViennaNGS::Util - Utility routines for Next-Generation Sequencing data
analysis
=head1 SYNOPSIS
use Bio::ViennaNGS::Util;
# make bigWig from BED or BAM
$type = "bam";
$strand = "+";
$bwfile = bed_or_bam2bw($type,$infile,$cs_in,$strand,$destdir,$wantnorm,$size_p,$scale,$logfile);
# make bigBed from BED
my $bb = bed2bigBed($bed_in,$cs_in,$destdir,$logfile);
# sort a BED file
sortbed($bed_in,$destdir,$bed_out,$rm_orig,$logfile)
=head1 DESCRIPTION
Bio::ViennaNGS::Util is a collection of utility subroutines for
building efficient Next-Generation Sequencing (NGS) data analysis
pipelines.
=head2 ROUTINES
=over
=item bed_or_bam2bw($type,$infile,$chromsizes,$strand,$dest,$want_norm,$size,$scale,$log)
Creates stranded, normalized BigWig coverage profiles from
strand-specific BAM or BED files (provided via C<$infile>). The
routine expects a file type 'bam' or 'bed' via the C<$type>
argument. C<$chromsizes> is the chromosome.sizes files, C<$strand> is
either "+" or "-" and C<$dest> contains the output path for
results. For normlization of bigWig profiles, additional attributes
are required: C<$want_norm> triggers normalization with values 0 or
1. C<$size> is the number of fragments/elements in the BAM or BED file
and C<$scale> gives the number to which data is normalized (ie. every
bedGraph entry is multiplied by a factor (C<$scale>/C<$size>). C<$log>
is expected to contain either the full path and file name of log file
or 'undef'. The routine returns the full file name of the newly
generated bigWig file.
While this routine can handle non-straned BAM/BED files (in which case
C<$strand> should be set to "+" and hence all coverage profiles will
be created with a positive sign, even if they map to the negative
strand), usage of strand-specific data is highly recommended. For BAM
file, this is easily achieved by calling the L<bam_split> routine (see
above) prior to this one, thus creating dedicated BAM files containing
exclusively reads mapped to the positive or negative strand,
respectively.
It is important to know that this routine B<does not extract> reads
mapped to either strand from a non-stranded BAM/BED file if the
C<$strand> argument is given. It rather adjusts the sign of B<all>
mapped reads/features in a BAM/BED file and then creates bigWig
files. See the L<split_bam> routine for extracting reads mapped to
either strand.
Stranded bigWigs can easily be visualized via
L<TrackHubs|http://genome.ucsc.edu/goldenPath/help/hgTrackHubHelp.html>
in the UCSC Genome Browser. Internally, the conversion from BAM/BED to
bigWig is accomplished via two third-party applications:
L<genomeCoverageBed|http://bedtools.readthedocs.org/en/latest/content/tools/genomecov.html>
and
L<bedGraphToBigWig|http://hgdownload.cse.ucsc.edu/admin/exe/>. Intermediate
bedGraph files are removed automatically once the bigWig files are
ready.
=item sortbed($infile,$dest,$outfile,$rm_orig,$log)
Sorts BED file C<$infile> with F<bedtools sort>. C<$dest> and
C<outfile> name path and filename of the resulting sorted BED
file. C<$rm_infile> is either 1 or 0 and indicated whether the
original C<$infile> should be deleted. C<$log> holds path and name of
log file.
=item bed2bigBed($infile,$chromsizes,$dest,$log)
Creates an indexed bigBed file from a BED file. C<$infile> is the BED
file to be transformed, C<$chromsizes> is the chromosome.sizes file
and C<$dest> contains the output path for results. C<$log> is the name
of a log file, or undef if no logging is reuqired. A '.bed', '.bed6'
or '.bed12' suffix in C<$infile> will be replaced by '.bb' in the
output. Else, the name of the output bigBed file will be the value of
C<$infile> plus '.bb' appended.
The conversion from BED to bigBed is done by a third-party utility
(bedToBigBed), which is executed by L<IPC::Cmd>.
=item unique_array($arrayref)
Takes a reference to an array and uniques entries via hash copy.
Returns a reference to an array containing unique values.
=item kmer_enrichment($seqs,$klen)
( run in 0.604 second using v1.01-cache-2.11-cpan-364913b4093 )