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

Go to the SVN repository for this file.

1 #ifndef OBJTOOLS_BLAST_FORMAT___BLASTHITMATRIX_HPP
2 #define OBJTOOLS_BLAST_FORMAT___BLASTHITMATRIX_HPP
3 /* $Id: blast_hitmatrix.hpp 46176 2021-01-28 17:07:49Z grichenk $
4  * ===========================================================================
5  *
6  * PUBLIC DOMAIN NOTICE
7  * National Center for Biotechnology Information
8  *
9  * This software/database is a "United States Government Work" under the
10  * terms of the United States Copyright Act. It was written as part of
11  * the author's official duties as a United States Government employee and
12  * thus cannot be copyrighted. This software/database is freely available
13  * to the public for use. The National Library of Medicine and the U.S.
14  * Government have not placed any restriction on its use or reproduction.
15  *
16  * Although all reasonable efforts have been taken to ensure the accuracy
17  * and reliability of the software and data, the NLM and the U.S.
18  * Government do not and cannot warrant the performance or results that
19  * may be obtained by using this software or data. The NLM and the U.S.
20  * Government disclaim all warranties, express or implied, including
21  * warranties of performance, merchantability or fitness for any particular
22  * purpose.
23  *
24  * Please cite the author in any work or product based on this material.
25  *
26  * ===========================================================================
27  *
28  * Author: Irena Zaretskaya
29  */
30 
31 /** @file blast_hitmatrix.hpp
32  * Declares class to display hitmatrix image view for blast 2 seq
33  */
34 #include <cgi/cgictx.hpp>
35 
38 #include <gui/opengl/glutils.hpp>
39 #include <gui/opengl/glpane.hpp>
40 #include <gui/objutils/label.hpp>
41 
43 
46 
47 /** @addtogroup BlastFormatting
48  *
49  * @{
50  */
51 
54 
55 
56 ///This class displays the image of the hitmatrix view for blast 2 seq results
57 ///
58 ///Usage:
59 ///blastHitMatrix = new CBlastHitMatrix(...);
60 ///If displasy on the screen
61 /// blastHitMatrix->Dispaly(out)
62 ///If write to the file:
63 /// blastHitMatrix->SetFileName(<filename>)
64 /// blastHitMatrix->WriteToFile()
65 
66 /**
67  * This class displays the defline for BLAST result.
68  *
69  * Example:
70  * @code
71  * blastHitMatrix = new CBlastHitMatrix(...);
72  * If display on the screen:
73  * string encoding("image/png");
74  * CCgiResponse& response = ctx.GetResponse();
75  * response.SetContentType(encoding);
76  * response.WriteHeader();
77  * blastHitMatrix->Display(response.out());
78  * If write to the file:
79  * blastHitMatrix->SetFileName(<filename>)
80  * blastHitMatrix->WriteToFile()
81  * @endcode
82  */
84 {
85 public:
86  ///Constructor
87  ///
88  ///@param seqAligns: input seqalign list
89  ///@param height: image height
90  ///@param width: image width
91  ///@param format: image type (png, bmp etc)
92  ///@param font_path: path to font files for rendering, the rendering
93  /// library will look for the fonts in font_path + "/fonts"
94  CBlastHitMatrix(const list< CRef< CSeq_align > > &seqAligns,
95  int height = 600,
96  int width = 800,
98  const string& font_path = ""
99 );
100  ///Destructor
102 
103  ///Inits file name if image is written to the file
104  ///
105  ///@param fileName: file name for image output
106  void SetFileName(string fileName) {m_File = fileName;m_FileOut = true;}
107 
108 
109  ///Indicates that thumbmail should be shown
110  ///
111  ///@param set
112  void SetThumbnail(bool set) {m_Thumbnail = set;}
113 
114  ///Checks if image is to be written to the file
115  ///
116  ///@return : true if image is to be written to the file
117  bool IsFileOut(void){return m_FileOut;}
118 
119  ///Get netcache ID for the image stored in netcache
120  ///
121  ///@return : string netcache ID
122  string GetNetcacheID(void) {return m_ImageKey;}
123 
124  ///Get error message
125  ///
126  ///@return : string error message
127  string GetErrorMessage(void) {return m_ErrorMessage;}
128 
129  ///Outputs the image into CNcbiOstream
130  ///
131  ///@param out: stream to output
132  ///@return : true if successful
133  bool Display(CNcbiOstream & out);
134 
135  ///Outputs the image into the file (m_FileOut=true) or netcache
136  ///
137  ///@return : true if successful
138  bool WriteToFile(void);
139 
140 protected:
141  ///Initializes Object Manager
142  void x_InitObjectManager();
143 
144  ///Initializes CGlPane
145  void x_InitPort();
146 
147  ///Creates Query and subject labels info
148  void x_GetLabels(void);
149 
150 
151  ///Renders a pairwise alignments between the first two Seq-id in the alignment
152  bool x_RenderImage(void);
153 
154  ///Performs pre-processing for image rendering
155  void x_PreProcess(void);
156 
157  ///Inits renderer display options and text labels
158  void x_Render(void);
159 
160  ///Initialize rendering environment
161  void x_InitGraphics(const string& font_path = "");
162 
163 private:
164  ///Object manager
166 
167  ///Current scope
169 
170  ///Vector of seqaligns
171  vector< CConstRef<CSeq_align> > m_Aligns;
172 
173  ///Query label id
174  string m_QueryID;
175 
176  ///Subject label id
177  string m_SubjectID;
178 
179  ///File name
180  string m_File;
181 
182  ///true if output to the file
183  bool m_FileOut;
184 
186 
187  ///Image height
188  int m_Height;
189 
190  ///Image width
191  int m_Width;
192 
193  ///Image format (png,bmp etc)
195 
196  ///netcacheID
197  string m_ImageKey;
198 
199  ///Error message
201 
202  /// Renderer setup Parameter
204 
205  /// Renderer setup Parameter
207 
208  /// Renderer setup Parameter
209  unique_ptr<CHitMatrixRenderer> m_Renderer;
210 
211  ///CGlOsContext context
213 };
214 
215 
216 
219 
220 /* @} */
221 
222 #endif /* OBJTOOLS_BLAST_FORMAT___BLASTHITMATRIX_HPP */
223 
This class displays the image of the hitmatrix view for blast 2 seq results.
class CGlPane
Definition: glpane.hpp:62
Definition: set.hpp:45
std::ofstream out("events_result.xml")
main entry point for tests
CRef< CScope > m_Scope
Current scope.
CRef< CGlOsContext > m_Context
CGlOsContext context.
int m_Height
Image height.
int m_Width
Image width.
bool IsFileOut(void)
Checks if image is to be written to the file.
string m_SubjectID
Subject label id.
vector< CConstRef< CSeq_align > > m_Aligns
Vector of seqaligns.
string GetNetcacheID(void)
Get netcache ID for the image stored in netcache.
CImageIO::EType m_Format
Image format (png,bmp etc)
CRef< CObjectManager > m_ObjMgr
Object manager.
bool m_FileOut
true if output to the file
void SetThumbnail(bool set)
Indicates that thumbmail should be shown.
unique_ptr< CHitMatrixRenderer > m_Renderer
Renderer setup Parameter.
CIRef< IHitMatrixDataSource > m_DataSource
Renderer setup Parameter.
string m_ImageKey
netcacheID
~CBlastHitMatrix()
Destructor.
void SetFileName(string fileName)
Inits file name if image is written to the file.
string GetErrorMessage(void)
Get error message.
string m_QueryID
Query label id.
string m_File
File name.
CGlPane m_Port
Renderer setup Parameter.
string m_ErrorMessage
Error message.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:149
#define NCBI_XBLASTFORMAT_EXPORT
Definition: ncbi_export.h:1073
static Format format
Definition: njn_ioutil.cpp:53
The Object manager core.
Modified on Tue May 21 11:02:03 2024 by modify_doxy.py rev. 669887