Navigation Menu

Skip to content

Commit

Permalink
Added a new method: opentox.listFeatures(otServer)
Browse files Browse the repository at this point in the history
  • Loading branch information
egonw committed Aug 11, 2012
1 parent 62b3893 commit 3977f97
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
Expand Up @@ -157,6 +157,13 @@ CDKMolecule.INCHI_OBJECT, new InChI(
Assert.assertNotSame(0, models.size());
}

@Test public void testListFeatures() throws Exception {
List<String> features = opentox.listFeatures(TEST_SERVER_OT);
Assert.assertNotNull(features);
// expect at least one hit:
Assert.assertNotSame(0, features.size());
}

@Test public void testCreateEmptyDataSet() throws Exception {
String uriString = opentox.createDataset(TEST_SERVER_OT);
Assert.assertNotNull(uriString);
Expand Down
Expand Up @@ -186,6 +186,13 @@ public interface IOpentoxManager extends IBioclipseManager {
)
public List<String> listDataSets(String service) throws BioclipseException;

@Recorded
@PublishedMethod(
methodSummary="Lists the features available from the given service.",
params="String service"
)
public List<String> listFeatures(String service) throws BioclipseException;

@Recorded
@PublishedMethod(
methodSummary=
Expand Down
Expand Up @@ -78,6 +78,11 @@ public class OpentoxManager implements IBioclipseManager {
" ?set a <http://www.opentox.org/api/1.1#Dataset> ." +
"}";

private final static String QUERY_FEATURES =
"SELECT ?feature WHERE {" +
" ?feature a <http://www.opentox.org/api/1.1#Feature> ." +
"}";

private final static String QUERY_COMPOUNDS =
"SELECT ?compound ?id WHERE {" +
" ?set a <http://www.opentox.org/api/1.1#Compound> ." +
Expand Down Expand Up @@ -226,6 +231,46 @@ public List<String> listDataSets(String service, IProgressMonitor monitor)
return dataSets;
}

public List<String> listFeatures(String service, IProgressMonitor monitor)
throws BioclipseException {
if (monitor == null) monitor = new NullProgressMonitor();
monitor.beginTask("Requesting available features...", 3);

IRDFStore store = rdf.createInMemoryStore();
List<String> dataSets = Collections.emptyList();
Map<String, String> extraHeaders = new HashMap<String, String>();
String token = Activator.getToken();
if (token != null) {
extraHeaders.put("subjectid", Activator.getToken());
}
try {
// download the list of data sets as RDF
rdf.importURL(store, service + "feature", extraHeaders, monitor);
String dump = rdf.asRDFN3(store);
System.out.println("RDF: " + dump);
monitor.worked(1);

// query the downloaded RDF
IStringMatrix results = rdf.sparql(store, QUERY_FEATURES);
monitor.worked(1);

if (results.getRowCount() > 0) {
dataSets = results.getColumn("feature");
}
monitor.worked(1);
} catch (BioclipseException exception) {
throw exception;
} catch (Exception exception) {
throw new BioclipseException(
"Error while accessing RDF API of service: " + exception.getMessage(),
exception
);
}

monitor.done();
return dataSets;
}

public IStringMatrix searchDataSets(String ontologyServer, String query, IProgressMonitor monitor)
throws BioclipseException {
if (monitor == null) monitor = new NullProgressMonitor();
Expand Down

0 comments on commit 3977f97

Please sign in to comment.