NAME
Bio::ToolBox::db_helper::bam
DESCRIPTION
This module is used to collect the dataset scores from a binary bam file (.bam) of alignments. Bam files may be local or remote, and are usually prefixed with 'file:', 'http://', of 'ftp://'.
Collected data values may be restricted to strand by specifying the desired strandedness (sense, antisense, or all), depending on the method of data collection. Collecting scores, or basepair coverage of alignments over the region of interest, does not currently support stranded data collection (as of this writing). However, enumerating alignments (count method) and collecting alignment lengths do support stranded data collection. Alignments are checked to see whether their midpoint is within the search interval before counting or length collected.
As of version 1.30, paired-end bam files are properly handled with regards to strand; Strand is determined by the orientation of the first mate. However, pairs are still counted as two alignments, not one. To avoid this, use the value_type of 'ncount' and count the number of unique alignment names. (Previous versions treated all paired-end alignments as single-end alignments, severely limiting usefulness.)
USAGE
The module requires Lincoln Stein's Bio::DB::Sam to be installed.
Load the module at the beginning of your program.
use Bio::ToolBox::db_helper::bam;
It will automatically export the name of the subroutines.
- open_bam_db()
-
This subroutine will open a Bam database connection. Pass either the local path to a Bam file (.bam extension) or the URL of a remote Bam file. A remote bam file must be indexed. A local bam file may be automatically indexed upon opening if the user has write permissions in the parent directory.
It will return the opened database object.
- check_bam_index()
-
This subroutine will check whether a bam index file is present and, if not, generate one. The Bio::DB::Sam module uses the samtools style index extension, .bam.bai, as opposed to the picard style extension, .bai. If a .bai index is present, it will copy the file as .bam.bai index. Unfortunately, a .bai index cannot be used directly.
This method is called automatically prior to opening a bam database.
- write_new_bam_file()
-
This subroutine will open a new empty Bam file. Pass the name of the new file as the argument. It will return a Bio::DB::Bam object to which you can write a header followed by alignments. Be sure you know what to do before using this method!
- collect_bam_scores
-
This subroutine will collect only the data values from a binary bam file for the specified database region. The positional information of the scores is not retained, and the values are best further processed through some statistical method (mean, median, etc.).
The subroutine is passed seven or more arguments in the following order:
- 1. The chromosome or seq_id
- 2. The start position of the segment to collect
- 3. The stop or end position of the segment to collect
- 4. The strand of the segment to collect
-
Strand values should be in BioPerl standard values, i.e. -1, 0, or 1.
- 5. The strandedness of the data to collect
-
A scalar value representing the desired strandedness of the data to be collected. Acceptable values include "sense", "antisense", or "all". Only those scores which match the indicated strandedness are collected.
- 6. The value type of data to collect
-
Acceptable values include score, count, pcount, ncount, and length.
* score returns the basepair coverage of alignments over the region of interest * count returns the number of alignments that overlap the search region. * pcount, or precise count, returns the count of alignments whose start and end fall within the region. * ncount, or named count, returns an array of alignment read names. Use this to avoid double-counting paired-end reads by counting only unique names. Reads are taken if they overlap the search region. length returns the lengths of all overlapping alignments
- 7. Paths to one or more Bam files
The subroutine returns an array of the defined dataset values found within the region of interest.
- collect_bam_position_scores
-
This subroutine will collect the score values from a binary bam file for the specified database region keyed by position.
The subroutine is passed the same arguments as collect_bam_scores().
The subroutine returns a hash of the defined dataset values found within the region of interest keyed by position. The feature midpoint is used as the key position. When multiple features are found at the same position, a simple mean (for length data methods) or sum (for count methods) is returned. The ncount value type is not supported with positioned scores.
- sum_total_bam_alignments()
-
This subroutine will sum the total number of properly mapped alignments in a bam file. Pass the subroutine one to four arguments in the following order.
- 1. Bam file path or object
-
The name of the Bam file which should be counted. Alternatively, an opened Bio::DB::Sam object may also be given. Required.
- 2. Minimum mapping quality (integer)
-
Optionally pass the minimum mapping quality of the reads to be counted. The default is 0, where all alignments are counted. Maximum is 255. See the SAM specification for details.
- 3. Paired-end (boolean)
-
Optionally pass a boolean value (1 or 0) indicating whether the Bam file represents paired-end alignments. Only proper alignment pairs are counted. The default is to treat all alignments as single-end.
- 4. Number of forks (integer)
-
Optionally pass the number of parallel processes to execute when counting alignments. Walking through a Bam file is time consuming but can be easily parallelized. The module Parallel::ForkManager is required, and the default is a conservative two processes when it is installed.
The subroutine will return the number of alignments.
AUTHOR
Timothy J. Parnell, PhD
Howard Hughes Medical Institute
Dept of Oncological Sciences
Huntsman Cancer Institute
University of Utah
Salt Lake City, UT, 84112
This package is free software; you can redistribute it and/or modify it under the terms of the Artistic License 2.0.