genome_policy.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:14k
- /*
- * ===========================================================================
- * PRODUCTION $Log: genome_policy.cpp,v $
- * PRODUCTION Revision 1000.2 2004/06/01 21:12:41 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.10
- * PRODUCTION
- * ===========================================================================
- */
- /* $Id: genome_policy.cpp,v 1000.2 2004/06/01 21:12:41 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/genome_policy.hpp>
- #include <objmgr/util/sequence.hpp>
- #include <gui/objutils/label.hpp>
- BEGIN_NCBI_SCOPE
- USING_SCOPE(objects);
- //const TModelUnit kOneRowHeight = 6.0f;
- TModelUnit kGenomeSpacerSize = 3.0f; // 3 pixels befween layout objects
- CGenomePolicy::CGenomePolicy()
- {
- }
- //
- // draw a given feature in a given mode
- //
- void
- CGenomePolicy::x_DrawFeature(CGlPane& pane, const CLayoutFeat* feat,
- GLfloat row_y, EObj_IterMode mode, bool selected) const
- {
- const TModelRect& rcV = pane.GetVisibleRect();
- const TModelRect& rcM = pane.GetModelLimitsRect();
-
- TModelUnit offsetX = pane.GetOffsetX();
- TModelUnit offsetY = pane.GetOffsetY();
-
- TSeqPos from = feat->GetLocation().GetTotalRange().GetFrom();
- TSeqPos to = feat->GetLocation().GetTotalRange().GetTo();
-
- TModelRect frc;
- frc.SetLeft(from);
- frc.SetRight(to);
- TModelRect inrc = frc.IntersectWith(rcV);
-
- GLfloat th = m_Font_Helv8.TextHeight();
-
- GLfloat line_y1 = feat->IsHiddenLabel() ? row_y + 2 : row_y + th + 5;
- GLfloat line_y2 = line_y1 + 3;
- GLfloat line_ym = line_y1 + 1;
-
- GLfloat title_y = row_y + th + 2;
- GLfloat off = rcM.Top() > 0 ? th : 0;
- switch (mode) {
- default:
- break;
- case eDrawObjectLines:
- // straight line
- x_SetFeatureColor(feat);
- glVertex2f(from - offsetX, line_ym - offsetY);
- glVertex2f(to - offsetX, line_ym - offsetY);
- // Draw selection
- if (selected) {
- x_Color(CSeqGraphicColorConfig::eSelection_Feature);
- x_DrawSelection(pane, from, line_y1, to, line_y2);
- }
-
- break;
- case eDrawObjectQuads:
- // Highlight named Seq Annotations
- if (feat->GetMappedFeature().GetAnnot().IsNamed()) {
- CSeq_annot_Handle annot = feat->GetMappedFeature().GetAnnot();
- size_t idx = x_GetSeqAnnotIndex(annot);
-
- TModelUnit h = x_GetRowHeight(pane, feat, selected);
- CGlColor color = m_ColorTable.GetColor(idx);
- glColor4f(color.GetRed(), color.GetGreen(), color.GetBlue(), 0.1f);
-
- // add small overhang of 5 pixels (left and right)
- TModelUnit over = pane.UnProjectWidth(5);
-
- glVertex2f(from - offsetX - over, row_y - offsetY);
- glVertex2f(from - offsetX - over, row_y+h - offsetY);
- glVertex2f(to - offsetX+1+over, row_y+h - offsetY);
- glVertex2f(to - offsetX+1+over, row_y - offsetY);
- }
- x_SetFeatureColor(feat);
-
- // quad for each interval (exon)
- ITERATE (vector<TSeqRange>, iter, feat->GetIntervals()) {
- const TSeqRange& curr = *iter;
- TModelUnit f = curr.GetFrom();
- TModelUnit t = curr.GetTo()+1;// + (neg_strand ? 0.0f : 1.0f);
-
- if (pane.ProjectX(t) - pane.ProjectX(f) <= 1.0f) {
- t = f + pane.UnProjectWidth(1);
- }
- 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:
- if (feat->IsHiddenLabel()) return;
- // do not even try to draw labels if less than 1 letter width
- if (inrc.Width() <= pane.UnProjectWidth(m_MinLabelWidth)) {
- return;
- }
-
- string fl_both;
- string fl_type;
- string fl_content;
- string fl_out;
- x_GetLabels(feat->GetFeature(), m_Handle.GetScope(),
- &fl_type, &fl_content, &fl_both);
- GLfloat widthP = inrc.Width() / pane.GetScaleX(); // width in pixels
- GLfloat lw_type = m_Font_Helv8.TextWidth(fl_type.c_str() );
- if ( lw_type * 3 < widthP) { // 3 widths of eType label width
- fl_out = m_Font_Helv8.Truncate(fl_both.c_str(), widthP);
- } else {
- fl_out = m_Font_Helv8.Truncate(fl_content.c_str(), widthP);
- }
-
- if (selected) {
- x_Color(CSeqGraphicColorConfig::eSelLabel_Feature);
- } else {
- x_Color(CSeqGraphicColorConfig::eLabel_Feature);
- }
- GLfloat xM = x_CenterText(pane, inrc,
- m_Font_Helv8.TextWidth(fl_out.c_str()));
- m_Font_Helv8.TextOut(xM - offsetX,
- title_y - off - offsetY, fl_out.c_str());
- break;
- }
- }
- void
- CGenomePolicy::x_DrawFeatPack(CGlPane& pane, const CLayoutFeatPack* pack,
- GLfloat row_y, EObj_IterMode mode, bool selected) const
- {
- const TModelRect& rcV = pane.GetVisibleRect();
- const TModelRect& rcM = pane.GetModelLimitsRect();
-
- TModelUnit offsetX = pane.GetOffsetX();
- TModelUnit offsetY = pane.GetOffsetY();
-
- TSeqPos from = pack->GetLocation().GetTotalRange().GetFrom();
- TSeqPos to = pack->GetLocation().GetTotalRange().GetTo();
-
- TModelRect frc;
- frc.SetLeft(from);
- frc.SetRight(to);
- TModelRect inrc = frc.IntersectWith(rcV);
- GLfloat th = m_Font_Helv8.TextHeight();
- GLfloat title_y = row_y + th + 2;
- GLfloat off = rcM.Top() > 0 ? th : 0;
-
- switch (mode) {
- default:
- break;
- case eDrawObjectLines:
- case eDrawObjectQuads:
- ITERATE (CLayoutFeat::TFeatList, iter, pack->GetFeatures()) {
- const CLayoutFeat* feat = *iter;
- x_DrawFeature(pane, feat, row_y, mode, selected);
- }
- break;
- case eDrawObjectLabel:
- // do not even try to draw labels if less than 1 letter width
- if (inrc.Width() <= pane.UnProjectWidth(m_MinLabelWidth)) {
- return;
- }
- string out = NStr::UIntToString(pack->GetFeatures().size()) + " mRNA(s)";
-
- GLfloat widthP = inrc.Width() / pane.GetScaleX(); // width in pixels
- string fl_out = m_Font_Helv8.Truncate(out.c_str(), widthP);
-
- if (selected) {
- x_Color(CSeqGraphicColorConfig::eSelLabel_Feature);
- } else {
- x_Color(CSeqGraphicColorConfig::eLabel_Feature);
- }
- GLfloat xM = x_CenterText(pane, inrc,
- m_Font_Helv8.TextWidth(fl_out.c_str()));
- m_Font_Helv8.TextOut(xM - offsetX,
- title_y - off - offsetY, fl_out.c_str());
- break;
- }
- }
- void
- CGenomePolicy::x_DrawComments(CGlPane& pane, const CLayoutComment* comm,
- GLfloat row_y, EObj_IterMode mode, bool selected) const
- {
- const TModelRect& rcV = pane.GetVisibleRect();
- const TModelRect& rcM = pane.GetModelLimitsRect();
-
- TModelUnit offsetX = pane.GetOffsetX();
- TModelUnit offsetY = pane.GetOffsetY();
-
- GLfloat th = m_Font_Helv8.TextHeight();
- GLfloat title_y = row_y + th + 1;
- GLfloat off = rcM.Top() > 0 ? th : 0;
- switch (mode) {
- default:
- case eDrawObjectLines:
- case eDrawObjectQuads:
- break;
- case eDrawObjectLabel:
- const string& out = comm->GetComment();
- x_Color(CSeqGraphicColorConfig::eFG_Comment);
- m_Font_Helv8.TextOut(rcV.Left() - offsetX,
- title_y - off - offsetY, out.c_str());
- break;
- }
- }
- // draw proteint product and label only when selected
- void CGenomePolicy::x_DrawProteinProduct(CGlPane& pane, const CLayoutFeat* feat,
- GLfloat row_y, EProtSeqType type, bool selected) const
- {
- // label for original protein only and when product is accessible
- if (type == eTranslatedSeq || !feat->GetFeature().IsSetProduct()) {
- return; // not drawing labels or no product
- }
-
- const TModelRect& rcV = pane.GetVisibleRect();
- const TModelRect& rcM = pane.GetModelLimitsRect();
-
- TModelUnit offsetX = pane.GetOffsetX();
- TModelUnit offsetY = pane.GetOffsetY();
-
- TSeqPos from = feat->GetLocation().GetTotalRange().GetFrom();
- TSeqPos to = feat->GetLocation().GetTotalRange().GetTo();
- TModelRect frc;
- frc.SetLeft(from);
- frc.SetRight(to);
- TModelRect inrc = frc.IntersectWith(rcV);
-
- // do not do anything if there is no spac for even one letter
- if (inrc.Width() < pane.UnProjectWidth(m_MinLabelWidth)) {
- return;
- }
- GLfloat scaleX = pane.GetScaleX();
- GLfloat th = m_Font_Helv8.TextHeight();
- GLfloat title_y = row_y + th + 2;
- GLfloat off = rcM.Top() > 0 ? th - 1 : 0;
- const CSeq_loc& product = feat->GetFeature().GetProduct();
- string prot_label;
- CLabel::GetLabel(product, &prot_label,
- CLabel::eDefault, &m_Handle.GetScope());
- string out = m_Font_Helv10.Truncate(prot_label.c_str(),
- inrc.Width() / scaleX);
- GLfloat xM = x_CenterText(pane, inrc,
- m_Font_Helv10.TextWidth(out.c_str()));
- x_Color(selected ? CSeqGraphicColorConfig::eSelLabel_ProtProduct :
- CSeqGraphicColorConfig::eLabel_ProtProduct);
- m_Font_Helv8.TextOut(xM - offsetX, title_y - off - offsetY, out.c_str());
- }
- TModelUnit CGenomePolicy::x_GetRowHeight(CGlPane& pane,
- const CLayoutFeatPack* pack, bool selected) const
- {
- return 12.0f;
- }
- TModelUnit CGenomePolicy::x_GetRowHeight(CGlPane& pane,
- const CLayoutFeat* feat, bool selected) const
- {
- if (feat->IsHiddenLabel()) {
- return 3.0f + kGenomeSpacerSize; // 3 pixel is the width of feature
- } else {
- return 3.0f + m_Font_Helv8.TextHeight() + 2 * kGenomeSpacerSize; // 3 pixel is the width of feature
- }
- }
- TModelUnit CGenomePolicy::x_GetRowHeight(CGlPane& pane,
- const CLayoutProtProd* prot, bool selected) const
- {
- if (prot->IsHiddenLabel()) {
- return 3.0f + kGenomeSpacerSize; // 3 pixel is the width of feature
- } else {
- return 3.0f + m_Font_Helv8.TextHeight() + 2 * kGenomeSpacerSize; // 3 pixel is the width of feature
- }
- }
- TModelUnit CGenomePolicy::x_GetRowHeight(CGlPane& pane,
- const CLayoutComment* comm, bool selected) const
- {
- return m_Font_Helv8.TextHeight() + kGenomeSpacerSize;
-
- }
- TModelUnit CGenomePolicy::x_GetRowHeight(CGlPane& pane,
- const CLayoutHistogram* hist, bool selected) const
- {
- return 10.0f + kGenomeSpacerSize; // 10 pixels for histogram in this policy
- }
- void CGenomePolicy::x_GetTitle(const CLayoutFeatPack* pack, string* title,
- CLabel::ELabelType type) const
- {
- *title = NStr::UIntToString(pack->GetFeatures().size()) + " mRNA(s)";
- }
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- * $Log: genome_policy.cpp,v $
- * Revision 1000.2 2004/06/01 21:12:41 gouriano
- * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.10
- *
- * Revision 1.10 2004/05/21 22:27:55 gorelenk
- * Added PCH ncbi_pch.hpp
- *
- * Revision 1.9 2004/05/14 15:57:11 lebedev
- * Optional argument to specify the type of title/tooltip added
- *
- * Revision 1.8 2004/05/07 15:37:35 dicuccio
- * Use CLabel instead of CSeqUtils::GetLabel()
- *
- * Revision 1.7 2004/04/14 11:25:02 lebedev
- * Use x_DrawSelection from the base class
- *
- * Revision 1.6 2004/04/07 13:11:46 dicuccio
- * Use CSeq_annot_Handle for proper annotation name handling
- *
- * Revision 1.5 2004/03/30 13:58:37 lebedev
- * Use elements colors from configuration instead of setting colors directly.
- *
- * Revision 1.4 2004/03/23 12:33:56 lebedev
- * Made sequence and histograms bars a layout objects in the object panel.
- * Made segment map a number of layout objects. Get rid of fixed size rows in the object panel.
- *
- * Revision 1.3 2004/03/11 17:53:06 dicuccio
- * Deprecated typedefs TPosition, TDimension, TIndex, TColor. Use TSeqRange instead of TRange
- *
- * Revision 1.2 2004/03/05 17:41:29 dicuccio
- * Use sequence::GetId() instead of CSeq_id::GetStringDescr()
- *
- * Revision 1.1 2004/02/24 14:43:49 lebedev
- * Initial revision
- *
- * ===========================================================================
- */