⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dense_seg.cpp

📁 ncbi源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* * =========================================================================== * PRODUCTION $Log: Dense_seg.cpp,v $ * PRODUCTION Revision 1000.4  2004/06/01 19:33:35  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.13 * PRODUCTION * =========================================================================== *//* $Id: Dense_seg.cpp,v 1000.4 2004/06/01 19:33:35 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 <algorithm>#include <objects/seqalign/seqalign_exception.hpp>// generated includes#include <objects/seqalign/Dense_seg.hpp>#include <objects/seqloc/Seq_id.hpp>#include <objects/seqloc/Seq_loc.hpp>// generated classesBEGIN_NCBI_SCOPEBEGIN_objects_SCOPE // namespace ncbi::objects::// destructorCDense_seg::~CDense_seg(void){}CDense_seg::TNumseg CDense_seg::CheckNumSegs() const{    const CDense_seg::TStarts&  starts  = GetStarts();    const CDense_seg::TStrands& strands = GetStrands();    const CDense_seg::TLens&    lens    = GetLens();    const CDense_seg::TWidths&  widths  = GetWidths();    const size_t& numrows = GetDim();    const size_t& numsegs = GetNumseg();    const size_t  num     = numrows * numsegs;    if (starts.size() != num) {        string errstr = string("CDense_seg::CheckNumSegs():")            + " starts.size is inconsistent with dim * numseg";        NCBI_THROW(CSeqalignException, eInvalidAlignment, errstr);    }    if (lens.size() != numsegs) {        string errstr = string("CDense_seg::CheckNumSegs():")            + " lens.size is inconsistent with numseg";        NCBI_THROW(CSeqalignException, eInvalidAlignment, errstr);    }    if (strands.size()  &&  strands.size() != num) {        string errstr = string("CDense_seg::CheckNumSegs():")            + " strands.size is inconsistent with dim * numseg";        NCBI_THROW(CSeqalignException, eInvalidAlignment, errstr);    }    if (widths.size()  &&  widths.size() != numrows) {        string errstr = string("CDense_seg::CheckNumSegs():")            + " widths.size is inconsistent with dim";        NCBI_THROW(CSeqalignException, eInvalidAlignment, errstr);    }    return numsegs;}TSeqPos CDense_seg::GetSeqStart(TDim row) const{    const TDim&    dim    = GetDim();    const TNumseg& numseg = CheckNumSegs();    const TStarts& starts = GetStarts();    if (row < 0  ||  row >= dim) {        NCBI_THROW(CSeqalignException, eInvalidRowNumber,                   "CDense_seg::GetSeqStop():"                   " Invalid row number");    }    TSignedSeqPos start;    if (CanGetStrands()  &&  GetStrands().size()  &&  GetStrands()[row] == eNa_strand_minus) {        TNumseg seg = numseg;        int pos = (seg - 1) * dim + row;        while (seg--) {            if ((start = starts[pos]) >= 0) {                return start;            }            pos -= dim;        }    } else {        TNumseg seg = -1;        int pos = row;        while (++seg < numseg) {            if ((start = starts[pos]) >= 0) {                return start;            }            pos += dim;        }    }    NCBI_THROW(CSeqalignException, eInvalidAlignment,               "CDense_seg::GetSeqStart(): Row is empty");}TSeqPos CDense_seg::GetSeqStop(TDim row) const{    const TDim& dim       = GetDim();    const TNumseg& numseg = CheckNumSegs();    const TStarts& starts = GetStarts();    if (row < 0  ||  row >= dim) {        NCBI_THROW(CSeqalignException, eInvalidRowNumber,                   "CDense_seg::GetSeqStop():"                   " Invalid row number");    }    TSignedSeqPos start;    if (CanGetStrands()  &&  GetStrands().size()  &&  GetStrands()[row] == eNa_strand_minus) {        TNumseg seg = -1;        int pos = row;        while (++seg < numseg) {            if ((start = starts[pos]) >= 0) {                return start + GetLens()[seg] - 1;            }            pos += dim;        }    } else {        TNumseg seg = numseg;        int pos = (seg - 1) * dim + row;        while (seg--) {            if ((start = starts[pos]) >= 0) {                return start + GetLens()[seg] - 1;            }            pos -= dim;        }            }    NCBI_THROW(CSeqalignException, eInvalidAlignment,               "CDense_seg::GetSeqStop(): Row is empty");}void CDense_seg::Validate(bool full_test) const{    const CDense_seg::TStarts&  starts  = GetStarts();    const CDense_seg::TStrands& strands = GetStrands();    const CDense_seg::TLens&    lens    = GetLens();    const CDense_seg::TWidths&  widths  = GetWidths();    const size_t& numrows = CheckNumRows();    const size_t& numsegs = CheckNumSegs();    if (full_test) {        const size_t  max     = numrows * (numsegs -1);        bool strands_exist = !strands.empty();        size_t numseg = 0, numrow = 0, offset = 0;        for (numrow = 0;  numrow < numrows;  numrow++) {            TSignedSeqPos min_start = -1, start;            bool plus = strands_exist ?                 strands[numrow] != eNa_strand_minus:                true;                        if (plus) {                offset = 0;            } else {                offset = max;            }                        for (numseg = 0;  numseg < numsegs;  numseg++) {                start = starts[offset + numrow];                if (start >= 0) {                    if (start < min_start) {                        string errstr = string("CDense_seg::Validate():")                            + " Starts are not consistent!"                            + " Row=" + NStr::IntToString(numrow) +                            " Seg=" + NStr::IntToString(plus ? numseg :                                                        numsegs - 1 - numseg) +                            " MinStart=" + NStr::IntToString(min_start) +                            " Start=" + NStr::IntToString(start);                                                NCBI_THROW(CSeqalignException, eInvalidAlignment,                                   errstr);                    }                    min_start = start +                         lens[plus ? numseg : numsegs - 1 - numseg] *                        (widths.size() == numrows ?                         widths[numrow] : 1);                }                if (plus) {                    offset += numrows;                } else {                    offset -= numrows;                }            }        }    }}//-----------------------------------------------------------------------------// PRE : none// POST: same alignment, opposite orientationvoid CDense_seg::Reverse(void){    //flip strands    NON_CONST_ITERATE (CDense_seg::TStrands, i, SetStrands()) {        switch (*i) {        case eNa_strand_plus:  *i = eNa_strand_minus; break;        case eNa_strand_minus: *i = eNa_strand_plus;  break;        default:                    break;//do nothing if not + or -        }    }    //reverse list o' lengths    {        CDense_seg::TLens::iterator f = SetLens().begin();        CDense_seg::TLens::iterator r = SetLens().end();        while (f < r) {            swap(*(f++), *(--r));        }    }    //reverse list o' starts    CDense_seg::TStarts &starts = SetStarts();    int f = 0;    int r = (GetNumseg() - 1) * GetDim();    while (f < r) {        for (int i = 0;  i < GetDim();  ++i) {            swap(starts[f+i], starts[r+i]);        }        f += GetDim();        r -= GetDim();    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -