Skip to content

Advanced search #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 28 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d1be45c
Adding advancedSearch;
susiehgt Mar 17, 2025
7fbc282
adding boolean advancedSearch to network fetching to mimic intAct por…
susiehgt Mar 18, 2025
84d037a
use of bodyRequest for network fetching advanced search
susiehgt Mar 18, 2025
6c16367
Multiple queries build;
susiehgt Mar 24, 2025
cd1c231
Multiple queries build corrections;
susiehgt Mar 24, 2025
809696c
get the buttons to change color correctly
susiehgt Mar 24, 2025
06f0678
refactoring for UI ruleset integration;
susiehgt Mar 25, 2025
4e9b7c8
ruleset comboboxes to query ok
susiehgt Mar 25, 2025
8939491
Fixing query operator bug for ruleset;
susiehgt Mar 26, 2025
5b58d03
Changes by eragueneau;
susiehgt Mar 28, 2025
88d9a02
Pagination of advance search query;
susiehgt Mar 28, 2025
650d578
:bug: Avoid failing color query if too many taxids
EliotRagueneau Apr 1, 2025
9a0f396
Merge pull request #16 from EBI-IntAct/fix/taxid-414
susiehgt Apr 2, 2025
264e9da
NOT FINISHED:
susiehgt Apr 7, 2025
e3079f2
NOT FINISHED:
susiehgt Apr 9, 2025
760d34b
NOT FINISHED:
susiehgt Apr 9, 2025
7047b88
query to builder and builder to query OK
susiehgt Apr 10, 2025
feac79f
Implementation in Cytoscape OK;
susiehgt Apr 10, 2025
f478b00
Fixing of the AND and OR update from query;
susiehgt Apr 11, 2025
2c92c90
Bug fix: queryTextField not working when added to cytoscape;
susiehgt Apr 14, 2025
ed3831d
- adding of more edge case tests;
susiehgt Apr 14, 2025
5fb5db5
Making the query the network name, small cleaning
susiehgt Apr 14, 2025
5384951
Adding of the negative interactions display + filters
susiehgt Apr 16, 2025
f2e02cd
Positive interaction update to be similar to IntAct portal;
susiehgt Apr 17, 2025
f68a599
Positive interactions selected by default (and negative by default in…
susiehgt Apr 28, 2025
574282c
Following comments on PR#15: cleanup;
susiehgt Apr 29, 2025
f111f5e
Use body in request for network from interactor acs
jmedinaebi May 12, 2025
b72b31c
Update endpoint to get network from interactors
jmedinaebi May 12, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
<enabled>false</enabled>
</releases>
<name>Cytoscape Snapshots</name>
<url>http://code.cytoscape.org/nexus/content/repositories/snapshots/</url>
<url>https://code.cytoscape.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>cytoscape_releases</id>
Expand All @@ -90,7 +90,7 @@
<enabled>true</enabled>
</releases>
<name>Cytoscape Releases</name>
<url>http://code.cytoscape.org/nexus/content/repositories/releases/</url>
<url>https://code.cytoscape.org/nexus/content/repositories/releases/</url>
</repository>
<repository>
<id>apache-repo-releases</id>
Expand All @@ -106,6 +106,7 @@
<enabled>true</enabled>
</releases>
</repository>

</repositories>

<dependencies>
Expand Down Expand Up @@ -249,6 +250,39 @@
<version>${osgi.api.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.34</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.8.2</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.8.2</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>1.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
</dependencies>

</project>
6 changes: 6 additions & 0 deletions src/main/java/uk/ac/ebi/intact/app/internal/CyActivator.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import uk.ac.ebi.intact.app.internal.tasks.query.NoGUIQueryTask;
import uk.ac.ebi.intact.app.internal.tasks.query.factories.ExactQueryTaskFactory;
import uk.ac.ebi.intact.app.internal.tasks.query.factories.FuzzySearchTaskFactory;
import uk.ac.ebi.intact.app.internal.tasks.query.factories.AdvancedSearchTaskFactory;
import uk.ac.ebi.intact.app.internal.tasks.settings.SettingsTask;
import uk.ac.ebi.intact.app.internal.tasks.version.factories.VersionTaskFactory;
import uk.ac.ebi.intact.app.internal.tasks.view.extract.ExtractNetworkViewTaskFactory;
Expand Down Expand Up @@ -222,6 +223,11 @@ public TaskIterator createTaskIterator() {
Properties propsSearch = new Properties();
registerService(bc, intactSearch, NetworkSearchTaskFactory.class, propsSearch);
}
{
AdvancedSearchTaskFactory advancedSearchTaskFactory = new AdvancedSearchTaskFactory(manager);
Properties propsSearch = new Properties();
registerService(bc, advancedSearchTaskFactory, NetworkSearchTaskFactory.class, propsSearch);
}

manager.utils.info("Intact App initialized");
}
Expand Down
85 changes: 66 additions & 19 deletions src/main/java/uk/ac/ebi/intact/app/internal/io/HttpUtils.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package uk.ac.ebi.intact.app.internal.io;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.json.JsonMapper;
import com.fasterxml.jackson.databind.node.NullNode;
import org.cytoscape.io.util.StreamUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import uk.ac.ebi.intact.app.internal.model.managers.Manager;
import uk.ac.ebi.intact.app.internal.ui.components.query.advanced.Field;

import java.io.*;
import java.net.*;
Expand All @@ -19,11 +25,53 @@
import java.util.concurrent.CompletableFuture;
import java.util.function.Supplier;

import static uk.ac.ebi.intact.app.internal.model.managers.Manager.INTACT_GRAPH_WS;

public class HttpUtils {

private static final HttpClient httpClient = HttpClient.newBuilder()
.version(HttpClient.Version.HTTP_1_1)
.build();

private static final HttpRequest.Builder requestBuilder = HttpRequest.newBuilder()
.header("Content-Type", "application/json")
.header("Accept", "application/json");

private static final ObjectMapper mapper = JsonMapper.builder()
.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true)
.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS, true)
.build();

