aln_table.cpp

来自「ncbi源码」· C++ 代码 · 共 243 行

CPP
243
字号
/* * =========================================================================== * PRODUCTION $Log: aln_table.cpp,v $ * PRODUCTION Revision 1000.1  2004/06/01 21:07:51  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.6 * PRODUCTION * =========================================================================== *//*  $Id: aln_table.cpp,v 1000.1 2004/06/01 21:07:51 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. * * =========================================================================== * * Authors:  Mike DiCuccio * * File Description: * */#include <ncbi_pch.hpp>#include <gui/widgets/aln_table/aln_table.hpp>#include <gui/objutils/utils.hpp>#include <gui/objutils/label.hpp>#include <serial/iterator.hpp>#include <objects/seqalign/Score.hpp>#include <objects/general/Object_id.hpp>#include <serial/iterator.hpp>BEGIN_NCBI_SCOPEUSING_SCOPE(objects);CAlnTableWidget::CAlnTableWidget(int x, int y, int w, int h,                                 const char* label)    : CTablePanel<SAlnProxy>(x, y, w, h, label){    SetColumn(eLabel,   "Alignment", eString,  FL_ALIGN_LEFT, 1.0f);    SetColumn(eType,    "Type",      eString,  FL_ALIGN_LEFT, 0.2f);    SetColumn(eNumSeqs, "Sequences", eNumeric, FL_ALIGN_LEFT, 0.2f);    SetCellBox(FL_BORDER_FRAME);}void CAlnTableWidget::Add(CScope& scope, const CSeq_align& aln){    if (m_DataSource) {        m_DataSource->Add(scope, aln);    }}void CAlnTableWidget::SetDataSource(CAlnTableDS& ds){    m_DataSource.Reset(&ds);    Update();}void CAlnTableWidget::Update(){    Clear();    if ( !m_DataSource ) {        return;    }    const CAlnTableDS::TAlignments& aligns = m_DataSource->GetAlignments();    SetRows(aligns.size());    size_t idx = 0;    ITERATE (CAlnTableDS::TAlignments, iter, aligns) {        const CSeq_align& al    = *iter->align;        CScope&           scope = *iter->scope;        SetData(idx, *iter);        if (al.IsSetScore()) {            ITERATE (CSeq_align::TScore, score_iter, al.GetScore()) {                const CScore& score = **score_iter;                string str;                if (score.GetId().IsStr()) {                    str = score.GetId().GetStr();                } else {                    str = NStr::IntToString(score.GetId().GetId());                }                TColNames::iterator col_iter = m_Cols.find(str);                if (col_iter == m_Cols.end()) {                    m_Cols[str] = eScoreStart + m_Cols.size();                    col_iter = m_Cols.find(str);                    SetColumn(col_iter->second, str, eNumeric,                              FL_ALIGN_RIGHT, 0.2f);                }                string& val = SetCell(idx, col_iter->second);                if (score.GetValue().IsInt()) {                    val = NStr::IntToString(score.GetValue().GetInt());                } else {                    val = NStr::DoubleToString(score.GetValue().GetReal());                }            }        }        // set our label        string label;        x_GetAlnLabel(*iter, label);        SetCell(idx, eLabel, label);        // set the alignment type        switch (iter->align->GetSegs().Which()) {        case CSeq_align::TSegs::e_not_set:            SetCell(idx, eType, "unknown");            break;        case CSeq_align::TSegs::e_Denseg:            SetCell(idx, eType, "dense-seg");            break;        case CSeq_align::TSegs::e_Dendiag:            SetCell(idx, eType, "dense-diag");            break;        case CSeq_align::TSegs::e_Std:            SetCell(idx, eType, "std-seg");            break;        case CSeq_align::TSegs::e_Packed:            SetCell(idx, eType, "packed-seg");            break;        case CSeq_align::TSegs::e_Disc:            SetCell(idx, eType, "discontinuous");            break;        }        // set the number of sequences in our alignment        SetCell(idx, eNumSeqs, NStr::IntToString(x_GetNumSeqs(*iter)));        // set our score columns        ++idx;    }}void CAlnTableWidget::GetSelections(TConstScopedObjects& objs) const{    objs.clear();    for (size_t i = 0;  i < GetRows();  ++i) {        if ( !IsRowSelected(i) ) {            continue;        }        const SAlnProxy& aln = GetData(i);        objs.push_back(SConstScopedObject(*aln.align, *aln.scope));    }}void CAlnTableWidget::SetSelections(const TConstScopedObjects& objs){}void CAlnTableWidget::x_GetAlnLabel(const SAlnProxy& proxy, string& label){    CLabel::GetLabel(*proxy.align, &label, CLabel::eDefault, proxy.scope);}struct SSortByIdRef {    bool operator() (const CConstRef<CSeq_id>& id1,                     const CConstRef<CSeq_id>& id2) const    {        return (*id1 < *id2);    }};size_t CAlnTableWidget::x_GetNumSeqs(const SAlnProxy& proxy){    set< CConstRef<CSeq_id>, SSortByIdRef> id_set;    CTypeConstIterator<CSeq_id> id_iter(*proxy.align);    for ( ;  id_iter;  ++id_iter) {        id_set.insert( CConstRef<CSeq_id>(&*id_iter) );    }    return id_set.size();}END_NCBI_SCOPE/* * =========================================================================== * $Log: aln_table.cpp,v $ * Revision 1000.1  2004/06/01 21:07:51  gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.6 * * Revision 1.6  2004/05/21 22:27:52  gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.5  2004/05/20 12:41:46  dicuccio * Added include for serial/iterator.hpp * * Revision 1.4  2004/05/15 03:17:05  ucko * Add missing #includes (formerly indirect?) * * Revision 1.3  2004/05/07 15:36:16  dicuccio * Use CLabel instead of CSeqUtils::GetLabel() * * Revision 1.2  2004/05/03 13:23:57  dicuccio * gui/utils --> gui/objutils where needed * * Revision 1.1  2004/04/16 15:56:16  dicuccio * Initial revision * * =========================================================================== */

⌨️ 快捷键说明

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