cross_panel_ir.cpp
来自「ncbi源码」· C++ 代码 · 共 401 行
CPP
401 行
/* * =========================================================================== * PRODUCTION $Log: cross_panel_ir.cpp,v $ * PRODUCTION Revision 1000.1 2004/06/01 21:06:37 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.6 * PRODUCTION * =========================================================================== *//* $Id: cross_panel_ir.cpp,v 1000.1 2004/06/01 21:06:37 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 * */#include <ncbi_pch.hpp>#include <gui/widgets/aln_crossaln/cross_panel_ir.hpp>#include <objmgr/seq_vector.hpp>#include <gui/objutils/utils.hpp>#include <gui/opengl/glcolortable.hpp>BEGIN_NCBI_SCOPEUSING_SCOPE(objects);const TModelUnit kSeqMapBarHeight = 3.0f;CCrossPanelIR::CCrossPanelIR() : m_Font_Bitmap9x15(CGlBitmapFont::eBitmap9x15){ m_OneCharWidth = int( m_Font_Bitmap9x15.TextWidth("A") );}CCrossPanelIR::~CCrossPanelIR(){}void CCrossPanelIR::SetProportions(TModelUnit k, TModelUnit dx){ m_K = k; m_Dx = dx;}void CCrossPanelIR::SetShifts(TModelUnit sh1, TModelUnit sh2){ m_Sh1 = sh1; m_Sh2 = sh2;}void CCrossPanelIR::SetDataSource(CCrossAlnDataSource* ds){ m_DS = ds;}void CCrossPanelIR::Render(CGlPane& pane){ const TModelRect& rcV = pane.GetVisibleRect(); m_OffsetX = pane.GetOffsetX(); m_OffsetY = pane.GetOffsetY(); pane.OpenOrtho(); // 1) Draw Black bars CBioseq_Handle hndl1 = m_DS->GetQueryHandle(); CBioseq_Handle hndl2 = m_DS->GetSubjectHandle(); TSeqPos s1 = hndl1.GetSeqVector(CBioseq_Handle::eCoding_Iupac).size(); TSeqPos s2 = hndl2.GetSeqVector(CBioseq_Handle::eCoding_Iupac).size(); TModelUnit x1 = x_Seq2Lim1(0); // Convert from sequence to limits TModelUnit x2 = x_Seq2Lim1(s1); TModelUnit xx1 = x_Seq2Lim2(0); TModelUnit xx2 = x_Seq2Lim2(s2); glColor3f(0.07f, 0.07f, 0.07f); glBegin(GL_QUADS); glVertex2f(x1, rcV.Top() + 5 - m_OffsetY); glVertex2f(x2, rcV.Top() + 5 - m_OffsetY); glVertex2f(x2, rcV.Top() + 17 - m_OffsetY); glVertex2f(x1, rcV.Top() + 17 - m_OffsetY); glVertex2f(xx1, rcV.Bottom() - 5 - m_OffsetY); glVertex2f(xx2, rcV.Bottom() - 5 - m_OffsetY); glVertex2f(xx2, rcV.Bottom() - 18 - m_OffsetY); glVertex2f(xx1, rcV.Bottom() - 18 - m_OffsetY); glEnd(); // 2) Draw cross alignment lines glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_LINE_SMOOTH); glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); glLineWidth(1.5f); x_DrawCrossAlignment(pane, GL_QUADS ); // Draw our quads x_DrawCrossAlignment(pane, GL_LINE_LOOP); // Draw the outline // 3) Draw two Sequences bool seq_fit1 = x_IsSeqLettersFit1(pane); bool seq_fit2 = x_IsSeqLettersFit2(pane); GLfloat y1 = rcV.Top() + m_Font_Bitmap9x15.TextHeight() + 5; GLfloat y2 = rcV.Bottom() - m_Font_Bitmap9x15.TextHeight() + 3; TModelUnit one1 = pane.UnProjectWidth(m_OneCharWidth); TModelUnit add1 = (1.0f - one1) / 2.0f; TModelUnit one2 = pane.UnProjectWidth(m_OneCharWidth) / m_K; TModelUnit add2 = (1.0f - one2) / 2.0f; //cout << "m_K: " << m_K << " / one1: " << one1 << " / one2: " << one2 << endl; char bases[2]; bases[1] = '\0'; string seq1, seq2; glColor3f(0.55f, 0.55f, 0.55f); if (seq_fit1) { // sequence 1 fit TModelUnit l1 = x_Lim2Seq1( rcV.Left () ); TModelUnit r1 = x_Lim2Seq1( rcV.Right() ); if (l1 < 0) l1 = 0; x_GetSequence(hndl1, l1, r1, seq1); for (TSeqPos bp = 0; bp != seq1.length(); bp++) { bases[0] = seq1[bp]; m_Font_Bitmap9x15.TextOut(x_Seq2Lim1(TSeqPos(l1) + bp) + add1, y1 - m_OffsetY, bases); } } if (seq_fit2) { // sequence 2 fit TModelUnit l2 = x_Lim2Seq2( rcV.Left () ); TModelUnit r2 = x_Lim2Seq2( rcV.Right() ); if (l2 < 0) l2 = 0; x_GetSequence(hndl2, l2, r2, seq2); for (TSeqPos bp = 0; bp != seq2.length(); bp++) { bases[0] = seq2[bp]; m_Font_Bitmap9x15.TextOut(x_Seq2Lim2(TSeqPos(l2) + bp) + add2, y2 - m_OffsetY, bases); } } // 4) Highlight mismatches (and draw connection lines) if (seq_fit1 || seq_fit2) { const CCrossAlnDataSource::THitAdapterCont& hits = m_DS->GetHits(); ITERATE(CCrossAlnDataSource::THitAdapterCont, iter, hits) { for (size_t idx = 0; idx != (*iter).GetElemsCount(); idx++) { CHitElemDataAdapter elem = (*iter).GetElem(idx); if (elem.GetQueryStart() < 0 || elem.GetSubjectStart() < 0 ) { continue; } TSeqPos from1 = elem.GetQueryStart(); TSeqPos from2 = elem.GetSubjectStart(); TSeqPos to1 = from1 + elem.GetLength(); TSeqPos to2 = from2 + elem.GetLength(); //cout << "from1: " << from1 << " : to1: " << to1 << " / from2: " << from2 << " : to2: " << to2 << endl; x_GetSequence(hndl1, from1, to1, seq1); x_GetSequence(hndl2, from2, to2, seq2); GLfloat y1 = rcV.Top() + m_Font_Bitmap9x15.TextHeight() + 5; GLfloat y2 = rcV.Bottom() - m_Font_Bitmap9x15.TextHeight() + 3; TSeqPos bp = 0; for (TSeqPos pos = 0; pos != to1 - from1; pos++) { GLfloat x1 = x_Seq2Lim1(from1 + pos); GLfloat x2 = x_Seq2Lim2(from2 + pos); // Draw lines to connect mismatches glColor3f(1.0f, 1.0f, 1.0f); // black if (seq1[bp] != seq2[bp]) { if (seq_fit1 && seq_fit2) { glColor4f(1.0f, 0.0f, 0.0f, 0.5f); glBegin(GL_LINES); glVertex2f(x1 , rcV.Top() + 17 - m_OffsetY); glVertex2f(x2 , rcV.Bottom() - 18 - m_OffsetY); glVertex2f(x1+1, rcV.Top() + 17 - m_OffsetY); glVertex2f(x2+1, rcV.Bottom() - 18 - m_OffsetY); glEnd(); } glColor3f(1.0f, 0.0f, 0.0f); } if (seq_fit1) { bases[0] = seq1[bp]; m_Font_Bitmap9x15.TextOut(x1 + add1, y1 - m_OffsetY, bases); } if (seq_fit2) { bases[0] = seq2[bp]; m_Font_Bitmap9x15.TextOut(x2 + add2, y2 - m_OffsetY, bases); } bp++; } // for: pos } // size_t } // for: map } glDisable(GL_BLEND); glDisable(GL_LINE_SMOOTH); glLineWidth(1.0f); pane.Close();}void CCrossPanelIR::x_DrawCrossAlignment(CGlPane& pane, GLenum shape){ const TModelRect& rcV = pane.GetVisibleRect(); const CCrossAlnDataSource::THitAdapterCont& hits = m_DS->GetHits(); int count = 0; ITERATE(CCrossAlnDataSource::THitAdapterCont, iter, hits) { count += (*iter).GetElemsCount(); } CGlColorTable table(count, 0.5f, 0.75f); ITERATE(CCrossAlnDataSource::THitAdapterCont, iter, hits) { for (size_t idx = 0; idx != (*iter).GetElemsCount(); idx++) { CHitElemDataAdapter elem = (*iter).GetElem(idx); if (elem.GetQueryStart() < 0 || elem.GetSubjectStart() < 0 ) { continue; } TSeqPos from1 = elem.GetQueryStart(); TSeqPos from2 = elem.GetSubjectStart(); TSeqPos to1 = from1 + elem.GetLength(); TSeqPos to2 = from2 + elem.GetLength(); TModelUnit x_from1 = x_Seq2Lim1(from1); TModelUnit x_to1 = x_Seq2Lim1(to1); TModelUnit x_from2 = x_Seq2Lim2(from2); TModelUnit x_to2 = x_Seq2Lim2(to2); CGlColor color = table.GetColor(idx); glColor4f(color.GetRed(), color.GetGreen(), color.GetBlue(), shape == GL_QUADS ? 0.4 : 0.8); glBegin(shape); glVertex2f(x_from1, rcV.Top() + 19 - m_OffsetY); glVertex2f(x_to1, rcV.Top() + 19 - m_OffsetY); glVertex2f(x_to2, rcV.Bottom() - 21 - m_OffsetY); glVertex2f(x_from2, rcV.Bottom() - 21 - m_OffsetY); glEnd(); } } }void CCrossPanelIR::x_GetSequence(const CBioseq_Handle& handle, TModelUnit from, TModelUnit to, string& buffer) const{ buffer.erase(); CSeqVector s_vec = handle.GetSeqVector(CBioseq_Handle::eCoding_Iupac); s_vec.GetSeqData(TSeqPos(from), TSeqPos(to), buffer);}// Convert sequence to limitsTModelUnit CCrossPanelIR::x_Seq2Lim1(TModelUnit seq){ if (m_Dx < 0) return seq - m_Dx - m_OffsetX; else return seq - m_OffsetX;}TModelUnit CCrossPanelIR::x_Seq2Lim2(TModelUnit seq){ if (m_Dx > 0) return (seq + m_Dx - m_Sh2 ) * m_K + m_Sh1 - m_OffsetX; else return (seq - m_Sh2) * m_K + m_Sh1 - m_OffsetX;}// Convert limits to sequenceTModelUnit CCrossPanelIR::x_Lim2Seq1(TModelUnit lim){ if (m_Dx < 0) return lim + m_Dx; else return lim;}TModelUnit CCrossPanelIR::x_Lim2Seq2(TModelUnit lim){ if (m_Dx > 0) return (lim - m_Sh1) / m_K -m_Dx + m_Sh2; else return (lim - m_Sh1) / m_K + m_Sh2;}bool CCrossPanelIR::x_IsSeqLettersFit1(CGlPane& pane) const{ return pane.GetScaleX() <= 1.0f / 8.0f;}bool CCrossPanelIR::x_IsSeqLettersFit2(CGlPane& pane) const{ return pane.GetScaleX() / m_K <= 1.0f / 8.0f;}// IRenderableTVPRect CCrossPanelIR::GetVPRect(){ TVPRect rc(0, 0); rc.SetSize(0, 0); return rc;}TModelRect CCrossPanelIR::GetModelRect(){ TModelRect rc(0, 0); rc.SetSize(0, 0); return rc;} END_NCBI_SCOPE/* * =========================================================================== * $Log: cross_panel_ir.cpp,v $ * Revision 1000.1 2004/06/01 21:06:37 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/03 13:23:57 dicuccio * gui/utils --> gui/objutils where needed * * Revision 1.4 2004/03/11 17:50:41 dicuccio * Updated typedefs: dropped TDimension, TPosition, TIndex, TColor; use TSeqRange * instead of TRange * * Revision 1.3 2003/12/23 12:59:42 ucko * Avoid deque<>::const_iterator::operator->, which fails to compile on * GCC 2.95.x due to a typo in its STL implementation. :-/ * * Revision 1.2 2003/12/22 16:51:33 lebedev * Use CHitElemDataAdapter to get start/length from datasource * * Revision 1.1 2003/12/22 13:12:34 lebedev * Initial revision * * =========================================================================== */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?