private static final Logger LOGGER = LoggerFactory.getLogger(HttpUtils.class);

public static JsonNode getJsonNetworkWithRequestBody(String query, int page) throws IOException, InterruptedException {
String baseUrl = INTACT_GRAPH_WS + "network/fromPagedInteractions";

Map<String, Object> params = Map.of(
"query", query,
"advancedSearch", isAdvancedSearch(query),
"page", page
);

HttpRequest request = requestBuilder
.uri(URI.create(baseUrl))
.POST(HttpRequest.BodyPublishers.ofString(mapper.writeValueAsString(params)))
.build();

HttpResponse<InputStream> response = httpClient.send(request, HttpResponse.BodyHandlers.ofInputStream());

return mapper.readTree(response.body());
}

public static boolean isAdvancedSearch(String query) {
for (Field field : Field.values()) {
if (query.contains(field.getMiqlQuery())) {
return true;
}
}
return false;
}

public static JsonNode getJSON(String url, Map<String, String> queryMap, Manager manager) {
URL trueURL;
try {
Expand All @@ -48,7 +96,7 @@ public static JsonNode getJSON(String url, Map<String, String> queryMap, Manager
entityStream.close();

} catch (Exception e) {
e.printStackTrace();
logError(e.getMessage());
}
return jsonObject;
}
Expand All @@ -65,11 +113,11 @@ public static JsonNode postJSON(String url, Map<Object, Object> data, Manager ma

HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
if (response == null) {
manager.utils.error("No response from " + url + " with post data = " + data.toString());
manager.utils.error("No response from " + url + " with post data = " + data);
return null;
}
if (response.statusCode() != 200) {
manager.utils.error("Error " + response.statusCode() + " from " + url + " with post data = " + data.toString());
manager.utils.error("Error " + response.statusCode() + " from " + url + " with post data = " + data);
}
return new ObjectMapper().readTree(response.body());

Expand All @@ -80,32 +128,31 @@ public static JsonNode postJSON(String url, Map<Object, Object> data, Manager ma
}
}

public static JsonNode postJSON(String url, Map<Object, Object> data, Manager manager, Supplier<Boolean> isCancelled) {
public static JsonNode postJSON(String url, Map<Object, Object> body, Manager manager, Supplier<Boolean> isCancelled) {
try {
HttpRequest request = HttpRequest.newBuilder()
.POST(buildFormDataFromMap(data))
.uri(URI.create(url))
.POST(HttpRequest.BodyPublishers.ofString(mapper.writeValueAsString(body)))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created a new endpoint in the GraphDB-WS, and it is deployed now. Endpoints is to replace network/data with a proper request body. It is named network/fromInteractors to be consistent with the other one.

I haven't tested this, so we should test it before this is merged.

.setHeader("User-Agent", "Java 11 HttpClient Bot") // add request header
.header("Content-Type", "application/x-www-form-urlencoded")
.header("accept", "application/json")
.build();
Instant begin = Instant.now();
CompletableFuture<String> body = httpClient.sendAsync(request, HttpResponse.BodyHandlers.ofString())
CompletableFuture<String> responseBody = httpClient.sendAsync(request, HttpResponse.BodyHandlers.ofString())
.thenApply(response -> {
if (response.statusCode() != 200) {
manager.utils.error("Error " + response.statusCode() + " from " + url + " with post data = " + data.toString());
manager.utils.error("Error " + response.statusCode() + " from " + url + " with post data = " + body);
}
return response;
}).thenApply(HttpResponse::body);

while (!body.isDone()) {
while (!responseBody.isDone()) {
if (isCancelled.get()) {
body.cancel(true);
responseBody.cancel(true);
return null;
}
}
System.out.println("Response received in " + Duration.between(begin, Instant.now()).toSeconds() + "s from " + url);
return new ObjectMapper().readTree(body.get());
return new ObjectMapper().readTree(responseBody.get());

} catch (Exception e) {
// e.printStackTrace();
Expand All @@ -114,7 +161,6 @@ public static JsonNode postJSON(String url, Map<Object, Object> data, Manager ma
}
}


public static String getStringArguments(Map<String, String> args) {
StringBuilder s = null;
try {
Expand All @@ -125,26 +171,24 @@ public static String getStringArguments(Map<String, String> args) {
s.append("&").append(key).append("=").append(URLEncoder.encode(args.get(key), StandardCharsets.UTF_8.displayName()));
}
} catch (Exception e) {
e.printStackTrace();
logError(e.getMessage());
}
return s != null ? s.toString() : "";
}


public static String truncate(String str) {
if (str.length() > 1000)
return str.substring(0, 1000) + "...";
return str;
}


private static URLConnection executeWithRedirect(Manager manager, String url, Map<String, String> queryMap) throws Exception {
// Get the connection from Cytoscape
HttpURLConnection connection = (HttpURLConnection) manager.utils.getService(StreamUtil.class).getURLConnection(new URL(url));

// We want to write on the stream
connection.setDoOutput(true);
// We want to deal with redirection ourself
// We want to deal with redirection ourselves
connection.setInstanceFollowRedirects(false);

// We write the POST arguments
Expand Down Expand Up @@ -178,7 +222,7 @@ private static String readStream(InputStream stream) throws Exception {
builder.append(line); // + "\r\n"(no need, json has no line breaks!)
}
}
System.out.println("JSON error response: " + builder.toString());
System.out.println("JSON error response: " + builder);
return builder.toString();
}

Expand All @@ -194,7 +238,7 @@ public static String getRequestResultForUrl(String requestURL) {
}
jsonText = builder.toString();
} catch (IOException e) {
e.printStackTrace();
logError(e.getMessage());
}

return jsonText;
Expand All @@ -206,7 +250,7 @@ public static JsonNode getJsonForUrl(String jsonQuery) {
try {
return new ObjectMapper().readTree(jsonText);
} catch (JsonProcessingException e) {
e.printStackTrace();
logError(e.getMessage());
}
}
return null;
Expand Down Expand Up @@ -235,4 +279,7 @@ private static HttpRequest.BodyPublisher buildFormDataFromMap(Map<Object, Object
return HttpRequest.BodyPublishers.ofString(builder.toString());
}

private static void logError(String message) {
LOGGER.error(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public abstract class Edge implements Element {
public final double miScore;
public final List<String> sourceFeatureAcs;
public final List<String> targetFeatureAcs;
public final boolean isNegative;


public static Edge createEdge(Network network, CyEdge edge) {
Expand Down Expand Up @@ -57,6 +58,8 @@ public static Edge createEdge(Network network, CyEdge edge) {
if (targetFeatureAcs != null) {
targetFeatureAcs.removeIf(String::isBlank);
}

isNegative = IS_NEGATIVE_INTERACTION.getValue(edgeRow);
}

public abstract Map<Node, List<Feature>> getFeatures() ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
import uk.ac.ebi.intact.app.internal.model.core.network.Network;
import uk.ac.ebi.intact.app.internal.model.tables.fields.enums.FeatureFields;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;

import static uk.ac.ebi.intact.app.internal.model.managers.Manager.INTACT_GRAPH_WS;
import static uk.ac.ebi.intact.app.internal.model.tables.fields.enums.EdgeFields.*;
Expand All @@ -36,6 +33,7 @@ public class EvidenceEdge extends Edge {
public final CVTerm targetBiologicalRole;
public final CVTerm targetExperimentalRole;
private JsonNode detailsJSON;
public final Boolean isNegative;

EvidenceEdge(Network network, CyEdge edge) {
super(network, edge);
Expand All @@ -55,6 +53,7 @@ public class EvidenceEdge extends Edge {
targetExperimentalRole = new CVTerm(edgeRow, EXPERIMENTAL_ROLE.TARGET);

pubMedId = PUBMED_ID.getValue(edgeRow);
isNegative = IS_NEGATIVE_INTERACTION.getValue(edgeRow);
}

@Override
Expand Down Expand Up @@ -128,6 +127,7 @@ public EvidenceEdge cloneInto(Network network) {
AFFECTED_BY_MUTATION.setValue(row, isAffectedByMutation());

PUBMED_ID.setValue(row, pubMedId);

return (EvidenceEdge) Edge.createEdge(network, edge);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ public Map<Node, List<Feature>> getFeatures() {
return features;
}

public Boolean isNegative() {
return getSummarizedEdges().stream().anyMatch(edge -> edge.isNegative);
}

protected void buildFeatures(Map<Node, List<Feature>> features, List<String> featureAcs, Node participant, Set<Long> edgesSUID) {
ArrayList<Feature> participantFeatures = new ArrayList<>();
features.put(participant, participantFeatures);
Expand Down Expand Up @@ -64,6 +68,7 @@ public void updateSummary() {
if (summarizedCyEdge == null) return false;
return network.getEvidenceEdge(summarizedCyEdge) != null;
}).count();
EdgeFields.IS_NEGATIVE_INTERACTION.setValue(edgeRow, isNegative());
EdgeFields.SUMMARY_NB_EDGES.setValue(edgeRow, nbSummarizedEdges);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ private void setupFilters(boolean loadData) {
filters.add(new EdgeExpansionTypeFilter(this));
filters.add(new EdgeTypeFilter(this));
filters.add(new EdgeMutationFilter(this));
filters.add(new EdgePositiveFilter(this));

filters.add(new OrphanNodeFilter(this)); // Must be after edge filters
filters.add(new OrphanEdgeFilter(this));
Expand Down
Loading