NAME
Bio::Search::Tiling::MapTiling - An implementation of an HSP tiling algorithm, with methods to obtain frequently-requested statistics
SYNOPSIS
# get a BLAST $hit from somewhere, then$tiling = Bio::Search::Tiling::MapTiling->new($hit);# stats$numID = $tiling->identities();$numCons = $tiling->conserved();$query_length = $tiling->length('query');$subject_length = $tiling->length('subject'); # or...$subject_length = $tiling->length('hit');# get a visual on the coverage mapprint $tiling->coverage_map_as_text('query',$context,'LEGEND');# tilings$context = $tiling->_context( -type => 'subject', -strand=> 1, -frame=>1);@covering_hsps_for_subject = $tiling->next_tiling('subject',$context);$context = $tiling->_context( -type => 'query', -strand=> -1, -frame=>0);@covering_hsps_for_query = $tiling->next_tiling('query', $context);
DESCRIPTION
Frequently, users want to use a set of high-scoring pairs (HSPs) obtained from a BLAST or other search to assess the overall level of identity, conservation, or coverage represented by matches between a subject and a query sequence. Because a set of HSPs frequently describes multiple overlapping sequence fragments, a simple summation of statistics over the HSPs will generally overestimate those statistics. To obtain an accurate estimate of global hit statistics, a 'tiling' of HSPs onto either the subject or the query sequence must be performed, in order to properly correct for this.
This module will execute a tiling algorithm on a given hit based on an interval decomposition I'm calling the "coverage map". Internal object methods compute the various statistics, which are then stored in appropriately-named public object attributes. See Bio::Search::Tiling::MapTileUtils for more info on the algorithm.
STRAND/FRAME CONTEXTS
In BLASTX, TBLASTN, and TBLASTX reports, strand and frame information are reported for the query, subject, or query and subject, respectively, for each HSP. Tilings for these sequence types are only meaningful when they include HSPs in the same strand and frame, or "context". So, in these situations, the context must be specified in the method calls or the methods will throw.
Contexts are specified as strings: "[ 'all' | [m|p][_|0|1|2] ]", where "all" = all HSPs (will throw if context must be specified), "m" = minus strand, "p" = plus strand, and "_" = no frame info, "0,1,2" = respective (absolute) frame. The "_make_context_key" method will convert a (strand, frame) specification to a context string, e.g.:
$context = $self->_context(-type=>'query', -strand=>-1, -frame=>-2);
returns "m2".
The contexts present among the HSPs in a hit are identified and stored for convenience upon object construction. These are accessed off the object with the "contexts" method. If contexts don't apply for the given report, this returns "('all')".
TILED ALIGNMENTS
The experimental method "get_tiled_alns" in ALIGNMENTS will use a tiling to concatenate tiled hsps into a series of Bio::SimpleAlign objects:
@alns = $tiling->get_tiled_alns($type, $context);
Each alignment contains two sequences with ids 'query' and 'subject', and consists of a concatenation of tiling HSPs which overlap or are directly adjacent. The alignment are returned in $type sequence order. When HSPs overlap, the alignment sequence is taken from the HSP which comes first in the coverage map array.
The sequences in each alignment contain features (even though they are Bio::LocatableSeq objects) which map the original query/subject coordinates to the new alignment sequence coordinates. You can determine the original BLAST fragments this way:
$aln = ($tiling->get_tiled_alns)[0];$qseq = $aln->get_seq_by_id('query');$hseq = $aln->get_seq_by_id('subject');foreach my $feat ($qseq->get_SeqFeatures) {$org_start = ($feat->get_tag_values('query_start'))[0];$org_end = ($feat->get_tag_values('query_end'))[0];# original fragment as represented in the tiled alignment:$org_fragment = $feat->seq;}foreach my $feat ($hseq->get_SeqFeatures) {$org_start = ($feat->get_tag_values('subject_start'))[0];$org_end = ($feat->get_tag_values('subject_end'))[0];# original fragment as represented in the tiled alignment:$org_fragment = $feat->seq;}
DESIGN NOTE
The major calculations are made just-in-time, and then memoized. So, for example, for a given MapTiling object, a coverage map would usually be calculated only once (for the query), and at most twice (if the subject perspective is also desired), and then only when a statistic is first accessed. Afterward, the map and/or any statistic is read from storage. So feel free to call the statistic methods frequently if it suits you.
FEEDBACK
Mailing Lists
User feedback is an integral part of the evolution of this and other Bioperl modules. Send your comments and suggestions preferably to the Bioperl mailing list. Your participation is much appreciated.
[email protected] - General discussionhttp://bioperl.org/wiki/Mailing_lists - About the mailing lists
Support
Please direct usage questions or support issues to the mailing list:
rather than to the module maintainer directly. Many experienced and reponsive experts will be able look at the problem and quickly address it. Please include a thorough description of the problem with code and data examples if at all possible.
Reporting Bugs
Report bugs to the Bioperl bug tracking system to help us keep track of the bugs and their resolution. Bug reports can be submitted via the web:
https://github.com/bioperl/bioperl-live/issues
AUTHOR - Mark A. Jensen
Email maj -at- fortinbras -dot- us
APPENDIX
The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _
CONSTRUCTOR
new
Title : newUsage : my $obj = new Bio::Search::Tiling::GenericTiling();Function: Builds a new Bio::Search::Tiling::GenericTiling objectReturns : an instance of Bio::Search::Tiling::GenericTilingArgs : -hit => $a_Bio_Search_Hit_HitI_objectgeneral filter function:-hsp_filter => sub { my $this_hsp = shift;...;return 1 if $wanted;return 0; }
TILING ITERATORS
next_tiling
Title : next_tilingUsage : @hsps = $self->next_tiling($type);Function: Obtain a tiling: a minimal set of HSPs covering the $type('hit', 'subject', 'query') sequenceExample :Returns : an array of HSPI objectsArgs : scalar $type: one of 'hit', 'subject', 'query', with'subject' an alias for 'hit'
rewind_tilings
Title : rewind_tilingsUsage : $self->rewind_tilings($type)Function: Reset the next_tilings($type) iteratorExample :Returns : True on successArgs : scalar $type: one of 'hit', 'subject', 'query';default is 'query'
ALIGNMENTS
get_tiled_alns()
Title : get_tiled_alnsUsage : @alns = $tiling->get_tiled_alns($type, $context)Function: Use a tiling to construct a minimal set of alignmentobjects covering the region specified by $type/$contextby splicing adjacent HSP tilesReturns : an array of Bio::SimpleAlign objects; see Note belowArgs : scalar $type: one of 'hit', 'subject', 'query'default is 'query'scalar $context: strand/frame context stringFollowing $type and $context, an array ofordered, tiled HSP objects can be specified; this isthe tiling that will directly the alignment constructiondefault -- the first tiling provided by a tiling iteratorNotes : Each returned alignment is a concatenation of adjacent tiles.The set of alignments will cover all regions described by the$type/$context pair in the hit. The pair of sequences in eachalignment have ids 'query' and 'subject', and each sequencepossesses SeqFeatures that map the original query or subjectcoordinates to the sequence coordinates in the tiled alignment.
STATISTICS
identities
Title : identitiesUsage : $tiling->identities($type, $action, $context)Function: Retrieve the calculated number of identities for the invocantExample :Returns : value of identities (a scalar)Args : scalar $type: one of 'hit', 'subject', 'query'default is 'query'option scalar $action: one of 'exact', 'est', 'fast', 'max'default is 'exact'option scalar $context: strand/frame context stringNote : getter only
conserved
Title : conservedUsage : $tiling->conserved($type, $action)Function: Retrieve the calculated number of conserved sites for the invocantExample :Returns : value of conserved (a scalar)Args : scalar $type: one of 'hit', 'subject', 'query'default is 'query'option scalar $action: one of 'exact', 'est', 'fast', 'max'default is 'exact'option scalar $context: strand/frame context stringNote : getter only
length
Title : lengthUsage : $tiling->length($type, $action, $context)Function: Retrieve the total length of aligned residues forthe seq $typeExample :Returns : value of length (a scalar)Args : scalar $type: one of 'hit', 'subject', 'query'default is 'query'option scalar $action: one of 'exact', 'est', 'fast', 'max'default is 'exact'option scalar $context: strand/frame context stringNote : getter only
frac
Title : fracUsage : $tiling->frac($type, $denom, $action, $context, $method)Function: Return the fraction of sequence length consistingof desired kinds of pairs (given by $method),with respect to $denomReturns : scalar floatArgs : -type => one of 'hit', 'subject', 'query'-denom => one of 'total', 'aligned'-action => one of 'exact', 'est', 'fast', 'max'-context => strand/frame context string-method => one of 'identical', 'conserved'Note : $denom == 'aligned', return desired_stat/num_aligned$denom == 'total', return desired_stat/_reported_length(i.e., length of the original input sequences)Note : In keeping with the spirit of Bio::Search::HSP::HSPI,reported lengths of translated dna are reduced bya factor of 3, to provide fractions relative toamino acid coordinates.
frac_identical
Title : frac_identicalUsage : $tiling->frac_identical($type, $denom, $action, $context)Function: Return the fraction of sequence length consistingof identical pairs, with respect to $denomReturns : scalar floatArgs : -type => one of 'hit', 'subject', 'query'-denom => one of 'total', 'aligned'-action => one of 'exact', 'est', 'fast', 'max'-context => strand/frame context stringNote : $denom == 'aligned', return conserved/num_aligned$denom == 'total', return conserved/_reported_length(i.e., length of the original input sequences)Note : In keeping with the spirit of Bio::Search::HSP::HSPI,reported lengths of translated dna are reduced bya factor of 3, to provide fractions relative toamino acid coordinates.Note : This an alias that calls frac()
frac_conserved
Title : frac_conservedUsage : $tiling->frac_conserved($type, $denom, $action, $context)Function: Return the fraction of sequence length consistingof conserved pairs, with respect to $denomReturns : scalar floatArgs : -type => one of 'hit', 'subject', 'query'-denom => one of 'total', 'aligned'-action => one of 'exact', 'est', 'fast', 'max'-context => strand/frame context stringNote : $denom == 'aligned', return conserved/num_aligned$denom == 'total', return conserved/_reported_length(i.e., length of the original input sequences)Note : In keeping with the spirit of Bio::Search::HSP::HSPI,reported lengths of translated dna are reduced bya factor of 3, to provide fractions relative toamino acid coordinates.Note : This an alias that calls frac()
frac_aligned
Title : frac_alignedAliases : frac_aligned_query - frac_aligned(-type=>'query',...)frac_aligned_hit - frac_aligned(-type=>'hit',...)Usage : $tiling->frac_aligned(-type=>$type,-action=>$action,-context=>$context)Function: Return the fraction of input sequence lengththat was aligned by the algorithmReturns : scalar floatArgs : -type => one of 'hit', 'subject', 'query'-action => one of 'exact', 'est', 'fast', 'max'-context => strand/frame context string
num_aligned
Title : num_alignedUsage : $tiling->num_aligned(-type=>$type)Function: Return the number of residues of sequence $typethat were aligned by the algorithmReturns : scalar intArgs : -type => one of 'hit', 'subject', 'query'-action => one of 'exact', 'est', 'fast', 'max'-context => strand/frame context stringNote : Since this is calculated from reported coordinates,not symbol string counts, it is already in terms of"logical length"Note : Aliases length()
num_unaligned
Title : num_unalignedUsage : $tiling->num_unaligned(-type=>$type)Function: Return the number of residues of sequence $typethat were left unaligned by the algorithmReturns : scalar intArgs : -type => one of 'hit', 'subject', 'query'-action => one of 'exact', 'est', 'fast', 'max'-context => strand/frame context stringNote : Since this is calculated from reported coordinates,not symbol string counts, it is already in terms of"logical length"
range
Title : rangeUsage : $tiling->range(-type=>$type)Function: Returns the extent of the longest tilingas ($min_coord, $max_coord)Returns : array of two scalar integersArgs : -type => one of 'hit', 'subject', 'query'-context => strand/frame context string
ACCESSORS
coverage_map
Title : coverage_mapUsage : $map = $tiling->coverage_map($type)Function: Property to contain the coverage map calculatedby _calc_coverage_map() - see that fordetailsExample :Returns : value of coverage_map_$type as an arrayArgs : scalar $type: one of 'hit', 'subject', 'query'default is 'query'Note : getter
coverage_map_as_text
Title : coverage_map_as_textUsage : $tiling->coverage_map_as_text($type, $legend_flag)Function: Format a text-graphic representation of thecoverage mapReturns : an array of scalar strings, suitable for printingArgs : $type: one of 'query', 'hit', 'subject'$context: strand/frame context string$legend_flag: boolean; add a legend indicatingthe actual interval coordinates for each componentinterval and hsp (in the $type sequence context)Example : print $tiling->coverage_map_as_text('query',1);
hit
Title : hitUsage : $tiling->hitFunction:Example :Returns : The HitI object associated with the invocantArgs : noneNote : getter only
hsps
Title : hspsUsage : $tiling->hsps()Function: Container for the HSP objects associated with invocantExample :Returns : an array of hsps associated with the hitArgs : on set, new value (an arrayref or undef, optional)
contexts
Title : contextsUsage : @contexts = $tiling->context($type) or@indices = $tiling->context($type, $context)Function: Retrieve the set of available contexts in the hit,or the indices of hsps having the given context(integer indices for the array returned by $self->hsps)Returns : array of scalar context strings orarray of scalar positive integersundef if no hsps in given contextArgs : $type: one of 'query', 'hit', 'subject'optional $context: context string
mapping
Title : mappingUsage : $tiling->mapping($type)Function: Retrieve the mapping coefficient for the sequence typebased on the underlying algorithmReturns : scalar integer (mapping coefficient)Args : $type: one of 'query', 'hit', 'subject'Note : getter only (set in constructor)
default_context
Title : default_contextUsage : $tiling->default_context($type)Function: Retrieve the default strand/frame context stringfor the sequence type based on the underlying algorithmReturns : scalar string (context string)Args : $type: one of 'query', 'hit', 'subject'Note : getter only (set in constructor)
algorithm
Title : algorithmUsage : $tiling->algorithmFunction: Retrieve the algorithm name associated with theinvocant's hit objectReturns : scalar stringArgs : noneNote : getter only (set in constructor)
"PRIVATE" METHODS
Calculators
See Bio::Search::Tiling::MapTileUtils for lower level calculation methods.
_calc_coverage_map
Title : _calc_coverage_mapUsage : $tiling->_calc_coverage_map($type)Function: Calculates the coverage map for the object's associatedhit from the perspective of the desired $type (see Args:)and sets the coverage_map() propertyReturns : True on successArgs : optional scalar $type: one of 'hit'|'subject'|'query'default is 'query'Note : The "coverage map" is an array with the following format:( [ $component_interval => [ @containing_hsps ] ], ... ),where $component_interval is a closed interval (seeDESCRIPTION) of the form [$a0, $a1] with $a0 <= $a1, and@containing_hsps is an array of all HspI objects in the hitwhich completely contain the $component_interval.The set of $component_interval's is a disjoint decompositionof the minimum set of minimal intervals that completelycover the hit's HSPs (from the perspective of the $type)Note : This calculates the map for all strand/frame contexts availablein the hit
_calc_stats
Title : _calc_statsUsage : $tiling->_calc_stats($type, $action, $context)Function: Calculates [estimated] tiling statistics (identities, conserved siteslength) and sets the public accessorsReturns : True on successArgs : scalar $type: one of 'hit', 'subject', 'query'default is 'query'optional scalar $action: requests calculation methodcurrently one of 'exact', 'est', 'fast', 'max'option scalar $context: strand/frame context stringNote : Action: The statistics are calculated by summing quantitiesover the disjoint component intervals, taking into accountcoverage of those intervals by multiple HSPs. The actiontells the algorithm how to obtain those quantities--'exact' will use Bio::Search::HSP::HSPI::matchesto count the appropriate segment of the homology string;'est' will estimate the statistics by multiplying thefraction of the HSP overlapped by the component interval(see MapTileUtils) by the BLAST-reported identities/postives(this may be convenient for BLAST summary report formats)* Both exact and est take the average over the number of HSPsthat overlap the component interval.'max' uses the exact method to calculate the statistics,and returns only the maximum identites/positives overoverlapping HSP for the component interval. No averagingis involved here.'fast' doesn't involve tiling at all (hence the name),but it seems like a very good estimate, and uses onlyreported values, and so does not require sequence data. Itcalculates an average of reported identities, conservedsites, and lengths, over unmodified hsps in the hit,weighted by the length of the hsps.
Tiling Helper Methods
_make_tiling_iterator
Title : _make_tiling_iteratorUsage : $self->_make_tiling_iterator($type)Function: Create an iterator code ref that will step through allminimal combinations of HSPs that produce complete coverageof the $type ('hit', 'subject', 'query') sequence,and set the correct iterator property of the invocantExample :Returns : The iteratorArgs : scalar $type, one of 'hit', 'subject', 'query';default is 'query'
_tiling_iterator
Title : _tiling_iteratorUsage : $tiling->_tiling_iterator($type,$context)Function: Retrieve the tiling iterator coderef for the requested$type ('hit', 'subject', 'query')Example :Returns : coderef to the desired iteratorArgs : scalar $type, one of 'hit', 'subject', 'query'default is 'query'option scalar $context: strand/frame context stringNote : getter only
Construction Helper Methods
See also Bio::Search::Tiling::MapTileUtils.
_make_context_key
Title : _make_context_keyAlias : _contextUsage : $tiling->_make_context_key(-strand => $strand, -frame => $frame)Function: create a string indicating strand/frame context; serves ascomponent of memoizing hash keysReturns : scalar stringArgs : -type => one of ('query', 'hit', 'subject')-strand => one of (1,0,-1)-frame => one of (-2, 1, 0, 1, -2)called w/o args: returns 'all'
_context
Title : _contextAlias : _make_context_keyUsage : $tiling->_make_context_key(-strand => $strand, -frame => $frame)Function: create a string indicating strand/frame context; serves ascomponent of memoizing hash keysReturns : scalar stringArgs : -type => one of ('query', 'hit', 'subject')-strand => one of (1,0,-1)-frame => one of (-2, 1, 0, 1, -2)called w/o args: returns 'all'
Predicates
Most based on a reading of the algorithm name with a configuration lookup.
- _has_sequence_data()
- _has_logical_length()
- _has_strand()
- _has_frame()
Private Accessors
_contig_intersection
Title : _contig_intersectionUsage : $tiling->_contig_intersection($type)Function: Return the minimal set of $type coordinate intervalscovered by the invocant's HSPsReturns : array of intervals (2-member arrayrefs; see MapTileUtils)Args : scalar $type: one of 'query', 'hit', 'subject'
_reported_length
Title : _reported_lengthUsage : $tiling->_reported_length($type)Function: Get the total length of the seq $typefor the invocant's hit object, as reportedby (not calculated from) the input data fileReturns : scalar intArgs : scalar $type: one of 'query', 'hit', 'subject'Note : This is kludgy; the hit object does not currentlymaintain accessors for these values, but thehsps possess these attributes. This is a wrapperthat allows a consistent access method in theMapTiling code.Note : Since this number is based on a reported length,it is already a "logical length".