feat_table.cpp

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

CPP
469
字号
/* * =========================================================================== * PRODUCTION $Log: feat_table.cpp,v $ * PRODUCTION Revision 1000.3  2004/06/01 21:00:30  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.34 * PRODUCTION * =========================================================================== *//*  $Id: feat_table.cpp,v 1000.3 2004/06/01 21:00:30 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: *    CFeatTable -- extends CListPanel to provide feature-specific options. */#include <ncbi_pch.hpp>#include "feat_table.hpp"#include <gui/utils/fltk_utils.hpp>#include <gui/objutils/utils.hpp>#include <objmgr/feat_ci.hpp>#include <objects/seqloc/Seq_bond.hpp>#include <objects/seqloc/Seq_interval.hpp>#include <objects/seqloc/Seq_loc.hpp>#include <objects/seqloc/Seq_loc_equiv.hpp>#include <objects/seqloc/Seq_point.hpp>#include <objmgr/util/feature.hpp>#include <objmgr/util/sequence.hpp>#include <FL/fl_draw.H>BEGIN_NCBI_SCOPECFeatTable::CFeatTable(int x, int y, int w, int h, const char* label)    : CTablePanel<CMappedFeat>(x, y, w, h, label){    //    // set up the actual columns for our internal data    //    SetColumn(eTitle,     "Title",     eString,  FL_ALIGN_LEFT,  0.5f);    SetColumn(eType,      "Type",      eString,  FL_ALIGN_LEFT,  0.15f);    SetColumn(eFrom,      "From",      eNumeric, FL_ALIGN_RIGHT, 0.1f);    SetColumn(eTo,        "To",        eNumeric, FL_ALIGN_RIGHT, 0.1f);    //SetColumn(eIntervals, "Intervals", eString,  FL_ALIGN_LEFT,  0.5f);    SetColumn(eStrand,    "Strand",    eString,  FL_ALIGN_LEFT,  0.1f);    // also set up the column types in our set of filters    m_Filters.SetColType(eTitle,     CFilter::eString);    m_Filters.SetColType(eType,      CFilter::eString);    m_Filters.SetColType(eFrom,      CFilter::eNumeric);    m_Filters.SetColType(eTo,        CFilter::eNumeric);    //m_Filters.SetColType(eIntervals, CFilter::eString);    m_Filters.SetColType(eStrand,    CFilter::eString);    // set the default visible range method    m_VisibleRangeMethod = eScrollTo;    /**    // set the default virtual columns    // this defines the order in which all the columns appear    m_VirtCols.push_back(eTitle);    m_VirtCols.push_back(eType);    m_VirtCols.push_back(eFrom);    m_VirtCols.push_back(eTo);    **/}CFeatTable::~CFeatTable(){}void CFeatTable::Update(const CBioseq_Handle& handle){    Clear();    //    // here, we just iterate all features and sort out the types ourselves    //    CLayoutFeat::TFeatList feats;    CSeqUtils::GetFeatures(handle, TSeqRange(0, 0),                           CSeqFeatData::e_not_set, feats);    int row = 0;    m_TotalFeats = 0;    m_FilteredFeats = 0;    m_InvFeats.clear();    vector<TSeqRange> intervals;    Reserve(feats.size(), eMaxCols);    ITERATE (CLayoutFeat::TFeatList, feat_iter, feats) {        const CLayoutFeat& feat = **feat_iter;        const CSeq_loc& loc  = feat.GetLocation();        // record the range of this feature        CRange<TSeqPos> range = loc.GetTotalRange();        // Check if in visible range for the entirely         //  contained and intersection methods        if (!x_InVisibleRange(range)) {            continue;        }        SetCell(row, eFrom, NStr::IntToString(range.GetFrom()));        SetCell(row, eTo,   NStr::IntToString(range.GetTo()));        SetCell(row, eType).erase();        SetCell(row, eTitle).erase();        feature::GetLabel(feat.GetFeature(),                          &SetCell(row, eType), feature::eType);        feature::GetLabel(feat.GetFeature(),                          &SetCell(row, eTitle), feature::eContent,                          &handle.GetScope());        switch (sequence::GetStrand(loc)) {        case eNa_strand_unknown:            SetCell(row, eStrand, "?");            break;        case eNa_strand_plus:            SetCell(row, eStrand, "+");            break;        case eNa_strand_minus:            SetCell(row, eStrand, "-");            break;        case eNa_strand_both:            SetCell(row, eStrand, "+-");            break;        case eNa_strand_both_rev:            SetCell(row, eStrand, "+- (rev)");            break;        case eNa_strand_other:            SetCell(row, eStrand, "other");            break;        }        /**        // extract a list of intervals from this feature        intervals = feat.GetIntervals();        string str;        ITERATE (vector<TSeqRange>, r_iter, intervals) {            if ( !str.empty() ) {                str += ", ";            }            str += NStr::IntToString(r_iter->GetFrom());            str += "..";            str += NStr::IntToString(r_iter->GetTo());        }        SetCell(row, eIntervals) = str;        **/        // filter this row        ++m_TotalFeats;        if (!m_Filters.Filter(GetRow(row))) {            continue;        }        ++m_FilteredFeats;        SetData(row) = feat.GetMappedFeature();        CConstRef<CSeq_feat> ref(&feat.GetMappedFeature().GetOriginalFeature());        m_InvFeats[ref] = row;        ++row;    }    // Check if Visible Range Scroll To method is set    if (m_VisibleRangeMethod == eScrollTo) {        x_ScrollToVisibleRange();    }    redraw();}void CFeatTable::ClearSelections(){    select_all_rows(0);}void CFeatTable::SelectFeature(const CSeq_feat& feat){    TInvFeatMap::iterator iter = m_InvFeats.find(CConstRef<CSeq_feat>(&feat));    if (iter == m_InvFeats.end()) {        return;    }    int idx = iter->second;    select_row(idx);}void CFeatTable::SetVisibleRange(const CSeq_loc& loc){    m_VisibleRange = loc.GetTotalRange();}int CFeatTable::handle(int event){    switch (event) {    case FL_PUSH:        // we ignore events bound to our internal popup state        // this removes an artifact with selection mode - it protects our        // selections when we popup our context menu        if (CFltkEvent::GetProcessedEvent() != CFltkEvent::ePopupState) {            break;        }        //ShowColSelectDlg();        return 1;    default:        break;    }    return CTablePanel< CMappedFeat >::handle(event);}bool CFeatTable::x_InVisibleRange(TSeqRange range) {    if (m_VisibleRange.Empty()) {        return true;    }    switch (m_VisibleRangeMethod) {        case eEntirelyContained:            if (range.GetFrom() < m_VisibleRange.GetFrom() ||                    range.GetTo()   > m_VisibleRange.GetTo()) {                return false;            }            break;        case eIntersection:            if (range.GetTo() < m_VisibleRange.GetFrom() ||                    range.GetFrom() > m_VisibleRange.GetTo()) {                return false;            }            break;    }    return true;}void CFeatTable::x_ScrollToVisibleRange(){        if (m_VisibleRange.Empty()) {        return;    }    size_t table_from =         NStr::StringToInt(GetCell(row_position(), eFrom));    if (table_from < m_VisibleRange.GetFrom()) {        x_ScrollDownToVisibleRange();    } else if (table_from > m_VisibleRange.GetFrom()) {        x_ScrollUpToVisibleRange();    }}void CFeatTable::x_ScrollDownToVisibleRange(){    for (size_t i = row_position() + 1;  i < GetRows();  i++) {        size_t table_from = NStr::StringToInt(GetCell(i, eFrom));        if (table_from >= m_VisibleRange.GetFrom()) {            row_position(i);            return;        }    }     // set to last row    row_position(GetRows() - 1);}void CFeatTable::x_ScrollUpToVisibleRange(){    for (int i = row_position() - 1; i >= 0; i--) {        size_t table_from = NStr::StringToInt(GetCell(i, eFrom));        if (table_from < m_VisibleRange.GetFrom()) {            row_position(i + 1);            return;        }    }     // set to first row    row_position(0);}/**void CFeatTable::get_style(Flv_Style& s, int row, int col){    // do our base class stuff    CListPanel< CMappedFeat >::get_style(s, row, col);    if ( row >= 0  &&  (row / 5) % 2 == 1  &&  !row_selected(row)) {        s.background(fl_rgb_color(220, 220, 220));    }}**/END_NCBI_SCOPE/* * =========================================================================== * $Log: feat_table.cpp,v $ * Revision 1000.3  2004/06/01 21:00:30  gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.34 * * Revision 1.34  2004/05/21 22:27:49  gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.33  2004/05/07 15:35:37  dicuccio * Fixed unsigned/signed comparison * * Revision 1.32  2004/05/03 13:30:49  dicuccio * gui/utils --> gui/objutils where needed * * Revision 1.31  2004/03/11 17:47:22  dicuccio * Use TSeqRange instead of TRange * * Revision 1.30  2004/01/20 18:17:52  dicuccio * Changed to match new API in CTablePanel * * Revision 1.29  2004/01/06 20:16:19  dicuccio * Dropped intervals list (temporarily) - it crowds the view * * Revision 1.28  2003/12/30 15:03:54  dicuccio * Added ability to pass selections into feature table * * Revision 1.27  2003/12/22 19:32:23  dicuccio * Lots of code clean-up.  Changed to match new APIs in IView.  Added first pass * at processing selections (not entirely working) * * Revision 1.26  2003/12/22 18:15:07  friedman * Added various visible range methods and the selection of a method * through the preference menu selection and dialog. * * Revision 1.25  2003/12/04 18:14:47  dicuccio * Changed to match API change in CTablePanel * * Revision 1.24  2003/11/19 20:45:28  friedman * Added handling a visible range change event * * Revision 1.23  2003/09/29 15:41:09  dicuccio * Deprecated gui/scope.hpp.  Merged gui/core/types.hpp into gui/types.hpp.  Made * all menu bars flat (used FL_FLAT_BOX) * * Revision 1.22  2003/09/04 14:54:23  dicuccio * Use IDocument instead of CDocument.  Changed APIs to match changes in IView * * Revision 1.21  2003/08/18 14:45:50  dicuccio * Changed nales: CFeature -> CLayoutFeat; CAlignment -> CLayoutAlign; CGraph -> * CLayoutGraph; CProtProduct -> CLayoutProtProd. * * Revision 1.20  2003/07/31 17:04:34  dicuccio * Changed type stored by feature table view - use CMappedFeat instead of CFeatue * (less memory consumption) * * Revision 1.19  2003/07/28 11:51:49  dicuccio * Rewrote CTablePanel<> to be more flexible and better contained.  Added standard * multicolumn list dialog.  Deprecated use of COutputDlg. * * Revision 1.18  2003/07/25 13:44:48  dicuccio * Replaced Flv_Table with Fl_Table * * Revision 1.17  2003/07/11 12:38:45  dicuccio * Altered feature table to use smarter feature retrieval * * Revision 1.16  2003/06/02 16:06:24  dicuccio * Rearranged src/objects/ subtree.  This includes the following shifts: *     - src/objects/asn2asn --> arc/app/asn2asn *     - src/objects/testmedline --> src/objects/ncbimime/test *     - src/objects/objmgr --> src/objmgr *     - src/objects/util --> src/objmgr/util *     - src/objects/alnmgr --> src/objtools/alnmgr *     - src/objects/flat --> src/objtools/flat *     - src/objects/validator --> src/objtools/validator *     - src/objects/cddalignview --> src/objtools/cddalignview * In addition, libseq now includes six of the objects/seq... libs, and libmmdb * replaces the three libmmdb? libs. * * Revision 1.15  2003/05/19 13:46:51  dicuccio * Moved gui/core/plugin/ --> gui/plugin/.  Merged core libraries into * libgui_core.so * * Revision 1.14  2003/05/16 18:50:34  dicuccio * Added smarter retrieval of features * * Revision 1.13  2003/04/19 14:20:00  ucko * remaining occurrences of iterate -> ITERATE * * Revision 1.12  2003/03/21 17:13:59  dicuccio * Moved fltk_utils --> gui/utils * * Revision 1.11  2003/03/11 15:23:30  kuznets * iterate -> ITERATE * * Revision 1.10  2003/03/03 14:58:56  dicuccio * Changed to use visible range from the base class.  Added an explicit setter for * the visible range * * Revision 1.9  2003/02/20 19:50:00  dicuccio * Created new plugin architecture, based on ASN.1 spec.  Moved GBENCH frameowrk * over to use new plugin architecture. * * Revision 1.8  2003/02/10 18:54:59  dicuccio * Fixed compilation issues relating to changes in CFeat_CI API * * Revision 1.7  2003/01/17 21:08:58  dicuccio * Fill in feature strand value * * Revision 1.6  2003/01/13 13:10:09  dicuccio * Namespace clean-up.  Retired namespace gui -> converted all to namespace ncbi. * Moved all FLUID-generated code into namespace ncbi. * * Revision 1.5  2003/01/09 14:50:42  dicuccio * Use 'const CBioseq_Handle&' instead of 'CBioseq_Handle&' * * Revision 1.4  2003/01/08 14:58:47  dicuccio * Major overhaul.  Added column selection dialog to base class - moved out of * this class.  Added ability to sort columns based on menu selections.  Added * ability to filter features based on a wide range of criteria. * * Revision 1.3  2003/01/03 17:27:44  dicuccio * Added ability to select columns for viewing and sorting * * Revision 1.2  2002/12/30 20:51:10  dicuccio * W\Tweaks for compiling on Windows * * Revision 1.1  2002/12/30 18:49:41  dicuccio * Initial revision * * =========================================================================== */

⌨️ 快捷键说明

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