Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Reworked Generators for DS selections.
* Switch Generator on SelectionChanged
* Contribute atoms to generators vis GeneratorParameter, not AtomContainer.Properties
* ITestResult contribute GeneratorParameters
* Added Visible and AtomMap parameter to Generators in DS
  • Loading branch information
olas committed Jun 30, 2010
1 parent b24acd5 commit 7ca4762
Show file tree
Hide file tree
Showing 21 changed files with 439 additions and 103 deletions.
Expand Up @@ -37,6 +37,7 @@
import net.bioclipse.ds.model.DSException;
import net.bioclipse.ds.model.IDSTest;
import net.bioclipse.ds.model.ITestResult;
import net.bioclipse.ds.model.result.PosNegIncMatch;
import net.bioclipse.ds.model.result.ScaledResultMatch;
import net.bioclipse.ds.model.result.SubStructureMatch;
import net.bioclipse.ds.signatures.business.ISignaturesManager;
Expand Down Expand Up @@ -382,7 +383,7 @@ protected List<? extends ITestResult> doRunTest( ICDKMolecule cdkmol,

//Create a new match with correct coloring
// SubStructureMatch match = new SubStructureMatch(significantSignature,ITestResult.INCONCLUSIVE);
ScaledResultMatch match = new ScaledResultMatch(significantSignature,ITestResult.INCONCLUSIVE);
PosNegIncMatch match = new PosNegIncMatch(significantSignature,ITestResult.INCONCLUSIVE);

if (prediction>0)
match.setClassification( ITestResult.POSITIVE );
Expand All @@ -398,8 +399,9 @@ protected List<? extends ITestResult> doRunTest( ICDKMolecule cdkmol,
//We should add atoms from the input cdkmol, not the clone!
// significantAtomsContainer.addAtom( cdkmol.getAtomContainer().getAtom( significantAtomNumber ));
logger.debug("center atom: " + significantAtom);
//Set to max for scaledresult
match.putAtomResult( significantAtomNumber, 100 );

//Set each atom to overall match classification
match.putAtomResult( significantAtomNumber, match.getClassification() );

//Also add all atoms connected to significant atoms to list
for (IAtom nbr : cdkmol.getAtomContainer().getConnectedAtomsList(cdkmol.getAtomContainer().getAtom( significantAtomNumber )) ){
Expand All @@ -408,17 +410,17 @@ protected List<? extends ITestResult> doRunTest( ICDKMolecule cdkmol,
// significantAtomsContainer.addAtom(atomToAdd);
logger.debug("nbr atom: " + nbrAtomNr);

//Set to max for scaledresult
match.putAtomResult( nbrAtomNr, 100 );
//Set each atom to overall match classification
match.putAtomResult( nbrAtomNr, match.getClassification() );
}
}
logger.debug("Number of center atoms: " + significantAtoms.size());

//We want to set the color of the hilighting depending on the prediction. If the decision function > 0.0 the color should be red, otherwise it should be green.
//we also want the filled circles to be larger so that they become visible for non carbons.
// match.setAtomContainer( significantAtomsContainer );
match.writeResultsAsProperties( cdkmol.getAtomContainer(),
net.bioclipse.ds.bursi.signatures.Activator.BURSI_RESULT_PROPERTY);
// match.writeResultsAsProperties( cdkmol.getAtomContainer(),
// net.bioclipse.ds.bursi.signatures.Activator.BURSI_RESULT_PROPERTY);

//We can have multiple hits...
List<ITestResult> results=new ArrayList<ITestResult>();
Expand Down
Expand Up @@ -252,7 +252,6 @@ protected List<? extends ITestResult> doRunTest( ICDKMolecule cdkmol,
match.putAtomResult( aindex, 100 );
}
match.setSmartsString( currentSmarts );
match.writeResultsAsProperties( cdkmol.getAtomContainer(), "SMARTS");

results.add( match );
}
Expand Down
Expand Up @@ -438,8 +438,7 @@ protected List<? extends ITestResult> doRunTest( ICDKMolecule cdkmol,
//we also want the filled circles to be larger so that they become visible for non carbons.
// match.setAtomContainer( significantAtomsContainer );

match.writeResultsAsProperties(cdkmol.getAtomContainer(),
net.bioclipse.ds.cpdb.signatures.Activator.CPDB_RESULT_PROPERTY);
// match.writeResultsAsProperties(cdkmol.getAtomContainer(), "BOGUS");

//We can have multiple hits...
List<ITestResult> results=new ArrayList<ITestResult>();
Expand Down
8 changes: 0 additions & 8 deletions plugins/net.bioclipse.ds.ui/plugin.xml
Expand Up @@ -2,14 +2,6 @@
<?eclipse version="3.4"?>
<plugin>


<extension
point="net.bioclipse.cdk.jchempaint.generator">
<generator
class="net.bioclipse.ds.ui.BlueRedColorScaleGenerator">
</generator>
</extension>

<extension
point="org.eclipse.ui.views">
<category
Expand Down
Expand Up @@ -17,6 +17,8 @@
import net.bioclipse.cdk.domain.ICDKMolecule;
import net.bioclipse.core.business.BioclipseException;
import net.bioclipse.ds.model.ITestResult;
import net.bioclipse.ds.model.result.BlueRedColorScaleGenerator;
import net.bioclipse.ds.model.result.PosNegIncColorGenerator;
import net.bioclipse.ds.model.result.SubStructureMatch;

import org.openscience.cdk.Molecule;
Expand Down Expand Up @@ -103,8 +105,9 @@ public static byte[] createImage( net.bioclipse.core.domain.IMolecule bcmol,

if (newMatch!=null){
BlueRedColorScaleGenerator generator=new BlueRedColorScaleGenerator();
// generator.add( newMatch );
PosNegIncColorGenerator gen2=new PosNegIncColorGenerator();
generators.add(generator);
generators.add( gen2 );
}

generators.add(new BasicAtomGenerator());
Expand Down
Expand Up @@ -20,6 +20,7 @@
import net.bioclipse.cdk.domain.CDKMolecule;
import net.bioclipse.cdk.domain.ICDKMolecule;
import net.bioclipse.cdk.jchempaint.editor.JChemPaintEditor;
import net.bioclipse.cdk.jchempaint.view.ChoiceGenerator;
import net.bioclipse.cdk.ui.sdfeditor.editor.MultiPageMoleculesEditorPart;
import net.bioclipse.core.business.BioclipseException;
import net.bioclipse.core.util.LogUtils;
Expand All @@ -30,7 +31,12 @@
import net.bioclipse.ds.model.IDSTest;
import net.bioclipse.ds.model.ITestResult;
import net.bioclipse.ds.model.TestRun;
import net.bioclipse.ds.model.result.AtomResultMatch;
import net.bioclipse.ds.model.result.BlueRedColorScaleGenerator;
import net.bioclipse.ds.model.result.PosNegIncColorGenerator;
import net.bioclipse.ds.model.result.PosNegIncMatch;
import net.bioclipse.ds.model.result.SimpleResult;
import net.bioclipse.ds.model.result.SubStructureMatch;
import net.bioclipse.ds.report.DSSingleReportModel;
import net.bioclipse.ds.report.StatusHelper;
import net.bioclipse.ds.ui.DSContextProvider;
Expand Down Expand Up @@ -70,6 +76,9 @@
import org.eclipse.swt.SWT;
import org.openscience.cdk.CDKConstants;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.renderer.RendererModel;
import org.openscience.cdk.renderer.generators.IGenerator;
import org.openscience.cdk.renderer.generators.IGeneratorParameter;

/**
*
Expand Down Expand Up @@ -204,13 +213,70 @@ public void createPartControl(Composite parent) {

public void selectionChanged( SelectionChangedEvent event ) {
updateActionStates();
turnOffAllExternalGenerators();
Object obj = ((IStructuredSelection)event.getSelection()).getFirstElement();
if ( obj instanceof ITestResult ) {
ITestResult tr = (ITestResult) obj;
selectedProperty=tr.getResultProperty();


Class<? extends IGeneratorParameter<Boolean>> visibilityParam = tr.getGeneratorVisibility();
Class<? extends IGeneratorParameter<Map<Integer, Integer>>> atomMapParam = tr.getGeneratorAtomMap();

if (visibilityParam==null){
logger.debug("The selected TestResult does not provide a generatorVisibility.");
return;
}

JChemPaintEditor jcp=getJCPfromActiveEditor();
if (jcp==null) return;

RendererModel model = jcp.getWidget().getRenderer2DModel();

//And turn only the selected on
model.set(visibilityParam, true);
logger.debug("Turned on Generator: " + tr.getGeneratorVisibility());

if (atomMapParam!=null){
if (tr instanceof AtomResultMatch) {
AtomResultMatch atomResMatch = (AtomResultMatch) tr;
model.set(atomMapParam, atomResMatch.getResultMap());
logger.debug(" ...and AtomMapGeneratorParameter is used with content.");
}else{
logger.debug(" ...however, an AtomMapGeneratorParameter is available but TestResult is not PosNegIncMatch.");
}

}
else{
logger.debug(" ...however, no AtomMapGeneratorParameter is available.");
}


}
}

private void turnOffAllExternalGenerators() {
//Switch off all other DS-generators!
List<IGenerator<IAtomContainer>> generators = ChoiceGenerator.getGeneratorsFromExtension();
for(IGenerator generator: generators) {
List<IGeneratorParameter<?>> params = generator.getParameters();
if(params.isEmpty()) continue;
for (IGeneratorParameter param : params){
if (param instanceof BlueRedColorScaleGenerator.Visibility) {
BlueRedColorScaleGenerator.Visibility v = (BlueRedColorScaleGenerator.Visibility) param;
v.setValue(false);
logger.debug("Turned off Generator: " + generator);
}
if (param instanceof PosNegIncColorGenerator.Visibility) {
PosNegIncColorGenerator.Visibility v = (PosNegIncColorGenerator.Visibility) param;
v.setValue(false);
logger.debug("Turned off Generator: " + generator);
}
// if (param instanceof IGeneratorParameter<Boolean>) {
// IGeneratorParameter<Boolean> bp= (IGeneratorParameter<Boolean>)param;
// model.set(bp, false);
// }
}
}
}

});

Expand Down
7 changes: 5 additions & 2 deletions plugins/net.bioclipse.ds/META-INF/MANIFEST.MF
Expand Up @@ -13,9 +13,12 @@ Require-Bundle: org.eclipse.ui,
net.bioclipse.cdk.business,
net.bioclipse.cdk.jchempaint,
org.openscience.cdk.interfaces,
org.openscience.cdk.nonotify
org.openscience.cdk.nonotify,
org.openscience.cdk.render;bundle-version="1.3.5",
org.openscience.cdk.renderbasic;bundle-version="1.3.5"
Bundle-ActivationPolicy: lazy
Import-Package: org.apache.log4j
Import-Package: javax.vecmath,
org.apache.log4j
Export-Package: net.bioclipse.ds,
net.bioclipse.ds.business,
net.bioclipse.ds.model,
Expand Down
10 changes: 10 additions & 0 deletions plugins/net.bioclipse.ds/plugin.xml
Expand Up @@ -12,4 +12,14 @@
</scriptContribution>
</extension>

<extension
point="net.bioclipse.cdk.jchempaint.generator">
<generator
class="net.bioclipse.ds.model.result.BlueRedColorScaleGenerator">
</generator>
<generator
class="net.bioclipse.ds.model.result.PosNegIncColorGenerator">
</generator>
</extension>

</plugin>
@@ -1,4 +1,4 @@
package net.bioclipse.ds.ui.prefs;
package net.bioclipse.ds;

/**
*
Expand Down
Expand Up @@ -10,8 +10,12 @@
******************************************************************************/
package net.bioclipse.ds.model;

import java.util.Map;

import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.swt.graphics.Image;
import org.openscience.cdk.renderer.generators.IGenerator;
import org.openscience.cdk.renderer.generators.IGeneratorParameter;

import net.bioclipse.cdk.domain.ISubStructure;

Expand Down Expand Up @@ -57,8 +61,10 @@ public interface ITestResult extends IAdaptable{

String getSuffix();

public String getResultProperty();
public void setResultProperty( String propertyKey );
// public String getResultProperty();
// public void setResultProperty( String propertyKey );

public Class<? extends IGeneratorParameter<Boolean>> getGeneratorVisibility();
public Class<? extends IGeneratorParameter<Map<Integer, Integer>>> getGeneratorAtomMap();

}
@@ -0,0 +1,37 @@
package net.bioclipse.ds.model.result;

import java.util.HashMap;
import java.util.Map;

/**
*
* @author ola
*/
public class AtomResultMatch extends SubStructureMatch{

//AtomNumber > Value
private Map<Integer, Integer> resultMap;

public AtomResultMatch(String name, int resultStatus) {
super( name, resultStatus );
resultMap=new HashMap<Integer, Integer>();
}

public void setResultMap( Map<Integer, Integer> resulMap ) {
this.resultMap = resulMap;
}

public Map<Integer, Integer> getResultMap() {
return resultMap;
}

public void putAtomResult( Integer atomToAdd, Integer result ) {
if (resultMap==null) resultMap=new HashMap<Integer, Integer>();
resultMap.put( atomToAdd, result );
if (!getAtomNumbers().contains( atomToAdd )){
getAtomNumbers().add( atomToAdd );
}

}

}

0 comments on commit 7ca4762

Please sign in to comment.