From 26b115b0a77d521da92a06572d9b7819c2d0d49a Mon Sep 17 00:00:00 2001 From: hansonr Date: Fri, 25 Jan 2019 23:13:29 -0600 Subject: [PATCH] Jalview.isJS() --> Platform.isJS(), DBRefEntry[] --> List --- src/jalview/analysis/AlignmentUtils.java | 50 +++-- src/jalview/analysis/CrossRef.java | 81 ++++--- src/jalview/analysis/Dna.java | 50 +++-- src/jalview/analysis/SequenceIdMatcher.java | 8 +- src/jalview/bin/Cache.java | 29 ++- src/jalview/bin/Jalview.java | 29 +-- src/jalview/datamodel/DBRefEntry.java | 113 ++++++---- src/jalview/datamodel/DBRefSource.java | 27 +++ src/jalview/datamodel/Sequence.java | 164 +++++++++----- src/jalview/datamodel/SequenceGroup.java | 18 +- src/jalview/datamodel/SequenceI.java | 13 +- src/jalview/ext/ensembl/EnsemblFeatures.java | 8 +- src/jalview/ext/ensembl/EnsemblGene.java | 22 ++ src/jalview/ext/ensembl/EnsemblSeqProxy.java | 45 +++- src/jalview/fts/service/pdb/PDBFTSRestClient.java | 4 +- .../fts/service/uniprot/UniProtFTSRestClient.java | 6 +- src/jalview/gui/AlignFrame.java | 3 +- src/jalview/gui/CrossRefAction.java | 8 +- src/jalview/gui/Desktop.java | 10 +- src/jalview/gui/FeatureSettings.java | 3 +- src/jalview/gui/IdPanel.java | 3 +- src/jalview/gui/ImageExporter.java | 3 +- src/jalview/gui/Jalview2XML.java | 16 +- src/jalview/gui/JvOptionPane.java | 10 +- src/jalview/gui/PopupMenu.java | 18 +- src/jalview/gui/Preferences.java | 9 +- src/jalview/gui/SeqPanel.java | 3 +- src/jalview/gui/SequenceFetcher.java | 11 +- src/jalview/gui/StructureChooser.java | 6 +- src/jalview/gui/TreePanel.java | 8 +- src/jalview/io/AppletFormatAdapter.java | 3 +- src/jalview/io/JSONFile.java | 13 +- src/jalview/io/JalviewFileChooser.java | 3 +- src/jalview/io/ModellerDescription.java | 16 +- src/jalview/io/SequenceAnnotationReport.java | 4 +- src/jalview/io/StockholmFile.java | 78 ++++--- src/jalview/io/WSWUBlastClient.java | 8 +- src/jalview/io/cache/JvCacheableInputBox.java | 32 +-- src/jalview/io/vamsas/Datasetsequence.java | 6 +- src/jalview/io/vamsas/Sequencemapping.java | 28 ++- src/jalview/io/vcf/VCFLoader.java | 2 +- src/jalview/jbgui/GAlignFrame.java | 11 +- src/jalview/jbgui/GDesktop.java | 7 +- src/jalview/jbgui/GPreferences.java | 10 +- src/jalview/project/Jalview2XML.java | 16 +- src/jalview/renderer/AnnotationRenderer.java | 3 +- src/jalview/util/DBRefUtils.java | 230 +++++++++++++------- src/jalview/util/Platform.java | 1 + src/jalview/util/UrlLink.java | 6 +- src/jalview/ws/DBRefFetcher.java | 51 +++-- src/jalview/ws/jws2/JabaParamStore.java | 2 +- src/jalview/ws/seqfetcher/ASequenceFetcher.java | 3 +- src/jalview/ws/utils/UrlDownloadClient.java | 15 +- 53 files changed, 829 insertions(+), 497 deletions(-) diff --git a/src/jalview/analysis/AlignmentUtils.java b/src/jalview/analysis/AlignmentUtils.java index 4f8897a..8fd961e 100644 --- a/src/jalview/analysis/AlignmentUtils.java +++ b/src/jalview/analysis/AlignmentUtils.java @@ -1599,11 +1599,12 @@ public class AlignmentUtils return false; } String name = seq2.getName(); - final DBRefEntry[] xrefs = seq1.getDBRefs(); + final List xrefs = seq1.getDBRefs(); if (xrefs != null) { - for (DBRefEntry xref : xrefs) + for (int ix = 0, nx = xrefs.size(); ix < nx; ix++) { + DBRefEntry xref = xrefs.get(ix); String xrefName = xref.getSource() + "|" + xref.getAccessionId(); // case-insensitive test, consistent with DBRefEntry.equalRef() if (xrefName.equalsIgnoreCase(name)) @@ -1799,8 +1800,10 @@ public class AlignmentUtils // need to // synthesize an xref. - for (DBRefEntry primRef : dnaDss.getPrimaryDBRefs()) + List primrefs = dnaDss.getPrimaryDBRefs(); + for (int ip = 0, np = primrefs.size(); ip < np; ip++) { + DBRefEntry primRef = primrefs.get(ip); /* * create a cross-reference from CDS to the source sequence's * primary reference and vice versa @@ -1814,7 +1817,6 @@ public class AlignmentUtils dnaSeq.addDBRef(new DBRefEntry(source, version, cdsSeq .getName(), new Mapping(cdsSeqDss, dnaToCdsMap))); - // problem here is that the cross-reference is synthesized - // cdsSeq.getName() may be like 'CDS|dnaaccession' or // 'CDS|emblcdsacc' @@ -1827,7 +1829,6 @@ public class AlignmentUtils .getInverse())); proteinProduct.addDBRef(proteinToCdsRef); } - /* * transfer any features on dna that overlap the CDS */ @@ -2071,13 +2072,15 @@ public class AlignmentUtils List direct = new ArrayList<>(); HashSet directSources = new HashSet<>(); - if (contig.getDBRefs() != null) + List refs = contig.getDBRefs(); + if (refs != null) { - for (DBRefEntry dbr : contig.getDBRefs()) + for (int ib = 0, nb = refs.size(); ib < nb; ib++) { - if (dbr.hasMap() && dbr.getMap().getMap().isTripletMap()) + DBRefEntry dbr = refs.get(ib); + MapList map; + if (dbr.hasMap() && (map = dbr.getMap().getMap()).isTripletMap()) { - MapList map = dbr.getMap().getMap(); // check if map is the CDS mapping if (mapping.getMap().equals(map)) { @@ -2087,21 +2090,22 @@ public class AlignmentUtils } } } - DBRefEntry[] onSource = DBRefUtils.selectRefs( + List onSource = DBRefUtils.selectRefs( proteinProduct.getDBRefs(), directSources.toArray(new String[0])); List propagated = new ArrayList<>(); // and generate appropriate mappings - for (DBRefEntry cdsref : direct) + for (int ic = 0, nc = direct.size(); ic < nc; ic++) { + DBRefEntry cdsref = direct.get(ic); + Mapping m = cdsref.getMap(); // clone maplist and mapping MapList cdsposmap = new MapList( Arrays.asList(new int[][] { new int[] { cdsSeq.getStart(), cdsSeq.getEnd() } }), - cdsref.getMap().getMap().getToRanges(), 3, 1); - Mapping cdsmap = new Mapping(cdsref.getMap().getTo(), - cdsref.getMap().getMap()); + m.getMap().getToRanges(), 3, 1); + Mapping cdsmap = new Mapping(m.getTo(),m.getMap()); // create dbref DBRefEntry newref = new DBRefEntry(cdsref.getSource(), @@ -2767,19 +2771,25 @@ public class AlignmentUtils SequenceIdMatcher matcher = new SequenceIdMatcher(seqs); if (xrefs != null) { - for (SequenceI xref : xrefs) + // BH 2019.01.25 streamlined this triply nested loop to remove all iterators + + for (int ix = 0, nx = xrefs.length; ix < nx; ix++) { - DBRefEntry[] dbrefs = xref.getDBRefs(); + SequenceI xref = xrefs[ix]; + List dbrefs = xref.getDBRefs(); if (dbrefs != null) { - for (DBRefEntry dbref : dbrefs) + for (int ir = 0, nir = dbrefs.size(); ir < nir; ir++) { - if (dbref.getMap() == null || dbref.getMap().getTo() == null - || dbref.getMap().getTo().isProtein() != isProtein) + DBRefEntry dbref = dbrefs.get(ir); + Mapping map = dbref.getMap(); + SequenceI mto; + if (map == null || (mto = map.getTo()) == null + || mto.isProtein() != isProtein) { continue; } - SequenceI mappedTo = dbref.getMap().getTo(); + SequenceI mappedTo = mto; SequenceI match = matcher.findIdMatch(mappedTo); if (match == null) { diff --git a/src/jalview/analysis/CrossRef.java b/src/jalview/analysis/CrossRef.java index 0e7662b..4f01cea 100644 --- a/src/jalview/analysis/CrossRef.java +++ b/src/jalview/analysis/CrossRef.java @@ -143,14 +143,14 @@ public class CrossRef /* * first find seq's xrefs (dna-to-peptide or peptide-to-dna) */ - DBRefEntry[] rfs = DBRefUtils.selectDbRefs(!fromDna, seq.getDBRefs()); + List rfs = DBRefUtils.selectDbRefs(!fromDna, seq.getDBRefs()); addXrefsToSources(rfs, sources); if (dataset != null) { /* * find sequence's direct (dna-to-dna, peptide-to-peptide) xrefs */ - DBRefEntry[] lrfs = DBRefUtils.selectDbRefs(fromDna, seq.getDBRefs()); + List lrfs = DBRefUtils.selectDbRefs(fromDna, seq.getDBRefs()); List foundSeqs = new ArrayList<>(); /* @@ -164,7 +164,7 @@ public class CrossRef */ for (SequenceI rs : foundSeqs) { - DBRefEntry[] xrs = DBRefUtils.selectDbRefs(!fromDna, + List xrs = DBRefUtils.selectDbRefs(!fromDna, rs.getDBRefs()); addXrefsToSources(xrs, sources); } @@ -178,7 +178,7 @@ public class CrossRef * @param xrefs * @param sources */ - void addXrefsToSources(DBRefEntry[] xrefs, List sources) + void addXrefsToSources(List xrefs, List sources) { if (xrefs != null) { @@ -230,18 +230,18 @@ public class CrossRef dss = dss.getDatasetSequence(); } boolean found = false; - DBRefEntry[] xrfs = DBRefUtils.selectDbRefs(!fromDna, + List xrfs = DBRefUtils.selectDbRefs(!fromDna, dss.getDBRefs()); // ENST & ENSP comes in to both Protein and nucleotide, so we need to // filter them // out later. - if ((xrfs == null || xrfs.length == 0) && dataset != null) + if ((xrfs == null || xrfs.size() == 0) && dataset != null) { /* * found no suitable dbrefs on sequence - look for sequences in the * alignment which share a dbref with this one */ - DBRefEntry[] lrfs = DBRefUtils.selectDbRefs(fromDna, + List lrfs = DBRefUtils.selectDbRefs(fromDna, seq.getDBRefs()); /* @@ -370,7 +370,7 @@ public class CrossRef { // do a bit more work - search for sequences with references matching // xrefs on this sequence. - found = searchDataset(fromDna, dss, xref, rseqs, cf, false); + found = searchDataset(fromDna, dss, xref, rseqs, cf, false, DBRefUtils.SEARCH_MODE_FULL); } if (found) { @@ -400,7 +400,7 @@ public class CrossRef } private void retrieveCrossRef(List sourceRefs, SequenceI seq, - DBRefEntry[] xrfs, boolean fromDna, AlignedCodonFrame cf) + List xrfs, boolean fromDna, AlignedCodonFrame cf) { ASequenceFetcher sftch = SequenceFetcherFactory.getSequenceFetcher(); SequenceI[] retrieved = null; @@ -483,19 +483,24 @@ public class CrossRef private void removeAlreadyRetrievedSeqs(List sourceRefs, boolean fromDna) { - DBRefEntry[] dbrSourceSet = sourceRefs.toArray(new DBRefEntry[0]); - for (SequenceI sq : dataset.getSequences()) + List dbrSourceSet = new ArrayList(sourceRefs); + List dsSeqs = dataset.getSequences(); + for (int ids = dsSeqs.size(); --ids >= 0;) { + SequenceI sq = dsSeqs.get(ids); boolean dupeFound = false; // !fromDna means we are looking only for nucleotide sequences, not // protein if (sq.isProtein() == fromDna) { - for (DBRefEntry dbr : sq.getPrimaryDBRefs()) + List sqdbrefs = sq.getPrimaryDBRefs(); + for (int idb = sqdbrefs.size(); --idb >= 0;) { - for (DBRefEntry found : DBRefUtils.searchRefs(dbrSourceSet, dbr)) + DBRefEntry dbr = sqdbrefs.get(idb); + List searchrefs = DBRefUtils.searchRefs(dbrSourceSet, dbr, DBRefUtils.SEARCH_MODE_FULL); + for (int isr = searchrefs.size(); --isr >= 0;) { - sourceRefs.remove(found); + sourceRefs.remove(searchrefs.get(isr)); dupeFound = true; } } @@ -503,7 +508,8 @@ public class CrossRef if (dupeFound) { // rebuild the search array from the filtered sourceRefs list - dbrSourceSet = sourceRefs.toArray(new DBRefEntry[0]); + dbrSourceSet.clear(); + dbrSourceSet.addAll(sourceRefs); } } } @@ -526,11 +532,13 @@ public class CrossRef * sourceSequence */ boolean imported = false; - DBRefEntry[] dbr = retrievedSequence.getDBRefs(); + List dbr = retrievedSequence.getDBRefs(); if (dbr != null) { - for (DBRefEntry dbref : dbr) + for (int ib = 0, nb = dbr.size(); ib < nb; ib++) { + + DBRefEntry dbref = dbr.get(ib); SequenceI matched = findInDataset(dbref); if (matched == sourceSequence) { @@ -542,9 +550,10 @@ public class CrossRef Mapping map = dbref.getMap(); if (map != null) { - if (map.getTo() != null && map.getMap() != null) + SequenceI ms = map.getTo(); + if (ms != null && map.getMap() != null) { - if (map.getTo() == sourceSequence) + if (ms == sourceSequence) { // already called to import once, and most likely this sequence // already imported ! @@ -555,7 +564,7 @@ public class CrossRef /* * sequence is new to dataset, so save a reference so it can be added. */ - newDsSeqs.add(map.getTo()); + newDsSeqs.add(ms); continue; } @@ -567,7 +576,6 @@ public class CrossRef { // compare ms with dss and replace with dss in mapping // if map is congruent - SequenceI ms = map.getTo(); // TODO findInDataset requires exact sequence match but // 'congruent' test is only for the mapped part // maybe not a problem in practice since only ENA provide a @@ -589,7 +597,7 @@ public class CrossRef + matched.getName(); System.out.println(msg); - DBRefEntry[] toRefs = map.getTo().getDBRefs(); + List toRefs = map.getTo().getDBRefs(); if (toRefs != null) { /* @@ -682,7 +690,7 @@ public class CrossRef { return; } - DBRefEntry[] dbrefs = mapTo.getDBRefs(); + List dbrefs = mapTo.getDBRefs(); if (dbrefs == null) { return; @@ -739,7 +747,7 @@ public class CrossRef { // first check primary refs. List match = DBRefUtils.searchRefs( - seq.getPrimaryDBRefs().toArray(new DBRefEntry[0]), template); + seq.getPrimaryDBRefs(), template, DBRefUtils.SEARCH_MODE_FULL); if (match != null && match.size() == 1 && sameSequence(seq, dss)) { return seq; @@ -812,7 +820,7 @@ public class CrossRef * @param retrieved * @param acf */ - void updateDbrefMappings(SequenceI mapFrom, DBRefEntry[] xrefs, + void updateDbrefMappings(SequenceI mapFrom, List xrefs, SequenceI[] retrieved, AlignedCodonFrame acf, boolean fromDna) { SequenceIdMatcher idMatcher = new SequenceIdMatcher(retrieved); @@ -946,7 +954,7 @@ public class CrossRef * @return true if matches were found. */ private boolean searchDatasetXrefs(boolean fromDna, SequenceI sequenceI, - DBRefEntry[] lrfs, List foundSeqs, + List lrfs, List foundSeqs, AlignedCodonFrame cf) { boolean found = false; @@ -954,14 +962,14 @@ public class CrossRef { return false; } - for (int i = 0; i < lrfs.length; i++) + for (int i = 0, n = lrfs.size(); i < n; i++) { - DBRefEntry xref = new DBRefEntry(lrfs[i]); - // add in wildcards - xref.setVersion(null); - xref.setMap(null); - found |= searchDataset(fromDna, sequenceI, xref, foundSeqs, cf, - false); +// DBRefEntry xref = new DBRefEntry(lrfs.get(i)); +// // add in wildcards +// xref.setVersion(null); +// xref.setMap(null); + found |= searchDataset(fromDna, sequenceI, lrfs.get(i), foundSeqs, cf, + false, DBRefUtils.SEARCH_MODE_NO_MAP_NO_VERSION); } return found; } @@ -992,11 +1000,12 @@ public class CrossRef * sequenceI or all the returned sequences (eg a genomic reference * associated with a locus and one or more transcripts) * + * @param mode SEARCH_MODE_FULL for all; SEARCH_MODE_NO_MAP_NO_VERSION optional * @return true if relationship found and sequence added. */ boolean searchDataset(boolean fromDna, SequenceI fromSeq, DBRefEntry xrf, List foundSeqs, AlignedCodonFrame mappings, - boolean direct) + boolean direct, int mode) { boolean found = false; if (dataset == null) @@ -1041,13 +1050,13 @@ public class CrossRef } // look for direct or indirect references in common - DBRefEntry[] poss = nxt.getDBRefs(); + List poss = nxt.getDBRefs(); List cands = null; // todo: indirect specifies we select either direct references to nxt // that match xrf which is indirect to sequenceI, or indirect // references to nxt that match xrf which is direct to sequenceI - cands = DBRefUtils.searchRefs(poss, xrf); + cands = DBRefUtils.searchRefs(poss, xrf, mode); // else // { // poss = DBRefUtils.selectDbRefs(nxt.isProtein()!fromDna, poss); diff --git a/src/jalview/analysis/Dna.java b/src/jalview/analysis/Dna.java index 2ad8487..4b81785 100644 --- a/src/jalview/analysis/Dna.java +++ b/src/jalview/analysis/Dna.java @@ -252,29 +252,30 @@ public class Dna for (int gd = 0; gd < selection.length; gd++) { SequenceI dna = selection[gd]; - DBRefEntry[] dnarefs = DBRefUtils.selectRefs(dna.getDBRefs(), + List dnarefs = DBRefUtils.selectRefs(dna.getDBRefs(), jalview.datamodel.DBRefSource.DNACODINGDBS); if (dnarefs != null) { // intersect with pep List mappedrefs = new ArrayList<>(); - DBRefEntry[] refs = dna.getDBRefs(); - for (int d = 0; d < refs.length; d++) + List refs = dna.getDBRefs(); + for (int d = 0, nd = refs.size(); d < nd; d++) { - if (refs[d].getMap() != null && refs[d].getMap().getMap() != null - && refs[d].getMap().getMap().getFromRatio() == 3 - && refs[d].getMap().getMap().getToRatio() == 1) + DBRefEntry ref = refs.get(d); + if (ref.getMap() != null && ref.getMap().getMap() != null + && ref.getMap().getMap().getFromRatio() == 3 + && ref.getMap().getMap().getToRatio() == 1) { - mappedrefs.add(refs[d]); // add translated protein maps + mappedrefs.add(ref); // add translated protein maps } } - dnarefs = mappedrefs.toArray(new DBRefEntry[mappedrefs.size()]); - for (int d = 0; d < dnarefs.length; d++) + dnarefs = mappedrefs;//.toArray(new DBRefEntry[mappedrefs.size()]); + for (int d = 0, nd = dnarefs.size(); d < nd; d++) { - Mapping mp = dnarefs[d].getMap(); + Mapping mp = dnarefs.get(d).getMap(); if (mp != null) { - for (int vc = 0; vc < viscontigs.length; vc += 2) + for (int vc = 0, nv = viscontigs.length; vc < nv; vc += 2) { int[] mpr = mp.locateMappedRange(viscontigs[vc], viscontigs[vc + 1]); @@ -796,19 +797,20 @@ public class Dna private static void transferCodedFeatures(SequenceI dna, SequenceI pep, MapList map) { - DBRefEntry[] dnarefs = DBRefUtils.selectRefs(dna.getDBRefs(), - DBRefSource.DNACODINGDBS); - if (dnarefs != null) - { - // intersect with pep - for (int d = 0; d < dnarefs.length; d++) - { - Mapping mp = dnarefs[d].getMap(); - if (mp != null) - { - } - } - } + // BH 2019.01.25 nop? +// List dnarefs = DBRefUtils.selectRefs(dna.getDBRefs(), +// DBRefSource.DNACODINGDBS); +// if (dnarefs != null) +// { +// // intersect with pep +// for (int d = 0, nd = dnarefs.size(); d < nd; d++) +// { +// Mapping mp = dnarefs.get(d).getMap(); +// if (mp != null) +// { +// } +// } +// } for (SequenceFeature sf : dna.getFeatures().getAllFeatures()) { if (FeatureProperties.isCodingFeature(null, sf.getType())) diff --git a/src/jalview/analysis/SequenceIdMatcher.java b/src/jalview/analysis/SequenceIdMatcher.java index 3d4cbe7..a85c7f3 100755 --- a/src/jalview/analysis/SequenceIdMatcher.java +++ b/src/jalview/analysis/SequenceIdMatcher.java @@ -74,13 +74,13 @@ public class SequenceIdMatcher dbseq = dbseq.getDatasetSequence(); } // add in any interesting identifiers - if (dbseq.getDBRefs() != null) + List dbr = dbseq.getDBRefs(); + if (dbr != null) { - DBRefEntry dbr[] = dbseq.getDBRefs(); SeqIdName sid = null; - for (int r = 0; r < dbr.length; r++) + for (int r = 0, nr = dbr.size(); r < nr; r++) { - sid = new SeqIdName(dbr[r].getAccessionId()); + sid = new SeqIdName(dbr.get(r).getAccessionId()); if (!names.containsKey(sid)) { names.put(sid, seq); diff --git a/src/jalview/bin/Cache.java b/src/jalview/bin/Cache.java index 6d23bd0..888dc29 100755 --- a/src/jalview/bin/Cache.java +++ b/src/jalview/bin/Cache.java @@ -28,6 +28,7 @@ import jalview.schemes.UserColourScheme; import jalview.structure.StructureImportSettings; import jalview.urls.IdOrgSettings; import jalview.util.ColorUtils; +import jalview.util.Platform; import jalview.ws.sifts.SiftsSettings; import java.awt.Color; @@ -396,10 +397,11 @@ public class Cache } // LOAD THE AUTHORS FROM THE authors.props file + boolean ignore = Platform.isJS(); + if (!ignore) try { - String authorDetails = /** @j2sNative "xxx" || */ - "jar:" + String authorDetails = "jar:" .concat(Cache.class.getProtectionDomain().getCodeSource() .getLocation().toString().concat("!/authors.props")); @@ -408,21 +410,28 @@ public class Cache InputStream in = localJarFileURL.openStream(); applicationProperties.load(in); in.close(); + } catch (Exception ex) { System.out.println("Error reading author details: " + ex); - applicationProperties.remove("AUTHORS"); - applicationProperties.remove("AUTHORFNAMES"); - applicationProperties.remove("YEAR"); + ignore = true; } + if (ignore) { + applicationProperties.remove("AUTHORS"); + applicationProperties.remove("AUTHORFNAMES"); + applicationProperties.remove("YEAR"); + } + // FIND THE VERSION NUMBER AND BUILD DATE FROM jalview.jar // MUST FOLLOW READING OF LOCAL PROPERTIES FILE AS THE // VERSION MAY HAVE CHANGED SINCE LAST USING JALVIEW + // BH 2019.01.25 switching to Platform.isJS() + ignore = Platform.isJS(); + if (!ignore) try { - String buildDetails = /** @j2sNative "xxx" || */ - "jar:".concat(Cache.class.getProtectionDomain() + String buildDetails = "jar:".concat(Cache.class.getProtectionDomain() .getCodeSource().getLocation().toString() .concat("!/.build_properties")); @@ -434,7 +443,11 @@ public class Cache } catch (Exception ex) { System.out.println("Error reading build details: " + ex); - applicationProperties.remove("VERSION"); + ignore = true; + } + + if (ignore) { + applicationProperties.remove("VERSION"); } String jnlpVersion = System.getProperty("jalview.version"); diff --git a/src/jalview/bin/Jalview.java b/src/jalview/bin/Jalview.java index 474c707..29d48b2 100755 --- a/src/jalview/bin/Jalview.java +++ b/src/jalview/bin/Jalview.java @@ -102,21 +102,22 @@ public class Jalview public static AlignFrame currentAlignFrame; - /** - * Answers true if Jalview is running as Javascript, else false. The value is - * set at compile time. - * - * @return - */ - public static boolean isJS() - { - return /** @j2sNative true || */ - false; - } +//BH 2019.01.25 moved to Platform +///** +// * Answers true if Jalview is running as Javascript, else false. The value is +// * set at compile time. +// * +// * @return +// */ +//public static boolean isJS() +//{ +// return /** @j2sNative true || */ +// false; +//} static { - if (!isJS()) + if (!Platform.isJS()) { // BH 2018 // grab all the rights we can the JVM Policy.setPolicy(new Policy() @@ -250,7 +251,7 @@ public class Jalview void doMain(String[] args) { - if (!isJS()) + if (!Platform.isJS()) { System.setSecurityManager(null); } @@ -590,7 +591,7 @@ public class Jalview } System.out.println("CMD [-open " + file + "] executed successfully!"); - if (!isJS() && !file.startsWith("http://")) + if (!Platform.isJS() && !file.startsWith("http://")) { if (!(new File(file)).exists()) { diff --git a/src/jalview/datamodel/DBRefEntry.java b/src/jalview/datamodel/DBRefEntry.java index 98868ce..1993516 100755 --- a/src/jalview/datamodel/DBRefEntry.java +++ b/src/jalview/datamodel/DBRefEntry.java @@ -21,6 +21,8 @@ package jalview.datamodel; import jalview.api.DBRefEntryI; +import jalview.util.DBRefUtils; +import jalview.util.MapList; import java.util.Arrays; import java.util.List; @@ -38,9 +40,14 @@ public class DBRefEntry implements DBRefEntryI String source = ""; - String version = ""; + String version = "", ucversion; String accessionId = ""; + + String sourceKey; + + String canonicalSourceName; + /** * maps from associated sequence to the database sequence's coordinate system @@ -72,20 +79,24 @@ public class DBRefEntry implements DBRefEntryI public DBRefEntry(String source, String version, String accessionId, Mapping map) { - this.source = source.toUpperCase(); - this.version = version; - this.accessionId = accessionId; + // BH 2019.01.25 made these always non-null. + // Is there a difference between "" and null for version? + // evidence is that source CANNOT be null. + setSource(source); + setVersion(version); + setAccessionId(accessionId); this.map = map; } public DBRefEntry(DBRefEntryI entry) { - this((entry.getSource() == null ? "" : new String(entry.getSource())), - (entry.getVersion() == null ? "" - : new String(entry.getVersion())), - (entry.getAccessionId() == null ? "" - : new String(entry.getAccessionId())), - (entry.getMap() == null ? null : new Mapping(entry.getMap()))); + this(entry.getSource(), entry.getVersion(), entry.getAccessionId(), entry.getMap() == null ? null : new Mapping(entry.getMap())); +// this((entry.getSource() == null ? "" : new String(entry.getSource())), +// (entry.getVersion() == null ? "" +// : new String(entry.getVersion())), +// (entry.getAccessionId() == null ? "" +// : new String(entry.getAccessionId())), +// (entry.getMap() == null ? null : new Mapping(entry.getMap()))); } @Override @@ -93,21 +104,28 @@ public class DBRefEntry implements DBRefEntryI { // TODO should also override hashCode to ensure equal objects have equal // hashcodes - if (o == null || !(o instanceof DBRefEntry)) - { - return false; - } - DBRefEntry entry = (DBRefEntry) o; - if (entry == this) - { - return true; - } - if (equalRef(entry) && ((map == null && entry.map == null) - || (map != null && entry.map != null && map.equals(entry.map)))) - { - return true; - } - return false; + + +// if (o == null || !(o instanceof DBRefEntry)) +// { +// return false; +// } +// DBRefEntry entry = (DBRefEntry) o; +// if (entry == this) +// { +// return true; +// } + Mapping em; + return (o != null && o instanceof DBRefEntry + && (o == this + || equalRef((DBRefEntry) o) + && (map == null) == ((em = ((DBRefEntry) o).map) == null) + && (map == null || map.equals(em)))); +// +// { +// return true; +// } +// return false; } /** @@ -208,6 +226,10 @@ public class DBRefEntry implements DBRefEntryI { return true; } + + // BH 2019.01.25 source, accessionId, and version cannot be null. + // for example, StructureChooser has dbRef.getSource().equalsIgnoreCase... + if (entry != null && (source != null && entry.getSource() != null && source.equalsIgnoreCase(entry.getSource())) @@ -227,6 +249,11 @@ public class DBRefEntry implements DBRefEntryI return source; } + public String getSourceKey() + { + return sourceKey; + } + @Override public String getVersion() { @@ -242,19 +269,22 @@ public class DBRefEntry implements DBRefEntryI @Override public void setAccessionId(String accessionId) { - this.accessionId = accessionId; + this.accessionId = (accessionId == null ? "" : accessionId).toUpperCase(); } @Override public void setSource(String source) { - this.source = source; + this.source = (source == null ? "" : source).toUpperCase(); + this.canonicalSourceName = DBRefUtils.getCanonicalName(this.source); + this.sourceKey = ";" + canonicalSourceName + ";"; } @Override public void setVersion(String version) { - this.version = version; + this.version = (version == null ? "" : version); + this.ucversion = this.version.toUpperCase(); } @Override @@ -301,19 +331,20 @@ public class DBRefEntry implements DBRefEntryI */ if (map != null) { - if (map.getTo() != null) + SequenceI mto = map.getTo(); + if (mto != null) { return false; } - if (map.getMap().getFromRatio() != map.getMap().getToRatio() - || map.getMap().getFromRatio() != 1) + MapList ml = map.getMap(); + if (ml.getFromRatio() != ml.getToRatio() + || ml.getFromRatio() != 1) { return false; } // check map is between identical single contiguous ranges - List fromRanges = map.getMap().getFromRanges(); - List toRanges = map.getMap().getToRanges(); - if (fromRanges.size() != 1 || toRanges.size() != 1) + List fromRanges, toRanges; + if ((fromRanges = ml.getFromRanges()).size() != 1 || (toRanges = ml.getToRanges()).size() != 1) { return false; } @@ -323,17 +354,17 @@ public class DBRefEntry implements DBRefEntryI return false; } } - if (version == null) + if (version == null || version == "") { // no version string implies the reference has not been verified at all. return false; } // tricky - this test really needs to search the sequence's set of dbrefs to // see if there is a primary reference that derived this reference. - String ucv = version.toUpperCase(); - for (String primsrc : Arrays.asList(DBRefSource.allSources())) + String[] sources = DBRefSource.allSources(); + for (int i = sources.length; --i >= 0;) { - if (ucv.startsWith(primsrc.toUpperCase())) + if (ucversion.startsWith(sources[i])) // BH 2019.01.25 .toUpperCase() unnecessary here for allSources { // by convention, many secondary references inherit the primary // reference's @@ -354,4 +385,10 @@ public class DBRefEntry implements DBRefEntryI { return accessionId != null && accessionId.startsWith(CHROMOSOME + ":"); } + + public Object getCanonicalSourceName() { + return canonicalSourceName; + } + + } diff --git a/src/jalview/datamodel/DBRefSource.java b/src/jalview/datamodel/DBRefSource.java index 47d1082..f8039bb 100755 --- a/src/jalview/datamodel/DBRefSource.java +++ b/src/jalview/datamodel/DBRefSource.java @@ -122,6 +122,33 @@ public class DBRefSource GENEDB, ENSEMBL, ENSEMBLGENOMES }; +public static final String PROTEINDBSKEYS, DNACODINGDBSKEYS; + +public static final String[] PROMTYPES; + + +public static final int UNIPROT_MASK = 1; + +public static final int ENSEMBL_MASK = 2; + +public static final int ALL_MASKS = UNIPROT_MASK | ENSEMBL_MASK; + +public static final String PDB_CANONICAL_NAME = PDB; + +static { + // BH 2019.01.25 trying to speed this up + String s = ";"; + for (int i = PROTEINDBS.length; --i >= 0;) + s += PROTEINDBS[i] + ";"; + PROTEINDBSKEYS = s; + + s = ";"; + for (int i = DNACODINGDBS.length; --i >= 0;) + s += DNACODINGDBS[i] + ";"; + DNACODINGDBSKEYS = s; + + PROMTYPES = new String[] { null, ";" + UNIPROT + ";", ";" + ENSEMBL + ";" , ";" + UNIPROT + ";" + ENSEMBL + ";" }; +} public static String[] allSourcesFromReflection; diff --git a/src/jalview/datamodel/Sequence.java b/src/jalview/datamodel/Sequence.java index f555855..6cf0646 100755 --- a/src/jalview/datamodel/Sequence.java +++ b/src/jalview/datamodel/Sequence.java @@ -21,13 +21,13 @@ package jalview.datamodel; import jalview.analysis.AlignSeq; -import jalview.api.DBRefEntryI; import jalview.datamodel.features.SequenceFeatures; import jalview.datamodel.features.SequenceFeaturesI; import jalview.util.Comparison; import jalview.util.DBRefUtils; import jalview.util.MapList; import jalview.util.StringUtils; +import jalview.ws.params.InvalidArgumentException; import java.util.ArrayList; import java.util.Arrays; @@ -47,7 +47,24 @@ import fr.orsay.lri.varna.models.rna.RNA; */ public class Sequence extends ASequence implements SequenceI { - SequenceI datasetSequence; + + /** + * A subclass that gives us access to modCount, which tracks + * whether there have been any changes. We use this to update + * @author hansonr + * + * @param + */ + @SuppressWarnings("serial") + protected class DBModList extends ArrayList { + + protected int getModCount() { + return modCount; + } + + } + +SequenceI datasetSequence; String name; @@ -63,10 +80,17 @@ public class Sequence extends ASequence implements SequenceI String vamsasId; - DBRefEntry[] dbrefs; + private DBModList dbrefs; // controlled acces - RNA rna; + /** + * a flag to let us know that elements have changed in dbrefs + * + * @author Bob Hanson + */ + private int refModCount = 0; + RNA rna; + /** * This annotation is displayed below the alignment but the positions are tied * to the residues of this sequence @@ -284,12 +308,12 @@ public class Sequence extends ASequence implements SequenceI */ if (datasetSequence == null) { - if (seq.getDBRefs() != null) + List dbr = seq.getDBRefs(); + if (dbr != null) { - DBRefEntry[] dbr = seq.getDBRefs(); - for (int i = 0; i < dbr.length; i++) + for (int i = 0, n = dbr.size(); i < n; i++) { - addDBRef(new DBRefEntry(dbr[i])); + addDBRef(new DBRefEntry(dbr.get(i))); } } @@ -682,7 +706,7 @@ public class Sequence extends ASequence implements SequenceI @Override public GeneLociI getGeneLoci() { - DBRefEntry[] refs = getDBRefs(); + List refs = getDBRefs(); if (refs != null) { for (final DBRefEntry ref : refs) @@ -1386,24 +1410,35 @@ public class Sequence extends ASequence implements SequenceI vamsasId = id; } - @Override - public void setDBRefs(DBRefEntry[] dbref) + @SuppressWarnings("deprecation") +@Override + public void setDBRefs(List newDBrefs) throws InvalidArgumentException { if (dbrefs == null && datasetSequence != null && this != datasetSequence) { - datasetSequence.setDBRefs(dbref); + datasetSequence.setDBRefs((DBModList)newDBrefs); return; } - dbrefs = dbref; - if (dbrefs != null) - { - DBRefUtils.ensurePrimaries(this); - } + if (newDBrefs != null && !(newDBrefs instanceof DBModList)) + throw new InvalidArgumentException("DBrefs must have DBModList class"); + + dbrefs = (DBModList)newDBrefs; + refModCount = 0; + } + + @Override + public void getDBRefsFrom(SequenceI seq) { + try { + setDBRefs(seq.getDBRefs()); + } catch (InvalidArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } @Override - public DBRefEntry[] getDBRefs() + public List getDBRefs() { if (dbrefs == null && datasetSequence != null && this != datasetSequence) @@ -1413,6 +1448,7 @@ public class Sequence extends ASequence implements SequenceI return dbrefs; } + @Override public void addDBRef(DBRefEntry entry) { @@ -1424,12 +1460,12 @@ public class Sequence extends ASequence implements SequenceI if (dbrefs == null) { - dbrefs = new DBRefEntry[0]; + dbrefs = new DBModList(); } - for (DBRefEntryI dbr : dbrefs) + for (int ib = 0, nb= dbrefs.size(); ib < nb; ib++) { - if (dbr.updateFrom(entry)) + if (dbrefs.get(ib).updateFrom(entry)) { /* * found a dbref that either matched, or could be @@ -1439,18 +1475,20 @@ public class Sequence extends ASequence implements SequenceI } } - /* - * extend the array to make room for one more - */ - // TODO use an ArrayList instead - int j = dbrefs.length; - DBRefEntry[] temp = new DBRefEntry[j + 1]; - System.arraycopy(dbrefs, 0, temp, 0, j); - temp[temp.length - 1] = entry; - - dbrefs = temp; - DBRefUtils.ensurePrimaries(this); +// /// BH OUCH! +// /* +// * extend the array to make room for one more +// */ +// // TODO use an ArrayList instead +// int j = dbrefs.length; +// List temp = new DBRefEntry[j + 1]; +// System.arraycopy(dbrefs, 0, temp, 0, j); +// temp[temp.length - 1] = entry; +// +// dbrefs = temp; + + dbrefs.add(entry); } @Override @@ -1563,6 +1601,8 @@ public class Sequence extends ASequence implements SequenceI private int _seqhash = 0; +private List primaryRefs; + /** * Answers false if the sequence is more than 85% nucleotide (ACGTU), else * true @@ -1694,13 +1734,14 @@ public class Sequence extends ASequence implements SequenceI // TODO: could merge DBRefs return datasetSequence.updatePDBIds(); } - if (dbrefs == null || dbrefs.length == 0) + if (dbrefs == null || dbrefs.size() == 0) { return false; } boolean added = false; - for (DBRefEntry dbr : dbrefs) + for (int ib = 0, nb = dbrefs.size(); ib < nb; ib++) { + DBRefEntry dbr = dbrefs.get(ib); if (DBRefSource.PDB.equals(dbr.getSource())) { /* @@ -1759,12 +1800,12 @@ public class Sequence extends ASequence implements SequenceI } } // transfer database references - DBRefEntry[] entryRefs = entry.getDBRefs(); + List entryRefs = entry.getDBRefs(); if (entryRefs != null) { - for (int r = 0; r < entryRefs.length; r++) + for (int r = 0, n = entryRefs.size(); r < n; r++) { - DBRefEntry newref = new DBRefEntry(entryRefs[r]); + DBRefEntry newref = new DBRefEntry(entryRefs.get(r)); if (newref.getMap() != null && mp != null) { // remap ref using our local mapping @@ -1838,6 +1879,8 @@ public class Sequence extends ASequence implements SequenceI return null; } + private List tmpList; + @Override public List getPrimaryDBRefs() { @@ -1845,16 +1888,28 @@ public class Sequence extends ASequence implements SequenceI { return datasetSequence.getPrimaryDBRefs(); } - if (dbrefs == null || dbrefs.length == 0) + if (dbrefs == null || dbrefs.size() == 0) { return Collections.emptyList(); } synchronized (dbrefs) { - List primaries = new ArrayList<>(); - DBRefEntry[] tmp = new DBRefEntry[1]; - for (DBRefEntry ref : dbrefs) + if (refModCount == dbrefs.getModCount() && primaryRefs != null) + return primaryRefs; { + refModCount = dbrefs.getModCount(); + DBRefUtils.ensurePrimaries(this); + primaryRefs = null; + } + List primaries = (primaryRefs == null ? (primaryRefs = new ArrayList<>()) : primaryRefs); + primaries.clear(); + if (tmpList == null) { + tmpList = new ArrayList<>(); + tmpList.add(null); // for replacement + } + for (int i = 0, n = dbrefs.size(); i < n; i++) + { + DBRefEntry ref = dbrefs.get(i); if (!ref.isPrimaryCandidate()) { continue; @@ -1869,8 +1924,7 @@ public class Sequence extends ASequence implements SequenceI } } // whilst it looks like it is a primary ref, we also sanity check type - if (DBRefUtils.getCanonicalName(DBRefSource.PDB) - .equals(DBRefUtils.getCanonicalName(ref.getSource()))) + if (DBRefSource.PDB_CANONICAL_NAME.equals(ref.getCanonicalSourceName())) { // PDB dbrefs imply there should be a PDBEntry associated // TODO: tighten PDB dbrefs @@ -1879,20 +1933,20 @@ public class Sequence extends ASequence implements SequenceI // handle on the PDBEntry, and a real mapping between sequence and // extracted sequence from PDB file PDBEntry pdbentry = getPDBEntry(ref.getAccessionId()); - if (pdbentry != null && pdbentry.getFile() != null) + if (pdbentry == null || pdbentry.getFile() == null) { - primaries.add(ref); + continue; } - continue; - } - // check standard protein or dna sources - tmp[0] = ref; - DBRefEntry[] res = DBRefUtils.selectDbRefs(!isProtein(), tmp); - if (res != null && res[0] == tmp[0]) - { - primaries.add(ref); - continue; - } + } else { + // check standard protein or dna sources + tmpList.set(0, ref); + List res = DBRefUtils.selectDbRefs(!isProtein(), tmpList); + if (res == null || res.get(0) != tmpList.get(0)) + { + continue; + } + } + primaries.add(ref); } return primaries; } diff --git a/src/jalview/datamodel/SequenceGroup.java b/src/jalview/datamodel/SequenceGroup.java index fc8ac49..1e579ec 100755 --- a/src/jalview/datamodel/SequenceGroup.java +++ b/src/jalview/datamodel/SequenceGroup.java @@ -25,6 +25,7 @@ import jalview.analysis.Conservation; import jalview.renderer.ResidueShader; import jalview.renderer.ResidueShaderI; import jalview.schemes.ColourSchemeI; +import jalview.ws.params.InvalidArgumentException; import java.awt.Color; import java.beans.PropertyChangeListener; @@ -257,16 +258,15 @@ public class SequenceGroup implements AnnotatedCollectionI for (int i = 0, ipos = 0; i < inorder.length; i++) { SequenceI seq = inorder[i]; - - seqs[ipos] = seq.getSubSequence(startRes, endRes + 1); - if (seqs[ipos] != null) + SequenceI seqipos = seqs[ipos] = seq.getSubSequence(startRes, endRes + 1); + if (seqipos != null) { - seqs[ipos].setDescription(seq.getDescription()); - seqs[ipos].setDBRefs(seq.getDBRefs()); - seqs[ipos].setSequenceFeatures(seq.getSequenceFeatures()); + seqipos.setDescription(seq.getDescription()); + seqipos.getDBRefsFrom(seq); + seqipos.setSequenceFeatures(seq.getSequenceFeatures()); if (seq.getDatasetSequence() != null) { - seqs[ipos].setDatasetSequence(seq.getDatasetSequence()); + seqipos.setDatasetSequence(seq.getDatasetSequence()); } if (seq.getAnnotation() != null) @@ -280,7 +280,7 @@ public class SequenceGroup implements AnnotatedCollectionI if (alann != null) { boolean found = false; - for (int pos = 0; pos < alann.length; pos++) + for (int pos = 0, np = alann.length; pos < np; pos++) { if (alann[pos] == tocopy) { @@ -298,7 +298,7 @@ public class SequenceGroup implements AnnotatedCollectionI newannot.restrict(startRes, endRes); newannot.setSequenceRef(seqs[ipos]); newannot.adjustForAlignment(); - seqs[ipos].addAlignmentAnnotation(newannot); + seqipos.addAlignmentAnnotation(newannot); } } ipos++; diff --git a/src/jalview/datamodel/SequenceI.java b/src/jalview/datamodel/SequenceI.java index 48615f0..9e9758c 100755 --- a/src/jalview/datamodel/SequenceI.java +++ b/src/jalview/datamodel/SequenceI.java @@ -22,6 +22,7 @@ package jalview.datamodel; import jalview.datamodel.features.SequenceFeaturesI; import jalview.util.MapList; +import jalview.ws.params.InvalidArgumentException; import java.util.BitSet; import java.util.Iterator; @@ -353,14 +354,20 @@ public interface SequenceI extends ASequenceI /** * set the array of Database references for the sequence. * + * BH 2019.01.25 added throw + * * @param dbs + * @throws InvalidArgumentException * @deprecated - use is discouraged since side-effects may occur if DBRefEntry * set are not normalised. + * @throws InvalidArgumentException if the is not one created by Sequence itself */ @Deprecated - public void setDBRefs(DBRefEntry[] dbs); + public void setDBRefs(List dbs) throws InvalidArgumentException; + + public List getDBRefs(); - public DBRefEntry[] getDBRefs(); + public void getDBRefsFrom(SequenceI seq); /** * add the given entry to the list of DBRefs for this sequence, or replace a @@ -576,4 +583,6 @@ public interface SequenceI extends ASequenceI * @return first residue not contained in regions */ public int firstResidueOutsideIterator(Iterator it); + } + diff --git a/src/jalview/ext/ensembl/EnsemblFeatures.java b/src/jalview/ext/ensembl/EnsemblFeatures.java index 6a0d67c..2772498 100644 --- a/src/jalview/ext/ensembl/EnsemblFeatures.java +++ b/src/jalview/ext/ensembl/EnsemblFeatures.java @@ -27,6 +27,7 @@ import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceI; import jalview.io.gff.SequenceOntologyI; import jalview.util.JSONUtils; +import jalview.util.Platform; import java.io.BufferedReader; import java.io.IOException; @@ -90,12 +91,14 @@ class EnsemblFeatures extends EnsemblRestClient public AlignmentI getSequenceRecords(String query) throws IOException { // TODO: use a vararg String... for getSequenceRecords instead? + List queries = new ArrayList<>(); queries.add(query); SequenceI seq = parseFeaturesJson(queries); if (seq == null) return null; return new Alignment(new SequenceI[] { seq }); + } /** @@ -119,7 +122,7 @@ private SequenceI parseFeaturesJson(List queries) if (rvals == null) return null; while (rvals.hasNext()) - { + { try { Map obj = (Map) rvals.next(); @@ -147,7 +150,7 @@ private SequenceI parseFeaturesJson(List queries) { type = SequenceOntologyI.CDS; } - + String desc = getFirstNotNull(obj, "alleles", "external_name", JSON_ID); SequenceFeature sf = new SequenceFeature(type, desc, start, end, @@ -160,6 +163,7 @@ private SequenceI parseFeaturesJson(List queries) sf.setValue("clinical_significance", clinSig); seq.addSequenceFeature(sf); + } catch (Throwable t) { // ignore - keep trying other features diff --git a/src/jalview/ext/ensembl/EnsemblGene.java b/src/jalview/ext/ensembl/EnsemblGene.java index 7648536..dd2547b 100644 --- a/src/jalview/ext/ensembl/EnsemblGene.java +++ b/src/jalview/ext/ensembl/EnsemblGene.java @@ -34,6 +34,7 @@ import jalview.io.gff.SequenceOntologyI; import jalview.schemes.FeatureColour; import jalview.schemes.FeatureSettingsAdapter; import jalview.util.MapList; +import jalview.util.Platform; import java.awt.Color; import java.io.UnsupportedEncodingException; @@ -134,17 +135,29 @@ public class EnsemblGene extends EnsemblSeqProxy @Override public AlignmentI getSequenceRecords(String query) throws Exception { + + + + Platform.timeCheck("EG " + query, Platform.TIME_MARK); + /* * convert to a non-duplicated list of gene identifiers */ List geneIds = getGeneIds(query); + + Platform.timeCheck("EG genIds " + geneIds.size(), Platform.TIME_MARK); + AlignmentI al = null; for (String geneId : geneIds) { /* * fetch the gene sequence(s) with features and xrefs */ + + Platform.timeCheck("EG fetch " + geneId, Platform.TIME_MARK); + + AlignmentI geneAlignment = super.getSequenceRecords(geneId); if (geneAlignment == null) { @@ -156,8 +169,14 @@ public class EnsemblGene extends EnsemblSeqProxy // ensure id has 'correct' case for the Ensembl identifier geneId = geneAlignment.getSequenceAt(0).getName(); + + Platform.timeCheck("EG loci " + geneId, Platform.TIME_MARK); + + findGeneLoci(geneAlignment.getSequenceAt(0), geneId); + Platform.timeCheck("EG transcript " + geneId, Platform.TIME_MARK); + getTranscripts(geneAlignment, geneId); } if (al == null) @@ -169,6 +188,9 @@ public class EnsemblGene extends EnsemblSeqProxy al.append(geneAlignment); } } + + Platform.timeCheck("EG done", Platform.TIME_MARK); + return al; } diff --git a/src/jalview/ext/ensembl/EnsemblSeqProxy.java b/src/jalview/ext/ensembl/EnsemblSeqProxy.java index 7bf2563..1d6b354 100644 --- a/src/jalview/ext/ensembl/EnsemblSeqProxy.java +++ b/src/jalview/ext/ensembl/EnsemblSeqProxy.java @@ -209,18 +209,28 @@ public abstract class EnsemblSeqProxy extends EnsemblRestClient SequenceI genomicSequence = null; EnsemblFeatures gffFetcher = new EnsemblFeatures(getDomain()); EnsemblFeatureType[] features = getFeaturesToFetch(); + + Platform.timeCheck("ESP.getsequencerec1", Platform.TIME_MARK); + + AlignmentI geneFeatures = gffFetcher.getSequenceRecords(accId, features); if (geneFeatures != null && geneFeatures.getHeight() > 0) { genomicSequence = geneFeatures.getSequenceAt(0); } + + Platform.timeCheck("ESP.getsequencerec2", Platform.TIME_MARK); + if (genomicSequence != null) { /* * transfer features to the query sequence */ SequenceI querySeq = alignment.findName(accId, true); + + Platform.timeCheck("ESP.transferfeat", Platform.TIME_MARK); + if (transferFeatures(accId, genomicSequence, querySeq)) { @@ -228,6 +238,7 @@ public abstract class EnsemblSeqProxy extends EnsemblRestClient * fetch and map protein product, and add it as a cross-reference * of the retrieved sequence */ + Platform.timeCheck("ESP.addprotein", Platform.TIME_MARK); addProteinProduct(querySeq); } } @@ -236,6 +247,7 @@ public abstract class EnsemblSeqProxy extends EnsemblRestClient System.err.println( "Error transferring Ensembl features: " + e.getMessage()); } + Platform.timeCheck("ESP.addfeat done", Platform.TIME_MARK); } /** @@ -284,10 +296,10 @@ public abstract class EnsemblSeqProxy extends EnsemblRestClient DBRefEntry dbr = new DBRefEntry(getDbSource(), getEnsemblDataVersion(), proteinSeq.getName(), map); querySeq.getDatasetSequence().addDBRef(dbr); - DBRefEntry[] uprots = DBRefUtils.selectRefs(ds.getDBRefs(), + List uprots = DBRefUtils.selectRefs(ds.getDBRefs(), new String[] { DBRefSource.UNIPROT }); - DBRefEntry[] upxrefs = DBRefUtils.selectRefs(querySeq.getDBRefs(), + List upxrefs = DBRefUtils.selectRefs(querySeq.getDBRefs(), new String[] { DBRefSource.UNIPROT }); if (uprots != null) @@ -348,25 +360,47 @@ public abstract class EnsemblSeqProxy extends EnsemblRestClient */ protected void getCrossReferences(SequenceI seq) { + + Platform.timeCheck("ESP. getdataseq ", Platform.TIME_MARK); + + while (seq.getDatasetSequence() != null) { seq = seq.getDatasetSequence(); } + Platform.timeCheck("ESP. getxref ", Platform.TIME_MARK); + EnsemblXref xrefFetcher = new EnsemblXref(getDomain(), getDbSource(), getEnsemblDataVersion()); List xrefs = xrefFetcher.getCrossReferences(seq.getName()); - for (DBRefEntry xref : xrefs) + + for (int i = 0, n = xrefs.size(); i < n; i++) { - seq.addDBRef(xref); + Platform.timeCheck("ESP. getxref + " + (i) + "/" + n, Platform.TIME_MARK); + // BH 2019.01.25 this next method was taking 174 ms PER addition for a 266-reference example. + // DBRefUtils.ensurePrimaries(seq) + // was at the end of seq.addDBRef, so executed after ever addition! + // This method was moved to seq.getPrimaryDBRefs() + seq.addDBRef(xrefs.get(i)); } + System.out.println("primaries are " + seq.getPrimaryDBRefs().toString()); /* * and add a reference to itself */ + + Platform.timeCheck("ESP. getxref self ", Platform.TIME_MARK); + DBRefEntry self = new DBRefEntry(getDbSource(), getEnsemblDataVersion(), seq.getName()); + + Platform.timeCheck("ESP. getxref self add ", Platform.TIME_MARK); + seq.addDBRef(self); + + Platform.timeCheck("ESP. seqprox done ", Platform.TIME_MARK); + } /** @@ -454,6 +488,8 @@ public abstract class EnsemblSeqProxy extends EnsemblRestClient * for now, assumes only one sequence returned; refactor if needed * in future to handle a JSONArray with more than one */ + + Platform.timeCheck("ENS seqproxy", Platform.TIME_MARK); Map val = (Map) getJSON(null, ids, -1, MODE_MAP, null); if (val == null) return null; @@ -479,6 +515,7 @@ public abstract class EnsemblSeqProxy extends EnsemblRestClient System.err.println("Error processing JSON response: " + e.toString()); // ignore } + Platform.timeCheck("ENS seqproxy2", Platform.TIME_MARK); return result; } diff --git a/src/jalview/fts/service/pdb/PDBFTSRestClient.java b/src/jalview/fts/service/pdb/PDBFTSRestClient.java index b4e5660..402efff 100644 --- a/src/jalview/fts/service/pdb/PDBFTSRestClient.java +++ b/src/jalview/fts/service/pdb/PDBFTSRestClient.java @@ -20,7 +20,6 @@ */ package jalview.fts.service.pdb; -import jalview.bin.Jalview; import jalview.datamodel.SequenceI; import jalview.fts.api.FTSData; import jalview.fts.api.FTSDataColumnI; @@ -30,6 +29,7 @@ import jalview.fts.core.FTSRestRequest; import jalview.fts.core.FTSRestResponse; import jalview.util.JSONUtils; import jalview.util.MessageManager; +import jalview.util.Platform; import java.net.URI; import java.util.ArrayList; @@ -125,7 +125,7 @@ public class PDBFTSRestClient extends FTSRestClient // different from the ones in Java yet still allow this to be correct for Java Client client; Class clientResponseClass; - if (Jalview.isJS()) + if (Platform.isJS()) { // JavaScript only -- coerce types to Java types for Java client = (Client) (Object) new jalview.javascript.web.Client(); diff --git a/src/jalview/fts/service/uniprot/UniProtFTSRestClient.java b/src/jalview/fts/service/uniprot/UniProtFTSRestClient.java index c3ca893..e6620f8 100644 --- a/src/jalview/fts/service/uniprot/UniProtFTSRestClient.java +++ b/src/jalview/fts/service/uniprot/UniProtFTSRestClient.java @@ -22,7 +22,6 @@ package jalview.fts.service.uniprot; import jalview.bin.Cache; -import jalview.bin.Jalview; import jalview.fts.api.FTSData; import jalview.fts.api.FTSDataColumnI; import jalview.fts.api.FTSRestClientI; @@ -30,6 +29,7 @@ import jalview.fts.core.FTSRestClient; import jalview.fts.core.FTSRestRequest; import jalview.fts.core.FTSRestResponse; import jalview.util.MessageManager; +import jalview.util.Platform; import java.util.ArrayList; import java.util.Collection; @@ -96,7 +96,7 @@ public class UniProtFTSRestClient extends FTSRestClient // Java Client client; Class clientResponseClass; - if (Jalview.isJS()) + if (Platform.isJS()) { // JavaScript only -- coerce types to Java types for Java client = (Client) (Object) new jalview.javascript.web.Client(); @@ -132,7 +132,7 @@ public class UniProtFTSRestClient extends FTSRestClient throw new Exception(errorMessage); } - int xTotalResults = Jalview.isJS() ? 1 + int xTotalResults = Platform.isJS() ? 1 : Integer.valueOf(clientResponse.getHeaders() .get("X-Total-Results").get(0)); clientResponse = null; diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 71ba94a..0b09fe5 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -89,6 +89,7 @@ import jalview.schemes.ResidueColourScheme; import jalview.schemes.TCoffeeColourScheme; import jalview.util.ImageMaker.TYPE; import jalview.util.MessageManager; +import jalview.util.Platform; import jalview.viewmodel.AlignmentViewport; import jalview.viewmodel.ViewportRanges; import jalview.ws.DBRefFetcher; @@ -3289,7 +3290,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { contents.toString() }); contents = null; - if (Jalview.isJS()) + if (Platform.isJS()) { JLabel textLabel = new JLabel(); textLabel.setText(content); diff --git a/src/jalview/gui/CrossRefAction.java b/src/jalview/gui/CrossRefAction.java index 85f2498..b5275e8 100644 --- a/src/jalview/gui/CrossRefAction.java +++ b/src/jalview/gui/CrossRefAction.java @@ -283,8 +283,8 @@ public class CrossRefAction implements Runnable */ String[] divisionsArray = ensemblDivisions .toArray(new String[ensemblDivisions.size()]); - DBRefEntry[] seqRefs = seq.getDBRefs(); - DBRefEntry[] directEnsemblRefs = DBRefUtils.selectRefs(seqRefs, + List seqRefs = seq.getDBRefs(); + List directEnsemblRefs = DBRefUtils.selectRefs(seqRefs, divisionsArray); if (directEnsemblRefs != null) { @@ -304,8 +304,8 @@ public class CrossRefAction implements Runnable { if (dbref.getMap() != null && dbref.getMap().getTo() != null) { - DBRefEntry[] dbrefs = dbref.getMap().getTo().getDBRefs(); - DBRefEntry[] indirectEnsemblRefs = DBRefUtils.selectRefs(dbrefs, + List dbrefs = dbref.getMap().getTo().getDBRefs(); + List indirectEnsemblRefs = DBRefUtils.selectRefs(dbrefs, divisionsArray); if (indirectEnsemblRefs != null) { diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index f1b8025..a50a2e6 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -350,7 +350,7 @@ public class Desktop extends jalview.jbgui.GDesktop * are spawned off as threads rather than waited for during this constructor. */ instance = this; - if (!Jalview.isJS()) + if (!Platform.isJS()) { doVamsasClientCheck(); } @@ -374,7 +374,7 @@ public class Desktop extends jalview.jbgui.GDesktop // getContentPane().add(sp, BorderLayout.CENTER); // BH 2018 - just an experiment to try unclipped JInternalFrames. - if (Jalview.isJS()) + if (Platform.isJS()) { getRootPane().putClientProperty("swingjs.overflow.hidden", "false"); } @@ -1178,7 +1178,7 @@ public class Desktop extends jalview.jbgui.GDesktop */ JComponent history; String urlBase = "http://www."; - if (Jalview.isJS()) + if (Platform.isJS()) { history = new JTextField(urlBase, 35); } @@ -1206,7 +1206,7 @@ public class Desktop extends jalview.jbgui.GDesktop @Override public void run() { - String url = Jalview.isJS() ? ((JTextField) history).getText() + String url = Platform.isJS() ? ((JTextField) history).getText() : ((JComboBox) history).getSelectedItem() .toString(); @@ -1431,7 +1431,7 @@ public class Desktop extends jalview.jbgui.GDesktop { try { - if (Jalview.isJS()) + if (Platform.isJS()) { BrowserLauncher.openURL("http://www.jalview.org/help.html"); } diff --git a/src/jalview/gui/FeatureSettings.java b/src/jalview/gui/FeatureSettings.java index 26cb104..b657ed3 100644 --- a/src/jalview/gui/FeatureSettings.java +++ b/src/jalview/gui/FeatureSettings.java @@ -22,7 +22,6 @@ package jalview.gui; import jalview.api.FeatureColourI; import jalview.api.FeatureSettingsControllerI; -import jalview.bin.Jalview; import jalview.datamodel.AlignmentI; import jalview.datamodel.SequenceI; import jalview.datamodel.features.FeatureMatcher; @@ -1765,7 +1764,7 @@ class ColorEditor extends AbstractCellEditor * variable colour and filters dialog */ chooser = new FeatureTypeSettings(fr, type); - if (!Jalview.isJS()) + if (!Platform.isJS()) { chooser.setRequestFocusEnabled(true); chooser.requestFocus(); diff --git a/src/jalview/gui/IdPanel.java b/src/jalview/gui/IdPanel.java index 9ee4750..d34c653 100755 --- a/src/jalview/gui/IdPanel.java +++ b/src/jalview/gui/IdPanel.java @@ -20,7 +20,6 @@ */ package jalview.gui; -import jalview.bin.Jalview; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceGroup; @@ -281,7 +280,7 @@ public class IdPanel extends JPanel void startScrolling(boolean up) { scrollThread = new ScrollThread(up); - if (!Jalview.isJS()) + if (!Platform.isJS()) { /* * Java - run in a new thread diff --git a/src/jalview/gui/ImageExporter.java b/src/jalview/gui/ImageExporter.java index a43eef0..5fb6951 100644 --- a/src/jalview/gui/ImageExporter.java +++ b/src/jalview/gui/ImageExporter.java @@ -7,6 +7,7 @@ import jalview.io.JalviewFileView; import jalview.util.ImageMaker; import jalview.util.ImageMaker.TYPE; import jalview.util.MessageManager; +import jalview.util.Platform; import java.awt.Component; import java.awt.Graphics; @@ -124,7 +125,7 @@ public class ImageExporter String renderStyle = Cache.getDefault( imageType.getName() + "_RENDERING", LineartOptions.PROMPT_EACH_TIME); - if (Jalview.isJS()) + if (Platform.isJS()) { renderStyle = "Text"; } diff --git a/src/jalview/gui/Jalview2XML.java b/src/jalview/gui/Jalview2XML.java index 897695e..3c070dc 100644 --- a/src/jalview/gui/Jalview2XML.java +++ b/src/jalview/gui/Jalview2XML.java @@ -29,6 +29,7 @@ import jalview.datamodel.AlignedCodonFrame; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; +import jalview.datamodel.DBRefEntry; import jalview.datamodel.GraphLine; import jalview.datamodel.PDBEntry; import jalview.datamodel.RnaViewerModel; @@ -2109,7 +2110,7 @@ public class Jalview2XML vamsasSeq.setName(jds.getName()); vamsasSeq.setSequence(jds.getSequenceAsString()); vamsasSeq.setDescription(jds.getDescription()); - jalview.datamodel.DBRefEntry[] dbrefs = null; + List dbrefs = null; if (jds.getDatasetSequence() != null) { vamsasSeq.setDsseqid(seqHash(jds.getDatasetSequence())); @@ -2127,15 +2128,16 @@ public class Jalview2XML } if (dbrefs != null) { - for (int d = 0; d < dbrefs.length; d++) + for (int d = 0, n = dbrefs.size(); d < n; d++) { DBRef dbref = new DBRef(); - dbref.setSource(dbrefs[d].getSource()); - dbref.setVersion(dbrefs[d].getVersion()); - dbref.setAccessionId(dbrefs[d].getAccessionId()); - if (dbrefs[d].hasMap()) + DBRefEntry e = dbrefs.get(d); + dbref.setSource(e.getSource()); + dbref.setVersion(e.getVersion()); + dbref.setAccessionId(e.getAccessionId()); + if (e.hasMap()) { - Mapping mp = createVamsasMapping(dbrefs[d].getMap(), parentseq, + Mapping mp = createVamsasMapping(e.getMap(), parentseq, jds, recurse); dbref.setMapping(mp); } diff --git a/src/jalview/gui/JvOptionPane.java b/src/jalview/gui/JvOptionPane.java index 2290b52..5bbe75f 100644 --- a/src/jalview/gui/JvOptionPane.java +++ b/src/jalview/gui/JvOptionPane.java @@ -21,7 +21,7 @@ package jalview.gui; -import jalview.bin.Jalview; +import jalview.util.Platform; import jalview.util.dialogrunner.DialogRunnerI; import java.awt.Component; @@ -58,7 +58,7 @@ public class JvOptionPane extends JOptionPane implements DialogRunnerI, public JvOptionPane(final Component parent) { - this.parentComponent = Jalview.isJS() ? this : parent; + this.parentComponent = Platform.isJS() ? this : parent; } public static int showConfirmDialog(Component parentComponent, @@ -720,7 +720,7 @@ public class JvOptionPane extends JOptionPane implements DialogRunnerI, String prefix = ""; // JavaScript only - if (Jalview.isJS()) + if (Platform.isJS()) { switch (messageType) { @@ -789,7 +789,7 @@ public class JvOptionPane extends JOptionPane implements DialogRunnerI, * In Java, the response is returned to this thread and handled here; * (for Javascript, see propertyChange) */ - if (!Jalview.isJS()) + if (!Platform.isJS()) { handleResponse(response); } @@ -818,7 +818,7 @@ public class JvOptionPane extends JOptionPane implements DialogRunnerI, yesNoCancelOption, questionMessage, icon, options, initresponse); } - if (!Jalview.isJS()) + if (!Platform.isJS()) { handleResponse(response); } diff --git a/src/jalview/gui/PopupMenu.java b/src/jalview/gui/PopupMenu.java index 5f58d51..7118c69 100644 --- a/src/jalview/gui/PopupMenu.java +++ b/src/jalview/gui/PopupMenu.java @@ -25,7 +25,6 @@ import jalview.analysis.AlignmentAnnotationUtils; import jalview.analysis.AlignmentUtils; import jalview.analysis.Conservation; import jalview.bin.Cache; -import jalview.bin.Jalview; import jalview.commands.ChangeCaseCommand; import jalview.commands.EditCommand; import jalview.commands.EditCommand.Action; @@ -51,6 +50,7 @@ import jalview.schemes.PIDColourScheme; import jalview.util.GroupUrlLink; import jalview.util.GroupUrlLink.UrlStringTooLongException; import jalview.util.MessageManager; +import jalview.util.Platform; import jalview.util.StringUtils; import jalview.util.UrlLink; @@ -864,12 +864,14 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener { sqi = sqi.getDatasetSequence(); } - DBRefEntry[] dbr = sqi.getDBRefs(); - if (dbr != null && dbr.length > 0) + List dbr = sqi.getDBRefs(); + int nd; + if (dbr != null && (nd = dbr.size()) > 0) { - for (int d = 0; d < dbr.length; d++) + for (int d = 0; d < nd; d++) { - String src = dbr[d].getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase(); + DBRefEntry e = dbr.get(d); + String src = e.getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase(); Object[] sarray = commonDbrefs.get(src); if (sarray == null) { @@ -882,10 +884,10 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener if (((String[]) sarray[1])[sq] == null) { - if (!dbr[d].hasMap() || (dbr[d].getMap() + if (!e.hasMap() || (e.getMap() .locateMappedRange(start, end) != null)) { - ((String[]) sarray[1])[sq] = dbr[d].getAccessionId(); + ((String[]) sarray[1])[sq] = e.getAccessionId(); ((int[]) sarray[0])[0]++; } } @@ -1650,7 +1652,7 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener String report = contents.toString(); JInternalFrame frame; - if (Jalview.isJS()) + if (Platform.isJS()) { JLabel textLabel = new JLabel(); textLabel.setText(report); diff --git a/src/jalview/gui/Preferences.java b/src/jalview/gui/Preferences.java index 6a558d5..35641f8 100755 --- a/src/jalview/gui/Preferences.java +++ b/src/jalview/gui/Preferences.java @@ -22,7 +22,6 @@ package jalview.gui; import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder; import jalview.bin.Cache; -import jalview.bin.Jalview; import jalview.gui.Help.HelpId; import jalview.gui.StructureViewer.ViewerType; import jalview.io.FileFormatI; @@ -189,7 +188,7 @@ public class Preferences extends GPreferences super(); frame = new JInternalFrame(); frame.setContentPane(this); - if (!Jalview.isJS()) + if (!Platform.isJS()) { wsPrefs = new WsPreferences(); wsTab.add(wsPrefs, BorderLayout.CENTER); @@ -555,7 +554,7 @@ public class Preferences extends GPreferences /* * JalviewJS doesn't support Lineart so force it to Text */ - String defaultOption = Jalview.isJS() ? "Text" + String defaultOption = Platform.isJS() ? "Text" : Cache.getDefault(propertyKey, "Prompt each time"); if (defaultOption.equalsIgnoreCase("Text")) { @@ -820,7 +819,7 @@ public class Preferences extends GPreferences Cache.applicationProperties.setProperty("PAD_GAPS", Boolean.toString(padGaps.isSelected())); - if (!Jalview.isJS()) + if (!Platform.isJS()) { wsPrefs.updateAndRefreshWsMenuConfig(false); } @@ -897,7 +896,7 @@ public class Preferences extends GPreferences { try { - if (!Jalview.isJS()) + if (!Platform.isJS()) { wsPrefs.updateWsMenuConfig(true); wsPrefs.refreshWs_actionPerformed(e); diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index 5e117ca..59f239f 100644 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -22,7 +22,6 @@ package jalview.gui; import jalview.api.AlignViewportI; import jalview.bin.Cache; -import jalview.bin.Jalview; import jalview.commands.EditCommand; import jalview.commands.EditCommand.Action; import jalview.commands.EditCommand.Edit; @@ -2054,7 +2053,7 @@ public class SeqPanel extends JPanel { scrollThread = new ScrollThread(); scrollThread.setMousePosition(mousePos); - if (!Jalview.isJS()) + if (!Platform.isJS()) { /* * Java - run in a new thread diff --git a/src/jalview/gui/SequenceFetcher.java b/src/jalview/gui/SequenceFetcher.java index 24db866..1e6d678 100755 --- a/src/jalview/gui/SequenceFetcher.java +++ b/src/jalview/gui/SequenceFetcher.java @@ -750,13 +750,14 @@ public class SequenceFetcher extends JPanel implements Runnable for (String q : queries) { - DBRefEntry dbr = new DBRefEntry(); - dbr.setSource(proxy.getDbSource()); - dbr.setVersion(null); + // BH 2019.01.25 dbr is never used. +// DBRefEntry dbr = new DBRefEntry(); +// dbr.setSource(proxy.getDbSource()); +// dbr.setVersion(null); String accId = proxy.getAccessionIdFromQuery(q); - dbr.setAccessionId(accId); +// dbr.setAccessionId(accId); boolean rfound = false; - for (int r = 0; r < rs.length; r++) + for (int r = 0, nr = rs.length; r < nr; r++) { if (rs[r] != null) { diff --git a/src/jalview/gui/StructureChooser.java b/src/jalview/gui/StructureChooser.java index d4d077f..23b7fcf 100644 --- a/src/jalview/gui/StructureChooser.java +++ b/src/jalview/gui/StructureChooser.java @@ -337,10 +337,12 @@ public class StructureChooser extends GStructureChooser } } - if (seq.getDBRefs() != null && seq.getDBRefs().length != 0) + List refs = seq.getDBRefs(); + if (refs != null && refs.size() != 0) { - for (DBRefEntry dbRef : seq.getDBRefs()) + for (int ib = 0, nb = refs.size(); ib < nb; ib++) { + DBRefEntry dbRef = refs.get(ib); if (isValidSeqName(getDBRefId(dbRef)) && queryBuilder.length() < MAX_QLENGTH) { diff --git a/src/jalview/gui/TreePanel.java b/src/jalview/gui/TreePanel.java index 30604cb..b59d197 100755 --- a/src/jalview/gui/TreePanel.java +++ b/src/jalview/gui/TreePanel.java @@ -709,20 +709,20 @@ public class TreePanel extends GTreePanel if (sq != null) { // search dbrefs, features and annotation - DBRefEntry[] refs = jalview.util.DBRefUtils + List refs = jalview.util.DBRefUtils .selectRefs(sq.getDBRefs(), new String[] { labelClass.toUpperCase() }); if (refs != null) { - for (int i = 0; i < refs.length; i++) + for (int i = 0, ni = refs.size(); i < ni; i++) { if (newname == null) { - newname = new String(refs[i].getAccessionId()); + newname = new String(refs.get(i).getAccessionId()); } else { - newname = newname + "; " + refs[i].getAccessionId(); + newname += "; " + refs.get(i).getAccessionId(); } } } diff --git a/src/jalview/io/AppletFormatAdapter.java b/src/jalview/io/AppletFormatAdapter.java index 8c376fc..6db04a0 100755 --- a/src/jalview/io/AppletFormatAdapter.java +++ b/src/jalview/io/AppletFormatAdapter.java @@ -30,6 +30,7 @@ import jalview.datamodel.PDBEntry.Type; import jalview.datamodel.SequenceI; import jalview.ext.jmol.JmolParser; import jalview.structure.StructureImportSettings; +import jalview.util.Platform; import java.io.File; import java.io.IOException; @@ -444,7 +445,7 @@ public class AppletFormatAdapter { protocol = DataSourceType.URL; } - else if (jalview.bin.Jalview.isJS()) + else if (Platform.isJS()) { protocol = DataSourceType.RELATIVE_URL; } diff --git a/src/jalview/io/JSONFile.java b/src/jalview/io/JSONFile.java index 3f1b1a7..390c771 100644 --- a/src/jalview/io/JSONFile.java +++ b/src/jalview/io/JSONFile.java @@ -601,9 +601,9 @@ public class JSONFile extends AlignFile implements ComplexAlignFile if (hiddenSeqs != null && !hiddenSeqs.isEmpty()) { String[] seqRefs = hiddenSeqs.split(";"); - for (String seqRef : seqRefs) + for (int i = seqRefs.length; --i >= 0;) { - hiddenSeqRefs.add(seqRef); + hiddenSeqRefs.add(seqRefs[i]); } } } @@ -615,9 +615,9 @@ public class JSONFile extends AlignFile implements ComplexAlignFile { hiddenColumns = new HiddenColumns(); String[] rangeStrings = hiddenCols.split(";"); - for (String rangeString : rangeStrings) + for (int i = rangeStrings.length; --i >= 0;) { - String[] range = rangeString.split("-"); + String[] range = rangeStrings[i].split("-"); hiddenColumns.hideColumns(Integer.valueOf(range[0]), Integer.valueOf(range[1])); } @@ -630,10 +630,9 @@ public class JSONFile extends AlignFile implements ComplexAlignFile if (jsonSeqFeatures != null) { displayedFeatures = new FeaturesDisplayed(); - for (Iterator seqFeatureItr = jsonSeqFeatures - .iterator(); seqFeatureItr.hasNext();) + for (Object o : jsonSeqFeatures) { - Map jsonFeature = (Map) seqFeatureItr.next(); + Map jsonFeature = (Map) o; Long begin = (Long) jsonFeature.get("xStart"); Long end = (Long) jsonFeature.get("xEnd"); String type = (String) jsonFeature.get("type"); diff --git a/src/jalview/io/JalviewFileChooser.java b/src/jalview/io/JalviewFileChooser.java index f6455bf..67f1115 100755 --- a/src/jalview/io/JalviewFileChooser.java +++ b/src/jalview/io/JalviewFileChooser.java @@ -22,7 +22,6 @@ package jalview.io; import jalview.bin.Cache; -import jalview.bin.Jalview; import jalview.gui.JvOptionPane; import jalview.util.MessageManager; import jalview.util.Platform; @@ -194,7 +193,7 @@ public class JalviewFileChooser extends JFileChooser implements DialogRunnerI, { int value = super.showOpenDialog(this); - if (!Jalview.isJS()) + if (!Platform.isJS()) { /* * code here is not run in JalviewJS, instead diff --git a/src/jalview/io/ModellerDescription.java b/src/jalview/io/ModellerDescription.java index 442278d..7e05b15 100755 --- a/src/jalview/io/ModellerDescription.java +++ b/src/jalview/io/ModellerDescription.java @@ -20,8 +20,11 @@ */ package jalview.io; +import jalview.datamodel.DBRefEntry; import jalview.datamodel.SequenceI; +import java.util.List; + public class ModellerDescription { /** @@ -271,21 +274,20 @@ public class ModellerDescription if (seq.getDatasetSequence() != null && seq.getDatasetSequence().getDBRefs() != null) { - jalview.datamodel.DBRefEntry[] dbr = seq.getDatasetSequence() - .getDBRefs(); - int i, j; - for (i = 0, j = dbr.length; i < j; i++) + List dbr = seq.getDatasetSequence().getDBRefs(); + for (int i = 0, ni = dbr.size(); i < ni; i++) { - if (dbr[i] != null) + DBRefEntry dbri = dbr.get(i); + if (dbri != null) { // JBPNote PDB dbRefEntry needs properties to propagate onto // ModellerField // JBPNote Need to get info from the user about whether the sequence // is the one being modelled, or if it is a template. - if (dbr[i].getSource() + if (dbri.getSource() .equals(jalview.datamodel.DBRefSource.PDB)) { - fields.put(Fields[LOCALID], dbr[i].getAccessionId()); + fields.put(Fields[LOCALID], dbri.getAccessionId()); t = 2; break; } diff --git a/src/jalview/io/SequenceAnnotationReport.java b/src/jalview/io/SequenceAnnotationReport.java index 6b82671..29b9942 100644 --- a/src/jalview/io/SequenceAnnotationReport.java +++ b/src/jalview/io/SequenceAnnotationReport.java @@ -394,14 +394,14 @@ public class SequenceAnnotationReport protected int appendDbRefs(final StringBuilder sb, SequenceI ds, boolean summary) { - DBRefEntry[] dbrefs = ds.getDBRefs(); + List dbrefs = ds.getDBRefs(); if (dbrefs == null) { return 0; } // note this sorts the refs held on the sequence! - Arrays.sort(dbrefs, comparator); + dbrefs.sort(comparator); boolean ellipsis = false; String source = null; String lastSource = null; diff --git a/src/jalview/io/StockholmFile.java b/src/jalview/io/StockholmFile.java index 0e73af1..84e629e 100644 --- a/src/jalview/io/StockholmFile.java +++ b/src/jalview/io/StockholmFile.java @@ -76,9 +76,9 @@ public class StockholmFile extends AlignFile { private static final String ANNOTATION = "annotation"; - private static final Regex OPEN_PAREN = new Regex("(<|\\[)", "("); - - private static final Regex CLOSE_PAREN = new Regex("(>|\\])", ")"); +// private static final Regex OPEN_PAREN = new Regex("(<|\\[)", "("); +// +// private static final Regex CLOSE_PAREN = new Regex("(>|\\])", ")"); public static final Regex DETECT_BRACKETS = new Regex( "(<|>|\\[|\\]|\\(|\\)|\\{|\\})"); @@ -239,8 +239,8 @@ public class StockholmFile extends AlignFile Regex openparen = new Regex("(<|\\[)", "("); Regex closeparen = new Regex("(>|\\])", ")"); - // Detect if file is RNA by looking for bracket types - Regex detectbrackets = new Regex("(<|>|\\[|\\]|\\(|\\))"); +// // Detect if file is RNA by looking for bracket types +// Regex detectbrackets = new Regex("(<|>|\\[|\\]|\\(|\\))"); rend.optimize(); p.optimize(); @@ -261,7 +261,7 @@ public class StockholmFile extends AlignFile // End of the alignment, pass stuff back this.noSeqs = seqs.size(); - String seqdb, dbsource = null; + String dbsource = null; Regex pf = new Regex("PF[0-9]{5}(.*)"); // Finds AC for Pfam Regex rf = new Regex("RF[0-9]{5}(.*)"); // Finds AC for Rfam if (getAlignmentProperty("AC") != null) @@ -941,28 +941,33 @@ public class StockholmFile extends AlignFile int max = 0; int maxid = 0; int in = 0; - Hashtable dataRef = null; - while ((in < s.length) && (s[in] != null)) + int slen = s.length; + SequenceI seq; + Hashtable dataRef = null; + while ((in < slen) && ((seq = s[in]) != null)) { - String tmp = printId(s[in], jvSuffix); - max = Math.max(max, s[in].getLength()); + String tmp = printId(seq, jvSuffix); + max = Math.max(max, seq.getLength()); if (tmp.length() > maxid) { maxid = tmp.length(); } - if (s[in].getDBRefs() != null) + List seqrefs = seq.getDBRefs(); + int ndb; + if (seqrefs != null && (ndb = seqrefs.size()) > 0) { - for (int idb = 0; idb < s[in].getDBRefs().length; idb++) + if (dataRef == null) + { + dataRef = new Hashtable<>(); + } + for (int idb = 0; idb < ndb; idb++) { - if (dataRef == null) - { - dataRef = new Hashtable(); - } - String datAs1 = s[in].getDBRefs()[idb].getSource().toString() + DBRefEntry ref = seqrefs.get(idb); + String datAs1 = ref.getSource().toString() + " ; " - + s[in].getDBRefs()[idb].getAccessionId().toString(); + + ref.getAccessionId().toString(); dataRef.put(tmp, datAs1); } } @@ -989,7 +994,7 @@ public class StockholmFile extends AlignFile // output database accessions if (dataRef != null) { - Enumeration en = dataRef.keys(); + Enumeration en = dataRef.keys(); while (en.hasMoreElements()) { Object idd = en.nextElement(); @@ -1010,13 +1015,13 @@ public class StockholmFile extends AlignFile } // output annotations - while (i < s.length && s[i] != null) + while (i < slen && (seq = s[i]) != null) { - AlignmentAnnotation[] alAnot = s[i].getAnnotation(); + AlignmentAnnotation[] alAnot = seq.getAnnotation(); if (alAnot != null) { Annotation[] ann; - for (int j = 0; j < alAnot.length; j++) + for (int j = 0, nj = alAnot.length; j < nj; j++) { String key = type2id(alAnot[j].label); @@ -1036,37 +1041,38 @@ public class StockholmFile extends AlignFile // out.append("#=GR "); out.append(new Format("%-" + maxid + "s").form( - "#=GR " + printId(s[i], jvSuffix) + " " + key + " ")); + "#=GR " + printId(seq, jvSuffix) + " " + key + " ")); ann = alAnot[j].annotations; - String seq = ""; - for (int k = 0; k < ann.length; k++) + String sseq = ""; + for (int k = 0, nk = ann.length; k < nk; k++) { - seq += outputCharacter(key, k, isrna, ann, s[i]); + sseq += outputCharacter(key, k, isrna, ann, seq); } - out.append(seq); + out.append(sseq); out.append(newline); } } out.append(new Format("%-" + maxid + "s") - .form(printId(s[i], jvSuffix) + " ")); - out.append(s[i].getSequenceAsString()); + .form(printId(seq, jvSuffix) + " ")); + out.append(seq.getSequenceAsString()); out.append(newline); i++; } // alignment annotation AlignmentAnnotation aa; - if (al.getAlignmentAnnotation() != null) + AlignmentAnnotation[] an = al.getAlignmentAnnotation(); + if (an != null) { - for (int ia = 0; ia < al.getAlignmentAnnotation().length; ia++) + for (int ia = 0, na = an.length; ia < na; ia++) { - aa = al.getAlignmentAnnotation()[ia]; + aa = an[ia]; if (aa.autoCalculated || !aa.visible || aa.sequenceRef != null) { continue; } - String seq = ""; + String sseq = ""; String label; String key = ""; if (aa.label.equals("seq")) @@ -1094,11 +1100,11 @@ public class StockholmFile extends AlignFile out.append( new Format("%-" + maxid + "s").form("#=GC " + label + " ")); boolean isrna = aa.isValidStruc(); - for (int j = 0; j < aa.annotations.length; j++) + for (int j = 0, nj = aa.annotations.length; j < nj; j++) { - seq += outputCharacter(key, j, isrna, aa.annotations, null); + sseq += outputCharacter(key, j, isrna, aa.annotations, null); } - out.append(seq); + out.append(sseq); out.append(newline); } } diff --git a/src/jalview/io/WSWUBlastClient.java b/src/jalview/io/WSWUBlastClient.java index d526a31..63b78b2 100755 --- a/src/jalview/io/WSWUBlastClient.java +++ b/src/jalview/io/WSWUBlastClient.java @@ -32,6 +32,7 @@ import jalview.util.MessageManager; import java.util.ArrayList; import java.util.Enumeration; +import java.util.List; import java.util.StringTokenizer; import java.util.Vector; @@ -175,12 +176,13 @@ public class WSWUBlastClient } } - DBRefEntry[] entries = oldseq.getDBRefs(); - if (entries != null) + List entries = oldseq.getDBRefs(); + // BH 2019.01.25 check for 0-length was missing here + if (entries != null && entries.size() > 0) { oldseq.addDBRef(new jalview.datamodel.DBRefEntry( jalview.datamodel.DBRefSource.UNIPROT, "0", - entries[0].getAccessionId())); + entries.get(0).getAccessionId())); } } } diff --git a/src/jalview/io/cache/JvCacheableInputBox.java b/src/jalview/io/cache/JvCacheableInputBox.java index b1b7ac5..cf21c62 100644 --- a/src/jalview/io/cache/JvCacheableInputBox.java +++ b/src/jalview/io/cache/JvCacheableInputBox.java @@ -21,8 +21,8 @@ package jalview.io.cache; import jalview.bin.Cache; -import jalview.bin.Jalview; import jalview.util.MessageManager; +import jalview.util.Platform; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -92,7 +92,7 @@ public class JvCacheableInputBox public JvCacheableInputBox(String newCacheKey) { super(); - if (Jalview.isJS()) + if (Platform.isJS()) { textField = new JTextField(); return; @@ -202,7 +202,7 @@ public class JvCacheableInputBox */ public void updateCache() { - if (Jalview.isJS()) + if (Platform.isJS()) { return; } @@ -278,7 +278,7 @@ public class JvCacheableInputBox */ public void persistCache() { - if (!Jalview.isJS()) + if (!Platform.isJS()) { appCache.persistCache(cacheKey); } @@ -291,7 +291,7 @@ public class JvCacheableInputBox */ public String getUserInput() { - if (Jalview.isJS()) + if (Platform.isJS()) { return textField.getText().trim(); } @@ -301,12 +301,12 @@ public class JvCacheableInputBox public JComponent getComponent() { - return Jalview.isJS() ? textField : comboBox; + return Platform.isJS() ? textField : comboBox; } public void addActionListener(ActionListener actionListener) { - if (Jalview.isJS()) + if (Platform.isJS()) { textField.addActionListener(actionListener); } @@ -318,7 +318,7 @@ public class JvCacheableInputBox public void addDocumentListener(DocumentListener listener) { - if (!Jalview.isJS()) + if (!Platform.isJS()) { ((JTextComponent) comboBox.getEditor().getEditorComponent()) .getDocument().addDocumentListener(listener); @@ -327,7 +327,7 @@ public class JvCacheableInputBox public void addFocusListener(FocusListener focusListener) { - if (Jalview.isJS()) + if (Platform.isJS()) { textField.addFocusListener(focusListener); } @@ -339,7 +339,7 @@ public class JvCacheableInputBox public void addKeyListener(KeyListener kl) { - if (!Jalview.isJS()) + if (!Platform.isJS()) { comboBox.getEditor().getEditorComponent().addKeyListener(kl); } @@ -347,7 +347,7 @@ public class JvCacheableInputBox public void setEditable(boolean b) { - if (!Jalview.isJS()) + if (!Platform.isJS()) { comboBox.setEditable(b); } @@ -355,7 +355,7 @@ public class JvCacheableInputBox public void setPrototypeDisplayValue(String string) { - if (!Jalview.isJS()) + if (!Platform.isJS()) { comboBox.setPrototypeDisplayValue(string); } @@ -363,7 +363,7 @@ public class JvCacheableInputBox public void setSelectedItem(String userInput) { - if (!Jalview.isJS()) + if (!Platform.isJS()) { comboBox.setSelectedItem(userInput); } @@ -371,7 +371,7 @@ public class JvCacheableInputBox public boolean isPopupVisible() { - if (!Jalview.isJS()) + if (!Platform.isJS()) { return comboBox.isPopupVisible(); } @@ -380,7 +380,7 @@ public class JvCacheableInputBox public void addCaretListener(CaretListener caretListener) { - if (!Jalview.isJS()) + if (!Platform.isJS()) { ((JTextComponent) comboBox.getEditor().getEditorComponent()) .addCaretListener(caretListener); @@ -389,7 +389,7 @@ public class JvCacheableInputBox public void addItem(String item) { - if (!Jalview.isJS()) + if (!Platform.isJS()) { comboBox.addItem(item); } diff --git a/src/jalview/io/vamsas/Datasetsequence.java b/src/jalview/io/vamsas/Datasetsequence.java index a399c04..d24e947 100644 --- a/src/jalview/io/vamsas/Datasetsequence.java +++ b/src/jalview/io/vamsas/Datasetsequence.java @@ -180,13 +180,13 @@ public class Datasetsequence extends DatastoreItem if (sq.getDatasetSequence() == null && sq.getDBRefs() != null) { // only sync database references for dataset sequences - DBRefEntry[] entries = sq.getDBRefs(); + List entries = sq.getDBRefs(); // jalview.datamodel.DBRefEntry dbentry; - for (int db = 0; db < entries.length; db++) + for (int db = 0, dn = entries.size(); db < dn; db++) { modifiedthedoc |= new jalview.io.vamsas.Dbref(datastore, // dbentry = - entries[db], sq, (Sequence) vobj, dataset).docWasUpdated(); + entries.get(db), sq, (Sequence) vobj, dataset).docWasUpdated(); } diff --git a/src/jalview/io/vamsas/Sequencemapping.java b/src/jalview/io/vamsas/Sequencemapping.java index 2bcef3a..0a582e5 100644 --- a/src/jalview/io/vamsas/Sequencemapping.java +++ b/src/jalview/io/vamsas/Sequencemapping.java @@ -22,11 +22,14 @@ package jalview.io.vamsas; import jalview.datamodel.AlignedCodonFrame; import jalview.datamodel.AlignmentI; +import jalview.datamodel.DBRefEntry; import jalview.datamodel.Mapping; import jalview.datamodel.SequenceI; import jalview.gui.Desktop; import jalview.io.VamsasAppDatastore; +import java.util.ArrayList; +import java.util.List; import java.util.Vector; import uk.ac.vamsas.objects.core.AlignmentSequence; @@ -398,18 +401,25 @@ public class Sequencemapping extends Rangetype jalview.bin.Cache.log.debug("Matching conjugate refs for " + from.getName() + " and " + to.getName()); } - jalview.datamodel.DBRefEntry[] fdb = from.getDBRefs(); - jalview.datamodel.DBRefEntry[] tdb = new jalview.datamodel.DBRefEntry[to - .getDBRefs().length]; - int tdblen = to.getDBRefs().length; - System.arraycopy(to.getDBRefs(), 0, tdb, 0, tdblen); + List fdb = from.getDBRefs(); + List tdb = new ArrayList(to.getDBRefs()); + int tdblen = to.getDBRefs().size(); +// +// +// YOWSER +// +// System.arraycopy(to.getDBRefs(), 0, tdb, 0, tdblen); +// +// +// +// Vector matched = new Vector(); jalview.util.MapList smapI = smap.getInverse(); - for (int f = 0; f < fdb.length; f++) + for (int f = 0, fn = fdb.size(); f < fn; f++) { - jalview.datamodel.DBRefEntry fe = fdb[f]; + jalview.datamodel.DBRefEntry fe = fdb.get(f); jalview.datamodel.Mapping fmp = fe.getMap(); - boolean fmpnnl = fmp != null; + boolean fmpnnl = (fmp != null); // if (fmpnnl && fmp.getTo()!=null) // { // jalview.bin.Cache.log.debug("Not overwriting existing To reference in @@ -424,7 +434,7 @@ public class Sequencemapping extends Rangetype : false; for (int t = 0; t < tdblen; t++) { - jalview.datamodel.DBRefEntry te = tdb[t]; + jalview.datamodel.DBRefEntry te = tdb.get(t); if (te != null) { if (fe.getSource().equals(te.getSource()) diff --git a/src/jalview/io/vcf/VCFLoader.java b/src/jalview/io/vcf/VCFLoader.java index de2f18a..90ecaca 100644 --- a/src/jalview/io/vcf/VCFLoader.java +++ b/src/jalview/io/vcf/VCFLoader.java @@ -543,7 +543,7 @@ public class VCFLoader */ protected void transferAddedFeatures(SequenceI seq) { - DBRefEntry[] dbrefs = seq.getDBRefs(); + List dbrefs = seq.getDBRefs(); if (dbrefs == null) { return; diff --git a/src/jalview/jbgui/GAlignFrame.java b/src/jalview/jbgui/GAlignFrame.java index 15d5713..2e6aab8 100755 --- a/src/jalview/jbgui/GAlignFrame.java +++ b/src/jalview/jbgui/GAlignFrame.java @@ -23,7 +23,6 @@ package jalview.jbgui; import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder; import jalview.api.SplitContainerI; import jalview.bin.Cache; -import jalview.bin.Jalview; import jalview.gui.JvSwingUtils; import jalview.gui.Preferences; import jalview.io.FileFormats; @@ -1711,7 +1710,7 @@ public class GAlignFrame extends JInternalFrame alignFrameMenuBar.add(formatMenu); alignFrameMenuBar.add(colourMenu); alignFrameMenuBar.add(calculateMenu); - if (!Jalview.isJS()) + if (!Platform.isJS()) { alignFrameMenuBar.add(webService); } @@ -1732,7 +1731,7 @@ public class GAlignFrame extends JInternalFrame fileMenu.add(exportAnnotations); fileMenu.add(loadTreeMenuItem); fileMenu.add(associatedData); - if (!Jalview.isJS()) + if (!Platform.isJS()) { fileMenu.add(loadVcf); } @@ -1830,7 +1829,7 @@ public class GAlignFrame extends JInternalFrame calculateMenu.addSeparator(); calculateMenu.add(expandAlignment); calculateMenu.add(extractScores); - if (!Jalview.isJS()) + if (!Platform.isJS()) { calculateMenu.addSeparator(); calculateMenu.add(runGroovy); @@ -1839,14 +1838,14 @@ public class GAlignFrame extends JInternalFrame webServiceNoServices = new JMenuItem( MessageManager.getString("label.no_services")); webService.add(webServiceNoServices); - if (!Jalview.isJS()) + if (!Platform.isJS()) { exportImageMenu.add(htmlMenuItem); } exportImageMenu.add(epsFile); exportImageMenu.add(createPNG); exportImageMenu.add(createBioJS); - if (!Jalview.isJS()) + if (!Platform.isJS()) { exportImageMenu.add(createSVG); } diff --git a/src/jalview/jbgui/GDesktop.java b/src/jalview/jbgui/GDesktop.java index b301f6e..28e544e 100755 --- a/src/jalview/jbgui/GDesktop.java +++ b/src/jalview/jbgui/GDesktop.java @@ -21,7 +21,6 @@ package jalview.jbgui; import jalview.api.AlignmentViewPanel; -import jalview.bin.Jalview; import jalview.io.FileFormatException; import jalview.util.MessageManager; import jalview.util.Platform; @@ -464,7 +463,7 @@ public class GDesktop extends JFrame FileMenu.addSeparator(); FileMenu.add(saveAsJaxb); FileMenu.add(loadAsJaxb); - if (!Jalview.isJS()) + if (!Platform.isJS()) { FileMenu.add(saveState); FileMenu.add(loadState); @@ -480,12 +479,12 @@ public class GDesktop extends JFrame VamsasMenu.add(vamsasSave); VamsasMenu.add(vamsasStop); toolsMenu.add(preferences); - if (!Jalview.isJS()) + if (!Platform.isJS()) { toolsMenu.add(showMemusage); toolsMenu.add(showConsole); } - if (!Jalview.isJS()) + if (!Platform.isJS()) { toolsMenu.add(showNews); toolsMenu.add(garbageCollect); diff --git a/src/jalview/jbgui/GPreferences.java b/src/jalview/jbgui/GPreferences.java index 9fc0398..1e01cc3 100755 --- a/src/jalview/jbgui/GPreferences.java +++ b/src/jalview/jbgui/GPreferences.java @@ -20,13 +20,13 @@ */ package jalview.jbgui; -import jalview.bin.Jalview; import jalview.fts.core.FTSDataColumnPreferences; import jalview.fts.core.FTSDataColumnPreferences.PreferenceSource; import jalview.fts.service.pdb.PDBFTSRestClient; import jalview.gui.JvSwingUtils; import jalview.gui.StructureViewer.ViewerType; import jalview.util.MessageManager; +import jalview.util.Platform; import java.awt.BorderLayout; import java.awt.Color; @@ -329,7 +329,7 @@ public class GPreferences extends JPanel /* * See WsPreferences for the real work of configuring this tab. */ - if (!Jalview.isJS()) + if (!Platform.isJS()) { wsTab.setLayout(new BorderLayout()); tabbedPane.add(wsTab, MessageManager.getString("label.web_services")); @@ -514,7 +514,7 @@ public class GPreferences extends JPanel outputTab.add(userIdWidth); outputTab.add(userIdWidthlabel); outputTab.add(modellerOutput); - if (!Jalview.isJS()) + if (!Platform.isJS()) { /* * JalviewJS doesn't support Lineart option or SVG output @@ -1289,7 +1289,7 @@ public class GPreferences extends JPanel /* * hide Chimera options in JalviewJS */ - if (Jalview.isJS()) + if (Platform.isJS()) { pathLabel.setVisible(false); chimeraPath.setVisible(false); @@ -1674,7 +1674,7 @@ public class GPreferences extends JPanel visualTab.add(fontSizeCB); visualTab.add(fontStyleCB); - if (Jalview.isJS()) + if (Platform.isJS()) { startupCheckbox.setVisible(false); startupFileTextfield.setVisible(false); diff --git a/src/jalview/project/Jalview2XML.java b/src/jalview/project/Jalview2XML.java index 646cab5..336ea47 100644 --- a/src/jalview/project/Jalview2XML.java +++ b/src/jalview/project/Jalview2XML.java @@ -29,6 +29,7 @@ import jalview.datamodel.AlignedCodonFrame; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; +import jalview.datamodel.DBRefEntry; import jalview.datamodel.GraphLine; import jalview.datamodel.PDBEntry; import jalview.datamodel.RnaViewerModel; @@ -2259,7 +2260,7 @@ public class Jalview2XML vamsasSeq.setName(jds.getName()); vamsasSeq.setSequence(jds.getSequenceAsString()); vamsasSeq.setDescription(jds.getDescription()); - jalview.datamodel.DBRefEntry[] dbrefs = null; + List dbrefs = null; if (jds.getDatasetSequence() != null) { vamsasSeq.setDsseqid(seqHash(jds.getDatasetSequence())); @@ -2277,15 +2278,16 @@ public class Jalview2XML } if (dbrefs != null) { - for (int d = 0; d < dbrefs.length; d++) + for (int d = 0, nd = dbrefs.size(); d < nd; d++) { DBRef dbref = new DBRef(); - dbref.setSource(dbrefs[d].getSource()); - dbref.setVersion(dbrefs[d].getVersion()); - dbref.setAccessionId(dbrefs[d].getAccessionId()); - if (dbrefs[d].hasMap()) + DBRefEntry ref = dbrefs.get(d); + dbref.setSource(ref.getSource()); + dbref.setVersion(ref.getVersion()); + dbref.setAccessionId(ref.getAccessionId()); + if (ref.hasMap()) { - Mapping mp = createVamsasMapping(dbrefs[d].getMap(), parentseq, + Mapping mp = createVamsasMapping(ref.getMap(), parentseq, jds, recurse); dbref.setMapping(mp); } diff --git a/src/jalview/renderer/AnnotationRenderer.java b/src/jalview/renderer/AnnotationRenderer.java index 4d3445b..ed266ae 100644 --- a/src/jalview/renderer/AnnotationRenderer.java +++ b/src/jalview/renderer/AnnotationRenderer.java @@ -25,7 +25,6 @@ import jalview.analysis.CodingUtils; import jalview.analysis.Rna; import jalview.analysis.StructureFrequency; import jalview.api.AlignViewportI; -import jalview.bin.Jalview; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.Annotation; import jalview.datamodel.ColumnSelection; @@ -1485,7 +1484,7 @@ public class AnnotationRenderer // int hght = (int) (ht + (newAsc - newDec); // - lm.getBaselineOffsets()[lm.getBaselineIndex()])); - if (Jalview.isJS()) + if (Platform.isJS()) { /* * SwingJS does not implement font.deriveFont() diff --git a/src/jalview/util/DBRefUtils.java b/src/jalview/util/DBRefUtils.java index 50a34fc..ee240b7 100755 --- a/src/jalview/util/DBRefUtils.java +++ b/src/jalview/util/DBRefUtils.java @@ -22,16 +22,16 @@ package jalview.util; import jalview.datamodel.DBRefEntry; import jalview.datamodel.DBRefSource; +import jalview.datamodel.Mapping; import jalview.datamodel.PDBEntry; import jalview.datamodel.SequenceI; import java.util.ArrayList; -import java.util.Arrays; +import java.util.BitSet; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Set; import com.stevesoft.pat.Regex; @@ -40,6 +40,16 @@ import com.stevesoft.pat.Regex; */ public class DBRefUtils { + + public final static int DB_SOURCE = 1; + public final static int DB_VERSION = 2; + public final static int DB_ID = 4; + public final static int DB_MAP = 8; + + + public final static int SEARCH_MODE_NO_MAP_NO_VERSION = DB_SOURCE | DB_ID; + public final static int SEARCH_MODE_FULL = DB_SOURCE | DB_VERSION | DB_ID | DB_MAP; + /* * lookup from lower-case form of a name to its canonical (standardised) form */ @@ -66,12 +76,13 @@ public class DBRefUtils canonicalSourceNameLookup.put("ensembl-gn", DBRefSource.ENSEMBL); // Make sure we have lowercase entries for all canonical string lookups - Set keys = canonicalSourceNameLookup.keySet(); - for (String k : keys) - { - canonicalSourceNameLookup.put(k.toLowerCase(), - canonicalSourceNameLookup.get(k)); - } +// BH 2019.01.25 unnecessary -- they are all lower case already + //Set keys = canonicalSourceNameLookup.keySet(); +// for (String k : keys) +// { +// canonicalSourceNameLookup.put(k.toLowerCase(), +// canonicalSourceNameLookup.get(k)); +// } dasCoordinateSystemsLookup.put("pdbresnum", DBRefSource.PDB); dasCoordinateSystemsLookup.put("uniprot", DBRefSource.UNIPROT); @@ -90,22 +101,26 @@ public class DBRefUtils * array of sources to select * @return */ - public static DBRefEntry[] selectRefs(DBRefEntry[] dbrefs, + public static List selectRefs(List dbrefs, String[] sources) { if (dbrefs == null || sources == null) { return dbrefs; } + + // BH TODO HashSet srcs = new HashSet(); for (String src : sources) { srcs.add(src.toUpperCase()); } + int nrefs = dbrefs.size(); List res = new ArrayList(); - for (DBRefEntry dbr : dbrefs) + for (int ib = 0; ib < nrefs; ib++) { + DBRefEntry dbr = dbrefs.get(ib); String source = getCanonicalName(dbr.getSource()); if (srcs.contains(source.toUpperCase())) { @@ -115,12 +130,29 @@ public class DBRefUtils if (res.size() > 0) { - DBRefEntry[] reply = new DBRefEntry[res.size()]; - return res.toArray(reply); + //List reply = new DBRefEntry[res.size()]; + return res;//.toArray(reply); } return null; } + private static boolean selectRefsBS(List dbrefs, String sourceKeys, BitSet bsSelect) { + if (dbrefs == null || sourceKeys == null) + { + return false; + } + for (int i = 0, n = dbrefs.size(); i < n; i++) + { + DBRefEntry dbr = dbrefs.get(i); + String sourceKey = dbr.getSourceKey(); + if (sourceKeys.indexOf(sourceKey) < 0) { + bsSelect.clear(i); + } + } + return !bsSelect.isEmpty(); + } + + /** * isDasCoordinateSystem * @@ -176,13 +208,14 @@ public class DBRefUtils * Set of references to search * @param entry * pattern to match + * @param mode SEARCH_MODE_FULL for all; SEARCH_MODE_NO_MAP_NO_VERSION optional * @return */ - public static List searchRefs(DBRefEntry[] ref, - DBRefEntry entry) + public static List searchRefs(List ref, + DBRefEntry entry, int mode) { return searchRefs(ref, entry, - matchDbAndIdAndEitherMapOrEquivalentMapList); + matchDbAndIdAndEitherMapOrEquivalentMapList, mode); } /** @@ -199,11 +232,26 @@ public class DBRefUtils * accession id to match * @return */ - public static List searchRefs(DBRefEntry[] refs, String accId) + public static List searchRefs(List refs, String accId) { - return searchRefs(refs, new DBRefEntry("", "", accId), matchId); + List rfs = new ArrayList(); + if (refs == null || accId == null) + { + return rfs; + } + for (int i = 0, n = refs.size(); i < n; i++) + { + DBRefEntry e = refs.get(i); + if (accId.equals(e.getAccessionId())) + { + rfs.add(e); + } + } + return rfs; +// return searchRefs(refs, new DBRefEntry("", "", accId), matchId, SEARCH_MODE_FULL); } + /** * Returns a (possibly empty) list of those references that match the given * entry, according to the given comparator. @@ -213,21 +261,23 @@ public class DBRefUtils * @param entry * an entry to compare against * @param comparator + * @param mode SEARCH_MODE_FULL for all; SEARCH_MODE_NO_MAP_NO_VERSION optional * @return */ - static List searchRefs(DBRefEntry[] refs, DBRefEntry entry, - DbRefComp comparator) + static List searchRefs(List refs, DBRefEntry entry, + DbRefComp comparator, int mode) { List rfs = new ArrayList(); if (refs == null || entry == null) { return rfs; } - for (int i = 0; i < refs.length; i++) + for (int i = 0, n = refs.size(); i < n; i++) { - if (comparator.matches(entry, refs[i])) + DBRefEntry e = refs.get(i); + if (comparator.matches(entry, e, SEARCH_MODE_FULL)) { - rfs.add(refs[i]); + rfs.add(e); } } return rfs; @@ -235,8 +285,12 @@ public class DBRefUtils interface DbRefComp { - public boolean matches(DBRefEntry refa, DBRefEntry refb); - } + default public boolean matches(DBRefEntry refa, DBRefEntry refb) { + return matches(refa, refb, SEARCH_MODE_FULL); + }; + + public boolean matches(DBRefEntry refa, DBRefEntry refb, int mode); +} /** * match on all non-null fields in refa @@ -244,20 +298,20 @@ public class DBRefUtils // TODO unused - remove? public static DbRefComp matchNonNullonA = new DbRefComp() { - @Override - public boolean matches(DBRefEntry refa, DBRefEntry refb) + @Override + public boolean matches(DBRefEntry refa, DBRefEntry refb, int mode) { - if (refa.getSource() == null + if ((mode & DB_SOURCE) != 0 && refa.getSource() == null || DBRefUtils.getCanonicalName(refb.getSource()).equals( DBRefUtils.getCanonicalName(refa.getSource()))) { - if (refa.getVersion() == null + if ((mode & DB_VERSION) != 0 && refa.getVersion() == null || refb.getVersion().equals(refa.getVersion())) { - if (refa.getAccessionId() == null + if ((mode & DB_ID) != 0 && refa.getAccessionId() == null || refb.getAccessionId().equals(refa.getAccessionId())) { - if (refa.getMap() == null || (refb.getMap() != null + if ((mode & DB_MAP) != 0 && refa.getMap() == null || (refb.getMap() != null && refb.getMap().equals(refa.getMap()))) { return true; @@ -277,7 +331,7 @@ public class DBRefUtils public static DbRefComp matchEitherNonNull = new DbRefComp() { @Override - public boolean matches(DBRefEntry refa, DBRefEntry refb) + public boolean matches(DBRefEntry refa, DBRefEntry refb, int mode) { if (nullOrEqualSource(refa.getSource(), refb.getSource()) && nullOrEqual(refa.getVersion(), refb.getVersion()) @@ -288,6 +342,7 @@ public class DBRefUtils } return false; } + }; /** @@ -298,7 +353,7 @@ public class DBRefUtils public static DbRefComp matchDbAndIdAndEitherMap = new DbRefComp() { @Override - public boolean matches(DBRefEntry refa, DBRefEntry refb) + public boolean matches(DBRefEntry refa, DBRefEntry refb, int mode) { if (refa.getSource() != null && refb.getSource() != null && DBRefUtils.getCanonicalName(refb.getSource()).equals( @@ -330,7 +385,7 @@ public class DBRefUtils public static DbRefComp matchDbAndIdAndComplementaryMapList = new DbRefComp() { @Override - public boolean matches(DBRefEntry refa, DBRefEntry refb) + public boolean matches(DBRefEntry refa, DBRefEntry refb, int mode) { if (refa.getSource() != null && refb.getSource() != null && DBRefUtils.getCanonicalName(refb.getSource()).equals( @@ -368,7 +423,7 @@ public class DBRefUtils public static DbRefComp matchDbAndIdAndEquivalentMapList = new DbRefComp() { @Override - public boolean matches(DBRefEntry refa, DBRefEntry refb) + public boolean matches(DBRefEntry refa, DBRefEntry refb, int mode) { if (refa.getSource() != null && refb.getSource() != null && DBRefUtils.getCanonicalName(refb.getSource()).equals( @@ -409,7 +464,7 @@ public class DBRefUtils public static DbRefComp matchDbAndIdAndEitherMapOrEquivalentMapList = new DbRefComp() { @Override - public boolean matches(DBRefEntry refa, DBRefEntry refb) + public boolean matches(DBRefEntry refa, DBRefEntry refb, int mode) { if (refa.getSource() != null && refb.getSource() != null && DBRefUtils.getCanonicalName(refb.getSource()).equals( @@ -446,7 +501,7 @@ public class DBRefUtils public static DbRefComp matchId = new DbRefComp() { @Override - public boolean matches(DBRefEntry refa, DBRefEntry refb) + public boolean matches(DBRefEntry refa, DBRefEntry refb, int mode) { if (refa.getAccessionId() != null && refb.getAccessionId() != null && refb.getAccessionId().equals(refa.getAccessionId())) @@ -573,8 +628,8 @@ public class DBRefUtils * a set of references to select from * @return */ - public static DBRefEntry[] selectDbRefs(boolean selectDna, - DBRefEntry[] refs) + public static List selectDbRefs(boolean selectDna, + List refs) { return selectRefs(refs, selectDna ? DBRefSource.DNACODINGDBS : DBRefSource.PROTEINDBS); @@ -591,7 +646,7 @@ public class DBRefUtils * @param source * @return */ - public static List searchRefsForSource(DBRefEntry[] dbRefs, + public static List searchRefsForSource(List dbRefs, String source) { List matches = new ArrayList(); @@ -644,71 +699,87 @@ public class DBRefUtils // nothing to do return; } - List selfs = new ArrayList(); - { - DBRefEntry[] selfArray = selectDbRefs(!sequence.isProtein(), - sequence.getDBRefs()); - if (selfArray == null || selfArray.length == 0) - { - // nothing to do - return; - } - selfs.addAll(Arrays.asList(selfArray)); - } + int sstart = sequence.getStart(); + int send = sequence.getEnd(); + boolean isProtein = sequence.isProtein(); + BitSet bsSelect = new BitSet(); + +// List selfs = new ArrayList(); +// { + +// List selddfs = selectDbRefs(!isprot, sequence.getDBRefs()); +// if (selfs == null || selfs.size() == 0) +// { +// // nothing to do +// return; +// } + + List dbrefs = sequence.getDBRefs(); + bsSelect.set(0, dbrefs.size()); + + if (!selectRefsBS(dbrefs, isProtein ? DBRefSource.PROTEINDBSKEYS : DBRefSource.DNACODINGDBSKEYS, bsSelect)) + return; + +// selfs.addAll(selfArray); +// } // filter non-primary refs - for (DBRefEntry p : pr) + for (int ip = pr.size(); --ip >= 0;) { - while (selfs.contains(p)) - { - selfs.remove(p); + DBRefEntry p = pr.get(ip); + for (int i = bsSelect.nextSetBit(0); i >= 0; i = bsSelect.nextSetBit(i + 1)) { + if (dbrefs.get(i) == p) + bsSelect.clear(i); } +// while (selfs.contains(p)) +// { +// selfs.remove(p); +// } } - List toPromote = new ArrayList(); +// List toPromote = new ArrayList(); - for (DBRefEntry p : pr) + + + for (int ip = pr.size(), keys = 0; --ip >= 0 && keys != DBRefSource.ALL_MASKS;) { - List promType = new ArrayList(); - if (sequence.isProtein()) + DBRefEntry p = pr.get(ip); + if (isProtein) { switch (getCanonicalName(p.getSource())) { case DBRefSource.UNIPROT: - // case DBRefSource.UNIPROTKB: - // case DBRefSource.UP_NAME: - // search for and promote ensembl - promType.add(DBRefSource.ENSEMBL); + keys |= DBRefSource.UNIPROT_MASK; break; case DBRefSource.ENSEMBL: - // search for and promote Uniprot - promType.add(DBRefSource.UNIPROT); + keys |= DBRefSource.ENSEMBL_MASK; break; } } else { - // TODO: promote transcript refs + // TODO: promote transcript refs ?? } - - // collate candidates and promote them - DBRefEntry[] candidates = selectRefs(selfs.toArray(new DBRefEntry[0]), - promType.toArray(new String[0])); - if (candidates != null) + if (keys == 0 || !selectRefsBS(dbrefs, DBRefSource.PROMTYPES[keys], bsSelect)) + return; +// if (candidates != null) { - for (DBRefEntry cand : candidates) + for (int ic = bsSelect.nextSetBit(0); ic >= 0; ic = bsSelect.nextSetBit(ic + 1)) +// for (int ic = 0, n = candidates.size(); ic < n; ic++) { + DBRefEntry cand = dbrefs.get(ic);//candidates.get(ic); if (cand.hasMap()) { - if (cand.getMap().getTo() != null - && cand.getMap().getTo() != sequence) + Mapping map = cand.getMap(); + SequenceI cto = map.getTo(); + if (cto != null + && cto != sequence) { // can't promote refs with mappings to other sequences continue; } - if (cand.getMap().getMap().getFromLowest() != sequence - .getStart() - && cand.getMap().getMap().getFromHighest() != sequence - .getEnd()) + MapList mlist = map.getMap(); + if (mlist.getFromLowest() != sstart + && mlist.getFromHighest() != send) { // can't promote refs with mappings from a region of this sequence // - eg CDS @@ -717,8 +788,9 @@ public class DBRefUtils } // and promote cand.setVersion(p.getVersion() + " (promoted)"); - selfs.remove(cand); - toPromote.add(cand); + bsSelect.clear(ic); + //selfs.remove(cand); +// toPromote.add(cand); if (!cand.isPrimaryCandidate()) { System.out.println( diff --git a/src/jalview/util/Platform.java b/src/jalview/util/Platform.java index 1f03f88..286ded1 100644 --- a/src/jalview/util/Platform.java +++ b/src/jalview/util/Platform.java @@ -219,5 +219,6 @@ public class Platform break; } } + } diff --git a/src/jalview/util/UrlLink.java b/src/jalview/util/UrlLink.java index 007da86..41c3062 100644 --- a/src/jalview/util/UrlLink.java +++ b/src/jalview/util/UrlLink.java @@ -576,17 +576,17 @@ public class UrlLink if (usesDBAccession()) // link is ID { // collect matching db-refs - DBRefEntry[] dbr = DBRefUtils.selectRefs(seq.getDBRefs(), + List dbr = DBRefUtils.selectRefs(seq.getDBRefs(), new String[] { target }); // if there are any dbrefs which match up with the link if (dbr != null) { - for (int r = 0; r < dbr.length; r++) + for (int r = 0, nd = dbr.size(); r < nd; r++) { // create Bare ID link for this URL - createBareURLLink(dbr[r].getAccessionId(), true, linkset); + createBareURLLink(dbr.get(r).getAccessionId(), true, linkset); } } } diff --git a/src/jalview/ws/DBRefFetcher.java b/src/jalview/ws/DBRefFetcher.java index 9a24281..241f443 100644 --- a/src/jalview/ws/DBRefFetcher.java +++ b/src/jalview/ws/DBRefFetcher.java @@ -394,18 +394,19 @@ public class DBRefFetcher implements Runnable && (i < 50); seqIndex++, i++) { SequenceI sequence = dataset[seqIndex]; - DBRefEntry[] uprefs = DBRefUtils + List uprefs = DBRefUtils .selectRefs(sequence.getDBRefs(), new String[] { dbsource.getDbSource() }); // jalview.datamodel.DBRefSource.UNIPROT // }); // check for existing dbrefs to use - if (uprefs != null && uprefs.length > 0) + if (uprefs != null && uprefs.size() > 0) { - for (int j = 0; j < uprefs.length; j++) + for (int j = 0, n = uprefs.size(); j < n; j++) { - addSeqId(sequence, uprefs[j].getAccessionId()); + DBRefEntry upref = uprefs.get(j); + addSeqId(sequence, upref.getAccessionId()); queries.addElement( - uprefs[j].getAccessionId().toUpperCase()); + upref.getAccessionId().toUpperCase()); } } else @@ -532,7 +533,7 @@ public class DBRefFetcher implements Runnable // taking into account all accessionIds and names in the file Vector sequenceMatches = new Vector<>(); // look for corresponding accession ids - DBRefEntry[] entryRefs = DBRefUtils + List entryRefs = DBRefUtils .selectRefs(retrievedSeq.getDBRefs(), new String[] { dbSource }); if (entryRefs == null) @@ -542,9 +543,10 @@ public class DBRefFetcher implements Runnable + dbSource + " on " + retrievedSeq.getName()); continue; } - for (int j = 0; j < entryRefs.length; j++) + for (int j = 0, n = entryRefs.size(); j < n; j++) { - String accessionId = entryRefs[j].getAccessionId(); + DBRefEntry ref = entryRefs.get(j); + String accessionId = ref.getAccessionId(); // match up on accessionId if (seqRefs.containsKey(accessionId.toUpperCase())) { @@ -582,7 +584,7 @@ public class DBRefFetcher implements Runnable // could be useful to extend this so we try to find any 'significant' // information in common between two sequence objects. /* - * DBRefEntry[] entryRefs = + * List entryRefs = * jalview.util.DBRefUtils.selectRefs(entry.getDBRef(), new String[] { * dbSource }); for (int j = 0; j < entry.getName().size(); j++) { String * name = entry.getName().elementAt(j).toString(); if @@ -603,7 +605,7 @@ public class DBRefFetcher implements Runnable // TODO: test for legacy where uniprot or EMBL refs exist but no // mappings are made (but content matches retrieved set) boolean updateRefFrame = sequence.getDBRefs() == null - || sequence.getDBRefs().length == 0; + || sequence.getDBRefs().size() == 0; // TODO: // verify sequence against the entry sequence @@ -783,28 +785,33 @@ public class DBRefFetcher implements Runnable */ private SequenceI[] recoverDbSequences(SequenceI[] sequencesArray) { - Vector nseq = new Vector<>(); - for (int i = 0; sequencesArray != null - && i < sequencesArray.length; i++) + int n; + if (sequencesArray == null || (n = sequencesArray.length) == 0) + return sequencesArray; + ArrayList nseq = new ArrayList<>(); + for (int i = 0;i < n; i++) { - nseq.addElement(sequencesArray[i]); - DBRefEntry[] dbr = sequencesArray[i].getDBRefs(); + nseq.add(sequencesArray[i]); + List dbr = sequencesArray[i].getDBRefs(); Mapping map = null; - for (int r = 0; (dbr != null) && r < dbr.length; r++) + if (dbr != null) { - if ((map = dbr[r].getMap()) != null) + for (int r = 0, rn = dbr.size(); r < rn; r++) { - if (map.getTo() != null && !nseq.contains(map.getTo())) + if ((map = dbr.get(r).getMap()) != null) { - nseq.addElement(map.getTo()); - } + if (map.getTo() != null && !nseq.contains(map.getTo())) + { + nseq.add(map.getTo()); + } + } } } } + // BH 2019.01.25 question here if this is the right logic. Return the original if nothing found? if (nseq.size() > 0) { - sequencesArray = new SequenceI[nseq.size()]; - nseq.toArray(sequencesArray); + return nseq.toArray(new SequenceI[nseq.size()]); } return sequencesArray; } diff --git a/src/jalview/ws/jws2/JabaParamStore.java b/src/jalview/ws/jws2/JabaParamStore.java index 10ec812..5e034cd 100644 --- a/src/jalview/ws/jws2/JabaParamStore.java +++ b/src/jalview/ws/jws2/JabaParamStore.java @@ -98,7 +98,7 @@ public class JabaParamStore implements ParamDatastoreI @Override public List getPresets() { - List prefs = new ArrayList(); + List prefs = new ArrayList<>(); if (servicePresets == null) { servicePresets = new Hashtable(); diff --git a/src/jalview/ws/seqfetcher/ASequenceFetcher.java b/src/jalview/ws/seqfetcher/ASequenceFetcher.java index 9284f82..2a27cce 100644 --- a/src/jalview/ws/seqfetcher/ASequenceFetcher.java +++ b/src/jalview/ws/seqfetcher/ASequenceFetcher.java @@ -205,9 +205,10 @@ public class ASequenceFetcher for (int is = 0; is < seqs.length; is++) { rseqs.addElement(seqs[is]); + // BH 2015.01.25 check about version/accessid being null here List frefs = DBRefUtils.searchRefs( seqs[is].getDBRefs(), - new DBRefEntry(db, null, null)); + new DBRefEntry(db, null, null), DBRefUtils.SEARCH_MODE_FULL); for (DBRefEntry dbr : frefs) { queriesFound.add(dbr.getAccessionId()); diff --git a/src/jalview/ws/utils/UrlDownloadClient.java b/src/jalview/ws/utils/UrlDownloadClient.java index cfe080c..055df15 100644 --- a/src/jalview/ws/utils/UrlDownloadClient.java +++ b/src/jalview/ws/utils/UrlDownloadClient.java @@ -21,6 +21,8 @@ package jalview.ws.utils; +import jalview.util.Platform; + import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileOutputStream; @@ -114,13 +116,14 @@ public class UrlDownloadClient public static void download(String urlstring, File tempFile) throws IOException { - if (/** @j2sNative 1?false: */true) { + // BH 2019.01.25 this said "...getFileAsBytes(..." which cannot work. + // maybe we cannot get here? + if (Platform.isJS()) { + /** @j2sNative + * tempFile._bytes = swingjs.JSUtil.getFileAsBytes$O(urlstring); + */ + } else { download(urlstring, tempFile.toString()); } - // JavaScript only - - /** @j2sNative - * tempFile._bytes = swingjs.JSUtil.getFileAsBytes(urlstring); - */ } } -- 1.7.10.2