Skip to content

Commit

Permalink
Added a method to get a MDL molfile by compound URI (and unit tests f…
Browse files Browse the repository at this point in the history
…or both methods
  • Loading branch information
egonw committed Aug 11, 2012
1 parent af85e45 commit 58fdac0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
Expand Up @@ -211,6 +211,22 @@ CDKMolecule.INCHI_OBJECT, new InChI(
Assert.assertNotSame(0, compounds.size());
}

@Test public void testDownloadAsMDLMolfile() throws Exception {
String mdlMolfile = opentox.downloadCompoundAsMDLMolfile(
TEST_SERVER_OT, "http://apps.ideaconsult.net:8080/ambit2/dataset/2", 1
);
Assert.assertNotNull(mdlMolfile);
Assert.assertTrue(mdlMolfile.contains("V2000"));
}

@Test public void testDownloadAsMDLMolfileFromURI() throws Exception {
String mdlMolfile = opentox.downloadCompoundAsMDLMolfile(
"http://apps.ideaconsult.net:8080/ambit2/dataset/2/compound/1"
);
Assert.assertNotNull(mdlMolfile);
Assert.assertTrue(mdlMolfile.contains("V2000"));
}

@Test public void testCreateDataSetFromSet() throws Exception {
List<ICDKMolecule> molecules = cdk.createMoleculeList();
molecules.add(cdk.fromSMILES("COC"));
Expand Down
Expand Up @@ -317,6 +317,15 @@ public interface IOpentoxManager extends IBioclipseManager {
public String downloadCompoundAsMDLMolfile(String service, String dataSet,
Integer compound) throws BioclipseException;

@Recorded
@PublishedMethod(
methodSummary=
"Downloads a compound and returns it as a MDL molfile formated " +
"String.",
params="String compoundURI"
)
public String downloadCompoundAsMDLMolfile(String compoundURI) throws BioclipseException;

@Recorded
@PublishedMethod(
methodSummary=
Expand Down
Expand Up @@ -470,14 +470,17 @@ public List<Integer> listCompounds(String dataSet,
monitor.worked(1);

// query the downloaded RDF
System.out.println(rdf.dump(store));
IStringMatrix results = rdf.sparql(store, QUERY_COMPOUNDS);
monitor.worked(1);

// return the data set identifiers
for (String compound : results.getColumn("compound")) {
compounds.add(
Integer.valueOf(compound.substring(compound.lastIndexOf('/')+1))
);
if (results.getRowCount() > 0) {
for (String compound : results.getColumn("compound")) {
compounds.add(
Integer.valueOf(compound.substring(compound.lastIndexOf('/')+1))
);
}
}
monitor.worked(1);
} catch (BioclipseException exception) {
Expand All @@ -496,14 +499,18 @@ public List<Integer> listCompounds(String dataSet,
public String downloadCompoundAsMDLMolfile(String service, String dataSet,
Integer compound, IProgressMonitor monitor)
throws BioclipseException {
return downloadCompoundAsMDLMolfile(dataSet + "/compound/" + compound, monitor);
}

public String downloadCompoundAsMDLMolfile(String compoundURI, IProgressMonitor monitor)
throws BioclipseException {

if (monitor == null) monitor = new NullProgressMonitor();

monitor.beginTask("Downloading compound...", 1);

String url = dataSet + "/compound/" + compound;
String result = bioclipse.download(
url, "chemical/x-mdl-molfile", monitor
compoundURI, "chemical/x-mdl-molfile", monitor
);
monitor.done();

Expand Down

0 comments on commit 58fdac0

Please sign in to comment.