From b41e048ca5217c3cd7cdff5ece0f20d885ce0a80 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Tue, 14 Sep 2021 12:35:20 +0100 Subject: [PATCH] =?utf8?q?JAL-3829=20some=20providers=20don=E2=80=99t=20prov?= =?utf8?q?ide=20model=20quality,=20some=20experimental=20methods=20don=E2=80?= =?utf8?q?=99t=20provide=20a=20resolution=20-=20try=20to=20leave=20these=20i?= =?utf8?q?n=20their=20natural=20order?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../gui/structurechooser/TDBResultAnalyser.java | 102 +++++++++++++++----- 1 file changed, 79 insertions(+), 23 deletions(-) diff --git a/src/jalview/gui/structurechooser/TDBResultAnalyser.java b/src/jalview/gui/structurechooser/TDBResultAnalyser.java index 06dbe2d..ffac9c4 100644 --- a/src/jalview/gui/structurechooser/TDBResultAnalyser.java +++ b/src/jalview/gui/structurechooser/TDBResultAnalyser.java @@ -23,8 +23,8 @@ public class TDBResultAnalyser */ private static List EXP_CATEGORIES = Arrays .asList(new String[] - { "EXPERIMENTALLY DETERMINED", "DEEP-LEARNING", - "TEMPLATE-BASED" }); + { "EXPERIMENTALLY DETERMINED", "DEEP-LEARNING", "TEMPLATE-BASED", + "AB-INITIO", "CONFORMATIONAL ENSEMBLE" }); private SequenceI seq; @@ -45,17 +45,19 @@ public class TDBResultAnalyser /** * selection model */ - private String filter=null; + private String filter = null; + /** * limit to particular source */ - private String sourceFilter=null; + private String sourceFilter = null; private int idx_mprov; public TDBResultAnalyser(SequenceI seq, Collection collectedResults, - FTSRestRequest lastTdbRequest, String fieldToFilterBy, String string) + FTSRestRequest lastTdbRequest, String fieldToFilterBy, + String string) { this.seq = seq; this.collectedResults = collectedResults; @@ -69,13 +71,27 @@ public class TDBResultAnalyser idx_mqual = lastTdbRequest.getFieldIndex("Confidence"); idx_resol = lastTdbRequest.getFieldIndex("Resolution"); } - private final int scoreCategory(String cat) + + /** + * maintain and resolve categories to 'trust order' TODO: change the trust + * scheme to something comprehensible. + * + * @param cat + * @return 0 for null cat, less than zero for others + */ + public final int scoreCategory(String cat) { - // TODO: make quicker - int idx = EXP_CATEGORIES.indexOf(cat.toUpperCase()); + if (cat == null) + { + return 0; + } + String upper_cat = cat.toUpperCase(); + int idx = EXP_CATEGORIES.indexOf(upper_cat); if (idx == -1) { System.out.println("Unknown category: '" + cat + "'"); + EXP_CATEGORIES.add(upper_cat); + idx = EXP_CATEGORIES.size() - 1; } return -EXP_CATEGORIES.size() - idx; } @@ -96,6 +112,9 @@ public class TDBResultAnalyser int up_s = (Integer) row.getSummaryData()[idx_ups]; int up_e = (Integer) row.getSummaryData()[idx_upe]; String provider = (String) row.getSummaryData()[idx_mprov]; + String mcat = (String) row.getSummaryData()[idx_mcat]; + // this makes sure all new categories are in the score array. + int scorecat = scoreCategory(mcat); if (sourceFilter == null || sourceFilter.equals(provider)) { if (seq == row.getSummaryData()[0] && up_e > seq.getStart() @@ -117,9 +136,12 @@ public class TDBResultAnalyser int o1_s = (Integer) o1data[idx_ups]; int o1_e = (Integer) o1data[idx_upe]; int o1_cat = scoreCategory((String) o1data[idx_mcat]); + String o1_prov= ((String) o1data[idx_mprov]).toUpperCase(); int o2_s = (Integer) o2data[idx_ups]; int o2_e = (Integer) o2data[idx_upe]; int o2_cat = scoreCategory((String) o2data[idx_mcat]); + String o2_prov= ((String) o2data[idx_mprov]).toUpperCase(); + if (o1_cat == o2_cat) { @@ -131,14 +153,30 @@ public class TDBResultAnalyser { if (o1_cat == scoreCategory(EXP_CATEGORIES.get(0))) { + if (o1_prov.equals(o2_prov)) { + if ("PDBE".equals(o1_prov)) { + if (eitherNull(idx_resol,o1data,o2data)) + { + return nonNullFirst(idx_resol,o1data,o2data); + } // experimental structures, so rank on quality double o1_res = (Double) o1data[idx_resol]; double o2_res = (Double) o2data[idx_resol]; return (o2_res < o1_res) ? 1 : (o2_res == o1_res) ? 0 : -1; + } else { + return 0; // no change in order + } + } else { + // PDBe always ranked above all other experimentally determined categories + return "PDBE".equals(o1_prov) ? -1 : "PDBE".equals(o2_prov) ? 1 : 0; + } } else { - // models, so rank on qmean + if (eitherNull(idx_mqual,o1data, o2data)) { + return nonNullFirst(idx_mqual, o1data, o2data); + } + // models, so rank on qmean - b float o1_mq = (Float) o1data[idx_mqual]; float o2_mq = (Float) o2data[idx_mqual]; return (o2_mq < o1_mq) ? 1 : (o2_mq == o1_mq) ? 0 : -1; @@ -160,6 +198,18 @@ public class TDBResultAnalyser } } + private int nonNullFirst(int idx_resol, Object[] o1data, + Object[] o2data) + { + return o1data[idx_resol] == o2data[idx_resol] ? 0: o1data[idx_resol] != null ? -1 : 1; + } + + private boolean eitherNull(int idx_resol, Object[] o1data, + Object[] o2data) + { + return (o1data[idx_resol] == null || o2data[idx_resol]==null); + } + @Override public boolean equals(Object obj) { @@ -170,49 +220,55 @@ public class TDBResultAnalyser } /** - * return list of structures to be marked as selected for this sequence according to given criteria - * @param filteredStructures - sorted, filtered structures from getFilteredResponse + * return list of structures to be marked as selected for this sequence + * according to given criteria + * + * @param filteredStructures + * - sorted, filtered structures from getFilteredResponse * */ public List selectStructures(List filteredStructures) { List selected = new ArrayList(); BitSet cover = new BitSet(); - cover.set(seq.getStart(),seq.getEnd()); + cover.set(seq.getStart(), seq.getEnd()); // walk down the list of structures, selecting some to add to selected - for (FTSData structure:filteredStructures) + for (FTSData structure : filteredStructures) { - Object[] odata=structure.getSummaryData(); + Object[] odata = structure.getSummaryData(); int o1_s = (Integer) odata[idx_ups]; int o1_e = (Integer) odata[idx_upe]; int o1_cat = scoreCategory((String) odata[idx_mcat]); BitSet scover = new BitSet(); // measure intersection - scover.set(o1_s,o1_e); + scover.set(o1_s, o1_e); scover.and(cover); - if (scover.cardinality()>4) + if (scover.cardinality() > 4) { selected.add(structure); // clear the range covered by this structure - cover.andNot(scover); + cover.andNot(scover); } } - // final step is to sort on length - this might help the superposition process - Collections.sort(selected,new Comparator() + // final step is to sort on length - this might help the superposition + // process + Collections.sort(selected, new Comparator() { @Override public int compare(FTSData o1, FTSData o2) { Object[] o1data = o1.getSummaryData(); Object[] o2data = o2.getSummaryData(); - int o1_xt = ((Integer) o1data[idx_upe]) - ((Integer) o1data[idx_ups]); + int o1_xt = ((Integer) o1data[idx_upe]) + - ((Integer) o1data[idx_ups]); int o1_cat = scoreCategory((String) o1data[idx_mcat]); - int o2_xt = ((Integer) o2data[idx_upe]-(Integer) o2data[idx_ups]); + int o2_xt = ((Integer) o2data[idx_upe] - (Integer) o2data[idx_ups]); int o2_cat = scoreCategory((String) o2data[idx_mcat]); - return o2_xt-o1_xt; + return o2_xt - o1_xt; } }); - if (filter.equals(ThreeDBStructureChooserQuerySource.FILTER_FIRST_BEST_COVERAGE)) + if (filter.equals( + ThreeDBStructureChooserQuerySource.FILTER_FIRST_BEST_COVERAGE)) { return selected.subList(0, 1); } -- 1.7.10.2