How to draw a glycan cartoon in an Excel cell

Required Libraries:

  • eurocarb-glycanbuilder-1.0rc.jar
  • eurocarb-glycoworkbench-1.0rc.jar

if done from a plugin, org.eurocarbdb plugin should be added as a dependency

First of all, we should have a sequence string to begin generating the cartoon. Sequence can be of two types for this tutorial:

  1. GlycoCTCondensed
  2. GlycoWorkbenchSequence (GWS)

Before generating the cartoon, we should get a Glycan object from the sequence.

  1. GlycoCTCondensed:
org.eurocarbdb.application.glycanbuilder.Glycan glycan = org.eurocarbdb.application.glycanbuilder.Glycan.fromGlycoCTCondensed(sequence);
  1. GWS
org.eurocarbdb.application.glycanbuilder.Glycan glycan = org.eurocarbdb.application.glycanbuilder.Glycan.fromString(sequence);

Generating the Image from Glycan

Need to initialize graphic options before generating the image

private static void initGraphicOptions() {
	if ( isInitializedGWS )
	// Set orientation of glycan: RL - right to left, LR - left to right, TB - top to bottom, BT - bottom to top
	glycanWorkspace.getGraphicOptions().ORIENTATION = GraphicOptions.RL;
	// Set flag to show information such as linkage positions and anomers
	glycanWorkspace.getGraphicOptions().SHOW_INFO = true;
	// Set flag to show mass
	glycanWorkspace.getGraphicOptions().SHOW_MASSES = false;
	// Set flag to show reducing end
	glycanWorkspace.getGraphicOptions().SHOW_REDEND = true;

	isInitializedGWS = true;

The above initialization should be done once. After the inialization, we can get the BufferedImage with:

BufferedImage t_image = glycanWorkspace.getGlycanRenderer()
				.getImage(new Union<org.eurocarbdb.application.glycanbuilder.Glycan>(glycan), true, false, true, 0.5d);

Writing the image to Excel

In order to put the image into a cell in an Excel workbook, we need to use the following helper method: is in "org.grits.utils" plugin within "" package.

     List<> m_lPictures = new ArrayList<>();    // should be initialized once for the workbook to contain all the generated Excel pictures, not for each row!!!

     ExcelWriterHelper helper = new ExcelWriterHelper();  // needs to be initialized once, not for each row!!

     helper.writeCellImage(a_workbook, a_sheet, a_iRow, a_iCol, t_image, m_lPictures);

     // do this after generating all the images
     //resize pictures
     for (Picture pic: m_lPictures) {
Last modified 2 years ago Last modified on 12/07/2018 04:11:55 PM