LocARNA-2.0.0
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
LocARNA::Scoring Class Reference

Provides methods for the scoring of alignments. More...

#include <scoring.hh>

Inheritance diagram for LocARNA::Scoring:
Inheritance graph
[legend]
Collaboration diagram for LocARNA::Scoring:
Collaboration graph
[legend]

Public Types

typedef BasePairs__Arc Arc
 arc
 

Public Member Functions

 Scoring (const Sequence &seqA, const Sequence &seqB, const RnaData &rna_dataA, const RnaData &rna_dataB, const ArcMatches &arc_matches, const MatchProbs *match_probs, const ScoringParams &params)
 construct scoring object More...
 
void modify_by_parameter (score_t lambda)
 modify scoring by a parameter lambda. More...
 
void apply_unpaired_penalty ()
 
score_t lambda () const
 Get factor lambda for normalized alignment. More...
 
score_t basematch (size_type i, size_type j) const
 Score of a match of bases (without structure) More...
 
score_t arcmatch (const ArcMatch &am, bool stacked=false) const
 Score of arc match, support explicit arc match scores. More...
 
score_t arcmatch (const BasePairs__Arc &arcA, const BasePairs__Arc &arcB, bool stacked=false) const
 Score of arc match, given two arcs. More...
 
const ArcMatchesarc_matches () const
 
template<bool gapAorB>
score_t arcDel (const BasePairs__Arc &arc, bool stacked=false) const
 Very basic interface, score of aligning a basepair to gap. More...
 
score_t arcmatch_stacked (const ArcMatch &am) const
 Score of stacked arc match. More...
 
template<bool gapInA>
score_t gapX (size_type alignedToGap) const
 
score_t gapA (size_type posA) const
 
score_t gapB (size_type posB) const
 
score_t exclusion () const
 cost of an exclusion
 
score_t indel_opening () const
 cost to begin a new indel
 
score_t loop_indel_score (const score_t score) const
 multiply an score by the ratio of indel_loop/indel
 
score_t indel_opening_loop () const
 cost to begin a new indel
 
double prob_exp (size_type len) const
 Expected base pair probability. More...
 
bool stacking () const
 Query stacking flag. More...
 
bool is_stackable_arcA (const Arc &a) const
 Is arc of A stackable. More...
 
bool is_stackable_arcB (const Arc &a) const
 Is arc of B stackable. More...
 
bool is_stackable_am (const ArcMatch &am) const
 Is arc match stackable. More...
 
template<>
score_t gapX (size_type alignedToGap) const
 
template<>
score_t gapX (size_type alignedToGap) const
 

Protected Member Functions

void precompute_sequence_identities ()
 
score_t round2score (double d) const
 Round a double to score_t. More...
 
score_t sigma_ (int i, int j) const
 Compute base similarity. More...
 
void precompute_sigma ()
 Precompute all base similarities. More...
 
void precompute_gapcost ()
 Precompute the tables for gapcost.
 
void precompute_weights ()
 Precompute weights/stacked weights for all arcs in A and B.
 
void precompute_weights (const RnaData &rna_data, const BasePairs &bps, double exp_prob, std::vector< score_t > &weights, std::vector< score_t > &stack_weights)
 Helper for precompute_weights (does job for one rna) More...
 
score_t probToWeight (double p, double prob_exp) const
 convert probability to weight for scoring More...
 
double ribosum_arcmatch_prob (const Arc &arcA, const Arc &arcB) const
 
score_t riboX_arcmatch_score (const Arc &arcA, const Arc &arcB) const
 ribofit or ribosum arcmatch score contribution More...
 
void subtract (std::vector< score_t > &v, score_t x) const
 subtract from each element of a score_t vector v a value x
 
void subtract (Matrix< score_t > &m, score_t x) const
 subtract from each element of a score_t Matrix m a value x
 

Protected Attributes

const ScoringParamsparams
 a collection of parameters for scoring
 
const ArcMatchesarc_matches_
 arc matches
 
const MatchProbsmatch_probs
 base match probabilities
 
const RnaDatarna_dataA
 rna data for RNA A
 
const RnaDatarna_dataB
 rna data for RNA B
 
const SequenceseqA
 sequence A
 
const SequenceseqB
 sequence B
 
score_t lambda_
 
Matrix< score_tsigma_tab
 precomputed table of base match similarities
 
std::vector< score_tgapcost_tabA
 table for gapcost in A
 
std::vector< score_tgapcost_tabB
 table for gapcost in B
 
std::vector< score_tweightsA
 
