Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactoder CS and CHEMBL to separate classes
- Loading branch information
Showing
4 changed files
with
252 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>net.bioclipse.ds.models_site</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.pde.FeatureBuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.pde.FeatureNature</nature> | ||
</natures> | ||
</projectDescription> |
155 changes: 155 additions & 0 deletions
155
...ipse.ds.chemspider/src/net/bioclipse/ds/chemspider/CopyOfSimilaritySearchChEMBLModel.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,155 @@ | ||
package net.bioclipse.ds.chemspider; | ||
|
||
import java.text.DecimalFormat; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.apache.log4j.Logger; | ||
import org.eclipse.core.runtime.IProgressMonitor; | ||
|
||
import net.bioclipse.cdk.business.ICDKManager; | ||
import net.bioclipse.cdk.domain.ICDKMolecule; | ||
import net.bioclipse.chemspider.Activator; | ||
import net.bioclipse.chemspider.business.IChemspiderManager; | ||
import net.bioclipse.core.business.BioclipseException; | ||
import net.bioclipse.ds.model.AbstractDSTest; | ||
import net.bioclipse.ds.model.DSException; | ||
import net.bioclipse.ds.model.ITestResult; | ||
import net.bioclipse.ds.model.result.ExternalMoleculeMatch; | ||
|
||
/** | ||
* Model for DS based on ChemSpider SimilaritySearch. | ||
* | ||
* @author Ola Spjuth | ||
* | ||
*/ | ||
public class CopyOfSimilaritySearchChEMBLModel extends AbstractDSTest{ | ||
|
||
private static final String TANIMOTO_DISTANCE = "distance.tanimoto"; | ||
private static final int MAX_NEIGHBORS = 15; | ||
|
||
|
||
private static final Logger logger = Logger.getLogger(CopyOfSimilaritySearchChEMBLModel.class); | ||
|
||
private float tanimoto; | ||
DecimalFormat formatter = new DecimalFormat( "0.00" ); | ||
|
||
@Override | ||
public List<String> getRequiredParameters() { | ||
List<String> ret=new ArrayList<String>(); | ||
ret.add( TANIMOTO_DISTANCE ); | ||
return ret; | ||
} | ||
|
||
@Override | ||
public void initialize(IProgressMonitor monitor) throws DSException { | ||
super.initialize(monitor); | ||
|
||
tanimoto=Float.parseFloat(getParameters().get(TANIMOTO_DISTANCE)); | ||
logger.debug("Chemspider similaritysearch is using tanimoto: " + tanimoto); | ||
|
||
} | ||
|
||
|
||
@Override | ||
protected List<? extends ITestResult> doRunTest(ICDKMolecule molecule, | ||
IProgressMonitor monitor) { | ||
|
||
//Managers we need | ||
IChemspiderManager chemspider = Activator.getDefault().getJavaChemspiderManager(); | ||
ICDKManager cdk = net.bioclipse.cdk.business.Activator.getDefault().getJavaCDKManager(); | ||
|
||
//Hold results here | ||
ArrayList<ExternalMoleculeMatch> results = new ArrayList<ExternalMoleculeMatch>(); | ||
|
||
//Do chemspider search | ||
List<ICDKMolecule> resultMols=null; | ||
try { | ||
resultMols = chemspider.similaritySearch(molecule, tanimoto, monitor); | ||
} catch (BioclipseException e1) { | ||
return returnError("Service failed to complete. Incorrect security token?", e1.getMessage()); | ||
} | ||
if (resultMols==null) | ||
return returnError("Null results",""); | ||
logger.debug("Model " + getName() + " had " + resultMols.size() + " hits"); | ||
|
||
// List<ICDKMolecule> resultMols = new ArrayList<ICDKMolecule>(); | ||
// try { | ||
// resultMols.add(cdk.fromSMILES("CCC")); | ||
// } catch (BioclipseException e1) { | ||
// e1.printStackTrace(); | ||
// } | ||
|
||
//Set up results, reduce to max 15 results | ||
logger.debug("Setting up results..."); | ||
for (ICDKMolecule cdkmol : resultMols.subList(0, Math.min(resultMols.size(), MAX_NEIGHBORS))){ | ||
|
||
//We calculate tanimoto locally for now | ||
String distance = "N/A"; | ||
try { | ||
distance = "" + formatter.format(cdk.calculateTanimoto(molecule, cdkmol)); | ||
} catch (BioclipseException e) { | ||
logger.error("Could not calculate tanimoto: " + e.getMessage()); | ||
} | ||
|
||
//Get name and other params from stored props on mol, set in chemspider manager | ||
String molname=(String) cdkmol.getProperty("chemspider.commonname", null); | ||
|
||
logger.debug("Hit: " + molname + " ; distance: " + distance); | ||
|
||
ExternalMoleculeMatch match = new ExternalMoleculeMatch(molname + " (tanimoto=" + distance + ")" , cdkmol, | ||
ITestResult.INFORMATIVE); | ||
|
||
Map<String, Map<String, String>> categories = new HashMap<String, Map<String,String>>(); | ||
Map<String,String> props = new HashMap<String, String>(); | ||
Integer csid = (Integer) cdkmol.getProperty("chemspider.id", null); | ||
props.put("Chemspider ID" , "" + csid); | ||
props.put("InChI" , "" + cdkmol.getProperty("chemspider.inchi", null)); | ||
props.put("InChIkey" , "" + cdkmol.getProperty("chemspider.inchikey", null)); | ||
props.put("AlogP" , "" + cdkmol.getProperty("chemspider.alogp", null)); | ||
props.put("XlogP" , "" + cdkmol.getProperty("chemspider.xlogp", null)); | ||
props.put("Average mass" , "" + cdkmol.getProperty("chemspider.averagemass", null)); | ||
props.put("Molecular formula" , "" + cdkmol.getProperty("chemspider.mf", null)); | ||
props.put("Molecular wheight" , "" + cdkmol.getProperty("chemspider.mw", null)); | ||
props.put("Monoisotopic mass" , "" + cdkmol.getProperty("chemspider.monoisotopicmass", null)); | ||
props.put("Nominal mass" , "" + cdkmol.getProperty("chemspider.nominalmass", null)); | ||
categories.put("Chemspider", props); | ||
|
||
//Look up interactions in ChEMBL | ||
try { | ||
List<ChemblInteraction> chemblInteractions = ChemblLookup.lookupCSID(csid); | ||
// List<ChemblInteraction> chemblInteractions = ChemblLookup.lookupCSID(10368587); | ||
|
||
if (chemblInteractions!=null){ | ||
for (ChemblInteraction ci : chemblInteractions){ | ||
Map<String,String> ciprops = new HashMap<String, String>(); | ||
if (ci.getRelation()!=null) | ||
ciprops.put("Value" , ci.getRelation() + ci.getValue()); | ||
else | ||
ciprops.put("Value" , ci.getValue()); | ||
ciprops.put("Unit" , ci.getUnit()); | ||
ciprops.put("Target type" , ci.getTargetType()); | ||
ciprops.put("Interaction type" , ci.getInteractionType()); | ||
ciprops.put("Description" , ci.getDescription()); | ||
|
||
categories.put("Target: " + ci.getTitle(), ciprops); | ||
} | ||
} | ||
else{ | ||
logger.debug("No ChEMBL interactions for CID=" + csid); | ||
} | ||
|
||
} catch (BioclipseException e) { | ||
logger.error("Error querying chembl: " + e.getMessage()); | ||
} | ||
|
||
match.setProperties(categories); | ||
results.add(match); | ||
} | ||
|
||
return results; | ||
} | ||
|
||
} |
80 changes: 80 additions & 0 deletions
80
....bioclipse.ds.chemspider/src/net/bioclipse/ds/chemspider/SimilaritySearchChEMBLModel.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,80 @@ | ||
package net.bioclipse.ds.chemspider; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.apache.log4j.Logger; | ||
import org.eclipse.core.runtime.IProgressMonitor; | ||
|
||
import net.bioclipse.cdk.domain.ICDKMolecule; | ||
import net.bioclipse.core.business.BioclipseException; | ||
import net.bioclipse.ds.model.ITestResult; | ||
import net.bioclipse.ds.model.result.ExternalMoleculeMatch; | ||
|
||
/** | ||
* Model for DS based on ChemSpider SimilaritySearch, | ||
* annotates with ChEMBL interaction data. | ||
* | ||
* @author Ola Spjuth | ||
* | ||
*/ | ||
public class SimilaritySearchChEMBLModel extends SimilaritySearchModel{ | ||
|
||
private static final Logger logger = Logger.getLogger(SimilaritySearchChEMBLModel.class); | ||
|
||
@Override | ||
protected List<? extends ITestResult> doRunTest(ICDKMolecule molecule, | ||
IProgressMonitor monitor) { | ||
|
||
List<? extends ITestResult> matches = super.doRunTest(molecule, monitor); | ||
List<ExternalMoleculeMatch> toRemove = new ArrayList<ExternalMoleculeMatch>(); | ||
|
||
for (ITestResult tr : matches){ | ||
if (!(tr instanceof ExternalMoleculeMatch)) { | ||
continue; | ||
} | ||
ExternalMoleculeMatch match = (ExternalMoleculeMatch)tr; | ||
|
||
Map<String, Map<String, String>> categories = match.getProperties(); | ||
Map<String, String> csprops = categories.get("Chemspider"); | ||
int csid=Integer.parseInt(csprops.get("Chemspider ID")); | ||
|
||
//Look up interactions in ChEMBL | ||
try { | ||
List<ChemblInteraction> chemblInteractions = ChemblLookup.lookupCSID(csid); | ||
// List<ChemblInteraction> chemblInteractions = ChemblLookup.lookupCSID(10368587); | ||
|
||
if (chemblInteractions!=null){ | ||
for (ChemblInteraction ci : chemblInteractions){ | ||
Map<String,String> ciprops = new HashMap<String, String>(); | ||
if (ci.getRelation()!=null) | ||
ciprops.put("Value" , ci.getRelation() + ci.getValue()); | ||
else | ||
ciprops.put("Value" , ci.getValue()); | ||
ciprops.put("Unit" , ci.getUnit()); | ||
ciprops.put("Target type" , ci.getTargetType()); | ||
ciprops.put("Interaction type" , ci.getInteractionType()); | ||
ciprops.put("Description" , ci.getDescription()); | ||
|
||
categories.put("Target: " + ci.getTitle(), ciprops); | ||
} | ||
} | ||
else{ | ||
logger.debug("No ChEMBL interactions for CID=" + csid); | ||
toRemove.add(match); | ||
} | ||
|
||
} catch (BioclipseException e) { | ||
logger.error("Error querying chembl: " + e.getMessage()); | ||
} | ||
|
||
} | ||
|
||
//Remove the ones with no ChEMBL data | ||
matches.removeAll(toRemove); | ||
return matches; | ||
} | ||
|
||
} |
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