NCBI C++ ToolKit
paint_sequence.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: paint_sequence.hpp 47464 2023-04-20 00:19:10Z evgeniev $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Igor Filippov
27  */
28 #ifndef _PAINT_SEQUENCE_H_
29 #define _PAINT_SEQUENCE_H_
30 
31 #include <corelib/ncbistd.hpp>
34 #include <objmgr/bioseq_handle.hpp>
35 /*!
36  * Includes
37  */
38 
39 ////@begin includes
40 ////@end includes
41 
42 
43 #include <wx/scrolwin.h>
44 #include <wx/vscroll.h>
45 #include <wx/textwrapper.h>
46 #include <wx/dcbuffer.h>
47 #include <wx/platform.h>
48 
49 #include <unordered_map>
50 
51 /*!
52  * Forward declarations
53  */
54 
55 ////@begin forward declarations
56 ////@end forward declarations
57 
59 
60 class CEditSequence;
61 
62 class CPaintSequence : public wxVScrolledWindow
63 {
64  DECLARE_DYNAMIC_CLASS( CPaintSequence )
65  DECLARE_EVENT_TABLE()
66 public:
67  CPaintSequence() : wxVScrolledWindow() {}
68  CPaintSequence(wxWindow *parent, const string &seq, const vector<int> &seq_len, const vector<vector<pair<TSeqPos,TSeqPos> > > &feat_ranges, const vector<pair<string,objects::CSeqFeatData::ESubtype> > &feat_types,
69  const vector<objects::CBioseq_Handle::EVectorStrand> &feat_strand, const vector<int> &feat_frames, const vector< CRef<objects::CGenetic_code> > &genetic_code, const vector<bool> &feat_partial5,
70  const string &allowed_char_set, const vector<string> &real_prot, const vector<bool> &read_only, const unordered_map<int, vector<vector<pair<TSeqPos,TSeqPos> > > > &prot_feat_ranges, const int start = 0,
71  wxWindowID id = wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize);
72  virtual ~CPaintSequence();
73  void InitPanel();
74  void OnMouseClick(wxMouseEvent& evt);
75  void OnKeyDown(wxKeyEvent& event);
76  void OnChar(wxKeyEvent& event);
77  void OnMouseDrag(wxMouseEvent& evt);
78  void OnMouseDown(wxMouseEvent& evt);
79  void OnCopy( wxCommandEvent& event );
80  void OnCut( wxCommandEvent& event );
81  void OnPaste( wxCommandEvent& event );
82  string GetSeq();
83  int GetLength();
84  void SetPos(int pos);
85  void SetRange(int pos1, int pos2);
86  void Search(const string &val);
87  vector<int> &GetSeqLen();
88  vector<bool> &GetReadOnly() {return m_read_only;}
89  void UpdateData();
90  void EnableTranslation(bool enable);
91  void EnableTranslation1(bool enable);
92  void EnableTranslation2(bool enable);
93  void EnableRevTranslation(bool enable);
94  void EnableRevTranslation1(bool enable);
95  void EnableRevTranslation2(bool enable);
96  void EnableComplement(bool enable);
97  void EnableFeatures(bool enable);
98  void EnableOnTheFly(bool enable);
99  void EnableMismatch(bool enable);
100  bool IsClipboard();
101  bool IsSelection();
102  pair<int,int> GetSelection();
103  virtual void OnPaint(wxPaintEvent& event);
104  virtual void OnEraseBackground(wxEraseEvent& event);
105  virtual wxCoord OnGetRowHeight( size_t row ) const;
106 
107  virtual void OnUpdate();
108  void OnResize(wxSizeEvent&);
109  void UpdateFeatures(const vector<vector<pair<TSeqPos,TSeqPos> > > &feat_ranges,
110  const vector<pair<string,objects::CSeqFeatData::ESubtype> > &feat_types,
111  const vector<objects::CBioseq_Handle::EVectorStrand> &feat_strand,
112  const vector<int> &feat_frames,
113  const vector< CRef<objects::CGenetic_code> > &genetic_code,
114  const vector<bool> &feat_partial5,
115  const vector<string> &real_prot,
116  const unordered_map<int, vector<vector<pair<TSeqPos,TSeqPos> > > > &prot_feat_ranges);
117  void SetClean(bool clean);
118  bool GetClean();
119  string * GetFindString(bool is_nuc, bool is_revcomp, const string &choice);
121  TSeqPos GetFeatureStart(int i, int j);
122  TSeqPos GetFeatureStop(int i, int j);
123  TSeqPos GetProtFeatureStart(int i, int k, int j) {return m_ProtFeatRanges[i][k][j].first;}
124  TSeqPos GetProtFeatureStop(int i, int k, int j) {return m_ProtFeatRanges[i][k][j].second;}
125 private:
126  void NormalizeCursorColRows();
127  void InsertChar(int uc);
128  void DeleteChar();
129  void ScrollWithCursor();
130  void SeqPosToColRow();
131  void ColRowToSeqPos();
132  unsigned int PosToSegment();
133  void ClearScreen(wxGraphicsContext *gc);
134  void CalculateFontWidthAndHeight(wxGraphicsContext *gc);
135  int CalculateNumCols();
136  void DrawTextLine(const string & substr, int &y_label, int row, wxGraphicsContext *gc, size_t &seq_pos);
137  void DrawTextCell(const wxString &substr, int col, int row, unsigned int seq_pos, int x, int &y, const vector<unsigned int> &feats_in_row, const map<unsigned int, vector<unsigned int> > &feats_with_exons, wxGraphicsContext *gc) const;
138  void DrawCursor(int col, int row, int x, int &y, wxGraphicsContext *gc) const;
139  void DrawTranslation(int x, int &y, unsigned int seq_pos, wxGraphicsContext *gc) const;
140  void DrawOffsetTranslation(int x, int y, unsigned int seq_pos, int offset, const string &prot, wxGraphicsContext *gc) const;
141  void DrawComplement(int x, int &y, unsigned int seq_pos, wxGraphicsContext *gc) const;
142  const wxPen *GetColorForFeature(objects::CSeqFeatData::ESubtype subtype) const;
143  void DrawFeatures(int row, unsigned int seq_pos, int x, int &y, int y_base, const vector<unsigned int> &feats_in_row, const map<unsigned int, vector<unsigned int> > &feats_with_exons, wxGraphicsContext *gc) const;
144  void DrawFeatureLabels(int row, int x, int &y, const vector<unsigned int> &feats_in_row, const map<unsigned int, vector<unsigned int> > &feats_with_exons, wxGraphicsContext *gc) const;
145  int LeftMarginWidth();
146  void DrawLineNumber(unsigned int seq_pos, int x, int &y, wxGraphicsContext *gc) const;
147  void DrawOnTheFly(int x, int &y, int y_base, unsigned int seq_pos, int i, const map<unsigned int, vector<unsigned int> > &feats_with_exons, wxGraphicsContext *gc) const;
148  char TranslateOnTheFly(unsigned int seq_pos, int i, const vector<unsigned int> &ranges, const vector<string> & translation, bool &left, bool &right) const;
149  void DrawMismatch(int x, int &y, int y_base, unsigned int seq_pos, int i, const map<unsigned int, vector<unsigned int> > &feats_with_exons, wxGraphicsContext *gc) const;
150  bool MouseToSeqPos(wxPoint p, int &row, int &y_row);
151  void DrawTripletMismatch(int x, int y, int y_base, int i, wxGraphicsContext *gc) const;
152  void DrawComplementLabel(int row, int x, int &y, wxGraphicsContext *gc) const;
153  void DrawOnTheFlyLabel(int x, int &y, bool is_exon_present, wxGraphicsContext *gc) const;
154  void DrawTranslationLabels(int row, int x, int &y, wxGraphicsContext *gc) const;
155  void DrawMismatchLabel(int x, int &y, bool is_exon_present, wxGraphicsContext *gc) const;
156  void TranslateCDS();
157  void MouseToFeature(wxPoint p, int row, int y0);
158  void AdjustFeatureRange(int origin, int offset);
159  void AdjustProtFeatRange(int origin, int offset, int i);
160  void AdjustFeatStartStop(int origin, int offset, int &start, int &stop);
161  int FindRowByCoord(int y, int &y_row);
162  int TopMarginHeight() {return 5;}
163  void DrawLabelCell(unsigned int pos, int x, int &y, int row, const vector<unsigned int> &feats_in_row, const map<unsigned int, vector<unsigned int> > &feats_with_exons, wxGraphicsContext *gc) const;
164  vector<unsigned int> GetFeaturesInRow(int row) const;
165  void GetFeatWholeRange();
166  vector<unsigned int> IsExonPresent(int i, int row) const;
167  map<unsigned int, vector<unsigned int> > GetFeatsWithExons(int row, const vector<unsigned int> &feats_in_row) const;
168  void RefreshWithScroll();
169  string CutSelection();
170  void SetStartPos(void);
171 
173  vector<int> m_SeqLen;
174  vector<vector<pair<TSeqPos,TSeqPos> > > m_FeatRanges;
175  unordered_map<int, vector<vector<pair<TSeqPos,TSeqPos> > > > m_ProtFeatRanges;
176  vector<pair<string,objects::CSeqFeatData::ESubtype> > m_FeatTypes;
177  vector<int> m_FeatFrames;
178  vector< CRef<objects::CGenetic_code> > m_GeneticCode;
179  vector<bool> m_Feat5Partial;
180  vector<pair<TSeqPos,TSeqPos> > m_FeatWholeRange;
181  vector< vector<TSeqPos> > m_FeatLengthBefore;
182  vector<TSeqPos> m_FeatTotalLength;
183  vector<string> m_Translated;
184  vector<objects::CBioseq_Handle::EVectorStrand> m_FeatStrand;
185  wxFont m_Font;
191  vector<string> m_RealProt;
197  bool m_Clean;
200  vector<bool> m_read_only;
201  int m_start;
202  bool m_Down;
203 };
204 
205 
206 
208 
209 #endif
210  // _PAINT_SEQUENCE_H_
set< int > & SetHighlights()
vector< vector< pair< TSeqPos, TSeqPos > > > m_FeatRanges
virtual wxCoord OnGetRowHeight(size_t row) const
vector< CRef< objects::CGenetic_code > > m_GeneticCode
void EnableRevTranslation1(bool enable)
virtual ~CPaintSequence()
void DrawOnTheFlyLabel(int x, int &y, bool is_exon_present, wxGraphicsContext *gc) const
void EnableOnTheFly(bool enable)
vector< pair< TSeqPos, TSeqPos > > m_FeatWholeRange
void DrawLineNumber(unsigned int seq_pos, int x, int &y, wxGraphicsContext *gc) const
const wxPen * GetColorForFeature(objects::CSeqFeatData::ESubtype subtype) const
void DrawLabelCell(unsigned int pos, int x, int &y, int row, const vector< unsigned int > &feats_in_row, const map< unsigned int, vector< unsigned int > > &feats_with_exons, wxGraphicsContext *gc) const
vector< bool > m_Feat5Partial
void SetStartPos(void)
vector< string > m_RealProt
vector< int > m_SeqLen
vector< int > m_FeatFrames
void AdjustFeatStartStop(int origin, int offset, int &start, int &stop)
void DrawOffsetTranslation(int x, int y, unsigned int seq_pos, int offset, const string &prot, wxGraphicsContext *gc) const
vector< string > m_Translated
CEditSequence * m_Parent
void OnChar(wxKeyEvent &event)
vector< unsigned int > GetFeaturesInRow(int row) const
void ClearScreen(wxGraphicsContext *gc)
void OnCut(wxCommandEvent &event)
set< int > m_highlights
vector< bool > m_read_only
virtual void OnEraseBackground(wxEraseEvent &event)
vector< int > & GetSeqLen()
void SetPos(int pos)
void InsertChar(int uc)
pair< int, int > m_FeatureStart
string * GetFindString(bool is_nuc, bool is_revcomp, const string &choice)
pair< int, int > GetSelection()
void DrawMismatch(int x, int &y, int y_base, unsigned int seq_pos, int i, const map< unsigned int, vector< unsigned int > > &feats_with_exons, wxGraphicsContext *gc) const
void DrawOnTheFly(int x, int &y, int y_base, unsigned int seq_pos, int i, const map< unsigned int, vector< unsigned int > > &feats_with_exons, wxGraphicsContext *gc) const
TSeqPos GetProtFeatureStart(int i, int k, int j)
void DrawTranslation(int x, int &y, unsigned int seq_pos, wxGraphicsContext *gc) const
void EnableMismatch(bool enable)
vector< bool > & GetReadOnly()
void DrawMismatchLabel(int x, int &y, bool is_exon_present, wxGraphicsContext *gc) const
void DrawCursor(int col, int row, int x, int &y, wxGraphicsContext *gc) const
void EnableComplement(bool enable)
void DrawTranslationLabels(int row, int x, int &y, wxGraphicsContext *gc) const
void OnMouseDrag(wxMouseEvent &evt)
int FindRowByCoord(int y, int &y_row)
void UpdateFeatures(const vector< vector< pair< TSeqPos, TSeqPos > > > &feat_ranges, const vector< pair< string, objects::CSeqFeatData::ESubtype > > &feat_types, const vector< objects::CBioseq_Handle::EVectorStrand > &feat_strand, const vector< int > &feat_frames, const vector< CRef< objects::CGenetic_code > > &genetic_code, const vector< bool > &feat_partial5, const vector< string > &real_prot, const unordered_map< int, vector< vector< pair< TSeqPos, TSeqPos > > > > &prot_feat_ranges)
void OnPaste(wxCommandEvent &event)
void DrawFeatures(int row, unsigned int seq_pos, int x, int &y, int y_base, const vector< unsigned int > &feats_in_row, const map< unsigned int, vector< unsigned int > > &feats_with_exons, wxGraphicsContext *gc) const
void OnKeyDown(wxKeyEvent &event)
void EnableTranslation1(bool enable)
void SetRange(int pos1, int pos2)
void DrawComplement(int x, int &y, unsigned int seq_pos, wxGraphicsContext *gc) const
void OnMouseClick(wxMouseEvent &evt)
void OnCopy(wxCommandEvent &event)
void DrawFeatureLabels(int row, int x, int &y, const vector< unsigned int > &feats_in_row, const map< unsigned int, vector< unsigned int > > &feats_with_exons, wxGraphicsContext *gc) const
void EnableRevTranslation(bool enable)
void MouseToFeature(wxPoint p, int row, int y0)
bool MouseToSeqPos(wxPoint p, int &row, int &y_row)
void DrawTextLine(const string &substr, int &y_label, int row, wxGraphicsContext *gc, size_t &seq_pos)
void NormalizeCursorColRows()
void EnableTranslation2(bool enable)
virtual void OnUpdate()
Notification for the derived class that moment is good for doing its update and drawing stuff.
void AdjustProtFeatRange(int origin, int offset, int i)
void OnResize(wxSizeEvent &)
void EnableTranslation(bool enable)
void AdjustFeatureRange(int origin, int offset)
char TranslateOnTheFly(unsigned int seq_pos, int i, const vector< unsigned int > &ranges, const vector< string > &translation, bool &left, bool &right) const
void Search(const string &val)
virtual void OnPaint(wxPaintEvent &event)
Painting.
void EnableRevTranslation2(bool enable)
vector< pair< string, objects::CSeqFeatData::ESubtype > > m_FeatTypes
void DrawTextCell(const wxString &substr, int col, int row, unsigned int seq_pos, int x, int &y, const vector< unsigned int > &feats_in_row, const map< unsigned int, vector< unsigned int > > &feats_with_exons, wxGraphicsContext *gc) const
void SetClean(bool clean)
vector< TSeqPos > m_FeatTotalLength
TSeqPos GetFeatureStop(int i, int j)
vector< vector< TSeqPos > > m_FeatLengthBefore
vector< unsigned int > IsExonPresent(int i, int row) const
pair< int, int > m_FeatureStop
unsigned int PosToSegment()
TSeqPos GetProtFeatureStop(int i, int k, int j)
void EnableFeatures(bool enable)
void CalculateFontWidthAndHeight(wxGraphicsContext *gc)
unordered_map< int, vector< vector< pair< TSeqPos, TSeqPos > > > > m_ProtFeatRanges
map< unsigned int, vector< unsigned int > > GetFeatsWithExons(int row, const vector< unsigned int > &feats_in_row) const
vector< objects::CBioseq_Handle::EVectorStrand > m_FeatStrand
CPaintSequence(wxWindow *parent, const string &seq, const vector< int > &seq_len, const vector< vector< pair< TSeqPos, TSeqPos > > > &feat_ranges, const vector< pair< string, objects::CSeqFeatData::ESubtype > > &feat_types, const vector< objects::CBioseq_Handle::EVectorStrand > &feat_strand, const vector< int > &feat_frames, const vector< CRef< objects::CGenetic_code > > &genetic_code, const vector< bool > &feat_partial5, const string &allowed_char_set, const vector< string > &real_prot, const vector< bool > &read_only, const unordered_map< int, vector< vector< pair< TSeqPos, TSeqPos > > > > &prot_feat_ranges, const int start=0, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize)
void OnMouseDown(wxMouseEvent &evt)
void DrawTripletMismatch(int x, int y, int y_base, int i, wxGraphicsContext *gc) const
TSeqPos GetFeatureStart(int i, int j)
void DrawComplementLabel(int row, int x, int &y, wxGraphicsContext *gc) const
CRef –.
Definition: ncbiobj.hpp:618
Definition: map.hpp:338
Include a standard set of the NCBI C++ Toolkit most basic headers.
int offset
Definition: replacements.h:160
unsigned int TSeqPos
Type for sequence locations and lengths.
Definition: ncbimisc.hpp:875
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
int i
const struct ncbi::grid::netcache::search::fields::SIZE size
static const GLdouble origin[]
static static static wxID_ANY
#define row(bind, expected)
Definition: string_bind.c:73
Modified on Fri Sep 20 14:57:24 2024 by modify_doxy.py rev. 669887