std::vector< score_tweightsB
 
std::vector< score_tstack_weightsA
 
std::vector< score_tstack_weightsB
 
Matrix< size_t > identity
 sequence identities in percent
 

Detailed Description

Provides methods for the scoring of alignments.

Maintains and provides the scores for the alignment of two specific Rnas. Configurable via class ScoringParams, supports the classic LocARNA-score as well as the LocARNA MEA-Score. for "Classic Score" it supports

The scoring class supports only characters ACGU, gap -, and N for ribosum scoring. ALL other characters are treated as unknown characters and are basically ignored. In consequence, IUPAC codes are handled badly. Even more important, for ribosum scoring, sequences have to be upper case and Ts should be converted to Us!!!

Note
The class implements two versions of the stacking score (controlled by ScoringParams flags stacking and new_stacking. The first flag lets the class derive the arc weights for stacked arcs from the conditional probability of the base pair (i,j) if (i+1,j-1) exists. The new_stacking flag adds a log odd contribution derived from the joint probability of (i,j) and (i+1,j-1) to the weight of (i,j).
Note
holds only pointers and references to passed objects; since no copies are made, the caller is responsible to keep the objects alive
the set of possible arc matches is considered part of the scoring information for alignments

Constructor & Destructor Documentation

◆ Scoring()

LocARNA::Scoring::Scoring ( const Sequence seqA,
const Sequence seqB,
const RnaData rna_dataA,
const RnaData rna_dataB,
const ArcMatches arc_matches,
const MatchProbs match_probs,
const ScoringParams params 
)

construct scoring object

Parameters
seqAfirst sequence
seqBsecond sequence
rna_dataAprobability data of first sequence
rna_dataBprobability data of second sequence
arc_matchesthe (significant) arc matches between the sequences
match_probspointer to base match probabilities (can be nullptr for non-mea scores)
paramsa collection of parameters for scoring
Note
caller must keep passed objects alive

Member Function Documentation

◆ apply_unpaired_penalty()

void LocARNA::Scoring::apply_unpaired_penalty ( )

subtract the fixed unpaired_penalty from base match and base indel scores it is similar to @modify_by_parameter method Please note that the base match and gap scores of ALL bases including the paired ones will be modified!

◆ arc_matches()

const ArcMatches* LocARNA::Scoring::arc_matches ( ) const
inline

Read access to the stored arc_matches pointer

◆ arcDel()

template<bool isA>
score_t LocARNA::Scoring::arcDel ( const BasePairs__Arc arc,
bool  stacked = false 
) const

Very basic interface, score of aligning a basepair to gap.

Note
gapAorB whether deleting element in A or B (true for A)
Parameters
arcthe base pair
stackedwhether the base pair is stacked
Returns

◆ arcmatch() [1/2]

score_t LocARNA::Scoring::arcmatch ( const ArcMatch am,
bool  stacked = false 
) const

Score of arc match, support explicit arc match scores.

Parameters
amarc match
stackedis stacked? (optional parameter)
Returns
Score of arc match am (potentially stacked)
Note
This method supports explicit arc match scores. Such scores are required for the probabilistic mode of (m)locarna.
This method should be prefered over arcmatch(const Arc &arcA, const Arc &arcB, bool stacked=false) unless explicit arc match scores are not needed and the use of this method would be too inefficient.

◆ arcmatch() [2/2]

score_t LocARNA::Scoring::arcmatch ( const BasePairs__Arc arcA,
const BasePairs__Arc arcB,
bool  stacked = false 
) const

Score of arc match, given two arcs.

Parameters
arcAbase pair in A
arcBbase pair in B
stackedis stacked? (optional parameter)
Returns
Score of arc match am (potentially stacked)
Note
This method does not support explicit arc match scores, since this would require to know the arcmatch object.
Using this method is disallowed if arc_matches->explicit_scores()==true (This results in a run-time error if !NDEBUG).

◆ arcmatch_stacked()

score_t LocARNA::Scoring::arcmatch_stacked ( const ArcMatch am) const
inline

Score of stacked arc match.

Parameters
amarc match
Returns
Score of arc match am when stacked

◆ basematch()

score_t LocARNA::Scoring::basematch ( size_type  i,
size_type  j 
) const
inline

Score of a match of bases (without structure)

Parameters
iposition in A
jposition in B
Returns
score of base match i~j

◆ gapA()

score_t LocARNA::Scoring::gapA ( size_type  posA) const
inline

Score of deletion

Parameters
posAposition in A
Returns
score of deletion of posA after posB

◆ gapB()

score_t LocARNA::Scoring::gapB ( size_type  posB) const
inline

Score of insertion

Parameters
posBposition in B
Returns
score of insertion of posB after posA

◆ gapX()

template<bool gapInA>
score_t LocARNA::Scoring::gapX ( size_type  alignedToGap) const
inline

Score of deletion

Parameters
alignedToGapposition in A or B
gapInAwhether symbol in A (true) or B (false) is aligned to gap
Returns
score of deletion : posA <--> posB

◆ is_stackable_am()

bool LocARNA::Scoring::is_stackable_am ( const ArcMatch am) const

Is arc match stackable.

Parameters
amArc match
Returns
whether stackable

◆ is_stackable_arcA()

bool LocARNA::Scoring::is_stackable_arcA ( const Arc a) const

Is arc of A stackable.

Parameters
aArc
Returns
whether stackable

◆ is_stackable_arcB()

bool LocARNA::Scoring::is_stackable_arcB ( const Arc a) const

Is arc of B stackable.

Parameters
aArc
Returns
whether stackable

◆ lambda()

score_t LocARNA::Scoring::lambda ( ) const
inline

Get factor lambda for normalized alignment.

Returns
lambda

◆ modify_by_parameter()

void LocARNA::Scoring::modify_by_parameter ( score_t  lambda)

modify scoring by a parameter lambda.

Used in the computational of normalized local alignment by fractional programming in the form of the Dinkelbach algorithm. The modification is destructive. modify_by_parameter(0) results in unmodified scoring. Repeated modifications are valid. The Outcome is undefined when the Scoring object is used to obtain exponentiated scores (methods exp_...) as in partition function alignment.

Parameters
lambdathe parameter

◆ precompute_sigma()

void LocARNA::Scoring::precompute_sigma ( )
protected

Precompute all base similarities.

Precomputed similarities are stored in the sigma table.

◆ precompute_weights()

void LocARNA::Scoring::precompute_weights ( const RnaData rna_data,
const BasePairs bps,
double  exp_prob,
std::vector< score_t > &  weights,
std::vector< score_t > &  stack_weights 
)
protected

Helper for precompute_weights (does job for one rna)

Parameters
rna_datarna probability data
bpsbase pairs
exp_probbackground probability
weights[out]base pair score weights
stack_weights[out]base pair stacking score weights

◆ prob_exp()

double LocARNA::Scoring::prob_exp ( size_type  len) const

Expected base pair probability.

Parameters
lenlength of RNA sequence
Returns
expected base pair probability for sequence length
Note
influences computation of weights for base pairs

◆ probToWeight()

score_t LocARNA::Scoring::probToWeight ( double  p,
double  prob_exp 
) const
protected

convert probability to weight for scoring

Parameters
pprobability
exp_probbackground probability
Returns
In standard case, normlized log of probability; in case of mea, score_res*probability.

◆ ribosum_arcmatch_prob()

double LocARNA::Scoring::ribosum_arcmatch_prob ( const Arc arcA,
const Arc arcB 
) const
protected

returns probability of matching the concrete bases in an arcmatch, probability is based on ribosum data

◆ riboX_arcmatch_score()

score_t LocARNA::Scoring::riboX_arcmatch_score ( const Arc arcA,
const Arc arcB 
) const
protected

ribofit or ribosum arcmatch score contribution

Sequence-based score contribution to match of the arcs due to ribofit matrix (if ribofit enabled) or ribosum matrix. The score contribution is calculated as sum-of-pairs; gaps and non-standard symbols (different from ACGU) are ignored!

Parameters
arcAarc A
arcBarc B
Returns
score contribution

◆ round2score()

score_t LocARNA::Scoring::round2score ( double  d) const
inlineprotected

Round a double to score_t.

Proper rounding is more robust than truncate

Parameters
dscore of type double
Returns
d rounded to integral type score_t

◆ sigma_()

score_t LocARNA::Scoring::sigma_ ( int  ia,
int  ib 
) const
protected

Compute base similarity.

Parameters
iposition in A
jposition in B
Returns
similarity of i and j
Note
used for precomputing the score, which is then tabellized

returns similarity of two alignment columns

◆ stacking()

bool LocARNA::Scoring::stacking ( ) const
inline

Query stacking flag.

Returns
flag, whether stacking is used (old or new stacking terms)

Member Data Documentation

◆ lambda_

score_t LocARNA::Scoring::lambda_
protected

parameter for modified scoring in normalized local alignment


The documentation for this class was generated from the following files: