From: <mar...@us...> - 2007-08-08 19:19:37
|
Revision: 8672 http://cdk.svn.sourceforge.net/cdk/?rev=8672&view=rev Author: mario_baseda Date: 2007-08-08 12:19:30 -0700 (Wed, 08 Aug 2007) Log Message: ----------- Classes modified/added Modified Paths: -------------- trunk/cdk-taverna/.project trunk/cdk-taverna/src/main/java/org/openscience/cdk/applications/taverna/qsar/model/weka/GenerateEMCluster.java trunk/cdk-taverna/src/main/java/org/openscience/cdk/applications/taverna/qsar/model/weka/GenerateJ48WModel.java trunk/cdk-taverna/src/main/java/org/openscience/cdk/applications/taverna/qsar/model/weka/GenerateKMeanCluster.java trunk/cdk-taverna/src/main/java/org/openscience/cdk/applications/taverna/qsar/model/weka/action/GenerateKMeanClusterAction.java trunk/cdk-taverna/src/main/resources/META-INF/services/org.embl.ebi.escience.scuflui.spi.ProcessorActionSPI Added Paths: ----------- trunk/cdk-taverna/src/main/java/org/openscience/cdk/applications/taverna/qsar/model/weka/action/GenerateEMClusterAction.java trunk/cdk-taverna/src/main/java/org/openscience/cdk/applications/taverna/qsar/model/weka/action/GenerateJ48WModelAction.java Modified: trunk/cdk-taverna/.project =================================================================== --- trunk/cdk-taverna/.project 2007-08-07 15:20:11 UTC (rev 8671) +++ trunk/cdk-taverna/.project 2007-08-08 19:19:30 UTC (rev 8672) @@ -1,23 +1,13 @@ -<?xml version="1.0" encoding="UTF-8"?> -<projectDescription> - <name>cdk-taverna</name> - <comment></comment> - <projects> - </projects> - <buildSpec> - <buildCommand> - <name>org.eclipse.jdt.core.javabuilder</name> - <arguments> - </arguments> - </buildCommand> - <buildCommand> - <name>org.maven.ide.eclipse.maven2Builder</name> - <arguments> - </arguments> - </buildCommand> - </buildSpec> - <natures> - <nature>org.eclipse.jdt.core.javanature</nature> - <nature>org.maven.ide.eclipse.maven2Nature</nature> - </natures> -</projectDescription> +<projectDescription> + <name>cdk-taverna</name> + <comment/> + <projects/> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> \ No newline at end of file Modified: trunk/cdk-taverna/src/main/java/org/openscience/cdk/applications/taverna/qsar/model/weka/GenerateEMCluster.java =================================================================== --- trunk/cdk-taverna/src/main/java/org/openscience/cdk/applications/taverna/qsar/model/weka/GenerateEMCluster.java 2007-08-07 15:20:11 UTC (rev 8671) +++ trunk/cdk-taverna/src/main/java/org/openscience/cdk/applications/taverna/qsar/model/weka/GenerateEMCluster.java 2007-08-08 19:19:30 UTC (rev 8672) @@ -35,6 +35,13 @@ import uk.ac.soton.itinnovation.taverna.enactor.entities.TaskExecutionException; import org.embl.ebi.escience.baclava.DataThing; +import org.embl.ebi.escience.scufl.DuplicatePortNameException; +import org.embl.ebi.escience.scufl.InputPort; +import org.embl.ebi.escience.scufl.OutputPort; +import org.embl.ebi.escience.scufl.PortCreationException; +import org.embl.ebi.escience.scufl.XScufl; +import org.jdom.Attribute; +import org.jdom.Element; import org.openscience.cdk.libio.weka.Weka; import org.openscience.cdk.qsar.model.weka.EMCluster; @@ -42,6 +49,9 @@ import org.openscience.cdk.applications.taverna.LocalWorkerCDK; import org.openscience.cdk.applications.taverna.qsar.model.weka.Selection; import org.openscience.cdk.applications.taverna.qsar.model.weka.Standardise; +import org.openscience.cdk.applications.taverna.scuflworkers.cdk.CDKLocalWorkerWithPorts; +import org.openscience.cdk.applications.taverna.scuflworkers.cdk.CDKProcessor; +import org.openscience.cdk.applications.taverna.scuflworkers.cdk.XMLExtensible; /** * GenerateEMCluster assigns a probability distribution to each instance which indicates the probability of it @@ -66,7 +76,7 @@ * @cdk.keyword clusterers * @cdk.keyword EM */ -public class GenerateEMCluster implements LocalWorkerCDK{ +public class GenerateEMCluster implements LocalWorkerCDK, CDKLocalWorkerWithPorts, XMLExtensible{ // new instance of EM cluster private EMCluster em = new EMCluster(); // Contains the possible class attributs @@ -75,6 +85,7 @@ private String[] y = null; // Contains the dacriptor titles to select the descriptor values, which was chosen before private String[] title; + private String[] options; private String[] inputNames = new String[] { "matrix" }; private String[] outputNames = new String[] { "ModelsNumericAtts", "LogDensityPerCluster", "NumberOfCluster", "ClusterPriorsProbability", "ClusterPriors", "MaxIterations", "MinStdDev", "NumClusters", "Seed"}; @@ -95,13 +106,40 @@ return new String[] {LocalWorkerCDK.ListOfListOfDoubleList, LocalWorkerCDK.ListOfDoubleList, LocalWorkerCDK.DOUBLE, LocalWorkerCDK.DoubleList, LocalWorkerCDK.DoubleList, LocalWorkerCDK.DOUBLE, LocalWorkerCDK.DOUBLE, LocalWorkerCDK.DOUBLE, LocalWorkerCDK.DOUBLE}; } + +// Region: XML tags/attributes + private static final String EXTENSIONS = "extensions"; + private static final String GenerateEMCluster = "generateemcluster"; + private static final String OPTIONS = "options"; + /** * Constructor of the GenerateEMCluster object * */ public GenerateEMCluster(){} - + + public List<InputPort> inputPorts(CDKProcessor processor) throws DuplicatePortNameException, PortCreationException { + List<InputPort> input = new ArrayList<InputPort>(); + InputPort inPort; + for (int i = 0; i < inputNames.length; i++) { + inPort = new InputPort(processor, inputNames[i]); + inPort.setSyntacticType(inputTypes()[i]); + input.add(inPort); + } + return input; + } + public List<OutputPort> outputPorts(CDKProcessor processor) throws DuplicatePortNameException, PortCreationException { + List<OutputPort> output = new ArrayList<OutputPort>(); + OutputPort outPort; + for (int i = 0; i < outputNames.length; i++) { + outPort = new OutputPort(processor, outputNames[i]); + outPort.setSyntacticType(outputTypes()[i]); + output.add(outPort); + } + return output; + } + /** * Set the specific cluster options. * Valid options are (according weka library): @@ -116,6 +154,7 @@ */ public void setOptions(String[] options) throws Exception{ em.setOptions(options); + this.options = options; } /**Set the class attributs. That are the possible dependent values @@ -359,17 +398,46 @@ return new Double (em.getSeed()); } - /** - * Gets the current settings of the cluster - * - * @return list A List which contains the current settings as String + /**Returns the specific cluster options. + * @return A string[] which contains the the specific cluster options */ - public List getOptions(){ - List list = new ArrayList(); - String[] object = em.getOptions(); - for (String string : object) { - list.add(string); + public String[] getOptions(){ + return this.options; + } + +// Region: XML processing methods + + public void consumeXML(Element element) { + List list = element.getChildren(GenerateEMCluster, XScufl.XScuflNS); + String[] temp = new String[list.size()]; + Attribute attribute; + int i = 0; + for (Iterator iter = list.iterator(); iter.hasNext();) { + Element elements = (Element) iter.next(); + attribute = elements.getAttribute(OPTIONS + (i + 1), XScufl.XScuflNS); + temp[i] = attribute.getValue(); + i++; } - return list; + try { + setOptions(temp); + } catch (Exception ex) { + System.out.println("consumeXML_Exeption" + ex.toString()); + // TODO: handle exception + } } -} + + public Element provideXML() { + Element extensions = new Element(EXTENSIONS, XScufl.XScuflNS); + String[] temp = getOptions(); + if (temp == null) return extensions; + Element options; + for (int i = 0; i < temp.length; i++){ + options = new Element(GenerateEMCluster, XScufl.XScuflNS); + options.setAttribute(OPTIONS + (i + 1), temp[i], XScufl.XScuflNS); + extensions.addContent(options); + } + return extensions; + } + + // End of region +} \ No newline at end of file Modified: trunk/cdk-taverna/src/main/java/org/openscience/cdk/applications/taverna/qsar/model/weka/GenerateJ48WModel.java =================================================================== --- trunk/cdk-taverna/src/main/java/org/openscience/cdk/applications/taverna/qsar/model/weka/GenerateJ48WModel.java 2007-08-07 15:20:11 UTC (rev 8671) +++ trunk/cdk-taverna/src/main/java/org/openscience/cdk/applications/taverna/qsar/model/weka/GenerateJ48WModel.java 2007-08-08 19:19:30 UTC (rev 8672) @@ -35,6 +35,13 @@ import uk.ac.soton.itinnovation.taverna.enactor.entities.TaskExecutionException; import org.embl.ebi.escience.baclava.DataThing; +import org.embl.ebi.escience.scufl.DuplicatePortNameException; +import org.embl.ebi.escience.scufl.InputPort; +import org.embl.ebi.escience.scufl.OutputPort; +import org.embl.ebi.escience.scufl.PortCreationException; +import org.embl.ebi.escience.scufl.XScufl; +import org.jdom.Attribute; +import org.jdom.Element; import org.openscience.cdk.libio.weka.Weka; import org.openscience.cdk.qsar.model.weka.J48WModel; @@ -42,6 +49,9 @@ import org.openscience.cdk.applications.taverna.LocalWorkerCDK; import org.openscience.cdk.applications.taverna.qsar.model.weka.Selection; import org.openscience.cdk.applications.taverna.qsar.model.weka.Standardise; +import org.openscience.cdk.applications.taverna.scuflworkers.cdk.CDKLocalWorkerWithPorts; +import org.openscience.cdk.applications.taverna.scuflworkers.cdk.CDKProcessor; +import org.openscience.cdk.applications.taverna.scuflworkers.cdk.XMLExtensible; /** * A modeling class that provides the Quinlan's model C4.5 known as J48 @@ -58,9 +68,9 @@ * as the pruning set.(Deafult:3)</p> * <p>-B: Use binary splits for nominal attributes</p> * <p>-S: Don't perform subtree raising</p> - * <p>-L: Do not clean up alfter the tree has been built</p> + * <p>-L: Do not clean up after the tree has been built</p> * <p>-A: If set, Laplace smoothing is used for predicted probabilities</p> - * <p>-Q:The seed for reduced-error pruning</p> + * <p>-Q: The seed for reduced-error pruning</p> * * @author Mario Baseda * @cdk.require cdk-svn.jar @@ -71,7 +81,7 @@ * @cdk.keyword decision and regression trees * @cdk.keyword J48 */ -public class GenerateJ48WModel implements LocalWorkerCDK{ +public class GenerateJ48WModel implements LocalWorkerCDK, CDKLocalWorkerWithPorts, XMLExtensible{ // new instance of k mean cluster private J48WModel j48; // Contains the dacriptor titles to select the descriptor values, which was chosen before @@ -100,13 +110,40 @@ public String[] outputTypes() { return new String[] {LocalWorkerCDK.StringList}; } + +// Region: XML tags/attributes + private static final String EXTENSIONS = "extensions"; + private static final String GenerateJ48WModel = "generatej48wmodel"; + private static final String OPTIONS = "options"; + /** * Constructor of the GenerateKMeanCluster object * */ public GenerateJ48WModel(){} - + + public List<InputPort> inputPorts(CDKProcessor processor) throws DuplicatePortNameException, PortCreationException { + List<InputPort> input = new ArrayList<InputPort>(); + InputPort inPort; + for (int i = 0; i < inputNames.length; i++) { + inPort = new InputPort(processor, inputNames[i]); + inPort.setSyntacticType(inputTypes()[i]); + input.add(inPort); + } + return input; + } + public List<OutputPort> outputPorts(CDKProcessor processor) throws DuplicatePortNameException, PortCreationException { + List<OutputPort> output = new ArrayList<OutputPort>(); + OutputPort outPort; + for (int i = 0; i < outputNames.length; i++) { + outPort = new OutputPort(processor, outputNames[i]); + outPort.setSyntacticType(outputTypes()[i]); + output.add(outPort); + } + return output; + } + /** * This method gets a Map with CMLChemfiles. The molecules in this Chemfile should be classified about their * specific descriptor values. @@ -183,7 +220,7 @@ /** * Set the specific model options. - * Valid options are (according weka library): + * Valid options are (according weka library): * <p>Valid options are (according weka library):</p> * <p>-U: Use unpruned tree.</p> * <p>-C confidence: Set confidence threshold for pruning. (Defalult:0.25)</p> @@ -202,7 +239,14 @@ public void setOptions(String[] options) throws Exception{ this.options = options; } - + + /**Returns the specific model options. + * @return A string[] which contains the the specific model options + */ + public String[] getOptions(){ + return this.options; + } + /**Set the class attributs. That are the possible dependent values * @param classAttributs A String[] contains the class attributs */ @@ -228,4 +272,40 @@ } return prediction; } + +// Region: XML processing methods + + public void consumeXML(Element element) { + List list = element.getChildren(GenerateJ48WModel, XScufl.XScuflNS); + String[] temp = new String[list.size()]; + Attribute attribute; + int i = 0; + for (Iterator iter = list.iterator(); iter.hasNext();) { + Element elements = (Element) iter.next(); + attribute = elements.getAttribute(OPTIONS + (i + 1), XScufl.XScuflNS); + temp[i] = attribute.getValue(); + i++; + } + try { + setOptions(temp); + } catch (Exception ex) { + System.out.println("consumeXML_Exeption" + ex.toString()); + // TODO: handle exception + } + } + + public Element provideXML() { + Element extensions = new Element(EXTENSIONS, XScufl.XScuflNS); + String[] temp = getOptions(); + if (temp == null) return extensions; + Element options; + for (int i = 0; i < temp.length; i++){ + options = new Element(GenerateJ48WModel, XScufl.XScuflNS); + options.setAttribute(OPTIONS + (i + 1), temp[i], XScufl.XScuflNS); + extensions.addContent(options); + } + return extensions; + } + + // End of region } Modified: trunk/cdk-taverna/src/main/java/org/openscience/cdk/applications/taverna/qsar/model/weka/GenerateKMeanCluster.java =================================================================== --- trunk/cdk-taverna/src/main/java/org/openscience/cdk/applications/taverna/qsar/model/weka/GenerateKMeanCluster.java 2007-08-07 15:20:11 UTC (rev 8671) +++ trunk/cdk-taverna/src/main/java/org/openscience/cdk/applications/taverna/qsar/model/weka/GenerateKMeanCluster.java 2007-08-08 19:19:30 UTC (rev 8672) @@ -328,7 +328,6 @@ */ public void setOptions(String[] options) throws Exception{ kMean.setOptions(options); - this.options = new String[2]; this.options = options; } Added: trunk/cdk-taverna/src/main/java/org/openscience/cdk/applications/taverna/qsar/model/weka/action/GenerateEMClusterAction.java =================================================================== --- trunk/cdk-taverna/src/main/java/org/openscience/cdk/applications/taverna/qsar/model/weka/action/GenerateEMClusterAction.java (rev 0) +++ trunk/cdk-taverna/src/main/java/org/openscience/cdk/applications/taverna/qsar/model/weka/action/GenerateEMClusterAction.java 2007-08-08 19:19:30 UTC (rev 8672) @@ -0,0 +1,302 @@ +/* + * $Author$ + * $Date$ + * $Revision$ + * + * Copyright (C) 2007 by Mario Baseda <mar...@us...> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 + * of the License, or (at your option) any later version. + * All we ask is that proper credit is given for our work, which includes + * - but is not limited to - adding the above copyright notice to the beginning + * of your source code files, and to any copyright notice that you may distribute + * with programs based on this work. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +package org.openscience.cdk.applications.taverna.qsar.model.weka.action; + +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ItemEvent; +import java.awt.event.ActionListener; +import java.awt.event.ItemListener; +import java.awt.Container; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import javax.swing.ImageIcon; +import javax.swing.JComponent; +import javax.swing.JFrame; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.SpinnerNumberModel; +import javax.swing.JSpinner; +import javax.swing.WindowConstants; +import javax.swing.SpringLayout.Constraints; +import javax.swing.SpringLayout; +import javax.swing.Spring; + +import org.embl.ebi.escience.scuflui.shared.UIUtils; +import org.embl.ebi.escience.scufl.Processor; +import org.embl.ebi.escience.scuflui.TavernaIcons; +import org.openscience.cdk.applications.taverna.actions.AbstractCDKProcessorAction; +import org.openscience.cdk.applications.taverna.qsar.model.weka.GenerateEMCluster; +import org.openscience.cdk.applications.taverna.scuflworkers.cdk.CDKProcessor; + +public class GenerateEMClusterAction extends AbstractCDKProcessorAction { + private static JFrame frame; + + @Override + public JComponent getComponent(Processor processor) { + return null; + } + + public boolean canHandle(Processor processor) { + if (!(processor instanceof CDKProcessor)) { + return false; + } + CDKProcessor proc = (CDKProcessor) processor; + if (proc.getWorker() instanceof GenerateEMCluster) { + return true; + } + else { + return false; + } + } + + public String getDescription() { + return "Set Options"; + } + + public Dimension getFrameSize() { + // should be small enought due to using a file dialog + return new Dimension(1, 1); + } + + public ImageIcon getIcon() { + return TavernaIcons.editIcon; + } + + @Override + public JFrame getFrame(Processor processor) { + if (!(processor instanceof CDKProcessor)) { + return null; + } + CDKProcessor proc = (CDKProcessor) processor; + final List<String> options = new ArrayList<String>(); + final GenerateEMCluster generator = (GenerateEMCluster) proc.getWorker(); + String[] pastOptions = generator.getOptions(); + frame = new JFrame("Set option for the EMCluster"); + Container contentPane = frame.getContentPane(); + SpringLayout layout = new SpringLayout(); + contentPane.setLayout(layout); + Spring x = Spring.constant(5); + Spring y = Spring.constant(5); + Spring xGes = x; + final JCheckBox cb1 = new JCheckBox("Specify the number of clusters to generate", false); + final JCheckBox cb2 = new JCheckBox("Specify the random number seed ", false); + final JCheckBox cb3 = new JCheckBox("Verbose", false); + final JCheckBox cb4 = new JCheckBox("Set the minimum allowable standard deviation for normal density calculation", false); + final JCheckBox cb5 = new JCheckBox("Terminate after this many iterations if EM has not converged ", false); + SpinnerNumberModel model1 = new SpinnerNumberModel(1, 1, null, 1); + SpinnerNumberModel model2 = new SpinnerNumberModel(1, 1, null, 1); + SpinnerNumberModel model3 = new SpinnerNumberModel(0.001, 0.001, null, 0.001); + SpinnerNumberModel model4 = new SpinnerNumberModel(1, 1, null, 1); + final JSpinner spin1 = new JSpinner(model1); + final JSpinner spin2 = new JSpinner(model2); + final JSpinner spin3 = new JSpinner(model3); + final JSpinner spin4 = new JSpinner(model4); + final JButton button2 = new JButton(" OK "); + final JButton button1 = new JButton("Cancel"); + Constraints c = layout.getConstraints(cb1); + c.setX(xGes); + xGes = Spring.sum(xGes, c.getConstraint("East")); + c.setY(y); + contentPane.add(cb1); + c = layout.getConstraints(spin1); + c.setX(xGes); + c.setWidth(Spring.constant(80)); + c.setY(y); + contentPane.add(spin1); + c = layout.getConstraints(cb2); + c.setX(x); + c.setY(Spring.sum(y, layout.getConstraints(cb1).getConstraint("South"))); + contentPane.add(cb2); + c = layout.getConstraints(spin2); + c.setX(xGes); + c.setWidth(Spring.constant(80)); + c.setY(Spring.sum(y, layout.getConstraints(cb1).getConstraint("South"))); + contentPane.add(spin2); + c = layout.getConstraints(cb3); + c.setX(x); + c.setY(Spring.sum(Spring.constant(30), layout.getConstraints(cb2).getConstraint("South"))); + contentPane.add(cb3); + c = layout.getConstraints(cb4); + c.setX(x); + c.setY(Spring.sum(y, layout.getConstraints(cb3).getConstraint("South"))); + xGes = Spring.sum(x, c.getConstraint("East")); + contentPane.add(cb4); + c = layout.getConstraints(spin3); + c.setX(xGes); + c.setWidth(Spring.constant(80)); + c.setY(Spring.sum(y, layout.getConstraints(cb3).getConstraint("South"))); + contentPane.add(spin3); + c = layout.getConstraints(cb5); + c.setX(x); + c.setY(Spring.sum(y, layout.getConstraints(cb4).getConstraint("South"))); + contentPane.add(cb5); + c = layout.getConstraints(spin4); + c.setX(xGes); + c.setWidth(Spring.constant(80)); + c.setY(Spring.sum(y, layout.getConstraints(cb4).getConstraint("South"))); + contentPane.add(spin4); + c = layout.getConstraints(button1); + Spring s1 = Spring.constant(480); + Spring s2 = c.getWidth(); + s2 = Spring.minus(s2); + x = Spring.sum(s1, s2); + c.setX(x); + c.setY(Spring.sum(Spring.constant(20), layout.getConstraints(cb5).getConstraint("South"))); + contentPane.add(button1); + c = layout.getConstraints(button2); + s1 = layout.getConstraints(button1).getConstraint("West"); + s2 = Spring.sum(Spring.constant(10), c.getWidth()); + s2 = Spring.minus(s2); + x = Spring.sum(s1, s2); + c.setX(x); + c.setY(Spring.sum(Spring.constant(20), layout.getConstraints(cb5).getConstraint("South"))); + contentPane.add(button2); + spin1.setVisible(false); + spin2.setVisible(false); + spin3.setVisible(false); + spin4.setVisible(false); + if (pastOptions != null && pastOptions.length != 0){ + for (int i = 0; i < pastOptions.length; i++) { + if (pastOptions[i].startsWith("-")){ + if (pastOptions[i].equals("-N")){ + cb1.setSelected(true); + model1.setValue(Integer.parseInt(pastOptions[i+1])); + spin1.setVisible(true); + } + if (pastOptions[i].equals("-S")){ + cb2.setSelected(true); + model2.setValue(Integer.parseInt(pastOptions[i+1])); + spin2.setVisible(true); + } + if (pastOptions[i].equals("-V")) cb3.setSelected(true); + if (pastOptions[i].equals("-M")){ + cb4.setSelected(true); + model3.setValue(Double.parseDouble(pastOptions[i+1])); + spin3.setVisible(true); + } + if (pastOptions[i].equals("-I")){ + cb5.setSelected(true); + model4.setValue(Integer.parseInt(pastOptions[i+1])); + spin4.setVisible(true); + } + } + } + } + ItemListener il1 = new ItemListener() { + public void itemStateChanged(ItemEvent e){ + if (cb2.isSelected()){ + cb2.setSelected(false); + } + if ((!(cb1.isSelected())) && (!(cb2.isSelected()))){ + spin1.setVisible(false); + spin2.setVisible(false); + } + if (cb1.isSelected()) { + spin1.setVisible(true); + spin2.setVisible(false); + } + } + }; + ItemListener il2 = new ItemListener() { + public void itemStateChanged(ItemEvent e2){ + if (cb1.isSelected()){ + cb1.setSelected(false); + } + if ((!(cb1.isSelected())) && (!(cb2.isSelected()))){ + spin1.setVisible(false); + spin2.setVisible(false); + } + if (cb2.isSelected()){ + spin1.setVisible(false); + spin2.setVisible(true); + } + } + }; + ItemListener il3 = new ItemListener() { + public void itemStateChanged(ItemEvent e3){ + if (cb4.isSelected()) spin3.setVisible(true); + else spin3.setVisible(false); + if (cb5.isSelected()) spin4.setVisible(true); + else spin4.setVisible(false); + } + }; + cb1.addItemListener(il1); + cb2.addItemListener(il2); + cb3.addItemListener(il3); + cb4.addItemListener(il3); + cb5.addItemListener(il3); + ActionListener ai = new ActionListener() { + public void actionPerformed (ActionEvent ae){ + if (ae.getActionCommand() == " OK "){ + if (cb1.isSelected()){ + options.add("-N"); + options.add(String.valueOf((Integer) spin1.getValue())); + } + if (cb2.isSelected()){ + options.add("-S"); + options.add(String.valueOf((Integer) spin2.getValue())); + } + if (cb3.isSelected()) options.add("-V"); + if (cb4.isSelected()) { + options.add("-M"); + options.add(String.valueOf((Double) spin3.getValue())); + } + if (cb5.isSelected()) { + options.add("-I"); + options.add(String.valueOf((Integer) spin4.getValue())); + } + String[] option = new String[options.size()]; + int i = 0; + for (Iterator iter = options.iterator(); iter.hasNext();) { + String element = (String) iter.next(); + option[i] = element; + i++; + } + try{ + generator.setOptions(option); + }catch(Exception exception){ + exception.getStackTrace(); + } + frame.dispose(); + } else { + if (ae.getActionCommand() == "Cancel"){ + frame.dispose();; + } + } + } + }; + button1.addActionListener(ai); + button2.addActionListener(ai); + frame.setSize(500, 260); + frame.setLocationByPlatform(true); + frame.setVisible(true); + frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); + return null; + } +} \ No newline at end of file Added: trunk/cdk-taverna/src/main/java/org/openscience/cdk/applications/taverna/qsar/model/weka/action/GenerateJ48WModelAction.java =================================================================== --- trunk/cdk-taverna/src/main/java/org/openscience/cdk/applications/taverna/qsar/model/weka/action/GenerateJ48WModelAction.java (rev 0) +++ trunk/cdk-taverna/src/main/java/org/openscience/cdk/applications/taverna/qsar/model/weka/action/GenerateJ48WModelAction.java 2007-08-08 19:19:30 UTC (rev 8672) @@ -0,0 +1,393 @@ +/* + * $Author$ + * $Date$ + * $Revision$ + * + * Copyright (C) 2007 by Mario Baseda <mar...@us...> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 + * of the License, or (at your option) any later version. + * All we ask is that proper credit is given for our work, which includes + * - but is not limited to - adding the above copyright notice to the beginning + * of your source code files, and to any copyright notice that you may distribute + * with programs based on this work. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +package org.openscience.cdk.applications.taverna.qsar.model.weka.action; + +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ItemEvent; +import java.awt.event.ActionListener; +import java.awt.event.ItemListener; +import java.awt.Container; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import javax.swing.ImageIcon; +import javax.swing.JComponent; +import javax.swing.JFrame; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.SpinnerNumberModel; +import javax.swing.JSpinner; +import javax.swing.WindowConstants; +import javax.swing.SpringLayout.Constraints; +import javax.swing.SpringLayout; +import javax.swing.Spring; + +import org.embl.ebi.escience.scuflui.shared.UIUtils; +import org.embl.ebi.escience.scufl.Processor; +import org.embl.ebi.escience.scuflui.TavernaIcons; +import org.openscience.cdk.applications.taverna.actions.AbstractCDKProcessorAction; +import org.openscience.cdk.applications.taverna.qsar.model.weka.GenerateJ48WModel; +import org.openscience.cdk.applications.taverna.scuflworkers.cdk.CDKProcessor; + +public class GenerateJ48WModelAction extends AbstractCDKProcessorAction { + private static JFrame frame; + + @Override + public JComponent getComponent(Processor processor) { + return null; + } + + public boolean canHandle(Processor processor) { + if (!(processor instanceof CDKProcessor)) { + return false; + } + CDKProcessor proc = (CDKProcessor) processor; + if (proc.getWorker() instanceof GenerateJ48WModel) { + return true; + } + else { + return false; + } + } + + public String getDescription() { + return "Set Options"; + } + + public Dimension getFrameSize() { + // should be small enought due to using a file dialog + return new Dimension(1, 1); + } + + public ImageIcon getIcon() { + return TavernaIcons.editIcon; + } + + @Override + public JFrame getFrame(Processor processor) { + if (!(processor instanceof CDKProcessor)) { + return null; + } + CDKProcessor proc = (CDKProcessor) processor; + final List<String> options = new ArrayList<String>(); + final GenerateJ48WModel generator = (GenerateJ48WModel) proc.getWorker(); + String[] pastOptions = generator.getOptions(); + frame = new JFrame("Set option for the J48WModel"); + Container contentPane = frame.getContentPane(); + SpringLayout layout = new SpringLayout(); + contentPane.setLayout(layout); + Spring x = Spring.constant(5); + Spring y = Spring.constant(5); + Spring xGes = x; + final JCheckBox cb1 = new JCheckBox("Use unpruned tree", false); + final JCheckBox cb2 = new JCheckBox("Set confidence threshold for pruning ", false); + final JCheckBox cb3 = new JCheckBox("Use reduced error pruning. No subte raising is performed", false); + final JCheckBox cb4 = new JCheckBox("Don't perform subtree raising", false); + final JCheckBox cb5 = new JCheckBox("Set number of folds for reduced error pruning. One fold is used as the pruning set", false); + final JCheckBox cb6 = new JCheckBox("Set minimum number of instances per leaf", false); + final JCheckBox cb7 = new JCheckBox("The seed for reduced-error pruning ", false); + final JCheckBox cb8 = new JCheckBox("Use binary splits for nominal attributes", false); + final JCheckBox cb9 = new JCheckBox("Do not clean up after the tree has been built", false); + final JCheckBox cb10 = new JCheckBox("If set, Laplace smoothing is used for predicted probabilities", false); + SpinnerNumberModel model1 = new SpinnerNumberModel(0.01, 0.01, null, 0.01); + SpinnerNumberModel model2 = new SpinnerNumberModel(2, 2, null, 1); + SpinnerNumberModel model3 = new SpinnerNumberModel(1, 1, null, 1); + SpinnerNumberModel model4 = new SpinnerNumberModel(1, 1, null, 1); + final JSpinner spin1 = new JSpinner(model1); + final JSpinner spin2 = new JSpinner(model2); + final JSpinner spin3 = new JSpinner(model3); + final JSpinner spin4 = new JSpinner(model4); + final JButton button2 = new JButton(" OK "); + final JButton button1 = new JButton("Cancel"); + Constraints c = layout.getConstraints(cb1); + c.setX(xGes); + //xGes = Spring.sum(xGes, c.getConstraint("East")); + c.setY(y); + contentPane.add(cb1); + c = layout.getConstraints(cb2); + c.setX(xGes); + c.setY(Spring.sum(y, layout.getConstraints(cb1).getConstraint("South"))); + xGes = Spring.sum(Spring.constant(10), layout.getConstraints(cb6).getConstraint("East")); + contentPane.add(cb2); + c = layout.getConstraints(spin1); + c.setX(xGes); + c.setWidth(Spring.constant(80)); + c.setY(Spring.sum(y, layout.getConstraints(cb1).getConstraint("South"))); + xGes = Spring.sum(x, c.getConstraint("East")); + contentPane.add(spin1); + c = layout.getConstraints(cb3); + c.setX(x); + c.setY(Spring.sum(y, layout.getConstraints(cb2).getConstraint("South"))); + contentPane.add(cb3); + c = layout.getConstraints(cb4); + c.setX(xGes); + Spring xG = xGes; + c.setY(Spring.sum(y, layout.getConstraints(cb1).getConstraint("South"))); + contentPane.add(cb4); + c = layout.getConstraints(cb5); + c.setX(xGes); + c.setY(Spring.sum(y, layout.getConstraints(cb4).getConstraint("South"))); + xGes = Spring.sum(x, c.getConstraint("East")); + contentPane.add(cb5); + c = layout.getConstraints(spin2); + c.setX(xGes); + c.setWidth(Spring.constant(80)); + c.setY(Spring.sum(y, layout.getConstraints(cb4).getConstraint("South"))); + contentPane.add(spin2); + c = layout.getConstraints(cb6); + c.setX(x); + c.setY(Spring.sum(Spring.constant(30), layout.getConstraints(cb3).getConstraint("South"))); + xGes = Spring.sum(x, c.getConstraint("East")); + contentPane.add(cb6); + c = layout.getConstraints(spin3); + c.setX(xGes); + c.setWidth(Spring.constant(80)); + c.setY(Spring.sum(Spring.constant(30), layout.getConstraints(cb3).getConstraint("South"))); + contentPane.add(spin3); + c = layout.getConstraints(cb7); + c.setX(x); + c.setY(Spring.sum(y, layout.getConstraints(cb6).getConstraint("South"))); + contentPane.add(cb7); + c = layout.getConstraints(spin4); + c.setX(xGes); + c.setWidth(Spring.constant(80)); + c.setY(Spring.sum(y, layout.getConstraints(cb6).getConstraint("South"))); + contentPane.add(spin4); + c = layout.getConstraints(cb8); + c.setX(x); + c.setY(Spring.sum(y, layout.getConstraints(cb7).getConstraint("South"))); + contentPane.add(cb8); + c = layout.getConstraints(cb9); + c.setX(xG); + c.setY(Spring.sum(Spring.constant(30), layout.getConstraints(cb3).getConstraint("South"))); + contentPane.add(cb9); + c = layout.getConstraints(cb10); + c.setX(xG); + c.setY(Spring.sum(y, layout.getConstraints(cb9).getConstraint("South"))); + contentPane.add(cb10); + c = layout.getConstraints(button1); + Spring s1 = Spring.constant(830); + Spring s2 = c.getWidth(); + s2 = Spring.minus(s2); + x = Spring.sum(s1, s2); + c.setX(x); + c.setY(Spring.sum(Spring.constant(20), layout.getConstraints(cb8).getConstraint("South"))); + contentPane.add(button1); + c = layout.getConstraints(button2); + s1 = layout.getConstraints(button1).getConstraint("West"); + s2 = Spring.sum(Spring.constant(10), c.getWidth()); + s2 = Spring.minus(s2); + x = Spring.sum(s1, s2); + c.setX(x); + c.setY(Spring.sum(Spring.constant(20), layout.getConstraints(cb8).getConstraint("South"))); + contentPane.add(button2); + spin1.setVisible(false); + spin2.setVisible(false); + spin3.setVisible(false); + spin4.setVisible(false); + cb4.setVisible(false); + cb5.setVisible(false); + if (pastOptions != null && pastOptions.length != 0){ + for (int i = 0; i < pastOptions.length; i++) { + if (pastOptions[i].startsWith("-")){ + if (pastOptions[i].equals("-C")){ + cb2.setSelected(true); + model1.setValue(Double.parseDouble(pastOptions[i+1])); + spin1.setVisible(true); + cb4.setVisible(true); + } + if (pastOptions[i].equals("-N")){ + cb5.setSelected(true); + cb5.setVisible(true); + model2.setValue(Integer.parseInt(pastOptions[i+1])); + spin2.setVisible(true); + } + if (pastOptions[i].equals("-M")){ + cb6.setSelected(true); + model3.setValue(Integer.parseInt(pastOptions[i+1])); + spin3.setVisible(true); + } + if (pastOptions[i].equals("-Q")){ + cb7.setSelected(true); + model4.setValue(Integer.parseInt(pastOptions[i+1])); + spin4.setVisible(true); + } + if (pastOptions[i].equals("-U")) cb1.setSelected(true); + if (pastOptions[i].equals("-R")) { + cb3.setSelected(true); + cb4.setVisible(true); + cb5.setVisible(true); + spin2.setVisible(true); + } + if (pastOptions[i].equals("-S")) { + cb4.setSelected(true); + cb4.setVisible(true); + } + if (pastOptions[i].equals("-B")) cb8.setSelected(true); + if (pastOptions[i].equals("-L")) cb9.setSelected(true); + if (pastOptions[i].equals("-A")) cb10.setSelected(true); + } + } + } + ItemListener il1 = new ItemListener() { + public void itemStateChanged(ItemEvent e){ + if (cb2.isSelected()) cb2.setSelected(false); + if (cb3.isSelected()) cb3.setSelected(false); + if (cb1.isSelected()){ + spin1.setVisible(false); + cb4.setVisible(false); + cb5.setVisible(false); + } + if (!(cb2.isSelected())){ + spin1.setVisible(false); + cb4.setVisible(false); + } + if (!(cb3.isSelected())){ + cb4.setVisible(false); + cb5.setVisible(false); + cb5.setSelected(false); + spin2.setVisible(false); + } + } + }; + ItemListener il2 = new ItemListener() { + public void itemStateChanged(ItemEvent e){ + if (cb1.isSelected()) cb1.setSelected(false); + if (cb3.isSelected()) cb3.setSelected(false); + if (cb2.isSelected()){ + spin1.setVisible(true); + cb4.setVisible(true); + cb5.setVisible(false); + } + if (!(cb2.isSelected())){ + spin1.setVisible(false); + cb4.setVisible(false); + } + if (!(cb3.isSelected())){ + cb5.setVisible(false); + cb5.setSelected(false); + spin2.setVisible(false); + } + } + }; + ItemListener il3 = new ItemListener() { + public void itemStateChanged(ItemEvent e){ + if (cb1.isSelected()) cb1.setSelected(false); + if (cb2.isSelected()) cb2.setSelected(false); + if (cb3.isSelected()){ + spin1.setVisible(false); + cb4.setVisible(true); + cb5.setVisible(true); + } + if (!(cb2.isSelected())){ + spin1.setVisible(false); + } + if (!(cb3.isSelected())){ + cb4.setVisible(false); + cb5.setVisible(false); + cb5.setSelected(false); + spin2.setVisible(false); + } + } + }; + ItemListener il4 = new ItemListener() { + public void itemStateChanged(ItemEvent e){ + if (cb5.isSelected()) spin2.setVisible(true); + else spin2.setVisible(false); + if (cb6.isSelected()) spin3.setVisible(true); + else spin3.setVisible(false); + if (cb7.isSelected()) spin4.setVisible(true); + else spin4.setVisible(false); + } + }; + cb1.addItemListener(il1); + cb2.addItemListener(il2); + cb3.addItemListener(il3); + cb4.addItemListener(il4); + cb5.addItemListener(il4); + cb6.addItemListener(il4); + cb7.addItemListener(il4); + cb8.addItemListener(il4); + cb9.addItemListener(il4); + cb10.addItemListener(il4); + ActionListener ai = new ActionListener() { + public void actionPerformed (ActionEvent ae){ + if (ae.getActionCommand() == " OK "){ + if (cb1.isSelected()){ + options.add("-U"); + } + if (cb2.isSelected()){ + options.add("-C"); + options.add(String.valueOf((Double) spin1.getValue())); + } + if (cb3.isSelected()) options.add("-R"); + if (cb4.isSelected()) options.add("-S"); + if (cb5.isSelected()) { + options.add("-N"); + options.add(String.valueOf((Integer) spin2.getValue())); + } + if (cb6.isSelected()) { + options.add("-M"); + options.add(String.valueOf((Integer) spin3.getValue())); + } + if (cb7.isSelected()) { + options.add("-Q"); + options.add(String.valueOf((Integer) spin4.getValue())); + } + if (cb8.isSelected()) options.add("-B"); + if (cb9.isSelected()) options.add("-L"); + if (cb10.isSelected()) options.add("-A"); + String[] option = new String[options.size()]; + int i = 0; + for (Iterator iter = options.iterator(); iter.hasNext();) { + String element = (String) iter.next(); + option[i] = element; + i++; + } + try{ + generator.setOptions(option); + }catch(Exception exception){ + exception.getStackTrace(); + } + frame.dispose(); + } else { + if (ae.getActionCommand() == "Cancel"){ + frame.dispose();; + } + } + } + }; + button1.addActionListener(ai); + button2.addActionListener(ai); + frame.setSize(860, 290); + frame.setLocationByPlatform(true); + frame.setVisible(true); + frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); + return null; + } +} Modified: trunk/cdk-taverna/src/main/java/org/openscience/cdk/applications/taverna/qsar/model/weka/action/GenerateKMeanClusterAction.java =================================================================== --- trunk/cdk-taverna/src/main/java/org/openscience/cdk/applications/taverna/qsar/model/weka/action/GenerateKMeanClusterAction.java 2007-08-07 15:20:11 UTC (rev 8671) +++ trunk/cdk-taverna/src/main/java/org/openscience/cdk/applications/taverna/qsar/model/weka/action/GenerateKMeanClusterAction.java 2007-08-08 19:19:30 UTC (rev 8672) @@ -92,6 +92,7 @@ } CDKProcessor proc = (CDKProcessor) processor; final GenerateKMeanCluster generator = (GenerateKMeanCluster) proc.getWorker(); + String[] pastOptions = generator.getOptions(); frame = new JFrame("Set option for the KMeanCluster"); Container contentPane = frame.getContentPane(); SpringLayout layout = new SpringLayout(); @@ -132,7 +133,7 @@ s2 = Spring.minus(s2); x = Spring.sum(s1, s2); c.setX(x); - c.setY(Spring.sum(y, layout.getConstraints(cb2).getConstraint("South"))); + c.setY(Spring.sum(Spring.constant(20), layout.getConstraints(cb2).getConstraint("South"))); contentPane.add(button1); c = layout.getConstraints(button2); s1 = layout.getConstraints(button1).getConstraint("West"); @@ -140,10 +141,26 @@ s2 = Spring.minus(s2); x = Spring.sum(s1, s2); c.setX(x); - c.setY(Spring.sum(y, layout.getConstraints(cb2).getConstraint("South"))); + c.setY(Spring.sum(Spring.constant(20), layout.getConstraints(cb2).getConstraint("South"))); contentPane.add(button2); spin1.setVisible(false); - spin2.setVisible(false); + spin2.setVisible(false); + if (pastOptions != null && pastOptions.length != 0){ + for (int i = 0; i < pastOptions.length; i++) { + if (pastOptions[i].startsWith("-")){ + if (pastOptions[i].equals("-N")){ + cb1.setSelected(true); + model1.setValue(Integer.parseInt(pastOptions[i+1])); + spin1.setVisible(true); + } + if (pastOptions[i].equals("-S")){ + cb2.setSelected(true); + model2.setValue(Integer.parseInt(pastOptions[i+1])); + spin2.setVisible(true); + } + } + } + } ItemListener il1 = new ItemListener() { public void itemStateChanged(ItemEvent e){ if (cb2.isSelected()){ @@ -207,7 +224,7 @@ }; button1.addActionListener(ai); button2.addActionListener(ai); - frame.setSize(420, 135); + frame.setSize(420, 145); frame.setLocationByPlatform(true); frame.setVisible(true); frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); Modified: trunk/cdk-taverna/src/main/resources/META-INF/services/org.embl.ebi.escience.scuflui.spi.ProcessorActionSPI =================================================================== --- trunk/cdk-taverna/src/main/resources/META-INF/services/org.embl.ebi.escience.scuflui.spi.ProcessorActionSPI 2007-08-07 15:20:11 UTC (rev 8671) +++ trunk/cdk-taverna/src/main/resources/META-INF/services/org.embl.ebi.escience.scuflui.spi.ProcessorActionSPI 2007-08-08 19:19:30 UTC (rev 8672) @@ -1,4 +1,6 @@ org.openscience.cdk.applications.taverna.io.action.ReadMDLMolFileAction org.openscience.cdk.applications.taverna.io.action.FileReaderAction org.openscience.cdk.applications.taverna.jchempaint.action.JChemPaintEditorAction -org.openscience.cdk.applications.taverna.qsar.model.weka.action.GenerateKMeanClusterAction \ No newline at end of file +org.openscience.cdk.applications.taverna.qsar.model.weka.action.GenerateKMeanClusterAction +org.openscience.cdk.applications.taverna.qsar.model.weka.action.GenerateEMClusterAction +org.openscience.cdk.applications.taverna.qsar.model.weka.action.GenerateJ48WModelAction \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |