Skip to content

Commit

Permalink
Merge pull request #41 from KlasJoenssson/Debuging
Browse files Browse the repository at this point in the history
Bugfixes for the plotting from SDF-editor.
  • Loading branch information
goglepox committed Dec 10, 2013
2 parents 41b68fb + 4777361 commit 632a2f6
Show file tree
Hide file tree
Showing 10 changed files with 632 additions and 100 deletions.
Expand Up @@ -29,4 +29,5 @@ Require-Bundle: javax.vecmath,
org.openscience.cdk.rendercontrol,
org.openscience.cdk.libiocml,
org.openscience.cdk.renderswt,
org.openscience.cdk.silent
org.openscience.cdk.silent,
net.bioclipse.chart;bundle-version="2.6.2"
Expand Up @@ -22,12 +22,15 @@
import net.bioclipse.cdk.domain.CDKMolecule;
import net.bioclipse.cdk.domain.ICDKMolecule;
import net.bioclipse.cdk.jchempaint.view.JChemPaintWidget.Message;
import net.bioclipse.chart.IChartDescriptor;
import net.bioclipse.core.business.BioclipseException;
import net.bioclipse.core.domain.AtomIndexSelection;
import net.bioclipse.core.domain.IChemicalSelection;
import net.bioclipse.core.domain.IMolecule;
import net.bioclipse.core.util.LogUtils;
import net.bioclipse.jobs.BioclipseUIJob;
import net.bioclipse.model.ChartSelection;
import net.bioclipse.model.PlotPointData;

