Skip to content

Commit

Permalink
Implemented regression models for NN and exact match.
Browse files Browse the repository at this point in the history
* Refactored all SDFmodels at the same time.
  • Loading branch information
olas committed Mar 2, 2012
1 parent cfe1663 commit 4e47d77
Show file tree
Hide file tree
Showing 23 changed files with 578 additions and 819 deletions.
6 changes: 4 additions & 2 deletions plugins/net.bioclipse.ds.ahr/plugin.xml
Expand Up @@ -24,11 +24,12 @@
endpoint="net.bioclipse.ds.ahr"
override="true"
propertycalculator="AHR Exact Match"
class="net.bioclipse.ds.matcher.SDFPosNegExactMatchSignatures">
class="net.bioclipse.ds.matcher.SDFExactMatcherSignatures">
<resource name="file"
path="data/2796_nosalts_molsign.sdf">
</resource>
<parameter name="responseProperty" value="c#Activity" />
<parameter name="isClassification" value="true" />
<parameter name="positiveValue" value="2" />
<parameter name="negativeValue" value="1" />

Expand All @@ -44,14 +45,15 @@
id="ahr.lookup.nearest"
name="AHR nearest neighbour"
endpoint="net.bioclipse.ds.ahr"
class="net.bioclipse.ds.matcher.SDFPosNegNearestMatchFP"
class="net.bioclipse.ds.matcher.SDFNearestMatchFP"
propertycalculator="AHR Nearest Neighbours"
consensus="net.bioclipse.ds.consensus.majority.emptyinconclusive">
<resource name="file"
path="data/2796_nosalts_fp.sdf">
</resource>
<parameter name="distance.tanimoto" value="0.7" />
<parameter name="responseProperty" value="c#Activity" />
<parameter name="isClassification" value="true" />
<parameter name="positiveValue" value="2" />
<parameter name="negativeValue" value="1" />

Expand Down
6 changes: 4 additions & 2 deletions plugins/net.bioclipse.ds.ames/plugin.xml
Expand Up @@ -24,13 +24,14 @@
id="ames.lookup.exact"
name="Ames exact matches"
endpoint="net.bioclipse.ds.mutagenicity"
class="net.bioclipse.ds.matcher.SDFPosNegExactMatchSignatures"
class="net.bioclipse.ds.matcher.SDFExactMatcherSignatures"
propertycalculator="Ames Exact Match"
override="true">
<resource name="file"
path="data/bursi_nosalts_molsign.sdf">
</resource>
<parameter name="responseProperty" value="Ames test categorisation" />
<parameter name="isClassification" value="true" />
<parameter name="positiveValue" value="mutagen" />
<parameter name="negativeValue" value="nonmutagen" />

Expand All @@ -46,14 +47,15 @@
id="ames.lookup.nearest"
name="Ames nearest neighbour"
endpoint="net.bioclipse.ds.mutagenicity"
class="net.bioclipse.ds.matcher.SDFPosNegNearestMatchFP"
class="net.bioclipse.ds.matcher.SDFNearestMatchFP"
consensus="net.bioclipse.ds.consensus.majority.emptyinconclusive"
propertycalculator="Ames Nearest Neighbours">
<resource name="file"
path="data/bursi_nosalts_fp.sdf">
</resource>
<parameter name="distance.tanimoto" value="0.7" />
<parameter name="responseProperty" value="Ames test categorisation" />
<parameter name="isClassification" value="true" />
<parameter name="positiveValue" value="mutagen" />
<parameter name="negativeValue" value="nonmutagen" />

Expand Down
2 changes: 1 addition & 1 deletion plugins/net.bioclipse.ds.common/.classpath
Expand Up @@ -2,6 +2,6 @@
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry excluding="net/bioclipse/ds/matcher/SDFPosNegExactMatchFP.java|net/bioclipse/ds/matcher/SDFPosNegExactMatchInchi.java|net/bioclipse/ds/matcher/SDFPosNegNearestMatchFP.java" kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Expand Up @@ -12,7 +12,6 @@

import java.util.List;

import net.bioclipse.ds.model.IConsensusCalculator;
import net.bioclipse.ds.model.ITestResult;


Expand Down
Expand Up @@ -12,7 +12,6 @@

import java.util.List;

