📄 seq_align.cpp
字号:
/* * =========================================================================== * PRODUCTION $Log: Seq_align.cpp,v $ * PRODUCTION Revision 1000.2 2004/06/01 19:33:39 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.16 * PRODUCTION * =========================================================================== *//* $Id: Seq_align.cpp,v 1000.2 2004/06/01 19:33:39 gouriano Exp $ * =========================================================================== * * PUBLIC DOMAIN NOTICE * National Center for Biotechnology Information * * This software/database is a "United States Government Work" under the * terms of the United States Copyright Act. It was written as part of * the author's official duties as a United States Government employee and * thus cannot be copyrighted. This software/database is freely available * to the public for use. The National Library of Medicine and the U.S. * Government have not placed any restriction on its use or reproduction. * * Although all reasonable efforts have been taken to ensure the accuracy * and reliability of the software and data, the NLM and the U.S. * Government do not and cannot warrant the performance or results that * may be obtained by using this software or data. The NLM and the U.S. * Government disclaim all warranties, express or implied, including * warranties of performance, merchantability or fitness for any particular * purpose. * * Please cite the author in any work or product based on this material. * * =========================================================================== * * Author: ....... * * File Description: * ....... * * Remark: * This code was originally generated by application DATATOOL * using specifications from the data definition file * 'seqalign.asn'. */// standard includes#include <ncbi_pch.hpp>#include <objects/seqalign/seqalign_exception.hpp>#include <objects/seqalign/Dense_seg.hpp>#include <objects/seqalign/Dense_diag.hpp>#include <objects/seqalign/Std_seg.hpp>#include <objects/seqalign/Seq_align_set.hpp>#include <objects/seqalign/Score.hpp>#include <objects/general/Object_id.hpp>#include <objects/seqloc/Seq_loc.hpp>#include <objects/seqloc/Seq_interval.hpp>#include <serial/iterator.hpp>// generated includes#include <objects/seqalign/Seq_align.hpp>// generated classesBEGIN_NCBI_SCOPEBEGIN_objects_SCOPE // namespace ncbi::objects::// destructorCSeq_align::~CSeq_align(void){}CSeq_align::TDim CSeq_align::CheckNumRows(void) const{ switch (GetSegs().Which()) { case C_Segs::e_Denseg: return GetSegs().GetDenseg().CheckNumRows(); case C_Segs::e_Std: { TDim numrows = 0; ITERATE (C_Segs::TStd, std_i, GetSegs().GetStd()) { const TDim& seg_numrows = (*std_i)->CheckNumRows(); if (numrows) { if (seg_numrows != numrows) { NCBI_THROW(CSeqalignException, eInvalidAlignment, "CSeq_align::CheckNumRows(): Number of rows " "is not the same for each std seg."); } } else { numrows = seg_numrows; } } return numrows; } default: NCBI_THROW(CSeqalignException, eUnsupported, "CSeq_align::CheckNumRows() currently does not handle " "this type of alignment"); }}CRange<TSeqPos> CSeq_align::GetSeqRange(TDim row) const{ switch (GetSegs().Which()) { case C_Segs::e_Denseg: return GetSegs().GetDenseg().GetSeqRange(row); case C_Segs::e_Std: { CRange<TSeqPos> rng; CSeq_id seq_id; size_t seg_i = 0; ITERATE (C_Segs::TStd, std_i, GetSegs().GetStd()) { TDim row_i = 0; ITERATE (CStd_seg::TLoc, i, (*std_i)->GetLoc()) { const CSeq_loc& loc = **i; if (row_i++ == row) { if (loc.IsInt()) { if ( !seg_i ) { seq_id.Assign(loc.GetInt().GetId()); } else if (seq_id.Compare(loc.GetInt().GetId()) != CSeq_id::e_YES) { NCBI_THROW(CSeqalignException, eInvalidRowNumber, "CSeq_align::GetSeqRange():" " Row seqids not consistent." " Cannot determine range."); } rng.CombineWith (CRange<TSeqPos> (loc.GetInt().GetFrom(), loc.GetInt().GetTo())); } } } if (row < 0 || row >= row_i) { NCBI_THROW(CSeqalignException, eInvalidRowNumber, "CSeq_align::GetSeqRange():" " Invalid row number"); } if (CanGetDim() && row_i != GetDim()) { NCBI_THROW(CSeqalignException, eInvalidAlignment, "CSeq_align::GetSeqRange():" " loc.size is inconsistent with dim"); } seg_i++; } if (rng.Empty()) { NCBI_THROW(CSeqalignException, eInvalidAlignment, "CSeq_align::GetSeqRange(): Row is empty"); } return rng; } default: NCBI_THROW(CSeqalignException, eUnsupported, "CSeq_align::GetSeqRange() currently does not handle " "this type of alignment."); }}TSeqPos CSeq_align::GetSeqStart(TDim row) const{ switch (GetSegs().Which()) { case C_Segs::e_Denseg: return GetSegs().GetDenseg().GetSeqStart(row); case C_Segs::e_Std: return GetSeqRange(row).GetFrom(); default: NCBI_THROW(CSeqalignException, eUnsupported, "CSeq_align::GetSeqStart() currently does not handle " "this type of alignment."); }}TSeqPos CSeq_align::GetSeqStop (TDim row) const{ switch (GetSegs().Which()) { case C_Segs::e_Denseg: return GetSegs().GetDenseg().GetSeqStop(row); case C_Segs::e_Std: return GetSeqRange(row).GetTo(); default: NCBI_THROW(CSeqalignException, eUnsupported, "CSeq_align::GetSeqStop() currently does not handle " "this type of alignment."); }}const CSeq_id& CSeq_align::GetSeq_id(TDim row) const{ switch (GetSegs().Which()) { case C_Segs::e_Denseg: { if ( GetSegs().GetDenseg().IsSetIds() && row < GetSegs().GetDenseg().GetIds().size()) { return *GetSegs().GetDenseg().GetIds()[row]; } break; } case C_Segs::e_Dendiag: { // If segments have different number of rows, this will try // to find the segment with enough rows to get the id. ITERATE(CSeq_align::C_Segs::TDendiag, seg, GetSegs().GetDendiag()) { if( (*seg)->IsSetIds() && row < (*seg)->GetIds().size() ) { return *(*seg)->GetIds()[row]; } } break; } case C_Segs::e_Std: { // If segments have different number of rows, this will try // to find the segment with enough rows to get the id. ITERATE(CSeq_align::C_Segs::TStd, seg, GetSegs().GetStd()) { if ( (*seg)->IsSetLoc() && row < (*seg)->GetLoc().size() ) { CSeq_loc_CI loc_iter(*(*seg)->GetLoc()[row]); return loc_iter.GetSeq_id(); } } break; } default: NCBI_THROW(CSeqalignException, eUnsupported, "CSeq_align::GetSeq_id() currently does not handle " "this type of alignment."); } NCBI_THROW(CSeqalignException, eInvalidRowNumber, "CSeq_align::GetSeq_id(): " "can not get seq-id for the row requested."); // return CSeq_id();}///---------------------------------------------------------------------------/// PRE : name of score to return/// POST: whether or not we found that score; score converted to intbool CSeq_align::GetNamedScore(const string &id, int &score) const{ if (IsSetScore()) { const TScore &scores = GetScore(); ITERATE (TScore, scoreI, scores) { if ((*scoreI)->IsSetId() && (*scoreI)->GetId().IsStr() && (*scoreI)->GetId().GetStr() == id) { if ((*scoreI)->GetValue().IsInt()) { score = (*scoreI)->GetValue().GetInt(); } else { score = (int) (*scoreI)->GetValue().GetReal(); } return true; } } } return false;}///---------------------------------------------------------------------------/// PRE : name of score to return/// POST: whether or not we found that score; score converted to doublebool CSeq_align::GetNamedScore(const string &id, double &score) const{ if (IsSetScore()) { const TScore &scores = GetScore(); ITERATE (TScore, scoreI, scores) { if ((*scoreI)->IsSetId() && (*scoreI)->GetId().IsStr() && (*scoreI)->GetId().GetStr() == id) { if ((*scoreI)->GetValue().IsInt()) { score = (double) (*scoreI)->GetValue().GetInt(); } else { score = (*scoreI)->GetValue().GetReal(); } return true; } } } return false;}void CSeq_align::Validate(bool full_test) const{ switch (GetSegs().Which()) { case C_Segs::e_Denseg: GetSegs().GetDenseg().Validate(full_test); break; case C_Segs::e_Std: CheckNumRows(); break; default: NCBI_THROW(CSeqalignException, eUnsupported, "CSeq_align::Validate() currently does not handle " "this type of alignment"); }}///---------------------------------------------------------------------------/// PRE : currently only implemented for dense-seg segments/// POST: same alignment, opposite orientationvoid CSeq_align::Reverse(void){ switch (GetSegs().Which()) { case C_Segs::e_Denseg: SetSegs().SetDenseg().Reverse(); break; default: NCBI_THROW(CSeqalignException, eUnsupported, "CSeq_align::Reverse() currently only handles dense-seg " "alignments"); }}///---------------------------------------------------------------------------/// PRE : currently only implemented for dense-seg segments; two row numbers/// POST: same alignment, position of the two rows has been swappedvoid CSeq_align::SwapRows(TDim row1, TDim row2){ switch (GetSegs().Which()) { case C_Segs::e_Denseg: SetSegs().SetDenseg().SwapRows(row1, row2); break; case C_Segs::e_Disc: SetSegs().SetDisc().SwapRows(row1, row2); break; default: NCBI_THROW(CSeqalignException, eUnsupported, "CSeq_align::SwapRows currently only handles dense-seg " "alignments"); }}///----------------------------------------------------------------------------/// PRE : the Seq-align has StdSeg segs/// POST: Seq_align of type Dense-seg is created with m_Widths if necessaryCRef<CSeq_align> CSeq_align::CreateDensegFromStdseg(SSeqIdChooser* SeqIdChooser) const{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -