From f3392c352962c6827674ada5948500725e4eed1e Mon Sep 17 00:00:00 2001 From: tcofoegbu Date: Wed, 23 Mar 2016 18:06:46 +0000 Subject: [PATCH] JAL-2009 added programmatic custom feature setting to show insertion position for PDB sequences fetched via SequenceFetcher, Paste and File (url, drag'n'drop, File dialog) --- src/jalview/api/AlignViewportI.java | 2 + src/jalview/appletgui/AlignViewport.java | 19 +++++++++ src/jalview/bin/Cache.java | 4 +- src/jalview/gui/CutAndPasteTransfer.java | 13 +++++- src/jalview/gui/Desktop.java | 7 ---- src/jalview/io/FileLoader.java | 13 +++++- src/jalview/io/FileParse.java | 12 ++++++ src/jalview/io/HtmlFile.java | 20 ++++++++++ src/jalview/io/JSONFile.java | 21 ++++++++++ src/jalview/io/PDBFeatureSettings.java | 63 ++++++++++++++++++++++++++++++ src/jalview/io/StructureFile.java | 16 ++++++++ src/jalview/ws/dbsources/Pdb.java | 21 ++++++++++ 12 files changed, 200 insertions(+), 11 deletions(-) create mode 100644 src/jalview/io/PDBFeatureSettings.java diff --git a/src/jalview/api/AlignViewportI.java b/src/jalview/api/AlignViewportI.java index 5df38d6..45e77ba 100644 --- a/src/jalview/api/AlignViewportI.java +++ b/src/jalview/api/AlignViewportI.java @@ -375,4 +375,6 @@ public interface AlignViewportI extends ViewStyleI * Set whether view should scroll to show the highlighted region of a sequence */ void setFollowHighlight(boolean b); + + public void applyFeaturesStyle(FeatureSettingsModelI featureSettings); } diff --git a/src/jalview/appletgui/AlignViewport.java b/src/jalview/appletgui/AlignViewport.java index 7ef2d59..09e6562 100644 --- a/src/jalview/appletgui/AlignViewport.java +++ b/src/jalview/appletgui/AlignViewport.java @@ -22,6 +22,7 @@ package jalview.appletgui; import jalview.analysis.NJTree; import jalview.api.AlignViewportI; +import jalview.api.FeatureSettingsModelI; import jalview.bin.JalviewLite; import jalview.commands.CommandI; import jalview.datamodel.AlignmentI; @@ -57,6 +58,7 @@ public class AlignViewport extends AlignmentViewport implements private AnnotationColumnChooser annotationColumnSelectionState; + @Override public void finalize() { applet = null; @@ -325,6 +327,7 @@ public class AlignViewport extends AlignmentViewport implements return followSelection; } + @Override public void sendSelection() { getStructureSelectionManager().sendSelection( @@ -378,6 +381,7 @@ public class AlignViewport extends AlignmentViewport implements } } + @Override public boolean isNormaliseSequenceLogo() { return normaliseSequenceLogo; @@ -392,6 +396,7 @@ public class AlignViewport extends AlignmentViewport implements * * @return true if alignment characters should be displayed */ + @Override public boolean isValidCharWidth() { return validCharWidth; @@ -470,4 +475,18 @@ public class AlignViewport extends AlignmentViewport implements } } + /** + * Applies the supplied feature settings descriptor to currently known + * features. This supports an 'initial configuration' of feature colouring + * based on a preset or user favourite. This may then be modified in the usual + * way using the Feature Settings dialogue. + * + * @param featureSettings + */ + @Override + public void applyFeaturesStyle(FeatureSettingsModelI featureSettings) + { + // TODO implement for applet + } + } diff --git a/src/jalview/bin/Cache.java b/src/jalview/bin/Cache.java index ebc2c21..cd875c9 100755 --- a/src/jalview/bin/Cache.java +++ b/src/jalview/bin/Cache.java @@ -228,7 +228,7 @@ public class Cache private final static String DEFAULT_FAIL_SAFE_PID_THRESHOLD = "30"; - private final static String DEFAULT_STRUCTURE_FOMART = DBRefSource.MMCIF; + private final static String DEFAULT_STRUCTURE_FORMAT = DBRefSource.MMCIF; /** * Initialises the Jalview Application Log @@ -427,7 +427,7 @@ public class Cache .println("Jalview Version: " + codeVersion + codeInstallation); Pdb.setCurrentDefaultFomart(jalview.bin.Cache.getDefault( - "DEFAULT_STRUCTURE_FOMART", DEFAULT_STRUCTURE_FOMART)); + "DEFAULT_STRUCTURE_FORMAT", DEFAULT_STRUCTURE_FORMAT)); // jnlpVersion will be null if we're using InstallAnywhere // Dont do this check if running in headless mode if (jnlpVersion == null diff --git a/src/jalview/gui/CutAndPasteTransfer.java b/src/jalview/gui/CutAndPasteTransfer.java index c0e59a4..76f1041 100644 --- a/src/jalview/gui/CutAndPasteTransfer.java +++ b/src/jalview/gui/CutAndPasteTransfer.java @@ -23,6 +23,7 @@ package jalview.gui; import jalview.api.AlignViewportI; import jalview.api.AlignmentViewPanel; import jalview.api.ComplexAlignFile; +import jalview.api.FeatureSettingsModelI; import jalview.api.FeaturesDisplayedI; import jalview.api.FeaturesSourceI; import jalview.bin.Jalview; @@ -253,12 +254,19 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer { String title = MessageManager.formatMessage( "label.input_cut_paste_params", new String[] { format }); + FeatureSettingsModelI proxyColourScheme = source + .getFeatureColourScheme(); + /* * if the view panel was closed its alignment is nulled * and this is an orphaned cut and paste window */ if (viewport != null && viewport.getAlignment() != null) { + if (proxyColourScheme != null) + { + viewport.applyFeaturesStyle(proxyColourScheme); + } ((AlignViewport) viewport).addAlignment(al, title); } else @@ -297,7 +305,10 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer af.getViewport().setShowSequenceFeatures(true); } } - + if (proxyColourScheme != null) + { + af.getViewport().applyFeaturesStyle(proxyColourScheme); + } af.currentFileFormat = format; Desktop.addInternalFrame(af, title, AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT); diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index 8f0d210..27f60ea 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -1065,13 +1065,6 @@ public class Desktop extends jalview.jbgui.GDesktop implements { new FileLoader().LoadFile(viewport, choice, FormatAdapter.FILE, format); - // viewport.setShowSequenceFeatures(JSONFile.isSeqFeaturesEnabled()); - // AlignFrame af = viewport.getAlignPanel().alignFrame; - // if (af != null) - // { - // af.changeColour(JSONFile.getColourScheme()); - // af.setMenusForViewport(); - // } } else { diff --git a/src/jalview/io/FileLoader.java b/src/jalview/io/FileLoader.java index b1944b4..b449d19 100755 --- a/src/jalview/io/FileLoader.java +++ b/src/jalview/io/FileLoader.java @@ -21,6 +21,7 @@ package jalview.io; import jalview.api.ComplexAlignFile; +import jalview.api.FeatureSettingsModelI; import jalview.api.FeaturesDisplayedI; import jalview.api.FeaturesSourceI; import jalview.bin.Jalview; @@ -362,8 +363,14 @@ public class FileLoader implements Runnable } } + FeatureSettingsModelI proxyColourScheme = source + .getFeatureColourScheme(); if (viewport != null) { + if (proxyColourScheme != null) + { + viewport.applyFeaturesStyle(proxyColourScheme); + } // append to existing alignment viewport.addAlignment(al, title); } @@ -407,7 +414,11 @@ public class FileLoader implements Runnable { alignFrame.setFileName(file, format); } - + if (proxyColourScheme != null) + { + alignFrame.getViewport() + .applyFeaturesStyle(proxyColourScheme); + } alignFrame.statusBar.setText(MessageManager.formatMessage( "label.successfully_loaded_file", new String[] { title })); diff --git a/src/jalview/io/FileParse.java b/src/jalview/io/FileParse.java index 61f5127..fddb565 100755 --- a/src/jalview/io/FileParse.java +++ b/src/jalview/io/FileParse.java @@ -23,6 +23,7 @@ package jalview.io; import jalview.api.AlignExportSettingI; import jalview.api.AlignViewportI; import jalview.api.AlignmentViewPanel; +import jalview.api.FeatureSettingsModelI; import jalview.util.MessageManager; import java.io.BufferedReader; @@ -613,4 +614,15 @@ public class FileParse } // could also set export/import settings } + + /** + * Returns the preferred feature colour configuration if there is one, else + * null + * + * @return + */ + public FeatureSettingsModelI getFeatureColourScheme() + { + return null; + } } diff --git a/src/jalview/io/HtmlFile.java b/src/jalview/io/HtmlFile.java index 954d12e..e31e78d 100644 --- a/src/jalview/io/HtmlFile.java +++ b/src/jalview/io/HtmlFile.java @@ -22,6 +22,7 @@ package jalview.io; import jalview.api.ComplexAlignFile; +import jalview.api.FeatureSettingsModelI; import jalview.api.FeaturesDisplayedI; import jalview.datamodel.ColumnSelection; import jalview.datamodel.SequenceI; @@ -124,6 +125,7 @@ public class HtmlFile extends AlignFile implements ComplexAlignFile "Print method of HtmlFile is not supported!"); } + @Override public boolean isShowSeqFeatures() { return showSeqFeatures; @@ -134,6 +136,7 @@ public class HtmlFile extends AlignFile implements ComplexAlignFile this.showSeqFeatures = showSeqFeatures; } + @Override public String getGlobalColourScheme() { return globalColourScheme; @@ -144,6 +147,7 @@ public class HtmlFile extends AlignFile implements ComplexAlignFile this.globalColourScheme = globalColourScheme; } + @Override public ColumnSelection getColumnSelection() { return columnSelection; @@ -154,6 +158,7 @@ public class HtmlFile extends AlignFile implements ComplexAlignFile this.columnSelection = columnSelection; } + @Override public SequenceI[] getHiddenSequences() { return hiddenSequences; @@ -170,4 +175,19 @@ public class HtmlFile extends AlignFile implements ComplexAlignFile return displayedFeatures; } + /** + * Returns a descriptor for suitable feature display settings with + * + */ + @Override + public FeatureSettingsModelI getFeatureColourScheme() + { + return new PDBFeatureSettings(); + } + } diff --git a/src/jalview/io/JSONFile.java b/src/jalview/io/JSONFile.java index 1038925..36980f8 100644 --- a/src/jalview/io/JSONFile.java +++ b/src/jalview/io/JSONFile.java @@ -26,6 +26,7 @@ import jalview.api.AlignViewportI; import jalview.api.AlignmentViewPanel; import jalview.api.ComplexAlignFile; import jalview.api.FeatureRenderer; +import jalview.api.FeatureSettingsModelI; import jalview.api.FeaturesDisplayedI; import jalview.bin.BuildDetails; import jalview.datamodel.AlignmentAnnotation; @@ -709,6 +710,7 @@ public class JSONFile extends AlignFile implements ComplexAlignFile } } + @Override public String getGlobalColourScheme() { return globalColourScheme; @@ -730,6 +732,7 @@ public class JSONFile extends AlignFile implements ComplexAlignFile this.displayedFeatures = displayedFeatures; } + @Override public void configureForView(AlignmentViewPanel avpanel) { super.configureForView(avpanel); @@ -755,6 +758,7 @@ public class JSONFile extends AlignFile implements ComplexAlignFile } + @Override public boolean isShowSeqFeatures() { return showSeqFeatures; @@ -775,6 +779,7 @@ public class JSONFile extends AlignFile implements ComplexAlignFile return hiddenColumns; } + @Override public ColumnSelection getColumnSelection() { return columnSelection; @@ -785,6 +790,7 @@ public class JSONFile extends AlignFile implements ComplexAlignFile this.columnSelection = columnSelection; } + @Override public SequenceI[] getHiddenSequences() { if (hiddenSequences == null || hiddenSequences.isEmpty()) @@ -864,4 +870,19 @@ public class JSONFile extends AlignFile implements ComplexAlignFile this.exportJalviewSettings = exportJalviewSettings; } } + + /** + * Returns a descriptor for suitable feature display settings with + * + */ + @Override + public FeatureSettingsModelI getFeatureColourScheme() + { + return new PDBFeatureSettings(); + } } diff --git a/src/jalview/io/PDBFeatureSettings.java b/src/jalview/io/PDBFeatureSettings.java new file mode 100644 index 0000000..a422a00 --- /dev/null +++ b/src/jalview/io/PDBFeatureSettings.java @@ -0,0 +1,63 @@ +package jalview.io; + +import jalview.api.FeatureColourI; +import jalview.schemes.FeatureColourAdapter; +import jalview.schemes.FeatureSettingsAdapter; +import jalview.ws.dbsources.Pdb; + +import java.awt.Color; + +public class PDBFeatureSettings extends FeatureSettingsAdapter +{ + + @Override + public boolean isFeatureDisplayed(String type) + { + return type.equalsIgnoreCase(Pdb.FEATURE_INSERTION) + || type.equalsIgnoreCase(Pdb.FEATURE_RES_NUM); + } + + @Override + public FeatureColourI getFeatureColour(String type) + { + if (type.equalsIgnoreCase(Pdb.FEATURE_INSERTION)) + { + return new FeatureColourAdapter() + { + + @Override + public Color getColour() + { + return Color.RED; + } + }; + } + return null; + } + + /** + * Order to render insertion after ResNum + */ + @Override + public int compare(String feature1, String feature2) + { + if (feature1.equalsIgnoreCase(Pdb.FEATURE_INSERTION)) + { + return +1; + } + if (feature2.equalsIgnoreCase(Pdb.FEATURE_INSERTION)) + { + return -1; + } + if (feature1.equalsIgnoreCase(Pdb.FEATURE_RES_NUM)) + { + return +1; + } + if (feature2.equalsIgnoreCase(Pdb.FEATURE_RES_NUM)) + { + return -1; + } + return 0; + } +} + diff --git a/src/jalview/io/StructureFile.java b/src/jalview/io/StructureFile.java index 7262443..fd488f0 100644 --- a/src/jalview/io/StructureFile.java +++ b/src/jalview/io/StructureFile.java @@ -1,6 +1,7 @@ package jalview.io; import jalview.analysis.AlignSeq; +import jalview.api.FeatureSettingsModelI; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; @@ -397,4 +398,19 @@ public abstract class StructureFile extends AlignFile { this.dbRefType = dbRefType; } + + /** + * Returns a descriptor for suitable feature display settings with + * + */ + @Override + public FeatureSettingsModelI getFeatureColourScheme() + { + return new PDBFeatureSettings(); + } } diff --git a/src/jalview/ws/dbsources/Pdb.java b/src/jalview/ws/dbsources/Pdb.java index 358c838..2421b82 100644 --- a/src/jalview/ws/dbsources/Pdb.java +++ b/src/jalview/ws/dbsources/Pdb.java @@ -20,6 +20,7 @@ */ package jalview.ws.dbsources; +import jalview.api.FeatureSettingsModelI; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; import jalview.datamodel.DBRefEntry; @@ -27,6 +28,7 @@ import jalview.datamodel.DBRefSource; import jalview.datamodel.PDBEntry; import jalview.datamodel.SequenceI; import jalview.io.FormatAdapter; +import jalview.io.PDBFeatureSettings; import jalview.util.MessageManager; import jalview.ws.ebi.EBIFetchClient; @@ -47,6 +49,10 @@ public class Pdb extends EbiFileRetrievedProxy super(); } + public static final String FEATURE_INSERTION = "INSERTION"; + + public static final String FEATURE_RES_NUM = "RESNUM"; + private static String currentDefaultFomart = DBRefSource.MMCIF; /* @@ -266,4 +272,19 @@ public class Pdb extends EbiFileRetrievedProxy { Pdb.currentDefaultFomart = currentDefaultFomart; } + + /** + * Returns a descriptor for suitable feature display settings with + * + */ + @Override + public FeatureSettingsModelI getFeatureColourScheme() + { + return new PDBFeatureSettings(); + } } -- 1.7.10.2