import org.apache.log4j.Logger;
import org.eclipse.core.runtime.IAdaptable;
Expand Down Expand Up @@ -60,6 +63,7 @@
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IPartListener2;
import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchPartReference;
Expand All @@ -83,7 +87,8 @@ public class JChemPaintView extends ViewPart
implements ISelectionListener, ISelectionProvider {

public static final String VIEW_ID="net.bioclipse.cdk.ui.view.Java2DRendererView";

public static final String CHART_VIEW_ID="net.bioclipse.plugins.views.ChartView";

private static final Logger logger = Logger.getLogger(JChemPaintView.class);

private JChemPaintWidget canvasView;
Expand Down Expand Up @@ -258,9 +263,24 @@ public void selectionChanged( IWorkbenchPart part, final ISelection selection )
return;
}
}
} else if ( part instanceof IViewPart ) {
if ( ((IViewPart) part).getSite().getId().equals( CHART_VIEW_ID ) ){
if( selection instanceof ChartSelection ) {
ChartSelection cSel = (ChartSelection) selection;
IChartDescriptor cd = cSel.getDescriptor();
Object obj = cSel.getFirstElement();
if (obj instanceof PlotPointData) {
int index = ((PlotPointData) obj).getRowNumber();
ICDKMolecule mol = cd.getAdapter(index-1,
ICDKMolecule.class );
if (mol != null)
setAtomContainer( mol.getAtomContainer() );
}
}
}
}
Display.getDefault().syncExec( new Runnable() {

public void run() {
reactOnSelection( selection );
}
Expand Down
@@ -0,0 +1,34 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Bioclipse Help</title>
<link rel="stylesheet" href="../../PRODUCT_PLUGIN/narrow_book.css" type="text/css">
</head>

<body>
<h1>Plot from the Molecules Table Editor</h1>
From a selection of some or all values from one or more columns there is possibly to make a plot of those values. This by right clicking on the selection and then choosing <b>Plot</b> and then select the wanted plot type in the submenu.<br><br>
<h2>Plot one column</h2>
If selecting all or only some values from one column and choosing to plot them, they will be plotted in respect to the row they are on. I.e. the x-axis will hold the row number of the values and the y-axis the values. The label on the x-axis will be "Row number" and on the y-axes the name of the column that contains the values. If a value in a cell isn't a number, then it will not be plotted. This means that if non of the values that is selected ar non-numbers the plot will be empty.<br>
<h3>The 2D-structure column</h3>
The column that displays the 2D-structure has been given a special roll in the plotting. Selecting some or all in this column will calculate and plot the mass of the molecule. The name of the axis that corresponds to this column is "Molecular mass". Because the values are calculated just before they are plotted, it might take some time if the are manny and/or lage structures.<br>
<h2>Plot two columns</h2>
If the values from two different columns are selected they will be plotted in respect to each other. Where the values of the column to the left will be on the x-axis and the one to the right on the y-axis. So by moving the columns in respect to each other its possibly to decide which columns values that are to be on which axis. The labels on the axis will corresponds to the name of the name of column the values are from.<br>
<h2>Plot several columns</h2>
Plotting values from more than two columns is only supported by the histogram and box plot alternatives for the moment.<br>
If several columns are selected and plotted as a histogram Bioclipse will take all values in those columns and divide them into a specific number of bins. The number of bins used is decided from the number of values in the selected columns.<br>
For the box plot alternative, each column will become a box and the name of the column will be printed below it's box. For example, if three columns are selected then the box plot will have three boxes.<br>
If values from more than two columns are selected for making a scatter or line plot only the values from the left-most column will be used and then plotted in respect to the row they are on, just as for selection in a single column.<br>

<h2>Selections</h2>
For more information about how the chart view works can be found <a href="../../net.bioclipse.statistics/html/ChartViewHelp.html">here</a>. However, below are some notes about selections in the chart when plotted from the Molecules Table Editor. Observe that selections does not work in histograms and box plots.<br>
When some values has been plotted then a selection in the plot will high-light the corresponding row(s) in the Molecules Table Editor. And the other way around, a selection in the Molecules Table Editor will high-light the corresponding point(s) in the plot. Observe that if the SD-file in the Molecules Table Editor are closed and then reopen the chart will not recognize it as the source for the plotted data, and therefor the interaction will not work.<br>
<h3>Selections in the Chart</h3>
Except for high-lighting in the corresponding rows a selection in the chart will show information about the selections in the properties view. Where it is located depends on the settings, but most likely it is below the Molecules Table Editor. If the view not open then it's possibly to open it via the menu <b>Window > Show view > Others... > properties view</b>.<br>
When selecting one point is selected the properties view will show the x-value of the point together with the label of the x-axis, and the y-value together with its label. If two or more values are selected the properties view will show (from the top row and down) the average value of the points, maximum value along the points, the minmum value and the number of points selected. In both the cases the properties view will show the name of file (source) that the plotted values are from. Observe that the labels of values are sorted in the alphabetic order, here-since the order of the vales when one point is selected will depend on the x- and y-labels of the chart.
<h3>Selections in the Molecules Table Editor</h3>
When making a selection in the Molecules Table Editor the properties view will show information about the molecule on the selected row. E.g. if the SD-file contains 2D- and/or 3D-coordinates, the properties etc. If several rows are selected it will show this information for the molecule, of the selected, that has the lowers row number, i.e. the molecules on the upper-most row of the selected.
</body>
</html>
96 changes: 92 additions & 4 deletions plugins/net.bioclipse.cdk.ui.sdfeditor/plugin.xml
Expand Up @@ -2,6 +2,7 @@
<?eclipse version="3.2"?>
<plugin>
<extension-point id="net.bioclipse.cdk.propertyCalculator" name="PropertyCalculator" schema="schema/net.bioclipse.cdk.propertyCalculator.exsd"/>
<extension-point id="net.bioclipse.cdk.ui.sdfeditor.plotParameter" name="Plot Parameter" schema="schema/net.bioclipse.cdk.ui.sdfeditor.plotParameter.exsd"/>
<extension
point="org.eclipse.ui.editors">
<editor
Expand Down Expand Up @@ -137,6 +138,11 @@
defaultHandler="net.bioclipse.cdk.ui.plot.ChartFromSDF"
id="net.bioclipse.chart.ui.chartFromSDF"
name="To chart">
<commandParameter
id="net.bioclipse.cdk.ui.sdfeditor.plotType"
name="Plot type"
optional="false">
</commandParameter>
</command>
</extension>

Expand Down Expand Up @@ -221,11 +227,54 @@
label="Remove Property"
style="push">
</command>
<command
<!--command
commandId="net.bioclipse.chart.ui.chartFromSDF"
label="Plot column"
style="push">
</command>
<parameter
name="net.bioclipse.cdk.ui.sdfeditor.plotType"
value="ScatterPlot">
</parameter>
</command-->
<menu
label="Plot">
<command
commandId="net.bioclipse.chart.ui.chartFromSDF"
label="Scatter Plot"
style="push">
<parameter
name="net.bioclipse.cdk.ui.sdfeditor.plotType"
value="ScatterPlot">
</parameter>
</command>
<command
commandId="net.bioclipse.chart.ui.chartFromSDF"
label="Histogram"
style="push">
<parameter
name="net.bioclipse.cdk.ui.sdfeditor.plotType"
value="Histogram">
</parameter>
</command>
<command
commandId="net.bioclipse.chart.ui.chartFromSDF"
label="Line Plot"
style="push">
<parameter
name="net.bioclipse.cdk.ui.sdfeditor.plotType"
value="LinePlot">
</parameter>
</command>
<command
commandId="net.bioclipse.chart.ui.chartFromSDF"
label="Box Plot"
style="push">
<parameter
name="net.bioclipse.cdk.ui.sdfeditor.plotType"
value="BoxPlot">
</parameter>
</command>
</menu>
</menuContribution>
<menuContribution
locationURI="popup:net.bioclipse.cdk.ui.sdfeditor.menu?before=additions">
Expand Down Expand Up @@ -311,11 +360,50 @@
name="net.bioclipse.cdk.ui.sdfeditor.extra"
visible="true">
</separator>
<command
<!--command
commandId="net.bioclipse.chart.ui.chartFromSDF"
label="Plot column"
style="push">
</command> </menuContribution>
</command-->
<menu
label="Plot">
<command
commandId="net.bioclipse.chart.ui.chartFromSDF"
label="Scatter Plot"
style="push">
<parameter
name="net.bioclipse.cdk.ui.sdfeditor.plotType"
value="ScatterPlot">
</parameter>
</command>
<command
commandId="net.bioclipse.chart.ui.chartFromSDF"
label="Histogram"
style="push">
<parameter
name="net.bioclipse.cdk.ui.sdfeditor.plotType"
value="Histogram">
</parameter>
</command>
<command
commandId="net.bioclipse.chart.ui.chartFromSDF"
label="Line Plot"
style="push">
<parameter
name="net.bioclipse.cdk.ui.sdfeditor.plotType"
value="LinePlot">
</parameter>
</command>
<command
commandId="net.bioclipse.chart.ui.chartFromSDF"
label="Box Plot"
style="push">
<parameter
name="net.bioclipse.cdk.ui.sdfeditor.plotType"
value="BoxPlot">
</parameter>
</command>
</menu> </menuContribution>
</extension>
<extension
point="net.bioclipse.scripting.contribution">
Expand Down
@@ -0,0 +1,84 @@
<?xml version='1.0' encoding='UTF-8'?>
<!-- Schema file written by PDE -->
<schema targetNamespace="net.bioclipse.cdk.ui.sdfeditor" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
<appInfo>
<meta.schema plugin="net.bioclipse.cdk.ui.sdfeditor" id="net.bioclipse.cdk.ui.sdfeditor.plotParameter" name="Plot Parameter"/>
</appInfo>
<documentation>
[Enter description of this extension point.]
</documentation>
</annotation>

<element name="extension">
<annotation>
<appInfo>
<meta.element />
</appInfo>
</annotation>
<complexType>
<attribute name="point" type="string" use="required">
<annotation>
<documentation>

</documentation>
</annotation>
</attribute>
<attribute name="id" type="string">
<annotation>
<documentation>

</documentation>
</annotation>
</attribute>
<attribute name="name" type="string">
<annotation>
<documentation>

</documentation>
<appInfo>
<meta.attribute translatable="true"/>
</appInfo>
</annotation>
</attribute>
</complexType>
</element>

<annotation>
<appInfo>
<meta.section type="since"/>
</appInfo>
<documentation>
[Enter the first release in which this extension point appears.]
</documentation>
</annotation>

<annotation>
<appInfo>
<meta.section type="examples"/>
</appInfo>
<documentation>
[Enter extension point usage example here.]
</documentation>
</annotation>

<annotation>
<appInfo>
<meta.section type="apiinfo"/>
</appInfo>
<documentation>
[Enter API information here.]
</documentation>
</annotation>

<annotation>
<appInfo>
<meta.section type="implementation"/>
</appInfo>
<documentation>
[Enter information about supplied implementation of this extension point.]
</documentation>
</annotation>


</schema>
@@ -0,0 +1,75 @@
/*******************************************************************************
* Copyright (c) 2013 Klas Jšnsson <klas.joensson@gmail.com>
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* <http://www.eclipse.org/legal/epl-v10.html>
*
* Contact: http://www.bioclipse.net/
******************************************************************************/
package net.bioclipse.cdk.smilesURL;

import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Hashtable;

import net.bioclipse.cdk.business.ICDKManager;
import net.bioclipse.cdk.business.IJavaCDKManager;
import net.bioclipse.cdk.domain.ICDKMolecule;
import net.bioclipse.chart.ChartUtils;
import net.bioclipse.core.business.BioclipseException;
import net.bioclipse.managers.business.IBioclipseManager;

import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.ServiceReference;
import org.osgi.service.url.AbstractURLStreamHandlerService;
import org.osgi.service.url.URLConstants;
import org.osgi.service.url.URLStreamHandlerService;


public class SmilesProtocol extends AbstractURLStreamHandlerService implements
BundleActivator {

@Override
public void start( BundleContext context ) throws Exception {
Hashtable<String, String[]> properties =
new Hashtable<String, String[]>();
properties.put( URLConstants.URL_HANDLER_PROTOCOL,
new String[] { "smiles" } );
context.registerService( URLStreamHandlerService.class.getName(), this,
properties );
}

@Override
public void stop( BundleContext context ) throws Exception { }

@Override
public URLConnection openConnection( URL url ) throws IOException {
return new SmilesURL( url );
}

public static ICDKMolecule smilesToMolecule(String smiles)
throws BioclipseException {
ICDKManager cdk = getManager( IJavaCDKManager.class );
return cdk.fromSMILES( smiles );
}

public static <T extends IBioclipseManager> T getManager(Class<T> clazz) {
Bundle bundle = FrameworkUtil.getBundle( ChartUtils.class );
BundleContext context = bundle.getBundleContext();
ServiceReference<T> sRef = context.getServiceReference( clazz );
if(sRef!=null) {
T manager = context.getService( sRef );
if(manager!=null){
return manager;
}

}
throw new IllegalStateException("Could not get the "+clazz.getName());
}
}

0 comments on commit 632a2f6

Please sign in to comment.