1 #ifndef OBJTOOLS_ALNMGR___ALN_CONVERTERS__HPP
2 #define OBJTOOLS_ALNMGR___ALN_CONVERTERS__HPP
77 const objects::CSeq_align& sa,
89 const objects::CDense_seg& ds,
101 const objects::CPacked_seg& ps,
113 const objects::CSeq_align::TSegs::TStd& stds,
139 const objects::CSparse_seg& sparse_seg,
151 const objects::CSpliced_seg& spliced_seg,
176 const objects::CSeq_loc& loc_1,
177 const objects::CSeq_loc& loc_2,
204 template<
class _TAlnStats>
206 const _TAlnStats& aln_stats,
212 TDim dim = aln_stats.GetDimForAln(aln_idx);
216 if (explicit_anchor_row >= 0) {
217 if (explicit_anchor_row >= dim) {
219 "Invalid explicit_anchor_row");
221 anchor_row = explicit_anchor_row;
224 size_t anchor_id_idx = 0;
225 if ( aln_stats.CanBeAnchored() ) {
231 if (it == aln_stats.GetAnchorIdMap().end()) {
233 "Invalid options.GetAnchorId()");
235 anchor_id_idx = it->second[0];
240 for (
size_t i = 0;
i < aln_stats.GetAnchorIdVec().
size(); ++
i) {
242 if (aln_stats.GetAnchorIdMap().find(anchor_id)->second.size() > 1) {
248 anchor_id_idx = aln_stats.GetAnchorIdxVec()[
i];
254 anchor_id_idx = aln_stats.GetAnchorIdxVec()[
i];
262 "Alignments cannot be anchored.");
264 anchor_row = aln_stats.GetRowVecVec()[anchor_id_idx][aln_idx];
270 bool force_widths =
false;
271 if ( aln_stats.GetIdVec()[anchor_row]->IsProtein() ) {
272 for (
size_t i = 0;
i < aln_stats.GetIdVec().
size(); ++
i) {
273 if ( !aln_stats.GetIdVec()[
i]->IsProtein() ) {
280 const CSeq_align& seq_aln = *aln_stats.GetAlnVec()[aln_idx];
298 typedef typename _TAlnStats::TIdVec TIdVec;
299 const TIdVec ids = aln_stats.GetSeqIdsForAln(aln_idx);
301 pairwises.resize(dim);
306 row == anchor_row ? anchor_flags :
flags));
309 *pairwise_aln, seq_aln,
314 if ( force_widths ) {
316 pairwise_aln->ForceGenomicCoords();
319 if ( pairwise_aln->empty() ) {
326 if (empty_rows == dim - 1) {
334 TDim new_dim = dim - empty_rows;
338 TDim target_anchor_row =
343 anchored_aln->
SetDim(new_dim);
347 if (target_row == target_anchor_row) {
352 target_row++].Reset(pairwises[
row]);
362 template<
class _TAlnStats>
368 out_vec.reserve(aln_stats.GetAlnCount());
369 for (
size_t aln_idx = 0; aln_idx < aln_stats.GetAlnCount(); ++aln_idx) {
372 if ( !anchored_aln )
continue;
374 const CSeq_align& aln = *aln_stats.GetAlnVec()[aln_idx];
376 bool need_split =
false;
391 if (
row == anchor_row)
continue;
393 for (
auto apw_seg = apw.
begin(), rpw_seg = rpw.
begin();
394 rpw_seg != rpw.
end(); ++apw_seg, ++rpw_seg) {
397 sub_anchored_aln->
SetDim(2);
400 sub_row->insert(sub_row->end(), *rpw_seg);
403 sub_anchor_row->insert(sub_anchor_row->end(), *apw_seg);
404 if (anchor_row == 0) {
414 out_vec.push_back(sub_anchored_aln);
415 sub_anchored_aln->
SetScore(rpw_seg->GetLength());
422 out_vec.push_back(anchored_aln);
426 anchored_aln->
SetScore() += rng_it->GetLength();
CRef< CPairwiseAln > CreatePairwiseAlnFromSeqAlign(const objects::CSeq_align &seq_align)
A simple API that assumes that the seq_align has exactly two rows and you want to create a pairwise w...
void ConvertSeqAlignToPairwiseAln(CPairwiseAln &pairwise_aln, const objects::CSeq_align &sa, objects::CSeq_align::TDim row_1, objects::CSeq_align::TDim row_2, CAlnUserOptions::EDirection direction=CAlnUserOptions::eBothDirections, const TAlnSeqIdVec *ids=0)
Build pairwise alignment from the selected rows of a seq-align.
void ConvertStdsegToPairwiseAln(CPairwiseAln &pairwise_aln, const objects::CSeq_align::TSegs::TStd &stds, objects::CSeq_align::TDim row_1, objects::CSeq_align::TDim row_2, CAlnUserOptions::EDirection direction=CAlnUserOptions::eBothDirections, const TAlnSeqIdVec *ids=0)
Build pairwise alignment from the selected rows of an std-seg.
void ConvertSeqLocsToPairwiseAln(CPairwiseAln &aln, const objects::CSeq_loc &loc_1, const objects::CSeq_loc &loc_2, CAlnUserOptions::EDirection direction=CAlnUserOptions::eBothDirections)
Build pairwise alignment from a pair of seq-locs.
void ConvertDensegToPairwiseAln(CPairwiseAln &pairwise_aln, const objects::CDense_seg &ds, objects::CSeq_align::TDim row_1, objects::CSeq_align::TDim row_2, CAlnUserOptions::EDirection direction=CAlnUserOptions::eBothDirections, const TAlnSeqIdVec *ids=0)
Build pairwise alignment from the selected rows of a dense-seg.
void ConvertSparseToPairwiseAln(CPairwiseAln &pairwise_aln, const objects::CSparse_seg &sparse_seg, objects::CSeq_align::TDim row_1, objects::CSeq_align::TDim row_2, CAlnUserOptions::EDirection direction=CAlnUserOptions::eBothDirections, const TAlnSeqIdVec *ids=0)
Build pairwise alignment from the selected rows of a sparse-seg.
void ConvertSplicedToPairwiseAln(CPairwiseAln &pairwise_aln, const objects::CSpliced_seg &spliced_seg, objects::CSeq_align::TDim row_1, objects::CSeq_align::TDim row_2, CAlnUserOptions::EDirection direction=CAlnUserOptions::eBothDirections, const TAlnSeqIdVec *ids=0)
Build pairwise alignment from the selected rows of a spliced-seg.
void ConvertDendiagToPairwiseAln(CPairwiseAln &pairwise_aln, const objects::CSeq_align::TSegs::TDendiag &dendiags, objects::CSeq_align::TDim row_1, objects::CSeq_align::TDim row_2, CAlnUserOptions::EDirection direction=CAlnUserOptions::eBothDirections, const TAlnSeqIdVec *ids=0)
Build pairwise alignment from the selected rows of a dendiag.
list< CRef< CPairwiseAln > > TPairwiseAlnList
void SeqLocMapperToPairwiseAligns(const objects::CSeq_loc_Mapper_Base &mapper, TPairwiseAlnList &aligns)
Build a list of pairwise alignments from a seq-loc mapper's mappings.
void CreateAnchoredAlnVec(_TAlnStats &aln_stats, TAnchoredAlnVec &out_vec, const CAlnUserOptions &options)
Create anchored alignment from each seq-align in the stats.
void ConvertPackedsegToPairwiseAln(CPairwiseAln &pairwise_aln, const objects::CPacked_seg &ps, objects::CSeq_align::TDim row_1, objects::CSeq_align::TDim row_2, CAlnUserOptions::EDirection direction=CAlnUserOptions::eBothDirections, const TAlnSeqIdVec *ids=0)
Build pairwise alignment from the selected rows of a packed-seg.
CRef< CAnchoredAln > CreateAnchoredAlnFromAln(const _TAlnStats &aln_stats, size_t aln_idx, const CAlnUserOptions &options, objects::CSeq_align::TDim explicit_anchor_row=-1)
Create an anchored alignment from Seq-align using hints.
vector< TAlnSeqIdIRef > TAlnSeqIdVec
#define _ALNMGR_ASSERT(expr)
bool IsSet(int flags) const
int GetPolicyFlags() const
const_iterator begin() const
@ fMixedDir
contains at least one reversed range
@ fAllowOverlap
allow segments with different orientation
@ fIgnoreInsertions
allows segments not separated by gaps
@ fAllowMixedDir
enforce all policies after any modification
@ fKeepNormalized
Policies:
const_iterator end() const
Options for different alignment manager operations.
const TAlnSeqIdIRef & GetAnchorId(void) const
Get anchor id.
EDirection
Row direction flags.
@ eBothDirections
No filtering: use both direct and reverse sequences.
@ eDirect
Use only sequences whose strand is the same as that of the anchor.
@ fAnchorRowFirst
Store anchor row in the first pairwise alignment (by default it's stored in the last one).
@ fIgnoreInsertions
Do not collect and store insertions (gaps on the anchor).
Query-anchored alignment can be 2 or multi-dimentional.
const TPairwiseAlnVector & GetPairwiseAlns(void) const
The vector of pairwise alns.
vector< CRef< CPairwiseAln > > TPairwiseAlnVector
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?
void SetDim(TDim dim)
Modify the number of rows.
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.
container_type::const_iterator const_iterator
const_iterator find(const key_type &key) const
Include a standard set of the NCBI C++ Toolkit most basic headers.
CSeq_align::C_Segs::TDendiag TDendiag
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
#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.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
#define NCBI_XALNMGR_EXPORT
bool IsStd(void) const
Check if variant Std is selected.
const TSegs & GetSegs(void) const
Get the Segs member data.
constexpr bool empty(list< Ts... >) noexcept
const struct ncbi::grid::netcache::search::fields::SIZE size
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
vector< CRef< CAnchoredAln > > TAnchoredAlnVec
Collection of anchored alignments.
#define row(bind, expected)