59 #ifdef _TRACE_MergeAlnRngColl
61 cerr <<
"existing:" << endl << existing << endl;
62 cerr <<
"addition:" << endl << addition << endl;
63 cerr <<
"difference = addition - existing:" << endl << difference << endl;
78 #ifdef _TRACE_MergeAlnRngColl
79 cerr <<
"result = existing + difference:" << endl << existing << endl;
115 (*it)->SortInsertions();
127 addition->GetSecondId(),
128 addition->GetPolicyFlags()));
133 #ifdef _TRACE_MergeAlnRngColl
135 cerr <<
"existing:" << endl << existing << endl;
136 cerr <<
"addition:" << endl << *addition << endl;
137 cerr <<
"truncated = addition - existing:" << endl << *truncated << endl;
148 addition = truncated;
149 addition->AddInsertions(gaps_truncated);
152 addition = truncated;
187 CPairwiseAln::const_iterator it =
a.find_insertion_point(
r);
189 if (it !=
a.begin()) {
193 r.IsDirect() ?
r : left) ) {
201 r.IsDirect() ? right :
r) ) {
210 TPairwiseAlnVector::iterator aln_it, aln_end;
212 CPairwiseAln::TInsertions::const_iterator gap_it = gaps.begin();
220 if (rng_it->IsDirect()) {
230 while (aln_it != aln_end) {
231 #ifdef _TRACE_MergeAlnRngColl
233 cerr << *rng_it << endl;
234 cerr << **aln_it << endl;
245 if (aln_it == aln_end) {
254 if (rng_it->IsDirect() &&
259 (*aln_it)->insert(*rng_it);
260 #ifdef _TRACE_MergeAlnRngColl
269 CPairwiseAln::const_iterator next_rng_it = rng_it;
272 if (next_rng_it != addition.
end()) {
273 next_rng_pos = next_rng_it->GetFirstFrom();
277 while (gap_it != gaps.end() &&
278 (gap_it->GetFirstFrom() <= next_rng_pos || next_rng_pos < 0)) {
279 (*aln_it)->AddInsertion(*gap_it);
295 out <<
"MergedPairwiseAln contains: " << endl;
312 size_t total_number_of_rows = 0;
314 total_number_of_rows += (*merged_i)->GetPairwiseAlns().size();
334 sort(anchored_aln_vec.begin(),
335 anchored_aln_vec.end(),
344 if ( anchor_pw.
empty() )
return;
348 aln_len += it->GetLength();
351 bool direct = anchor_pw.
begin()->IsFirstDirect();
376 CPairwiseAln::TInsertions::const_iterator gap_it = gaps.begin();
387 if (gap_it != gaps.end()) {
388 CPairwiseAln::const_iterator next_it = it;
390 if (next_it != pw.
end()) {
391 while (gap_it != gaps.end() &&
392 gap_it->GetFirstFrom() <= next_it->GetFirstFrom()) {
411 while (gap_it != gaps.end()) {
417 if (new_gap_pos == -1) {
422 else if ( !direct ) {
454 bool direct = (new_anchor_pw->begin()->IsFirstDirect() == anchor_pw.
begin()->IsFirstDirect());
457 for (
TDim row = 0; row < (
TDim)pairwises.size(); ++row) {
458 if (row == anchor_row) {
459 pairwises[row].Reset(new_anchor_pw);
468 pairwises[row].Reset(new_pw);
481 bool have_direct =
false;
482 bool have_reverse =
false;
488 if ( !common_anchor_id ) {
491 else if ( !common_anchor_id->GetSeqId().Equals(
498 if ( seg->IsFirstDirect() ) {
504 if (have_direct && have_reverse) {
508 if (have_direct && have_reverse) {
512 if (have_direct && have_reverse) {
516 if (!have_direct || !have_reverse) {
529 out_alns->push_back(anchored_copy);
531 for (
int row = 0; row < anchored.
GetDim(); ++row) {
541 pw_copy->insert(seg_copy);
570 if (anchored_it == adj_alns->begin()) {
575 for (
TDim row = 0; row < anchored.
GetDim(); ++row) {
580 }
else if (!anchor_first) {
591 if ( !adj_alns->empty() ) {
596 const CAnchoredAln& first_anchored = *adj_alns->front();
597 merged_vec.resize(first_anchored.
GetDim());
602 string errstr =
"All input alignments need to have "
603 "the same dimension when using ePreserveRows.";
608 string errstr =
"All input alignments need to have "
609 "the same anchor row when using ePreserveRows.";
612 for (
TDim row = 0; row < anchored.
GetDim(); ++row) {
614 if (merged.
Empty()) {
633 TIdMergedMap id_merged_map;
636 #ifdef _TRACE_MergeAlnRngColl
643 merged_vec.push_back(merged_anchor);
652 #ifdef _TRACE_MergeAlnRngColl
654 cerr << *merged_anchor << endl;
655 cerr <<
"inserting aln " << aln_idx <<
", anchor row (" << anchor_row <<
")" << endl;
659 if (anchored_it == adj_alns->begin()) {
660 id_merged_map[anchored_aln.
GetId(anchor_row)].
Reset(merged_anchor);
664 for (
TDim row = anchored_aln.
GetDim() - 1; row >=0; --row) {
665 if (row != anchor_row) {
667 if (merged.
Empty()) {
672 merged_vec.push_back(merged);
674 #ifdef _TRACE_MergeAlnRngColl
675 cerr << *merged << endl;
676 cerr <<
"inserting aln " << aln_idx <<
", row " << row << endl;
682 #ifdef _TRACE_MergeAlnRngColl
688 merged_vec.push_back(merged_anchor);
691 (*ma)->SortInsertions();
699 if ( !pseudo_seqid ) {
703 pseudo_seqid.
Reset(aln_seq_id);
void MergePairwiseAlns(CPairwiseAln &existing, const CPairwiseAln &addition, const CAlnUserOptions::TMergeFlags &flags)
Merge two pariwise alignments.
void s_TranslateAnchorToAlnCoords(CPairwiseAln &out_anchor_pw, const CPairwiseAln &anchor_pw)
void SortAnchoredAlnVecByScore(TAnchoredAlnVec &anchored_aln_vec)
Sort anchored alignments by score.
void s_TranslatePairwiseToAlnCoords(CPairwiseAln &out_pw, const CPairwiseAln &pw, const CPairwiseAln &tr, bool direct)
vector< CRef< CMergedPairwiseAln > > TMergedVec
void x_AdjustAnchorDirection(TAnchoredAlnVec &in_alns, AutoPtr< TAnchoredAlnVec > &out_alns)
ostream & operator<<(ostream &out, const CMergedPairwiseAln &merged)
void BuildAln(const TMergedVec &merged_vec, CAnchoredAln &out_aln)
void s_TranslateToAlnCoords(CAnchoredAln &anchored_aln, const TAlnSeqIdIRef &pseudo_seqid)
void SubtractAlnRngCollections(const CAlignRangeCollectionList< TAlnRng > &minuend, const CAlignRangeCollectionList< TAlnRng > &subtrahend, CAlignRangeCollectionList< TAlnRng > &difference)
Subtract one range collection from another.
class CAlignRangeCollectionList<TAlignRange> represent a sorted collection of TAlignRange.
int GetPolicyFlags() const
const_iterator begin() const
const_iterator insert(const TAlignRange &r)
@ fAllowOverlap
allow segments with different orientation
@ fAllowAbutting
allow segments overlapping on the first sequence
@ fAllowMixedDir
enforce all policies after any modification
@ fReversed
contains at least one direct range
TSignedSeqPos GetFirstPosBySecondPos(position_type pos, ESearchDirection dir=eNone) const
const TInsertions & GetInsertions() const
Each insertion shows where the 'first' sequence has a gap while the 'second' sequence has the inserti...
vector< TAlignRange > TInsertions
const_iterator end() const
void AddInsertion(const TAlignRange &r)
void AddInsertions(const TInsertions &insertions)
CAlignRange Represents an element of pairwise alignment of two sequences.
Default IAlnSeqId implementation based on CSeq_id_Handle.
Options for different alignment manager operations.
@ eMergeAllSeqs
Merge all sequences (greedy algo).
@ ePreserveRows
Preserve all rows as they were in the input (e.g.
@ eQuerySeqMergeOnly
Only put the query seq on same row (input order is not significant).
@ fUseAnchorAsAlnSeq
Use the anchor sequence as the alignment sequence.
@ fAllowTranslocation
Allow translocations on the same row.
@ fSkipSortByScore
In greedy algos, skip sorting input alignments by score thus allowing for user-defined sort order.
@ fAnchorRowFirst
Store anchor row in the first pairwise alignment (by default it's stored in the last one).
@ fTruncateOverlaps
Truncate overlapping ranges.
@ fIgnoreInsertions
Do not collect and store insertions (gaps on the anchor).
@ fAllowMixedStrand
Allow mixed strands on the same row.
Query-anchored alignment can be 2 or multi-dimentional.
const TPairwiseAlnVector & GetPairwiseAlns(void) const
The vector of pairwise alns.
vector< CRef< CPairwiseAln > > TPairwiseAlnVector
const TAlnSeqIdIRef & GetId(TDim row) const
Seq ids of the rows.
TDim GetDim(void) const
How many rows.
void SetAnchorRow(TDim anchor_row)
Modify anchor row (never do this unless you are creating a new alignment and know what you're doing).
TPairwiseAlnVector & SetPairwiseAlns(void)
Modify pairwise alns.
void SetScore(int score)
Set the total score.
TDim GetAnchorRow(void) const
Which is the anchor row?
int GetScore(void) const
What is the total score?
const TAlnSeqIdIRef & GetAnchorId(void) const
What is the seq id of the anchor?
void SetDim(TDim dim)
Modify the number of rows.
bool x_ValidNeighboursOnSecondDim(const CPairwiseAln::TAlnRng &left, const CPairwiseAln::TAlnRng &right)
const TPairwiseAlnVector & GetPairwiseAlns() const
bool x_CanInsertRng(CPairwiseAln &a, const CPairwiseAln::TAlnRng &r)
void x_TruncateOverlaps(CRef< CPairwiseAln > &addition)
size_t m_NumberOfDirectAlns
bool x_ValidNeighboursOnFirstDim(const CPairwiseAln::TAlnRng &left, const CPairwiseAln::TAlnRng &right)
const CAlnUserOptions::TMergeFlags m_MergeFlags
void SortInsertions(void)
const CAlnUserOptions::TMergeFlags & GetMergedFlags() const
CMergedPairwiseAln(const CAlnUserOptions::TMergeFlags &merge_flags)
void x_AddPairwise(const CPairwiseAln &addition)
void insert(const CRef< CPairwiseAln > &pairwise)
CAnchoredAln::TPairwiseAlnVector TPairwiseAlnVector
TPairwiseAlnVector m_PairwiseAlns
A pairwise aln is a collection of ranges for a pair of rows.
const TAlnSeqIdIRef & GetFirstId(void) const
Get first sequence id.
const TAlnSeqIdIRef & GetSecondId(void) const
Get second sequence id.
std::ofstream out("events_result.xml")
main entry point for tests
void reset(element_type *p=0, EOwnership ownership=eTakeOwnership)
Reset will delete the old pointer (if owned), set content to the new value, and assume the ownership ...
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
element_type * get(void) const
Get pointer.
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
@ eTakeOwnership
An object can take ownership of another.
@ eNoOwnership
No ownership is assumed.
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
void Reset(void)
Reset reference object.
bool Empty(void) const THROWS_NONE
Check if CRef is empty – not pointing to any object, which means having a null value.
position_type GetFirstToOpen(void) const
position_type GetFirstTo(void) const
position_type GetSecondFrom(void) const
void SetDirect(bool direct=true)
TThisType & SetFirstFrom(position_type from)
void SetFirstDirect(bool direct=true)
position_type GetFirstFrom(void) const
position_type GetSecondToOpen(void) const
position_type GetLength(void) const
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
@ eCurrent
Use current time. See also CCurrentTime.
constexpr auto sort(_Init &&init)
Defines: CTimeFormat - storage class for time format.
double r(size_t dimension_, const Int4 *score_, const double *prob_, double theta_)
vector< CRef< CAnchoredAln > > TAnchoredAlnVec
Collection of anchored alignments.
Compare alignments by score.