migrate to the BioModels REST API
This commit is contained in:
parent
ab1b1a55a4
commit
eda9078f4c
14 changed files with 565 additions and 67 deletions
|
|
@ -0,0 +1,64 @@
|
|||
package edu.utah.ece.async.ibiosim.biomodels;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.StatusLine;
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.apache.http.client.HttpResponseException;
|
||||
import org.apache.http.client.ResponseHandler;
|
||||
import org.apache.http.entity.ContentType;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* @author Mihai Glon\u021b mglont@ebi.ac.uk
|
||||
*/
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public abstract class AbstractResponseHandler<T> implements ResponseHandler<T> {
|
||||
|
||||
@Override
|
||||
public T handleResponse(HttpResponse response) throws IOException {
|
||||
StatusLine statusLine = response.getStatusLine();
|
||||
HttpEntity entity = response.getEntity();
|
||||
if (statusLine.getStatusCode() == 307) {
|
||||
//noinspection unused
|
||||
final Header location = response.getFirstHeader("Location");
|
||||
// TODO follow the redirection if location is not null
|
||||
}
|
||||
return parseResponse(statusLine, entity, getObjectMappingClass());
|
||||
}
|
||||
|
||||
protected abstract Class<T> getObjectMappingClass();
|
||||
|
||||
protected T parseResponse(StatusLine statusLine, HttpEntity entity, Class<T> pojoClass)
|
||||
throws IOException {
|
||||
if (statusLine.getStatusCode() >= 400) {
|
||||
throw new HttpResponseException(
|
||||
statusLine.getStatusCode(),
|
||||
statusLine.getReasonPhrase());
|
||||
}
|
||||
if (entity == null) {
|
||||
throw new ClientProtocolException("Response contains no content");
|
||||
}
|
||||
ContentType contentType = ContentType.getOrDefault(entity);
|
||||
Charset charset = contentType.getCharset() != null ? contentType.getCharset() :
|
||||
StandardCharsets.UTF_8;
|
||||
|
||||
try (BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(entity.getContent(), charset))) {
|
||||
return unmarshallContent(reader, pojoClass);
|
||||
}
|
||||
}
|
||||
|
||||
protected T unmarshallContent(BufferedReader reader, Class<T> type) {
|
||||
Gson gson = new GsonBuilder().create();
|
||||
return gson.fromJson(reader, type);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,101 @@
|
|||
package edu.utah.ece.async.ibiosim.biomodels;
|
||||
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static edu.utah.ece.async.ibiosim.biomodels.Requests.SEARCH_RESULTS_PER_PAGE;
|
||||
|
||||
/**
|
||||
* @author Mihai Glon\u021b mglont@ebi.ac.uk
|
||||
*/
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public class BioModelsConnectionService implements AutoCloseable {
|
||||
private final CloseableHttpClient client;
|
||||
|
||||
public BioModelsConnectionService() {
|
||||
this(HttpClients.createDefault());
|
||||
}
|
||||
|
||||
public BioModelsConnectionService(CloseableHttpClient client) {
|
||||
this.client = Objects.requireNonNull(client, "The HttpClient cannot be null");
|
||||
}
|
||||
|
||||
public ModelResponse getModel(String m) {
|
||||
final HttpGet request = Requests.newGetModelRequest(m);
|
||||
return performRequest(request, new GetModelResponseHandler());
|
||||
}
|
||||
|
||||
public CuratedModelsResponse getCuratedModelSet() {
|
||||
final HttpGet request = Requests.newCuratedModelSearchRequest();
|
||||
CuratedModelsResponse firstPage = performRequest(request, new CuratedModelsResponseHandler());
|
||||
if (null == firstPage) return null;
|
||||
|
||||
return doGetAllCuratedModels(firstPage);
|
||||
}
|
||||
|
||||
public String getModelFileName(String model) {
|
||||
HttpGet filesRequest = Requests.newGetFilesRequest(model);
|
||||
|
||||
ModelFilesResponse files = performRequest(filesRequest, new GetFilesResponseHandler());
|
||||
if (null == files) return null;
|
||||
|
||||
return files.getMainFileName();
|
||||
}
|
||||
|
||||
public ModelFileResponse getModelFile(String model) {
|
||||
String mainFileName = getModelFileName(model);
|
||||
if (mainFileName == null) return null;
|
||||
HttpGet modelFileRequest = Requests.newGetModelFileRequest(model, mainFileName);
|
||||
return performRequest(modelFileRequest, new GetModelFileResponseHandler());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
try {
|
||||
client.close();
|
||||
} catch (IOException e) {
|
||||
System.err.printf("Could not close the HttpClient instance: %s%n", e);
|
||||
}
|
||||
}
|
||||
|
||||
private CuratedModelsResponse doGetAllCuratedModels(CuratedModelsResponse firstPage) {
|
||||
int total = firstPage.getMatches();
|
||||
int pageCount = (int) Math.ceil(((double) total) / SEARCH_RESULTS_PER_PAGE);
|
||||
Stream<ModelSummary> remainder = IntStream.range(1, pageCount)
|
||||
.mapToObj(this::getSearchResultsPage)
|
||||
.filter(p -> p != null) // requests that threw exceptions return null
|
||||
.flatMap(CuratedModelsResponse::getModelsStream);
|
||||
|
||||
Set<ModelSummary> responses = Stream.concat(firstPage.getModelsStream(), remainder)
|
||||
.collect(Collectors.toCollection(TreeSet::new));
|
||||
|
||||
return new CuratedModelsResponse(responses);
|
||||
}
|
||||
|
||||
private <T> T performRequest(HttpGet request, AbstractResponseHandler<T> responseHandler) {
|
||||
try {
|
||||
return client.execute(request, responseHandler);
|
||||
} catch (IOException e) {
|
||||
System.err.printf("I/O exception encountered while performing request %s: %s%n",
|
||||
request.getURI().toString(), e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private CuratedModelsResponse getSearchResultsPage(int page) {
|
||||
if (page < 1) throw new IllegalArgumentException(String.valueOf(page));
|
||||
|
||||
final int offset = page * SEARCH_RESULTS_PER_PAGE;
|
||||
HttpGet request = Requests.newCuratedModelSearchRequest(offset);
|
||||
return performRequest(request, new CuratedModelsResponseHandler());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
package edu.utah.ece.async.ibiosim.biomodels;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* @author Mihai Glon\u021b mglont@ebi.ac.uk
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class CuratedModelsResponse {
|
||||
private int matches;
|
||||
private Set<ModelSummary> models;
|
||||
|
||||
public CuratedModelsResponse() {
|
||||
}
|
||||
|
||||
public CuratedModelsResponse(Set<ModelSummary> models) {
|
||||
this.models = models;
|
||||
if (null == models) {
|
||||
matches = 0;
|
||||
} else {
|
||||
matches = models.size();
|
||||
}
|
||||
}
|
||||
|
||||
public Stream<ModelSummary> getModelsStream() {
|
||||
return models.parallelStream();
|
||||
}
|
||||
|
||||
public int getMatches() {
|
||||
return matches;
|
||||
}
|
||||
|
||||
public Set<ModelSummary> getModels() {
|
||||
return models;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
package edu.utah.ece.async.ibiosim.biomodels;
|
||||
|
||||
/**
|
||||
* @author Mihai Glon\u021b mglont@ebi.ac.uk
|
||||
*/
|
||||
public class CuratedModelsResponseHandler extends AbstractResponseHandler<CuratedModelsResponse> {
|
||||
@Override
|
||||
protected Class<CuratedModelsResponse> getObjectMappingClass() {
|
||||
return CuratedModelsResponse.class;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
package edu.utah.ece.async.ibiosim.biomodels;
|
||||
|
||||
/**
|
||||
* @author Mihai Glon\u021b mglont@ebi.ac.uk
|
||||
*/
|
||||
public class GetFilesResponseHandler extends AbstractResponseHandler<ModelFilesResponse> {
|
||||
@Override
|
||||
protected Class<ModelFilesResponse> getObjectMappingClass() {
|
||||
return ModelFilesResponse.class;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
package edu.utah.ece.async.ibiosim.biomodels;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
|
||||
/**
|
||||
* @author Mihai Glon\u021b mglont@ebi.ac.uk
|
||||
*/
|
||||
public class GetModelFileResponseHandler extends AbstractResponseHandler<ModelFileResponse> {
|
||||
@Override
|
||||
protected Class<ModelFileResponse> getObjectMappingClass() {
|
||||
return ModelFileResponse.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ModelFileResponse unmarshallContent(BufferedReader reader, Class<ModelFileResponse> type) {
|
||||
return ModelFileResponse.parse(reader);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
package edu.utah.ece.async.ibiosim.biomodels;
|
||||
|
||||
/**
|
||||
* @author Mihai Glon\u021b mglont@ebi.ac.uk
|
||||
*/
|
||||
public final class GetModelResponseHandler extends AbstractResponseHandler<ModelResponse> {
|
||||
|
||||
@Override
|
||||
protected Class<ModelResponse> getObjectMappingClass() {
|
||||
return ModelResponse.class;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
package edu.utah.ece.async.ibiosim.biomodels;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
|
||||
/**
|
||||
* @author Mihai Glon\u021b mglont@ebi.ac.uk>
|
||||
*/
|
||||
public class ModelFileResponse {
|
||||
private String fileContent;
|
||||
|
||||
public static ModelFileResponse parse(BufferedReader reader) {
|
||||
ModelFileResponse response = new ModelFileResponse();
|
||||
|
||||
StringWriter stringWriter = new StringWriter(8192);
|
||||
try (PrintWriter writer = new PrintWriter(stringWriter)) {
|
||||
String currentLine;
|
||||
while ((currentLine = reader.readLine()) != null) {
|
||||
writer.write(currentLine);
|
||||
writer.println();
|
||||
}
|
||||
response.fileContent = stringWriter.toString();
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException("Failed to read model file contents", e);
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
public String getFileContent() {
|
||||
return fileContent;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package edu.utah.ece.async.ibiosim.biomodels;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings("WeakerAccess,unused")
|
||||
public class ModelFilesResponse {
|
||||
@SuppressWarnings("MismatchedQueryAndUpdateOfCollection")
|
||||
private List<RepositoryFile> main;
|
||||
private List<RepositoryFile> additional;
|
||||
|
||||
public static final class RepositoryFile {
|
||||
private String name;
|
||||
private String description;
|
||||
private int fileSize;
|
||||
}
|
||||
|
||||
public String getMainFileName() {
|
||||
return main.get(0).name;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
package edu.utah.ece.async.ibiosim.biomodels;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author Mihai Glon\u021b mglont@ebi.ac.uk
|
||||
*/
|
||||
public class ModelResponse {
|
||||
private String name;
|
||||
private String submissionId;
|
||||
private Publication publication;
|
||||
|
||||
private class Publication {
|
||||
private String link;
|
||||
}
|
||||
|
||||
public String getPublicationLink() {
|
||||
if (null == publication) return null;
|
||||
|
||||
return publication.link;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder response = new StringBuilder();
|
||||
|
||||
response.append("Model id ")
|
||||
.append(submissionId)
|
||||
.append(" (")
|
||||
.append(name)
|
||||
.append(")");
|
||||
|
||||
return response.toString();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
package edu.utah.ece.async.ibiosim.biomodels;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class ModelSummary implements Comparable<ModelSummary> {
|
||||
private String id;
|
||||
private String name;
|
||||
private Publication publication;
|
||||
|
||||
public static class Publication {
|
||||
private String link;
|
||||
}
|
||||
|
||||
public String getPublicationLink() {
|
||||
return null == publication ? null : publication.link;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return id + ' ' + name;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(ModelSummary o) {
|
||||
return id.compareTo(o.getId());
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
return (o instanceof ModelSummary) && ((ModelSummary) o).getId().equals(id);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
package edu.utah.ece.async.ibiosim.biomodels;
|
||||
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author Mihai Glon\u021b mglont@ebi.ac.uk
|
||||
*/
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public final class Requests {
|
||||
// can also use the Caltech instance: http://biomodels.caltech.edu/
|
||||
public static final String BIOMODELS_EBI_BASE = "https://www.ebi.ac.uk/biomodels/";
|
||||
public static final String SEARCH_CMD =
|
||||
"search?query=curationstatus%3AManually%20curated&sort=id-desc";
|
||||
public static final String GET_FILES_CMD = "model/files/";
|
||||
public static final String DLD_MODEL_CMD = "model/download/";
|
||||
public static final int SEARCH_RESULTS_PER_PAGE = 100;
|
||||
|
||||
public static HttpGet newGetModelRequest(String model) {
|
||||
final String url = String.format("%s%s", BIOMODELS_EBI_BASE,
|
||||
Objects.requireNonNull(model, "Model identifier (e.g. BIOMD0000000001) required"));
|
||||
return constructSignedJsonGetRequest(url);
|
||||
}
|
||||
|
||||
public static HttpGet newCuratedModelSearchRequest() {
|
||||
return newCuratedModelSearchRequest(0);
|
||||
}
|
||||
|
||||
public static HttpGet newCuratedModelSearchRequest(int offset) {
|
||||
String url = String.format("%s%s&offset=%d&numResults=%d", BIOMODELS_EBI_BASE,
|
||||
SEARCH_CMD, offset, SEARCH_RESULTS_PER_PAGE);
|
||||
return constructSignedJsonGetRequest(url);
|
||||
}
|
||||
|
||||
public static HttpGet newGetModelFileRequest(String modelId, String fileName) {
|
||||
String url = String.format("%s%s%s?filename=%s", BIOMODELS_EBI_BASE, DLD_MODEL_CMD,
|
||||
Objects.requireNonNull(modelId, "The model identifier is required"),
|
||||
Objects.requireNonNull(fileName, "Model file name is required"));
|
||||
return constructSignedJsonGetRequest(url);
|
||||
}
|
||||
|
||||
public static HttpGet newGetFilesRequest(String modelId) {
|
||||
String getFilesUrl = String.format("%s%s%s", BIOMODELS_EBI_BASE, GET_FILES_CMD,
|
||||
Objects.requireNonNull(modelId, "The model identifier is required"));
|
||||
return constructSignedJsonGetRequest(getFilesUrl);
|
||||
}
|
||||
|
||||
private static HttpGet constructSignedJsonGetRequest(String uri) {
|
||||
final HttpGet request = new HttpGet(uri);
|
||||
request.setHeader("User-Agent", "iBioSim <https://github.com/MyersResearchGroup/iBioSim>");
|
||||
request.setHeader("Accept", "application/json");
|
||||
|
||||
return request;
|
||||
}
|
||||
}
|
||||
|
|
@ -101,9 +101,11 @@ import javax.xml.stream.XMLStreamException;
|
|||
import javax.xml.transform.TransformerException;
|
||||
import javax.xml.xpath.XPathExpressionException;
|
||||
|
||||
import edu.utah.ece.async.ibiosim.biomodels.*;
|
||||
import org.antlr.runtime.ANTLRFileStream;
|
||||
import org.antlr.runtime.CommonTokenStream;
|
||||
import org.antlr.runtime.TokenStream;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.jdom2.JDOMException;
|
||||
import org.jlibsedml.AbstractTask;
|
||||
import org.jlibsedml.ArchiveComponents;
|
||||
|
|
@ -175,7 +177,6 @@ import edu.utah.ece.async.sboldesigner.sbol.editor.SBOLEditorPreferences;
|
|||
import edu.utah.ece.async.sboldesigner.sbol.editor.SynBioHubFrontends;
|
||||
import edu.utah.ece.async.sboldesigner.sbol.editor.dialog.RegistryInputDialog;
|
||||
import uk.ac.ebi.biomodels.ws.BioModelsWSClient;
|
||||
import uk.ac.ebi.biomodels.ws.BioModelsWSException;
|
||||
import de.unirostock.sems.cbarchive.ArchiveEntry;
|
||||
import de.unirostock.sems.cbarchive.CombineArchive;
|
||||
import de.unirostock.sems.cbarchive.CombineArchiveException;
|
||||
|
|
@ -306,13 +307,11 @@ public class Gui implements BioObserver, MouseListener, ActionListener, MouseMot
|
|||
|
||||
protected String viewer;
|
||||
|
||||
protected boolean runGetNames;
|
||||
|
||||
// protected boolean showParts = false;
|
||||
|
||||
// protected Thread getPartsThread = null;
|
||||
|
||||
private String[] BioModelIds = null;
|
||||
private ModelSummary[] BioModelIds = null;
|
||||
|
||||
// protected Parts allVirtualParts = null;
|
||||
|
||||
|
|
@ -2758,20 +2757,44 @@ public class Gui implements BioObserver, MouseListener, ActionListener, MouseMot
|
|||
}
|
||||
}
|
||||
|
||||
private ModelSummary[] retrieveCuratedBioModels() {
|
||||
try(BioModelsConnectionService service = new BioModelsConnectionService()) {
|
||||
CuratedModelsResponse response = service.getCuratedModelSet();
|
||||
Set<ModelSummary> summaries = response.getModels();
|
||||
return summaries.toArray(new ModelSummary[summaries.size()]);
|
||||
}
|
||||
}
|
||||
|
||||
private String getBioModelsModelFile(String modelId) {
|
||||
try(BioModelsConnectionService service = new BioModelsConnectionService()) {
|
||||
ModelFileResponse response = service.getModelFile(modelId);
|
||||
return response.getFileContent();
|
||||
}
|
||||
}
|
||||
|
||||
private String getPublicationLinkForModel(String modelId) {
|
||||
try (BioModelsConnectionService service = new BioModelsConnectionService()) {
|
||||
ModelResponse modelInformation = service.getModel(modelId);
|
||||
if (null == modelInformation) {
|
||||
System.err.println("No entry found in BioModels for " + modelId);
|
||||
return null;
|
||||
}
|
||||
return modelInformation.getPublicationLink();
|
||||
}
|
||||
}
|
||||
|
||||
private void downloadBioModel() {
|
||||
final BioModelsWSClient client = new BioModelsWSClient();
|
||||
if (BioModelIds == null) {
|
||||
try {
|
||||
BioModelIds = client.getAllCuratedModelsId();
|
||||
} catch (BioModelsWSException e2) {
|
||||
JOptionPane.showMessageDialog(frame, "Error Contacting BioModels Database", "Error",
|
||||
BioModelIds = retrieveCuratedBioModels();
|
||||
} catch (Exception e2) {
|
||||
JOptionPane.showMessageDialog(frame, "Error Contacting BioModels", "Error",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
final JPanel BioModelsPanel = new JPanel(new BorderLayout());
|
||||
final JList ListOfBioModels = new JList();
|
||||
edu.utah.ece.async.ibiosim.dataModels.biomodel.util.Utility.sort(BioModelIds);
|
||||
final JList<ModelSummary> ListOfBioModels = new JList<>();
|
||||
ListOfBioModels.setListData(BioModelIds);
|
||||
ListOfBioModels.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
JLabel TextBioModels = new JLabel("List of BioModels");
|
||||
|
|
@ -2780,65 +2803,28 @@ public class Gui implements BioObserver, MouseListener, ActionListener, MouseMot
|
|||
ScrollBioModels.setPreferredSize(new Dimension(552, 250));
|
||||
ScrollBioModels.setViewportView(ListOfBioModels);
|
||||
JPanel GetButtons = new JPanel();
|
||||
JButton GetNames = new JButton("Get Names");
|
||||
JButton GetDescription = new JButton("Get Description");
|
||||
JButton GetReference = new JButton("Get Reference");
|
||||
final JProgressBar progressBar = new JProgressBar(0, 100);
|
||||
progressBar.setStringPainted(true);
|
||||
progressBar.setValue(0);
|
||||
runGetNames = true;
|
||||
final Thread getNamesThread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Preferences biosimrc = Preferences.userRoot();
|
||||
for (int i = 0; i < BioModelIds.length && runGetNames; i++) {
|
||||
try {
|
||||
progressBar.setValue(100 * i / BioModelIds.length);
|
||||
if (!BioModelIds[i].contains(" ")) {
|
||||
if (!biosimrc.get(BioModelIds[i], "").equals("")) {
|
||||
BioModelIds[i] += " " + biosimrc.get(BioModelIds[i], "");
|
||||
} else {
|
||||
String name = client.getModelNameById(BioModelIds[i]);
|
||||
biosimrc.put(BioModelIds[i], name);
|
||||
BioModelIds[i] += " " + name;
|
||||
}
|
||||
ListOfBioModels.setListData(BioModelIds);
|
||||
ListOfBioModels.revalidate();
|
||||
ListOfBioModels.repaint();
|
||||
}
|
||||
} catch (BioModelsWSException e1) {
|
||||
JOptionPane.showMessageDialog(frame, "Error Contacting BioModels Database", "Error",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
runGetNames = false;
|
||||
}
|
||||
}
|
||||
progressBar.setValue(100);
|
||||
ListOfBioModels.setListData(BioModelIds);
|
||||
runGetNames = false;
|
||||
}
|
||||
});
|
||||
GetNames.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (runGetNames && !getNamesThread.isAlive()) {
|
||||
getNamesThread.start();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
GetDescription.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (ListOfBioModels.isSelectionEmpty()) {
|
||||
return;
|
||||
}
|
||||
String SelectedModel = ((String) ListOfBioModels.getSelectedValue()).split(" ")[0];
|
||||
String selectedModel = ListOfBioModels.getSelectedValue().getId();
|
||||
Preferences biosimrc = Preferences.userRoot();
|
||||
String command = biosimrc.get("biosim.general.browser", "");
|
||||
command = command + " http://www.ebi.ac.uk/compneur-srv/biomodels-main/" + SelectedModel;
|
||||
command = command + " http://identifiers.org/biomodels.db/" + selectedModel;
|
||||
progressBar.setValue(25);
|
||||
log.addText("Executing:\n" + command + "\n");
|
||||
Runtime exec = Runtime.getRuntime();
|
||||
try {
|
||||
exec.exec(command);
|
||||
progressBar.setValue(100);
|
||||
} catch (IOException e1) {
|
||||
JOptionPane.showMessageDialog(frame, "Unable to open model description.", "Error",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
|
|
@ -2851,25 +2837,31 @@ public class Gui implements BioObserver, MouseListener, ActionListener, MouseMot
|
|||
if (ListOfBioModels.isSelectionEmpty()) {
|
||||
return;
|
||||
}
|
||||
String SelectedModel = ((String) ListOfBioModels.getSelectedValue()).split(" ")[0];
|
||||
ModelSummary model = ListOfBioModels.getSelectedValue();
|
||||
String modelId = model.getId();
|
||||
try {
|
||||
String Pub = (client.getSimpleModelById(SelectedModel)).getPublicationId();
|
||||
String pub = getPublicationLinkForModel(modelId);
|
||||
progressBar.setValue(25);
|
||||
progressBar.repaint();
|
||||
if (null == pub) {
|
||||
JOptionPane.showMessageDialog(frame,
|
||||
"Could not find publication information in BioModels for " + modelId,
|
||||
"Warning", JOptionPane.WARNING_MESSAGE);
|
||||
return;
|
||||
}
|
||||
Preferences biosimrc = Preferences.userRoot();
|
||||
String command = biosimrc.get("biosim.general.browser", "");
|
||||
command = command + " http://www.ncbi.nlm.nih.gov/pubmed/?term=" + Pub;
|
||||
command = command + ' ' + pub;
|
||||
log.addText("Executing:\n" + command + "\n");
|
||||
Runtime exec = Runtime.getRuntime();
|
||||
exec.exec(command);
|
||||
} catch (BioModelsWSException e2) {
|
||||
JOptionPane.showMessageDialog(frame, "Error Contacting BioModels Database", "Error",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
progressBar.setValue(100);
|
||||
} catch (IOException e1) {
|
||||
JOptionPane.showMessageDialog(frame, "Unable to open model description.", "Error",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
});
|
||||
GetButtons.add(GetNames);
|
||||
GetButtons.add(GetDescription);
|
||||
GetButtons.add(GetReference);
|
||||
GetButtons.add(progressBar);
|
||||
|
|
@ -2879,17 +2871,16 @@ public class Gui implements BioObserver, MouseListener, ActionListener, MouseMot
|
|||
Object[] options = { "OK", "Cancel" };
|
||||
int value = JOptionPane.showOptionDialog(frame, BioModelsPanel, "List of BioModels", JOptionPane.YES_NO_OPTION,
|
||||
JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
|
||||
runGetNames = false;
|
||||
if (value == JOptionPane.YES_OPTION && ListOfBioModels.getSelectedValue() != null) {
|
||||
String ModelId = ((String) ListOfBioModels.getSelectedValue()).split(" ")[0];
|
||||
String filename = ModelId + ".xml";
|
||||
String modelId = ListOfBioModels.getSelectedValue().getId();
|
||||
String filename = modelId + ".xml";
|
||||
try {
|
||||
if (overwrite(root + File.separator + filename, filename)) {
|
||||
String model = client.getModelSBMLById(ModelId);
|
||||
Writer out = new BufferedWriter(new OutputStreamWriter(
|
||||
new FileOutputStream(root + File.separator + filename), "UTF-8"));
|
||||
out.write(model);
|
||||
out.close();
|
||||
String model = getBioModelsModelFile(modelId);
|
||||
try (Writer out = new BufferedWriter(new OutputStreamWriter(
|
||||
new FileOutputStream(root + File.separator + filename), "UTF-8"))) {
|
||||
out.write(model);
|
||||
}
|
||||
String[] file = GlobalConstants.splitPath(filename.trim());
|
||||
SBMLDocument document = SBMLutilities.readSBML(root + File.separator + filename.trim(), null, this);
|
||||
Utils.check(root + File.separator + filename.trim(), document, false, null, this);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,74 @@
|
|||
package edu.utah.ece.async.ibiosim.biomodels;
|
||||
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Mihai Glon\u021b mglont@ebi.ac.uk
|
||||
*/
|
||||
public class BioModelsConnectionServiceTest {
|
||||
private BioModelsConnectionService service;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
service = new BioModelsConnectionService(HttpClients.createMinimal());
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
Optional.ofNullable(service).ifPresent(BioModelsConnectionService::close);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRetrieveAModel() {
|
||||
String expected = "Model id MODEL6615119181 (Kholodenko2000 - " +
|
||||
"Ultrasensitivity and negative feedback bring oscillations in MAPK cascade)";
|
||||
ModelResponse response = service.getModel("MODEL6615119181");
|
||||
|
||||
assertEquals("the correct model is retrieved", expected, response.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldGetCuratedModelSet() {
|
||||
CuratedModelsResponse response = service.getCuratedModelSet();
|
||||
assertNotNull("the response object is defined", response);
|
||||
assertTrue("Have at least 700 models", response.getMatches() > 700);
|
||||
assertTrue(response.getModels().size() == response.getMatches());
|
||||
|
||||
String biomd738 = "BIOMD0000000738 Mouse Iron Distribution - Rich iron diet (No Tracer)";
|
||||
Optional<ModelSummary> match = response.getModelsStream()
|
||||
.filter(summary -> summary.toString().equals(biomd738))
|
||||
.findAny();
|
||||
assertTrue("BIOMD0000000738 is in the search results", match.isPresent());
|
||||
|
||||
/*response.getModelsStream()
|
||||
.map(ModelSummary::getId)
|
||||
.forEachOrdered(System.out::println);*/
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRetrieveModelFileNameForAKnownModel() {
|
||||
String name = service.getModelFileName("BIOMD0000000044");
|
||||
assertEquals("BIOMD0000000044_url.xml is the model file name", "BIOMD0000000044_url.xml", name);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRetrieveModelFileContents() {
|
||||
ModelFileResponse response = service.getModelFile("BIOMD0000000044");
|
||||
|
||||
assertNotNull(response);
|
||||
String content = response.getFileContent();
|
||||
assertNotNull(content);
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
public void shouldThrowExceptionWhenRetrievingFilesForUndefinedModel() {
|
||||
service.getModelFileName(null);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue