Skip to content

Commit

Permalink
Fix: Handle empty network parameters on session startup
Browse files Browse the repository at this point in the history
  • Loading branch information
AkMo3 committed Jul 8, 2022
1 parent f3f2664 commit 1440ccb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
Expand Up @@ -26,7 +26,10 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;


public class FilterEnrichmentTableTask extends AbstractTask implements ObservableTask {
Expand All @@ -38,28 +41,28 @@ public class FilterEnrichmentTableTask extends AbstractTask implements Observabl
gravity = 1.0)
public ListMultipleSelection<TermSource> categories = new ListMultipleSelection<>(TermSource.getValues());

@Tunable(description = "Select evidence code.",
@Tunable(description = "Select evidence code",
tooltip = "Select the evidence codes to show in the table. If multiple codes are selected, those terms which " +
"contains all the selected codes will be present in result.",
"contains all the selected codes will be present in result",
exampleStringValue = "GO:0005737",
gravity = 1.0
)
public ListMultipleSelection<String> evidenceCodes;

@Tunable(description = "Remove redundant terms",
tooltip = "Removes terms whose enriched genes significantly overlap with already selected terms.",
longDescription = "Removes terms whose enriched genes significantly overlap with already selected terms.",
tooltip = "Removes terms whose enriched genes significantly overlap with already selected terms",
longDescription = "Removes terms whose enriched genes significantly overlap with already selected terms",
exampleStringValue = "true",
gravity = 8.0)
public boolean removeOverlapping;

@Tunable(description = "Redundancy cutoff",
tooltip = "<html>This is the maximum Jaccard similarity that will be allowed <br/>"
+ "between a less significant term and a more significant term such that <br/>"
+ "the less significant term is kept in the list.</html>",
+ "the less significant term is kept in the list</html>",
longDescription = "This is the maximum Jaccard similarity that will be allowed "
+ "between a less significant term and a more significant term such that "
+ "the less significant term is kept in the list.",
+ "the less significant term is kept in the list",
exampleStringValue="0.5",
params="slider=true", dependsOn="removeOverlapping=true", gravity = 9.0)
public BoundedDouble overlapCutoff = new BoundedDouble(0.0, 0.5, 1.0, false, false);
Expand All @@ -77,6 +80,7 @@ public FilterEnrichmentTableTask(final CyServiceRegistrar registrar, EnrichmentC
this.applicationManager = registrar.getService(CyApplicationManager.class);
this.network = applicationManager.getCurrentNetwork();
this.enrichmentPanel = panel;
this.setCategoriesAndEvidenceCodesAtStartup();
List<String> evidenceCodesEnum = EVIDENCE_CODES.stringValue();
categories.setSelectedValues(ModelUtils.getNetSelectedCategories(network));
this.evidenceCodes = new ListMultipleSelection<>(evidenceCodesEnum);
Expand All @@ -85,6 +89,21 @@ public FilterEnrichmentTableTask(final CyServiceRegistrar registrar, EnrichmentC
overlapCutoff.setValue(ModelUtils.getNetRedundantCutoff(network));
}

private void setCategoriesAndEvidenceCodesAtStartup() {
List<TermSource> selectedCategories = ModelUtils.getNetSelectedCategories(network);
if (!selectedCategories.isEmpty()) {
TermSource termSource = selectedCategories.get(0);
if (Objects.isNull(termSource)) ModelUtils.setNetSelectedCategories(network, Collections.emptyList());
}
List<String> selectedEvidenceCodes = ModelUtils.getNetSelectedEvidenceCode(network);
if (!selectedEvidenceCodes.isEmpty()) {
String termSource = selectedEvidenceCodes.get(0);
System.out.println("Filer evi: " + termSource);
if (Objects.isNull(termSource) || termSource.isEmpty())
ModelUtils.setNetSelectedEvidenceCodes(network, Collections.emptyList());
}
}


@Override
public void run(TaskMonitor monitor) throws Exception {
Expand Down
Expand Up @@ -229,7 +229,7 @@ public void filter(List<TermSource> sources, List<String> evidenceList, boolean
double cutoff) {
filterBySource(sources);
int length = filterByEvidenceCode(evidenceList);
if (removeOverlapping) {
if (removeOverlapping && length > 0) {
rowNames = removeRedundancy(length, cutoff);
}
fireTableDataChanged();
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/nrnb/gsoc/enrichment/utils/ModelUtils.java
Expand Up @@ -762,7 +762,7 @@ public static void setNetSelectedEvidenceCodes(CyNetwork network, List<String> s

public static List<String> getNetSelectedEvidenceCode(CyNetwork network) {
if (network.getDefaultNetworkTable().getColumn(NET_SELECTED_EVIDENCE_CODES) == null) {
return new ArrayList<>();
return Collections.emptyList();
};
return network.getRow(network).getList(NET_SELECTED_EVIDENCE_CODES, String.class);
}
Expand All @@ -776,10 +776,10 @@ public static void setNetSelectedCategories(CyNetwork network, List<TermSource>
public static List<TermSource> getNetSelectedCategories(CyNetwork network) {
CyColumn column = network.getDefaultNetworkTable().getColumn(NET_SELECTED_CATEGORIES);
if (column == null) {
return new ArrayList<>();
return Collections.emptyList();
};
List<String> categoriesString = network.getRow(network).getList(NET_SELECTED_CATEGORIES, String.class);
if (categoriesString == null || categoriesString.isEmpty()) return new ArrayList<>();
if (categoriesString == null || categoriesString.isEmpty()) return Collections.emptyList();
return categoriesString.stream().map(TermSource::getByKey).collect(Collectors.toList());
}

Expand Down

0 comments on commit 1440ccb

Please sign in to comment.