Changes between Initial Version and Version 1 of ExportGlycansIntoExcel


Ignore:
Timestamp:
12/06/2018 06:54:19 PM (3 years ago)
Author:
sena
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ExportGlycansIntoExcel

    v1 v1  
     1== How to draw a glycan cartoon in an Excel cell ==
     2
     3Required Libraries:
     4* eurocarb-glycanbuilder-1.0rc.jar
     5* eurocarb-glycoworkbench-1.0rc.jar
     6
     7if done from a plugin, org.eurocarbdb plugin should be added as a dependency
     8
     9First of all, we should have a sequence string to begin generating the cartoon. Sequence can be of two types for this tutorial:
     101. GlycoCTCondensed
     112. GlycoWorkbenchSequence (GWS)
     12
     13Before generating the cartoon, we should get a Glycan object from the sequence.
     141. GlycoCTCondensed:
     15
     16{{{
     17org.eurocarbdb.application.glycanbuilder.Glycan glycan = org.eurocarbdb.application.glycanbuilder.Glycan.fromGlycoCTCondensed(sequence);
     18}}}
     19
     202. GWS
     21
     22{{{
     23org.eurocarbdb.application.glycanbuilder.Glycan glycan = org.eurocarbdb.application.glycanbuilder.Glycan.fromString(sequence);
     24}}}
     25
     26=== Generating the Image from Glycan ===
     27
     28Need to initialize graphic options before generating the image
     29
     30{{{
     31private static void initGraphicOptions() {
     32        if ( isInitializedGWS )
     33                return;
     34        // Set orientation of glycan: RL - right to left, LR - left to right, TB - top to bottom, BT - bottom to top
     35        glycanWorkspace.getGraphicOptions().ORIENTATION = GraphicOptions.RL;
     36        // Set flag to show information such as linkage positions and anomers
     37        glycanWorkspace.getGraphicOptions().SHOW_INFO = true;
     38        // Set flag to show mass
     39        glycanWorkspace.getGraphicOptions().SHOW_MASSES = false;
     40        // Set flag to show reducing end
     41        glycanWorkspace.getGraphicOptions().SHOW_REDEND = true;
     42
     43        isInitializedGWS = true;
     44}
     45}}}
     46
     47The above initialization should be done once. After the inialization, we can get the BufferedImage with:
     48
     49{{{
     50BufferedImage t_image = glycanWorkspace.getGlycanRenderer()
     51                                .getImage(new Union<org.eurocarbdb.application.glycanbuilder.Glycan>(glycan), true, false, true, 0.5d);
     52}}}
     53
     54=== Writing the image to Excel ===
     55In order to put the image into a cell in an Excel workbook, we need to use the following helper method:
     56
     57ExcelWriterHelper.java is in "org.grits.utils" plugin within "org.grits.utils.io" package.
     58{{{
     59     List<org.apache.poi.ss.usermodel.Picture> m_lPictures = new ArrayList<>();    // should be initialized once for the workbook to contain all the generated Excel pictures, not for each row!!!
     60
     61     ExcelWriterHelper.writeCellImage(a_workbook, a_sheet, a_iRow, a_iCol, t_image, m_lPictures);
     62}}}