From: gmungoc Date: Mon, 18 May 2020 09:59:52 +0000 (+0100) Subject: Merge branch 'Jalview-JS/develop' into develop X-Git-Tag: Release_2_11_4_0~45^2~18 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=65740880573a48adc758bec3939ece9d9ae104dd;p=jalview.git Merge branch 'Jalview-JS/develop' into develop Conflicts: build.gradle src/jalview/gui/PopupMenu.java src/jalview/io/SequenceAnnotationReport.java src/jalview/io/StockholmFile.java src/jalview/util/DBRefUtils.java src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java --- 65740880573a48adc758bec3939ece9d9ae104dd diff --cc src/jalview/gui/IdPanel.java index 3ce9d4d,f53d8b3..4b5e9d4 --- a/src/jalview/gui/IdPanel.java +++ b/src/jalview/gui/IdPanel.java @@@ -20,7 -20,20 +20,9 @@@ */ package jalview.gui; -import jalview.datamodel.AlignmentAnnotation; -import jalview.datamodel.Sequence; -import jalview.datamodel.SequenceGroup; -import jalview.datamodel.SequenceI; -import jalview.gui.SeqPanel.MousePos; -import jalview.io.SequenceAnnotationReport; -import jalview.util.MessageManager; -import jalview.util.Platform; -import jalview.viewmodel.AlignmentViewport; -import jalview.viewmodel.ViewportRanges; - import java.awt.BorderLayout; + import java.awt.event.ActionEvent; + import java.awt.event.ActionListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; @@@ -31,19 -44,9 +33,20 @@@ import java.util.List import javax.swing.JPanel; import javax.swing.JPopupMenu; import javax.swing.SwingUtilities; + import javax.swing.Timer; import javax.swing.ToolTipManager; +import jalview.datamodel.AlignmentAnnotation; +import jalview.datamodel.Sequence; +import jalview.datamodel.SequenceGroup; +import jalview.datamodel.SequenceI; +import jalview.gui.SeqPanel.MousePos; +import jalview.io.SequenceAnnotationReport; +import jalview.util.MessageManager; +import jalview.util.Platform; +import jalview.viewmodel.AlignmentViewport; +import jalview.viewmodel.ViewportRanges; + /** * This panel hosts alignment sequence ids and responds to mouse clicks on them, * as well as highlighting ids matched by a search from the Find menu. diff --cc src/jalview/gui/PopupMenu.java index 568f7f1,8be93a1..2a7fb9f --- a/src/jalview/gui/PopupMenu.java +++ b/src/jalview/gui/PopupMenu.java @@@ -20,31 -20,6 +20,35 @@@ */ package jalview.gui; ++import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.BitSet; +import java.util.Collection; +import java.util.Collections; +import java.util.Hashtable; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.SortedMap; +import java.util.TreeMap; +import java.util.Vector; + +import javax.swing.ButtonGroup; +import javax.swing.JCheckBoxMenuItem; - import javax.swing.JColorChooser; ++import javax.swing.JInternalFrame; ++import javax.swing.JLabel; +import javax.swing.JMenu; +import javax.swing.JMenuItem; ++import javax.swing.JPanel; +import javax.swing.JPopupMenu; +import javax.swing.JRadioButtonMenuItem; ++import javax.swing.JScrollPane; + import jalview.analysis.AAFrequency; import jalview.analysis.AlignmentAnnotationUtils; import jalview.analysis.AlignmentUtils; @@@ -879,22 -873,46 +885,47 @@@ public class PopupMenu extends JPopupMe } /** - * Opens a panel showing a text report of feature dteails - * - * @param seqName + * Opens a panel showing a text report of feature details * * @param sf + * @param seqName + * @param mf */ - protected void showFeatureDetails(String seqName, SequenceFeature sf) + protected void showFeatureDetails(SequenceFeature sf, String seqName, + MappedFeatures mf) { - CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer(); - // it appears Java's CSS does not support border-collapse :-( - cap.addStylesheetRule("table { border-collapse: collapse;}"); - cap.addStylesheetRule("table, td, th {border: 1px solid black;}"); - cap.setText(sf.getDetailsReport(seqName, mf)); - - Desktop.addInternalFrame(cap, + JInternalFrame details; + if (Platform.isJS()) + { + details = new JInternalFrame(); + JPanel panel = new JPanel(new BorderLayout()); + panel.setOpaque(true); + panel.setBackground(Color.white); + // TODO JAL-3026 set style of table correctly for feature details + JLabel reprt = new JLabel(MessageManager + .formatMessage("label.html_content", new Object[] - { sf.getDetailsReport(seqName) })); ++ { sf.getDetailsReport(seqName, mf) })); + reprt.setBackground(Color.WHITE); + reprt.setOpaque(true); + panel.add(reprt, BorderLayout.CENTER); + details.setContentPane(panel); + details.pack(); + } + else + /** + * Java only + * + * @j2sIgnore + */ + { + CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer(); - // it appears Java's CSS does not support border-collaps :-( ++ // it appears Java's CSS does not support border-collapse :-( + cap.addStylesheetRule("table { border-collapse: collapse;}"); + cap.addStylesheetRule("table, td, th {border: 1px solid black;}"); - cap.setText(sf.getDetailsReport(seqName)); ++ cap.setText(sf.getDetailsReport(seqName, mf)); + details = cap; + } + Desktop.addInternalFrame(details, MessageManager.getString("label.feature_details"), 500, 500); } diff --cc src/jalview/gui/SeqPanel.java index d7d4af0,2ad5bea..d22ddd4 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@@ -207,11 -212,23 +212,21 @@@ public class SeqPanel extends JPane StringBuffer keyboardNo2; - java.net.URL linkImageURL; - private final SequenceAnnotationReport seqARep; - StringBuilder tooltipText = new StringBuilder(); + /* + * the last tooltip on mousing over the alignment (or annotation in wrapped mode) + * - the tooltip is not set again if unchanged + * - this is the tooltip text _before_ formatting as html + */ + private String lastTooltip; - String tmpString; + /* + * the last tooltip on mousing over the alignment (or annotation in wrapped mode) + * - used to decide where to place the tooltip in getTooltipLocation() + * - this is the tooltip text _after_ formatting as html + */ + private String lastFormattedTooltip; EditCommand editCommand; diff --cc src/jalview/io/SequenceAnnotationReport.java index 27c1652,9d7fcfc..8e4e783 --- a/src/jalview/io/SequenceAnnotationReport.java +++ b/src/jalview/io/SequenceAnnotationReport.java @@@ -56,11 -55,9 +55,9 @@@ public class SequenceAnnotationRepor private static final int MAX_SOURCES = 40; - // public static final String[][] PRIMARY_SOURCES moved to DBRefSource.java + private static String linkImageURL; - private static final String[][] PRIMARY_SOURCES = new String[][] { - DBRefSource.CODINGDBS, DBRefSource.DNACODINGDBS, - DBRefSource.PROTEINDBS }; - final String linkImageURL; ++ // public static final String[][] PRIMARY_SOURCES moved to DBRefSource.java /* * Comparator to order DBRefEntry by Source + accession id (case-insensitive), @@@ -104,41 -101,25 +101,41 @@@ return comp; } - private boolean isPrimarySource(String source) - { - for (String[] primary : PRIMARY_SOURCES) - { - for (String s : primary) - { - if (source.equals(s)) - { - return true; - } - } - } - return false; - } + // private boolean isPrimarySource(String source) + // { + // for (String[] primary : DBRefSource.PRIMARY_SOURCES) + // { + // for (String s : primary) + // { + // if (source.equals(s)) + // { + // return true; + // } + // } + // } + // return false; + // } }; - public SequenceAnnotationReport(String linkURL) + private boolean forTooltip; + + /** + * Constructor given a flag which affects behaviour + * + * + * @param isForTooltip + */ + public SequenceAnnotationReport(boolean isForTooltip) { - this.linkImageURL = linkURL; + this.forTooltip = isForTooltip; + if (linkImageURL == null) + { + linkImageURL = getClass().getResource("/images/link.gif").toString(); + } } /** diff --cc src/jalview/io/StockholmFile.java index 4697262,84e629e..8b26757 --- a/src/jalview/io/StockholmFile.java +++ b/src/jalview/io/StockholmFile.java @@@ -23,22 -23,20 +23,6 @@@ */ package jalview.io; --import jalview.analysis.Rna; --import jalview.datamodel.AlignmentAnnotation; --import jalview.datamodel.AlignmentI; --import jalview.datamodel.Annotation; --import jalview.datamodel.DBRefEntry; - import jalview.datamodel.DBRefSource; --import jalview.datamodel.Mapping; --import jalview.datamodel.Sequence; --import jalview.datamodel.SequenceFeature; --import jalview.datamodel.SequenceI; --import jalview.schemes.ResidueProperties; --import jalview.util.Comparison; - import jalview.util.DBRefUtils; --import jalview.util.Format; --import jalview.util.MessageManager; -- import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; @@@ -55,6 -53,6 +39,21 @@@ import com.stevesoft.pat.Regex import fr.orsay.lri.varna.exceptions.ExceptionUnmatchedClosingParentheses; import fr.orsay.lri.varna.factories.RNAFactory; import fr.orsay.lri.varna.models.rna.RNA; ++import jalview.analysis.Rna; ++import jalview.datamodel.AlignmentAnnotation; ++import jalview.datamodel.AlignmentI; ++import jalview.datamodel.Annotation; ++import jalview.datamodel.DBRefEntry; ++import jalview.datamodel.DBRefSource; ++import jalview.datamodel.Mapping; ++import jalview.datamodel.Sequence; ++import jalview.datamodel.SequenceFeature; ++import jalview.datamodel.SequenceI; ++import jalview.schemes.ResidueProperties; ++import jalview.util.Comparison; ++import jalview.util.DBRefUtils; ++import jalview.util.Format; ++import jalview.util.MessageManager; // import org.apache.log4j.*; @@@ -954,13 -941,13 +953,14 @@@ public class StockholmFile extends Alig int max = 0; int maxid = 0; int in = 0; - Hashtable dataRef = null; + int slen = s.length; + SequenceI seq; + Hashtable dataRef = null; + boolean isAA = s[in].isProtein(); - while ((in < s.length) && (s[in] != 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) { @@@ -970,31 -959,16 +972,31 @@@ { if (dataRef == null) { - dataRef = new Hashtable(); + dataRef = new Hashtable<>(); } - List primrefs = s[in].getPrimaryDBRefs(); - for (int idb = 0; idb < ndb; idb++) ++ List primrefs = seq.getPrimaryDBRefs(); + if (primrefs.size() >= 1) { - - DBRefEntry ref = seqrefs.get(idb); - String datAs1 = ref.getSource().toString() - + " ; " - + ref.getAccessionId().toString(); - dataRef.put(tmp, datAs1); + dataRef.put(tmp, dbref_to_ac_record(primrefs.get(0))); + } + else + { - for (int idb = 0; idb < s[in].getDBRefs().length; idb++) ++ for (int idb = 0; idb < seq.getDBRefs().size(); idb++) + { - DBRefEntry dbref = s[in].getDBRefs()[idb]; ++ DBRefEntry dbref = seq.getDBRefs().get(idb); + dataRef.put(tmp, dbref_to_ac_record(dbref)); + // if we put in a uniprot or EMBL record then we're done: + if (isAA && DBRefSource.UNIPROT + .equals(DBRefUtils.getCanonicalName(dbref.getSource()))) + { + break; + } + if (!isAA && DBRefSource.EMBL + .equals(DBRefUtils.getCanonicalName(dbref.getSource()))) + { + break; + } + } } } in++; @@@ -1024,11 -998,10 +1026,11 @@@ while (en.hasMoreElements()) { Object idd = en.nextElement(); -- String type = (String) dataRef.remove(idd); ++ String type = dataRef.remove(idd); out.append(new Format("%-" + (maxid - 2) + "s") .form("#=GS " + idd.toString() + " ")); - if (type.contains("PFAM") || type.contains("RFAM")) + if (isAA && type.contains("UNIPROT") + || (!isAA && type.contains("EMBL"))) { out.append(" AC " + type.substring(type.indexOf(";") + 1)); diff --cc src/jalview/util/DBRefUtils.java index 4d5a025,fb54bba..ae0243e --- a/src/jalview/util/DBRefUtils.java +++ b/src/jalview/util/DBRefUtils.java @@@ -20,21 -20,22 +20,21 @@@ */ package jalview.util; --import jalview.datamodel.DBRefEntry; --import jalview.datamodel.DBRefSource; - import jalview.datamodel.PDBEntry; - import jalview.datamodel.SequenceI; - -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 com.stevesoft.pat.Regex; ++import jalview.datamodel.DBRefEntry; ++import jalview.datamodel.DBRefSource; ++import jalview.datamodel.Mapping; ++import jalview.datamodel.PDBEntry; ++import jalview.datamodel.SequenceI; ++ /** * Utilities for handling DBRef objects and their collections. */ @@@ -205,357 -167,265 +166,334 @@@ public class DBRefUtil return rfs; } - interface DbRefComp - { - public boolean matches(DBRefEntry refa, DBRefEntry refb); - } - - /** - * match on all non-null fields in refa - */ - // TODO unused - remove? - public static DbRefComp matchNonNullonA = new DbRefComp() - { - @Override - public boolean matches(DBRefEntry refa, DBRefEntry refb) - { - if (refa.getSource() == null - || DBRefUtils.getCanonicalName(refb.getSource()).equals( - DBRefUtils.getCanonicalName(refa.getSource()))) - { - if (refa.getVersion() == null - || refb.getVersion().equals(refa.getVersion())) - { - if (refa.getAccessionId() == null - || refb.getAccessionId().equals(refa.getAccessionId())) - { - if (refa.getMap() == null || (refb.getMap() != null - && refb.getMap().equals(refa.getMap()))) - { - return true; - } - } - } - } - return false; - } - }; - - /** - * either field is null or field matches for all of source, version, accession - * id and map. - */ - // TODO unused - remove? - public static DbRefComp matchEitherNonNull = new DbRefComp() - { - @Override - public boolean matches(DBRefEntry refa, DBRefEntry refb) - { - if (nullOrEqualSource(refa.getSource(), refb.getSource()) - && nullOrEqual(refa.getVersion(), refb.getVersion()) - && nullOrEqual(refa.getAccessionId(), refb.getAccessionId()) - && nullOrEqual(refa.getMap(), refb.getMap())) - { - return true; - } - return false; - } - }; - - /** - * accession ID and DB must be identical. Version is ignored. Map is either - * not defined or is a match (or is compatible?) - */ - // TODO unused - remove? - public static DbRefComp matchDbAndIdAndEitherMap = new DbRefComp() - { - @Override - public boolean matches(DBRefEntry refa, DBRefEntry refb) - { - if (refa.getSource() != null && refb.getSource() != null - && DBRefUtils.getCanonicalName(refb.getSource()).equals( - DBRefUtils.getCanonicalName(refa.getSource()))) - { - // We dont care about version - if (refa.getAccessionId() != null && refb.getAccessionId() != null - // FIXME should be && not || here? - || refb.getAccessionId().equals(refa.getAccessionId())) - { - if ((refa.getMap() == null || refb.getMap() == null) - || (refa.getMap() != null && refb.getMap() != null - && refb.getMap().equals(refa.getMap()))) - { - return true; - } - } - } - return false; - } - }; - - /** - * accession ID and DB must be identical. Version is ignored. No map on either - * or map but no maplist on either or maplist of map on a is the complement of - * maplist of map on b. - */ - // TODO unused - remove? - public static DbRefComp matchDbAndIdAndComplementaryMapList = new DbRefComp() - { - @Override - public boolean matches(DBRefEntry refa, DBRefEntry refb) - { - if (refa.getSource() != null && refb.getSource() != null - && DBRefUtils.getCanonicalName(refb.getSource()).equals( - DBRefUtils.getCanonicalName(refa.getSource()))) - { - // We dont care about version - if (refa.getAccessionId() != null && refb.getAccessionId() != null - || refb.getAccessionId().equals(refa.getAccessionId())) - { - if ((refa.getMap() == null && refb.getMap() == null) - || (refa.getMap() != null && refb.getMap() != null)) - { - if ((refb.getMap().getMap() == null - && refa.getMap().getMap() == null) - || (refb.getMap().getMap() != null - && refa.getMap().getMap() != null - && refb.getMap().getMap().getInverse() - .equals(refa.getMap().getMap()))) - { - return true; - } - } - } - } - return false; - } - }; - - /** - * accession ID and DB must be identical. Version is ignored. No map on both - * or or map but no maplist on either or maplist of map on a is equivalent to - * the maplist of map on b. - */ - // TODO unused - remove? - public static DbRefComp matchDbAndIdAndEquivalentMapList = new DbRefComp() - { - @Override - public boolean matches(DBRefEntry refa, DBRefEntry refb) - { - if (refa.getSource() != null && refb.getSource() != null - && DBRefUtils.getCanonicalName(refb.getSource()).equals( - DBRefUtils.getCanonicalName(refa.getSource()))) - { - // We dont care about version - // if ((refa.getVersion()==null || refb.getVersion()==null) - // || refb.getVersion().equals(refa.getVersion())) - // { - if (refa.getAccessionId() != null && refb.getAccessionId() != null - || refb.getAccessionId().equals(refa.getAccessionId())) - { - if (refa.getMap() == null && refb.getMap() == null) - { - return true; - } - if (refa.getMap() != null && refb.getMap() != null - && ((refb.getMap().getMap() == null - && refa.getMap().getMap() == null) - || (refb.getMap().getMap() != null - && refa.getMap().getMap() != null - && refb.getMap().getMap() - .equals(refa.getMap().getMap())))) - { - return true; - } - } - } - return false; - } - }; - - /** - * accession ID and DB must be identical, or null on a. Version is ignored. No - * map on either or map but no maplist on either or maplist of map on a is - * equivalent to the maplist of map on b. - */ - public static DbRefComp matchDbAndIdAndEitherMapOrEquivalentMapList = new DbRefComp() - { - @Override - public boolean matches(DBRefEntry refa, DBRefEntry refb) - { - if (refa.getSource() != null && refb.getSource() != null - && DBRefUtils.getCanonicalName(refb.getSource()).equals( - DBRefUtils.getCanonicalName(refa.getSource()))) - { - // We dont care about version - - if (refa.getAccessionId() == null - || refa.getAccessionId().equals(refb.getAccessionId())) - { - if (refa.getMap() == null || refb.getMap() == null) - { - return true; - } - if ((refa.getMap() != null && refb.getMap() != null) - && (refb.getMap().getMap() == null - && refa.getMap().getMap() == null) - || (refb.getMap().getMap() != null - && refa.getMap().getMap() != null - && (refb.getMap().getMap() - .equals(refa.getMap().getMap())))) - { - return true; - } - } - } - return false; - } - }; - - /** - * accession ID only must be identical. - */ - public static DbRefComp matchId = new DbRefComp() - { - @Override - public boolean matches(DBRefEntry refa, DBRefEntry refb) - { - if (refa.getAccessionId() != null && refb.getAccessionId() != null - && refb.getAccessionId().equals(refa.getAccessionId())) - { - return true; - } - return false; - } - }; + /** + * look up source in an internal list of database reference sources and return + * the canonical jalview name for the source, or the original string if it has + * no canonical form. + * + * @param source + * @return canonical jalview source (one of jalview.datamodel.DBRefSource.*) or + * original source + */ + public static String getCanonicalName(String source) + { + if (source == null) + { + return null; + } + String canonical = canonicalSourceNameLookup.get(source.toLowerCase()); + return canonical == null ? source : canonical; + } + + /** + * Returns a (possibly empty) list of those references that match the given + * entry. Currently uses a comparator which matches if + *
    + *
  • database sources are the same
  • + *
  • accession ids are the same
  • + *
  • both have no mapping, or the mappings are the same
  • + *
+ * + * @param ref 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(List ref, DBRefEntry entry, int mode) { + return searchRefs(ref, entry, matchDbAndIdAndEitherMapOrEquivalentMapList, mode); + } + + /** + * Returns a list of those references that match the given accession id + *
    + *
  • database sources are the same
  • + *
  • accession ids are the same
  • + *
  • both have no mapping, or the mappings are the same
  • + *
+ * + * @param refs Set of references to search + * @param accId accession id to match + * @return + */ + public static List searchRefs(List refs, String accId) { + 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. + * + * @param refs an array of database references to search + * @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(List refs, DBRefEntry entry, DbRefComp comparator, int mode) { + List rfs = new ArrayList(); + if (refs == null || entry == null) { + return rfs; + } + for (int i = 0, n = refs.size(); i < n; i++) { + DBRefEntry e = refs.get(i); + if (comparator.matches(entry, e, SEARCH_MODE_FULL)) { + rfs.add(e); + } + } + return rfs; + } + + interface DbRefComp { + 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 + */ + // TODO unused - remove? would be broken by equating "" with null + public static DbRefComp matchNonNullonA = new DbRefComp() { + @Override + public boolean matches(DBRefEntry refa, DBRefEntry refb, int mode) { + if ((mode & DB_SOURCE) != 0 && + (refa.getSource() == null || DBRefUtils.getCanonicalName(refb.getSource()) + .equals(DBRefUtils.getCanonicalName(refa.getSource())))) { + if ((mode & DB_VERSION) != 0 && + (refa.getVersion() == null || refb.getVersion().equals(refa.getVersion()))) { + if ((mode & DB_ID) != 0 && + (refa.getAccessionId() == null || refb.getAccessionId().equals(refa.getAccessionId()))) { + if ((mode & DB_MAP) != 0 && + (refa.getMap() == null || (refb.getMap() != null && refb.getMap().equals(refa.getMap())))) { + return true; + } + } + } + } + return false; + } + }; + + /** + * either field is null or field matches for all of source, version, accession + * id and map. + */ + // TODO unused - remove? + public static DbRefComp matchEitherNonNull = new DbRefComp() { + @Override + public boolean matches(DBRefEntry refa, DBRefEntry refb, int mode) { + if (nullOrEqualSource(refa.getSource(), refb.getSource()) + && nullOrEqual(refa.getVersion(), refb.getVersion()) + && nullOrEqual(refa.getAccessionId(), refb.getAccessionId()) + && nullOrEqual(refa.getMap(), refb.getMap())) { + return true; + } + return false; + } + + }; + /** + * Parses a DBRefEntry and adds it to the sequence, also a PDBEntry if the + * database is PDB. + *

+ * Used by file parsers to generate DBRefs from annotation within file (eg + * Stockholm) + * + * @param dbname + * @param version + * @param acn + * @param seq + * where to annotate with reference + * @return parsed version of entry that was added to seq (if any) + */ + public static DBRefEntry parseToDbRef(SequenceI seq, String dbname, + String version, String acn) + { + DBRefEntry ref = null; + if (dbname != null) + { + String locsrc = DBRefUtils.getCanonicalName(dbname); + if (locsrc.equals(DBRefSource.PDB)) + { + /* + * Check for PFAM style stockhom PDB accession id citation e.g. + * "1WRI A; 7-80;" + */ + Regex r = new com.stevesoft.pat.Regex( + "([0-9][0-9A-Za-z]{3})\\s*(.?)\\s*;\\s*([0-9]+)-([0-9]+)"); + if (r.search(acn.trim())) + { + String pdbid = r.stringMatched(1); + String chaincode = r.stringMatched(2); + if (chaincode == null) + { + chaincode = " "; + } + // String mapstart = r.stringMatched(3); + // String mapend = r.stringMatched(4); + if (chaincode.equals(" ")) + { + chaincode = "_"; + } + // construct pdb ref. + ref = new DBRefEntry(locsrc, version, pdbid + chaincode); + PDBEntry pdbr = new PDBEntry(); + pdbr.setId(pdbid); + pdbr.setType(PDBEntry.Type.PDB); + pdbr.setChainCode(chaincode); + seq.addPDBId(pdbr); + } + else + { + System.err.println("Malformed PDB DR line:" + acn); + } + } + else + { + // default: + ref = new DBRefEntry(locsrc, version, acn.trim()); + } + } + if (ref != null) + { + seq.addDBRef(ref); + } + return ref; + } + - /** - * Returns true if either object is null, or they are equal - * - * @param o1 - * @param o2 - * @return - */ - public static boolean nullOrEqual(Object o1, Object o2) - { - if (o1 == null || o2 == null) - { - return true; - } - return o1.equals(o2); - } - - /** - * canonicalise source string before comparing. null is always wildcard - * - * @param o1 - * - null or source string to compare - * @param o2 - * - null or source string to compare - * @return true if either o1 or o2 are null, or o1 equals o2 under - * DBRefUtils.getCanonicalName - * (o1).equals(DBRefUtils.getCanonicalName(o2)) - */ - public static boolean nullOrEqualSource(String o1, String o2) - { - if (o1 == null || o2 == null) - { - return true; - } - return DBRefUtils.getCanonicalName(o1) - .equals(DBRefUtils.getCanonicalName(o2)); - } - - /** - * Selects just the DNA or protein references from a set of references - * - * @param selectDna - * if true, select references to 'standard' DNA databases, else to - * 'standard' peptide databases - * @param refs - * a set of references to select from - * @return - */ - public static DBRefEntry[] selectDbRefs(boolean selectDna, - DBRefEntry[] refs) - { - return selectRefs(refs, - selectDna ? DBRefSource.DNACODINGDBS : DBRefSource.PROTEINDBS); - // could attempt to find other cross - // refs here - ie PDB xrefs - // (not dna, not protein seq) - } - - /** + /** + * accession ID and DB must be identical. Version is ignored. Map is either not + * defined or is a match (or is compatible?) + */ + // TODO unused - remove? + public static DbRefComp matchDbAndIdAndEitherMap = new DbRefComp() { + @Override + public boolean matches(DBRefEntry refa, DBRefEntry refb, int mode) { + if (refa.getSource() != null && refb.getSource() != null && DBRefUtils.getCanonicalName(refb.getSource()) + .equals(DBRefUtils.getCanonicalName(refa.getSource()))) { + // We dont care about version + if (refa.getAccessionId() != null && refb.getAccessionId() != null + // FIXME should be && not || here? + || refb.getAccessionId().equals(refa.getAccessionId())) { + if ((refa.getMap() == null || refb.getMap() == null) || (refa.getMap() != null + && refb.getMap() != null && refb.getMap().equals(refa.getMap()))) { + return true; + } + } + } + return false; + } + }; + + /** + * accession ID and DB must be identical. Version is ignored. No map on either + * or map but no maplist on either or maplist of map on a is the complement of + * maplist of map on b. + */ + // TODO unused - remove? + public static DbRefComp matchDbAndIdAndComplementaryMapList = new DbRefComp() { + @Override + public boolean matches(DBRefEntry refa, DBRefEntry refb, int mode) { + if (refa.getSource() != null && refb.getSource() != null && DBRefUtils.getCanonicalName(refb.getSource()) + .equals(DBRefUtils.getCanonicalName(refa.getSource()))) { + // We dont care about version + if (refa.getAccessionId() != null && refb.getAccessionId() != null + || refb.getAccessionId().equals(refa.getAccessionId())) { + if ((refa.getMap() == null && refb.getMap() == null) + || (refa.getMap() != null && refb.getMap() != null)) { + if ((refb.getMap().getMap() == null && refa.getMap().getMap() == null) + || (refb.getMap().getMap() != null && refa.getMap().getMap() != null + && refb.getMap().getMap().getInverse().equals(refa.getMap().getMap()))) { + return true; + } + } + } + } + return false; + } + }; + + /** + * accession ID and DB must be identical. Version is ignored. No map on both or + * or map but no maplist on either or maplist of map on a is equivalent to the + * maplist of map on b. + */ + // TODO unused - remove? + public static DbRefComp matchDbAndIdAndEquivalentMapList = new DbRefComp() { + @Override + public boolean matches(DBRefEntry refa, DBRefEntry refb, int mode) { + if (refa.getSource() != null && refb.getSource() != null && DBRefUtils.getCanonicalName(refb.getSource()) + .equals(DBRefUtils.getCanonicalName(refa.getSource()))) { + // We dont care about version + // if ((refa.getVersion()==null || refb.getVersion()==null) + // || refb.getVersion().equals(refa.getVersion())) + // { + if (refa.getAccessionId() != null && refb.getAccessionId() != null + || refb.getAccessionId().equals(refa.getAccessionId())) { + if (refa.getMap() == null && refb.getMap() == null) { + return true; + } + if (refa.getMap() != null && refb.getMap() != null + && ((refb.getMap().getMap() == null && refa.getMap().getMap() == null) + || (refb.getMap().getMap() != null && refa.getMap().getMap() != null + && refb.getMap().getMap().equals(refa.getMap().getMap())))) { + return true; + } + } + } + return false; + } + }; + + /** + * accession ID and DB must be identical, or null on a. Version is ignored. No + * map on either or map but no maplist on either or maplist of map on a is + * equivalent to the maplist of map on b. + */ + public static DbRefComp matchDbAndIdAndEitherMapOrEquivalentMapList = new DbRefComp() + { + @Override + public boolean matches(DBRefEntry refa, DBRefEntry refb, int mode) + { + if (refa.getSource() != null && refb.getSource() != null && DBRefUtils.getCanonicalName(refb.getSource()) + .equals(DBRefUtils.getCanonicalName(refa.getSource()))) + { + // We dont care about version + if (refa.getAccessionId() == null || refa.getAccessionId().equals(refb.getAccessionId())) + { + if (refa.getMap() == null || refb.getMap() == null) + { + return true; + } + if ((refa.getMap() != null && refb.getMap() != null) + && (refb.getMap().getMap() == null && refa.getMap().getMap() == null) + || (refb.getMap().getMap() != null && refa.getMap().getMap() != null + && (refb.getMap().getMap().equals(refa.getMap().getMap())))) + { + return true; + } + } + } + return false; + } + }; + + /** * Returns the (possibly empty) list of those supplied dbrefs which have the * specified source database, with a case-insensitive match of source name * @@@ -580,126 -450,245 +518,191 @@@ return matches; } - /** - * promote direct database references to primary for nucleotide or protein - * sequences if they have an appropriate primary ref - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - *
Seq TypePrimary DBDirect which will be promoted
peptidesEnsemblUniprot
peptidesEnsemblUniprot
dnaEnsemblENA
- * - * @param sequence - */ - public static void ensurePrimaries(SequenceI sequence) - { - List pr = sequence.getPrimaryDBRefs(); - if (pr.size() == 0) - { - // 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)); - } - - // filter non-primary refs - for (DBRefEntry p : pr) - { - while (selfs.contains(p)) - { - selfs.remove(p); - } - } - List toPromote = new ArrayList<>(); - - for (DBRefEntry p : pr) - { - List promType = new ArrayList<>(); - if (sequence.isProtein()) - { - switch (getCanonicalName(p.getSource())) - { - case DBRefSource.UNIPROT: - // case DBRefSource.UNIPROTKB: - // case DBRefSource.UP_NAME: - // search for and promote ensembl - promType.add(DBRefSource.ENSEMBL); - break; - case DBRefSource.ENSEMBL: - // search for and promote Uniprot - promType.add(DBRefSource.UNIPROT); - break; - } - } - else - { - // 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) - { - for (DBRefEntry cand : candidates) - { - if (cand.hasMap()) - { - if (cand.getMap().getTo() != null - && cand.getMap().getTo() != sequence) - { - // can't promote refs with mappings to other sequences - continue; - } - if (cand.getMap().getMap().getFromLowest() != sequence - .getStart() - && cand.getMap().getMap().getFromHighest() != sequence - .getEnd()) - { - // can't promote refs with mappings from a region of this sequence - // - eg CDS - continue; - } - } - // and promote - cand.setVersion(p.getVersion() + " (promoted)"); - selfs.remove(cand); - toPromote.add(cand); - if (!cand.isPrimaryCandidate()) - { - System.out.println( - "Warning: Couldn't promote dbref " + cand.toString() - + " for sequence " + sequence.toString()); - } - } - } - } - } + /** - * Parses a DBRefEntry and adds it to the sequence, also a PDBEntry if the - * database is PDB. - *

- * Used by file parsers to generate DBRefs from annotation within file (eg - * Stockholm) - * - * @param dbname - * @param version - * @param acn - * @param seq where to annotate with reference - * @return parsed version of entry that was added to seq (if any) - */ - public static DBRefEntry parseToDbRef(SequenceI seq, String dbname, String version, String acn) { - DBRefEntry ref = null; - if (dbname != null) { - String locsrc = DBRefUtils.getCanonicalName(dbname); - if (locsrc.equals(DBRefSource.PDB)) { - /* - * Check for PFAM style stockhom PDB accession id citation e.g. "1WRI A; 7-80;" - */ - Regex r = new com.stevesoft.pat.Regex("([0-9][0-9A-Za-z]{3})\\s*(.?)\\s*;\\s*([0-9]+)-([0-9]+)"); - if (r.search(acn.trim())) { - String pdbid = r.stringMatched(1); - String chaincode = r.stringMatched(2); - if (chaincode == null) { - chaincode = " "; - } - // String mapstart = r.stringMatched(3); - // String mapend = r.stringMatched(4); - if (chaincode.equals(" ")) { - chaincode = "_"; - } - // construct pdb ref. - ref = new DBRefEntry(locsrc, version, pdbid + chaincode); - PDBEntry pdbr = new PDBEntry(); - pdbr.setId(pdbid); - pdbr.setType(PDBEntry.Type.PDB); - pdbr.setChainCode(chaincode); - seq.addPDBId(pdbr); - } else { - System.err.println("Malformed PDB DR line:" + acn); - } - } else { - // default: - ref = new DBRefEntry(locsrc, version, acn); - } - } - if (ref != null) { - seq.addDBRef(ref); - } - return ref; - } - - /** + * Returns true if either object is null, or they are equal + * + * @param o1 + * @param o2 + * @return + */ + public static boolean nullOrEqual(Object o1, Object o2) { + if (o1 == null || o2 == null) { + return true; + } + return o1.equals(o2); + } + + /** + * canonicalise source string before comparing. null is always wildcard + * + * @param o1 - null or source string to compare + * @param o2 - null or source string to compare + * @return true if either o1 or o2 are null, or o1 equals o2 under + * DBRefUtils.getCanonicalName + * (o1).equals(DBRefUtils.getCanonicalName(o2)) + */ + public static boolean nullOrEqualSource(String o1, String o2) { + if (o1 == null || o2 == null) { + return true; + } + return DBRefUtils.getCanonicalName(o1).equals(DBRefUtils.getCanonicalName(o2)); + } + + /** + * Selects just the DNA or protein references from a set of references + * + * @param selectDna if true, select references to 'standard' DNA databases, else + * to 'standard' peptide databases + * @param refs a set of references to select from + * @return + */ + public static List selectDbRefs(boolean selectDna, List refs) { + return selectRefs(refs, selectDna ? DBRefSource.DNACODINGDBS : DBRefSource.PROTEINDBS); + // could attempt to find other cross + // refs here - ie PDB xrefs + // (not dna, not protein seq) + } + + /** + * Returns the (possibly empty) list of those supplied dbrefs which have the + * specified source database, with a case-insensitive match of source name + * + * @param dbRefs + * @param source + * @return + */ + public static List searchRefsForSource(List dbRefs, String source) { + List matches = new ArrayList(); + if (dbRefs != null && source != null) { + for (DBRefEntry dbref : dbRefs) { + if (source.equalsIgnoreCase(dbref.getSource())) { + matches.add(dbref); + } + } + } + return matches; + } + + /** + * promote direct database references to primary for nucleotide or protein + * sequences if they have an appropriate primary ref + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
Seq TypePrimary DBDirect which will be promoted
peptidesEnsemblUniprot
peptidesEnsemblUniprot
dnaEnsemblENA
+ * + * @param sequence + */ + public static void ensurePrimaries(SequenceI sequence, List pr) { + if (pr.size() == 0) { + // nothing to do + return; + } + 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.PROTEIN_MASK : DBRefSource.DNA_CODING_MASK, bsSelect)) + return; + + // selfs.addAll(selfArray); + // } + + // filter non-primary refs + for (int ip = pr.size(); --ip >= 0;) { + 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(); + + for (int ip = pr.size(), keys = 0; --ip >= 0 && keys != DBRefSource.PRIMARY_MASK;) { + DBRefEntry p = pr.get(ip); + if (isProtein) { + switch (getCanonicalName(p.getSource())) { + case DBRefSource.UNIPROT: + keys |= DBRefSource.UNIPROT_MASK; + break; + case DBRefSource.ENSEMBL: + keys |= DBRefSource.ENSEMBL_MASK; + break; + } + } else { + // TODO: promote transcript refs ?? + } + if (keys == 0 || !selectRefsBS(dbrefs, keys, bsSelect)) + return; + // if (candidates != null) + { + 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()) { + Mapping map = cand.getMap(); + SequenceI cto = map.getTo(); + if (cto != null && cto != sequence) { + // can't promote refs with mappings to other sequences + continue; + } + 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 + continue; + } + } + // and promote - not that version must be non-null here, + // as p must have passed isPrimaryCandidate() + cand.setVersion(p.getVersion() + " (promoted)"); + bsSelect.clear(ic); + // selfs.remove(cand); + // toPromote.add(cand); + if (!cand.isPrimaryCandidate()) { + System.out.println("Warning: Couldn't promote dbref " + cand.toString() + " for sequence " + + sequence.toString()); + } + } + } + } + } } diff --cc src/jalview/util/JSONUtils.java index eec78f9,dde1662..7a5fb15 --- a/src/jalview/util/JSONUtils.java +++ b/src/jalview/util/JSONUtils.java @@@ -1,26 -1,10 +1,30 @@@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ package jalview.util; - import org.json.simple.JSONArray; + import java.io.IOException; + import java.io.Reader; + import java.util.List; + + import org.json.simple.parser.ParseException; public class JSONUtils { diff --cc src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java index 426ec1f,68345b9..3608626 --- a/src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java +++ b/src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java @@@ -1161,9 -1171,36 +1171,36 @@@ public abstract class FeatureRendererMo return filter == null ? true : filter.matches(sf); } + /** + * Answers true unless the specified group is set to hidden. Defaults to true + * if group visibility is not set. + * + * @param group + * @return + */ + public boolean isGroupVisible(String group) + { + if (!featureGroups.containsKey(group)) + { + return true; + } + return featureGroups.get(group); + } + + /** + * Orders features in render precedence (last in order is last to render, so + * displayed on top of other features) + * + * @param order + */ + public void orderFeatures(Comparator order) + { + Arrays.sort(renderOrder, order); + } + @Override - public MappedFeatures findComplementFeaturesAtResidue(SequenceI sequence, - int pos) + public MappedFeatures findComplementFeaturesAtResidue( + final SequenceI sequence, final int pos) { SequenceI ds = sequence.getDatasetSequence(); if (ds == null)