import net.bioclipse.ds.model.IConsensusCalculator;
import net.bioclipse.ds.model.ITestResult;


Expand Down
@@ -0,0 +1,158 @@
/* *****************************************************************************
* Copyright (c) 2010 Ola Spjuth.
* 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
*
* Contributors:
* Ola Spjuth - initial API and implementation
******************************************************************************/
package net.bioclipse.ds.matcher;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.bioclipse.cdk.domain.ICDKMolecule;
import net.bioclipse.core.util.LogUtils;
import net.bioclipse.ds.model.DSException;
import net.bioclipse.ds.model.IDSTest;
import net.bioclipse.ds.model.ITestResult;
import net.bioclipse.ds.model.result.ExternalMoleculeMatch;

import org.apache.log4j.Logger;
import org.eclipse.core.runtime.IProgressMonitor;
import org.openscience.cdk.CDKConstants;


/**
* Exact match implementation for SDFiles using Signatures
*
* @author ola
*
*/
public abstract class BaseSDFExactMatcher extends BaseSDFMatcher implements IDSTest{

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

/**
* We require mol sign as property in SDFile
*/
@Override
public List<String> getRequiredProperties() {
List<String> ret=new ArrayList<String>();
ret.add(getPropertyKey());
return ret;
}

/**
* InChI implementation for finding exact matches in an SDFModel
*/
protected List<? extends ITestResult> doRunTest(
ICDKMolecule cdkmol,
IProgressMonitor monitor) {
//Store results here
ArrayList<ExternalMoleculeMatch> results=new
ArrayList<ExternalMoleculeMatch>();

//Calculate property using subclass implementation
String calculatedProperty;
try {
calculatedProperty = getCalculatedProperty(cdkmol);
} catch (DSException e) {
LogUtils.debugTrace(logger, e);
return returnError("Could not calculate property: " + getPropertyKey(), "");
}
if (calculatedProperty==null || calculatedProperty.length()<=0)
return returnError("Could not calculate property: " + getPropertyKey(), "");


//Search the entire SDFmodel for the query property
logger.debug( "Quering for: " + calculatedProperty);
for (int i=0; i<getSDFmodel().getNumberOfMolecules(); i++){

Object storedPropObject=getSDFmodel().getPropertyFor( i,
getPropertyKey() );

String storedProp="";
try {
storedProp = processQueryResult(storedPropObject);
} catch (DSException e) {
logger.error("Could not process object " + storedPropObject); //Should not happen
}

//Compare signatures
if (calculatedProperty.equals( storedProp )){

// logger.debug("Found match for mol " + i + ": " + storedProp);

ICDKMolecule matchmol = getSDFmodel().getMoleculeAt( i );
String molResponse = getSDFmodel().getPropertyFor( i,
getResponseProperty());

String cdktitle=(String) matchmol.getAtomContainer()
.getProperty( CDKConstants.TITLE );
String molname="Index " + i;
if (cdktitle!=null)
molname=cdktitle;

ExternalMoleculeMatch match =null;
if (isClassification){
match =
new ExternalMoleculeMatch(molname, matchmol,
getConclusion(molResponse));
}else{
match =
new ExternalMoleculeMatch(molname + ", value=" + molResponse, matchmol,
getConclusion(molResponse));
}

Map<String, Map<String, String>> categories = new HashMap<String, Map<String,String>>();
Map<String,String> props = new HashMap<String, String>();
props.put("Observed value" , molResponse);
categories.put("Observations", props);
match.setProperties(categories);

results.add( match );
}

if (monitor.isCanceled())
return returnError( "Cancelled","");

}

return results;
}


/**
* @return the stored property in SDF that we compare with
*/
public abstract String getPropertyKey();


/**
*
* @param cdkmol Molecule to calculate on
* @return The calculated property that we compare against all mols in SDF
* @throws DSException
*/
public abstract String getCalculatedProperty(ICDKMolecule cdkmol) throws DSException;


/**
* Optional logic to get from a read property to String
* used for comparison with calculated property.
*
* Subclasses may override, default impl is toString();
*
* @param obj input to process
* @return String of processed input.
* @throws DSException if serialization fails.
*/
public String processQueryResult(Object obj) throws DSException{
return obj.toString();
}
}

0 comments on commit 4e47d77

Please sign in to comment.