Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added initial plugin n.b.ds.liblinear and n.b.liblinear
- Loading branch information
Showing
11 changed files
with
900 additions
and
0 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,7 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/> | ||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
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,28 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>net.bioclipse.ds.liblinear</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.pde.ManifestBuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.pde.SchemaBuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.pde.PluginNature</nature> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
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,26 @@ | ||
Manifest-Version: 1.0 | ||
Bundle-ManifestVersion: 2 | ||
Bundle-Name: DS Liblinear | ||
Bundle-SymbolicName: net.bioclipse.ds.liblinear | ||
Bundle-Version: 0.1.1 | ||
Bundle-RequiredExecutionEnvironment: JavaSE-1.7 | ||
Require-Bundle: org.eclipse.ui, | ||
org.eclipse.core.runtime, | ||
org.eclipse.help, | ||
org.eclipse.core.resources, | ||
net.bioclipse.ds, | ||
net.bioclipse.liblinear, | ||
net.bioclipse.cdk.business, | ||
net.bioclipse.core, | ||
net.bioclipse.ds.signatures, | ||
org.openscience.cdk.interfaces, | ||
org.openscience.cdk.standard, | ||
org.openscience.cdk.io, | ||
net.bioclipse.ds.common, | ||
net.bioclipse.cdk.ui.sdfeditor, | ||
signatures, | ||
org.openscience.cdk.valencycheck, | ||
net.bioclipse.ds.libsvm;bundle-version="2.6.2" | ||
Import-Package: org.apache.log4j, | ||
org.slf4j | ||
Export-Package: net.bioclipse.ds.liblinear |
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,4 @@ | ||
source.. = src/ | ||
output.. = bin/ | ||
bin.includes = META-INF/,\ | ||
. |
120 changes: 120 additions & 0 deletions
120
plugins/net.bioclipse.ds.liblinear/src/net/bioclipse/ds/liblinear/SignLibLinearModel.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,120 @@ | ||
package net.bioclipse.ds.liblinear; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.apache.log4j.Logger; | ||
|
||
import de.bwaldvogel.liblinear.Feature; | ||
import de.bwaldvogel.liblinear.FeatureNode; | ||
import de.bwaldvogel.liblinear.Linear; | ||
import de.bwaldvogel.liblinear.Model; | ||
import libsvm.svm; | ||
import libsvm.svm_model; | ||
import libsvm.svm_node; | ||
|
||
|
||
/** | ||
* A SignaturesLibLinearModel. Consists of a Model and a list of signatures. | ||
* | ||
* @author ola | ||
* | ||
*/ | ||
public class SignLibLinearModel { | ||
|
||
private static final Logger logger = Logger.getLogger(SignLibLinearModel.class); | ||
|
||
List<String> modelSignatures; | ||
Model model; | ||
|
||
public SignLibLinearModel(Model model, List<String> signatures) { | ||
super(); | ||
this.model = model; | ||
this.modelSignatures = signatures; | ||
} | ||
|
||
|
||
public List<String> getModelSignatures() { | ||
return modelSignatures; | ||
} | ||
public void setModelSignatures(List<String> modelSignatures) { | ||
this.modelSignatures = modelSignatures; | ||
} | ||
public Model getModel() { | ||
return model; | ||
} | ||
public void setModel(Model model) { | ||
this.model = model; | ||
} | ||
|
||
|
||
/** | ||
* Wrap a standard internal LibLinear prediction. | ||
* | ||
* @return | ||
*/ | ||
public double predict(Feature[] instance){ | ||
return Linear.predict(model, instance); | ||
} | ||
|
||
|
||
|
||
/** | ||
* For a given set of signatures, predict the results for this model. | ||
* | ||
* @param querySignatures | ||
* @return | ||
*/ | ||
public double predict(List<String> querySignatures){ | ||
|
||
|
||
// Contains the signatures for a molecule and the count. | ||
//We store the count as a double although it is an integer. libsvm wants a double. | ||
Map<String, Double> moleculeSignatures = new HashMap<String, Double>(); | ||
|
||
Iterator<String> signsIter = querySignatures.iterator(); | ||
int signsIndex = 0; | ||
while (signsIter.hasNext()){ | ||
String currentSignature = signsIter.next(); | ||
if (modelSignatures.contains(currentSignature)){ | ||
if (moleculeSignatures.containsKey(currentSignature)){ | ||
moleculeSignatures.put(currentSignature, (Double)moleculeSignatures.get(currentSignature)+1.00); | ||
} | ||
else{ | ||
moleculeSignatures.put(currentSignature, 1.0); | ||
} | ||
} | ||
signsIndex++; | ||
} | ||
|
||
// logger.debug("Signatures with count: " + moleculeSignatures.toString()); | ||
|
||
//Set up input for LibLinear | ||
List<FeatureNode> nodes = new ArrayList<FeatureNode>(); | ||
Iterator<String> signaturesIter = modelSignatures.iterator(); | ||
while (signaturesIter.hasNext()){ | ||
String currentSignature = signaturesIter.next(); | ||
if (moleculeSignatures.containsKey(currentSignature)){ | ||
int index = modelSignatures.indexOf(currentSignature)+1; // libsvm assumes that the index starts at one. | ||
Double value = (Double) moleculeSignatures.get(currentSignature); | ||
FeatureNode node = new FeatureNode(index, value); | ||
nodes.add(node); | ||
|
||
// System.out.println(currentSignature + " ==> " | ||
// + node.index + "=" + node.value); | ||
|
||
} | ||
} | ||
|
||
//This is the array with signature descriptor values | ||
Feature[] instance = nodes.toArray(new Feature[0]); | ||
|
||
return predict(instance); | ||
} | ||
|
||
|
||
|
||
} |
Oops, something went wrong.