1 #ifndef OBJTOOLS_BLAST_FORMAT___BLASTHITMATRIX_HPP 2 #define OBJTOOLS_BLAST_FORMAT___BLASTHITMATRIX_HPP 3 /* $Id: blast_hitmatrix.hpp 631986 2021-05-25 17:42:22Z ivanov $ 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 36 #include <gui/opengl/mesa/glcgi_image.hpp> 37 #include <gui/opengl/mesa/gloscontext.hpp> 38 #include <gui/opengl/glutils.hpp> 39 #include <gui/opengl/glpane.hpp> 40 #include <gui/objutils/label.hpp> 41 42 #include <objmgr/object_manager.hpp> 43 44 #include <gui/widgets/hit_matrix/hit_matrix_renderer.hpp> 45 #include <gui/widgets/hit_matrix/hit_matrix_ds_builder.hpp> 46 47 /** @addtogroup BlastFormatting 48 * 49 * @{ 50 */ 51 52 BEGIN_NCBI_SCOPE 53 BEGIN_SCOPE(objects) 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 */ 83 class NCBI_XBLASTFORMAT_EXPORT CBlastHitMatrix 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, 97 CImageIO::EType format = CImageIO::ePng, 98 const string& font_path = "" 99 ); 100 ///Destructor ~CBlastHitMatrix()101 ~CBlastHitMatrix(){}; 102 103 ///Inits file name if image is written to the file 104 /// 105 ///@param fileName: file name for image output SetFileName(string fileName)106 void SetFileName(string fileName) {m_File = fileName;m_FileOut = true;} 107 108 109 ///Indicates that thumbmail should be shown 110 /// 111 ///@param set SetThumbnail(bool 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 IsFileOut(void)117 bool IsFileOut(void){return m_FileOut;} 118 119 ///Get netcache ID for the image stored in netcache 120 /// 121 ///@return : string netcache ID GetNetcacheID(void)122 string GetNetcacheID(void) {return m_ImageKey;} 123 124 ///Get error message 125 /// 126 ///@return : string error message GetErrorMessage(void)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 165 CRef<CObjectManager> m_ObjMgr; 166 167 ///Current scope 168 CRef<CScope> m_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 185 bool m_Thumbnail; 186 187 ///Image height 188 int m_Height; 189 190 ///Image width 191 int m_Width; 192 193 ///Image format (png,bmp etc) 194 CImageIO::EType m_Format; 195 196 ///netcacheID 197 string m_ImageKey; 198 199 ///Error message 200 string m_ErrorMessage; 201 202 /// Renderer setup Parameter 203 CIRef<IHitMatrixDataSource> m_DataSource; 204 205 /// Renderer setup Parameter 206 CGlPane m_Port; 207 208 /// Renderer setup Parameter 209 unique_ptr<CHitMatrixRenderer> m_Renderer; 210 211 ///CGlOsContext context 212 CRef <CGlOsContext> m_Context; 213 }; 214 215 216 217 END_SCOPE(objects) 218 END_NCBI_SCOPE 219 220 /* @} */ 221 222 #endif /* OBJTOOLS_BLAST_FORMAT___BLASTHITMATRIX_HPP */ 223 224