default_policy.cpp

来自「ncbi源码」· C++ 代码 · 共 1,851 行 · 第 1/5 页

CPP
1,851
字号
/* * =========================================================================== * PRODUCTION $Log: default_policy.cpp,v $ * PRODUCTION Revision 1000.3  2004/06/01 21:12:33  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.41 * PRODUCTION * =========================================================================== *//*  $Id: default_policy.cpp,v 1000.3 2004/06/01 21:12:33 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:  Vlad Lebedev * * File Description: * */#include <ncbi_pch.hpp>#include <corelib/ncbistd.hpp>#include <gui/widgets/seq_graphic/default_policy.hpp>#include <gui/objutils/label.hpp>#include <objects/seqfeat/Cdregion.hpp>#include <objects/seqfeat/Gb_qual.hpp>#include <objects/seqfeat/Imp_feat.hpp>#include <objects/seqres/Byte_graph.hpp>#include <objects/seqres/Int_graph.hpp>#include <objects/seqres/Real_graph.hpp>#include <gui/config/feat_config_list.hpp>#include <objmgr/scope.hpp>#include <objmgr/util/feature.hpp>#include <objmgr/util/sequence.hpp>#include <objtools/alnmgr/alnmix.hpp>#include <serial/iterator.hpp>#include <util/sequtil/sequtil_manip.hpp>BEGIN_NCBI_SCOPEUSING_SCOPE(objects);// temporary, until a method for fast// retrieving of annotations is availablestatic const int	 kSeqAnnotCount      =  20;// size of an alignment rowstatic const int kAlnRowHeight       =  13;// size of a single row in alignmentstatic const int kAlnElementHeight   =  3;// size of a single row in alignmentstatic const int kPWAlignHeight =  6;// width of a column smallstatic const int kLabelsColWidth     = 100;// width of a feature label smallstatic const int kLabelsMaxWidth     = 90;// at this point sequence will fitstatic const TModelUnit kPixPerBase4Sequence = 8.0f;TModelUnit kCommentFontSize = 0.0f;// 3 pixels befween layout objectsstatic const TModelUnit kSpacerSize   = 3.0f;// Max number of unique library IDs for mate pairsstatic const float kMaxLibraryIDCount = 8.0f; CDefaultPolicy::CDefaultPolicy()    : m_Font_Bitmap9x15(CGlBitmapFont::eBitmap9x15),      m_Font_Helv10(CGlBitmapFont::eHelvetica10),      m_Font_Helv8(CGlBitmapFont::eHelvetica8){    m_MinLabelWidth  = TVPUnit(m_Font_Helv10.TextWidth("AA"));    m_ColorTable     = CGlColorTable(kSeqAnnotCount, 0.5f, 0.75f);            kCommentFontSize = m_Font_Helv10.TextHeight();}void CDefaultPolicy::SetHandle(const CBioseq_Handle& handle){    m_Handle = handle;    m_Annots.clear();}void CDefaultPolicy::SetConfig(CSeqGraphicConfig* config){    m_ConfigSettings = config;}void CDefaultPolicy::SetHitPoint(TModelPoint click){    m_LastClick = click;}void CDefaultPolicy::SetActiveArea(TAreaVector* p_area){    m_ActiveAreas = p_area;}    // retrieve a set of labels for a given featurevoid CDefaultPolicy::x_GetLabels(const CSeq_feat& feat,                                 CScope& scope,                                 string* label_type,                                 string* label_content,                                 string* label_both) const{    if (feat.IsSetProduct()) {        CLabel::GetLabel(feat.GetProduct(), label_both,                         CLabel::eDefault, &scope);        *label_both += ": ";        *label_type    = *label_both;        *label_content = *label_both;        feature::GetLabel(feat, label_both,    feature::eContent, &scope);        feature::GetLabel(feat, label_type,    feature::eType,    &scope);        feature::GetLabel(feat, label_content, feature::eContent, &scope);    } else {        feature::GetLabel(feat, label_both,    feature::eBoth,    &scope);        feature::GetLabel(feat, label_type,    feature::eType,    &scope);        feature::GetLabel(feat, label_content, feature::eContent, &scope);    }}void CDefaultPolicy::x_SetFeatureColor(const CLayoutFeat* feat) const{    CGlColor color;    if (dynamic_cast<const CLayoutProtProd*>(feat)) {        color = m_ConfigSettings->GetElementColor(CSeqGraphicColorConfig::eFG_ProtProduct);    } else {        const CSeqFeatData& data = feat->GetFeature().GetData();        color = m_ConfigSettings->GetColor(data.Which(), data.GetSubtype());    }    glColor4f(color.GetRed(), color.GetGreen(), color.GetBlue(), 0.65f);}void CDefaultPolicy::x_DrawAlignmentSmear(CGlPane& pane, const CLayoutAlignSmear* layout_smear,                 GLfloat row_y, EObj_IterMode mode, bool selected) const{    const TModelRect& rcV = pane.GetVisibleRect();    const TModelRect& rcM = pane.GetModelLimitsRect();    const CAlignmentSmear& smear = layout_smear->GetAlignSmear();    TModelUnit offsetX = pane.GetOffsetX();    TModelUnit offsetY = pane.GetOffsetY();    GLfloat th = m_Font_Helv10.TextHeight();    GLfloat title_y  = row_y + th + 1;    GLfloat line_y1  = title_y + 3;    GLfloat line_y2  = line_y1 + th + 2;    GLfloat line_ym  = line_y1 + (th + 2) / 2;    GLfloat strand_y = line_y1 + th;    GLfloat off      = rcM.Top() > 0 ? th - 1 : 0;    CGlColor    minColor("lightblue1"), maxColor("dark blue");    switch (mode) {    default:        break;    case eDrawObjectLines:        {{            CAlignmentSmear::runlen_iterator gap_it = smear.SmearGapBegin();            for (; gap_it; gap_it.Advance()) {                float   value = gap_it.GetValue();                if (value == 0)                    continue;                                glColor4f(maxColor.GetRed(), maxColor.GetGreen(), maxColor.GetBlue(), 1.0f);                TModelUnit f = gap_it.GetSeqPosition();                TModelUnit t = f + gap_it.GetSeqRunLength();                glVertex2f(f - offsetX, line_ym - offsetY);                glVertex2f(t - offsetX, line_ym - offsetY);             }                       }}        break;            case eDrawObjectQuads:        {{            CAlignmentSmear::runlen_iterator seg_it = smear.SmearSegBegin();            for (; seg_it; seg_it.Advance()) {                float   value = seg_it.GetValue();                if (value == 0)                    continue;                                // set color of segment.                float   score = value/smear.GetMaxValue();                // CGlColor(1.0f-score, 1.0f-score, 1.0f-score); // shades of grey.                // glColor4f(1.0f-score, 1.0f-score, 1.0f-score, 0.65);                CRgbaColor color(CRgbaColor::Interpolate(maxColor, minColor, score));                glColor4f(color.GetRed(), color.GetGreen(), color.GetBlue(), 1.0f);                                // draw segment                TModelUnit f = seg_it.GetSeqPosition();                TModelUnit t = f + seg_it.GetSeqRunLength();                glVertex2f(f - offsetX, line_y1 - offsetY);                glVertex2f(f - offsetX, line_y2 - offsetY);                glVertex2f(t - offsetX, line_y2 - offsetY);                glVertex2f(t - offsetX, line_y1 - offsetY);            }         }}        break;    case eDrawObjectLabel:        {{            string as_label = smear.GetLabel();                  if (selected) {                x_Color(CSeqGraphicColorConfig::eSelLabel_AlignSmear);            } else {                x_Color(CSeqGraphicColorConfig::eLabel_AlignSmear);            }                    m_Font_Helv10.TextOut(rcV.Left() - offsetX + 3, title_y - off - offsetY, as_label.c_str());            // draw strand indicator if needed.            if (smear.GetStrandType() != CAlignmentSmear::eSmearStrand_Both) {                bool neg_strand = smear.GetStrandType() == CAlignmentSmear::eSmearStrand_Neg;                            glColor3f(0.0f, 0.0f, 0.0f);  // Black                            m_Font_Helv10.TextOut(rcV.Left() - offsetX + 3, strand_y - off - offsetY, neg_strand ? "<" : ">");            }        }}        break;    }    }void CDefaultPolicy::x_DrawAlignment(CGlPane& pane, const CLayoutAlign* align,                     GLfloat row_y, EObj_IterMode mode, bool selected) const{    const TModelRect& rcV = pane.GetVisibleRect();    const CAlnVec& aln_mgr = align->GetAlignMgr();    TModelUnit offsetX = pane.GetOffsetX();    TModelUnit offsetY = pane.GetOffsetY();    TSeqPos from = align->GetLocation().GetTotalRange().GetFrom();    TSeqPos to   = align->GetLocation().GetTotalRange().GetTo();    TModelRect frc;    frc.SetLeft(from);    frc.SetRight(to);    TModelRect inrc = frc.IntersectWith(rcV);    GLfloat scaleX = pane.GetScaleX();    GLfloat yy  = row_y + m_Font_Helv10.TextHeight() + 4;    GLfloat aln_height = x_CalcAlignHeight(align);    switch (mode) {    default:        break;    case eDrawObjectLines:        {{            x_Color(CSeqGraphicColorConfig::eFG_Alignment);            CAlnMap::TNumrow anchor = aln_mgr.GetAnchor();            TSeqPos start = aln_mgr.GetSeqStart(anchor);            TSeqPos stop  = aln_mgr.GetSeqStop (anchor);            CAlnMap::TNumrow row = 0;            for (row = 0;  row < aln_mgr.GetNumRows();  ++row) {                if (row == anchor) {                    continue;  // skip master seq                }                glVertex2f(start - offsetX,     yy - offsetY + kAlnElementHeight * 0.5f);                glVertex2f(stop  - offsetX + 1, yy - offsetY + kAlnElementHeight * 0.5f);                // advance to next row: 1 pixel between                yy += kAlnElementHeight + 1;            }        }}        // Draw selection        if (selected) {            x_Color(CSeqGraphicColorConfig::eSelection_Alignment);            x_DrawSelection(pane, from, row_y, to, row_y + aln_height);        }        break;    case eDrawObjectQuads:        {{            x_Color(CSeqGraphicColorConfig::eFG_Alignment);             CAlnMap::TNumrow row = 0;             const CAlnMap::TNumrow anchor = aln_mgr.GetAnchor();             TSignedSeqRange range(aln_mgr.GetAlnStart(),                                   aln_mgr.GetAlnStop());             for ( ;  row < aln_mgr.GetNumRows();  ++row) {                 if (row == anchor) {                     continue;  // skip master seq                 }                 CRef<CAlnVec::CAlnChunkVec> aln_chunks                     (aln_mgr.GetAlnChunks(row, range,                                           CAlnVec::fSeqOnly |                                           CAlnVec::fChunkSameAsSeg));                 for (int i = 0;  i < aln_chunks->size();  ++i) {                     CConstRef<CAlnVec::CAlnChunk> chunk((*aln_chunks)[i]);                     TSeqPos start = chunk->GetRange().GetFrom();                     start = aln_mgr.GetSeqPosFromSeqPos(anchor, row, start);                     TSeqPos stop = chunk->GetRange().GetTo();                     stop = aln_mgr.GetSeqPosFromSeqPos(anchor, row, stop);                     if (start > stop) {                         swap(start, stop);                     }                     glVertex2f(start - offsetX,     yy - offsetY);                     glVertex2f(stop  - offsetX + 1, yy - offsetY);                     glVertex2f(stop  - offsetX + 1,                                yy + kAlnElementHeight - offsetY);                     glVertex2f(start - offsetX,                                yy + kAlnElementHeight - offsetY);                 }                 // advance to next row: 1 pixel between                 yy += kAlnElementHeight + 1;             }        }}        break;

⌨️ 快捷键说明

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