Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented regression models for NN and exact match.
* Refactored all SDFmodels at the same time.
- Loading branch information
Showing
23 changed files
with
578 additions
and
819 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
158 changes: 158 additions & 0 deletions
158
plugins/net.bioclipse.ds.common/src/net/bioclipse/ds/matcher/BaseSDFExactMatcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
Oops, something went wrong.