hit_matrix_pane.cpp
来自「ncbi源码」· C++ 代码 · 共 570 行 · 第 1/2 页
CPP
570 行
/* * =========================================================================== * PRODUCTION $Log: hit_matrix_pane.cpp,v $ * PRODUCTION Revision 1000.3 2004/06/01 21:10:58 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.9 * PRODUCTION * =========================================================================== *//* $Id: hit_matrix_pane.cpp,v 1000.3 2004/06/01 21:10:58 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: Andrey Yazhuk * * File Description: * */#include <ncbi_pch.hpp>#include <corelib/ncbistl.hpp>#include <corelib/ncbitime.hpp>#include <gui/widgets/hit_matrix/hit_matrix_pane.hpp>#include <gui/widgets/hit_matrix/hit_matrix_widget.hpp>#include <FL/Fl.H>BEGIN_NCBI_SCOPE#define AXIS_AREA_W 50#define AXIS_AREA_H 30CHitMatrixPane::CHitMatrixPane(int PosX, int PosY, int Width, int Height, const char* Label): CGlPaneWidgetChild(PosX, PosY, Width, Height, Label), m_BackColor(0.95f, 1.0f, 0.95f), m_pTextFont(NULL), m_pSeqFont(NULL), m_VertSelHandler(eVert), m_BottomRuler(true), m_TopRuler(true), m_LeftRuler(false), m_RightRuler(false), m_QueryGraph(false), m_SubjectGraph(true){ m_MatrixPane.EnableOffset(true); m_SubjectPane.EnableOffset(true); m_QueryPane.EnableOffset(true); m_Gen.SetIntegerMode(true, true); m_Gen.EnableOneBased(true, true); m_Grid.EnableIntegerCentering(true); m_pTextFont = new CGlBitmapFont(CGlBitmapFont::eHelvetica12); m_pSeqFont = new CGlBitmapFont(CGlBitmapFont::eCourier14); m_QueryGraph.SetFonts(m_pTextFont, m_pSeqFont); m_SubjectGraph.SetFonts(m_pTextFont, m_pSeqFont); //setup Event Handlers m_HorzSelHandler.SetHost(static_cast<ISelHandlerHost*>(this)); x_RegisterHandler(dynamic_cast<IEventHandler*>(&m_HorzSelHandler), fSubjectArea, &m_SubjectPane); m_VertSelHandler.SetHost(static_cast<ISelHandlerHost*>(this)); x_RegisterHandler(dynamic_cast<IEventHandler*>(&m_VertSelHandler), fQueryArea, &m_QueryPane); m_MouseZoomHandler.SetHost(static_cast<IMouseZoomHandlerHost*>(this)); x_RegisterHandler(dynamic_cast<IEventHandler*>(&m_MouseZoomHandler), fMatrixArea, &m_MatrixPane); m_Graph.SetHost(static_cast<IHitMatrixGraphHost*>(this)); x_RegisterHandler(dynamic_cast<IEventHandler*>(&m_Graph), fMatrixArea, &m_MatrixPane); /* x_AddHandler(dynamic_cast<IEventHandler*>(this), fDescrArea); */ m_Event.StandardConfig(); x_Layout(); x_SetupAxes();}void CHitMatrixPane::x_SetupAxes(){ m_TopRuler.SetHorizontal(true, CRuler::eTop); m_RightRuler.SetHorizontal(false, CRuler::eRight);}TVPPoint CHitMatrixPane::GetPortSize(void){ return TVPPoint(m_rcMatrix.Width(), m_rcMatrix.Height());}void CHitMatrixPane::SetWidget(CHitMatrixWidget* pParent){ m_pParent = pParent; if(m_pParent) { m_MatrixPane = x_GetParent()->GetPort(); }}void CHitMatrixPane::resize(int x, int y, int w, int h){ CGlPaneWidgetChild::resize(x, y, w, h); x_Layout(); m_MatrixPane.SetViewport(m_rcMatrix); m_SubjectPane.SetViewport(m_rcBottomSeq); x_AdjsutToMasterPane(m_SubjectPane, true, false); m_QueryPane.SetViewport(m_rcLeftSeq); x_AdjsutToMasterPane(m_QueryPane, false, true);}void CHitMatrixPane::x_Render(void){ glClearColor(m_BackColor.GetRed(), m_BackColor.GetGreen(), m_BackColor.GetBlue(), m_BackColor.GetAlpha()); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // optional render background images x_RenderContent();}void CHitMatrixPane::Update(){ _ASSERT(x_GetParent()); m_Graph.DeleteGlyphs(); CHitMatrixDataSource* pDS = x_GetParent()->GetDS(); if(pDS) { CBioseq_Handle q_handle = pDS->GetQueryHandle(); CBioseq_Handle s_handle = pDS->GetSubjectHandle(); const CHitMatrixDataSource::THitAdapterCont& hits = pDS->GetHits(); for( CHitMatrixDataSource::THitAdapterCont::const_iterator it = hits.begin(); it != hits.end(); it++ ) { //const CHitDataAdapter* hit = *it; //cout << "Q Start " << hit.GetQueryStart() << ", Subj Start " << hit.GetSubjectStart() << endl; m_Graph.CreateGlyph(&(*it)); } if(m_ColorScoreId) { m_Graph.AssignColorsByScore(m_ColorScoreId); m_ColorScoreId.Reset(); } m_SubjectGraph.SetBioseqHandle(s_handle); m_QueryGraph.SetBioseqHandle(q_handle); } else { CBioseq_Handle h_null; m_SubjectGraph.SetBioseqHandle(h_null); m_QueryGraph.SetBioseqHandle(h_null); }}void CHitMatrixPane::ColorByScore(CConstRef<CObject_id> score_id){ m_ColorScoreId = score_id; CHitMatrixDataSource* pDS = x_GetParent()->GetDS(); if(pDS) { m_Graph.AssignColorsByScore(score_id); }}typedef multimap<const CHitDataAdapter*, const CHitElemGlyph*> THitToElemGlyphMap;bool SubjectStartLess(const CHitElemDataAdapter* el1, const CHitElemDataAdapter* el2){ return el1->GetSubjectStart() < el2->GetSubjectStart();} CConstRef<CSeq_align_set> CHitMatrixPane::GetSelectedHits() const{ const TElemGlyphSet& glyphs = m_Graph.GetSelectedGlyphs(); // build a temporary map THitToElemGlyphMap hit_to_glyph; ITERATE( CHitMatrixPane::TElemGlyphSet, it_G, glyphs) { const CHitElemDataAdapter& elem = (*it_G)->GetHitElem(); const CHitDataAdapter& hit = elem.GetHit(); hit_to_glyph.insert(THitToElemGlyphMap::value_type(&hit, *it_G)); } // create a new seq-align-set CRef<CSeq_align_set> set(new CSeq_align_set); CSeq_align_set::Tdata ls_rf_aligns = set->Set(); const CHitDataAdapter* p_curr_hit = NULL; CSeq_align* p_align = NULL; CDense_seg* p_denseg = NULL; vector<const CHitElemDataAdapter*> elems; // iterate by Glyphs for( THitToElemGlyphMap::const_iterator it = hit_to_glyph.begin(); it != hit_to_glyph.end(); ) { // for a new Hit create a CSeq_align p_curr_hit = it->first; p_align = new CSeq_align(); p_align->SetType(CSeq_align::eType_partial); ls_rf_aligns.push_back(CRef<CSeq_align>(p_align)); // add to set CSeq_align::C_Segs& segs = p_align->SetSegs(); segs.Select(CSeq_align::C_Segs::e_Denseg); p_denseg = & segs.SetDenseg(); // for all elements of the current hit - add to list for( ; it != hit_to_glyph.end() && it->first == p_curr_hit; it++ ) { const CHitElemDataAdapter& elem = it->second->GetHitElem(); elems.push_back(&elem); } int size = elems.size(); if(size) sort(elems.begin(), elems.end(), SubjectStartLess); p_denseg->SetDim(2); p_denseg->SetNumseg(size); p_denseg->SetStarts().resize(2*size); p_denseg->SetLens().resize(size); p_denseg->SetStrands().resize(size); // add elems to denseg int i_start = 0, i_len = 0; ITERATE(vector<const CHitElemDataAdapter*>, it_e, elems) { const CHitElemDataAdapter* elem = *it_e; p_denseg->SetStarts()[i_start++] = elem->GetSubjectStart(); p_denseg->SetStarts()[i_start++] = elem->GetQueryStart(); p_denseg->SetLens()[i_len++] = elem->GetLength(); } elems.clear(); } return ConstRef<CSeq_align_set>(set);}TModelRect CHitMatrixPane::GetSelectedHitElemsRect() const{ const TElemGlyphSet& glyphs = m_Graph.GetSelectedGlyphs(); bool b_first = true; int left, right, top, bottom; ITERATE( CHitMatrixPane::TElemGlyphSet, it_G, glyphs) { const CHitElemDataAdapter& elem = (*it_G)->GetHitElem(); int s_from = elem.GetSubjectStart(); int q_from = elem.GetQueryStart(); int len = elem.GetLength(); int s_to = s_from + len; int q_to = q_from + len; if(q_from > q_to) swap(q_from, q_to); if(s_from > s_to) swap(s_from, s_to); if(b_first) { left = s_from; right = s_to; bottom = q_from; top = q_to; b_first = false; } else { left = min(left, s_from); right = max(right, s_to); bottom = min(bottom, q_from); top = max(top, q_to);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?