JAL-3130 Merge of JAL-3130_Java_11_investigations-Ben-2 and updated develop
authorBen Soares <bsoares@dundee.ac.uk>
Tue, 19 Mar 2019 14:58:52 +0000 (14:58 +0000)
committerBen Soares <bsoares@dundee.ac.uk>
Tue, 19 Mar 2019 14:58:52 +0000 (14:58 +0000)
293 files changed:
.ant-targets-build.xml
.classpath
.gitignore
THIRDPARTYLIBS
authors.props [new file with mode: 0644]
build-j11.xml
examples/backupfilestest.fa [new file with mode: 0644]
examples/groovy/colourConserved.groovy
examples/groovy/colourSchemes.groovy
examples/groovy/colourUnconserved.groovy
examples/testdata/projects/manyViews.jvp [new file with mode: 0644]
examples/testdata/projects/twoViews.jvp [new file with mode: 0644]
help/help.jhm
help/html/calculations/pca.html
help/html/calculations/treeviewer.html
help/html/colourSchemes/index.html
help/html/features/das.gif [deleted file]
help/html/features/exportannot.gif [deleted file]
help/html/features/pdbsequencefetcher.html
help/html/features/preferences.html
help/html/features/search.gif [deleted file]
help/html/features/uniprotsequencefetcher.html
help/html/menus/alignmentMenu.html
help/html/menus/alwcolour.html
help/html/releases.html
lib/intervalstore-src-v0.4.jar [new file with mode: 0644]
lib/intervalstore-v0.4.jar [new file with mode: 0644]
lib/spring-core-3.0.5.RELEASE.jar [deleted file]
lib/spring-web-3.0.5.RELEASE.jar [deleted file]
resources/AmbiguityCodes.dat [new file with mode: 0644]
resources/GeneticCodes.dat [new file with mode: 0644]
resources/lang/Messages.properties
resources/lang/Messages_es.properties
schemas/jalview.xsd
src/jalview/analysis/AlignmentUtils.java
src/jalview/analysis/Dna.java
src/jalview/analysis/Finder.java
src/jalview/analysis/GeneticCodeI.java [new file with mode: 0644]
src/jalview/analysis/GeneticCodes.java [new file with mode: 0644]
src/jalview/analysis/PCA.java
src/jalview/analysis/scoremodels/PIDModel.java
src/jalview/analysis/scoremodels/ScoreMatrix.java
src/jalview/analysis/scoremodels/ScoreModels.java
src/jalview/analysis/scoremodels/SimilarityParams.java
src/jalview/api/AlignViewportI.java
src/jalview/api/FeatureColourI.java
src/jalview/api/FeatureRenderer.java
src/jalview/api/FinderI.java [new file with mode: 0644]
src/jalview/api/RotatableCanvasI.java
src/jalview/appletgui/AlignFrame.java
src/jalview/appletgui/AlignViewport.java
src/jalview/appletgui/AlignmentPanel.java
src/jalview/appletgui/AppletJmolBinding.java
src/jalview/appletgui/ExtJmol.java
src/jalview/appletgui/FeatureColourChooser.java
src/jalview/appletgui/Finder.java
src/jalview/appletgui/IdCanvas.java
src/jalview/appletgui/IdPanel.java
src/jalview/appletgui/OverviewCanvas.java
src/jalview/appletgui/OverviewPanel.java
src/jalview/appletgui/PCAPanel.java
src/jalview/appletgui/RotatableCanvas.java
src/jalview/appletgui/SeqCanvas.java
src/jalview/appletgui/TreeCanvas.java
src/jalview/bin/Cache.java
src/jalview/bin/Jalview.java
src/jalview/commands/EditCommand.java
src/jalview/controller/AlignViewController.java
src/jalview/datamodel/Alignment.java
src/jalview/datamodel/AlignmentI.java
src/jalview/datamodel/AlignmentView.java
src/jalview/datamodel/ColumnSelection.java
src/jalview/datamodel/HiddenColumns.java
src/jalview/datamodel/Point.java [new file with mode: 0644]
src/jalview/datamodel/SearchResultMatchI.java
src/jalview/datamodel/SearchResults.java
src/jalview/datamodel/SearchResultsI.java
src/jalview/datamodel/Sequence.java
src/jalview/datamodel/SequenceCollectionI.java
src/jalview/datamodel/SequenceGroup.java
src/jalview/datamodel/SequenceI.java
src/jalview/datamodel/SequencePoint.java
src/jalview/datamodel/features/FeatureLocationI.java
src/jalview/datamodel/features/FeatureStore.java
src/jalview/datamodel/features/NCList.java [deleted file]
src/jalview/datamodel/features/NCNode.java [deleted file]
src/jalview/datamodel/features/RangeComparator.java [deleted file]
src/jalview/datamodel/features/SequenceFeatures.java
src/jalview/datamodel/features/SequenceFeaturesI.java
src/jalview/ext/ensembl/EnsemblCdna.java
src/jalview/ext/ensembl/EnsemblCds.java
src/jalview/ext/ensembl/EnsemblFeatures.java
src/jalview/ext/ensembl/EnsemblGene.java
src/jalview/ext/ensembl/EnsemblGenome.java
src/jalview/ext/ensembl/EnsemblRestClient.java
src/jalview/ext/ensembl/EnsemblSeqProxy.java
src/jalview/ext/ensembl/EnsemblSequenceFetcher.java
src/jalview/ext/jmol/JalviewJmolBinding.java
src/jalview/fts/core/GFTSPanel.java
src/jalview/fts/service/pdb/PDBFTSPanel.java
src/jalview/fts/service/uniprot/UniprotFTSPanel.java
src/jalview/gui/AlignFrame.java
src/jalview/gui/AlignViewport.java
src/jalview/gui/AlignmentPanel.java
src/jalview/gui/AnnotationChooser.java
src/jalview/gui/AnnotationColourChooser.java
src/jalview/gui/AnnotationColumnChooser.java
src/jalview/gui/AnnotationExporter.java
src/jalview/gui/AnnotationLabels.java
src/jalview/gui/AnnotationPanel.java
src/jalview/gui/CalculationChooser.java
src/jalview/gui/ColourMenuHelper.java
src/jalview/gui/CutAndPasteTransfer.java
src/jalview/gui/Desktop.java
src/jalview/gui/FeatureSettings.java
src/jalview/gui/FeatureTypeSettings.java
src/jalview/gui/Finder.java
src/jalview/gui/Help.java
src/jalview/gui/IdCanvas.java
src/jalview/gui/IdPanel.java
src/jalview/gui/JalviewBooleanRadioButtons.java [new file with mode: 0644]
src/jalview/gui/OverviewCanvas.java
src/jalview/gui/OverviewPanel.java
src/jalview/gui/PCAPanel.java
src/jalview/gui/PopupMenu.java
src/jalview/gui/Preferences.java
src/jalview/gui/RotatableCanvas.java
src/jalview/gui/ScalePanel.java
src/jalview/gui/SeqCanvas.java
src/jalview/gui/SeqPanel.java
src/jalview/gui/SequenceFetcher.java
src/jalview/gui/SliderPanel.java
src/jalview/gui/StructureViewerBase.java
src/jalview/gui/TreeCanvas.java
src/jalview/gui/TreePanel.java
src/jalview/io/AnnotationFile.java
src/jalview/io/BackupFilenameFilter.java [new file with mode: 0644]
src/jalview/io/BackupFilenameParts.java [new file with mode: 0644]
src/jalview/io/BackupFiles.java [new file with mode: 0644]
src/jalview/io/FeaturesFile.java
src/jalview/io/FileLoader.java
src/jalview/io/JalviewFileChooser.java
src/jalview/io/JalviewFileFilter.java
src/jalview/io/JalviewFileView.java
src/jalview/io/vcf/VCFLoader.java
src/jalview/jbgui/GAlignFrame.java
src/jalview/jbgui/GDasSourceBrowser.java [deleted file]
src/jalview/jbgui/GDesktop.java
src/jalview/jbgui/GFinder.java
src/jalview/jbgui/GPCAPanel.java
src/jalview/jbgui/GPreferences.java
src/jalview/jbgui/GWsPreferences.java
src/jalview/math/Matrix.java
src/jalview/math/MatrixI.java
src/jalview/math/RotatableMatrix.java
src/jalview/math/SparseMatrix.java
src/jalview/project/Jalview2XML.java
src/jalview/renderer/seqfeatures/FeatureRenderer.java
src/jalview/schemes/AnnotationColourGradient.java
src/jalview/schemes/Blosum62ColourScheme.java
src/jalview/schemes/BuriedColourScheme.java
src/jalview/schemes/ClustalxColourScheme.java
src/jalview/schemes/ColourSchemeI.java
src/jalview/schemes/ColourSchemeProperty.java
src/jalview/schemes/ColourSchemes.java
src/jalview/schemes/CovariationColourScheme.java
src/jalview/schemes/FeatureColour.java
src/jalview/schemes/FollowerColourScheme.java
src/jalview/schemes/HelixColourScheme.java
src/jalview/schemes/HydrophobicColourScheme.java
src/jalview/schemes/IdColourScheme.java [new file with mode: 0644]
src/jalview/schemes/JalviewColourScheme.java
src/jalview/schemes/NucleotideColourScheme.java
src/jalview/schemes/PIDColourScheme.java
src/jalview/schemes/PurinePyrimidineColourScheme.java
src/jalview/schemes/RNAHelicesColour.java
src/jalview/schemes/RNAInteractionColourScheme.java
src/jalview/schemes/ResidueColourScheme.java
src/jalview/schemes/ResidueProperties.java
src/jalview/schemes/ScoreColourScheme.java
src/jalview/schemes/StrandColourScheme.java
src/jalview/schemes/TCoffeeColourScheme.java
src/jalview/schemes/TaylorColourScheme.java
src/jalview/schemes/TurnColourScheme.java
src/jalview/schemes/UserColourScheme.java
src/jalview/schemes/ZappoColourScheme.java
src/jalview/util/DBRefUtils.java
src/jalview/util/JSONUtils.java [new file with mode: 0644]
src/jalview/viewmodel/AlignmentViewport.java
src/jalview/viewmodel/PCAModel.java
src/jalview/viewmodel/ViewportRanges.java
src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java
src/jalview/workers/ConsensusThread.java
src/jalview/ws/DBRefFetcher.java
src/jalview/ws/dbsources/Uniprot.java
src/jalview/ws/jws2/AADisorderClient.java
src/jalview/xml/binding/jalview/AlcodonFrame.java
src/jalview/xml/binding/jalview/Annotation.java
src/jalview/xml/binding/jalview/AnnotationColourScheme.java
src/jalview/xml/binding/jalview/AnnotationElement.java
src/jalview/xml/binding/jalview/DoubleMatrix.java [new file with mode: 0644]
src/jalview/xml/binding/jalview/DoubleVector.java [new file with mode: 0644]
src/jalview/xml/binding/jalview/Feature.java
src/jalview/xml/binding/jalview/FeatureMatcher.java
src/jalview/xml/binding/jalview/FeatureMatcherSet.java
src/jalview/xml/binding/jalview/FilterBy.java
src/jalview/xml/binding/jalview/JalviewModel.java
src/jalview/xml/binding/jalview/JalviewUserColours.java
src/jalview/xml/binding/jalview/MapListType.java
src/jalview/xml/binding/jalview/Mapping.java
src/jalview/xml/binding/jalview/NoValueColour.java
src/jalview/xml/binding/jalview/ObjectFactory.java
src/jalview/xml/binding/jalview/PcaDataType.java [new file with mode: 0644]
src/jalview/xml/binding/jalview/Pdbentry.java
src/jalview/xml/binding/jalview/Sequence.java
src/jalview/xml/binding/jalview/SequenceSet.java
src/jalview/xml/binding/jalview/SequenceType.java
src/jalview/xml/binding/jalview/ThresholdType.java
src/jalview/xml/binding/jalview/VAMSAS.java
src/jalview/xml/binding/jalview/WebServiceParameterSet.java
src/jalview/xml/binding/jalview/package-info.java
test/jalview/analysis/AlignSeqTest.java
test/jalview/analysis/AlignmentUtilsTests.java
test/jalview/analysis/CrossRefTest.java
test/jalview/analysis/DnaTest.java
test/jalview/analysis/FinderTest.java
test/jalview/analysis/GeneticCodesTest.java [new file with mode: 0644]
test/jalview/analysis/scoremodels/PIDModelTest.java
test/jalview/analysis/scoremodels/ScoreMatrixTest.java
test/jalview/analysis/scoremodels/ScoreModelsTest.java
test/jalview/bin/CommandLineOperations.java
test/jalview/commands/EditCommandTest.java
test/jalview/controller/AlignViewControllerTest.java
test/jalview/datamodel/AlignmentTest.java
test/jalview/datamodel/AllColsIteratorTest.java
test/jalview/datamodel/AllRowsIteratorTest.java
test/jalview/datamodel/ColumnSelectionTest.java
test/jalview/datamodel/SearchResultsTest.java
test/jalview/datamodel/SequenceGroupTest.java
test/jalview/datamodel/SequenceTest.java
test/jalview/datamodel/features/FeatureStoreTest.java
test/jalview/datamodel/features/NCListTest.java [deleted file]
test/jalview/datamodel/features/NCNodeTest.java [deleted file]
test/jalview/datamodel/features/RangeComparatorTest.java [deleted file]
test/jalview/datamodel/features/SequenceFeaturesTest.java
test/jalview/ext/ensembl/EnsemblCdnaTest.java
test/jalview/ext/ensembl/EnsemblCdsTest.java
test/jalview/ext/ensembl/EnsemblGeneTest.java
test/jalview/ext/ensembl/EnsemblGenomeTest.java
test/jalview/ext/ensembl/EnsemblSeqProxyTest.java
test/jalview/ext/htsjdk/TestHtsContigDb.java
test/jalview/ext/rbvi/chimera/ChimeraConnect.java
test/jalview/gui/AlignFrameTest.java
test/jalview/gui/AlignViewportTest.java
test/jalview/gui/AlignmentPanelTest.java
test/jalview/gui/AnnotationLabelsTest.java [new file with mode: 0644]
test/jalview/gui/AnnotationPanelTest.java [new file with mode: 0644]
test/jalview/gui/CalculationChooserTest.java [new file with mode: 0644]
test/jalview/gui/ColourMenuHelperTest.java [new file with mode: 0644]
test/jalview/gui/FeatureSettingsTest.java
test/jalview/gui/FreeUpMemoryTest.java
test/jalview/gui/ScalePanelTest.java [new file with mode: 0644]
test/jalview/gui/SeqCanvasTest.java
test/jalview/gui/SeqPanelTest.java
test/jalview/io/AnnotationFileIOTest.java
test/jalview/io/BackupFilesTest.java [new file with mode: 0644]
test/jalview/io/FeaturesFileTest.java
test/jalview/io/ScoreMatrixFileTest.java
test/jalview/io/SequenceAnnotationReportTest.java
test/jalview/io/cache/JvCacheableInputBoxTest.java
test/jalview/io/testProps.jvprops
test/jalview/io/vcf/VCFLoaderTest.java
test/jalview/math/MatrixTest.java
test/jalview/math/RotatableMatrixTest.java [new file with mode: 0644]
test/jalview/project/Jalview2xmlTests.java
test/jalview/renderer/seqfeatures/FeatureColourFinderTest.java
test/jalview/renderer/seqfeatures/FeatureRendererTest.java
test/jalview/schemes/AnnotationColourGradientTest.java
test/jalview/schemes/ColourSchemePropertyTest.java
test/jalview/schemes/ColourSchemesTest.java
test/jalview/schemes/DnaCodonTests.java [deleted file]
test/jalview/schemes/FeatureColourTest.java
test/jalview/schemes/JalviewColourSchemeTest.java
test/jalview/schemes/ResiduePropertiesTest.java
test/jalview/util/DBRefUtilsTest.java
test/jalview/util/JSONUtilsTest.java [new file with mode: 0644]
test/jalview/viewmodel/styles/ViewStyleTest.java
test/jalview/ws/dbsources/UniprotTest.java
utils/checkstyle/README.txt
utils/checkstyle/checkstyle-suppress.xml
utils/checkstyle/checkstyle.xml
utils/checkstyle/import-control.xml
utils/i18nAnt.xml

index 15432a1..2a9de83 100644 (file)
@@ -3,12 +3,12 @@ buildPropertiesFile
 buildTests
 buildextclients
 buildindices
-castorbinding
 clean
 compileApplet
 distclean
 help
 init
+jaxb-bindings
 linkcheck
 makeApplet
 makedist
index 0da91bb..4f9cb8a 100644 (file)
@@ -13,7 +13,6 @@
        <classpathentry kind="lib" path="lib/saaj.jar"/>
        <classpathentry kind="lib" path="lib/wsdl4j.jar"/>
        <classpathentry kind="lib" path="lib/xercesImpl.jar"/>
-       <classpathentry kind="lib" path="lib/castor-1.1-cycle-xml.jar" sourcepath="C:/Documents and Settings/JimP/workspace-3.3/castor/src/main/java"/>
        <classpathentry kind="lib" path="lib/JGoogleAnalytics_0.3.jar" sourcepath="/JGoogleAnalytics/src/main/java"/>
        <classpathentry kind="lib" path="lib/vamsas-client.jar"/>
        <classpathentry kind="lib" path="lib/commons-logging-1.1.1.jar"/>
@@ -36,8 +35,6 @@
        <classpathentry kind="lib" path="lib/miglayout-4.0-swing.jar"/>
        <classpathentry kind="lib" path="lib/jswingreader-0.3.jar" sourcepath="/jswingreader"/>
        <classpathentry kind="lib" path="lib/commons-codec-1.3.jar"/>
-       <classpathentry kind="lib" path="lib/spring-core-3.0.5.RELEASE.jar"/>
-       <classpathentry kind="lib" path="lib/spring-web-3.0.5.RELEASE.jar"/>
        <classpathentry kind="lib" path="lib/jabaws-min-client-2.2.0.jar" sourcepath="/clustengine"/>
        <classpathentry kind="lib" path="lib/json_simple-1.1.jar" sourcepath="/Users/jimp/Downloads/json_simple-1.1-all.zip"/>
        <classpathentry kind="lib" path="lib/slf4j-api-1.7.7.jar"/>
@@ -70,5 +67,6 @@
        <classpathentry kind="lib" path="lib/htsjdk-2.12.0.jar"/>
        <classpathentry kind="lib" path="lib/groovy-all-2.4.12-indy.jar"/>
        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
+       <classpathentry kind="lib" path="lib/intervalstore-v0.4.jar"/>
        <classpathentry kind="output" path="classes"/>
 </classpath>
index 86637df..211ddc9 100644 (file)
@@ -1,11 +1,13 @@
-.project
+/*.project
+.classpath
 /dist
 /clover
 /classes
 /tests
 /test-reports
 /test-output
-.externalToolBuilders/Jalview Release indices [Builder].launch
+.externalToolBuilders/*
+.settings/*
 /.DS_Store
 .DS_Store
 /.com.apple.timemachine.supported
@@ -14,3 +16,4 @@ TESTNG
 /jalviewApplet.jar
 /benchmarking/lib
 *.class
+/site
index afa99d2..728711e 100644 (file)
@@ -38,8 +38,6 @@ miglayout-4.0-swing.jar       BSD http://www.migcalendar.com/miglayout/versions/4.0/li
 min-jaba-client.jar
 regex.jar
 saaj.jar
-spring-core-3.0.5.RELEASE.jar : Apache License: jdas runtime dependencies retrieved via maven - TODO: JAL-3035 remove if no longer needed ?
-spring-web-3.0.5.RELEASE.jar : Apache License: jdas runtime dependencies retrieved via maven - TODO: JAL-3035 remove if no longer needed ?
 vamsas-client.jar
 wsdl4j.jar
 xercesImpl.jar
diff --git a/authors.props b/authors.props
new file mode 100644 (file)
index 0000000..3c06708
--- /dev/null
@@ -0,0 +1,4 @@
+YEAR=2018
+AUTHORS=J Procter, M Carstairs, B Soares, K Mourao, TC Ofoegbu, AM Waterhouse, J Engelhardt, LM Lui, A Menard, D Barton, N Sherstnev, D Roldan-Martinez, M Clamp, S Searle, G Barton
+AUTHORFNAMES=Jim Procter, Mungo Carstairs, Ben Soares, Kira Mourao, Tochukwu 'Charles' Ofoegbu, Andrew Waterhouse, Jan Engelhardt, Lauren Lui, Anne Menard, Daniel Barton, Natasha Sherstnev, David Roldan-Martinez, Michele Clamp, James Cuff, Steve Searle, David Martin & Geoff Barton
\ No newline at end of file
index 35d3926..71fee4f 100755 (executable)
   <delete file="in.jar" />
 </target>
 
+<target name="jaxb-bindings" depends="init" description="Generates JAXB bindings for supported Jalview XML models (needs xjc on the path)">
+  <delete>
+    <fileset dir="${sourceDir}/jalview/xml/binding/jalview">
+      <include name="*.java" />
+    </fileset>
+  </delete>
+  <exec executable="xjc">
+    <arg value="${schemaDir}/jalview.xsd"/>
+    <arg value="-d"/>
+    <arg value="${sourceDir}"/>
+    <arg value="-p"/>
+    <arg value="jalview.xml.binding.jalview"/>
+  </exec>
+  <delete>
+    <fileset dir="${sourceDir}/jalview/xml/binding/embl">
+      <include name="*.java" />
+    </fileset>
+  </delete>
+
+  <exec executable="xjc">
+    <arg value="${schemaDir}/embl.xsd"/>
+    <arg value="-d"/>
+    <arg value="${sourceDir}"/>
+    <arg value="-b"/>
+    <arg value="${schemaDir}/embl_bindings.xml"/>
+    <arg value="-p"/>
+    <arg value="jalview.xml.binding.embl"/>
+  </exec>
+
+  <delete>
+    <fileset dir="${sourceDir}/jalview/xml/binding/uniprot">
+      <include name="*.java" />
+    </fileset>
+  </delete>
+
+  <exec executable="xjc">
+    <arg value="${schemaDir}/uniprot.xsd"/>
+    <arg value="-d"/>
+    <arg value="${sourceDir}"/>
+    <arg value="-p"/>
+    <arg value="jalview.xml.binding.uniprot"/>
+  </exec>
+</target>
+
 <target name="sourcedist" description="create jalview source distribution" depends="init">
   <delete file="${source.dist.name}" />
   <!-- temporary copy of source to update timestamps -->
diff --git a/examples/backupfilestest.fa b/examples/backupfilestest.fa
new file mode 100644 (file)
index 0000000..c536a79
--- /dev/null
@@ -0,0 +1,2 @@
+>BACKUP_FILES/1-6 backupfiles
+AAAARG
index 4a15922..35c54d5 100644 (file)
@@ -24,6 +24,7 @@ import jalview.schemes.ColourSchemes
 import jalview.datamodel.AnnotatedCollectionI
 import jalview.datamodel.SequenceI
 import jalview.datamodel.SequenceCollectionI
+import jalview.api.AlignViewportI
 import jalview.util.Comparison
 
 /*
@@ -42,7 +43,7 @@ conserved = { ->
     /*
      * to make a new instance for each alignment view
      */
-    getInstance: { AnnotatedCollectionI coll, Map<SequenceI, SequenceCollectionI> map -> conserved() },
+    getInstance: { AlignViewportI view, AnnotatedCollectionI coll, Map<SequenceI, SequenceCollectionI> map -> conserved() },
     
     /*
      * method only needed if colour scheme has to recalculate
index d5ca973..3f1f953 100644 (file)
@@ -4,6 +4,7 @@ import jalview.schemes.ColourSchemes;
 import jalview.datamodel.AnnotatedCollectionI;
 import jalview.datamodel.SequenceI;
 import jalview.datamodel.SequenceCollectionI;
+import jalview.api.AlignViewportI
 
 /*
  * Example script that registers two new alignment colour schemes
@@ -25,7 +26,7 @@ candy = { ->
     /*
      * to make a new instance for each alignment view
      */
-    getInstance: { AnnotatedCollectionI coll, Map<SequenceI, SequenceCollectionI> map -> candy() },
+    getInstance: { AlignViewportI view, AnnotatedCollectionI coll, Map<SequenceI, SequenceCollectionI> map -> candy() },
     
     /*
      * method only needed if colour scheme has to recalculate
index 68730f3..e186766 100644 (file)
@@ -24,6 +24,7 @@ import jalview.schemes.ColourSchemes
 import jalview.datamodel.AnnotatedCollectionI
 import jalview.datamodel.SequenceI
 import jalview.datamodel.SequenceCollectionI
+import jalview.api.AlignViewportI
 import jalview.util.Comparison
 
 /*
diff --git a/examples/testdata/projects/manyViews.jvp b/examples/testdata/projects/manyViews.jvp
new file mode 100644 (file)
index 0000000..065b29c
Binary files /dev/null and b/examples/testdata/projects/manyViews.jvp differ
diff --git a/examples/testdata/projects/twoViews.jvp b/examples/testdata/projects/twoViews.jvp
new file mode 100644 (file)
index 0000000..80333cd
Binary files /dev/null and b/examples/testdata/projects/twoViews.jvp differ
index 78f86b6..1666cc6 100755 (executable)
    
    <mapID target="biojson" url="html/features/bioJsonFormat.html" />
    <mapID target="pdbfetcher" url="html/features/pdbsequencefetcher.html" />
+   <mapID target="pdbfts" url="html/features/pdbsequencefetcher.html#pdbfts" />
    <mapID target="siftsmapping" url="html/features/siftsmapping.html" />
    <mapID target="pdbchooser" url="html/features/structurechooser.html" />
    <mapID target="selectcolbyannot" url="html/features/columnFilterByAnnotation.html" />
    <mapID target="ensemblfetch" url="html/features/ensemblsequencefetcher.html" />
    
    <mapID target="uniprotfetcher" url="html/features/uniprotsequencefetcher.html" />
+   <mapID target="uniprotfts" url="html/features/uniprotsequencefetcher.html#uniprotfts" />
    
    <mapID target="urllinks" url="html/webServices/urllinks.html" />
    <mapID target="linksprefs" url="html/features/preferences.html#links" />
index 0104078..5b76d10 100755 (executable)
     <em>Calculating PCAs for aligned sequences</em><br />Jalview can
     perform PCA analysis on both proteins and nucleotide sequence
     alignments. In both cases, components are generated by an
-    eigenvector decomposition of the matrix formed from the sum of
-    substitution matrix scores at each aligned position between each
-    pair of sequences - computed with one of the available score
-    matrices, such as <a href="scorematrices.html#blosum62">BLOSUM62</a>,
+    eigenvector decomposition of the matrix formed from pairwise similarity
+    scores between each pair of sequences. The similarity score model is 
+    selected on the <a href="calculations.html">calculations dialog</a>, and
+    may use one of the available score matrices, such as 
+    <a href="scorematrices.html#blosum62">BLOSUM62</a>,
     <a href="scorematrices.html#pam250">PAM250</a>, or the <a
       href="scorematrices.html#simplenucleotide">simple single
-      nucleotide substitution matrix</a>. The options available for
-    calculation are given in the <strong><em>Change
-        Parameters</em></strong> menu.
+      nucleotide substitution matrix</a>, or by sequence percentage identity,
+      or sequence feature similarity. 
   </p>
   <img src="pcaviewer.gif">
   <p>
index 3d6245e..8cb2b59 100755 (executable)
   </p>
   <p>
     <strong><em>Selecting Sequence Leaf Nodes</em></strong><br>
-    Selecting sequence ids at the leaves of the tree selects the
+    Selecting sequence IDs at the leaves of the tree selects the
     corresponding sequences in the original alignment. These selections
     are also reflected in any other analysis windows associated with the
     alignment, such as another tree viewer.
   </p>
   <p>
-    <strong><em>Grouping sequences by partitioning the
-        tree at a particular distanec</em></strong><br> Clicking anywhere along
+    <strong><em><a name="partitioning">Grouping sequences by partitioning</a> the
+        tree at a particular distance</em></strong><br> Clicking anywhere along
     the extent of the tree (but not on a leaf or internal node) defines
     a tree 'partition', by cutting every branch of the tree spanning the
     depth where the mouse-click occurred. Groups are created containing
     sequences at the leaves of each connected sub tree. These groups are
     each given a different colour, which are reflected in other windows
-    in the same way as if the sequence ids were selected, and can be
+    in the same way as if the sequence IDs were selected, and can be
     edited in the same way as user defined sequence groups.
   </p>
   <p>
     identifying specific patterns of conservation and mutation
     corresponding to the overall phylogenetic structure, when combined
     with the <a href="../colourSchemes/conservation.html">conservation
-      based colour scheme</a>.
+      based colour scheme</a>.To distinguish parts of the alignment assigned
+    to different groups, you may also enable the Sequence ID colour
+    scheme via the <a href="../menus/alwcolour.html">Alignment
+      window's Colours menu</a> (<em>Since 2.11</em>).
   </p>
   <p>
     <strong><em>Selecting Subtrees and changing the branch
index 7664101..51d0738 100755 (executable)
@@ -35,18 +35,18 @@ td {
   <p>
     <strong>Colour schemes</strong>
   </p>
-  <p>Jalview allows the user to set a background colour for the
+  <p>Jalview allows the user to set a colour scheme for the
     whole alignment view or for each group defined on regions within it.</p>
-  <p>To change the background colour, simply select the colour from
+  <p>To change the colour for a view, simply select a new colour scheme from
     the &quot;Colour&quot; menu.</p>
   <p>To change the colour of a group, right click on any residue
     within a group and use the popup menu to define the group colour.</p>
-  <p>At the top of the &quot;Colour&quot; menu the tick box
-    &quot;Apply Background Colour to all groups&quot;. This is ticked by
+  <p>At the top of the &quot;Colour&quot; menu you'll see a tick box
+    &quot;Apply Colour to all groups&quot;. This is ticked by
     default so that a chosen colour scheme will be applied to all
     existing groups. If you wish to maintain the colour scheme for
-    defined groups, make sure you deselect this option before changing
-    the background colour.</p>
+    defined groups, make sure you deselect this option before selecting
+    a new scheme in the Colour menu.</p>
   <p>
     The <strong>&quot;Colour&#8594;<a
       href="../colourSchemes/textcolour.html">Colour Text...</a>&quot;
diff --git a/help/html/features/das.gif b/help/html/features/das.gif
deleted file mode 100644 (file)
index 1f884cb..0000000
Binary files a/help/html/features/das.gif and /dev/null differ
diff --git a/help/html/features/exportannot.gif b/help/html/features/exportannot.gif
deleted file mode 100644 (file)
index 2133cc1..0000000
Binary files a/help/html/features/exportannot.gif and /dev/null differ
index bb63bed..9251277 100644 (file)
@@ -43,7 +43,7 @@
     alt="PDB sequence fetcher (introduced in Jalview 2.9)" />
 
   <p>
-    <strong>Searching the PDB Database</strong>
+    <a name="pdbfts"><strong>Searching the PDB Database</strong></a>
   </p>
   <p>To search the PDB, begin typing in the text box. If the
     'autosearch' checkbox is enabled, then the results of your query
index 52e88db..8c6b699 100755 (executable)
@@ -62,8 +62,7 @@
       sequence alignments and EPS files.
     </li>
     <li>The <a href="#editing"><strong>&quot;Editing&quot;</strong>
-        Preferences</a> tab contains settings affecting the export of
-      sequence alignments and EPS files.
+        Preferences</a> tab contains settings affecting behaviour when editing alignments.
     </li>
     <li>The <a href="../webServices/webServicesPrefs.html"><strong>&quot;Web
           Service&quot;</strong> Preferences</a> tab allows you to configure the <a
     the backbone atoms in the PDB file will be extracted as annotation
     lines shown on the alignment.
   <p>
-    <em>Default structure viewer</em> - choose JMOL or CHIMERA for
+    <em>Default structure viewer</em> - choose Jmol or CHIMERA for
     viewing 3D structures.
   <p>
     <em>Path to Chimera program</em> - Optional, as Jalview will search
         Preferences tab</strong></a>
   </p>
   <p>
-    <em>Default Browser (Unix)</em><br> Its difficult in Java to
+    <em>Default Browser (Unix)</em><br> It's difficult in Java to
     detect the default web browser for Unix users. If Jalview can't find
     your default web browser, enter the name or full path to your web
     browser application.
     just those you have configured yourself <em>via</em> the <em>Edit
       Links</em> buttons. Press <em>Show all</em> to clear any filters.
   </p>
-  <p>The links table is prepoulated with persistent URLs for many common
+  <p>The links table is prepopulated with persistent URLs for many common
     bioinformatics databases (since 2.10.2). These links are downloaded by Jalview from
     the <em>identifiers.org</em> website, and the names and URLs are not
     user editable.
     allows the user to set a default rendering style for EPS export:
   <ul>
     <li>&quot;Prompt each time&quot;<br> Choose this to be
-      asked select between Lineart and Text each time you make an EPS
+      asked to select between Lineart and Text each time you make an EPS
       file.
     </li>
     <li>&quot;Lineart&quot;<br> EPS files will accurately
     ignored if <em>&quot;Automatically set ID width&quot;</em> is set.
   </p>
   <p>
-    <em>Sequence//Start-End Numbering</em><br> The output tab also
+    <em>Sequence/Start-End Numbering</em><br> The output tab also
     has a group of checkboxes for each file format. If these are ticked,
     then Jalview will write files with the start and end sequence
     positions appended to each sequence id:
diff --git a/help/html/features/search.gif b/help/html/features/search.gif
deleted file mode 100755 (executable)
index 1c0ffb0..0000000
Binary files a/help/html/features/search.gif and /dev/null differ
index 4a64f52..72e7649 100644 (file)
@@ -44,7 +44,7 @@
   </p>
 
   <p>
-    <strong>Searching the UniProt Database</strong>
+    <a name="uniprotfts"><strong>Searching the UniProt Database</strong></a>
   </p>
   <p>To search UniProt, simply begin typing in the text box. If the
     'autosearch' check box is enabled, then after a short delay (about
index f3ab75d..3a057a8 100755 (executable)
       </strong> <em>See <a href="../colourSchemes/index.html">colours</a>
           for a description of all colour schemes.
       </em><br></li>
-      <li><strong>By Conservation<br>
+        <li><strong>Sequence ID<br></strong><em>Shades
+            sequences using their Sequence ID colour. Useful when
+            performing <a
+            href="../calculations/treeviewer.html#partitioning">tree
+              based subfamily analysis</a>.
+        </em></li>
+        <li><strong>By Conservation<br>
       </strong><em>See <a href="../colourSchemes/conservation.html">Colouring
             by Conservation</a>.
       </em><br></li>
index e62a130..9a96595 100755 (executable)
         a description of all colour schemes.
     </em><br>
     </li>
+    <li><strong>Sequence ID<br></strong><em>Shades
+        sequences using their Sequence ID colour. Useful when performing
+        <a href="../calculations/treeviewer.html#partitioning">tree
+          based subfamily analysis</a>.
+    </em></li>
     <li><strong>By Conservation<br>
     </strong><em>See <a href="../colourSchemes/conservation.html">Colouring
           by Conservation</a>.
index af417a7..0fba08a 100755 (executable)
@@ -71,25 +71,64 @@ li:before {
       <td width="60" nowrap>
         <div align="center">
           <strong><a name="Jalview.2.11.0">2.11.0</a><br />
-            <em>8/09/2018</em></strong>
+            <em>29/01/2019</em></strong>
         </div>
       </td>
-      <td><div align="left">
-          <em></em>
-          <ul>
-            <li>
-              <!-- JAL-2865 -->Jalview doesn't hang when closing windows or the overview updates with large alignments.
-            </li>
-          </ul>
-        </div></td>
-      <td><div align="left">
-          <em></em>
-          <ul>
-            <li>
-              <!-- JAL-3035 -->DAS sequence retrieval and annotation capabilities removed from the Jalview Desktop
-            </li>
-          </ul>
-        </div></td>
+    <td><div align="left">
+        <em>Deprecations</em>
+        <ul>
+          <li>
+            <!-- JAL-3035 -->DAS sequence retrieval and annotation
+            capabilities removed from the Jalview Desktop
+          </li>
+        </ul>
+        <em>Release Processes</em>
+        <ul>
+        <li>Atlassian Bamboo continuous integration server for unattended Test Suite execution</li>
+        <li><!-- JAL-2864 -->Memory test suite to detect leaks in common operations</li> 
+        </ul>
+      </div></td>
+    <td><div align="left">
+        <em></em>
+        <ul>
+          <li>
+            <!-- JAL-2865 -->Jalview hangs when closing windows
+            or the overview updates with large alignments.
+          </li>
+          <li>
+            <!-- JAL-2865 -->Tree and PCA calculation fails for selected
+            region if columns were selected by dragging right-to-left
+            and the mouse moved to the left of the first column.
+          </li>
+          <li>
+            <!-- JAL-2846 -->Error message for trying to load in invalid
+            URLs doesn't tell users the invalid URL
+          </li>
+        </ul>
+        <em>Editing</em>
+        <ul>
+          <li>
+            <!-- JAL-2822 -->Start and End should be updated when
+            sequence data at beginning or end of alignment added/removed
+            via 'Edit' sequence
+          </li>
+          <li>
+            <!-- JAL-2541 -->Delete/Cut selection doesn't relocate
+            sequence features correctly when start of sequence is
+            removed (Known defect since 2.10)
+          </li>
+          <li>
+            <!-- JAL- -->
+          </li>
+        </ul>
+        <em>New Known Defects</em>
+        <ul>
+          <li>
+            <!-- JAL-3178 -->Nonpositional features lose feature group
+            on export as jalview features file
+          </li>
+        </ul>
+      </div></td>
     </tr>
     <tr>
     <td width="60" nowrap>
diff --git a/lib/intervalstore-src-v0.4.jar b/lib/intervalstore-src-v0.4.jar
new file mode 100644 (file)
index 0000000..3feafbb
Binary files /dev/null and b/lib/intervalstore-src-v0.4.jar differ
diff --git a/lib/intervalstore-v0.4.jar b/lib/intervalstore-v0.4.jar
new file mode 100644 (file)
index 0000000..4f6101c
Binary files /dev/null and b/lib/intervalstore-v0.4.jar differ
diff --git a/lib/spring-core-3.0.5.RELEASE.jar b/lib/spring-core-3.0.5.RELEASE.jar
deleted file mode 100644 (file)
index ea9500d..0000000
Binary files a/lib/spring-core-3.0.5.RELEASE.jar and /dev/null differ
diff --git a/lib/spring-web-3.0.5.RELEASE.jar b/lib/spring-web-3.0.5.RELEASE.jar
deleted file mode 100644 (file)
index 5a2381a..0000000
Binary files a/lib/spring-web-3.0.5.RELEASE.jar and /dev/null differ
diff --git a/resources/AmbiguityCodes.dat b/resources/AmbiguityCodes.dat
new file mode 100644 (file)
index 0000000..9372c03
--- /dev/null
@@ -0,0 +1,13 @@
+# source: IUPAC codes as per http://www.insdc.org/documents/feature_table.html#7.4.1
+DNA
+R      AG
+Y      TC
+W      AT
+S      GC
+M      AC
+K      GT
+H      ATC
+B      GTC
+V      GAC
+D      GAT
+N      GATC
diff --git a/resources/GeneticCodes.dat b/resources/GeneticCodes.dat
new file mode 100644 (file)
index 0000000..4735cf2
--- /dev/null
@@ -0,0 +1,327 @@
+-- source: ftp://ftp.ncbi.nih.gov/entrez/misc/data/gc.prt (19th March 2018)
+-- SGC3 name edited slightly so as to fit all on one line
+--**************************************************************************
+--  This is the NCBI genetic code table
+--  Initial base data set from Andrzej Elzanowski while at PIR International
+--  Addition of Eubacterial and Alternative Yeast by J.Ostell at NCBI
+--  Base 1-3 of each codon have been added as comments to facilitate
+--    readability at the suggestion of Peter Rice, EMBL
+--  Later additions by Taxonomy Group staff at NCBI
+--
+--  Version 4.2
+--     Added Karyorelict nuclear genetic code 27
+--     Added Condylostoma nuclear genetic code 28
+--     Added Mesodinium nuclear genetic code 29
+--     Added Peritrich nuclear genetic code 30
+--     Added Blastocrithidia nuclear genetic code 31
+--
+--  Version 4.1
+--     Added Pachysolen tannophilus nuclear genetic code 26
+--
+--  Version 4.0
+--     Updated version to reflect numerous undocumented changes:
+--     Corrected start codons for genetic code 25
+--     Name of new genetic code is Candidate Division SR1 and Gracilibacteria
+--     Added candidate division SR1 nuclear genetic code 25
+--     Added GTG as start codon for genetic code 24
+--     Corrected Pterobranchia Mitochondrial genetic code (24)
+--     Added genetic code 24, Pterobranchia Mitochondrial
+--     Genetic code 11 is now Bacterial, Archaeal and Plant Plastid
+--     Fixed capitalization of mitochondrial in codes 22 and 23
+--     Added GTG, ATA, and TTG as alternative start codons to code 13
+--
+--  Version 3.9
+--     Code 14 differs from code 9 only by translating UAA to Tyr rather than
+--     STOP.  A recent study (Telford et al, 2000) has found no evidence that
+--     the codon UAA codes for Tyr in the flatworms, but other opinions exist.
+--     There are very few GenBank records that are translated with code 14,
+--     but a test translation shows that retranslating these records with code
+--     9 can cause premature terminations.  Therefore, GenBank will maintain
+--     code 14 until further information becomes available.
+--
+--  Version 3.8
+--     Added GTG start to Echinoderm mitochondrial code, code 9
+--
+--  Version 3.7
+--     Added code 23 Thraustochytrium mitochondrial code
+--        formerly OGMP code 93
+--        submitted by Gertraude Berger, Ph.D.
+--
+--  Version 3.6
+--     Added code 22 TAG-Leu, TCA-stop
+--        found in mitochondrial DNA of Scenedesmus obliquus
+--        submitted by Gertraude Berger, Ph.D.
+--        Organelle Genome Megasequencing Program, Univ Montreal
+--
+--  Version 3.5
+--     Added code 21, Trematode Mitochondrial
+--       (as deduced from: Garey & Wolstenholme,1989; Ohama et al, 1990)
+--     Added code 16, Chlorophycean Mitochondrial
+--       (TAG can translated to Leucine instaed to STOP in chlorophyceans
+--        and fungi)
+--
+--  Version 3.4
+--     Added CTG,TTG as allowed alternate start codons in Standard code.
+--        Prats et al. 1989, Hann et al. 1992
+--
+--  Version 3.3 - 10/13/95
+--     Added alternate intiation codon ATC to code 5
+--        based on complete mitochondrial genome of honeybee
+--        Crozier and Crozier (1993)
+--
+--  Version 3.2 - 6/24/95
+--  Code       Comments
+--   10        Alternative Ciliate Macronuclear renamed to Euplotid Macro...
+--   15        Blepharisma Macro.. code added
+--    5        Invertebrate Mito.. GTG allowed as alternate initiator
+--   11        Eubacterial renamed to Bacterial as most alternate starts
+--               have been found in Archea
+--
+--
+--  Version 3.1 - 1995
+--  Updated as per Andrzej Elzanowski at NCBI
+--     Complete documentation in NCBI toolkit documentation
+--  Note: 2 genetic codes have been deleted
+--
+--   Old id   Use id     - Notes
+--
+--   id 7      id 4      - Kinetoplast code now merged in code id 4
+--   id 8      id 1      - all plant chloroplast differences due to RNA edit
+--
+--*************************************************************************
+
+Genetic-code-table ::= {
+ {
+  name "Standard" ,
+  name "SGC0" ,
+  id 1 ,
+  ncbieaa  "FFLLSSSSYY**CC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG",
+  sncbieaa "---M------**--*----M---------------M----------------------------"
+  -- Base1  TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG
+  -- Base2  TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG
+  -- Base3  TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG
+ },
+ {
+  name "Vertebrate Mitochondrial" ,
+  name "SGC1" ,
+  id 2 ,
+  ncbieaa  "FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIMMTTTTNNKKSS**VVVVAAAADDEEGGGG",
+  sncbieaa "----------**--------------------MMMM----------**---M------------"
+  -- Base1  TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG
+  -- Base2  TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG
+  -- Base3  TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG
+ },
+ {
+  name "Yeast Mitochondrial" ,
+  name "SGC2" ,
+  id 3 ,
+  ncbieaa  "FFLLSSSSYY**CCWWTTTTPPPPHHQQRRRRIIMMTTTTNNKKSSRRVVVVAAAADDEEGGGG",
+  sncbieaa "----------**----------------------MM----------------------------"
+  -- Base1  TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG
+  -- Base2  TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG
+  -- Base3  TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG
+ },
+ {
+    name "Mold / Protozoan / Coelenterate Mitochondrial; Mycoplasma; Spiroplasma" ,
+  name "SGC3" ,
+  id 4 ,
+  ncbieaa  "FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG",
+  sncbieaa "--MM------**-------M------------MMMM---------------M------------"
+  -- Base1  TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG
+  -- Base2  TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG
+  -- Base3  TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG
+ },
+ {
+  name "Invertebrate Mitochondrial" ,
+  name "SGC4" ,
+  id 5 ,
+  ncbieaa  "FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIMMTTTTNNKKSSSSVVVVAAAADDEEGGGG",
+  sncbieaa "---M------**--------------------MMMM---------------M------------"
+  -- Base1  TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG
+  -- Base2  TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG
+  -- Base3  TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG
+ },
+ {
+  name "Ciliate Nuclear; Dasycladacean Nuclear; Hexamita Nuclear" ,
+  name "SGC5" ,
+  id 6 ,
+  ncbieaa  "FFLLSSSSYYQQCC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG",
+  sncbieaa "--------------*--------------------M----------------------------"
+  -- Base1  TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG
+  -- Base2  TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG
+  -- Base3  TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG
+ },
+ {
+  name "Echinoderm Mitochondrial; Flatworm Mitochondrial" ,
+  name "SGC8" ,
+  id 9 ,
+  ncbieaa  "FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIIMTTTTNNNKSSSSVVVVAAAADDEEGGGG",
+  sncbieaa "----------**-----------------------M---------------M------------"
+  -- Base1  TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG
+  -- Base2  TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG
+  -- Base3  TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG
+ },
+ {
+  name "Euplotid Nuclear" ,
+  name "SGC9" ,
+  id 10 ,
+  ncbieaa  "FFLLSSSSYY**CCCWLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG",
+  sncbieaa "----------**-----------------------M----------------------------"
+  -- Base1  TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG
+  -- Base2  TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG
+  -- Base3  TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG
+ },
+ {
+  name "Bacterial, Archaeal and Plant Plastid" ,
+  id 11 ,
+  ncbieaa  "FFLLSSSSYY**CC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG",
+  sncbieaa "---M------**--*----M------------MMMM---------------M------------"
+  -- Base1  TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG
+  -- Base2  TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG
+  -- Base3  TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG
+ },
+ {
+  name "Alternative Yeast Nuclear" ,
+  id 12 ,
+  ncbieaa  "FFLLSSSSYY**CC*WLLLSPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG",
+  sncbieaa "----------**--*----M---------------M----------------------------"
+  -- Base1  TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG
+  -- Base2  TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG
+  -- Base3  TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG
+ },
+ {
+  name "Ascidian Mitochondrial" ,
+  id 13 ,
+  ncbieaa  "FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIMMTTTTNNKKSSGGVVVVAAAADDEEGGGG",
+  sncbieaa "---M------**----------------------MM---------------M------------"
+  -- Base1  TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG
+  -- Base2  TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG
+  -- Base3  TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG
+ },
+ {
+  name "Alternative Flatworm Mitochondrial" ,
+  id 14 ,
+  ncbieaa  "FFLLSSSSYYY*CCWWLLLLPPPPHHQQRRRRIIIMTTTTNNNKSSSSVVVVAAAADDEEGGGG",
+  sncbieaa "-----------*-----------------------M----------------------------"
+  -- Base1  TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG
+  -- Base2  TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG
+  -- Base3  TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG
+ } ,
+ {
+  name "Blepharisma Macronuclear" ,
+  id 15 ,
+  ncbieaa  "FFLLSSSSYY*QCC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG",
+  sncbieaa "----------*---*--------------------M----------------------------"
+  -- Base1  TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG
+  -- Base2  TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG
+  -- Base3  TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG
+ } ,
+ {
+  name "Chlorophycean Mitochondrial" ,
+  id 16 ,
+  ncbieaa  "FFLLSSSSYY*LCC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG",
+  sncbieaa "----------*---*--------------------M----------------------------"
+  -- Base1  TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG
+  -- Base2  TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG
+  -- Base3  TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG
+ } ,
+ {
+  name "Trematode Mitochondrial" ,
+  id 21 ,
+  ncbieaa  "FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIMMTTTTNNNKSSSSVVVVAAAADDEEGGGG",
+  sncbieaa "----------**-----------------------M---------------M------------"
+  -- Base1  TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG
+  -- Base2  TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG
+  -- Base3  TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG
+ } ,
+ {
+  name "Scenedesmus obliquus Mitochondrial" ,
+  id 22 ,
+  ncbieaa  "FFLLSS*SYY*LCC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG",
+  sncbieaa "------*---*---*--------------------M----------------------------"
+  -- Base1  TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG
+  -- Base2  TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG
+  -- Base3  TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG
+ } ,
+ {
+  name "Thraustochytrium Mitochondrial" ,
+  id 23 ,
+  ncbieaa  "FF*LSSSSYY**CC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG",
+  sncbieaa "--*-------**--*-----------------M--M---------------M------------"
+  -- Base1  TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG
+  -- Base2  TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG
+  -- Base3  TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG
+ } ,
+ {
+  name "Pterobranchia Mitochondrial" ,
+  id 24 ,
+  ncbieaa  "FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSSKVVVVAAAADDEEGGGG",
+  sncbieaa "---M------**-------M---------------M---------------M------------"
+  -- Base1  TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG
+  -- Base2  TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG
+  -- Base3  TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG
+ } ,
+ {
+  name "Candidate Division SR1 and Gracilibacteria" ,
+  id 25 ,
+  ncbieaa  "FFLLSSSSYY**CCGWLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG",
+  sncbieaa "---M------**-----------------------M---------------M------------"
+  -- Base1  TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG
+  -- Base2  TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG
+  -- Base3  TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG
+ } ,
+ {
+  name "Pachysolen tannophilus Nuclear" ,
+  id 26 ,
+  ncbieaa  "FFLLSSSSYY**CC*WLLLAPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG",
+  sncbieaa "----------**--*----M---------------M----------------------------"
+  -- Base1  TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG
+  -- Base2  TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG
+  -- Base3  TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG
+ } ,
+ {
+  name "Karyorelict Nuclear" ,
+  id 27 ,
+  ncbieaa  "FFLLSSSSYYQQCCWWLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG",
+  sncbieaa "--------------*--------------------M----------------------------"
+  -- Base1  TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG
+  -- Base2  TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG
+  -- Base3  TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG
+ } ,
+ {
+  name "Condylostoma Nuclear" ,
+  id 28 ,
+  ncbieaa  "FFLLSSSSYYQQCCWWLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG",
+  sncbieaa "----------**--*--------------------M----------------------------"
+  -- Base1  TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG
+  -- Base2  TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG
+  -- Base3  TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG
+ } ,
+ {
+  name "Mesodinium Nuclear" ,
+  id 29 ,
+  ncbieaa  "FFLLSSSSYYYYCC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG",
+  sncbieaa "--------------*--------------------M----------------------------"
+  -- Base1  TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG
+  -- Base2  TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG
+  -- Base3  TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG
+ } ,
+ {
+  name "Peritrich Nuclear" ,
+  id 30 ,
+  ncbieaa  "FFLLSSSSYYEECC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG",
+  sncbieaa "--------------*--------------------M----------------------------"
+  -- Base1  TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG
+  -- Base2  TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG
+  -- Base3  TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG
+ } ,
+ {
+  name "Blastocrithidia Nuclear" ,
+  id 31 ,
+  ncbieaa  "FFLLSSSSYYEECCWWLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG",
+  sncbieaa "----------**-----------------------M----------------------------"
+  -- Base1  TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG
+  -- Base2  TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG
+  -- Base3  TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG
+ }
+}
index 7a89b71..2d48fac 100644 (file)
@@ -30,6 +30,7 @@ action.minimize_associated_windows = Minimize Associated Windows
 action.close_all = Close all
 action.load_project = Load Project
 action.save_project = Save Project
+action.save_project_as = Save Project as...
 action.quit = Quit
 label.quit_jalview = Quit Jalview?
 action.expand_views = Expand Views
@@ -119,10 +120,8 @@ action.select = Select
 action.new_view = New View
 action.close = Close
 action.add = Add
-action.save_as_default = Save as default
 action.save_as = Save as...
 action.save = Save
-action.cancel_fetch = Cancel Fetch
 action.change_font = Change Font
 action.change_font_tree_panel = Change Font (Tree Panel)
 action.colour = Colour
@@ -141,7 +140,6 @@ action.fetch_db_references = Fetch DB References
 action.view_flanking_regions = Show flanking regions
 label.view_flanking_regions = Show sequence data either side of the subsequences involved in this alignment
 label.structures_manager = Structures Manager
-label.nickname = Nickname:
 label.url = URL
 label.url\: = URL:
 label.input_file_url = Enter URL or Input File
@@ -163,7 +161,6 @@ label.current_parameter_set_name = Current parameter set name:
 label.service_action = Service Action:
 label.post_url = POST URL:
 label.url_suffix = URL Suffix
-label.sequence_source = Sequence Source
 label.per_seq = per Sequence
 label.result_vertically_separable = Results are vertically separable
 label.amend = Amend
@@ -173,10 +170,9 @@ label.principal_component_analysis = Principal Component Analysis
 label.average_distance_identity = Average Distance Using % Identity
 label.neighbour_joining_identity = Neighbour Joining Using % Identity
 label.choose_calculation = Choose Calculation
-label.treecalc_title = {0} Using {1}
+label.calc_title = {0} Using {1}
 label.tree_calc_av = Average Distance
 label.tree_calc_nj = Neighbour Joining
-label.select_score_model = Select score model
 label.score_model_pid = % Identity
 label.score_model_blosum62 = BLOSUM62
 label.score_model_pam250 = PAM 250
@@ -204,6 +200,7 @@ label.colourScheme_purine/pyrimidine = Purine/Pyrimidine
 label.colourScheme_nucleotide = Nucleotide
 label.colourScheme_t-coffee_scores = T-Coffee Scores
 label.colourScheme_rna_helices = By RNA Helices
+label.colourScheme_sequence_id = Sequence ID Colour
 label.blc = BLC
 label.fasta = Fasta
 label.msf = MSF
@@ -354,7 +351,6 @@ label.status = Status
 label.channels = Channels
 label.channel_title_item_count = {0} ({1})
 label.blog_item_published_on_date = {0} {1} 
-label.select_das_service_from_table = Select a DAS service from the table to read a full description here.</font></html>
 label.session_update = Session Update
 label.new_vamsas_session = New Vamsas Session
 action.load_vamsas_session = Load Vamsas Session...
@@ -372,7 +368,6 @@ label.load_colours = Load Colours
 label.save_colours = Save Colours
 label.load_colours_tooltip = Load feature colours and filters from file
 label.save_colours_tooltip = Save feature colours and filters to file
-label.fetch_das_features = Fetch DAS Features
 label.selected_database_to_fetch_from = Selected {0} database {1} to fetch from {2} 
 label.database_param = Database: {0}
 label.example = Example
@@ -410,14 +405,11 @@ label.couldnt_find_pdb_id_in_file = Couldn't find a PDB id in the file supplied.
 label.no_pdb_id_in_file = No PDB Id in File
 label.couldnt_read_pasted_text = Couldn't read the pasted text {0}
 label.error_parsing_text = Error parsing text
-label.enter_local_das_source = Enter Nickname & URL of Local DAS Source
-label.you_can_only_edit_or_remove_local_das_sources = You can only edit or remove local DAS Sources!
-label.public_das_source = Public DAS source - not editable
 label.input_alignment_from_url = Input Alignment From URL
 label.input_alignment = Input Alignment
 label.couldnt_import_as_vamsas_session = Couldn't import {0} as a new vamsas session.
 label.vamsas_document_import_failed = Vamsas Document Import Failed
-label.couldnt_locate = Couldn't locate {0}
+label.couldnt_locate = Could not locate {0}
 label.url_not_found = URL not found
 label.new_sequence_url_link = New sequence URL link
 label.cannot_edit_annotations_in_wrapped_view = Cannot edit annotations in wrapped view
@@ -429,8 +421,6 @@ label.invalid_url = Invalid URL !
 label.error_loading_file = Error loading file
 label.problems_opening_file = Encountered problems opening {0}!!
 label.file_open_error = File open error
-label.no_das_sources_selected_warn = No das sources were selected.\nPlease select some sources and\ntry again.
-label.no_das_sources_selected_title = No DAS Sources Selected
 label.colour_scheme_exists_overwrite = Colour scheme {0} exists.\nContinue saving colour scheme as {1}?"
 label.duplicate_scheme_name = Duplicate scheme name
 label.jalview_new_questionnaire = There is a new Questionnaire available. Would you like to complete it now ?\n
@@ -503,6 +493,10 @@ label.edit_name_description = Edit Name/Description...
 label.create_sequence_feature = Create Sequence Feature...
 label.edit_sequence = Edit Sequence
 label.edit_sequences = Edit Sequences
+label.insert_gap = Insert 1 gap
+label.insert_gaps = Insert {0} gaps
+label.delete_gap = Delete 1 gap
+label.delete_gaps = Delete {0} gaps
 label.sequence_details = Sequence Details
 label.jmol_help = Jmol Help
 label.chimera_help = Chimera Help
@@ -623,7 +617,6 @@ label.visual = Visual
 label.connections = Connections
 label.output = Output
 label.editing = Editing
-label.das_settings = DAS Settings
 label.web_services = Web Services
 label.right_click_to_edit_currently_selected_parameter = Right click to edit currently selected parameter.
 label.let_jmol_manage_structure_colours = Let Jmol manage structure colours
@@ -639,10 +632,6 @@ label.delete_service_url = Delete Service URL
 label.details = Details
 label.options = Options
 label.parameters = Parameters
-label.available_das_sources = Available DAS Sources
-label.full_details = Full Details
-label.authority = Authority
-label.type = Type
 label.proxy_server = Proxy Server
 label.file_output = File Output
 label.select_input_type = Select input type
@@ -711,9 +700,6 @@ label.sort_alignment_new_tree = Sort Alignment With New Tree
 label.add_sequences = Add Sequences
 label.new_window = New Window
 label.split_window = Split Window
-label.refresh_available_sources = Refresh Available Sources
-label.use_registry = Use Registry
-label.add_local_source = Add Local Source
 label.set_as_default = Set as Default
 label.show_labels = Show labels
 action.background_colour = Background Colour...
@@ -772,7 +758,7 @@ label.run_with_preset_params = Run {0} with preset
 label.view_and_change_parameters_before_running_calculation = View and change parameters before running calculation
 label.view_documentation = View documentation
 label.select_return_type = Select return type
-label.translation_of_params = Translation of {0}
+label.translation_of_params = Translation of {0} (Table {1})
 label.features_for_params = Features for - {0}
 label.annotations_for_params = Annotations for - {0}
 label.generating_features_for_params = Generating features for - {0}
@@ -854,7 +840,6 @@ label.multiharmony = Multi-Harmony
 label.unable_start_web_service_analysis = Unable to start web service analysis
 label.job_couldnt_be_started_check_input = The Job couldn't be started. Please check your input, and the Jalview console for any warning messages.
 label.prompt_each_time = Prompt each time
-label.use_source = Use Source
 label.couldnt_save_project = Couldn't save project
 label.error_whilst_saving_current_state_to = Error whilst saving current state to {0}
 label.error_whilst_loading_project_from = Error whilst loading project from {0}
@@ -880,7 +865,6 @@ label.error_unsupported_owwner_user_colour_scheme = Unsupported owner for User C
 label.save_alignment_to_file = Save Alignment to file
 label.save_features_to_file = Save Features to File
 label.save_annotation_to_file = Save Annotation to File
-label.no_features_on_alignment = No features found on alignment
 label.save_pdb_file = Save PDB File
 label.save_text_to_file = Save Text to File
 label.save_state = Save State
@@ -1080,8 +1064,6 @@ exception.unable_to_create_internet_config = Unable to create an Internet Config
 exception.invocation_target_calling_url = InvocationTargetException while calling openURL: {0}
 exception.illegal_access_calling_url = IllegalAccessException while calling openURL: {0}
 exception.interrupted_launching_browser = InterruptedException while launching browser: {0}
-exception.das_source_doesnt_support_sequence_command = Source {0} does not support the sequence command.
-exception.invalid_das_source = Invalid das source: {0}
 exception.ebiembl_retrieval_failed_on = EBI EMBL XML retrieval failed on {0}:{1}
 exception.no_pdb_records_for_chain = No PDB Records for {0} chain {1}
 exception.unexpected_handling_rnaml_translation_for_pdb = Unexpected exception when handling RNAML translation of PDB data
@@ -1136,10 +1118,6 @@ status.parsing_results = Parsing results.
 status.processing = Processing...
 status.refreshing_web_service_menus = Refreshing Web Service Menus
 status.collecting_job_results = Collecting job results.
-status.fetching_das_sequence_features = Fetching DAS Sequence Features
-status.no_das_sources_active = No DAS Sources Active
-status.das_feature_fetching_cancelled = DAS Feature Fetching Cancelled
-status.das_feature_fetching_complete = DAS Feature Fetching Complete
 status.fetching_db_refs = Fetching db refs
 status.loading_cached_pdb_entries = Loading Cached PDB Entries
 status.searching_for_pdb_structures = Searching for PDB Structures
@@ -1162,8 +1140,6 @@ warn.urls_not_contacted = URLs that could not be contacted
 warn.urls_no_jaba = URLs without any JABA Services
 info.validate_jabaws_server = Validate JabaWS Server ?\n(Look in console output for results)
 label.test_server = Test Server?
-info.you_want_jalview_to_find_uniprot_accessions = Do you want Jalview to find\nUniprot Accession ids for given sequence names?
-label.find_uniprot_accession_ids = Find Uniprot Accession Ids
 label.new_sequence_fetcher = New Sequence Fetcher
 label.additional_sequence_fetcher = Additional Sequence Fetcher
 label.select_database_retrieval_source = Select Database Retrieval Source
@@ -1285,7 +1261,6 @@ label.SEQUENCE_ID_for_DB_ACCESSION1 = Please review your URL links in the 'Conne
 label.SEQUENCE_ID_for_DB_ACCESSION2 = URL links using '$SEQUENCE_ID$' for DB accessions now use '$DB_ACCESSION$'.
 label.do_not_display_again = Do not display this message again
 exception.url_cannot_have_duplicate_id = {0} cannot be used as a label for more than one line
-label.filter = Filter text:
 action.customfilter = Custom only
 action.showall = Show All
 label.insert = Insert:
@@ -1300,7 +1275,6 @@ label.edit_sequence_url_link = Edit sequence URL link
 warn.name_cannot_be_duplicate = User-defined URL names must be unique and cannot be MIRIAM ids
 label.output_seq_details = Output Sequence Details to list all database references
 label.urllinks = Links
-label.default_cache_size = Default Cache Size
 action.clear_cached_items = Clear Cached Items
 label.togglehidden = Show hidden regions
 label.quality_descr = Alignment Quality based on Blosum62 scores
@@ -1353,7 +1327,6 @@ label.colour_by_text = Colour by text
 label.graduated_colour = Graduated Colour
 label.by_text_of = By text of
 label.by_range_of = By range of
-label.filters_tooltip = Click to set or amend filters
 label.or = Or
 label.and = And
 label.sequence_feature_colours = Sequence Feature Colours
@@ -1364,3 +1337,60 @@ label.most_bound_molecules = Most Bound Molecules
 label.most_polymer_residues = Most Polymer Residues
 label.cached_structures = Cached Structures
 label.free_text_search = Free Text Search
+label.backupfiles_confirm_delete = Confirm delete
+label.backupfiles_confirm_delete_old_files = Delete the following older backup files? (see the Backups tab in Preferences for more options)
+label.backupfiles_confirm_save_file = Confirm save file
+label.backupfiles_confirm_save_file_backupfiles_roll_wrong = Something possibly went wrong with the backups of this file.
+label.backupfiles_confirm_save_new_saved_file_ok = The new saved file seems okay.
+label.backupfiles_confirm_save_new_saved_file_not_ok = The new saved file might not be okay.
+label.backups = Backups
+label.backup = Backup
+label.backup_files = Backup Files
+label.enable_backupfiles = Enable backup files
+label.backup_filename_strategy = Backup filename strategy
+label.append_to_filename = Append to filename (%n is replaced by the backup number)
+label.append_to_filename_tooltip = %n in the text will be replaced by the backup number. The text will appear after the filename. See the summary box above.
+label.index_digits = Number of digits to use for the backup number (%n)
+label.summary_of_backups_scheme = Summary of backup scheme
+label.increment_index = Increase appended text numbers - newest file has largest number.
+label.reverse_roll = "Roll" appended text numbers - newest backup file is always number 1.
+label.keep_files = Deleting old backup files
+label.keep_all_backup_files = Do not delete old backup files
+label.keep_only_this_number_of_backup_files = Keep only this number of most recent backup files
+label.autodelete_old_backup_files = Autodelete old backup files:
+label.always_ask = Always ask
+label.auto_delete = Automatically delete
+label.filename = filename
+label.braced_oldest = (oldest)
+label.braced_newest = (most recent)
+label.configuration = Configuration
+label.configure_feature_tooltip = Click to configure variable colour or filters
+label.schemes = Schemes
+label.customise = Customise
+label.default = Default
+label.single_file = Single backup
+label.keep_all_versions = Keep all versions
+label.rolled_backups = Rolled backup files
+label.previously_saved_scheme = Previously saved scheme
+label.no_backup_files = NO BACKUP FILES
+label.include_backup_files = Include backup files
+label.cancel_changes = Cancel changes
+label.warning_confirm_change_reverse = Warning!\nIf you change the increment/decrement of the backup filename number, without changing the suffix or number of digits,\nthis may cause loss of backup files created with the previous backup filename scheme.\nAre you sure you wish to do this?
+label.change_increment_decrement = Change increment/decrement?
+label.was_previous = was {0}
+label.newerdelete_replacement_line = Backup file\n''{0}''\t(modified {2}, size {4})\nis to be deleted and replaced by apparently older file\n''{1}''\t(modified {3}, size {5}).
+label.confirm_deletion_or_rename = Confirm deletion of ''{0}'' or rename to ''{1}''?
+label.newerdelete_line = Backup file\n''{0}''\t(modified {2}, size {4})\nis to be deleted but is newer than the oldest remaining backup file\n''{1}''\t(modified {3}, size {5}).
+label.confirm_deletion = Confirm deletion of ''{0}''?
+label.delete = Delete
+label.rename = Rename
+label.keep = Keep
+label.file_info = (modified {0}, size {1})
+label.annotation_name = Annotation Name
+label.annotation_description = Annotation Description 
+label.edit_annotation_name_description = Edit Annotation Name/Description
+label.alignment = alignment
+label.pca = PCA
+label.create_image_of = Create {0} image of {1}
+label.click_to_edit = Click to edit, right-click for menu
+label.by_annotation_tooltip = Annotation Colour is configured from the main Colour menu
index 756d1c9..ade37ff 100644 (file)
@@ -30,6 +30,7 @@ action.minimize_associated_windows = Minimizar ventanas asociadas
 action.close_all = Cerrar todo
 action.load_project = Cargar proyecto
 action.save_project = Guardar proyecto
+action.save_project_as = Guardar proyecto como...
 action.quit = Salir
 label.quit_jalview = Salir Javliew?
 action.expand_views = Expandir vistas
@@ -116,10 +117,8 @@ action.select = Seleccionar
 action.new_view = Nueva vista
 action.close = Cerrar
 action.add = Añadir
-action.save_as_default = Guardar como por defecto
 action.save_as = Guardar como
 action.save = Guardar
-action.cancel_fetch = Cancelar búsqueda
 action.change_font = Cambiar Fuente
 action.change_font_tree_panel = Cambiar fuente (panel del Ã¡rbol)
 action.colour = Color
@@ -138,7 +137,6 @@ action.fetch_db_references = Recuperar referencias a base de datos
 action.view_flanking_regions = Mostrar flancos
 label.view_flanking_regions = Mostrar los datos de la secuencia a ambos lados de las subsecuencias implicadas en este alineamiento
 label.structures_manager = Administrar estructuras
-label.nickname = Sobrenombre:
 label.url\: = URL:
 label.url = URL 
 label.input_file_url = Introducir URL en el fichero de entrada
@@ -160,7 +158,6 @@ label.current_parameter_set_name = Nombre actual del conjunto de par
 label.service_action = Acción de servicio:
 label.post_url = POST URL: 
 label.url_suffix = URL Sufijo
-label.sequence_source = Fuente de la secuencia
 label.per_seq = por secuencia
 label.result_vertically_separable = Los resultados son separables verticalmente
 label.amend = Modificar
@@ -170,10 +167,9 @@ label.principal_component_analysis = An
 label.average_distance_identity = Distancia Media Usando % de Identidad
 label.neighbour_joining_identity = Unir vecinos utilizando % de Identidad
 label.choose_calculation = Elegir el cálculo
-label.treecalc_title = {0} utilizando {1}
+label.calc_title = {0} utilizando {1}
 label.tree_calc_av = Distancia media
 label.tree_calc_nj = Unir vecinos
-label.select_score_model = Selecciones modelo de puntuación
 label.score_model_pid = % Identidad
 label.score_model_blosum62 = BLOSUM62
 label.score_model_pam250 = PAM 250
@@ -200,6 +196,7 @@ label.colourScheme_purine/pyrimidine = Purina/Pirimidina
 label.colourScheme_nucleotide = Nucleótido
 label.colourScheme_t-coffee_scores = Puntuación del T-Coffee
 label.colourScheme_rna_helices = Por hélices de RNA
+label.colourScheme_sequence_id = Color de ID de secuencia
 label.blc = BLC
 label.fasta = Fasta
 label.msf = MSF
@@ -323,7 +320,6 @@ label.status =  [Estado]
 label.channels = Canales
 label.channel_title_item_count = {0} ({1})
 label.blog_item_published_on_date = {0} {1} 
-label.select_das_service_from_table = Seleccionar servicio DAS de la tabla para leer una descripción completa aquí.
 label.session_update = Actualizar sesión
 label.new_vamsas_session = Nueva sesión Vamsas
 action.save_vamsas_session = Guardar Sesión Vamsas
@@ -340,7 +336,6 @@ label.load_colours = Cargar colores
 label.save_colours = Guardar colores
 label.load_colours_tooltip = Cargar colores y filtros desde fichero
 label.save_colours_tooltip = Guardar colores y filtros en fichero
-label.fetch_das_features = Recuperar funciones DAS
 label.selected_database_to_fetch_from = Seleccionada {0} Base de datos {1} para buscar de {2} 
 label.database_param = Base de datos: {0}
 label.example = Ejemplo
@@ -377,9 +372,6 @@ label.couldnt_find_pdb_id_in_file = No se pudo encontrar un Id PDB en el fichero
 label.no_pdb_id_in_file = No hay un Id PDB en el fichero
 label.couldnt_read_pasted_text = No se pudo leer el texto pegado {0}
 label.error_parsing_text = Error analizando el texto
-label.enter_local_das_source = Intruduzca el Nickname & URL de la fuente DAS local
-label.you_can_only_edit_or_remove_local_das_sources = Sólo puedes editar o eliminar fuentes DAS locales!
-label.public_das_source = Fuente pública DAS - no editable
 label.input_alignment_from_url = Alineamiento de entrada desde URL
 label.input_alignment = Alineamiento de entrada
 label.couldnt_import_as_vamsas_session = No se pudo importar {0} como una nueva sesión Vamsas.
@@ -396,8 +388,6 @@ label.invalid_url = URL Invalido!
 label.error_loading_file = Error al cargar el fichero
 label.problems_opening_file = Encontrados problemas al abrir el fichero {0}!!
 label.file_open_error = Error al abrir el fichero
-label.no_das_sources_selected_warn = No han sido seleccionadas fuentes DAS.\nPor favor, seleccione algunas fuentes y\npruebe de nuevo.
-label.no_das_sources_selected_title = No han sido seleccionadas fuentes DAS
 label.colour_scheme_exists_overwrite = El esquema de colores {0} ya existe.\nContinuar guardando el esquema de colores como {1}?
 label.duplicate_scheme_name = Duplicar nombre de esquema
 label.jalview_new_questionnaire = Hay un nuevo cuestionario disponible. Querr\u00EDa completarlo ahora ?\n
@@ -469,6 +459,10 @@ label.edit_name_description = Editar nombre/descripci
 label.create_sequence_feature = Crear función de secuencia
 label.edit_sequence = Editar secuencia
 label.edit_sequences = Editar secuencias
+label.insert_gap = Insertar 1 hueco
+label.insert_gaps = Insertar {0} huecos
+label.delete_gap = Borrar 1 hueco
+label.delete_gaps = Borrar {0} huecos
 label.sequence_details = Detalles de la secuencia
 label.jmol_help = Ayuda de Jmol
 # Todos/Todas is gender-sensitive, but currently only used for feminine (cadena / anotación)! 
@@ -578,7 +572,6 @@ label.visual = Visual
 label.connections = Conexiones
 label.output = Salida
 label.editing = Edición
-label.das_settings = Configuración DAS
 label.web_services = Servicios web
 label.right_click_to_edit_currently_selected_parameter = Haga clic en el botón derecho para editar el parámetro seleccionado actualmente.
 label.let_jmol_manage_structure_colours = Permitir que Jmol gestione la estructuras cromáticas
@@ -591,10 +584,6 @@ label.delete_service_url = Borrar la URL del servicio
 label.details = Detalles
 label.options = Opciones
 label.parameters = Paramétros
-label.available_das_sources = Fuentes DAS disponibles
-label.full_details = Detalles completos
-label.authority = Autoridad
-label.type = Tipo
 label.proxy_server = Servidor proxy
 label.file_output = Fichero de salida
 label.select_input_type = Seleccionar el tipo de entrada
@@ -657,9 +646,6 @@ label.get_cross_refs = Obtener referencias cruzadas
 label.sort_alignment_new_tree = Alinear el alineamiento con el nuevo Ã¡rbol
 label.add_sequences = Añadir secuencias
 label.new_window = Nueva ventana
-label.refresh_available_sources = Refrescar las fuentes disponibles
-label.use_registry = Utilizar el registro
-label.add_local_source = Añadir fuente local
 label.set_as_default = Establecer por defecto
 label.show_labels = Mostrar etiquetas
 label.associate_nodes_with = Asociar nodos con
@@ -701,7 +687,7 @@ label.run_with_preset_params = Ejecutar {0} con preconfiguraci
 label.view_and_change_parameters_before_running_calculation = Ver y cambiar los parámetros antes de lanzar el cálculo
 label.view_documentation = Ver documentación
 label.select_return_type = Seleccionar el tipo de retorno
-label.translation_of_params = Traducción de {0}
+label.translation_of_params = Traducción de {0} (Tabla {1})
 label.features_for_params = Características de - {0}
 label.annotations_for_params = Anotaciones de - {0}
 label.generating_features_for_params = Generando características de - {0}
@@ -779,7 +765,6 @@ label.multiharmony = Multi-Harmony
 label.unable_start_web_service_analysis = No es posible iniciar el servicio web de análisis
 label.job_couldnt_be_started_check_input = El trabajo no puede arrancarse. Por favor, compruebe los parámetros de entrada y los mensajes de advertencia de la consola de Jalview.
 label.prompt_each_time = Preguntar siempre
-label.use_source = Fuente
 label.couldnt_save_project = No es posible guardar el proyecto
 label.error_whilst_saving_current_state_to = Error mientras se guardaba el estado a {0}
 label.error_whilst_loading_project_from = Error cargando el proyecto desde  {0}
@@ -805,7 +790,6 @@ label.error_unsupported_owwner_user_colour_scheme = Propietario no soportado par
 label.save_alignment_to_file = Guardar Alineamiento en fichero
 label.save_features_to_file = Guardar Características en un fichero
 label.save_annotation_to_file = Guardar Anotación en un fichero
-label.no_features_on_alignment = No se han encontrado características en el alineamiento
 label.save_pdb_file = Guardar fichero PDB 
 label.save_text_to_file = Guardar Texto en un fichero
 label.save_state = Guardar estado
@@ -1005,8 +989,6 @@ exception.unable_to_create_internet_config = Imposible crear una instancia de co
 exception.invocation_target_calling_url = InvocationTargetException mientras se invocaba openURL: {0}
 exception.illegal_access_calling_url = IllegalAccessException mientras se invocaba openURL: {0}
 exception.interrupted_launching_browser = InterruptedException mientras se lanzaba el navegador: {0}
-exception.das_source_doesnt_support_sequence_command = La fuente {0} no soporta el comando sequence.
-exception.invalid_das_source = Fuente DAS no válida: {0}
 exception.ebiembl_retrieval_failed_on = La recuperación de datos EBI EMBL XML ha fallado en {0}:{1}
 exception.no_pdb_records_for_chain = No se han encontrado registros {0} para la cadena {1}
 exception.unexpected_handling_rnaml_translation_for_pdb = Excepcion inesperada cuando se traducían a RNAML los datos PDB
@@ -1058,10 +1040,6 @@ status.parsing_results = Parseando resultados.
 status.processing = Procesando...
 status.refreshing_web_service_menus = Refrescando los menús de servicios web
 status.collecting_job_results = Recolectando los resultados de los trabajos.
-status.fetching_das_sequence_features = Recuperando las características DAS de las secuencias
-status.no_das_sources_active = No existe ninguna fuente DAS activa
-status.das_feature_fetching_cancelled = Recuperación de características DAS cancelada
-status.das_feature_fetching_complete = Recuperación de características DAS completada
 status.fetching_db_refs = Recuperando db refs
 label.font_doesnt_have_letters_defined = La fuente no tiene letras definidas\npor lo que no puede emplease\ncon datos de alineamientos
 label.font_too_small = Tamaño de la letra es demasiado pequeña
@@ -1078,8 +1056,6 @@ warn.server_didnt_pass_validation = El servicio no ha pasado la validaci\u00F3n.
 warn.url_must_contain = La URL de la secuencia debe contener $SEQUENCE_ID$, $DB_ACCESSION$ o un regex
 info.validate_jabaws_server = \u00BFValidar el servidor JabaWS?\n(Consulte la consola de salida para obtener los resultados)
 label.test_server = Â¿Probar servidor?
-info.you_want_jalview_to_find_uniprot_accessions = \u00BFDesea que Jalview encuentre\nUniprot Accession ids para los nombres de secuencias dados?
-label.find_uniprot_accession_ids = Buscar Uniprot Accession Ids
 label.new_sequence_fetcher = Añadir recuperador de secuencias
 label.additional_sequence_fetcher = Recuperador de secuencia adicional
 label.select_database_retrieval_source = Seleccionar fuente de recuperación de bases de datos
@@ -1286,7 +1262,6 @@ label.SEQUENCE_ID_for_DB_ACCESSION1 = Por favor, revise sus URLs en la pesta
 label.SEQUENCE_ID_for_DB_ACCESSION2 = URL enlaza usando '$SEQUENCE_ID$' para accesiones DB ahora usar '$DB_ACCESSION$'.
 label.do_not_display_again = No mostrar este mensaje de nuevo
 exception.url_cannot_have_duplicate_id = {0} no puede ser usada como etiqueta en más de un enlace
-label.filter = Filtrar texto:
 action.customfilter = Sólo personalizado
 action.showall = Mostrar todo
 label.insert = Insertar:
@@ -1301,7 +1276,6 @@ label.edit_sequence_url_link = Editar link de secuencia URL
 warn.name_cannot_be_duplicate = Los nombres URL definidos por el usuario deben ser Ãºnicos y no pueden ser ids de MIRIAM
 label.output_seq_details = Seleccionar Detalles de la secuencia para ver todas
 label.urllinks = Enlaces
-label.default_cache_size = Tamaño del caché por defecto
 action.clear_cached_items = Borrar elementos en caché
 label.quality_descr = Calidad de alineamiento basándose en puntuación Blosum62
 label.conservation_descr = Conservación del alineamiento total menos de {0}% huecos
@@ -1354,7 +1328,6 @@ label.colour_by_text = Colorear por texto
 label.graduated_colour = Color graduado
 label.by_text_of = Por texto de
 label.by_range_of = Por rango de
-label.filters_tooltip = Haga clic para configurar o modificar los filtros
 label.or = O
 label.and = Y
 label.sequence_feature_colours = Colores de características de las secuencias
@@ -1365,3 +1338,60 @@ label.most_bound_molecules = M
 label.most_polymer_residues = Más Residuos de Polímeros
 label.cached_structures = Estructuras en Caché
 label.free_text_search = Búsqueda de texto libre
+label.backupfiles_confirm_delete = Confirmar borrar
+label.backupfiles_confirm_delete_old_files = Â¿Borrar los siguientes archivos? (ver la pestaña 'Copias' de la ventana de Preferencias para más opciones)
+label.backupfiles_confirm_save_file = Confirmar guardar archivo
+label.backupfiles_confirm_save_file_backupfiles_roll_wrong = Posiblemente algo está mal con los archivos de respaldos.
+label.backupfiles_confirm_save_new_saved_file_ok = El nuevo archivo guardado parece estar bien.
+label.backupfiles_confirm_save_new_saved_file_not_ok = El nuevo archivo guardado podría no estar bien.
+label.backups = Respaldos
+label.backup = Respaldo
+label.backup_files = Archivos de respaldos
+label.enable_backupfiles = Habilitar archivos de respaldos
+label.backup_filename_strategy = Estrategia de nombres de archivo de respaldos
+label.append_to_filename = Adjuntar texto (%n es reemplazado por el número de respaldo)
+label.append_to_filename_tooltip = %n en el texto será reemplazado por el número de respaldo. El texto será después del nombre del archivo. Vea el cuadro de resumen arriba.
+label.index_digits = Número de dígitos a utilizar para el número de respaldo.
+label.summary_of_backups_scheme = Resumen del esquema de copias de seguridad
+label.increment_index = Aumente los números de texto adjuntos: el archivo más nuevo tiene el número más grande
+label.reverse_roll = Ciclos de texto adjuntos: el respaldo más reciente es siempre el número 1
+label.keep_files = Borrando los respaldos antiguos
+label.keep_all_backup_files = No borrar respaldos antiguas
+label.keep_only_this_number_of_backup_files = Mantenga solo este número de respaldos más recientes
+label.autodelete_old_backup_files = Borrer automáticamente respaldos antiguos:
+label.always_ask = Pregunta siempre
+label.auto_delete = Borrer automáticamente
+label.filename = nombre_de_archivo
+label.braced_oldest = (mas antiguo)
+label.braced_newest = (mas nuevo)
+label.configuration = Configuración
+label.configure_feature_tooltip = Haga clic para configurar el color o los filtros
+label.schemes = Esquemas
+label.customise = Personalizado
+label.default = Defecto
+label.single_file = Solo uno respaldo
+label.keep_all_versions = Mantener todas las versiones
+label.rolled_backups = Ciclos respaldos
+label.previously_saved_scheme = Esquema previamente guardado
+label.no_backup_files = NO ARCHIVOS DE RESPALDOS
+label.include_backup_files = Incluir archivos de respaldos
+label.cancel_changes = Cancelar cambios
+label.warning_confirm_change_reverse = Â¡Advertencia!\nSi cambia el incremento/decremento del número de archivos de respaldos, sin cambiar el sufijo o número de dígitos,\nesto puede causar la pérdida de los archivos de respaldos creados con el esquema anterior de nombre de archivo de respaldos.\n¿Está seguro de que desea hacer esto?
+label.change_increment_decrement = Â¿Cambiar de incremento/decremento?
+label.was_previous = era {0}
+label.newerdelete_replacement_line = El archivo de respaldo\n''{0}''\t(modificado {2}, tamaño {4})\nserá borrado y reemplazarse por un archivo aparentemente más antiguo\n''{1}''\t(modificado {3}, tamaño {5}).
+label.confirm_deletion_or_rename = Confirmar borrar ''{0}'', o cambiar el nombre a ''{1}''?
+label.newerdelete_line = El archivo de respaldo\n''{0}''\t(modificado {2}, tamaño {4})\nserá borrado pero es mas nuevo que el archivo de respaldo restante más antiguo\n''{1}''\t(modified {3}, size {5}).
+label.confirm_deletion = Confirmar eliminar ''{0}''?
+label.delete = Borrar
+label.rename = Cambiar
+label.keep = Mantener
+label.file_info = (modificado {0}, tamaño {1})
+label.annotation_name = Nombre de la anotación
+label.annotation_description = Descripción de la anotación 
+label.edit_annotation_name_description = Editar el nombre/descripción de la anotación
+label.alignment = alineamiento
+label.pca = ACP
+label.create_image_of = Crear imagen {0} de {1}
+label.click_to_edit = Haga clic para editar, clic en el botón derecho para ver el menú  
+label.by_annotation_tooltip = El color de anotación se configura desde el menú principal de colores
index 7511ad2..07dee98 100755 (executable)
                                                        </xs:annotation>
                                                </xs:attribute>
                                                <xs:attributeGroup ref="jv:swingwindow" />
+                                               <xs:attribute name="linkToAllViews" use="optional" default="false" type="xs:boolean" />
+                                       </xs:complexType>
+                               </xs:element>
+                               <xs:element name="PcaViewer" minOccurs="0" maxOccurs="unbounded">
+                                       <xs:complexType>
+                                               <xs:sequence>
+                                                       <xs:element name="sequencePoint" minOccurs="1" maxOccurs="unbounded">
+                                                               <xs:complexType>
+                                                                       <xs:attribute name="sequenceRef" type="xs:string" />
+                                                                       <xs:attributeGroup ref="jv:position" />
+                                                               </xs:complexType>
+                                                       </xs:element>
+                                                       <xs:element name="axis" minOccurs="3" maxOccurs="3">
+                                                               <xs:annotation>
+                                                                       <xs:documentation>
+                                                                               endpoints of X, Y and Z axes in that order
+                                                                       </xs:documentation>
+                                                               </xs:annotation>
+                                                               <xs:complexType>
+                                                                       <xs:attributeGroup ref="jv:position" />
+                                                               </xs:complexType>
+                                                       </xs:element>
+                                                       <xs:element name="seqPointMin">
+                                                               <xs:complexType>
+                                                                       <xs:attributeGroup ref="jv:position" />
+                                                               </xs:complexType>
+                                                       </xs:element>
+                                                       <xs:element name="seqPointMax">
+                                                               <xs:complexType>
+                                                                       <xs:attributeGroup ref="jv:position" />
+                                                               </xs:complexType>
+                                                       </xs:element>
+                                                       <xs:element name="pcaData" type="jv:PcaDataType" />
+                                               </xs:sequence>
+                                               <xs:attribute name="title" type="xs:string" />
+                                               <xs:attribute name="scoreModelName" type="xs:string" />
+                                               <xs:attribute name="xDim" type="xs:int" />
+                                               <xs:attribute name="yDim" type="xs:int" />
+                                               <xs:attribute name="zDim" type="xs:int" />
+                                               <xs:attribute name="bgColour" type="xs:int" />
+                                               <xs:attribute name="scaleFactor" type="xs:float" />
+                                               <xs:attribute name="showLabels" type="xs:boolean" />
+                                               <xs:attribute name="linkToAllViews" type="xs:boolean" />
+                                               <xs:attributeGroup ref="jv:SimilarityParams" />
+                                               <xs:attributeGroup ref="jv:swingwindow" />
                                        </xs:complexType>
                                </xs:element>
                                <xs:element name="FeatureSettings" minOccurs="0">
                <xs:attribute name="predefinedColours" type="xs:boolean"
                        use="optional" />
        </xs:complexType>
-
+       <xs:attributeGroup name="SimilarityParams">
+               <xs:annotation>
+                       <xs:documentation>
+                               parameters that condition a similarity score calculation
+                       </xs:documentation>
+               </xs:annotation>
+               <xs:attribute name="includeGaps" type="xs:boolean" />
+               <xs:attribute name="matchGaps" type="xs:boolean" />
+               <xs:attribute name="includeGappedColumns" type="xs:boolean" />
+               <xs:attribute name="denominateByShortestLength" type="xs:boolean" />
+       </xs:attributeGroup>
+       <xs:attributeGroup name="position">
+               <xs:attribute name="xPos" type="xs:float" />
+               <xs:attribute name="yPos" type="xs:float" />
+               <xs:attribute name="zPos" type="xs:float" />
+       </xs:attributeGroup>
+       <xs:complexType name="PcaDataType">
+               <xs:annotation>
+                       <xs:documentation>
+                               The results of a PCA calculation
+                       </xs:documentation>
+               </xs:annotation>
+               <xs:sequence>
+                       <xs:element name="pairwiseMatrix" type="jv:DoubleMatrix" />
+                       <xs:element name="tridiagonalMatrix" type="jv:DoubleMatrix" />
+                       <xs:element name="eigenMatrix" type="jv:DoubleMatrix" />
+               </xs:sequence>
+       </xs:complexType>
+       <xs:complexType name="DoubleVector">
+               <xs:sequence>
+                       <xs:element name="v" type="xs:double" minOccurs="0" maxOccurs="unbounded" />
+               </xs:sequence>
+       </xs:complexType>
+       <xs:complexType name="DoubleMatrix">
+               <xs:sequence>
+                       <xs:element name="row" type="jv:DoubleVector" minOccurs="0" maxOccurs="unbounded" />
+                       <xs:element name="D" minOccurs="0" type="jv:DoubleVector" />
+                       <xs:element name="E" minOccurs="0" type="jv:DoubleVector" />
+               </xs:sequence>
+               <xs:attribute name="rows"  type="xs:int" />
+               <xs:attribute name="columns" type="xs:int" />
+       </xs:complexType>
 </xs:schema>
index d1217bf..0dfd383 100644 (file)
@@ -74,12 +74,15 @@ import java.util.TreeMap;
  */
 public class AlignmentUtils
 {
-
   private static final int CODON_LENGTH = 3;
 
   private static final String SEQUENCE_VARIANT = "sequence_variant:";
 
-  private static final String ID = "ID";
+  /*
+   * the 'id' attribute is provided for variant features fetched from
+   * Ensembl using its REST service with JSON format 
+   */
+  public static final String VARIANT_ID = "id";
 
   /**
    * A data model to hold the 'normal' base value at a position, and an optional
@@ -2575,15 +2578,15 @@ public class AlignmentUtils
             peptidePos, var.getSource());
 
     StringBuilder attributes = new StringBuilder(32);
-    String id = (String) var.variant.getValue(ID);
+    String id = (String) var.variant.getValue(VARIANT_ID);
     if (id != null)
     {
       if (id.startsWith(SEQUENCE_VARIANT))
       {
         id = id.substring(SEQUENCE_VARIANT.length());
       }
-      sf.setValue(ID, id);
-      attributes.append(ID).append("=").append(id);
+      sf.setValue(VARIANT_ID, id);
+      attributes.append(VARIANT_ID).append("=").append(id);
       // TODO handle other species variants JAL-2064
       StringBuilder link = new StringBuilder(32);
       try
index 2ad8487..9611a4c 100644 (file)
@@ -194,10 +194,11 @@ public class Dna
   }
 
   /**
+   * Translates cDNA using the specified code table
    * 
    * @return
    */
-  public AlignmentI translateCdna()
+  public AlignmentI translateCdna(GeneticCodeI codeTable)
   {
     AlignedCodonFrame acf = new AlignedCodonFrame();
 
@@ -209,7 +210,7 @@ public class Dna
     for (s = 0; s < sSize; s++)
     {
       SequenceI newseq = translateCodingRegion(selection.get(s),
-              seqstring[s], acf, pepseqs);
+              seqstring[s], acf, pepseqs, codeTable);
 
       if (newseq != null)
       {
@@ -429,11 +430,12 @@ public class Dna
    * @param acf
    *          Definition of global ORF alignment reference frame
    * @param proteinSeqs
+   * @param codeTable
    * @return sequence ready to be added to alignment.
    */
   protected SequenceI translateCodingRegion(SequenceI selection,
           String seqstring, AlignedCodonFrame acf,
-          List<SequenceI> proteinSeqs)
+          List<SequenceI> proteinSeqs, GeneticCodeI codeTable)
   {
     List<int[]> skip = new ArrayList<>();
     int[] skipint = null;
@@ -466,9 +468,8 @@ public class Dna
         /*
          * Filled up a reading frame...
          */
-        AlignedCodon alignedCodon = new AlignedCodon(cdp[0], cdp[1],
-                cdp[2]);
-        String aa = ResidueProperties.codonTranslate(new String(codon));
+        AlignedCodon alignedCodon = new AlignedCodon(cdp[0], cdp[1], cdp[2]);
+        String aa = codeTable.translate(new String(codon));
         rf = 0;
         final String gapString = String.valueOf(gapChar);
         if (aa == null)
index 191f6e8..3cbef6d 100644 (file)
  */
 package jalview.analysis;
 
+import jalview.api.AlignViewportI;
+import jalview.api.FinderI;
 import jalview.datamodel.AlignmentI;
+import jalview.datamodel.Range;
 import jalview.datamodel.SearchResultMatchI;
 import jalview.datamodel.SearchResults;
 import jalview.datamodel.SearchResultsI;
 import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
+import jalview.datamodel.VisibleContigsIterator;
 import jalview.util.Comparison;
 
-import java.util.ArrayList;
 import java.util.List;
 import java.util.Vector;
 
 import com.stevesoft.pat.Regex;
 
-public class Finder
+/**
+ * Implements the search algorithm for the Find dialog
+ */
+public class Finder implements FinderI
 {
-  /**
-   * Implements the search algorithms for the Find dialog box.
+  /*
+   * matched residue locations
    */
-  SearchResultsI searchResults;
+  private SearchResultsI searchResults;
 
-  AlignmentI alignment;
+  /*
+   * sequences matched by id or description
+   */
+  private Vector<SequenceI> idMatches;
 
-  SequenceGroup selection = null;
+  /*
+   * the viewport to search over
+   */
+  private AlignViewportI viewport;
 
-  Vector<SequenceI> idMatch = null;
+  /*
+   * sequence index in alignment to search from
+   */
+  private int sequenceIndex;
 
-  boolean caseSensitive = false;
+  /*
+   * column position in sequence to search from, base 0
+   * - absolute column number including any hidden columns
+   * (position after start of last match for a repeat search)
+   */
+  private int columnIndex;
 
-  private boolean includeDescription = false;
+  /**
+   * Constructor for searching a viewport
+   * 
+   * @param av
+   */
+  public Finder(AlignViewportI av)
+  {
+    this.viewport = av;
+    this.sequenceIndex = 0;
+    this.columnIndex = -1;
+  }
 
-  boolean findAll = false;
+  @Override
+  public void findAll(String theSearchString, boolean matchCase,
+          boolean searchDescription)
+  {
+    /*
+     * search from the start
+     */
+    sequenceIndex = 0;
+    columnIndex = -1;
 
-  Regex regex = null;
+    doFind(theSearchString, matchCase, searchDescription, true);
 
-  /**
-   * holds last-searched position between calls to find(false)
-   */
-  int seqIndex = 0, resIndex = -1;
+    /*
+     * reset to start for next search
+     */
+    sequenceIndex = 0;
+    columnIndex = -1;
+  }
 
-  public Finder(AlignmentI alignment, SequenceGroup selection)
+  @Override
+  public void findNext(String theSearchString, boolean matchCase,
+          boolean searchDescription)
   {
-    this.alignment = alignment;
-    this.selection = selection;
+    doFind(theSearchString, matchCase, searchDescription, false);
+    
+    if (searchResults.isEmpty() && idMatches.isEmpty())
+    {
+      /*
+       * search failed - reset to start for next search
+       */
+      sequenceIndex = 0;
+      columnIndex = -1;
+    }
   }
 
   /**
-   * restart search at given sequence and residue on alignment and (optionally)
-   * contained in selection
+   * Performs a 'find next' or 'find all'
    * 
-   * @param alignment
-   * @param selectionGroup
-   * @param seqIndex
-   * @param resIndex
+   * @param theSearchString
+   * @param matchCase
+   * @param searchDescription
+   * @param findAll
    */
-  public Finder(AlignmentI alignment, SequenceGroup selectionGroup,
-          int seqIndex, int resIndex)
+  protected void doFind(String theSearchString, boolean matchCase,
+          boolean searchDescription, boolean findAll)
   {
-    this(alignment, selectionGroup);
-    this.seqIndex = seqIndex;
-    this.resIndex = resIndex;
-  }
+    String searchString = matchCase ? theSearchString
+            : theSearchString.toUpperCase();
+    Regex searchPattern = new Regex(searchString);
+    searchPattern.setIgnoreCase(!matchCase);
 
-  public boolean find(String searchString)
-  {
-    boolean hasResults = false;
-    if (!caseSensitive)
-    {
-      searchString = searchString.toUpperCase();
-    }
-    regex = new Regex(searchString);
-    regex.setIgnoreCase(!caseSensitive);
     searchResults = new SearchResults();
-    idMatch = new Vector<SequenceI>();
-    String item = null;
-    boolean found = false;
-    int end = alignment.getHeight();
+    idMatches = new Vector<>();
 
-    // /////////////////////////////////////////////
-
-    if (selection != null)
+    SequenceGroup selection = viewport.getSelectionGroup();
+    if (selection != null && selection.getSize() < 1)
     {
-      if ((selection.getSize() < 1)
-              || ((selection.getEndRes() - selection.getStartRes()) < 2))
-      {
-        selection = null;
-      }
+      selection = null; // ? ignore column-only selection
     }
-    SearchResultMatchI lastm = null;
 
-    while (!found && (seqIndex < end))
-    {
-      SequenceI seq = alignment.getSequenceAt(seqIndex);
+    AlignmentI alignment = viewport.getAlignment();
+    int end = alignment.getHeight();
 
-      if ((selection != null && selection.getSize() > 0)
-              && !selection.getSequences(null).contains(seq))
+    while (sequenceIndex < end)
+    {
+      SequenceI seq = alignment.getSequenceAt(sequenceIndex);
+      boolean found = findNextMatch(seq, searchString, searchPattern,
+              searchDescription);
+      if (found && !findAll)
       {
-        seqIndex++;
-        resIndex = -1;
-
-        continue;
+        return;
       }
-      if (resIndex < 0)
+      if (!found)
       {
-        resIndex = 0;
-        // test for one off matches - sequence position and sequence ID
-        // //// is the searchString a residue number?
-        try
-        {
-          int res = Integer.parseInt(searchString);
-          // possibly a residue number - check if valid for seq
-          if (seq.getEnd() >= res)
-          {
-            searchResults.addResult(seq, res, res);
-            hasResults = true;
-            // resIndex=seq.getLength();
-            // seqIndex++;
-            if (!findAll)
-            {
-              found = true;
-              break;
-            }
-          }
-        } catch (NumberFormatException ex)
-        {
-        }
-
-        if (regex.search(seq.getName()) && !idMatch.contains(seq))
-        {
-          idMatch.addElement(seq);
-          hasResults = true;
-          if (!findAll)
-          {
-            // stop and return the match
-            found = true;
-            break;
-          }
-        }
-
-        if (isIncludeDescription() && seq.getDescription() != null
-                && regex.search(seq.getDescription())
-                && !idMatch.contains(seq))
-        {
-          idMatch.addElement(seq);
-          hasResults = true;
-          if (!findAll)
-          {
-            // stop and return the match
-            found = true;
-            break;
-          }
-        }
+        sequenceIndex++;
+        columnIndex = -1;
       }
-      item = seq.getSequenceAsString();
+    }
+  }
 
-      if ((selection != null)
-              && (selection.getEndRes() < alignment.getWidth() - 1))
-      {
-        item = item.substring(0, selection.getEndRes() + 1);
-      }
+  /**
+   * Answers the start-end column range of the visible region of
+   * <code>sequence</code> starting at or after the given <code>column</code>.
+   * If there are no hidden columns, this just returns the remaining width of
+   * the sequence. The range is restricted to the current <code>selection</code>
+   * if there is one. Answers null if there are no visible columns at or after
+   * <code>column</code>.
+   */
+  protected Range getNextVisibleSequenceRegion(SequenceI sequence,
+          int column)
+  {
+    int seqColStart = column;
+    int seqColEnd = sequence.getLength() - 1;
 
-      // /Shall we ignore gaps???? - JBPNote: Add Flag for forcing this or not
-      StringBuilder noGapsSB = new StringBuilder();
-      int insertCount = 0;
-      List<Integer> spaces = new ArrayList<Integer>();
+    /*
+     * restrict search to (next) visible column region, 
+     * in case there are hidden columns
+     */
+    AlignmentI alignment = viewport.getAlignment();
+    VisibleContigsIterator visibleRegions = alignment.getHiddenColumns()
+            .getVisContigsIterator(column, alignment.getWidth(),
+                    false);
+    int[] visible = visibleRegions.hasNext() ? visibleRegions.next() : null;
+    if (visible == null)
+    {
+      columnIndex = seqColEnd + 1;
+      return null;
+    }
+    seqColStart = Math.max(seqColStart, visible[0]);
+    seqColEnd = Math.min(seqColEnd, visible[1]);
 
-      for (int j = 0; j < item.length(); j++)
+    /*
+     * restrict search to selected region if there is one
+     */
+    SequenceGroup selection = viewport.getSelectionGroup();
+    if (selection != null)
+    {
+      int selectionStart = selection.getStartRes();
+      int selectionEnd = selection.getEndRes();
+      if (selectionStart > seqColEnd || selectionEnd < seqColStart)
       {
-        if (!Comparison.isGap(item.charAt(j)))
-        {
-          noGapsSB.append(item.charAt(j));
-          spaces.add(Integer.valueOf(insertCount));
-        }
-        else
-        {
-          insertCount++;
-        }
+        /*
+         * sequence region doesn't overlap selection region 
+         */
+        columnIndex = seqColEnd + 1;
+        return null;
       }
+      seqColStart = Math.max(seqColStart, selectionStart);
+      seqColEnd = Math.min(seqColEnd, selectionEnd);
+    }
 
-      String noGaps = noGapsSB.toString();
-      for (int r = resIndex; r < noGaps.length(); r++)
-      {
+    return new Range(seqColStart, seqColEnd);
+  }
 
-        if (regex.searchFrom(noGaps, r))
-        {
-          resIndex = regex.matchedFrom();
-
-          if ((selection != null && selection.getSize() > 0) && (resIndex
-                  + spaces.get(resIndex) < selection.getStartRes()))
-          {
-            continue;
-          }
-          // if invalid string used, then regex has no matched to/from
-          int sres = seq.findPosition(resIndex + spaces.get(resIndex));
-          int eres = seq.findPosition(regex.matchedTo() - 1
-                  + (spaces.get(regex.matchedTo() - 1)));
-          // only add result if not contained in previous result
-          if (lastm == null || (lastm.getSequence() != seq
-                  || (!(lastm.getStart() <= sres
-                          && lastm.getEnd() >= eres))))
-          {
-            lastm = searchResults.addResult(seq, sres, eres);
-          }
-          hasResults = true;
-          if (!findAll)
-          {
-            // thats enough, break and display the result
-            found = true;
-            resIndex++;
-
-            break;
-          }
-
-          r = resIndex;
-        }
-        else
-        {
-          break;
-        }
-      }
+  /**
+   * Finds the next match in the given sequence, starting at column at
+   * <code>columnIndex</code>. Answers true if a match is found, else false. If
+   * a match is found, <code>columnIndex</code> is advanced to the column after
+   * the start of the matched region, ready for a search from the next position.
+   * 
+   * @param seq
+   * @param searchString
+   * @param searchPattern
+   * @param matchDescription
+   * @return
+   */
+  protected boolean findNextMatch(SequenceI seq, String searchString,
+          Regex searchPattern, boolean matchDescription)
+  {
+    SequenceGroup selection = viewport.getSelectionGroup();
+    if (selection != null && !selection.contains(seq))
+    {
+      /*
+       * this sequence is not in the selection - advance to next sequence
+       */
+      return false;
+    }
 
-      if (!found)
+    if (columnIndex < 0)
+    {
+      /*
+       * at start of sequence; try find by residue number, in sequence id,
+       * or (optionally) in sequence description
+       */
+      if (doNonMotifSearches(seq, searchString, searchPattern,
+              matchDescription))
       {
-        seqIndex++;
-        resIndex = -1;
+        return true;
       }
     }
 
-    /**
-     * We now search the Id string in the main search loop. for (int id = 0; id
-     * < alignment.getHeight(); id++) { if
-     * (regex.search(alignment.getSequenceAt(id).getName())) {
-     * idMatch.addElement(alignment.getSequenceAt(id)); hasResults = true; } }
+    /*
+     * search for next match in sequence string
      */
-    return hasResults;
-  }
-
-  /**
-   * @return the alignment
-   */
-  public AlignmentI getAlignment()
-  {
-    return alignment;
+    int end = seq.getLength();
+    while (columnIndex < end)
+    {
+      if (searchNextVisibleRegion(seq, searchPattern))
+      {
+        return true;
+      }
+    }
+    return false;
   }
 
   /**
-   * @param alignment
-   *          the alignment to set
+   * Searches the sequence, starting from <code>columnIndex</code>, and adds the
+   * next match (if any) to <code>searchResults</code>. The search is restricted
+   * to the next visible column region, and to the <code>selection</code> region
+   * if there is one. Answers true if a match is added, else false.
+   * 
+   * @param seq
+   * @param searchPattern
+   * @return
    */
-  public void setAlignment(AlignmentI alignment)
+  protected boolean searchNextVisibleRegion(SequenceI seq, Regex searchPattern)
   {
-    this.alignment = alignment;
-  }
+    Range visible = getNextVisibleSequenceRegion(seq, columnIndex);
+    if (visible == null)
+    {
+      return false;
+    }
+    String seqString = seq.getSequenceAsString(visible.start, visible.end + 1);
+    String noGaps = AlignSeq.extractGaps(Comparison.GapChars, seqString);
 
-  /**
-   * @return the caseSensitive
-   */
-  public boolean isCaseSensitive()
-  {
-    return caseSensitive;
-  }
+    if (searchPattern.search(noGaps))
+    {
+      int sequenceStartPosition = seq.findPosition(visible.start);
+      recordMatch(seq, searchPattern, sequenceStartPosition);
+      return true;
+    }
+    else
+    {
+      /*
+       * no match - advance columnIndex past this visible region
+       * so the next visible region (if any) is searched next
+       */
+      columnIndex = visible.end + 1;
+    }
 
-  /**
-   * @param caseSensitive
-   *          the caseSensitive to set
-   */
-  public void setCaseSensitive(boolean caseSensitive)
-  {
-    this.caseSensitive = caseSensitive;
+    return false;
   }
 
   /**
-   * @return the findAll
+   * Adds the match held in the <code>searchPattern</code> Regex to the
+   * <code>searchResults</code>, unless it is a subregion of the last match
+   * recorded. <code>columnIndex</code> is advanced to the position after the
+   * start of the matched region, ready for the next search. Answers true if a
+   * match was added, else false.
+   * 
+   * @param seq
+   * @param searchPattern
+   * @param firstResiduePosition
+   * @return
    */
-  public boolean isFindAll()
+  protected boolean recordMatch(SequenceI seq, Regex searchPattern,
+          int firstResiduePosition)
   {
-    return findAll;
-  }
+    /*
+     * get start/end of the match in sequence coordinates
+     */
+    int offset = searchPattern.matchedFrom();
+    int matchStartPosition = firstResiduePosition + offset;
+    int matchEndPosition = matchStartPosition
+            + searchPattern.charsMatched() - 1;
+
+    /*
+     * update columnIndex to next column after the start of the match
+     * (findIndex returns a value base 1, columnIndex is held base 0)
+     */
+    columnIndex = seq.findIndex(matchStartPosition);
 
-  /**
-   * @param findAll
-   *          the findAll to set
-   */
-  public void setFindAll(boolean findAll)
-  {
-    this.findAll = findAll;
-  }
+    /*
+     * check that this match is not a subset of the previous one (JAL-2302)
+     */
+    List<SearchResultMatchI> matches = searchResults.getResults();
+    SearchResultMatchI lastMatch = matches.isEmpty() ? null
+            : matches.get(matches.size() - 1);
 
-  /**
-   * @return the selection
-   */
-  public jalview.datamodel.SequenceGroup getSelection()
-  {
-    return selection;
-  }
+    if (lastMatch == null || !lastMatch.contains(seq, matchStartPosition,
+            matchEndPosition))
+    {
+      searchResults.addResult(seq, matchStartPosition, matchEndPosition);
+      return true;
+    }
 
-  /**
-   * @param selection
-   *          the selection to set
-   */
-  public void setSelection(jalview.datamodel.SequenceGroup selection)
-  {
-    this.selection = selection;
+    return false;
   }
 
   /**
-   * Returns the (possibly empty) list of matching sequences (when search
-   * includes searching sequence names)
+   * Does searches other than for residue patterns. Currently this includes
+   * <ul>
+   * <li>find residue by position (if search string is a number)</li>
+   * <li>match search string to sequence id</li>
+   * <li>match search string to sequence description (optional)</li>
+   * </ul>
+   * Answers true if a match is found, else false.
    * 
+   * @param seq
+   * @param searchString
+   * @param searchPattern
+   * @param includeDescription
    * @return
    */
-  public Vector<SequenceI> getIdMatch()
+  protected boolean doNonMotifSearches(SequenceI seq, String searchString,
+          Regex searchPattern, boolean includeDescription)
   {
-    return idMatch;
-  }
+    /*
+     * position sequence search to start of sequence
+     */
+    columnIndex = 0;
 
-  /**
-   * @return the regex
-   */
-  public com.stevesoft.pat.Regex getRegex()
-  {
-    return regex;
+    if (searchForResidueNumber(seq, searchString))
+    {
+      return true;
+    }
+    if (searchSequenceName(seq, searchPattern))
+    {
+      return true;
+    }
+    if (includeDescription && searchSequenceDescription(seq, searchPattern))
+    {
+      return true;
+    }
+    return false;
   }
 
   /**
-   * @return the searchResults
+   * Searches for a match with the sequence description, and if found, adds the
+   * sequence to the list of match ids (but not as a duplicate). Answers true if
+   * a match was added, else false.
+   * 
+   * @param seq
+   * @param searchPattern
+   * @return
    */
-  public SearchResultsI getSearchResults()
+  protected boolean searchSequenceDescription(SequenceI seq, Regex searchPattern)
   {
-    return searchResults;
+    String desc = seq.getDescription();
+    if (desc != null && searchPattern.search(desc) && !idMatches.contains(seq))
+    {
+      idMatches.addElement(seq);
+      return true;
+    }
+    return false;
   }
 
   /**
-   * @return the resIndex
+   * Searches for a match with the sequence name, and if found, adds the
+   * sequence to the list of match ids (but not as a duplicate). Answers true if
+   * a match was added, else false.
+   * 
+   * @param seq
+   * @param searchPattern
+   * @return
    */
-  public int getResIndex()
+  protected boolean searchSequenceName(SequenceI seq, Regex searchPattern)
   {
-    return resIndex;
+    if (searchPattern.search(seq.getName()) && !idMatches.contains(seq))
+    {
+      idMatches.addElement(seq);
+      return true;
+    }
+    return false;
   }
 
   /**
-   * @param resIndex
-   *          the resIndex to set
+   * Tries to interpret the search string as a residue position, and if valid,
+   * adds the position to the search results and returns true, else answers
+   * false
    */
-  public void setResIndex(int resIndex)
+  protected boolean searchForResidueNumber(SequenceI seq, String searchString)
   {
-    this.resIndex = resIndex;
+    try
+    {
+      int res = Integer.parseInt(searchString);
+      if (seq.getStart() <= res && seq.getEnd() >= res)
+      {
+        searchResults.addResult(seq, res, res);
+        return true;
+      }
+    } catch (NumberFormatException ex)
+    {
+    }
+    return false;
   }
 
-  /**
-   * @return the seqIndex
+  /* (non-Javadoc)
+   * @see jalview.analysis.FinderI#getIdMatch()
    */
-  public int getSeqIndex()
+  @Override
+  public Vector<SequenceI> getIdMatches()
   {
-    return seqIndex;
+    return idMatches;
   }
 
-  /**
-   * @param seqIndex
-   *          the seqIndex to set
+  /* (non-Javadoc)
+   * @see jalview.analysis.FinderI#getSearchResults()
    */
-  public void setSeqIndex(int seqIndex)
-  {
-    this.seqIndex = seqIndex;
-  }
-
-  public boolean isIncludeDescription()
-  {
-    return includeDescription;
-  }
-
-  public void setIncludeDescription(boolean includeDescription)
+  @Override
+  public SearchResultsI getSearchResults()
   {
-    this.includeDescription = includeDescription;
+    return searchResults;
   }
 }
diff --git a/src/jalview/analysis/GeneticCodeI.java b/src/jalview/analysis/GeneticCodeI.java
new file mode 100644 (file)
index 0000000..daed0ac
--- /dev/null
@@ -0,0 +1,46 @@
+package jalview.analysis;
+
+public interface GeneticCodeI
+{
+  /**
+   * Answers the single letter amino acid code (e.g. "D") for the given codon
+   * (e.g. "GAC"), or "*" for a stop codon, or null for an unknown input. The
+   * codon is not case-sensitive, the return value is upper case.
+   * <p>
+   * If the codon includes any of the standard ambiguity codes
+   * <ul>
+   * <li>if all possible translations are the same, returns that value</li>
+   * <li>else returns null</li>
+   * </ul>
+   * 
+   * @param codon
+   * @return
+   */
+  String translate(String codon);
+
+  /**
+   * Answers the single letter amino acid code (e.g. "D") for the given codon
+   * (e.g. "GAC"), or "*" for a stop codon, or null for an unknown input. The
+   * codon is not case-sensitive, the return value is upper case. If the codon
+   * includes any of the standard ambiguity codes, this method returns null.
+   * 
+   * @param codon
+   * @return
+   */
+  String translateCanonical(String codon);
+
+  /**
+   * Answers a unique identifier for the genetic code (using the numbering
+   * system as on NCBI)
+   * 
+   * @return
+   */
+  String getId();
+
+  /**
+   * Answers a display name suitable for use in menus, reports etc
+   * 
+   * @return
+   */
+  String getName();
+}
diff --git a/src/jalview/analysis/GeneticCodes.java b/src/jalview/analysis/GeneticCodes.java
new file mode 100644 (file)
index 0000000..d07253e
--- /dev/null
@@ -0,0 +1,402 @@
+package jalview.analysis;
+
+import jalview.bin.Cache;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.StringTokenizer;
+
+/**
+ * A singleton that provides instances of genetic code translation tables
+ * 
+ * @author gmcarstairs
+ * @see https://www.ncbi.nlm.nih.gov/Taxonomy/Utils/wprintgc.cgi
+ */
+public final class GeneticCodes
+{
+  private static final int CODON_LENGTH = 3;
+
+  private static final String QUOTE = "\"";
+
+  /*
+   * nucleotides as ordered in data file
+   */
+  private static final String NUCS = "TCAG";
+
+  private static final int NUCS_COUNT = NUCS.length();
+
+  private static final int NUCS_COUNT_SQUARED = NUCS_COUNT * NUCS_COUNT;
+
+  private static final int NUCS_COUNT_CUBED = NUCS_COUNT * NUCS_COUNT
+          * NUCS_COUNT;
+
+  private static final String AMBIGUITY_CODES_FILE = "/AmbiguityCodes.dat";
+
+  private static final String RESOURCE_FILE = "/GeneticCodes.dat";
+
+  private static GeneticCodes instance = new GeneticCodes();
+
+  private Map<String, String> ambiguityCodes;
+
+  /*
+   * loaded code tables, with keys in order of loading 
+   */
+  private Map<String, GeneticCodeI> codeTables;
+
+  /**
+   * Private constructor enforces singleton
+   */
+  private GeneticCodes()
+  {
+    if (instance == null)
+    {
+      ambiguityCodes = new HashMap<>();
+
+      /*
+       * LinkedHashMap preserves order of addition of entries,
+       * so we can assume the Standard Code Table is the first
+       */
+      codeTables = new LinkedHashMap<>();
+      loadAmbiguityCodes(AMBIGUITY_CODES_FILE);
+      loadCodes(RESOURCE_FILE);
+    }
+  };
+
+  /**
+   * Returns the singleton instance of this class
+   * 
+   * @return
+   */
+  public static GeneticCodes getInstance()
+  {
+    return instance;
+  }
+
+  /**
+   * Returns the known code tables, in order of loading.
+   * 
+   * @return
+   */
+  public Iterable<GeneticCodeI> getCodeTables()
+  {
+    return codeTables.values();
+  }
+
+  /**
+   * Answers the code table with the given id
+   * 
+   * @param id
+   * @return
+   */
+  public GeneticCodeI getCodeTable(String id)
+  {
+    return codeTables.get(id);
+  }
+
+  /**
+   * A convenience method that returns the standard code table (table 1). As
+   * implemented, this has to be the first table defined in the data file.
+   * 
+   * @return
+   */
+  public GeneticCodeI getStandardCodeTable()
+  {
+    return codeTables.values().iterator().next();
+  }
+
+  /**
+   * Loads the code tables from a data file
+   */
+  protected void loadCodes(String fileName)
+  {
+    try
+    {
+      InputStream is = getClass().getResourceAsStream(fileName);
+      BufferedReader dataIn = new BufferedReader(new InputStreamReader(is));
+
+      /*
+       * skip comments and start of table
+       */
+      String line = "";
+      while (line != null && !line.startsWith("Genetic-code-table"))
+      {
+        line = readLine(dataIn);
+      }
+      line = readLine(dataIn);
+
+      while (line.startsWith("{"))
+      {
+        line = loadOneTable(dataIn);
+      }
+    } catch (IOException | NullPointerException e)
+    {
+      Cache.log.error(
+              "Error reading genetic codes data file: "
+              + e.getMessage());
+    }
+  }
+
+  /**
+   * Reads and saves Nucleotide ambiguity codes from a data file. The file may
+   * include comment lines (starting with #), a header 'DNA', and one line per
+   * ambiguity code, for example:
+   * <p>
+   * R&lt;tab&gt;AG
+   * <p>
+   * means that R is an ambiguity code meaning "A or G"
+   * 
+   * @param fileName
+   */
+  protected void loadAmbiguityCodes(String fileName)
+  {
+    try
+    {
+      InputStream is = getClass().getResourceAsStream(fileName);
+      BufferedReader dataIn = new BufferedReader(new InputStreamReader(is));
+      String line = "";
+      while (line != null)
+      {
+        line = readLine(dataIn);
+        if (line != null && !"DNA".equals(line.toUpperCase()))
+        {
+          String[] tokens = line.split("\\t");
+          ambiguityCodes.put(tokens[0].toUpperCase(),
+                  tokens[1].toUpperCase());
+        }
+      }
+    } catch (IOException e)
+    {
+      Cache.log.error(
+              "Error reading nucleotide ambiguity codes data file: "
+                      + e.getMessage());
+    }
+  }
+
+  /**
+   * Reads up to and returns the next non-comment line, trimmed. Comment lines
+   * start with a #. Returns null at end of file.
+   * 
+   * @param dataIn
+   * @return
+   * @throws IOException
+   */
+  protected String readLine(BufferedReader dataIn) throws IOException
+  {
+    String line = dataIn.readLine();
+    while (line != null && line.startsWith("#"))
+    {
+      line = readLine(dataIn);
+    }
+    return line == null ? null : line.trim();
+  }
+
+  /**
+   * Reads the lines of the data file describing one translation table, and
+   * creates and stores an instance of GeneticCodeI. Returns the '{' line
+   * starting the next table, or the '}' line at end of all tables. Data format
+   * is
+   * 
+   * <pre>
+   * {
+   *   name "Vertebrate Mitochondrial" ,
+   *   name "SGC1" ,
+   *   id 2 ,
+   *   ncbieaa  "FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIMMTTTTNNKKSS**VVVVAAAADDEEGGGG",
+   *   sncbieaa "----------**--------------------MMMM----------**---M------------"
+   *   -- Base1  TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG
+   *   -- Base2  TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG
+   *   -- Base3  TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG
+   * },
+   * </pre>
+   * 
+   * of which we parse the first name, the id, and the ncbieaa translations for
+   * codons as ordered by the Base1/2/3 lines. Note Base1/2/3 are included for
+   * readability and are in a fixed order, these are not parsed. The sncbieaa
+   * line marks alternative start codons, these are not parsed.
+   * 
+   * @param dataIn
+   * @return
+   * @throws IOException
+   */
+  protected String loadOneTable(BufferedReader dataIn) throws IOException
+  {
+    String name = null;
+    String id = null;
+    Map<String, String> codons = new HashMap<>();
+
+    String line = readLine(dataIn);
+
+    while (line != null && !line.startsWith("}"))
+    {
+      if (line.startsWith("name") && name == null)
+      {
+        name = line.substring(line.indexOf(QUOTE) + 1,
+                line.lastIndexOf(QUOTE));
+      }
+      else if (line.startsWith("id"))
+      {
+        id = new StringTokenizer(line.substring(2)).nextToken();
+      }
+      else if (line.startsWith("ncbieaa"))
+      {
+        String aminos = line.substring(line.indexOf(QUOTE) + 1,
+                line.lastIndexOf(QUOTE));
+        if (aminos.length() != NUCS_COUNT_CUBED) // 4 * 4 * 4 combinations
+        {
+          Cache.log.error("wrong data length in code table: " + line);
+        }
+        else
+        {
+          for (int i = 0; i < aminos.length(); i++)
+          {
+            String peptide = String.valueOf(aminos.charAt(i));
+            char codon1 = NUCS.charAt(i / NUCS_COUNT_SQUARED);
+            char codon2 = NUCS
+                    .charAt((i % NUCS_COUNT_SQUARED) / NUCS_COUNT);
+            char codon3 = NUCS.charAt(i % NUCS_COUNT);
+            String codon = new String(
+                    new char[]
+                    { codon1, codon2, codon3 });
+            codons.put(codon, peptide);
+          }
+        }
+      }
+      line = readLine(dataIn);
+    }
+
+    registerCodeTable(id, name, codons);
+    return readLine(dataIn);
+  }
+
+  /**
+   * Constructs and registers a GeneticCodeI instance with the codon
+   * translations as defined in the data file. For all instances except the
+   * first, any undeclared translations default to those in the standard code
+   * table.
+   * 
+   * @param id
+   * @param name
+   * @param codons
+   */
+  protected void registerCodeTable(final String id, final String name,
+          final Map<String, String> codons)
+  {
+    codeTables.put(id, new GeneticCodeI()
+    {
+      /*
+       * map of ambiguous codons to their 'product'
+       * (null if not all possible translations match)
+       */
+      Map<String, String> ambiguous = new HashMap<>();
+
+      @Override
+      public String translateCanonical(String codon)
+      {
+        return codons.get(codon.toUpperCase());
+      }
+
+      @Override
+      public String translate(String codon)
+      {
+        String upper = codon.toUpperCase();
+        String peptide = translateCanonical(upper);
+
+        /*
+         * if still not translated, check for ambiguity codes
+         */
+        if (peptide == null)
+        {
+          peptide = getAmbiguousTranslation(upper, ambiguous, this);
+        }
+        return peptide;
+      }
+
+      @Override
+      public String getId()
+      {
+        return id;
+      }
+
+      @Override
+      public String getName()
+      {
+        return name;
+      }
+    });
+  }
+
+  /**
+   * Computes all possible translations of a codon including one or more
+   * ambiguity codes, and stores and returns the result (null if not all
+   * translations match). If the codon includes no ambiguity codes, simply
+   * returns null.
+   * 
+   * @param codon
+   * @param ambiguous
+   * @param codeTable
+   * @return
+   */
+  protected String getAmbiguousTranslation(String codon,
+          Map<String, String> ambiguous, GeneticCodeI codeTable)
+  {
+    if (codon.length() != CODON_LENGTH)
+    {
+      return null;
+    }
+
+    boolean isAmbiguous = false;
+
+    char[][] expanded = new char[CODON_LENGTH][];
+    for (int i = 0; i < CODON_LENGTH; i++)
+    {
+      String base = String.valueOf(codon.charAt(i));
+      if (ambiguityCodes.containsKey(base))
+      {
+        isAmbiguous = true;
+        base = ambiguityCodes.get(base);
+      }
+      expanded[i] = base.toCharArray();
+    }
+
+    if (!isAmbiguous)
+    {
+      // no ambiguity code involved here
+      return null;
+    }
+
+    /*
+     * generate and translate all permutations of the ambiguous codon
+     * only return the translation if they all agree, else null
+     */
+    String peptide = null;
+    for (char c1 : expanded[0])
+    {
+      for (char c2 : expanded[1])
+      {
+        for (char c3 : expanded[2])
+        {
+          char[] cdn = new char[] { c1, c2, c3 };
+          String possibleCodon = String.valueOf(cdn);
+          String pep = codeTable.translate(possibleCodon);
+          if (pep == null || (peptide != null && !pep.equals(peptide)))
+          {
+            ambiguous.put(codon, null);
+            return null;
+          }
+          peptide = pep;
+        }
+      }
+    }
+
+    /*
+     * all translations of ambiguous codons matched!
+     */
+    ambiguous.put(codon, peptide);
+    return peptide;
+  }
+}
index 42a168d..d51f00e 100755 (executable)
@@ -22,7 +22,9 @@ package jalview.analysis;
 
 import jalview.api.analysis.ScoreModelI;
 import jalview.api.analysis.SimilarityParamsI;
+import jalview.bin.Cache;
 import jalview.datamodel.AlignmentView;
+import jalview.datamodel.Point;
 import jalview.math.MatrixI;
 
 import java.io.PrintStream;
@@ -32,28 +34,37 @@ import java.io.PrintStream;
  */
 public class PCA implements Runnable
 {
-  MatrixI symm;
-
-  double[] eigenvalue;
+  /*
+   * inputs
+   */
+  final private AlignmentView seqs;
 
-  MatrixI eigenvector;
+  final private ScoreModelI scoreModel;
 
-  StringBuilder details = new StringBuilder(1024);
+  final private SimilarityParamsI similarityParams;
 
-  final private AlignmentView seqs;
+  /*
+   * outputs
+   */
+  private MatrixI pairwiseScores;
 
-  private ScoreModelI scoreModel;
+  private MatrixI tridiagonal;
 
-  private SimilarityParamsI similarityParams;
+  private MatrixI eigenMatrix;
 
-  public PCA(AlignmentView s, ScoreModelI sm, SimilarityParamsI options)
+  /**
+   * Constructor given the sequences to compute for, the similarity model to
+   * use, and a set of parameters for sequence comparison
+   * 
+   * @param sequences
+   * @param sm
+   * @param options
+   */
+  public PCA(AlignmentView sequences, ScoreModelI sm, SimilarityParamsI options)
   {
-    this.seqs = s;
-    this.similarityParams = options;
+    this.seqs = sequences;
     this.scoreModel = sm;
-
-    details.append("PCA calculation using " + sm.getName()
-            + " sequence similarity matrix\n========\n\n");
+    this.similarityParams = options;
   }
 
   /**
@@ -66,7 +77,7 @@ public class PCA implements Runnable
    */
   public double getEigenvalue(int i)
   {
-    return eigenvector.getD()[i];
+    return eigenMatrix.getD()[i];
   }
 
   /**
@@ -83,15 +94,16 @@ public class PCA implements Runnable
    * 
    * @return DOCUMENT ME!
    */
-  public float[][] getComponents(int l, int n, int mm, float factor)
+  public Point[] getComponents(int l, int n, int mm, float factor)
   {
-    float[][] out = new float[getHeight()][3];
+    Point[] out = new Point[getHeight()];
 
     for (int i = 0; i < getHeight(); i++)
     {
-      out[i][0] = (float) component(i, l) * factor;
-      out[i][1] = (float) component(i, n) * factor;
-      out[i][2] = (float) component(i, mm) * factor;
+      float x = (float) component(i, l) * factor;
+      float y = (float) component(i, n) * factor;
+      float z = (float) component(i, mm) * factor;
+      out[i] = new Point(x, y, z);
     }
 
     return out;
@@ -132,84 +144,111 @@ public class PCA implements Runnable
   {
     double out = 0.0;
 
-    for (int i = 0; i < symm.width(); i++)
+    for (int i = 0; i < pairwiseScores.width(); i++)
     {
-      out += (symm.getValue(row, i) * eigenvector.getValue(i, n));
+      out += (pairwiseScores.getValue(row, i) * eigenMatrix.getValue(i, n));
     }
 
-    return out / eigenvector.getD()[n];
+    return out / eigenMatrix.getD()[n];
   }
 
+  /**
+   * Answers a formatted text report of the PCA calculation results (matrices
+   * and eigenvalues) suitable for display
+   * 
+   * @return
+   */
   public String getDetails()
   {
-    return details.toString();
+    StringBuilder sb = new StringBuilder(1024);
+    sb.append("PCA calculation using ").append(scoreModel.getName())
+            .append(" sequence similarity matrix\n========\n\n");
+    PrintStream ps = wrapOutputBuffer(sb);
+    
+    /*
+     * pairwise similarity scores
+     */
+    sb.append(" --- OrigT * Orig ---- \n");
+    pairwiseScores.print(ps, "%8.2f");
+    
+    /*
+     * tridiagonal matrix, with D and E vectors
+     */
+    sb.append(" ---Tridiag transform matrix ---\n");
+    sb.append(" --- D vector ---\n");
+    tridiagonal.printD(ps, "%15.4e");
+    ps.println();
+    sb.append("--- E vector ---\n");
+    tridiagonal.printE(ps, "%15.4e");
+    ps.println();
+    
+    /*
+     * eigenvalues matrix, with D vector
+     */
+    sb.append(" --- New diagonalization matrix ---\n");
+    eigenMatrix.print(ps, "%8.2f");
+    sb.append(" --- Eigenvalues ---\n");
+    eigenMatrix.printD(ps, "%15.4e");
+    ps.println();
+    
+    return sb.toString();
   }
 
   /**
-   * DOCUMENT ME!
+   * Performs the PCA calculation
    */
   @Override
   public void run()
   {
+    try
+    {
+      /*
+       * sequence pairwise similarity scores
+       */
+      pairwiseScores = scoreModel.findSimilarities(seqs, similarityParams);
+
+      /*
+       * tridiagonal matrix
+       */
+      tridiagonal = pairwiseScores.copy();
+      tridiagonal.tred();
+
+      /*
+       * the diagonalization matrix
+       */
+      eigenMatrix = tridiagonal.copy();
+      eigenMatrix.tqli();
+    } catch (Exception q)
+    {
+      Cache.log.error("Error computing PCA:  " + q.getMessage());
+      q.printStackTrace();
+    }
+  }
+
+  /**
+   * Returns a PrintStream that wraps (appends its output to) the given
+   * StringBuilder
+   * 
+   * @param sb
+   * @return
+   */
+  protected PrintStream wrapOutputBuffer(StringBuilder sb)
+  {
     PrintStream ps = new PrintStream(System.out)
     {
       @Override
       public void print(String x)
       {
-        details.append(x);
+        sb.append(x);
       }
 
       @Override
       public void println()
       {
-        details.append("\n");
+        sb.append("\n");
       }
     };
-
-    // long now = System.currentTimeMillis();
-    try
-    {
-      eigenvector = scoreModel.findSimilarities(seqs, similarityParams);
-
-      details.append(" --- OrigT * Orig ---- \n");
-      eigenvector.print(ps, "%8.2f");
-
-      symm = eigenvector.copy();
-
-      eigenvector.tred();
-
-      details.append(" ---Tridiag transform matrix ---\n");
-      details.append(" --- D vector ---\n");
-      eigenvector.printD(ps, "%15.4e");
-      ps.println();
-      details.append("--- E vector ---\n");
-      eigenvector.printE(ps, "%15.4e");
-      ps.println();
-
-      // Now produce the diagonalization matrix
-      eigenvector.tqli();
-    } catch (Exception q)
-    {
-      q.printStackTrace();
-      details.append("\n*** Unexpected exception when performing PCA ***\n"
-              + q.getLocalizedMessage());
-      details.append(
-              "*** Matrices below may not be fully diagonalised. ***\n");
-    }
-
-    details.append(" --- New diagonalization matrix ---\n");
-    eigenvector.print(ps, "%8.2f");
-    details.append(" --- Eigenvalues ---\n");
-    eigenvector.printD(ps, "%15.4e");
-    ps.println();
-    /*
-     * for (int seq=0;seq<symm.rows;seq++) { ps.print("\"Seq"+seq+"\""); for
-     * (int ev=0;ev<symm.rows; ev++) {
-     * 
-     * ps.print(","+component(seq, ev)); } ps.println(); }
-     */
-    // System.out.println(("PCA.run() took "
-    // + (System.currentTimeMillis() - now) + "ms"));
+    return ps;
   }
 
   /**
@@ -221,6 +260,42 @@ public class PCA implements Runnable
   public int getHeight()
   {
     // TODO can any of seqs[] be null?
-    return seqs.getSequences().length;
+    return pairwiseScores.height();// seqs.getSequences().length;
+  }
+
+  /**
+   * Answers the sequence pairwise similarity scores which were the first step
+   * of the PCA calculation
+   * 
+   * @return
+   */
+  public MatrixI getPairwiseScores()
+  {
+    return pairwiseScores;
+  }
+
+  public void setPairwiseScores(MatrixI m)
+  {
+    pairwiseScores = m;
+  }
+
+  public MatrixI getEigenmatrix()
+  {
+    return eigenMatrix;
+  }
+
+  public void setEigenmatrix(MatrixI m)
+  {
+    eigenMatrix = m;
+  }
+
+  public MatrixI getTridiagonal()
+  {
+    return tridiagonal;
+  }
+
+  public void setTridiagonal(MatrixI tridiagonal)
+  {
+    this.tridiagonal = tridiagonal;
   }
 }
index c1e8b42..ddfe5e4 100644 (file)
@@ -152,15 +152,17 @@ public class PIDModel extends SimilarityScoreModel
   protected MatrixI findSimilarities(String[] seqs,
           SimilarityParamsI options)
   {
-    // TODO reuse code in ScoreMatrix instead somehow
-    double[][] values = new double[seqs.length][];
+    /*
+     * calculation is symmetric so just compute lower diagonal
+     */
+    double[][] values = new double[seqs.length][seqs.length];
     for (int row = 0; row < seqs.length; row++)
     {
-      values[row] = new double[seqs.length];
-      for (int col = 0; col < seqs.length; col++)
+      for (int col = row; col < seqs.length; col++)
       {
         double total = computePID(seqs[row], seqs[col], options);
         values[row][col] = total;
+        values[col][row] = total;
       }
     }
     return new Matrix(values);
index 6cdfacb..b206339 100644 (file)
@@ -99,6 +99,8 @@ public class ScoreMatrix extends SimilarityScoreModel
 
   private float maxValue;
 
+  private boolean symmetric;
+
   /**
    * Constructor given a name, symbol alphabet, and matrix of scores for pairs
    * of symbols. The matrix should be square and of the same size as the
@@ -156,6 +158,8 @@ public class ScoreMatrix extends SimilarityScoreModel
 
     findMinMax();
 
+    symmetric = checkSymmetry();
+
     /*
      * crude heuristic for now...
      */
@@ -163,6 +167,27 @@ public class ScoreMatrix extends SimilarityScoreModel
   }
 
   /**
+   * Answers true if the matrix is symmetric, else false. Usually, substitution
+   * matrices are symmetric, which allows calculations to be short cut.
+   * 
+   * @return
+   */
+  private boolean checkSymmetry()
+  {
+    for (int i = 0; i < matrix.length; i++)
+    {
+      for (int j = i; j < matrix.length; j++)
+      {
+        if (matrix[i][j] != matrix[j][i])
+        {
+          return false;
+        }
+      }
+    }
+    return true;
+  }
+
+  /**
    * Record the minimum and maximum score values
    */
   protected void findMinMax()
@@ -457,14 +482,17 @@ public class ScoreMatrix extends SimilarityScoreModel
   protected MatrixI findSimilarities(String[] seqs,
           SimilarityParamsI params)
   {
-    double[][] values = new double[seqs.length][];
+    double[][] values = new double[seqs.length][seqs.length];
     for (int row = 0; row < seqs.length; row++)
     {
-      values[row] = new double[seqs.length];
-      for (int col = 0; col < seqs.length; col++)
+      for (int col = symmetric ? row : 0; col < seqs.length; col++)
       {
         double total = computeSimilarity(seqs[row], seqs[col], params);
         values[row][col] = total;
+        if (symmetric)
+        {
+          values[col][row] = total;
+        }
       }
     }
     return new Matrix(values);
@@ -592,4 +620,9 @@ public class ScoreMatrix extends SimilarityScoreModel
   {
     return this;
   }
+
+  public boolean isSymmetric()
+  {
+    return symmetric;
+  }
 }
index 7262fb8..ebc9a26 100644 (file)
@@ -41,12 +41,22 @@ public class ScoreModels
 
   private final ScoreMatrix DNA;
 
-  private static ScoreModels instance = new ScoreModels();
+  private static ScoreModels instance;
 
   private Map<String, ScoreModelI> models;
 
+  /**
+   * Answers the singleton instance of this class, with lazy initialisation
+   * (built-in score models are loaded on the first call to this method)
+   * 
+   * @return
+   */
   public static ScoreModels getInstance()
   {
+    if (instance == null)
+    {
+      instance = new ScoreModels();
+    }
     return instance;
   }
 
@@ -66,11 +76,11 @@ public class ScoreModels
     /*
      * using LinkedHashMap keeps models ordered as added
      */
-    models = new LinkedHashMap<String, ScoreModelI>();
+    models = new LinkedHashMap<>();
     BLOSUM62 = loadScoreMatrix("scoreModel/blosum62.scm");
     PAM250 = loadScoreMatrix("scoreModel/pam250.scm");
-    registerScoreModel(new PIDModel());
     DNA = loadScoreMatrix("scoreModel/dna.scm");
+    registerScoreModel(new PIDModel());
     registerScoreModel(new FeatureDistanceModel());
   }
 
@@ -139,6 +149,14 @@ public class ScoreModels
   }
 
   /**
+   * Resets to just the built-in score models
+   */
+  public void reset()
+  {
+    instance = new ScoreModels();
+  }
+
+  /**
    * Returns the default peptide or nucleotide score model, currently BLOSUM62
    * or DNA
    * 
index 58b08dd..5c47703 100644 (file)
@@ -147,4 +147,57 @@ public class SimilarityParams implements SimilarityParamsI
   {
     return matchGaps;
   }
+
+  /**
+   * IDE-generated hashCode method
+   */
+  @Override
+  public int hashCode()
+  {
+    final int prime = 31;
+    int result = 1;
+    result = prime * result + (denominateByShortestLength ? 1231 : 1237);
+    result = prime * result + (includeGappedColumns ? 1231 : 1237);
+    result = prime * result + (includeGaps ? 1231 : 1237);
+    result = prime * result + (matchGaps ? 1231 : 1237);
+    return result;
+  }
+
+  /**
+   * IDE-generated equals method
+   */
+  @Override
+  public boolean equals(Object obj)
+  {
+    if (this == obj)
+    {
+      return true;
+    }
+    if (obj == null)
+    {
+      return false;
+    }
+    if (getClass() != obj.getClass())
+    {
+      return false;
+    }
+    SimilarityParams other = (SimilarityParams) obj;
+    if (denominateByShortestLength != other.denominateByShortestLength)
+    {
+      return false;
+    }
+    if (includeGappedColumns != other.includeGappedColumns)
+    {
+      return false;
+    }
+    if (includeGaps != other.includeGaps)
+    {
+      return false;
+    }
+    if (matchGaps != other.matchGaps)
+    {
+      return false;
+    }
+    return true;
+  }
 }
index 931eba6..389d9cf 100644 (file)
@@ -490,4 +490,32 @@ public interface AlignViewportI extends ViewStyleI
   public abstract TreeModel getCurrentTree();
 
   public abstract void setCurrentTree(TreeModel tree);
+
+  /**
+   * @param update
+   *          - set the flag for updating structures on next repaint
+   */
+  void setUpdateStructures(boolean update);
+
+  /**
+   *
+   * @return true if structure views will be updated on next refresh
+   */
+  boolean isUpdateStructures();
+
+  /**
+   * check if structure views need to be updated, and clear the flag afterwards.
+   * 
+   * @return if an update is needed
+   */
+  boolean needToUpdateStructureViews();
+
+  /**
+   * Adds sequencegroup to the alignment in the view. Also adds a group to the
+   * complement view if one is defined.
+   * 
+   * @param sequenceGroup
+   *          - a group defined on sequences in the alignment held by the view
+   */
+  void addSequenceGroup(SequenceGroup sequenceGroup);
 }
index 4dbb1bb..7bfd8a8 100644 (file)
@@ -192,4 +192,24 @@ public interface FeatureColourI
    * @return
    */
   void setAttributeName(String... name);
+
+  /**
+   * Answers true if colour has a threshold set, and the feature score (or other
+   * attribute selected for colouring) is outwith the threshold.
+   * <p>
+   * Answers false if not a graduated colour, or no threshold is set, or value
+   * is not outwith the threshold, or value is null or non-numeric.
+   * 
+   * @param sf
+   * @return
+   */
+  boolean isOutwithThreshold(SequenceFeature sf);
+
+  /*
+   * Answers a human-readable text description of the colour, suitable for
+   * display as a tooltip, possibly internationalised for the user's locale.
+   * 
+   * @return
+   */
+  String getDescription();
 }
index cf3c8da..404c497 100644 (file)
@@ -255,14 +255,29 @@ public interface FeatureRenderer
    * <p>
    * Returns null if
    * <ul>
-   * <li>feature type is not visible, or</li>
    * <li>feature group is not visible, or</li>
    * <li>feature values lie outside any colour threshold, or</li>
    * <li>feature is excluded by filter conditions</li>
    * </ul>
+   * This method does not check feature type visibility.
    * 
    * @param feature
    * @return
    */
   Color getColour(SequenceFeature feature);
+
+  /**
+   * Answers true if feature would be shown, else false. A feature is shown if
+   * <ul>
+   * <li>its feature type is set to visible</li>
+   * <li>its feature group is either null, or set to visible</li>
+   * <li>it is not excluded by a colour threshold on score or other numeric
+   * attribute</li>
+   * <li>it is not excluded by a filter condition</li>
+   * </ul>
+   * 
+   * @param feature
+   * @return
+   */
+  boolean isVisible(SequenceFeature feature);
 }
diff --git a/src/jalview/api/FinderI.java b/src/jalview/api/FinderI.java
new file mode 100644 (file)
index 0000000..19f6136
--- /dev/null
@@ -0,0 +1,62 @@
+package jalview.api;
+
+import jalview.datamodel.SearchResultsI;
+import jalview.datamodel.SequenceI;
+
+import java.util.List;
+
+/**
+ * An interface for searching for a pattern in an aligment
+ */
+public interface FinderI
+{
+
+  /**
+   * Performs a find for the given search string (interpreted as a regular
+   * expression). Search may optionally be case-sensitive, and may optionally
+   * including match in sequence description (sequence id is always searched).
+   * If the viewport has an active selection, then the find is restricted to the
+   * selection region. Sequences matched by id or description can be retrieved
+   * by getIdMatches(), and matched residue patterns by getSearchResults().
+   * 
+   * @param theSearchString
+   * @param caseSensitive
+   * @param searchDescription
+   * @return
+   */
+  void findAll(String theSearchString, boolean caseSensitive,
+          boolean searchDescription);
+
+  /**
+   * Finds the next match for the given search string (interpreted as a regular
+   * expression), starting from the position after the last match found. Search
+   * may optionally be case-sensitive, and may optionally including match in
+   * sequence description (sequence id is always searched). If the viewport has
+   * an active selection, then the find is restricted to the selection region.
+   * Sequences matched by id or description can be retrieved by getIdMatches(),
+   * and matched residue patterns by getSearchResults().
+   * 
+   * @param theSearchString
+   * @param caseSensitive
+   * @param searchDescription
+   * @return
+   */
+  void findNext(String theSearchString, boolean caseSensitive,
+          boolean searchDescription);
+
+  /**
+   * Returns the (possibly empty) list of sequences matched on sequence name or
+   * description
+   * 
+   * @return
+   */
+  List<SequenceI> getIdMatches();
+
+  /**
+   * Answers the search results (possibly empty) from the last search
+   * 
+   * @return
+   */
+  SearchResultsI getSearchResults();
+
+}
\ No newline at end of file
index a57bcdb..c6eb6de 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
- * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2b1)
+ * Copyright (C) 2014 The Jalview Authors
  * 
  * This file is part of Jalview.
  * 
@@ -22,7 +22,7 @@ package jalview.api;
 
 import jalview.datamodel.SequencePoint;
 
-import java.util.Vector;
+import java.util.List;
 
 /**
  * interface implemented by RotatatableCanvas GUI elements (such as point clouds
@@ -33,7 +33,23 @@ import java.util.Vector;
  */
 public interface RotatableCanvasI
 {
+  void setPoints(List<SequencePoint> points, int rows);
 
-  void setPoints(Vector<SequencePoint> points, int rows);
+  /**
+   * Zoom the view in (or out) by the given factor, which should be >= 0. A
+   * factor greater than 1 zooms in (expands the display), a factor less than 1
+   * zooms out (shrinks the display).
+   * 
+   * @param factor
+   */
+  void zoom(float factor);
 
+  /**
+   * Rotates the view by the specified number of degrees about the x and/or y
+   * axis
+   * 
+   * @param x
+   * @param y
+   */
+  void rotate(float x, float y);
 }
index 5ad212e..85fb03c 100644 (file)
@@ -1447,14 +1447,12 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     {
       features = formatter.printJalviewFormat(
               viewport.getAlignment().getSequencesArray(),
-              getDisplayedFeatureCols(), null, getDisplayedFeatureGroups(),
-              true);
+              alignPanel.getFeatureRenderer(), true);
     }
     else
     {
       features = formatter.printGffFormat(viewport.getAlignment()
-              .getSequencesArray(), getDisplayedFeatureCols(),
-              getDisplayedFeatureGroups(), true);
+              .getSequencesArray(), alignPanel.getFeatureRenderer(), true);
     }
 
     if (displayTextbox)
index 262948d..055584a 100644 (file)
@@ -25,14 +25,11 @@ import jalview.api.FeatureSettingsModelI;
 import jalview.bin.JalviewLite;
 import jalview.commands.CommandI;
 import jalview.datamodel.AlignmentI;
-import jalview.datamodel.Annotation;
 import jalview.datamodel.ColumnSelection;
 import jalview.datamodel.HiddenColumns;
 import jalview.datamodel.SearchResults;
 import jalview.datamodel.SearchResultsI;
-import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceGroup;
-import jalview.datamodel.SequenceI;
 import jalview.renderer.ResidueShader;
 import jalview.schemes.ColourSchemeProperty;
 import jalview.schemes.UserColourScheme;
@@ -200,7 +197,8 @@ public class AlignViewport extends AlignmentViewport
       if (colour != null)
       {
         residueShading = new ResidueShader(
-                ColourSchemeProperty.getColourScheme(alignment, colour));
+                ColourSchemeProperty.getColourScheme(this, alignment,
+                        colour));
         if (residueShading != null)
         {
           residueShading.setConsensus(hconsensus);
index 83d8ade..e9081b0 100644 (file)
@@ -669,14 +669,9 @@ public class AlignmentPanel extends Panel
     }
     else
     {
-      int width = av.getAlignment().getWidth();
+      int width = av.getAlignment().getVisibleWidth();
       int height = av.getAlignment().getHeight();
 
-      if (av.hasHiddenColumns())
-      {
-        width = av.getAlignment().getHiddenColumns()
-                .absoluteToVisibleColumn(width);
-      }
       if (x < 0)
       {
         x = 0;
index 2f61b24..e5767b6 100644 (file)
@@ -24,7 +24,6 @@ import jalview.api.AlignmentViewPanel;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceI;
 import jalview.ext.jmol.JalviewJmolBinding;
-import jalview.gui.IProgressIndicator;
 import jalview.io.DataSourceType;
 import jalview.structure.StructureSelectionManager;
 
@@ -174,21 +173,12 @@ class AppletJmolBinding extends JalviewJmolBinding
   @Override
   public int[] resizeInnerPanel(String data)
   {
-    // TODO Auto-generated method stub
     return null;
   }
 
   @Override
   public Map<String, Object> getJSpecViewProperty(String arg0)
   {
-    // TODO Auto-generated method stub
-    return null;
-  }
-
-  @Override
-  protected IProgressIndicator getIProgressIndicator()
-  {
-    // no progress indicators on the applet
     return null;
   }
 }
index 89228d5..b0d3f7a 100644 (file)
@@ -26,7 +26,6 @@ import jalview.api.SequenceRenderer;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceI;
 import jalview.ext.jmol.JalviewJmolBinding;
-import jalview.gui.IProgressIndicator;
 import jalview.io.DataSourceType;
 
 import java.awt.Container;
@@ -66,18 +65,8 @@ public class ExtJmol extends JalviewJmolBinding
   }
 
   @Override
-  protected IProgressIndicator getIProgressIndicator()
-  {
-    // no progress indicators on applet (could access javascript for this)
-    return null;
-  }
-
-  @Override
   public void updateColours(Object source)
   {
-
-    // TODO Auto-generated method stub
-
   }
 
   @Override
@@ -190,7 +179,6 @@ public class ExtJmol extends JalviewJmolBinding
   protected JmolAppConsoleInterface createJmolConsole(
           Container consolePanel, String buttonsToShow)
   {
-    // TODO Auto-generated method stub
     return null;
   }
 
@@ -205,14 +193,11 @@ public class ExtJmol extends JalviewJmolBinding
   @Override
   public void releaseReferences(Object svl)
   {
-    // TODO Auto-generated method stub
-
   }
 
   @Override
   public Map<String, Object> getJSpecViewProperty(String arg0)
   {
-    // TODO Auto-generated method stub
     return null;
   }
 
index d9eae11..5569ab0 100644 (file)
@@ -134,7 +134,8 @@ public class FeatureColourChooser extends Panel implements ActionListener,
     if (oldcs.isGraduatedColour())
     {
       threshline.value = oldcs.getThreshold();
-      cs = new FeatureColour((FeatureColour) oldcs, min, max);
+      cs = new FeatureColour(oldcs.getColour(), oldcs.getMinColour(),
+              oldcs.getMaxColour(), oldcs.getNoColour(), min, max);
     }
     else
     {
@@ -145,7 +146,8 @@ public class FeatureColourChooser extends Panel implements ActionListener,
         bl = oldcs.getColour();
       }
       // original colour becomes the maximum colour
-      cs = new FeatureColour(Color.white, bl, mm[0], mm[1]);
+      cs = new FeatureColour(bl, Color.white, bl, Color.white, mm[0],
+              mm[1]);
     }
     minColour.setBackground(cs.getMinColour());
     maxColour.setBackground(cs.getMaxColour());
@@ -411,8 +413,9 @@ public class FeatureColourChooser extends Panel implements ActionListener,
 
     slider.setEnabled(true);
     thresholdValue.setEnabled(true);
-    FeatureColour acg = new FeatureColour(minColour.getBackground(),
-            maxColour.getBackground(), min, max);
+    Color minc = minColour.getBackground();
+    Color maxc = maxColour.getBackground();
+    FeatureColour acg = new FeatureColour(maxc, minc, maxc, minc, min, max);
 
     acg.setColourByLabel(colourFromLabel.getState());
     maxColour.setEnabled(!colourFromLabel.getState());
@@ -448,11 +451,15 @@ public class FeatureColourChooser extends Panel implements ActionListener,
     {
       if (thresholdOption == AnnotationColourGradient.ABOVE_THRESHOLD)
       {
-        acg = new FeatureColour(acg, threshline.value, max);
+        acg = new FeatureColour(acg.getColour(), acg.getMinColour(),
+                acg.getMaxColour(), acg.getNoColour(), threshline.value,
+                max);
       }
       else
       {
-        acg = new FeatureColour(acg, min, threshline.value);
+        acg = new FeatureColour(acg.getColour(), acg.getMinColour(),
+                acg.getMaxColour(), acg.getNoColour(), min,
+                threshline.value);
       }
     }
 
index 675b862..2fc3441 100644 (file)
  */
 package jalview.appletgui;
 
+import jalview.api.AlignViewportI;
+import jalview.api.FinderI;
 import jalview.datamodel.SearchResultMatchI;
 import jalview.datamodel.SearchResultsI;
 import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
 import jalview.util.MessageManager;
-import jalview.viewmodel.AlignmentViewport;
 
 import java.awt.Button;
 import java.awt.Checkbox;
@@ -42,25 +43,39 @@ import java.awt.event.KeyEvent;
 import java.awt.event.WindowAdapter;
 import java.awt.event.WindowEvent;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
-import java.util.Vector;
+import java.util.Map;
 
 public class Finder extends Panel implements ActionListener
 {
-  AlignmentViewport av;
+  private AlignViewportI av;
 
-  AlignmentPanel ap;
+  private AlignmentPanel ap;
 
-  Frame frame;
+  private TextField textfield = new TextField();
 
-  SearchResultsI searchResults;
+  private Button findAll = new Button();
 
-  int seqIndex = 0;
+  private Button findNext = new Button();
 
-  int resIndex = -1;
+  private Button createFeatures = new Button();
+
+  private Checkbox caseSensitive = new Checkbox();
+
+  private Checkbox searchDescription = new Checkbox();
+
+  private SearchResultsI searchResults;
+
+  /*
+   * Finder agent per viewport searched
+   */
+  Map<AlignViewportI, FinderI> finders;
 
   public Finder(final AlignmentPanel ap)
   {
+    finders = new HashMap<>();
+
     try
     {
       jbInit();
@@ -72,7 +87,7 @@ public class Finder extends Panel implements ActionListener
 
     this.av = ap.av;
     this.ap = ap;
-    frame = new Frame();
+    Frame frame = new Frame();
     frame.add(this);
     jalview.bin.JalviewLite.addFrame(frame,
             MessageManager.getString("action.find"), 340, 120);
@@ -103,20 +118,18 @@ public class Finder extends Panel implements ActionListener
 
     else if (evt.getSource() == findAll)
     {
-      resIndex = -1;
-      seqIndex = 0;
       doSearch(true);
     }
-    else if (evt.getSource() == createNewGroup)
+    else if (evt.getSource() == createFeatures)
     {
-      createNewGroup_actionPerformed();
+      createFeatures_actionPerformed();
     }
   }
 
-  public void createNewGroup_actionPerformed()
+  public void createFeatures_actionPerformed()
   {
-    List<SequenceI> seqs = new ArrayList<SequenceI>();
-    List<SequenceFeature> features = new ArrayList<SequenceFeature>();
+    List<SequenceI> seqs = new ArrayList<>();
+    List<SequenceFeature> features = new ArrayList<>();
     String searchString = textfield.getText().trim();
 
     for (SearchResultMatchI match : searchResults.getResults())
@@ -135,48 +148,48 @@ public class Finder extends Panel implements ActionListener
     }
   }
 
-  void doSearch(boolean findAll)
+  void doSearch(boolean doFindAll)
   {
     if (ap.av.applet.currentAlignFrame != null)
     {
       ap = ap.av.applet.currentAlignFrame.alignPanel;
       av = ap.av;
     }
-    createNewGroup.setEnabled(false);
-    jalview.analysis.Finder finder = new jalview.analysis.Finder(
-            av.getAlignment(), av.getSelectionGroup(), seqIndex, resIndex);
-    finder.setCaseSensitive(caseSensitive.getState());
-    finder.setIncludeDescription(searchDescription.getState());
-    finder.setFindAll(findAll);
+    createFeatures.setEnabled(false);
+    FinderI finder = finders.get(av);
+    if (finder == null)
+    {
+      /*
+       * first time we searched this viewport
+       */
+      finder = new jalview.analysis.Finder(av);
+      finders.put(av, finder);
+    }
 
     String searchString = textfield.getText();
-
-    finder.find(searchString);
-    seqIndex = finder.getSeqIndex();
-    resIndex = finder.getResIndex();
-    searchResults = finder.getSearchResults();
-    Vector<SequenceI> idMatch = finder.getIdMatch();
-    boolean haveResults = false;
-    // set or reset the GUI
-    if ((idMatch.size() > 0))
+    boolean isCaseSensitive = caseSensitive.getState();
+    boolean doSearchDescription = searchDescription.getState();
+    if (doFindAll)
     {
-      haveResults = true;
-      ap.idPanel.highlightSearchResults(idMatch);
+      finder.findAll(searchString, isCaseSensitive, doSearchDescription);
     }
     else
     {
-      ap.idPanel.highlightSearchResults(null);
+      finder.findNext(searchString, isCaseSensitive, doSearchDescription);
     }
 
-    if (searchResults.getSize() > 0)
-    {
-      haveResults = true;
-      createNewGroup.setEnabled(true);
+    searchResults = finder.getSearchResults();
+
+    List<SequenceI> idMatches = finder.getIdMatches();
+    ap.idPanel.highlightSearchResults(idMatches);
 
+    if (searchResults.isEmpty())
+    {
+      searchResults = null;
     }
     else
     {
-      searchResults = null;
+      createFeatures.setEnabled(true);
     }
 
     // if allResults is null, this effectively switches displaySearch flag in
@@ -184,20 +197,18 @@ public class Finder extends Panel implements ActionListener
     ap.highlightSearchResults(searchResults);
     // TODO: add enablers for 'SelectSequences' or 'SelectColumns' or
     // 'SelectRegion' selection
-    if (!haveResults)
+    if (idMatches.isEmpty() && searchResults == null)
     {
       ap.alignFrame.statusBar.setText(
               MessageManager.getString("label.finished_searching"));
-      resIndex = -1;
-      seqIndex = 0;
     }
     else
     {
-      if (findAll)
+      if (doFindAll)
       {
-        String message = (idMatch.size() > 0) ? "" + idMatch.size() + " IDs"
+        String message = (idMatches.size() > 0) ? "" + idMatches.size() + " IDs"
                 : "";
-        if (idMatch.size() > 0 && searchResults != null
+        if (idMatches.size() > 0 && searchResults != null
                 && searchResults.getSize() > 0)
         {
           message += " and ";
@@ -221,28 +232,10 @@ public class Finder extends Panel implements ActionListener
     }
   }
 
-  Label jLabel1 = new Label();
-
-  protected TextField textfield = new TextField();
-
-  protected Button findAll = new Button();
-
-  protected Button findNext = new Button();
-
-  Panel actionsPanel = new Panel();
-
-  GridLayout gridLayout1 = new GridLayout();
-
-  protected Button createNewGroup = new Button();
-
-  Checkbox caseSensitive = new Checkbox();
-
-  Checkbox searchDescription = new Checkbox();
-
   private void jbInit() throws Exception
   {
+    Label jLabel1 = new Label(MessageManager.getString("action.find"));
     jLabel1.setFont(new java.awt.Font("Verdana", 0, 12));
-    jLabel1.setText(MessageManager.getString("action.find"));
     jLabel1.setBounds(new Rectangle(3, 30, 34, 15));
     this.setLayout(null);
     textfield.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
@@ -253,7 +246,7 @@ public class Finder extends Panel implements ActionListener
       @Override
       public void keyTyped(KeyEvent e)
       {
-        textfield_keyTyped(e);
+        textfield_keyTyped();
       }
     });
     textfield.addActionListener(this);
@@ -264,15 +257,18 @@ public class Finder extends Panel implements ActionListener
     findNext.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
     findNext.setLabel(MessageManager.getString("action.find_next"));
     findNext.addActionListener(this);
+
+    Panel actionsPanel = new Panel();
     actionsPanel.setBounds(new Rectangle(195, 5, 141, 64));
+    GridLayout gridLayout1 = new GridLayout();
     actionsPanel.setLayout(gridLayout1);
     gridLayout1.setHgap(0);
     gridLayout1.setRows(3);
     gridLayout1.setVgap(2);
-    createNewGroup.setEnabled(false);
-    createNewGroup.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
-    createNewGroup.setLabel(MessageManager.getString("label.new_feature"));
-    createNewGroup.addActionListener(this);
+    createFeatures.setEnabled(false);
+    createFeatures.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
+    createFeatures.setLabel(MessageManager.getString("label.new_feature"));
+    createFeatures.addActionListener(this);
     caseSensitive.setLabel(MessageManager.getString("label.match_case"));
     caseSensitive.setBounds(new Rectangle(30, 39, 126, 23));
 
@@ -281,7 +277,7 @@ public class Finder extends Panel implements ActionListener
     searchDescription.setBounds(new Rectangle(30, 59, 170, 23));
     actionsPanel.add(findNext, null);
     actionsPanel.add(findAll, null);
-    actionsPanel.add(createNewGroup, null);
+    actionsPanel.add(createFeatures, null);
     this.add(caseSensitive);
     this.add(textfield, null);
     this.add(jLabel1, null);
@@ -289,7 +285,7 @@ public class Finder extends Panel implements ActionListener
     this.add(searchDescription);
   }
 
-  void textfield_keyTyped(KeyEvent e)
+  void textfield_keyTyped()
   {
     findNext.setEnabled(true);
   }
index 296f898..ef80616 100755 (executable)
@@ -280,15 +280,9 @@ public class IdCanvas extends Panel implements ViewportListenerI
   protected void drawIdsWrapped(int starty, final boolean doHiddenCheck,
           boolean hiddenRows)
   {
-    int maxwidth = av.getAlignment().getWidth();
+    int maxwidth = av.getAlignment().getVisibleWidth();
     int alheight = av.getAlignment().getHeight();
 
-    if (av.hasHiddenColumns())
-    {
-      maxwidth = av.getAlignment().getHiddenColumns()
-              .absoluteToVisibleColumn(maxwidth) - 1;
-    }
-
     int annotationHeight = 0;
     AnnotationLabels labels = null;
 
index 15e269c..af1c47b 100755 (executable)
@@ -395,7 +395,7 @@ public class IdPanel extends Panel
   {
     idCanvas.setHighlighted(list);
 
-    if (list == null)
+    if (list == null || list.isEmpty())
     {
       return;
     }
index e99c021..07f5919 100644 (file)
@@ -162,4 +162,12 @@ public class OverviewCanvas extends Component
     }
   }
 
+  /**
+   * Nulls references to protect against potential memory leaks
+   */
+  void dispose()
+  {
+    od = null;
+  }
+
 }
index 3bbbe95..96138bf 100755 (executable)
@@ -126,13 +126,14 @@ public class OverviewPanel extends Panel implements Runnable,
   {
     if (od.isPositionInBox(evt.getX(), evt.getY()))
     {
-      // display drag cursor at mouse position
-      setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
+      this.getParent()
+              .setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
     }
     else
     {
-      // reset cursor
-      setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
+      this.getParent()
+              .setCursor(
+                      Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
     }
   }
 
@@ -162,6 +163,8 @@ public class OverviewPanel extends Panel implements Runnable,
         od.updateViewportFromMouse(evt.getX(), evt.getY(),
                 av.getAlignment().getHiddenSequences(),
                 av.getAlignment().getHiddenColumns());
+        getParent()
+                .setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
       }
       else
       {
@@ -334,6 +337,10 @@ public class OverviewPanel extends Panel implements Runnable,
     } finally
     {
       av = null;
+      if (oviewCanvas != null)
+      {
+        oviewCanvas.dispose();
+      }
       oviewCanvas = null;
       ap = null;
       od = null;
index fc1d359..7c0dfa9 100644 (file)
@@ -134,7 +134,7 @@ public class PCAPanel extends EmbmenuFrame
     {
       nuclSetting.setState(pcaModel.isNucleotide());
       protSetting.setState(!pcaModel.isNucleotide());
-      pcaModel.run();
+      pcaModel.calculate();
       // ////////////////
       xCombobox.select(0);
       yCombobox.select(1);
@@ -167,9 +167,7 @@ public class PCAPanel extends EmbmenuFrame
     int dim2 = top - yCombobox.getSelectedIndex();
     int dim3 = top - zCombobox.getSelectedIndex();
     pcaModel.updateRcView(dim1, dim2, dim3);
-    rc.img = null;
-    rc.rotmat.setIdentity();
-    rc.initAxes();
+    rc.resetView();
     rc.paint(rc.getGraphics());
   }
 
@@ -281,7 +279,7 @@ public class PCAPanel extends EmbmenuFrame
     {
     }
     ;
-    Object[] alAndColsel = pcaModel.getSeqtrings()
+    Object[] alAndColsel = pcaModel.getInputData()
             .getAlignmentAndHiddenColumns(gc);
 
     if (alAndColsel != null && alAndColsel[0] != null)
index afb4e95..34f8ea5 100755 (executable)
 package jalview.appletgui;
 
 import jalview.api.RotatableCanvasI;
+import jalview.datamodel.Point;
 import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
 import jalview.datamodel.SequencePoint;
 import jalview.math.RotatableMatrix;
-import jalview.util.Format;
+import jalview.math.RotatableMatrix.Axis;
 import jalview.util.MessageManager;
 import jalview.viewmodel.AlignmentViewport;
 
@@ -40,32 +41,26 @@ import java.awt.event.KeyListener;
 import java.awt.event.MouseEvent;
 import java.awt.event.MouseListener;
 import java.awt.event.MouseMotionListener;
-import java.util.Vector;
+import java.util.List;
 
 public class RotatableCanvas extends Panel implements MouseListener,
         MouseMotionListener, KeyListener, RotatableCanvasI
 {
-  RotatableMatrix idmat = new RotatableMatrix(3, 3);
-
-  RotatableMatrix objmat = new RotatableMatrix(3, 3);
-
-  RotatableMatrix rotmat = new RotatableMatrix(3, 3);
+  private static final int DIMS = 3;
 
   String tooltip;
 
-  int toolx, tooly;
+  int toolx;
+
+  int tooly;
 
   // RubberbandRectangle rubberband;
 
   boolean drawAxes = true;
 
-  int omx = 0;
-
-  int mx = 0;
-
-  int omy = 0;
+  int mouseX = 0;
 
-  int my = 0;
+  int mouseY = 0;
 
   Image img;
 
@@ -73,13 +68,13 @@ public class RotatableCanvas extends Panel implements MouseListener,
 
   Dimension prefsize;
 
-  float centre[] = new float[3];
+  Point centre;
 
-  float width[] = new float[3];
+  float[] width = new float[DIMS];
 
-  float max[] = new float[3];
+  float[] max = new float[DIMS];
 
-  float min[] = new float[3];
+  float[] min = new float[DIMS];
 
   float maxwidth;
 
@@ -87,11 +82,11 @@ public class RotatableCanvas extends Panel implements MouseListener,
 
   int npoint;
 
-  Vector points;
+  List<SequencePoint> points;
 
-  float[][] orig;
+  Point[] orig;
 
-  float[][] axes;
+  Point[] axisEndPoints;
 
   int startx;
 
@@ -115,9 +110,10 @@ public class RotatableCanvas extends Panel implements MouseListener,
 
   boolean showLabels = false;
 
-  public RotatableCanvas(AlignmentViewport av)
+  public RotatableCanvas(AlignmentViewport viewport)
   {
-    this.av = av;
+    this.av = viewport;
+    axisEndPoints = new Point[DIMS];
   }
 
   public void showLabels(boolean b)
@@ -126,46 +122,23 @@ public class RotatableCanvas extends Panel implements MouseListener,
     repaint();
   }
 
-  public void setPoints(Vector points, int npoint)
+  @Override
+  public void setPoints(List<SequencePoint> points, int npoint)
   {
     this.points = points;
     this.npoint = npoint;
     PaintRefresher.Register(this, av.getSequenceSetId());
 
     prefsize = getPreferredSize();
-    orig = new float[npoint][3];
+    orig = new Point[npoint];
 
     for (int i = 0; i < npoint; i++)
     {
-      SequencePoint sp = (SequencePoint) points.elementAt(i);
-      for (int j = 0; j < 3; j++)
-      {
-        orig[i][j] = sp.coord[j];
-      }
-    }
-    // Initialize the matrices to identity
-
-    for (int i = 0; i < 3; i++)
-    {
-      for (int j = 0; j < 3; j++)
-      {
-        if (i != j)
-        {
-          idmat.addElement(i, j, 0);
-          objmat.addElement(i, j, 0);
-          rotmat.addElement(i, j, 0);
-        }
-        else
-        {
-          idmat.addElement(i, j, 0);
-          objmat.addElement(i, j, 0);
-          rotmat.addElement(i, j, 0);
-        }
-      }
+      SequencePoint sp = points.get(i);
+      orig[i] = sp.coord;
     }
 
-    axes = new float[3][3];
-    initAxes();
+    resetAxes();
 
     findCentre();
     findWidth();
@@ -195,115 +168,93 @@ public class RotatableCanvas extends Panel implements MouseListener,
    * super.removeNotify(); }
    */
 
-  public void initAxes()
+  /**
+   * Resets axes to the initial state: x-axis to the right, y-axis up, z-axis to
+   * back (so obscured in a 2-D display)
+   */
+  public void resetAxes()
   {
-    for (int i = 0; i < 3; i++)
-    {
-      for (int j = 0; j < 3; j++)
-      {
-        if (i != j)
-        {
-          axes[i][j] = 0;
-        }
-        else
-        {
-          axes[i][j] = 1;
-        }
-      }
-    }
+    axisEndPoints[0] = new Point(1f, 0f, 0f);
+    axisEndPoints[1] = new Point(0f, 1f, 0f);
+    axisEndPoints[2] = new Point(0f, 0f, 1f);
   }
 
+  /**
+   * Computes and saves the maximum and minimum (x, y, z) positions of any
+   * sequence point, and also the min-max range (width) for each dimension, and
+   * the maximum width for all dimensions
+   */
   public void findWidth()
   {
     max = new float[3];
     min = new float[3];
 
-    max[0] = (float) -1e30;
-    max[1] = (float) -1e30;
-    max[2] = (float) -1e30;
+    max[0] = Float.MIN_VALUE;
+    max[1] = Float.MIN_VALUE;
+    max[2] = Float.MIN_VALUE;
 
-    min[0] = (float) 1e30;
-    min[1] = (float) 1e30;
-    min[2] = (float) 1e30;
+    min[0] = Float.MAX_VALUE;
+    min[1] = Float.MAX_VALUE;
+    min[2] = Float.MAX_VALUE;
 
-    for (int i = 0; i < 3; i++)
+    for (SequencePoint sp : points)
     {
-      for (int j = 0; j < npoint; j++)
-      {
-        SequencePoint sp = (SequencePoint) points.elementAt(j);
-        if (sp.coord[i] >= max[i])
-        {
-          max[i] = sp.coord[i];
-        }
-        if (sp.coord[i] <= min[i])
-        {
-          min[i] = sp.coord[i];
-        }
-      }
+      max[0] = Math.max(max[0], sp.coord.x);
+      max[1] = Math.max(max[1], sp.coord.y);
+      max[2] = Math.max(max[2], sp.coord.z);
+      min[0] = Math.min(min[0], sp.coord.x);
+      min[1] = Math.min(min[1], sp.coord.y);
+      min[2] = Math.min(min[2], sp.coord.z);
     }
 
-    // System.out.println("xmax " + max[0] + " min " + min[0]);
-    // System.out.println("ymax " + max[1] + " min " + min[1]);
-    // System.out.println("zmax " + max[2] + " min " + min[2]);
-
     width[0] = Math.abs(max[0] - min[0]);
     width[1] = Math.abs(max[1] - min[1]);
     width[2] = Math.abs(max[2] - min[2]);
 
-    maxwidth = width[0];
-
-    if (width[1] > width[0])
-    {
-      maxwidth = width[1];
-    }
-    if (width[2] > width[1])
-    {
-      maxwidth = width[2];
-    }
-
-    // System.out.println("Maxwidth = " + maxwidth);
+    maxwidth = Math.max(width[0], Math.max(width[1], width[2]));
   }
 
   public float findScale()
   {
-    int dim, width, height;
+    int dim, w, height;
     if (getSize().width != 0)
     {
-      width = getSize().width;
+      w = getSize().width;
       height = getSize().height;
     }
     else
     {
-      width = prefsize.width;
+      w = prefsize.width;
       height = prefsize.height;
     }
 
-    if (width < height)
+    if (w < height)
     {
-      dim = width;
+      dim = w;
     }
     else
     {
       dim = height;
     }
 
-    return (float) (dim * scalefactor / (2 * maxwidth));
+    return dim * scalefactor / (2 * maxwidth);
   }
 
+  /**
+   * Computes and saves the position of the centre of the view
+   */
   public void findCentre()
   {
-    // Find centre coordinate
     findWidth();
 
-    centre[0] = (max[0] + min[0]) / 2;
-    centre[1] = (max[1] + min[1]) / 2;
-    centre[2] = (max[2] + min[2]) / 2;
+    float x = (max[0] + min[0]) / 2;
+    float y = (max[1] + min[1]) / 2;
+    float z = (max[2] + min[2]) / 2;
 
-    // System.out.println("Centre x " + centre[0]);
-    // System.out.println("Centre y " + centre[1]);
-    // System.out.println("Centre z " + centre[2]);
+    centre = new Point(x, y, z);
   }
 
+  @Override
   public Dimension getPreferredSize()
   {
     if (prefsize != null)
@@ -316,16 +267,19 @@ public class RotatableCanvas extends Panel implements MouseListener,
     }
   }
 
+  @Override
   public Dimension getMinimumSize()
   {
     return getPreferredSize();
   }
 
+  @Override
   public void update(Graphics g)
   {
     paint(g);
   }
 
+  @Override
   public void paint(Graphics g)
   {
     if (points == null)
@@ -355,7 +309,7 @@ public class RotatableCanvas extends Panel implements MouseListener,
 
       drawBackground(ig, Color.black);
       drawScene(ig);
-      if (drawAxes == true)
+      if (drawAxes)
       {
         drawAxes(ig);
       }
@@ -377,8 +331,8 @@ public class RotatableCanvas extends Panel implements MouseListener,
     for (int i = 0; i < 3; i++)
     {
       g.drawLine(getSize().width / 2, getSize().height / 2,
-              (int) (axes[i][0] * scale * max[0] + getSize().width / 2),
-              (int) (axes[i][1] * scale * max[1] + getSize().height / 2));
+              (int) (axisEndPoints[i].x * scale * max[0] + getSize().width / 2),
+              (int) (axisEndPoints[i].y * scale * max[1] + getSize().height / 2));
     }
   }
 
@@ -390,81 +344,85 @@ public class RotatableCanvas extends Panel implements MouseListener,
 
   public void drawScene(Graphics g)
   {
-    // boolean darker = false;
-
-    int halfwidth = getSize().width / 2;
-    int halfheight = getSize().height / 2;
-
     for (int i = 0; i < npoint; i++)
     {
-      SequencePoint sp = (SequencePoint) points.elementAt(i);
-      int x = (int) ((float) (sp.coord[0] - centre[0]) * scale) + halfwidth;
-      int y = (int) ((float) (sp.coord[1] - centre[1]) * scale)
-              + halfheight;
-      float z = sp.coord[1] - centre[2];
-
-      if (av.getSequenceColour(sp.sequence) == Color.black)
-      {
-        g.setColor(Color.white);
-      }
-      else
-      {
-        g.setColor(av.getSequenceColour(sp.sequence));
-      }
-
+      SequencePoint sp = points.get(i);
+      SequenceI sequence = sp.getSequence();
+      Color sequenceColour = av.getSequenceColour(sequence);
+      g.setColor(
+              sequenceColour == Color.black ? Color.white : sequenceColour);
       if (av.getSelectionGroup() != null)
       {
         if (av.getSelectionGroup().getSequences(null)
-                .contains(((SequencePoint) points.elementAt(i)).sequence))
+                .contains(sequence))
         {
           g.setColor(Color.gray);
         }
       }
-      if (z < 0)
+
+      if (sp.coord.z < centre.z)
       {
         g.setColor(g.getColor().darker());
       }
 
+      int halfwidth = getSize().width / 2;
+      int halfheight = getSize().height / 2;
+      int x = (int) ((sp.coord.x - centre.x) * scale) + halfwidth;
+      int y = (int) ((sp.coord.y - centre.y) * scale) + halfheight;
       g.fillRect(x - 3, y - 3, 6, 6);
+
       if (showLabels)
       {
         g.setColor(Color.red);
-        g.drawString(
-                ((SequencePoint) points.elementAt(i)).sequence.getName(),
-                x - 3, y - 4);
+        g.drawString(sequence.getName(), x - 3, y - 4);
       }
     }
   }
 
-  public Dimension minimumsize()
-  {
-    return prefsize;
-  }
-
-  public Dimension preferredsize()
-  {
-    return prefsize;
-  }
-
+  @Override
   public void keyTyped(KeyEvent evt)
   {
   }
 
+  @Override
   public void keyReleased(KeyEvent evt)
   {
   }
 
+  @Override
   public void keyPressed(KeyEvent evt)
   {
-    if (evt.getKeyCode() == KeyEvent.VK_UP)
+    boolean shiftDown = evt.isShiftDown();
+    int keyCode = evt.getKeyCode();
+    if (keyCode == KeyEvent.VK_UP)
+    {
+      if (shiftDown)
+      {
+        rotate(0f, -1f);
+      }
+      else
+      {
+        zoom(1.1f);
+      }
+    }
+    else if (keyCode == KeyEvent.VK_DOWN)
     {
-      scalefactor = (float) (scalefactor * 1.1);
-      scale = findScale();
+      if (shiftDown)
+      {
+        rotate(0f, 1f);
+      }
+      else
+      {
+        zoom(0.9f);
+      }
     }
-    else if (evt.getKeyCode() == KeyEvent.VK_DOWN)
+    else if (shiftDown && keyCode == KeyEvent.VK_LEFT)
     {
-      scalefactor = (float) (scalefactor * 0.9);
-      scale = findScale();
+      rotate(1f, 0f);
+    }
+    else if (shiftDown && keyCode == KeyEvent.VK_RIGHT)
+    {
+      rotate(-1f, 0f);
     }
     else if (evt.getKeyChar() == 's')
     {
@@ -478,46 +436,34 @@ public class RotatableCanvas extends Panel implements MouseListener,
     repaint();
   }
 
-  public void printPoints()
-  {
-    for (int i = 0; i < npoint; i++)
-    {
-      SequencePoint sp = (SequencePoint) points.elementAt(i);
-      Format.print(System.out, "%5d ", i);
-      for (int j = 0; j < 3; j++)
-      {
-        Format.print(System.out, "%13.3f  ", sp.coord[j]);
-      }
-      System.out.println();
-    }
-  }
-
+  @Override
   public void mouseClicked(MouseEvent evt)
   {
   }
 
+  @Override
   public void mouseEntered(MouseEvent evt)
   {
   }
 
+  @Override
   public void mouseExited(MouseEvent evt)
   {
   }
 
+  @Override
   public void mouseReleased(MouseEvent evt)
   {
   }
 
+  @Override
   public void mousePressed(MouseEvent evt)
   {
     int x = evt.getX();
     int y = evt.getY();
 
-    mx = x;
-    my = y;
-
-    omx = mx;
-    omy = my;
+    mouseX = x;
+    mouseY = y;
 
     startx = x;
     starty = y;
@@ -528,7 +474,7 @@ public class RotatableCanvas extends Panel implements MouseListener,
     rectx2 = -1;
     recty2 = -1;
 
-    SequenceI found = findPoint(x, y);
+    SequenceI found = findSequenceAtPoint(x, y);
 
     if (found != null)
     {
@@ -552,9 +498,10 @@ public class RotatableCanvas extends Panel implements MouseListener,
     repaint();
   }
 
+  @Override
   public void mouseMoved(MouseEvent evt)
   {
-    SequenceI found = findPoint(evt.getX(), evt.getY());
+    SequenceI found = findSequenceAtPoint(evt.getX(), evt.getY());
     if (found == null)
     {
       tooltip = null;
@@ -568,40 +515,22 @@ public class RotatableCanvas extends Panel implements MouseListener,
     repaint();
   }
 
+  @Override
   public void mouseDragged(MouseEvent evt)
   {
-    mx = evt.getX();
-    my = evt.getY();
-
-    rotmat.setIdentity();
+    int xPos = evt.getX();
+    int yPos = evt.getY();
 
-    rotmat.rotate((float) (my - omy), 'x');
-    rotmat.rotate((float) (mx - omx), 'y');
-
-    for (int i = 0; i < npoint; i++)
+    if (xPos == mouseX && yPos == mouseY)
     {
-      SequencePoint sp = (SequencePoint) points.elementAt(i);
-      sp.coord[0] -= centre[0];
-      sp.coord[1] -= centre[1];
-      sp.coord[2] -= centre[2];
-
-      // Now apply the rotation matrix
-      sp.coord = rotmat.vectorMultiply(sp.coord);
-
-      // Now translate back again
-      sp.coord[0] += centre[0];
-      sp.coord[1] += centre[1];
-      sp.coord[2] += centre[2];
+      return;
     }
 
-    for (int i = 0; i < 3; i++)
-    {
-      axes[i] = rotmat.vectorMultiply(axes[i]);
-    }
-    omx = mx;
-    omy = my;
+    int xDelta = xPos - mouseX;
+    int yDelta = yPos - mouseY;
 
-    paint(this.getGraphics());
+    rotate(xDelta, yDelta);
+    repaint();
   }
 
   public void rectSelect(int x1, int y1, int x2, int y2)
@@ -609,29 +538,38 @@ public class RotatableCanvas extends Panel implements MouseListener,
     // boolean changedSel = false;
     for (int i = 0; i < npoint; i++)
     {
-      SequencePoint sp = (SequencePoint) points.elementAt(i);
-      int tmp1 = (int) ((sp.coord[0] - centre[0]) * scale
-              + (float) getSize().width / 2.0);
-      int tmp2 = (int) ((sp.coord[1] - centre[1]) * scale
-              + (float) getSize().height / 2.0);
+      SequencePoint sp = points.get(i);
+      int tmp1 = (int) ((sp.coord.x - centre.x) * scale
+              + getSize().width / 2.0);
+      int tmp2 = (int) ((sp.coord.y - centre.y) * scale
+              + getSize().height / 2.0);
 
+      SequenceI sequence = sp.getSequence();
       if (tmp1 > x1 && tmp1 < x2 && tmp2 > y1 && tmp2 < y2)
       {
         if (av != null)
         {
           if (!av.getSelectionGroup().getSequences(null)
-                  .contains(sp.sequence))
+                  .contains(sequence))
           {
-            av.getSelectionGroup().addSequence(sp.sequence, true);
+            av.getSelectionGroup().addSequence(sequence, true);
           }
         }
       }
     }
   }
 
-  public SequenceI findPoint(int x, int y)
+  /**
+   * Answers the first sequence found whose point on the display is within 2
+   * pixels of the given coordinates, or null if none is found
+   * 
+   * @param x
+   * @param y
+   * 
+   * @return
+   */
+  public SequenceI findSequenceAtPoint(int x, int y)
   {
-
     int halfwidth = getSize().width / 2;
     int halfheight = getSize().height / 2;
 
@@ -640,20 +578,22 @@ public class RotatableCanvas extends Panel implements MouseListener,
     for (int i = 0; i < npoint; i++)
     {
 
-      SequencePoint sp = (SequencePoint) points.elementAt(i);
-      int px = (int) ((float) (sp.coord[0] - centre[0]) * scale)
+      SequencePoint sp = points.get(i);
+      int px = (int) ((sp.coord.x - centre.x) * scale)
               + halfwidth;
-      int py = (int) ((float) (sp.coord[1] - centre[1]) * scale)
+      int py = (int) ((sp.coord.y - centre.y) * scale)
               + halfheight;
 
       if (Math.abs(px - x) < 3 && Math.abs(py - y) < 3)
       {
         found = i;
+        break;
       }
     }
+
     if (found != -1)
     {
-      return ((SequencePoint) points.elementAt(found)).sequence;
+      return points.get(found).getSequence();
     }
     else
     {
@@ -661,4 +601,79 @@ public class RotatableCanvas extends Panel implements MouseListener,
     }
   }
 
+  /**
+   * Resets the view to initial state (no rotation)
+   */
+  public void resetView()
+  {
+    img = null;
+    resetAxes();
+  }
+
+  @Override
+  public void zoom(float factor)
+  {
+    if (factor > 0f)
+    {
+      scalefactor *= factor;
+    }
+    scale = findScale();
+  }
+
+  @Override
+  public void rotate(float x, float y)
+  {
+    if (x == 0f && y == 0f)
+    {
+      return;
+    }
+  
+    /*
+     * get the identity transformation...
+     */
+    RotatableMatrix rotmat = new RotatableMatrix();
+  
+    /*
+     * rotate around the X axis for change in Y
+     * (mouse movement up/down); note we are equating a
+     * number of pixels with degrees of rotation here!
+     */
+    if (y != 0)
+    {
+      rotmat.rotate(y, Axis.X);
+    }
+  
+    /*
+     * rotate around the Y axis for change in X
+     * (mouse movement left/right)
+     */
+    if (x != 0)
+    {
+      rotmat.rotate(x, Axis.Y);
+    }
+  
+    /*
+     * apply the composite transformation to sequence points
+     */
+    for (int i = 0; i < npoint; i++)
+    {
+      SequencePoint sp = points.get(i);
+      sp.translate(-centre.x, -centre.y, -centre.z);
+
+      // Now apply the rotation matrix
+      sp.coord = rotmat.vectorMultiply(sp.coord);
+
+      // Now translate back again
+      sp.translate(centre.x, centre.y, centre.z);
+    }
+  
+    /*
+     * rotate the x/y/z axis positions
+     */
+    for (int i = 0; i < DIMS; i++)
+    {
+      axisEndPoints[i] = rotmat.vectorMultiply(axisEndPoints[i]);
+    }
+  }
+
 }
index 35d73de..96eb6b9 100755 (executable)
@@ -136,13 +136,6 @@ public class SeqCanvas extends Panel implements ViewportListenerI
               .visibleToAbsoluteColumn(endx);
     }
 
-    int maxwidth = av.getAlignment().getWidth();
-    if (av.hasHiddenColumns())
-    {
-      maxwidth = av.getAlignment().getHiddenColumns()
-              .absoluteToVisibleColumn(maxwidth) - 1;
-    }
-
     // WEST SCALE
     for (int i = 0; i < av.getAlignment().getHeight(); i++)
     {
@@ -450,13 +443,7 @@ public class SeqCanvas extends Panel implements ViewportListenerI
     int endx;
     int ypos = hgap;
   
-    int maxwidth = av.getAlignment().getWidth();
-  
-    if (av.hasHiddenColumns())
-    {
-      maxwidth = av.getAlignment().getHiddenColumns()
-              .absoluteToVisibleColumn(maxwidth);
-    }
+    int maxwidth = av.getAlignment().getVisibleWidth();
   
     while ((ypos <= canvasHeight) && (startRes < maxwidth))
     {
@@ -565,7 +552,7 @@ public class SeqCanvas extends Panel implements ViewportListenerI
       int blockEnd;
 
       HiddenColumns hidden = av.getAlignment().getHiddenColumns();
-      VisibleContigsIterator regions = (VisibleContigsIterator) hidden
+      VisibleContigsIterator regions = hidden
               .getVisContigsIterator(startRes, endRes + 1, true);
 
       while (regions.hasNext())
index 6ee75bd..cb26fb5 100755 (executable)
@@ -631,7 +631,7 @@ public class TreeCanvas extends Panel
 
       Vector<SequenceNode> l = tree.findLeaves(groups.get(i));
 
-      Vector<SequenceI> sequences = new Vector<SequenceI>();
+      Vector<SequenceI> sequences = new Vector<>();
       for (int j = 0; j < l.size(); j++)
       {
         SequenceI s1 = (SequenceI) l.elementAt(j).element();
@@ -657,7 +657,8 @@ public class TreeCanvas extends Panel
         }
         else
         {
-          cs = ColourSchemeProperty.getColourScheme(sg, ColourSchemeProperty
+          cs = ColourSchemeProperty.getColourScheme(av, sg,
+                  ColourSchemeProperty
                   .getColourName(av.getGlobalColourScheme()));
         }
         // cs is null if shading is an annotationColourGradient
index 83bc810..19aa800 100755 (executable)
@@ -114,7 +114,6 @@ import org.apache.log4j.SimpleLayout;
  * service</li>
  * <li>USAGESTATS (false - user prompted) Enable google analytics tracker for
  * collecting usage statistics</li>
- * <li>DAS_LOCAL_SOURCE list of local das sources</li>
  * <li>SHOW_OVERVIEW boolean for overview window display</li>
  * <li>ANTI_ALIAS boolean for smooth fonts</li>
  * <li>RIGHT_ALIGN_IDS boolean</li>
@@ -134,9 +133,7 @@ import org.apache.log4j.SimpleLayout;
  * sequence id (must be in SEQUENCE_LINKS or STORED_LINKS)
  * <li>GROUP_LINKS list of name|URL[|&lt;separator&gt;] tuples - see
  * jalview.utils.GroupURLLink for more info</li>
- * <li>DAS_REGISTRY_URL the registry to query</li>
  * <li>DEFAULT_BROWSER for unix</li>
- * <li>DAS_ACTIVE_SOURCE list of active sources</li>
  * <li>SHOW_MEMUSAGE boolean show memory usage and warning indicator on desktop
  * (false)</li>
  * <li>VERSION_CHECK (true) check for the latest release version from
@@ -226,12 +223,6 @@ public class Cache
    */
   public static final String JALVIEWLOGLEVEL = "logs.Jalview.level";
 
-  public static final String DAS_LOCAL_SOURCE = "DAS_LOCAL_SOURCE";
-
-  public static final String DAS_REGISTRY_URL = "DAS_REGISTRY_URL";
-
-  public static final String DAS_ACTIVE_SOURCE = "DAS_ACTIVE_SOURCE";
-
   /**
    * Sifts settings
    */
@@ -600,6 +591,24 @@ public class Cache
     return def;
   }
 
+  public static int getDefault(String property, int def)
+  {
+    String string = getProperty(property);
+    if (string != null)
+    {
+      try
+      {
+        def = Integer.parseInt(string);
+      } catch (NumberFormatException e)
+      {
+        System.out.println("Error parsing int property '" + property
+                + "' with value '" + string + "'");
+      }
+    }
+
+    return def;
+  }
+
   /**
    * These methods are used when checking if the saved preference is different
    * to the default setting
index 3270144..cc41c53 100755 (executable)
@@ -391,10 +391,7 @@ public class Jalview
     FileFormatI format = null;
     DataSourceType protocol = null;
     FileLoader fileLoader = new FileLoader(!headless);
-    Vector<String> getFeatures = null; // vector of das source nicknames to
-                                       // fetch
-    // features from
-    // loading is done.
+
     String groovyscript = null; // script to execute after all loading is
     // completed one way or another
     // extract groovy argument and execute if necessary
@@ -541,7 +538,8 @@ public class Jalview
           data.replaceAll("%20", " ");
 
           ColourSchemeI cs = ColourSchemeProperty
-                  .getColourScheme(af.getViewport().getAlignment(), data);
+                  .getColourScheme(af.getViewport(),
+                          af.getViewport().getAlignment(), data);
 
           if (cs != null)
           {
@@ -625,27 +623,6 @@ public class Jalview
         // TODO - load PDB structure(s) to alignment JAL-629
         // (associate with identical sequence in alignment, or a specified
         // sequence)
-
-        getFeatures = checkDasArguments(aparser);
-        if (af != null && getFeatures != null)
-        {
-          FeatureFetcher ff = startFeatureFetching(getFeatures);
-          if (ff != null)
-          {
-            while (!ff.allFinished() || af.operationInProgress())
-            {
-              // wait around until fetching is finished.
-              try
-              {
-                Thread.sleep(100);
-              } catch (Exception e)
-              {
-
-              }
-            }
-          }
-          getFeatures = null; // have retrieved features - forget them now.
-        }
         if (groovyscript != null)
         {
           // Execute the groovy script after we've done all the rendering stuff
@@ -787,20 +764,9 @@ public class Jalview
 
       startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
               format);
-      getFeatures = checkDasArguments(aparser);
       // extract groovy arguments before anything else.
     }
-    // If the user has specified features to be retrieved,
-    // or a groovy script to be executed, do them if they
-    // haven't been done already
-    // fetch features for the default alignment
-    if (getFeatures != null)
-    {
-      if (startUpAlframe != null)
-      {
-        startFeatureFetching(getFeatures);
-      }
-    }
+
     // Once all other stuff is done, execute any groovy scripts (in order)
     if (groovyscript != null)
     {
@@ -863,9 +829,6 @@ public class Jalview
                     // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
                     // passed in correctly)"
                     + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
-                    + "-dasserver nickname=URL\tAdd and enable a das server with given nickname\n\t\t\t(alphanumeric or underscores only) for retrieval of features for all alignments.\n"
-                    + "\t\t\tSources that also support the sequence command may be specified by prepending the URL with sequence:\n"
-                    + "\t\t\t e.g. sequence:http://localdas.somewhere.org/das/source)\n"
                     + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
                     // +
                     // "-vdoc vamsas-document\tImport vamsas document into new
@@ -1024,94 +987,6 @@ public class Jalview
     }
   }
 
-  /**
-   * Check commandline for any das server definitions or any fetchfrom switches
-   * 
-   * @return vector of DAS source nicknames to retrieve from
-   */
-  private static Vector<String> checkDasArguments(ArgsParser aparser)
-  {
-    Vector<String> source = null;
-    String data;
-    String locsources = Cache.getProperty(Cache.DAS_LOCAL_SOURCE);
-    while ((data = aparser.getValue("dasserver", true)) != null)
-    {
-      String nickname = null;
-      String url = null;
-      int pos = data.indexOf('=');
-      // determine capabilities
-      if (pos > 0)
-      {
-        nickname = data.substring(0, pos);
-      }
-      url = data.substring(pos + 1);
-      if (url != null && (url.startsWith("http:")
-              || url.startsWith("sequence:http:")))
-      {
-        if (nickname == null)
-        {
-          nickname = url;
-        }
-        if (locsources == null)
-        {
-          locsources = "";
-        }
-        else
-        {
-          locsources += "\t";
-        }
-        locsources = locsources + nickname + "|" + url;
-        System.err.println(
-                "NOTE! dasserver parameter not yet really supported (got args of "
-                        + nickname + "|" + url);
-        if (source == null)
-        {
-          source = new Vector<>();
-        }
-        source.addElement(nickname);
-      }
-      System.out.println(
-              "CMD [-dasserver " + data + "] executed successfully!");
-    } // loop until no more server entries are found.
-    if (locsources != null && locsources.indexOf('|') > -1)
-    {
-      Cache.log.debug("Setting local source list in properties file to:\n"
-              + locsources);
-      Cache.setProperty(Cache.DAS_LOCAL_SOURCE, locsources);
-    }
-    while ((data = aparser.getValue("fetchfrom", true)) != null)
-    {
-      System.out.println("adding source '" + data + "'");
-      if (source == null)
-      {
-        source = new Vector<>();
-      }
-      source.addElement(data);
-    }
-    return source;
-  }
-
-  /**
-   * start a feature fetcher for every alignment frame
-   * 
-   * @param dasSources
-   */
-  private FeatureFetcher startFeatureFetching(
-          final Vector<String> dasSources)
-  {
-    FeatureFetcher ff = new FeatureFetcher();
-    AlignFrame afs[] = Desktop.getAlignFrames();
-    if (afs == null || afs.length == 0)
-    {
-      return null;
-    }
-    for (int i = 0; i < afs.length; i++)
-    {
-      ff.addFetcher(afs[i], dasSources);
-    }
-    return ff;
-  }
-
   public static boolean isHeadlessMode()
   {
     String isheadless = System.getProperty("java.awt.headless");
index cac843f..b9d32f7 100644 (file)
  */
 package jalview.commands;
 
+import jalview.analysis.AlignSeq;
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.Annotation;
+import jalview.datamodel.ContiguousI;
+import jalview.datamodel.Range;
 import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
+import jalview.datamodel.features.SequenceFeaturesI;
+import jalview.util.Comparison;
 import jalview.util.ReverseListIterator;
 import jalview.util.StringUtils;
 
@@ -114,7 +119,7 @@ public class EditCommand implements CommandI
     public abstract Action getUndoAction();
   };
 
-  private List<Edit> edits = new ArrayList<Edit>();
+  private List<Edit> edits = new ArrayList<>();
 
   String description;
 
@@ -330,20 +335,8 @@ public class EditCommand implements CommandI
           int position, int number, AlignmentI al, boolean performEdit,
           AlignmentI[] views)
   {
-    Edit edit = new Edit(command, seqs, position, number,
-            al.getGapCharacter());
-    if (al.getHeight() == seqs.length)
-    {
-      edit.al = al;
-      edit.fullAlignmentHeight = true;
-    }
-
-    addEdit(edit);
-
-    if (performEdit)
-    {
-      performEdit(edit, views);
-    }
+    Edit edit = new Edit(command, seqs, position, number, al);
+    appendEdit(edit, al, performEdit, views);
   }
 
   /**
@@ -534,39 +527,62 @@ public class EditCommand implements CommandI
         command.string[i] = sequence.getSequence(command.position,
                 command.position + command.number);
         SequenceI oldds = sequence.getDatasetSequence();
+        ContiguousI cutPositions = sequence.findPositions(
+                command.position + 1, command.position + command.number);
+        boolean cutIsInternal = cutPositions != null
+                && sequence.getStart() != cutPositions
+                .getBegin() && sequence.getEnd() != cutPositions.getEnd();
+
+        /*
+         * perform the cut; if this results in a new dataset sequence, add
+         * that to the alignment dataset
+         */
+        SequenceI ds = sequence.getDatasetSequence();
+        sequence.deleteChars(command.position, command.position
+                + command.number);
+
         if (command.oldds != null && command.oldds[i] != null)
         {
-          // we are redoing an undone cut.
-          sequence.setDatasetSequence(null);
-        }
-        sequence.deleteChars(command.position,
-                command.position + command.number);
-        if (command.oldds != null && command.oldds[i] != null)
-        {
-          // oldds entry contains the cut dataset sequence.
+          /*
+           * we are Redoing a Cut, or Undoing a Paste - so
+           * oldds entry contains the cut dataset sequence,
+           * with sequence features in expected place
+           */
           sequence.setDatasetSequence(command.oldds[i]);
           command.oldds[i] = oldds;
         }
         else
         {
-          // modify the oldds if necessary
+          /* 
+           * new cut operation: save the dataset sequence 
+           * so it can be restored in an Undo
+           */
+          if (command.oldds == null)
+          {
+            command.oldds = new SequenceI[command.seqs.length];
+          }
+          command.oldds[i] = oldds;// todo not if !cutIsInternal?
+
+          // do we need to edit sequence features for new sequence ?
           if (oldds != sequence.getDatasetSequence()
-                  || sequence.getFeatures().hasFeatures())
+                  || (cutIsInternal
+                          && sequence.getFeatures().hasFeatures()))
+          // todo or just test cutIsInternal && cutPositions != null ?
           {
-            if (command.oldds == null)
+            if (cutPositions != null)
             {
-              command.oldds = new SequenceI[command.seqs.length];
+              cutFeatures(command, sequence, cutPositions.getBegin(),
+                              cutPositions.getEnd(), cutIsInternal);
             }
-            command.oldds[i] = oldds;
-            // FIXME JAL-2541 JAL-2526 get correct positions if on a gap
-            adjustFeatures(
-                    command,
-                    i,
-                    sequence.findPosition(command.position),
-                    sequence.findPosition(command.position + command.number),
-                    false);
           }
         }
+        SequenceI newDs = sequence.getDatasetSequence();
+        if (newDs != ds && command.al != null
+                && command.al.getDataset() != null
+                && !command.al.getDataset().getSequences().contains(newDs))
+        {
+          command.al.getDataset().addSequence(newDs);
+        }
       }
 
       if (sequence.getLength() < 1)
@@ -588,21 +604,19 @@ public class EditCommand implements CommandI
    */
   static void paste(Edit command, AlignmentI[] views)
   {
-    StringBuffer tmp;
-    boolean newDSNeeded;
-    boolean newDSWasNeeded;
-    int newstart, newend;
     boolean seqWasDeleted = false;
-    int start = 0, end = 0;
 
     for (int i = 0; i < command.seqs.length; i++)
     {
-      newDSNeeded = false;
-      newDSWasNeeded = command.oldds != null && command.oldds[i] != null;
-      if (command.seqs[i].getLength() < 1)
+      boolean newDSNeeded = false;
+      boolean newDSWasNeeded = command.oldds != null
+              && command.oldds[i] != null;
+      SequenceI sequence = command.seqs[i];
+      if (sequence.getLength() < 1)
       {
-        // ie this sequence was deleted, we need to
-        // readd it to the alignment
+        /*
+         * sequence was deleted; re-add it to the alignment
+         */
         if (command.alIndex[i] < command.al.getHeight())
         {
           List<SequenceI> sequences;
@@ -610,68 +624,78 @@ public class EditCommand implements CommandI
           {
             if (!(command.alIndex[i] < 0))
             {
-              sequences.add(command.alIndex[i], command.seqs[i]);
+              sequences.add(command.alIndex[i], sequence);
             }
           }
         }
         else
         {
-          command.al.addSequence(command.seqs[i]);
+          command.al.addSequence(sequence);
         }
         seqWasDeleted = true;
       }
-      newstart = command.seqs[i].getStart();
-      newend = command.seqs[i].getEnd();
+      int newStart = sequence.getStart();
+      int newEnd = sequence.getEnd();
 
-      tmp = new StringBuffer();
-      tmp.append(command.seqs[i].getSequence());
+      StringBuilder tmp = new StringBuilder();
+      tmp.append(sequence.getSequence());
       // Undo of a delete does not replace original dataset sequence on to
       // alignment sequence.
 
+      int start = 0;
+      int length = 0;
+
       if (command.string != null && command.string[i] != null)
       {
         if (command.position >= tmp.length())
         {
           // This occurs if padding is on, and residues
           // are removed from end of alignment
-          int length = command.position - tmp.length();
-          while (length > 0)
+          int len = command.position - tmp.length();
+          while (len > 0)
           {
             tmp.append(command.gapChar);
-            length--;
+            len--;
           }
         }
         tmp.insert(command.position, command.string[i]);
         for (int s = 0; s < command.string[i].length; s++)
         {
-          if (jalview.schemes.ResidueProperties.aaIndex[command.string[i][s]] != 23)
+          if (!Comparison.isGap(command.string[i][s]))
           {
+            length++;
             if (!newDSNeeded)
             {
               newDSNeeded = true;
-              start = command.seqs[i].findPosition(command.position);
-              end = command.seqs[i]
-                      .findPosition(command.position + command.number);
+              start = sequence.findPosition(command.position);
+              // end = sequence
+              // .findPosition(command.position + command.number);
             }
-            if (command.seqs[i].getStart() == start)
+            if (sequence.getStart() == start)
             {
-              newstart--;
+              newStart--;
             }
             else
             {
-              newend++;
+              newEnd++;
             }
           }
         }
         command.string[i] = null;
       }
 
-      command.seqs[i].setSequence(tmp.toString());
-      command.seqs[i].setStart(newstart);
-      command.seqs[i].setEnd(newend);
+      sequence.setSequence(tmp.toString());
+      sequence.setStart(newStart);
+      sequence.setEnd(newEnd);
+
+      /*
+       * command and Undo share the same dataset sequence if cut was
+       * at start or end of sequence
+       */
+      boolean sameDatasetSequence = false;
       if (newDSNeeded)
       {
-        if (command.seqs[i].getDatasetSequence() != null)
+        if (sequence.getDatasetSequence() != null)
         {
           SequenceI ds;
           if (newDSWasNeeded)
@@ -682,21 +706,29 @@ public class EditCommand implements CommandI
           {
             // make a new DS sequence
             // use new ds mechanism here
-            ds = new Sequence(command.seqs[i].getName(),
-                    jalview.analysis.AlignSeq.extractGaps(
-                            jalview.util.Comparison.GapChars,
-                            command.seqs[i].getSequenceAsString()),
-                    command.seqs[i].getStart(), command.seqs[i].getEnd());
-            ds.setDescription(command.seqs[i].getDescription());
+            String ungapped = AlignSeq.extractGaps(Comparison.GapChars,
+                    sequence.getSequenceAsString());
+            ds = new Sequence(sequence.getName(), ungapped,
+                    sequence.getStart(), sequence.getEnd());
+            ds.setDescription(sequence.getDescription());
           }
           if (command.oldds == null)
           {
             command.oldds = new SequenceI[command.seqs.length];
           }
-          command.oldds[i] = command.seqs[i].getDatasetSequence();
-          command.seqs[i].setDatasetSequence(ds);
+          command.oldds[i] = sequence.getDatasetSequence();
+          sameDatasetSequence = ds == sequence.getDatasetSequence();
+          ds.setSequenceFeatures(sequence.getSequenceFeatures());
+          if (!sameDatasetSequence && command.al.getDataset() != null)
+          {
+            // delete 'undone' sequence from alignment dataset
+            command.al.getDataset()
+                    .deleteSequence(sequence.getDatasetSequence());
+          }
+          sequence.setDatasetSequence(ds);
         }
-        adjustFeatures(command, i, start, end, true);
+        undoCutFeatures(command, command.seqs[i], start, length,
+                sameDatasetSequence);
       }
     }
     adjustAnnotations(command, true, seqWasDeleted, views);
@@ -706,7 +738,7 @@ public class EditCommand implements CommandI
 
   static void replace(Edit command)
   {
-    StringBuffer tmp;
+    StringBuilder tmp;
     String oldstring;
     int start = command.position;
     int end = command.number;
@@ -719,6 +751,7 @@ public class EditCommand implements CommandI
     {
       boolean newDSWasNeeded = command.oldds != null
               && command.oldds[i] != null;
+      boolean newStartEndWasNeeded = command.oldStartEnd!=null && command.oldStartEnd[i]!=null;
 
       /**
        * cut addHistoryItem(new EditCommand("Cut Sequences", EditCommand.CUT,
@@ -731,49 +764,147 @@ public class EditCommand implements CommandI
        * EditCommand.PASTE, sequences, 0, alignment.getWidth(), alignment) );
        * 
        */
+      ContiguousI beforeEditedPositions = command.seqs[i].findPositions(1,
+              start);
+      ContiguousI afterEditedPositions = command.seqs[i]
+              .findPositions(end + 1, command.seqs[i].getLength());
+      
       oldstring = command.seqs[i].getSequenceAsString();
-      tmp = new StringBuffer(oldstring.substring(0, start));
+      tmp = new StringBuilder(oldstring.substring(0, start));
       tmp.append(command.string[i]);
-      String nogaprep = jalview.analysis.AlignSeq.extractGaps(
-              jalview.util.Comparison.GapChars,
+      String nogaprep = AlignSeq.extractGaps(Comparison.GapChars,
               new String(command.string[i]));
-      int ipos = command.seqs[i].findPosition(start)
-              - command.seqs[i].getStart();
-      tmp.append(oldstring.substring(end));
+      if (end < oldstring.length())
+      {
+        tmp.append(oldstring.substring(end));
+      }
+      // stash end prior to updating the sequence object so we can save it if
+      // need be.
+      Range oldstartend = new Range(command.seqs[i].getStart(),
+              command.seqs[i].getEnd());
       command.seqs[i].setSequence(tmp.toString());
-      command.string[i] = oldstring.substring(start, end).toCharArray();
-      String nogapold = jalview.analysis.AlignSeq.extractGaps(
-              jalview.util.Comparison.GapChars,
+      command.string[i] = oldstring
+              .substring(start, Math.min(end, oldstring.length()))
+              .toCharArray();
+      String nogapold = AlignSeq.extractGaps(Comparison.GapChars,
               new String(command.string[i]));
+
       if (!nogaprep.toLowerCase().equals(nogapold.toLowerCase()))
       {
-        if (newDSWasNeeded)
+        // we may already have dataset and limits stashed...
+        if (newDSWasNeeded || newStartEndWasNeeded)
         {
+          if (newDSWasNeeded)
+          {
+          // then just switch the dataset sequence
           SequenceI oldds = command.seqs[i].getDatasetSequence();
           command.seqs[i].setDatasetSequence(command.oldds[i]);
           command.oldds[i] = oldds;
+          }
+          if (newStartEndWasNeeded)
+          {
+            Range newStart = command.oldStartEnd[i];
+            command.oldStartEnd[i] = oldstartend;
+            command.seqs[i].setStart(newStart.getBegin());
+            command.seqs[i].setEnd(newStart.getEnd());
+          }
         }
-        else
+        else         
         {
-          if (command.oldds == null)
+          // decide if we need a new dataset sequence or modify start/end
+          // first edit the original dataset sequence string
+          SequenceI oldds = command.seqs[i].getDatasetSequence();
+          String osp = oldds.getSequenceAsString();
+          int beforeStartOfEdit = -oldds.getStart() + 1
+                  + (beforeEditedPositions == null
+                          ? ((afterEditedPositions != null)
+                                  ? afterEditedPositions.getBegin() - 1
+                                  : oldstartend.getBegin()
+                                          + nogapold.length())
+                          : beforeEditedPositions.getEnd()
+                  );
+          int afterEndOfEdit = -oldds.getStart() + 1
+                  + ((afterEditedPositions == null)
+                  ? oldstartend.getEnd()
+                          : afterEditedPositions.getBegin() - 1);
+          String fullseq = osp.substring(0,
+                  beforeStartOfEdit)
+                  + nogaprep
+                  + osp.substring(afterEndOfEdit);
+
+          // and check if new sequence data is different..
+          if (!fullseq.equalsIgnoreCase(osp))
           {
-            command.oldds = new SequenceI[command.seqs.length];
-          }
-          command.oldds[i] = command.seqs[i].getDatasetSequence();
-          SequenceI newds = new Sequence(
-                  command.seqs[i].getDatasetSequence());
-          String fullseq, osp = newds.getSequenceAsString();
-          fullseq = osp.substring(0, ipos) + nogaprep
-                  + osp.substring(ipos + nogaprep.length());
-          newds.setSequence(fullseq.toUpperCase());
-          // TODO: JAL-1131 ensure newly created dataset sequence is added to
-          // the set of
-          // dataset sequences associated with the alignment.
-          // TODO: JAL-1131 fix up any annotation associated with new dataset
-          // sequence to ensure that original sequence/annotation relationships
-          // are preserved.
-          command.seqs[i].setDatasetSequence(newds);
+            // old ds and edited ds are different, so
+            // create the new dataset sequence
+            SequenceI newds = new Sequence(oldds);
+            newds.setSequence(fullseq);
+
+            if (command.oldds == null)
+            {
+              command.oldds = new SequenceI[command.seqs.length];
+            }
+            command.oldds[i] = command.seqs[i].getDatasetSequence();
 
+            // And preserve start/end for good-measure
+
+            if (command.oldStartEnd == null)
+            {
+              command.oldStartEnd = new Range[command.seqs.length];
+            }
+            command.oldStartEnd[i] = oldstartend;
+            // TODO: JAL-1131 ensure newly created dataset sequence is added to
+            // the set of
+            // dataset sequences associated with the alignment.
+            // TODO: JAL-1131 fix up any annotation associated with new dataset
+            // sequence to ensure that original sequence/annotation
+            // relationships
+            // are preserved.
+            command.seqs[i].setDatasetSequence(newds);
+          }
+          else
+          {
+            if (command.oldStartEnd == null)
+            {
+              command.oldStartEnd = new Range[command.seqs.length];
+            }
+            command.oldStartEnd[i] = new Range(command.seqs[i].getStart(),
+                    command.seqs[i].getEnd());
+            if (beforeEditedPositions != null
+                    && afterEditedPositions == null)
+            {
+              // modification at end
+              command.seqs[i].setEnd(
+                      beforeEditedPositions.getEnd() + nogaprep.length()
+                              - nogapold.length());
+            }
+            else if (afterEditedPositions != null
+                    && beforeEditedPositions == null)
+            {
+              // modification at start
+              command.seqs[i].setStart(
+                      afterEditedPositions.getBegin() - nogaprep.length());
+            }
+            else
+            {
+              // edit covered both start and end. Here we can only guess the
+              // new
+              // start/end
+              String nogapalseq = AlignSeq.extractGaps(Comparison.GapChars,
+                      command.seqs[i].getSequenceAsString().toUpperCase());
+              int newStart = command.seqs[i].getDatasetSequence()
+                      .getSequenceAsString().indexOf(nogapalseq);
+              if (newStart == -1)
+              {
+                throw new Error(
+                        "Implementation Error: could not locate start/end "
+                                + "in dataset sequence after an edit of the sequence string");
+              }
+              int newEnd = newStart + nogapalseq.length() - 1;
+              command.seqs[i].setStart(newStart);
+              command.seqs[i].setEnd(newEnd);
+            }
+          }
         }
       }
       tmp = null;
@@ -789,7 +920,7 @@ public class EditCommand implements CommandI
     if (modifyVisibility && !insert)
     {
       // only occurs if a sequence was added or deleted.
-      command.deletedAnnotationRows = new Hashtable<SequenceI, AlignmentAnnotation[]>();
+      command.deletedAnnotationRows = new Hashtable<>();
     }
     if (command.fullAlignmentHeight)
     {
@@ -892,8 +1023,7 @@ public class EditCommand implements CommandI
                 }
                 // and then duplicate added annotation on every other alignment
                 // view
-                for (int vnum = 0; views != null
-                        && vnum < views.length; vnum++)
+                for (int vnum = 0; views != null && vnum < views.length; vnum++)
                 {
                   if (views[vnum] != command.al)
                   {
@@ -948,7 +1078,7 @@ public class EditCommand implements CommandI
 
     if (!insert)
     {
-      command.deletedAnnotations = new Hashtable<String, Annotation[]>();
+      command.deletedAnnotations = new Hashtable<>();
     }
 
     int aSize;
@@ -1109,98 +1239,97 @@ public class EditCommand implements CommandI
     }
   }
 
-  final static void adjustFeatures(Edit command, int index, final int i,
-          final int j, boolean insert)
+  /**
+   * Restores features to the state before a Cut.
+   * <ul>
+   * <li>re-add any features deleted by the cut</li>
+   * <li>remove any truncated features created by the cut</li>
+   * <li>shift right any features to the right of the cut</li>
+   * </ul>
+   * 
+   * @param command
+   *          the Cut command
+   * @param seq
+   *          the sequence the Cut applied to
+   * @param start
+   *          the start residue position of the cut
+   * @param length
+   *          the number of residues cut
+   * @param sameDatasetSequence
+   *          true if dataset sequence and frame of reference were left
+   *          unchanged by the Cut
+   */
+  final static void undoCutFeatures(Edit command, SequenceI seq,
+          final int start, final int length, boolean sameDatasetSequence)
   {
-    SequenceI seq = command.seqs[index];
     SequenceI sequence = seq.getDatasetSequence();
     if (sequence == null)
     {
       sequence = seq;
     }
 
-    if (insert)
+    /*
+     * shift right features that lie to the right of the restored cut (but not 
+     * if dataset sequence unchanged - so coordinates were changed by Cut)
+     */
+    if (!sameDatasetSequence)
     {
-      if (command.editedFeatures != null
-              && command.editedFeatures.containsKey(seq))
+      /*
+       * shift right all features right of and not 
+       * contiguous with the cut position
+       */
+      seq.getFeatures().shiftFeatures(start + 1, length);
+
+      /*
+       * shift right any features that start at the cut position,
+       * unless they were truncated
+       */
+      List<SequenceFeature> sfs = seq.getFeatures().findFeatures(start,
+              start);
+      for (SequenceFeature sf : sfs)
       {
-        sequence.setSequenceFeatures(command.editedFeatures.get(seq));
+        if (sf.getBegin() == start)
+        {
+          if (!command.truncatedFeatures.containsKey(seq)
+                  || !command.truncatedFeatures.get(seq).contains(sf))
+          {
+            /*
+             * feature was shifted left to cut position (not truncated),
+             * so shift it back right
+             */
+            SequenceFeature shifted = new SequenceFeature(sf, sf.getBegin()
+                    + length, sf.getEnd() + length, sf.getFeatureGroup(),
+                    sf.getScore());
+            seq.addSequenceFeature(shifted);
+            seq.deleteFeature(sf);
+          }
+        }
       }
-
-      return;
     }
 
-    List<SequenceFeature> sf = sequence.getFeatures()
-            .getPositionalFeatures();
-
-    if (sf.isEmpty())
-    {
-      return;
-    }
-
-    List<SequenceFeature> oldsf = new ArrayList<SequenceFeature>();
-
-    int cSize = j - i;
-
-    for (SequenceFeature feature : sf)
+    /*
+     * restore any features that were deleted or truncated
+     */
+    if (command.deletedFeatures != null
+            && command.deletedFeatures.containsKey(seq))
     {
-      SequenceFeature copy = new SequenceFeature(feature);
-
-      oldsf.add(copy);
-
-      if (feature.getEnd() < i)
-      {
-        continue;
-      }
-
-      if (feature.getBegin() > j)
-      {
-        int newBegin = copy.getBegin() - cSize;
-        int newEnd = copy.getEnd() - cSize;
-        SequenceFeature newSf = new SequenceFeature(feature, newBegin,
-                newEnd, feature.getFeatureGroup(), feature.getScore());
-        sequence.deleteFeature(feature);
-        sequence.addSequenceFeature(newSf);
-        // feature.setBegin(newBegin);
-        // feature.setEnd(newEnd);
-        continue;
-      }
-
-      int newBegin = feature.getBegin();
-      int newEnd = feature.getEnd();
-      if (newBegin >= i)
-      {
-        newBegin = i;
-        // feature.setBegin(i);
-      }
-
-      if (newEnd < j)
+      for (SequenceFeature deleted : command.deletedFeatures.get(seq))
       {
-        newEnd = j - 1;
-        // feature.setEnd(j - 1);
+        sequence.addSequenceFeature(deleted);
       }
-      newEnd = newEnd - cSize;
-      // feature.setEnd(feature.getEnd() - (cSize));
-
-      sequence.deleteFeature(feature);
-      if (newEnd >= newBegin)
-      {
-        sequence.addSequenceFeature(new SequenceFeature(feature, newBegin,
-                newEnd, feature.getFeatureGroup(), feature.getScore()));
-      }
-      // if (feature.getBegin() > feature.getEnd())
-      // {
-      // sequence.deleteFeature(feature);
-      // }
     }
 
-    if (command.editedFeatures == null)
+    /*
+     * delete any truncated features
+     */
+    if (command.truncatedFeatures != null
+            && command.truncatedFeatures.containsKey(seq))
     {
-      command.editedFeatures = new Hashtable<SequenceI, List<SequenceFeature>>();
+      for (SequenceFeature amended : command.truncatedFeatures.get(seq))
+      {
+        sequence.deleteFeature(amended);
+      }
     }
-
-    command.editedFeatures.put(seq, oldsf);
-
   }
 
   /**
@@ -1233,7 +1362,7 @@ public class EditCommand implements CommandI
    */
   public Map<SequenceI, SequenceI> priorState(boolean forUndo)
   {
-    Map<SequenceI, SequenceI> result = new HashMap<SequenceI, SequenceI>();
+    Map<SequenceI, SequenceI> result = new HashMap<>();
     if (getEdits() == null)
     {
       return result;
@@ -1266,7 +1395,7 @@ public class EditCommand implements CommandI
      * Work backwards through the edit list, deriving the sequences before each
      * was applied. The final result is the sequence set before any edits.
      */
-    Iterator<Edit> editList = new ReverseListIterator<Edit>(getEdits());
+    Iterator<Edit> editList = new ReverseListIterator<>(getEdits());
     while (editList.hasNext())
     {
       Edit oldEdit = editList.next();
@@ -1315,29 +1444,51 @@ public class EditCommand implements CommandI
 
   public class Edit
   {
-    public SequenceI[] oldds;
+    private SequenceI[] oldds;
 
-    boolean fullAlignmentHeight = false;
+    /**
+     * start and end of sequence prior to edit
+     */
+    private Range[] oldStartEnd;
 
-    Hashtable<SequenceI, AlignmentAnnotation[]> deletedAnnotationRows;
+    private boolean fullAlignmentHeight = false;
 
-    Hashtable<String, Annotation[]> deletedAnnotations;
+    private Map<SequenceI, AlignmentAnnotation[]> deletedAnnotationRows;
 
-    Hashtable<SequenceI, List<SequenceFeature>> editedFeatures;
+    private Map<String, Annotation[]> deletedAnnotations;
 
-    AlignmentI al;
+    /*
+     * features deleted by the cut (re-add on Undo)
+     * (including the original of any shortened features)
+     */
+    private Map<SequenceI, List<SequenceFeature>> deletedFeatures;
+
+    /*
+     * shortened features added by the cut (delete on Undo)
+     */
+    private Map<SequenceI, List<SequenceFeature>> truncatedFeatures;
+
+    private AlignmentI al;
 
-    Action command;
+    final private Action command;
 
     char[][] string;
 
     SequenceI[] seqs;
 
-    int[] alIndex;
+    private int[] alIndex;
+
+    private int position;
 
-    int position, number;
+    private int number;
 
-    char gapChar;
+    private char gapChar;
+
+    /*
+     * flag that identifies edits inserted to balance 
+     * user edits in a 'locked editing' region
+     */
+    private boolean systemGenerated;
 
     public Edit(Action cmd, SequenceI[] sqs, int pos, int count,
             char gap)
@@ -1352,11 +1503,8 @@ public class EditCommand implements CommandI
     Edit(Action cmd, SequenceI[] sqs, int pos, int count,
             AlignmentI align)
     {
-      this.gapChar = align.getGapCharacter();
-      this.command = cmd;
-      this.seqs = sqs;
-      this.position = pos;
-      this.number = count;
+      this(cmd, sqs, pos, count, align.getGapCharacter());
+
       this.al = align;
 
       alIndex = new int[sqs.length];
@@ -1368,22 +1516,26 @@ public class EditCommand implements CommandI
       fullAlignmentHeight = (align.getHeight() == sqs.length);
     }
 
+    /**
+     * Constructor given a REPLACE command and the replacement string
+     * 
+     * @param cmd
+     * @param sqs
+     * @param pos
+     * @param count
+     * @param align
+     * @param replace
+     */
     Edit(Action cmd, SequenceI[] sqs, int pos, int count,
             AlignmentI align, String replace)
     {
-      this.command = cmd;
-      this.seqs = sqs;
-      this.position = pos;
-      this.number = count;
-      this.al = align;
-      this.gapChar = align.getGapCharacter();
+      this(cmd, sqs, pos, count, align);
+
       string = new char[sqs.length][];
       for (int i = 0; i < sqs.length; i++)
       {
         string[i] = replace.toCharArray();
       }
-
-      fullAlignmentHeight = (align.getHeight() == sqs.length);
     }
 
     public SequenceI[] getSequences()
@@ -1410,6 +1562,16 @@ public class EditCommand implements CommandI
     {
       return gapChar;
     }
+
+    public void setSystemGenerated(boolean b)
+    {
+      systemGenerated = b;
+    }
+
+    public boolean isSystemGenerated()
+    {
+      return systemGenerated;
+    }
   }
 
   /**
@@ -1427,7 +1589,163 @@ public class EditCommand implements CommandI
     }
     else
     {
-      return new ReverseListIterator<Edit>(getEdits());
+      return new ReverseListIterator<>(getEdits());
+    }
+  }
+
+  /**
+   * Adjusts features for Cut, and saves details of changes made to allow Undo
+   * <ul>
+   * <li>features left of the cut are unchanged</li>
+   * <li>features right of the cut are shifted left</li>
+   * <li>features internal to the cut region are deleted</li>
+   * <li>features that overlap or span the cut are shortened</li>
+   * <li>the originals of any deleted or shortened features are saved, to re-add
+   * on Undo</li>
+   * <li>any added (shortened) features are saved, to delete on Undo</li>
+   * </ul>
+   * 
+   * @param command
+   * @param seq
+   * @param fromPosition
+   * @param toPosition
+   * @param cutIsInternal
+   */
+  protected static void cutFeatures(Edit command, SequenceI seq,
+          int fromPosition, int toPosition, boolean cutIsInternal)
+  {
+    /* 
+     * if the cut is at start or end of sequence
+     * then we don't modify the sequence feature store
+     */
+    if (!cutIsInternal)
+    {
+      return;
+    }
+    List<SequenceFeature> added = new ArrayList<>();
+    List<SequenceFeature> removed = new ArrayList<>();
+  
+    SequenceFeaturesI featureStore = seq.getFeatures();
+    if (toPosition < fromPosition || featureStore == null)
+    {
+      return;
+    }
+  
+    int cutStartPos = fromPosition;
+    int cutEndPos = toPosition;
+    int cutWidth = cutEndPos - cutStartPos + 1;
+  
+    synchronized (featureStore)
+    {
+      /*
+       * get features that overlap the cut region
+       */
+      List<SequenceFeature> toAmend = featureStore.findFeatures(
+              cutStartPos, cutEndPos);
+  
+      /*
+       * add any contact features that span the cut region
+       * (not returned by findFeatures)
+       */
+      for (SequenceFeature contact : featureStore.getContactFeatures())
+      {
+        if (contact.getBegin() < cutStartPos
+                && contact.getEnd() > cutEndPos)
+        {
+          toAmend.add(contact);
+        }
+      }
+
+      /*
+       * adjust start-end of overlapping features;
+       * delete features enclosed by the cut;
+       * delete partially overlapping contact features
+       */
+      for (SequenceFeature sf : toAmend)
+      {
+        int sfBegin = sf.getBegin();
+        int sfEnd = sf.getEnd();
+        int newBegin = sfBegin;
+        int newEnd = sfEnd;
+        boolean toDelete = false;
+        boolean follows = false;
+        
+        if (sfBegin >= cutStartPos && sfEnd <= cutEndPos)
+        {
+          /*
+           * feature lies within cut region - delete it
+           */
+          toDelete = true;
+        }
+        else if (sfBegin < cutStartPos && sfEnd > cutEndPos)
+        {
+          /*
+           * feature spans cut region - left-shift the end
+           */
+          newEnd -= cutWidth;
+        }
+        else if (sfEnd <= cutEndPos)
+        {
+          /*
+           * feature overlaps left of cut region - truncate right
+           */
+          newEnd = cutStartPos - 1;
+          if (sf.isContactFeature())
+          {
+            toDelete = true;
+          }
+        }
+        else if (sfBegin >= cutStartPos)
+        {
+          /*
+           * remaining case - feature overlaps right
+           * truncate left, adjust end of feature
+           */
+          newBegin = cutIsInternal ? cutStartPos : cutEndPos + 1;
+          newEnd = newBegin + sfEnd - cutEndPos - 1;
+          if (sf.isContactFeature())
+          {
+            toDelete = true;
+          }
+        }
+  
+        seq.deleteFeature(sf);
+        if (!follows)
+        {
+          removed.add(sf);
+        }
+        if (!toDelete)
+        {
+          SequenceFeature copy = new SequenceFeature(sf, newBegin, newEnd,
+                  sf.getFeatureGroup(), sf.getScore());
+          seq.addSequenceFeature(copy);
+          if (!follows)
+          {
+            added.add(copy);
+          }
+        }
+      }
+  
+      /*
+       * and left shift any features lying to the right of the cut region
+       */
+
+      featureStore.shiftFeatures(cutEndPos + 1, -cutWidth);
+    }
+
+    /*
+     * save deleted and amended features, so that Undo can 
+     * re-add or delete them respectively
+     */
+    if (command.deletedFeatures == null)
+    {
+      command.deletedFeatures = new HashMap<>();
+    }
+    if (command.truncatedFeatures == null)
+    {
+      command.truncatedFeatures = new HashMap<>();
     }
+    command.deletedFeatures.put(seq, removed);
+    command.truncatedFeatures.put(seq, added);
   }
 }
index d992e4e..a82b98d 100644 (file)
@@ -35,6 +35,7 @@ import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
 import jalview.io.DataSourceType;
 import jalview.io.FeaturesFile;
+import jalview.schemes.ColourSchemeI;
 import jalview.util.MessageManager;
 
 import java.awt.Color;
@@ -97,19 +98,22 @@ public class AlignViewController implements AlignViewControllerI
       viewport.getAlignment().deleteAllGroups();
       viewport.clearSequenceColours();
       viewport.setSelectionGroup(null);
+      ColourSchemeI colours = viewport.getGlobalColourScheme();
       // set view properties for each group
       for (int g = 0; g < gps.length; g++)
       {
         // gps[g].setShowunconserved(viewport.getShowUnconserved());
         gps[g].setshowSequenceLogo(viewport.isShowSequenceLogo());
         viewport.getAlignment().addGroup(gps[g]);
-        Color col = new Color((int) (Math.random() * 255),
-                (int) (Math.random() * 255), (int) (Math.random() * 255));
-        col = col.brighter();
-        for (SequenceI sq : gps[g].getSequences(null))
+        if (colours != null)
         {
-          viewport.setSequenceColour(sq, col);
+          gps[g].setColourScheme(colours.getInstance(viewport, gps[g]));
         }
+        Color col = new Color((int) (Math.random() * 255),
+                (int) (Math.random() * 255), (int) (Math.random() * 255));
+        gps[g].idColour = col;
+        viewport.setUpdateStructures(true);
+        viewport.addSequenceGroup(gps[g]);
       }
       return true;
     }
index 3ba35b6..ac00fa2 100755 (executable)
@@ -712,39 +712,21 @@ public class Alignment implements AlignmentI
   
     for (int i = 0; i < sequences.size(); i++)
     {
-      if (getSequenceAt(i).getLength() > maxLength)
-      {
-        maxLength = getSequenceAt(i).getLength();
-      }
+      maxLength = Math.max(maxLength, getSequenceAt(i).getLength());
     }
-  
     return maxLength;
   }
-  /*
+
   @Override
-  public int getWidth()
+  public int getVisibleWidth()
   {
-    final Wrapper temp = new Wrapper();
-  
-    forEachSequence(new Consumer<SequenceI>()
+    int w = getWidth();
+    if (hiddenCols != null)
     {
-      @Override
-      public void accept(SequenceI s)
-      {
-        if (s.getLength() > temp.inner)
-        {
-          temp.inner = s.getLength();
-        }
-      }
-    }, 0, sequences.size() - 1);
-  
-    return temp.inner;
+      w -= hiddenCols.getSize();
+    }
+    return w;
   }
-  
-  public static class Wrapper
-  {
-    public int inner;
-  }*/
 
   /**
    * DOCUMENT ME!
@@ -1922,9 +1904,12 @@ public class Alignment implements AlignmentI
   }
 
   @Override
-  public void setHiddenColumns(HiddenColumns cols)
+  public boolean setHiddenColumns(HiddenColumns cols)
   {
+    boolean changed = cols == null ? hiddenCols != null
+            : !cols.equals(hiddenCols);
     hiddenCols = cols;
+    return changed;
   }
 
   @Override
index 5fb16d6..93a2456 100755 (executable)
@@ -48,15 +48,29 @@ public interface AlignmentI extends AnnotatedCollectionI
 
   /**
    * 
-   * Calculates the maximum width of the alignment, including gaps.
+   * Answers the width of the alignment, including gaps, that is, the length of
+   * the longest sequence, or -1 if there are no sequences. Avoid calling this
+   * method repeatedly where possible, as it has to perform a calculation. Note
+   * that this width includes any hidden columns.
    * 
-   * @return Greatest sequence length within alignment, or -1 if no sequences
-   *         present
+   * @return
+   * @see AlignmentI#getVisibleWidth()
    */
   @Override
   int getWidth();
 
   /**
+   * 
+   * Answers the visible width of the alignment, including gaps, that is, the
+   * length of the longest sequence, excluding any hidden columns. Answers -1 if
+   * there are no sequences. Avoid calling this method repeatedly where
+   * possible, as it has to perform a calculation.
+   * 
+   * @return
+   */
+  int getVisibleWidth();
+
+  /**
    * Calculates if this set of sequences (visible and invisible) are all the
    * same length
    * 
@@ -581,11 +595,13 @@ public interface AlignmentI extends AnnotatedCollectionI
   AlignedCodonFrame getMapping(SequenceI mapFrom, SequenceI mapTo);
 
   /**
-   * Set the hidden columns collection on the alignment
+   * Set the hidden columns collection on the alignment. Answers true if the
+   * hidden column selection changed, else false.
    * 
    * @param cols
+   * @return
    */
-  public void setHiddenColumns(HiddenColumns cols);
+  public boolean setHiddenColumns(HiddenColumns cols);
 
   /**
    * Set the first sequence as representative and hide its insertions. Typically
index d3d1b2b..e6604d1 100644 (file)
@@ -74,7 +74,7 @@ public class AlignmentView
 
     ScGroup()
     {
-      seqs = new ArrayList<SeqCigar>();
+      seqs = new ArrayList<>();
     }
 
     /**
@@ -160,7 +160,6 @@ public class AlignmentView
     SequenceI[] selseqs;
     if (selection != null && selection.getSize() > 0)
     {
-      List<SequenceI> sel = selection.getSequences(null);
       this.selected = new ScGroup();
       selseqs = selection.getSequencesInOrder(alignment,
               selectedRegionOnly);
@@ -170,9 +169,9 @@ public class AlignmentView
       selseqs = alignment.getSequencesArray();
     }
 
-    List<List<SequenceI>> seqsets = new ArrayList<List<SequenceI>>();
+    List<List<SequenceI>> seqsets = new ArrayList<>();
     // get the alignment's group list and make a copy
-    List<SequenceGroup> grps = new ArrayList<SequenceGroup>();
+    List<SequenceGroup> grps = new ArrayList<>();
     List<SequenceGroup> gg = alignment.getGroups();
     grps.addAll(gg);
     ScGroup[] sgrps = null;
@@ -185,7 +184,7 @@ public class AlignmentView
         // strip out any groups that do not actually intersect with the
         // visible and selected region
         int ssel = selection.getStartRes(), esel = selection.getEndRes();
-        List<SequenceGroup> isg = new ArrayList<SequenceGroup>();
+        List<SequenceGroup> isg = new ArrayList<>();
         for (SequenceGroup sg : grps)
         {
           if (!(sg.getStartRes() > esel || sg.getEndRes() < ssel))
@@ -245,7 +244,7 @@ public class AlignmentView
               {
                 if (scGroups == null)
                 {
-                  scGroups = new ArrayList<ScGroup>();
+                  scGroups = new ArrayList<>();
                 }
                 addedgps[sg] = true;
                 scGroups.add(sgrps[sg]);
index 6d620b4..3ccaab8 100644 (file)
@@ -27,6 +27,7 @@ import java.util.ArrayList;
 import java.util.BitSet;
 import java.util.Collections;
 import java.util.List;
+import java.util.regex.PatternSyntaxException;
 
 /**
  * Data class holding the selected columns and hidden column ranges for a view.
@@ -59,7 +60,7 @@ public class ColumnSelection
      */
     IntList()
     {
-      order = new ArrayList<Integer>();
+      order = new ArrayList<>();
       _uorder = Collections.unmodifiableList(order);
       selected = new BitSet();
     }
@@ -230,7 +231,7 @@ public class ColumnSelection
      */
     List<int[]> getRanges()
     {
-      List<int[]> rlist = new ArrayList<int[]>();
+      List<int[]> rlist = new ArrayList<>();
       if (selected.isEmpty())
       {
         return rlist;
@@ -263,7 +264,7 @@ public class ColumnSelection
     }
   }
 
-  IntList selection = new IntList();
+  private IntList selection = new IntList();
 
   /**
    * Add a column to the selection
@@ -533,92 +534,109 @@ public class ColumnSelection
     return (selection != null && selection.size() > 0);
   }
 
-  public boolean filterAnnotations(Annotation[] annotations,
+  /**
+   * Selects columns where the given annotation matches the provided filter
+   * condition(s). Any existing column selections are first cleared. Answers the
+   * number of columns added.
+   * 
+   * @param annotations
+   * @param filterParams
+   * @return
+   */
+  public int filterAnnotations(Annotation[] annotations,
           AnnotationFilterParameter filterParams)
   {
     // JBPNote - this method needs to be refactored to become independent of
     // viewmodel package
     this.clear();
-    int count = 0;
+    int addedCount = 0;
+    int column = 0;
     do
     {
-      if (annotations[count] != null)
+      Annotation ann = annotations[column];
+      if (ann != null)
       {
+        boolean matched = false;
 
-        boolean itemMatched = false;
-
+        /*
+         * filter may have multiple conditions - 
+         * these are or'd until a match is found
+         */
         if (filterParams
                 .getThresholdType() == AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD
-                && annotations[count].value >= filterParams
-                        .getThresholdValue())
+                && ann.value > filterParams.getThresholdValue())
         {
-          itemMatched = true;
+          matched = true;
         }
-        if (filterParams
+
+        if (!matched && filterParams
                 .getThresholdType() == AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD
-                && annotations[count].value <= filterParams
-                        .getThresholdValue())
+                && ann.value < filterParams.getThresholdValue())
         {
-          itemMatched = true;
+          matched = true;
         }
 
-        if (filterParams.isFilterAlphaHelix()
-                && annotations[count].secondaryStructure == 'H')
+        if (!matched && filterParams.isFilterAlphaHelix()
+                && ann.secondaryStructure == 'H')
         {
-          itemMatched = true;
+          matched = true;
         }
 
-        if (filterParams.isFilterBetaSheet()
-                && annotations[count].secondaryStructure == 'E')
+        if (!matched && filterParams.isFilterBetaSheet()
+                && ann.secondaryStructure == 'E')
         {
-          itemMatched = true;
+          matched = true;
         }
 
-        if (filterParams.isFilterTurn()
-                && annotations[count].secondaryStructure == 'S')
+        if (!matched && filterParams.isFilterTurn()
+                && ann.secondaryStructure == 'S')
         {
-          itemMatched = true;
+          matched = true;
         }
 
         String regexSearchString = filterParams.getRegexString();
-        if (regexSearchString != null
-                && !filterParams.getRegexSearchFields().isEmpty())
+        if (!matched && regexSearchString != null)
         {
           List<SearchableAnnotationField> fields = filterParams
                   .getRegexSearchFields();
-          try
+          for (SearchableAnnotationField field : fields)
           {
-            if (fields.contains(SearchableAnnotationField.DISPLAY_STRING)
-                    && annotations[count].displayCharacter
-                            .matches(regexSearchString))
+            String compareTo = field == SearchableAnnotationField.DISPLAY_STRING
+                    ? ann.displayCharacter // match 'Label'
+                    : ann.description; // and/or 'Description'
+            if (compareTo != null)
             {
-              itemMatched = true;
-            }
-          } catch (java.util.regex.PatternSyntaxException pse)
-          {
-            if (annotations[count].displayCharacter
-                    .equals(regexSearchString))
-            {
-              itemMatched = true;
+              try
+              {
+                if (compareTo.matches(regexSearchString))
+                {
+                  matched = true;
+                }
+              } catch (PatternSyntaxException pse)
+              {
+                if (compareTo.equals(regexSearchString))
+                {
+                  matched = true;
+                }
+              }
+              if (matched)
+              {
+                break;
+              }
             }
           }
-          if (fields.contains(SearchableAnnotationField.DESCRIPTION)
-                  && annotations[count].description != null
-                  && annotations[count].description
-                          .matches(regexSearchString))
-          {
-            itemMatched = true;
-          }
         }
 
-        if (itemMatched)
+        if (matched)
         {
-          this.addElement(count);
+          this.addElement(column);
+          addedCount++;
         }
       }
-      count++;
-    } while (count < annotations.length);
-    return false;
+      column++;
+    } while (column < annotations.length);
+
+    return addedCount;
   }
 
   /**
index a7e93da..2d43f02 100644 (file)
@@ -469,6 +469,10 @@ public class HiddenColumns
     }
   }
 
+  /**
+   * Answers true if obj is an instance of HiddenColumns, and holds the same
+   * array of start-end column ranges as this, else answers false
+   */
   @Override
   public boolean equals(Object obj)
   {
diff --git a/src/jalview/datamodel/Point.java b/src/jalview/datamodel/Point.java
new file mode 100644 (file)
index 0000000..e7c77c0
--- /dev/null
@@ -0,0 +1,71 @@
+package jalview.datamodel;
+
+/**
+ * A bean that models an (x, y, z) position in 3-D space
+ */
+public final class Point
+{
+  public final float x;
+
+  public final float y;
+
+  public final float z;
+
+  public Point(float xVal, float yVal, float zVal)
+  {
+    x = xVal;
+    y = yVal;
+    z = zVal;
+  }
+
+  /**
+   * toString for convenience of inspection in debugging or logging
+   */
+  @Override
+  public String toString()
+  {
+    return String.format("[%f, %f, %f]", x, y, z);
+  }
+
+  @Override
+  public int hashCode()
+  {
+    final int prime = 31;
+    int result = 1;
+    result = prime * result + Float.floatToIntBits(x);
+    result = prime * result + Float.floatToIntBits(y);
+    result = prime * result + Float.floatToIntBits(z);
+    return result;
+  }
+
+  @Override
+  public boolean equals(Object obj)
+  {
+    if (this == obj)
+    {
+      return true;
+    }
+    if (obj == null)
+    {
+      return false;
+    }
+    if (getClass() != obj.getClass())
+    {
+      return false;
+    }
+    Point other = (Point) obj;
+    if (Float.floatToIntBits(x) != Float.floatToIntBits(other.x))
+    {
+      return false;
+    }
+    if (Float.floatToIntBits(y) != Float.floatToIntBits(other.y))
+    {
+      return false;
+    }
+    if (Float.floatToIntBits(z) != Float.floatToIntBits(other.z))
+    {
+      return false;
+    }
+    return true;
+  }
+}
index a47ca8b..661ad6c 100644 (file)
@@ -47,4 +47,14 @@ public interface SearchResultMatchI
    */
   int getEnd();
 
+  /**
+   * Answers true if this match is for the given sequence and includes (matches
+   * or encloses) the given start-end range
+   * 
+   * @param seq
+   * @param start
+   * @param end
+   * @return
+   */
+  boolean contains(SequenceI seq, int start, int end);
 }
\ No newline at end of file
index d1e3fcc..31736e5 100755 (executable)
@@ -91,27 +91,18 @@ public class SearchResults implements SearchResultsI
       }
     }
 
-    /* (non-Javadoc)
-     * @see jalview.datamodel.SearchResultMatchI#getSequence()
-     */
     @Override
     public SequenceI getSequence()
     {
       return sequence;
     }
 
-    /* (non-Javadoc)
-     * @see jalview.datamodel.SearchResultMatchI#getStart()
-     */
     @Override
     public int getStart()
     {
       return start;
     }
 
-    /* (non-Javadoc)
-     * @see jalview.datamodel.SearchResultMatchI#getEnd()
-     */
     @Override
     public int getEnd()
     {
@@ -162,22 +153,25 @@ public class SearchResults implements SearchResultsI
       return (sequence == m.getSequence() && start == m.getStart()
               && end == m.getEnd());
     }
+
+    @Override
+    public boolean contains(SequenceI seq, int from, int to)
+    {
+      return (sequence == seq && start <= from && end >= to);
+    }
   }
 
-  /* (non-Javadoc)
-   * @see jalview.datamodel.SearchResultsI#addResult(jalview.datamodel.SequenceI, int, int)
-   */
   @Override
   public SearchResultMatchI addResult(SequenceI seq, int start, int end)
   {
     Match m = new Match(seq, start, end);
-    matches.add(m);
+    if (!matches.contains(m))
+    {
+      matches.add(m);
+    }
     return m;
   }
 
-  /* (non-Javadoc)
-   * @see jalview.datamodel.SearchResultsI#involvesSequence(jalview.datamodel.SequenceI)
-   */
   @Override
   public boolean involvesSequence(SequenceI sequence)
   {
@@ -193,9 +187,6 @@ public class SearchResults implements SearchResultsI
     return false;
   }
 
-  /* (non-Javadoc)
-   * @see jalview.datamodel.SearchResultsI#getResults(jalview.datamodel.SequenceI, int, int)
-   */
   @Override
   public int[] getResults(SequenceI sequence, int start, int end)
   {
@@ -290,27 +281,18 @@ public class SearchResults implements SearchResultsI
     return count;
   }
 
-  /* (non-Javadoc)
-   * @see jalview.datamodel.SearchResultsI#getSize()
-   */
   @Override
   public int getSize()
   {
     return matches.size();
   }
 
-  /* (non-Javadoc)
-   * @see jalview.datamodel.SearchResultsI#isEmpty()
-   */
   @Override
   public boolean isEmpty()
   {
     return matches.isEmpty();
   }
 
-  /* (non-Javadoc)
-   * @see jalview.datamodel.SearchResultsI#getResults()
-   */
   @Override
   public List<SearchResultMatchI> getResults()
   {
index c3dc0e8..3c3ad4e 100644 (file)
@@ -31,14 +31,11 @@ public interface SearchResultsI
 {
 
   /**
-   * Adds one region to the results
+   * Adds one region to the results (unless already added, to avoid duplicates)
    * 
    * @param seq
-   *          Sequence
    * @param start
-   *          int
    * @param end
-   *          int
    * @return
    */
   SearchResultMatchI addResult(SequenceI seq, int start, int end);
index 33de452..80310c0 100755 (executable)
@@ -43,10 +43,7 @@ import fr.orsay.lri.varna.models.rna.RNA;
 
 /**
  * 
- * Implements the SequenceI interface for a char[] based sequence object.
- * 
- * @author $author$
- * @version $Revision$
+ * Implements the SequenceI interface for a char[] based sequence object
  */
 public class Sequence extends ASequence implements SequenceI
 {
@@ -797,6 +794,7 @@ public class Sequence extends ASequence implements SequenceI
      * preserve end residue column provided cursor was valid
      */
     int endColumn = isValidCursor(cursor) ? cursor.lastColumnPosition : 0;
+
     if (residuePos == this.end)
     {
       endColumn = column;
@@ -833,8 +831,7 @@ public class Sequence extends ASequence implements SequenceI
     /*
      * move left or right to find pos from hint.position
      */
-    int col = curs.columnPosition - 1; // convert from base 1 to 0-based array
-                                       // index
+    int col = curs.columnPosition - 1; // convert from base 1 to base 0
     int newPos = curs.residuePosition;
     int delta = newPos > pos ? -1 : 1;
 
@@ -1069,7 +1066,7 @@ public class Sequence extends ASequence implements SequenceI
    * {@inheritDoc}
    */
   @Override
-  public Range findPositions(int fromColumn, int toColumn)
+  public ContiguousI findPositions(int fromColumn, int toColumn)
   {
     if (toColumn < fromColumn || fromColumn < 1)
     {
@@ -1263,12 +1260,13 @@ public class Sequence extends ASequence implements SequenceI
     boolean createNewDs = false;
     // TODO: take a (second look) at the dataset creation validation method for
     // the very large sequence case
+
     int startIndex = findIndex(start) - 1;
     int endIndex = findIndex(end) - 1;
     int startDeleteColumn = -1; // for dataset sequence deletions
     int deleteCount = 0;
 
-    for (int s = i; s < j; s++)
+    for (int s = i; s < j && s < sequence.length; s++)
     {
       if (Comparison.isGap(sequence[s]))
       {
@@ -1913,6 +1911,15 @@ public class Sequence extends ASequence implements SequenceI
 
     List<SequenceFeature> result = getFeatures().findFeatures(startPos,
             endPos, types);
+    if (datasetSequence != null)
+    {
+      result = datasetSequence.getFeatures().findFeatures(startPos, endPos,
+              types);
+    }
+    else
+    {
+      result = sequenceFeatureStore.findFeatures(startPos, endPos, types);
+    }
 
     /*
      * if end column is gapped, endPos may be to the right, 
index f681f11..e2bb5a6 100644 (file)
@@ -25,8 +25,21 @@ import java.util.Map;
 
 public interface SequenceCollectionI
 {
+  /**
+   * 
+   * @return (visible) sequences in this collection. This may be a direct
+   *         reference to the collection so not thread safe
+   */
   List<SequenceI> getSequences();
 
+  /**
+   * FIXME: AlignmentI.getSequences(hiddenReps) doesn't actually obey this
+   * contract!
+   * 
+   * @param hiddenReps
+   * @return the full set of sequences in this collection, including any
+   *         sequences represented by sequences in the collection.
+   */
   List<SequenceI> getSequences(
           Map<SequenceI, SequenceCollectionI> hiddenReps);
 
index 944f263..3bf7bc4 100755 (executable)
@@ -88,7 +88,7 @@ public class SequenceGroup implements AnnotatedCollectionI
   /**
    * group members
    */
-  private List<SequenceI> sequences = new ArrayList<>();
+  private List<SequenceI> sequences;
 
   /**
    * representative sequence for this group (if any)
@@ -102,11 +102,15 @@ public class SequenceGroup implements AnnotatedCollectionI
    */
   public ResidueShaderI cs;
 
-  // start column (base 0)
-  int startRes = 0;
+  /**
+   * start column (base 0)
+   */
+  private int startRes = 0;
 
-  // end column (base 0)
-  int endRes = 0;
+  /**
+   *  end column (base 0)
+   */
+  private int endRes = 0;
 
   public Color outlineColour = Color.black;
 
@@ -158,6 +162,7 @@ public class SequenceGroup implements AnnotatedCollectionI
   {
     groupName = "JGroup:" + this.hashCode();
     cs = new ResidueShader();
+    sequences = new ArrayList<>();
   }
 
   /**
@@ -209,6 +214,7 @@ public class SequenceGroup implements AnnotatedCollectionI
       displayBoxes = seqsel.displayBoxes;
       displayText = seqsel.displayText;
       colourText = seqsel.colourText;
+      
       startRes = seqsel.startRes;
       endRes = seqsel.endRes;
       cs = new ResidueShader((ResidueShader) seqsel.cs);
@@ -238,6 +244,17 @@ public class SequenceGroup implements AnnotatedCollectionI
     }
   }
 
+  /**
+   * Constructor that copies the given list of sequences
+   * 
+   * @param seqs
+   */
+  public SequenceGroup(List<SequenceI> seqs)
+  {
+    this();
+    this.sequences.addAll(seqs);
+  }
+
   public boolean isShowSequenceLogo()
   {
     return showSequenceLogo;
@@ -752,13 +769,16 @@ public class SequenceGroup implements AnnotatedCollectionI
   /**
    * Set the first column selected by this group. Runs from 0<=i<N_cols
    * 
-   * @param i
+   * @param newStart
    */
-  public void setStartRes(int i)
+  public void setStartRes(int newStart)
   {
     int before = startRes;
-    startRes = i;
-    changeSupport.firePropertyChange(SEQ_GROUP_CHANGED, before, startRes);
+   startRes= Math.max(0,newStart); // sanity check for negative start column positions
+   changeSupport.firePropertyChange(SEQ_GROUP_CHANGED, before, startRes);
+    
+
+
   }
 
   /**
index 8dce31e..15b61d2 100755 (executable)
@@ -112,9 +112,11 @@ public interface SequenceI extends ASequenceI
    * get a range on the sequence as a string
    * 
    * @param start
-   *          position relative to start of sequence including gaps (from 0)
+   *          (inclusive) position relative to start of sequence including gaps
+   *          (from 0)
    * @param end
-   *          position relative to start of sequence including gaps (from 0)
+   *          (exclusive) position relative to start of sequence including gaps
+   *          (from 0)
    * 
    * @return String containing all gap and symbols in specified range
    */
@@ -206,14 +208,17 @@ public interface SequenceI extends ASequenceI
   public int findPosition(int i);
 
   /**
-   * Returns the from-to sequence positions (start..) for the given column
-   * positions (1..), or null if no residues are included in the range
+   * Returns the sequence positions for first and last residues lying within the
+   * given column positions [fromColum,toColumn] (where columns are numbered
+   * from 1), or null if no residues are included in the range
    * 
    * @param fromColum
+   *          - first column base 1
    * @param toColumn
+   *          - last column, base 1
    * @return
    */
-  public Range findPositions(int fromColum, int toColumn);
+  public ContiguousI findPositions(int fromColum, int toColumn);
 
   /**
    * Returns an int array where indices correspond to each residue in the
index a6b967e..3db7cee 100755 (executable)
 package jalview.datamodel;
 
 /**
- * DOCUMENT ME!
- * 
- * @author $author$
- * @version $Revision$
+ * A bean that models a set of (x, y, z) values and a reference to a sequence.
+ * As used in Principal Component Analysis, the (x, y, z) values are the
+ * sequence's score for the currently selected first, second and third
+ * dimensions of the PCA.
  */
 public class SequencePoint
 {
-  // SMJS PUBLIC
+  /*
+   * Associated alignment sequence, or dummy sequence object
+   */
+  private final SequenceI sequence;
+
+  /*
+   * x, y, z values
+   */
+  public Point coord;
+
   /**
-   * for points with no real physical association with an alignment sequence
+   * Constructor
+   * 
+   * @param sequence
+   * @param coord
    */
-  public boolean isPlaceholder = false;
+  public SequencePoint(SequenceI sequence, Point pt)
+  {
+    this.sequence = sequence;
+    this.coord = pt;
+  }
 
   /**
-   * Associated alignment sequence, or dummy sequence object.
+   * Constructor given a sequence and an array of x, y, z coordinate positions
+   * 
+   * @param sequence
+   * @param coords
+   * @throws ArrayIndexOutOfBoundsException
+   *           if array length is less than 3
    */
-  public SequenceI sequence;
+  public SequencePoint(SequenceI sequence, float[] coords)
+  {
+    this(sequence, new Point(coords[0], coords[1], coords[2]));
+  }
+
+  public SequenceI getSequence()
+  {
+    return sequence;
+  }
 
   /**
-   * array of coordinates in embedded sequence space.
+   * Applies a translation to the (x, y, z) coordinates
+   * 
+   * @param centre
    */
-  public float[] coord;
+  public void translate(float x, float y, float z)
+  {
+    coord = new Point(coord.x + x, coord.y + y, coord.z + z);
+  }
 
-  // SMJS ENDPUBLIC
-  public SequencePoint(SequenceI sequence, float[] coord)
+  /**
+   * string representation for ease of inspection in debugging or logging only
+   */
+  @Override
+  public String toString()
   {
-    this.sequence = sequence;
-    this.coord = coord;
+    return sequence.getName() + " " + coord.toString();
   }
 }
index 378b8db..535346c 100644 (file)
  */
 package jalview.datamodel.features;
 
-import jalview.datamodel.ContiguousI;
+import intervalstore.api.IntervalI;
 
 /**
- * An extension of ContiguousI that allows start/end values to be interpreted
+ * An extension of IntervalI that allows start/end values to be interpreted
  * instead as two contact positions
  */
-public interface FeatureLocationI extends ContiguousI
+public interface FeatureLocationI extends IntervalI
 {
   boolean isContactFeature();
 }
index 02ce1c5..54c0d59 100644 (file)
  */
 package jalview.datamodel.features;
 
-import jalview.datamodel.ContiguousI;
 import jalview.datamodel.SequenceFeature;
 
 import java.util.ArrayList;
 import java.util.Collections;
-import java.util.Comparator;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
+import intervalstore.api.IntervalStoreI;
+import intervalstore.impl.BinarySearcher;
+import intervalstore.impl.IntervalStore;
+
 /**
  * A data store for a set of sequence features that supports efficient lookup of
  * features overlapping a given range. Intended for (but not limited to) storage
@@ -40,80 +42,6 @@ import java.util.Set;
  */
 public class FeatureStore
 {
-  /**
-   * a class providing criteria for performing a binary search of a list
-   */
-  abstract static class SearchCriterion
-  {
-    /**
-     * Answers true if the entry passes the search criterion test
-     * 
-     * @param entry
-     * @return
-     */
-    abstract boolean compare(SequenceFeature entry);
-
-    /**
-     * serves a search condition for finding the first feature whose start
-     * position follows a given target location
-     * 
-     * @param target
-     * @return
-     */
-    static SearchCriterion byStart(final long target)
-    {
-      return new SearchCriterion() {
-
-        @Override
-        boolean compare(SequenceFeature entry)
-        {
-          return entry.getBegin() >= target;
-        }
-      };
-    }
-
-    /**
-     * serves a search condition for finding the first feature whose end
-     * position is at or follows a given target location
-     * 
-     * @param target
-     * @return
-     */
-    static SearchCriterion byEnd(final long target)
-    {
-      return new SearchCriterion()
-      {
-
-        @Override
-        boolean compare(SequenceFeature entry)
-        {
-          return entry.getEnd() >= target;
-        }
-      };
-    }
-
-    /**
-     * serves a search condition for finding the first feature which follows the
-     * given range as determined by a supplied comparator
-     * 
-     * @param target
-     * @return
-     */
-    static SearchCriterion byFeature(final ContiguousI to,
-            final Comparator<ContiguousI> rc)
-    {
-      return new SearchCriterion()
-      {
-
-        @Override
-        boolean compare(SequenceFeature entry)
-        {
-          return rc.compare(entry, to) >= 0;
-        }
-      };
-    }
-  }
-
   /*
    * Non-positional features have no (zero) start/end position.
    * Kept as a separate list in case this criterion changes in future.
@@ -121,14 +49,6 @@ public class FeatureStore
   List<SequenceFeature> nonPositionalFeatures;
 
   /*
-   * An ordered list of features, with the promise that no feature in the list 
-   * properly contains any other. This constraint allows bounded linear search
-   * of the list for features overlapping a region.
-   * Contact features are not included in this list.
-   */
-  List<SequenceFeature> nonNestedFeatures;
-
-  /*
    * contact features ordered by first contact position
    */
   List<SequenceFeature> contactFeatureStarts;
@@ -139,13 +59,10 @@ public class FeatureStore
   List<SequenceFeature> contactFeatureEnds;
 
   /*
-   * Nested Containment List is used to hold any features that are nested 
-   * within (properly contained by) any other feature. This is a recursive tree
-   * which supports depth-first scan for features overlapping a range.
-   * It is used here as a 'catch-all' fallback for features that cannot be put
-   * into a simple ordered list without invalidating the search methods.
+   * IntervalStore holds remaining features and provides efficient
+   * query for features overlapping any given interval
    */
-  NCList<SequenceFeature> nestedFeatures;
+  IntervalStoreI<SequenceFeature> features;
 
   /*
    * Feature groups represented in stored positional features 
@@ -178,16 +95,15 @@ public class FeatureStore
    */
   public FeatureStore()
   {
-    nonNestedFeatures = new ArrayList<SequenceFeature>();
-    positionalFeatureGroups = new HashSet<String>();
-    nonPositionalFeatureGroups = new HashSet<String>();
+    features = new IntervalStore<>();
+    positionalFeatureGroups = new HashSet<>();
+    nonPositionalFeatureGroups = new HashSet<>();
     positionalMinScore = Float.NaN;
     positionalMaxScore = Float.NaN;
     nonPositionalMinScore = Float.NaN;
     nonPositionalMaxScore = Float.NaN;
 
-    // we only construct nonPositionalFeatures, contactFeatures
-    // or the NCList if we need to
+    // we only construct nonPositionalFeatures, contactFeatures if we need to
   }
 
   /**
@@ -213,58 +129,46 @@ public class FeatureStore
       positionalFeatureGroups.add(feature.getFeatureGroup());
     }
 
-    boolean added = false;
-
     if (feature.isContactFeature())
     {
-      added = addContactFeature(feature);
+      addContactFeature(feature);
     }
     else if (feature.isNonPositional())
     {
-      added = addNonPositionalFeature(feature);
+      addNonPositionalFeature(feature);
     }
     else
     {
-      added = addNonNestedFeature(feature);
-      if (!added)
-      {
-        /*
-         * detected a nested feature - put it in the NCList structure
-         */
-        added = addNestedFeature(feature);
-      }
+      addNestedFeature(feature);
     }
 
-    if (added)
-    {
-      /*
-       * record the total extent of positional features, to make
-       * getTotalFeatureLength possible; we count the length of a 
-       * contact feature as 1
-       */
-      totalExtent += getFeatureLength(feature);
+    /*
+     * record the total extent of positional features, to make
+     * getTotalFeatureLength possible; we count the length of a 
+     * contact feature as 1
+     */
+    totalExtent += getFeatureLength(feature);
 
-      /*
-       * record the minimum and maximum score for positional
-       * and non-positional features
-       */
-      float score = feature.getScore();
-      if (!Float.isNaN(score))
+    /*
+     * record the minimum and maximum score for positional
+     * and non-positional features
+     */
+    float score = feature.getScore();
+    if (!Float.isNaN(score))
+    {
+      if (feature.isNonPositional())
       {
-        if (feature.isNonPositional())
-        {
-          nonPositionalMinScore = min(nonPositionalMinScore, score);
-          nonPositionalMaxScore = max(nonPositionalMaxScore, score);
-        }
-        else
-        {
-          positionalMinScore = min(positionalMinScore, score);
-          positionalMaxScore = max(positionalMaxScore, score);
-        }
+        nonPositionalMinScore = min(nonPositionalMinScore, score);
+        nonPositionalMaxScore = max(nonPositionalMaxScore, score);
+      }
+      else
+      {
+        positionalMinScore = min(positionalMinScore, score);
+        positionalMaxScore = max(positionalMaxScore, score);
       }
     }
 
-    return added;
+    return true;
   }
 
   /**
@@ -288,12 +192,7 @@ public class FeatureStore
               contactFeatureStarts, feature);
     }
 
-    if (listContains(nonNestedFeatures, feature))
-    {
-      return true;
-    }
-
-    return nestedFeatures == null ? false : nestedFeatures
+    return features == null ? false : features
             .contains(feature);
   }
 
@@ -330,7 +229,7 @@ public class FeatureStore
   {
     if (nonPositionalFeatures == null)
     {
-      nonPositionalFeatures = new ArrayList<SequenceFeature>();
+      nonPositionalFeatures = new ArrayList<>();
     }
 
     nonPositionalFeatures.add(feature);
@@ -341,91 +240,16 @@ public class FeatureStore
   }
 
   /**
-   * Adds one feature to the NCList that can manage nested features (creating
-   * the NCList if necessary), and returns true. If the feature is already
-   * stored in the NCList (by equality test), then it is not added, and this
-   * method returns false.
-   */
-  protected synchronized boolean addNestedFeature(SequenceFeature feature)
-  {
-    if (nestedFeatures == null)
-    {
-      nestedFeatures = new NCList<>(feature);
-      return true;
-    }
-    return nestedFeatures.add(feature, false);
-  }
-
-  /**
-   * Add a feature to the list of non-nested features, maintaining the ordering
-   * of the list. A check is made for whether the feature is nested in (properly
-   * contained by) an existing feature. If there is no nesting, the feature is
-   * added to the list and the method returns true. If nesting is found, the
-   * feature is not added and the method returns false.
-   * 
-   * @param feature
-   * @return
-   */
-  protected boolean addNonNestedFeature(SequenceFeature feature)
-  {
-    synchronized (nonNestedFeatures)
-    {
-      /*
-       * find the first stored feature which doesn't precede the new one
-       */
-      int insertPosition = binarySearch(nonNestedFeatures,
-              SearchCriterion.byFeature(feature, RangeComparator.BY_START_POSITION));
-
-      /*
-       * fail if we detect feature enclosure - of the new feature by
-       * the one preceding it, or of the next feature by the new one
-       */
-      if (insertPosition > 0)
-      {
-        if (encloses(nonNestedFeatures.get(insertPosition - 1), feature))
-        {
-          return false;
-        }
-      }
-      if (insertPosition < nonNestedFeatures.size())
-      {
-        if (encloses(feature, nonNestedFeatures.get(insertPosition)))
-        {
-          return false;
-        }
-      }
-
-      /*
-       * checks passed - add the feature
-       */
-      nonNestedFeatures.add(insertPosition, feature);
-
-      return true;
-    }
-  }
-
-  /**
-   * Answers true if range1 properly encloses range2, else false
-   * 
-   * @param range1
-   * @param range2
-   * @return
+   * Adds one feature to the IntervalStore that can manage nested features
+   * (creating the IntervalStore if necessary)
    */
-  protected boolean encloses(ContiguousI range1, ContiguousI range2)
+  protected synchronized void addNestedFeature(SequenceFeature feature)
   {
-    int begin1 = range1.getBegin();
-    int begin2 = range2.getBegin();
-    int end1 = range1.getEnd();
-    int end2 = range2.getEnd();
-    if (begin1 == begin2 && end1 > end2)
+    if (features == null)
     {
-      return true;
+      features = new IntervalStore<>();
     }
-    if (begin1 < begin2 && end1 >= end2)
-    {
-      return true;
-    }
-    return false;
+    features.add(feature);
   }
 
   /**
@@ -441,28 +265,29 @@ public class FeatureStore
   {
     if (contactFeatureStarts == null)
     {
-      contactFeatureStarts = new ArrayList<SequenceFeature>();
+      contactFeatureStarts = new ArrayList<>();
     }
     if (contactFeatureEnds == null)
     {
-      contactFeatureEnds = new ArrayList<SequenceFeature>();
+      contactFeatureEnds = new ArrayList<>();
     }
 
     /*
+     * insert into list sorted by start (first contact position):
      * binary search the sorted list to find the insertion point
      */
-    int insertPosition = binarySearch(contactFeatureStarts,
-            SearchCriterion.byFeature(feature,
-                    RangeComparator.BY_START_POSITION));
+    int insertPosition = BinarySearcher.findFirst(contactFeatureStarts,
+            f -> f.getBegin() >= feature.getBegin());
     contactFeatureStarts.add(insertPosition, feature);
-    // and resort to mak siccar...just in case insertion point not quite right
-    Collections.sort(contactFeatureStarts, RangeComparator.BY_START_POSITION);
 
-    insertPosition = binarySearch(contactFeatureStarts,
-            SearchCriterion.byFeature(feature,
-                    RangeComparator.BY_END_POSITION));
-    contactFeatureEnds.add(feature);
-    Collections.sort(contactFeatureEnds, RangeComparator.BY_END_POSITION);
+
+    /*
+     * insert into list sorted by end (second contact position):
+     * binary search the sorted list to find the insertion point
+     */
+    insertPosition = BinarySearcher.findFirst(contactFeatureEnds,
+            f -> f.getEnd() >= feature.getEnd());
+    contactFeatureEnds.add(insertPosition, feature);
 
     return true;
   }
@@ -487,8 +312,10 @@ public class FeatureStore
     /*
      * locate the first entry in the list which does not precede the feature
      */
-    int pos = binarySearch(features,
-            SearchCriterion.byFeature(feature, RangeComparator.BY_START_POSITION));
+    // int pos = binarySearch(features,
+    // SearchCriterion.byFeature(feature, RangeComparator.BY_START_POSITION));
+    int pos = BinarySearcher.findFirst(features,
+            val -> val.getBegin() >= feature.getBegin());
     int len = features.size();
     while (pos < len)
     {
@@ -521,13 +348,11 @@ public class FeatureStore
   {
     List<SequenceFeature> result = new ArrayList<>();
 
-    findNonNestedFeatures(start, end, result);
-
     findContactFeatures(start, end, result);
 
-    if (nestedFeatures != null)
+    if (features != null)
     {
-      result.addAll(nestedFeatures.findOverlaps(start, end));
+      result.addAll(features.findOverlaps(start, end));
     }
 
     return result;
@@ -546,11 +371,11 @@ public class FeatureStore
   {
     if (contactFeatureStarts != null)
     {
-      findContactStartFeatures(from, to, result);
+      findContactStartOverlaps(from, to, result);
     }
     if (contactFeatureEnds != null)
     {
-      findContactEndFeatures(from, to, result);
+      findContactEndOverlaps(from, to, result);
     }
   }
 
@@ -563,22 +388,24 @@ public class FeatureStore
    * @param to
    * @param result
    */
-  protected void findContactEndFeatures(long from, long to,
+  protected void findContactEndOverlaps(long from, long to,
           List<SequenceFeature> result)
   {
     /*
-     * find the first contact feature (if any) that does not lie 
-     * entirely before the target range
+     * find the first contact feature (if any) 
+     * whose end point is not before the target range
      */
-    int startPosition = binarySearch(contactFeatureEnds,
-            SearchCriterion.byEnd(from));
-    for (; startPosition < contactFeatureEnds.size(); startPosition++)
+    int index = BinarySearcher.findFirst(contactFeatureEnds,
+            f -> f.getEnd() >= from);
+
+    while (index < contactFeatureEnds.size())
     {
-      SequenceFeature sf = contactFeatureEnds.get(startPosition);
+      SequenceFeature sf = contactFeatureEnds.get(index);
       if (!sf.isContactFeature())
       {
         System.err.println("Error! non-contact feature type "
                 + sf.getType() + " in contact features list");
+        index++;
         continue;
       }
 
@@ -589,54 +416,24 @@ public class FeatureStore
          * this feature's first contact position lies in the search range
          * so we don't include it in results a second time
          */
+        index++;
         continue;
       }
 
-      int end = sf.getEnd();
-      if (end >= from && end <= to)
-      {
-        result.add(sf);
-      }
-      if (end > to)
+      if (sf.getEnd() > to)
       {
+        /*
+         * this feature (and all following) has end point after the target range
+         */
         break;
       }
-    }
-  }
 
-  /**
-   * Adds non-nested features to the result list that lie within the target
-   * range. Non-positional features (start=end=0), contact features and nested
-   * features are excluded.
-   * 
-   * @param from
-   * @param to
-   * @param result
-   */
-  protected void findNonNestedFeatures(long from, long to,
-          List<SequenceFeature> result)
-  {
-    /*
-     * find the first feature whose end position is
-     * after the target range start
-     */
-    int startIndex = binarySearch(nonNestedFeatures,
-            SearchCriterion.byEnd(from));
-
-    final int startIndex1 = startIndex;
-    int i = startIndex1;
-    while (i < nonNestedFeatures.size())
-    {
-      SequenceFeature sf = nonNestedFeatures.get(i);
-      if (sf.getBegin() > to)
-      {
-        break;
-      }
-      if (sf.getBegin() <= to && sf.getEnd() >= from)
-      {
-        result.add(sf);
-      }
-      i++;
+      /*
+       * feature has end >= from and end <= to
+       * i.e. contact end point lies within overlap search range
+       */
+      result.add(sf);
+      index++;
     }
   }
 
@@ -648,26 +445,36 @@ public class FeatureStore
    * @param to
    * @param result
    */
-  protected void findContactStartFeatures(long from, long to,
+  protected void findContactStartOverlaps(long from, long to,
           List<SequenceFeature> result)
   {
-    int startPosition = binarySearch(contactFeatureStarts,
-            SearchCriterion.byStart(from));
+    int index = BinarySearcher.findFirst(contactFeatureStarts,
+            f -> f.getBegin() >= from);
 
-    for (; startPosition < contactFeatureStarts.size(); startPosition++)
+    while (index < contactFeatureStarts.size())
     {
-      SequenceFeature sf = contactFeatureStarts.get(startPosition);
+      SequenceFeature sf = contactFeatureStarts.get(index);
       if (!sf.isContactFeature())
       {
-        System.err.println("Error! non-contact feature type "
-                + sf.getType() + " in contact features list");
+        System.err.println("Error! non-contact feature " + sf.toString()
+                + " in contact features list");
+        index++;
         continue;
       }
-      int begin = sf.getBegin();
-      if (begin >= from && begin <= to)
+      if (sf.getBegin() > to)
       {
-        result.add(sf);
+        /*
+         * this feature's start (and all following) follows the target range
+         */
+        break;
       }
+
+      /*
+       * feature has begin >= from and begin <= to
+       * i.e. contact start point lies within overlap search range
+       */
+      result.add(sf);
+      index++;
     }
   }
 
@@ -678,11 +485,7 @@ public class FeatureStore
    */
   public List<SequenceFeature> getPositionalFeatures()
   {
-    /*
-     * add non-nested features (may be all features for many cases)
-     */
     List<SequenceFeature> result = new ArrayList<>();
-    result.addAll(nonNestedFeatures);
 
     /*
      * add any contact features - from the list by start position
@@ -695,9 +498,9 @@ public class FeatureStore
     /*
      * add any nested features
      */
-    if (nestedFeatures != null)
+    if (features != null)
     {
-      result.addAll(nestedFeatures.getEntries());
+      result.addAll(features);
     }
 
     return result;
@@ -743,13 +546,10 @@ public class FeatureStore
    */
   public synchronized boolean delete(SequenceFeature sf)
   {
-    /*
-     * try the non-nested positional features first
-     */
-    boolean removed = nonNestedFeatures.remove(sf);
+    boolean removed = false;
 
     /*
-     * if not found, try contact positions (and if found, delete
+     * try contact positions (and if found, delete
      * from both lists of contact positions)
      */
     if (!removed && contactFeatureStarts != null)
@@ -775,9 +575,9 @@ public class FeatureStore
     /*
      * if not found, try nested features
      */
-    if (!removed && nestedFeatures != null)
+    if (!removed && features != null)
     {
-      removed = nestedFeatures.delete(sf);
+      removed = features.remove(sf);
     }
 
     if (removed)
@@ -874,12 +674,12 @@ public class FeatureStore
    */
   public boolean isEmpty()
   {
-    boolean hasFeatures = !nonNestedFeatures.isEmpty()
-            || (contactFeatureStarts != null && !contactFeatureStarts
+    boolean hasFeatures = (contactFeatureStarts != null
+            && !contactFeatureStarts
                     .isEmpty())
             || (nonPositionalFeatures != null && !nonPositionalFeatures
                     .isEmpty())
-            || (nestedFeatures != null && nestedFeatures.size() > 0);
+            || (features != null && features.size() > 0);
 
     return !hasFeatures;
   }
@@ -907,41 +707,6 @@ public class FeatureStore
   }
 
   /**
-   * Performs a binary search of the (sorted) list to find the index of the
-   * first entry which returns true for the given comparator function. Returns
-   * the length of the list if there is no such entry.
-   * 
-   * @param features
-   * @param sc
-   * @return
-   */
-  protected static int binarySearch(List<SequenceFeature> features,
-          SearchCriterion sc)
-  {
-    int start = 0;
-    int end = features.size() - 1;
-    int matched = features.size();
-
-    while (start <= end)
-    {
-      int mid = (start + end) / 2;
-      SequenceFeature entry = features.get(mid);
-      boolean compare = sc.compare(entry);
-      if (compare)
-      {
-        matched = mid;
-        end = mid - 1;
-      }
-      else
-      {
-        start = mid + 1;
-      }
-    }
-
-    return matched;
-  }
-
-  /**
    * Answers the number of positional (or non-positional) features stored.
    * Contact features count as 1.
    * 
@@ -956,7 +721,7 @@ public class FeatureStore
               .size();
     }
 
-    int size = nonNestedFeatures.size();
+    int size = 0;
 
     if (contactFeatureStarts != null)
     {
@@ -964,9 +729,9 @@ public class FeatureStore
       size += contactFeatureStarts.size();
     }
 
-    if (nestedFeatures != null)
+    if (features != null)
     {
-      size += nestedFeatures.size();
+      size += features.size();
     }
 
     return size;
@@ -1047,13 +812,15 @@ public class FeatureStore
   }
 
   /**
-   * Adds the shift value to the start and end of all positional features.
-   * Returns true if at least one feature was updated, else false.
+   * Adds the shift amount to the start and end of all positional features whose
+   * start position is at or after fromPosition. Returns true if at least one
+   * feature was shifted, else false.
    * 
-   * @param shift
+   * @param fromPosition
+   * @param shiftBy
    * @return
    */
-  public synchronized boolean shiftFeatures(int shift)
+  public synchronized boolean shiftFeatures(int fromPosition, int shiftBy)
   {
     /*
      * Because begin and end are final fields (to ensure the data store's
@@ -1063,21 +830,24 @@ public class FeatureStore
     boolean modified = false;
     for (SequenceFeature sf : getPositionalFeatures())
     {
-      modified = true;
-      int newBegin = sf.getBegin() + shift;
-      int newEnd = sf.getEnd() + shift;
-
-      /*
-       * sanity check: don't shift left of the first residue
-       */
-      if (newEnd > 0)
+      if (sf.getBegin() >= fromPosition)
       {
-        newBegin = Math.max(1, newBegin);
-        SequenceFeature sf2 = new SequenceFeature(sf, newBegin, newEnd,
-                sf.getFeatureGroup(), sf.getScore());
-        addFeature(sf2);
+        modified = true;
+        int newBegin = sf.getBegin() + shiftBy;
+        int newEnd = sf.getEnd() + shiftBy;
+
+        /*
+         * sanity check: don't shift left of the first residue
+         */
+        if (newEnd > 0)
+        {
+          newBegin = Math.max(1, newBegin);
+          SequenceFeature sf2 = new SequenceFeature(sf, newBegin, newEnd,
+                  sf.getFeatureGroup(), sf.getScore());
+          addFeature(sf2);
+        }
+        delete(sf);
       }
-      delete(sf);
     }
     return modified;
   }
diff --git a/src/jalview/datamodel/features/NCList.java b/src/jalview/datamodel/features/NCList.java
deleted file mode 100644 (file)
index ae58a69..0000000
+++ /dev/null
@@ -1,646 +0,0 @@
-/*
- * 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 <http://www.gnu.org/licenses/>.
- * The Jalview Authors are detailed in the 'AUTHORS' file.
- */
-package jalview.datamodel.features;
-
-import jalview.datamodel.ContiguousI;
-import jalview.datamodel.Range;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-/**
- * An adapted implementation of NCList as described in the paper
- * 
- * <pre>
- * Nested Containment List (NCList): a new algorithm for accelerating
- * interval query of genome alignment and interval databases
- * - Alexander V. Alekseyenko, Christopher J. Lee
- * https://doi.org/10.1093/bioinformatics/btl647
- * </pre>
- */
-public class NCList<T extends ContiguousI>
-{
-  /*
-   * the number of ranges represented
-   */
-  private int size;
-
-  /*
-   * a list, in start position order, of sublists of ranges ordered so 
-   * that each contains (or is the same as) the one that follows it
-   */
-  private List<NCNode<T>> subranges;
-
-  /**
-   * Constructor given a list of things that are each located on a contiguous
-   * interval. Note that the constructor may reorder the list.
-   * <p>
-   * We assume here that for each range, start &lt;= end. Behaviour for reverse
-   * ordered ranges is undefined.
-   * 
-   * @param ranges
-   */
-  public NCList(List<T> ranges)
-  {
-    this();
-    build(ranges);
-  }
-
-  /**
-   * Sort and group ranges into sublists where each sublist represents a region
-   * and its contained subregions
-   * 
-   * @param ranges
-   */
-  protected void build(List<T> ranges)
-  {
-    /*
-     * sort by start ascending so that contained intervals 
-     * follow their containing interval
-     */
-    Collections.sort(ranges, RangeComparator.BY_START_POSITION);
-
-    List<Range> sublists = buildSubranges(ranges);
-
-    /*
-     * convert each subrange to an NCNode consisting of a range and
-     * (possibly) its contained NCList
-     */
-    for (Range sublist : sublists)
-    {
-      subranges.add(new NCNode<T>(ranges.subList(sublist.start,
-              sublist.end + 1)));
-    }
-
-    size = ranges.size();
-  }
-
-  public NCList(T entry)
-  {
-    this();
-    subranges.add(new NCNode<>(entry));
-    size = 1;
-  }
-
-  public NCList()
-  {
-    subranges = new ArrayList<NCNode<T>>();
-  }
-
-  /**
-   * Traverses the sorted ranges to identify sublists, within which each
-   * interval contains the one that follows it
-   * 
-   * @param ranges
-   * @return
-   */
-  protected List<Range> buildSubranges(List<T> ranges)
-  {
-    List<Range> sublists = new ArrayList<>();
-    
-    if (ranges.isEmpty())
-    {
-      return sublists;
-    }
-
-    int listStartIndex = 0;
-    long lastEndPos = Long.MAX_VALUE;
-
-    for (int i = 0; i < ranges.size(); i++)
-    {
-      ContiguousI nextInterval = ranges.get(i);
-      long nextStart = nextInterval.getBegin();
-      long nextEnd = nextInterval.getEnd();
-      if (nextStart > lastEndPos || nextEnd > lastEndPos)
-      {
-        /*
-         * this interval is not contained in the preceding one 
-         * close off the last sublist
-         */
-        sublists.add(new Range(listStartIndex, i - 1));
-        listStartIndex = i;
-      }
-      lastEndPos = nextEnd;
-    }
-
-    sublists.add(new Range(listStartIndex, ranges.size() - 1));
-    return sublists;
-  }
-
-  /**
-   * Adds one entry to the stored set (with duplicates allowed)
-   * 
-   * @param entry
-   */
-  public void add(T entry)
-  {
-    add(entry, true);
-  }
-
-  /**
-   * Adds one entry to the stored set, and returns true, unless allowDuplicates
-   * is set to false and it is already contained (by object equality test), in
-   * which case it is not added and this method returns false.
-   * 
-   * @param entry
-   * @param allowDuplicates
-   * @return
-   */
-  public synchronized boolean add(T entry, boolean allowDuplicates)
-  {
-    if (!allowDuplicates && contains(entry))
-    {
-      return false;
-    }
-
-    size++;
-    long start = entry.getBegin();
-    long end = entry.getEnd();
-
-    /*
-     * cases:
-     * - precedes all subranges: add as NCNode on front of list
-     * - follows all subranges: add as NCNode on end of list
-     * - enclosed by a subrange - add recursively to subrange
-     * - encloses one or more subranges - push them inside it
-     * - none of the above - add as a new node and resort nodes list (?)
-     */
-
-    /*
-     * find the first subrange whose end does not precede entry's start
-     */
-    int candidateIndex = findFirstOverlap(start);
-    if (candidateIndex == -1)
-    {
-      /*
-       * all subranges precede this one - add it on the end
-       */
-      subranges.add(new NCNode<>(entry));
-      return true;
-    }
-
-    /*
-     * search for maximal span of subranges i-k that the new entry
-     * encloses; or a subrange that encloses the new entry
-     */
-    boolean enclosing = false;
-    int firstEnclosed = 0;
-    int lastEnclosed = 0;
-    boolean overlapping = false;
-
-    for (int j = candidateIndex; j < subranges.size(); j++)
-    {
-      NCNode<T> subrange = subranges.get(j);
-
-      if (end < subrange.getBegin() && !overlapping && !enclosing)
-      {
-        /*
-         * new entry lies between subranges j-1 j
-         */
-        subranges.add(j, new NCNode<>(entry));
-        return true;
-      }
-
-      if (subrange.getBegin() <= start && subrange.getEnd() >= end)
-      {
-        /*
-         * push new entry inside this subrange as it encloses it
-         */
-        subrange.add(entry);
-        return true;
-      }
-      
-      if (start <= subrange.getBegin())
-      {
-        if (end >= subrange.getEnd())
-        {
-          /*
-           * new entry encloses this subrange (and possibly preceding ones);
-           * continue to find the maximal list it encloses
-           */
-          if (!enclosing)
-          {
-            firstEnclosed = j;
-          }
-          lastEnclosed = j;
-          enclosing = true;
-          continue;
-        }
-        else
-        {
-          /*
-           * entry spans from before this subrange to inside it
-           */
-          if (enclosing)
-          {
-            /*
-             * entry encloses one or more preceding subranges
-             */
-            addEnclosingRange(entry, firstEnclosed, lastEnclosed);
-            return true;
-          }
-          else
-          {
-            /*
-             * entry spans two subranges but doesn't enclose any
-             * so just add it 
-             */
-            subranges.add(j, new NCNode<>(entry));
-            return true;
-          }
-        }
-      }
-      else
-      {
-        overlapping = true;
-      }
-    }
-
-    /*
-     * drops through to here if new range encloses all others
-     * or overlaps the last one
-     */
-    if (enclosing)
-    {
-      addEnclosingRange(entry, firstEnclosed, lastEnclosed);
-    }
-    else
-    {
-      subranges.add(new NCNode<>(entry));
-    }
-
-    return true;
-  }
-  
-  /**
-   * Answers true if this NCList contains the given entry (by object equality
-   * test), else false
-   * 
-   * @param entry
-   * @return
-   */
-  public boolean contains(T entry)
-  {
-    /*
-     * find the first sublist that might overlap, i.e. 
-     * the first whose end position is >= from
-     */
-    int candidateIndex = findFirstOverlap(entry.getBegin());
-
-    if (candidateIndex == -1)
-    {
-      return false;
-    }
-
-    int to = entry.getEnd();
-
-    for (int i = candidateIndex; i < subranges.size(); i++)
-    {
-      NCNode<T> candidate = subranges.get(i);
-      if (candidate.getBegin() > to)
-      {
-        /*
-         * we are past the end of our target range
-         */
-        break;
-      }
-      if (candidate.contains(entry))
-      {
-        return true;
-      }
-    }
-    return false;
-  }
-
-  /**
-   * Update the tree so that the range of the new entry encloses subranges i to
-   * j (inclusive). That is, replace subranges i-j (inclusive) with a new
-   * subrange that contains them.
-   * 
-   * @param entry
-   * @param i
-   * @param j
-   */
-  protected synchronized void addEnclosingRange(T entry, final int i,
-          final int j)
-  {
-    NCList<T> newNCList = new NCList<>();
-    newNCList.addNodes(subranges.subList(i, j + 1));
-    NCNode<T> newNode = new NCNode<>(entry, newNCList);
-    for (int k = j; k >= i; k--)
-    {
-      subranges.remove(k);
-    }
-    subranges.add(i, newNode);
-  }
-
-  protected void addNodes(List<NCNode<T>> nodes)
-  {
-    for (NCNode<T> node : nodes)
-    {
-      subranges.add(node);
-      size += node.size();
-    }
-  }
-
-  /**
-   * Returns a (possibly empty) list of items whose extent overlaps the given
-   * range
-   * 
-   * @param from
-   *          start of overlap range (inclusive)
-   * @param to
-   *          end of overlap range (inclusive)
-   * @return
-   */
-  public List<T> findOverlaps(long from, long to)
-  {
-    List<T> result = new ArrayList<>();
-
-    findOverlaps(from, to, result);
-    
-    return result;
-  }
-
-  /**
-   * Recursively searches the NCList adding any items that overlap the from-to
-   * range to the result list
-   * 
-   * @param from
-   * @param to
-   * @param result
-   */
-  protected void findOverlaps(long from, long to, List<T> result)
-  {
-    /*
-     * find the first sublist that might overlap, i.e. 
-     * the first whose end position is >= from
-     */
-    int candidateIndex = findFirstOverlap(from);
-
-    if (candidateIndex == -1)
-    {
-      return;
-    }
-
-    for (int i = candidateIndex; i < subranges.size(); i++)
-    {
-      NCNode<T> candidate = subranges.get(i);
-      if (candidate.getBegin() > to)
-      {
-        /*
-         * we are past the end of our target range
-         */
-        break;
-      }
-      candidate.findOverlaps(from, to, result);
-    }
-
-  }
-
-  /**
-   * Search subranges for the first one whose end position is not before the
-   * target range's start position, i.e. the first one that may overlap the
-   * target range. Returns the index in the list of the first such range found,
-   * or -1 if none found.
-   * 
-   * @param from
-   * @return
-   */
-  protected int findFirstOverlap(long from)
-  {
-    /*
-     * The NCList paper describes binary search for this step,
-     * but this not implemented here as (a) I haven't understood it yet
-     * and (b) it seems to imply complications for adding to an NCList
-     */
-
-    int i = 0;
-    if (subranges != null)
-    {
-      for (NCNode<T> subrange : subranges)
-      {
-        if (subrange.getEnd() >= from)
-        {
-          return i;
-        }
-        i++;
-      }
-    }
-    return -1;
-  }
-
-  /**
-   * Formats the tree as a bracketed list e.g.
-   * 
-   * <pre>
-   * [1-100 [10-30 [10-20]], 15-30 [20-20]]
-   * </pre>
-   */
-  @Override
-  public String toString()
-  {
-    return subranges.toString();
-  }
-
-  /**
-   * Returns a string representation of the data where containment is shown by
-   * indentation on new lines
-   * 
-   * @return
-   */
-  public String prettyPrint()
-  {
-    StringBuilder sb = new StringBuilder(512);
-    int offset = 0;
-    int indent = 2;
-    prettyPrint(sb, offset, indent);
-    sb.append(System.lineSeparator());
-    return sb.toString();
-  }
-
-  /**
-   * @param sb
-   * @param offset
-   * @param indent
-   */
-  void prettyPrint(StringBuilder sb, int offset, int indent)
-  {
-    boolean first = true;
-    for (NCNode<T> subrange : subranges)
-    {
-      if (!first)
-      {
-        sb.append(System.lineSeparator());
-      }
-      first = false;
-      subrange.prettyPrint(sb, offset, indent);
-    }
-  }
-
-  /**
-   * Answers true if the data held satisfy the rules of construction of an
-   * NCList, else false.
-   * 
-   * @return
-   */
-  public boolean isValid()
-  {
-    return isValid(Integer.MIN_VALUE, Integer.MAX_VALUE);
-  }
-
-  /**
-   * Answers true if the data held satisfy the rules of construction of an
-   * NCList bounded within the given start-end range, else false.
-   * <p>
-   * Each subrange must lie within start-end (inclusive). Subranges must be
-   * ordered by start position ascending.
-   * <p>
-   * 
-   * @param start
-   * @param end
-   * @return
-   */
-  boolean isValid(final int start, final int end)
-  {
-    int lastStart = start;
-    for (NCNode<T> subrange : subranges)
-    {
-      if (subrange.getBegin() < lastStart)
-      {
-        System.err.println("error in NCList: range " + subrange.toString()
-                + " starts before " + lastStart);
-        return false;
-      }
-      if (subrange.getEnd() > end)
-      {
-        System.err.println("error in NCList: range " + subrange.toString()
-                + " ends after " + end);
-        return false;
-      }
-      lastStart = subrange.getBegin();
-
-      if (!subrange.isValid())
-      {
-        return false;
-      }
-    }
-    return true;
-  }
-
-  /**
-   * Answers the lowest start position enclosed by the ranges
-   * 
-   * @return
-   */
-  public int getStart()
-  {
-    return subranges.isEmpty() ? 0 : subranges.get(0).getBegin();
-  }
-
-  /**
-   * Returns the number of ranges held (deep count)
-   * 
-   * @return
-   */
-  public int size()
-  {
-    return size;
-  }
-
-  /**
-   * Returns a list of all entries stored
-   * 
-   * @return
-   */
-  public List<T> getEntries()
-  {
-    List<T> result = new ArrayList<>();
-    getEntries(result);
-    return result;
-  }
-
-  /**
-   * Adds all contained entries to the given list
-   * 
-   * @param result
-   */
-  void getEntries(List<T> result)
-  {
-    for (NCNode<T> subrange : subranges)
-    {
-      subrange.getEntries(result);
-    }
-  }
-
-  /**
-   * Deletes the given entry from the store, returning true if it was found (and
-   * deleted), else false. This method makes no assumption that the entry is in
-   * the 'expected' place in the store, in case it has been modified since it
-   * was added. Only the first 'same object' match is deleted, not 'equal' or
-   * multiple objects.
-   * 
-   * @param entry
-   */
-  public synchronized boolean delete(T entry)
-  {
-    if (entry == null)
-    {
-      return false;
-    }
-    for (int i = 0; i < subranges.size(); i++)
-    {
-      NCNode<T> subrange = subranges.get(i);
-      NCList<T> subRegions = subrange.getSubRegions();
-
-      if (subrange.getRegion() == entry)
-      {
-        /*
-         * if the subrange is rooted on this entry, promote its
-         * subregions (if any) to replace the subrange here;
-         * NB have to resort subranges after doing this since e.g.
-         * [10-30 [12-20 [16-18], 13-19]]
-         * after deleting 12-20, 16-18 is promoted to sibling of 13-19
-         * but should follow it in the list of subranges of 10-30 
-         */
-        subranges.remove(i);
-        if (subRegions != null)
-        {
-          subranges.addAll(subRegions.subranges);
-          Collections.sort(subranges, RangeComparator.BY_START_POSITION);
-        }
-        size--;
-        return true;
-      }
-      else
-      {
-        if (subRegions != null && subRegions.delete(entry))
-        {
-          size--;
-          subrange.deleteSubRegionsIfEmpty();
-          return true;
-        }
-      }
-    }
-    return false;
-  }
-}
diff --git a/src/jalview/datamodel/features/NCNode.java b/src/jalview/datamodel/features/NCNode.java
deleted file mode 100644 (file)
index b991750..0000000
+++ /dev/null
@@ -1,275 +0,0 @@
-/*
- * 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 <http://www.gnu.org/licenses/>.
- * The Jalview Authors are detailed in the 'AUTHORS' file.
- */
-package jalview.datamodel.features;
-
-import jalview.datamodel.ContiguousI;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Each node of the NCList tree consists of a range, and (optionally) the NCList
- * of ranges it encloses
- *
- * @param <V>
- */
-class NCNode<V extends ContiguousI> implements ContiguousI
-{
-  /*
-   * deep size (number of ranges included)
-   */
-  private int size;
-
-  private V region;
-
-  /*
-   * null, or an object holding contained subregions of this nodes region
-   */
-  private NCList<V> subregions;
-
-  /**
-   * Constructor given a list of ranges
-   * 
-   * @param ranges
-   */
-  NCNode(List<V> ranges)
-  {
-    build(ranges);
-  }
-
-  /**
-   * Constructor given a single range
-   * 
-   * @param range
-   */
-  NCNode(V range)
-  {
-    List<V> ranges = new ArrayList<>();
-    ranges.add(range);
-    build(ranges);
-  }
-
-  NCNode(V entry, NCList<V> newNCList)
-  {
-    region = entry;
-    subregions = newNCList;
-    size = 1 + newNCList.size();
-  }
-
-  /**
-   * @param ranges
-   */
-  protected void build(List<V> ranges)
-  {
-    size = ranges.size();
-
-    if (!ranges.isEmpty())
-    {
-      region = ranges.get(0);
-    }
-    if (ranges.size() > 1)
-    {
-      subregions = new NCList<V>(ranges.subList(1, ranges.size()));
-    }
-  }
-
-  @Override
-  public int getBegin()
-  {
-    return region.getBegin();
-  }
-
-  @Override
-  public int getEnd()
-  {
-    return region.getEnd();
-  }
-
-  /**
-   * Formats the node as a bracketed list e.g.
-   * 
-   * <pre>
-   * [1-100 [10-30 [10-20]], 15-30 [20-20]]
-   * </pre>
-   */
-  @Override
-  public String toString() {
-    StringBuilder sb = new StringBuilder(10 * size);
-    sb.append(region.getBegin()).append("-").append(region.getEnd());
-    if (subregions != null)
-    {
-      sb.append(" ").append(subregions.toString());
-    }
-    return sb.toString();
-  }
-
-  void prettyPrint(StringBuilder sb, int offset, int indent) {
-    for (int i = 0 ; i < offset ; i++) {
-      sb.append(" ");
-    }
-    sb.append(region.getBegin()).append("-").append(region.getEnd());
-    if (subregions != null)
-    {
-      sb.append(System.lineSeparator());
-      subregions.prettyPrint(sb, offset + 2, indent);
-    }
-  }
-  /**
-   * Add any ranges that overlap the from-to range to the result list
-   * 
-   * @param from
-   * @param to
-   * @param result
-   */
-  void findOverlaps(long from, long to, List<V> result)
-  {
-    if (region.getBegin() <= to && region.getEnd() >= from)
-    {
-      result.add(region);
-    }
-    if (subregions != null)
-    {
-      subregions.findOverlaps(from, to, result);
-    }
-  }
-
-  /**
-   * Add one range to this subrange
-   * 
-   * @param entry
-   */
-  synchronized void add(V entry)
-  {
-    if (entry.getBegin() < region.getBegin() || entry.getEnd() > region.getEnd()) {
-      throw new IllegalArgumentException(String.format(
-              "adding improper subrange %d-%d to range %d-%d",
-              entry.getBegin(), entry.getEnd(), region.getBegin(),
-              region.getEnd()));
-    }
-    if (subregions == null)
-    {
-      subregions = new NCList<V>(entry);
-    }
-    else
-    {
-      subregions.add(entry);
-    }
-    size++;
-  }
-
-  /**
-   * Answers true if the data held satisfy the rules of construction of an
-   * NCList, else false.
-   * 
-   * @return
-   */
-  boolean isValid()
-  {
-    /*
-     * we don't handle reverse ranges
-     */
-    if (region != null && region.getBegin() > region.getEnd())
-    {
-      return false;
-    }
-    if (subregions == null)
-    {
-      return true;
-    }
-    return subregions.isValid(getBegin(), getEnd());
-  }
-
-  /**
-   * Adds all contained entries to the given list
-   * 
-   * @param entries
-   */
-  void getEntries(List<V> entries)
-  {
-    entries.add(region);
-    if (subregions != null)
-    {
-      subregions.getEntries(entries);
-    }
-  }
-
-  /**
-   * Answers true if this object contains the given entry (by object equals
-   * test), else false
-   * 
-   * @param entry
-   * @return
-   */
-  boolean contains(V entry)
-  {
-    if (entry == null)
-    {
-      return false;
-    }
-    if (entry.equals(region))
-    {
-      return true;
-    }
-    return subregions == null ? false : subregions.contains(entry);
-  }
-
-  /**
-   * Answers the 'root' region modelled by this object
-   * 
-   * @return
-   */
-  V getRegion()
-  {
-    return region;
-  }
-
-  /**
-   * Answers the (possibly null) contained regions within this object
-   * 
-   * @return
-   */
-  NCList<V> getSubRegions()
-  {
-    return subregions;
-  }
-
-  /**
-   * Nulls the subregion reference if it is empty (after a delete entry
-   * operation)
-   */
-  void deleteSubRegionsIfEmpty()
-  {
-    if (subregions != null && subregions.size() == 0)
-    {
-      subregions = null;
-    }
-  }
-
-  /**
-   * Answers the (deep) size of this node i.e. the number of ranges it models
-   * 
-   * @return
-   */
-  int size()
-  {
-    return size;
-  }
-}
diff --git a/src/jalview/datamodel/features/RangeComparator.java b/src/jalview/datamodel/features/RangeComparator.java
deleted file mode 100644 (file)
index b7d702d..0000000
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * 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 <http://www.gnu.org/licenses/>.
- * The Jalview Authors are detailed in the 'AUTHORS' file.
- */
-package jalview.datamodel.features;
-
-import jalview.datamodel.ContiguousI;
-
-import java.util.Comparator;
-
-/**
- * A comparator that orders ranges by either start position or end position
- * ascending. If the position matches, ordering is resolved by end position (or
- * start position).
- * 
- * @author gmcarstairs
- *
- */
-public class RangeComparator implements Comparator<ContiguousI>
-{
-  public static final Comparator<ContiguousI> BY_START_POSITION = new RangeComparator(
-          true);
-
-  public static final Comparator<ContiguousI> BY_END_POSITION = new RangeComparator(
-          false);
-
-  boolean byStart;
-
-  /**
-   * Constructor
-   * 
-   * @param byStartPosition
-   *          if true, order based on start position, if false by end position
-   */
-  RangeComparator(boolean byStartPosition)
-  {
-    byStart = byStartPosition;
-  }
-
-  @Override
-  public int compare(ContiguousI o1, ContiguousI o2)
-  {
-    int len1 = o1.getEnd() - o1.getBegin();
-    int len2 = o2.getEnd() - o2.getBegin();
-
-    if (byStart)
-    {
-      return compare(o1.getBegin(), o2.getBegin(), len1, len2);
-    }
-    else
-    {
-      return compare(o1.getEnd(), o2.getEnd(), len1, len2);
-    }
-  }
-
-  /**
-   * Compares two ranges for ordering
-   * 
-   * @param pos1
-   *          first range positional ordering criterion
-   * @param pos2
-   *          second range positional ordering criterion
-   * @param len1
-   *          first range length ordering criterion
-   * @param len2
-   *          second range length ordering criterion
-   * @return
-   */
-  public int compare(long pos1, long pos2, int len1, int len2)
-  {
-    int order = Long.compare(pos1, pos2);
-    if (order == 0)
-    {
-      /*
-       * if tied on position order, longer length sorts to left
-       * i.e. the negation of normal ordering by length
-       */
-      order = -Integer.compare(len1, len2);
-    }
-    return order;
-  }
-}
index 727d3ef..ba8396a 100644 (file)
  */
 package jalview.datamodel.features;
 
-import jalview.datamodel.ContiguousI;
 import jalview.datamodel.SequenceFeature;
 import jalview.io.gff.SequenceOntologyFactory;
 import jalview.io.gff.SequenceOntologyI;
 
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Collections;
-import java.util.Comparator;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
@@ -36,6 +33,8 @@ import java.util.Map.Entry;
 import java.util.Set;
 import java.util.TreeMap;
 
+import intervalstore.api.IntervalI;
+
 /**
  * A class that stores sequence features in a way that supports efficient
  * querying by type and location (overlap). Intended for (but not limited to)
@@ -46,29 +45,6 @@ import java.util.TreeMap;
  */
 public class SequenceFeatures implements SequenceFeaturesI
 {
-  /**
-   * a comparator for sorting features by start position ascending
-   */
-  private static Comparator<ContiguousI> FORWARD_STRAND = new Comparator<ContiguousI>()
-  {
-    @Override
-    public int compare(ContiguousI o1, ContiguousI o2)
-    {
-      return Integer.compare(o1.getBegin(), o2.getBegin());
-    }
-  };
-
-  /**
-   * a comparator for sorting features by end position descending
-   */
-  private static Comparator<ContiguousI> REVERSE_STRAND = new Comparator<ContiguousI>()
-  {
-    @Override
-    public int compare(ContiguousI o1, ContiguousI o2)
-    {
-      return Integer.compare(o2.getEnd(), o1.getEnd());
-    }
-  };
 
   /*
    * map from feature type to structured store of features for that type
@@ -435,11 +411,10 @@ public class SequenceFeatures implements SequenceFeaturesI
    * @param features
    * @param forwardStrand
    */
-  public static void sortFeatures(List<SequenceFeature> features,
+  public static void sortFeatures(List<? extends IntervalI> features,
           final boolean forwardStrand)
   {
-    Collections.sort(features, forwardStrand ? FORWARD_STRAND
-            : REVERSE_STRAND);
+    IntervalI.sortIntervals(features, forwardStrand);
   }
 
   /**
@@ -472,13 +447,22 @@ public class SequenceFeatures implements SequenceFeaturesI
    * {@inheritDoc}
    */
   @Override
-  public boolean shiftFeatures(int shift)
+  public boolean shiftFeatures(int fromPosition, int shiftBy)
   {
     boolean modified = false;
     for (FeatureStore fs : featureStore.values())
     {
-      modified |= fs.shiftFeatures(shift);
+      modified |= fs.shiftFeatures(fromPosition, shiftBy);
     }
     return modified;
   }
-}
\ No newline at end of file
+
+  /**
+   * {@inheritDoc}
+   */
+  @Override
+  public void deleteAll()
+  {
+    featureStore.clear();
+  }
+}
index 31712b9..ca0283e 100644 (file)
@@ -215,10 +215,17 @@ public interface SequenceFeaturesI
   float getMaximumScore(String type, boolean positional);
 
   /**
-   * Adds the shift amount to the start and end of all positional features,
-   * returning true if at least one feature was shifted, else false
+   * Adds the shift amount to the start and end of all positional features whose
+   * start position is at or after fromPosition. Returns true if at least one
+   * feature was shifted, else false.
    * 
-   * @param shift
+   * @param fromPosition
+   * @param shiftBy
    */
-  abstract boolean shiftFeatures(int shift);
-}
\ No newline at end of file
+  boolean shiftFeatures(int fromPosition, int shiftBy);
+
+  /**
+   * Deletes all positional and non-positional features
+   */
+  void deleteAll();
+}
index 7384327..e01ad17 100644 (file)
@@ -22,7 +22,6 @@ package jalview.ext.ensembl;
 
 import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
-import jalview.io.gff.SequenceOntologyFactory;
 import jalview.io.gff.SequenceOntologyI;
 
 import java.util.ArrayList;
@@ -127,7 +126,7 @@ public class EnsemblCdna extends EnsemblSeqProxy
     for (SequenceFeature sf : sfs)
     {
       String parentFeature = (String) sf.getValue(PARENT);
-      if (("transcript:" + accId).equals(parentFeature))
+      if (accId.equals(parentFeature))
       {
         result.add(sf);
       }
index 8a71b64..8f13d99 100644 (file)
@@ -116,7 +116,7 @@ public class EnsemblCds extends EnsemblSeqProxy
     for (SequenceFeature sf : sfs)
     {
       String parentFeature = (String) sf.getValue(PARENT);
-      if (("transcript:" + accId).equals(parentFeature))
+      if ( accId.equals(parentFeature))
       {
         result.add(sf);
       }
index 582eac6..744191d 100644 (file)
@@ -22,17 +22,25 @@ package jalview.ext.ensembl;
 
 import jalview.datamodel.Alignment;
 import jalview.datamodel.AlignmentI;
-import jalview.io.DataSourceType;
-import jalview.io.FeaturesFile;
-import jalview.io.FileParse;
+import jalview.datamodel.Sequence;
+import jalview.datamodel.SequenceFeature;
+import jalview.datamodel.SequenceI;
+import jalview.io.gff.SequenceOntologyI;
+import jalview.util.JSONUtils;
 
 import java.io.BufferedReader;
 import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
 
+import org.json.simple.JSONArray;
+import org.json.simple.JSONObject;
+import org.json.simple.parser.JSONParser;
+import org.json.simple.parser.ParseException;
+
 /**
  * A client for fetching and processing Ensembl feature data in GFF format by
  * calling the overlap REST service
@@ -91,9 +99,128 @@ class EnsemblFeatures extends EnsemblRestClient
     {
       return null;
     }
-    FeaturesFile fr = new FeaturesFile(
-            new FileParse(fp, null, DataSourceType.URL));
-    return new Alignment(fr.getSeqsAsArray());
+
+    SequenceI seq = parseFeaturesJson(fp);
+    return new Alignment(new SequenceI[] { seq });
+  }
+
+  /**
+   * Parses the JSON response into Jalview sequence features and attaches them
+   * to a dummy sequence
+   * 
+   * @param br
+   * @return
+   */
+  private SequenceI parseFeaturesJson(BufferedReader br)
+  {
+    SequenceI seq = new Sequence("Dummy", "");
+
+    JSONParser jp = new JSONParser();
+    try
+    {
+      JSONArray responses = (JSONArray) jp.parse(br);
+      Iterator rvals = responses.iterator();
+      while (rvals.hasNext())
+      {
+        try
+        {
+          JSONObject obj = (JSONObject) rvals.next();
+          String type = obj.get("feature_type").toString();
+          int start = Integer.parseInt(obj.get("start").toString());
+          int end = Integer.parseInt(obj.get("end").toString());
+          String source = obj.get("source").toString();
+          String strand = obj.get("strand").toString();
+          String alleles = JSONUtils
+                  .arrayToList((JSONArray) obj.get("alleles"));
+          String clinSig = JSONUtils
+                  .arrayToList(
+                          (JSONArray) obj.get("clinical_significance"));
+
+          /*
+           * convert 'variation' to 'sequence_variant', and 'cds' to 'CDS'
+           * so as to have a valid SO term for the feature type
+           * ('gene', 'exon', 'transcript' don't need any conversion)
+           */
+          if ("variation".equals(type))
+          {
+            type = SequenceOntologyI.SEQUENCE_VARIANT;
+          }
+          else if (SequenceOntologyI.CDS.equalsIgnoreCase((type)))
+          {
+            type = SequenceOntologyI.CDS;
+          }
+          
+          String desc = getFirstNotNull(obj, "alleles", "external_name",
+                  JSON_ID);
+          SequenceFeature sf = new SequenceFeature(type, desc, start, end,
+                  source);
+          sf.setStrand("1".equals(strand) ? "+" : "-");
+          setFeatureAttribute(sf, obj, "id");
+          setFeatureAttribute(sf, obj, "Parent");
+          setFeatureAttribute(sf, obj, "consequence_type");
+          sf.setValue("alleles", alleles);
+          sf.setValue("clinical_significance", clinSig);
+
+          seq.addSequenceFeature(sf);
+        } catch (Throwable t)
+        {
+          // ignore - keep trying other features
+        }
+      }
+    } catch (ParseException | IOException e)
+    {
+      // ignore
+    }
+
+    return seq;
+  }
+
+  /**
+   * Returns the first non-null attribute found (if any) as a string, formatted
+   * suitably for display as feature description or tooltip. Answers null if
+   * none of the attribute keys is present.
+   * 
+   * @param obj
+   * @param keys
+   * @return
+   */
+  protected String getFirstNotNull(JSONObject obj, String... keys)
+  {
+    String desc = null;
+
+    for (String key : keys)
+    {
+      Object val = obj.get(key);
+      if (val != null)
+      {
+        String s = val instanceof JSONArray
+                ? JSONUtils.arrayToList((JSONArray) val)
+                : val.toString();
+        if (!s.isEmpty())
+        {
+          return s;
+        }
+      }
+    }
+    return desc;
+  }
+
+  /**
+   * A helper method that reads the 'key' entry in the JSON object, and if not
+   * null, sets its string value as an attribute on the sequence feature
+   * 
+   * @param sf
+   * @param obj
+   * @param key
+   */
+  protected void setFeatureAttribute(SequenceFeature sf, JSONObject obj,
+          String key)
+  {
+    Object object = obj.get(key);
+    if (object != null)
+    {
+      sf.setValue(key, object.toString());
+    }
   }
 
   /**
@@ -109,7 +236,7 @@ class EnsemblFeatures extends EnsemblRestClient
     urlstring.append(getDomain()).append("/overlap/id/").append(ids.get(0));
 
     // @see https://github.com/Ensembl/ensembl-rest/wiki/Output-formats
-    urlstring.append("?content-type=text/x-gff3");
+    urlstring.append("?content-type=" + getResponseMimeType());
 
     /*
      * specify object_type=gene in case is shared by transcript and/or protein;
@@ -145,16 +272,16 @@ class EnsemblFeatures extends EnsemblRestClient
   @Override
   protected String getRequestMimeType()
   {
-    return "text/x-gff3";
+    return "application/json";
   }
 
   /**
-   * Returns the MIME type for GFF3
+   * Returns the MIME type wanted for the response
    */
   @Override
   protected String getResponseMimeType()
   {
-    return "text/x-gff3";
+    return "application/json";
   }
 
   /**
index 36b19e2..7648536 100644 (file)
@@ -51,8 +51,6 @@ import com.stevesoft.pat.Regex;
  */
 public class EnsemblGene extends EnsemblSeqProxy
 {
-  private static final String GENE_PREFIX = "gene:";
-
   /*
    * accepts anything as we will attempt lookup of gene or 
    * transcript id or gene name
@@ -368,7 +366,7 @@ public class EnsemblGene extends EnsemblSeqProxy
      * look for exon features of the transcript, failing that for CDS
      * (for example ENSG00000124610 has 1 CDS but no exon features)
      */
-    String parentId = "transcript:" + accId;
+    String parentId = accId;
     List<SequenceFeature> splices = findFeatures(gene,
             SequenceOntologyI.EXON, parentId);
     if (splices.isEmpty())
@@ -399,7 +397,7 @@ public class EnsemblGene extends EnsemblSeqProxy
      * Ensembl has gene name as transcript Name
      * EnsemblGenomes doesn't, but has a url-encoded description field
      */
-    String description = (String) transcriptFeature.getValue(NAME);
+    String description = transcriptFeature.getDescription();
     if (description == null)
     {
       description = (String) transcriptFeature.getValue(DESCRIPTION);
@@ -488,7 +486,7 @@ public class EnsemblGene extends EnsemblSeqProxy
    */
   protected String getTranscriptId(SequenceFeature feature)
   {
-    return (String) feature.getValue("transcript_id");
+    return (String) feature.getValue(JSON_ID);
   }
 
   /**
@@ -510,7 +508,7 @@ public class EnsemblGene extends EnsemblSeqProxy
   {
     List<SequenceFeature> transcriptFeatures = new ArrayList<>();
 
-    String parentIdentifier = GENE_PREFIX + accId;
+    String parentIdentifier = accId;
 
     List<SequenceFeature> sfs = geneSequence.getFeatures()
             .getFeaturesByOntology(SequenceOntologyI.TRANSCRIPT);
@@ -561,9 +559,8 @@ public class EnsemblGene extends EnsemblSeqProxy
             .getFeaturesByOntology(SequenceOntologyI.GENE);
     for (SequenceFeature sf : sfs)
     {
-      // NB features as gff use 'ID'; rest services return as 'id'
-      String id = (String) sf.getValue("ID");
-      if ((GENE_PREFIX + accId).equalsIgnoreCase(id))
+      String id = (String) sf.getValue(JSON_ID);
+      if (accId.equalsIgnoreCase(id))
       {
         result.add(sf);
       }
@@ -590,7 +587,7 @@ public class EnsemblGene extends EnsemblSeqProxy
     if (isTranscript(type))
     {
       String parent = (String) sf.getValue(PARENT);
-      if (!(GENE_PREFIX + accessionId).equalsIgnoreCase(parent))
+      if (!accessionId.equalsIgnoreCase(parent))
       {
         return false;
       }
index 6684e20..4f59bc5 100644 (file)
@@ -117,9 +117,8 @@ public class EnsemblGenome extends EnsemblSeqProxy
             SequenceOntologyI.NMD_TRANSCRIPT_VARIANT);
     for (SequenceFeature sf : sfs)
     {
-      // NB features as gff use 'ID'; rest services return as 'id'
-      String id = (String) sf.getValue("ID");
-      if (("transcript:" + accId).equals(id))
+      String id = (String) sf.getValue(JSON_ID);
+      if (accId.equals(id))
       {
         result.add(sf);
       }
index 9e01cc4..e64c51a 100644 (file)
@@ -60,13 +60,13 @@ abstract class EnsemblRestClient extends EnsemblSequenceFetcher
 
   /*
    * update these constants when Jalview has been checked / updated for
-   * changes to Ensembl REST API (ref JAL-2105)
+   * changes to Ensembl REST API, and updated JAL-3018
    * @see https://github.com/Ensembl/ensembl-rest/wiki/Change-log
    * @see http://rest.ensembl.org/info/rest?content-type=application/json
    */
-  private static final String LATEST_ENSEMBLGENOMES_REST_VERSION = "7.0";
+  private static final String LATEST_ENSEMBLGENOMES_REST_VERSION = "9.0";
 
-  private static final String LATEST_ENSEMBL_REST_VERSION = "7.0";
+  private static final String LATEST_ENSEMBL_REST_VERSION = "9.0";
 
   private static final String REST_CHANGE_LOG = "https://github.com/Ensembl/ensembl-rest/wiki/Change-log";
 
index 7b448fd..5dc701d 100644 (file)
@@ -62,8 +62,6 @@ import org.json.simple.parser.ParseException;
  */
 public abstract class EnsemblSeqProxy extends EnsemblRestClient
 {
-  protected static final String NAME = "Name";
-
   protected static final String DESCRIPTION = "description";
 
   /*
@@ -867,9 +865,8 @@ public abstract class EnsemblSeqProxy extends EnsemblRestClient
   protected boolean featureMayBelong(SequenceFeature sf, String identifier)
   {
     String parent = (String) sf.getValue(PARENT);
-    // using contains to allow for prefix "gene:", "transcript:" etc
     if (parent != null
-            && !parent.toUpperCase().contains(identifier.toUpperCase()))
+            && !parent.equalsIgnoreCase(identifier))
     {
       // this genomic feature belongs to a different transcript
       return false;
@@ -877,6 +874,9 @@ public abstract class EnsemblSeqProxy extends EnsemblRestClient
     return true;
   }
 
+  /**
+   * Answers a short description of the sequence fetcher
+   */
   @Override
   public String getDescription()
   {
@@ -915,10 +915,14 @@ public abstract class EnsemblSeqProxy extends EnsemblRestClient
 
   /**
    * Answers true if the feature type is either 'NMD_transcript_variant' or
-   * 'transcript' or one of its sub-types in the Sequence Ontology. This is
-   * needed because NMD_transcript_variant behaves like 'transcript' in Ensembl
+   * 'transcript' (or one of its sub-types in the Sequence Ontology). This is
+   * because NMD_transcript_variant behaves like 'transcript' in Ensembl
    * although strictly speaking it is not (it is a sub-type of
    * sequence_variant).
+   * <p>
+   * (This test was needed when fetching transcript features as GFF. As we are
+   * now fetching as JSON, all features have type 'transcript' so the check for
+   * NMD_transcript_variant is redundant. Left in for any future case arising.)
    * 
    * @param featureType
    * @return
index 9e3fef4..8296985 100644 (file)
@@ -20,6 +20,7 @@
  */
 package jalview.ext.ensembl;
 
+import jalview.analysis.AlignmentUtils;
 import jalview.bin.Cache;
 import jalview.datamodel.DBRefSource;
 import jalview.ws.seqfetcher.DbSourceProxyImpl;
@@ -64,7 +65,7 @@ abstract class EnsemblSequenceFetcher extends DbSourceProxyImpl
 
   protected static final String PARENT = "Parent";
 
-  protected static final String JSON_ID = "id";
+  protected static final String JSON_ID = AlignmentUtils.VARIANT_ID; // "id";
 
   protected static final String OBJECT_TYPE = "object_type";
 
@@ -91,9 +92,9 @@ abstract class EnsemblSequenceFetcher extends DbSourceProxyImpl
      * this allows an easy change from http to https in future if needed
      */
     ensemblDomain = Cache.getDefault(ENSEMBL_BASEURL,
-            DEFAULT_ENSEMBL_BASEURL);
+            DEFAULT_ENSEMBL_BASEURL).trim();
     ensemblGenomesDomain = Cache.getDefault(ENSEMBL_GENOMES_BASEURL,
-            DEFAULT_ENSEMBL_GENOMES_BASEURL);
+            DEFAULT_ENSEMBL_GENOMES_BASEURL).trim();
     domain = ensemblDomain;
   }
 
@@ -168,6 +169,6 @@ abstract class EnsemblSequenceFetcher extends DbSourceProxyImpl
 
   protected void setDomain(String d)
   {
-    domain = d;
+    domain = d == null ? null : d.trim();
   }
 }
index 8832278..a5b1110 100644 (file)
@@ -1254,7 +1254,10 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel
     return chainNames;
   }
 
-  protected abstract IProgressIndicator getIProgressIndicator();
+  protected IProgressIndicator getIProgressIndicator()
+  {
+    return null;
+  }
 
   public void notifyNewPickingModeMeasurement(int iatom, String strMeasure)
   {
index 86710e1..232561c 100644 (file)
@@ -34,6 +34,7 @@ import jalview.util.MessageManager;
 import java.awt.BorderLayout;
 import java.awt.CardLayout;
 import java.awt.Dimension;
+import java.awt.Font;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.FocusAdapter;
@@ -86,6 +87,8 @@ import javax.swing.text.JTextComponent;
 @SuppressWarnings("serial")
 public abstract class GFTSPanel extends JPanel implements GFTSPanelI
 {
+  private static final Font VERDANA_12 = new Font("Verdana", 0, 12);
+
   protected JInternalFrame mainFrame = new JInternalFrame(
           getFTSFrameTitle());
 
@@ -300,11 +303,11 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI
     Integer height = getTempUserPrefs().get("FTSPanel.height") == null ? 400
             : getTempUserPrefs().get("FTSPanel.height");
     lbl_warning.setVisible(false);
-    lbl_warning.setFont(new java.awt.Font("Verdana", 0, 12));
+    lbl_warning.setFont(VERDANA_12);
     lbl_loading.setVisible(false);
-    lbl_loading.setFont(new java.awt.Font("Verdana", 0, 12));
+    lbl_loading.setFont(VERDANA_12);
     lbl_blank.setVisible(true);
-    lbl_blank.setFont(new java.awt.Font("Verdana", 0, 12));
+    lbl_blank.setFont(VERDANA_12);
 
     tbl_summary.setAutoCreateRowSorter(true);
     tbl_summary.getTableHeader().setReorderingAllowed(false);
@@ -357,6 +360,19 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI
       }
     });
 
+    JButton txt_help = new JButton("?");
+    txt_help.setFont(VERDANA_12);
+    txt_help.setPreferredSize(new Dimension(15, 15));
+    txt_help.setToolTipText(MessageManager.getString("action.help"));
+    txt_help.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        showHelp();
+      }
+    });
+
     btn_autosearch.setText(MessageManager.getString("option.autosearch"));
     btn_autosearch.setToolTipText(
             MessageManager.getString("option.enable_disable_autosearch"));
@@ -371,7 +387,7 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI
                 Boolean.toString(btn_autosearch.isSelected()));
       }
     });
-    btn_back.setFont(new java.awt.Font("Verdana", 0, 12));
+    btn_back.setFont(VERDANA_12);
     btn_back.setText(MessageManager.getString("action.back"));
     btn_back.addActionListener(new java.awt.event.ActionListener()
     {
@@ -394,7 +410,7 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI
     });
 
     btn_ok.setEnabled(false);
-    btn_ok.setFont(new java.awt.Font("Verdana", 0, 12));
+    btn_ok.setFont(VERDANA_12);
     btn_ok.setText(MessageManager.getString("action.ok"));
     btn_ok.addActionListener(new java.awt.event.ActionListener()
     {
@@ -418,7 +434,7 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI
     btn_next_page.setEnabled(false);
     btn_next_page.setToolTipText(
             MessageManager.getString("label.next_page_tooltip"));
-    btn_next_page.setFont(new java.awt.Font("Verdana", 0, 12));
+    btn_next_page.setFont(VERDANA_12);
     btn_next_page.setText(MessageManager.getString("action.next_page"));
     btn_next_page.addActionListener(new java.awt.event.ActionListener()
     {
@@ -443,7 +459,7 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI
     btn_prev_page.setEnabled(false);
     btn_prev_page.setToolTipText(
             MessageManager.getString("label.prev_page_tooltip"));
-    btn_prev_page.setFont(new java.awt.Font("Verdana", 0, 12));
+    btn_prev_page.setFont(VERDANA_12);
     btn_prev_page.setText(MessageManager.getString("action.prev_page"));
     btn_prev_page.addActionListener(new java.awt.event.ActionListener()
     {
@@ -476,7 +492,7 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI
       btn_next_page.setVisible(false);
     }
 
-    btn_cancel.setFont(new java.awt.Font("Verdana", 0, 12));
+    btn_cancel.setFont(VERDANA_12);
     btn_cancel.setText(MessageManager.getString("action.cancel"));
     btn_cancel.addActionListener(new java.awt.event.ActionListener()
     {
@@ -499,7 +515,7 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI
     });
     scrl_searchResult.setPreferredSize(new Dimension(width, height));
 
-    cmb_searchTarget.setFont(new java.awt.Font("Verdana", 0, 12));
+    cmb_searchTarget.setFont(VERDANA_12);
     cmb_searchTarget.addItemListener(new ItemListener()
     {
       @Override
@@ -532,7 +548,7 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI
       }
     });
 
-    txt_search.setFont(new java.awt.Font("Verdana", 0, 12));
+    txt_search.setFont(VERDANA_12);
 
     txt_search.getEditor().getEditorComponent()
             .addKeyListener(new KeyAdapter()
@@ -666,6 +682,7 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI
     pnl_results.add(tabbedPane);
     pnl_inputs.add(cmb_searchTarget);
     pnl_inputs.add(txt_search);
+    pnl_inputs.add(txt_help);
     pnl_inputs.add(btn_autosearch);
     pnl_inputs.add(lbl_loading);
     pnl_inputs.add(lbl_warning);
@@ -710,6 +727,8 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI
     Desktop.addInternalFrame(mainFrame, getFTSFrameTitle(), width, height);
   }
 
+  abstract protected void showHelp();
+
   protected void closeAction()
   {
     getTempUserPrefs().put("FTSPanel.width", this.getWidth());
index 053d91b..da164f0 100644 (file)
@@ -26,6 +26,8 @@ import jalview.fts.api.FTSRestClientI;
 import jalview.fts.core.FTSRestRequest;
 import jalview.fts.core.FTSRestResponse;
 import jalview.fts.core.GFTSPanel;
+import jalview.gui.Help;
+import jalview.gui.Help.HelpId;
 import jalview.gui.SequenceFetcher;
 import jalview.util.MessageManager;
 
@@ -33,13 +35,15 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
 
+import javax.help.HelpSetException;
+
 @SuppressWarnings("serial")
 public class PDBFTSPanel extends GFTSPanel
 {
   private static String defaultFTSFrameTitle = MessageManager
           .getString("label.pdb_sequence_fetcher");
 
-  private static Map<String, Integer> tempUserPrefs = new HashMap<String, Integer>();
+  private static Map<String, Integer> tempUserPrefs = new HashMap<>();
 
   private static final String PDB_FTS_CACHE_KEY = "CACHE.PDB_FTS";
 
@@ -190,7 +194,7 @@ public class PDBFTSPanel extends GFTSPanel
     // mainFrame.dispose();
     disableActionButtons();
     StringBuilder selectedIds = new StringBuilder();
-    HashSet<String> selectedIdsSet = new HashSet<String>();
+    HashSet<String> selectedIdsSet = new HashSet<>();
     int primaryKeyColIndex = 0;
     try
     {
@@ -288,4 +292,16 @@ public class PDBFTSPanel extends GFTSPanel
   {
     return PDB_AUTOSEARCH;
   }
+
+  @Override
+  protected void showHelp()
+  {
+    try
+    {
+      Help.showHelpWindow(HelpId.PdbFts);
+    } catch (HelpSetException e1)
+    {
+      e1.printStackTrace();
+    }
+ }
 }
\ No newline at end of file
index df54dea..977abfa 100644 (file)
@@ -26,6 +26,8 @@ import jalview.fts.api.FTSRestClientI;
 import jalview.fts.core.FTSRestRequest;
 import jalview.fts.core.FTSRestResponse;
 import jalview.fts.core.GFTSPanel;
+import jalview.gui.Help;
+import jalview.gui.Help.HelpId;
 import jalview.gui.SequenceFetcher;
 import jalview.util.MessageManager;
 
@@ -33,6 +35,8 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
 
+import javax.help.HelpSetException;
+
 @SuppressWarnings("serial")
 public class UniprotFTSPanel extends GFTSPanel
 {
@@ -245,4 +249,16 @@ public class UniprotFTSPanel extends GFTSPanel
   {
     return UNIPROT_AUTOSEARCH;
   }
+
+  @Override
+  protected void showHelp()
+  {
+    try
+    {
+      Help.showHelpWindow(HelpId.UniprotFts);
+    } catch (HelpSetException e1)
+    {
+      e1.printStackTrace();
+    }
+  }
 }
index 2b6d868..bd9f661 100644 (file)
@@ -24,6 +24,7 @@ import jalview.analysis.AlignmentSorter;
 import jalview.analysis.AlignmentUtils;
 import jalview.analysis.CrossRef;
 import jalview.analysis.Dna;
+import jalview.analysis.GeneticCodeI;
 import jalview.analysis.ParseProperties;
 import jalview.analysis.SequenceIdMatcher;
 import jalview.api.AlignExportSettingI;
@@ -64,6 +65,7 @@ import jalview.gui.ColourMenuHelper.ColourChangeListener;
 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
 import jalview.io.AlignmentProperties;
 import jalview.io.AnnotationFile;
+import jalview.io.BackupFiles;
 import jalview.io.BioJsHTMLOutput;
 import jalview.io.DataSourceType;
 import jalview.io.FileFormat;
@@ -134,6 +136,7 @@ import java.util.Hashtable;
 import java.util.List;
 import java.util.Vector;
 
+import javax.swing.ButtonGroup;
 import javax.swing.JCheckBoxMenuItem;
 import javax.swing.JEditorPane;
 import javax.swing.JInternalFrame;
@@ -963,6 +966,11 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     return progressBar.operationInProgress();
   }
 
+  /**
+   * Sets the text of the status bar. Note that setting a null or empty value
+   * will cause the status bar to be hidden, with possibly undesirable flicker
+   * of the screen layout.
+   */
   @Override
   public void setStatus(String text)
   {
@@ -1187,10 +1195,13 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       }
       else
       {
+        // create backupfiles object and get new temp filename destination
+        BackupFiles backupfiles = new BackupFiles(file);
+
         try
         {
-          // PrintWriter out = new PrintWriter(new FileWriter(file));
-          PrintWriter out = new PrintWriter(new FileWriter(file), true);
+          PrintWriter out = new PrintWriter(
+                  new FileWriter(backupfiles.getTempFilePath()));
 
           // TESTING code here
           boolean TESTING = true;
@@ -1219,6 +1230,11 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
           success = false;
           ex.printStackTrace();
         }
+
+        backupfiles.setWriteSuccess(success);
+        // do the backup file roll and rename the temp file to actual file
+        success = backupfiles.rollBackupsAndRenameTempFile();
+
       }
     }
 
@@ -2415,15 +2431,12 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   @Override
   public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
   {
-    SequenceGroup sg = new SequenceGroup();
-
-    for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
-    {
-      sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
-    }
+    SequenceGroup sg = new SequenceGroup(
+            viewport.getAlignment().getSequences());
 
     sg.setEndRes(viewport.getAlignment().getWidth() - 1);
     viewport.setSelectionGroup(sg);
+    viewport.isSelectionGroupChanged(true);
     viewport.sendSelection();
     // JAL-2034 - should delegate to
     // alignPanel to decide if overview needs
@@ -2734,8 +2747,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
 
     if (viewport.getViewName() == null)
     {
-      viewport.setViewName(
-              MessageManager.getString("label.view_name_original"));
+      viewport.setViewName(MessageManager
+              .getString("label.view_name_original"));
     }
 
     /*
@@ -2745,6 +2758,12 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     newap.av.setRedoList(viewport.getRedoList());
 
     /*
+     * copy any visualisation settings that are not saved in the project
+     */
+    newap.av.setColourAppliesToAllGroups(
+            viewport.getColourAppliesToAllGroups());
+
+    /*
      * Views share the same mappings; need to deregister any new mappings
      * created by copyAlignPanel, and register the new reference to the shared
      * mappings
@@ -2907,7 +2926,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     viewport.setFollowHighlight(state);
     if (state)
     {
-      alignPanel.scrollToPosition(viewport.getSearchResults(), false);
+      alignPanel.scrollToPosition(viewport.getSearchResults());
     }
   }
 
@@ -3054,6 +3073,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     viewport.expandColSelection(sg, false);
     viewport.hideAllSelectedSeqs();
     viewport.hideSelectedColumns();
+    alignPanel.updateLayout();
     alignPanel.paintAlignment(true, true);
     viewport.sendSelection();
   }
@@ -3078,6 +3098,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   public void hideSelColumns_actionPerformed(ActionEvent e)
   {
     viewport.hideSelectedColumns();
+    alignPanel.updateLayout();
     alignPanel.paintAlignment(true, true);
     viewport.sendSelection();
   }
@@ -3347,6 +3368,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
      * otherwise set the chosen colour scheme (or null for 'None')
      */
     ColourSchemeI cs = ColourSchemes.getInstance().getColourScheme(name,
+            viewport,
             viewport.getAlignment(), viewport.getHiddenRepSequences());
     changeColour(cs);
   }
@@ -4279,14 +4301,14 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * frame's DNA sequences to their aligned protein (amino acid) equivalents.
    */
   @Override
-  public void showTranslation_actionPerformed(ActionEvent e)
+  public void showTranslation_actionPerformed(GeneticCodeI codeTable)
   {
     AlignmentI al = null;
     try
     {
       Dna dna = new Dna(viewport, viewport.getViewAsVisibleContigs(true));
 
-      al = dna.translateCdna();
+      al = dna.translateCdna(codeTable);
     } catch (Exception ex)
     {
       jalview.bin.Cache.log.error(
@@ -4315,7 +4337,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       af.setFileFormat(this.currentFileFormat);
       final String newTitle = MessageManager
               .formatMessage("label.translation_of_params", new Object[]
-              { this.getTitle() });
+              { this.getTitle(), codeTable.getId() });
       af.setTitle(newTitle);
       if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, true))
       {
@@ -5304,7 +5326,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     {
       PaintRefresher.Refresh(this, viewport.getSequenceSetId());
       alignPanel.updateAnnotation();
-      alignPanel.paintAlignment(true, true);
+      alignPanel.paintAlignment(true,
+              viewport.needToUpdateStructureViews());
     }
   }
 
@@ -5590,15 +5613,16 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     colourMenu.add(textColour);
     colourMenu.addSeparator();
 
-    ColourMenuHelper.addMenuItems(colourMenu, this, viewport.getAlignment(),
-            false);
+    ButtonGroup bg = ColourMenuHelper.addMenuItems(colourMenu, this,
+            viewport.getAlignment(), false);
 
+    colourMenu.add(annotationColour);
+    bg.add(annotationColour);
     colourMenu.addSeparator();
     colourMenu.add(conservationMenuItem);
     colourMenu.add(modifyConservation);
     colourMenu.add(abovePIDThreshold);
     colourMenu.add(modifyPID);
-    colourMenu.add(annotationColour);
 
     ColourSchemeI colourScheme = viewport.getGlobalColourScheme();
     ColourMenuHelper.setColourSelected(colourMenu, colourScheme);
index cc533ce..bc668fd 100644 (file)
@@ -290,7 +290,7 @@ public class AlignViewport extends AlignmentViewport
               ResidueColourScheme.NONE);
     }
     ColourSchemeI colourScheme = ColourSchemeProperty
-            .getColourScheme(alignment, schemeName);
+            .getColourScheme(this, alignment, schemeName);
     residueShading = new ResidueShader(colourScheme);
 
     if (colourScheme instanceof UserColourScheme)
@@ -304,6 +304,7 @@ public class AlignViewport extends AlignmentViewport
     {
       residueShading.setConsensus(hconsensus);
     }
+    setColourAppliesToAllGroups(true);
   }
 
   boolean validCharWidth;
@@ -795,7 +796,7 @@ public class AlignViewport extends AlignmentViewport
     AlignFrame newAlignFrame = new AlignFrame(al, AlignFrame.DEFAULT_WIDTH,
             AlignFrame.DEFAULT_HEIGHT);
     newAlignFrame.setTitle(title);
-    newAlignFrame.statusBar.setText(MessageManager
+    newAlignFrame.setStatus(MessageManager
             .formatMessage("label.successfully_loaded_file", new Object[]
             { title }));
 
index c03b56d..92b9a50 100644 (file)
@@ -328,12 +328,12 @@ public class AlignmentPanel extends GAlignmentPanel implements
   }
 
   /**
-   * Highlight the given results on the alignment.
+   * Highlight the given results on the alignment
    * 
    */
   public void highlightSearchResults(SearchResultsI results)
   {
-    boolean scrolled = scrollToPosition(results, 0, true, false);
+    boolean scrolled = scrollToPosition(results, 0, false);
 
     boolean noFastPaint = scrolled && av.getWrapAlignment();
 
@@ -345,13 +345,11 @@ public class AlignmentPanel extends GAlignmentPanel implements
    * (if any)
    * 
    * @param searchResults
-   * @param redrawOverview
    * @return
    */
-  public boolean scrollToPosition(SearchResultsI searchResults,
-          boolean redrawOverview)
+  public boolean scrollToPosition(SearchResultsI searchResults)
   {
-    return scrollToPosition(searchResults, 0, redrawOverview, false);
+    return scrollToPosition(searchResults, 0, false);
   }
 
   /**
@@ -364,14 +362,12 @@ public class AlignmentPanel extends GAlignmentPanel implements
    * @param verticalOffset
    *          if greater than zero, allows scrolling to a position below the
    *          first displayed sequence
-   * @param redrawOverview
-   *          - when set, the overview will be recalculated (takes longer)
    * @param centre
    *          if true, try to centre the search results horizontally in the view
    * @return
    */
   protected boolean scrollToPosition(SearchResultsI results,
-          int verticalOffset, boolean redrawOverview, boolean centre)
+          int verticalOffset, boolean centre)
   {
     int startv, endv, starts, ends;
     ViewportRanges ranges = av.getRanges();
@@ -477,7 +473,7 @@ public class AlignmentPanel extends GAlignmentPanel implements
       scrollNeeded = ranges.scrollToWrappedVisible(start);
     }
 
-    paintAlignment(redrawOverview, false);
+    paintAlignment(false, false);
 
     return scrollNeeded;
   }
@@ -536,7 +532,7 @@ public class AlignmentPanel extends GAlignmentPanel implements
     addNotify();
     // TODO: many places call this method and also paintAlignment with various
     // different settings. this means multiple redraws are triggered...
-    paintAlignment(true, false);
+    paintAlignment(true, av.needToUpdateStructureViews());
   }
 
   /**
@@ -641,16 +637,9 @@ public class AlignmentPanel extends GAlignmentPanel implements
     }
     else
     {
-      int width = av.getAlignment().getWidth();
+      int width = av.getAlignment().getVisibleWidth();
       int height = av.getAlignment().getHeight();
 
-      if (av.hasHiddenColumns())
-      {
-        // reset the width to exclude hidden columns
-        width = av.getAlignment().getHiddenColumns()
-                .absoluteToVisibleColumn(width);
-      }
-
       hextent = getSeqPanel().seqCanvas.getWidth() / av.getCharWidth();
       vextent = getSeqPanel().seqCanvas.getHeight() / av.getCharHeight();
 
@@ -962,8 +951,8 @@ public class AlignmentPanel extends GAlignmentPanel implements
 
     final int totalSeq = (pageHeight - scaleHeight) / charHeight - 1;
 
-    final int alignmentWidth = av.getAlignment().getWidth();
-    final int pagesWide = (alignmentWidth / totalRes) + 1;
+    final int alignmentWidth = av.getAlignment().getVisibleWidth();
+    int pagesWide = (alignmentWidth / totalRes) + 1;
 
     final int startRes = (pageIndex % pagesWide) * totalRes;
     final int endRes = Math.min(startRes + totalRes - 1,
@@ -1080,12 +1069,7 @@ public class AlignmentPanel extends GAlignmentPanel implements
 
     int idWidth = getVisibleIdWidth(false);
 
-    int maxwidth = av.getAlignment().getWidth();
-    if (av.hasHiddenColumns())
-    {
-      maxwidth = av.getAlignment().getHiddenColumns()
-              .absoluteToVisibleColumn(maxwidth) - 1;
-    }
+    int maxwidth = av.getAlignment().getVisibleWidth();
 
     int resWidth = getSeqPanel().seqCanvas
             .getWrappedCanvasWidth(pageWidth - idWidth);
@@ -1247,12 +1231,7 @@ public class AlignmentPanel extends GAlignmentPanel implements
 
   public AlignmentDimension getAlignmentDimension()
   {
-    int maxwidth = av.getAlignment().getWidth();
-    if (av.hasHiddenColumns())
-    {
-      maxwidth = av.getAlignment().getHiddenColumns()
-              .absoluteToVisibleColumn(maxwidth);
-    }
+    int maxwidth = av.getAlignment().getVisibleWidth();
 
     int height = ((av.getAlignment().getHeight() + 1) * av.getCharHeight())
             + getScalePanel().getHeight();
@@ -1698,7 +1677,7 @@ public class AlignmentPanel extends GAlignmentPanel implements
    */
   protected void scrollToCentre(SearchResultsI sr, int verticalOffset)
   {
-    scrollToPosition(sr, verticalOffset, true, true);
+    scrollToPosition(sr, verticalOffset, true);
   }
 
   /**
index 84883d7..791421d 100644 (file)
@@ -195,14 +195,7 @@ public class AnnotationChooser extends JPanel
   {
     setAnnotationVisibility(true);
 
-    // copied from AnnotationLabel.actionPerformed (after show/hide row)...
-    // TODO should drive this functionality into AlignmentPanel
     ap.updateAnnotation();
-    // this.ap.annotationPanel.adjustPanelHeight();
-    // this.ap.alabels.setSize(this.ap.alabels.getSize().width,
-    // this.ap.annotationPanel.getSize().height);
-    // this.ap.validate();
-    this.ap.paintAlignment(true, false);
   }
 
   /**
@@ -229,11 +222,6 @@ public class AnnotationChooser extends JPanel
       }
     }
     ap.updateAnnotation();
-    // // this.ap.annotationPanel.adjustPanelHeight();
-    // this.ap.alabels.setSize(this.ap.alabels.getSize().width,
-    // this.ap.annotationPanel.getSize().height);
-    // this.ap.validate();
-    this.ap.paintAlignment(true, false);
   }
 
   /**
@@ -249,9 +237,7 @@ public class AnnotationChooser extends JPanel
   {
     setAnnotationVisibility(false);
 
-    this.ap.updateAnnotation();
-    // this.ap.annotationPanel.adjustPanelHeight();
-    this.ap.paintAlignment(true, false);
+    ap.updateAnnotation();
   }
 
   /**
index 384635b..60ad75d 100644 (file)
@@ -317,7 +317,7 @@ public class AnnotationColourChooser extends AnnotationRowFilter
   @Override
   public void reset()
   {
-    av.setGlobalColourScheme(oldcs);
+    this.ap.alignFrame.changeColour(oldcs);
     if (av.getAlignment().getGroups() != null)
     {
 
@@ -442,7 +442,7 @@ public class AnnotationColourChooser extends AnnotationRowFilter
 
     acg.setThresholdIsMinMax(thresholdIsMin.isSelected());
 
-    av.setGlobalColourScheme(acg);
+    this.ap.alignFrame.changeColour(acg);
 
     if (av.getAlignment().getGroups() != null)
     {
@@ -454,7 +454,7 @@ public class AnnotationColourChooser extends AnnotationRowFilter
           continue;
         }
         sg.setColourScheme(
-                acg.getInstance(sg, ap.av.getHiddenRepSequences()));
+                acg.getInstance(av, sg));
       }
     }
   }
@@ -465,5 +465,4 @@ public class AnnotationColourChooser extends AnnotationRowFilter
     super.sliderDragReleased();
     ap.paintAlignment(true, true);
   }
-
 }
index 6924b63..5adecad 100644 (file)
@@ -33,6 +33,8 @@ import java.awt.Color;
 import java.awt.Dimension;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
+import java.awt.event.FocusAdapter;
+import java.awt.event.FocusEvent;
 import java.awt.event.ItemEvent;
 import java.awt.event.ItemListener;
 import java.awt.event.KeyEvent;
@@ -744,6 +746,15 @@ public class AnnotationColumnChooser extends AnnotationRowFilter
                   }
                 }
               });
+      searchBox.getEditor().getEditorComponent()
+              .addFocusListener(new FocusAdapter()
+      {
+        @Override
+        public void focusLost(FocusEvent e)
+        {
+          searchStringAction();
+        }
+      });
 
       JvSwingUtils.jvInitComponent(displayName, "label.label");
       displayName.addActionListener(new ActionListener()
@@ -761,7 +772,7 @@ public class AnnotationColumnChooser extends AnnotationRowFilter
         @Override
         public void actionPerformed(ActionEvent actionEvent)
         {
-          discriptionCheckboxAction();
+          descriptionCheckboxAction();
         }
       });
 
@@ -777,7 +788,7 @@ public class AnnotationColumnChooser extends AnnotationRowFilter
       aColChooser.updateView();
     }
 
-    public void discriptionCheckboxAction()
+    public void descriptionCheckboxAction()
     {
       aColChooser.setCurrentSearchPanel(this);
       aColChooser.updateView();
index 6fefbd0..fac531e 100644 (file)
  */
 package jalview.gui;
 
-import jalview.api.FeatureColourI;
+import jalview.api.FeatureRenderer;
 import jalview.bin.Cache;
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.SequenceI;
-import jalview.datamodel.features.FeatureMatcherSetI;
 import jalview.io.AnnotationFile;
 import jalview.io.FeaturesFile;
 import jalview.io.JalviewFileChooser;
@@ -38,8 +37,6 @@ import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.io.FileWriter;
 import java.io.PrintWriter;
-import java.util.List;
-import java.util.Map;
 
 import javax.swing.BorderFactory;
 import javax.swing.ButtonGroup;
@@ -214,24 +211,18 @@ public class AnnotationExporter extends JPanel
   {
     String text;
     SequenceI[] sequences = ap.av.getAlignment().getSequencesArray();
-    Map<String, FeatureColourI> featureColours = ap.getFeatureRenderer()
-            .getDisplayedFeatureCols();
-    Map<String, FeatureMatcherSetI> featureFilters = ap.getFeatureRenderer()
-            .getFeatureFilters();
-    List<String> featureGroups = ap.getFeatureRenderer()
-            .getDisplayedFeatureGroups();
     boolean includeNonPositional = ap.av.isShowNPFeats();
 
     FeaturesFile formatter = new FeaturesFile();
+    final FeatureRenderer fr = ap.getFeatureRenderer();
     if (GFFFormat.isSelected())
     {
-      text = formatter.printGffFormat(sequences, featureColours,
-              featureGroups, includeNonPositional);
+      text = formatter.printGffFormat(sequences, fr, includeNonPositional);
     }
     else
     {
-      text = formatter.printJalviewFormat(sequences, featureColours,
-              featureFilters, featureGroups, includeNonPositional);
+      text = formatter.printJalviewFormat(sequences, fr,
+              includeNonPositional);
     }
     return text;
   }
index 6f8b225..6da6cc3 100755 (executable)
@@ -51,12 +51,9 @@ import java.awt.event.MouseEvent;
 import java.awt.event.MouseListener;
 import java.awt.event.MouseMotionListener;
 import java.awt.geom.AffineTransform;
-import java.awt.image.BufferedImage;
-import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.Iterator;
-import java.util.regex.Pattern;
 
 import javax.swing.JCheckBoxMenuItem;
 import javax.swing.JMenuItem;
@@ -73,6 +70,10 @@ import javax.swing.ToolTipManager;
 public class AnnotationLabels extends JPanel
         implements MouseListener, MouseMotionListener, ActionListener
 {
+  private static final String HTML_END_TAG = "</html>";
+
+  private static final String HTML_START_TAG = "<html>";
+
   /**
    * width in pixels within which height adjuster arrows are shown and active
    */
@@ -83,9 +84,6 @@ public class AnnotationLabels extends JPanel
    */
   private static int HEIGHT_ADJUSTER_HEIGHT = 10;
 
-  private static final Pattern LEFT_ANGLE_BRACKET_PATTERN = Pattern
-          .compile("<");
-
   private static final Font font = new Font("Arial", Font.PLAIN, 11);
 
   private static final String TOGGLE_LABELSCALE = MessageManager
@@ -378,15 +376,6 @@ public class AnnotationLabels extends JPanel
             AlignmentUtils.showOrHideSequenceAnnotations(
                     ap.av.getAlignment(), Collections.singleton(label),
                     null, false, false);
-            // for (AlignmentAnnotation ann : ap.av.getAlignment()
-            // .getAlignmentAnnotation())
-            // {
-            // if (ann.sequenceRef != null && ann.label != null
-            // && ann.label.equals(label))
-            // {
-            // ann.visible = false;
-            // }
-            // }
             ap.refresh(true);
           }
         });
@@ -425,174 +414,154 @@ public class AnnotationLabels extends JPanel
       }
       else if (label.indexOf("Consensus") > -1)
       {
-        pop.addSeparator();
-        // av and sequencegroup need to implement same interface for
-        final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem(
-                MessageManager.getString("label.ignore_gaps_consensus"),
-                (aa[selectedRow].groupRef != null)
-                        ? aa[selectedRow].groupRef.getIgnoreGapsConsensus()
-                        : ap.av.isIgnoreGapsConsensus());
-        final AlignmentAnnotation aaa = aa[selectedRow];
-        cbmi.addActionListener(new ActionListener()
-        {
-          @Override
-          public void actionPerformed(ActionEvent e)
-          {
-            if (aaa.groupRef != null)
-            {
-              // TODO: pass on reference to ap so the view can be updated.
-              aaa.groupRef.setIgnoreGapsConsensus(cbmi.getState());
-              ap.getAnnotationPanel()
-                      .paint(ap.getAnnotationPanel().getGraphics());
-            }
-            else
-            {
-              ap.av.setIgnoreGapsConsensus(cbmi.getState(), ap);
-            }
-            ap.alignmentChanged();
-          }
-        });
-        pop.add(cbmi);
-        // av and sequencegroup need to implement same interface for
+        addConsensusMenuOptions(ap, aa[selectedRow], pop);
+
+        final JMenuItem consclipbrd = new JMenuItem(COPYCONS_SEQ);
+        consclipbrd.addActionListener(this);
+        pop.add(consclipbrd);
+      }
+    }
+    pop.show(this, evt.getX(), evt.getY());
+  }
+
+  /**
+   * A helper method that adds menu options for calculation and visualisation of
+   * group and/or alignment consensus annotation to a popup menu. This is
+   * designed to be reusable for either unwrapped mode (popup menu is shown on
+   * component AnnotationLabels), or wrapped mode (popup menu is shown on
+   * IdPanel when the mouse is over an annotation label).
+   * 
+   * @param ap
+   * @param ann
+   * @param pop
+   */
+  static void addConsensusMenuOptions(AlignmentPanel ap,
+          AlignmentAnnotation ann,
+          JPopupMenu pop)
+  {
+    pop.addSeparator();
+
+    final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem(
+            MessageManager.getString("label.ignore_gaps_consensus"),
+            (ann.groupRef != null) ? ann.groupRef.getIgnoreGapsConsensus()
+                    : ap.av.isIgnoreGapsConsensus());
+    final AlignmentAnnotation aaa = ann;
+    cbmi.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
         if (aaa.groupRef != null)
         {
-          final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
-                  MessageManager.getString("label.show_group_histogram"),
-                  aa[selectedRow].groupRef.isShowConsensusHistogram());
-          chist.addActionListener(new ActionListener()
-          {
-            @Override
-            public void actionPerformed(ActionEvent e)
-            {
-              // TODO: pass on reference
-              // to ap
-              // so the
-              // view
-              // can be
-              // updated.
-              aaa.groupRef.setShowConsensusHistogram(chist.getState());
-              ap.repaint();
-              // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
-            }
-          });
-          pop.add(chist);
-          final JCheckBoxMenuItem cprofl = new JCheckBoxMenuItem(
-                  MessageManager.getString("label.show_group_logo"),
-                  aa[selectedRow].groupRef.isShowSequenceLogo());
-          cprofl.addActionListener(new ActionListener()
-          {
-            @Override
-            public void actionPerformed(ActionEvent e)
-            {
-              // TODO: pass on reference
-              // to ap
-              // so the
-              // view
-              // can be
-              // updated.
-              aaa.groupRef.setshowSequenceLogo(cprofl.getState());
-              ap.repaint();
-              // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
-            }
-          });
-          pop.add(cprofl);
-          final JCheckBoxMenuItem cproflnorm = new JCheckBoxMenuItem(
-                  MessageManager.getString("label.normalise_group_logo"),
-                  aa[selectedRow].groupRef.isNormaliseSequenceLogo());
-          cproflnorm.addActionListener(new ActionListener()
-          {
-            @Override
-            public void actionPerformed(ActionEvent e)
-            {
-
-              // TODO: pass on reference
-              // to ap
-              // so the
-              // view
-              // can be
-              // updated.
-              aaa.groupRef.setNormaliseSequenceLogo(cproflnorm.getState());
-              // automatically enable logo display if we're clicked
-              aaa.groupRef.setshowSequenceLogo(true);
-              ap.repaint();
-              // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
-            }
-          });
-          pop.add(cproflnorm);
+          aaa.groupRef.setIgnoreGapsConsensus(cbmi.getState());
+          ap.getAnnotationPanel()
+                  .paint(ap.getAnnotationPanel().getGraphics());
         }
         else
         {
-          final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
-                  MessageManager.getString("label.show_histogram"),
-                  av.isShowConsensusHistogram());
-          chist.addActionListener(new ActionListener()
-          {
-            @Override
-            public void actionPerformed(ActionEvent e)
-            {
-              // TODO: pass on reference
-              // to ap
-              // so the
-              // view
-              // can be
-              // updated.
-              av.setShowConsensusHistogram(chist.getState());
-              ap.alignFrame.setMenusForViewport();
-              ap.repaint();
-              // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
-            }
-          });
-          pop.add(chist);
-          final JCheckBoxMenuItem cprof = new JCheckBoxMenuItem(
-                  MessageManager.getString("label.show_logo"),
-                  av.isShowSequenceLogo());
-          cprof.addActionListener(new ActionListener()
-          {
-            @Override
-            public void actionPerformed(ActionEvent e)
-            {
-              // TODO: pass on reference
-              // to ap
-              // so the
-              // view
-              // can be
-              // updated.
-              av.setShowSequenceLogo(cprof.getState());
-              ap.alignFrame.setMenusForViewport();
-              ap.repaint();
-              // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
-            }
-          });
-          pop.add(cprof);
-          final JCheckBoxMenuItem cprofnorm = new JCheckBoxMenuItem(
-                  MessageManager.getString("label.normalise_logo"),
-                  av.isNormaliseSequenceLogo());
-          cprofnorm.addActionListener(new ActionListener()
-          {
-            @Override
-            public void actionPerformed(ActionEvent e)
-            {
-              // TODO: pass on reference
-              // to ap
-              // so the
-              // view
-              // can be
-              // updated.
-              av.setShowSequenceLogo(true);
-              av.setNormaliseSequenceLogo(cprofnorm.getState());
-              ap.alignFrame.setMenusForViewport();
-              ap.repaint();
-              // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
-            }
-          });
-          pop.add(cprofnorm);
+          ap.av.setIgnoreGapsConsensus(cbmi.getState(), ap);
         }
-        final JMenuItem consclipbrd = new JMenuItem(COPYCONS_SEQ);
-        consclipbrd.addActionListener(this);
-        pop.add(consclipbrd);
+        ap.alignmentChanged();
       }
+    });
+    pop.add(cbmi);
+
+    if (aaa.groupRef != null)
+    {
+      /*
+       * group consensus options
+       */
+      final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
+              MessageManager.getString("label.show_group_histogram"),
+              ann.groupRef.isShowConsensusHistogram());
+      chist.addActionListener(new ActionListener()
+      {
+        @Override
+        public void actionPerformed(ActionEvent e)
+        {
+          aaa.groupRef.setShowConsensusHistogram(chist.getState());
+          ap.repaint();
+        }
+      });
+      pop.add(chist);
+      final JCheckBoxMenuItem cprofl = new JCheckBoxMenuItem(
+              MessageManager.getString("label.show_group_logo"),
+              ann.groupRef.isShowSequenceLogo());
+      cprofl.addActionListener(new ActionListener()
+      {
+        @Override
+        public void actionPerformed(ActionEvent e)
+        {
+          aaa.groupRef.setshowSequenceLogo(cprofl.getState());
+          ap.repaint();
+        }
+      });
+      pop.add(cprofl);
+      final JCheckBoxMenuItem cproflnorm = new JCheckBoxMenuItem(
+              MessageManager.getString("label.normalise_group_logo"),
+              ann.groupRef.isNormaliseSequenceLogo());
+      cproflnorm.addActionListener(new ActionListener()
+      {
+        @Override
+        public void actionPerformed(ActionEvent e)
+        {
+          aaa.groupRef.setNormaliseSequenceLogo(cproflnorm.getState());
+          // automatically enable logo display if we're clicked
+          aaa.groupRef.setshowSequenceLogo(true);
+          ap.repaint();
+        }
+      });
+      pop.add(cproflnorm);
+    }
+    else
+    {
+      /*
+       * alignment consensus options
+       */
+      final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
+              MessageManager.getString("label.show_histogram"),
+              ap.av.isShowConsensusHistogram());
+      chist.addActionListener(new ActionListener()
+      {
+        @Override
+        public void actionPerformed(ActionEvent e)
+        {
+          ap.av.setShowConsensusHistogram(chist.getState());
+          ap.alignFrame.setMenusForViewport();
+          ap.repaint();
+        }
+      });
+      pop.add(chist);
+      final JCheckBoxMenuItem cprof = new JCheckBoxMenuItem(
+              MessageManager.getString("label.show_logo"),
+              ap.av.isShowSequenceLogo());
+      cprof.addActionListener(new ActionListener()
+      {
+        @Override
+        public void actionPerformed(ActionEvent e)
+        {
+          ap.av.setShowSequenceLogo(cprof.getState());
+          ap.alignFrame.setMenusForViewport();
+          ap.repaint();
+        }
+      });
+      pop.add(cprof);
+      final JCheckBoxMenuItem cprofnorm = new JCheckBoxMenuItem(
+              MessageManager.getString("label.normalise_logo"),
+              ap.av.isNormaliseSequenceLogo());
+      cprofnorm.addActionListener(new ActionListener()
+      {
+        @Override
+        public void actionPerformed(ActionEvent e)
+        {
+          ap.av.setShowSequenceLogo(true);
+          ap.av.setNormaliseSequenceLogo(cprofnorm.getState());
+          ap.alignFrame.setMenusForViewport();
+          ap.repaint();
+        }
+      });
+      pop.add(cprofnorm);
     }
-    pop.show(this, evt.getX(), evt.getY());
   }
 
   /**
@@ -705,73 +674,123 @@ public class AnnotationLabels extends JPanel
     if (selectedRow > -1 && ap.av.getAlignment()
             .getAlignmentAnnotation().length > selectedRow)
     {
-      AlignmentAnnotation aa = ap.av.getAlignment()
-              .getAlignmentAnnotation()[selectedRow];
+      AlignmentAnnotation[] anns = ap.av.getAlignment()
+              .getAlignmentAnnotation();
+      AlignmentAnnotation aa = anns[selectedRow];
+
+      String desc = getTooltip(aa);
+      this.setToolTipText(desc);
+      String msg = getStatusMessage(aa, anns);
+      ap.alignFrame.setStatus(msg);
+    }
+  }
+
+  /**
+   * Constructs suitable text to show in the status bar when over an annotation
+   * label, containing the associated sequence name (if any), and the annotation
+   * labels (or all labels for a graph group annotation)
+   * 
+   * @param aa
+   * @param anns
+   * @return
+   */
+  static String getStatusMessage(AlignmentAnnotation aa,
+          AlignmentAnnotation[] anns)
+  {
+    if (aa == null)
+    {
+      return null;
+    }
 
-      StringBuffer desc = new StringBuffer();
-      if (aa.description != null
-              && !aa.description.equals("New description"))
+    StringBuilder msg = new StringBuilder(32);
+    if (aa.sequenceRef != null)
+    {
+      msg.append(aa.sequenceRef.getName()).append(" : ");
+    }
+
+    if (aa.graphGroup == -1)
+    {
+      msg.append(aa.label);
+    }
+    else if (anns != null)
+    {
+      boolean first = true;
+      for (int i = anns.length - 1; i >= 0; i--)
       {
-        // TODO: we could refactor and merge this code with the code in
-        // jalview.gui.SeqPanel.mouseMoved(..) that formats sequence feature
-        // tooltips
-        desc.append(aa.getDescription(true).trim());
-        // check to see if the description is an html fragment.
-        if (desc.length() < 6 || (desc.substring(0, 6).toLowerCase()
-                .indexOf("<html>") < 0))
+        if (anns[i].graphGroup == aa.graphGroup)
         {
-          // clean the description ready for embedding in html
-          desc = new StringBuffer(LEFT_ANGLE_BRACKET_PATTERN.matcher(desc)
-                  .replaceAll("&lt;"));
-          desc.insert(0, "<html>");
-        }
-        else
-        {
-          // remove terminating html if any
-          int i = desc.substring(desc.length() - 7).toLowerCase()
-                  .lastIndexOf("</html>");
-          if (i > -1)
+          if (!first)
           {
-            desc.setLength(desc.length() - 7 + i);
+            msg.append(", ");
           }
+          msg.append(anns[i].label);
+          first = false;
         }
-        if (aa.hasScore())
-        {
-          desc.append("<br/>");
-        }
-        // if (aa.hasProperties())
-        // {
-        // desc.append("<table>");
-        // for (String prop : aa.getProperties())
-        // {
-        // desc.append("<tr><td>" + prop + "</td><td>"
-        // + aa.getProperty(prop) + "</td><tr>");
-        // }
-        // desc.append("</table>");
-        // }
       }
-      else
+    }
+
+    return msg.toString();
+  }
+
+  /**
+   * Answers a tooltip, formatted as html, containing the annotation description
+   * (prefixed by associated sequence id if applicable), and the annotation
+   * (non-positional) score if it has one. Answers null if neither description
+   * nor score is found.
+   * 
+   * @param aa
+   * @return
+   */
+  static String getTooltip(AlignmentAnnotation aa)
+  {
+    if (aa == null)
+    {
+      return null;
+    }
+    StringBuilder tooltip = new StringBuilder();
+    if (aa.description != null && !aa.description.equals("New description"))
+    {
+      // TODO: we could refactor and merge this code with the code in
+      // jalview.gui.SeqPanel.mouseMoved(..) that formats sequence feature
+      // tooltips
+      String desc = aa.getDescription(true).trim();
+      if (!desc.toLowerCase().startsWith(HTML_START_TAG))
       {
-        // begin the tooltip's html fragment
-        desc.append("<html>");
-        if (aa.hasScore())
-        {
-          // TODO: limit precision of score to avoid noise from imprecise
-          // doubles
-          // (64.7 becomes 64.7+/some tiny value).
-          desc.append(" Score: " + aa.score);
-        }
+        tooltip.append(HTML_START_TAG);
+        desc = desc.replace("<", "&lt;");
       }
-      if (desc.length() > 6)
+      else if (desc.toLowerCase().endsWith(HTML_END_TAG))
       {
-        desc.append("</html>");
-        this.setToolTipText(desc.toString());
+        desc = desc.substring(0, desc.length() - HTML_END_TAG.length());
       }
-      else
+      tooltip.append(desc);
+    }
+    else
+    {
+      // begin the tooltip's html fragment
+      tooltip.append(HTML_START_TAG);
+    }
+    if (aa.hasScore())
+    {
+      if (tooltip.length() > HTML_START_TAG.length())
       {
-        this.setToolTipText(null);
+        tooltip.append("<br/>");
       }
+      // TODO: limit precision of score to avoid noise from imprecise
+      // doubles
+      // (64.7 becomes 64.7+/some tiny value).
+      tooltip.append(" Score: ").append(String.valueOf(aa.score));
+    }
+
+    if (tooltip.length() > HTML_START_TAG.length())
+    {
+      return tooltip.append(HTML_END_TAG).toString();
     }
+
+    /*
+     * nothing in the tooltip (except "<html>")
+     */
+    return null;
   }
 
   /**
index 50971c7..16db94c 100755 (executable)
@@ -21,6 +21,7 @@
 package jalview.gui;
 
 import jalview.datamodel.AlignmentAnnotation;
+import jalview.datamodel.AlignmentI;
 import jalview.datamodel.Annotation;
 import jalview.datamodel.ColumnSelection;
 import jalview.datamodel.HiddenColumns;
@@ -76,6 +77,11 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
         MouseListener, MouseWheelListener, MouseMotionListener,
         ActionListener, AdjustmentListener, Scrollable, ViewportListenerI
 {
+  enum DragMode
+  {
+    Select, Resize, Undefined
+  };
+
   String HELIX = MessageManager.getString("label.helix");
 
   String SHEET = MessageManager.getString("label.sheet");
@@ -119,11 +125,11 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
   // Used For mouse Dragging and resizing graphs
   int graphStretch = -1;
 
-  int graphStretchY = -1;
+  int mouseDragLastX = -1;
 
-  int min; // used by mouseDragged to see if user
+  int mouseDragLastY = -1;
 
-  int max; // used by mouseDragged to see if user
+  DragMode dragMode = DragMode.Undefined;
 
   boolean mouseDragging = false;
 
@@ -499,10 +505,11 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
   }
 
   /**
-   * DOCUMENT ME!
+   * Action on right mouse pressed on Mac is to show a pop-up menu for the
+   * annotation. Action on left mouse pressed is to find which annotation is
+   * pressed and mark the start of a column selection or graph resize operation.
    * 
    * @param evt
-   *          DOCUMENT ME!
    */
   @Override
   public void mousePressed(MouseEvent evt)
@@ -513,7 +520,13 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
     {
       return;
     }
+    mouseDragLastX = evt.getX();
+    mouseDragLastY = evt.getY();
 
+    /*
+     * add visible annotation heights until we reach the y
+     * position, to find which annotation it is in
+     */
     int height = 0;
     activeRow = -1;
 
@@ -533,11 +546,11 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
         }
         else if (aa[i].graph > 0)
         {
-          // Stretch Graph
+          /*
+           * we have clicked on a resizable graph annotation
+           */
           graphStretch = i;
-          graphStretchY = y;
         }
-
         break;
       }
     }
@@ -603,17 +616,20 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
   }
 
   /**
-   * DOCUMENT ME!
+   * Action on mouse up is to clear mouse drag data and call mouseReleased on
+   * ScalePanel, to deal with defining the selection group (if any) defined by
+   * the mouse drag
    * 
    * @param evt
-   *          DOCUMENT ME!
    */
   @Override
   public void mouseReleased(MouseEvent evt)
   {
     graphStretch = -1;
-    graphStretchY = -1;
+    mouseDragLastX = -1;
+    mouseDragLastY = -1;
     mouseDragging = false;
+    dragMode = DragMode.Undefined;
     ap.getScalePanel().mouseReleased(evt);
 
     /*
@@ -660,24 +676,73 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
   @Override
   public void mouseDragged(MouseEvent evt)
   {
-    if (graphStretch > -1)
+    /*
+     * todo: if dragMode is Undefined:
+     * - set to Select if dx > dy
+     * - set to Resize if dy > dx
+     * - do nothing if dx == dy
+     */
+    final int x = evt.getX();
+    final int y = evt.getY();
+    if (dragMode == DragMode.Undefined)
     {
-      av.getAlignment()
-              .getAlignmentAnnotation()[graphStretch].graphHeight += graphStretchY
-                      - evt.getY();
-      if (av.getAlignment()
-              .getAlignmentAnnotation()[graphStretch].graphHeight < 0)
+      int dx = Math.abs(x - mouseDragLastX);
+      int dy = Math.abs(y - mouseDragLastY);
+      if (graphStretch == -1 || dx > dy)
       {
-        av.getAlignment()
-                .getAlignmentAnnotation()[graphStretch].graphHeight = 0;
+        /*
+         * mostly horizontal drag, or not a graph annotation
+         */
+        dragMode = DragMode.Select;
+      }
+      else if (dy > dx)
+      {
+        /*
+         * mostly vertical drag
+         */
+        dragMode = DragMode.Resize;
       }
-      graphStretchY = evt.getY();
-      adjustPanelHeight();
-      ap.paintAlignment(false, false);
     }
-    else
+
+    if (dragMode == DragMode.Undefined)
     {
-      ap.getScalePanel().mouseDragged(evt);
+      /*
+       * drag is diagonal - defer deciding whether to
+       * treat as up/down or left/right
+       */
+      return;
+    }
+
+    try
+    {
+      if (dragMode == DragMode.Resize)
+      {
+        /*
+         * resize graph annotation if mouse was dragged up or down
+         */
+        int deltaY = mouseDragLastY - evt.getY();
+        if (deltaY != 0)
+        {
+          AlignmentAnnotation graphAnnotation = av.getAlignment()
+                  .getAlignmentAnnotation()[graphStretch];
+          int newHeight = Math.max(0, graphAnnotation.graphHeight + deltaY);
+          graphAnnotation.graphHeight = newHeight;
+          adjustPanelHeight();
+          ap.paintAlignment(false, false);
+        }
+      }
+      else
+      {
+        /*
+         * for mouse drag left or right, delegate to 
+         * ScalePanel to adjust the column selection
+         */
+        ap.getScalePanel().mouseDragged(evt);
+      }
+    } finally
+    {
+      mouseDragLastX = x;
+      mouseDragLastY = y;
     }
   }
 
@@ -690,30 +755,10 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
   @Override
   public void mouseMoved(MouseEvent evt)
   {
+    int yPos = evt.getY();
     AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
 
-    if (aa == null)
-    {
-      this.setToolTipText(null);
-      return;
-    }
-
-    int row = -1;
-    int height = 0;
-
-    for (int i = 0; i < aa.length; i++)
-    {
-      if (aa[i].visible)
-      {
-        height += aa[i].height;
-      }
-
-      if (evt.getY() < height)
-      {
-        row = i;
-        break;
-      }
-    }
+    int row = getRowIndex(yPos, aa);
 
     if (row == -1)
     {
@@ -723,6 +768,7 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
 
     int column = (evt.getX() / av.getCharWidth())
             + av.getRanges().getStartRes();
+    column = Math.min(column, av.getRanges().getEndRes());
 
     if (av.hasHiddenColumns())
     {
@@ -734,26 +780,63 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
     if (row > -1 && ann.annotations != null
             && column < ann.annotations.length)
     {
-      buildToolTip(ann, column, aa);
-      setStatusMessage(column, ann);
+      setToolTipText(buildToolTip(ann, column, aa));
+      String msg = getStatusMessage(av.getAlignment(), column, ann);
+      ap.alignFrame.setStatus(msg);
     }
     else
     {
       this.setToolTipText(null);
-      ap.alignFrame.statusBar.setText(" ");
+      ap.alignFrame.setStatus(" ");
+    }
+  }
+
+  /**
+   * Answers the index in the annotations array of the visible annotation at the
+   * given y position. This is done by adding the heights of visible annotations
+   * until the y position has been exceeded. Answers -1 if no annotations are
+   * visible, or the y position is below all annotations.
+   * 
+   * @param yPos
+   * @param aa
+   * @return
+   */
+  static int getRowIndex(int yPos, AlignmentAnnotation[] aa)
+  {
+    if (aa == null)
+    {
+      return -1;
     }
+    int row = -1;
+    int height = 0;
+
+    for (int i = 0; i < aa.length; i++)
+    {
+      if (aa[i].visible)
+      {
+        height += aa[i].height;
+      }
+
+      if (height > yPos)
+      {
+        row = i;
+        break;
+      }
+    }
+    return row;
   }
 
   /**
-   * Builds a tooltip for the annotation at the current mouse position.
+   * Answers a tooltip for the annotation at the current mouse position
    * 
    * @param ann
    * @param column
    * @param anns
    */
-  void buildToolTip(AlignmentAnnotation ann, int column,
+  static String buildToolTip(AlignmentAnnotation ann, int column,
           AlignmentAnnotation[] anns)
   {
+    String tooltip = null;
     if (ann.graphGroup > -1)
     {
       StringBuilder tip = new StringBuilder(32);
@@ -775,35 +858,39 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
       if (tip.length() != 6)
       {
         tip.setLength(tip.length() - 4);
-        this.setToolTipText(tip.toString() + "</html>");
+        tooltip = tip.toString() + "</html>";
       }
     }
-    else if (ann.annotations[column] != null)
+    else if (column < ann.annotations.length
+            && ann.annotations[column] != null)
     {
       String description = ann.annotations[column].description;
       if (description != null && description.length() > 0)
       {
-        this.setToolTipText(JvSwingUtils.wrapTooltip(true, description));
+        tooltip = JvSwingUtils.wrapTooltip(true, description);
       }
       else
       {
-        this.setToolTipText(null); // no tooltip if null or empty description
+        tooltip = null; // no tooltip if null or empty description
       }
     }
     else
     {
       // clear the tooltip.
-      this.setToolTipText(null);
+      tooltip = null;
     }
+    return tooltip;
   }
 
   /**
-   * Constructs and displays the status bar message
+   * Constructs and returns the status bar message
    * 
+   * @param al
    * @param column
    * @param ann
    */
-  void setStatusMessage(int column, AlignmentAnnotation ann)
+  static String getStatusMessage(AlignmentI al, int column,
+          AlignmentAnnotation ann)
   {
     /*
      * show alignment column and annotation description if any
@@ -812,7 +899,7 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
     text.append(MessageManager.getString("label.column")).append(" ")
             .append(column + 1);
 
-    if (ann.annotations[column] != null)
+    if (column < ann.annotations.length && ann.annotations[column] != null)
     {
       String description = ann.annotations[column].description;
       if (description != null && description.trim().length() > 0)
@@ -828,7 +915,7 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
     SequenceI seqref = ann.sequenceRef;
     if (seqref != null)
     {
-      int seqIndex = av.getAlignment().findIndex(seqref);
+      int seqIndex = al.findIndex(seqref);
       if (seqIndex != -1)
       {
         text.append(", ").append(MessageManager.getString("label.sequence"))
@@ -838,7 +925,7 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
         {
           text.append(" ");
           String name;
-          if (av.getAlignment().isNucleotide())
+          if (al.isNucleotide())
           {
             name = ResidueProperties.nucleotideName
                     .get(String.valueOf(residue));
@@ -859,7 +946,7 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
       }
     }
 
-    ap.alignFrame.statusBar.setText(text.toString());
+    return text.toString();
   }
 
   /**
index 183419e..336a312 100644 (file)
@@ -25,6 +25,7 @@ import jalview.analysis.scoremodels.ScoreModels;
 import jalview.analysis.scoremodels.SimilarityParams;
 import jalview.api.analysis.ScoreModelI;
 import jalview.api.analysis.SimilarityParamsI;
+import jalview.bin.Cache;
 import jalview.datamodel.SequenceGroup;
 import jalview.util.MessageManager;
 
@@ -103,7 +104,7 @@ public class CalculationChooser extends JPanel
 
   final ComboBoxTooltipRenderer renderer = new ComboBoxTooltipRenderer();
 
-  List<String> tips = new ArrayList<String>();
+  List<String> tips = new ArrayList<>();
 
   /*
    * the most recently opened PCA results panel
@@ -375,7 +376,7 @@ public class CalculationChooser extends JPanel
    */
   protected JComboBox<String> buildModelOptionsList()
   {
-    final JComboBox<String> scoreModelsCombo = new JComboBox<String>();
+    final JComboBox<String> scoreModelsCombo = new JComboBox<>();
     scoreModelsCombo.setRenderer(renderer);
 
     /*
@@ -418,39 +419,42 @@ public class CalculationChooser extends JPanel
   {
     Object curSel = comboBox.getSelectedItem();
     toolTips.clear();
-    DefaultComboBoxModel<String> model = new DefaultComboBoxModel<String>();
+    DefaultComboBoxModel<String> model = new DefaultComboBoxModel<>();
+
+    /*
+     * select the score models applicable to the alignment type
+     */
+    boolean nucleotide = af.getViewport().getAlignment().isNucleotide();
+    List<ScoreModelI> models = getApplicableScoreModels(nucleotide,
+            pca.isSelected());
 
     /*
      * now we can actually add entries to the combobox,
      * remembering their descriptions for tooltips
      */
-    ScoreModels scoreModels = ScoreModels.getInstance();
     boolean selectedIsPresent = false;
-    for (ScoreModelI sm : scoreModels.getModels())
+    for (ScoreModelI sm : models)
     {
-      boolean nucleotide = af.getViewport().getAlignment().isNucleotide();
-      if (sm.isDNA() && nucleotide || sm.isProtein() && !nucleotide)
+      if (curSel != null && sm.getName().equals(curSel))
+      {
+        selectedIsPresent = true;
+        curSel = sm.getName();
+      }
+      model.addElement(sm.getName());
+
+      /*
+       * tooltip is description if provided, else text lookup with
+       * fallback on the model name
+       */
+      String tooltip = sm.getDescription();
+      if (tooltip == null)
       {
-        if (curSel != null && sm.getName().equals(curSel))
-        {
-          selectedIsPresent = true;
-          curSel = sm.getName();
-        }
-        model.addElement(sm.getName());
-
-        /*
-         * tooltip is description if provided, else text lookup with
-         * fallback on the model name
-         */
-        String tooltip = sm.getDescription();
-        if (tooltip == null)
-        {
-          tooltip = MessageManager.getStringOrReturn("label.score_model_",
-                  sm.getName());
-        }
-        toolTips.add(tooltip);
+        tooltip = MessageManager.getStringOrReturn("label.score_model_",
+                sm.getName());
       }
+      toolTips.add(tooltip);
     }
+
     if (selectedIsPresent)
     {
       model.setSelectedItem(curSel);
@@ -460,6 +464,47 @@ public class CalculationChooser extends JPanel
   }
 
   /**
+   * Builds a list of score models which are applicable for the alignment and
+   * calculation type (peptide or generic models for protein, nucleotide or
+   * generic models for nucleotide).
+   * <p>
+   * As a special case, includes BLOSUM62 as an extra option for nucleotide PCA.
+   * This is for backwards compatibility with Jalview prior to 2.8 when BLOSUM62
+   * was the only score matrix supported. This is included if property
+   * BLOSUM62_PCA_FOR_NUCLEOTIDE is set to true in the Jalview properties file.
+   * 
+   * @param nucleotide
+   * @param forPca
+   * @return
+   */
+  protected static List<ScoreModelI> getApplicableScoreModels(
+          boolean nucleotide, boolean forPca)
+  {
+    List<ScoreModelI> filtered = new ArrayList<>();
+
+    ScoreModels scoreModels = ScoreModels.getInstance();
+    for (ScoreModelI sm : scoreModels.getModels())
+    {
+      if (!nucleotide && sm.isProtein() || nucleotide && sm.isDNA())
+      {
+        filtered.add(sm);
+      }
+    }
+
+    /*
+     * special case: add BLOSUM62 as last option for nucleotide PCA, 
+     * for backwards compatibility with Jalview < 2.8 (JAL-2962)
+     */
+    if (nucleotide && forPca
+            && Cache.getDefault("BLOSUM62_PCA_FOR_NUCLEOTIDE", false))
+    {
+      filtered.add(scoreModels.getBlosum62());
+    }
+
+    return filtered;
+  }
+
+  /**
    * Open and calculate the selected tree or PCA on 'OK'
    */
   protected void calculate_actionPerformed()
@@ -539,7 +584,13 @@ public class CalculationChooser extends JPanel
               JvOptionPane.WARNING_MESSAGE);
       return;
     }
+
+    /*
+     * construct the panel and kick off its calculation thread
+     */
     pcaPanel = new PCAPanel(af.alignPanel, modelName, params);
+    new Thread(pcaPanel).start();
+
   }
 
   /**
index 8f0b88c..9479ea6 100644 (file)
@@ -121,8 +121,7 @@ public class ColourMenuHelper
        */
       final String name = scheme.getSchemeName();
       String label = MessageManager.getStringOrReturn(
-              "label.colourScheme_" + name.toLowerCase().replace(" ", "_"),
-              name);
+              "label.colourScheme_", name.toLowerCase().replace(" ", "_"));
       final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
               label);
       radioItem.setName(name);
index 2a96daf..b3bff0d 100644 (file)
@@ -322,7 +322,7 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer
         af.currentFileFormat = format;
         Desktop.addInternalFrame(af, title, AlignFrame.DEFAULT_WIDTH,
                 AlignFrame.DEFAULT_HEIGHT);
-        af.statusBar.setText(MessageManager
+        af.setStatus(MessageManager
                 .getString("label.successfully_pasted_alignment_file"));
 
         try
index 874c619..d3e87ad 100644 (file)
@@ -24,6 +24,7 @@ import jalview.api.AlignViewportI;
 import jalview.api.AlignmentViewPanel;
 import jalview.bin.Cache;
 import jalview.bin.Jalview;
+import jalview.io.BackupFiles;
 import jalview.io.DataSourceType;
 import jalview.io.FileFormat;
 import jalview.io.FileFormatException;
@@ -1221,7 +1222,7 @@ public class Desktop extends jalview.jbgui.GDesktop
   {
     String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT");
     JalviewFileChooser chooser = JalviewFileChooser
-            .forRead(Cache.getProperty("LAST_DIRECTORY"), fileFormat);
+            .forRead(Cache.getProperty("LAST_DIRECTORY"), fileFormat, true);
 
     chooser.setFileView(new JalviewFileView());
     chooser.setDialogTitle(
@@ -1742,20 +1743,43 @@ public class Desktop extends jalview.jbgui.GDesktop
   @Override
   public void saveState_actionPerformed()
   {
-    JalviewFileChooser chooser = new JalviewFileChooser("jvp",
-            "Jalview Project");
+    saveState_actionPerformed(false);
+  }
 
-    chooser.setFileView(new JalviewFileView());
-    chooser.setDialogTitle(MessageManager.getString("label.save_state"));
+  public void saveState_actionPerformed(boolean saveAs)
+  {
+    java.io.File projectFile = getProjectFile();
+    // autoSave indicates we already have a file and don't need to ask
+    boolean autoSave = projectFile != null && !saveAs
+            && BackupFiles.getEnabled();
 
-    int value = chooser.showSaveDialog(this);
+    // System.out.println("autoSave="+autoSave+", projectFile='"+projectFile+"',
+    // saveAs="+saveAs+", Backups
+    // "+(BackupFiles.getEnabled()?"enabled":"disabled"));
 
-    if (value == JalviewFileChooser.APPROVE_OPTION)
+    boolean approveSave = false;
+    if (!autoSave)
     {
-      final Desktop me = this;
-      final java.io.File choice = chooser.getSelectedFile();
-      setProjectFile(choice);
+      JalviewFileChooser chooser = new JalviewFileChooser("jvp",
+              "Jalview Project");
+
+      chooser.setFileView(new JalviewFileView());
+      chooser.setDialogTitle(MessageManager.getString("label.save_state"));
 
+      int value = chooser.showSaveDialog(this);
+
+      if (value == JalviewFileChooser.APPROVE_OPTION)
+      {
+        projectFile = chooser.getSelectedFile();
+        setProjectFile(projectFile);
+        approveSave = true;
+      }
+    }
+
+    if (approveSave || autoSave)
+    {
+      final Desktop me = this;
+      final java.io.File chosenFile = projectFile;
       new Thread(new Runnable()
       {
         @Override
@@ -1764,38 +1788,47 @@ public class Desktop extends jalview.jbgui.GDesktop
           // TODO: refactor to Jalview desktop session controller action.
           setProgressBar(MessageManager.formatMessage(
                   "label.saving_jalview_project", new Object[]
-                  { choice.getName() }), choice.hashCode());
+                  { chosenFile.getName() }), chosenFile.hashCode());
           jalview.bin.Cache.setProperty("LAST_DIRECTORY",
-                  choice.getParent());
+                  chosenFile.getParent());
           // TODO catch and handle errors for savestate
           // TODO prevent user from messing with the Desktop whilst we're saving
           try
           {
-            new Jalview2XML().saveState(choice);
+            BackupFiles backupfiles = new BackupFiles(chosenFile);
+
+            new Jalview2XML().saveState(backupfiles.getTempFile());
+
+            backupfiles.setWriteSuccess(true);
+            backupfiles.rollBackupsAndRenameTempFile();
           } catch (OutOfMemoryError oom)
           {
-            new OOMWarning(
-                    "Whilst saving current state to " + choice.getName(),
-                    oom);
+            new OOMWarning("Whilst saving current state to "
+                    + chosenFile.getName(), oom);
           } catch (Exception ex)
           {
-            Cache.log.error(
-                    "Problems whilst trying to save to " + choice.getName(),
-                    ex);
+            Cache.log.error("Problems whilst trying to save to "
+                    + chosenFile.getName(), ex);
             JvOptionPane.showMessageDialog(me,
                     MessageManager.formatMessage(
                             "label.error_whilst_saving_current_state_to",
                             new Object[]
-                            { choice.getName() }),
+                            { chosenFile.getName() }),
                     MessageManager.getString("label.couldnt_save_project"),
                     JvOptionPane.WARNING_MESSAGE);
           }
-          setProgressBar(null, choice.hashCode());
+          setProgressBar(null, chosenFile.hashCode());
         }
       }).start();
     }
   }
 
+  @Override
+  public void saveAsState_actionPerformed(ActionEvent e)
+  {
+    saveState_actionPerformed(true);
+  }
+
   private void setProjectFile(File choice)
   {
     this.projectFile = choice;
@@ -1818,7 +1851,8 @@ public class Desktop extends jalview.jbgui.GDesktop
         "Jalview Project (old)" };
     JalviewFileChooser chooser = new JalviewFileChooser(
             Cache.getProperty("LAST_DIRECTORY"), suffix, desc,
-            "Jalview Project");
+            "Jalview Project", true, true); // last two booleans: allFiles,
+                                            // allowBackupFiles
     chooser.setFileView(new JalviewFileView());
     chooser.setDialogTitle(MessageManager.getString("label.restore_state"));
 
index a135785..4526517 100644 (file)
@@ -24,6 +24,7 @@ import jalview.api.FeatureColourI;
 import jalview.api.FeatureSettingsControllerI;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.SequenceI;
+import jalview.datamodel.features.FeatureMatcher;
 import jalview.datamodel.features.FeatureMatcherI;
 import jalview.datamodel.features.FeatureMatcherSet;
 import jalview.datamodel.features.FeatureMatcherSetI;
@@ -79,7 +80,6 @@ import javax.swing.BorderFactory;
 import javax.swing.Icon;
 import javax.swing.JButton;
 import javax.swing.JCheckBox;
-import javax.swing.JCheckBoxMenuItem;
 import javax.swing.JColorChooser;
 import javax.swing.JDialog;
 import javax.swing.JInternalFrame;
@@ -93,9 +93,11 @@ import javax.swing.JSlider;
 import javax.swing.JTable;
 import javax.swing.ListSelectionModel;
 import javax.swing.SwingConstants;
+import javax.swing.border.Border;
 import javax.swing.event.ChangeEvent;
 import javax.swing.event.ChangeListener;
 import javax.swing.table.AbstractTableModel;
+import javax.swing.table.JTableHeader;
 import javax.swing.table.TableCellEditor;
 import javax.swing.table.TableCellRenderer;
 import javax.swing.table.TableColumn;
@@ -128,6 +130,8 @@ public class FeatureSettings extends JPanel
 
   private static final int MIN_HEIGHT = 400;
 
+  private final static String BASE_TOOLTIP = MessageManager.getString("label.click_to_edit");
+
   final FeatureRenderer fr;
 
   public final AlignFrame af;
@@ -158,12 +162,6 @@ public class FeatureSettings extends JPanel
 
   int selectedRow = -1;
 
-  JButton fetchDAS = new JButton();
-
-  JButton saveDAS = new JButton();
-
-  JButton cancelDAS = new JButton();
-
   boolean resettingTable = false;
 
   /*
@@ -208,32 +206,54 @@ public class FeatureSettings extends JPanel
       {
         String tip = null;
         int column = table.columnAtPoint(e.getPoint());
+        int row = table.rowAtPoint(e.getPoint());
+
         switch (column)
         {
         case TYPE_COLUMN:
           tip = JvSwingUtils.wrapTooltip(true, MessageManager
                   .getString("label.feature_settings_click_drag"));
           break;
+        case COLOUR_COLUMN:
+          FeatureColourI colour = (FeatureColourI) table.getValueAt(row,
+                  column);
+          tip = getColorTooltip(colour, true);
+          break;
         case FILTER_COLUMN:
-          int row = table.rowAtPoint(e.getPoint());
           FeatureMatcherSet o = (FeatureMatcherSet) table.getValueAt(row,
                   column);
           tip = o.isEmpty()
-                  ? MessageManager.getString("label.filters_tooltip")
+                  ? MessageManager
+                          .getString("label.configure_feature_tooltip")
                   : o.toString();
           break;
         default:
           break;
         }
+        
         return tip;
       }
+
+      /**
+       * Position the tooltip near the bottom edge of, and half way across, the
+       * current cell
+       */
+      @Override
+      public Point getToolTipLocation(MouseEvent e)
+      {
+        Point point = e.getPoint();
+        int column = table.columnAtPoint(point);
+        int row = table.rowAtPoint(point);
+        Rectangle r = getCellRect(row, column, false);
+        Point loc = new Point(r.x + r.width / 2, r.y + r.height - 3);
+        return loc;
+      }
     };
-    table.getTableHeader().setFont(new Font("Verdana", Font.PLAIN, 12));
+    JTableHeader tableHeader = table.getTableHeader();
+    tableHeader.setFont(new Font("Verdana", Font.PLAIN, 12));
+    tableHeader.setReorderingAllowed(false);
     table.setFont(new Font("Verdana", Font.PLAIN, 12));
 
-    // table.setDefaultRenderer(Color.class, new ColorRenderer());
-    // table.setDefaultEditor(Color.class, new ColorEditor(this));
-    //
     table.setDefaultEditor(FeatureColour.class, new ColorEditor(this));
     table.setDefaultRenderer(FeatureColour.class, new ColorRenderer());
 
@@ -415,69 +435,6 @@ public class FeatureSettings extends JPanel
     });
     men.add(dens);
 
-    /*
-     * variable colour options include colour by label, by score,
-     * by selected attribute text, or attribute value
-     */
-    final JCheckBoxMenuItem mxcol = new JCheckBoxMenuItem(
-            MessageManager.getString("label.variable_colour"));
-    mxcol.setSelected(!featureColour.isSimpleColour());
-    men.add(mxcol);
-    mxcol.addActionListener(new ActionListener()
-    {
-      JColorChooser colorChooser;
-
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        if (e.getSource() == mxcol)
-        {
-          if (featureColour.isSimpleColour())
-          {
-            FeatureTypeSettings fc = new FeatureTypeSettings(me.fr, type);
-            fc.addActionListener(this);
-          }
-          else
-          {
-            // bring up simple color chooser
-            colorChooser = new JColorChooser();
-            String title = MessageManager
-                    .getString("label.select_colour");
-            JDialog dialog = JColorChooser.createDialog(me,
-                    title, true, // modal
-                    colorChooser, this, // OK button handler
-                    null); // no CANCEL button handler
-            colorChooser.setColor(featureColour.getMaxColour());
-            dialog.setVisible(true);
-          }
-        }
-        else
-        {
-          if (e.getSource() instanceof FeatureTypeSettings)
-          {
-            /*
-             * update after OK in feature colour dialog; the updated
-             * colour will have already been set in the FeatureRenderer
-             */
-            FeatureColourI fci = fr.getFeatureColours().get(type);
-            table.setValueAt(fci, rowSelected, 1);
-            table.validate();
-          }
-          else
-          {
-            // probably the color chooser!
-            table.setValueAt(new FeatureColour(colorChooser.getColor()),
-                    rowSelected, 1);
-            table.validate();
-            me.updateFeatureRenderer(
-                    ((FeatureTableModel) table.getModel()).getData(),
-                    false);
-          }
-        }
-      }
-
-    });
-
     JMenuItem selCols = new JMenuItem(
             MessageManager.getString("label.select_columns_containing"));
     selCols.addActionListener(new ActionListener()
@@ -1237,22 +1194,6 @@ public class FeatureSettings extends JPanel
         }
       }
     });
-    help.setFont(JvSwingUtils.getLabelFont());
-    help.setText(MessageManager.getString("action.help"));
-    help.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        try
-        {
-          Help.showHelpWindow(HelpId.SequenceFeatureSettings);
-        } catch (HelpSetException e1)
-        {
-          e1.printStackTrace();
-        }
-      }
-    });
 
     JButton cancel = new JButton(MessageManager.getString("action.cancel"));
     cancel.setFont(JvSwingUtils.getLabelFont());
@@ -1346,6 +1287,90 @@ public class FeatureSettings extends JPanel
     this.add(settingsPane);
   }
 
+  /**
+   * Answers a suitable tooltip to show on the colour cell of the table
+   * 
+   * @param fcol
+   * @param withHint
+   *          if true include 'click to edit' and similar text
+   * @return
+   */
+  public static String getColorTooltip(FeatureColourI fcol,
+          boolean withHint)
+  {
+    if (fcol == null)
+    {
+      return null;
+    }
+    if (fcol.isSimpleColour())
+    {
+      return withHint ? BASE_TOOLTIP : null;
+    }
+    String description = fcol.getDescription();
+    description = description.replaceAll("<", "&lt;");
+    description = description.replaceAll(">", "&gt;");
+    StringBuilder tt = new StringBuilder(description);
+    if (withHint)
+    {
+      tt.append("<br>").append(BASE_TOOLTIP).append("</br>");
+    }
+    return JvSwingUtils.wrapTooltip(true, tt.toString());
+  }
+
+  public static void renderGraduatedColor(JLabel comp, FeatureColourI gcol,
+          int w, int h)
+  {
+    boolean thr = false;
+    StringBuilder tx = new StringBuilder();
+  
+    if (gcol.isColourByAttribute())
+    {
+      tx.append(FeatureMatcher
+              .toAttributeDisplayName(gcol.getAttributeName()));
+    }
+    else if (!gcol.isColourByLabel())
+    {
+      tx.append(MessageManager.getString("label.score"));
+    }
+    tx.append(" ");
+    if (gcol.isAboveThreshold())
+    {
+      thr = true;
+      tx.append(">");
+    }
+    if (gcol.isBelowThreshold())
+    {
+      thr = true;
+      tx.append("<");
+    }
+    if (gcol.isColourByLabel())
+    {
+      if (thr)
+      {
+        tx.append(" ");
+      }
+      if (!gcol.isColourByAttribute())
+      {
+        tx.append("Label");
+      }
+      comp.setIcon(null);
+    }
+    else
+    {
+      Color newColor = gcol.getMaxColour();
+      comp.setBackground(newColor);
+      // System.err.println("Width is " + w / 2);
+      Icon ficon = new FeatureIcon(gcol, comp.getBackground(), w, h, thr);
+      comp.setIcon(ficon);
+      // tt+="RGB value: Max (" + newColor.getRed() + ", "
+      // + newColor.getGreen() + ", " + newColor.getBlue()
+      // + ")\nMin (" + minCol.getRed() + ", " + minCol.getGreen()
+      // + ", " + minCol.getBlue() + ")");
+    }
+    comp.setHorizontalAlignment(SwingConstants.CENTER);
+    comp.setText(tx.toString());
+  }
+
   // ///////////////////////////////////////////////////////////////////////
   // http://java.sun.com/docs/books/tutorial/uiswing/components/table.html
   // ///////////////////////////////////////////////////////////////////////
@@ -1354,7 +1379,7 @@ public class FeatureSettings extends JPanel
     private String[] columnNames = {
         MessageManager.getString("label.feature_type"),
         MessageManager.getString("action.colour"),
-        MessageManager.getString("label.filter"),
+        MessageManager.getString("label.configuration"),
         MessageManager.getString("label.show") };
 
     private Object[][] data;
@@ -1431,11 +1456,9 @@ public class FeatureSettings extends JPanel
 
   class ColorRenderer extends JLabel implements TableCellRenderer
   {
-    javax.swing.border.Border unselectedBorder = null;
+    Border unselectedBorder = null;
 
-    javax.swing.border.Border selectedBorder = null;
-
-    final String baseTT = "Click to edit, right/apple click for menu.";
+    Border selectedBorder = null;
 
     public ColorRenderer()
     {
@@ -1450,7 +1473,6 @@ public class FeatureSettings extends JPanel
     {
       FeatureColourI cellColour = (FeatureColourI) color;
       setOpaque(true);
-      setToolTipText(baseTT);
       setBackground(tbl.getBackground());
       if (!cellColour.isSimpleColour())
       {
@@ -1557,77 +1579,6 @@ public class FeatureSettings extends JPanel
     renderGraduatedColor(comp, gcol, w, h);
   }
 
-  public static void renderGraduatedColor(JLabel comp, FeatureColourI gcol,
-          int w, int h)
-  {
-    boolean thr = false;
-    StringBuilder tt = new StringBuilder();
-    StringBuilder tx = new StringBuilder();
-
-    if (gcol.isColourByAttribute())
-    {
-      tx.append(String.join(":", gcol.getAttributeName()));
-    }
-    else if (!gcol.isColourByLabel())
-    {
-      tx.append(MessageManager.getString("label.score"));
-    }
-    tx.append(" ");
-    if (gcol.isAboveThreshold())
-    {
-      thr = true;
-      tx.append(">");
-      tt.append("Thresholded (Above ").append(gcol.getThreshold())
-              .append(") ");
-    }
-    if (gcol.isBelowThreshold())
-    {
-      thr = true;
-      tx.append("<");
-      tt.append("Thresholded (Below ").append(gcol.getThreshold())
-              .append(") ");
-    }
-    if (gcol.isColourByLabel())
-    {
-      tt.append("Coloured by label text. ").append(tt);
-      if (thr)
-      {
-        tx.append(" ");
-      }
-      if (!gcol.isColourByAttribute())
-      {
-        tx.append("Label");
-      }
-      comp.setIcon(null);
-    }
-    else
-    {
-      Color newColor = gcol.getMaxColour();
-      comp.setBackground(newColor);
-      // System.err.println("Width is " + w / 2);
-      Icon ficon = new FeatureIcon(gcol, comp.getBackground(), w, h, thr);
-      comp.setIcon(ficon);
-      // tt+="RGB value: Max (" + newColor.getRed() + ", "
-      // + newColor.getGreen() + ", " + newColor.getBlue()
-      // + ")\nMin (" + minCol.getRed() + ", " + minCol.getGreen()
-      // + ", " + minCol.getBlue() + ")");
-    }
-    comp.setHorizontalAlignment(SwingConstants.CENTER);
-    comp.setText(tx.toString());
-    if (tt.length() > 0)
-    {
-      if (comp.getToolTipText() == null)
-      {
-        comp.setToolTipText(tt.toString());
-      }
-      else
-      {
-        comp.setToolTipText(
-                tt.append(" ").append(comp.getToolTipText()).toString());
-      }
-    }
-  }
-
   class ColorEditor extends AbstractCellEditor
           implements TableCellEditor, ActionListener
   {
@@ -1863,7 +1814,6 @@ public class FeatureSettings extends JPanel
       button.setOpaque(true);
       button.setBackground(me.getBackground());
       button.setText(currentFilter.toString());
-      button.setToolTipText(currentFilter.toString());
       button.setIcon(null);
       return button;
     }
index 55bc519..82e826f 100644 (file)
@@ -242,8 +242,7 @@ public class FeatureTypeSettings extends JalviewDialog
     String title = MessageManager
             .formatMessage("label.display_settings_for", new String[]
             { theType });
-    initDialogFrame(this, true, false, title, 500, 500);
-    
+    initDialogFrame(this, true, false, title, 580, 500);
     waitForInput();
   }
 
@@ -366,7 +365,7 @@ public class FeatureTypeSettings extends JalviewDialog
                         : BELOW_THRESHOLD_OPTION);
         slider.setEnabled(true);
         slider.setValue((int) (fc.getThreshold() * scaleFactor));
-        thresholdValue.setText(String.valueOf(getRoundedSliderValue()));
+        thresholdValue.setText(String.valueOf(fc.getThreshold()));
         thresholdValue.setEnabled(true);
         thresholdIsMin.setEnabled(true);
       }
@@ -563,13 +562,20 @@ public class FeatureTypeSettings extends JalviewDialog
     maxColour.setBorder(new LineBorder(Color.black));
 
     /*
-     * default max colour to last plain colour;
-     * make min colour a pale version of max colour
+     * if not set, default max colour to last plain colour,
+     * and make min colour a pale version of max colour
      */
-    FeatureColourI fc = fr.getFeatureColours().get(featureType);
-    Color bg = fc.getColour() == null ? Color.BLACK : fc.getColour();
-    maxColour.setBackground(bg);
-    minColour.setBackground(ColorUtils.bleachColour(bg, 0.9f));
+    Color max = originalColour.getMaxColour();
+    if (max == null)
+    {
+      max = originalColour.getColour();
+      minColour.setBackground(ColorUtils.bleachColour(max, 0.9f));
+    }
+    else
+    {
+      maxColour.setBackground(max);
+      minColour.setBackground(originalColour.getMinColour());
+    }
 
     noValueCombo = new JComboBox<>();
     noValueCombo.addItem(MessageManager.getString("label.no_colour"));
@@ -652,6 +658,7 @@ public class FeatureTypeSettings extends JalviewDialog
         {
           thresholdValue
                   .setText(String.valueOf(slider.getValue() / scaleFactor));
+          thresholdValue.setBackground(Color.white); // to reset red for invalid
           sliderValueChanged();
         }
       }
@@ -747,16 +754,16 @@ public class FeatureTypeSettings extends JalviewDialog
     singleColour.setFont(JvSwingUtils.getLabelFont());
     singleColour.setBorder(BorderFactory.createLineBorder(Color.black));
     singleColour.setPreferredSize(new Dimension(40, 20));
-    if (originalColour.isGraduatedColour())
-    {
-      singleColour.setBackground(originalColour.getMaxColour());
-      singleColour.setForeground(originalColour.getMaxColour());
-    }
-    else
-    {
+    // if (originalColour.isGraduatedColour())
+    // {
+    // singleColour.setBackground(originalColour.getMaxColour());
+    // singleColour.setForeground(originalColour.getMaxColour());
+    // }
+    // else
+    // {
       singleColour.setBackground(originalColour.getColour());
       singleColour.setForeground(originalColour.getColour());
-    }
+    // }
     singleColour.addMouseListener(new MouseAdapter()
     {
       @Override
@@ -881,42 +888,9 @@ public class FeatureTypeSettings extends JalviewDialog
   private FeatureColourI makeColourFromInputs()
   {
     /*
-     * easiest case - a single colour
-     */
-    if (simpleColour.isSelected())
-    {
-      return new FeatureColour(singleColour.getBackground());
-    }
-
-    /*
-     * next easiest case - colour by Label, or attribute text
-     */
-    if (byCategory.isSelected())
-    {
-      Color c = singleColour.getBackground();
-      FeatureColourI fc = new FeatureColour(c);
-      fc.setColourByLabel(true);
-      String byWhat = (String) colourByTextCombo.getSelectedItem();
-      if (!LABEL_18N.equals(byWhat))
-      {
-        fc.setAttributeName(
-                FeatureMatcher.fromAttributeDisplayName(byWhat));
-      }
-      return fc;
-    }
-
-    /*
-     * remaining case - graduated colour by score, or attribute value
+     * min-max range is to (or from) threshold value if 
+     * 'threshold is min/max' is selected 
      */
-    Color noColour = null;
-    if (noValueCombo.getSelectedIndex() == MIN_COLOUR_OPTION)
-    {
-      noColour = minColour.getBackground();
-    }
-    else if (noValueCombo.getSelectedIndex() == MAX_COLOUR_OPTION)
-    {
-      noColour = maxColour.getBackground();
-    }
 
     float thresh = 0f;
     try
@@ -926,11 +900,6 @@ public class FeatureTypeSettings extends JalviewDialog
     {
       // invalid inputs are already handled on entry
     }
-
-    /*
-     * min-max range is to (or from) threshold value if 
-     * 'threshold is min/max' is selected 
-     */
     float minValue = min;
     float maxValue = max;
     final int thresholdOption = threshold.getSelectedIndex();
@@ -944,14 +913,50 @@ public class FeatureTypeSettings extends JalviewDialog
     {
       maxValue = thresh;
     }
+    Color noColour = null;
+    if (noValueCombo.getSelectedIndex() == MIN_COLOUR_OPTION)
+    {
+      noColour = minColour.getBackground();
+    }
+    else if (noValueCombo.getSelectedIndex() == MAX_COLOUR_OPTION)
+    {
+      noColour = maxColour.getBackground();
+    }
 
     /*
-     * make the graduated colour
+     * construct a colour that 'remembers' all the options, including
+     * those not currently selected
      */
-    FeatureColourI fc = new FeatureColour(minColour.getBackground(),
-            maxColour.getBackground(), noColour, minValue, maxValue);
+    FeatureColourI fc = new FeatureColour(singleColour.getBackground(),
+            minColour.getBackground(), maxColour.getBackground(), noColour,
+            minValue, maxValue);
 
     /*
+     * easiest case - a single colour
+     */
+    if (simpleColour.isSelected())
+    {
+      ((FeatureColour) fc).setGraduatedColour(false);
+      return fc;
+    }
+
+    /*
+     * next easiest case - colour by Label, or attribute text
+     */
+    if (byCategory.isSelected())
+    {
+      fc.setColourByLabel(true);
+      String byWhat = (String) colourByTextCombo.getSelectedItem();
+      if (!LABEL_18N.equals(byWhat))
+      {
+        fc.setAttributeName(
+                FeatureMatcher.fromAttributeDisplayName(byWhat));
+      }
+      return fc;
+    }
+
+    /*
+     * remaining case - graduated colour by score, or attribute value;
      * set attribute to colour by if selected
      */
     String byWhat = (String) colourByRangeCombo.getSelectedItem();
@@ -1019,21 +1024,23 @@ public class FeatureTypeSettings extends JalviewDialog
   {
     try
     {
+      /*
+       * set 'adjusting' flag while moving the slider, so it 
+       * doesn't then in turn change the value (with rounding)
+       */
       adjusting = true;
       float f = Float.parseFloat(thresholdValue.getText());
+      f = Float.max(f,  this.min);
+      f = Float.min(f, this.max);
+      thresholdValue.setText(String.valueOf(f));
       slider.setValue((int) (f * scaleFactor));
       threshline.value = f;
       thresholdValue.setBackground(Color.white); // ok
-
-      /*
-       * force repaint of any Overview window or structure
-       */
-      ap.paintAlignment(true, true);
+      adjusting = false;
+      colourChanged(true);
     } catch (NumberFormatException ex)
     {
       thresholdValue.setBackground(Color.red); // not ok
-    } finally
-    {
       adjusting = false;
     }
   }
index 84540f4..a4d7ad0 100755 (executable)
@@ -20,6 +20,8 @@
  */
 package jalview.gui;
 
+import jalview.api.AlignViewportI;
+import jalview.api.FinderI;
 import jalview.datamodel.SearchResultMatchI;
 import jalview.datamodel.SearchResultsI;
 import jalview.datamodel.SequenceFeature;
@@ -32,8 +34,9 @@ import java.awt.Dimension;
 import java.awt.event.ActionEvent;
 import java.awt.event.KeyEvent;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
-import java.util.Vector;
+import java.util.Map;
 import java.util.regex.Pattern;
 import java.util.regex.PatternSyntaxException;
 
@@ -42,6 +45,7 @@ import javax.swing.JComponent;
 import javax.swing.JInternalFrame;
 import javax.swing.JLayeredPane;
 import javax.swing.KeyStroke;
+import javax.swing.event.InternalFrameAdapter;
 import javax.swing.event.InternalFrameEvent;
 
 /**
@@ -57,33 +61,39 @@ import javax.swing.event.InternalFrameEvent;
  */
 public class Finder extends GFinder
 {
-  private static final int MY_HEIGHT = 120;
+  private static final int MIN_WIDTH = 350;
 
-  private static final int MY_WIDTH = 400;
+  private static final int MIN_HEIGHT = 120;
 
-  AlignmentViewport av;
+  private static final int MY_HEIGHT = 120;
 
-  AlignmentPanel ap;
+  private static final int MY_WIDTH = 400;
 
-  private static final int MIN_WIDTH = 350;
+  private AlignViewportI av;
 
-  private static final int MIN_HEIGHT = 120;
+  private AlignmentPanel ap;
 
-  JInternalFrame frame;
+  private JInternalFrame frame;
 
-  int seqIndex = 0;
+  /*
+   * Finder agent per viewport searched
+   */
+  private Map<AlignViewportI, FinderI> finders;
 
-  int resIndex = -1;
+  private SearchResultsI searchResults;
 
-  SearchResultsI searchResults;
+  /*
+   * true if we only search a given alignment view
+   */
+  private boolean focusfixed;
 
   /**
-   * Creates a new Finder object with no associated viewport or panel.
+   * Creates a new Finder object with no associated viewport or panel. Each Find
+   * or Find Next action will act on whichever viewport has focus at the time.
    */
   public Finder()
   {
     this(null, null);
-    focusfixed = false;
   }
 
   /**
@@ -97,12 +107,13 @@ public class Finder extends GFinder
   {
     av = viewport;
     ap = alignPanel;
-    focusfixed = true;
+    finders = new HashMap<>();
+    focusfixed = viewport != null;
     frame = new JInternalFrame();
     frame.setContentPane(this);
     frame.setLayer(JLayeredPane.PALETTE_LAYER);
     frame.addInternalFrameListener(
-            new javax.swing.event.InternalFrameAdapter()
+            new InternalFrameAdapter()
             {
               @Override
               public void internalFrameClosing(InternalFrameEvent e)
@@ -135,12 +146,10 @@ public class Finder extends GFinder
   }
 
   /**
-   * Performs the 'Find Next' action.
-   * 
-   * @param e
+   * Performs the 'Find Next' action on the alignment panel with focus
    */
   @Override
-  public void findNext_actionPerformed(ActionEvent e)
+  public void findNext_actionPerformed()
   {
     if (getFocusedViewport())
     {
@@ -149,27 +158,18 @@ public class Finder extends GFinder
   }
 
   /**
-   * Performs the 'Find All' action.
-   * 
-   * @param e
+   * Performs the 'Find All' action on the alignment panel with focus
    */
   @Override
-  public void findAll_actionPerformed(ActionEvent e)
+  public void findAll_actionPerformed()
   {
     if (getFocusedViewport())
     {
-      resIndex = -1;
-      seqIndex = 0;
       doSearch(true);
     }
   }
 
   /**
-   * do we only search a given alignment view ?
-   */
-  private boolean focusfixed;
-
-  /**
    * if !focusfixed and not in a desktop environment, checks that av and ap are
    * valid. Otherwise, gets the topmost alignment window and sets av and ap
    * accordingly
@@ -193,7 +193,8 @@ public class Finder extends GFinder
     for (int f = 0; f < frames.length; f++)
     {
       JInternalFrame alignFrame = frames[f];
-      if (alignFrame != null && alignFrame instanceof AlignFrame)
+      if (alignFrame != null && alignFrame instanceof AlignFrame
+              && !alignFrame.isIcon())
       {
         av = ((AlignFrame) alignFrame).viewport;
         ap = ((AlignFrame) alignFrame).alignPanel;
@@ -210,8 +211,8 @@ public class Finder extends GFinder
   @Override
   public void createFeatures_actionPerformed()
   {
-    List<SequenceI> seqs = new ArrayList<SequenceI>();
-    List<SequenceFeature> features = new ArrayList<SequenceFeature>();
+    List<SequenceI> seqs = new ArrayList<>();
+    List<SequenceFeature> features = new ArrayList<>();
 
     String searchString = searchBox.getEditor().getItem().toString().trim();
     String desc = "Search Results";
@@ -261,55 +262,48 @@ public class Finder extends GFinder
     // other stuff
     // TODO: add switches to control what is searched - sequences, IDS,
     // descriptions, features
-    jalview.analysis.Finder finder = new jalview.analysis.Finder(
-            av.getAlignment(), av.getSelectionGroup(), seqIndex, resIndex);
-    finder.setCaseSensitive(caseSensitive.isSelected());
-    finder.setIncludeDescription(searchDescription.isSelected());
-
-    finder.setFindAll(doFindAll);
-
-    finder.find(searchString); // returns true if anything was actually found
-
-    seqIndex = finder.getSeqIndex();
-    resIndex = finder.getResIndex();
+    FinderI finder = finders.get(av);
+    if (finder == null)
+    {
+      /*
+       * first time we've searched this viewport
+       */
+      finder = new jalview.analysis.Finder(av);
+      finders.put(av, finder);
+    }
 
-    searchResults = finder.getSearchResults(); // find(regex,
-    // caseSensitive.isSelected(), )
-    Vector<SequenceI> idMatch = finder.getIdMatch();
-    boolean haveResults = false;
-    // set or reset the GUI
-    if ((idMatch.size() > 0))
+    boolean isCaseSensitive = caseSensitive.isSelected();
+    boolean doSearchDescription = searchDescription.isSelected();
+    if (doFindAll)
     {
-      haveResults = true;
-      ap.getIdPanel().highlightSearchResults(idMatch);
+      finder.findAll(searchString, isCaseSensitive, doSearchDescription);
     }
     else
     {
-      ap.getIdPanel().highlightSearchResults(null);
+      finder.findNext(searchString, isCaseSensitive, doSearchDescription);
     }
 
-    if (searchResults.getSize() > 0)
+    searchResults = finder.getSearchResults();
+    List<SequenceI> idMatch = finder.getIdMatches();
+    ap.getIdPanel().highlightSearchResults(idMatch);
+
+    if (searchResults.isEmpty())
     {
-      haveResults = true;
-      createFeatures.setEnabled(true);
+      searchResults = null;
     }
     else
     {
-      searchResults = null;
+      createFeatures.setEnabled(true);
     }
 
-    // if allResults is null, this effectively switches displaySearch flag in
-    // seqCanvas
     ap.highlightSearchResults(searchResults);
     // TODO: add enablers for 'SelectSequences' or 'SelectColumns' or
     // 'SelectRegion' selection
-    if (!haveResults)
+    if (idMatch.isEmpty() && searchResults == null)
     {
       JvOptionPane.showInternalMessageDialog(this,
               MessageManager.getString("label.finished_searching"), null,
               JvOptionPane.INFORMATION_MESSAGE);
-      resIndex = -1;
-      seqIndex = 0;
     }
     else
     {
@@ -329,8 +323,6 @@ public class Finder extends GFinder
         }
         JvOptionPane.showInternalMessageDialog(this, message, null,
                 JvOptionPane.INFORMATION_MESSAGE);
-        resIndex = -1;
-        seqIndex = 0;
       }
     }
     searchBox.updateCache();
index f2d8113..810fc92 100644 (file)
@@ -20,6 +20,7 @@
  */
 package jalview.gui;
 
+import java.awt.Point;
 import java.net.URL;
 
 import javax.help.BadIDException;
@@ -28,17 +29,17 @@ import javax.help.HelpSet;
 import javax.help.HelpSetException;
 
 /**
- * Utility class to show the help documentation window.
+ * Utility class to show the help documentation window
  * 
  * @author gmcarstairs
- *
  */
 public class Help
 {
   public enum HelpId
   {
     Home("home"), SequenceFeatureSettings("seqfeatures.settings"),
-    StructureViewer("viewingpdbs");
+    StructureViewer("viewingpdbs"), PdbFts("pdbfts"),
+    UniprotFts("uniprotfts");
 
     private String id;
 
@@ -54,9 +55,7 @@ public class Help
     }
   }
 
-  private static final long HALF_A_MO = 500; // half a second
-
-  private static long lastOpenedTime = 0L;
+  private static HelpBroker hb;
 
   /**
    * Not instantiable
@@ -67,42 +66,50 @@ public class Help
   }
 
   /**
-   * Show help text in a new window. But do nothing if within half a second of
-   * the last invocation.
-   * 
-   * This is a workaround for issue JAL-914 - both Desktop and AlignFrame
-   * responding to F1 key, resulting in duplicate help windows opened.
+   * Shows the help window, at the entry specified by the given helpId
    * 
    * @param id
-   *          TODO
    * 
    * @throws HelpSetException
    */
   public static void showHelpWindow(HelpId id) throws HelpSetException
   {
-    long timeNow = System.currentTimeMillis();
+    ClassLoader cl = Desktop.class.getClassLoader();
+    URL url = HelpSet.findHelpSet(cl, "help/help"); // $NON-NLS-$
+    HelpSet hs = new HelpSet(cl, url);
 
-    if (timeNow - lastOpenedTime > HALF_A_MO)
+    if (hb == null)
     {
-      lastOpenedTime = timeNow;
-      ClassLoader cl = Desktop.class.getClassLoader();
-      URL url = HelpSet.findHelpSet(cl, "help/help"); // $NON-NLS-$
-      HelpSet hs = new HelpSet(cl, url);
+      /*
+       * create help broker first time (only)
+       */
+      hb = hs.createHelpBroker();
+    }
 
-      HelpBroker hb = hs.createHelpBroker();
-      try
-      {
-        hb.setCurrentID(id.toString());
-      } catch (BadIDException bad)
-      {
-        System.out.println("Bad help link: " + id.toString()
-                + ": must match a target in help.jhm");
-        throw bad;
-      }
-      hb.setDisplayed(true);
+    try
+    {
+      hb.setCurrentID(id.toString());
+    } catch (BadIDException bad)
+    {
+      System.out.println("Bad help link: " + id.toString()
+              + ": must match a target in help.jhm");
+      throw bad;
     }
+
+    /*
+     * set Help visible - at its current location if it is already shown,
+     * else at a location as determined by the window manager
+     */
+    Point p = hb.getLocation();
+    hb.setLocation(p);
+    hb.setDisplayed(true);
   }
 
+  /**
+   * Show the Help window at the root entry
+   * 
+   * @throws HelpSetException
+   */
   public static void showHelpWindow() throws HelpSetException
   {
     showHelpWindow(HelpId.Home);
index cf88c90..951db78 100755 (executable)
@@ -380,12 +380,6 @@ public class IdCanvas extends JPanel implements ViewportListenerI
     int alignmentWidth = alignViewport.getAlignment().getWidth();
     final int alheight = alignViewport.getAlignment().getHeight();
 
-    if (alignViewport.hasHiddenColumns())
-    {
-      alignmentWidth = alignViewport.getAlignment().getHiddenColumns()
-              .absoluteToVisibleColumn(alignmentWidth) - 1;
-    }
-
     int annotationHeight = 0;
 
     AnnotationLabels labels = null;
index a183144..d11d7a1 100755 (executable)
  */
 package jalview.gui;
 
+import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceFeature;
 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.MouseEvent;
@@ -38,6 +41,7 @@ import java.awt.event.MouseWheelListener;
 import java.util.List;
 
 import javax.swing.JPanel;
+import javax.swing.JPopupMenu;
 import javax.swing.SwingUtilities;
 import javax.swing.ToolTipManager;
 
@@ -92,25 +96,46 @@ public class IdPanel extends JPanel
   }
 
   /**
-   * Respond to mouse movement by constructing tooltip text for the sequence id
-   * under the mouse.
+   * Responds to mouse movement by setting tooltip text for the sequence id
+   * under the mouse (or possibly annotation label, when in wrapped mode)
    * 
    * @param e
-   *          DOCUMENT ME!
    */
   @Override
   public void mouseMoved(MouseEvent e)
   {
     SeqPanel sp = alignPanel.getSeqPanel();
-    int seq = Math.max(0, sp.findSeq(e));
-    if (seq > -1 && seq < av.getAlignment().getHeight())
+    MousePos pos = sp.findMousePosition(e);
+    if (pos.isOverAnnotation())
+    {
+      /*
+       * mouse is over an annotation label in wrapped mode
+       */
+      AlignmentAnnotation[] anns = av.getAlignment()
+              .getAlignmentAnnotation();
+      AlignmentAnnotation annotation = anns[pos.annotationIndex];
+      setToolTipText(AnnotationLabels.getTooltip(annotation));
+      alignPanel.alignFrame.setStatus(
+              AnnotationLabels.getStatusMessage(annotation, anns));
+    }
+    else
     {
-      SequenceI sequence = av.getAlignment().getSequenceAt(seq);
-      StringBuilder tip = new StringBuilder(64);
-      seqAnnotReport.createTooltipAnnotationReport(tip, sequence,
-              av.isShowDBRefs(), av.isShowNPFeats(), sp.seqCanvas.fr);
-      setToolTipText(JvSwingUtils.wrapTooltip(true,
-              sequence.getDisplayId(true) + " " + tip.toString()));
+      int seq = Math.max(0, pos.seqIndex);
+      if (seq < av.getAlignment().getHeight())
+      {
+        SequenceI sequence = av.getAlignment().getSequenceAt(seq);
+        StringBuilder tip = new StringBuilder(64);
+        tip.append(sequence.getDisplayId(true)).append(" ");
+        seqAnnotReport.createTooltipAnnotationReport(tip, sequence,
+                av.isShowDBRefs(), av.isShowNPFeats(), sp.seqCanvas.fr);
+        setToolTipText(JvSwingUtils.wrapTooltip(true, tip.toString()));
+
+        StringBuilder text = new StringBuilder();
+        text.append("Sequence ").append(String.valueOf(seq + 1))
+                .append(" ID: ")
+                .append(sequence.getName());
+        alignPanel.alignFrame.setStatus(text.toString());
+      }
     }
   }
 
@@ -125,7 +150,14 @@ public class IdPanel extends JPanel
   {
     mouseDragging = true;
 
-    int seq = Math.max(0, alignPanel.getSeqPanel().findSeq(e));
+    MousePos pos = alignPanel.getSeqPanel().findMousePosition(e);
+    if (pos.isOverAnnotation())
+    {
+      // mouse is over annotation label in wrapped mode
+      return;
+    }
+
+    int seq = Math.max(0, pos.seqIndex);
 
     if (seq < lastid)
     {
@@ -196,7 +228,13 @@ public class IdPanel extends JPanel
       return;
     }
 
-    int seq = alignPanel.getSeqPanel().findSeq(e);
+    MousePos pos = alignPanel.getSeqPanel().findMousePosition(e);
+    int seq = pos.seqIndex;
+    if (pos.isOverAnnotation() || seq < 0)
+    {
+      return;
+    }
+
     String id = av.getAlignment().getSequenceAt(seq).getName();
     String url = Preferences.sequenceUrlLinks.getPrimaryUrl(id);
 
@@ -224,7 +262,7 @@ public class IdPanel extends JPanel
   {
     if (scrollThread != null)
     {
-      scrollThread.running = false;
+      scrollThread.stopScrolling();
     }
   }
 
@@ -276,9 +314,11 @@ public class IdPanel extends JPanel
       return;
     }
 
+    MousePos pos = alignPanel.getSeqPanel().findMousePosition(e);
+    
     if (e.isPopupTrigger()) // Mac reports this in mousePressed
     {
-      showPopupMenu(e);
+      showPopupMenu(e, pos);
       return;
     }
 
@@ -301,14 +341,13 @@ public class IdPanel extends JPanel
       av.getSelectionGroup().setEndRes(av.getAlignment().getWidth() - 1);
     }
 
-    int seq = alignPanel.getSeqPanel().findSeq(e);
     if (e.isShiftDown() && (lastid != -1))
     {
-      selectSeqs(lastid, seq);
+      selectSeqs(lastid, pos.seqIndex);
     }
     else
     {
-      selectSeq(seq);
+      selectSeq(pos.seqIndex);
     }
 
     av.isSelectionGroupChanged(true);
@@ -321,27 +360,33 @@ public class IdPanel extends JPanel
    * 
    * @param e
    */
-  void showPopupMenu(MouseEvent e)
+  void showPopupMenu(MouseEvent e, MousePos pos)
   {
-    int seq2 = alignPanel.getSeqPanel().findSeq(e);
-    Sequence sq = (Sequence) av.getAlignment().getSequenceAt(seq2);
+    if (pos.isOverAnnotation())
+    {
+      showAnnotationMenu(e, pos);
+      return;
+    }
+
+    Sequence sq = (Sequence) av.getAlignment().getSequenceAt(pos.seqIndex);
 
     /*
      *  build a new links menu based on the current links
      *  and any non-positional features
      */
+    List<SequenceFeature> features = null;
+    if (sq != null)
+    {
     List<String> nlinks = Preferences.sequenceUrlLinks.getLinksForMenu();
-    List<SequenceFeature> features = sq.getFeatures().getNonPositionalFeatures();
+      features = sq.getFeatures().getNonPositionalFeatures();
     for (SequenceFeature sf : features)
     {
       if (sf.links != null)
       {
-        for (String link : sf.links)
-        {
-          nlinks.add(link);
-        }
+        nlinks.addAll(sf.links);
       }
     }
+    }
 
     PopupMenu pop = new PopupMenu(alignPanel, sq, features,
             Preferences.getGroupURLLinks());
@@ -349,6 +394,38 @@ public class IdPanel extends JPanel
   }
 
   /**
+   * On right mouse click on a Consensus annotation label, shows a limited popup
+   * menu, with options to configure the consensus calculation and rendering.
+   * 
+   * @param e
+   * @param pos
+   * @see AnnotationLabels#showPopupMenu(MouseEvent)
+   */
+  void showAnnotationMenu(MouseEvent e, MousePos pos)
+  {
+    if (pos.annotationIndex == -1)
+    {
+      return;
+    }
+    AlignmentAnnotation[] anns = this.av.getAlignment()
+            .getAlignmentAnnotation();
+    if (anns == null || pos.annotationIndex >= anns.length)
+    {
+      return;
+    }
+    AlignmentAnnotation ann = anns[pos.annotationIndex];
+    if (!ann.label.contains("Consensus"))
+    {
+      return;
+    }
+
+    JPopupMenu pop = new JPopupMenu(
+            MessageManager.getString("label.annotations"));
+    AnnotationLabels.addConsensusMenuOptions(this.alignPanel, ann, pop);
+    pop.show(this, e.getX(), e.getY());
+  }
+
+  /**
    * Toggle whether the sequence is part of the current selection group.
    * 
    * @param seq
@@ -358,7 +435,7 @@ public class IdPanel extends JPanel
     lastid = seq;
 
     SequenceI pickedSeq = av.getAlignment().getSequenceAt(seq);
-    av.getSelectionGroup().addOrRemove(pickedSeq, true);
+    av.getSelectionGroup().addOrRemove(pickedSeq, false);
   }
 
   /**
@@ -393,7 +470,7 @@ public class IdPanel extends JPanel
     for (int i = start; i <= end; i++)
     {
       av.getSelectionGroup().addSequence(av.getAlignment().getSequenceAt(i),
-              i == end);
+              false);
     }
   }
 
@@ -408,8 +485,9 @@ public class IdPanel extends JPanel
   {
     if (scrollThread != null)
     {
-      scrollThread.running = false;
+      scrollThread.stopScrolling();
     }
+    MousePos pos = alignPanel.getSeqPanel().findMousePosition(e);
 
     mouseDragging = false;
     PaintRefresher.Refresh(this, av.getSequenceSetId());
@@ -418,7 +496,7 @@ public class IdPanel extends JPanel
 
     if (e.isPopupTrigger()) // Windows reports this in mouseReleased
     {
-      showPopupMenu(e);
+      showPopupMenu(e, pos);
     }
   }
 
@@ -432,7 +510,7 @@ public class IdPanel extends JPanel
   {
     getIdCanvas().setHighlighted(list);
 
-    if (list == null)
+    if (list == null || list.isEmpty())
     {
       return;
     }
@@ -457,24 +535,42 @@ public class IdPanel extends JPanel
     this.idCanvas = idCanvas;
   }
 
-  // this class allows scrolling off the bottom of the visible alignment
+  /**
+   * Performs scrolling of the visible alignment up or down, adding newly
+   * visible sequences to the current selection
+   */
   class ScrollThread extends Thread
   {
-    boolean running = false;
+    private boolean running = false;
 
-    boolean up = true;
+    private boolean up;
 
+    /**
+     * Constructor for a thread that scrolls either up or down
+     * 
+     * @param up
+     */
     public ScrollThread(boolean up)
     {
       this.up = up;
+      setName("IdPanel$ScrollThread$" + String.valueOf(up));
       start();
     }
 
+    /**
+     * Sets a flag to stop the scrolling
+     */
     public void stopScrolling()
     {
       running = false;
     }
 
+    /**
+     * Scrolls the alignment either up or down, one row at a time, adding newly
+     * visible sequences to the current selection. Speed is limited to a maximum
+     * of ten rows per second. The thread exits when the end of the alignment is
+     * reached or a flag is set to stop it.
+     */
     @Override
     public void run()
     {
@@ -482,29 +578,20 @@ public class IdPanel extends JPanel
 
       while (running)
       {
-        if (av.getRanges().scrollUp(up))
+        ViewportRanges ranges = IdPanel.this.av.getRanges();
+        if (ranges.scrollUp(up))
         {
-          // scroll was ok, so add new sequence to selection
-          int seq = av.getRanges().getStartSeq();
-
-          if (!up)
-          {
-            seq = av.getRanges().getEndSeq();
-          }
-
-          if (seq < lastid)
-          {
-            selectSeqs(lastid - 1, seq);
-          }
-          else if (seq > lastid)
-          {
-            selectSeqs(lastid + 1, seq);
-          }
-
-          lastid = seq;
+          int toSeq = up ? ranges.getStartSeq() : ranges.getEndSeq();
+          int fromSeq = toSeq < lastid ? lastid - 1 : lastid + 1;
+          IdPanel.this.selectSeqs(fromSeq, toSeq);
+
+          lastid = toSeq;
         }
         else
         {
+          /*
+           * scroll did nothing - reached limit of visible alignment
+           */
           running = false;
         }
 
diff --git a/src/jalview/gui/JalviewBooleanRadioButtons.java b/src/jalview/gui/JalviewBooleanRadioButtons.java
new file mode 100644 (file)
index 0000000..1f0c35a
--- /dev/null
@@ -0,0 +1,107 @@
+package jalview.gui;
+
+import java.awt.Font;
+import java.awt.event.ActionListener;
+
+import javax.swing.AbstractButton;
+import javax.swing.ButtonGroup;
+import javax.swing.JRadioButton;
+
+public class JalviewBooleanRadioButtons extends AbstractButton
+{
+  private static final Font LABEL_FONT = JvSwingUtils.getLabelFont();
+
+  private ButtonGroup buttonGroup = new ButtonGroup();
+
+  private JRadioButton buttonTrue = new JRadioButton();
+
+  private JRadioButton buttonFalse = new JRadioButton();
+
+  public JalviewBooleanRadioButtons(boolean value, String trueLabel,
+          String falseLabel)
+  {
+    init();
+    this.setLabels(trueLabel, falseLabel);
+  }
+
+  public JalviewBooleanRadioButtons(boolean value)
+  {
+    init();
+    setSelected(value);
+  }
+
+  public JalviewBooleanRadioButtons()
+  {
+    init();
+  }
+
+  protected void init()
+  {
+    buttonTrue.setFont(LABEL_FONT);
+    buttonFalse.setFont(LABEL_FONT);
+    buttonGroup.add(buttonTrue);
+    buttonGroup.add(buttonFalse);
+  }
+
+  public void setLabels(String trueLabel, String falseLabel)
+  {
+    buttonTrue.setText(trueLabel);
+    buttonFalse.setText(falseLabel);
+  }
+
+  @Override
+  public void setSelected(boolean b)
+  {
+    buttonFalse.setSelected(!b);
+    // this should probably happen automatically, no harm in forcing the issue!
+    // setting them this way round so the last setSelected is on buttonTrue
+    buttonTrue.setSelected(b);
+  }
+
+  @Override
+  public boolean isSelected()
+  {
+    // unambiguous selection
+    return buttonTrue.isSelected() && !buttonFalse.isSelected();
+  }
+
+  @Override
+  public void setEnabled(boolean b)
+  {
+    buttonTrue.setEnabled(b);
+    buttonFalse.setEnabled(b);
+  }
+
+  @Override
+  public boolean isEnabled()
+  {
+    return buttonTrue.isEnabled() && buttonFalse.isEnabled();
+  }
+
+  public JRadioButton getTrueButton()
+  {
+    return buttonTrue;
+  }
+
+  public JRadioButton getFalseButton()
+  {
+    return buttonFalse;
+  }
+  
+  @Override
+  public void addActionListener(ActionListener l)
+  {
+    buttonTrue.addActionListener(l);
+    buttonFalse.addActionListener(l);
+  }
+
+  public void addTrueActionListener(ActionListener l)
+  {
+    buttonTrue.addActionListener(l);
+  }
+
+  public void addFalseActionListener(ActionListener l)
+  {
+    buttonFalse.addActionListener(l);
+  }
+}
index cc361a5..89088b8 100644 (file)
@@ -257,6 +257,7 @@ public class OverviewCanvas extends JComponent
   public void dispose()
   {
     dispose = true;
+    od = null;
     synchronized (this)
     {
       restart = true;
index 02d54a8..9d0a55d 100755 (executable)
@@ -86,7 +86,7 @@ public class OverviewPanel extends JPanel
     this.ap = alPanel;
 
     showHidden = Cache.getDefault(Preferences.SHOW_OV_HIDDEN_AT_START,
-            true);
+            false);
     if (showHidden)
     {
       od = new OverviewDimensionsShowHidden(av.getRanges(),
@@ -112,7 +112,7 @@ public class OverviewPanel extends JPanel
 
     // without this the overview window does not size to fit the overview canvas
     setPreferredSize(new Dimension(od.getWidth(), od.getHeight()));
-
+    
     addComponentListener(new ComponentAdapter()
     {
       @Override
@@ -170,22 +170,23 @@ public class OverviewPanel extends JPanel
       @Override
       public void mouseMoved(MouseEvent evt)
       {
-        if (!draggingBox)
-        // don't bother changing the cursor if we're dragging the box
-        // as we can't have moved inside or out of the box in that case
+        if (od.isPositionInBox(evt.getX(), evt.getY()))
         {
-          if (od.isPositionInBox(evt.getX(), evt.getY()))
-          {
-            // display drag cursor at mouse position
-            setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
-          }
-          else
-          {
-            // reset cursor
-            setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
-          }
+          /*
+           * using HAND_CURSOR rather than DRAG_CURSOR 
+           * as the latter is not supported on Mac
+           */
+          getParent().setCursor(
+                  Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
+        }
+        else
+        {
+          // reset cursor
+          getParent().setCursor(
+                  Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
         }
       }
+
     });
 
     addMouseListener(new MouseAdapter()
@@ -215,6 +216,8 @@ public class OverviewPanel extends JPanel
             od.updateViewportFromMouse(evt.getX(), evt.getY(),
                     av.getAlignment().getHiddenSequences(),
                     av.getAlignment().getHiddenColumns());
+            getParent().setCursor(
+                    Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
           }
           else
           {
index c1e935a..3388d4d 100644 (file)
 package jalview.gui;
 
 import jalview.analysis.scoremodels.ScoreModels;
-import jalview.analysis.scoremodels.SimilarityParams;
+import jalview.api.AlignViewportI;
 import jalview.api.analysis.ScoreModelI;
 import jalview.api.analysis.SimilarityParamsI;
+import jalview.bin.Cache;
 import jalview.datamodel.Alignment;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.AlignmentView;
 import jalview.datamodel.HiddenColumns;
 import jalview.datamodel.SequenceI;
 import jalview.jbgui.GPCAPanel;
+import jalview.math.RotatableMatrix.Axis;
+import jalview.util.ImageMaker;
 import jalview.util.MessageManager;
 import jalview.viewmodel.AlignmentViewport;
 import jalview.viewmodel.PCAModel;
@@ -46,7 +49,6 @@ import java.awt.print.PrinterException;
 import java.awt.print.PrinterJob;
 
 import javax.swing.ButtonGroup;
-import javax.swing.JCheckBoxMenuItem;
 import javax.swing.JColorChooser;
 import javax.swing.JMenuItem;
 import javax.swing.JRadioButtonMenuItem;
@@ -54,49 +56,30 @@ import javax.swing.event.InternalFrameAdapter;
 import javax.swing.event.InternalFrameEvent;
 
 /**
- * DOCUMENT ME!
- * 
- * @author $author$
- * @version $Revision$
+ * The panel holding the Principal Component Analysis 3-D visualisation
  */
 public class PCAPanel extends GPCAPanel
         implements Runnable, IProgressIndicator
 {
+  private static final int MIN_WIDTH = 470;
 
-  private IProgressIndicator progressBar;
+  private static final int MIN_HEIGHT = 250;
 
-  RotatableCanvas rc;
+  private RotatableCanvas rc;
 
   AlignmentPanel ap;
 
   AlignmentViewport av;
 
-  PCAModel pcaModel;
+  private PCAModel pcaModel;
 
-  private static final int MIN_WIDTH = 470;
-
-  private static final int MIN_HEIGHT = 250;
+  private int top = 0;
 
-  int top = 0;
+  private IProgressIndicator progressBar;
 
   private boolean working;
 
   /**
-   * Creates a new PCAPanel object using default score model and parameters
-   * 
-   * @param alignPanel
-   */
-  public PCAPanel(AlignmentPanel alignPanel)
-  {
-    this(alignPanel,
-            ScoreModels.getInstance()
-                    .getDefaultModel(
-                            !alignPanel.av.getAlignment().isNucleotide())
-                    .getName(),
-            SimilarityParams.SeqSpace);
-  }
-
-  /**
    * Constructor given sequence data, a similarity (or distance) score model
    * name, and score calculation parameters
    * 
@@ -138,14 +121,17 @@ public class PCAPanel extends GPCAPanel
 
     ScoreModelI scoreModel = ScoreModels.getInstance()
             .getScoreModel(modelName, ap);
-    pcaModel = new PCAModel(seqstrings, seqs, nucleotide, scoreModel,
-            params);
+    setPcaModel(new PCAModel(seqstrings, seqs, nucleotide, scoreModel,
+            params));
     PaintRefresher.Register(this, av.getSequenceSetId());
 
-    rc = new RotatableCanvas(alignPanel);
-    this.getContentPane().add(rc, BorderLayout.CENTER);
-    Thread worker = new Thread(this);
-    worker.start();
+    setRotatableCanvas(new RotatableCanvas(alignPanel));
+    this.getContentPane().add(getRotatableCanvas(), BorderLayout.CENTER);
+
+    addKeyListener(getRotatableCanvas());
+    validate();
+
+    this.setMinimumSize(new Dimension(MIN_WIDTH, MIN_HEIGHT));
   }
 
   /**
@@ -154,79 +140,30 @@ public class PCAPanel extends GPCAPanel
    */
   protected void close_actionPerformed()
   {
-    pcaModel = null;
-  }
-
-  /**
-   * Repopulate the options and actions under the score model menu when it is
-   * selected. Options will depend on whether 'nucleotide' or 'peptide'
-   * modelling is selected (and also possibly on whether any additional score
-   * models have been added).
-   */
-  @Override
-  protected void scoreModel_menuSelected()
-  {
-    scoreModelMenu.removeAll();
-    for (final ScoreModelI sm : ScoreModels.getInstance().getModels())
-    {
-      final String name = sm.getName();
-      JCheckBoxMenuItem jm = new JCheckBoxMenuItem(name);
-
-      /*
-       * if the score model doesn't provide a description, try to look one
-       * up in the text bundle, falling back on its name
-       */
-      String tooltip = sm.getDescription();
-      if (tooltip == null)
-      {
-        tooltip = MessageManager.getStringOrReturn("label.score_model_",
-                name);
-      }
-      jm.setToolTipText(tooltip);
-      jm.setSelected(pcaModel.getScoreModelName().equals(name));
-      if ((pcaModel.isNucleotide() && sm.isDNA())
-              || (!pcaModel.isNucleotide() && sm.isProtein()))
-      {
-        jm.addActionListener(new ActionListener()
-        {
-          @Override
-          public void actionPerformed(ActionEvent e)
-          {
-            if (!pcaModel.getScoreModelName().equals(name))
-            {
-              ScoreModelI sm2 = ScoreModels.getInstance()
-                      .getScoreModel(name, ap);
-              pcaModel.setScoreModel(sm2);
-              Thread worker = new Thread(PCAPanel.this);
-              worker.start();
-            }
-          }
-        });
-        scoreModelMenu.add(jm);
-      }
-    }
+    setPcaModel(null);
   }
 
   @Override
-  public void bgcolour_actionPerformed(ActionEvent e)
+  protected void bgcolour_actionPerformed()
   {
     Color col = JColorChooser.showDialog(this,
             MessageManager.getString("label.select_background_colour"),
-            rc.bgColour);
+            getRotatableCanvas().getBgColour());
 
     if (col != null)
     {
-      rc.bgColour = col;
+      getRotatableCanvas().setBgColour(col);
     }
-    rc.repaint();
+    getRotatableCanvas().repaint();
   }
 
   /**
-   * DOCUMENT ME!
+   * Calculates the PCA and displays the results
    */
   @Override
   public void run()
   {
+    working = true;
     long progId = System.currentTimeMillis();
     IProgressIndicator progress = this;
     String message = MessageManager.getString("label.pca_recalculating");
@@ -236,21 +173,17 @@ public class PCAPanel extends GPCAPanel
       message = MessageManager.getString("label.pca_calculating");
     }
     progress.setProgressBar(message, progId);
-    working = true;
     try
     {
-      calcSettings.setEnabled(false);
-      pcaModel.run();
-      // ////////////////
+      getPcaModel().calculate();
+
       xCombobox.setSelectedIndex(0);
       yCombobox.setSelectedIndex(1);
       zCombobox.setSelectedIndex(2);
 
-      pcaModel.updateRc(rc);
+      getPcaModel().updateRc(getRotatableCanvas());
       // rc.invalidate();
-      nuclSetting.setSelected(pcaModel.isNucleotide());
-      protSetting.setSelected(!pcaModel.isNucleotide());
-      top = pcaModel.getTop();
+      setTop(getPcaModel().getTop());
 
     } catch (OutOfMemoryError er)
     {
@@ -261,109 +194,68 @@ public class PCAPanel extends GPCAPanel
     {
       progress.setProgressBar("", progId);
     }
-    calcSettings.setEnabled(true);
+
     repaint();
     if (getParent() == null)
     {
-      addKeyListener(rc);
-      Desktop.addInternalFrame(this, MessageManager
-              .getString("label.principal_component_analysis"), 475, 450);
-      this.setMinimumSize(new Dimension(MIN_WIDTH, MIN_HEIGHT));
+      Desktop.addInternalFrame(this,
+              MessageManager.formatMessage("label.calc_title", "PCA",
+                      getPcaModel().getScoreModelName()),
+              475, 450);
     }
     working = false;
   }
 
-  @Override
-  protected void nuclSetting_actionPerfomed(ActionEvent arg0)
-  {
-    if (!pcaModel.isNucleotide())
-    {
-      pcaModel.setNucleotide(true);
-      pcaModel.setScoreModel(
-              ScoreModels.getInstance().getDefaultModel(false));
-      Thread worker = new Thread(this);
-      worker.start();
-    }
-
-  }
-
-  @Override
-  protected void protSetting_actionPerfomed(ActionEvent arg0)
-  {
-
-    if (pcaModel.isNucleotide())
-    {
-      pcaModel.setNucleotide(false);
-      pcaModel.setScoreModel(
-              ScoreModels.getInstance().getDefaultModel(true));
-      Thread worker = new Thread(this);
-      worker.start();
-    }
-  }
-
   /**
-   * DOCUMENT ME!
+   * Updates the PCA display after a change of component to use for x, y or z
+   * axis
    */
-  void doDimensionChange()
+  @Override
+  protected void doDimensionChange()
   {
-    if (top == 0)
+    if (getTop() == 0)
     {
       return;
     }
 
-    int dim1 = top - xCombobox.getSelectedIndex();
-    int dim2 = top - yCombobox.getSelectedIndex();
-    int dim3 = top - zCombobox.getSelectedIndex();
-    pcaModel.updateRcView(dim1, dim2, dim3);
-    rc.img = null;
-    rc.rotmat.setIdentity();
-    rc.initAxes();
-    rc.paint(rc.getGraphics());
-  }
-
-  /**
-   * DOCUMENT ME!
-   * 
-   * @param e
-   *          DOCUMENT ME!
-   */
-  @Override
-  protected void xCombobox_actionPerformed(ActionEvent e)
-  {
-    doDimensionChange();
-  }
-
-  /**
-   * DOCUMENT ME!
-   * 
-   * @param e
-   *          DOCUMENT ME!
-   */
-  @Override
-  protected void yCombobox_actionPerformed(ActionEvent e)
-  {
-    doDimensionChange();
+    int dim1 = getTop() - xCombobox.getSelectedIndex();
+    int dim2 = getTop() - yCombobox.getSelectedIndex();
+    int dim3 = getTop() - zCombobox.getSelectedIndex();
+    getPcaModel().updateRcView(dim1, dim2, dim3);
+    getRotatableCanvas().resetView();
   }
 
   /**
-   * DOCUMENT ME!
+   * Sets the selected checkbox item index for PCA dimension (1, 2, 3...) for
+   * the given axis (X/Y/Z)
    * 
-   * @param e
-   *          DOCUMENT ME!
+   * @param index
+   * @param axis
    */
-  @Override
-  protected void zCombobox_actionPerformed(ActionEvent e)
+  public void setSelectedDimensionIndex(int index, Axis axis)
   {
-    doDimensionChange();
+    switch (axis)
+    {
+    case X:
+      xCombobox.setSelectedIndex(index);
+      break;
+    case Y:
+      yCombobox.setSelectedIndex(index);
+      break;
+    case Z:
+      zCombobox.setSelectedIndex(index);
+      break;
+    default:
+    }
   }
 
   @Override
-  public void outputValues_actionPerformed(ActionEvent e)
+  protected void outputValues_actionPerformed()
   {
     CutAndPasteTransfer cap = new CutAndPasteTransfer();
     try
     {
-      cap.setText(pcaModel.getDetails());
+      cap.setText(getPcaModel().getDetails());
       Desktop.addInternalFrame(cap,
               MessageManager.getString("label.pca_details"), 500, 500);
     } catch (OutOfMemoryError oom)
@@ -374,32 +266,35 @@ public class PCAPanel extends GPCAPanel
   }
 
   @Override
-  public void showLabels_actionPerformed(ActionEvent e)
+  protected void showLabels_actionPerformed()
   {
-    rc.showLabels(showLabels.getState());
+    getRotatableCanvas().showLabels(showLabels.getState());
   }
 
   @Override
-  public void print_actionPerformed(ActionEvent e)
+  protected void print_actionPerformed()
   {
     PCAPrinter printer = new PCAPrinter();
     printer.start();
   }
 
+  /**
+   * If available, shows the data which formed the inputs for the PCA as a new
+   * alignment
+   */
   @Override
-  public void originalSeqData_actionPerformed(ActionEvent e)
+  public void originalSeqData_actionPerformed()
   {
-    // this was cut'n'pasted from the equivalent TreePanel method - we should
-    // make this an abstract function of all jalview analysis windows
-    if (pcaModel.getSeqtrings() == null)
+    // JAL-2647 disabled after load from project (until save to project done)
+    if (getPcaModel().getInputData() == null)
     {
-      jalview.bin.Cache.log.info(
+      Cache.log.info(
               "Unexpected call to originalSeqData_actionPerformed - should have hidden this menu action.");
       return;
     }
     // decide if av alignment is sufficiently different to original data to
     // warrant a new window to be created
-    // create new alignmnt window with hidden regions (unhiding hidden regions
+    // create new alignment window with hidden regions (unhiding hidden regions
     // yields unaligned seqs)
     // or create a selection box around columns in alignment view
     // test Alignment(SeqCigar[])
@@ -412,8 +307,8 @@ public class PCAPanel extends GPCAPanel
     } catch (Exception ex)
     {
     }
-    ;
-    Object[] alAndColsel = pcaModel.getSeqtrings()
+
+    Object[] alAndColsel = getPcaModel().getInputData()
             .getAlignmentAndHiddenColumns(gc);
 
     if (alAndColsel != null && alAndColsel[0] != null)
@@ -495,11 +390,11 @@ public class PCAPanel extends GPCAPanel
     {
       pg.translate((int) pf.getImageableX(), (int) pf.getImageableY());
 
-      rc.drawBackground(pg, rc.bgColour);
-      rc.drawScene(pg);
-      if (rc.drawAxes == true)
+      getRotatableCanvas().drawBackground(pg);
+      getRotatableCanvas().drawScene(pg);
+      if (getRotatableCanvas().drawAxes)
       {
-        rc.drawAxes(pg);
+        getRotatableCanvas().drawAxes(pg);
       }
 
       if (pi == 0)
@@ -514,79 +409,75 @@ public class PCAPanel extends GPCAPanel
   }
 
   /**
-   * DOCUMENT ME!
-   * 
-   * @param e
-   *          DOCUMENT ME!
+   * Handler for 'Save as EPS' option
    */
   @Override
-  public void eps_actionPerformed(ActionEvent e)
+  protected void eps_actionPerformed()
   {
-    makePCAImage(jalview.util.ImageMaker.TYPE.EPS);
+    makePCAImage(ImageMaker.TYPE.EPS);
   }
 
   /**
-   * DOCUMENT ME!
-   * 
-   * @param e
-   *          DOCUMENT ME!
+   * Handler for 'Save as PNG' option
    */
   @Override
-  public void png_actionPerformed(ActionEvent e)
+  protected void png_actionPerformed()
   {
-    makePCAImage(jalview.util.ImageMaker.TYPE.PNG);
+    makePCAImage(ImageMaker.TYPE.PNG);
   }
 
-  void makePCAImage(jalview.util.ImageMaker.TYPE type)
+  void makePCAImage(ImageMaker.TYPE type)
   {
-    int width = rc.getWidth();
-    int height = rc.getHeight();
-
-    jalview.util.ImageMaker im;
-
-    if (type == jalview.util.ImageMaker.TYPE.PNG)
-    {
-      im = new jalview.util.ImageMaker(this,
-              jalview.util.ImageMaker.TYPE.PNG, "Make PNG image from PCA",
-              width, height, null, null, null, 0, false);
-    }
-    else if (type == jalview.util.ImageMaker.TYPE.EPS)
-    {
-      im = new jalview.util.ImageMaker(this,
-              jalview.util.ImageMaker.TYPE.EPS, "Make EPS file from PCA",
-              width, height, null, this.getTitle(), null, 0, false);
-    }
-    else
-    {
-      im = new jalview.util.ImageMaker(this,
-              jalview.util.ImageMaker.TYPE.SVG, "Make SVG file from PCA",
-              width, height, null, this.getTitle(), null, 0, false);
-
+    int width = getRotatableCanvas().getWidth();
+    int height = getRotatableCanvas().getHeight();
+
+    ImageMaker im;
+
+    switch (type)
+    {
+    case PNG:
+      im = new ImageMaker(this, ImageMaker.TYPE.PNG,
+              "Make PNG image from PCA", width, height, null, null, null, 0,
+              false);
+      break;
+    case EPS:
+      im = new ImageMaker(this, ImageMaker.TYPE.EPS,
+              "Make EPS file from PCA", width, height, null,
+              this.getTitle(), null, 0, false);
+      break;
+    default:
+      im = new ImageMaker(this, ImageMaker.TYPE.SVG,
+              "Make SVG file from PCA", width, height, null,
+              this.getTitle(), null, 0, false);
     }
 
     if (im.getGraphics() != null)
     {
-      rc.drawBackground(im.getGraphics(), Color.black);
-      rc.drawScene(im.getGraphics());
-      if (rc.drawAxes == true)
+      getRotatableCanvas().drawBackground(im.getGraphics());
+      getRotatableCanvas().drawScene(im.getGraphics());
+      if (getRotatableCanvas().drawAxes)
       {
-        rc.drawAxes(im.getGraphics());
+        getRotatableCanvas().drawAxes(im.getGraphics());
       }
       im.writeImage();
     }
   }
 
   @Override
-  public void viewMenu_menuSelected()
+  protected void viewMenu_menuSelected()
   {
     buildAssociatedViewMenu();
   }
 
+  /**
+   * Builds the menu showing the choice of possible views (for the associated
+   * sequence data) to which the PCA may be linked
+   */
   void buildAssociatedViewMenu()
   {
     AlignmentPanel[] aps = PaintRefresher
             .getAssociatedPanels(av.getSequenceSetId());
-    if (aps.length == 1 && rc.av == aps[0].av)
+    if (aps.length == 1 && getRotatableCanvas().av == aps[0].av)
     {
       associateViewsMenu.setVisible(false);
       return;
@@ -604,22 +495,20 @@ public class PCAPanel extends GPCAPanel
 
     JRadioButtonMenuItem item;
     ButtonGroup buttonGroup = new ButtonGroup();
-    int i, iSize = aps.length;
-    final PCAPanel thisPCAPanel = this;
-    for (i = 0; i < iSize; i++)
+    int iSize = aps.length;
+
+    for (int i = 0; i < iSize; i++)
     {
-      final AlignmentPanel ap = aps[i];
-      item = new JRadioButtonMenuItem(ap.av.getViewName(), ap.av == rc.av);
+      final AlignmentPanel panel = aps[i];
+      item = new JRadioButtonMenuItem(panel.av.getViewName(),
+              panel.av == getRotatableCanvas().av);
       buttonGroup.add(item);
       item.addActionListener(new ActionListener()
       {
         @Override
         public void actionPerformed(ActionEvent evt)
         {
-          rc.applyToAllViews = false;
-          rc.av = ap.av;
-          rc.ap = ap;
-          PaintRefresher.Register(thisPCAPanel, ap.av.getSequenceSetId());
+          selectAssociatedView(panel);
         }
       });
 
@@ -631,13 +520,13 @@ public class PCAPanel extends GPCAPanel
 
     buttonGroup.add(itemf);
 
-    itemf.setSelected(rc.applyToAllViews);
+    itemf.setSelected(getRotatableCanvas().isApplyToAllViews());
     itemf.addActionListener(new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent evt)
       {
-        rc.applyToAllViews = itemf.isSelected();
+        getRotatableCanvas().setApplyToAllViews(itemf.isSelected());
       }
     });
     associateViewsMenu.add(itemf);
@@ -652,12 +541,12 @@ public class PCAPanel extends GPCAPanel
    * )
    */
   @Override
-  protected void outputPoints_actionPerformed(ActionEvent e)
+  protected void outputPoints_actionPerformed()
   {
     CutAndPasteTransfer cap = new CutAndPasteTransfer();
     try
     {
-      cap.setText(pcaModel.getPointsasCsv(false,
+      cap.setText(getPcaModel().getPointsasCsv(false,
               xCombobox.getSelectedIndex(), yCombobox.getSelectedIndex(),
               zCombobox.getSelectedIndex()));
       Desktop.addInternalFrame(cap, MessageManager
@@ -678,12 +567,12 @@ public class PCAPanel extends GPCAPanel
    * .ActionEvent)
    */
   @Override
-  protected void outputProjPoints_actionPerformed(ActionEvent e)
+  protected void outputProjPoints_actionPerformed()
   {
     CutAndPasteTransfer cap = new CutAndPasteTransfer();
     try
     {
-      cap.setText(pcaModel.getPointsasCsv(true,
+      cap.setText(getPcaModel().getPointsasCsv(true,
               xCombobox.getSelectedIndex(), yCombobox.getSelectedIndex(),
               zCombobox.getSelectedIndex()));
       Desktop.addInternalFrame(cap, MessageManager.formatMessage(
@@ -793,13 +682,13 @@ public class PCAPanel extends GPCAPanel
   }
 
   @Override
-  protected void resetButton_actionPerformed(ActionEvent e)
+  protected void resetButton_actionPerformed()
   {
-    int t = top;
-    top = 0; // ugly - prevents dimensionChanged events from being processed
+    int t = getTop();
+    setTop(0); // ugly - prevents dimensionChanged events from being processed
     xCombobox.setSelectedIndex(0);
     yCombobox.setSelectedIndex(1);
-    top = t;
+    setTop(t);
     zCombobox.setSelectedIndex(2);
   }
 
@@ -812,4 +701,94 @@ public class PCAPanel extends GPCAPanel
   {
     return working;
   }
+
+  /**
+   * Answers the selected checkbox item index for PCA dimension for the X, Y or
+   * Z axis of the display
+   * 
+   * @param axis
+   * @return
+   */
+  public int getSelectedDimensionIndex(Axis axis)
+  {
+    switch (axis)
+    {
+    case X:
+      return xCombobox.getSelectedIndex();
+    case Y:
+      return yCombobox.getSelectedIndex();
+    default:
+      return zCombobox.getSelectedIndex();
+    }
+  }
+
+  public void setShowLabels(boolean show)
+  {
+    showLabels.setSelected(show);
+  }
+
+  /**
+   * Sets the input data used to calculate the PCA. This is provided for
+   * 'restore from project', which does not currently support this (AL-2647), so
+   * sets the value to null, and hides the menu option for "Input Data...". J
+   * 
+   * @param data
+   */
+  public void setInputData(AlignmentView data)
+  {
+    getPcaModel().setInputData(data);
+    originalSeqData.setVisible(data != null);
+  }
+
+  public AlignViewportI getAlignViewport()
+  {
+    return av;
+  }
+
+  public PCAModel getPcaModel()
+  {
+    return pcaModel;
+  }
+
+  public void setPcaModel(PCAModel pcaModel)
+  {
+    this.pcaModel = pcaModel;
+  }
+
+  public RotatableCanvas getRotatableCanvas()
+  {
+    return rc;
+  }
+
+  public void setRotatableCanvas(RotatableCanvas rc)
+  {
+    this.rc = rc;
+  }
+
+  public int getTop()
+  {
+    return top;
+  }
+
+  public void setTop(int top)
+  {
+    this.top = top;
+  }
+
+  /**
+   * set the associated view for this PCA.
+   * 
+   * @param panel
+   */
+  public void selectAssociatedView(AlignmentPanel panel)
+  {
+    getRotatableCanvas().setApplyToAllViews(false);
+
+    ap = panel;
+    av = panel.av;
+
+    getRotatableCanvas().av = panel.av;
+    getRotatableCanvas().ap = panel;
+    PaintRefresher.Register(PCAPanel.this, panel.av.getSequenceSetId());
+  }
 }
index ed3d29a..86febed 100644 (file)
@@ -46,6 +46,7 @@ import jalview.schemes.Blosum62ColourScheme;
 import jalview.schemes.ColourSchemeI;
 import jalview.schemes.ColourSchemes;
 import jalview.schemes.PIDColourScheme;
+import jalview.schemes.ResidueColourScheme;
 import jalview.util.GroupUrlLink;
 import jalview.util.GroupUrlLink.UrlStringTooLongException;
 import jalview.util.MessageManager;
@@ -68,11 +69,13 @@ 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.JMenu;
 import javax.swing.JMenuItem;
 import javax.swing.JPopupMenu;
+import javax.swing.JRadioButtonMenuItem;
 
 /**
  * DOCUMENT ME!
@@ -92,6 +95,8 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener
 
   protected JCheckBoxMenuItem conservationMenuItem = new JCheckBoxMenuItem();
 
+  protected JRadioButtonMenuItem annotationColour;
+
   protected JMenuItem modifyConservation = new JMenuItem();
 
   AlignmentPanel ap;
@@ -401,9 +406,20 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener
         }
       }
     }
-    // for the case when no sequences are even visible
+
+    /*
+     * offer 'Reveal All'
+     * - in the IdPanel (seq not null) if any sequence is hidden
+     * - in the IdPanel or SeqPanel if all sequences are hidden (seq is null)
+     */
     if (alignPanel.av.hasHiddenRows())
     {
+      boolean addOption = seq != null;
+      if (!addOption && alignPanel.av.getAlignment().getHeight() == 0)
+      {
+        addOption = true;
+      }
+      if (addOption)
       {
         menuItem = new JMenuItem(
                 MessageManager.getString("action.reveal_all"));
@@ -419,7 +435,6 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener
             }
           }
         });
-
         add(menuItem);
       }
     }
@@ -1401,6 +1416,13 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener
       }
     });
 
+    annotationColour = new JRadioButtonMenuItem(
+            MessageManager.getString("action.by_annotation"));
+    annotationColour.setName(ResidueColourScheme.ANNOTATION_COLOUR);
+    annotationColour.setEnabled(false);
+    annotationColour.setToolTipText(
+            MessageManager.getString("label.by_annotation_tooltip"));
+
     modifyConservation.setText(MessageManager
             .getString("label.modify_conservation_threshold"));
     modifyConservation.addActionListener(new ActionListener()
@@ -1431,7 +1453,10 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener
     colourMenu.add(textColour);
     colourMenu.addSeparator();
 
-    ColourMenuHelper.addMenuItems(colourMenu, this, sg, false);
+    ButtonGroup bg = ColourMenuHelper.addMenuItems(colourMenu, this, sg,
+            false);
+    bg.add(annotationColour);
+    colourMenu.add(annotationColour);
 
     colourMenu.addSeparator();
     colourMenu.add(conservationMenuItem);
@@ -2126,7 +2151,7 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener
      * switch to the chosen colour scheme (or null for None)
      */
     ColourSchemeI colourScheme = ColourSchemes.getInstance()
-            .getColourScheme(colourSchemeName, sg,
+            .getColourScheme(colourSchemeName, ap.av, sg,
                     ap.av.getHiddenRepSequences());
     sg.setColourScheme(colourScheme);
     if (colourScheme instanceof Blosum62ColourScheme
index 7d02fac..ab09f74 100755 (executable)
@@ -24,6 +24,7 @@ import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
 import jalview.bin.Cache;
 import jalview.gui.Help.HelpId;
 import jalview.gui.StructureViewer.ViewerType;
+import jalview.io.BackupFiles;
 import jalview.io.FileFormatI;
 import jalview.io.JalviewFileChooser;
 import jalview.io.JalviewFileView;
@@ -325,7 +326,7 @@ public class Preferences extends GPreferences
     gapLabel.setEnabled(!useLegacyGap.isSelected());
     gapColour.setEnabled(!useLegacyGap.isSelected());
     showHiddenAtStart
-            .setSelected(Cache.getDefault(SHOW_OV_HIDDEN_AT_START, true));
+            .setSelected(Cache.getDefault(SHOW_OV_HIDDEN_AT_START, false));
 
     /*
      * Set Structure tab defaults.
@@ -546,6 +547,12 @@ public class Preferences extends GPreferences
 
     annotations_actionPerformed(null); // update the display of the annotation
                                        // settings
+    
+    
+    /*
+     * Set Backups tab defaults
+     */
+    loadLastSavedBackupsOptions();
   }
 
   /**
@@ -794,6 +801,27 @@ public class Preferences extends GPreferences
             Boolean.toString(padGaps.isSelected()));
 
     wsPrefs.updateAndRefreshWsMenuConfig(false);
+
+    /*
+     * Save Backups settings
+     */
+    Cache.applicationProperties.setProperty(BackupFiles.CONFIRM_DELETE_OLD,
+            Boolean.toString(backupfilesConfirmDelete.isSelected()));
+    Cache.applicationProperties.setProperty(BackupFiles.ENABLED,
+            Boolean.toString(enableBackupFiles.isSelected()));
+    Cache.applicationProperties.setProperty(BackupFiles.NO_MAX,
+            Boolean.toString(backupfilesKeepAll.isSelected()));
+    Cache.applicationProperties.setProperty(BackupFiles.REVERSE_ORDER,
+            Boolean.toString(suffixReverse.isSelected()));
+    Cache.applicationProperties.setProperty(BackupFiles.SUFFIX,
+            suffixTemplate.getText());
+    Cache.applicationProperties.setProperty(BackupFiles.ROLL_MAX,
+            Integer.toString(getSpinnerInt(backupfilesRollMaxSpinner, 4)));
+    Cache.applicationProperties.setProperty(BackupFiles.SUFFIX_DIGITS,
+            Integer.toString(getSpinnerInt(suffixDigitsSpinner, 3)));
+    Cache.applicationProperties.setProperty(BackupFiles.NS+"_PRESET",
+            Integer.toString(getComboIntStringKey(backupfilesPresetsCombo)));
+
     Cache.saveProperties();
     Desktop.instance.doConfigureStructurePrefs();
     try
@@ -1116,7 +1144,7 @@ public class Preferences extends GPreferences
   {
     useLegacyGap.setSelected(false);
     useLegacyGaps_actionPerformed(null);
-    showHiddenAtStart.setSelected(true);
+    showHiddenAtStart.setSelected(false);
     hiddenColour.setBackground(
             jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN);
   }
index 02368df..dc0cdb4 100755 (executable)
 package jalview.gui;
 
 import jalview.api.RotatableCanvasI;
+import jalview.datamodel.Point;
 import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
 import jalview.datamodel.SequencePoint;
 import jalview.math.RotatableMatrix;
+import jalview.math.RotatableMatrix.Axis;
+import jalview.util.ColorUtils;
 import jalview.util.MessageManager;
 import jalview.viewmodel.AlignmentViewport;
 
@@ -43,328 +46,192 @@ import java.awt.event.MouseListener;
 import java.awt.event.MouseMotionListener;
 import java.awt.event.MouseWheelEvent;
 import java.awt.event.MouseWheelListener;
-import java.util.Vector;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
 
 import javax.swing.JPanel;
 import javax.swing.ToolTipManager;
 
 /**
- * DOCUMENT ME!
- * 
- * @author $author$
- * @version $Revision$
+ * Models a Panel on which a set of points, and optionally x/y/z axes, can be
+ * drawn, and rotated or zoomed with the mouse
  */
 public class RotatableCanvas extends JPanel implements MouseListener,
-        MouseMotionListener, KeyListener, RotatableCanvasI
+        MouseMotionListener, KeyListener, RotatableCanvasI,
+        MouseWheelListener
 {
-  RotatableMatrix idmat = new RotatableMatrix(3, 3);
+  private static final float ZOOM_OUT = 0.9f;
 
-  RotatableMatrix objmat = new RotatableMatrix(3, 3);
+  private static final float ZOOM_IN = 1.1f;
 
-  RotatableMatrix rotmat = new RotatableMatrix(3, 3);
+  /*
+   * pixels distance within which tooltip shows sequence name
+   */
+  private static final int NEARBY = 3;
 
-  // RubberbandRectangle rubberband;
-  boolean drawAxes = true;
+  private static final List<String> AXES = Arrays.asList("x", "y", "z");
 
-  int omx = 0;
+  private static final Color AXIS_COLOUR = Color.yellow;
 
-  int mx = 0;
+  private static final int DIMS = 3;
 
-  int omy = 0;
+  boolean drawAxes = true;
+
+  int mouseX;
 
-  int my = 0;
+  int mouseY;
 
   Image img;
 
   Graphics ig;
 
-  Dimension prefsize;
-
-  float[] centre = new float[3];
+  Dimension prefSize;
 
-  float[] width = new float[3];
-
-  float[] max = new float[3];
-
-  float[] min = new float[3];
+  /*
+   * the min-max [x, y, z] values of sequence points when the points
+   * were set on the object, or when the view is reset; 
+   * x and y ranges are not recomputed as points are rotated, as this
+   * would make scaling (zoom) unstable, but z ranges are (for correct
+   * graduated colour brightness based on z-coordinate)
+   */
+  float[] seqMin;
 
-  float maxwidth;
+  float[] seqMax;
 
-  float scale;
+  /*
+   * a scale factor used in drawing; when equal to 1, the points span
+   * half the available width or height (whichever is less); increase this
+   * factor to zoom in, decrease it to zoom out
+   */
+  private float scaleFactor;
 
   int npoint;
 
-  Vector points;
-
-  float[][] orig;
-
-  float[][] axes;
-
-  int startx;
-
-  int starty;
-
-  int lastx;
-
-  int lasty;
-
-  int rectx1;
-
-  int recty1;
-
-  int rectx2;
+  /*
+   * sequences and their (x, y, z) PCA dimension values
+   */
+  List<SequencePoint> sequencePoints;
 
-  int recty2;
+  /*
+   * x, y, z axis end points (PCA dimension values)
+   */
+  private Point[] axisEndPoints;
 
-  float scalefactor = 1;
+  // fields for 'select rectangle' (JAL-1124)
+  // int rectx1;
+  // int recty1;
+  // int rectx2;
+  // int recty2;
 
   AlignmentViewport av;
 
   AlignmentPanel ap;
 
-  boolean showLabels = false;
+  private boolean showLabels;
 
-  Color bgColour = Color.black;
+  private Color bgColour;
 
-  boolean applyToAllViews = false;
+  private boolean applyToAllViews;
 
-  public RotatableCanvas(AlignmentPanel ap)
+  /**
+   * Constructor
+   * 
+   * @param panel
+   */
+  public RotatableCanvas(AlignmentPanel panel)
   {
-    this.av = ap.av;
-    this.ap = ap;
-
-    addMouseWheelListener(new MouseWheelListener()
-    {
-      @Override
-      public void mouseWheelMoved(MouseWheelEvent e)
-      {
-        double wheelRotation = e.getPreciseWheelRotation();
-        if (wheelRotation > 0)
-        {
-          /*
-           * zoom in
-           */
-          scale = (float) (scale * 1.1);
-          repaint();
-        }
-        else if (wheelRotation < 0)
-        {
-          /*
-           * zoom out
-           */
-          scale = (float) (scale * 0.9);
-          repaint();
-        }
-      }
-    });
-
+    this.av = panel.av;
+    this.ap = panel;
+    setAxisEndPoints(new Point[DIMS]);
+    setShowLabels(false);
+    setApplyToAllViews(false);
+    setBgColour(Color.BLACK);
+    resetAxes();
+
+    ToolTipManager.sharedInstance().registerComponent(this);
+
+    addMouseListener(this);
+    addMouseMotionListener(this);
+    addMouseWheelListener(this);
   }
 
-  public void showLabels(boolean b)
+  /**
+   * Refreshes the display with labels shown (or not)
+   * 
+   * @param show
+   */
+  public void showLabels(boolean show)
   {
-    showLabels = b;
+    setShowLabels(show);
     repaint();
   }
 
-  boolean first = true;
-
   @Override
-  public void setPoints(Vector points, int npoint)
+  public void setPoints(List<SequencePoint> points, int np)
   {
-    this.points = points;
-    this.npoint = npoint;
-    if (first)
-    {
-      ToolTipManager.sharedInstance().registerComponent(this);
-      ToolTipManager.sharedInstance().setInitialDelay(0);
-      ToolTipManager.sharedInstance().setDismissDelay(10000);
-    }
-    prefsize = getPreferredSize();
-    orig = new float[npoint][3];
+    this.sequencePoints = points;
+    this.npoint = np;
+    prefSize = getPreferredSize();
 
-    for (int i = 0; i < npoint; i++)
-    {
-      SequencePoint sp = (SequencePoint) points.elementAt(i);
+    findWidths();
 
-      for (int j = 0; j < 3; j++)
-      {
-        orig[i][j] = sp.coord[j];
-      }
-    }
-
-    // Initialize the matrices to identity
-    for (int i = 0; i < 3; i++)
-    {
-      for (int j = 0; j < 3; j++)
-      {
-        if (i != j)
-        {
-          idmat.addElement(i, j, 0);
-          objmat.addElement(i, j, 0);
-          rotmat.addElement(i, j, 0);
-        }
-        else
-        {
-          idmat.addElement(i, j, 0);
-          objmat.addElement(i, j, 0);
-          rotmat.addElement(i, j, 0);
-        }
-      }
-    }
-
-    axes = new float[3][3];
-    initAxes();
-
-    findCentre();
-    findWidth();
-
-    scale = findScale();
-    if (first)
-    {
-
-      addMouseListener(this);
-
-      addMouseMotionListener(this);
-    }
-    first = false;
-  }
-
-  public void initAxes()
-  {
-    for (int i = 0; i < 3; i++)
-    {
-      for (int j = 0; j < 3; j++)
-      {
-        if (i != j)
-        {
-          axes[i][j] = 0;
-        }
-        else
-        {
-          axes[i][j] = 1;
-        }
-      }
-    }
+    setScaleFactor(1f);
   }
 
   /**
-   * DOCUMENT ME!
+   * Resets axes to the initial state: x-axis to the right, y-axis up, z-axis to
+   * back (so obscured in a 2-D display)
    */
-  public void findWidth()
+  protected void resetAxes()
   {
-    max = new float[3];
-    min = new float[3];
-
-    max[0] = (float) -1e30;
-    max[1] = (float) -1e30;
-    max[2] = (float) -1e30;
-
-    min[0] = (float) 1e30;
-    min[1] = (float) 1e30;
-    min[2] = (float) 1e30;
-
-    for (int i = 0; i < 3; i++)
-    {
-      for (int j = 0; j < npoint; j++)
-      {
-        SequencePoint sp = (SequencePoint) points.elementAt(j);
-
-        if (sp.coord[i] >= max[i])
-        {
-          max[i] = sp.coord[i];
-        }
-
-        if (sp.coord[i] <= min[i])
-        {
-          min[i] = sp.coord[i];
-        }
-      }
-    }
-
-    // System.out.println("xmax " + max[0] + " min " + min[0]);
-    // System.out.println("ymax " + max[1] + " min " + min[1]);
-    // System.out.println("zmax " + max[2] + " min " + min[2]);
-    width[0] = Math.abs(max[0] - min[0]);
-    width[1] = Math.abs(max[1] - min[1]);
-    width[2] = Math.abs(max[2] - min[2]);
-
-    maxwidth = width[0];
-
-    if (width[1] > width[0])
-    {
-      maxwidth = width[1];
-    }
-
-    if (width[2] > width[1])
-    {
-      maxwidth = width[2];
-    }
-
-    // System.out.println("Maxwidth = " + maxwidth);
-  }
-
-  /**
-   * DOCUMENT ME!
-   * 
-   * @return DOCUMENT ME!
-   */
-  public float findScale()
-  {
-    int dim;
-    int width;
-    int height;
-
-    if (getWidth() != 0)
-    {
-      width = getWidth();
-      height = getHeight();
-    }
-    else
-    {
-      width = prefsize.width;
-      height = prefsize.height;
-    }
-
-    if (width < height)
-    {
-      dim = width;
-    }
-    else
-    {
-      dim = height;
-    }
-
-    return (dim * scalefactor) / (2 * maxwidth);
+    getAxisEndPoints()[0] = new Point(1f, 0f, 0f);
+    getAxisEndPoints()[1] = new Point(0f, 1f, 0f);
+    getAxisEndPoints()[2] = new Point(0f, 0f, 1f);
   }
 
   /**
-   * DOCUMENT ME!
+   * Computes and saves the min-max ranges of x/y/z positions of the sequence
+   * points
    */
-  public void findCentre()
+  protected void findWidths()
   {
-    // Find centre coordinate
-    findWidth();
-
-    centre[0] = (max[0] + min[0]) / 2;
-    centre[1] = (max[1] + min[1]) / 2;
-    centre[2] = (max[2] + min[2]) / 2;
-
-    // System.out.println("Centre x " + centre[0]);
-    // System.out.println("Centre y " + centre[1]);
-    // System.out.println("Centre z " + centre[2]);
+    float[] max = new float[DIMS];
+    float[] min = new float[DIMS];
+    
+    max[0] = -Float.MAX_VALUE;
+    max[1] = -Float.MAX_VALUE;
+    max[2] = -Float.MAX_VALUE;
+    
+    min[0] = Float.MAX_VALUE;
+    min[1] = Float.MAX_VALUE;
+    min[2] = Float.MAX_VALUE;
+    
+    for (SequencePoint sp : sequencePoints)
+    {
+      max[0] = Math.max(max[0], sp.coord.x);
+      max[1] = Math.max(max[1], sp.coord.y);
+      max[2] = Math.max(max[2], sp.coord.z);
+      min[0] = Math.min(min[0], sp.coord.x);
+      min[1] = Math.min(min[1], sp.coord.y);
+      min[2] = Math.min(min[2], sp.coord.z);
+    }
+    
+    seqMin = min;
+    seqMax = max;
   }
 
   /**
-   * DOCUMENT ME!
+   * Answers the preferred size if it has been set, else 400 x 400
    * 
-   * @return DOCUMENT ME!
+   * @return
    */
   @Override
   public Dimension getPreferredSize()
   {
-    if (prefsize != null)
+    if (prefSize != null)
     {
-      return prefsize;
+      return prefSize;
     }
     else
     {
@@ -373,9 +240,10 @@ public class RotatableCanvas extends JPanel implements MouseListener,
   }
 
   /**
-   * DOCUMENT ME!
+   * Answers the preferred size
    * 
-   * @return DOCUMENT ME!
+   * @return
+   * @see RotatableCanvas#getPreferredSize()
    */
   @Override
   public Dimension getMinimumSize()
@@ -384,10 +252,9 @@ public class RotatableCanvas extends JPanel implements MouseListener,
   }
 
   /**
-   * DOCUMENT ME!
+   * Repaints the panel
    * 
    * @param g
-   *          DOCUMENT ME!
    */
   @Override
   public void paintComponent(Graphics g1)
@@ -397,7 +264,7 @@ public class RotatableCanvas extends JPanel implements MouseListener,
 
     g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
             RenderingHints.VALUE_ANTIALIAS_ON);
-    if (points == null)
+    if (sequencePoints == null)
     {
       g.setFont(new Font("Verdana", Font.PLAIN, 18));
       g.drawString(
@@ -406,24 +273,24 @@ public class RotatableCanvas extends JPanel implements MouseListener,
     }
     else
     {
-      // Only create the image at the beginning -
-      if ((img == null) || (prefsize.width != getWidth())
-              || (prefsize.height != getHeight()))
+      /*
+       * create the image at the beginning or after a resize
+       */
+      boolean resized = prefSize.width != getWidth()
+              || prefSize.height != getHeight();
+      if (img == null || resized)
       {
-        prefsize.width = getWidth();
-        prefsize.height = getHeight();
+        prefSize.width = getWidth();
+        prefSize.height = getHeight();
 
-        scale = findScale();
-
-        // System.out.println("New scale = " + scale);
         img = createImage(getWidth(), getHeight());
         ig = img.getGraphics();
       }
 
-      drawBackground(ig, bgColour);
+      drawBackground(ig);
       drawScene(ig);
 
-      if (drawAxes == true)
+      if (drawAxes)
       {
         drawAxes(ig);
       }
@@ -433,96 +300,110 @@ public class RotatableCanvas extends JPanel implements MouseListener,
   }
 
   /**
-   * DOCUMENT ME!
+   * Resets the rotation and choice of axes to the initial state (without change
+   * of scale factor)
+   */
+  public void resetView()
+  {
+    img = null;
+    findWidths();
+    resetAxes();
+    repaint();
+  }
+
+  /**
+   * Draws lines for the x, y, z axes
    * 
    * @param g
-   *          DOCUMENT ME!
    */
   public void drawAxes(Graphics g)
   {
+    g.setColor(AXIS_COLOUR);
 
-    g.setColor(Color.yellow);
+    int midX = getWidth() / 2;
+    int midY = getHeight() / 2;
+    float maxWidth = Math.max(Math.abs(seqMax[0] - seqMin[0]),
+            Math.abs(seqMax[1] - seqMin[1]));
+    int pix = Math.min(getWidth(), getHeight());
+    float scaleBy = pix * getScaleFactor() / (2f * maxWidth);
 
-    for (int i = 0; i < 3; i++)
+    for (int i = 0; i < DIMS; i++)
     {
-      g.drawLine(getWidth() / 2, getHeight() / 2,
-              (int) ((axes[i][0] * scale * max[0]) + (getWidth() / 2)),
-              (int) ((axes[i][1] * scale * max[1]) + (getHeight() / 2)));
+      g.drawLine(midX, midY,
+              midX + (int) (getAxisEndPoints()[i].x * scaleBy * seqMax[0]),
+              midY + (int) (getAxisEndPoints()[i].y * scaleBy * seqMax[1]));
     }
   }
 
   /**
-   * DOCUMENT ME!
+   * Fills the background with the currently configured background colour
    * 
    * @param g
-   *          DOCUMENT ME!
-   * @param col
-   *          DOCUMENT ME!
    */
-  public void drawBackground(Graphics g, Color col)
+  public void drawBackground(Graphics g)
   {
-    g.setColor(col);
-    g.fillRect(0, 0, prefsize.width, prefsize.height);
+    g.setColor(getBgColour());
+    g.fillRect(0, 0, prefSize.width, prefSize.height);
   }
 
   /**
-   * DOCUMENT ME!
+   * Draws points (6x6 squares) for the sequences of the PCA, and labels
+   * (sequence names) if configured to do so. The sequence points colours are
+   * taken from the sequence ids in the alignment (converting black to white).
+   * Sequences 'at the back' (z-coordinate is negative) are shaded slightly
+   * darker to help give a 3-D sensation.
    * 
    * @param g
-   *          DOCUMENT ME!
    */
   public void drawScene(Graphics g1)
   {
-
     Graphics2D g = (Graphics2D) g1;
 
     g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
             RenderingHints.VALUE_ANTIALIAS_ON);
+    int pix = Math.min(getWidth(), getHeight());
+    float xWidth = Math.abs(seqMax[0] - seqMin[0]);
+    float yWidth = Math.abs(seqMax[1] - seqMin[1]);
+    float maxWidth = Math.max(xWidth, yWidth);
+    float scaleBy = pix * getScaleFactor() / (2f * maxWidth);
 
-    int halfwidth = getWidth() / 2;
-    int halfheight = getHeight() / 2;
+    float[] centre = getCentre();
 
     for (int i = 0; i < npoint; i++)
     {
-      SequencePoint sp = (SequencePoint) points.elementAt(i);
-      int x = (int) ((sp.coord[0] - centre[0]) * scale) + halfwidth;
-      int y = (int) ((sp.coord[1] - centre[1]) * scale)
-              + halfheight;
-      float z = sp.coord[1] - centre[2];
-
-      if (av.getSequenceColour(sp.sequence) == Color.black)
-      {
-        g.setColor(Color.white);
-      }
-      else
-      {
-        g.setColor(av.getSequenceColour(sp.sequence));
-      }
-
-      if (av.getSelectionGroup() != null)
-      {
-        if (av.getSelectionGroup().getSequences(null)
-                .contains(((SequencePoint) points.elementAt(i)).sequence))
-        {
-          g.setColor(Color.gray);
-        }
-      }
+      /*
+       * sequence point colour as sequence id, but
+       * gray if sequence is currently selected
+       */
+      SequencePoint sp = sequencePoints.get(i);
+      Color sequenceColour = getSequencePointColour(sp);
+      g.setColor(sequenceColour);
+
+      int halfwidth = getWidth() / 2;
+      int halfheight = getHeight() / 2;
+      int x = (int) ((sp.coord.x - centre[0]) * scaleBy) + halfwidth;
+      int y = (int) ((sp.coord.y - centre[1]) * scaleBy) + halfheight;
+      g.fillRect(x - 3, y - 3, 6, 6);
 
-      if (z < 0)
+      if (isShowLabels())
       {
-        g.setColor(g.getColor().darker());
+        g.setColor(Color.red);
+        g.drawString(sp.getSequence().getName(), x - 3, y - 4);
       }
-
-      g.fillRect(x - 3, y - 3, 6, 6);
-      if (showLabels)
+    }
+    if (isShowLabels())
+    {
+      g.setColor(AXIS_COLOUR);
+      int midX = getWidth() / 2;
+      int midY = getHeight() / 2;
+      Iterator<String> axes = AXES.iterator();
+      for (Point p : getAxisEndPoints())
       {
-        g.setColor(Color.red);
-        g.drawString(
-                ((SequencePoint) points.elementAt(i)).sequence.getName(),
-                x - 3, y - 4);
+        int x = midX + (int) (p.x * scaleBy * seqMax[0]);
+        int y = midY + (int) (p.y * scaleBy * seqMax[1]);
+        g.drawString(axes.next(), x - 3, y - 4);
       }
     }
-
     // //Now the rectangle
     // if (rectx2 != -1 && recty2 != -1) {
     // g.setColor(Color.white);
@@ -532,128 +413,147 @@ public class RotatableCanvas extends JPanel implements MouseListener,
   }
 
   /**
-   * DOCUMENT ME!
+   * Determines the colour to use when drawing a sequence point. The colour is
+   * taken from the sequence id, with black converted to white, and then
+   * graduated from darker (at the back) to brighter (at the front) based on the
+   * z-axis coordinate of the point.
    * 
-   * @return DOCUMENT ME!
+   * @param sp
+   * @return
    */
-  public Dimension minimumsize()
+  protected Color getSequencePointColour(SequencePoint sp)
   {
-    return prefsize;
-  }
+    SequenceI sequence = sp.getSequence();
+    Color sequenceColour = av.getSequenceColour(sequence);
+    if (sequenceColour == Color.black)
+    {
+      sequenceColour = Color.white;
+    }
+    if (av.getSelectionGroup() != null)
+    {
+      if (av.getSelectionGroup().getSequences(null).contains(sequence))
+      {
+        sequenceColour = Color.gray;
+      }
+    }
 
-  /**
-   * DOCUMENT ME!
-   * 
-   * @return DOCUMENT ME!
-   */
-  public Dimension preferredsize()
-  {
-    return prefsize;
+    /*
+     * graduate brighter for point in front of centre, darker if behind centre
+     */
+    float zCentre = (seqMin[2] + seqMax[2]) / 2f;
+    if (sp.coord.z > zCentre)
+    {
+      sequenceColour = ColorUtils.getGraduatedColour(sp.coord.z, 0,
+              sequenceColour, seqMax[2], sequenceColour.brighter());
+    }
+    else if (sp.coord.z < zCentre)
+    {
+      sequenceColour = ColorUtils.getGraduatedColour(sp.coord.z, seqMin[2],
+              sequenceColour.darker(), 0, sequenceColour);
+    }
+
+    return sequenceColour;
   }
 
-  /**
-   * DOCUMENT ME!
-   * 
-   * @param evt
-   *          DOCUMENT ME!
-   */
   @Override
   public void keyTyped(KeyEvent evt)
   {
   }
 
-  /**
-   * DOCUMENT ME!
-   * 
-   * @param evt
-   *          DOCUMENT ME!
-   */
   @Override
   public void keyReleased(KeyEvent evt)
   {
   }
 
   /**
-   * DOCUMENT ME!
+   * Responds to up or down arrow key by zooming in or out, respectively
    * 
    * @param evt
-   *          DOCUMENT ME!
    */
   @Override
   public void keyPressed(KeyEvent evt)
   {
-    if (evt.getKeyCode() == KeyEvent.VK_UP)
+    int keyCode = evt.getKeyCode();
+    boolean shiftDown = evt.isShiftDown();
+
+    if (keyCode == KeyEvent.VK_UP)
+    {
+      if (shiftDown)
+      {
+        rotate(0f, -1f);
+      }
+      else
+      {
+        zoom(ZOOM_IN);
+      }
+    }
+    else if (keyCode == KeyEvent.VK_DOWN)
+    {
+      if (shiftDown)
+      {
+        rotate(0f, 1f);
+      }
+      else
+      {
+        zoom(ZOOM_OUT);
+      }
+    }
+    else if (shiftDown && keyCode == KeyEvent.VK_LEFT)
     {
-      scalefactor = (float) (scalefactor * 1.1);
-      scale = findScale();
+      rotate(1f, 0f);
     }
-    else if (evt.getKeyCode() == KeyEvent.VK_DOWN)
+    else if (shiftDown && keyCode == KeyEvent.VK_RIGHT)
     {
-      scalefactor = (float) (scalefactor * 0.9);
-      scale = findScale();
+      rotate(-1f, 0f);
     }
     else if (evt.getKeyChar() == 's')
     {
-      System.err.println("DEBUG: Rectangle selection"); // log.debug
-
-      if ((rectx2 != -1) && (recty2 != -1))
-      {
-        rectSelect(rectx1, recty1, rectx2, recty2);
-      }
+      // Cache.log.warn("DEBUG: Rectangle selection");
+      // todo not yet enabled as rectx2, recty2 are always -1
+      // need to set them in mouseDragged; JAL-1124
+      // if ((rectx2 != -1) && (recty2 != -1))
+      // {
+      // rectSelect(rectx1, recty1, rectx2, recty2);
+      // }
     }
 
     repaint();
   }
 
-  /**
-   * DOCUMENT ME!
-   * 
-   * @param evt
-   *          DOCUMENT ME!
-   */
+  @Override
+  public void zoom(float factor)
+  {
+    if (factor > 0f)
+    {
+      setScaleFactor(getScaleFactor() * factor);
+    }
+  }
+
   @Override
   public void mouseClicked(MouseEvent evt)
   {
   }
 
-  /**
-   * DOCUMENT ME!
-   * 
-   * @param evt
-   *          DOCUMENT ME!
-   */
   @Override
   public void mouseEntered(MouseEvent evt)
   {
   }
 
-  /**
-   * DOCUMENT ME!
-   * 
-   * @param evt
-   *          DOCUMENT ME!
-   */
   @Override
   public void mouseExited(MouseEvent evt)
   {
   }
 
-  /**
-   * DOCUMENT ME!
-   * 
-   * @param evt
-   *          DOCUMENT ME!
-   */
   @Override
   public void mouseReleased(MouseEvent evt)
   {
   }
 
   /**
-   * DOCUMENT ME!
-   * 
-   * @param evt
-   *          DOCUMENT ME!
+   * If the mouse press is at (within 2 pixels of) a sequence point, toggles
+   * (adds or removes) the corresponding sequence as a member of the viewport
+   * selection group. This supports configuring a group in the alignment by
+   * clicking on points in the PCA display.
    */
   @Override
   public void mousePressed(MouseEvent evt)
@@ -661,22 +561,15 @@ public class RotatableCanvas extends JPanel implements MouseListener,
     int x = evt.getX();
     int y = evt.getY();
 
-    mx = x;
-    my = y;
-
-    omx = mx;
-    omy = my;
-
-    startx = x;
-    starty = y;
+    mouseX = x;
+    mouseY = y;
 
-    rectx1 = x;
-    recty1 = y;
+    // rectx1 = x;
+    // recty1 = y;
+    // rectx2 = -1;
+    // recty2 = -1;
 
-    rectx2 = -1;
-    recty2 = -1;
-
-    SequenceI found = findPoint(x, y);
+    SequenceI found = findSequenceAtPoint(x, y);
 
     if (found != null)
     {
@@ -704,36 +597,37 @@ public class RotatableCanvas extends JPanel implements MouseListener,
     repaint();
   }
 
-  // private void fireSequenceSelectionEvent(Selection sel) {
-  // controller.handleSequenceSelectionEvent(new
-  // SequenceSelectionEvent(this,sel));
-  // }
+  /**
+   * Sets the tooltip to the name of the sequence within 2 pixels of the mouse
+   * position, or clears the tooltip if none found
+   */
   @Override
   public void mouseMoved(MouseEvent evt)
   {
-    SequenceI found = findPoint(evt.getX(), evt.getY());
+    SequenceI found = findSequenceAtPoint(evt.getX(), evt.getY());
 
-    if (found != null)
-    {
-      this.setToolTipText(found.getName());
-    }
-    else
-    {
-      this.setToolTipText(null);
-    }
+    this.setToolTipText(found == null ? null : found.getName());
   }
 
   /**
-   * DOCUMENT ME!
+   * Action handler for a mouse drag. Rotates the display around the X axis (for
+   * up/down mouse movement) and/or the Y axis (for left/right mouse movement).
    * 
    * @param evt
-   *          DOCUMENT ME!
    */
   @Override
   public void mouseDragged(MouseEvent evt)
   {
-    mx = evt.getX();
-    my = evt.getY();
+    int xPos = evt.getX();
+    int yPos = evt.getY();
+
+    if (xPos == mouseX && yPos == mouseY)
+    {
+      return;
+    }
+
+    int xDelta = xPos - mouseX;
+    int yDelta = yPos - mouseY;
 
     // Check if this is a rectangle drawing drag
     if ((evt.getModifiers() & InputEvent.BUTTON2_MASK) != 0)
@@ -743,113 +637,178 @@ public class RotatableCanvas extends JPanel implements MouseListener,
     }
     else
     {
-      rotmat.setIdentity();
+      rotate(xDelta, yDelta);
 
-      rotmat.rotate(my - omy, 'x');
-      rotmat.rotate(mx - omx, 'y');
+      mouseX = xPos;
+      mouseY = yPos;
 
-      for (int i = 0; i < npoint; i++)
-      {
-        SequencePoint sp = (SequencePoint) points.elementAt(i);
-        sp.coord[0] -= centre[0];
-        sp.coord[1] -= centre[1];
-        sp.coord[2] -= centre[2];
-
-        // Now apply the rotation matrix
-        sp.coord = rotmat.vectorMultiply(sp.coord);
-
-        // Now translate back again
-        sp.coord[0] += centre[0];
-        sp.coord[1] += centre[1];
-        sp.coord[2] += centre[2];
-      }
+      // findWidths();
 
-      for (int i = 0; i < 3; i++)
-      {
-        axes[i] = rotmat.vectorMultiply(axes[i]);
-      }
+      repaint();
+    }
+  }
+
+  @Override
+  public void rotate(float x, float y)
+  {
+    if (x == 0f && y == 0f)
+    {
+      return;
+    }
+
+    /*
+     * get the identity transformation...
+     */
+    RotatableMatrix rotmat = new RotatableMatrix();
+
+    /*
+     * rotate around the X axis for change in Y
+     * (mouse movement up/down); note we are equating a
+     * number of pixels with degrees of rotation here!
+     */
+    if (y != 0)
+    {
+      rotmat.rotate(y, Axis.X);
+    }
+
+    /*
+     * rotate around the Y axis for change in X
+     * (mouse movement left/right)
+     */
+    if (x != 0)
+    {
+      rotmat.rotate(x, Axis.Y);
+    }
+
+    /*
+     * apply the composite transformation to sequence points;
+     * update z min-max range (affects colour graduation), but not
+     * x or y min-max (as this would affect axis scaling)
+     */
+    float[] centre = getCentre();
+    float zMin = Float.MAX_VALUE;
+    float zMax = -Float.MAX_VALUE;
+
+    for (int i = 0; i < npoint; i++)
+    {
+      SequencePoint sp = sequencePoints.get(i);
+      sp.translate(-centre[0], -centre[1], -centre[2]);
+
+      // Now apply the rotation matrix
+      sp.coord = rotmat.vectorMultiply(sp.coord);
+
+      // Now translate back again
+      sp.translate(centre[0], centre[1], centre[2]);
+      
+      zMin = Math.min(zMin, sp.coord.z);
+      zMax = Math.max(zMax, sp.coord.z);
+    }
 
-      omx = mx;
-      omy = my;
+    seqMin[2] = zMin;
+    seqMax[2] = zMax;
 
-      paint(this.getGraphics());
+    /*
+     * rotate the x/y/z axis positions
+     */
+    for (int i = 0; i < DIMS; i++)
+    {
+      getAxisEndPoints()[i] = rotmat.vectorMultiply(getAxisEndPoints()[i]);
     }
   }
 
   /**
-   * DOCUMENT ME!
+   * Answers the x/y/z coordinates that are midway between the maximum and
+   * minimum sequence point values
+   * 
+   * @return
+   */
+  private float[] getCentre()
+  {
+    float xCentre = (seqMin[0] + seqMax[0]) / 2f;
+    float yCentre = (seqMin[1] + seqMax[1]) / 2f;
+    float zCentre = (seqMin[2] + seqMax[2]) / 2f;
+
+    return new float[] { xCentre, yCentre, zCentre };
+  }
+
+  /**
+   * Adds any sequences whose displayed points are within the given rectangle to
+   * the viewport's current selection. Intended for key 's' after dragging to
+   * select a region of the PCA.
    * 
    * @param x1
-   *          DOCUMENT ME!
    * @param y1
-   *          DOCUMENT ME!
    * @param x2
-   *          DOCUMENT ME!
    * @param y2
-   *          DOCUMENT ME!
    */
-  public void rectSelect(int x1, int y1, int x2, int y2)
+  protected void rectSelect(int x1, int y1, int x2, int y2)
   {
+    float[] centre = getCentre();
+
     for (int i = 0; i < npoint; i++)
     {
-      SequencePoint sp = (SequencePoint) points.elementAt(i);
-      int tmp1 = (int) (((sp.coord[0] - centre[0]) * scale)
+      SequencePoint sp = sequencePoints.get(i);
+      int tmp1 = (int) (((sp.coord.x - centre[0]) * getScaleFactor())
               + (getWidth() / 2.0));
-      int tmp2 = (int) (((sp.coord[1] - centre[1]) * scale)
+      int tmp2 = (int) (((sp.coord.y - centre[1]) * getScaleFactor())
               + (getHeight() / 2.0));
 
       if ((tmp1 > x1) && (tmp1 < x2) && (tmp2 > y1) && (tmp2 < y2))
       {
         if (av != null)
         {
+          SequenceI sequence = sp.getSequence();
           if (!av.getSelectionGroup().getSequences(null)
-                  .contains(sp.sequence))
+                  .contains(sequence))
           {
-            av.getSelectionGroup().addSequence(sp.sequence, true);
+            av.getSelectionGroup().addSequence(sequence, true);
           }
         }
       }
     }
-
-    // if (changedSel) {
-    // fireSequenceSelectionEvent(av.getSelection());
-    // }
   }
 
   /**
-   * DOCUMENT ME!
+   * Answers the first sequence found whose point on the display is within 2
+   * pixels of the given coordinates, or null if none is found
    * 
    * @param x
-   *          DOCUMENT ME!
    * @param y
-   *          DOCUMENT ME!
    * 
-   * @return DOCUMENT ME!
+   * @return
    */
-  public SequenceI findPoint(int x, int y)
+  protected SequenceI findSequenceAtPoint(int x, int y)
   {
     int halfwidth = getWidth() / 2;
     int halfheight = getHeight() / 2;
 
     int found = -1;
+    int pix = Math.min(getWidth(), getHeight());
+    float xWidth = Math.abs(seqMax[0] - seqMin[0]);
+    float yWidth = Math.abs(seqMax[1] - seqMin[1]);
+    float maxWidth = Math.max(xWidth, yWidth);
+    float scaleBy = pix * getScaleFactor() / (2f * maxWidth);
+
+    float[] centre = getCentre();
 
     for (int i = 0; i < npoint; i++)
     {
-      SequencePoint sp = (SequencePoint) points.elementAt(i);
-      int px = (int) ((sp.coord[0] - centre[0]) * scale)
+      SequencePoint sp = sequencePoints.get(i);
+      int px = (int) ((sp.coord.x - centre[0]) * scaleBy)
               + halfwidth;
-      int py = (int) ((sp.coord[1] - centre[1]) * scale)
+      int py = (int) ((sp.coord.y - centre[1]) * scaleBy)
               + halfheight;
 
-      if ((Math.abs(px - x) < 3) && (Math.abs(py - y) < 3))
+      if ((Math.abs(px - x) < NEARBY) && (Math.abs(py - y) < NEARBY))
       {
         found = i;
+        break;
       }
     }
 
     if (found != -1)
     {
-      return ((SequencePoint) points.elementAt(found)).sequence;
+      return sequencePoints.get(found).getSequence();
     }
     else
     {
@@ -857,9 +816,15 @@ public class RotatableCanvas extends JPanel implements MouseListener,
     }
   }
 
+  /**
+   * Answers the panel the PCA is associated with (all panels for this alignment
+   * if 'associate with all panels' is selected).
+   * 
+   * @return
+   */
   AlignmentPanel[] getAssociatedPanels()
   {
-    if (applyToAllViews)
+    if (isApplyToAllViews())
     {
       return PaintRefresher.getAssociatedPanels(av.getSequenceSetId());
     }
@@ -869,19 +834,114 @@ public class RotatableCanvas extends JPanel implements MouseListener,
     }
   }
 
+  public Color getBackgroundColour()
+  {
+    return getBgColour();
+  }
+
+  /**
+   * Zooms in or out in response to mouse wheel movement
+   */
+  @Override
+  public void mouseWheelMoved(MouseWheelEvent e)
+  {
+    double wheelRotation = e.getPreciseWheelRotation();
+    if (wheelRotation > 0)
+    {
+      zoom(ZOOM_IN);
+      repaint();
+    }
+    else if (wheelRotation < 0)
+    {
+      zoom(ZOOM_OUT);
+      repaint();
+    }
+  }
+
+  /**
+   * Answers the sequence point minimum [x, y, z] values. Note these are derived
+   * when sequence points are set, but x and y values are not updated on
+   * rotation (because this would result in changes to scaling).
+   * 
+   * @return
+   */
+  public float[] getSeqMin()
+  {
+    return seqMin;
+  }
+
+  /**
+   * Answers the sequence point maximum [x, y, z] values. Note these are derived
+   * when sequence points are set, but x and y values are not updated on
+   * rotation (because this would result in changes to scaling).
+   * 
+   * @return
+   */
+  public float[] getSeqMax()
+  {
+    return seqMax;
+  }
+
   /**
+   * Sets the minimum and maximum [x, y, z] positions for sequence points. For
+   * use when restoring a saved PCA from state data.
    * 
-   * @return x,y,z positions of point s (index into points) under current
-   *         transform.
+   * @param min
+   * @param max
    */
-  public double[] getPointPosition(int s)
+  public void setSeqMinMax(float[] min, float[] max)
+  {
+    seqMin = min;
+    seqMax = max;
+  }
+
+  public float getScaleFactor()
+  {
+    return scaleFactor;
+  }
+
+  public void setScaleFactor(float scaleFactor)
+  {
+    this.scaleFactor = scaleFactor;
+  }
+
+  public boolean isShowLabels()
   {
-    double pts[] = new double[3];
-    float[] p = ((SequencePoint) points.elementAt(s)).coord;
-    pts[0] = p[0];
-    pts[1] = p[1];
-    pts[2] = p[2];
-    return pts;
+    return showLabels;
   }
 
+  public void setShowLabels(boolean showLabels)
+  {
+    this.showLabels = showLabels;
+  }
+
+  public boolean isApplyToAllViews()
+  {
+    return applyToAllViews;
+  }
+
+  public void setApplyToAllViews(boolean applyToAllViews)
+  {
+    this.applyToAllViews = applyToAllViews;
+  }
+
+  public Point[] getAxisEndPoints()
+  {
+    return axisEndPoints;
+  }
+
+  public void setAxisEndPoints(Point[] axisEndPoints)
+  {
+    this.axisEndPoints = axisEndPoints;
+  }
+
+  public Color getBgColour()
+  {
+    return bgColour;
+  }
+
+  public void setBgColour(Color bgColour)
+  {
+    this.bgColour = bgColour;
+  }
 }
index e6bba02..b95c569 100755 (executable)
@@ -23,7 +23,6 @@ package jalview.gui;
 import jalview.datamodel.ColumnSelection;
 import jalview.datamodel.HiddenColumns;
 import jalview.datamodel.SequenceGroup;
-import jalview.datamodel.SequenceI;
 import jalview.renderer.ScaleRenderer;
 import jalview.renderer.ScaleRenderer.ScaleMark;
 import jalview.util.MessageManager;
@@ -35,6 +34,7 @@ import java.awt.Color;
 import java.awt.FontMetrics;
 import java.awt.Graphics;
 import java.awt.Graphics2D;
+import java.awt.Point;
 import java.awt.RenderingHints;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
@@ -158,7 +158,12 @@ public class ScalePanel extends JPanel
   protected void rightMouseButtonPressed(MouseEvent evt, final int res)
   {
     JPopupMenu pop = new JPopupMenu();
-    if (reveal != null)
+
+    /*
+     * grab the hidden range in case mouseMoved nulls it
+     */
+    final int[] hiddenRange = reveal;
+    if (hiddenRange != null)
     {
       JMenuItem item = new JMenuItem(
               MessageManager.getString("label.reveal"));
@@ -167,8 +172,9 @@ public class ScalePanel extends JPanel
         @Override
         public void actionPerformed(ActionEvent e)
         {
-          av.showColumn(reveal[0]);
+          av.showColumn(hiddenRange[0]);
           reveal = null;
+          ap.updateLayout();
           ap.paintAlignment(true, true);
           av.sendSelection();
         }
@@ -185,6 +191,7 @@ public class ScalePanel extends JPanel
           {
             av.showAllHiddenColumns();
             reveal = null;
+            ap.updateLayout();
             ap.paintAlignment(true, true);
             av.sendSelection();
           }
@@ -209,6 +216,7 @@ public class ScalePanel extends JPanel
             av.setSelectionGroup(null);
           }
 
+          ap.updateLayout();
           ap.paintAlignment(true, true);
           av.sendSelection();
         }
@@ -237,15 +245,7 @@ public class ScalePanel extends JPanel
     }
 
     av.getColumnSelection().addElement(res);
-    SequenceGroup sg = new SequenceGroup();
-    // try to be as quick as possible
-    SequenceI[] iVec = av.getAlignment().getSequencesArray();
-    for (int i = 0; i < iVec.length; i++)
-    {
-      sg.addSequence(iVec[i], false);
-      iVec[i] = null;
-    }
-    iVec = null;
+    SequenceGroup sg = new SequenceGroup(av.getAlignment().getSequences());
     sg.setStartRes(res);
     sg.setEndRes(res);
 
@@ -266,29 +266,28 @@ public class ScalePanel extends JPanel
   }
 
   /**
-   * DOCUMENT ME!
+   * Action on mouseUp is to set the limit of the current selection group (if
+   * there is one) and broadcast the selection
    * 
    * @param evt
-   *          DOCUMENT ME!
    */
   @Override
   public void mouseReleased(MouseEvent evt)
   {
+    boolean wasDragging = mouseDragging;
     mouseDragging = false;
+    ap.getSeqPanel().stopScrolling();
 
-    int res = (evt.getX() / av.getCharWidth())
+    int xCords = Math.max(0, evt.getX()); // prevent negative X coordinates
+    int res = (xCords / av.getCharWidth())
             + av.getRanges().getStartRes();
-
     if (av.hasHiddenColumns())
     {
       res = av.getAlignment().getHiddenColumns()
               .visibleToAbsoluteColumn(res);
     }
-
-    if (res >= av.getAlignment().getWidth())
-    {
-      res = av.getAlignment().getWidth() - 1;
-    }
+    res = Math.min(res, av.getRanges().getEndRes());
+    res = Math.max(0, res);
 
     if (!stretchingGroup)
     {
@@ -315,15 +314,26 @@ public class ScalePanel extends JPanel
       {
         sg.setStartRes(res);
       }
+      if (wasDragging)
+      {
+        min = Math.min(res, min);
+        max = Math.max(res, max);
+        av.getColumnSelection().stretchGroup(res, sg, min, max);
+      }
     }
     stretchingGroup = false;
     ap.paintAlignment(false, false);
+    av.isSelectionGroupChanged(true);
+    av.isColSelChanged(true);
     av.sendSelection();
   }
 
   /**
    * Action on dragging the mouse in the scale panel is to expand or shrink the
-   * selection group range (including any hidden columns that it spans)
+   * selection group range (including any hidden columns that it spans). Note
+   * that the selection is only broadcast at the start of the drag (on
+   * mousePressed) and at the end (on mouseReleased), to avoid overload
+   * redrawing of other views.
    * 
    * @param evt
    */
@@ -356,16 +366,22 @@ public class ScalePanel extends JPanel
   {
     if (mouseDragging)
     {
-      ap.getSeqPanel().scrollCanvas(null);
+      ap.getSeqPanel().stopScrolling();
     }
   }
 
+  /**
+   * Action on leaving the panel bounds with mouse drag in progress is to start
+   * scrolling the alignment in the direction of the mouse. To restrict
+   * scrolling to left-right (not up-down), the y-value of the mouse position is
+   * replaced with zero.
+   */
   @Override
   public void mouseExited(MouseEvent evt)
   {
     if (mouseDragging)
     {
-      ap.getSeqPanel().scrollCanvas(evt);
+      ap.getSeqPanel().startScrolling(new Point(evt.getX(), 0));
     }
   }
 
index 5c404f0..b3fcc54 100755 (executable)
@@ -55,6 +55,11 @@ import javax.swing.JComponent;
  */
 public class SeqCanvas extends JComponent implements ViewportListenerI
 {
+  /*
+   * pixels gap between sequences and annotations when in wrapped mode
+   */
+  static final int SEQS_ANNOTATION_GAP = 3;
+
   private static final String ZEROS = "0000000000";
 
   final FeatureRenderer fr;
@@ -82,9 +87,9 @@ public class SeqCanvas extends JComponent implements ViewportListenerI
 
   private int labelWidthWest; // label left width in pixels if shown
 
-  private int wrappedSpaceAboveAlignment; // gap between widths
+  int wrappedSpaceAboveAlignment; // gap between widths
 
-  private int wrappedRepeatHeightPx; // height in pixels of wrapped width
+  int wrappedRepeatHeightPx; // height in pixels of wrapped width
 
   private int wrappedVisibleWidths; // number of wrapped widths displayed
 
@@ -559,7 +564,7 @@ public class SeqCanvas extends JComponent implements ViewportListenerI
     calculateWrappedGeometry(canvasWidth, canvasHeight);
 
     /*
-     * draw one width at a time (excluding any scales or annotation shown),
+     * draw one width at a time (excluding any scales shown),
      * until we have run out of either alignment or vertical space available
      */
     int ypos = wrappedSpaceAboveAlignment;
@@ -606,14 +611,22 @@ public class SeqCanvas extends JComponent implements ViewportListenerI
             * (av.getScaleAboveWrapped() ? 2 : 1);
 
     /*
-     * height in pixels of the wrapped widths
+     * compute height in pixels of the wrapped widths
+     * - start with space above plus sequences
      */
     wrappedRepeatHeightPx = wrappedSpaceAboveAlignment;
-    // add sequences
     wrappedRepeatHeightPx += av.getAlignment().getHeight()
             * charHeight;
-    // add annotations panel height if shown
-    wrappedRepeatHeightPx += getAnnotationHeight();
+
+    /*
+     * add annotations panel height if shown
+     * also gap between sequences and annotations
+     */
+    if (av.isShowAnnotation())
+    {
+      wrappedRepeatHeightPx += getAnnotationHeight();
+      wrappedRepeatHeightPx += SEQS_ANNOTATION_GAP; // 3px
+    }
 
     /*
      * number of visible widths (the last one may be part height),
@@ -657,8 +670,9 @@ public class SeqCanvas extends JComponent implements ViewportListenerI
    * @param endColumn
    * @param canvasHeight
    */
-  protected void drawWrappedWidth(Graphics g, int ypos, int startColumn,
-          int endColumn, int canvasHeight)
+  protected void drawWrappedWidth(Graphics g, final int ypos,
+          final int startColumn, final int endColumn,
+          final int canvasHeight)
   {
     ViewportRanges ranges = av.getRanges();
     int viewportWidth = ranges.getViewportWidth();
@@ -705,7 +719,8 @@ public class SeqCanvas extends JComponent implements ViewportListenerI
 
     if (av.isShowAnnotation())
     {
-      g.translate(0, cHeight + ypos + 3);
+      final int yShift = cHeight + ypos + SEQS_ANNOTATION_GAP;
+      g.translate(0, yShift);
       if (annotations == null)
       {
         annotations = new AnnotationPanel(av);
@@ -713,7 +728,7 @@ public class SeqCanvas extends JComponent implements ViewportListenerI
 
       annotations.renderer.drawComponent(annotations, av, g, -1,
               startColumn, endx + 1);
-      g.translate(0, -cHeight - ypos - 3);
+      g.translate(0, -yShift);
     }
     g.setClip(clip);
     g.translate(-xOffset, 0);
@@ -855,13 +870,7 @@ public class SeqCanvas extends JComponent implements ViewportListenerI
     int startx = startRes;
     int endx;
     int ypos = hgap; // vertical offset
-    int maxwidth = av.getAlignment().getWidth();
-
-    if (av.hasHiddenColumns())
-    {
-      maxwidth = av.getAlignment().getHiddenColumns()
-              .absoluteToVisibleColumn(maxwidth);
-    }
+    int maxwidth = av.getAlignment().getVisibleWidth();
 
     // chop the wrapped alignment extent up into panel-sized blocks and treat
     // each block as if it were a block from an unwrapped alignment
@@ -1646,7 +1655,7 @@ public class SeqCanvas extends JComponent implements ViewportListenerI
       }
       ViewportRanges vpRanges = av.getRanges();
 
-      int range = vpRanges.getEndRes() - vpRanges.getStartRes();
+      int range = vpRanges.getEndRes() - vpRanges.getStartRes() + 1;
       if (scrollX > range)
       {
         scrollX = range;
@@ -1715,10 +1724,10 @@ public class SeqCanvas extends JComponent implements ViewportListenerI
   {
     ViewportRanges ranges = av.getRanges();
 
-    if (Math.abs(scrollX) > ranges.getViewportWidth())
+    if (Math.abs(scrollX) >= ranges.getViewportWidth())
     {
       /*
-       * shift of more than one view width is 
+       * shift of one view width or more is 
        * overcomplicated to handle in this method
        */
       fastPaint = false;
@@ -1909,10 +1918,17 @@ public class SeqCanvas extends JComponent implements ViewportListenerI
 
       while (y >= 0)
       {
+        /*
+         * shift 'widthToCopy' residues by 'positions' places to the right
+         */
         gg.copyArea(copyFromLeftStart, y, widthToCopy, heightToCopy,
                 positions * charWidth, 0);
         if (y > 0)
         {
+          /*
+           * copy 'positions' residue from the row above (right hand end)
+           * to this row's left hand end
+           */
           gg.copyArea(copyFromRightStart, y - wrappedRepeatHeightPx,
                   positions * charWidth, heightToCopy, -widthToCopy,
                   wrappedRepeatHeightPx);
index 8b2e7bc..4a1a9ee 100644 (file)
@@ -25,6 +25,7 @@ import jalview.bin.Cache;
 import jalview.commands.EditCommand;
 import jalview.commands.EditCommand.Action;
 import jalview.commands.EditCommand.Edit;
+import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.ColumnSelection;
 import jalview.datamodel.HiddenColumns;
@@ -48,6 +49,7 @@ import jalview.util.MappingUtils;
 import jalview.util.MessageManager;
 import jalview.util.Platform;
 import jalview.viewmodel.AlignmentViewport;
+import jalview.viewmodel.ViewportRanges;
 
 import java.awt.BorderLayout;
 import java.awt.Color;
@@ -76,6 +78,82 @@ public class SeqPanel extends JPanel
         implements MouseListener, MouseMotionListener, MouseWheelListener,
         SequenceListener, SelectionListener
 {
+  /*
+   * a class that holds computed mouse position
+   * - column of the alignment (0...)
+   * - sequence offset (0...)
+   * - annotation row offset (0...)
+   * where annotation offset is -1 unless the alignment is shown
+   * in wrapped mode, annotations are shown, and the mouse is
+   * over an annnotation row
+   */
+  static class MousePos
+  {
+    /*
+     * alignment column position of cursor (0...)
+     */
+    final int column;
+
+    /*
+     * index in alignment of sequence under cursor,
+     * or nearest above if cursor is not over a sequence
+     */
+    final int seqIndex;
+
+    /*
+     * index in annotations array of annotation under the cursor
+     * (only possible in wrapped mode with annotations shown),
+     * or -1 if cursor is not over an annotation row
+     */
+    final int annotationIndex;
+
+    MousePos(int col, int seq, int ann)
+    {
+      column = col;
+      seqIndex = seq;
+      annotationIndex = ann;
+    }
+
+    boolean isOverAnnotation()
+    {
+      return annotationIndex != -1;
+    }
+
+    @Override
+    public boolean equals(Object obj)
+    {
+      if (obj == null || !(obj instanceof MousePos))
+      {
+        return false;
+      }
+      MousePos o = (MousePos) obj;
+      boolean b = (column == o.column && seqIndex == o.seqIndex
+              && annotationIndex == o.annotationIndex);
+      // System.out.println(obj + (b ? "= " : "!= ") + this);
+      return b;
+    }
+
+    /**
+     * A simple hashCode that ensures that instances that satisfy equals() have
+     * the same hashCode
+     */
+    @Override
+    public int hashCode()
+    {
+      return column + seqIndex + annotationIndex;
+    }
+
+    /**
+     * toString method for debug output purposes only
+     */
+    @Override
+    public String toString()
+    {
+      return String.format("c%d:s%d:a%d", column, seqIndex,
+              annotationIndex);
+    }
+  }
+
   private static final int MAX_TOOLTIP_LENGTH = 300;
 
   public SeqCanvas seqCanvas;
@@ -83,18 +161,13 @@ public class SeqPanel extends JPanel
   public AlignmentPanel ap;
 
   /*
-   * last column position for mouseMoved event
+   * last position for mouseMoved event
    */
-  private int lastMouseColumn;
+  private MousePos lastMousePosition;
 
-  /*
-   * last sequence offset for mouseMoved event
-   */
-  private int lastMouseSeq;
-
-  protected int lastres;
+  protected int editLastRes;
 
-  protected int startseq;
+  protected int editStartSeq;
 
   protected AlignViewport av;
 
@@ -176,9 +249,6 @@ public class SeqPanel extends JPanel
       ssm.addStructureViewerListener(this);
       ssm.addSelectionListener(this);
     }
-
-    lastMouseColumn = -1;
-    lastMouseSeq = -1;
   }
 
   int startWrapBlock = -1;
@@ -186,6 +256,71 @@ public class SeqPanel extends JPanel
   int wrappedBlock = -1;
 
   /**
+   * Computes the column and sequence row (and possibly annotation row when in
+   * wrapped mode) for the given mouse position
+   * 
+   * @param evt
+   * @return
+   */
+  MousePos findMousePosition(MouseEvent evt)
+  {
+    int col = findColumn(evt);
+    int seqIndex = -1;
+    int annIndex = -1;
+    int y = evt.getY();
+
+    int charHeight = av.getCharHeight();
+    int alignmentHeight = av.getAlignment().getHeight();
+    if (av.getWrapAlignment())
+    {
+      seqCanvas.calculateWrappedGeometry(seqCanvas.getWidth(),
+              seqCanvas.getHeight());
+
+      /*
+       * yPos modulo height of repeating width
+       */
+      int yOffsetPx = y % seqCanvas.wrappedRepeatHeightPx;
+
+      /*
+       * height of sequences plus space / scale above,
+       * plus gap between sequences and annotations
+       */
+      int alignmentHeightPixels = seqCanvas.wrappedSpaceAboveAlignment
+              + alignmentHeight * charHeight
+              + SeqCanvas.SEQS_ANNOTATION_GAP;
+      if (yOffsetPx >= alignmentHeightPixels)
+      {
+        /*
+         * mouse is over annotations; find annotation index, also set
+         * last sequence above (for backwards compatible behaviour)
+         */
+        AlignmentAnnotation[] anns = av.getAlignment()
+                .getAlignmentAnnotation();
+        int rowOffsetPx = yOffsetPx - alignmentHeightPixels;
+        annIndex = AnnotationPanel.getRowIndex(rowOffsetPx, anns);
+        seqIndex = alignmentHeight - 1;
+      }
+      else
+      {
+        /*
+         * mouse is over sequence (or the space above sequences)
+         */
+        yOffsetPx -= seqCanvas.wrappedSpaceAboveAlignment;
+        if (yOffsetPx >= 0)
+        {
+          seqIndex = Math.min(yOffsetPx / charHeight, alignmentHeight - 1);
+        }
+      }
+    }
+    else
+    {
+      seqIndex = Math.min((y / charHeight) + av.getRanges().getStartSeq(),
+              alignmentHeight - 1);
+    }
+
+    return new MousePos(col, seqIndex, annIndex);
+  }
+  /**
    * Returns the aligned sequence position (base 0) at the mouse position, or
    * the closest visible one
    * 
@@ -197,10 +332,11 @@ public class SeqPanel extends JPanel
     int res = 0;
     int x = evt.getX();
 
-    int startRes = av.getRanges().getStartRes();
+    final int startRes = av.getRanges().getStartRes();
+    final int charWidth = av.getCharWidth();
+
     if (av.getWrapAlignment())
     {
-
       int hgap = av.getCharHeight();
       if (av.getScaleAboveWrapped())
       {
@@ -212,35 +348,40 @@ public class SeqPanel extends JPanel
 
       int y = evt.getY();
       y = Math.max(0, y - hgap);
-      x = Math.max(0, x - seqCanvas.getLabelWidthWest());
+      x -= seqCanvas.getLabelWidthWest();
+      if (x < 0)
+      {
+        // mouse is over left scale
+        return -1;
+      }
 
       int cwidth = seqCanvas.getWrappedCanvasWidth(this.getWidth());
       if (cwidth < 1)
       {
         return 0;
       }
+      if (x >= cwidth * charWidth)
+      {
+        // mouse is over right scale
+        return -1;
+      }
 
       wrappedBlock = y / cHeight;
       wrappedBlock += startRes / cwidth;
       // allow for wrapped view scrolled right (possible from Overview)
       int startOffset = startRes % cwidth;
       res = wrappedBlock * cwidth + startOffset
-              + +Math.min(cwidth - 1, x / av.getCharWidth());
+              + Math.min(cwidth - 1, x / charWidth);
     }
     else
     {
-      if (x > seqCanvas.getX() + seqCanvas.getWidth())
-      {
-        // make sure we calculate relative to visible alignment, rather than
-        // right-hand gutter
-        x = seqCanvas.getX() + seqCanvas.getWidth();
-      }
-      res = (x / av.getCharWidth()) + startRes;
-      if (res > av.getRanges().getEndRes())
-      {
-        // moused off right
-        res = av.getRanges().getEndRes();
-      }
+      /*
+       * make sure we calculate relative to visible alignment, 
+       * rather than right-hand gutter
+       */
+      x = Math.min(x, seqCanvas.getX() + seqCanvas.getWidth());
+      res = (x / charWidth) + startRes;
+      res = Math.min(res, av.getRanges().getEndRes());
     }
 
     if (av.hasHiddenColumns())
@@ -250,38 +391,6 @@ public class SeqPanel extends JPanel
     }
 
     return res;
-
-  }
-
-  int findSeq(MouseEvent evt)
-  {
-    int seq = 0;
-    int y = evt.getY();
-
-    if (av.getWrapAlignment())
-    {
-      int hgap = av.getCharHeight();
-      if (av.getScaleAboveWrapped())
-      {
-        hgap += av.getCharHeight();
-      }
-
-      int cHeight = av.getAlignment().getHeight() * av.getCharHeight()
-              + hgap + seqCanvas.getAnnotationHeight();
-
-      y -= hgap;
-
-      seq = Math.min((y % cHeight) / av.getCharHeight(),
-              av.getAlignment().getHeight() - 1);
-    }
-    else
-    {
-      seq = Math.min(
-              (y / av.getCharHeight()) + av.getRanges().getStartSeq(),
-              av.getAlignment().getHeight() - 1);
-    }
-
-    return seq;
   }
 
   /**
@@ -303,8 +412,8 @@ public class SeqPanel extends JPanel
       /*
        * Tidy up come what may...
        */
-      startseq = -1;
-      lastres = -1;
+      editStartSeq = -1;
+      editLastRes = -1;
       editingSeqs = false;
       groupEditing = false;
       keyboardNo1 = null;
@@ -532,8 +641,8 @@ public class SeqPanel extends JPanel
   void insertGapAtCursor(boolean group)
   {
     groupEditing = group;
-    startseq = seqCanvas.cursorY;
-    lastres = seqCanvas.cursorX;
+    editStartSeq = seqCanvas.cursorY;
+    editLastRes = seqCanvas.cursorX;
     editSequence(true, false, seqCanvas.cursorX + getKeyboardNo1());
     endEditing();
   }
@@ -541,8 +650,8 @@ public class SeqPanel extends JPanel
   void deleteGapAtCursor(boolean group)
   {
     groupEditing = group;
-    startseq = seqCanvas.cursorY;
-    lastres = seqCanvas.cursorX + getKeyboardNo1();
+    editStartSeq = seqCanvas.cursorY;
+    editLastRes = seqCanvas.cursorX + getKeyboardNo1();
     editSequence(false, false, seqCanvas.cursorX);
     endEditing();
   }
@@ -551,8 +660,8 @@ public class SeqPanel extends JPanel
   {
     // TODO not called - delete?
     groupEditing = group;
-    startseq = seqCanvas.cursorY;
-    lastres = seqCanvas.cursorX;
+    editStartSeq = seqCanvas.cursorY;
+    editLastRes = seqCanvas.cursorX;
     editSequence(false, true, seqCanvas.cursorX + getKeyboardNo1());
     endEditing();
   }
@@ -617,24 +726,31 @@ public class SeqPanel extends JPanel
   @Override
   public void mouseReleased(MouseEvent evt)
   {
+    MousePos pos = findMousePosition(evt);
+    if (pos.isOverAnnotation() || pos.seqIndex == -1 || pos.column == -1)
+    {
+      return;
+    }
+
     boolean didDrag = mouseDragging; // did we come here after a drag
     mouseDragging = false;
     mouseWheelPressed = false;
 
     if (evt.isPopupTrigger()) // Windows: mouseReleased
     {
-      showPopupMenu(evt);
+      showPopupMenu(evt, pos);
       evt.consume();
       return;
     }
 
-    if (!editingSeqs)
+    if (editingSeqs)
+    {
+      endEditing();
+    }
+    else
     {
       doMouseReleasedDefineMode(evt, didDrag);
-      return;
     }
-
-    endEditing();
   }
 
   /**
@@ -647,6 +763,11 @@ public class SeqPanel extends JPanel
   public void mousePressed(MouseEvent evt)
   {
     lastMousePress = evt.getPoint();
+    MousePos pos = findMousePosition(evt);
+    if (pos.isOverAnnotation() || pos.seqIndex == -1 || pos.column == -1)
+    {
+      return;
+    }
 
     if (SwingUtilities.isMiddleMouseButton(evt))
     {
@@ -665,28 +786,23 @@ public class SeqPanel extends JPanel
     }
     else
     {
-      doMousePressedDefineMode(evt);
+      doMousePressedDefineMode(evt, pos);
       return;
     }
 
-    int seq = findSeq(evt);
-    int res = findColumn(evt);
-
-    if (seq < 0 || res < 0)
-    {
-      return;
-    }
+    int seq = pos.seqIndex;
+    int res = pos.column;
 
     if ((seq < av.getAlignment().getHeight())
             && (res < av.getAlignment().getSequenceAt(seq).getLength()))
     {
-      startseq = seq;
-      lastres = res;
+      editStartSeq = seq;
+      editLastRes = res;
     }
     else
     {
-      startseq = -1;
-      lastres = -1;
+      editStartSeq = -1;
+      editLastRes = -1;
     }
 
     return;
@@ -731,7 +847,7 @@ public class SeqPanel extends JPanel
       // over residue to change abruptly, causing highlighted residue in panel 2
       // to change, causing a scroll in panel 1 etc)
       ap.setToScrollComplementPanel(false);
-      wasScrolled = ap.scrollToPosition(results, false);
+      wasScrolled = ap.scrollToPosition(results);
       if (wasScrolled)
       {
         seqCanvas.revalidate();
@@ -777,23 +893,32 @@ public class SeqPanel extends JPanel
       mouseDragged(evt);
     }
 
-    final int column = findColumn(evt);
-    final int seq = findSeq(evt);
+    final MousePos mousePos = findMousePosition(evt);
+    if (mousePos.equals(lastMousePosition))
+    {
+      /*
+       * just a pixel move without change of 'cell'
+       */
+      return;
+    }
+    lastMousePosition = mousePos;
 
-    if (column < 0 || seq < 0 || seq >= av.getAlignment().getHeight())
+    if (mousePos.isOverAnnotation())
     {
-      lastMouseSeq = -1;
+      mouseMovedOverAnnotation(mousePos);
       return;
     }
-    if (column == lastMouseColumn && seq == lastMouseSeq)
+    final int seq = mousePos.seqIndex;
+
+    final int column = mousePos.column;
+    if (column < 0 || seq < 0 || seq >= av.getAlignment().getHeight())
     {
-      /*
-       * just a pixel move without change of residue
-       */
+      lastMousePosition = null;
+      setToolTipText(null);
+      lastTooltip = null;
+      ap.alignFrame.setStatus("");
       return;
     }
-    lastMouseColumn = column;
-    lastMouseSeq = seq;
 
     SequenceI sequence = av.getAlignment().getSequenceAt(seq);
 
@@ -871,6 +996,35 @@ public class SeqPanel extends JPanel
     }
   }
 
+  /**
+   * When the view is in wrapped mode, and the mouse is over an annotation row,
+   * shows the corresponding tooltip and status message (if any)
+   * 
+   * @param pos
+   * @param column
+   */
+  protected void mouseMovedOverAnnotation(MousePos pos)
+  {
+    final int column = pos.column;
+    final int rowIndex = pos.annotationIndex;
+
+    if (column < 0 || !av.getWrapAlignment() || !av.isShowAnnotation()
+            || rowIndex < 0)
+    {
+      return;
+    }
+    AlignmentAnnotation[] anns = av.getAlignment().getAlignmentAnnotation();
+
+    String tooltip = AnnotationPanel.buildToolTip(anns[rowIndex], column,
+            anns);
+    setToolTipText(tooltip);
+    lastTooltip = tooltip;
+
+    String msg = AnnotationPanel.getStatusMessage(av.getAlignment(), column,
+            anns[rowIndex]);
+    ap.alignFrame.setStatus(msg);
+  }
+
   private Point lastp = null;
 
   /*
@@ -881,20 +1035,26 @@ public class SeqPanel extends JPanel
   @Override
   public Point getToolTipLocation(MouseEvent event)
   {
-    int x = event.getX(), w = getWidth();
-    int wdth = (w - x < 200) ? -(w / 2) : 5; // switch sides when tooltip is too
-    // close to edge
+    if (tooltipText == null || tooltipText.length() <= 6)
+    {
+      lastp = null;
+      return null;
+    }
+
+    int x = event.getX();
+    int w = getWidth();
+    // switch sides when tooltip is too close to edge
+    int wdth = (w - x < 200) ? -(w / 2) : 5;
     Point p = lastp;
     if (!event.isShiftDown() || p == null)
     {
-      p = (tooltipText != null && tooltipText.length() > 6)
-              ? new Point(event.getX() + wdth, event.getY() - 20)
-              : null;
+      p = new Point(event.getX() + wdth, event.getY() - 20);
+      lastp = p;
     }
     /*
-     * TODO: try to modify position region is not obcured by tooltip
+     * TODO: try to set position so region is not obscured by tooltip
      */
-    return lastp = p;
+    return p;
   }
 
   String lastTooltip;
@@ -997,7 +1157,7 @@ public class SeqPanel extends JPanel
 
       text.append(" (").append(Integer.toString(residuePos)).append(")");
     }
-    ap.alignFrame.statusBar.setText(text.toString());
+    ap.alignFrame.setStatus(text.toString());
   }
 
   /**
@@ -1039,6 +1199,12 @@ public class SeqPanel extends JPanel
   @Override
   public void mouseDragged(MouseEvent evt)
   {
+    MousePos pos = findMousePosition(evt);
+    if (pos.isOverAnnotation() || pos.column == -1)
+    {
+      return;
+    }
+
     if (mouseWheelPressed)
     {
       boolean inSplitFrame = ap.av.getCodingComplement() != null;
@@ -1134,23 +1300,23 @@ public class SeqPanel extends JPanel
 
     if (!editingSeqs)
     {
-      doMouseDraggedDefineMode(evt);
+      dragStretchGroup(evt);
       return;
     }
 
-    int res = findColumn(evt);
+    int res = pos.column;
 
     if (res < 0)
     {
       res = 0;
     }
 
-    if ((lastres == -1) || (lastres == res))
+    if ((editLastRes == -1) || (editLastRes == res))
     {
       return;
     }
 
-    if ((res < av.getAlignment().getWidth()) && (res < lastres))
+    if ((res < av.getAlignment().getWidth()) && (res < editLastRes))
     {
       // dragLeft, delete gap
       editSequence(false, false, res);
@@ -1161,22 +1327,46 @@ public class SeqPanel extends JPanel
     }
 
     mouseDragging = true;
-    if ((scrollThread != null) && (scrollThread.isRunning()))
+    if (scrollThread != null)
     {
-      scrollThread.setEvent(evt);
+      scrollThread.setMousePosition(evt.getPoint());
     }
   }
 
-  // TODO: Make it more clever than many booleans
+  /**
+   * Edits the sequence to insert or delete one or more gaps, in response to a
+   * mouse drag or cursor mode command. The number of inserts/deletes may be
+   * specified with the cursor command, or else depends on the mouse event
+   * (normally one column, but potentially more for a fast mouse drag).
+   * <p>
+   * Delete gaps is limited to the number of gaps left of the cursor position
+   * (mouse drag), or at or right of the cursor position (cursor mode).
+   * <p>
+   * In group editing mode (Ctrl or Cmd down), the edit acts on all sequences in
+   * the current selection group.
+   * <p>
+   * In locked editing mode (with a selection group present), inserts/deletions
+   * within the selection group are limited to its boundaries (and edits outside
+   * the group stop at its border).
+   * 
+   * @param insertGap
+   *          true to insert gaps, false to delete gaps
+   * @param editSeq
+   *          (unused parameter)
+   * @param startres
+   *          the column at which to perform the action; the number of columns
+   *          affected depends on <code>this.editLastRes</code> (cursor column
+   *          position)
+   */
   synchronized void editSequence(boolean insertGap, boolean editSeq,
-          int startres)
+          final int startres)
   {
     int fixedLeft = -1;
     int fixedRight = -1;
     boolean fixedColumns = false;
     SequenceGroup sg = av.getSelectionGroup();
 
-    SequenceI seq = av.getAlignment().getSequenceAt(startseq);
+    final SequenceI seq = av.getAlignment().getSequenceAt(editStartSeq);
 
     // No group, but the sequence may represent a group
     if (!groupEditing && av.hasHiddenRows())
@@ -1188,30 +1378,38 @@ public class SeqPanel extends JPanel
       }
     }
 
-    StringBuilder message = new StringBuilder(64);
+    StringBuilder message = new StringBuilder(64); // for status bar
+
+    /*
+     * make a name for the edit action, for
+     * status bar message and Undo/Redo menu
+     */
+    String label = null;
     if (groupEditing)
     {
-      message.append("Edit group:");
-      if (editCommand == null)
-      {
-        editCommand = new EditCommand(
-                MessageManager.getString("action.edit_group"));
-      }
+        message.append("Edit group:");
+      label = MessageManager.getString("action.edit_group");
     }
     else
     {
-      message.append("Edit sequence: " + seq.getName());
-      String label = seq.getName();
+        message.append("Edit sequence: " + seq.getName());
+      label = seq.getName();
       if (label.length() > 10)
       {
         label = label.substring(0, 10);
       }
-      if (editCommand == null)
-      {
-        editCommand = new EditCommand(MessageManager
-                .formatMessage("label.edit_params", new String[]
-                { label }));
-      }
+      label = MessageManager.formatMessage("label.edit_params",
+              new String[]
+              { label });
+    }
+
+    /*
+     * initialise the edit command if there is not
+     * already one being extended
+     */
+    if (editCommand == null)
+    {
+      editCommand = new EditCommand(label);
     }
 
     if (insertGap)
@@ -1223,12 +1421,17 @@ public class SeqPanel extends JPanel
       message.append(" delete ");
     }
 
-    message.append(Math.abs(startres - lastres) + " gaps.");
-    ap.alignFrame.statusBar.setText(message.toString());
+    message.append(Math.abs(startres - editLastRes) + " gaps.");
+    ap.alignFrame.setStatus(message.toString());
 
-    // Are we editing within a selection group?
-    if (groupEditing || (sg != null
-            && sg.getSequences(av.getHiddenRepSequences()).contains(seq)))
+    /*
+     * is there a selection group containing the sequence being edited?
+     * if so the boundary of the group is the limit of the edit
+     * (but the edit may be inside or outside the selection group)
+     */
+    boolean inSelectionGroup = sg != null
+            && sg.getSequences(av.getHiddenRepSequences()).contains(seq);
+    if (groupEditing || inSelectionGroup)
     {
       fixedColumns = true;
 
@@ -1247,10 +1450,10 @@ public class SeqPanel extends JPanel
       fixedLeft = sg.getStartRes();
       fixedRight = sg.getEndRes();
 
-      if ((startres < fixedLeft && lastres >= fixedLeft)
-              || (startres >= fixedLeft && lastres < fixedLeft)
-              || (startres > fixedRight && lastres <= fixedRight)
-              || (startres <= fixedRight && lastres > fixedRight))
+      if ((startres < fixedLeft && editLastRes >= fixedLeft)
+              || (startres >= fixedLeft && editLastRes < fixedLeft)
+              || (startres > fixedRight && editLastRes <= fixedRight)
+              || (startres <= fixedRight && editLastRes > fixedRight))
       {
         endEditing();
         return;
@@ -1276,8 +1479,8 @@ public class SeqPanel extends JPanel
       int y2 = av.getAlignment().getHiddenColumns()
               .getNextHiddenBoundary(false, startres);
 
-      if ((insertGap && startres > y1 && lastres < y1)
-              || (!insertGap && startres < y2 && lastres > y2))
+      if ((insertGap && startres > y1 && editLastRes < y1)
+              || (!insertGap && startres < y2 && editLastRes > y2))
       {
         endEditing();
         return;
@@ -1298,6 +1501,54 @@ public class SeqPanel extends JPanel
       }
     }
 
+    boolean success = doEditSequence(insertGap, editSeq, startres,
+            fixedRight, fixedColumns, sg);
+
+    /*
+     * report what actually happened (might be less than
+     * what was requested), by inspecting the edit commands added
+     */
+    String msg = getEditStatusMessage(editCommand);
+    ap.alignFrame.setStatus(msg == null ? " " : msg);
+    if (!success)
+    {
+      endEditing();
+    }
+
+    editLastRes = startres;
+    seqCanvas.repaint();
+  }
+
+  /**
+   * A helper method that performs the requested editing to insert or delete
+   * gaps (if possible). Answers true if the edit was successful, false if could
+   * only be performed in part or not at all. Failure may occur in 'locked edit'
+   * mode, when an insertion requires a matching gapped position (or column) to
+   * delete, and deletion requires an adjacent gapped position (or column) to
+   * remove.
+   * 
+   * @param insertGap
+   *          true if inserting gap(s), false if deleting
+   * @param editSeq
+   *          (unused parameter, currently always false)
+   * @param startres
+   *          the column at which to perform the edit
+   * @param fixedRight
+   *          fixed right boundary column of a locked edit (within or to the
+   *          left of a selection group)
+   * @param fixedColumns
+   *          true if this is a locked edit
+   * @param sg
+   *          the sequence group (if group edit is being performed)
+   * @return
+   */
+  protected boolean doEditSequence(final boolean insertGap,
+          final boolean editSeq, final int startres, int fixedRight,
+          final boolean fixedColumns, final SequenceGroup sg)
+  {
+    final SequenceI seq = av.getAlignment().getSequenceAt(editStartSeq);
+    SequenceI[] seqs = new SequenceI[] { seq };
+
     if (groupEditing)
     {
       List<SequenceI> vseqs = sg.getSequences(av.getHiddenRepSequences());
@@ -1316,7 +1567,8 @@ public class SeqPanel extends JPanel
         if (sg.getStartRes() == 0 && sg.getEndRes() == fixedRight
                 && sg.getEndRes() == av.getAlignment().getWidth() - 1)
         {
-          sg.setEndRes(av.getAlignment().getWidth() + startres - lastres);
+          sg.setEndRes(
+                  av.getAlignment().getWidth() + startres - editLastRes);
           fixedRight = sg.getEndRes();
         }
 
@@ -1324,15 +1576,16 @@ public class SeqPanel extends JPanel
         // Find the next gap before the end
         // of the visible region boundary
         boolean blank = false;
-        for (; fixedRight > lastres; fixedRight--)
+        for (; fixedRight > editLastRes; fixedRight--)
         {
           blank = true;
 
           for (g = 0; g < groupSize; g++)
           {
-            for (int j = 0; j < startres - lastres; j++)
+            for (int j = 0; j < startres - editLastRes; j++)
             {
-              if (!Comparison.isGap(groupSeqs[g].getCharAt(fixedRight - j)))
+              if (!Comparison
+                      .isGap(groupSeqs[g].getCharAt(fixedRight - j)))
               {
                 blank = false;
                 break;
@@ -1349,12 +1602,11 @@ public class SeqPanel extends JPanel
         {
           if (sg.getSize() == av.getAlignment().getHeight())
           {
-            if ((av.hasHiddenColumns() && startres < av.getAlignment()
-                    .getHiddenColumns()
-                    .getNextHiddenBoundary(false, startres)))
+            if ((av.hasHiddenColumns()
+                    && startres < av.getAlignment().getHiddenColumns()
+                            .getNextHiddenBoundary(false, startres)))
             {
-              endEditing();
-              return;
+              return false;
             }
 
             int alWidth = av.getAlignment().getWidth();
@@ -1369,13 +1621,12 @@ public class SeqPanel extends JPanel
             }
             // We can still insert gaps if the selectionGroup
             // contains all the sequences
-            sg.setEndRes(sg.getEndRes() + startres - lastres);
-            fixedRight = alWidth + startres - lastres;
+            sg.setEndRes(sg.getEndRes() + startres - editLastRes);
+            fixedRight = alWidth + startres - editLastRes;
           }
           else
           {
-            endEditing();
-            return;
+            return false;
           }
         }
       }
@@ -1388,7 +1639,7 @@ public class SeqPanel extends JPanel
 
         for (g = 0; g < groupSize; g++)
         {
-          for (int j = startres; j < lastres; j++)
+          for (int j = startres; j < editLastRes; j++)
           {
             if (groupSeqs[g].getLength() <= j)
             {
@@ -1398,8 +1649,7 @@ public class SeqPanel extends JPanel
             if (!Comparison.isGap(groupSeqs[g].getCharAt(j)))
             {
               // Not a gap, block edit not valid
-              endEditing();
-              return;
+              return false;
             }
           }
         }
@@ -1410,15 +1660,15 @@ public class SeqPanel extends JPanel
         // dragging to the right
         if (fixedColumns && fixedRight != -1)
         {
-          for (int j = lastres; j < startres; j++)
+          for (int j = editLastRes; j < startres; j++)
           {
-            insertChar(j, groupSeqs, fixedRight);
+            insertGap(j, groupSeqs, fixedRight);
           }
         }
         else
         {
           appendEdit(Action.INSERT_GAP, groupSeqs, startres,
-                  startres - lastres);
+                  startres - editLastRes, false);
         }
       }
       else
@@ -1426,7 +1676,7 @@ public class SeqPanel extends JPanel
         // dragging to the left
         if (fixedColumns && fixedRight != -1)
         {
-          for (int j = lastres; j > startres; j--)
+          for (int j = editLastRes; j > startres; j--)
           {
             deleteChar(startres, groupSeqs, fixedRight);
           }
@@ -1434,28 +1684,36 @@ public class SeqPanel extends JPanel
         else
         {
           appendEdit(Action.DELETE_GAP, groupSeqs, startres,
-                  lastres - startres);
+                  editLastRes - startres, false);
         }
-
       }
     }
     else
-    // ///Editing a single sequence///////////
     {
+      /*
+       * editing a single sequence
+       */
       if (insertGap)
       {
         // dragging to the right
         if (fixedColumns && fixedRight != -1)
         {
-          for (int j = lastres; j < startres; j++)
+          for (int j = editLastRes; j < startres; j++)
           {
-            insertChar(j, new SequenceI[] { seq }, fixedRight);
+            if (!insertGap(j, seqs, fixedRight))
+            {
+              /*
+               * e.g. cursor mode command specified 
+               * more inserts than are possible
+               */
+              return false;
+            }
           }
         }
         else
         {
-          appendEdit(Action.INSERT_GAP, new SequenceI[] { seq }, lastres,
-                  startres - lastres);
+          appendEdit(Action.INSERT_GAP, seqs, editLastRes,
+                  startres - editLastRes, false);
         }
       }
       else
@@ -1465,21 +1723,20 @@ public class SeqPanel extends JPanel
           // dragging to the left
           if (fixedColumns && fixedRight != -1)
           {
-            for (int j = lastres; j > startres; j--)
+            for (int j = editLastRes; j > startres; j--)
             {
               if (!Comparison.isGap(seq.getCharAt(startres)))
               {
-                endEditing();
-                break;
+                return false;
               }
-              deleteChar(startres, new SequenceI[] { seq }, fixedRight);
+              deleteChar(startres, seqs, fixedRight);
             }
           }
           else
           {
             // could be a keyboard edit trying to delete none gaps
             int max = 0;
-            for (int m = startres; m < lastres; m++)
+            for (int m = startres; m < editLastRes; m++)
             {
               if (!Comparison.isGap(seq.getCharAt(m)))
               {
@@ -1487,11 +1744,9 @@ public class SeqPanel extends JPanel
               }
               max++;
             }
-
             if (max > 0)
             {
-              appendEdit(Action.DELETE_GAP, new SequenceI[] { seq },
-                      startres, max);
+              appendEdit(Action.DELETE_GAP, seqs, startres, max, false);
             }
           }
         }
@@ -1499,25 +1754,82 @@ public class SeqPanel extends JPanel
         {// insertGap==false AND editSeq==TRUE;
           if (fixedColumns && fixedRight != -1)
           {
-            for (int j = lastres; j < startres; j++)
+            for (int j = editLastRes; j < startres; j++)
             {
-              insertChar(j, new SequenceI[] { seq }, fixedRight);
+              insertGap(j, seqs, fixedRight);
             }
           }
           else
           {
-            appendEdit(Action.INSERT_NUC, new SequenceI[] { seq }, lastres,
-                    startres - lastres);
+            appendEdit(Action.INSERT_NUC, seqs, editLastRes,
+                    startres - editLastRes, false);
           }
         }
       }
     }
 
-    lastres = startres;
-    seqCanvas.repaint();
+    return true;
   }
 
-  void insertChar(int j, SequenceI[] seq, int fixedColumn)
+  /**
+   * Constructs an informative status bar message while dragging to insert or
+   * delete gaps. Answers null if inserts and deletes cancel out.
+   * 
+   * @param editCommand
+   *          a command containing the list of individual edits
+   * @return
+   */
+  protected static String getEditStatusMessage(EditCommand editCommand)
+  {
+    if (editCommand == null)
+    {
+      return null;
+    }
+
+    /*
+     * add any inserts, and subtract any deletes,  
+     * not counting those auto-inserted when doing a 'locked edit'
+     * (so only counting edits 'under the cursor')
+     */
+    int count = 0;
+    for (Edit cmd : editCommand.getEdits())
+    {
+      if (!cmd.isSystemGenerated())
+      {
+        count += cmd.getAction() == Action.INSERT_GAP ? cmd.getNumber()
+                : -cmd.getNumber();
+      }
+    }
+
+    if (count == 0)
+    {
+      /*
+       * inserts and deletes cancel out
+       */
+      return null;
+    }
+
+    String msgKey = count > 1 ? "label.insert_gaps"
+            : (count == 1 ? "label.insert_gap"
+                    : (count == -1 ? "label.delete_gap"
+                            : "label.delete_gaps"));
+    count = Math.abs(count);
+
+    return MessageManager.formatMessage(msgKey, String.valueOf(count));
+  }
+
+  /**
+   * Inserts one gap at column j, deleting the right-most gapped column up to
+   * (and including) fixedColumn. Returns true if the edit is successful, false
+   * if no blank column is available to allow the insertion to be balanced by a
+   * deletion.
+   * 
+   * @param j
+   * @param seq
+   * @param fixedColumn
+   * @return
+   */
+  boolean insertGap(int j, SequenceI[] seq, int fixedColumn)
   {
     int blankColumn = fixedColumn;
     for (int s = 0; s < seq.length; s++)
@@ -1538,47 +1850,60 @@ public class SeqPanel extends JPanel
       {
         blankColumn = fixedColumn;
         endEditing();
-        return;
+        return false;
       }
     }
 
-    appendEdit(Action.DELETE_GAP, seq, blankColumn, 1);
+    appendEdit(Action.DELETE_GAP, seq, blankColumn, 1, true);
 
-    appendEdit(Action.INSERT_GAP, seq, j, 1);
+    appendEdit(Action.INSERT_GAP, seq, j, 1, false);
 
+    return true;
   }
 
   /**
-   * Helper method to add and perform one edit action.
+   * Helper method to add and perform one edit action
    * 
    * @param action
    * @param seq
    * @param pos
    * @param count
+   * @param systemGenerated
+   *          true if the edit is a 'balancing' delete (or insert) to match a
+   *          user's insert (or delete) in a locked editing region
    */
   protected void appendEdit(Action action, SequenceI[] seq, int pos,
-          int count)
+          int count, boolean systemGenerated)
   {
 
     final Edit edit = new EditCommand().new Edit(action, seq, pos, count,
             av.getAlignment().getGapCharacter());
+    edit.setSystemGenerated(systemGenerated);
 
     editCommand.appendEdit(edit, av.getAlignment(), true, null);
   }
 
-  void deleteChar(int j, SequenceI[] seq, int fixedColumn)
+  /**
+   * Deletes the character at column j, and inserts a gap at fixedColumn, in
+   * each of the given sequences. The caller should ensure that all sequences
+   * are gapped in column j.
+   * 
+   * @param j
+   * @param seqs
+   * @param fixedColumn
+   */
+  void deleteChar(int j, SequenceI[] seqs, int fixedColumn)
   {
+    appendEdit(Action.DELETE_GAP, seqs, j, 1, false);
 
-    appendEdit(Action.DELETE_GAP, seq, j, 1);
-
-    appendEdit(Action.INSERT_GAP, seq, fixedColumn, 1);
+    appendEdit(Action.INSERT_GAP, seqs, fixedColumn, 1, true);
   }
 
   /**
-   * DOCUMENT ME!
+   * On reentering the panel, stops any scrolling that was started on dragging
+   * out of the panel
    * 
    * @param e
-   *          DOCUMENT ME!
    */
   @Override
   public void mouseEntered(MouseEvent e)
@@ -1587,23 +1912,19 @@ public class SeqPanel extends JPanel
     {
       oldSeq = 0;
     }
-
-    if ((scrollThread != null) && (scrollThread.isRunning()))
-    {
-      scrollThread.stopScrolling();
-      scrollThread = null;
-    }
+    stopScrolling();
   }
 
   /**
-   * DOCUMENT ME!
+   * On leaving the panel, if the mouse is being dragged, starts a thread to
+   * scroll it until the mouse is released (in unwrapped mode only)
    * 
    * @param e
-   *          DOCUMENT ME!
    */
   @Override
   public void mouseExited(MouseEvent e)
   {
+    ap.alignFrame.setStatus(" ");
     if (av.getWrapAlignment())
     {
       return;
@@ -1624,7 +1945,12 @@ public class SeqPanel extends JPanel
   public void mouseClicked(MouseEvent evt)
   {
     SequenceGroup sg = null;
-    SequenceI sequence = av.getAlignment().getSequenceAt(findSeq(evt));
+    MousePos pos = findMousePosition(evt);
+    if (pos.isOverAnnotation() || pos.seqIndex == -1 || pos.column == -1)
+    {
+      return;
+    }
+
     if (evt.getClickCount() > 1)
     {
       sg = av.getSelectionGroup();
@@ -1634,12 +1960,13 @@ public class SeqPanel extends JPanel
         av.setSelectionGroup(null);
       }
 
-      int column = findColumn(evt);
+      int column = pos.column;
 
       /*
        * find features at the position (if not gapped), or straddling
        * the position (if at a gap)
        */
+      SequenceI sequence = av.getAlignment().getSequenceAt(pos.seqIndex);
       List<SequenceFeature> features = seqCanvas.getFeatureRenderer()
               .findFeaturesAtColumn(sequence, column + 1);
 
@@ -1706,32 +2033,22 @@ public class SeqPanel extends JPanel
   /**
    * DOCUMENT ME!
    * 
-   * @param evt
+   * @param pos
    *          DOCUMENT ME!
    */
-  public void doMousePressedDefineMode(MouseEvent evt)
+  protected void doMousePressedDefineMode(MouseEvent evt, MousePos pos)
   {
-    final int res = findColumn(evt);
-    final int seq = findSeq(evt);
-    oldSeq = seq;
-    updateOverviewAndStructs = false;
-
-    startWrapBlock = wrappedBlock;
-
-    if (av.getWrapAlignment() && seq > av.getAlignment().getHeight())
+    if (pos.isOverAnnotation() || pos.seqIndex == -1 || pos.column == -1)
     {
-      JvOptionPane.showInternalMessageDialog(Desktop.desktop,
-              MessageManager.getString(
-                      "label.cannot_edit_annotations_in_wrapped_view"),
-              MessageManager.getString("label.wrapped_view_no_edit"),
-              JvOptionPane.WARNING_MESSAGE);
       return;
     }
 
-    if (seq < 0 || res < 0)
-    {
-      return;
-    }
+    final int res = pos.column;
+    final int seq = pos.seqIndex;
+    oldSeq = seq;
+    updateOverviewAndStructs = false;
+
+    startWrapBlock = wrappedBlock;
 
     SequenceI sequence = av.getAlignment().getSequenceAt(seq);
 
@@ -1755,7 +2072,7 @@ public class SeqPanel extends JPanel
 
     if (evt.isPopupTrigger()) // Mac: mousePressed
     {
-      showPopupMenu(evt);
+      showPopupMenu(evt, pos);
       return;
     }
 
@@ -1771,8 +2088,8 @@ public class SeqPanel extends JPanel
 
     if (av.cursorMode)
     {
-      seqCanvas.cursorX = findColumn(evt);
-      seqCanvas.cursorY = findSeq(evt);
+      seqCanvas.cursorX = res;
+      seqCanvas.cursorY = seq;
       seqCanvas.repaint();
       return;
     }
@@ -1830,15 +2147,14 @@ public class SeqPanel extends JPanel
 
   /**
    * Build and show a pop-up menu at the right-click mouse position
-   * 
+   *
    * @param evt
-   * @param res
-   * @param sequences
+   * @param pos
    */
-  void showPopupMenu(MouseEvent evt)
+  void showPopupMenu(MouseEvent evt, MousePos pos)
   {
-    final int column = findColumn(evt);
-    final int seq = findSeq(evt);
+    final int column = pos.column;
+    final int seq = pos.seqIndex;
     SequenceI sequence = av.getAlignment().getSequenceAt(seq);
     List<SequenceFeature> features = ap.getFeatureRenderer()
             .findFeaturesAtColumn(sequence, column + 1);
@@ -1856,7 +2172,8 @@ public class SeqPanel extends JPanel
    *          true if this event is happening after a mouse drag (rather than a
    *          mouse down)
    */
-  public void doMouseReleasedDefineMode(MouseEvent evt, boolean afterDrag)
+  protected void doMouseReleasedDefineMode(MouseEvent evt,
+          boolean afterDrag)
   {
     if (stretchGroup == null)
     {
@@ -1872,8 +2189,11 @@ public class SeqPanel extends JPanel
             && afterDrag;
     if (stretchGroup.cs != null)
     {
-      stretchGroup.cs.alignmentChanged(stretchGroup,
-              av.getHiddenRepSequences());
+      if (afterDrag)
+      {
+        stretchGroup.cs.alignmentChanged(stretchGroup,
+                av.getHiddenRepSequences());
+      }
 
       ResidueShaderI groupColourScheme = stretchGroup
               .getGroupColourScheme();
@@ -1899,31 +2219,34 @@ public class SeqPanel extends JPanel
   }
 
   /**
-   * DOCUMENT ME!
+   * Resizes the borders of a selection group depending on the direction of
+   * mouse drag
    * 
    * @param evt
-   *          DOCUMENT ME!
    */
-  public void doMouseDraggedDefineMode(MouseEvent evt)
+  protected void dragStretchGroup(MouseEvent evt)
   {
-    int res = findColumn(evt);
-    int y = findSeq(evt);
-
-    if (wrappedBlock != startWrapBlock)
+    if (stretchGroup == null)
     {
       return;
     }
 
-    if (stretchGroup == null)
+    MousePos pos = findMousePosition(evt);
+    if (pos.isOverAnnotation() || pos.column == -1 || pos.seqIndex == -1)
     {
       return;
     }
 
-    if (res >= av.getAlignment().getWidth())
+    int res = pos.column;
+    int y = pos.seqIndex;
+
+    if (wrappedBlock != startWrapBlock)
     {
-      res = av.getAlignment().getWidth() - 1;
+      return;
     }
 
+    res = Math.min(res, av.getAlignment().getWidth()-1);
+
     if (stretchGroup.getEndRes() == res)
     {
       // Edit end res position of selected group
@@ -2008,89 +2331,152 @@ public class SeqPanel extends JPanel
 
     mouseDragging = true;
 
-    if ((scrollThread != null) && (scrollThread.isRunning()))
+    if (scrollThread != null)
     {
-      scrollThread.setEvent(evt);
+      scrollThread.setMousePosition(evt.getPoint());
     }
+
+    /*
+     * construct a status message showing the range of the selection
+     */
+    StringBuilder status = new StringBuilder(64);
+    List<SequenceI> seqs = stretchGroup.getSequences();
+    String name = seqs.get(0).getName();
+    if (name.length() > 20)
+    {
+      name = name.substring(0, 20);
+    }
+    status.append(name).append(" - ");
+    name = seqs.get(seqs.size() - 1).getName();
+    if (name.length() > 20)
+    {
+      name = name.substring(0, 20);
+    }
+    status.append(name).append(" ");
+    int startRes = stretchGroup.getStartRes();
+    status.append(" cols ").append(String.valueOf(startRes + 1))
+            .append("-");
+    int endRes = stretchGroup.getEndRes();
+    status.append(String.valueOf(endRes + 1));
+    status.append(" (").append(String.valueOf(seqs.size())).append(" x ")
+            .append(String.valueOf(endRes - startRes + 1)).append(")");
+    ap.alignFrame.setStatus(status.toString());
   }
 
-  void scrollCanvas(MouseEvent evt)
+  /**
+   * Stops the scroll thread if it is running
+   */
+  void stopScrolling()
   {
-    if (evt == null)
+    if (scrollThread != null)
     {
-      if ((scrollThread != null) && (scrollThread.isRunning()))
-      {
-        scrollThread.stopScrolling();
-        scrollThread = null;
-      }
-      mouseDragging = false;
+      scrollThread.stopScrolling();
+      scrollThread = null;
     }
-    else
-    {
-      if (scrollThread == null)
-      {
-        scrollThread = new ScrollThread();
-      }
+    mouseDragging = false;
+  }
 
-      mouseDragging = true;
-      scrollThread.setEvent(evt);
+  /**
+   * Starts a thread to scroll the alignment, towards a given mouse position
+   * outside the panel bounds
+   * 
+   * @param mousePos
+   */
+  void startScrolling(Point mousePos)
+  {
+    if (scrollThread == null)
+    {
+      scrollThread = new ScrollThread();
     }
 
+    mouseDragging = true;
+    scrollThread.setMousePosition(mousePos);
   }
 
-  // this class allows scrolling off the bottom of the visible alignment
+  /**
+   * Performs scrolling of the visible alignment left, right, up or down
+   */
   class ScrollThread extends Thread
   {
-    MouseEvent evt;
+    private Point mousePos;
 
     private volatile boolean threadRunning = true;
 
+    /**
+     * Constructor
+     */
     public ScrollThread()
     {
+      setName("SeqPanel$ScrollThread");
       start();
     }
 
-    public void setEvent(MouseEvent e)
+    /**
+     * Sets the position of the mouse that determines the direction of the
+     * scroll to perform
+     * 
+     * @param p
+     */
+    public void setMousePosition(Point p)
     {
-      evt = e;
+      mousePos = p;
     }
 
+    /**
+     * Sets a flag that will cause the thread to exit
+     */
     public void stopScrolling()
     {
       threadRunning = false;
     }
 
-    public boolean isRunning()
-    {
-      return threadRunning;
-    }
-
+    /**
+     * Scrolls the alignment left or right, and/or up or down, depending on the
+     * last notified mouse position, until the limit of the alignment is
+     * reached, or a flag is set to stop the scroll
+     */
     @Override
     public void run()
     {
-      while (threadRunning)
+      while (threadRunning && mouseDragging)
       {
-        if (evt != null)
+        if (mousePos != null)
         {
-          if (mouseDragging && (evt.getY() < 0)
-                  && (av.getRanges().getStartSeq() > 0))
+          boolean scrolled = false;
+          ViewportRanges ranges = SeqPanel.this.av.getRanges();
+
+          /*
+           * scroll up or down
+           */
+          if (mousePos.y < 0)
           {
-            av.getRanges().scrollUp(true);
+            // mouse is above this panel - try scroll up
+            scrolled = ranges.scrollUp(true);
           }
-
-          if (mouseDragging && (evt.getY() >= getHeight()) && (av
-                  .getAlignment().getHeight() > av.getRanges().getEndSeq()))
+          else if (mousePos.y >= getHeight())
           {
-            av.getRanges().scrollUp(false);
+            // mouse is below this panel - try scroll down
+            scrolled = ranges.scrollUp(false);
           }
 
-          if (mouseDragging && (evt.getX() < 0))
+          /*
+           * scroll left or right
+           */
+          if (mousePos.x < 0)
           {
-            av.getRanges().scrollRight(false);
+            scrolled |= ranges.scrollRight(false);
           }
-          else if (mouseDragging && (evt.getX() >= getWidth()))
+          else if (mousePos.x >= getWidth())
           {
-            av.getRanges().scrollRight(true);
+            scrolled |= ranges.scrollRight(true);
+          }
+          if (!scrolled)
+          {
+            /*
+             * we have reached the limit of the visible alignment - quit
+             */
+            threadRunning = false;
+            SeqPanel.this.ap.repaint();
           }
         }
 
@@ -2280,7 +2666,7 @@ public class SeqPanel extends JPanel
     HiddenColumns hs = new HiddenColumns();
     MappingUtils.mapColumnSelection(colsel, hidden, sourceAv, av, cs, hs);
     av.setColumnSelection(cs);
-    av.getAlignment().setHiddenColumns(hs);
+    boolean hiddenChanged = av.getAlignment().setHiddenColumns(hs);
 
     // lastly, update any dependent dialogs
     if (ap.getCalculationDialog() != null)
@@ -2288,7 +2674,11 @@ public class SeqPanel extends JPanel
       ap.getCalculationDialog().validateCalcTypes();
     }
 
-    PaintRefresher.Refresh(this, av.getSequenceSetId());
+    /*
+     * repaint alignment, and also Overview or Structure
+     * if hidden column selection has changed
+     */
+    ap.paintAlignment(hiddenChanged, hiddenChanged);
 
     return true;
   }
index 8754fbb..1c4e6a6 100755 (executable)
@@ -1038,7 +1038,7 @@ public class SequenceFetcher extends JPanel implements Runnable
         Desktop.addInternalFrame(af, title, AlignFrame.DEFAULT_WIDTH,
                 AlignFrame.DEFAULT_HEIGHT);
 
-        af.statusBar.setText(MessageManager
+        af.setStatus(MessageManager
                 .getString("label.successfully_pasted_alignment_file"));
 
         try
index 93a2457..f98139b 100755 (executable)
@@ -26,6 +26,7 @@ import jalview.jbgui.GSliderPanel;
 import jalview.renderer.ResidueShaderI;
 import jalview.util.MessageManager;
 
+import java.awt.event.ActionEvent;
 import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
 import java.beans.PropertyVetoException;
@@ -396,7 +397,6 @@ public class SliderPanel extends GSliderPanel
   public void setAllGroupsCheckEnabled(boolean b)
   {
     allGroupsCheck.setEnabled(b);
-    allGroupsCheck.setSelected(ap.av.getColourAppliesToAllGroups());
   }
 
   /**
@@ -497,4 +497,13 @@ public class SliderPanel extends GSliderPanel
     }
     return title;
   }
+
+  @Override
+  protected void allGroupsCheck_actionPerformed(ActionEvent e)
+  {
+    if (allGroupsCheck.isSelected())
+    {
+      valueChanged(slider.getValue());
+    }
+  }
 }
index 72b0bcc..35a5475 100644 (file)
@@ -564,7 +564,8 @@ public abstract class StructureViewerBase extends GStructureViewer
   {
     AlignmentI al = getAlignmentPanel().av.getAlignment();
     ColourSchemeI cs = ColourSchemes.getInstance()
-            .getColourScheme(colourSchemeName, al, null);
+            .getColourScheme(colourSchemeName, getAlignmentPanel().av, al,
+                    null);
     getBinding().setJalviewColourScheme(cs);
   }
 
index 45def89..180467a 100755 (executable)
@@ -28,11 +28,8 @@ import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
 import jalview.datamodel.SequenceNode;
 import jalview.schemes.ColourSchemeI;
-import jalview.schemes.ColourSchemeProperty;
-import jalview.schemes.UserColourScheme;
 import jalview.structure.SelectionSource;
 import jalview.util.Format;
-import jalview.util.MappingUtils;
 import jalview.util.MessageManager;
 
 import java.awt.Color;
@@ -512,29 +509,21 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
       return;
     }
 
-    if ((node.left() == null) && (node.right() == null)) // TODO: internal node
+    node.color = c;
+    if (node.element() instanceof SequenceI)
     {
-      node.color = c;
-
-      if (node.element() instanceof SequenceI)
+      final SequenceI seq = (SequenceI) node.element();
+      AlignmentPanel[] aps = getAssociatedPanels();
+      if (aps != null)
       {
-        AlignmentPanel[] aps = getAssociatedPanels();
-        if (aps != null)
+        for (int a = 0; a < aps.length; a++)
         {
-          for (int a = 0; a < aps.length; a++)
-          {
-            final SequenceI seq = (SequenceI) node.element();
-            aps[a].av.setSequenceColour(seq, c);
-          }
+          aps[a].av.setSequenceColour(seq, c);
         }
       }
     }
-    else
-    {
-      node.color = c;
-      setColor((SequenceNode) node.left(), c);
-      setColor((SequenceNode) node.right(), c);
-    }
+    setColor((SequenceNode) node.left(), c);
+    setColor((SequenceNode) node.right(), c);
   }
 
   /**
@@ -960,6 +949,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
                     .deleteAllGroups();
             aps[a].av.getCodingComplement().clearSequenceColours();
           }
+          aps[a].av.setUpdateStructures(true);
         }
         colourGroups(groups);
 
@@ -1003,76 +993,48 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
       }
 
       ColourSchemeI cs = null;
-      SequenceGroup sg = new SequenceGroup(sequences, null, cs, true, true,
+      SequenceGroup _sg = new SequenceGroup(sequences, null, cs, true, true,
               false, 0, av.getAlignment().getWidth() - 1);
 
-      if (av.getGlobalColourScheme() != null)
-      {
-        if (av.getGlobalColourScheme() instanceof UserColourScheme)
-        {
-          cs = new UserColourScheme(
-                  ((UserColourScheme) av.getGlobalColourScheme())
-                          .getColours());
-
-        }
-        else
-        {
-          cs = ColourSchemeProperty.getColourScheme(sg, ColourSchemeProperty
-                  .getColourName(av.getGlobalColourScheme()));
-        }
-        // cs is null if shading is an annotationColourGradient
-        // if (cs != null)
-        // {
-        // cs.setThreshold(av.getViewportColourScheme().getThreshold(),
-        // av.isIgnoreGapsConsensus());
-        // }
-      }
-      sg.setColourScheme(cs);
-      sg.getGroupColourScheme().setThreshold(
-              av.getResidueShading().getThreshold(),
-              av.isIgnoreGapsConsensus());
-      // sg.recalcConservation();
-      sg.setName("JTreeGroup:" + sg.hashCode());
-      sg.setIdColour(col);
+      _sg.setName("JTreeGroup:" + _sg.hashCode());
+      _sg.setIdColour(col);
 
       for (int a = 0; a < aps.length; a++)
       {
-        if (aps[a].av.getGlobalColourScheme() != null
-                && aps[a].av.getResidueShading().conservationApplied())
-        {
-          Conservation c = new Conservation("Group", sg.getSequences(null),
-                  sg.getStartRes(), sg.getEndRes());
-          c.calculate();
-          c.verdict(false, aps[a].av.getConsPercGaps());
-          sg.cs.setConservation(c);
-        }
+        SequenceGroup sg = new SequenceGroup(_sg);
+        AlignViewport viewport = aps[a].av;
 
-        aps[a].av.getAlignment().addGroup(new SequenceGroup(sg));
-        // TODO can we push all of the below into AlignViewportI?
-        final AlignViewportI codingComplement = aps[a].av
-                .getCodingComplement();
-        if (codingComplement != null)
+        // Propagate group colours in each view
+        if (viewport.getGlobalColourScheme() != null)
         {
-          SequenceGroup mappedGroup = MappingUtils.mapSequenceGroup(sg, av,
-                  codingComplement);
-          if (mappedGroup.getSequences().size() > 0)
+          cs = viewport.getGlobalColourScheme().getInstance(viewport, sg);
+          sg.setColourScheme(cs);
+          sg.getGroupColourScheme().setThreshold(
+                  viewport.getResidueShading().getThreshold(),
+                  viewport.isIgnoreGapsConsensus());
+
+          if (viewport.getResidueShading().conservationApplied())
           {
-            codingComplement.getAlignment().addGroup(mappedGroup);
-            for (SequenceI seq : mappedGroup.getSequences())
-            {
-              codingComplement.setSequenceColour(seq, col.brighter());
-            }
+            Conservation c = new Conservation("Group",
+                    sg.getSequences(null), sg.getStartRes(),
+                    sg.getEndRes());
+            c.calculate();
+            c.verdict(false, viewport.getConsPercGaps());
+            sg.cs.setConservation(c);
           }
         }
+        // indicate that associated structure views will need an update
+        viewport.setUpdateStructures(true);
+        // propagate structure view update and sequence group to complement view
+        viewport.addSequenceGroup(sg);
       }
     }
 
-    // notify the panel(s) to redo any group specific stuff.
+    // notify the panel(s) to redo any group specific stuff
+    // also updates structure views if necessary
     for (int a = 0; a < aps.length; a++)
     {
       aps[a].updateAnnotation();
-      // TODO: JAL-868 - need to ensure view colour change message is broadcast
-      // to any Jmols listening in
       final AlignViewportI codingComplement = aps[a].av
               .getCodingComplement();
       if (codingComplement != null)
@@ -1160,4 +1122,14 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
   {
     this.threshold = threshold;
   }
+
+  public boolean isApplyToAllViews()
+  {
+    return this.applyToAllViews;
+  }
+
+  public void setApplyToAllViews(boolean applyToAllViews)
+  {
+    this.applyToAllViews = applyToAllViews;
+  }
 }
index 084f461..ca4f84e 100755 (executable)
@@ -879,7 +879,7 @@ public class TreePanel extends GTreePanel
     /*
      * put them together as <method> Using <model>
      */
-    final String ttl = MessageManager.formatMessage("label.treecalc_title",
+    final String ttl = MessageManager.formatMessage("label.calc_title",
             treecalcnm, smn);
     return ttl;
   }
index e578a45..dd385d2 100755 (executable)
@@ -1617,8 +1617,10 @@ public class AnnotationFile
         }
         else if (key.equalsIgnoreCase("colour"))
         {
+          // TODO need to notify colourscheme of view reference once it is
+          // available
           sg.cs.setColourScheme(
-                  ColourSchemeProperty.getColourScheme(al, value));
+                  ColourSchemeProperty.getColourScheme(null, al, value));
         }
         else if (key.equalsIgnoreCase("pidThreshold"))
         {
diff --git a/src/jalview/io/BackupFilenameFilter.java b/src/jalview/io/BackupFilenameFilter.java
new file mode 100644 (file)
index 0000000..573040f
--- /dev/null
@@ -0,0 +1,46 @@
+package jalview.io;
+
+import java.io.File;
+import java.io.FilenameFilter;
+import java.io.IOException;
+
+public class BackupFilenameFilter implements FilenameFilter
+{
+
+  public String base;
+
+  public String template;
+
+  public int digits;
+
+  public BackupFilenameFilter(String base, String template, int digits)
+  {
+    this.base = base;
+    this.template = template;
+    this.digits = digits;
+  }
+
+  @Override
+  public boolean accept(File dir, String filename)
+  {
+    try
+    {
+      File file = new File(
+              dir.getCanonicalPath() + File.separatorChar + filename);
+      if (file.isDirectory())
+      {
+        // backup files aren't dirs!
+        return false;
+      }
+    } catch (IOException e)
+    {
+      System.out.println("IOException when checking file '" + filename
+              + "' is a backupfile");
+    }
+
+    BackupFilenameParts bffp = new BackupFilenameParts(filename, base,
+            template, digits);
+    return bffp.isBackupFile();
+  }
+
+}
diff --git a/src/jalview/io/BackupFilenameParts.java b/src/jalview/io/BackupFilenameParts.java
new file mode 100644 (file)
index 0000000..4f93ece
--- /dev/null
@@ -0,0 +1,153 @@
+package jalview.io;
+
+import jalview.bin.Cache;
+
+import java.io.File;
+
+public class BackupFilenameParts
+{
+  private String base;
+
+  private String templateStart;
+
+  private int num;
+
+  private int digits;
+
+  private String templateEnd;
+
+  private boolean isBackupFile;
+
+  private BackupFilenameParts()
+  {
+    this.isBackupFile = false;
+  }
+
+  public BackupFilenameParts(File file, String base, String template,
+          int digits)
+  {
+    this(file.getName(), base, template, digits);
+  }
+
+  public BackupFilenameParts(String filename, String base, String template,
+          int suggesteddigits)
+  {
+    this(filename, base, template, suggesteddigits, false);
+  }
+
+  public BackupFilenameParts(String filename, String base, String template,
+          int suggesteddigits, boolean extensionMatch)
+  {
+    this.isBackupFile = false;
+
+    int numcharstart = template.indexOf(BackupFiles.NUM_PLACEHOLDER);
+    int digits = 0;
+    String templateStart = template;
+    String templateEnd = "";
+    if (numcharstart > -1)
+    {
+      templateStart = template.substring(0, numcharstart);
+      templateEnd = template.substring(
+              numcharstart + BackupFiles.NUM_PLACEHOLDER.length());
+      digits = suggesteddigits;
+    }
+
+    String savedFilename = "";
+    // if extensionOnly is set then reset the filename to the last occurrence of the extension+templateStart and try the match
+    if (extensionMatch)
+    {
+      // only trying to match from extension onwards
+
+      int extensioncharstart = filename
+              .lastIndexOf('.' + base + templateStart);
+      if (extensioncharstart == -1)
+      {
+        return;
+      }
+
+      savedFilename = filename.substring(0, extensioncharstart + 1); // include
+                                                                     // the "."
+      filename = filename.substring(extensioncharstart + 1);
+    }
+
+    // full filename match
+
+    // calculate minimum length of a backup filename
+    int minlength = base.length() + template.length()
+            - BackupFiles.NUM_PLACEHOLDER.length() + digits;
+
+    if (!(filename.startsWith(base + templateStart)
+            && filename.endsWith(templateEnd)
+            && filename.length() >= minlength))
+    {
+      // non-starter
+      return;
+    }
+
+    int startLength = base.length() + templateStart.length();
+    int endLength = templateEnd.length();
+    String numString = numcharstart > -1
+            ? filename.substring(startLength, filename.length() - endLength)
+            : "";
+
+    if (filename.length() >= startLength + digits + endLength
+            && filename.startsWith(base + templateStart)
+            && filename.endsWith(templateEnd)
+            // match exactly digits number of number-characters (numString
+            // should be all digits and at least the right length), or more than
+            // digits long with proviso it's not zero-leading.
+            && (numString.matches("[0-9]{" + digits + "}")
+                    || numString.matches("[1-9][0-9]{" + digits + ",}")))
+    {
+      this.base = extensionMatch ? savedFilename + base : base;
+      this.templateStart = templateStart;
+      this.num = numString.length() > 0 ? Integer.parseInt(numString) : 0;
+      this.digits = digits;
+      this.templateEnd = templateEnd;
+      this.isBackupFile = true;
+    }
+
+  }
+
+  public static BackupFilenameParts currentBackupFilenameParts(
+          String filename, String base, boolean extensionMatch)
+  {
+    BackupFilenameParts bfp = new BackupFilenameParts();
+    String template = Cache.getDefault(BackupFiles.SUFFIX, null);
+    if (template == null)
+    {
+      return bfp;
+    }
+    int digits;
+    try
+    {
+      digits = Integer
+              .parseInt(Cache.getDefault(BackupFiles.SUFFIX_DIGITS, null));
+    } catch (Exception e)
+    {
+      return bfp;
+    }
+    return new BackupFilenameParts(filename, base, template, digits,
+            extensionMatch);
+  }
+
+  public boolean isBackupFile()
+  {
+    return this.isBackupFile;
+  }
+
+  public int indexNum()
+  {
+    return this.num;
+  }
+
+  public static String getBackupFilename(int index, String base,
+          String template, int digits)
+  {
+    String numString = String.format("%0" + digits + "d", index);
+    String backupSuffix = template.replaceFirst(BackupFiles.NUM_PLACEHOLDER,
+            numString);
+    String backupfilename = base + backupSuffix;
+    return backupfilename;
+  }
+}
diff --git a/src/jalview/io/BackupFiles.java b/src/jalview/io/BackupFiles.java
new file mode 100644 (file)
index 0000000..dbda022
--- /dev/null
@@ -0,0 +1,764 @@
+package jalview.io;
+
+import jalview.bin.Cache;
+import jalview.gui.Desktop;
+import jalview.gui.JvOptionPane;
+import jalview.util.MessageManager;
+
+import java.io.File;
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.TreeMap;
+
+/*
+ * BackupFiles used for manipulating (naming rolling/deleting) backup/version files when an alignment or project file is saved.
+ * User configurable options are:
+ * BACKUPFILES_ENABLED - boolean flag as to whether to use this mechanism or act as before, including overwriting files as saved.
+ * BACKUPFILES_SUFFIX - a template to insert after the file extension.  Use '%n' to be replaced by a 0-led SUFFIX_DIGITS long integer.
+ * BACKUPFILES_NO_MAX - flag to turn off setting a maximum number of backup files to keep.
+ * BACKUPFILES_ROLL_MAX - the maximum number of backupfiles to keep for any one alignment or project file.
+ * BACKUPFILES_SUFFIX_DIGITS - the number of digits to insert replace %n with (e.g. BACKUPFILES_SUFFIX_DIGITS = 3 would make "001", "002", etc)
+ * BACKUPFILES_REVERSE_ORDER - if true then "logfile" style numbering and file rolling will occur. If false then ever-increasing version numbering will occur, but old files will still be deleted if there are more than ROLL_MAX backup files. 
+ * BACKUPFILES_CONFIRM_DELETE_OLD - if true then prompt/confirm with the user when deleting older backup/version files.
+ */
+
+public class BackupFiles
+{
+
+  // labels for saved params in Cache and .jalview_properties
+  public static final String NS = "BACKUPFILES";
+
+  public static final String ENABLED = NS + "_ENABLED";
+
+  public static final String SUFFIX = NS + "_SUFFIX";
+
+  public static final String NO_MAX = NS + "_NO_MAX";
+
+  public static final String ROLL_MAX = NS + "_ROLL_MAX";
+
+  public static final String SUFFIX_DIGITS = NS + "_SUFFIX_DIGITS";
+
+  public static final String NUM_PLACEHOLDER = "%n";
+
+  public static final String REVERSE_ORDER = NS + "_REVERSE_ORDER";
+
+  public static final String CONFIRM_DELETE_OLD = NS
+          + "_CONFIRM_DELETE_OLD";
+
+  private static final String DEFAULT_TEMP_FILE = "jalview_temp_file_" + NS;
+
+  private static final String TEMP_FILE_EXT = ".tmp";
+
+  // file - File object to be backed up and then updated (written over)
+  private File file;
+
+  // enabled - default flag as to whether to do the backup file roll (if not
+  // defined in preferences)
+  private static boolean enabled;
+
+  // confirmDelete - default flag as to whether to confirm with the user before
+  // deleting old backup/version files
+  private static boolean confirmDelete;
+
+  // defaultSuffix - default template to use to append to basename of file
+  private String suffix;
+
+  // noMax - flag to turn off a maximum number of files
+  private boolean noMax;
+
+  // defaultMax - default max number of backup files
+  private int max;
+
+  // defaultDigits - number of zero-led digits to use in the filename
+  private int digits;
+
+  // reverseOrder - set to true to make newest (latest) files lowest number
+  // (like rolled log files)
+  private boolean reverseOrder;
+
+  // temp saved file to become new saved file
+  private File tempFile;
+
+  // flag set to see if file save to temp file was successful
+  private boolean tempFileWriteSuccess;
+
+  // array of files to be deleted, with extra information
+  private ArrayList<File> deleteFiles = new ArrayList<>();
+
+  // date formatting for modification times
+  private static final SimpleDateFormat sdf = new SimpleDateFormat(
+          "yyyy-MM-dd HH:mm:ss");
+
+  public BackupFiles(String filename)
+  {
+    this(new File(filename));
+  }
+
+  // first time defaults for SUFFIX, NO_MAX, ROLL_MAX, SUFFIX_DIGITS and
+  // REVERSE_ORDER
+  public BackupFiles(File file)
+  {
+    this(file, ".bak" + NUM_PLACEHOLDER, false, 3, 3, false);
+  }
+
+  public BackupFiles(File file, String defaultSuffix, boolean defaultNoMax,
+          int defaultMax, int defaultDigits, boolean defaultReverseOrder)
+  {
+    classInit();
+    this.file = file;
+    this.suffix = Cache.getDefault(SUFFIX, defaultSuffix);
+    this.noMax = Cache.getDefault(NO_MAX, defaultNoMax);
+    this.max = Cache.getDefault(ROLL_MAX, defaultMax);
+    this.digits = Cache.getDefault(SUFFIX_DIGITS, defaultDigits);
+    this.reverseOrder = Cache.getDefault(REVERSE_ORDER,
+            defaultReverseOrder);
+
+    // create a temp file to save new data in
+    File temp = null;
+    try
+    {
+      if (file != null)
+      {
+        String tempfilename = file.getName();
+        File tempdir = file.getParentFile();
+        temp = File.createTempFile(tempfilename, TEMP_FILE_EXT + "_newfile",
+                tempdir);
+      }
+      else
+      {
+        temp = File.createTempFile(DEFAULT_TEMP_FILE, TEMP_FILE_EXT);
+      }
+    } catch (IOException e)
+    {
+      System.out.println(
+              "Could not create temp file to save into (IOException)");
+    } catch (Exception e)
+    {
+      System.out.println("Exception ctreating temp file for saving");
+    }
+    this.setTempFile(temp);
+  }
+
+  public static void classInit()
+  {
+    setEnabled(Cache.getDefault(ENABLED, true));
+    setConfirmDelete(Cache.getDefault(CONFIRM_DELETE_OLD, true));
+  }
+
+  public static void setEnabled(boolean flag)
+  {
+    enabled = flag;
+  }
+
+  public static boolean getEnabled()
+  {
+    classInit();
+    return enabled;
+  }
+
+  public static void setConfirmDelete(boolean flag)
+  {
+    confirmDelete = flag;
+  }
+
+  public static boolean getConfirmDelete()
+  {
+    classInit();
+    return confirmDelete;
+  }
+
+  // set, get and rename temp file into place
+  public void setTempFile(File temp)
+  {
+    this.tempFile = temp;
+  }
+
+  public File getTempFile()
+  {
+    return tempFile;
+  }
+
+  public String getTempFilePath()
+  {
+    String path = null;
+    try
+    {
+      path = this.getTempFile().getCanonicalPath();
+    } catch (IOException e)
+    {
+      System.out.println(
+              "IOException when getting Canonical Path of temp file '"
+                      + this.getTempFile().getName() + "'");
+    }
+    return path;
+  }
+
+  public boolean setWriteSuccess(boolean flag)
+  {
+    boolean old = this.tempFileWriteSuccess;
+    this.tempFileWriteSuccess = flag;
+    return old;
+  }
+
+  public boolean getWriteSuccess()
+  {
+    return this.tempFileWriteSuccess;
+  }
+
+  public boolean renameTempFile()
+  {
+    return tempFile.renameTo(file);
+  }
+
+  // roll the backupfiles
+  public boolean rollBackupFiles()
+  {
+    return this.rollBackupFiles(true);
+  }
+
+  public boolean rollBackupFiles(boolean tidyUp)
+  {
+    // file doesn't yet exist or backups are not enabled or template is null or
+    // empty
+    if ((!file.exists()) || (!enabled) || max < 0 || suffix == null
+            || suffix.length() == 0)
+    {
+      // nothing to do
+      return true;
+    }
+
+    String dir = "";
+    File dirFile;
+    try
+    {
+      dirFile = file.getParentFile();
+      dir = dirFile.getCanonicalPath();
+    } catch (Exception e)
+    {
+      System.out.println(
+              "Could not get canonical path for file '" + file + "'");
+      return false;
+    }
+    String filename = file.getName();
+    String basename = filename;
+
+    boolean ret = true;
+    // Create/move backups up one
+
+    deleteFiles.clear();
+
+    // find existing backup files
+    BackupFilenameFilter bff = new BackupFilenameFilter(basename, suffix,
+            digits);
+    File[] backupFiles = dirFile.listFiles(bff);
+    int nextIndexNum = 0;
+
+    if (backupFiles.length == 0)
+    {
+      // No other backup files. Just need to move existing file to backupfile_1
+      nextIndexNum = 1;
+    }
+    else
+    {
+      TreeMap<Integer, File> bfTreeMap = sortBackupFilesAsTreeMap(
+              backupFiles, basename);
+      // bfTreeMap now a sorted list of <Integer index>,<File backupfile>
+      // mappings
+
+      if (reverseOrder)
+      {
+        // backup style numbering
+
+
+        int tempMax = noMax ? -1 : max;
+        // noMax == true means no limits
+        // look for first "gap" in backupFiles
+        // if tempMax is -1 at this stage just keep going until there's a gap,
+        // then hopefully tempMax gets set to the right index (a positive
+        // integer so the loop breaks)...
+        // why do I feel a little uneasy about this loop?..
+        for (int i = 1; tempMax < 0 || i <= max; i++)
+        {
+          if (!bfTreeMap.containsKey(i)) // first index without existent
+                                         // backupfile
+          {
+            tempMax = i;
+          }
+        }
+        
+        File previousFile = null;
+        File fileToBeDeleted = null;
+        for (int n = tempMax; n > 0; n--)
+        {
+          String backupfilename = dir + File.separatorChar
+                  + BackupFilenameParts.getBackupFilename(n, basename,
+                          suffix, digits);
+          File backupfile_n = new File(backupfilename);
+
+          if (!backupfile_n.exists())
+          {
+            // no "oldest" file to delete
+            previousFile = backupfile_n;
+            fileToBeDeleted = null;
+            continue;
+          }
+
+          // check the modification time of this (backupfile_n) and the previous
+          // file (fileToBeDeleted) if the previous file is going to be deleted
+          if (fileToBeDeleted != null)
+          {
+            File replacementFile = backupfile_n;
+            long fileToBeDeletedLMT = fileToBeDeleted.lastModified();
+            long replacementFileLMT = replacementFile.lastModified();
+
+            try
+            {
+              File oldestTempFile = nextTempFile(fileToBeDeleted.getName(),
+                      dirFile);
+              
+              if (fileToBeDeletedLMT > replacementFileLMT)
+              {
+                String fileToBeDeletedLMTString = sdf
+                        .format(fileToBeDeletedLMT);
+                String replacementFileLMTString = sdf
+                        .format(replacementFileLMT);
+                System.out.println("WARNING! I am set to delete backupfile "
+                        + fileToBeDeleted.getName()
+                        + " has modification time "
+                        + fileToBeDeletedLMTString
+                        + " which is newer than its replacement "
+                        + replacementFile.getName()
+                        + " with modification time "
+                        + replacementFileLMTString);
+
+                boolean delete = confirmNewerDeleteFile(fileToBeDeleted,
+                        replacementFile, true);
+
+                if (delete)
+                {
+                  // User has confirmed delete -- no need to add it to the list
+                  fileToBeDeleted.delete();
+                }
+                else
+                {
+                  fileToBeDeleted.renameTo(oldestTempFile);
+                }
+              }
+              else
+              {
+                fileToBeDeleted.renameTo(oldestTempFile);
+                addDeleteFile(oldestTempFile);
+              }
+
+            } catch (Exception e)
+            {
+              System.out.println(
+                      "Error occurred, probably making new temp file for '"
+                              + fileToBeDeleted.getName() + "'");
+              e.printStackTrace();
+            }
+
+            // reset
+            fileToBeDeleted = null;
+          }
+
+          if (!noMax && n == tempMax && backupfile_n.exists())
+          {
+            fileToBeDeleted = backupfile_n;
+          }
+          else
+          {
+            if (previousFile != null)
+            {
+              ret = ret && backupfile_n.renameTo(previousFile);
+            }
+          }
+
+          previousFile = backupfile_n;
+        }
+
+        // index to use for the latest backup
+        nextIndexNum = 1;
+      }
+      else
+      {
+        // version style numbering (with earliest file deletion if max files
+        // reached)
+
+        bfTreeMap.values().toArray(backupFiles);
+
+        // noMax == true means keep all backup files
+        if ((!noMax) && bfTreeMap.size() >= max)
+        {
+          // need to delete some files to keep number of backups to designated
+          // max
+          int numToDelete = bfTreeMap.size() - max + 1;
+          // the "replacement" file is the latest backup file being kept (it's
+          // not replacing though)
+          File replacementFile = numToDelete < backupFiles.length
+                  ? backupFiles[numToDelete]
+                  : null;
+          for (int i = 0; i < numToDelete; i++)
+          {
+            // check the deletion files for modification time of the last
+            // backupfile being saved
+            File fileToBeDeleted = backupFiles[i];
+            boolean delete = true;
+
+            boolean newer = false;
+            if (replacementFile != null)
+            {
+              long fileToBeDeletedLMT = fileToBeDeleted.lastModified();
+              long replacementFileLMT = replacementFile != null
+                      ? replacementFile.lastModified()
+                      : Long.MAX_VALUE;
+              if (fileToBeDeletedLMT > replacementFileLMT)
+              {
+                String fileToBeDeletedLMTString = sdf
+                        .format(fileToBeDeletedLMT);
+                String replacementFileLMTString = sdf
+                        .format(replacementFileLMT);
+
+                System.out
+                        .println("WARNING! I am set to delete backupfile '"
+                                + fileToBeDeleted.getName()
+                                + "' has modification time "
+                        + fileToBeDeletedLMTString
+                                + " which is newer than the oldest backupfile being kept '"
+                        + replacementFile.getName()
+                                + "' with modification time "
+                        + replacementFileLMTString);
+
+                delete = confirmNewerDeleteFile(fileToBeDeleted,
+                        replacementFile, false);
+                if (delete)
+                {
+                  // User has confirmed delete -- no need to add it to the list
+                  fileToBeDeleted.delete();
+                  delete = false;
+                }
+                else
+                {
+                  // keeping file, nothing to do!
+                }
+              }
+            }
+            if (delete)
+            {
+              addDeleteFile(fileToBeDeleted);
+            }
+
+          }
+
+        }
+
+        nextIndexNum = bfTreeMap.lastKey() + 1;
+      }
+    }
+
+    // Let's make the new backup file!! yay, got there at last!
+    String latestBackupFilename = dir + File.separatorChar
+            + BackupFilenameParts.getBackupFilename(nextIndexNum, basename,
+                    suffix, digits);
+    ret |= file.renameTo(new File(latestBackupFilename));
+
+    if (tidyUp)
+    {
+      tidyUpFiles();
+    }
+
+    return ret;
+  }
+
+  private static File nextTempFile(String filename, File dirFile)
+          throws IOException
+  {
+    File temp = null;
+    COUNT: for (int i = 1; i < 1000; i++)
+    {
+      File trythis = new File(dirFile,
+              filename + '~' + Integer.toString(i));
+      if (!trythis.exists())
+      {
+        temp = trythis;
+        break COUNT;
+      }
+
+    }
+    if (temp == null)
+    {
+      temp = File.createTempFile(filename, TEMP_FILE_EXT, dirFile);
+    }
+    return temp;
+  }
+
+  private void tidyUpFiles()
+  {
+    deleteOldFiles();
+  }
+
+  private static boolean confirmNewerDeleteFile(File fileToBeDeleted,
+          File replacementFile, boolean replace)
+  {
+    StringBuilder messageSB = new StringBuilder();
+
+    File ftbd = fileToBeDeleted;
+    String ftbdLMT = sdf.format(ftbd.lastModified());
+    String ftbdSize = Long.toString(ftbd.length());
+
+    File rf = replacementFile;
+    String rfLMT = sdf.format(rf.lastModified());
+    String rfSize = Long.toString(rf.length());
+
+    int confirmButton = JvOptionPane.NO_OPTION;
+    if (replace)
+    {
+      File saveFile = null;
+      try
+      {
+        saveFile = nextTempFile(ftbd.getName(), ftbd.getParentFile());
+      } catch (Exception e)
+      {
+        System.out.println(
+                "Error when confirming to keep backup file newer than other backup files.");
+        e.printStackTrace();
+      }
+      messageSB.append(MessageManager.formatMessage(
+              "label.newerdelete_replacement_line", new String[]
+              { ftbd.getName(), rf.getName(), ftbdLMT, rfLMT, ftbdSize,
+                  rfSize }));
+      messageSB.append("\n\n");
+      messageSB.append(MessageManager.formatMessage(
+              "label.confirm_deletion_or_rename", new String[]
+              { ftbd.getName(), saveFile.getName() }));
+      String[] options = new String[] {
+          MessageManager.getString("label.delete"),
+          MessageManager.getString("label.rename") };
+
+      confirmButton = JvOptionPane.showOptionDialog(Desktop.desktop,
+              messageSB.toString(),
+              MessageManager.getString("label.backupfiles_confirm_delete"),
+              JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE,
+              null, options, options[0]);
+    }
+    else
+    {
+      messageSB.append(MessageManager
+              .formatMessage("label.newerdelete_line", new String[]
+              { ftbd.getName(), rf.getName(), ftbdLMT, rfLMT, ftbdSize,
+                  rfSize }));
+      messageSB.append("\n\n");
+      messageSB.append(MessageManager
+              .formatMessage("label.confirm_deletion", new String[]
+              { ftbd.getName() }));
+      String[] options = new String[] {
+          MessageManager.getString("label.delete"),
+          MessageManager.getString("label.keep") };
+
+      confirmButton = JvOptionPane.showOptionDialog(Desktop.desktop,
+              messageSB.toString(),
+              MessageManager.getString("label.backupfiles_confirm_delete"),
+              JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE,
+              null, options, options[0]);
+    }
+
+
+    // return should be TRUE if file is to be deleted
+    return (confirmButton == JvOptionPane.YES_OPTION);
+  }
+
+  private void deleteOldFiles()
+  {
+    if (deleteFiles != null && !deleteFiles.isEmpty())
+    {
+      boolean doDelete = false;
+      StringBuilder messageSB = null;
+      if (confirmDelete && deleteFiles.size() > 0)
+      {
+        messageSB = new StringBuilder();
+        messageSB.append(MessageManager
+                .getString("label.backupfiles_confirm_delete_old_files"));
+        for (int i = 0; i < deleteFiles.size(); i++)
+        {
+          File df = deleteFiles.get(i);
+          messageSB.append("\n");
+          messageSB.append(df.getName());
+          messageSB.append(" ");
+          messageSB.append(MessageManager.formatMessage("label.file_info",
+                  new String[]
+                  { sdf.format(df.lastModified()),
+                      Long.toString(df.length()) }));
+        }
+
+        int confirmButton = JvOptionPane.showConfirmDialog(Desktop.desktop,
+                messageSB.toString(),
+                MessageManager
+                        .getString("label.backupfiles_confirm_delete"),
+                JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE);
+
+        doDelete = (confirmButton == JvOptionPane.YES_OPTION);
+      }
+      else
+      {
+        doDelete = true;
+      }
+
+      if (doDelete)
+      {
+        for (int i = 0; i < deleteFiles.size(); i++)
+        {
+          File fileToDelete = deleteFiles.get(i);
+          fileToDelete.delete();
+          System.out.println("DELETING '" + fileToDelete.getName() + "'");
+        }
+      }
+
+    }
+
+    deleteFiles.clear();
+  }
+
+  private TreeMap<Integer, File> sortBackupFilesAsTreeMap(
+          File[] backupFiles,
+          String basename)
+  {
+    // sort the backup files (based on integer found in the suffix) using a
+    // precomputed Hashmap for speed
+    Map<Integer, File> bfHashMap = new HashMap<>();
+    for (int i = 0; i < backupFiles.length; i++)
+    {
+      File f = backupFiles[i];
+      BackupFilenameParts bfp = new BackupFilenameParts(f, basename, suffix,
+              digits);
+      bfHashMap.put(bfp.indexNum(), f);
+    }
+    TreeMap<Integer, File> bfTreeMap = new TreeMap<>();
+    bfTreeMap.putAll(bfHashMap);
+    return bfTreeMap;
+  }
+
+  public boolean rollBackupsAndRenameTempFile()
+  {
+    boolean write = this.getWriteSuccess();
+
+    boolean roll = false;
+    boolean rename = false;
+    if (write)
+    {
+      roll = this.rollBackupFiles(false);
+      rename = this.renameTempFile();
+    }
+
+    /*
+     * Not sure that this confirmation is desirable.  By this stage the new file is
+     * already written successfully, but something (e.g. disk full) has happened while 
+     * trying to roll the backup files, and most likely the filename needed will already
+     * be vacant so renaming the temp file is nearly always correct!
+     */
+    boolean okay = roll && rename;
+    if (!okay)
+    {
+      StringBuilder messageSB = new StringBuilder();
+      messageSB.append(MessageManager.getString( "label.backupfiles_confirm_save_file_backupfiles_roll_wrong"));
+      if (rename)
+      {
+        if (messageSB.length() > 0)
+        {
+          messageSB.append("\n");
+        }
+        messageSB.append(MessageManager.getString(
+                "label.backupfiles_confirm_save_new_saved_file_ok"));
+      }
+      else
+      {
+        if (messageSB.length() > 0)
+        {
+          messageSB.append("\n");
+        }
+        messageSB.append(MessageManager.getString(
+                "label.backupfiles_confirm_save_new_saved_file_not_ok"));
+      }
+
+      int confirmButton = JvOptionPane.showConfirmDialog(Desktop.desktop,
+              messageSB.toString(),
+              MessageManager
+                      .getString("label.backupfiles_confirm_save_file"),
+              JvOptionPane.OK_OPTION, JvOptionPane.WARNING_MESSAGE);
+      okay = confirmButton == JvOptionPane.OK_OPTION;
+    }
+    if (okay)
+    {
+      tidyUpFiles();
+    }
+
+    return rename;
+  }
+
+  public static TreeMap<Integer, File> getBackupFilesAsTreeMap(
+          String fileName, String suffix, int digits)
+  {
+    File[] backupFiles = null;
+
+    File file = new File(fileName);
+
+    File dirFile;
+    try
+    {
+      dirFile = file.getParentFile();
+    } catch (Exception e)
+    {
+      System.out.println(
+              "Could not get canonical path for file '" + file + "'");
+      return new TreeMap<>();
+    }
+
+    String filename = file.getName();
+    String basename = filename;
+
+    // find existing backup files
+    BackupFilenameFilter bff = new BackupFilenameFilter(basename, suffix,
+            digits);
+    backupFiles = dirFile.listFiles(bff); // is clone needed?
+
+    // sort the backup files (based on integer found in the suffix) using a
+    // precomputed Hashmap for speed
+    Map<Integer, File> bfHashMap = new HashMap<>();
+    for (int i = 0; i < backupFiles.length; i++)
+    {
+      File f = backupFiles[i];
+      BackupFilenameParts bfp = new BackupFilenameParts(f, basename, suffix,
+              digits);
+      bfHashMap.put(bfp.indexNum(), f);
+    }
+    TreeMap<Integer, File> bfTreeMap = new TreeMap<>();
+    bfTreeMap.putAll(bfHashMap);
+
+    return bfTreeMap;
+  }
+
+  /*
+  private boolean addDeleteFile(File fileToBeDeleted, File originalFile,
+          boolean delete, boolean newer)
+  {
+    return addDeleteFile(fileToBeDeleted, originalFile, null, delete, newer);
+  }
+  */
+  private boolean addDeleteFile(File fileToBeDeleted)
+  {
+    boolean ret = false;
+    int pos = deleteFiles.indexOf(fileToBeDeleted);
+    if (pos > -1)
+    {
+      return true;
+    }
+    else
+    {
+      deleteFiles.add(fileToBeDeleted);
+    }
+    return ret;
+  }
+
+}
index 169da5a..12ad0d4 100755 (executable)
@@ -24,6 +24,7 @@ import jalview.analysis.AlignmentUtils;
 import jalview.analysis.SequenceIdMatcher;
 import jalview.api.AlignViewportI;
 import jalview.api.FeatureColourI;
+import jalview.api.FeatureRenderer;
 import jalview.api.FeaturesSourceI;
 import jalview.datamodel.AlignedCodonFrame;
 import jalview.datamodel.Alignment;
@@ -562,28 +563,27 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI
   }
 
   /**
-   * Returns contents of a Jalview format features file, for visible features, as
-   * filtered by type and group. Features with a null group are displayed if their
-   * feature type is visible. Non-positional features may optionally be included
-   * (with no check on type or group).
+   * Returns contents of a Jalview format features file, for visible features,
+   * as filtered by type and group. Features with a null group are displayed if
+   * their feature type is visible. Non-positional features may optionally be
+   * included (with no check on type or group).
    * 
    * @param sequences
-   *          source of features
-   * @param visible
-   *          map of colour for each visible feature type
-   * @param featureFilters
-   * @param visibleFeatureGroups
+   * @param fr
    * @param includeNonPositional
    *          if true, include non-positional features (regardless of group or
    *          type)
    * @return
    */
   public String printJalviewFormat(SequenceI[] sequences,
-          Map<String, FeatureColourI> visible,
-          Map<String, FeatureMatcherSetI> featureFilters,
-          List<String> visibleFeatureGroups, boolean includeNonPositional)
+          FeatureRenderer fr, boolean includeNonPositional)
   {
-    if (!includeNonPositional && (visible == null || visible.isEmpty()))
+    Map<String, FeatureColourI> visibleColours = fr
+            .getDisplayedFeatureCols();
+    Map<String, FeatureMatcherSetI> featureFilters = fr.getFeatureFilters();
+
+    if (!includeNonPositional
+            && (visibleColours == null || visibleColours.isEmpty()))
     {
       // no point continuing.
       return "No Features Visible";
@@ -594,9 +594,10 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI
      */
     // TODO: decide if feature links should also be written here ?
     StringBuilder out = new StringBuilder(256);
-    if (visible != null)
+    if (visibleColours != null)
     {
-      for (Entry<String, FeatureColourI> featureColour : visible.entrySet())
+      for (Entry<String, FeatureColourI> featureColour : visibleColours
+              .entrySet())
       {
         FeatureColourI colour = featureColour.getValue();
         out.append(colour.toJalviewFormat(featureColour.getKey())).append(
@@ -604,50 +605,22 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI
       }
     }
 
-    String[] types = visible == null ? new String[0] : visible.keySet()
-            .toArray(new String[visible.keySet().size()]);
+    String[] types = visibleColours == null ? new String[0]
+            : visibleColours.keySet()
+                    .toArray(new String[visibleColours.keySet().size()]);
 
     /*
      * feature filters if any
      */
-    outputFeatureFilters(out, visible, featureFilters);
-
-    /*
-     * sort groups alphabetically, and ensure that features with a
-     * null or empty group are output after those in named groups
-     */
-    List<String> sortedGroups = new ArrayList<>(visibleFeatureGroups);
-    sortedGroups.remove(null);
-    sortedGroups.remove("");
-    Collections.sort(sortedGroups);
-    sortedGroups.add(null);
-    sortedGroups.add("");
-
-    boolean foundSome = false;
-
-    /*
-     * first output any non-positional features
-     */
-    if (includeNonPositional)
-    {
-      for (int i = 0; i < sequences.length; i++)
-      {
-        String sequenceName = sequences[i].getName();
-        for (SequenceFeature feature : sequences[i].getFeatures()
-                .getNonPositionalFeatures())
-        {
-          foundSome = true;
-          out.append(formatJalviewFeature(sequenceName, feature));
-        }
-      }
-    }
+    outputFeatureFilters(out, visibleColours, featureFilters);
 
     /*
-     * positional features within groups
+     * output features within groups
      */
-    foundSome |= outputFeaturesByGroup(out, sortedGroups, types, sequences);
+    int count = outputFeaturesByGroup(out, fr, types, sequences,
+            includeNonPositional);
 
-    return foundSome ? out.toString() : "No Features Visible";
+    return count > 0 ? out.toString() : "No Features Visible";
   }
 
   /**
@@ -685,65 +658,104 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI
     }
     if (!first)
     {
-      out.append(ENDFILTERS).append(newline).append(newline);
+      out.append(ENDFILTERS).append(newline);
     }
 
   }
 
   /**
-   * Appends output of sequence features within feature groups to the output
-   * buffer. Groups other than the null or empty group are sandwiched by
-   * STARTGROUP and ENDGROUP lines.
+   * Appends output of visible sequence features within feature groups to the
+   * output buffer. Groups other than the null or empty group are sandwiched by
+   * STARTGROUP and ENDGROUP lines. Answers the number of features written.
    * 
    * @param out
-   * @param groups
+   * @param fr
    * @param featureTypes
    * @param sequences
+   * @param includeNonPositional
    * @return
    */
-  private boolean outputFeaturesByGroup(StringBuilder out,
-          List<String> groups, String[] featureTypes, SequenceI[] sequences)
+  private int outputFeaturesByGroup(StringBuilder out,
+          FeatureRenderer fr, String[] featureTypes,
+          SequenceI[] sequences, boolean includeNonPositional)
   {
-    boolean foundSome = false;
-    for (String group : groups)
+    List<String> featureGroups = fr.getFeatureGroups();
+
+    /*
+     * sort groups alphabetically, and ensure that features with a
+     * null or empty group are output after those in named groups
+     */
+    List<String> sortedGroups = new ArrayList<>(featureGroups);
+    sortedGroups.remove(null);
+    sortedGroups.remove("");
+    Collections.sort(sortedGroups);
+    sortedGroups.add(null);
+    sortedGroups.add("");
+
+    int count = 0;
+    List<String> visibleGroups = fr.getDisplayedFeatureGroups();
+
+    /*
+     * loop over all groups (may be visible or not);
+     * non-positional features are output even if group is not visible
+     */
+    for (String group : sortedGroups)
     {
-      boolean isNamedGroup = (group != null && !"".equals(group));
-      if (isNamedGroup)
-      {
-        out.append(newline);
-        out.append(STARTGROUP).append(TAB);
-        out.append(group);
-        out.append(newline);
-      }
+      boolean firstInGroup = true;
+      boolean isNullGroup = group == null || "".equals(group);
 
-      /*
-       * output positional features within groups
-       */
       for (int i = 0; i < sequences.length; i++)
       {
         String sequenceName = sequences[i].getName();
         List<SequenceFeature> features = new ArrayList<>();
-        if (featureTypes.length > 0)
+
+        /*
+         * get any non-positional features in this group, if wanted
+         * (for any feature type, whether visible or not)
+         */
+        if (includeNonPositional)
+        {
+          features.addAll(sequences[i].getFeatures()
+                  .getFeaturesForGroup(false, group));
+        }
+
+        /*
+         * add positional features for visible feature types, but
+         * (for named groups) only if feature group is visible
+         */
+        if (featureTypes.length > 0
+                && (isNullGroup || visibleGroups.contains(group)))
         {
           features.addAll(sequences[i].getFeatures().getFeaturesForGroup(
                   true, group, featureTypes));
         }
 
-        for (SequenceFeature sequenceFeature : features)
+        for (SequenceFeature sf : features)
         {
-          foundSome = true;
-          out.append(formatJalviewFeature(sequenceName, sequenceFeature));
+          if (sf.isNonPositional() || fr.isVisible(sf))
+          {
+            count++;
+            if (firstInGroup)
+            {
+              out.append(newline);
+              if (!isNullGroup)
+              {
+                out.append(STARTGROUP).append(TAB).append(group)
+                        .append(newline);
+              }
+            }
+            firstInGroup = false;
+            out.append(formatJalviewFeature(sequenceName, sf));
+          }
         }
       }
 
-      if (isNamedGroup)
+      if (!isNullGroup && !firstInGroup)
       {
-        out.append(ENDGROUP).append(TAB);
-        out.append(group);
-        out.append(newline);
+        out.append(ENDGROUP).append(TAB).append(group).append(newline);
       }
     }
-    return foundSome;
+    return count;
   }
 
   /**
@@ -872,23 +884,23 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI
    * @return
    */
   public String printGffFormat(SequenceI[] sequences,
-          Map<String, FeatureColourI> visible,
-          List<String> visibleFeatureGroups,
-          boolean includeNonPositionalFeatures)
+          FeatureRenderer fr, boolean includeNonPositionalFeatures)
   {
+    Map<String, FeatureColourI> visibleColours = fr.getDisplayedFeatureCols();
+
     StringBuilder out = new StringBuilder(256);
 
     out.append(String.format("%s %d\n", GFF_VERSION, gffVersion == 0 ? 2 : gffVersion));
 
     if (!includeNonPositionalFeatures
-            && (visible == null || visible.isEmpty()))
+            && (visibleColours == null || visibleColours.isEmpty()))
     {
       return out.toString();
     }
 
-    String[] types = visible == null ? new String[0] : visible.keySet()
-            .toArray(
-            new String[visible.keySet().size()]);
+    String[] types = visibleColours == null ? new String[0]
+            : visibleColours.keySet()
+                    .toArray(new String[visibleColours.keySet().size()]);
 
     for (SequenceI seq : sequences)
     {
@@ -897,21 +909,23 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI
       {
         features.addAll(seq.getFeatures().getNonPositionalFeatures());
       }
-      if (visible != null && !visible.isEmpty())
+      if (visibleColours != null && !visibleColours.isEmpty())
       {
         features.addAll(seq.getFeatures().getPositionalFeatures(types));
       }
 
       for (SequenceFeature sf : features)
       {
-        String source = sf.featureGroup;
-        if (!sf.isNonPositional() && source != null
-                && !visibleFeatureGroups.contains(source))
+        if (!sf.isNonPositional() && !fr.isVisible(sf))
         {
-          // group is not visible
+          /*
+           * feature hidden by group visibility, colour threshold,
+           * or feature filter condition
+           */
           continue;
         }
 
+        String source = sf.featureGroup;
         if (source == null)
         {
           source = sf.getDescription();
index 78f646c..3afbaad 100755 (executable)
@@ -443,7 +443,7 @@ public class FileLoader implements Runnable
               alignFrame.getViewport()
                       .applyFeaturesStyle(proxyColourScheme);
             }
-            alignFrame.statusBar.setText(MessageManager.formatMessage(
+            alignFrame.setStatus(MessageManager.formatMessage(
                     "label.successfully_loaded_file", new String[]
                     { title }));
 
index 7a21c16..7fbe801 100755 (executable)
@@ -30,6 +30,8 @@ import java.awt.Component;
 import java.awt.Dimension;
 import java.awt.EventQueue;
 import java.awt.HeadlessException;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
 import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
 import java.io.File;
@@ -38,12 +40,17 @@ import java.util.List;
 import java.util.StringTokenizer;
 import java.util.Vector;
 
+import javax.swing.BoxLayout;
 import javax.swing.DefaultListCellRenderer;
+import javax.swing.JCheckBox;
 import javax.swing.JFileChooser;
 import javax.swing.JList;
 import javax.swing.JPanel;
 import javax.swing.JScrollPane;
 import javax.swing.SpringLayout;
+import javax.swing.SwingUtilities;
+import javax.swing.border.TitledBorder;
+import javax.swing.filechooser.FileFilter;
 import javax.swing.plaf.basic.BasicFileChooserUI;
 
 /**
@@ -58,6 +65,14 @@ import javax.swing.plaf.basic.BasicFileChooserUI;
 public class JalviewFileChooser extends JFileChooser
 {
   /**
+   * backupfilesCheckBox = "Include backup files" checkbox includeBackupfiles =
+   * flag set by checkbox
+   */
+  private JCheckBox backupfilesCheckBox = null;
+
+  protected boolean includeBackupFiles = false;
+
+  /**
    * Factory method to return a file chooser that offers readable alignment file
    * formats
    * 
@@ -68,6 +83,12 @@ public class JalviewFileChooser extends JFileChooser
   public static JalviewFileChooser forRead(String directory,
           String selected)
   {
+    return JalviewFileChooser.forRead(directory, selected, false);
+  }
+
+  public static JalviewFileChooser forRead(String directory,
+          String selected, boolean allowBackupFiles)
+  {
     List<String> extensions = new ArrayList<>();
     List<String> descs = new ArrayList<>();
     for (FileFormatI format : FileFormats.getInstance().getFormats())
@@ -78,9 +99,11 @@ public class JalviewFileChooser extends JFileChooser
         descs.add(format.getName());
       }
     }
+
     return new JalviewFileChooser(directory,
             extensions.toArray(new String[extensions.size()]),
-            descs.toArray(new String[descs.size()]), selected, true);
+            descs.toArray(new String[descs.size()]), selected, true,
+            allowBackupFiles);
   }
 
   /**
@@ -139,6 +162,12 @@ public class JalviewFileChooser extends JFileChooser
   JalviewFileChooser(String dir, String[] extensions, String[] descs,
           String selected, boolean allFiles)
   {
+    this(dir, extensions, descs, selected, allFiles, false);
+  }
+
+  public JalviewFileChooser(String dir, String[] extensions, String[] descs,
+          String selected, boolean allFiles, boolean allowBackupFiles)
+  {
     super(safePath(dir));
     if (extensions.length == descs.length)
     {
@@ -147,7 +176,7 @@ public class JalviewFileChooser extends JFileChooser
       {
         formats.add(new String[] { extensions[i], descs[i] });
       }
-      init(formats, selected, allFiles);
+      init(formats, selected, allFiles, allowBackupFiles);
     }
     else
     {
@@ -181,6 +210,12 @@ public class JalviewFileChooser extends JFileChooser
    */
   void init(List<String[]> formats, String selected, boolean allFiles)
   {
+    init(formats, selected, allFiles, false);
+  }
+
+  void init(List<String[]> formats, String selected, boolean allFiles,
+          boolean allowBackupFiles)
+  {
 
     JalviewFileFilter chosen = null;
 
@@ -191,6 +226,10 @@ public class JalviewFileChooser extends JFileChooser
     for (String[] format : formats)
     {
       JalviewFileFilter jvf = new JalviewFileFilter(format[0], format[1]);
+      if (allowBackupFiles)
+      {
+        jvf.setParentJFC(this);
+      }
       addChoosableFileFilter(jvf);
       if ((selected != null) && selected.equalsIgnoreCase(format[1]))
       {
@@ -203,7 +242,64 @@ public class JalviewFileChooser extends JFileChooser
       setFileFilter(chosen);
     }
 
-    setAccessory(new RecentlyOpened());
+    if (allowBackupFiles)
+    {
+      JPanel multi = new JPanel();
+      multi.setLayout(new BoxLayout(multi, BoxLayout.PAGE_AXIS));
+      if (backupfilesCheckBox == null)
+      {
+        try {
+          includeBackupFiles = Boolean.parseBoolean(
+                  Cache.getProperty(BackupFiles.NS + "_FC_INCLUDE"));
+        } catch (Exception e)
+        {
+          includeBackupFiles = false;
+        }
+        backupfilesCheckBox = new JCheckBox(
+                MessageManager.getString("label.include_backup_files"),
+                includeBackupFiles);
+        backupfilesCheckBox.setAlignmentX(Component.CENTER_ALIGNMENT);
+        JalviewFileChooser jfc = this;
+        backupfilesCheckBox.addActionListener(new ActionListener()
+        {
+          @Override
+          public void actionPerformed(ActionEvent e)
+          {
+            includeBackupFiles = backupfilesCheckBox.isSelected();
+            Cache.setProperty(BackupFiles.NS + "_FC_INCLUDE",
+                    String.valueOf(includeBackupFiles));
+
+            FileFilter f = jfc.getFileFilter();
+            // deselect the selected file if it's no longer choosable
+            File selectedFile = jfc.getSelectedFile();
+            if (selectedFile != null && !f.accept(selectedFile))
+            {
+              jfc.setSelectedFile(null);
+            }
+            // fake the OK button changing (to force it to upate)
+            String s = jfc.getApproveButtonText();
+            jfc.firePropertyChange(
+                    APPROVE_BUTTON_TEXT_CHANGED_PROPERTY, null, s);
+            // fake the file filter changing (its behaviour actually has)
+            jfc.firePropertyChange(FILE_FILTER_CHANGED_PROPERTY, null, f);
+
+            jfc.rescanCurrentDirectory();
+            jfc.revalidate();
+            jfc.repaint();
+          }
+        });
+      }
+      multi.add(new RecentlyOpened());
+      multi.add(backupfilesCheckBox);
+      setAccessory(multi);
+    }
+    else
+    {
+      // set includeBackupFiles=false to avoid other file choosers from picking
+      // up backup files (Just In Case)
+      includeBackupFiles = false;
+      setAccessory(new RecentlyOpened());
+    }
   }
 
   @Override
@@ -295,14 +391,29 @@ public class JalviewFileChooser extends JFileChooser
   public int showSaveDialog(Component parent) throws HeadlessException
   {
     this.setAccessory(null);
+    this.setSelectedFile(null);
+    return super.showSaveDialog(parent);
+  }
 
-    setDialogType(SAVE_DIALOG);
+  /**
+   * If doing a Save, and an existing file is chosen or entered, prompt for
+   * confirmation of overwrite. Proceed if Yes, else leave the file chooser
+   * open.
+   * 
+   * @see https://stackoverflow.com/questions/8581215/jfilechooser-and-checking-for-overwrite
+   */
+  @Override
+  public void approveSelection()
+  {
+    if (getDialogType() != SAVE_DIALOG)
+    {
+      super.approveSelection();
+      return;
+    }
 
-    this.setSelectedFile(null);
-    int ret = showDialog(parent, MessageManager.getString("action.save"));
     ourselectedFile = getSelectedFile();
 
-    if (getSelectedFile() == null)
+    if (ourselectedFile == null)
     {
       // Workaround for Java 9,10 on OSX - no selected file, but there is a
       // filename typed in
@@ -319,11 +430,15 @@ public class JalviewFileChooser extends JFileChooser
                 "Unexpected exception when trying to get filename.");
         x.printStackTrace();
       }
+      // TODO: ENSURE THAT FILES SAVED WITH A ':' IN THE NAME ARE REFUSED AND
+      // THE
+      // USER PROMPTED FOR A NEW FILENAME
     }
     if (ourselectedFile == null)
     {
-      return JalviewFileChooser.CANCEL_OPTION;
+      return;
     }
+
     if (getFileFilter() instanceof JalviewFileFilter)
     {
       JalviewFileFilter jvf = (JalviewFileFilter) getFileFilter();
@@ -336,23 +451,21 @@ public class JalviewFileChooser extends JFileChooser
         setSelectedFile(ourselectedFile);
       }
     }
-    // TODO: ENSURE THAT FILES SAVED WITH A ':' IN THE NAME ARE REFUSED AND THE
-    // USER PROMPTED FOR A NEW FILENAME
-    if ((ret == JalviewFileChooser.APPROVE_OPTION)
-            && ourselectedFile.exists())
+
+    if (ourselectedFile.exists())
     {
-      int confirm = JvOptionPane.showConfirmDialog(parent,
+      int confirm = JvOptionPane.showConfirmDialog(this,
               MessageManager.getString("label.overwrite_existing_file"),
               MessageManager.getString("label.file_already_exists"),
               JvOptionPane.YES_NO_OPTION);
 
       if (confirm != JvOptionPane.YES_OPTION)
       {
-        ret = JalviewFileChooser.CANCEL_OPTION;
+        return;
       }
     }
 
-    return ret;
+    super.approveSelection();
   }
 
   void recentListSelectionChanged(Object selection)
@@ -375,28 +488,35 @@ public class JalviewFileChooser extends JFileChooser
     }
   }
 
+  /**
+   * A panel to set as the 'accessory' component to the file chooser dialog,
+   * holding a list of recently opened files (if any). These are held as a
+   * tab-separated list of file paths under key <code>RECENT_FILE</code> in
+   * <code>.jalview_properties</code>. A click in the list calls a method in
+   * JalviewFileChooser to set the chosen file as the selection.
+   */
   class RecentlyOpened extends JPanel
   {
-    JList list;
+    private static final long serialVersionUID = 1L;
 
-    public RecentlyOpened()
-    {
+    private JList<String> list;
 
-      String historyItems = jalview.bin.Cache.getProperty("RECENT_FILE");
+    RecentlyOpened()
+    {
+      String historyItems = Cache.getProperty("RECENT_FILE");
       StringTokenizer st;
-      Vector recent = new Vector();
+      Vector<String> recent = new Vector<>();
 
       if (historyItems != null)
       {
         st = new StringTokenizer(historyItems, "\t");
-
         while (st.hasMoreTokens())
         {
-          recent.addElement(st.nextElement());
+          recent.addElement(st.nextToken());
         }
       }
 
-      list = new JList(recent);
+      list = new JList<>(recent);
 
       DefaultListCellRenderer dlcr = new DefaultListCellRenderer();
       dlcr.setHorizontalAlignment(DefaultListCellRenderer.RIGHT);
@@ -411,7 +531,7 @@ public class JalviewFileChooser extends JFileChooser
         }
       });
 
-      this.setBorder(new javax.swing.border.TitledBorder(
+      this.setBorder(new TitledBorder(
               MessageManager.getString("label.recently_opened")));
 
       final JScrollPane scroller = new JScrollPane(list);
@@ -422,7 +542,7 @@ public class JalviewFileChooser extends JFileChooser
       layout.putConstraint(SpringLayout.NORTH, scroller, 5,
               SpringLayout.NORTH, this);
 
-      if (new Platform().isAMac())
+      if (Platform.isAMac())
       {
         scroller.setPreferredSize(new Dimension(500, 100));
       }
@@ -433,7 +553,7 @@ public class JalviewFileChooser extends JFileChooser
 
       this.add(scroller);
 
-      javax.swing.SwingUtilities.invokeLater(new Runnable()
+      SwingUtilities.invokeLater(new Runnable()
       {
         @Override
         public void run()
@@ -442,8 +562,6 @@ public class JalviewFileChooser extends JFileChooser
                   .setValue(scroller.getHorizontalScrollBar().getMaximum());
         }
       });
-
     }
-
   }
 }
index 21f5b0f..bc20342 100755 (executable)
@@ -41,6 +41,8 @@ public class JalviewFileFilter extends FileFilter
 
   private boolean useExtensionsInDescription = true;
 
+  private JalviewFileChooser parentJFC = null;
+
   public JalviewFileFilter(String extension, String description)
   {
     StringTokenizer st = new StringTokenizer(extension, ",");
@@ -81,6 +83,7 @@ public class JalviewFileFilter extends FileFilter
   @Override
   public boolean accept(File f)
   {
+
     if (f != null)
     {
       String extension = getExtension(f);
@@ -94,8 +97,31 @@ public class JalviewFileFilter extends FileFilter
       {
         return true;
       }
+
     }
 
+    if (parentJFC != null && parentJFC.includeBackupFiles)
+    {
+      Iterator<String> it = filters.keySet().iterator();
+      EXTENSION: while (it.hasNext())
+      {
+        String ext = it.next();
+
+        // quick negative test
+        if (!f.getName().contains(ext))
+        {
+          continue EXTENSION;
+        }
+
+        BackupFilenameParts bfp = BackupFilenameParts
+                .currentBackupFilenameParts(f.getName(), ext, true);
+        if (bfp.isBackupFile())
+        {
+          return true;
+        }
+      }
+    }
+    
     return false;
   }
 
@@ -178,4 +204,10 @@ public class JalviewFileFilter extends FileFilter
   {
     return useExtensionsInDescription;
   }
+
+  protected void setParentJFC(JalviewFileChooser p)
+  {
+    this.parentJFC = p;
+  }
+
 }
index 18114f3..52d130c 100755 (executable)
  */
 package jalview.io;
 
+import jalview.util.MessageManager;
+
 import java.io.File;
 import java.net.URL;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.Map;
 
 import javax.swing.Icon;
@@ -55,7 +58,9 @@ public class JalviewFileView extends FileView
   public String getTypeDescription(File f)
   {
     String extension = getExtension(f);
+    
     String type = getDescriptionForExtension(extension);
+    
     if (extension != null)
     {
       if (extensions.containsKey(extension))
@@ -84,8 +89,34 @@ public class JalviewFileView extends FileView
   {
     String extension = getExtension(f);
     Icon icon = null;
+    String type = getDescriptionForExtension(extension);
+
+    if (type == null)
+    {
+      Iterator<String> it = extensions.keySet().iterator();
+      EXTENSION: while (it.hasNext())
+      {
+        String ext = it.next();
+
+        // quick negative test
+        if (!f.getName().contains(ext))
+        {
+          continue EXTENSION;
+        }
+
+        BackupFilenameParts bfp = BackupFilenameParts
+                .currentBackupFilenameParts(f.getName(), ext, true);
+        if (bfp.isBackupFile())
+        {
+          extension = ext;
+          type = getDescriptionForExtension(extension)
+                  + MessageManager.getString("label.backup");
+          break;
+        }
+      }
+    }
 
-    if (getDescriptionForExtension(extension) != null)
+    if (type != null)
     {
       icon = getImageIcon("/images/file.png");
     }
index de2f18a..5ba5d93 100644 (file)
@@ -835,33 +835,6 @@ public class VCFLoader
   }
 
   /**
-   * A convenience method to get the AF value for the given alternate allele
-   * index
-   * 
-   * @param variant
-   * @param alleleIndex
-   * @return
-   */
-  protected float getAlleleFrequency(VariantContext variant, int alleleIndex)
-  {
-    float score = 0f;
-    String attributeValue = getAttributeValue(variant,
-            ALLELE_FREQUENCY_KEY, alleleIndex);
-    if (attributeValue != null)
-    {
-      try
-      {
-        score = Float.parseFloat(attributeValue);
-      } catch (NumberFormatException e)
-      {
-        // leave as 0
-      }
-    }
-
-    return score;
-  }
-
-  /**
    * A convenience method to get an attribute value for an alternate allele
    * 
    * @param variant
@@ -981,10 +954,8 @@ public class VCFLoader
       type = getOntologyTerm(consequence);
     }
 
-    float score = getAlleleFrequency(variant, altAlleleIndex);
-
     SequenceFeature sf = new SequenceFeature(type, alleles, featureStart,
-            featureEnd, score, FEATURE_GROUP_VCF);
+            featureEnd, FEATURE_GROUP_VCF);
     sf.setSource(sourceId);
 
     sf.setValue(Gff3Helper.ALLELES, alleles);
index 1cf482d..9f41c92 100755 (executable)
 package jalview.jbgui;
 
 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
+import jalview.analysis.GeneticCodeI;
+import jalview.analysis.GeneticCodes;
 import jalview.api.SplitContainerI;
 import jalview.bin.Cache;
 import jalview.gui.JvSwingUtils;
 import jalview.gui.Preferences;
 import jalview.io.FileFormats;
+import jalview.schemes.ResidueColourScheme;
 import jalview.util.MessageManager;
 import jalview.util.Platform;
 
@@ -75,7 +78,7 @@ public class GAlignFrame extends JInternalFrame
 
   protected JMenu sortByAnnotScore = new JMenu();
 
-  public JLabel statusBar = new JLabel();
+  protected JLabel statusBar = new JLabel();
 
   protected JMenu outputTextboxMenu = new JMenu();
 
@@ -123,7 +126,7 @@ public class GAlignFrame extends JInternalFrame
 
   protected JMenuItem modifyPID;
 
-  protected JMenuItem annotationColour;
+  protected JRadioButtonMenuItem annotationColour;
 
   protected JMenu sortByTreeMenu = new JMenu();
 
@@ -137,7 +140,7 @@ public class GAlignFrame extends JInternalFrame
 
   protected JCheckBoxMenuItem showDbRefsMenuitem = new JCheckBoxMenuItem();
 
-  protected JMenuItem showTranslation = new JMenuItem();
+  protected JMenu showTranslation = new JMenu();
 
   protected JMenuItem showReverse = new JMenuItem();
 
@@ -201,7 +204,7 @@ public class GAlignFrame extends JInternalFrame
 
   private boolean showAutoCalculatedAbove = false;
 
-  private Map<KeyStroke, JMenuItem> accelerators = new HashMap<KeyStroke, JMenuItem>();
+  private Map<KeyStroke, JMenuItem> accelerators = new HashMap<>();
 
   private SplitContainerI splitFrame;
 
@@ -1221,16 +1224,33 @@ public class GAlignFrame extends JInternalFrame
         vamsasStore_actionPerformed(e);
       }
     });
-    showTranslation
-            .setText(MessageManager.getString("label.translate_cDNA"));
-    showTranslation.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
+
+    /*
+     * Translate as cDNA with sub-menu of translation tables
+     */
+    showTranslation.setText(MessageManager
+            .getString("label.translate_cDNA"));
+    boolean first = true;
+    for (final GeneticCodeI table : GeneticCodes.getInstance()
+            .getCodeTables())
+    {
+      JMenuItem item = new JMenuItem(table.getId() + " " + table.getName());
+      showTranslation.add(item);
+      item.addActionListener(new ActionListener()
+      {
+        @Override
+        public void actionPerformed(ActionEvent e)
+        {
+          showTranslation_actionPerformed(table);
+        }
+      });
+      if (first)
       {
-        showTranslation_actionPerformed(e);
+        showTranslation.addSeparator();
       }
-    });
+      first = false;
+    }
+
     showReverse.setText(MessageManager.getString("label.reverse"));
     showReverse.addActionListener(new ActionListener()
     {
@@ -1943,8 +1963,9 @@ public class GAlignFrame extends JInternalFrame
       }
     });
 
-    annotationColour = new JMenuItem(
+    annotationColour = new JRadioButtonMenuItem(
             MessageManager.getString("action.by_annotation"));
+    annotationColour.setName(ResidueColourScheme.ANNOTATION_COLOUR);
     annotationColour.addActionListener(new ActionListener()
     {
       @Override
@@ -2440,7 +2461,7 @@ public class GAlignFrame extends JInternalFrame
 
   }
 
-  public void showTranslation_actionPerformed(ActionEvent e)
+  public void showTranslation_actionPerformed(GeneticCodeI codeTable)
   {
 
   }
diff --git a/src/jalview/jbgui/GDasSourceBrowser.java b/src/jalview/jbgui/GDasSourceBrowser.java
deleted file mode 100755 (executable)
index a91769a..0000000
+++ /dev/null
@@ -1,256 +0,0 @@
-/*
- * 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 <http://www.gnu.org/licenses/>.
- * The Jalview Authors are detailed in the 'AUTHORS' file.
- */
-package jalview.jbgui;
-
-import jalview.util.MessageManager;
-
-import java.awt.BorderLayout;
-import java.awt.Dimension;
-import java.awt.FlowLayout;
-import java.awt.Font;
-import java.awt.GridBagConstraints;
-import java.awt.GridBagLayout;
-import java.awt.Insets;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-
-import javax.swing.BorderFactory;
-import javax.swing.JButton;
-import javax.swing.JEditorPane;
-import javax.swing.JLabel;
-import javax.swing.JList;
-import javax.swing.JPanel;
-import javax.swing.JProgressBar;
-import javax.swing.JScrollPane;
-import javax.swing.JTable;
-import javax.swing.JTextField;
-import javax.swing.SwingConstants;
-import javax.swing.border.TitledBorder;
-import javax.swing.event.HyperlinkEvent;
-import javax.swing.event.HyperlinkListener;
-
-public class GDasSourceBrowser extends JPanel
-{
-  public GDasSourceBrowser()
-  {
-    try
-    {
-      jbInit();
-    } catch (Exception ex)
-    {
-      ex.printStackTrace();
-    }
-  }
-
-  private void jbInit() throws Exception
-  {
-    this.setLayout(gridBagLayout1);
-    refresh.setText(
-            MessageManager.getString("label.refresh_available_sources"));
-    refresh.addActionListener(new ActionListener()
-    {
-      public void actionPerformed(ActionEvent e)
-      {
-        refresh_actionPerformed(e);
-      }
-    });
-    progressBar.setPreferredSize(new Dimension(450, 20));
-    progressBar.setString("");
-    scrollPane.setBorder(titledBorder1);
-    scrollPane.setBorder(BorderFactory.createEtchedBorder());
-    fullDetailsScrollpane.setBorder(BorderFactory.createEtchedBorder());
-    fullDetails.addHyperlinkListener(new HyperlinkListener()
-    {
-      public void hyperlinkUpdate(HyperlinkEvent e)
-      {
-        fullDetails_hyperlinkUpdate(e);
-      }
-    });
-    fullDetails.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
-    fullDetails.setEditable(false);
-    registryLabel.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
-    registryLabel.setHorizontalAlignment(SwingConstants.TRAILING);
-    registryLabel.setText(MessageManager.getString("label.use_registry"));
-    addLocal.setText(MessageManager.getString("label.add_local_source"));
-    addLocal.addActionListener(new ActionListener()
-    {
-      public void actionPerformed(ActionEvent e)
-      {
-        amendLocal(true);
-      }
-    });
-    jPanel1.setLayout(flowLayout1);
-    jPanel1.setMinimumSize(new Dimension(596, 30));
-    jPanel1.setPreferredSize(new Dimension(596, 30));
-    jScrollPane2.setBorder(titledBorder3);
-    jScrollPane3.setBorder(titledBorder4);
-    jScrollPane4.setBorder(titledBorder5);
-    titledBorder2
-            .setTitleFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
-    titledBorder3
-            .setTitleFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
-    titledBorder4
-            .setTitleFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
-    filter1.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
-    filter2.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
-    filter3.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
-    table.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
-    reset.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
-    reset.setMargin(new Insets(2, 2, 2, 2));
-    reset.setText(MessageManager.getString("action.reset"));
-    reset.addActionListener(new ActionListener()
-    {
-      public void actionPerformed(ActionEvent e)
-      {
-        reset_actionPerformed(e);
-      }
-    });
-    jPanel2.setLayout(borderLayout1);
-    borderLayout1.setHgap(5);
-    registryURL.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
-    scrollPane.getViewport().add(table);
-    fullDetailsScrollpane.getViewport().add(fullDetails);
-    jScrollPane3.getViewport().add(filter2);
-    jScrollPane4.getViewport().add(filter3);
-    jPanel1.add(refresh, null);
-    jPanel1.add(addLocal, null);
-    jPanel1.add(progressBar, null);
-    jScrollPane2.getViewport().add(filter1);
-    this.add(jPanel1, new GridBagConstraints(0, 3, 3, 1, 1.0, 1.0,
-            GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
-            new Insets(0, 0, 0, 0), 0, 0));
-    this.add(fullDetailsScrollpane,
-            new GridBagConstraints(1, 0, 2, 1, 1.0, 1.0,
-                    GridBagConstraints.CENTER, GridBagConstraints.BOTH,
-                    new Insets(3, 0, 0, 3), 240, 130));
-    this.add(scrollPane,
-            new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0,
-                    GridBagConstraints.CENTER, GridBagConstraints.BOTH,
-                    new Insets(3, 2, 0, 0), 150, 130));
-    jPanel2.add(registryLabel, java.awt.BorderLayout.WEST);
-    jPanel2.add(registryURL, java.awt.BorderLayout.CENTER);
-    jPanel2.add(reset, java.awt.BorderLayout.EAST);
-    this.add(jPanel2, new GridBagConstraints(0, 2, 3, 1, 0.0, 0.0,
-            GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
-            new Insets(5, 10, 0, 10), 339, 0));
-    this.add(jScrollPane2,
-            new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0,
-                    GridBagConstraints.CENTER, GridBagConstraints.BOTH,
-                    new Insets(0, 0, 0, 60), 80, 60));
-    this.add(jScrollPane4,
-            new GridBagConstraints(2, 1, 1, 1, 1.0, 1.0,
-                    GridBagConstraints.CENTER, GridBagConstraints.BOTH,
-                    new Insets(0, -80, 0, 0), 80, 60));
-    this.add(jScrollPane3,
-            new GridBagConstraints(1, 1, 1, 1, 1.0, 1.0,
-                    GridBagConstraints.CENTER, GridBagConstraints.BOTH,
-                    new Insets(0, -60, 0, 80), 80, 60));
-  }
-
-  protected JTable table = new JTable();
-
-  protected JEditorPane fullDetails = new JEditorPane("text/html", "");
-
-  TitledBorder titledBorder1 = new TitledBorder(
-          MessageManager.getString("label.available_das_sources"));
-
-  protected JButton refresh = new JButton();
-
-  protected JProgressBar progressBar = new JProgressBar();
-
-  protected JScrollPane scrollPane = new JScrollPane();
-
-  TitledBorder titledBorder2 = new TitledBorder(
-          MessageManager.getString("label.full_details"));
-
-  protected JScrollPane fullDetailsScrollpane = new JScrollPane();
-
-  protected JList filter1 = new JList();
-
-  protected JList filter2 = new JList();
-
-  protected JList filter3 = new JList();
-
-  JScrollPane jScrollPane2 = new JScrollPane();
-
-  JScrollPane jScrollPane3 = new JScrollPane();
-
-  JScrollPane jScrollPane4 = new JScrollPane();
-
-  protected JTextField registryURL = new JTextField();
-
-  protected JLabel registryLabel = new JLabel();
-
-  protected JButton addLocal = new JButton();
-
-  JPanel jPanel1 = new JPanel();
-
-  FlowLayout flowLayout1 = new FlowLayout();
-
-  GridBagLayout gridBagLayout1 = new GridBagLayout();
-
-  TitledBorder titledBorder3 = new TitledBorder(
-          MessageManager.getString("label.authority") + ":");
-
-  TitledBorder titledBorder4 = new TitledBorder(
-          MessageManager.getString("label.type") + ":");
-
-  TitledBorder titledBorder5 = new TitledBorder(
-          MessageManager.getString("label.label") + ":");
-
-  JButton reset = new JButton();
-
-  JPanel jPanel2 = new JPanel();
-
-  BorderLayout borderLayout1 = new BorderLayout();
-
-  public void refresh_actionPerformed(ActionEvent e)
-  {
-
-  }
-
-  public void fullDetails_hyperlinkUpdate(HyperlinkEvent e)
-  {
-    try
-    {
-
-      if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
-      {
-        jalview.util.BrowserLauncher.openURL(e.getURL().toString());
-      }
-    } catch (Exception ex)
-    {
-      System.out.println(e.getURL());
-      ex.printStackTrace();
-    }
-  }
-
-  public void amendLocal(boolean newSource)
-  {
-
-  }
-
-  public void reset_actionPerformed(ActionEvent e)
-  {
-
-  }
-
-}
index d200d06..2cc86e4 100755 (executable)
@@ -76,6 +76,8 @@ public class GDesktop extends JFrame
 
   JMenuItem saveState = new JMenuItem();
 
+  JMenuItem saveAsState = new JMenuItem();
+
   JMenuItem loadState = new JMenuItem();
 
   JMenu inputMenu = new JMenu();
@@ -248,6 +250,15 @@ public class GDesktop extends JFrame
         saveState_actionPerformed();
       }
     });
+    saveAsState.setText(MessageManager.getString("action.save_project_as"));
+    saveAsState.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        saveAsState_actionPerformed(e);
+      }
+    });
     loadState.setText(MessageManager.getString("action.load_project"));
     loadState.addActionListener(new ActionListener()
     {
@@ -424,6 +435,7 @@ public class GDesktop extends JFrame
     FileMenu.add(inputSequence);
     FileMenu.addSeparator();
     FileMenu.add(saveState);
+    FileMenu.add(saveAsState);
     FileMenu.add(loadState);
     FileMenu.addSeparator();
     FileMenu.add(quit);
@@ -584,6 +596,16 @@ public class GDesktop extends JFrame
   {
   }
 
+  public void saveAsState_actionPerformed(ActionEvent e)
+  {
+  }
+
+  /**
+   * DOCUMENT ME!
+   * 
+   * @param e
+   *          DOCUMENT ME!
+   */
   public void loadState_actionPerformed()
   {
   }
index 1ea4ab5..b433570 100755 (executable)
@@ -47,41 +47,20 @@ import javax.swing.text.JTextComponent;
 
 public class GFinder extends JPanel
 {
-  JLabel jLabelFind = new JLabel();
+  private static final java.awt.Font VERDANA_12 = new java.awt.Font("Verdana", 0,
+          12);
 
-  protected JButton findAll = new JButton();
-
-  protected JButton findNext = new JButton();
-
-  JPanel actionsPanel = new JPanel();
-
-  GridLayout gridLayout1 = new GridLayout();
+  private static final String FINDER_CACHE_KEY = "CACHE.FINDER";
 
   protected JButton createFeatures = new JButton();
 
-  protected JvCacheableInputBox<String> searchBox = new JvCacheableInputBox<String>(
+  protected JvCacheableInputBox<String> searchBox = new JvCacheableInputBox<>(
           getCacheKey());
 
-  BorderLayout mainBorderLayout = new BorderLayout();
-
-  JPanel jPanel2 = new JPanel();
-
-  JPanel jPanel3 = new JPanel();
-
-  JPanel jPanel4 = new JPanel();
-
-  BorderLayout borderLayout2 = new BorderLayout();
-
-  JPanel jPanel6 = new JPanel();
-
   protected JCheckBox caseSensitive = new JCheckBox();
 
   protected JCheckBox searchDescription = new JCheckBox();
 
-  GridLayout optionsGridLayout = new GridLayout();
-
-  private static final String FINDER_CACHE_KEY = "CACHE.FINDER";
-
   public GFinder()
   {
     try
@@ -95,35 +74,47 @@ public class GFinder extends JPanel
 
   private void jbInit() throws Exception
   {
-    jLabelFind.setFont(new java.awt.Font("Verdana", 0, 12));
-    jLabelFind.setText(MessageManager.getString("label.find"));
+    BorderLayout mainBorderLayout = new BorderLayout();
     this.setLayout(mainBorderLayout);
-    findAll.setFont(new java.awt.Font("Verdana", 0, 12));
-    findAll.setText(MessageManager.getString("action.find_all"));
+    mainBorderLayout.setHgap(5);
+    mainBorderLayout.setVgap(5);
+
+    JLabel jLabelFind = new JLabel(MessageManager.getString("label.find"));
+    jLabelFind.setFont(VERDANA_12);
+
+    JButton findAll = new JButton(
+            MessageManager.getString("action.find_all"));
+    findAll.setFont(VERDANA_12);
     findAll.addActionListener(new java.awt.event.ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
       {
-        findAll_actionPerformed(e);
+        findAll_actionPerformed();
       }
     });
-    findNext.setFont(new java.awt.Font("Verdana", 0, 12));
-    findNext.setText(MessageManager.getString("action.find_next"));
+
+    JButton findNext = new JButton(
+            MessageManager.getString("action.find_next"));
+    findNext.setFont(VERDANA_12);
     findNext.addActionListener(new java.awt.event.ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
       {
-        findNext_actionPerformed(e);
+        findNext_actionPerformed();
       }
     });
+
+    JPanel actionsPanel = new JPanel();
+    GridLayout gridLayout1 = new GridLayout();
     actionsPanel.setLayout(gridLayout1);
     gridLayout1.setHgap(0);
     gridLayout1.setRows(3);
     gridLayout1.setVgap(2);
+
     createFeatures.setEnabled(false);
-    createFeatures.setFont(new java.awt.Font("Verdana", 0, 12));
+    createFeatures.setFont(VERDANA_12);
     createFeatures.setMargin(new Insets(0, 0, 0, 0));
     createFeatures.setText(MessageManager.getString("label.new_feature"));
     createFeatures.addActionListener(new java.awt.event.ActionListener()
@@ -141,7 +132,7 @@ public class GFinder extends JPanel
               @Override
               public void caretUpdate(CaretEvent e)
               {
-                textfield_caretUpdate(e);
+                textfield_caretUpdate();
               }
             });
     searchBox.getEditor().getEditorComponent()
@@ -153,11 +144,7 @@ public class GFinder extends JPanel
                 textfield_keyPressed(e);
               }
             });
-    mainBorderLayout.setHgap(5);
-    mainBorderLayout.setVgap(5);
-    jPanel4.setLayout(borderLayout2);
-    jPanel2.setPreferredSize(new Dimension(10, 1));
-    jPanel3.setPreferredSize(new Dimension(10, 1));
+
     caseSensitive.setHorizontalAlignment(SwingConstants.LEFT);
     caseSensitive.setText(MessageManager.getString("label.match_case"));
 
@@ -169,6 +156,13 @@ public class GFinder extends JPanel
     actionsPanel.add(createFeatures, null);
     this.add(jLabelFind, java.awt.BorderLayout.WEST);
     this.add(actionsPanel, java.awt.BorderLayout.EAST);
+
+    JPanel jPanel2 = new JPanel();
+    jPanel2.setPreferredSize(new Dimension(10, 1));
+    JPanel jPanel3 = new JPanel();
+    jPanel3.setPreferredSize(new Dimension(10, 1));
+    JPanel jPanel4 = new JPanel();
+    jPanel4.setLayout(new BorderLayout());
     this.add(jPanel2, java.awt.BorderLayout.SOUTH);
     this.add(jPanel3, java.awt.BorderLayout.NORTH);
     this.add(jPanel4, java.awt.BorderLayout.CENTER);
@@ -176,6 +170,7 @@ public class GFinder extends JPanel
 
     JPanel optionsPanel = new JPanel();
 
+    GridLayout optionsGridLayout = new GridLayout();
     optionsGridLayout.setHgap(0);
     optionsGridLayout.setRows(2);
     optionsGridLayout.setVgap(2);
@@ -193,16 +188,16 @@ public class GFinder extends JPanel
       if (!searchBox.isPopupVisible())
       {
         e.consume();
-        findNext_actionPerformed(null);
+        findNext_actionPerformed();
       }
     }
   }
 
-  protected void findNext_actionPerformed(ActionEvent e)
+  protected void findNext_actionPerformed()
   {
   }
 
-  protected void findAll_actionPerformed(ActionEvent e)
+  protected void findAll_actionPerformed()
   {
   }
 
@@ -210,9 +205,10 @@ public class GFinder extends JPanel
   {
   }
 
-  public void textfield_caretUpdate(CaretEvent e)
+  public void textfield_caretUpdate()
   {
-    if (searchBox.getUserInput().indexOf(">") > -1)
+    // disabled as appears to be running a non-functional
+    if (false && searchBox.getUserInput().indexOf(">") > -1)
     {
       SwingUtilities.invokeLater(new Runnable()
       {
@@ -233,7 +229,7 @@ public class GFinder extends JPanel
             str = jalview.analysis.AlignSeq.extractGaps(
                     jalview.util.Comparison.GapChars,
                     al.getSequenceAt(0).getSequenceAsString());
-
+            // todo and what? set str as searchBox text?
           }
         }
       });
index a183794..122ad0f 100755 (executable)
@@ -46,13 +46,11 @@ public class GPCAPanel extends JInternalFrame
 {
   private static final Font VERDANA_12 = new Font("Verdana", 0, 12);
 
-  protected JComboBox<String> xCombobox = new JComboBox<String>();
+  protected JComboBox<String> xCombobox = new JComboBox<>();
 
-  protected JComboBox<String> yCombobox = new JComboBox<String>();
+  protected JComboBox<String> yCombobox = new JComboBox<>();
 
-  protected JComboBox<String> zCombobox = new JComboBox<String>();
-
-  protected JMenu scoreModelMenu = new JMenu();
+  protected JComboBox<String> zCombobox = new JComboBox<>();
 
   protected JMenu viewMenu = new JMenu();
 
@@ -60,16 +58,15 @@ public class GPCAPanel extends JInternalFrame
 
   protected JMenu associateViewsMenu = new JMenu();
 
-  protected JMenu calcSettings = new JMenu();
-
-  protected JCheckBoxMenuItem nuclSetting = new JCheckBoxMenuItem();
-
-  protected JCheckBoxMenuItem protSetting = new JCheckBoxMenuItem();
-
   protected JLabel statusBar = new JLabel();
 
   protected JPanel statusPanel = new JPanel();
 
+  protected JMenuItem originalSeqData;
+
+  /**
+   * Constructor
+   */
   public GPCAPanel()
   {
     try
@@ -110,7 +107,7 @@ public class GPCAPanel extends JInternalFrame
       @Override
       public void actionPerformed(ActionEvent e)
       {
-        zCombobox_actionPerformed(e);
+        doDimensionChange();
       }
     });
     yCombobox.setFont(VERDANA_12);
@@ -119,7 +116,7 @@ public class GPCAPanel extends JInternalFrame
       @Override
       public void actionPerformed(ActionEvent e)
       {
-        yCombobox_actionPerformed(e);
+        doDimensionChange();
       }
     });
     xCombobox.setFont(VERDANA_12);
@@ -128,7 +125,7 @@ public class GPCAPanel extends JInternalFrame
       @Override
       public void actionPerformed(ActionEvent e)
       {
-        xCombobox_actionPerformed(e);
+        doDimensionChange();
       }
     });
     JButton resetButton = new JButton();
@@ -139,7 +136,7 @@ public class GPCAPanel extends JInternalFrame
       @Override
       public void actionPerformed(ActionEvent e)
       {
-        resetButton_actionPerformed(e);
+        resetButton_actionPerformed();
       }
     });
     JMenu fileMenu = new JMenu();
@@ -152,7 +149,7 @@ public class GPCAPanel extends JInternalFrame
       @Override
       public void actionPerformed(ActionEvent e)
       {
-        eps_actionPerformed(e);
+        eps_actionPerformed();
       }
     });
     JMenuItem png = new JMenuItem("PNG");
@@ -161,7 +158,7 @@ public class GPCAPanel extends JInternalFrame
       @Override
       public void actionPerformed(ActionEvent e)
       {
-        png_actionPerformed(e);
+        png_actionPerformed();
       }
     });
     JMenuItem outputValues = new JMenuItem();
@@ -171,7 +168,7 @@ public class GPCAPanel extends JInternalFrame
       @Override
       public void actionPerformed(ActionEvent e)
       {
-        outputValues_actionPerformed(e);
+        outputValues_actionPerformed();
       }
     });
     JMenuItem outputPoints = new JMenuItem();
@@ -181,7 +178,7 @@ public class GPCAPanel extends JInternalFrame
       @Override
       public void actionPerformed(ActionEvent e)
       {
-        outputPoints_actionPerformed(e);
+        outputPoints_actionPerformed();
       }
     });
     JMenuItem outputProjPoints = new JMenuItem();
@@ -192,7 +189,7 @@ public class GPCAPanel extends JInternalFrame
       @Override
       public void actionPerformed(ActionEvent e)
       {
-        outputProjPoints_actionPerformed(e);
+        outputProjPoints_actionPerformed();
       }
     });
     JMenuItem print = new JMenuItem();
@@ -202,7 +199,7 @@ public class GPCAPanel extends JInternalFrame
       @Override
       public void actionPerformed(ActionEvent e)
       {
-        print_actionPerformed(e);
+        print_actionPerformed();
       }
     });
     viewMenu.setText(MessageManager.getString("action.view"));
@@ -224,33 +221,13 @@ public class GPCAPanel extends JInternalFrame
       {
       }
     });
-    scoreModelMenu
-            .setText(MessageManager.getString("label.select_score_model"));
-    scoreModelMenu.addMenuListener(new MenuListener()
-    {
-      @Override
-      public void menuSelected(MenuEvent e)
-      {
-        scoreModel_menuSelected();
-      }
-
-      @Override
-      public void menuDeselected(MenuEvent e)
-      {
-      }
-
-      @Override
-      public void menuCanceled(MenuEvent e)
-      {
-      }
-    });
     showLabels.setText(MessageManager.getString("label.show_labels"));
     showLabels.addActionListener(new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
       {
-        showLabels_actionPerformed(e);
+        showLabels_actionPerformed();
       }
     });
     JMenuItem bgcolour = new JMenuItem();
@@ -260,47 +237,22 @@ public class GPCAPanel extends JInternalFrame
       @Override
       public void actionPerformed(ActionEvent e)
       {
-        bgcolour_actionPerformed(e);
+        bgcolour_actionPerformed();
       }
     });
-    JMenuItem originalSeqData = new JMenuItem();
+    originalSeqData = new JMenuItem();
     originalSeqData.setText(MessageManager.getString("label.input_data"));
     originalSeqData.addActionListener(new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
       {
-        originalSeqData_actionPerformed(e);
+        originalSeqData_actionPerformed();
       }
     });
     associateViewsMenu.setText(
             MessageManager.getString("label.associate_nodes_with"));
-    calcSettings.setText(MessageManager.getString("action.change_params"));
-    nuclSetting
-            .setText(MessageManager.getString("label.nucleotide_matrix"));
-    protSetting.setText(MessageManager.getString("label.protein_matrix"));
-    nuclSetting.addActionListener(new ActionListener()
-    {
-
-      @Override
-      public void actionPerformed(ActionEvent arg0)
-      {
-        nuclSetting_actionPerfomed(arg0);
-      }
-    });
-    protSetting.addActionListener(new ActionListener()
-    {
-
-      @Override
-      public void actionPerformed(ActionEvent arg0)
-      {
-        protSetting_actionPerfomed(arg0);
-      }
-    });
 
-    calcSettings.add(nuclSetting);
-    calcSettings.add(protSetting);
-    calcSettings.add(scoreModelMenu);
     statusPanel.setLayout(new GridLayout());
     statusBar.setFont(VERDANA_12);
     // statusPanel.setBackground(Color.lightGray);
@@ -321,7 +273,6 @@ public class GPCAPanel extends JInternalFrame
     JMenuBar jMenuBar1 = new JMenuBar();
     jMenuBar1.add(fileMenu);
     jMenuBar1.add(viewMenu);
-    jMenuBar1.add(calcSettings);
     setJMenuBar(jMenuBar1);
     fileMenu.add(saveMenu);
     fileMenu.add(outputValues);
@@ -336,91 +287,51 @@ public class GPCAPanel extends JInternalFrame
     viewMenu.add(associateViewsMenu);
   }
 
-  protected void scoreModel_menuSelected()
-  {
-    // TODO Auto-generated method stub
-
-  }
-
-  protected void resetButton_actionPerformed(ActionEvent e)
+  protected void resetButton_actionPerformed()
   {
-    // TODO Auto-generated method stub
-
   }
 
-  protected void protSetting_actionPerfomed(ActionEvent arg0)
+  protected void outputPoints_actionPerformed()
   {
-    // TODO Auto-generated method stub
-
   }
 
-  protected void nuclSetting_actionPerfomed(ActionEvent arg0)
+  protected void outputProjPoints_actionPerformed()
   {
-    // TODO Auto-generated method stub
-
   }
 
-  protected void outputPoints_actionPerformed(ActionEvent e)
+  protected void eps_actionPerformed()
   {
-    // TODO Auto-generated method stub
-
   }
 
-  protected void outputProjPoints_actionPerformed(ActionEvent e)
+  protected void png_actionPerformed()
   {
-    // TODO Auto-generated method stub
-
   }
 
-  protected void xCombobox_actionPerformed(ActionEvent e)
+  protected void outputValues_actionPerformed()
   {
   }
 
-  protected void yCombobox_actionPerformed(ActionEvent e)
+  protected void print_actionPerformed()
   {
   }
 
-  protected void zCombobox_actionPerformed(ActionEvent e)
+  protected void showLabels_actionPerformed()
   {
   }
 
-  public void eps_actionPerformed(ActionEvent e)
+  protected void bgcolour_actionPerformed()
   {
-
   }
 
-  public void png_actionPerformed(ActionEvent e)
+  protected void originalSeqData_actionPerformed()
   {
-
   }
 
-  public void outputValues_actionPerformed(ActionEvent e)
+  protected void viewMenu_menuSelected()
   {
-
   }
 
-  public void print_actionPerformed(ActionEvent e)
+  protected void doDimensionChange()
   {
-
-  }
-
-  public void showLabels_actionPerformed(ActionEvent e)
-  {
-
-  }
-
-  public void bgcolour_actionPerformed(ActionEvent e)
-  {
-
-  }
-
-  public void originalSeqData_actionPerformed(ActionEvent e)
-  {
-
-  }
-
-  public void viewMenu_menuSelected()
-  {
-
   }
 }
index 6807382..87cc87b 100755 (executable)
  */
 package jalview.jbgui;
 
+import jalview.bin.Cache;
 import jalview.fts.core.FTSDataColumnPreferences;
 import jalview.fts.core.FTSDataColumnPreferences.PreferenceSource;
 import jalview.fts.service.pdb.PDBFTSRestClient;
+import jalview.gui.Desktop;
+import jalview.gui.JalviewBooleanRadioButtons;
+import jalview.gui.JvOptionPane;
 import jalview.gui.JvSwingUtils;
 import jalview.gui.StructureViewer.ViewerType;
+import jalview.io.BackupFilenameParts;
+import jalview.io.BackupFiles;
 import jalview.util.MessageManager;
 
 import java.awt.BorderLayout;
@@ -42,8 +48,11 @@ import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.FocusEvent;
 import java.awt.event.KeyEvent;
+import java.awt.event.KeyListener;
 import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
+import java.util.HashMap;
+import java.util.Map;
 
 import javax.swing.AbstractCellEditor;
 import javax.swing.BorderFactory;
@@ -54,13 +63,18 @@ import javax.swing.JCheckBox;
 import javax.swing.JComboBox;
 import javax.swing.JFileChooser;
 import javax.swing.JLabel;
+import javax.swing.JList;
 import javax.swing.JPanel;
 import javax.swing.JRadioButton;
 import javax.swing.JScrollPane;
+import javax.swing.JSpinner;
 import javax.swing.JTabbedPane;
 import javax.swing.JTable;
+import javax.swing.JTextArea;
 import javax.swing.JTextField;
 import javax.swing.ListSelectionModel;
+import javax.swing.SpinnerModel;
+import javax.swing.SpinnerNumberModel;
 import javax.swing.SwingConstants;
 import javax.swing.border.Border;
 import javax.swing.border.EmptyBorder;
@@ -84,6 +98,9 @@ public class GPreferences extends JPanel
   private static final Font LABEL_FONT_ITALIC = JvSwingUtils
           .getLabelFont(false, true);
 
+  private static final Font LABEL_FONT_BOLD = JvSwingUtils
+          .getLabelFont(true, false);
+
   /*
    * Visual tab components
    */
@@ -264,12 +281,51 @@ public class GPreferences extends JPanel
 
   protected JCheckBox sortByTree = new JCheckBox();
 
-
   /*
    * Web Services tab
    */
   protected JPanel wsTab = new JPanel();
 
+  /*
+   * Backups tab components
+   * a lot of these are member variables instead of local variables only so that they
+   * can be enabled/disabled easily in one go
+   */
+
+  protected JCheckBox enableBackupFiles = new JCheckBox();
+
+  protected JPanel presetsPanel = new JPanel();
+
+  protected JButton revertButton = new JButton();
+
+  protected JComboBox<IntKeyStringValueEntry> backupfilesPresetsCombo = new JComboBox<>();
+
+  protected JPanel suffixPanel = new JPanel();
+
+  protected JPanel keepfilesPanel = new JPanel();
+
+  protected JPanel exampleFilesPanel = new JPanel();
+
+  protected JTextField suffixTemplate = new JTextField(null, 8);
+
+  protected JLabel suffixTemplateLabel = new JLabel();
+
+  protected JLabel suffixDigitsLabel = new JLabel();
+
+  protected JSpinner suffixDigitsSpinner = new JSpinner();
+
+  protected JalviewBooleanRadioButtons suffixReverse = new JalviewBooleanRadioButtons();
+
+  protected JalviewBooleanRadioButtons backupfilesKeepAll = new JalviewBooleanRadioButtons();
+
+  public JSpinner backupfilesRollMaxSpinner = new JSpinner();
+
+  protected JLabel oldBackupFilesLabel = new JLabel();
+
+  protected JalviewBooleanRadioButtons backupfilesConfirmDelete = new JalviewBooleanRadioButtons();
+
+  protected JTextArea backupfilesExampleLabel = new JTextArea();
+
   /**
    * Creates a new GPreferences object.
    */
@@ -312,6 +368,9 @@ public class GPreferences extends JPanel
     tabbedPane.add(initConnectionsTab(),
             MessageManager.getString("label.connections"));
 
+    tabbedPane.add(initBackupsTab(),
+            MessageManager.getString("label.backups"));
+
     tabbedPane.add(initLinksTab(),
             MessageManager.getString("label.urllinks"));
 
@@ -584,6 +643,7 @@ public class GPreferences extends JPanel
     linkTab.setLayout(new GridBagLayout());
 
     // Set up table for Url links
+    linkUrlTable.getTableHeader().setReorderingAllowed(false);
     linkUrlTable.setFillsViewportHeight(true);
     linkUrlTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
     linkUrlTable.setAutoCreateRowSorter(true);
@@ -1008,14 +1068,13 @@ public class GPreferences extends JPanel
         hiddenColour_actionPerformed(hiddenColour);
       }
     });
-    
+
     useLegacyGap = new JCheckBox(
             MessageManager.getString("label.ov_legacy_gap"));
     useLegacyGap.setFont(LABEL_FONT);
     useLegacyGap.setHorizontalAlignment(SwingConstants.LEFT);
     useLegacyGap.setVerticalTextPosition(SwingConstants.TOP);
-    gapLabel = new JLabel(
-            MessageManager.getString("label.gap_colour"));
+    gapLabel = new JLabel(MessageManager.getString("label.gap_colour"));
     gapLabel.setFont(LABEL_FONT);
     gapLabel.setHorizontalAlignment(SwingConstants.LEFT);
     gapLabel.setVerticalTextPosition(SwingConstants.TOP);
@@ -1630,6 +1689,846 @@ public class GPreferences extends JPanel
     return visualTab;
   }
 
+  /**
+   * Load the saved Backups options EXCEPT "Enabled" and "Scheme"
+   */
+
+  protected void loadLastSavedBackupsOptions()
+  {
+    enableBackupFiles
+            .setSelected(Cache.getDefault(BackupFiles.ENABLED, true));
+    setComboIntStringKey(backupfilesPresetsCombo,
+            Cache.getDefault(BackupFiles.NS + "_PRESET", 1));
+    suffixTemplate.setText(Cache.getDefault(BackupFiles.SUFFIX,
+            ".bak" + BackupFiles.NUM_PLACEHOLDER));
+    suffixDigitsSpinner
+            .setValue(Cache.getDefault(BackupFiles.SUFFIX_DIGITS, 3));
+    suffixReverse.setSelected(
+            Cache.getDefault(BackupFiles.REVERSE_ORDER, false));
+    backupfilesKeepAll
+            .setSelected(Cache.getDefault(BackupFiles.NO_MAX, false));
+    backupfilesRollMaxSpinner
+            .setValue(Cache.getDefault(BackupFiles.ROLL_MAX, 3));
+    backupfilesConfirmDelete.setSelected(
+            Cache.getDefault(BackupFiles.CONFIRM_DELETE_OLD, true));
+
+    backupsOptionsSetEnabled();
+    updateBackupFilesExampleLabel();
+  }
+
+  private boolean warnAboutSuffixReverseChange()
+  {
+    boolean savedSuffixReverse = Cache.getDefault(BackupFiles.REVERSE_ORDER,
+            false);
+    int savedSuffixDigits = Cache.getDefault(BackupFiles.SUFFIX_DIGITS, 3);
+    String savedSuffixTemplate = Cache.getDefault(BackupFiles.SUFFIX,
+            ".bak" + BackupFiles.NUM_PLACEHOLDER);
+
+    boolean nowSuffixReverse = suffixReverse.isSelected();
+    int nowSuffixDigits = getSpinnerInt(suffixDigitsSpinner, 3);
+    String nowSuffixTemplate = suffixTemplate.getText();
+    return nowSuffixReverse != savedSuffixReverse
+            && nowSuffixDigits == savedSuffixDigits
+            && nowSuffixTemplate != null
+            && nowSuffixTemplate.equals(savedSuffixTemplate);
+  }
+
+  /**
+   * Initialises the Backups tabbed panel.
+   * 
+   * @return
+   */
+  private JPanel initBackupsTab()
+  {
+    JPanel backupsTab = new JPanel();
+    backupsTab.setBorder(new TitledBorder(
+            MessageManager.getString("label.backup_files")));
+    backupsTab.setLayout(new GridBagLayout());
+
+    GridBagConstraints gbc = new GridBagConstraints();
+    gbc.weightx = 0.0;
+    gbc.weighty = 0.0;
+    gbc.anchor = GridBagConstraints.FIRST_LINE_START;
+    gbc.fill = GridBagConstraints.NONE;
+
+    initBackupsTabPresetsPanel();
+    initBackupsTabSuffixPanel();
+    initBackupsTabKeepFilesPanel();
+    initBackupsTabFilenameExamplesPanel();
+
+    enableBackupFiles.setFont(LABEL_FONT_BOLD);
+    enableBackupFiles
+            .setText(MessageManager.getString("label.enable_backupfiles"));
+    enableBackupFiles.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        // enable other options only when the first is checked
+        backupsOptionsSetEnabled();
+      }
+    });
+
+
+    // enable checkbox 1 col
+    gbc.gridwidth = 1;
+    gbc.gridheight = 1;
+    gbc.gridx = 0;
+    gbc.gridy = 0; // row 0
+    backupsTab.add(enableBackupFiles, gbc);
+
+    // summary of scheme box (over two rows)
+    gbc.gridx = 1;
+    gbc.weightx = 0.0;
+    gbc.gridheight = 2;
+    gbc.anchor = GridBagConstraints.FIRST_LINE_END;
+    gbc.fill = GridBagConstraints.BOTH;
+    backupsTab.add(exampleFilesPanel, gbc);
+    gbc.gridheight = 1;
+    gbc.anchor = GridBagConstraints.FIRST_LINE_START;
+    gbc.fill = GridBagConstraints.NONE;
+
+    // fill empty space on right
+    gbc.gridx++;
+    gbc.weightx = 1.0;
+    backupsTab.add(new JPanel(), gbc);
+
+    // schemes box
+    gbc.weightx = 0.0;
+    gbc.gridx = 0;
+    gbc.gridy++; // row 1
+    backupsTab.add(presetsPanel, gbc);
+
+    // gbc.anchor = GridBagConstraints.NORTHWEST;
+    // now using whole row
+    gbc.gridwidth = 2;
+    gbc.gridheight = 1;
+    // keep files box
+    gbc.gridx = 0;
+    gbc.gridy++; // row 2
+    backupsTab.add(keepfilesPanel, gbc);
+
+    // filename strategy box
+    gbc.gridy++; // row 3
+    backupsTab.add(suffixPanel, gbc);
+
+    // fill empty space
+    gbc.gridy++; // row 4
+    gbc.weighty = 1.0;
+    backupsTab.add(new JPanel(), gbc);
+
+    backupsOptionsSetEnabled();
+    return backupsTab;
+  }
+
+  protected static final int BACKUPFILESSCHEMECUSTOMISE = 0;
+
+  private static final IntKeyStringValueEntry[] backupfilesPresetEntries = {
+      new IntKeyStringValueEntry(1,
+              MessageManager.getString("label.default")),
+      new IntKeyStringValueEntry(2,
+              MessageManager.getString("label.single_file")),
+      new IntKeyStringValueEntry(3,
+              MessageManager.getString("label.keep_all_versions")),
+      new IntKeyStringValueEntry(4,
+              MessageManager.getString("label.rolled_backups")),
+      // ...
+      // IMPORTANT, keep "Custom" entry with key 0 (even though it appears last)
+      new IntKeyStringValueEntry(BACKUPFILESSCHEMECUSTOMISE,
+              MessageManager.getString("label.customise")) };
+
+  private static final Map<Integer, BackupFilesPresetEntry> backupfilesPresetEntriesValues = new HashMap<Integer, BackupFilesPresetEntry>()
+  {
+    /**
+     * 
+     */
+    private static final long serialVersionUID = 125L;
+
+    {
+      put(1, new BackupFilesPresetEntry(
+              ".bak" + BackupFiles.NUM_PLACEHOLDER, 3, false, false, 3,
+              false));
+      put(2, new BackupFilesPresetEntry("~", 1, false, false, 1, false));
+      put(3, new BackupFilesPresetEntry(".v" + BackupFiles.NUM_PLACEHOLDER,
+              3, false, true, 10, true));
+      put(4, new BackupFilesPresetEntry(
+              "_bak." + BackupFiles.NUM_PLACEHOLDER, 1, true, false, 9,
+              false));
+    }
+  };
+
+  private JPanel initBackupsTabPresetsPanel()
+  {
+
+    String title = MessageManager.getString("label.schemes");
+    // TitledBorder tb = new TitledBorder(new EmptyBorder(0, 0, 0, 0), title);
+    // TitledBorder tb = new TitledBorder(title);
+    // tb.setTitleFont(LABEL_FONT);
+    // presetsPanel.setBorder(tb);
+
+    presetsPanel.setLayout(new GridBagLayout());
+
+    GridBagConstraints gbc = new GridBagConstraints();
+    gbc.weightx = 0.0;
+    gbc.weighty = 0.0;
+    gbc.anchor = GridBagConstraints.BASELINE_LEADING;
+    gbc.fill = GridBagConstraints.NONE;
+    gbc.gridwidth = 1;
+    gbc.gridheight = 1;
+
+    // "Scheme: "
+    gbc.gridx = 0;
+    gbc.gridy = 0;
+    presetsPanel.add(new JLabel(title + ":"), gbc);
+
+    for (int i = 0; i < backupfilesPresetEntries.length; i++)
+    {
+      backupfilesPresetsCombo.addItem(backupfilesPresetEntries[i]);
+    }
+
+    // put "Previously saved scheme" item in italics (it's not really
+    // selectable, as such -- it deselects itself when selected) and
+    // "Customise" in bold
+    backupfilesPresetsCombo
+            .setRenderer(new BackupFilesPresetsComboBoxRenderer());
+    backupfilesPresetsCombo.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        backupsTabUpdatePresets();
+      }
+    });
+
+    // dropdown list of preset schemes
+    gbc.gridx = 1;
+    presetsPanel.add(backupfilesPresetsCombo, gbc);
+
+    revertButton.setText(MessageManager.getString("label.cancel_changes"));
+    revertButton.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        loadLastSavedBackupsOptions();
+      }
+
+    });
+    revertButton.setFont(LABEL_FONT);
+
+    // "Cancel changes" button (aligned with combo box above)
+    gbc.gridx = 1;
+    gbc.gridy++;
+    presetsPanel.add(revertButton, gbc);
+
+    return presetsPanel;
+  }
+
+  private JPanel initBackupsTabFilenameExamplesPanel()
+  {
+    String title = MessageManager
+            .getString("label.summary_of_backups_scheme");
+    TitledBorder tb = new TitledBorder(title);
+    exampleFilesPanel.setBorder(tb);
+    exampleFilesPanel.setLayout(new GridBagLayout());
+
+
+    backupfilesExampleLabel.setEditable(false);
+    backupfilesExampleLabel
+            .setBackground(exampleFilesPanel.getBackground());
+
+    updateBackupFilesExampleLabel();
+
+    GridBagConstraints gbc = new GridBagConstraints();
+    gbc.weightx = 1.0;
+    gbc.weighty = 1.0;
+    gbc.fill = GridBagConstraints.NONE;
+    gbc.anchor = GridBagConstraints.FIRST_LINE_START;
+
+    exampleFilesPanel.add(backupfilesExampleLabel, gbc);
+    return exampleFilesPanel;
+  }
+
+  private void backupsTabUpdatePresets()
+  {
+    IntKeyStringValueEntry entry = (IntKeyStringValueEntry) backupfilesPresetsCombo
+            .getSelectedItem();
+    int key = entry.getKey();
+    String value = entry.getValue();
+
+    // BACKUPFILESSCHEMECUSTOMISE (==0) reserved for "Custom"
+    if (key != BACKUPFILESSCHEMECUSTOMISE)
+    {
+      if (backupfilesPresetEntriesValues.containsKey(key))
+      {
+        backupsSetOptions(backupfilesPresetEntriesValues.get(key));
+      }
+      else
+      {
+        System.out.println("Preset '" + value + "' not implemented");
+      }
+    }
+
+    backupfilesCustomOptionsSetEnabled();
+    updateBackupFilesExampleLabel();
+  }
+
+  protected int getComboIntStringKey(JComboBox<IntKeyStringValueEntry> c)
+  {
+    IntKeyStringValueEntry e = (IntKeyStringValueEntry) c.getSelectedItem();
+    return e != null ? e.getKey() : 0;
+  }
+
+  protected void setComboIntStringKey(JComboBox<IntKeyStringValueEntry> c,
+          int key)
+  {
+    for (int i = 0; i < c.getItemCount(); i++)
+    {
+      IntKeyStringValueEntry e = c.getItemAt(i);
+      if (e.getKey() == key)
+      {
+        c.setSelectedIndex(i);
+        break;
+      }
+    }
+    backupsTabUpdatePresets();
+  }
+
+  private JPanel initBackupsTabSuffixPanel()
+  {
+    suffixPanel.setBorder(new TitledBorder(
+            MessageManager.getString("label.backup_filename_strategy")));
+    suffixPanel.setLayout(new GridBagLayout());
+
+    suffixTemplateLabel
+            .setText(MessageManager.getString("label.append_to_filename"));
+    suffixTemplateLabel.setHorizontalAlignment(SwingConstants.LEFT);
+    suffixTemplateLabel.setFont(LABEL_FONT);
+
+    final String tooltip = JvSwingUtils.wrapTooltip(true,
+            MessageManager.getString("label.append_to_filename_tooltip"));
+    suffixTemplate.setToolTipText(tooltip);
+    suffixTemplate.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        updateBackupFilesExampleLabel();
+        backupfilesCustomOptionsSetEnabled();
+      }
+
+    });
+    KeyListener kl = new KeyListener()
+    {
+      @Override
+      public void keyReleased(KeyEvent e)
+      {
+        updateBackupFilesExampleLabel();
+        backupfilesCustomOptionsSetEnabled();
+      }
+
+      @Override
+      public void keyPressed(KeyEvent e)
+      {
+      }
+
+      // disable use of ':' or '/' or '\'
+      @Override
+      public void keyTyped(KeyEvent e)
+      {
+        char c = e.getKeyChar();
+        if (c == ':' || c == '/' || c == '\\')
+        {
+          // don't process ':' or '/' or '\'
+          e.consume();
+        }
+      }
+
+    };
+    suffixTemplate.addKeyListener(kl);
+
+    // digits spinner
+    suffixDigitsLabel
+            .setText(MessageManager.getString("label.index_digits"));
+    suffixDigitsLabel.setHorizontalAlignment(SwingConstants.LEFT);
+    suffixDigitsLabel.setFont(LABEL_FONT);
+    int defaultmin = 1;
+    int defaultmax = 6;
+    ChangeListener c = new ChangeListener()
+    {
+      @Override
+      public void stateChanged(ChangeEvent e)
+      {
+        updateBackupFilesExampleLabel();
+      }
+
+    };
+    setIntegerSpinner(suffixDigitsSpinner, defaultmin, defaultmax, 3, c);
+
+    suffixReverse.setLabels(MessageManager.getString("label.reverse_roll"),
+            MessageManager.getString("label.increment_index"));
+    suffixReverse.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        boolean okay = true;
+        if (warnAboutSuffixReverseChange())
+        {
+          // Warning popup
+          okay = confirmSuffixReverseChange();
+        }
+        if (okay)
+        {
+          updateBackupFilesExampleLabel();
+        }
+        else
+        {
+          boolean savedSuffixReverse = Cache
+                  .getDefault(BackupFiles.REVERSE_ORDER, false);
+          suffixReverse.setSelected(savedSuffixReverse);
+        }
+      }
+    });
+
+    GridBagConstraints sgbc = new GridBagConstraints();
+
+    // first row (template text box)
+    sgbc.anchor = GridBagConstraints.WEST;
+    sgbc.gridx = 0;
+    sgbc.gridy = 0;
+    sgbc.gridwidth = 1;
+    sgbc.gridheight = 1;
+    sgbc.weightx = 1.0;
+    sgbc.weighty = 0.0;
+    sgbc.fill = GridBagConstraints.NONE;
+    suffixPanel.add(suffixTemplateLabel, sgbc);
+
+    sgbc.gridx = 1;
+    sgbc.fill = GridBagConstraints.HORIZONTAL;
+    suffixPanel.add(suffixTemplate, sgbc);
+
+    // second row (number of digits spinner)
+    sgbc.gridy = 1;
+
+    sgbc.gridx = 0;
+    sgbc.fill = GridBagConstraints.NONE;
+    suffixPanel.add(suffixDigitsLabel, sgbc);
+
+    sgbc.gridx = 1;
+    sgbc.fill = GridBagConstraints.HORIZONTAL;
+    suffixPanel.add(suffixDigitsSpinner, sgbc);
+
+    // third row (forward order radio selection)
+    sgbc.gridx = 0;
+    sgbc.gridy = 2;
+    sgbc.gridwidth = GridBagConstraints.REMAINDER;
+    sgbc.fill = GridBagConstraints.HORIZONTAL;
+    suffixPanel.add(suffixReverse.getFalseButton(), sgbc);
+
+    // fourth row (reverse order radio selection)
+    sgbc.gridy = 3;
+    suffixPanel.add(suffixReverse.getTrueButton(), sgbc);
+    return suffixPanel;
+  }
+
+  private boolean confirmSuffixReverseChange()
+  {
+    boolean ret = false;
+    String warningMessage = MessageManager
+            .getString("label.warning_confirm_change_reverse");
+    int confirm = JvOptionPane.showConfirmDialog(Desktop.desktop,
+            warningMessage,
+            MessageManager.getString("label.change_increment_decrement"),
+            JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE);
+
+    ret = (confirm == JvOptionPane.YES_OPTION);
+    return ret;
+  }
+
+  private JPanel initBackupsTabKeepFilesPanel()
+  {
+    keepfilesPanel.setBorder(
+            new TitledBorder(MessageManager.getString("label.keep_files")));
+    keepfilesPanel.setLayout(new GridBagLayout());
+
+    backupfilesKeepAll.setLabels(
+            MessageManager.getString("label.keep_all_backup_files"),
+            MessageManager.getString(
+                    "label.keep_only_this_number_of_backup_files"));
+    backupfilesKeepAll.addTrueActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        updateBackupFilesExampleLabel();
+      }
+    });
+    backupfilesKeepAll.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        keepRollMaxOptionsEnabled();
+        updateBackupFilesExampleLabel();
+      }
+    });
+
+    ChangeListener c = new ChangeListener()
+    {
+      @Override
+      public void stateChanged(ChangeEvent e)
+      {
+        updateBackupFilesExampleLabel();
+      }
+
+    };
+    setIntegerSpinner(backupfilesRollMaxSpinner, 1, 999, 4, true, c);
+
+    backupfilesConfirmDelete.setLabels(
+            MessageManager.getString("label.always_ask"),
+            MessageManager.getString("label.auto_delete"));
+    // update the enabled section
+    keepRollMaxOptionsEnabled();
+
+    GridBagConstraints kgbc = new GridBagConstraints();
+
+    // first row (template text box)
+    kgbc.anchor = GridBagConstraints.WEST;
+    kgbc.gridx = 0;
+    kgbc.gridy = 0;
+    kgbc.gridwidth = GridBagConstraints.REMAINDER;
+    kgbc.gridheight = 1;
+    kgbc.weightx = 1.0;
+    kgbc.weighty = 0.0;
+    kgbc.fill = GridBagConstraints.HORIZONTAL;
+    keepfilesPanel.add(backupfilesKeepAll.getTrueButton(), kgbc);
+
+    // second row
+    kgbc.gridy = 1;
+
+    kgbc.gridx = 0;
+    kgbc.gridwidth = GridBagConstraints.RELATIVE;
+    keepfilesPanel.add(backupfilesKeepAll.getFalseButton(), kgbc);
+
+    kgbc.gridx = 1;
+    kgbc.gridwidth = GridBagConstraints.REMAINDER;
+    keepfilesPanel.add(backupfilesRollMaxSpinner, kgbc);
+
+    // third row (indented)
+    kgbc.gridy = 2;
+    kgbc.insets = new Insets(0, 20, 0, 0);
+
+    kgbc.gridx = 0;
+    kgbc.gridwidth = GridBagConstraints.REMAINDER;
+    kgbc.fill = GridBagConstraints.HORIZONTAL;
+    kgbc.weightx = 1.0;
+    /*
+    keepfilesPanel.add(backupfilesConfirmDelete.getTrueButton(), kgbc);
+    
+    // fourth row (indented)
+    kgbc.gridy = 3;
+    keepfilesPanel.add(backupfilesConfirmDelete.getFalseButton(), kgbc);
+    */
+
+    JPanel jp = new JPanel();
+    jp.setLayout(new FlowLayout());
+    oldBackupFilesLabel
+            .setText(MessageManager
+                    .getString("label.autodelete_old_backup_files"));
+    oldBackupFilesLabel.setFont(LABEL_FONT);
+    oldBackupFilesLabel.setHorizontalAlignment(SwingConstants.LEFT);
+    jp.add(oldBackupFilesLabel);
+    jp.add(backupfilesConfirmDelete.getTrueButton());
+    jp.add(backupfilesConfirmDelete.getFalseButton());
+    keepfilesPanel.add(jp, kgbc);
+
+    return keepfilesPanel;
+  }
+
+  protected void updateBackupFilesExampleLabel()
+  {
+    int exampleindex = 12;
+    String base = MessageManager.getString("label.filename") + ".fa";
+    if (base == null || base.length() == 0)
+    {
+      base = "file_name.fa";
+    }
+
+    boolean reverse = suffixReverse.isSelected();
+    boolean keepAll = backupfilesKeepAll.isSelected();
+    int rollMax = 4;
+    String suffix = suffixTemplate.getText();
+    int digits = 3;
+
+    backupfilesExampleLabel.setFont(LABEL_FONT_ITALIC);
+    if (suffix == null || suffix.length() == 0)
+    {
+      backupfilesExampleLabel
+              .setText(MessageManager.getString("label.no_backup_files"));
+      backupfilesExampleLabel.setFont(LABEL_FONT_BOLD);
+      return;
+    }
+
+    rollMax = getSpinnerInt(backupfilesRollMaxSpinner, 4);
+    rollMax = rollMax < 1 ? 1 : rollMax;
+
+    if (suffix.indexOf(BackupFiles.NUM_PLACEHOLDER) == -1)
+    {
+      rollMax = 1;
+    }
+
+    digits = getSpinnerInt(suffixDigitsSpinner, 3);
+    digits = digits < 1 ? 1 : digits;
+
+    int lowersurround = 2;
+    int uppersurround = 0;
+    StringBuilder exampleSB = new StringBuilder();
+    boolean firstLine = true;
+    if (reverse)
+    {
+
+      int min = 1;
+      int max = keepAll ? exampleindex : rollMax;
+      for (int index = min; index <= max; index++)
+      {
+        if (index == min + lowersurround && index < max - uppersurround - 1)
+        {
+          exampleSB.append("\n...");
+        }
+        else if (index > min + lowersurround && index < max - uppersurround)
+        {
+          // nothing
+        }
+        else
+        {
+          if (firstLine)
+          {
+            firstLine = false;
+          }
+          else
+          {
+            exampleSB.append("\n");
+          }
+          exampleSB.append(BackupFilenameParts.getBackupFilename(index,
+                  base, suffix, digits));
+          if (min == max)
+          {
+            // no extra text needed
+          }
+          else if (index == min)
+          {
+            String newest = MessageManager.getString("label.braced_newest");
+            if (newest != null && newest.length() > 0)
+            {
+              exampleSB.append(" " + newest);
+            }
+          }
+          else if (index == max)
+          {
+            String oldest = MessageManager.getString("label.braced_oldest");
+            if (oldest != null && oldest.length() > 0)
+            {
+              exampleSB.append(" " + oldest);
+            }
+          }
+        }
+      }
+    }
+    else
+    {
+
+      int min = (keepAll || exampleindex - rollMax < 0) ? 1
+              : exampleindex - rollMax + 1;
+      int max = exampleindex;
+
+      for (int index = min; index <= max; index++)
+      {
+
+        if (index == min + lowersurround && index < max - uppersurround - 1)
+        {
+          exampleSB.append("\n...");
+        }
+        else if (index > min + lowersurround && index < max - uppersurround)
+        {
+          // nothing
+        }
+        else
+        {
+          if (firstLine)
+          {
+            firstLine = false;
+          }
+          else
+          {
+            exampleSB.append("\n");
+          }
+          exampleSB.append(BackupFilenameParts.getBackupFilename(index,
+                  base, suffix, digits));
+          if (min == max)
+          {
+            // no extra text needed
+          }
+          else if (index == min)
+          {
+            String oldest = MessageManager.getString("label.braced_oldest");
+            if (oldest != null && oldest.length() > 0)
+            {
+              exampleSB.append(" " + oldest);
+            }
+          }
+          else if (index == max)
+          {
+            String newest = MessageManager.getString("label.braced_newest");
+            if (newest != null && newest.length() > 0)
+            {
+              exampleSB.append(" " + newest);
+            }
+          }
+        }
+      }
+
+    }
+
+    backupfilesExampleLabel.setText(exampleSB.toString());
+  }
+
+  protected void setIntegerSpinner(JSpinner s, int min, int max, int def,
+          boolean useExistingVal, ChangeListener c)
+  {
+    int i = def;
+    if (useExistingVal)
+    {
+      try
+      {
+        i = Integer.parseInt((String) s.getValue());
+      } catch (Exception e)
+      {
+        System.out.println(
+                "Exception casting the initial value of s.getValue()");
+      }
+    }
+
+    setIntegerSpinner(s, min, max, i, c);
+  }
+
+  protected void setIntegerSpinner(JSpinner s, int min, int max, int def,
+          ChangeListener c)
+  {
+    // integer spinner for number of digits
+    if (def > max)
+    {
+      max = def;
+    }
+    SpinnerModel sModel = new SpinnerNumberModel(def, min, max, 1);
+    s.setModel(sModel);
+
+    s.addChangeListener(c);
+
+  }
+
+  protected static int getSpinnerInt(JSpinner s, int def)
+  {
+    int i = def;
+    try
+    {
+      s.commitEdit();
+      i = (Integer) s.getValue();
+    } catch (Exception e)
+    {
+      System.out.println("Failed casting (Integer) JSpinner s.getValue()");
+    }
+    return i;
+  }
+
+  private void keepRollMaxOptionsEnabled()
+  {
+    boolean enabled = backupfilesKeepAll.isEnabled()
+            && !backupfilesKeepAll.isSelected();
+    oldBackupFilesLabel.setEnabled(enabled);
+    backupfilesRollMaxSpinner.setEnabled(enabled);
+    backupfilesConfirmDelete.setEnabled(enabled);
+  }
+
+  private void backupfilesKeepAllSetEnabled(boolean tryEnabled)
+  {
+    boolean enabled = tryEnabled && enableBackupFiles.isSelected()
+            && getComboIntStringKey(backupfilesPresetsCombo) == 0
+            && suffixTemplate.getText()
+                    .indexOf(BackupFiles.NUM_PLACEHOLDER) > -1;
+    keepfilesPanel.setEnabled(enabled);
+    backupfilesKeepAll.setEnabled(enabled);
+    oldBackupFilesLabel.setEnabled(enabled);
+    keepRollMaxOptionsEnabled();
+  }
+
+  private void backupfilesSuffixTemplateDigitsSetEnabled()
+  {
+    boolean enabled = suffixTemplate.isEnabled() && suffixTemplate.getText()
+            .indexOf(BackupFiles.NUM_PLACEHOLDER) > -1;
+    suffixDigitsLabel.setEnabled(enabled);
+    suffixDigitsSpinner.setEnabled(enabled);
+    suffixReverse.setEnabled(enabled);
+  }
+
+  private void backupfilesSuffixTemplateSetEnabled(boolean tryEnabled)
+  {
+    boolean enabled = tryEnabled && enableBackupFiles.isSelected()
+            && getComboIntStringKey(backupfilesPresetsCombo) == 0;
+    suffixPanel.setEnabled(enabled);
+    suffixTemplateLabel.setEnabled(enabled);
+    suffixTemplate.setEnabled(enabled);
+    backupfilesSuffixTemplateDigitsSetEnabled();
+  }
+
+  protected void backupfilesCustomOptionsSetEnabled()
+  {
+    int scheme = getComboIntStringKey(backupfilesPresetsCombo);
+    boolean enabled = scheme == 0 && enableBackupFiles.isSelected();
+
+    backupfilesSuffixTemplateSetEnabled(enabled);
+    backupfilesKeepAllSetEnabled(enabled);
+  }
+
+  private void backupfilesSummarySetEnabled()
+  {
+    boolean enabled = enableBackupFiles.isSelected();
+    backupfilesExampleLabel.setEnabled(enabled);
+    exampleFilesPanel.setEnabled(enabled);
+  }
+
+  private void backupfilesPresetsSetEnabled()
+  {
+    boolean enabled = enableBackupFiles.isSelected();
+    presetsPanel.setEnabled(enabled);
+    backupfilesPresetsCombo.setEnabled(enabled);
+  }
+
+  protected void backupsOptionsSetEnabled()
+  {
+    backupfilesPresetsSetEnabled();
+    backupfilesSummarySetEnabled();
+    backupfilesCustomOptionsSetEnabled();
+  }
+
+  protected void backupsSetOptions(String suffix, int digits,
+          boolean reverse, boolean keepAll, int rollMax,
+          boolean confirmDelete)
+  {
+    suffixTemplate.setText(suffix);
+    suffixDigitsSpinner.setValue(digits);
+    suffixReverse.setSelected(reverse);
+    backupfilesKeepAll.setSelected(keepAll);
+    backupfilesRollMaxSpinner.setValue(rollMax);
+    backupfilesConfirmDelete.setSelected(confirmDelete);
+  }
+
+  protected void backupsSetOptions(BackupFilesPresetEntry p)
+  {
+    backupsSetOptions(p.suffix, p.digits, p.reverse, p.keepAll, p.rollMax,
+            p.confirmDelete);
+  }
+
   protected void autoIdWidth_actionPerformed()
   {
     // TODO Auto-generated method stub
@@ -1815,3 +2714,86 @@ public class GPreferences extends JPanel
 
   }
 }
+
+class IntKeyStringValueEntry
+{
+  int k;
+
+  String v;
+
+  public IntKeyStringValueEntry(int k, String v)
+  {
+    this.k = k;
+    this.v = v;
+  }
+
+  @Override
+  public String toString()
+  {
+    return this.getValue();
+  }
+
+  public int getKey()
+  {
+    return k;
+  }
+
+  public String getValue()
+  {
+    return v;
+  }
+}
+
+class BackupFilesPresetEntry
+{
+  String suffix;
+
+  int digits;
+
+  boolean reverse;
+
+  boolean keepAll;
+
+  int rollMax;
+
+  boolean confirmDelete;
+
+  public BackupFilesPresetEntry(String suffix, int digits, boolean reverse,
+          boolean keepAll, int rollMax, boolean confirmDelete)
+  {
+    this.suffix = suffix;
+    this.digits = digits;
+    this.reverse = reverse;
+    this.keepAll = keepAll;
+    this.rollMax = rollMax;
+    this.confirmDelete = confirmDelete;
+  }
+}
+
+class BackupFilesPresetsComboBoxRenderer extends DefaultListCellRenderer
+{
+  /**
+   * 
+   */
+  private static final long serialVersionUID = 88L;
+
+  @Override
+  public Component getListCellRendererComponent(JList list, Object value,
+          int index, boolean isSelected, boolean cellHasFocus)
+  {
+    super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
+    
+    try {
+      IntKeyStringValueEntry e = (IntKeyStringValueEntry) value;
+      if (e.getKey() == GPreferences.BACKUPFILESSCHEMECUSTOMISE)
+      {
+        // "Customise" item
+        this.setFont(this.getFont().deriveFont(Font.BOLD));
+      }
+    } catch (Exception e) {
+      return this;
+    }
+
+    return this;
+  }
+}
index c3fd4fa..84de493 100644 (file)
@@ -146,6 +146,7 @@ public class GWsPreferences extends JPanel
     refreshWs.setText(MessageManager.getString("action.refresh_services"));
     refreshWs.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent e)
       {
         refreshWs_actionPerformed(e);
@@ -156,6 +157,7 @@ public class GWsPreferences extends JPanel
 
     resetWs.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent e)
       {
         resetWs_actionPerformed(e);
@@ -167,6 +169,7 @@ public class GWsPreferences extends JPanel
             .getString("label.index_web_services_menu_by_host_site"));
     indexByHost.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent e)
       {
         indexByHost_actionPerformed(e);
@@ -176,6 +179,7 @@ public class GWsPreferences extends JPanel
     indexByType.setText(MessageManager.getString("label.index_by_type"));
     indexByType.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent e)
       {
         indexByType_actionPerformed(e);
@@ -187,6 +191,7 @@ public class GWsPreferences extends JPanel
             MessageManager.getString("label.enable_jabaws_services"));
     enableJws2Services.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent e)
       {
         enableJws2Services_actionPerformed(e);
@@ -199,6 +204,7 @@ public class GWsPreferences extends JPanel
             "label.option_want_informed_web_service_URL_cannot_be_accessed_jalview_when_starts_up"));
     displayWsWarning.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent e)
       {
         displayWsWarning_actionPerformed(e);
@@ -208,6 +214,7 @@ public class GWsPreferences extends JPanel
     newWsUrl.setText(MessageManager.getString("label.new_service_url"));
     newWsUrl.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent e)
       {
         newWsUrl_actionPerformed(e);
@@ -217,6 +224,7 @@ public class GWsPreferences extends JPanel
     editWsUrl.setText(MessageManager.getString("label.edit_service_url"));
     editWsUrl.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent e)
       {
         editWsUrl_actionPerformed(e);
@@ -228,6 +236,7 @@ public class GWsPreferences extends JPanel
             .setText(MessageManager.getString("label.delete_service_url"));
     deleteWsUrl.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent e)
       {
         deleteWsUrl_actionPerformed(e);
@@ -239,6 +248,7 @@ public class GWsPreferences extends JPanel
             .setToolTipText(MessageManager.getString("label.move_url_up"));
     moveWsUrlUp.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent e)
       {
         moveWsUrlUp_actionPerformed(e);
@@ -250,6 +260,7 @@ public class GWsPreferences extends JPanel
             MessageManager.getString("label.move_url_down"));
     moveWsUrlDown.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent e)
       {
         moveWsUrlDown_actionPerformed(e);
@@ -260,6 +271,7 @@ public class GWsPreferences extends JPanel
             .setText(MessageManager.getString("label.add_sbrs_definition"));
     newSbrsUrl.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent e)
       {
         newSbrsUrl_actionPerformed(e);
@@ -270,6 +282,7 @@ public class GWsPreferences extends JPanel
             MessageManager.getString("label.edit_sbrs_definition"));
     editSbrsUrl.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent e)
       {
         editSbrsUrl_actionPerformed(e);
@@ -281,6 +294,7 @@ public class GWsPreferences extends JPanel
             MessageManager.getString("label.delete_sbrs_definition"));
     deleteSbrsUrl.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent e)
       {
         deleteSbrsUrl_actionPerformed(e);
@@ -294,14 +308,16 @@ public class GWsPreferences extends JPanel
     wsListUrlPanel.setBorder(BorderFactory.createEtchedBorder());
     wsListUrlPanel.setLayout(new BorderLayout());
     wsListPane.setBorder(BorderFactory.createEtchedBorder());
-    wsListPane.getViewport().add(wsList);
     wsList.setPreferredSize(new Dimension(482, 202));
+    wsList.getTableHeader().setReorderingAllowed(false);
+    wsListPane.getViewport().add(wsList);
     wsListPane.setPreferredSize(new Dimension(380, 80));
     wsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
     wsList.setColumnSelectionAllowed(false);
     wsList.addMouseListener(new MouseListener()
     {
 
+      @Override
       public void mouseClicked(MouseEvent e)
       {
         if (e.getClickCount() > 1)
@@ -311,20 +327,24 @@ public class GWsPreferences extends JPanel
 
       }
 
+      @Override
       public void mouseEntered(MouseEvent e)
       {
 
       }
 
+      @Override
       public void mouseExited(MouseEvent e)
       {
       }
 
+      @Override
       public void mousePressed(MouseEvent e)
       {
 
       }
 
+      @Override
       public void mouseReleased(MouseEvent e)
       {
 
@@ -356,6 +376,7 @@ public class GWsPreferences extends JPanel
     sbrsList.addMouseListener(new MouseListener()
     {
 
+      @Override
       public void mouseClicked(MouseEvent e)
       {
         if (e.getClickCount() > 1)
@@ -365,20 +386,24 @@ public class GWsPreferences extends JPanel
 
       }
 
+      @Override
       public void mouseEntered(MouseEvent e)
       {
 
       }
 
+      @Override
       public void mouseExited(MouseEvent e)
       {
       }
 
+      @Override
       public void mousePressed(MouseEvent e)
       {
 
       }
 
+      @Override
       public void mouseReleased(MouseEvent e)
       {
 
index 8910c67..b22bf4e 100755 (executable)
@@ -24,6 +24,7 @@ import jalview.util.Format;
 import jalview.util.MessageManager;
 
 import java.io.PrintStream;
+import java.util.Arrays;
 
 /**
  * A class to model rectangular matrices of double values and operations on them
@@ -31,37 +32,40 @@ import java.io.PrintStream;
 public class Matrix implements MatrixI
 {
   /*
-   * the cell values in row-major order
+   * maximum number of iterations for tqli
    */
-  private double[][] value;
+  private static final int MAX_ITER = 45;
+  // fudge - add 15 iterations, just in case
 
   /*
    * the number of rows
    */
-  protected int rows;
+  final protected int rows;
 
   /*
    * the number of columns
    */
-  protected int cols;
+  final protected int cols;
+
+  /*
+   * the cell values in row-major order
+   */
+  private double[][] value;
 
   protected double[] d; // Diagonal
 
   protected double[] e; // off diagonal
 
   /**
-   * maximum number of iterations for tqli
+   * Constructor given number of rows and columns
    * 
+   * @param colCount
+   * @param rowCount
    */
-  private static final int maxIter = 45; // fudge - add 15 iterations, just in
-                                         // case
-
-  /**
-   * Default constructor
-   */
-  public Matrix()
+  protected Matrix(int rowCount, int colCount)
   {
-
+    rows = rowCount;
+    cols = colCount;
   }
 
   /**
@@ -103,11 +107,6 @@ public class Matrix implements MatrixI
     }
   }
 
-  /**
-   * Returns a new matrix which is the transpose of this one
-   * 
-   * @return
-   */
   @Override
   public MatrixI transpose()
   {
@@ -145,18 +144,6 @@ public class Matrix implements MatrixI
     }
   }
 
-  /**
-   * Returns a new matrix which is the result of premultiplying this matrix by
-   * the supplied argument. If this of size AxB (A rows and B columns), and the
-   * argument is CxA (C rows and A columns), the result is of size CxB.
-   * 
-   * @param in
-   * 
-   * @return
-   * @throws IllegalArgumentException
-   *           if the number of columns in the pre-multiplier is not equal to
-   *           the number of rows in the multiplicand (this)
-   */
   @Override
   public MatrixI preMultiply(MatrixI in)
   {
@@ -208,21 +195,6 @@ public class Matrix implements MatrixI
     return out;
   }
 
-  /**
-   * Returns a new matrix which is the result of postmultiplying this matrix by
-   * the supplied argument. If this of size AxB (A rows and B columns), and the
-   * argument is BxC (B rows and C columns), the result is of size AxC.
-   * <p>
-   * This method simply returns the result of in.preMultiply(this)
-   * 
-   * @param in
-   * 
-   * @return
-   * @throws IllegalArgumentException
-   *           if the number of rows in the post-multiplier is not equal to the
-   *           number of columns in the multiplicand (this)
-   * @see #preMultiply(Matrix)
-   */
   @Override
   public MatrixI postMultiply(MatrixI in)
   {
@@ -234,11 +206,6 @@ public class Matrix implements MatrixI
     return in.preMultiply(this);
   }
 
-  /**
-   * Answers a new matrix with a copy of the values in this one
-   * 
-   * @return
-   */
   @Override
   public MatrixI copy()
   {
@@ -249,7 +216,17 @@ public class Matrix implements MatrixI
       System.arraycopy(value[i], 0, newmat[i], 0, value[i].length);
     }
 
-    return new Matrix(newmat);
+    Matrix m = new Matrix(newmat);
+    if (this.d != null)
+    {
+      m.d = Arrays.copyOf(this.d, this.d.length);
+    }
+    if (this.e != null)
+    {
+      m.e = Arrays.copyOf(this.e, this.e.length);
+    }
+
+    return m;
   }
 
   /**
@@ -479,11 +456,11 @@ public class Matrix implements MatrixI
         {
           iter++;
 
-          if (iter == maxIter)
+          if (iter == MAX_ITER)
           {
             throw new Exception(MessageManager.formatMessage(
                     "exception.matrix_too_many_iteration", new String[]
-                    { "tqli", Integer.valueOf(maxIter).toString() }));
+                    { "tqli", Integer.valueOf(MAX_ITER).toString() }));
           }
           else
           {
@@ -743,11 +720,11 @@ public class Matrix implements MatrixI
         {
           iter++;
 
-          if (iter == maxIter)
+          if (iter == MAX_ITER)
           {
             throw new Exception(MessageManager.formatMessage(
                     "exception.matrix_too_many_iteration", new String[]
-                    { "tqli2", Integer.valueOf(maxIter).toString() }));
+                    { "tqli2", Integer.valueOf(MAX_ITER).toString() }));
           }
           else
           {
@@ -995,4 +972,54 @@ public class Matrix implements MatrixI
       }
     }
   }
+
+  @Override
+  public void setD(double[] v)
+  {
+    d = v;
+  }
+
+  @Override
+  public void setE(double[] v)
+  {
+    e = v;
+  }
+
+  public double getTotal()
+  {
+    double d = 0d;
+    for (int i = 0; i < this.height(); i++)
+    {
+      for (int j = 0; j < this.width(); j++)
+      {
+        d += value[i][j];
+      }
+    }
+    return d;
+  }
+
+  /**
+   * {@inheritDoc}
+   */
+  @Override
+  public boolean equals(MatrixI m2, double delta)
+  {
+    if (m2 == null || this.height() != m2.height()
+            || this.width() != m2.width())
+    {
+      return false;
+    }
+    for (int i = 0; i < this.height(); i++)
+    {
+      for (int j = 0; j < this.width(); j++)
+      {
+        double diff = this.getValue(i, j) - m2.getValue(i, j);
+        if (Math.abs(diff) > delta)
+        {
+          return false;
+        }
+      }
+    }
+    return true;
+  }
 }
index 5b93c76..2c78653 100644 (file)
@@ -22,6 +22,10 @@ package jalview.math;
 
 import java.io.PrintStream;
 
+/**
+ * An interface that describes a rectangular matrix of double values and
+ * operations on it
+ */
 public interface MatrixI
 {
   /**
@@ -63,18 +67,59 @@ public interface MatrixI
    */
   double[] getRow(int i);
 
+  /**
+   * Answers a new matrix with a copy of the values in this one
+   * 
+   * @return
+   */
   MatrixI copy();
 
+  /**
+   * Returns a new matrix which is the transpose of this one
+   * 
+   * @return
+   */
   MatrixI transpose();
 
+  /**
+   * Returns a new matrix which is the result of premultiplying this matrix by
+   * the supplied argument. If this of size AxB (A rows and B columns), and the
+   * argument is CxA (C rows and A columns), the result is of size CxB.
+   * 
+   * @param in
+   * 
+   * @return
+   * @throws IllegalArgumentException
+   *           if the number of columns in the pre-multiplier is not equal to
+   *           the number of rows in the multiplicand (this)
+   */
   MatrixI preMultiply(MatrixI m);
 
+  /**
+   * Returns a new matrix which is the result of postmultiplying this matrix by
+   * the supplied argument. If this of size AxB (A rows and B columns), and the
+   * argument is BxC (B rows and C columns), the result is of size AxC.
+   * <p>
+   * This method simply returns the result of in.preMultiply(this)
+   * 
+   * @param in
+   * 
+   * @return
+   * @throws IllegalArgumentException
+   *           if the number of rows in the post-multiplier is not equal to the
+   *           number of columns in the multiplicand (this)
+   * @see #preMultiply(Matrix)
+   */
   MatrixI postMultiply(MatrixI m);
 
   double[] getD();
 
   double[] getE();
 
+  void setD(double[] v);
+
+  void setE(double[] v);
+
   void print(PrintStream ps, String format);
 
   void printD(PrintStream ps, String format);
@@ -114,4 +159,14 @@ public interface MatrixI
    * @param d
    */
   void multiply(double d);
+
+  /**
+   * Answers true if the two matrices have the same dimensions, and corresponding values all differ by no
+   * more than delta (which should be a positive value), else false
+   * 
+   * @param m2
+   * @param delta
+   * @return
+   */
+  boolean equals(MatrixI m2, double delta);
 }
index 5971227..602c5e4 100755 (executable)
  */
 package jalview.math;
 
+import jalview.datamodel.Point;
+
+import java.util.HashMap;
+import java.util.Map;
+
 /**
- * DOCUMENT ME!
- * 
- * @author $author$
- * @version $Revision$
+ * Model for a 3x3 matrix which provides methods for rotation in 3-D space
  */
 public class RotatableMatrix
 {
-  float[][] matrix;
+  private static final int DIMS = 3;
 
-  float[] temp;
+  /*
+   * cache the most used rotations: +/- 1, 2, 3, 4 degrees around x or y axis
+   */
+  private static Map<Axis, Map<Float, float[][]>> cachedRotations;
 
-  float[][] rot;
+  static
+  {
+    cachedRotations = new HashMap<>();
+    for (Axis axis : Axis.values())
+    {
+      HashMap<Float, float[][]> map = new HashMap<>();
+      cachedRotations.put(axis, map);
+      for (int deg = 1; deg < 5; deg++)
+      {
+        float[][] rotation = getRotation(deg, axis);
+        map.put(Float.valueOf(deg), rotation);
+        rotation = getRotation(-deg, axis);
+        map.put(Float.valueOf(-deg), rotation);
+      }
+    }
+  }
 
-  /**
-   * Creates a new RotatableMatrix object.
-   * 
-   * @param rows
-   *          DOCUMENT ME!
-   * @param cols
-   *          DOCUMENT ME!
-   */
-  public RotatableMatrix(int rows, int cols)
+  public enum Axis
   {
-    matrix = new float[rows][cols];
+    X, Y, Z
+  };
 
-    temp = new float[3];
+  float[][] matrix;
 
-    rot = new float[3][3];
+  /**
+   * Constructor creates a new identity matrix (all values zero except for 1 on
+   * the diagonal)
+   */
+  public RotatableMatrix()
+  {
+    matrix = new float[DIMS][DIMS];
+    for (int j = 0; j < DIMS; j++)
+    {
+      matrix[j][j] = 1f;
+    }
   }
 
   /**
-   * DOCUMENT ME!
+   * Sets the value at position (i, j) of the matrix
    * 
    * @param i
-   *          DOCUMENT ME!
    * @param j
-   *          DOCUMENT ME!
    * @param value
-   *          DOCUMENT ME!
    */
-  public void addElement(int i, int j, float value)
+  public void setValue(int i, int j, float value)
   {
     matrix[i][j] = value;
   }
 
   /**
-   * DOCUMENT ME!
+   * Answers the value at position (i, j) of the matrix
+   * 
+   * @param i
+   * @param j
+   * @return
+   */
+  public float getValue(int i, int j)
+  {
+    return matrix[i][j];
+  }
+
+  /**
+   * Prints the matrix in rows of space-delimited values
    */
   public void print()
   {
@@ -82,174 +114,137 @@ public class RotatableMatrix
   }
 
   /**
-   * DOCUMENT ME!
+   * Rotates the matrix through the specified number of degrees around the
+   * specified axis
    * 
    * @param degrees
-   *          DOCUMENT ME!
    * @param axis
-   *          DOCUMENT ME!
    */
-  public void rotate(float degrees, char axis)
+  public void rotate(float degrees, Axis axis)
   {
-    float costheta = (float) Math.cos((degrees * Math.PI) / (float) 180.0);
+    float[][] rot = getRotation(degrees, axis);
 
-    float sintheta = (float) Math.sin((degrees * Math.PI) / (float) 180.0);
+    preMultiply(rot);
+  }
 
-    if (axis == 'z')
+  /**
+   * Answers a matrix which, when it pre-multiplies another matrix, applies a
+   * rotation of the specified number of degrees around the specified axis
+   * 
+   * @param degrees
+   * @param axis
+   * @return
+   * @see https://en.wikipedia.org/wiki/Rotation_matrix#Basic_rotations
+   */
+  protected static float[][] getRotation(float degrees, Axis axis)
+  {
+    Float floatValue = Float.valueOf(degrees);
+    if (cachedRotations.get(axis).containsKey(floatValue))
     {
-      rot[0][0] = (float) costheta;
-
-      rot[0][1] = (float) -sintheta;
-
-      rot[0][2] = (float) 0.0;
-
-      rot[1][0] = (float) sintheta;
-
-      rot[1][1] = (float) costheta;
-
-      rot[1][2] = (float) 0.0;
-
-      rot[2][0] = (float) 0.0;
-
-      rot[2][1] = (float) 0.0;
-
-      rot[2][2] = (float) 1.0;
-
-      preMultiply(rot);
+      // System.out.println("getRotation from cache: " + (int) degrees);
+      return cachedRotations.get(axis).get(floatValue);
     }
 
-    if (axis == 'x')
-    {
-      rot[0][0] = (float) 1.0;
-
-      rot[0][1] = (float) 0.0;
-
-      rot[0][2] = (float) 0.0;
-
-      rot[1][0] = (float) 0.0;
+    float costheta = (float) Math.cos(degrees * Math.PI / 180f);
 
-      rot[1][1] = (float) costheta;
+    float sintheta = (float) Math.sin(degrees * Math.PI / 180f);
 
-      rot[1][2] = (float) sintheta;
+    float[][] rot = new float[DIMS][DIMS];
 
-      rot[2][0] = (float) 0.0;
-
-      rot[2][1] = (float) -sintheta;
-
-      rot[2][2] = (float) costheta;
-
-      preMultiply(rot);
-    }
-
-    if (axis == 'y')
+    switch (axis)
     {
-      rot[0][0] = (float) costheta;
-
-      rot[0][1] = (float) 0.0;
-
-      rot[0][2] = (float) -sintheta;
-
-      rot[1][0] = (float) 0.0;
-
-      rot[1][1] = (float) 1.0;
-
-      rot[1][2] = (float) 0.0;
-
-      rot[2][0] = (float) sintheta;
-
-      rot[2][1] = (float) 0.0;
-
-      rot[2][2] = (float) costheta;
-
-      preMultiply(rot);
+    case X:
+      rot[0][0] = 1f;
+      rot[1][1] = costheta;
+      rot[1][2] = sintheta;
+      rot[2][1] = -sintheta;
+      rot[2][2] = costheta;
+      break;
+    case Y:
+      rot[0][0] = costheta;
+      rot[0][2] = -sintheta;
+      rot[1][1] = 1f;
+      rot[2][0] = sintheta;
+      rot[2][2] = costheta;
+      break;
+    case Z:
+      rot[0][0] = costheta;
+      rot[0][1] = -sintheta;
+      rot[1][0] = sintheta;
+      rot[1][1] = costheta;
+      rot[2][2] = 1f;
+      break;
     }
+    return rot;
   }
 
   /**
-   * DOCUMENT ME!
+   * Answers a new array of float values which is the result of pre-multiplying
+   * this matrix by the given vector. Each value of the result is the dot
+   * product of the vector with one column of this matrix. The matrix and input
+   * vector are not modified.
    * 
    * @param vect
-   *          DOCUMENT ME!
    * 
-   * @return DOCUMENT ME!
+   * @return
    */
   public float[] vectorMultiply(float[] vect)
   {
-    temp[0] = vect[0];
-
-    temp[1] = vect[1];
-
-    temp[2] = vect[2];
+    float[] result = new float[DIMS];
 
-    for (int i = 0; i < 3; i++)
+    for (int i = 0; i < DIMS; i++)
     {
-      temp[i] = (matrix[i][0] * vect[0]) + (matrix[i][1] * vect[1])
+      result[i] = (matrix[i][0] * vect[0]) + (matrix[i][1] * vect[1])
               + (matrix[i][2] * vect[2]);
     }
 
-    vect[0] = temp[0];
-
-    vect[1] = temp[1];
-
-    vect[2] = temp[2];
-
-    return vect;
+    return result;
   }
 
   /**
-   * DOCUMENT ME!
+   * Performs pre-multiplication of this matrix by the given one. Value (i, j)
+   * of the result is the dot product of the i'th row of <code>mat</code> with
+   * the j'th column of this matrix.
    * 
    * @param mat
-   *          DOCUMENT ME!
    */
   public void preMultiply(float[][] mat)
   {
-    float[][] tmp = new float[3][3];
+    float[][] tmp = new float[DIMS][DIMS];
 
-    for (int i = 0; i < 3; i++)
+    for (int i = 0; i < DIMS; i++)
     {
-      for (int j = 0; j < 3; j++)
+      for (int j = 0; j < DIMS; j++)
       {
         tmp[i][j] = (mat[i][0] * matrix[0][j]) + (mat[i][1] * matrix[1][j])
                 + (mat[i][2] * matrix[2][j]);
       }
     }
 
-    for (int i = 0; i < 3; i++)
-    {
-      for (int j = 0; j < 3; j++)
-      {
-        matrix[i][j] = tmp[i][j];
-      }
-    }
+    matrix = tmp;
   }
 
   /**
-   * DOCUMENT ME!
+   * Performs post-multiplication of this matrix by the given one. Value (i, j)
+   * of the result is the dot product of the i'th row of this matrix with the
+   * j'th column of <code>mat</code>.
    * 
    * @param mat
-   *          DOCUMENT ME!
    */
   public void postMultiply(float[][] mat)
   {
-    float[][] tmp = new float[3][3];
+    float[][] tmp = new float[DIMS][DIMS];
 
-    for (int i = 0; i < 3; i++)
+    for (int i = 0; i < DIMS; i++)
     {
-      for (int j = 0; j < 3; j++)
+      for (int j = 0; j < DIMS; j++)
       {
         tmp[i][j] = (matrix[i][0] * mat[0][j]) + (matrix[i][1] * mat[1][j])
                 + (matrix[i][2] * mat[2][j]);
       }
     }
 
-    for (int i = 0; i < 3; i++)
-    {
-      for (int j = 0; j < 3; j++)
-      {
-        matrix[i][j] = tmp[i][j];
-      }
-    }
+    matrix = tmp;
   }
 
   /**
@@ -260,47 +255,47 @@ public class RotatableMatrix
    */
   public static void main(String[] args)
   {
-    RotatableMatrix m = new RotatableMatrix(3, 3);
+    RotatableMatrix m = new RotatableMatrix();
 
-    m.addElement(0, 0, 1);
+    m.setValue(0, 0, 1);
 
-    m.addElement(0, 1, 0);
+    m.setValue(0, 1, 0);
 
-    m.addElement(0, 2, 0);
+    m.setValue(0, 2, 0);
 
-    m.addElement(1, 0, 0);
+    m.setValue(1, 0, 0);
 
-    m.addElement(1, 1, 2);
+    m.setValue(1, 1, 2);
 
-    m.addElement(1, 2, 0);
+    m.setValue(1, 2, 0);
 
-    m.addElement(2, 0, 0);
+    m.setValue(2, 0, 0);
 
-    m.addElement(2, 1, 0);
+    m.setValue(2, 1, 0);
 
-    m.addElement(2, 2, 1);
+    m.setValue(2, 2, 1);
 
     m.print();
 
-    RotatableMatrix n = new RotatableMatrix(3, 3);
+    RotatableMatrix n = new RotatableMatrix();
 
-    n.addElement(0, 0, 2);
+    n.setValue(0, 0, 2);
 
-    n.addElement(0, 1, 1);
+    n.setValue(0, 1, 1);
 
-    n.addElement(0, 2, 1);
+    n.setValue(0, 2, 1);
 
-    n.addElement(1, 0, 2);
+    n.setValue(1, 0, 2);
 
-    n.addElement(1, 1, 1);
+    n.setValue(1, 1, 1);
 
-    n.addElement(1, 2, 1);
+    n.setValue(1, 2, 1);
 
-    n.addElement(2, 0, 2);
+    n.setValue(2, 0, 2);
 
-    n.addElement(2, 1, 1);
+    n.setValue(2, 1, 1);
 
-    n.addElement(2, 2, 1);
+    n.setValue(2, 2, 1);
 
     n.print();
 
@@ -321,26 +316,15 @@ public class RotatableMatrix
   }
 
   /**
-   * DOCUMENT ME!
+   * Performs a vector multiplication whose result is the Point representing the
+   * input point's value vector post-multiplied by this matrix.
+   * 
+   * @param coord
+   * @return
    */
-  public void setIdentity()
+  public Point vectorMultiply(Point coord)
   {
-    matrix[0][0] = (float) 1.0;
-
-    matrix[1][1] = (float) 1.0;
-
-    matrix[2][2] = (float) 1.0;
-
-    matrix[0][1] = (float) 0.0;
-
-    matrix[0][2] = (float) 0.0;
-
-    matrix[1][0] = (float) 0.0;
-
-    matrix[1][2] = (float) 0.0;
-
-    matrix[2][0] = (float) 0.0;
-
-    matrix[2][1] = (float) 0.0;
+    float[] v = vectorMultiply(new float[] { coord.x, coord.y, coord.z });
+    return new Point(v[0], v[1], v[2]);
   }
 }
index 86592a0..e24cda5 100644 (file)
@@ -45,11 +45,8 @@ public class SparseMatrix extends Matrix
    */
   public SparseMatrix(double[][] v)
   {
-    rows = v.length;
-    if (rows > 0)
-    {
-      cols = v[0].length;
-    }
+    super(v.length, v.length > 0 ? v[0].length : 0);
+
     sparseColumns = new SparseDoubleArray[cols];
 
     /*
index b153d9f..02b405e 100644 (file)
  */
 package jalview.project;
 
+import static jalview.math.RotatableMatrix.Axis.X;
+import static jalview.math.RotatableMatrix.Axis.Y;
+import static jalview.math.RotatableMatrix.Axis.Z;
+
 import jalview.analysis.Conservation;
+import jalview.analysis.PCA;
+import jalview.analysis.scoremodels.ScoreModels;
+import jalview.analysis.scoremodels.SimilarityParams;
 import jalview.api.FeatureColourI;
 import jalview.api.ViewStyleI;
+import jalview.api.analysis.ScoreModelI;
+import jalview.api.analysis.SimilarityParamsI;
 import jalview.api.structures.JalviewStructureDisplayI;
 import jalview.bin.Cache;
 import jalview.datamodel.AlignedCodonFrame;
@@ -31,6 +40,7 @@ import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.GraphLine;
 import jalview.datamodel.PDBEntry;
+import jalview.datamodel.Point;
 import jalview.datamodel.RnaViewerModel;
 import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceGroup;
@@ -51,15 +61,19 @@ import jalview.gui.Desktop;
 import jalview.gui.FeatureRenderer;
 import jalview.gui.JvOptionPane;
 import jalview.gui.OOMWarning;
+import jalview.gui.PCAPanel;
 import jalview.gui.PaintRefresher;
 import jalview.gui.SplitFrame;
 import jalview.gui.StructureViewer;
 import jalview.gui.StructureViewer.ViewerType;
 import jalview.gui.StructureViewerBase;
 import jalview.gui.TreePanel;
+import jalview.io.BackupFiles;
 import jalview.io.DataSourceType;
 import jalview.io.FileFormat;
 import jalview.io.NewickFile;
+import jalview.math.Matrix;
+import jalview.math.MatrixI;
 import jalview.renderer.ResidueShaderI;
 import jalview.schemes.AnnotationColourGradient;
 import jalview.schemes.ColourSchemeI;
@@ -76,6 +90,7 @@ import jalview.util.StringUtils;
 import jalview.util.jarInputStreamProvider;
 import jalview.util.matcher.Condition;
 import jalview.viewmodel.AlignmentViewport;
+import jalview.viewmodel.PCAModel;
 import jalview.viewmodel.ViewportRanges;
 import jalview.viewmodel.seqfeatures.FeatureRendererSettings;
 import jalview.viewmodel.seqfeatures.FeaturesDisplayed;
@@ -91,6 +106,8 @@ import jalview.xml.binding.jalview.Annotation;
 import jalview.xml.binding.jalview.Annotation.ThresholdLine;
 import jalview.xml.binding.jalview.AnnotationColourScheme;
 import jalview.xml.binding.jalview.AnnotationElement;
+import jalview.xml.binding.jalview.DoubleMatrix;
+import jalview.xml.binding.jalview.DoubleVector;
 import jalview.xml.binding.jalview.Feature;
 import jalview.xml.binding.jalview.Feature.OtherData;
 import jalview.xml.binding.jalview.FeatureMatcherSet.CompoundMatcher;
@@ -105,6 +122,11 @@ import jalview.xml.binding.jalview.JalviewModel.JSeq.Pdbids;
 import jalview.xml.binding.jalview.JalviewModel.JSeq.Pdbids.StructureState;
 import jalview.xml.binding.jalview.JalviewModel.JSeq.RnaViewer;
 import jalview.xml.binding.jalview.JalviewModel.JSeq.RnaViewer.SecondaryStructure;
+import jalview.xml.binding.jalview.JalviewModel.PcaViewer;
+import jalview.xml.binding.jalview.JalviewModel.PcaViewer.Axis;
+import jalview.xml.binding.jalview.JalviewModel.PcaViewer.SeqPointMax;
+import jalview.xml.binding.jalview.JalviewModel.PcaViewer.SeqPointMin;
+import jalview.xml.binding.jalview.JalviewModel.PcaViewer.SequencePoint;
 import jalview.xml.binding.jalview.JalviewModel.Tree;
 import jalview.xml.binding.jalview.JalviewModel.UserColours;
 import jalview.xml.binding.jalview.JalviewModel.Viewport;
@@ -117,6 +139,7 @@ import jalview.xml.binding.jalview.MapListType.MapListTo;
 import jalview.xml.binding.jalview.Mapping;
 import jalview.xml.binding.jalview.NoValueColour;
 import jalview.xml.binding.jalview.ObjectFactory;
+import jalview.xml.binding.jalview.PcaDataType;
 import jalview.xml.binding.jalview.Pdbentry.Property;
 import jalview.xml.binding.jalview.Sequence;
 import jalview.xml.binding.jalview.Sequence.DBRef;
@@ -191,6 +214,12 @@ public class Jalview2XML
 
   private static final String UTF_8 = "UTF-8";
 
+  /**
+   * prefix for recovering datasets for alignments with multiple views where
+   * non-existent dataset IDs were written for some views
+   */
+  private static final String UNIQSEQSETID = "uniqueSeqSetId.";
+
   // use this with nextCounter() to make unique names for entities
   private int counter = 0;
 
@@ -522,24 +551,30 @@ public class Jalview2XML
   public void saveState(File statefile)
   {
     FileOutputStream fos = null;
+
     try
     {
+
       fos = new FileOutputStream(statefile);
+
       JarOutputStream jout = new JarOutputStream(fos);
       saveState(jout);
+      fos.close();
 
     } catch (Exception e)
     {
+      Cache.log.error("Couln't write Jalview state to " + statefile, e);
       // TODO: inform user of the problem - they need to know if their data was
       // not saved !
       if (errorMessage == null)
       {
-        errorMessage = "Couldn't write Jalview Archive to output file '"
+        errorMessage = "Did't write Jalview Archive to output file '"
                 + statefile + "' - See console error log for details";
       }
       else
       {
-        errorMessage += "(output file was '" + statefile + "')";
+        errorMessage += "(Didn't write Jalview Archive to output file '"
+                + statefile + ")";
       }
       e.printStackTrace();
     } finally
@@ -709,7 +744,11 @@ public class Jalview2XML
   {
     try
     {
-      FileOutputStream fos = new FileOutputStream(jarFile);
+      // create backupfiles object and get new temp filename destination
+      BackupFiles backupfiles = new BackupFiles(jarFile);
+      FileOutputStream fos = new FileOutputStream(
+              backupfiles.getTempFilePath());
+
       JarOutputStream jout = new JarOutputStream(fos);
       List<AlignFrame> frames = new ArrayList<>();
 
@@ -731,7 +770,12 @@ public class Jalview2XML
       }
       ;
       jout.close();
-      return true;
+      boolean success = true;
+
+      backupfiles.setWriteSuccess(success);
+      success = backupfiles.rollBackupsAndRenameTempFile();
+
+      return success;
     } catch (Exception ex)
     {
       errorMessage = "Couldn't Write alignment view to Jalview Archive - see error output for details";
@@ -1208,6 +1252,9 @@ public class Jalview2XML
               tree.setXpos(tp.getX());
               tree.setYpos(tp.getY());
               tree.setId(makeHashCode(tp, null));
+              tree.setLinkToAllViews(
+                      tp.getTreeCanvas().isApplyToAllViews());
+
               // jms.addTree(tree);
               object.getTree().add(tree);
             }
@@ -1216,6 +1263,24 @@ public class Jalview2XML
       }
     }
 
+    /*
+     * save PCA viewers
+     */
+    if (!storeDS && Desktop.desktop != null)
+    {
+      for (JInternalFrame frame : Desktop.desktop.getAllFrames())
+      {
+        if (frame instanceof PCAPanel)
+        {
+          PCAPanel panel = (PCAPanel) frame;
+          if (panel.getAlignViewport().getAlignment() == jal)
+          {
+            savePCA(panel, object);
+          }
+        }
+      }
+    }
+
     // SAVE ANNOTATIONS
     /**
      * store forward refs from an annotationRow to any groups
@@ -1623,6 +1688,196 @@ public class Jalview2XML
   }
 
   /**
+   * Writes PCA viewer attributes and computed values to an XML model object and
+   * adds it to the JalviewModel. Any exceptions are reported by logging.
+   */
+  protected void savePCA(PCAPanel panel, JalviewModel object)
+  {
+    try
+    {
+      PcaViewer viewer = new PcaViewer();
+      viewer.setHeight(panel.getHeight());
+      viewer.setWidth(panel.getWidth());
+      viewer.setXpos(panel.getX());
+      viewer.setYpos(panel.getY());
+      viewer.setTitle(panel.getTitle());
+      PCAModel pcaModel = panel.getPcaModel();
+      viewer.setScoreModelName(pcaModel.getScoreModelName());
+      viewer.setXDim(panel.getSelectedDimensionIndex(X));
+      viewer.setYDim(panel.getSelectedDimensionIndex(Y));
+      viewer.setZDim(panel.getSelectedDimensionIndex(Z));
+      viewer.setBgColour(
+              panel.getRotatableCanvas().getBackgroundColour().getRGB());
+      viewer.setScaleFactor(panel.getRotatableCanvas().getScaleFactor());
+      float[] spMin = panel.getRotatableCanvas().getSeqMin();
+      SeqPointMin spmin = new SeqPointMin();
+      spmin.setXPos(spMin[0]);
+      spmin.setYPos(spMin[1]);
+      spmin.setZPos(spMin[2]);
+      viewer.setSeqPointMin(spmin);
+      float[] spMax = panel.getRotatableCanvas().getSeqMax();
+      SeqPointMax spmax = new SeqPointMax();
+      spmax.setXPos(spMax[0]);
+      spmax.setYPos(spMax[1]);
+      spmax.setZPos(spMax[2]);
+      viewer.setSeqPointMax(spmax);
+      viewer.setShowLabels(panel.getRotatableCanvas().isShowLabels());
+      viewer.setLinkToAllViews(
+              panel.getRotatableCanvas().isApplyToAllViews());
+      SimilarityParamsI sp = pcaModel.getSimilarityParameters();
+      viewer.setIncludeGaps(sp.includeGaps());
+      viewer.setMatchGaps(sp.matchGaps());
+      viewer.setIncludeGappedColumns(sp.includeGappedColumns());
+      viewer.setDenominateByShortestLength(sp.denominateByShortestLength());
+
+      /*
+       * sequence points on display
+       */
+      for (jalview.datamodel.SequencePoint spt : pcaModel
+              .getSequencePoints())
+      {
+        SequencePoint point = new SequencePoint();
+        point.setSequenceRef(seqHash(spt.getSequence()));
+        point.setXPos(spt.coord.x);
+        point.setYPos(spt.coord.y);
+        point.setZPos(spt.coord.z);
+        viewer.getSequencePoint().add(point);
+      }
+
+      /*
+       * (end points of) axes on display
+       */
+      for (Point p : panel.getRotatableCanvas().getAxisEndPoints())
+      {
+
+        Axis axis = new Axis();
+        axis.setXPos(p.x);
+        axis.setYPos(p.y);
+        axis.setZPos(p.z);
+        viewer.getAxis().add(axis);
+      }
+
+      /*
+       * raw PCA data (note we are not restoring PCA inputs here -
+       * alignment view, score model, similarity parameters)
+       */
+      PcaDataType data = new PcaDataType();
+      viewer.setPcaData(data);
+      PCA pca = pcaModel.getPcaData();
+
+      DoubleMatrix pm = new DoubleMatrix();
+      saveDoubleMatrix(pca.getPairwiseScores(), pm);
+      data.setPairwiseMatrix(pm);
+
+      DoubleMatrix tm = new DoubleMatrix();
+      saveDoubleMatrix(pca.getTridiagonal(), tm);
+      data.setTridiagonalMatrix(tm);
+
+      DoubleMatrix eigenMatrix = new DoubleMatrix();
+      data.setEigenMatrix(eigenMatrix);
+      saveDoubleMatrix(pca.getEigenmatrix(), eigenMatrix);
+
+      object.getPcaViewer().add(viewer);
+    } catch (Throwable t)
+    {
+      Cache.log.error("Error saving PCA: " + t.getMessage());
+    }
+  }
+
+  /**
+   * Stores values from a matrix into an XML element, including (if present) the
+   * D or E vectors
+   * 
+   * @param m
+   * @param xmlMatrix
+   * @see #loadDoubleMatrix(DoubleMatrix)
+   */
+  protected void saveDoubleMatrix(MatrixI m, DoubleMatrix xmlMatrix)
+  {
+    xmlMatrix.setRows(m.height());
+    xmlMatrix.setColumns(m.width());
+    for (int i = 0; i < m.height(); i++)
+    {
+      DoubleVector row = new DoubleVector();
+      for (int j = 0; j < m.width(); j++)
+      {
+        row.getV().add(m.getValue(i, j));
+      }
+      xmlMatrix.getRow().add(row);
+    }
+    if (m.getD() != null)
+    {
+      DoubleVector dVector = new DoubleVector();
+      for (double d : m.getD())
+      {
+        dVector.getV().add(d);
+      }
+      xmlMatrix.setD(dVector);
+    }
+    if (m.getE() != null)
+    {
+      DoubleVector eVector = new DoubleVector();
+      for (double e : m.getE())
+      {
+        eVector.getV().add(e);
+      }
+      xmlMatrix.setE(eVector);
+    }
+  }
+
+  /**
+   * Loads XML matrix data into a new Matrix object, including the D and/or E
+   * vectors (if present)
+   * 
+   * @param mData
+   * @return
+   * @see Jalview2XML#saveDoubleMatrix(MatrixI, DoubleMatrix)
+   */
+  protected MatrixI loadDoubleMatrix(DoubleMatrix mData)
+  {
+    int rows = mData.getRows();
+    double[][] vals = new double[rows][];
+
+    for (int i = 0; i < rows; i++)
+    {
+      List<Double> dVector = mData.getRow().get(i).getV();
+      vals[i] = new double[dVector.size()];
+      int dvi = 0;
+      for (Double d : dVector)
+      {
+        vals[i][dvi++] = d;
+      }
+    }
+
+    MatrixI m = new Matrix(vals);
+
+    if (mData.getD() != null)
+    {
+      List<Double> dVector = mData.getD().getV();
+      double[] vec = new double[dVector.size()];
+      int dvi = 0;
+      for (Double d : dVector)
+      {
+        vec[dvi++] = d;
+      }
+      m.setD(vec);
+    }
+    if (mData.getE() != null)
+    {
+      List<Double> dVector = mData.getE().getV();
+      double[] vec = new double[dVector.size()];
+      int dvi = 0;
+      for (Double d : dVector)
+      {
+        vec[dvi++] = d;
+      }
+      m.setE(vec);
+    }
+
+    return m;
+  }
+
+  /**
    * Save any Varna viewers linked to this sequence. Writes an rnaViewer element
    * for each viewer, with
    * <ul>
@@ -3020,6 +3275,28 @@ public class Jalview2XML
             : null;
 
     // ////////////////////////////////
+    // INITIALISE ALIGNMENT SEQUENCESETID AND VIEWID
+    //
+    //
+    // If we just load in the same jar file again, the sequenceSetId
+    // will be the same, and we end up with multiple references
+    // to the same sequenceSet. We must modify this id on load
+    // so that each load of the file gives a unique id
+
+    /**
+     * used to resolve correct alignment dataset for alignments with multiple
+     * views
+     */
+    String uniqueSeqSetId = null;
+    String viewId = null;
+    if (view != null)
+    {
+      uniqueSeqSetId = view.getSequenceSetId() + uniqueSetSuffix;
+      viewId = (view.getId() == null ? null
+              : view.getId() + uniqueSetSuffix);
+    }
+
+    // ////////////////////////////////
     // LOAD SEQUENCES
 
     List<SequenceI> hiddenSeqs = null;
@@ -3140,7 +3417,7 @@ public class Jalview2XML
 
       // finally, verify all data in vamsasSet is actually present in al
       // passing on flag indicating if it is actually a stored dataset
-      recoverDatasetFor(vamsasSet, al, isdsal);
+      recoverDatasetFor(vamsasSet, al, isdsal, uniqueSeqSetId);
     }
 
     if (referenceseqForView != null)
@@ -3582,7 +3859,7 @@ public class Jalview2XML
           }
           else
           {
-            cs = ColourSchemeProperty.getColourScheme(al,
+            cs = ColourSchemeProperty.getColourScheme(null, al,
                     jGroup.getColour());
           }
         }
@@ -3680,13 +3957,6 @@ public class Jalview2XML
     // ///////////////////////////////
     // LOAD VIEWPORT
 
-    // If we just load in the same jar file again, the sequenceSetId
-    // will be the same, and we end up with multiple references
-    // to the same sequenceSet. We must modify this id on load
-    // so that each load of the file gives a unique id
-    String uniqueSeqSetId = view.getSequenceSetId() + uniqueSetSuffix;
-    String viewId = (view.getId() == null ? null
-            : view.getId() + uniqueSetSuffix);
     AlignFrame af = null;
     AlignViewport av = null;
     // now check to see if we really need to create a new viewport.
@@ -3768,6 +4038,7 @@ public class Jalview2XML
     if (loadTreesAndStructures)
     {
       loadTrees(jalviewModel, view, af, av, ap);
+      loadPCAViewers(jalviewModel, ap);
       loadPDBStructures(jprovider, jseqs, af, ap);
       loadRnaViewers(jprovider, jseqs, ap);
     }
@@ -3916,8 +4187,8 @@ public class Jalview2XML
           // TODO: verify 'associate with all views' works still
           tp.getTreeCanvas().setViewport(av); // af.viewport;
           tp.getTreeCanvas().setAssociatedPanel(ap); // af.alignPanel;
-
         }
+        tp.getTreeCanvas().setApplyToAllViews(tree.isLinkToAllViews());
         if (tp == null)
         {
           warn("There was a problem recovering stored Newick tree: \n"
@@ -4700,25 +4971,27 @@ public class Jalview2XML
       }
       else
       {
-        cs = ColourSchemeProperty.getColourScheme(al, view.getBgColour());
+        cs = ColourSchemeProperty.getColourScheme(af.getViewport(), al,
+                view.getBgColour());
       }
     }
 
+    /*
+     * turn off 'alignment colour applies to all groups'
+     * while restoring global colour scheme
+     */
+    viewport.setColourAppliesToAllGroups(false);
     viewport.setGlobalColourScheme(cs);
     viewport.getResidueShading().setThreshold(pidThreshold,
             view.isIgnoreGapsinConsensus());
     viewport.getResidueShading()
             .setConsensus(viewport.getSequenceConsensusHash());
-    viewport.setColourAppliesToAllGroups(false);
-
     if (safeBoolean(view.isConservationSelected()) && cs != null)
     {
       viewport.getResidueShading()
               .setConservationInc(safeInt(view.getConsThreshold()));
     }
-
     af.changeColour(cs);
-
     viewport.setColourAppliesToAllGroups(true);
 
     viewport
@@ -4794,7 +5067,8 @@ public class Jalview2XML
           float min = safeFloat(safeFloat(setting.getMin()));
           float max = setting.getMax() == null ? 1f
                   : setting.getMax().floatValue();
-          FeatureColourI gc = new FeatureColour(minColour, maxColour,
+          FeatureColourI gc = new FeatureColour(maxColour, minColour,
+                  maxColour,
                   noValueColour, min, max);
           if (setting.getAttributeName().size() > 0)
           {
@@ -4996,7 +5270,7 @@ public class Jalview2XML
     else
     {
       cs = new AnnotationColourGradient(matchedAnnotation,
-              ColourSchemeProperty.getColourScheme(al,
+              ColourSchemeProperty.getColourScheme(af.getViewport(), al,
                       viewAnnColour.getColourScheme()),
               safeInt(viewAnnColour.getAboveThreshold()));
     }
@@ -5185,13 +5459,51 @@ public class Jalview2XML
   }
 
   private void recoverDatasetFor(SequenceSet vamsasSet, AlignmentI al,
-          boolean ignoreUnrefed)
+          boolean ignoreUnrefed, String uniqueSeqSetId)
   {
     jalview.datamodel.AlignmentI ds = getDatasetFor(
             vamsasSet.getDatasetId());
+    AlignmentI xtant_ds = ds;
+    if (xtant_ds == null)
+    {
+      // good chance we are about to create a new dataset, but check if we've
+      // seen some of the dataset sequence IDs before.
+      // TODO: skip this check if we are working with project generated by
+      // version 2.11 or later
+      xtant_ds = checkIfHasDataset(vamsasSet.getSequence());
+      if (xtant_ds != null)
+      {
+        ds = xtant_ds;
+        addDatasetRef(vamsasSet.getDatasetId(), ds);
+      }
+    }
     Vector dseqs = null;
+    if (!ignoreUnrefed)
+    {
+      // recovering an alignment View
+      AlignmentI seqSetDS = getDatasetFor(UNIQSEQSETID + uniqueSeqSetId);
+      if (seqSetDS != null)
+      {
+        if (ds != null && ds != seqSetDS)
+        {
+          warn("JAL-3171 regression: Overwriting a dataset reference for an alignment"
+                  + " - CDS/Protein crossreference data may be lost");
+          if (xtant_ds != null)
+          {
+            // This can only happen if the unique sequence set ID was bound to a
+            // dataset that did not contain any of the sequences in the view
+            // currently being restored.
+            warn("JAL-3171 SERIOUS!  TOTAL CONFUSION - please consider contacting the Jalview Development team so they can investigate why your project caused this message to be displayed.");
+          }
+        }
+        ds = seqSetDS;
+        addDatasetRef(vamsasSet.getDatasetId(), ds);
+      }
+    }
     if (ds == null)
     {
+      // try even harder to restore dataset
+      AlignmentI xtantDS = checkIfHasDataset(vamsasSet.getSequence());
       // create a list of new dataset sequences
       dseqs = new Vector();
     }
@@ -5214,10 +5526,58 @@ public class Jalview2XML
     if (al.getDataset() == null && !ignoreUnrefed)
     {
       al.setDataset(ds);
+      // register dataset for the alignment's uniqueSeqSetId for legacy projects
+      addDatasetRef(UNIQSEQSETID + uniqueSeqSetId, ds);
     }
+    updateSeqDatasetBinding(vamsasSet.getSequence(), ds);
   }
 
   /**
+   * XML dataset sequence ID to materialised dataset reference
+   */
+  HashMap<String, AlignmentI> seqToDataset = new HashMap<>();
+
+  /**
+   * @return the first materialised dataset reference containing a dataset
+   *         sequence referenced in the given view
+   * @param list
+   *          - sequences from the view
+   */
+  AlignmentI checkIfHasDataset(List<Sequence> list)
+  {
+    for (Sequence restoredSeq : list)
+    {
+      AlignmentI datasetFor = seqToDataset.get(restoredSeq.getDsseqid());
+      if (datasetFor != null)
+      {
+        return datasetFor;
+      }
+    }
+    return null;
+  }
+
+  /**
+   * Register ds as the containing dataset for the dataset sequences referenced
+   * by sequences in list
+   * 
+   * @param list
+   *          - sequences in a view
+   * @param ds
+   */
+  void updateSeqDatasetBinding(List<Sequence> list, AlignmentI ds)
+  {
+    for (Sequence restoredSeq : list)
+    {
+      AlignmentI prevDS = seqToDataset.put(restoredSeq.getDsseqid(), ds);
+      if (prevDS != null && prevDS != ds)
+      {
+        warn("Dataset sequence appears in many datasets: "
+                + restoredSeq.getDsseqid());
+        // TODO: try to merge!
+      }
+    }
+  }
+  /**
    * 
    * @param vamsasSeq
    *          sequence definition to create/merge dataset sequence for
@@ -5476,15 +5836,16 @@ public class Jalview2XML
     jalview.datamodel.Mapping jmap = new jalview.datamodel.Mapping(dsto, fr,
             fto, m.getMapFromUnit().intValue(),
             m.getMapToUnit().intValue());
-    // if (m.getMappingChoice() != null)
-    // {
-    // MappingChoice mc = m.getMappingChoice();
+
+    /*
+     * (optional) choice of dseqFor or Sequence
+     */
     if (m.getDseqFor() != null)
     {
       String dsfor = m.getDseqFor();
       if (seqRefIds.containsKey(dsfor))
       {
-        /**
+        /*
          * recover from hash
          */
         jmap.setTo(seqRefIds.get(dsfor));
@@ -5494,9 +5855,9 @@ public class Jalview2XML
         frefedSequence.add(newMappingRef(dsfor, jmap));
       }
     }
-    else
+    else if (m.getSequence() != null)
     {
-      /**
+      /*
        * local sequence definition
        */
       Sequence ms = m.getSequence();
@@ -5553,6 +5914,10 @@ public class Jalview2XML
     initSeqRefs();
     JalviewModel jm = saveState(ap, null, null, null);
 
+    addDatasetRef(
+            jm.getVamsasModel().getSequenceSet().get(0).getDatasetId(),
+            ap.getAlignment().getDataset());
+
     uniqueSetSuffix = "";
     // jm.getJalviewModelSequence().getViewport(0).setId(null);
     jm.getViewport().get(0).setId(null);
@@ -5814,6 +6179,128 @@ public class Jalview2XML
   }
 
   /**
+   * Loads any saved PCA viewers
+   * 
+   * @param jms
+   * @param ap
+   */
+  protected void loadPCAViewers(JalviewModel model, AlignmentPanel ap)
+  {
+    try
+    {
+      List<PcaViewer> pcaviewers = model.getPcaViewer();
+      for (PcaViewer viewer : pcaviewers)
+      {
+        String modelName = viewer.getScoreModelName();
+        SimilarityParamsI params = new SimilarityParams(
+                viewer.isIncludeGappedColumns(), viewer.isMatchGaps(),
+                viewer.isIncludeGaps(),
+                viewer.isDenominateByShortestLength());
+
+        /*
+         * create the panel (without computing the PCA)
+         */
+        PCAPanel panel = new PCAPanel(ap, modelName, params);
+
+        panel.setTitle(viewer.getTitle());
+        panel.setBounds(new Rectangle(viewer.getXpos(), viewer.getYpos(),
+                viewer.getWidth(), viewer.getHeight()));
+
+        boolean showLabels = viewer.isShowLabels();
+        panel.setShowLabels(showLabels);
+        panel.getRotatableCanvas().setShowLabels(showLabels);
+        panel.getRotatableCanvas()
+                .setBgColour(new Color(viewer.getBgColour()));
+        panel.getRotatableCanvas()
+                .setApplyToAllViews(viewer.isLinkToAllViews());
+
+        /*
+         * load PCA output data
+         */
+        ScoreModelI scoreModel = ScoreModels.getInstance()
+                .getScoreModel(modelName, ap);
+        PCA pca = new PCA(null, scoreModel, params);
+        PcaDataType pcaData = viewer.getPcaData();
+
+        MatrixI pairwise = loadDoubleMatrix(pcaData.getPairwiseMatrix());
+        pca.setPairwiseScores(pairwise);
+
+        MatrixI triDiag = loadDoubleMatrix(pcaData.getTridiagonalMatrix());
+        pca.setTridiagonal(triDiag);
+
+        MatrixI result = loadDoubleMatrix(pcaData.getEigenMatrix());
+        pca.setEigenmatrix(result);
+
+        panel.getPcaModel().setPCA(pca);
+
+        /*
+         * we haven't saved the input data! (JAL-2647 to do)
+         */
+        panel.setInputData(null);
+
+        /*
+         * add the sequence points for the PCA display
+         */
+        List<jalview.datamodel.SequencePoint> seqPoints = new ArrayList<>();
+        for (SequencePoint sp : viewer.getSequencePoint())
+        {
+          String seqId = sp.getSequenceRef();
+          SequenceI seq = seqRefIds.get(seqId);
+          if (seq == null)
+          {
+            throw new IllegalStateException(
+                    "Unmatched seqref for PCA: " + seqId);
+          }
+          Point pt = new Point(sp.getXPos(), sp.getYPos(), sp.getZPos());
+          jalview.datamodel.SequencePoint seqPoint = new jalview.datamodel.SequencePoint(
+                  seq, pt);
+          seqPoints.add(seqPoint);
+        }
+        panel.getRotatableCanvas().setPoints(seqPoints, seqPoints.size());
+
+        /*
+         * set min-max ranges and scale after setPoints (which recomputes them)
+         */
+        panel.getRotatableCanvas().setScaleFactor(viewer.getScaleFactor());
+        SeqPointMin spMin = viewer.getSeqPointMin();
+        float[] min = new float[] { spMin.getXPos(), spMin.getYPos(),
+            spMin.getZPos() };
+        SeqPointMax spMax = viewer.getSeqPointMax();
+        float[] max = new float[] { spMax.getXPos(), spMax.getYPos(),
+            spMax.getZPos() };
+        panel.getRotatableCanvas().setSeqMinMax(min, max);
+
+        // todo: hold points list in PCAModel only
+        panel.getPcaModel().setSequencePoints(seqPoints);
+
+        panel.setSelectedDimensionIndex(viewer.getXDim(), X);
+        panel.setSelectedDimensionIndex(viewer.getYDim(), Y);
+        panel.setSelectedDimensionIndex(viewer.getZDim(), Z);
+
+        // is this duplication needed?
+        panel.setTop(seqPoints.size() - 1);
+        panel.getPcaModel().setTop(seqPoints.size() - 1);
+
+        /*
+         * add the axes' end points for the display
+         */
+        for (int i = 0; i < 3; i++)
+        {
+          Axis axis = viewer.getAxis().get(i);
+          panel.getRotatableCanvas().getAxisEndPoints()[i] = new Point(
+                  axis.getXPos(), axis.getYPos(), axis.getZPos());
+        }
+
+        Desktop.addInternalFrame(panel, MessageManager.formatMessage(
+                "label.calc_title", "PCA", modelName), 475, 450);
+      }
+    } catch (Exception ex)
+    {
+      Cache.log.error("Error loading PCA: " + ex.toString());
+    }
+  }
+
+  /**
    * Populates an XML model of the feature colour scheme for one feature type
    * 
    * @param featureType
@@ -6076,7 +6563,7 @@ public class Jalview2XML
         noValueColour = maxcol;
       }
   
-      colour = new FeatureColour(mincol, maxcol, noValueColour,
+      colour = new FeatureColour(maxcol, mincol, maxcol, noValueColour,
               safeFloat(colourModel.getMin()),
               safeFloat(colourModel.getMax()));
       final List<String> attributeName = colourModel.getAttributeName();
index 795cd36..13885b4 100644 (file)
@@ -22,7 +22,7 @@ package jalview.renderer.seqfeatures;
 
 import jalview.api.AlignViewportI;
 import jalview.api.FeatureColourI;
-import jalview.datamodel.Range;
+import jalview.datamodel.ContiguousI;
 import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
 import jalview.util.Comparison;
@@ -272,7 +272,7 @@ public class FeatureRenderer extends FeatureRendererModel
     /*
      * if columns are all gapped, or sequence has no features, nothing to do
      */
-    Range visiblePositions = seq.findPositions(start+1, end+1);
+    ContiguousI visiblePositions = seq.findPositions(start + 1, end + 1);
     if (visiblePositions == null || !seq.getFeatures().hasFeatures())
     {
       return null;
index c28ea5f..75a07b9 100755 (executable)
@@ -20,6 +20,7 @@
  */
 package jalview.schemes;
 
+import jalview.api.AlignViewportI;
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.AnnotatedCollectionI;
@@ -76,8 +77,8 @@ public class AnnotationColourGradient extends FollowerColourScheme
   private IdentityHashMap<SequenceI, AlignmentAnnotation> seqannot = null;
 
   @Override
-  public ColourSchemeI getInstance(AnnotatedCollectionI sg,
-          Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
+  public ColourSchemeI getInstance(AlignViewportI view,
+          AnnotatedCollectionI sg)
   {
     AnnotationColourGradient acg = new AnnotationColourGradient(annotation,
             getColourScheme(), aboveAnnotationThreshold);
@@ -185,7 +186,7 @@ public class AnnotationColourGradient extends FollowerColourScheme
       }
       else
       {
-        seqannot = new IdentityHashMap<SequenceI, AlignmentAnnotation>();
+        seqannot = new IdentityHashMap<>();
       }
       // resolve the context containing all the annotation for the sequence
       AnnotatedCollectionI alcontext = alignment instanceof AlignmentI
@@ -319,9 +320,9 @@ public class AnnotationColourGradient extends FollowerColourScheme
     if (annotationThreshold != null)
     {
       if ((aboveAnnotationThreshold == ABOVE_THRESHOLD
-              && aj.value < annotationThreshold.value)
+              && aj.value <= annotationThreshold.value)
               || (aboveAnnotationThreshold == BELOW_THRESHOLD
-                      && aj.value > annotationThreshold.value))
+                      && aj.value >= annotationThreshold.value))
       {
         return Color.white;
       }
@@ -414,14 +415,17 @@ public class AnnotationColourGradient extends FollowerColourScheme
             && aboveAnnotationThreshold == ABOVE_THRESHOLD
             && value >= ann.threshold.value)
     {
-      range = (value - ann.threshold.value)
+      range = ann.graphMax == ann.threshold.value ? 1f
+              : (value - ann.threshold.value)
               / (ann.graphMax - ann.threshold.value);
     }
     else if (thresholdIsMinMax && ann.threshold != null
             && aboveAnnotationThreshold == BELOW_THRESHOLD
             && value <= ann.threshold.value)
     {
-      range = (value - ann.graphMin) / (ann.threshold.value - ann.graphMin);
+      range = ann.graphMin == ann.threshold.value ? 0f
+              : (value - ann.graphMin)
+                      / (ann.threshold.value - ann.graphMin);
     }
     else
     {
@@ -475,7 +479,7 @@ public class AnnotationColourGradient extends FollowerColourScheme
   @Override
   public String getSchemeName()
   {
-    return "Annotation";
+    return ANNOTATION_COLOUR;
   }
 
   @Override
index 02f9b3e..8188f4d 100755 (executable)
 package jalview.schemes;
 
 import jalview.analysis.scoremodels.ScoreModels;
+import jalview.api.AlignViewportI;
 import jalview.api.analysis.PairwiseScoreModelI;
 import jalview.datamodel.AnnotatedCollectionI;
-import jalview.datamodel.SequenceCollectionI;
 import jalview.datamodel.SequenceI;
 import jalview.util.Comparison;
 
 import java.awt.Color;
-import java.util.Map;
 
 public class Blosum62ColourScheme extends ResidueColourScheme
 {
@@ -46,8 +45,8 @@ public class Blosum62ColourScheme extends ResidueColourScheme
    * be coloured
    */
   @Override
-  public ColourSchemeI getInstance(AnnotatedCollectionI coll,
-          Map<SequenceI, SequenceCollectionI> hrs)
+  public ColourSchemeI getInstance(AlignViewportI view,
+          AnnotatedCollectionI coll)
   {
     return new Blosum62ColourScheme();
   }
index a3b85b9..e6672fc 100755 (executable)
  */
 package jalview.schemes;
 
+import jalview.api.AlignViewportI;
 import jalview.datamodel.AnnotatedCollectionI;
-import jalview.datamodel.SequenceCollectionI;
-import jalview.datamodel.SequenceI;
 
 import java.awt.Color;
-import java.util.Map;
 
 /**
  * DOCUMENT ME!
@@ -75,8 +73,8 @@ public class BuriedColourScheme extends ScoreColourScheme
    * be coloured
    */
   @Override
-  public ColourSchemeI getInstance(AnnotatedCollectionI coll,
-          Map<SequenceI, SequenceCollectionI> hrs)
+  public ColourSchemeI getInstance(AlignViewportI view,
+          AnnotatedCollectionI coll)
   {
     return new BuriedColourScheme();
   }
index ec13343..19723ca 100755 (executable)
@@ -20,6 +20,7 @@
  */
 package jalview.schemes;
 
+import jalview.api.AlignViewportI;
 import jalview.datamodel.AnnotatedCollectionI;
 import jalview.datamodel.SequenceCollectionI;
 import jalview.datamodel.SequenceI;
@@ -335,11 +336,11 @@ public class ClustalxColourScheme extends ResidueColourScheme
   }
 
   @Override
-  public ColourSchemeI getInstance(AnnotatedCollectionI sg,
-          Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
+  public ColourSchemeI getInstance(AlignViewportI view,
+          AnnotatedCollectionI sg)
   {
     ClustalxColourScheme css = new ClustalxColourScheme(sg,
-            hiddenRepSequences);
+            view == null ? null : view.getHiddenRepSequences());
     css.includeGaps = includeGaps;
     return css;
   }
index d70b4e2..7b79d88 100755 (executable)
@@ -20,6 +20,7 @@
  */
 package jalview.schemes;
 
+import jalview.api.AlignViewportI;
 import jalview.datamodel.AnnotatedCollectionI;
 import jalview.datamodel.SequenceCollectionI;
 import jalview.datamodel.SequenceI;
@@ -62,12 +63,14 @@ public interface ColourSchemeI
    * new instance for each call to this method, as different instances may have
    * differing shading by consensus or percentage identity applied.
    * 
+   * @param viewport
+   *          - the parent viewport
    * @param sg
-   * @param hiddenRepSequences
+   *          - the collection of sequences to be coloured
    * @return copy of current scheme with any inherited settings transferred
    */
-  ColourSchemeI getInstance(AnnotatedCollectionI sg,
-          Map<SequenceI, SequenceCollectionI> hiddenRepSequences);
+  ColourSchemeI getInstance(AlignViewportI viewport,
+          AnnotatedCollectionI sg);
 
   /**
    * Answers true if the colour scheme is suitable for the given data, else
index fc92cd9..2d5b23d 100755 (executable)
@@ -20,6 +20,7 @@
  */
 package jalview.schemes;
 
+import jalview.api.AlignViewportI;
 import jalview.datamodel.AnnotatedCollectionI;
 import jalview.util.ColorUtils;
 
@@ -75,7 +76,8 @@ public class ColourSchemeProperty
    * @param name
    * @return
    */
-  public static ColourSchemeI getColourScheme(AnnotatedCollectionI forData,
+  public static ColourSchemeI getColourScheme(AlignViewportI view,
+          AnnotatedCollectionI forData,
           String name)
   {
     if (ResidueColourScheme.NONE.equalsIgnoreCase(name))
@@ -89,6 +91,7 @@ public class ColourSchemeProperty
      * create a new instance of it
      */
     ColourSchemeI scheme = ColourSchemes.getInstance().getColourScheme(name,
+            view,
             forData, null);
     if (scheme != null)
     {
index 99e9759..42465f2 100644 (file)
@@ -20,6 +20,7 @@
  */
 package jalview.schemes;
 
+import jalview.api.AlignViewportI;
 import jalview.datamodel.AnnotatedCollectionI;
 import jalview.datamodel.SequenceCollectionI;
 import jalview.datamodel.SequenceI;
@@ -65,7 +66,7 @@ public class ColourSchemes
      * store in an order-preserving map, so items can be added to menus 
      * in the order in which they are 'discovered'
      */
-    schemes = new LinkedHashMap<String, ColourSchemeI>();
+    schemes = new LinkedHashMap<>();
 
     for (JalviewColourScheme cs : JalviewColourScheme.values())
     {
@@ -76,6 +77,7 @@ public class ColourSchemes
       {
         System.err.println("Error instantiating colour scheme for "
                 + cs.toString() + " " + e.getMessage());
+        e.printStackTrace();
       }
     }
   }
@@ -126,6 +128,7 @@ public class ColourSchemes
    * 
    * @param name
    *          name of the colour scheme
+   * @param viewport
    * @param forData
    *          the data to be coloured
    * @param optional
@@ -134,7 +137,7 @@ public class ColourSchemes
    * @return
    */
   public ColourSchemeI getColourScheme(String name,
-          AnnotatedCollectionI forData,
+          AlignViewportI viewport, AnnotatedCollectionI forData,
           Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
   {
     if (name == null)
@@ -142,7 +145,8 @@ public class ColourSchemes
       return null;
     }
     ColourSchemeI cs = schemes.get(name.toLowerCase());
-    return cs == null ? null : cs.getInstance(forData, hiddenRepSequences);
+    return cs == null ? null
+            : cs.getInstance(viewport, forData);
   }
 
   /**
@@ -158,7 +162,7 @@ public class ColourSchemes
   public ColourSchemeI getColourScheme(String name,
           AnnotatedCollectionI forData)
   {
-    return getColourScheme(name, forData, null);
+    return getColourScheme(name, null, forData, null);
   }
 
   /**
index 923bd85..dc7971b 100644 (file)
  */
 package jalview.schemes;
 
+import jalview.api.AlignViewportI;
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.AnnotatedCollectionI;
-import jalview.datamodel.SequenceCollectionI;
-import jalview.datamodel.SequenceI;
 import jalview.util.ColorUtils;
 
 import java.awt.Color;
@@ -38,9 +37,9 @@ import java.util.Map;
  */
 public class CovariationColourScheme extends ResidueColourScheme
 {
-  public Map<String, Color> helixcolorhash = new Hashtable<String, Color>();
+  public Map<String, Color> helixcolorhash = new Hashtable<>();
 
-  public Map<Integer, String> positionsToHelix = new Hashtable<Integer, String>();
+  public Map<Integer, String> positionsToHelix = new Hashtable<>();
 
   int numHelix = 0;
 
@@ -51,8 +50,8 @@ public class CovariationColourScheme extends ResidueColourScheme
    * be coloured
    */
   @Override
-  public ColourSchemeI getInstance(AnnotatedCollectionI coll,
-          Map<SequenceI, SequenceCollectionI> hrs)
+  public ColourSchemeI getInstance(AlignViewportI view,
+          AnnotatedCollectionI coll)
   {
     return new CovariationColourScheme(coll.getAlignmentAnnotation()[0]);
   }
index 51e7645..6483b85 100644 (file)
@@ -25,6 +25,7 @@ import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.features.FeatureMatcher;
 import jalview.util.ColorUtils;
 import jalview.util.Format;
+import jalview.util.MessageManager;
 
 import java.awt.Color;
 import java.util.StringTokenizer;
@@ -50,6 +51,12 @@ import java.util.StringTokenizer;
  */
 public class FeatureColour implements FeatureColourI
 {
+  private static final String I18N_LABEL = MessageManager
+          .getString("label.label");
+
+  private static final String I18N_SCORE = MessageManager
+          .getString("label.score");
+
   private static final String ABSOLUTE = "abso";
 
   private static final String ABOVE = "above";
@@ -358,8 +365,8 @@ public class FeatureColour implements FeatureColourI
       Color maxColour = ColorUtils.parseColourString(maxcol);
       Color noColour = noValueColour.equals(NO_VALUE_MAX) ? maxColour
               : (noValueColour.equals(NO_VALUE_NONE) ? null : minColour);
-      featureColour = new FeatureColour(minColour, maxColour, noColour, min,
-              max);
+      featureColour = new FeatureColour(maxColour, minColour, maxColour,
+              noColour, min, max);
       featureColour.setColourByLabel(minColour == null);
       featureColour.setAutoScaled(autoScaled);
       if (byAttribute)
@@ -429,36 +436,25 @@ public class FeatureColour implements FeatureColourI
   }
 
   /**
-   * Constructor given a simple colour
+   * Constructor given a simple colour. This also 'primes' a graduated colour
+   * range, where the maximum colour is the given simple colour, and the minimum
+   * colour a paler shade of it. This is for convenience when switching from a
+   * simple colour to a graduated colour scheme.
    * 
    * @param c
    */
   public FeatureColour(Color c)
   {
-    minColour = Color.WHITE;
-    maxColour = Color.BLACK;
-    noColour = DEFAULT_NO_COLOUR;
-    minRed = 0f;
-    minGreen = 0f;
-    minBlue = 0f;
-    deltaRed = 0f;
-    deltaGreen = 0f;
-    deltaBlue = 0f;
-    colour = c;
-  }
+    /*
+     * set max colour to the simple colour, min colour to a paler shade of it
+     */
+    this(c, c == null ? Color.white : ColorUtils.bleachColour(c, 0.9f),
+            c == null ? Color.black : c, DEFAULT_NO_COLOUR, 0, 0);
 
-  /**
-   * Constructor given a colour range and a score range, defaulting 'no value
-   * colour' to be the same as minimum colour
-   * 
-   * @param low
-   * @param high
-   * @param min
-   * @param max
-   */
-  public FeatureColour(Color low, Color high, float min, float max)
-  {
-    this(low, high, low, min, max);
+    /*
+     * but enforce simple colour for now!
+     */
+    setGraduatedColour(false);
   }
 
   /**
@@ -491,29 +487,23 @@ public class FeatureColour implements FeatureColourI
   }
 
   /**
-   * Copy constructor with new min/max ranges
-   * 
-   * @param fc
-   * @param min
-   * @param max
-   */
-  public FeatureColour(FeatureColour fc, float min, float max)
-  {
-    this(fc);
-    updateBounds(min, max);
-  }
-
-  /**
-   * Constructor for a graduated colour
+   * Constructor that sets both simple and graduated colour values. This allows
+   * alternative colour schemes to be 'preserved' while switching between them
+   * to explore their effects on the visualisation.
+   * <p>
+   * This sets the colour scheme to 'graduated' by default. Override this if
+   * wanted by calling <code>setGraduatedColour(false)</code> for a simple
+   * colour, or <code>setColourByLabel(true)</code> for colour by label.
    * 
+   * @param myColour
    * @param low
    * @param high
    * @param noValueColour
    * @param min
    * @param max
    */
-  public FeatureColour(Color low, Color high, Color noValueColour,
-          float min, float max)
+  public FeatureColour(Color myColour, Color low, Color high,
+          Color noValueColour, float min, float max)
   {
     if (low == null)
     {
@@ -523,10 +513,10 @@ public class FeatureColour implements FeatureColourI
     {
       high = Color.black;
     }
-    graduatedColour = true;
-    colour = null;
+    colour = myColour;
     minColour = low;
     maxColour = high;
+    setGraduatedColour(true);
     noColour = noValueColour;
     threshold = Float.NaN;
     isHighToLow = min >= max;
@@ -558,7 +548,7 @@ public class FeatureColour implements FeatureColourI
    * Sets the 'graduated colour' flag. If true, also sets 'colour by label' to
    * false.
    */
-  void setGraduatedColour(boolean b)
+  public void setGraduatedColour(boolean b)
   {
     graduatedColour = b;
     if (b)
@@ -689,9 +679,12 @@ public class FeatureColour implements FeatureColourI
 
   /**
    * Returns the colour for the given instance of the feature. This may be a
-   * simple colour, a colour generated from the feature description (if
-   * isColourByLabel()), or a colour derived from the feature score (if
-   * isGraduatedColour()).
+   * simple colour, a colour generated from the feature description or other
+   * attribute (if isColourByLabel()), or a colour derived from the feature
+   * score or other attribute (if isGraduatedColour()).
+   * <p>
+   * Answers null if feature score (or attribute) value lies outside a
+   * configured threshold.
    * 
    * @param feature
    * @return
@@ -830,9 +823,20 @@ public class FeatureColour implements FeatureColourI
         sb.append(BAR).append(Format.getHexString(getMinColour()))
                 .append(BAR);
         sb.append(Format.getHexString(getMaxColour())).append(BAR);
-        String noValue = minColour.equals(noColour) ? NO_VALUE_MIN
-                : (maxColour.equals(noColour) ? NO_VALUE_MAX
-                        : NO_VALUE_NONE);
+        
+        /*
+         * 'no value' colour should be null, min or max colour;
+         * if none of these, coerce to minColour
+         */
+        String noValue = NO_VALUE_MIN;
+        if (maxColour.equals(noColour))
+        {
+          noValue = NO_VALUE_MAX;
+        }
+        if (noColour == null)
+        {
+          noValue = NO_VALUE_NONE;
+        }
         sb.append(noValue).append(BAR);
         if (!isAutoScaled())
         {
@@ -890,4 +894,78 @@ public class FeatureColour implements FeatureColourI
     attributeName = name;
   }
 
+  @Override
+  public boolean isOutwithThreshold(SequenceFeature feature)
+  {
+    if (!isGraduatedColour())
+    {
+      return false;
+    }
+    float scr = feature.getScore();
+    if (attributeName != null)
+    {
+      try
+      {
+        String attVal = feature.getValueAsString(attributeName);
+        scr = Float.valueOf(attVal);
+      } catch (Throwable e)
+      {
+        scr = Float.NaN;
+      }
+    }
+    if (Float.isNaN(scr))
+    {
+      return false;
+    }
+
+    return ((isAboveThreshold() && scr <= threshold)
+            || (isBelowThreshold() && scr >= threshold));
+  }
+
+  @Override
+  public String getDescription()
+  {
+    if (isSimpleColour())
+    {
+      return "r=" + colour.getRed() + ",g=" + colour.getGreen() + ",b="
+              + colour.getBlue();
+    }
+    StringBuilder tt = new StringBuilder();
+    String by = null;
+
+    if (getAttributeName() != null)
+    {
+      by = FeatureMatcher.toAttributeDisplayName(getAttributeName());
+    }
+    else if (isColourByLabel())
+    {
+      by = I18N_LABEL;
+    }
+    else
+    {
+      by = I18N_SCORE;
+    }
+    tt.append(MessageManager.formatMessage("action.by_title_param", by));
+
+    /*
+     * add threshold if any
+     */
+    if (isAboveThreshold() || isBelowThreshold())
+    {
+      tt.append(" (");
+      if (isColourByLabel())
+      {
+        /*
+         * Jalview features file supports the combination of 
+         * colour by label or attribute text with score threshold
+         */
+        tt.append(I18N_SCORE).append(" ");
+      }
+      tt.append(isAboveThreshold() ? "> " : "< ");
+      tt.append(getThreshold()).append(")");
+    }
+
+    return tt.toString();
+  }
+
 }
index 57c19e5..24b7713 100644 (file)
  */
 package jalview.schemes;
 
+import jalview.api.AlignViewportI;
 import jalview.datamodel.AnnotatedCollectionI;
-import jalview.datamodel.SequenceCollectionI;
-import jalview.datamodel.SequenceI;
-
-import java.util.Map;
 
 /**
  * Colourscheme that takes its colours from some other colourscheme
@@ -53,8 +50,8 @@ public class FollowerColourScheme extends ResidueColourScheme
    * be coloured
    */
   @Override
-  public ColourSchemeI getInstance(AnnotatedCollectionI coll,
-          Map<SequenceI, SequenceCollectionI> hrs)
+  public ColourSchemeI getInstance(AlignViewportI view,
+          AnnotatedCollectionI coll)
   {
     return new FollowerColourScheme();
   }
index 7123d93..2724f77 100755 (executable)
  */
 package jalview.schemes;
 
+import jalview.api.AlignViewportI;
 import jalview.datamodel.AnnotatedCollectionI;
-import jalview.datamodel.SequenceCollectionI;
-import jalview.datamodel.SequenceI;
 
 import java.awt.Color;
-import java.util.Map;
 
 public class HelixColourScheme extends ScoreColourScheme
 {
@@ -58,8 +56,8 @@ public class HelixColourScheme extends ScoreColourScheme
    * be coloured
    */
   @Override
-  public ColourSchemeI getInstance(AnnotatedCollectionI coll,
-          Map<SequenceI, SequenceCollectionI> hrs)
+  public ColourSchemeI getInstance(AlignViewportI view,
+          AnnotatedCollectionI coll)
   {
     return new HelixColourScheme();
   }
index 69af3c9..d886bdf 100755 (executable)
  */
 package jalview.schemes;
 
+import jalview.api.AlignViewportI;
 import jalview.datamodel.AnnotatedCollectionI;
-import jalview.datamodel.SequenceCollectionI;
-import jalview.datamodel.SequenceI;
 
 import java.awt.Color;
-import java.util.Map;
 
 /**
  * DOCUMENT ME!
@@ -75,8 +73,8 @@ public class HydrophobicColourScheme extends ScoreColourScheme
    * be coloured
    */
   @Override
-  public ColourSchemeI getInstance(AnnotatedCollectionI coll,
-          Map<SequenceI, SequenceCollectionI> hrs)
+  public ColourSchemeI getInstance(AlignViewportI view,
+          AnnotatedCollectionI coll)
   {
     return new HydrophobicColourScheme();
   }
diff --git a/src/jalview/schemes/IdColourScheme.java b/src/jalview/schemes/IdColourScheme.java
new file mode 100644 (file)
index 0000000..5add470
--- /dev/null
@@ -0,0 +1,108 @@
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+package jalview.schemes;
+
+import jalview.api.AlignViewportI;
+import jalview.datamodel.AnnotatedCollectionI;
+import jalview.datamodel.SequenceCollectionI;
+import jalview.datamodel.SequenceI;
+
+import java.awt.Color;
+import java.util.Map;
+
+/**
+ * shade sequences using the colour shown in the ID panel. Useful to map
+ * sequence groupings onto residue data (eg tree subgroups visualised on
+ * structures or overview window)
+ * 
+ * @author jprocter
+ */
+public class IdColourScheme implements ColourSchemeI
+{
+  AlignViewportI view = null;
+
+  public IdColourScheme()
+  {
+
+  }
+  public IdColourScheme(AlignViewportI view, AnnotatedCollectionI coll)
+  {
+    this.view = view;
+  }
+
+
+  @Override
+  public String getSchemeName()
+  {
+    return JalviewColourScheme.IdColour.toString();
+  }
+
+  /**
+   * Returns a new instance of this colour scheme with which the given data may
+   * be coloured
+   */
+  @Override
+  public ColourSchemeI getInstance(AlignViewportI view,
+          AnnotatedCollectionI coll)
+  {
+    return new IdColourScheme(view, coll);
+  }
+
+  @Override
+  public void alignmentChanged(AnnotatedCollectionI alignment,
+          Map<SequenceI, SequenceCollectionI> hiddenReps)
+  {
+  }
+
+  @Override
+  public Color findColour(char symbol, int position, SequenceI seq,
+          String consensusResidue, float pid)
+  {
+    // rather than testing if coll is a sequence group, and if so looking at
+    // ((SequenceGroup)coll).idColour
+    // we always return the sequence ID colour, in case the user has customised
+    // the displayed Id colour by right-clicking an internal node in the tree.
+    if (view == null)
+    {
+      return Color.WHITE;
+    }
+    Color col = view.getSequenceColour(seq);
+    return Color.WHITE.equals(col) ? Color.WHITE : col.darker();
+  }
+
+  @Override
+  public boolean hasGapColour()
+  {
+    return false;
+  }
+
+  @Override
+  public boolean isApplicableTo(AnnotatedCollectionI ac)
+  {
+    return true;
+  }
+
+  @Override
+  public boolean isSimple()
+  {
+    return false;
+  }
+}
index e1fc02d..456397e 100644 (file)
@@ -42,7 +42,8 @@ public enum JalviewColourScheme
   Nucleotide("Nucleotide", NucleotideColourScheme.class),
   PurinePyrimidine("Purine/Pyrimidine", PurinePyrimidineColourScheme.class),
   RNAHelices("RNA Helices", RNAHelicesColour.class),
-  TCoffee("T-Coffee Scores", TCoffeeColourScheme.class);
+  TCoffee("T-Coffee Scores", TCoffeeColourScheme.class),
+  IdColour("Sequence ID", IdColourScheme.class);
   // RNAInteraction("RNA Interaction type", RNAInteractionColourScheme.class)
 
   private String name;
index abae733..4977107 100755 (executable)
  */
 package jalview.schemes;
 
+import jalview.api.AlignViewportI;
 import jalview.datamodel.AnnotatedCollectionI;
-import jalview.datamodel.SequenceCollectionI;
-import jalview.datamodel.SequenceI;
-
-import java.util.Map;
 
 /**
  * DOCUMENT ME!
@@ -59,8 +56,8 @@ public class NucleotideColourScheme extends ResidueColourScheme
    * be coloured
    */
   @Override
-  public ColourSchemeI getInstance(AnnotatedCollectionI coll,
-          Map<SequenceI, SequenceCollectionI> hrs)
+  public ColourSchemeI getInstance(AlignViewportI view,
+          AnnotatedCollectionI coll)
   {
     return new NucleotideColourScheme();
   }
index fc922b9..3a5c066 100755 (executable)
  */
 package jalview.schemes;
 
+import jalview.api.AlignViewportI;
 import jalview.datamodel.AnnotatedCollectionI;
-import jalview.datamodel.SequenceCollectionI;
 import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
 import jalview.util.Comparison;
 
 import java.awt.Color;
-import java.util.Map;
 
 public class PIDColourScheme extends ResidueColourScheme
 {
@@ -92,8 +91,8 @@ public class PIDColourScheme extends ResidueColourScheme
    * be coloured
    */
   @Override
-  public ColourSchemeI getInstance(AnnotatedCollectionI coll,
-          Map<SequenceI, SequenceCollectionI> hrs)
+  public ColourSchemeI getInstance(AlignViewportI view,
+          AnnotatedCollectionI coll)
   {
     return new PIDColourScheme();
   }
index 1b36f30..a8270cc 100644 (file)
  */
 package jalview.schemes;
 
+import jalview.api.AlignViewportI;
 import jalview.datamodel.AnnotatedCollectionI;
-import jalview.datamodel.SequenceCollectionI;
-import jalview.datamodel.SequenceI;
-
-import java.util.Map;
 
 /**
  * Class is based off of NucleotideColourScheme
@@ -59,8 +56,8 @@ public class PurinePyrimidineColourScheme extends ResidueColourScheme
    * be coloured
    */
   @Override
-  public ColourSchemeI getInstance(AnnotatedCollectionI coll,
-          Map<SequenceI, SequenceCollectionI> hrs)
+  public ColourSchemeI getInstance(AlignViewportI view,
+          AnnotatedCollectionI coll)
   {
     return new PurinePyrimidineColourScheme();
   }
index dbc9c03..33b275d 100644 (file)
@@ -20,6 +20,7 @@
  */
 package jalview.schemes;
 
+import jalview.api.AlignViewportI;
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.AnnotatedCollectionI;
@@ -45,7 +46,7 @@ public class RNAHelicesColour extends ResidueColourScheme
    * Maps sequence positions to the RNA helix they belong to. Key: position,
    * Value: helix TODO: Revise or drop in favour of annotation position numbers
    */
-  public Hashtable<Integer, String> positionsToHelix = new Hashtable<Integer, String>();
+  public Hashtable<Integer, String> positionsToHelix = new Hashtable<>();
 
   /**
    * Number of helices in the RNA secondary structure
@@ -132,7 +133,7 @@ public class RNAHelicesColour extends ResidueColourScheme
       annotation.getRNAStruc();
       lastrefresh = annotation._rnasecstr.hashCode();
       numHelix = 0;
-      positionsToHelix = new Hashtable<Integer, String>();
+      positionsToHelix = new Hashtable<>();
 
       // Figure out number of helices
       // Length of rnasecstr is the number of pairs of positions that base pair
@@ -206,8 +207,8 @@ public class RNAHelicesColour extends ResidueColourScheme
   }
 
   @Override
-  public ColourSchemeI getInstance(AnnotatedCollectionI sg,
-          Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
+  public ColourSchemeI getInstance(AlignViewportI view,
+          AnnotatedCollectionI sg)
   {
     return new RNAHelicesColour(sg);
   }
index d236803..8610417 100644 (file)
  */
 package jalview.schemes;
 
+import jalview.api.AlignViewportI;
 import jalview.datamodel.AnnotatedCollectionI;
-import jalview.datamodel.SequenceCollectionI;
 import jalview.datamodel.SequenceI;
 
 import java.awt.Color;
-import java.util.Map;
 
 public class RNAInteractionColourScheme extends ResidueColourScheme
 {
@@ -73,8 +72,8 @@ public class RNAInteractionColourScheme extends ResidueColourScheme
    * be coloured
    */
   @Override
-  public ColourSchemeI getInstance(AnnotatedCollectionI coll,
-          Map<SequenceI, SequenceCollectionI> hrs)
+  public ColourSchemeI getInstance(AlignViewportI view,
+          AnnotatedCollectionI coll)
   {
     return new RNAInteractionColourScheme();
   }
index 2f7a5e0..03ab536 100755 (executable)
@@ -46,6 +46,12 @@ public abstract class ResidueColourScheme implements ColourSchemeI
   public static final String USER_DEFINED_MENU = "*User Defined*";
 
   /*
+   * the canonical name of the annotation colour scheme 
+   * (may be used to identify it in menu items)
+   */
+  public static final String ANNOTATION_COLOUR = "Annotation";
+
+  /*
    * lookup up by character value e.g. 'G' to the colors array index
    * e.g. if symbolIndex['K'] = 11 then colors[11] is the colour for K
    */
index a4e6480..d435065 100755 (executable)
@@ -20,6 +20,8 @@
  */
 package jalview.schemes;
 
+import jalview.analysis.GeneticCodes;
+
 import java.awt.Color;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -502,260 +504,6 @@ public class ResidueProperties
 
   public static String START = "ATG";
 
-  /**
-   * Nucleotide Ambiguity Codes
-   */
-  public static final Map<String, String[]> ambiguityCodes = new Hashtable<>();
-
-  /**
-   * Codon triplets with additional symbols for unambiguous codons that include
-   * ambiguity codes
-   */
-  public static final Hashtable<String, String> codonHash2 = new Hashtable<>();
-
-  /**
-   * all ambiguity codes for a given base
-   */
-  public final static Hashtable<String, List<String>> _ambiguityCodes = new Hashtable<>();
-
-  static
-  {
-    /*
-     * Ambiguity codes as per http://www.chem.qmul.ac.uk/iubmb/misc/naseq.html
-     */
-    ambiguityCodes.put("R", new String[] { "A", "G" });
-    ambiguityCodes.put("Y", new String[] { "T", "C" });
-    ambiguityCodes.put("W", new String[] { "A", "T" });
-    ambiguityCodes.put("S", new String[] { "G", "C" });
-    ambiguityCodes.put("M", new String[] { "A", "C" });
-    ambiguityCodes.put("K", new String[] { "G", "T" });
-    ambiguityCodes.put("H", new String[] { "A", "T", "C" });
-    ambiguityCodes.put("B", new String[] { "G", "T", "C" });
-    ambiguityCodes.put("V", new String[] { "G", "A", "C" });
-    ambiguityCodes.put("D", new String[] { "G", "A", "T" });
-    ambiguityCodes.put("N", new String[] { "G", "A", "T", "C" });
-
-    // Now build codon translation table
-    codonHash2.put("AAA", "K");
-    codonHash2.put("AAG", "K");
-    codonHash2.put("AAC", "N");
-    codonHash2.put("AAT", "N");
-
-    codonHash2.put("CAA", "Q");
-    codonHash2.put("CAG", "Q");
-    codonHash2.put("CAC", "H");
-    codonHash2.put("CAT", "H");
-
-    codonHash2.put("GAA", "E");
-    codonHash2.put("GAG", "E");
-    codonHash2.put("GAC", "D");
-    codonHash2.put("GAT", "D");
-
-    codonHash2.put("TAC", "Y");
-    codonHash2.put("TAT", "Y");
-
-    codonHash2.put("ACA", "T");
-    codonHash2.put("ACC", "T");
-    codonHash2.put("ACT", "T");
-    codonHash2.put("ACG", "T");
-
-    codonHash2.put("CCA", "P");
-    codonHash2.put("CCG", "P");
-    codonHash2.put("CCC", "P");
-    codonHash2.put("CCT", "P");
-
-    codonHash2.put("GCA", "A");
-    codonHash2.put("GCG", "A");
-    codonHash2.put("GCC", "A");
-    codonHash2.put("GCT", "A");
-
-    codonHash2.put("TCA", "S");
-    codonHash2.put("TCG", "S");
-    codonHash2.put("TCC", "S");
-    codonHash2.put("TCT", "S");
-    codonHash2.put("AGC", "S");
-    codonHash2.put("AGT", "S");
-
-    codonHash2.put("AGA", "R");
-    codonHash2.put("AGG", "R");
-    codonHash2.put("CGA", "R");
-    codonHash2.put("CGG", "R");
-    codonHash2.put("CGC", "R");
-    codonHash2.put("CGT", "R");
-
-    codonHash2.put("GGA", "G");
-    codonHash2.put("GGG", "G");
-    codonHash2.put("GGC", "G");
-    codonHash2.put("GGT", "G");
-
-    codonHash2.put("TGA", "*");
-    codonHash2.put("TAA", "*");
-    codonHash2.put("TAG", "*");
-
-    codonHash2.put("TGG", "W");
-
-    codonHash2.put("TGC", "C");
-    codonHash2.put("TGT", "C");
-
-    codonHash2.put("ATA", "I");
-    codonHash2.put("ATC", "I");
-    codonHash2.put("ATT", "I");
-
-    codonHash2.put("ATG", "M");
-
-    codonHash2.put("CTA", "L");
-    codonHash2.put("CTG", "L");
-    codonHash2.put("CTC", "L");
-    codonHash2.put("CTT", "L");
-    codonHash2.put("TTA", "L");
-    codonHash2.put("TTG", "L");
-
-    codonHash2.put("GTA", "V");
-    codonHash2.put("GTG", "V");
-    codonHash2.put("GTC", "V");
-    codonHash2.put("GTT", "V");
-
-    codonHash2.put("TTC", "F");
-    codonHash2.put("TTT", "F");
-
-    buildAmbiguityCodonSet();
-  }
-
-  /**
-   * programmatic generation of codons including ambiguity codes
-   */
-  public static void buildAmbiguityCodonSet()
-  {
-    if (_ambiguityCodes.size() > 0)
-    {
-      System.err
-              .println("Ignoring multiple calls to buildAmbiguityCodonSet");
-      return;
-    }
-    // Invert the ambiguity code set
-    for (Map.Entry<String, String[]> acode : ambiguityCodes.entrySet())
-    {
-      for (String r : acode.getValue())
-      {
-        List<String> codesfor = _ambiguityCodes.get(r);
-        if (codesfor == null)
-        {
-          _ambiguityCodes.put(r, codesfor = new ArrayList<>());
-        }
-        if (!codesfor.contains(acode.getKey()))
-        {
-          codesfor.add(acode.getKey());
-        }
-        else
-        {
-          System.err.println(
-                  "Inconsistency in the IUBMB ambiguity code nomenclature table: collision for "
-                          + acode.getKey() + " in residue " + r);
-        }
-      }
-    }
-    // and programmatically add in the ambiguity codes that yield the same amino
-    // acid
-    String[] unambcodons = codonHash2.keySet()
-            .toArray(new String[codonHash2.size()]);
-    for (String codon : unambcodons)
-    {
-      String residue = codonHash2.get(codon);
-      String acodon[][] = new String[codon.length()][];
-      for (int i = 0, iSize = codon.length(); i < iSize; i++)
-      {
-        String _ac = "" + codon.charAt(i);
-        List<String> acodes = _ambiguityCodes.get(_ac);
-        if (acodes != null)
-        {
-          acodon[i] = acodes.toArray(new String[acodes.size()]);
-        }
-        else
-        {
-          acodon[i] = new String[] {};
-        }
-      }
-      // enumerate all combinations and test for veracity of translation
-      int tpos[] = new int[codon.length()],
-              cpos[] = new int[codon.length()];
-      for (int i = 0; i < tpos.length; i++)
-      {
-        tpos[i] = -1;
-      }
-      tpos[acodon.length - 1] = 0;
-      int ipos, j;
-      while (tpos[0] < acodon[0].length)
-      {
-        // make all codons for this combination
-        char allres[][] = new char[tpos.length][];
-        String _acodon = "";
-        for (ipos = 0; ipos < tpos.length; ipos++)
-        {
-          if (acodon[ipos].length == 0 || tpos[ipos] < 0)
-          {
-            _acodon += codon.charAt(ipos);
-            allres[ipos] = new char[] { codon.charAt(ipos) };
-          }
-          else
-          {
-            _acodon += acodon[ipos][tpos[ipos]];
-            String[] altbase = ambiguityCodes.get(acodon[ipos][tpos[ipos]]);
-            allres[ipos] = new char[altbase.length];
-            j = 0;
-            for (String ab : altbase)
-            {
-              allres[ipos][j++] = ab.charAt(0);
-            }
-          }
-        }
-        // test all codons for this combination
-        for (ipos = 0; ipos < cpos.length; ipos++)
-        {
-          cpos[ipos] = 0;
-        }
-        boolean valid = true;
-        do
-        {
-          String _codon = "";
-          for (j = 0; j < cpos.length; j++)
-          {
-            _codon += allres[j][cpos[j]];
-          }
-          String tr = codonHash2.get(_codon);
-          if (valid = (tr != null && tr.equals(residue)))
-          {
-            // advance to next combination
-            ipos = acodon.length - 1;
-            while (++cpos[ipos] >= allres[ipos].length && ipos > 0)
-            {
-              cpos[ipos] = 0;
-              ipos--;
-            }
-          }
-        } while (valid && cpos[0] < allres[0].length);
-        if (valid)
-        {
-          // Add this to the set of codons we will translate
-          // System.out.println("Adding ambiguity codon: " + _acodon + " for "
-          // + residue);
-          codonHash2.put(_acodon, residue);
-        }
-        else
-        {
-          // System.err.println("Rejecting ambiguity codon: " + _acodon
-          // + " for " + residue);
-        }
-        // next combination
-        ipos = acodon.length - 1;
-        while (++tpos[ipos] >= acodon[ipos].length && ipos > 0)
-        {
-          tpos[ipos] = -1;
-          ipos--;
-        }
-      }
-    }
-  }
-
   // Stores residue codes/names and colours and other things
   public static Map<String, Map<String, Integer>> propHash = new Hashtable<>();
 
@@ -1148,55 +896,60 @@ public class ResidueProperties
 
   public static String codonTranslate(String lccodon)
   {
-    String cdn = codonHash2.get(lccodon.toUpperCase());
-    if ("*".equals(cdn))
+    String peptide = GeneticCodes.getInstance().getStandardCodeTable()
+            .translate(lccodon);
+    if ("*".equals(peptide))
     {
-      return STOP;
+      return "STOP";
     }
-    return cdn;
+    return peptide;
   }
 
-  public static Hashtable<String, String> toDssp3State;
+  /*
+   * lookup of (A-Z) alternative secondary structure symbols'
+   * equivalents in DSSP3 notation
+   */
+  private static char[] toDssp3State;
   static
   {
-    toDssp3State = new Hashtable<>();
-    toDssp3State.put("H", "H");
-    toDssp3State.put("E", "E");
-    toDssp3State.put("C", " ");
-    toDssp3State.put(" ", " ");
-    toDssp3State.put("T", " ");
-    toDssp3State.put("B", "E");
-    toDssp3State.put("G", "H");
-    toDssp3State.put("I", "H");
-    toDssp3State.put("X", " ");
+    toDssp3State = new char[9]; // for 'A'-'I'; extend if needed
+    Arrays.fill(toDssp3State, ' ');
+    toDssp3State['B' - 'A'] = 'E';
+    toDssp3State['E' - 'A'] = 'E';
+    toDssp3State['G' - 'A'] = 'H';
+    toDssp3State['H' - 'A'] = 'H';
+    toDssp3State['I' - 'A'] = 'H';
   }
 
   /**
    * translate from other dssp secondary structure alphabets to 3-state
    * 
-   * @param ssstring
-   * @return ssstring as a three-state secondary structure assignment.
+   * @param ssString
+   * @return ssstring
    */
-  public static String getDssp3state(String ssstring)
+  public static String getDssp3state(String ssString)
   {
-    if (ssstring == null)
+    if (ssString == null)
     {
       return null;
     }
-    StringBuffer ss = new StringBuffer();
-    for (int i = 0; i < ssstring.length(); i++)
+    int lookupSize = toDssp3State.length;
+    int len = ssString.length();
+    char[] trans = new char[len];
+    for (int i = 0; i < len; i++)
     {
-      String ssc = ssstring.substring(i, i + 1);
-      if (toDssp3State.containsKey(ssc))
+      char c = ssString.charAt(i);
+      int index = c - 'A';
+      if (index < 0 || index >= lookupSize)
       {
-        ss.append(toDssp3State.get(ssc));
+        trans[i] = ' ';
       }
       else
       {
-        ss.append(" ");
+        trans[i] = toDssp3State[index];
       }
     }
-    return ss.toString();
+    return new String(trans);
   }
 
   static
index e1b60ca..eae76e1 100755 (executable)
  */
 package jalview.schemes;
 
+import jalview.api.AlignViewportI;
 import jalview.datamodel.AnnotatedCollectionI;
-import jalview.datamodel.SequenceCollectionI;
 import jalview.datamodel.SequenceI;
 import jalview.util.Comparison;
 
 import java.awt.Color;
-import java.util.Map;
 
 /**
  * DOCUMENT ME!
@@ -119,8 +118,8 @@ public class ScoreColourScheme extends ResidueColourScheme
    * be coloured
    */
   @Override
-  public ColourSchemeI getInstance(AnnotatedCollectionI coll,
-          Map<SequenceI, SequenceCollectionI> hrs)
+  public ColourSchemeI getInstance(AlignViewportI view,
+          AnnotatedCollectionI coll)
   {
     return new ScoreColourScheme(symbolIndex, scores, min, max);
   }
index 5f11c29..ef55d69 100755 (executable)
  */
 package jalview.schemes;
 
+import jalview.api.AlignViewportI;
 import jalview.datamodel.AnnotatedCollectionI;
-import jalview.datamodel.SequenceCollectionI;
-import jalview.datamodel.SequenceI;
 
 import java.awt.Color;
-import java.util.Map;
 
 /**
  * DOCUMENT ME!
@@ -75,8 +73,8 @@ public class StrandColourScheme extends ScoreColourScheme
    * be coloured
    */
   @Override
-  public ColourSchemeI getInstance(AnnotatedCollectionI coll,
-          Map<SequenceI, SequenceCollectionI> hrs)
+  public ColourSchemeI getInstance(AlignViewportI view,
+          AnnotatedCollectionI coll)
   {
     return new StrandColourScheme();
   }
index 812dca7..db85cc8 100644 (file)
@@ -20,6 +20,7 @@
  */
 package jalview.schemes;
 
+import jalview.api.AlignViewportI;
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.AnnotatedCollectionI;
@@ -83,10 +84,10 @@ public class TCoffeeColourScheme extends ResidueColourScheme
 
     // assume only one set of TCOFFEE scores - but could have more than one
     // potentially.
-    List<AlignmentAnnotation> annots = new ArrayList<AlignmentAnnotation>();
+    List<AlignmentAnnotation> annots = new ArrayList<>();
     // Search alignment to get all tcoffee annotation and pick one set of
     // annotation to use to colour seqs.
-    seqMap = new IdentityHashMap<SequenceI, Color[]>();
+    seqMap = new IdentityHashMap<>();
     AnnotatedCollectionI alcontext = alignment instanceof AlignmentI
             ? alignment
             : alignment.getContext();
@@ -143,8 +144,8 @@ public class TCoffeeColourScheme extends ResidueColourScheme
   }
 
   @Override
-  public ColourSchemeI getInstance(AnnotatedCollectionI sg,
-          Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
+  public ColourSchemeI getInstance(AlignViewportI view,
+          AnnotatedCollectionI sg)
   {
     return new TCoffeeColourScheme(sg);
   }
index ac8abbc..e2a4516 100755 (executable)
  */
 package jalview.schemes;
 
+import jalview.api.AlignViewportI;
 import jalview.datamodel.AnnotatedCollectionI;
-import jalview.datamodel.SequenceCollectionI;
-import jalview.datamodel.SequenceI;
-
-import java.util.Map;
 
 public class TaylorColourScheme extends ResidueColourScheme
 {
@@ -50,8 +47,8 @@ public class TaylorColourScheme extends ResidueColourScheme
    * be coloured
    */
   @Override
-  public ColourSchemeI getInstance(AnnotatedCollectionI coll,
-          Map<SequenceI, SequenceCollectionI> hrs)
+  public ColourSchemeI getInstance(AlignViewportI view,
+          AnnotatedCollectionI coll)
   {
     return new TaylorColourScheme();
   }
index 67116b8..7d8035a 100755 (executable)
  */
 package jalview.schemes;
 
+import jalview.api.AlignViewportI;
 import jalview.datamodel.AnnotatedCollectionI;
-import jalview.datamodel.SequenceCollectionI;
-import jalview.datamodel.SequenceI;
 
 import java.awt.Color;
-import java.util.Map;
 
 /**
  * DOCUMENT ME!
@@ -75,8 +73,8 @@ public class TurnColourScheme extends ScoreColourScheme
    * be coloured
    */
   @Override
-  public ColourSchemeI getInstance(AnnotatedCollectionI coll,
-          Map<SequenceI, SequenceCollectionI> hrs)
+  public ColourSchemeI getInstance(AlignViewportI view,
+          AnnotatedCollectionI coll)
   {
     return new TurnColourScheme();
   }
index bf62e45..d77f2f5 100755 (executable)
@@ -20,9 +20,8 @@
  */
 package jalview.schemes;
 
+import jalview.api.AlignViewportI;
 import jalview.datamodel.AnnotatedCollectionI;
-import jalview.datamodel.SequenceCollectionI;
-import jalview.datamodel.SequenceI;
 import jalview.util.ColorUtils;
 import jalview.util.StringUtils;
 
@@ -56,8 +55,8 @@ public class UserColourScheme extends ResidueColourScheme
   }
 
   @Override
-  public ColourSchemeI getInstance(AnnotatedCollectionI sg,
-          Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
+  public ColourSchemeI getInstance(AlignViewportI view,
+          AnnotatedCollectionI sg)
   {
     return new UserColourScheme(this);
   }
index c32a39c..d69695f 100755 (executable)
  */
 package jalview.schemes;
 
+import jalview.api.AlignViewportI;
 import jalview.datamodel.AnnotatedCollectionI;
-import jalview.datamodel.SequenceCollectionI;
-import jalview.datamodel.SequenceI;
-
-import java.util.Map;
 
 /**
  * DOCUMENT ME!
@@ -59,8 +56,8 @@ public class ZappoColourScheme extends ResidueColourScheme
    * be coloured
    */
   @Override
-  public ColourSchemeI getInstance(AnnotatedCollectionI coll,
-          Map<SequenceI, SequenceCollectionI> hrs)
+  public ColourSchemeI getInstance(AlignViewportI view,
+          AnnotatedCollectionI coll)
   {
     return new ZappoColourScheme();
   }
index 50a34fc..5afbca5 100755 (executable)
@@ -43,9 +43,8 @@ public class DBRefUtils
   /*
    * lookup from lower-case form of a name to its canonical (standardised) form
    */
-  private static Map<String, String> canonicalSourceNameLookup = new HashMap<String, String>();
+  private static Map<String, String> canonicalSourceNameLookup = new HashMap<>();
 
-  private static Map<String, String> dasCoordinateSystemsLookup = new HashMap<String, String>();
 
   static
   {
@@ -73,10 +72,6 @@ public class DBRefUtils
               canonicalSourceNameLookup.get(k));
     }
 
-    dasCoordinateSystemsLookup.put("pdbresnum", DBRefSource.PDB);
-    dasCoordinateSystemsLookup.put("uniprot", DBRefSource.UNIPROT);
-    dasCoordinateSystemsLookup.put("embl", DBRefSource.EMBL);
-    // dasCoordinateSystemsLookup.put("embl", DBRefSource.EMBLCDS);
   }
 
   /**
@@ -97,13 +92,13 @@ public class DBRefUtils
     {
       return dbrefs;
     }
-    HashSet<String> srcs = new HashSet<String>();
+    HashSet<String> srcs = new HashSet<>();
     for (String src : sources)
     {
       srcs.add(src.toUpperCase());
     }
 
-    List<DBRefEntry> res = new ArrayList<DBRefEntry>();
+    List<DBRefEntry> res = new ArrayList<>();
     for (DBRefEntry dbr : dbrefs)
     {
       String source = getCanonicalName(dbr.getSource());
@@ -122,29 +117,6 @@ public class DBRefUtils
   }
 
   /**
-   * isDasCoordinateSystem
-   * 
-   * @param string
-   *          String
-   * @param dBRefEntry
-   *          DBRefEntry
-   * @return boolean true if Source DBRefEntry is compatible with DAS
-   *         CoordinateSystem name
-   */
-
-  public static boolean isDasCoordinateSystem(String string,
-          DBRefEntry dBRefEntry)
-  {
-    if (string == null || dBRefEntry == null)
-    {
-      return false;
-    }
-    String coordsys = dasCoordinateSystemsLookup.get(string.toLowerCase());
-    return coordsys == null ? false
-            : coordsys.equals(dBRefEntry.getSource());
-  }
-
-  /**
    * 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.
@@ -218,7 +190,7 @@ public class DBRefUtils
   static List<DBRefEntry> searchRefs(DBRefEntry[] refs, DBRefEntry entry,
           DbRefComp comparator)
   {
-    List<DBRefEntry> rfs = new ArrayList<DBRefEntry>();
+    List<DBRefEntry> rfs = new ArrayList<>();
     if (refs == null || entry == null)
     {
       return rfs;
@@ -594,7 +566,7 @@ public class DBRefUtils
   public static List<DBRefEntry> searchRefsForSource(DBRefEntry[] dbRefs,
           String source)
   {
-    List<DBRefEntry> matches = new ArrayList<DBRefEntry>();
+    List<DBRefEntry> matches = new ArrayList<>();
     if (dbRefs != null && source != null)
     {
       for (DBRefEntry dbref : dbRefs)
@@ -644,7 +616,7 @@ public class DBRefUtils
       // nothing to do
       return;
     }
-    List<DBRefEntry> selfs = new ArrayList<DBRefEntry>();
+    List<DBRefEntry> selfs = new ArrayList<>();
     {
       DBRefEntry[] selfArray = selectDbRefs(!sequence.isProtein(),
               sequence.getDBRefs());
@@ -664,11 +636,11 @@ public class DBRefUtils
         selfs.remove(p);
       }
     }
-    List<DBRefEntry> toPromote = new ArrayList<DBRefEntry>();
+    List<DBRefEntry> toPromote = new ArrayList<>();
 
     for (DBRefEntry p : pr)
     {
-      List<String> promType = new ArrayList<String>();
+      List<String> promType = new ArrayList<>();
       if (sequence.isProtein())
       {
         switch (getCanonicalName(p.getSource()))
diff --git a/src/jalview/util/JSONUtils.java b/src/jalview/util/JSONUtils.java
new file mode 100644 (file)
index 0000000..cdfc88e
--- /dev/null
@@ -0,0 +1,34 @@
+package jalview.util;
+
+import org.json.simple.JSONArray;
+
+public class JSONUtils
+{
+
+  /**
+   * Converts a JSONArray of values to a string as a comma-separated list.
+   * Answers null if the array is null or empty.
+   * 
+   * @param jsonArray
+   * @return
+   */
+  public static String arrayToList(JSONArray jsonArray)
+  {
+    if (jsonArray == null)
+    {
+      return null;
+    }
+
+    StringBuilder sb = new StringBuilder();
+    for (int i = 0; i < jsonArray.size(); i++)
+    {
+      if (i > 0)
+      {
+        sb.append(",");
+      }
+      sb.append(jsonArray.get(i).toString());
+    }
+    return sb.length() == 0 ? null : sb.toString();
+  }
+
+}
index 1366ada..148ea16 100644 (file)
@@ -662,7 +662,8 @@ public abstract class AlignmentViewport
          * retain any colour thresholds per group while
          * changing choice of colour scheme (JAL-2386)
          */
-        sg.setColourScheme(cs);
+        sg.setColourScheme(
+                cs == null ? null : cs.getInstance(this, sg));
         if (cs != null)
         {
           sg.getGroupColourScheme().alignmentChanged(sg,
@@ -1636,6 +1637,7 @@ public abstract class AlignmentViewport
   public void invertColumnSelection()
   {
     colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
+    isColSelChanged(true);
   }
 
   @Override
@@ -2954,4 +2956,68 @@ public abstract class AlignmentViewport
   {
     return currentTree;
   }
+
+  /**
+   * flag set to indicate if structure views might be out of sync with sequences
+   * in the alignment
+   */
+
+  private boolean needToUpdateStructureViews = false;
+
+  @Override
+  public boolean isUpdateStructures()
+  {
+    return needToUpdateStructureViews;
+  }
+
+  @Override
+  public void setUpdateStructures(boolean update)
+  {
+    needToUpdateStructureViews = update;
+  }
+
+  @Override
+  public boolean needToUpdateStructureViews()
+  {
+    boolean update = needToUpdateStructureViews;
+    needToUpdateStructureViews = false;
+    return update;
+  }
+
+  @Override
+  public void addSequenceGroup(SequenceGroup sequenceGroup)
+  {
+    alignment.addGroup(sequenceGroup);
+
+    Color col = sequenceGroup.idColour;
+    if (col != null)
+    {
+      col = col.brighter();
+
+      for (SequenceI sq : sequenceGroup.getSequences())
+      {
+        setSequenceColour(sq, col);
+      }
+    }
+
+    if (codingComplement != null)
+    {
+      SequenceGroup mappedGroup = MappingUtils
+              .mapSequenceGroup(sequenceGroup, this, codingComplement);
+      if (mappedGroup.getSequences().size() > 0)
+      {
+        codingComplement.getAlignment().addGroup(mappedGroup);
+
+        if (col != null)
+        {
+          for (SequenceI seq : mappedGroup.getSequences())
+          {
+            codingComplement.setSequenceColour(seq, col);
+          }
+        }
+      }
+      // propagate the structure view update flag according to our own setting
+      codingComplement.setUpdateStructures(needToUpdateStructureViews);
+    }
+  }
 }
index 5e7fca2..1693294 100644 (file)
@@ -25,31 +25,39 @@ import jalview.api.RotatableCanvasI;
 import jalview.api.analysis.ScoreModelI;
 import jalview.api.analysis.SimilarityParamsI;
 import jalview.datamodel.AlignmentView;
+import jalview.datamodel.Point;
 import jalview.datamodel.SequenceI;
 import jalview.datamodel.SequencePoint;
 
+import java.util.List;
 import java.util.Vector;
 
 public class PCAModel
 {
-  private volatile PCA pca;
-
-  int top;
+  /*
+   * inputs
+   */
+  private AlignmentView inputData;
 
-  AlignmentView seqstrings;
+  private final SequenceI[] seqs;
 
-  SequenceI[] seqs;
+  private final SimilarityParamsI similarityParams;
 
   /*
-   * Name of score model used to calculate PCA
+   * options - score model, nucleotide / protein
    */
-  ScoreModelI scoreModel;
+  private ScoreModelI scoreModel;
 
   private boolean nucleotide = false;
 
-  private Vector<SequencePoint> points;
+  /*
+   * outputs
+   */
+  private PCA pca;
 
-  private SimilarityParamsI similarityParams;
+  int top;
+
+  private List<SequencePoint> points;
 
   /**
    * Constructor given sequence data, score model and score calculation
@@ -64,17 +72,21 @@ public class PCAModel
   public PCAModel(AlignmentView seqData, SequenceI[] sqs, boolean nuc,
           ScoreModelI modelName, SimilarityParamsI params)
   {
-    seqstrings = seqData;
+    inputData = seqData;
     seqs = sqs;
     nucleotide = nuc;
     scoreModel = modelName;
     similarityParams = params;
   }
 
-  public void run()
+  /**
+   * Performs the PCA calculation (in the same thread) and extracts result data
+   * needed for visualisation by PCAPanel
+   */
+  public void calculate()
   {
-    pca = new PCA(seqstrings, scoreModel, similarityParams);
-    pca.run();
+    pca = new PCA(inputData, scoreModel, similarityParams);
+    pca.run(); // executes in same thread, wait for completion
 
     // Now find the component coordinates
     int ii = 0;
@@ -88,13 +100,13 @@ public class PCAModel
     // top = pca.getM().height() - 1;
     top = height - 1;
 
-    points = new Vector<SequencePoint>();
-    float[][] scores = pca.getComponents(top - 1, top - 2, top - 3, 100);
+    points = new Vector<>();
+    Point[] scores = pca.getComponents(top - 1, top - 2, top - 3, 100);
 
     for (int i = 0; i < height; i++)
     {
       SequencePoint sp = new SequencePoint(seqs[i], scores[i]);
-      points.addElement(sp);
+      points.add(sp);
     }
   }
 
@@ -114,17 +126,22 @@ public class PCAModel
   }
 
   /**
+   * Answers the index of the principal dimension of the PCA
    * 
-   * 
-   * @return index of principle dimension of PCA
+   * @return
    */
   public int getTop()
   {
     return top;
   }
 
+  public void setTop(int t)
+  {
+    top = t;
+  }
+
   /**
-   * update the 2d coordinates for the list of points to the given dimensions
+   * Updates the 3D coordinates for the list of points to the given dimensions.
    * Principal dimension is getTop(). Next greatest eigenvector is getTop()-1.
    * Note - pca.getComponents starts counting the spectrum from rank-2 to zero,
    * rather than rank-1, so getComponents(dimN ...) == updateRcView(dimN+1 ..)
@@ -136,11 +153,11 @@ public class PCAModel
   public void updateRcView(int dim1, int dim2, int dim3)
   {
     // note: actual indices for components are dim1-1, etc (patch for JAL-1123)
-    float[][] scores = pca.getComponents(dim1 - 1, dim2 - 1, dim3 - 1, 100);
+    Point[] scores = pca.getComponents(dim1 - 1, dim2 - 1, dim3 - 1, 100);
 
     for (int i = 0; i < pca.getHeight(); i++)
     {
-      points.elementAt(i).coord = scores[i];
+      points.get(i).coord = scores[i];
     }
   }
 
@@ -149,9 +166,14 @@ public class PCAModel
     return pca.getDetails();
   }
 
-  public AlignmentView getSeqtrings()
+  public AlignmentView getInputData()
+  {
+    return inputData;
+  }
+
+  public void setInputData(AlignmentView data)
   {
-    return seqstrings;
+    inputData = data;
   }
 
   public String getPointsasCsv(boolean transformed, int xdim, int ydim,
@@ -192,42 +214,58 @@ public class PCAModel
       }
       else
       {
-        // output current x,y,z coords for points
-        fl = getPointPosition(s);
-        for (int d = 0; d < fl.length; d++)
-        {
-          csv.append(",");
-          csv.append(fl[d]);
-        }
+        Point p = points.get(s).coord;
+        csv.append(",").append(p.x);
+        csv.append(",").append(p.y);
+        csv.append(",").append(p.z);
       }
       csv.append("\n");
     }
     return csv.toString();
   }
 
+  public String getScoreModelName()
+  {
+    return scoreModel == null ? "" : scoreModel.getName();
+  }
+
+  public void setScoreModel(ScoreModelI sm)
+  {
+    this.scoreModel = sm;
+  }
+
   /**
+   * Answers the parameters configured for pairwise similarity calculations
    * 
-   * @return x,y,z positions of point s (index into points) under current
-   *         transform.
+   * @return
    */
-  public double[] getPointPosition(int s)
+  public SimilarityParamsI getSimilarityParameters()
   {
-    double pts[] = new double[3];
-    float[] p = points.elementAt(s).coord;
-    pts[0] = p[0];
-    pts[1] = p[1];
-    pts[2] = p[2];
-    return pts;
+    return similarityParams;
   }
 
-  public String getScoreModelName()
+  public List<SequencePoint> getSequencePoints()
   {
-    return scoreModel == null ? "" : scoreModel.getName();
+    return points;
   }
 
-  public void setScoreModel(ScoreModelI sm)
+  public void setSequencePoints(List<SequencePoint> sp)
   {
-    this.scoreModel = sm;
+    points = sp;
+  }
+
+  /**
+   * Answers the object holding the values of the computed PCA
+   * 
+   * @return
+   */
+  public PCA getPcaData()
+  {
+    return pca;
   }
 
+  public void setPCA(PCA data)
+  {
+    pca = data;
+  }
 }
index 691e492..6f817bb 100644 (file)
@@ -97,7 +97,7 @@ public class ViewportRanges extends ViewportProperties
    */
   public int getVisibleAlignmentWidth()
   {
-    return al.getWidth() - al.getHiddenColumns().getSize();
+    return al.getVisibleWidth();
   }
 
   /**
index 553f813..4af6fde 100644 (file)
@@ -1029,11 +1029,11 @@ public abstract class FeatureRendererModel
   }
 
   /**
-   * Removes from the list of features any that duplicate the location of a
-   * feature of the same type. Should be used only for features of the same,
-   * simple, feature colour (which normally implies the same feature type). Does
-   * not check visibility settings for feature type or feature group. No
-   * filtering is done if transparency, or any feature filters, are in force.
+   * Removes from the list of features any whose group is not shown, or that are
+   * visible and duplicate the location of a visible feature of the same type.
+   * Should be used only for features of the same, simple, feature colour (which
+   * normally implies the same feature type). No filtering is done if
+   * transparency, or any feature filters, are in force.
    * 
    * @param features
    */
@@ -1057,6 +1057,11 @@ public abstract class FeatureRendererModel
     while (it.hasNext())
     {
       SequenceFeature sf = it.next();
+      if (featureGroupNotShown(sf))
+      {
+        it.remove();
+        continue;
+      }
 
       /*
        * a feature is redundant for rendering purposes if it has the
@@ -1064,7 +1069,8 @@ public abstract class FeatureRendererModel
        * (checking type and isContactFeature as a fail-safe here, although
        * currently they are guaranteed to match in this context)
        */
-      if (lastFeature != null && sf.getBegin() == lastFeature.getBegin()
+      if (lastFeature != null
+              && sf.getBegin() == lastFeature.getBegin()
               && sf.getEnd() == lastFeature.getEnd()
               && sf.isContactFeature() == lastFeature.isContactFeature()
               && sf.getType().equals(lastFeature.getType()))
@@ -1150,4 +1156,32 @@ public abstract class FeatureRendererModel
     return filter == null ? true : filter.matches(sf);
   }
 
+  @Override
+  public boolean isVisible(SequenceFeature feature)
+  {
+    if (feature == null)
+    {
+      return false;
+    }
+    if (getFeaturesDisplayed() == null
+            || !getFeaturesDisplayed().isVisible(feature.getType()))
+    {
+      return false;
+    }
+    if (featureGroupNotShown(feature))
+    {
+      return false;
+    }
+    FeatureColourI fc = featureColours.get(feature.getType());
+    if (fc != null && fc.isOutwithThreshold(feature))
+    {
+      return false;
+    }
+    if (!featureMatchesFilters(feature))
+    {
+      return false;
+    }
+    return true;
+  }
+
 }
index 335529c..78c6da2 100644 (file)
@@ -118,7 +118,10 @@ public class ConsensusThread extends AlignCalcWorker
   protected void eraseConsensus(int aWidth)
   {
     AlignmentAnnotation consensus = getConsensusAnnotation();
-    consensus.annotations = new Annotation[aWidth];
+    if (consensus != null)
+    {
+      consensus.annotations = new Annotation[aWidth];
+    }
     AlignmentAnnotation gap = getGapAnnotation();
     if (gap != null)
     {
index 061e70c..ae4207b 100644 (file)
@@ -670,7 +670,8 @@ public class DBRefFetcher implements Runnable
             int startShift = absStart - sequenceStart + 1;
             if (startShift != 0)
             {
-              modified |= sequence.getFeatures().shiftFeatures(startShift);
+              modified |= sequence.getFeatures().shiftFeatures(1,
+                      startShift);
             }
           }
         }
@@ -754,8 +755,6 @@ public class DBRefFetcher implements Runnable
         // and remove it from the rest
         // TODO: decide if we should remove annotated sequence from set
         sdataset.remove(sequence);
-        // TODO: should we make a note of sequences that have received new DB
-        // ids, so we can query all enabled DAS servers for them ?
       }
     }
     return modified;
index 86282c7..d97bf69 100644 (file)
@@ -178,16 +178,12 @@ public class Uniprot extends DbSourceProxyImpl
   SequenceI uniprotEntryToSequence(Entry entry)
   {
     String id = getUniprotEntryId(entry);
-    String seqString = entry.getSequence().getValue();
-
     /*
-     * for backwards compatibility with Castor processing,
-     * remove any internal spaces
+     * Sequence should not include any whitespace, but JAXB leaves these in
      */
-    if (seqString.indexOf(' ') > -1)
-    {
-      seqString = seqString.replace(" ", "");
-    }
+    String seqString = entry.getSequence().getValue().replaceAll("\\s*",
+            "");
+
     SequenceI sequence = new Sequence(id,
             seqString);
     sequence.setDescription(getUniprotEntryDescription(entry));
index 9a2316c..a1b8e7a 100644 (file)
@@ -344,8 +344,9 @@ public class AADisorderClient extends JabawsCalcWorker
             {
               // set graduated color as fading to white for minimum, and
               // autoscaling to values on alignment
-              FeatureColourI ggc = new FeatureColour(Color.white,
-                      gc.getColour(), Float.MIN_VALUE, Float.MAX_VALUE);
+              FeatureColourI ggc = new FeatureColour(gc.getColour(),
+                      Color.white, gc.getColour(), Color.white,
+                      Float.MIN_VALUE, Float.MAX_VALUE);
               ggc.setAutoScaled(true);
               fr.setColour(ft, ggc);
             }
index 370ecc5..83f1ee2 100644 (file)
@@ -2,7 +2,7 @@
 // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 
 // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 
 // Any modifications to this file will be lost upon recompilation of the source schema. 
-// Generated on: 2018.09.28 at 12:18:54 PM BST 
+// Generated on: 2018.12.20 at 11:47:26 AM GMT 
 //
 
 
index 148406e..0dbcad0 100644 (file)
@@ -2,7 +2,7 @@
 // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 
 // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 
 // Any modifications to this file will be lost upon recompilation of the source schema. 
-// Generated on: 2018.09.28 at 12:18:54 PM BST 
+// Generated on: 2018.12.20 at 11:47:26 AM GMT 
 //
 
 
index c9ee5f1..44affa2 100644 (file)
@@ -2,7 +2,7 @@
 // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 
 // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 
 // Any modifications to this file will be lost upon recompilation of the source schema. 
-// Generated on: 2018.09.28 at 12:18:54 PM BST 
+// Generated on: 2018.12.20 at 11:47:26 AM GMT 
 //
 
 
index 8cbd4fe..de408d2 100644 (file)
@@ -2,7 +2,7 @@
 // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 
 // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 
 // Any modifications to this file will be lost upon recompilation of the source schema. 
-// Generated on: 2018.09.28 at 12:18:54 PM BST 
+// Generated on: 2018.12.20 at 11:47:26 AM GMT 
 //
 
 
diff --git a/src/jalview/xml/binding/jalview/DoubleMatrix.java b/src/jalview/xml/binding/jalview/DoubleMatrix.java
new file mode 100644 (file)
index 0000000..b4c07bc
--- /dev/null
@@ -0,0 +1,186 @@
+//
+// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 
+// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 
+// Any modifications to this file will be lost upon recompilation of the source schema. 
+// Generated on: 2018.12.20 at 11:47:26 AM GMT 
+//
+
+
+package jalview.xml.binding.jalview;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlType;
+
+
+/**
+ * <p>Java class for DoubleMatrix complex type.
+ * 
+ * <p>The following schema fragment specifies the expected content contained within this class.
+ * 
+ * <pre>
+ * &lt;complexType name="DoubleMatrix">
+ *   &lt;complexContent>
+ *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       &lt;sequence>
+ *         &lt;element name="row" type="{www.jalview.org}DoubleVector" maxOccurs="unbounded" minOccurs="0"/>
+ *         &lt;element name="D" type="{www.jalview.org}DoubleVector" minOccurs="0"/>
+ *         &lt;element name="E" type="{www.jalview.org}DoubleVector" minOccurs="0"/>
+ *       &lt;/sequence>
+ *       &lt;attribute name="rows" type="{http://www.w3.org/2001/XMLSchema}int" />
+ *       &lt;attribute name="columns" type="{http://www.w3.org/2001/XMLSchema}int" />
+ *     &lt;/restriction>
+ *   &lt;/complexContent>
+ * &lt;/complexType>
+ * </pre>
+ * 
+ * 
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "DoubleMatrix", namespace = "www.jalview.org", propOrder = {
+    "row",
+    "d",
+    "e"
+})
+public class DoubleMatrix {
+
+    protected List<DoubleVector> row;
+    @XmlElement(name = "D")
+    protected DoubleVector d;
+    @XmlElement(name = "E")
+    protected DoubleVector e;
+    @XmlAttribute(name = "rows")
+    protected Integer rows;
+    @XmlAttribute(name = "columns")
+    protected Integer columns;
+
+    /**
+     * Gets the value of the row property.
+     * 
+     * <p>
+     * This accessor method returns a reference to the live list,
+     * not a snapshot. Therefore any modification you make to the
+     * returned list will be present inside the JAXB object.
+     * This is why there is not a <CODE>set</CODE> method for the row property.
+     * 
+     * <p>
+     * For example, to add a new item, do as follows:
+     * <pre>
+     *    getRow().add(newItem);
+     * </pre>
+     * 
+     * 
+     * <p>
+     * Objects of the following type(s) are allowed in the list
+     * {@link DoubleVector }
+     * 
+     * 
+     */
+    public List<DoubleVector> getRow() {
+        if (row == null) {
+            row = new ArrayList<DoubleVector>();
+        }
+        return this.row;
+    }
+
+    /**
+     * Gets the value of the d property.
+     * 
+     * @return
+     *     possible object is
+     *     {@link DoubleVector }
+     *     
+     */
+    public DoubleVector getD() {
+        return d;
+    }
+
+    /**
+     * Sets the value of the d property.
+     * 
+     * @param value
+     *     allowed object is
+     *     {@link DoubleVector }
+     *     
+     */
+    public void setD(DoubleVector value) {
+        this.d = value;
+    }
+
+    /**
+     * Gets the value of the e property.
+     * 
+     * @return
+     *     possible object is
+     *     {@link DoubleVector }
+     *     
+     */
+    public DoubleVector getE() {
+        return e;
+    }
+
+    /**
+     * Sets the value of the e property.
+     * 
+     * @param value
+     *     allowed object is
+     *     {@link DoubleVector }
+     *     
+     */
+    public void setE(DoubleVector value) {
+        this.e = value;
+    }
+
+    /**
+     * Gets the value of the rows property.
+     * 
+     * @return
+     *     possible object is
+     *     {@link Integer }
+     *     
+     */
+    public Integer getRows() {
+        return rows;
+    }
+
+    /**
+     * Sets the value of the rows property.
+     * 
+     * @param value
+     *     allowed object is
+     *     {@link Integer }
+     *     
+     */
+    public void setRows(Integer value) {
+        this.rows = value;
+    }
+
+    /**
+     * Gets the value of the columns property.
+     * 
+     * @return
+     *     possible object is
+     *     {@link Integer }
+     *     
+     */
+    public Integer getColumns() {
+        return columns;
+    }
+
+    /**
+     * Sets the value of the columns property.
+     * 
+     * @param value
+     *     allowed object is
+     *     {@link Integer }
+     *     
+     */
+    public void setColumns(Integer value) {
+        this.columns = value;
+    }
+
+}
diff --git a/src/jalview/xml/binding/jalview/DoubleVector.java b/src/jalview/xml/binding/jalview/DoubleVector.java
new file mode 100644 (file)
index 0000000..e2592ab
--- /dev/null
@@ -0,0 +1,76 @@
+//
+// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 
+// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 
+// Any modifications to this file will be lost upon recompilation of the source schema. 
+// Generated on: 2018.12.20 at 11:47:26 AM GMT 
+//
+
+
+package jalview.xml.binding.jalview;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlType;
+
+
+/**
+ * <p>Java class for DoubleVector complex type.
+ * 
+ * <p>The following schema fragment specifies the expected content contained within this class.
+ * 
+ * <pre>
+ * &lt;complexType name="DoubleVector">
+ *   &lt;complexContent>
+ *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       &lt;sequence>
+ *         &lt;element name="v" type="{http://www.w3.org/2001/XMLSchema}double" maxOccurs="unbounded" minOccurs="0"/>
+ *       &lt;/sequence>
+ *     &lt;/restriction>
+ *   &lt;/complexContent>
+ * &lt;/complexType>
+ * </pre>
+ * 
+ * 
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "DoubleVector", namespace = "www.jalview.org", propOrder = {
+    "v"
+})
+public class DoubleVector {
+
+    @XmlElement(type = Double.class)
+    protected List<Double> v;
+
+    /**
+     * Gets the value of the v property.
+     * 
+     * <p>
+     * This accessor method returns a reference to the live list,
+     * not a snapshot. Therefore any modification you make to the
+     * returned list will be present inside the JAXB object.
+     * This is why there is not a <CODE>set</CODE> method for the v property.
+     * 
+     * <p>
+     * For example, to add a new item, do as follows:
+     * <pre>
+     *    getV().add(newItem);
+     * </pre>
+     * 
+     * 
+     * <p>
+     * Objects of the following type(s) are allowed in the list
+     * {@link Double }
+     * 
+     * 
+     */
+    public List<Double> getV() {
+        if (v == null) {
+            v = new ArrayList<Double>();
+        }
+        return this.v;
+    }
+
+}
index 7585f83..9001ee2 100644 (file)
@@ -2,7 +2,7 @@
 // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 
 // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 
 // Any modifications to this file will be lost upon recompilation of the source schema. 
-// Generated on: 2018.09.28 at 12:18:54 PM BST 
+// Generated on: 2018.12.20 at 11:47:26 AM GMT 
 //
 
 
index 3161408..0daf56a 100644 (file)
@@ -2,7 +2,7 @@
 // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 
 // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 
 // Any modifications to this file will be lost upon recompilation of the source schema. 
-// Generated on: 2018.09.28 at 12:18:54 PM BST 
+// Generated on: 2018.12.20 at 11:47:26 AM GMT 
 //
 
 
index 5e181a1..bf69d5b 100644 (file)
@@ -2,7 +2,7 @@
 // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 
 // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 
 // Any modifications to this file will be lost upon recompilation of the source schema. 
-// Generated on: 2018.09.28 at 12:18:54 PM BST 
+// Generated on: 2018.12.20 at 11:47:26 AM GMT 
 //
 
 
index a854b63..5684acf 100644 (file)
@@ -2,7 +2,7 @@
 // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 
 // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 
 // Any modifications to this file will be lost upon recompilation of the source schema. 
-// Generated on: 2018.09.28 at 12:18:54 PM BST 
+// Generated on: 2018.12.20 at 11:47:26 AM GMT 
 //
 
 
index 0f538f2..ed57edc 100644 (file)
@@ -2,7 +2,7 @@
 // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 
 // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 
 // Any modifications to this file will be lost upon recompilation of the source schema. 
-// Generated on: 2018.09.28 at 12:18:54 PM BST 
+// Generated on: 2018.12.20 at 11:47:26 AM GMT 
 //
 
 
@@ -243,6 +243,66 @@ import javax.xml.datatype.XMLGregorianCalendar;
  *                   &lt;attribute name="fitToWindow" type="{http://www.w3.org/2001/XMLSchema}boolean" />
  *                   &lt;attribute name="currentTree" type="{http://www.w3.org/2001/XMLSchema}boolean" />
  *                   &lt;attribute name="id" type="{http://www.w3.org/2001/XMLSchema}ID" />
+ *                   &lt;attribute name="linkToAllViews" type="{http://www.w3.org/2001/XMLSchema}boolean" default="false" />
+ *                 &lt;/restriction>
+ *               &lt;/complexContent>
+ *             &lt;/complexType>
+ *           &lt;/element>
+ *           &lt;element name="PcaViewer" maxOccurs="unbounded" minOccurs="0">
+ *             &lt;complexType>
+ *               &lt;complexContent>
+ *                 &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *                   &lt;sequence>
+ *                     &lt;element name="sequencePoint" maxOccurs="unbounded">
+ *                       &lt;complexType>
+ *                         &lt;complexContent>
+ *                           &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *                             &lt;attGroup ref="{www.jalview.org}position"/>
+ *                             &lt;attribute name="sequenceRef" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *                           &lt;/restriction>
+ *                         &lt;/complexContent>
+ *                       &lt;/complexType>
+ *                     &lt;/element>
+ *                     &lt;element name="axis" maxOccurs="3" minOccurs="3">
+ *                       &lt;complexType>
+ *                         &lt;complexContent>
+ *                           &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *                             &lt;attGroup ref="{www.jalview.org}position"/>
+ *                           &lt;/restriction>
+ *                         &lt;/complexContent>
+ *                       &lt;/complexType>
+ *                     &lt;/element>
+ *                     &lt;element name="seqPointMin">
+ *                       &lt;complexType>
+ *                         &lt;complexContent>
+ *                           &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *                             &lt;attGroup ref="{www.jalview.org}position"/>
+ *                           &lt;/restriction>
+ *                         &lt;/complexContent>
+ *                       &lt;/complexType>
+ *                     &lt;/element>
+ *                     &lt;element name="seqPointMax">
+ *                       &lt;complexType>
+ *                         &lt;complexContent>
+ *                           &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *                             &lt;attGroup ref="{www.jalview.org}position"/>
+ *                           &lt;/restriction>
+ *                         &lt;/complexContent>
+ *                       &lt;/complexType>
+ *                     &lt;/element>
+ *                     &lt;element name="pcaData" type="{www.jalview.org}PcaDataType"/>
+ *                   &lt;/sequence>
+ *                   &lt;attGroup ref="{www.jalview.org}swingwindow"/>
+ *                   &lt;attGroup ref="{www.jalview.org}SimilarityParams"/>
+ *                   &lt;attribute name="title" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *                   &lt;attribute name="scoreModelName" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *                   &lt;attribute name="xDim" type="{http://www.w3.org/2001/XMLSchema}int" />
+ *                   &lt;attribute name="yDim" type="{http://www.w3.org/2001/XMLSchema}int" />
+ *                   &lt;attribute name="zDim" type="{http://www.w3.org/2001/XMLSchema}int" />
+ *                   &lt;attribute name="bgColour" type="{http://www.w3.org/2001/XMLSchema}int" />
+ *                   &lt;attribute name="scaleFactor" type="{http://www.w3.org/2001/XMLSchema}float" />
+ *                   &lt;attribute name="showLabels" type="{http://www.w3.org/2001/XMLSchema}boolean" />
+ *                   &lt;attribute name="linkToAllViews" type="{http://www.w3.org/2001/XMLSchema}boolean" />
  *                 &lt;/restriction>
  *               &lt;/complexContent>
  *             &lt;/complexType>
@@ -310,6 +370,7 @@ import javax.xml.datatype.XMLGregorianCalendar;
     "viewport",
     "userColours",
     "tree",
+    "pcaViewer",
     "featureSettings"
 })
 public class JalviewModel {
@@ -330,6 +391,8 @@ public class JalviewModel {
     @XmlElement(name = "UserColours")
     protected List<JalviewModel.UserColours> userColours;
     protected List<JalviewModel.Tree> tree;
+    @XmlElement(name = "PcaViewer")
+    protected List<JalviewModel.PcaViewer> pcaViewer;
     @XmlElement(name = "FeatureSettings")
     protected JalviewModel.FeatureSettings featureSettings;
 
@@ -551,6 +614,35 @@ public class JalviewModel {
     }
 
     /**
+     * Gets the value of the pcaViewer property.
+     * 
+     * <p>
+     * This accessor method returns a reference to the live list,
+     * not a snapshot. Therefore any modification you make to the
+     * returned list will be present inside the JAXB object.
+     * This is why there is not a <CODE>set</CODE> method for the pcaViewer property.
+     * 
+     * <p>
+     * For example, to add a new item, do as follows:
+     * <pre>
+     *    getPcaViewer().add(newItem);
+     * </pre>
+     * 
+     * 
+     * <p>
+     * Objects of the following type(s) are allowed in the list
+     * {@link JalviewModel.PcaViewer }
+     * 
+     * 
+     */
+    public List<JalviewModel.PcaViewer> getPcaViewer() {
+        if (pcaViewer == null) {
+            pcaViewer = new ArrayList<JalviewModel.PcaViewer>();
+        }
+        return this.pcaViewer;
+    }
+
+    /**
      * Gets the value of the featureSettings property.
      * 
      * @return
@@ -2974,21 +3066,57 @@ public class JalviewModel {
      * &lt;complexType>
      *   &lt;complexContent>
      *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
-     *       &lt;sequence minOccurs="0">
-     *         &lt;element name="title" type="{http://www.w3.org/2001/XMLSchema}string"/>
-     *         &lt;element name="newick" type="{http://www.w3.org/2001/XMLSchema}string"/>
+     *       &lt;sequence>
+     *         &lt;element name="sequencePoint" maxOccurs="unbounded">
+     *           &lt;complexType>
+     *             &lt;complexContent>
+     *               &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+     *                 &lt;attGroup ref="{www.jalview.org}position"/>
+     *                 &lt;attribute name="sequenceRef" type="{http://www.w3.org/2001/XMLSchema}string" />
+     *               &lt;/restriction>
+     *             &lt;/complexContent>
+     *           &lt;/complexType>
+     *         &lt;/element>
+     *         &lt;element name="axis" maxOccurs="3" minOccurs="3">
+     *           &lt;complexType>
+     *             &lt;complexContent>
+     *               &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+     *                 &lt;attGroup ref="{www.jalview.org}position"/>
+     *               &lt;/restriction>
+     *             &lt;/complexContent>
+     *           &lt;/complexType>
+     *         &lt;/element>
+     *         &lt;element name="seqPointMin">
+     *           &lt;complexType>
+     *             &lt;complexContent>
+     *               &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+     *                 &lt;attGroup ref="{www.jalview.org}position"/>
+     *               &lt;/restriction>
+     *             &lt;/complexContent>
+     *           &lt;/complexType>
+     *         &lt;/element>
+     *         &lt;element name="seqPointMax">
+     *           &lt;complexType>
+     *             &lt;complexContent>
+     *               &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+     *                 &lt;attGroup ref="{www.jalview.org}position"/>
+     *               &lt;/restriction>
+     *             &lt;/complexContent>
+     *           &lt;/complexType>
+     *         &lt;/element>
+     *         &lt;element name="pcaData" type="{www.jalview.org}PcaDataType"/>
      *       &lt;/sequence>
      *       &lt;attGroup ref="{www.jalview.org}swingwindow"/>
-     *       &lt;attribute name="fontName" type="{http://www.w3.org/2001/XMLSchema}string" />
-     *       &lt;attribute name="fontSize" type="{http://www.w3.org/2001/XMLSchema}int" />
-     *       &lt;attribute name="fontStyle" type="{http://www.w3.org/2001/XMLSchema}int" />
-     *       &lt;attribute name="threshold" type="{http://www.w3.org/2001/XMLSchema}float" />
-     *       &lt;attribute name="showBootstrap" type="{http://www.w3.org/2001/XMLSchema}boolean" />
-     *       &lt;attribute name="showDistances" type="{http://www.w3.org/2001/XMLSchema}boolean" />
-     *       &lt;attribute name="markUnlinked" type="{http://www.w3.org/2001/XMLSchema}boolean" />
-     *       &lt;attribute name="fitToWindow" type="{http://www.w3.org/2001/XMLSchema}boolean" />
-     *       &lt;attribute name="currentTree" type="{http://www.w3.org/2001/XMLSchema}boolean" />
-     *       &lt;attribute name="id" type="{http://www.w3.org/2001/XMLSchema}ID" />
+     *       &lt;attGroup ref="{www.jalview.org}SimilarityParams"/>
+     *       &lt;attribute name="title" type="{http://www.w3.org/2001/XMLSchema}string" />
+     *       &lt;attribute name="scoreModelName" type="{http://www.w3.org/2001/XMLSchema}string" />
+     *       &lt;attribute name="xDim" type="{http://www.w3.org/2001/XMLSchema}int" />
+     *       &lt;attribute name="yDim" type="{http://www.w3.org/2001/XMLSchema}int" />
+     *       &lt;attribute name="zDim" type="{http://www.w3.org/2001/XMLSchema}int" />
+     *       &lt;attribute name="bgColour" type="{http://www.w3.org/2001/XMLSchema}int" />
+     *       &lt;attribute name="scaleFactor" type="{http://www.w3.org/2001/XMLSchema}float" />
+     *       &lt;attribute name="showLabels" type="{http://www.w3.org/2001/XMLSchema}boolean" />
+     *       &lt;attribute name="linkToAllViews" type="{http://www.w3.org/2001/XMLSchema}boolean" />
      *     &lt;/restriction>
      *   &lt;/complexContent>
      * &lt;/complexType>
@@ -2998,38 +3126,42 @@ public class JalviewModel {
      */
     @XmlAccessorType(XmlAccessType.FIELD)
     @XmlType(name = "", propOrder = {
-        "title",
-        "newick"
+        "sequencePoint",
+        "axis",
+        "seqPointMin",
+        "seqPointMax",
+        "pcaData"
     })
-    public static class Tree {
+    public static class PcaViewer {
 
-        @XmlElement(namespace = "www.jalview.org")
+        @XmlElement(namespace = "www.jalview.org", required = true)
+        protected List<JalviewModel.PcaViewer.SequencePoint> sequencePoint;
+        @XmlElement(namespace = "www.jalview.org", required = true)
+        protected List<JalviewModel.PcaViewer.Axis> axis;
+        @XmlElement(namespace = "www.jalview.org", required = true)
+        protected JalviewModel.PcaViewer.SeqPointMin seqPointMin;
+        @XmlElement(namespace = "www.jalview.org", required = true)
+        protected JalviewModel.PcaViewer.SeqPointMax seqPointMax;
+        @XmlElement(namespace = "www.jalview.org", required = true)
+        protected PcaDataType pcaData;
+        @XmlAttribute(name = "title")
         protected String title;
-        @XmlElement(namespace = "www.jalview.org")
-        protected String newick;
-        @XmlAttribute(name = "fontName")
-        protected String fontName;
-        @XmlAttribute(name = "fontSize")
-        protected Integer fontSize;
-        @XmlAttribute(name = "fontStyle")
-        protected Integer fontStyle;
-        @XmlAttribute(name = "threshold")
-        protected Float threshold;
-        @XmlAttribute(name = "showBootstrap")
-        protected Boolean showBootstrap;
-        @XmlAttribute(name = "showDistances")
-        protected Boolean showDistances;
-        @XmlAttribute(name = "markUnlinked")
-        protected Boolean markUnlinked;
-        @XmlAttribute(name = "fitToWindow")
-        protected Boolean fitToWindow;
-        @XmlAttribute(name = "currentTree")
-        protected Boolean currentTree;
-        @XmlAttribute(name = "id")
-        @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
-        @XmlID
-        @XmlSchemaType(name = "ID")
-        protected String id;
+        @XmlAttribute(name = "scoreModelName")
+        protected String scoreModelName;
+        @XmlAttribute(name = "xDim")
+        protected Integer xDim;
+        @XmlAttribute(name = "yDim")
+        protected Integer yDim;
+        @XmlAttribute(name = "zDim")
+        protected Integer zDim;
+        @XmlAttribute(name = "bgColour")
+        protected Integer bgColour;
+        @XmlAttribute(name = "scaleFactor")
+        protected Float scaleFactor;
+        @XmlAttribute(name = "showLabels")
+        protected Boolean showLabels;
+        @XmlAttribute(name = "linkToAllViews")
+        protected Boolean linkToAllViews;
         @XmlAttribute(name = "width")
         protected Integer width;
         @XmlAttribute(name = "height")
@@ -3038,201 +3170,1266 @@ public class JalviewModel {
         protected Integer xpos;
         @XmlAttribute(name = "ypos")
         protected Integer ypos;
+        @XmlAttribute(name = "includeGaps")
+        protected Boolean includeGaps;
+        @XmlAttribute(name = "matchGaps")
+        protected Boolean matchGaps;
+        @XmlAttribute(name = "includeGappedColumns")
+        protected Boolean includeGappedColumns;
+        @XmlAttribute(name = "denominateByShortestLength")
+        protected Boolean denominateByShortestLength;
 
         /**
-         * Gets the value of the title property.
+         * Gets the value of the sequencePoint property.
+         * 
+         * <p>
+         * This accessor method returns a reference to the live list,
+         * not a snapshot. Therefore any modification you make to the
+         * returned list will be present inside the JAXB object.
+         * This is why there is not a <CODE>set</CODE> method for the sequencePoint property.
+         * 
+         * <p>
+         * For example, to add a new item, do as follows:
+         * <pre>
+         *    getSequencePoint().add(newItem);
+         * </pre>
+         * 
+         * 
+         * <p>
+         * Objects of the following type(s) are allowed in the list
+         * {@link JalviewModel.PcaViewer.SequencePoint }
+         * 
          * 
-         * @return
-         *     possible object is
-         *     {@link String }
-         *     
          */
-        public String getTitle() {
-            return title;
+        public List<JalviewModel.PcaViewer.SequencePoint> getSequencePoint() {
+            if (sequencePoint == null) {
+                sequencePoint = new ArrayList<JalviewModel.PcaViewer.SequencePoint>();
+            }
+            return this.sequencePoint;
         }
 
         /**
-         * Sets the value of the title property.
+         * Gets the value of the axis property.
+         * 
+         * <p>
+         * This accessor method returns a reference to the live list,
+         * not a snapshot. Therefore any modification you make to the
+         * returned list will be present inside the JAXB object.
+         * This is why there is not a <CODE>set</CODE> method for the axis property.
+         * 
+         * <p>
+         * For example, to add a new item, do as follows:
+         * <pre>
+         *    getAxis().add(newItem);
+         * </pre>
+         * 
+         * 
+         * <p>
+         * Objects of the following type(s) are allowed in the list
+         * {@link JalviewModel.PcaViewer.Axis }
+         * 
          * 
-         * @param value
-         *     allowed object is
-         *     {@link String }
-         *     
          */
-        public void setTitle(String value) {
-            this.title = value;
+        public List<JalviewModel.PcaViewer.Axis> getAxis() {
+            if (axis == null) {
+                axis = new ArrayList<JalviewModel.PcaViewer.Axis>();
+            }
+            return this.axis;
         }
 
         /**
-         * Gets the value of the newick property.
+         * Gets the value of the seqPointMin property.
          * 
          * @return
          *     possible object is
-         *     {@link String }
+         *     {@link JalviewModel.PcaViewer.SeqPointMin }
          *     
          */
-        public String getNewick() {
-            return newick;
+        public JalviewModel.PcaViewer.SeqPointMin getSeqPointMin() {
+            return seqPointMin;
         }
 
         /**
-         * Sets the value of the newick property.
+         * Sets the value of the seqPointMin property.
          * 
          * @param value
          *     allowed object is
-         *     {@link String }
+         *     {@link JalviewModel.PcaViewer.SeqPointMin }
          *     
          */
-        public void setNewick(String value) {
-            this.newick = value;
+        public void setSeqPointMin(JalviewModel.PcaViewer.SeqPointMin value) {
+            this.seqPointMin = value;
         }
 
         /**
-         * Gets the value of the fontName property.
+         * Gets the value of the seqPointMax property.
          * 
          * @return
          *     possible object is
-         *     {@link String }
+         *     {@link JalviewModel.PcaViewer.SeqPointMax }
          *     
          */
-        public String getFontName() {
-            return fontName;
+        public JalviewModel.PcaViewer.SeqPointMax getSeqPointMax() {
+            return seqPointMax;
         }
 
         /**
-         * Sets the value of the fontName property.
+         * Sets the value of the seqPointMax property.
          * 
          * @param value
          *     allowed object is
-         *     {@link String }
+         *     {@link JalviewModel.PcaViewer.SeqPointMax }
          *     
          */
-        public void setFontName(String value) {
-            this.fontName = value;
+        public void setSeqPointMax(JalviewModel.PcaViewer.SeqPointMax value) {
+            this.seqPointMax = value;
         }
 
         /**
-         * Gets the value of the fontSize property.
+         * Gets the value of the pcaData property.
          * 
          * @return
          *     possible object is
-         *     {@link Integer }
+         *     {@link PcaDataType }
          *     
          */
-        public Integer getFontSize() {
-            return fontSize;
+        public PcaDataType getPcaData() {
+            return pcaData;
         }
 
         /**
-         * Sets the value of the fontSize property.
+         * Sets the value of the pcaData property.
          * 
          * @param value
          *     allowed object is
-         *     {@link Integer }
+         *     {@link PcaDataType }
          *     
          */
-        public void setFontSize(Integer value) {
-            this.fontSize = value;
+        public void setPcaData(PcaDataType value) {
+            this.pcaData = value;
         }
 
         /**
-         * Gets the value of the fontStyle property.
+         * Gets the value of the title property.
          * 
          * @return
          *     possible object is
-         *     {@link Integer }
+         *     {@link String }
          *     
          */
-        public Integer getFontStyle() {
-            return fontStyle;
+        public String getTitle() {
+            return title;
         }
 
         /**
-         * Sets the value of the fontStyle property.
+         * Sets the value of the title property.
          * 
          * @param value
          *     allowed object is
-         *     {@link Integer }
+         *     {@link String }
          *     
          */
-        public void setFontStyle(Integer value) {
-            this.fontStyle = value;
+        public void setTitle(String value) {
+            this.title = value;
         }
 
         /**
-         * Gets the value of the threshold property.
+         * Gets the value of the scoreModelName property.
          * 
          * @return
          *     possible object is
-         *     {@link Float }
+         *     {@link String }
          *     
          */
-        public Float getThreshold() {
-            return threshold;
+        public String getScoreModelName() {
+            return scoreModelName;
         }
 
         /**
-         * Sets the value of the threshold property.
+         * Sets the value of the scoreModelName property.
          * 
          * @param value
          *     allowed object is
-         *     {@link Float }
+         *     {@link String }
          *     
          */
-        public void setThreshold(Float value) {
-            this.threshold = value;
+        public void setScoreModelName(String value) {
+            this.scoreModelName = value;
         }
 
         /**
-         * Gets the value of the showBootstrap property.
+         * Gets the value of the xDim property.
          * 
          * @return
          *     possible object is
-         *     {@link Boolean }
+         *     {@link Integer }
          *     
          */
-        public Boolean isShowBootstrap() {
-            return showBootstrap;
+        public Integer getXDim() {
+            return xDim;
         }
 
         /**
-         * Sets the value of the showBootstrap property.
+         * Sets the value of the xDim property.
          * 
          * @param value
          *     allowed object is
-         *     {@link Boolean }
+         *     {@link Integer }
          *     
          */
-        public void setShowBootstrap(Boolean value) {
-            this.showBootstrap = value;
+        public void setXDim(Integer value) {
+            this.xDim = value;
         }
 
         /**
-         * Gets the value of the showDistances property.
+         * Gets the value of the yDim property.
          * 
          * @return
          *     possible object is
-         *     {@link Boolean }
+         *     {@link Integer }
          *     
          */
-        public Boolean isShowDistances() {
-            return showDistances;
+        public Integer getYDim() {
+            return yDim;
         }
 
         /**
-         * Sets the value of the showDistances property.
+         * Sets the value of the yDim property.
          * 
          * @param value
          *     allowed object is
-         *     {@link Boolean }
+         *     {@link Integer }
          *     
          */
-        public void setShowDistances(Boolean value) {
-            this.showDistances = value;
+        public void setYDim(Integer value) {
+            this.yDim = value;
         }
 
         /**
-         * Gets the value of the markUnlinked property.
+         * Gets the value of the zDim property.
+         * 
+         * @return
+         *     possible object is
+         *     {@link Integer }
+         *     
+         */
+        public Integer getZDim() {
+            return zDim;
+        }
+
+        /**
+         * Sets the value of the zDim property.
+         * 
+         * @param value
+         *     allowed object is
+         *     {@link Integer }
+         *     
+         */
+        public void setZDim(Integer value) {
+            this.zDim = value;
+        }
+
+        /**
+         * Gets the value of the bgColour property.
+         * 
+         * @return
+         *     possible object is
+         *     {@link Integer }
+         *     
+         */
+        public Integer getBgColour() {
+            return bgColour;
+        }
+
+        /**
+         * Sets the value of the bgColour property.
+         * 
+         * @param value
+         *     allowed object is
+         *     {@link Integer }
+         *     
+         */
+        public void setBgColour(Integer value) {
+            this.bgColour = value;
+        }
+
+        /**
+         * Gets the value of the scaleFactor property.
+         * 
+         * @return
+         *     possible object is
+         *     {@link Float }
+         *     
+         */
+        public Float getScaleFactor() {
+            return scaleFactor;
+        }
+
+        /**
+         * Sets the value of the scaleFactor property.
+         * 
+         * @param value
+         *     allowed object is
+         *     {@link Float }
+         *     
+         */
+        public void setScaleFactor(Float value) {
+            this.scaleFactor = value;
+        }
+
+        /**
+         * Gets the value of the showLabels property.
+         * 
+         * @return
+         *     possible object is
+         *     {@link Boolean }
+         *     
+         */
+        public Boolean isShowLabels() {
+            return showLabels;
+        }
+
+        /**
+         * Sets the value of the showLabels property.
+         * 
+         * @param value
+         *     allowed object is
+         *     {@link Boolean }
+         *     
+         */
+        public void setShowLabels(Boolean value) {
+            this.showLabels = value;
+        }
+
+        /**
+         * Gets the value of the linkToAllViews property.
+         * 
+         * @return
+         *     possible object is
+         *     {@link Boolean }
+         *     
+         */
+        public Boolean isLinkToAllViews() {
+            return linkToAllViews;
+        }
+
+        /**
+         * Sets the value of the linkToAllViews property.
+         * 
+         * @param value
+         *     allowed object is
+         *     {@link Boolean }
+         *     
+         */
+        public void setLinkToAllViews(Boolean value) {
+            this.linkToAllViews = value;
+        }
+
+        /**
+         * Gets the value of the width property.
+         * 
+         * @return
+         *     possible object is
+         *     {@link Integer }
+         *     
+         */
+        public Integer getWidth() {
+            return width;
+        }
+
+        /**
+         * Sets the value of the width property.
+         * 
+         * @param value
+         *     allowed object is
+         *     {@link Integer }
+         *     
+         */
+        public void setWidth(Integer value) {
+            this.width = value;
+        }
+
+        /**
+         * Gets the value of the height property.
+         * 
+         * @return
+         *     possible object is
+         *     {@link Integer }
+         *     
+         */
+        public Integer getHeight() {
+            return height;
+        }
+
+        /**
+         * Sets the value of the height property.
+         * 
+         * @param value
+         *     allowed object is
+         *     {@link Integer }
+         *     
+         */
+        public void setHeight(Integer value) {
+            this.height = value;
+        }
+
+        /**
+         * Gets the value of the xpos property.
+         * 
+         * @return
+         *     possible object is
+         *     {@link Integer }
+         *     
+         */
+        public Integer getXpos() {
+            return xpos;
+        }
+
+        /**
+         * Sets the value of the xpos property.
+         * 
+         * @param value
+         *     allowed object is
+         *     {@link Integer }
+         *     
+         */
+        public void setXpos(Integer value) {
+            this.xpos = value;
+        }
+
+        /**
+         * Gets the value of the ypos property.
+         * 
+         * @return
+         *     possible object is
+         *     {@link Integer }
+         *     
+         */
+        public Integer getYpos() {
+            return ypos;
+        }
+
+        /**
+         * Sets the value of the ypos property.
+         * 
+         * @param value
+         *     allowed object is
+         *     {@link Integer }
+         *     
+         */
+        public void setYpos(Integer value) {
+            this.ypos = value;
+        }
+
+        /**
+         * Gets the value of the includeGaps property.
+         * 
+         * @return
+         *     possible object is
+         *     {@link Boolean }
+         *     
+         */
+        public Boolean isIncludeGaps() {
+            return includeGaps;
+        }
+
+        /**
+         * Sets the value of the includeGaps property.
+         * 
+         * @param value
+         *     allowed object is
+         *     {@link Boolean }
+         *     
+         */
+        public void setIncludeGaps(Boolean value) {
+            this.includeGaps = value;
+        }
+
+        /**
+         * Gets the value of the matchGaps property.
+         * 
+         * @return
+         *     possible object is
+         *     {@link Boolean }
+         *     
+         */
+        public Boolean isMatchGaps() {
+            return matchGaps;
+        }
+
+        /**
+         * Sets the value of the matchGaps property.
+         * 
+         * @param value
+         *     allowed object is
+         *     {@link Boolean }
+         *     
+         */
+        public void setMatchGaps(Boolean value) {
+            this.matchGaps = value;
+        }
+
+        /**
+         * Gets the value of the includeGappedColumns property.
+         * 
+         * @return
+         *     possible object is
+         *     {@link Boolean }
+         *     
+         */
+        public Boolean isIncludeGappedColumns() {
+            return includeGappedColumns;
+        }
+
+        /**
+         * Sets the value of the includeGappedColumns property.
+         * 
+         * @param value
+         *     allowed object is
+         *     {@link Boolean }
+         *     
+         */
+        public void setIncludeGappedColumns(Boolean value) {
+            this.includeGappedColumns = value;
+        }
+
+        /**
+         * Gets the value of the denominateByShortestLength property.
+         * 
+         * @return
+         *     possible object is
+         *     {@link Boolean }
+         *     
+         */
+        public Boolean isDenominateByShortestLength() {
+            return denominateByShortestLength;
+        }
+
+        /**
+         * Sets the value of the denominateByShortestLength property.
+         * 
+         * @param value
+         *     allowed object is
+         *     {@link Boolean }
+         *     
+         */
+        public void setDenominateByShortestLength(Boolean value) {
+            this.denominateByShortestLength = value;
+        }
+
+
+        /**
+         * <p>Java class for anonymous complex type.
+         * 
+         * <p>The following schema fragment specifies the expected content contained within this class.
+         * 
+         * <pre>
+         * &lt;complexType>
+         *   &lt;complexContent>
+         *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+         *       &lt;attGroup ref="{www.jalview.org}position"/>
+         *     &lt;/restriction>
+         *   &lt;/complexContent>
+         * &lt;/complexType>
+         * </pre>
+         * 
+         * 
+         */
+        @XmlAccessorType(XmlAccessType.FIELD)
+        @XmlType(name = "")
+        public static class Axis {
+
+            @XmlAttribute(name = "xPos")
+            protected Float xPos;
+            @XmlAttribute(name = "yPos")
+            protected Float yPos;
+            @XmlAttribute(name = "zPos")
+            protected Float zPos;
+
+            /**
+             * Gets the value of the xPos property.
+             * 
+             * @return
+             *     possible object is
+             *     {@link Float }
+             *     
+             */
+            public Float getXPos() {
+                return xPos;
+            }
+
+            /**
+             * Sets the value of the xPos property.
+             * 
+             * @param value
+             *     allowed object is
+             *     {@link Float }
+             *     
+             */
+            public void setXPos(Float value) {
+                this.xPos = value;
+            }
+
+            /**
+             * Gets the value of the yPos property.
+             * 
+             * @return
+             *     possible object is
+             *     {@link Float }
+             *     
+             */
+            public Float getYPos() {
+                return yPos;
+            }
+
+            /**
+             * Sets the value of the yPos property.
+             * 
+             * @param value
+             *     allowed object is
+             *     {@link Float }
+             *     
+             */
+            public void setYPos(Float value) {
+                this.yPos = value;
+            }
+
+            /**
+             * Gets the value of the zPos property.
+             * 
+             * @return
+             *     possible object is
+             *     {@link Float }
+             *     
+             */
+            public Float getZPos() {
+                return zPos;
+            }
+
+            /**
+             * Sets the value of the zPos property.
+             * 
+             * @param value
+             *     allowed object is
+             *     {@link Float }
+             *     
+             */
+            public void setZPos(Float value) {
+                this.zPos = value;
+            }
+
+        }
+
+
+        /**
+         * <p>Java class for anonymous complex type.
+         * 
+         * <p>The following schema fragment specifies the expected content contained within this class.
+         * 
+         * <pre>
+         * &lt;complexType>
+         *   &lt;complexContent>
+         *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+         *       &lt;attGroup ref="{www.jalview.org}position"/>
+         *     &lt;/restriction>
+         *   &lt;/complexContent>
+         * &lt;/complexType>
+         * </pre>
+         * 
+         * 
+         */
+        @XmlAccessorType(XmlAccessType.FIELD)
+        @XmlType(name = "")
+        public static class SeqPointMax {
+
+            @XmlAttribute(name = "xPos")
+            protected Float xPos;
+            @XmlAttribute(name = "yPos")
+            protected Float yPos;
+            @XmlAttribute(name = "zPos")
+            protected Float zPos;
+
+            /**
+             * Gets the value of the xPos property.
+             * 
+             * @return
+             *     possible object is
+             *     {@link Float }
+             *     
+             */
+            public Float getXPos() {
+                return xPos;
+            }
+
+            /**
+             * Sets the value of the xPos property.
+             * 
+             * @param value
+             *     allowed object is
+             *     {@link Float }
+             *     
+             */
+            public void setXPos(Float value) {
+                this.xPos = value;
+            }
+
+            /**
+             * Gets the value of the yPos property.
+             * 
+             * @return
+             *     possible object is
+             *     {@link Float }
+             *     
+             */
+            public Float getYPos() {
+                return yPos;
+            }
+
+            /**
+             * Sets the value of the yPos property.
+             * 
+             * @param value
+             *     allowed object is
+             *     {@link Float }
+             *     
+             */
+            public void setYPos(Float value) {
+                this.yPos = value;
+            }
+
+            /**
+             * Gets the value of the zPos property.
+             * 
+             * @return
+             *     possible object is
+             *     {@link Float }
+             *     
+             */
+            public Float getZPos() {
+                return zPos;
+            }
+
+            /**
+             * Sets the value of the zPos property.
+             * 
+             * @param value
+             *     allowed object is
+             *     {@link Float }
+             *     
+             */
+            public void setZPos(Float value) {
+                this.zPos = value;
+            }
+
+        }
+
+
+        /**
+         * <p>Java class for anonymous complex type.
+         * 
+         * <p>The following schema fragment specifies the expected content contained within this class.
+         * 
+         * <pre>
+         * &lt;complexType>
+         *   &lt;complexContent>
+         *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+         *       &lt;attGroup ref="{www.jalview.org}position"/>
+         *     &lt;/restriction>
+         *   &lt;/complexContent>
+         * &lt;/complexType>
+         * </pre>
+         * 
+         * 
+         */
+        @XmlAccessorType(XmlAccessType.FIELD)
+        @XmlType(name = "")
+        public static class SeqPointMin {
+
+            @XmlAttribute(name = "xPos")
+            protected Float xPos;
+            @XmlAttribute(name = "yPos")
+            protected Float yPos;
+            @XmlAttribute(name = "zPos")
+            protected Float zPos;
+
+            /**
+             * Gets the value of the xPos property.
+             * 
+             * @return
+             *     possible object is
+             *     {@link Float }
+             *     
+             */
+            public Float getXPos() {
+                return xPos;
+            }
+
+            /**
+             * Sets the value of the xPos property.
+             * 
+             * @param value
+             *     allowed object is
+             *     {@link Float }
+             *     
+             */
+            public void setXPos(Float value) {
+                this.xPos = value;
+            }
+
+            /**
+             * Gets the value of the yPos property.
+             * 
+             * @return
+             *     possible object is
+             *     {@link Float }
+             *     
+             */
+            public Float getYPos() {
+                return yPos;
+            }
+
+            /**
+             * Sets the value of the yPos property.
+             * 
+             * @param value
+             *     allowed object is
+             *     {@link Float }
+             *     
+             */
+            public void setYPos(Float value) {
+                this.yPos = value;
+            }
+
+            /**
+             * Gets the value of the zPos property.
+             * 
+             * @return
+             *     possible object is
+             *     {@link Float }
+             *     
+             */
+            public Float getZPos() {
+                return zPos;
+            }
+
+            /**
+             * Sets the value of the zPos property.
+             * 
+             * @param value
+             *     allowed object is
+             *     {@link Float }
+             *     
+             */
+            public void setZPos(Float value) {
+                this.zPos = value;
+            }
+
+        }
+
+
+        /**
+         * <p>Java class for anonymous complex type.
+         * 
+         * <p>The following schema fragment specifies the expected content contained within this class.
+         * 
+         * <pre>
+         * &lt;complexType>
+         *   &lt;complexContent>
+         *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+         *       &lt;attGroup ref="{www.jalview.org}position"/>
+         *       &lt;attribute name="sequenceRef" type="{http://www.w3.org/2001/XMLSchema}string" />
+         *     &lt;/restriction>
+         *   &lt;/complexContent>
+         * &lt;/complexType>
+         * </pre>
+         * 
+         * 
+         */
+        @XmlAccessorType(XmlAccessType.FIELD)
+        @XmlType(name = "")
+        public static class SequencePoint {
+
+            @XmlAttribute(name = "sequenceRef")
+            protected String sequenceRef;
+            @XmlAttribute(name = "xPos")
+            protected Float xPos;
+            @XmlAttribute(name = "yPos")
+            protected Float yPos;
+            @XmlAttribute(name = "zPos")
+            protected Float zPos;
+
+            /**
+             * Gets the value of the sequenceRef property.
+             * 
+             * @return
+             *     possible object is
+             *     {@link String }
+             *     
+             */
+            public String getSequenceRef() {
+                return sequenceRef;
+            }
+
+            /**
+             * Sets the value of the sequenceRef property.
+             * 
+             * @param value
+             *     allowed object is
+             *     {@link String }
+             *     
+             */
+            public void setSequenceRef(String value) {
+                this.sequenceRef = value;
+            }
+
+            /**
+             * Gets the value of the xPos property.
+             * 
+             * @return
+             *     possible object is
+             *     {@link Float }
+             *     
+             */
+            public Float getXPos() {
+                return xPos;
+            }
+
+            /**
+             * Sets the value of the xPos property.
+             * 
+             * @param value
+             *     allowed object is
+             *     {@link Float }
+             *     
+             */
+            public void setXPos(Float value) {
+                this.xPos = value;
+            }
+
+            /**
+             * Gets the value of the yPos property.
+             * 
+             * @return
+             *     possible object is
+             *     {@link Float }
+             *     
+             */
+            public Float getYPos() {
+                return yPos;
+            }
+
+            /**
+             * Sets the value of the yPos property.
+             * 
+             * @param value
+             *     allowed object is
+             *     {@link Float }
+             *     
+             */
+            public void setYPos(Float value) {
+                this.yPos = value;
+            }
+
+            /**
+             * Gets the value of the zPos property.
+             * 
+             * @return
+             *     possible object is
+             *     {@link Float }
+             *     
+             */
+            public Float getZPos() {
+                return zPos;
+            }
+
+            /**
+             * Sets the value of the zPos property.
+             * 
+             * @param value
+             *     allowed object is
+             *     {@link Float }
+             *     
+             */
+            public void setZPos(Float value) {
+                this.zPos = value;
+            }
+
+        }
+
+    }
+
+
+    /**
+     * <p>Java class for anonymous complex type.
+     * 
+     * <p>The following schema fragment specifies the expected content contained within this class.
+     * 
+     * <pre>
+     * &lt;complexType>
+     *   &lt;complexContent>
+     *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+     *       &lt;sequence minOccurs="0">
+     *         &lt;element name="title" type="{http://www.w3.org/2001/XMLSchema}string"/>
+     *         &lt;element name="newick" type="{http://www.w3.org/2001/XMLSchema}string"/>
+     *       &lt;/sequence>
+     *       &lt;attGroup ref="{www.jalview.org}swingwindow"/>
+     *       &lt;attribute name="fontName" type="{http://www.w3.org/2001/XMLSchema}string" />
+     *       &lt;attribute name="fontSize" type="{http://www.w3.org/2001/XMLSchema}int" />
+     *       &lt;attribute name="fontStyle" type="{http://www.w3.org/2001/XMLSchema}int" />
+     *       &lt;attribute name="threshold" type="{http://www.w3.org/2001/XMLSchema}float" />
+     *       &lt;attribute name="showBootstrap" type="{http://www.w3.org/2001/XMLSchema}boolean" />
+     *       &lt;attribute name="showDistances" type="{http://www.w3.org/2001/XMLSchema}boolean" />
+     *       &lt;attribute name="markUnlinked" type="{http://www.w3.org/2001/XMLSchema}boolean" />
+     *       &lt;attribute name="fitToWindow" type="{http://www.w3.org/2001/XMLSchema}boolean" />
+     *       &lt;attribute name="currentTree" type="{http://www.w3.org/2001/XMLSchema}boolean" />
+     *       &lt;attribute name="id" type="{http://www.w3.org/2001/XMLSchema}ID" />
+     *       &lt;attribute name="linkToAllViews" type="{http://www.w3.org/2001/XMLSchema}boolean" default="false" />
+     *     &lt;/restriction>
+     *   &lt;/complexContent>
+     * &lt;/complexType>
+     * </pre>
+     * 
+     * 
+     */
+    @XmlAccessorType(XmlAccessType.FIELD)
+    @XmlType(name = "", propOrder = {
+        "title",
+        "newick"
+    })
+    public static class Tree {
+
+        @XmlElement(namespace = "www.jalview.org")
+        protected String title;
+        @XmlElement(namespace = "www.jalview.org")
+        protected String newick;
+        @XmlAttribute(name = "fontName")
+        protected String fontName;
+        @XmlAttribute(name = "fontSize")
+        protected Integer fontSize;
+        @XmlAttribute(name = "fontStyle")
+        protected Integer fontStyle;
+        @XmlAttribute(name = "threshold")
+        protected Float threshold;
+        @XmlAttribute(name = "showBootstrap")
+        protected Boolean showBootstrap;
+        @XmlAttribute(name = "showDistances")
+        protected Boolean showDistances;
+        @XmlAttribute(name = "markUnlinked")
+        protected Boolean markUnlinked;
+        @XmlAttribute(name = "fitToWindow")
+        protected Boolean fitToWindow;
+        @XmlAttribute(name = "currentTree")
+        protected Boolean currentTree;
+        @XmlAttribute(name = "id")
+        @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
+        @XmlID
+        @XmlSchemaType(name = "ID")
+        protected String id;
+        @XmlAttribute(name = "linkToAllViews")
+        protected Boolean linkToAllViews;
+        @XmlAttribute(name = "width")
+        protected Integer width;
+        @XmlAttribute(name = "height")
+        protected Integer height;
+        @XmlAttribute(name = "xpos")
+        protected Integer xpos;
+        @XmlAttribute(name = "ypos")
+        protected Integer ypos;
+
+        /**
+         * Gets the value of the title property.
+         * 
+         * @return
+         *     possible object is
+         *     {@link String }
+         *     
+         */
+        public String getTitle() {
+            return title;
+        }
+
+        /**
+         * Sets the value of the title property.
+         * 
+         * @param value
+         *     allowed object is
+         *     {@link String }
+         *     
+         */
+        public void setTitle(String value) {
+            this.title = value;
+        }
+
+        /**
+         * Gets the value of the newick property.
+         * 
+         * @return
+         *     possible object is
+         *     {@link String }
+         *     
+         */
+        public String getNewick() {
+            return newick;
+        }
+
+        /**
+         * Sets the value of the newick property.
+         * 
+         * @param value
+         *     allowed object is
+         *     {@link String }
+         *     
+         */
+        public void setNewick(String value) {
+            this.newick = value;
+        }
+
+        /**
+         * Gets the value of the fontName property.
+         * 
+         * @return
+         *     possible object is
+         *     {@link String }
+         *     
+         */
+        public String getFontName() {
+            return fontName;
+        }
+
+        /**
+         * Sets the value of the fontName property.
+         * 
+         * @param value
+         *     allowed object is
+         *     {@link String }
+         *     
+         */
+        public void setFontName(String value) {
+            this.fontName = value;
+        }
+
+        /**
+         * Gets the value of the fontSize property.
+         * 
+         * @return
+         *     possible object is
+         *     {@link Integer }
+         *     
+         */
+        public Integer getFontSize() {
+            return fontSize;
+        }
+
+        /**
+         * Sets the value of the fontSize property.
+         * 
+         * @param value
+         *     allowed object is
+         *     {@link Integer }
+         *     
+         */
+        public void setFontSize(Integer value) {
+            this.fontSize = value;
+        }
+
+        /**
+         * Gets the value of the fontStyle property.
+         * 
+         * @return
+         *     possible object is
+         *     {@link Integer }
+         *     
+         */
+        public Integer getFontStyle() {
+            return fontStyle;
+        }
+
+        /**
+         * Sets the value of the fontStyle property.
+         * 
+         * @param value
+         *     allowed object is
+         *     {@link Integer }
+         *     
+         */
+        public void setFontStyle(Integer value) {
+            this.fontStyle = value;
+        }
+
+        /**
+         * Gets the value of the threshold property.
+         * 
+         * @return
+         *     possible object is
+         *     {@link Float }
+         *     
+         */
+        public Float getThreshold() {
+            return threshold;
+        }
+
+        /**
+         * Sets the value of the threshold property.
+         * 
+         * @param value
+         *     allowed object is
+         *     {@link Float }
+         *     
+         */
+        public void setThreshold(Float value) {
+            this.threshold = value;
+        }
+
+        /**
+         * Gets the value of the showBootstrap property.
+         * 
+         * @return
+         *     possible object is
+         *     {@link Boolean }
+         *     
+         */
+        public Boolean isShowBootstrap() {
+            return showBootstrap;
+        }
+
+        /**
+         * Sets the value of the showBootstrap property.
+         * 
+         * @param value
+         *     allowed object is
+         *     {@link Boolean }
+         *     
+         */
+        public void setShowBootstrap(Boolean value) {
+            this.showBootstrap = value;
+        }
+
+        /**
+         * Gets the value of the showDistances property.
+         * 
+         * @return
+         *     possible object is
+         *     {@link Boolean }
+         *     
+         */
+        public Boolean isShowDistances() {
+            return showDistances;
+        }
+
+        /**
+         * Sets the value of the showDistances property.
+         * 
+         * @param value
+         *     allowed object is
+         *     {@link Boolean }
+         *     
+         */
+        public void setShowDistances(Boolean value) {
+            this.showDistances = value;
+        }
+
+        /**
+         * Gets the value of the markUnlinked property.
          * 
          * @return
          *     possible object is
@@ -3328,6 +4525,34 @@ public class JalviewModel {
         }
 
         /**
+         * Gets the value of the linkToAllViews property.
+         * 
+         * @return
+         *     possible object is
+         *     {@link Boolean }
+         *     
+         */
+        public boolean isLinkToAllViews() {
+            if (linkToAllViews == null) {
+                return false;
+            } else {
+                return linkToAllViews;
+            }
+        }
+
+        /**
+         * Sets the value of the linkToAllViews property.
+         * 
+         * @param value
+         *     allowed object is
+         *     {@link Boolean }
+         *     
+         */
+        public void setLinkToAllViews(Boolean value) {
+            this.linkToAllViews = value;
+        }
+
+        /**
          * Gets the value of the width property.
          * 
          * @return
index 0de2ac0..701647c 100644 (file)
@@ -2,7 +2,7 @@
 // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 
 // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 
 // Any modifications to this file will be lost upon recompilation of the source schema. 
-// Generated on: 2018.09.28 at 12:18:54 PM BST 
+// Generated on: 2018.12.20 at 11:47:26 AM GMT 
 //
 
 
index 345556f..3d7b5eb 100644 (file)
@@ -2,7 +2,7 @@
 // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 
 // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 
 // Any modifications to this file will be lost upon recompilation of the source schema. 
-// Generated on: 2018.09.28 at 12:18:54 PM BST 
+// Generated on: 2018.12.20 at 11:47:26 AM GMT 
 //
 
 
index cd82a2a..3cbebc0 100644 (file)
@@ -2,7 +2,7 @@
 // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 
 // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 
 // Any modifications to this file will be lost upon recompilation of the source schema. 
-// Generated on: 2018.09.28 at 12:18:54 PM BST 
+// Generated on: 2018.12.20 at 11:47:26 AM GMT 
 //
 
 
index 8fd65f0..15fc45d 100644 (file)
@@ -2,7 +2,7 @@
 // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 
 // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 
 // Any modifications to this file will be lost upon recompilation of the source schema. 
-// Generated on: 2018.09.28 at 12:18:54 PM BST 
+// Generated on: 2018.12.20 at 11:47:26 AM GMT 
 //
 
 
index 0903928..6858f07 100644 (file)
@@ -2,7 +2,7 @@
 // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 
 // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 
 // Any modifications to this file will be lost upon recompilation of the source schema. 
-// Generated on: 2018.09.28 at 12:18:54 PM BST 
+// Generated on: 2018.12.20 at 11:47:26 AM GMT 
 //
 
 
@@ -131,6 +131,14 @@ public class ObjectFactory {
     }
 
     /**
+     * Create an instance of {@link JalviewModel.PcaViewer }
+     * 
+     */
+    public JalviewModel.PcaViewer createJalviewModelPcaViewer() {
+        return new JalviewModel.PcaViewer();
+    }
+
+    /**
      * Create an instance of {@link JalviewModel.Viewport }
      * 
      */
@@ -163,6 +171,14 @@ public class ObjectFactory {
     }
 
     /**
+     * Create an instance of {@link DoubleMatrix }
+     * 
+     */
+    public DoubleMatrix createDoubleMatrix() {
+        return new DoubleMatrix();
+    }
+
+    /**
      * Create an instance of {@link AnnotationColourScheme }
      * 
      */
@@ -171,6 +187,22 @@ public class ObjectFactory {
     }
 
     /**
+     * Create an instance of {@link PcaDataType }
+     * 
+     */
+    public PcaDataType createPcaDataType() {
+        return new PcaDataType();
+    }
+
+    /**
+     * Create an instance of {@link DoubleVector }
+     * 
+     */
+    public DoubleVector createDoubleVector() {
+        return new DoubleVector();
+    }
+
+    /**
      * Create an instance of {@link AlcodonFrame.Alcodon }
      * 
      */
@@ -363,6 +395,38 @@ public class ObjectFactory {
     }
 
     /**
+     * Create an instance of {@link JalviewModel.PcaViewer.SequencePoint }
+     * 
+     */
+    public JalviewModel.PcaViewer.SequencePoint createJalviewModelPcaViewerSequencePoint() {
+        return new JalviewModel.PcaViewer.SequencePoint();
+    }
+
+    /**
+     * Create an instance of {@link JalviewModel.PcaViewer.Axis }
+     * 
+     */
+    public JalviewModel.PcaViewer.Axis createJalviewModelPcaViewerAxis() {
+        return new JalviewModel.PcaViewer.Axis();
+    }
+
+    /**
+     * Create an instance of {@link JalviewModel.PcaViewer.SeqPointMin }
+     * 
+     */
+    public JalviewModel.PcaViewer.SeqPointMin createJalviewModelPcaViewerSeqPointMin() {
+        return new JalviewModel.PcaViewer.SeqPointMin();
+    }
+
+    /**
+     * Create an instance of {@link JalviewModel.PcaViewer.SeqPointMax }
+     * 
+     */
+    public JalviewModel.PcaViewer.SeqPointMax createJalviewModelPcaViewerSeqPointMax() {
+        return new JalviewModel.PcaViewer.SeqPointMax();
+    }
+
+    /**
      * Create an instance of {@link JalviewModel.Viewport.HiddenColumns }
      * 
      */
diff --git a/src/jalview/xml/binding/jalview/PcaDataType.java b/src/jalview/xml/binding/jalview/PcaDataType.java
new file mode 100644 (file)
index 0000000..e8c7cf2
--- /dev/null
@@ -0,0 +1,129 @@
+//
+// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 
+// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 
+// Any modifications to this file will be lost upon recompilation of the source schema. 
+// Generated on: 2018.12.20 at 11:47:26 AM GMT 
+//
+
+
+package jalview.xml.binding.jalview;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlType;
+
+
+/**
+ * 
+ *                             The results of a PCA calculation
+ *                     
+ * 
+ * <p>Java class for PcaDataType complex type.
+ * 
+ * <p>The following schema fragment specifies the expected content contained within this class.
+ * 
+ * <pre>
+ * &lt;complexType name="PcaDataType">
+ *   &lt;complexContent>
+ *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       &lt;sequence>
+ *         &lt;element name="pairwiseMatrix" type="{www.jalview.org}DoubleMatrix"/>
+ *         &lt;element name="tridiagonalMatrix" type="{www.jalview.org}DoubleMatrix"/>
+ *         &lt;element name="eigenMatrix" type="{www.jalview.org}DoubleMatrix"/>
+ *       &lt;/sequence>
+ *     &lt;/restriction>
+ *   &lt;/complexContent>
+ * &lt;/complexType>
+ * </pre>
+ * 
+ * 
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "PcaDataType", namespace = "www.jalview.org", propOrder = {
+    "pairwiseMatrix",
+    "tridiagonalMatrix",
+    "eigenMatrix"
+})
+public class PcaDataType {
+
+    @XmlElement(required = true)
+    protected DoubleMatrix pairwiseMatrix;
+    @XmlElement(required = true)
+    protected DoubleMatrix tridiagonalMatrix;
+    @XmlElement(required = true)
+    protected DoubleMatrix eigenMatrix;
+
+    /**
+     * Gets the value of the pairwiseMatrix property.
+     * 
+     * @return
+     *     possible object is
+     *     {@link DoubleMatrix }
+     *     
+     */
+    public DoubleMatrix getPairwiseMatrix() {
+        return pairwiseMatrix;
+    }
+
+    /**
+     * Sets the value of the pairwiseMatrix property.
+     * 
+     * @param value
+     *     allowed object is
+     *     {@link DoubleMatrix }
+     *     
+     */
+    public void setPairwiseMatrix(DoubleMatrix value) {
+        this.pairwiseMatrix = value;
+    }
+
+    /**
+     * Gets the value of the tridiagonalMatrix property.
+     * 
+     * @return
+     *     possible object is
+     *     {@link DoubleMatrix }
+     *     
+     */
+    public DoubleMatrix getTridiagonalMatrix() {
+        return tridiagonalMatrix;
+    }
+
+    /**
+     * Sets the value of the tridiagonalMatrix property.
+     * 
+     * @param value
+     *     allowed object is
+     *     {@link DoubleMatrix }
+     *     
+     */
+    public void setTridiagonalMatrix(DoubleMatrix value) {
+        this.tridiagonalMatrix = value;
+    }
+
+    /**
+     * Gets the value of the eigenMatrix property.
+     * 
+     * @return
+     *     possible object is
+     *     {@link DoubleMatrix }
+     *     
+     */
+    public DoubleMatrix getEigenMatrix() {
+        return eigenMatrix;
+    }
+
+    /**
+     * Sets the value of the eigenMatrix property.
+     * 
+     * @param value
+     *     allowed object is
+     *     {@link DoubleMatrix }
+     *     
+     */
+    public void setEigenMatrix(DoubleMatrix value) {
+        this.eigenMatrix = value;
+    }
+
+}
index 4accccd..843ea6c 100644 (file)
@@ -2,7 +2,7 @@
 // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 
 // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 
 // Any modifications to this file will be lost upon recompilation of the source schema. 
-// Generated on: 2018.09.28 at 12:18:54 PM BST 
+// Generated on: 2018.12.20 at 11:47:26 AM GMT 
 //
 
 
index 937142a..abb40c9 100644 (file)
@@ -2,7 +2,7 @@
 // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 
 // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 
 // Any modifications to this file will be lost upon recompilation of the source schema. 
-// Generated on: 2018.09.28 at 12:18:54 PM BST 
+// Generated on: 2018.12.20 at 11:47:26 AM GMT 
 //
 
 
index 7bd7c1e..0fc7771 100644 (file)
@@ -2,7 +2,7 @@
 // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 
 // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 
 // Any modifications to this file will be lost upon recompilation of the source schema. 
-// Generated on: 2018.09.28 at 12:18:54 PM BST 
+// Generated on: 2018.12.20 at 11:47:26 AM GMT 
 //
 
 
index 004119f..07b8c24 100644 (file)
@@ -2,7 +2,7 @@
 // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 
 // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 
 // Any modifications to this file will be lost upon recompilation of the source schema. 
-// Generated on: 2018.09.28 at 12:18:54 PM BST 
+// Generated on: 2018.12.20 at 11:47:26 AM GMT 
 //
 
 
index 7ec43c7..e8b7e28 100644 (file)
@@ -2,7 +2,7 @@
 // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 
 // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 
 // Any modifications to this file will be lost upon recompilation of the source schema. 
-// Generated on: 2018.09.28 at 12:18:54 PM BST 
+// Generated on: 2018.12.20 at 11:47:26 AM GMT 
 //
 
 
index 70799ea..1f68de9 100644 (file)
@@ -2,7 +2,7 @@
 // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 
 // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 
 // Any modifications to this file will be lost upon recompilation of the source schema. 
-// Generated on: 2018.09.28 at 12:18:54 PM BST 
+// Generated on: 2018.12.20 at 11:47:26 AM GMT 
 //
 
 
index fea0324..c884556 100644 (file)
@@ -2,7 +2,7 @@
 // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 
 // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 
 // Any modifications to this file will be lost upon recompilation of the source schema. 
-// Generated on: 2018.09.28 at 12:18:54 PM BST 
+// Generated on: 2018.12.20 at 11:47:26 AM GMT 
 //
 
 
index 4235c64..bd6dc77 100644 (file)
@@ -2,7 +2,7 @@
 // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 
 // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 
 // Any modifications to this file will be lost upon recompilation of the source schema. 
-// Generated on: 2018.09.28 at 12:18:54 PM BST 
+// Generated on: 2018.12.20 at 11:47:26 AM GMT 
 //
 
 @javax.xml.bind.annotation.XmlSchema(namespace = "www.vamsas.ac.uk/jalview/version2", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
index 837e970..bd827f9 100644 (file)
@@ -52,6 +52,7 @@ public class AlignSeqTest
     assertEquals(AlignSeq.extractGaps(" -", " AC-G.T"), "ACG.T");
     assertEquals(AlignSeq.extractGaps(" -.", " AC-G.T ."), "ACGT");
     assertEquals(AlignSeq.extractGaps("-", " AC-G.T"), " ACG.T");
+    assertEquals(AlignSeq.extractGaps("-. ", " -. .-"), "");
   }
 
   @Test(groups = { "Functional" })
index a7a7d34..70ae6a0 100644 (file)
@@ -2040,44 +2040,48 @@ public class AlignmentUtilsTests
     String dbSnp = "dbSNP";
     String cosmic = "COSMIC";
 
+    /*
+     * NB setting "id" (as returned by Ensembl for features in JSON format);
+     * previously "ID" (as returned for GFF3 format)
+     */
     SequenceFeature sf1 = new SequenceFeature("sequence_variant", "", 1, 1,
             0f, ensembl);
     sf1.setValue("alleles", "A,G"); // AAA -> GAA -> K/E
-    sf1.setValue("ID", "var1.125A>G");
+    sf1.setValue("id", "var1.125A>G");
 
     SequenceFeature sf2 = new SequenceFeature("sequence_variant", "", 1, 1,
             0f, dbSnp);
     sf2.setValue("alleles", "A,C"); // AAA -> CAA -> K/Q
-    sf2.setValue("ID", "var2");
+    sf2.setValue("id", "var2");
     sf2.setValue("clinical_significance", "Dodgy");
 
     SequenceFeature sf3 = new SequenceFeature("sequence_variant", "", 1, 1,
             0f, dbSnp);
     sf3.setValue("alleles", "A,T"); // AAA -> TAA -> stop codon
-    sf3.setValue("ID", "var3");
+    sf3.setValue("id", "var3");
     sf3.setValue("clinical_significance", "Bad");
 
     SequenceFeature sf4 = new SequenceFeature("sequence_variant", "", 3, 3,
             0f, cosmic);
     sf4.setValue("alleles", "A,G"); // AAA -> AAG synonymous
-    sf4.setValue("ID", "var4");
+    sf4.setValue("id", "var4");
     sf4.setValue("clinical_significance", "None");
 
     SequenceFeature sf5 = new SequenceFeature("sequence_variant", "", 3, 3,
             0f, ensembl);
     sf5.setValue("alleles", "A,T"); // AAA -> AAT -> K/N
-    sf5.setValue("ID", "sequence_variant:var5"); // prefix gets stripped off
+    sf5.setValue("id", "sequence_variant:var5"); // prefix gets stripped off
     sf5.setValue("clinical_significance", "Benign");
 
     SequenceFeature sf6 = new SequenceFeature("sequence_variant", "", 6, 6,
             0f, dbSnp);
     sf6.setValue("alleles", "T,C"); // TTT -> TTC synonymous
-    sf6.setValue("ID", "var6");
+    sf6.setValue("id", "var6");
 
     SequenceFeature sf7 = new SequenceFeature("sequence_variant", "", 8, 8,
             0f, cosmic);
     sf7.setValue("alleles", "C,A,G"); // CCC -> CAC,CGC -> P/H/R
-    sf7.setValue("ID", "var7");
+    sf7.setValue("id", "var7");
     sf7.setValue("clinical_significance", "Good");
 
     List<DnaVariant> codon1Variants = new ArrayList<>();
@@ -2149,9 +2153,9 @@ public class AlignmentUtilsTests
     assertEquals(1, sf.getEnd());
     assertEquals("nonsynonymous_variant", sf.getType());
     assertEquals("p.Lys1Asn", sf.getDescription());
-    assertEquals("var5", sf.getValue("ID"));
+    assertEquals("var5", sf.getValue("id"));
     assertEquals("Benign", sf.getValue("clinical_significance"));
-    assertEquals("ID=var5;clinical_significance=Benign",
+    assertEquals("id=var5;clinical_significance=Benign",
             sf.getAttributes());
     assertEquals(1, sf.links.size());
     assertEquals(
@@ -2165,9 +2169,9 @@ public class AlignmentUtilsTests
     assertEquals(1, sf.getEnd());
     assertEquals("nonsynonymous_variant", sf.getType());
     assertEquals("p.Lys1Gln", sf.getDescription());
-    assertEquals("var2", sf.getValue("ID"));
+    assertEquals("var2", sf.getValue("id"));
     assertEquals("Dodgy", sf.getValue("clinical_significance"));
-    assertEquals("ID=var2;clinical_significance=Dodgy", sf.getAttributes());
+    assertEquals("id=var2;clinical_significance=Dodgy", sf.getAttributes());
     assertEquals(1, sf.links.size());
     assertEquals(
             "p.Lys1Gln var2|http://www.ensembl.org/Homo_sapiens/Variation/Summary?v=var2",
@@ -2180,9 +2184,9 @@ public class AlignmentUtilsTests
     assertEquals(1, sf.getEnd());
     assertEquals("nonsynonymous_variant", sf.getType());
     assertEquals("p.Lys1Glu", sf.getDescription());
-    assertEquals("var1.125A>G", sf.getValue("ID"));
+    assertEquals("var1.125A>G", sf.getValue("id"));
     assertNull(sf.getValue("clinical_significance"));
-    assertEquals("ID=var1.125A>G", sf.getAttributes());
+    assertEquals("id=var1.125A>G", sf.getAttributes());
     assertEquals(1, sf.links.size());
     // link to variation is urlencoded
     assertEquals(
@@ -2196,9 +2200,9 @@ public class AlignmentUtilsTests
     assertEquals(1, sf.getEnd());
     assertEquals("stop_gained", sf.getType());
     assertEquals("Aaa/Taa", sf.getDescription());
-    assertEquals("var3", sf.getValue("ID"));
+    assertEquals("var3", sf.getValue("id"));
     assertEquals("Bad", sf.getValue("clinical_significance"));
-    assertEquals("ID=var3;clinical_significance=Bad", sf.getAttributes());
+    assertEquals("id=var3;clinical_significance=Bad", sf.getAttributes());
     assertEquals(1, sf.links.size());
     assertEquals(
             "Aaa/Taa var3|http://www.ensembl.org/Homo_sapiens/Variation/Summary?v=var3",
@@ -2211,9 +2215,9 @@ public class AlignmentUtilsTests
     assertEquals(1, sf.getEnd());
     assertEquals("synonymous_variant", sf.getType());
     assertEquals("aaA/aaG", sf.getDescription());
-    assertEquals("var4", sf.getValue("ID"));
+    assertEquals("var4", sf.getValue("id"));
     assertEquals("None", sf.getValue("clinical_significance"));
-    assertEquals("ID=var4;clinical_significance=None", sf.getAttributes());
+    assertEquals("id=var4;clinical_significance=None", sf.getAttributes());
     assertEquals(1, sf.links.size());
     assertEquals(
             "aaA/aaG var4|http://www.ensembl.org/Homo_sapiens/Variation/Summary?v=var4",
@@ -2226,9 +2230,9 @@ public class AlignmentUtilsTests
     assertEquals(2, sf.getEnd());
     assertEquals("synonymous_variant", sf.getType());
     assertEquals("ttT/ttC", sf.getDescription());
-    assertEquals("var6", sf.getValue("ID"));
+    assertEquals("var6", sf.getValue("id"));
     assertNull(sf.getValue("clinical_significance"));
-    assertEquals("ID=var6", sf.getAttributes());
+    assertEquals("id=var6", sf.getAttributes());
     assertEquals(1, sf.links.size());
     assertEquals(
             "ttT/ttC var6|http://www.ensembl.org/Homo_sapiens/Variation/Summary?v=var6",
@@ -2242,9 +2246,9 @@ public class AlignmentUtilsTests
     assertEquals(3, sf.getEnd());
     assertEquals("nonsynonymous_variant", sf.getType());
     assertEquals("p.Pro3Arg", sf.getDescription());
-    assertEquals("var7", sf.getValue("ID"));
+    assertEquals("var7", sf.getValue("id"));
     assertEquals("Good", sf.getValue("clinical_significance"));
-    assertEquals("ID=var7;clinical_significance=Good", sf.getAttributes());
+    assertEquals("id=var7;clinical_significance=Good", sf.getAttributes());
     assertEquals(1, sf.links.size());
     assertEquals(
             "p.Pro3Arg var7|http://www.ensembl.org/Homo_sapiens/Variation/Summary?v=var7",
@@ -2257,9 +2261,9 @@ public class AlignmentUtilsTests
     assertEquals(3, sf.getEnd());
     assertEquals("nonsynonymous_variant", sf.getType());
     assertEquals("p.Pro3His", sf.getDescription());
-    assertEquals("var7", sf.getValue("ID"));
+    assertEquals("var7", sf.getValue("id"));
     assertEquals("Good", sf.getValue("clinical_significance"));
-    assertEquals("ID=var7;clinical_significance=Good", sf.getAttributes());
+    assertEquals("id=var7;clinical_significance=Good", sf.getAttributes());
     assertEquals(1, sf.links.size());
     assertEquals(
             "p.Pro3His var7|http://www.ensembl.org/Homo_sapiens/Variation/Summary?v=var7",
index b3c78be..81ec443 100644 (file)
@@ -454,7 +454,7 @@ public class CrossRefTest
     assertSame(pep2, xrefs.getSequenceAt(1));
   }
 
-  @AfterClass
+  @AfterClass(alwaysRun = true)
   public void tearDown()
   {
     SequenceFetcherFactory.setSequenceFetcher(null);
index 6a31b31..27ae8cd 100644 (file)
@@ -139,7 +139,8 @@ public class DnaTest
     Iterator<int[]> contigs = cs.getVisContigsIterator(0, alf.getWidth(),
             false);
     Dna dna = new Dna(av, contigs);
-    AlignmentI translated = dna.translateCdna();
+    AlignmentI translated = dna.translateCdna(GeneticCodes.getInstance()
+            .getStandardCodeTable());
     assertNotNull("Couldn't do a full width translation of test data.",
             translated);
   }
@@ -170,7 +171,8 @@ public class DnaTest
               alf.getWidth(), false);
       AlignViewportI av = new AlignViewport(alf, cs);
       Dna dna = new Dna(av, vcontigs);
-      AlignmentI transAlf = dna.translateCdna();
+      AlignmentI transAlf = dna.translateCdna(GeneticCodes.getInstance()
+              .getStandardCodeTable());
 
       assertTrue("Translation failed (ipos=" + ipos
               + ") No alignment data.", transAlf != null);
@@ -197,7 +199,8 @@ public class DnaTest
     Iterator<int[]> contigs = cs.getVisContigsIterator(0, alf.getWidth(),
             false);
     Dna dna = new Dna(av, contigs);
-    AlignmentI translated = dna.translateCdna();
+    AlignmentI translated = dna.translateCdna(GeneticCodes.getInstance()
+            .getStandardCodeTable());
     String aa = translated.getSequenceAt(0).getSequenceAsString();
     assertEquals(
             "AAAACCDDEEFFGGGGHHIIIKKLLLLLLMNNPPPPQQRRRRRRSSSSSSTTTTVVVVWYY***",
@@ -222,7 +225,8 @@ public class DnaTest
     Iterator<int[]> contigs = cs.getVisContigsIterator(0, alf.getWidth(),
             false);
     Dna dna = new Dna(av, contigs);
-    AlignmentI translated = dna.translateCdna();
+    AlignmentI translated = dna.translateCdna(GeneticCodes.getInstance()
+            .getStandardCodeTable());
     String aa = translated.getSequenceAt(0).getSequenceAsString();
     assertEquals("AACDDGGGGHHIIIKKLLLLLLMNNPPPPQQRRRRRRSSSSSSTTTTVVVVW", aa);
   }
@@ -309,7 +313,8 @@ public class DnaTest
     Iterator<int[]> contigs = cs.getVisContigsIterator(0, cdna.getWidth(),
             false);
     Dna dna = new Dna(av, contigs);
-    AlignmentI translated = dna.translateCdna();
+    AlignmentI translated = dna.translateCdna(GeneticCodes.getInstance()
+            .getStandardCodeTable());
 
     /*
      * Jumble the cDNA sequences and translate.
@@ -325,7 +330,8 @@ public class DnaTest
     av = new AlignViewport(cdnaReordered, cs);
     contigs = cs.getVisContigsIterator(0, cdna.getWidth(), false);
     dna = new Dna(av, contigs);
-    AlignmentI translated2 = dna.translateCdna();
+    AlignmentI translated2 = dna.translateCdna(GeneticCodes.getInstance()
+            .getStandardCodeTable());
 
     /*
      * Check translated sequences are the same in both alignments.
index d7a509f..5f64b28 100644 (file)
@@ -24,21 +24,31 @@ import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertSame;
 import static org.testng.Assert.assertTrue;
 
+import jalview.api.AlignViewportI;
+import jalview.api.FinderI;
+import jalview.bin.Cache;
 import jalview.datamodel.Alignment;
 import jalview.datamodel.AlignmentI;
+import jalview.datamodel.ColumnSelection;
+import jalview.datamodel.HiddenColumns;
 import jalview.datamodel.SearchResultMatchI;
 import jalview.datamodel.SearchResultsI;
 import jalview.datamodel.Sequence;
+import jalview.datamodel.SequenceGroup;
 import jalview.gui.AlignFrame;
+import jalview.gui.AlignViewport;
 import jalview.gui.JvOptionPane;
 import jalview.io.DataSourceType;
 import jalview.io.FileLoader;
 
 import java.util.List;
 
+import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
+import junit.extensions.PA;
+
 public class FinderTest
 {
   @BeforeClass(alwaysRun = true)
@@ -52,32 +62,56 @@ public class FinderTest
 
   private AlignmentI al;
 
+  private AlignViewportI av;
+
   @BeforeClass(groups = "Functional")
   public void setUp()
   {
-    String seqData = "seq1 ABCD--EF-GHI\n" + "seq2 A--BCDefHI\n"
+    Cache.loadProperties("test/jalview/io/testProps.jvprops");
+    Cache.applicationProperties.setProperty("PAD_GAPS",
+            Boolean.FALSE.toString());
+
+    String seqData = "seq1seq1/8-18 ABCD--EF-GHIJI\n" + "seq2 A--BCDefHI\n"
             + "seq3 --bcdEFH\n" + "seq4 aa---aMMMMMaaa\n";
     af = new FileLoader().LoadFileWaitTillLoaded(seqData,
             DataSourceType.PASTE);
-    al = af.getViewport().getAlignment();
+    av = af.getViewport();
+    al = av.getAlignment();
+  }
+
+  @AfterMethod(alwaysRun = true)
+  public void tearDownAfterTest()
+  {
+    av.setSelectionGroup(null);
   }
 
   /**
-   * Test for find all matches of a regular expression
+   * Test for find matches of a regular expression
    */
   @Test(groups = "Functional")
-  public void testFindAll_regex()
+  public void testFind_regex()
   {
-    Finder f = new Finder(al, null);
-    f.setFindAll(true);
-    f.find("E.H"); // 'E, any character, H'
+    /*
+     * find next match only
+     */
+    Finder f = new Finder(av);
+    f.findNext("E.H", false, false); // 'E, any character, H'
+    // should match seq2 efH only
+    SearchResultsI sr = f.getSearchResults();
+    assertEquals(sr.getSize(), 1);
+    List<SearchResultMatchI> matches = sr.getResults();
+    assertSame(matches.get(0).getSequence(), al.getSequenceAt(1));
+    assertEquals(matches.get(0).getStart(), 5);
+    assertEquals(matches.get(0).getEnd(), 7);
 
+    f = new Finder(av);
+    f.findAll("E.H", false, false); // 'E, any character, H'
     // should match seq2 efH and seq3 EFH
-    SearchResultsI sr = f.getSearchResults();
+    sr = f.getSearchResults();
     assertEquals(sr.getSize(), 2);
-    List<SearchResultMatchI> matches = sr.getResults();
-    assertSame(al.getSequenceAt(1), matches.get(0).getSequence());
-    assertSame(al.getSequenceAt(2), matches.get(1).getSequence());
+    matches = sr.getResults();
+    assertSame(matches.get(0).getSequence(), al.getSequenceAt(1));
+    assertSame(matches.get(1).getSequence(), al.getSequenceAt(2));
     assertEquals(matches.get(0).getStart(), 5);
     assertEquals(matches.get(0).getEnd(), 7);
     assertEquals(matches.get(1).getStart(), 4);
@@ -90,20 +124,40 @@ public class FinderTest
   @Test(groups = "Functional")
   public void testFind_residueNumber()
   {
-    Finder f = new Finder(al, null);
-    f.setFindAll(true);
-    f.find("9");
+    Finder f = new Finder(av);
 
-    // seq1 and seq4 have 9 residues; no match in other sequences
+    /*
+     * find first match should return seq1 residue 9
+     */
+    f.findNext("9", false, false);
     SearchResultsI sr = f.getSearchResults();
-    assertEquals(sr.getSize(), 2);
+    assertEquals(sr.getSize(), 1);
     List<SearchResultMatchI> matches = sr.getResults();
-    assertSame(al.getSequenceAt(0), matches.get(0).getSequence());
-    assertSame(al.getSequenceAt(3), matches.get(1).getSequence());
+    assertSame(matches.get(0).getSequence(), al.getSequenceAt(0));
+    assertEquals(matches.get(0).getStart(), 9);
+    assertEquals(matches.get(0).getEnd(), 9);
+
+    /*
+     * find all matches should return seq1 and seq4 (others are too short)
+     */
+    f = new Finder(av);
+    f.findAll("9", false, false);
+    sr = f.getSearchResults();
+    assertEquals(sr.getSize(), 2);
+    matches = sr.getResults();
+    assertSame(matches.get(0).getSequence(), al.getSequenceAt(0));
+    assertSame(matches.get(1).getSequence(), al.getSequenceAt(3));
     assertEquals(matches.get(0).getStart(), 9);
     assertEquals(matches.get(0).getEnd(), 9);
     assertEquals(matches.get(1).getStart(), 9);
     assertEquals(matches.get(1).getEnd(), 9);
+
+    /*
+     * parsing of search string as integer is strict
+     */
+    f = new Finder(av);
+    f.findNext(" 9", false, false);
+    assertTrue(f.getSearchResults().isEmpty());
   }
 
   /**
@@ -113,69 +167,84 @@ public class FinderTest
   public void testFindNext()
   {
     /*
-     * start at second sequence; resIndex of -1
+     * start at second sequence; colIndex of -1
      * means sequence id / description is searched
      */
-    Finder f = new Finder(al, null, 1, -1);
-    f.find("e"); // matches id
+    Finder f = new Finder(av);
+    PA.setValue(f, "sequenceIndex", 1);
+    PA.setValue(f, "columnIndex", -1);
+    f.findNext("e", false, false); // matches id
 
     assertTrue(f.getSearchResults().isEmpty());
-    assertEquals(f.getIdMatch().size(), 1);
-    assertSame(f.getIdMatch().get(0), al.getSequenceAt(1));
-
-    // resIndex is now 0 - for use in next find next
-    assertEquals(f.getResIndex(), 0);
-    f = new Finder(al, null, 1, 0);
-    f.find("e"); // matches in sequence
-    assertTrue(f.getIdMatch().isEmpty());
+    assertEquals(f.getIdMatches().size(), 1);
+    assertSame(f.getIdMatches().get(0), al.getSequenceAt(1));
+
+    // colIndex is now 0 - for use in next find next
+    // searching A--BCDefHI
+    assertEquals(PA.getValue(f, "columnIndex"), 0);
+    f = new Finder(av);
+    PA.setValue(f, "sequenceIndex", 1);
+    PA.setValue(f, "columnIndex", 0);
+    f.findNext("e", false, false); // matches in sequence
+    assertTrue(f.getIdMatches().isEmpty());
     assertEquals(f.getSearchResults().getSize(), 1);
     List<SearchResultMatchI> matches = f.getSearchResults().getResults();
     assertEquals(matches.get(0).getStart(), 5);
     assertEquals(matches.get(0).getEnd(), 5);
     assertSame(matches.get(0).getSequence(), al.getSequenceAt(1));
     // still in the second sequence
-    assertEquals(f.getSeqIndex(), 1);
-    // next residue position to search from is 5
-    // (used as base 0 by RegEx so the same as 6 if base 1)
-    assertEquals(f.getResIndex(), 5);
+    assertEquals(PA.getValue(f, "sequenceIndex"), 1);
+    // next column position to search from is 7
+    assertEquals(PA.getValue(f, "columnIndex"), 7);
 
     // find next from end of sequence - finds next sequence id
-    f = new Finder(al, null, 1, 5);
-    f.find("e");
-    assertEquals(f.getIdMatch().size(), 1);
-    assertSame(f.getIdMatch().get(0), al.getSequenceAt(2));
+    f = new Finder(av);
+    PA.setValue(f, "sequenceIndex", 1);
+    PA.setValue(f, "columnIndex", 7);
+    f.findNext("e", false, false);
+    assertEquals(f.getIdMatches().size(), 1);
+    assertSame(f.getIdMatches().get(0), al.getSequenceAt(2));
+    assertTrue(f.getSearchResults().isEmpty());
   }
 
   /**
    * Test for matching within sequence descriptions
    */
   @Test(groups = "Functional")
-  public void testFindAll_inDescription()
+  public void testFind_inDescription()
   {
     AlignmentI al2 = new Alignment(al);
     al2.getSequenceAt(0).setDescription("BRAF");
     al2.getSequenceAt(1).setDescription("braf");
-    Finder f = new Finder(al2, null);
-    f.setFindAll(true);
-    f.setIncludeDescription(true);
-
-    f.find("rAF");
-    assertEquals(f.getIdMatch().size(), 2);
-    assertSame(f.getIdMatch().get(0), al2.getSequenceAt(0));
-    assertSame(f.getIdMatch().get(1), al2.getSequenceAt(1));
+
+    AlignViewportI av2 = new AlignViewport(al2);
+
+    /*
+     * find first match only
+     */
+    Finder f = new Finder(av2);
+    f.findNext("rAF", false, true);
+    assertEquals(f.getIdMatches().size(), 1);
+    assertSame(f.getIdMatches().get(0), al2.getSequenceAt(0));
     assertTrue(f.getSearchResults().isEmpty());
 
     /*
-     * case sensitive
+     * find all matches
      */
-    f = new Finder(al2, null);
-    f.setFindAll(true);
-    f.setCaseSensitive(true);
-    f.setIncludeDescription(true);
+    f = new Finder(av2);
+    f.findAll("rAF", false, true);
+    assertEquals(f.getIdMatches().size(), 2);
+    assertSame(f.getIdMatches().get(0), al2.getSequenceAt(0));
+    assertSame(f.getIdMatches().get(1), al2.getSequenceAt(1));
+    assertTrue(f.getSearchResults().isEmpty());
 
-    f.find("RAF");
-    assertEquals(f.getIdMatch().size(), 1);
-    assertSame(f.getIdMatch().get(0), al2.getSequenceAt(0));
+    /*
+     * case sensitive
+     */
+    f = new Finder(av2);
+    f.findAll("RAF", true, true);
+    assertEquals(f.getIdMatches().size(), 1);
+    assertSame(f.getIdMatches().get(0), al2.getSequenceAt(0));
     assertTrue(f.getSearchResults().isEmpty());
 
     /*
@@ -184,27 +253,25 @@ public class FinderTest
     al2.getSequenceAt(0).setDescription("the efh sequence");
     al2.getSequenceAt(0).setName("mouseEFHkinase");
     al2.getSequenceAt(1).setName("humanEFHkinase");
-    f = new Finder(al2, null);
-    f.setFindAll(true);
-    f.setIncludeDescription(true);
+    f = new Finder(av2);
 
     /*
      * sequence matches should have no duplicates
      */
-    f.find("EFH");
-    assertEquals(f.getIdMatch().size(), 2);
-    assertSame(f.getIdMatch().get(0), al2.getSequenceAt(0));
-    assertSame(f.getIdMatch().get(1), al2.getSequenceAt(1));
+    f.findAll("EFH", false, true);
+    assertEquals(f.getIdMatches().size(), 2);
+    assertSame(f.getIdMatches().get(0), al2.getSequenceAt(0));
+    assertSame(f.getIdMatches().get(1), al2.getSequenceAt(1));
 
     assertEquals(f.getSearchResults().getSize(), 2);
     SearchResultMatchI match = f.getSearchResults().getResults().get(0);
-    assertSame(al2.getSequenceAt(1), match.getSequence());
-    assertEquals(5, match.getStart());
-    assertEquals(7, match.getEnd());
+    assertSame(match.getSequence(), al2.getSequenceAt(1));
+    assertEquals(match.getStart(), 5);
+    assertEquals(match.getEnd(), 7);
     match = f.getSearchResults().getResults().get(1);
-    assertSame(al2.getSequenceAt(2), match.getSequence());
-    assertEquals(4, match.getStart());
-    assertEquals(6, match.getEnd());
+    assertSame(match.getSequence(), al2.getSequenceAt(2));
+    assertEquals(match.getStart(), 4);
+    assertEquals(match.getEnd(), 6);
   }
 
   /**
@@ -213,105 +280,454 @@ public class FinderTest
   @Test(groups = "Functional")
   public void testFindAll_sequenceIds()
   {
-    Finder f = new Finder(al, null);
-    f.setFindAll(true);
+    Finder f = new Finder(av);
 
     /*
-     * case insensitive
+     * case insensitive; seq1 occurs twice in sequence id but
+     * only one match should be returned
      */
-    f.find("SEQ1");
-    assertEquals(f.getIdMatch().size(), 1);
-    assertSame(f.getIdMatch().get(0), al.getSequenceAt(0));
-    assertTrue(f.getSearchResults().isEmpty());
+    f.findAll("SEQ1", false, false);
+    assertEquals(f.getIdMatches().size(), 1);
+    assertSame(f.getIdMatches().get(0), al.getSequenceAt(0));
+    SearchResultsI searchResults = f.getSearchResults();
+    assertTrue(searchResults.isEmpty());
 
     /*
      * case sensitive
      */
-    f = new Finder(al, null);
-    f.setFindAll(true);
-    f.setCaseSensitive(true);
-    f.find("SEQ1");
-    assertTrue(f.getSearchResults().isEmpty());
+    f = new Finder(av);
+    f.findAll("SEQ1", true, false);
+    searchResults = f.getSearchResults();
+    assertTrue(searchResults.isEmpty());
 
     /*
      * match both sequence id and sequence
      */
     AlignmentI al2 = new Alignment(al);
+    AlignViewportI av2 = new AlignViewport(al2);
     al2.addSequence(new Sequence("aBz", "xyzabZpqrAbZ"));
-    f = new Finder(al2, null);
-    f.setFindAll(true);
-    f.find("ABZ");
-    assertEquals(f.getIdMatch().size(), 1);
-    assertSame(f.getIdMatch().get(0), al2.getSequenceAt(4));
-    assertEquals(f.getSearchResults().getSize(), 2);
-    SearchResultMatchI match = f.getSearchResults().getResults().get(0);
-    assertSame(al2.getSequenceAt(4), match.getSequence());
-    assertEquals(4, match.getStart());
-    assertEquals(6, match.getEnd());
-    match = f.getSearchResults().getResults().get(1);
-    assertSame(al2.getSequenceAt(4), match.getSequence());
-    assertEquals(10, match.getStart());
-    assertEquals(12, match.getEnd());
+    f = new Finder(av2);
+    f.findAll("ABZ", false, false);
+    assertEquals(f.getIdMatches().size(), 1);
+    assertSame(f.getIdMatches().get(0), al2.getSequenceAt(4));
+    searchResults = f.getSearchResults();
+    assertEquals(searchResults.getSize(), 2);
+    SearchResultMatchI match = searchResults.getResults().get(0);
+    assertSame(match.getSequence(), al2.getSequenceAt(4));
+    assertEquals(match.getStart(), 4);
+    assertEquals(match.getEnd(), 6);
+    match = searchResults.getResults().get(1);
+    assertSame(match.getSequence(), al2.getSequenceAt(4));
+    assertEquals(match.getStart(), 10);
+    assertEquals(match.getEnd(), 12);
   }
 
   /**
-   * Test finding all matches of a sequence pattern in an alignment
+   * Test finding next match of a sequence pattern in an alignment
    */
   @Test(groups = "Functional")
-  public void testFindAll_simpleMatch()
+  public void testFind_findNext()
   {
-    Finder f = new Finder(al, null);
-    f.setFindAll(true);
+    /*
+     * efh should be matched in seq2 only
+     */
+    FinderI f = new Finder(av);
+    f.findNext("EfH", false, false);
+    SearchResultsI searchResults = f.getSearchResults();
+    assertEquals(searchResults.getSize(), 1);
+    SearchResultMatchI match = searchResults.getResults().get(0);
+    assertSame(match.getSequence(), al.getSequenceAt(1));
+    assertEquals(match.getStart(), 5);
+    assertEquals(match.getEnd(), 7);
 
     /*
-     * case insensitive first
+     * I should be found in seq1 (twice) and seq2 (once)
      */
-    f.find("EfH");
+    f = new Finder(av);
+    f.findNext("I", false, false); // find next: seq1/16
+    searchResults = f.getSearchResults();
+    assertEquals(searchResults.getSize(), 1);
+    match = searchResults.getResults().get(0);
+    assertSame(match.getSequence(), al.getSequenceAt(0));
+    assertEquals(match.getStart(), 16);
+    assertEquals(match.getEnd(), 16);
+
+    f.findNext("I", false, false); // find next: seq1/18
+    searchResults = f.getSearchResults();
+    assertEquals(searchResults.getSize(), 1);
+    match = searchResults.getResults().get(0);
+    assertSame(match.getSequence(), al.getSequenceAt(0));
+    assertEquals(match.getStart(), 18);
+    assertEquals(match.getEnd(), 18);
+
+    f.findNext("I", false, false); // find next: seq2/8
+    searchResults = f.getSearchResults();
+    assertEquals(searchResults.getSize(), 1);
+    match = searchResults.getResults().get(0);
+    assertSame(match.getSequence(), al.getSequenceAt(1));
+    assertEquals(match.getStart(), 8);
+    assertEquals(match.getEnd(), 8);
+
+    f.findNext("I", false, false);
+    assertTrue(f.getSearchResults().isEmpty());
+
+    /*
+     * find should reset to start of alignment after a failed search
+     */
+    f.findNext("I", false, false); // find next: seq1/16
+    searchResults = f.getSearchResults();
+    assertEquals(searchResults.getSize(), 1);
+    match = searchResults.getResults().get(0);
+    assertSame(match.getSequence(), al.getSequenceAt(0));
+    assertEquals(match.getStart(), 16);
+    assertEquals(match.getEnd(), 16);
+  }
+
+  /**
+   * Test for JAL-2302 to verify that sub-matches are not included in a find all
+   * result
+   */
+  @Test(groups = "Functional")
+  public void testFind_maximalResultOnly()
+  {
+    Finder f = new Finder(av);
+    f.findAll("M+", false, false);
+    SearchResultsI searchResults = f.getSearchResults();
+    assertEquals(searchResults.getSize(), 1);
+    SearchResultMatchI match = searchResults.getResults().get(0);
+    assertSame(match.getSequence(), al.getSequenceAt(3));
+    assertEquals(match.getStart(), 4); // dataset sequence positions
+    assertEquals(match.getEnd(), 8); // base 1
+  }
+
+  /**
+   * Test finding all matches of a sequence pattern in an alignment
+   */
+  @Test(groups = "Functional")
+  public void testFind_findAll()
+  {
+    Finder f = new Finder(av);
+    f.findAll("EfH", false, false);
     SearchResultsI searchResults = f.getSearchResults();
     assertEquals(searchResults.getSize(), 2);
     SearchResultMatchI match = searchResults.getResults().get(0);
-    assertSame(al.getSequenceAt(1), match.getSequence());
-    assertEquals(5, match.getStart());
-    assertEquals(7, match.getEnd());
+    assertSame(match.getSequence(), al.getSequenceAt(1));
+    assertEquals(match.getStart(), 5);
+    assertEquals(match.getEnd(), 7);
     match = searchResults.getResults().get(1);
-    assertSame(al.getSequenceAt(2), match.getSequence());
-    assertEquals(4, match.getStart());
-    assertEquals(6, match.getEnd());
+    assertSame(match.getSequence(), al.getSequenceAt(2));
+    assertEquals(match.getStart(), 4);
+    assertEquals(match.getEnd(), 6);
 
     /*
-     * case sensitive
+     * find all I should find 2 positions in seq1, 1 in seq2
      */
-    f = new Finder(al, null);
-    f.setFindAll(true);
-    f.setCaseSensitive(true);
-    f.find("BC");
+    f.findAll("I", false, false);
     searchResults = f.getSearchResults();
+    assertEquals(searchResults.getSize(), 3);
+    match = searchResults.getResults().get(0);
+    assertSame(match.getSequence(), al.getSequenceAt(0));
+    assertEquals(match.getStart(), 16);
+    assertEquals(match.getEnd(), 16);
+    match = searchResults.getResults().get(1);
+    assertSame(match.getSequence(), al.getSequenceAt(0));
+    assertEquals(match.getStart(), 18);
+    assertEquals(match.getEnd(), 18);
+    match = searchResults.getResults().get(2);
+    assertSame(match.getSequence(), al.getSequenceAt(1));
+    assertEquals(match.getStart(), 8);
+    assertEquals(match.getEnd(), 8);
+  }
+
+  /**
+   * Test finding all matches, case-sensitive
+   */
+  @Test(groups = "Functional")
+  public void testFind_findAllCaseSensitive()
+  {
+    Finder f = new Finder(av);
+
+    /*
+     * BC should match seq1/9-10 and seq2/2-3
+     */
+    f.findAll("BC", true, false);
+    SearchResultsI searchResults = f.getSearchResults();
     assertEquals(searchResults.getSize(), 2);
+    SearchResultMatchI match = searchResults.getResults().get(0);
+    assertSame(match.getSequence(), al.getSequenceAt(0));
+    assertEquals(match.getStart(), 9);
+    assertEquals(match.getEnd(), 10);
+    match = searchResults.getResults().get(1);
+    assertSame(match.getSequence(), al.getSequenceAt(1));
+    assertEquals(match.getStart(), 2);
+    assertEquals(match.getEnd(), 3);
+
+    /*
+     * bc should match seq3/1-2
+     */
+    f = new Finder(av);
+    f.findAll("bc", true, false);
+    searchResults = f.getSearchResults();
+    assertEquals(searchResults.getSize(), 1);
+    match = searchResults.getResults().get(0);
+    assertSame(match.getSequence(), al.getSequenceAt(2));
+    assertEquals(match.getStart(), 1);
+    assertEquals(match.getEnd(), 2);
+
+    f.findAll("bC", true, false);
+    assertTrue(f.getSearchResults().isEmpty());
+  }
+
+  /**
+   * Test finding next match of a sequence pattern in a selection group
+   */
+  @Test(groups = "Functional")
+  public void testFind_inSelection()
+  {
+    /*
+     * select sequences 2 and 3, columns 4-6 which contains
+     * BCD
+     * cdE
+     */
+    SequenceGroup sg = new SequenceGroup();
+    sg.setStartRes(3);
+    sg.setEndRes(5);
+    sg.addSequence(al.getSequenceAt(1), false);
+    sg.addSequence(al.getSequenceAt(2), false);
+    av.setSelectionGroup(sg);
+
+    FinderI f = new Finder(av);
+    f.findNext("b", false, false);
+    assertTrue(f.getIdMatches().isEmpty());
+    SearchResultsI searchResults = f.getSearchResults();
+    assertEquals(searchResults.getSize(), 1);
+    SearchResultMatchI match = searchResults.getResults().get(0);
+    assertSame(match.getSequence(), al.getSequenceAt(1));
+    assertEquals(match.getStart(), 2);
+    assertEquals(match.getEnd(), 2);
+
+    /*
+     * a second Find should not return the 'b' in seq3 as outside the selection
+     */
+    f.findNext("b", false, false);
+    assertTrue(f.getSearchResults().isEmpty());
+    assertTrue(f.getIdMatches().isEmpty());
+
+    f = new Finder(av);
+    f.findNext("d", false, false);
+    assertTrue(f.getIdMatches().isEmpty());
+    searchResults = f.getSearchResults();
+    assertEquals(searchResults.getSize(), 1);
     match = searchResults.getResults().get(0);
-    assertSame(al.getSequenceAt(0), match.getSequence());
-    assertEquals(2, match.getStart());
-    assertEquals(3, match.getEnd());
+    assertSame(match.getSequence(), al.getSequenceAt(1));
+    assertEquals(match.getStart(), 4);
+    assertEquals(match.getEnd(), 4);
+    f.findNext("d", false, false);
+    assertTrue(f.getIdMatches().isEmpty());
+    searchResults = f.getSearchResults();
+    assertEquals(searchResults.getSize(), 1);
+    match = searchResults.getResults().get(0);
+    assertSame(match.getSequence(), al.getSequenceAt(2));
+    assertEquals(match.getStart(), 3);
+    assertEquals(match.getEnd(), 3);
+  }
+
+  /**
+   * Test finding all matches of a search pattern in a selection group
+   */
+  @Test(groups = "Functional")
+  public void testFind_findAllInSelection()
+  {
+    /*
+     * select sequences 2 and 3, columns 4-6 which contains
+     * BCD
+     * cdE
+     */
+    SequenceGroup sg = new SequenceGroup();
+    sg.setStartRes(3);
+    sg.setEndRes(5);
+    sg.addSequence(al.getSequenceAt(1), false);
+    sg.addSequence(al.getSequenceAt(2), false);
+    av.setSelectionGroup(sg);
+  
+    /*
+     * search for 'e' should match two sequence ids and one residue
+     */
+    Finder f = new Finder(av);
+    f.findAll("e", false, false);
+    assertEquals(f.getIdMatches().size(), 2);
+    assertSame(f.getIdMatches().get(0), al.getSequenceAt(1));
+    assertSame(f.getIdMatches().get(1), al.getSequenceAt(2));
+    SearchResultsI searchResults = f.getSearchResults();
+    assertEquals(searchResults.getSize(), 1);
+    SearchResultMatchI match = searchResults.getResults().get(0);
+    assertSame(match.getSequence(), al.getSequenceAt(2));
+    assertEquals(match.getStart(), 4);
+    assertEquals(match.getEnd(), 4);
+
+    /*
+     * search for 'Q' should match two sequence ids only
+     */
+    f = new Finder(av);
+    f.findAll("Q", false, false);
+    assertEquals(f.getIdMatches().size(), 2);
+    assertSame(f.getIdMatches().get(0), al.getSequenceAt(1));
+    assertSame(f.getIdMatches().get(1), al.getSequenceAt(2));
+    assertTrue(f.getSearchResults().isEmpty());
+  }
+
+  /**
+   * Test finding in selection with a sequence too short to reach it
+   */
+  @Test(groups = "Functional")
+  public void testFind_findAllInSelectionWithShortSequence()
+  {
+    /*
+     * select all sequences, columns 10-12
+     * BCD
+     * cdE
+     */
+    SequenceGroup sg = new SequenceGroup();
+    sg.setStartRes(9);
+    sg.setEndRes(11);
+    sg.addSequence(al.getSequenceAt(0), false);
+    sg.addSequence(al.getSequenceAt(1), false);
+    sg.addSequence(al.getSequenceAt(2), false);
+    sg.addSequence(al.getSequenceAt(3), false);
+    av.setSelectionGroup(sg);
+
+    /*
+     * search for 'I' should match two sequence positions
+     */
+    Finder f = new Finder(av);
+    f.findAll("I", false, false);
+    assertTrue(f.getIdMatches().isEmpty());
+    SearchResultsI searchResults = f.getSearchResults();
+    assertEquals(searchResults.getSize(), 2);
+    SearchResultMatchI match = searchResults.getResults().get(0);
+    assertSame(match.getSequence(), al.getSequenceAt(0));
+    assertEquals(match.getStart(), 16);
+    assertEquals(match.getEnd(), 16);
     match = searchResults.getResults().get(1);
-    assertSame(al.getSequenceAt(1), match.getSequence());
-    assertEquals(2, match.getStart());
-    assertEquals(3, match.getEnd());
+    assertSame(match.getSequence(), al.getSequenceAt(1));
+    assertEquals(match.getStart(), 8);
+    assertEquals(match.getEnd(), 8);
   }
 
   /**
-   * Test for JAL-2302 to verify that sub-matches are not included in a find all
-   * result
+   * Test that find does not report hidden positions
    */
   @Test(groups = "Functional")
-  public void testFind_maximalResultOnly()
+  public void testFind_withHiddenColumns()
   {
-    Finder f = new Finder(al, null);
-    f.setFindAll(true);
-    f.find("M+");
+    /*
+     * 0    5   9
+     * ABCD--EF-GHI
+     * A--BCDefHI
+     * --bcdEFH
+     * aa---aMMMMMaaa
+     */
+
+    /*
+     * hide 2-4 (CD- -BC bcd ---)
+     */
+    HiddenColumns hc = new HiddenColumns();
+    hc.hideColumns(2, 4);
+    al.setHiddenColumns(hc);
+
+    /*
+     * find all search for D should ignore hidden positions in seq1 and seq3,
+     * find the visible D in seq2
+     */
+    Finder f = new Finder(av);
+    f.findAll("D", false, false);
     SearchResultsI searchResults = f.getSearchResults();
     assertEquals(searchResults.getSize(), 1);
     SearchResultMatchI match = searchResults.getResults().get(0);
-    assertSame(al.getSequenceAt(3), match.getSequence());
-    assertEquals(4, match.getStart()); // dataset sequence positions
-    assertEquals(8, match.getEnd()); // base 1
+    assertSame(match.getSequence(), al.getSequenceAt(1));
+    assertEquals(match.getStart(), 4);
+    assertEquals(match.getEnd(), 4);
+
+    /*
+     * hide columns 2-5:
+     * find all 'aaa' should find end of seq4 only
+     */
+    hc.hideColumns(2, 5);
+    f = new Finder(av);
+    f.findAll("aaa", false, false);
+    searchResults = f.getSearchResults();
+    assertEquals(searchResults.getSize(), 1);
+    match = searchResults.getResults().get(0);
+    assertSame(match.getSequence(), al.getSequenceAt(3));
+    assertEquals(match.getStart(), 9);
+    assertEquals(match.getEnd(), 11);
+
+    /*
+     * find all 'BE' should not match across hidden columns in seq1
+     */
+    f.findAll("BE", false, false);
+    assertTrue(f.getSearchResults().isEmpty());
+
+    /*
+     * boundary case: hide columns at end of alignment
+     * search for H should match seq3/6 only
+     */
+    hc.revealAllHiddenColumns(new ColumnSelection());
+    hc.hideColumns(8, 13);
+    f = new Finder(av);
+    f.findNext("H", false, false);
+    searchResults = f.getSearchResults();
+    assertEquals(searchResults.getSize(), 1);
+    match = searchResults.getResults().get(0);
+    assertSame(match.getSequence(), al.getSequenceAt(2));
+    assertEquals(match.getStart(), 6);
+    assertEquals(match.getEnd(), 6);
+  }
+
+  @Test(groups = "Functional")
+  public void testFind_withHiddenColumnsAndSelection()
+  {
+    /*
+     * 0    5   9
+     * ABCD--EF-GHI
+     * A--BCDefHI
+     * --bcdEFH
+     * aa---aMMMMMaaa
+     */
+  
+    /*
+     * hide columns 2-4 and 6-7
+     */
+    HiddenColumns hc = new HiddenColumns();
+    hc.hideColumns(2, 4);
+    hc.hideColumns(6, 7);
+    al.setHiddenColumns(hc);
+  
+    /*
+     * select rows 2-3
+     */
+    SequenceGroup sg = new SequenceGroup();
+    sg.addSequence(al.getSequenceAt(1), false);
+    sg.addSequence(al.getSequenceAt(2), false);
+    sg.setStartRes(0);
+    sg.setEndRes(13);
+    av.setSelectionGroup(sg);
+
+    /*
+     * find all search for A or H
+     * should match seq2/1, seq2/7, not seq3/6
+     */
+    Finder f = new Finder(av);
+    f.findAll("[AH]", false, false);
+    SearchResultsI searchResults = f.getSearchResults();
+    assertEquals(searchResults.getSize(), 2);
+    SearchResultMatchI match = searchResults.getResults().get(0);
+    assertSame(match.getSequence(), al.getSequenceAt(1));
+    assertEquals(match.getStart(), 1);
+    assertEquals(match.getEnd(), 1);
+    match = searchResults.getResults().get(1);
+    assertSame(match.getSequence(), al.getSequenceAt(1));
+    assertEquals(match.getStart(), 7);
+    assertEquals(match.getEnd(), 7);
   }
 }
diff --git a/test/jalview/analysis/GeneticCodesTest.java b/test/jalview/analysis/GeneticCodesTest.java
new file mode 100644 (file)
index 0000000..5f49092
--- /dev/null
@@ -0,0 +1,298 @@
+package jalview.analysis;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertSame;
+
+import java.util.Iterator;
+
+import org.testng.annotations.Test;
+
+public class GeneticCodesTest
+{
+  @Test(groups = "Functional")
+  public void testGetCodeTable()
+  {
+    GeneticCodes codes = GeneticCodes.getInstance();
+    assertEquals(codes.getStandardCodeTable().getName(), "Standard");
+    assertEquals(codes.getStandardCodeTable().getId(), "1");
+    assertSame(codes.getStandardCodeTable(), codes.getCodeTable("1"));
+    assertEquals(codes.getCodeTable("2").getName(),
+            "Vertebrate Mitochondrial");
+    assertEquals(codes.getCodeTable("11").getName(),
+            "Bacterial, Archaeal and Plant Plastid");
+    assertEquals(codes.getCodeTable("31").getName(),
+            "Blastocrithidia Nuclear");
+  }
+
+  @Test(groups = "Functional")
+  public void testGetCodeTables()
+  {
+    GeneticCodes codes = GeneticCodes.getInstance();
+    Iterator<GeneticCodeI> tableIterator = codes.getCodeTables().iterator();
+    String[] ids = new String[] { "1", "2", "3", "4", "5", "6", "9", "10",
+        "11", "12", "13", "14", "15", "16", "21", "22", "23", "24", "25",
+        "26", "27", "28", "29", "30", "31" };
+    for (int i = 0; i < ids.length; i++)
+    {
+      assertEquals(tableIterator.next().getId(), ids[i]);
+    }
+    assertFalse(tableIterator.hasNext());
+  }
+
+  @Test(groups = "Functional")
+  public void testTranslate()
+  {
+    GeneticCodes codes = GeneticCodes.getInstance();
+
+    GeneticCodeI gc = codes.getCodeTable("1");
+    assertNull(gc.translate("XYZ"));
+    assertEquals(gc.translate("AGA"), "R");
+
+    gc = codes.getCodeTable("2");
+    assertEquals(gc.translate("AGA"), "*"); // variant
+    assertEquals(gc.translate("ttc"), "F"); // non-variant
+
+    // table 11 has no variant translations - should serve the standard values
+    gc = codes.getCodeTable("11");
+    assertEquals(gc.translate("ttc"), "F");
+
+    gc = codes.getCodeTable("31");
+    assertEquals(gc.translate("TGA"), "W"); // variant
+    assertEquals(gc.translate("tag"), "E"); // variant
+    assertEquals(gc.translate("AGC"), "S"); // non-variant
+  }
+
+  /**
+   * Test 'standard' codon translations (no ambiguity codes)
+   */
+  @Test(groups = { "Functional" })
+  public void testTranslate_standardTable()
+  {
+    GeneticCodeI st = GeneticCodes.getInstance().getStandardCodeTable();
+    assertEquals("F", st.translate("TTT"));
+    assertEquals("F", st.translate("TTC"));
+    assertEquals("L", st.translate("TTA"));
+    assertEquals("L", st.translate("TTG"));
+    assertEquals("L", st.translate("CTT"));
+    assertEquals("L", st.translate("CTC"));
+    assertEquals("L", st.translate("CTA"));
+    assertEquals("L", st.translate("CTG"));
+    assertEquals("I", st.translate("ATT"));
+    assertEquals("I", st.translate("ATC"));
+    assertEquals("I", st.translate("ATA"));
+    assertEquals("M", st.translate("ATG"));
+    assertEquals("V", st.translate("GTT"));
+    assertEquals("V", st.translate("GTC"));
+    assertEquals("V", st.translate("GTA"));
+    assertEquals("V", st.translate("GTG"));
+    assertEquals("S", st.translate("TCT"));
+    assertEquals("S", st.translate("TCC"));
+    assertEquals("S", st.translate("TCA"));
+    assertEquals("S", st.translate("TCG"));
+    assertEquals("P", st.translate("CCT"));
+    assertEquals("P", st.translate("CCC"));
+    assertEquals("P", st.translate("CCA"));
+    assertEquals("P", st.translate("CCG"));
+    assertEquals("T", st.translate("ACT"));
+    assertEquals("T", st.translate("ACC"));
+    assertEquals("T", st.translate("ACA"));
+    assertEquals("T", st.translate("ACG"));
+    assertEquals("A", st.translate("GCT"));
+    assertEquals("A", st.translate("GCC"));
+    assertEquals("A", st.translate("GCA"));
+    assertEquals("A", st.translate("GCG"));
+    assertEquals("Y", st.translate("TAT"));
+    assertEquals("Y", st.translate("TAC"));
+    assertEquals("*", st.translate("TAA"));
+    assertEquals("*", st.translate("TAG"));
+    assertEquals("H", st.translate("CAT"));
+    assertEquals("H", st.translate("CAC"));
+    assertEquals("Q", st.translate("CAA"));
+    assertEquals("Q", st.translate("CAG"));
+    assertEquals("N", st.translate("AAT"));
+    assertEquals("N", st.translate("AAC"));
+    assertEquals("K", st.translate("AAA"));
+    assertEquals("K", st.translate("AAG"));
+    assertEquals("D", st.translate("GAT"));
+    assertEquals("D", st.translate("GAC"));
+    assertEquals("E", st.translate("GAA"));
+    assertEquals("E", st.translate("GAG"));
+    assertEquals("C", st.translate("TGT"));
+    assertEquals("C", st.translate("TGC"));
+    assertEquals("*", st.translate("TGA"));
+    assertEquals("W", st.translate("TGG"));
+    assertEquals("R", st.translate("CGT"));
+    assertEquals("R", st.translate("CGC"));
+    assertEquals("R", st.translate("CGA"));
+    assertEquals("R", st.translate("CGG"));
+    assertEquals("S", st.translate("AGT"));
+    assertEquals("S", st.translate("AGC"));
+    assertEquals("R", st.translate("AGA"));
+    assertEquals("R", st.translate("AGG"));
+    assertEquals("G", st.translate("GGT"));
+    assertEquals("G", st.translate("GGC"));
+    assertEquals("G", st.translate("GGA"));
+    assertEquals("G", st.translate("GGG"));
+  }
+
+  /**
+   * Test a sample of codon translations involving ambiguity codes. Should
+   * return a protein value where the ambiguity does not affect the translation.
+   */
+  @Test(groups = { "Functional" })
+  public void testTranslate_standardTableAmbiguityCodes()
+  {
+    GeneticCodeI st = GeneticCodes.getInstance().getStandardCodeTable();
+    // Y is C or T
+    assertEquals("C", st.translate("TGY"));
+    // Phenylalanine first base variation
+    assertEquals("L", st.translate("YTA"));
+
+    // W is A or T
+    assertEquals("L", st.translate("CTW"));
+    assertNull(st.translate("TTW"));
+
+    // S is G or C
+    assertEquals("G", st.translate("GGS"));
+    assertNull(st.translate("ATS"));
+
+    // K is T or G
+    assertEquals("S", st.translate("TCK"));
+    assertNull(st.translate("ATK"));
+
+    // M is C or A
+    assertEquals("T", st.translate("ACM"));
+    // Arginine first base variation
+    assertEquals("R", st.translate("MGA"));
+    assertEquals("R", st.translate("MGG"));
+    assertNull(st.translate("TAM"));
+
+    // D is A, G or T
+    assertEquals("P", st.translate("CCD"));
+    assertNull(st.translate("AAD"));
+
+    // V is A, C or G
+    assertEquals("V", st.translate("GTV"));
+    assertNull(st.translate("TTV"));
+
+    // H is A, C or T
+    assertEquals("A", st.translate("GCH"));
+    assertEquals("I", st.translate("ATH"));
+    assertNull(st.translate("AGH"));
+
+    // B is C, G or T
+    assertEquals("P", st.translate("CCB"));
+    assertNull(st.translate("TAB"));
+
+    // R is A or G
+    // additional tests for JAL-1685 (resolved)
+    assertEquals("L", st.translate("CTR"));
+    assertEquals("V", st.translate("GTR"));
+    assertEquals("S", st.translate("TCR"));
+    assertEquals("P", st.translate("CCR"));
+    assertEquals("T", st.translate("ACR"));
+    assertEquals("A", st.translate("GCR"));
+    assertEquals("R", st.translate("CGR"));
+    assertEquals("G", st.translate("GGR"));
+    assertEquals("R", st.translate("AGR"));
+    assertEquals("E", st.translate("GAR"));
+    assertEquals("K", st.translate("AAR"));
+    assertEquals("L", st.translate("TTR"));
+    assertEquals("Q", st.translate("CAR"));
+    assertEquals("*", st.translate("TAR"));
+    assertEquals("*", st.translate("TRA"));
+    // Arginine first and third base ambiguity
+    assertEquals("R", st.translate("MGR"));
+    assertNull(st.translate("ATR"));
+
+    // N is any base; 8 proteins accept any base in 3rd position
+    assertEquals("L", st.translate("CTN"));
+    assertEquals("V", st.translate("GTN"));
+    assertEquals("S", st.translate("TCN"));
+    assertEquals("P", st.translate("CCN"));
+    assertEquals("T", st.translate("ACN"));
+    assertEquals("A", st.translate("GCN"));
+    assertEquals("R", st.translate("CGN"));
+    assertEquals("G", st.translate("GGN"));
+    assertNull(st.translate("ATN"));
+    assertNull(st.translate("ANT"));
+    assertNull(st.translate("NAT"));
+    assertNull(st.translate("ANN"));
+    assertNull(st.translate("NNA"));
+    assertNull(st.translate("NNN"));
+
+    // some random stuff
+    assertNull(st.translate("YWB"));
+    assertNull(st.translate("VHD"));
+    assertNull(st.translate("WSK"));
+  }
+
+  /**
+   * Test a sample of codon translations involving ambiguity codes. Should
+   * return a protein value where the ambiguity does not affect the translation.
+   */
+  @Test(groups = { "Functional" })
+  public void testTranslate_nonStandardTableAmbiguityCodes()
+  {
+    GeneticCodeI standard = GeneticCodes.getInstance()
+            .getStandardCodeTable();
+
+    /*
+     * Vertebrate Mitochondrial (Table 2)
+     */
+    GeneticCodeI gc = GeneticCodes.getInstance().getCodeTable("2");
+    // AGR is AGA or AGG - R in standard code, * in table 2
+    assertEquals(gc.translate("AGR"), "*");
+    assertEquals(standard.translate("AGR"), "R");
+    // TGR is TGA or TGG - ambiguous in standard code, W in table 2
+    assertEquals(gc.translate("TGR"), "W");
+    assertNull(standard.translate("TGR"));
+
+    /*
+     * Yeast Mitochondrial (Table 3)
+     */
+    gc = GeneticCodes.getInstance().getCodeTable("3");
+    // CTN is L in standard code, T in table 3
+    assertEquals(gc.translate("ctn"), "T");
+    assertEquals(standard.translate("CTN"), "L");
+
+    /*
+     * Alternative Yeast Nuclear (Table 12)
+     */
+    gc = GeneticCodes.getInstance().getCodeTable("12");
+    // CTG is S; in the standard code CTN is L
+    assertEquals(gc.translate("CTG"), "S");
+    assertNull(gc.translate("CTK")); // K is G or T -> S or L
+    assertEquals(standard.translate("CTK"), "L");
+    assertEquals(gc.translate("CTH"), "L"); // H is anything other than G
+    assertEquals(standard.translate("CTH"), "L");
+    assertEquals(standard.translate("CTN"), "L");
+
+    /*
+     * Trematode Mitochondrial (Table 21)
+     */
+    gc = GeneticCodes.getInstance().getCodeTable("21");
+    // AAR is K in standard code, ambiguous in table 21 as AAA=N not K
+    assertNull(gc.translate("AAR"));
+    assertEquals(standard.translate("AAR"), "K");
+  }
+
+  @Test(groups = "Functional")
+  public void testTranslateCanonical()
+  {
+    GeneticCodes codes = GeneticCodes.getInstance();
+
+    GeneticCodeI gc = codes.getCodeTable("1");
+    assertNull(gc.translateCanonical("XYZ"));
+    assertEquals(gc.translateCanonical("AGA"), "R");
+    // translateCanonical should not resolve ambiguity codes
+    assertNull(gc.translateCanonical("TGY"));
+
+    gc = codes.getCodeTable("2");
+    assertNull(gc.translateCanonical("AGR"));
+    assertEquals(gc.translateCanonical("AGA"), "*"); // variant
+    assertEquals(gc.translateCanonical("ttc"), "F"); // non-variant
+  }
+}
index 212f825..e8ffd2f 100644 (file)
@@ -44,6 +44,8 @@ public class PIDModelTest
     double newScore = PIDModel.computePID(s1, s2, params);
     double oldScore = Comparison.PID(s1, s2);
     assertEquals(newScore, oldScore, DELTA);
+    // and verify PIDModel calculation is symmetric
+    assertEquals(newScore, PIDModel.computePID(s2, s1, params));
 
     /*
      * same length, with gaps
@@ -54,6 +56,7 @@ public class PIDModelTest
     newScore = PIDModel.computePID(s1, s2, params);
     oldScore = Comparison.PID(s1, s2);
     assertEquals(newScore, oldScore, DELTA);
+    assertEquals(newScore, PIDModel.computePID(s2, s1, params));
 
     /*
      * s2 longer than s1, with gaps
@@ -64,6 +67,7 @@ public class PIDModelTest
     newScore = PIDModel.computePID(s1, s2, params);
     oldScore = Comparison.PID(s1, s2);
     assertEquals(newScore, oldScore, DELTA);
+    assertEquals(newScore, PIDModel.computePID(s2, s1, params));
 
     /*
      * s1 longer than s2, with gaps
@@ -74,6 +78,7 @@ public class PIDModelTest
     newScore = PIDModel.computePID(s1, s2, params);
     oldScore = Comparison.PID(s1, s2);
     assertEquals(newScore, oldScore, DELTA);
+    assertEquals(newScore, PIDModel.computePID(s2, s1, params));
 
     /*
      * same but now also with gapped columns
@@ -84,6 +89,7 @@ public class PIDModelTest
     newScore = PIDModel.computePID(s1, s2, params);
     oldScore = Comparison.PID(s1, s2);
     assertEquals(newScore, oldScore, DELTA);
+    assertEquals(newScore, PIDModel.computePID(s2, s1, params));
   }
 
   /**
@@ -102,6 +108,7 @@ public class PIDModelTest
      */
     SimilarityParamsI params = new SimilarityParams(true, true, true, true);
     assertEquals(PIDModel.computePID(s1, s2, params), 80d);
+    assertEquals(PIDModel.computePID(s2, s1, params), 80d);
 
     /*
      * match gap-char but not gap-gap
@@ -109,6 +116,7 @@ public class PIDModelTest
      */
     params = new SimilarityParams(false, true, true, true);
     assertEquals(PIDModel.computePID(s1, s2, params), 75d);
+    assertEquals(PIDModel.computePID(s2, s1, params), 75d);
 
     /*
      * include gaps but don't match them
@@ -117,6 +125,7 @@ public class PIDModelTest
      */
     params = new SimilarityParams(true, false, true, true);
     assertEquals(PIDModel.computePID(s1, s2, params), 40d);
+    assertEquals(PIDModel.computePID(s2, s1, params), 40d);
 
     /*
      * include gaps but don't match them
@@ -125,6 +134,7 @@ public class PIDModelTest
      */
     params = new SimilarityParams(false, false, true, true);
     assertEquals(PIDModel.computePID(s1, s2, params), 25d);
+    assertEquals(PIDModel.computePID(s2, s1, params), 25d);
   }
 
   /**
@@ -144,6 +154,7 @@ public class PIDModelTest
      */
     SimilarityParamsI params = new SimilarityParams(true, true, true, false);
     assertEquals(PIDModel.computePID(s1, s2, params), 500d / 6);
+    assertEquals(PIDModel.computePID(s2, s1, params), 500d / 6);
   
     /*
      * match gap-char but not gap-gap
@@ -151,6 +162,7 @@ public class PIDModelTest
      */
     params = new SimilarityParams(false, true, true, false);
     assertEquals(PIDModel.computePID(s1, s2, params), 80d);
+    assertEquals(PIDModel.computePID(s2, s1, params), 80d);
   
     /*
      * include gaps but don't match them
@@ -159,6 +171,7 @@ public class PIDModelTest
      */
     params = new SimilarityParams(true, false, true, false);
     assertEquals(PIDModel.computePID(s1, s2, params), 100d / 3);
+    assertEquals(PIDModel.computePID(s2, s1, params), 100d / 3);
   
     /*
      * include gaps but don't match them
@@ -167,6 +180,7 @@ public class PIDModelTest
      */
     params = new SimilarityParams(false, false, true, false);
     assertEquals(PIDModel.computePID(s1, s2, params), 20d);
+    assertEquals(PIDModel.computePID(s2, s1, params), 20d);
 
     /*
      * no tests for matchGaps=true, includeGaps=false
index 1a5d43c..15bdce1 100644 (file)
@@ -13,6 +13,7 @@ import jalview.api.analysis.SimilarityParamsI;
 import jalview.io.DataSourceType;
 import jalview.io.FileParse;
 import jalview.io.ScoreMatrixFile;
+import jalview.math.Matrix;
 import jalview.math.MatrixI;
 import jalview.schemes.ResidueProperties;
 
@@ -22,6 +23,8 @@ import java.util.Arrays;
 
 import org.testng.annotations.Test;
 
+import junit.extensions.PA;
+
 public class ScoreMatrixTest
 {
   @Test(groups = "Functional")
@@ -33,6 +36,7 @@ public class ScoreMatrixTest
     scores[1] = new float[] { -4f, 5f, 6f };
     scores[2] = new float[] { 7f, 8f, 9f };
     ScoreMatrix sm = new ScoreMatrix("Test", "ABC".toCharArray(), scores);
+    assertFalse(sm.isSymmetric());
     assertEquals(sm.getSize(), 3);
     assertArrayEquals(scores, sm.getMatrix());
     assertEquals(sm.getPairwiseScore('A', 'a'), 1f);
@@ -50,7 +54,8 @@ public class ScoreMatrixTest
 
   @Test(
     groups = "Functional",
-    expectedExceptions = { IllegalArgumentException.class })
+    expectedExceptions =
+    { IllegalArgumentException.class })
   public void testConstructor_matrixTooSmall()
   {
     float[][] scores = new float[2][];
@@ -61,7 +66,8 @@ public class ScoreMatrixTest
 
   @Test(
     groups = "Functional",
-    expectedExceptions = { IllegalArgumentException.class })
+    expectedExceptions =
+    { IllegalArgumentException.class })
   public void testConstructor_matrixTooBig()
   {
     float[][] scores = new float[2][];
@@ -72,7 +78,8 @@ public class ScoreMatrixTest
 
   @Test(
     groups = "Functional",
-    expectedExceptions = { IllegalArgumentException.class })
+    expectedExceptions =
+    { IllegalArgumentException.class })
   public void testConstructor_matrixNotSquare()
   {
     float[][] scores = new float[2][];
@@ -240,8 +247,8 @@ public class ScoreMatrixTest
    * @throws MalformedURLException
    */
   @Test(groups = "Functional")
-  public void testOutputMatrix_roundTrip() throws MalformedURLException,
-          IOException
+  public void testOutputMatrix_roundTrip()
+          throws MalformedURLException, IOException
   {
     ScoreMatrix sm = ScoreModels.getInstance().getBlosum62();
     String output = sm.outputMatrix(false);
@@ -256,8 +263,8 @@ public class ScoreMatrixTest
   public void testEqualsAndHashCode()
   {
     ScoreMatrix sm = ScoreModels.getInstance().getBlosum62();
-    ScoreMatrix sm2 = new ScoreMatrix(sm.getName(), sm.getSymbols()
-            .toCharArray(), sm.getMatrix());
+    ScoreMatrix sm2 = new ScoreMatrix(sm.getName(),
+            sm.getSymbols().toCharArray(), sm.getMatrix());
     assertTrue(sm.equals(sm2));
     assertEquals(sm.hashCode(), sm2.hashCode());
 
@@ -280,19 +287,20 @@ public class ScoreMatrixTest
     String s1 = "FR-K-S";
     String s2 = "FS--L";
     ScoreMatrix blosum = ScoreModels.getInstance().getBlosum62();
-  
+
     /*
      * score gap-gap and gap-char
      * shorter sequence treated as if with trailing gaps
      * score = F^F + R^S + -^- + K^- + -^L + S^-
      * = 6 + -1 + 1 + -4 + -4 + -4 = -6
      */
-    SimilarityParamsI params = new SimilarityParams(true, true, true, false);
+    SimilarityParamsI params = new SimilarityParams(true, true, true,
+            false);
     assertEquals(blosum.computeSimilarity(s1, s2, params), -6d);
     // matchGap (arg2) is ignored:
     params = new SimilarityParams(true, false, true, false);
     assertEquals(blosum.computeSimilarity(s1, s2, params), -6d);
-  
+
     /*
      * score gap-char but not gap-gap
      * score = F^F + R^S + 0 + K^- + -^L + S^-
@@ -303,7 +311,7 @@ public class ScoreMatrixTest
     // matchGap (arg2) is ignored:
     params = new SimilarityParams(false, false, true, false);
     assertEquals(blosum.computeSimilarity(s1, s2, params), -7d);
-  
+
     /*
      * score gap-gap but not gap-char
      * score = F^F + R^S + -^- + 0 + 0 + 0
@@ -314,7 +322,7 @@ public class ScoreMatrixTest
     // matchGap (arg2) is ignored:
     params = new SimilarityParams(true, true, false, false);
     assertEquals(blosum.computeSimilarity(s1, s2, params), 6d);
-  
+
     /*
      * score neither gap-gap nor gap-char
      * score = F^F + R^S + 0 + 0 + 0 + 0
@@ -352,7 +360,7 @@ public class ScoreMatrixTest
     // matchGap (arg2) is ignored:
     params = new SimilarityParams(true, false, true, true);
     assertEquals(blosum.computeSimilarity(s1, s2, params), -2d);
-  
+
     /*
      * score gap-char but not gap-gap
      * score = F^F + R^S + 0 + K^- + -^L
@@ -363,7 +371,7 @@ public class ScoreMatrixTest
     // matchGap (arg2) is ignored:
     params = new SimilarityParams(false, false, true, true);
     assertEquals(blosum.computeSimilarity(s1, s2, params), -3d);
-  
+
     /*
      * score gap-gap but not gap-char
      * score = F^F + R^S + -^- + 0 + 0
@@ -374,7 +382,7 @@ public class ScoreMatrixTest
     // matchGap (arg2) is ignored:
     params = new SimilarityParams(true, true, false, true);
     assertEquals(blosum.computeSimilarity(s1, s2, params), 6d);
-  
+
     /*
      * score neither gap-gap nor gap-char
      * score = F^F + R^S + 0 + 0 + 0
@@ -395,6 +403,12 @@ public class ScoreMatrixTest
     verifySymmetric(ScoreModels.getInstance().getDefaultModel(false)); // dna
   }
 
+  /**
+   * A helper method that inspects a loaded matrix and reports any asymmetry as
+   * a test failure
+   * 
+   * @param sm
+   */
   private void verifySymmetric(ScoreMatrix sm)
   {
     float[][] m = sm.getMatrix();
@@ -404,9 +418,10 @@ public class ScoreMatrixTest
       assertEquals(m[row].length, rows);
       for (int col = 0; col < rows; col++)
       {
-        assertEquals(m[row][col], m[col][row], String.format("%s [%s, %s]",
-                sm.getName(), ResidueProperties.aa[row],
-                ResidueProperties.aa[col]));
+        assertEquals(m[row][col], m[col][row],
+                String.format("%s [%s, %s]", sm.getName(),
+                        ResidueProperties.aa[row],
+                        ResidueProperties.aa[col]));
       }
     }
   }
@@ -427,63 +442,98 @@ public class ScoreMatrixTest
      * verify expected scores against ARNDCQEGHILKMFPSTWYVBZX
      * scraped from https://www.ncbi.nlm.nih.gov/Class/FieldGuide/BLOSUM62.txt
      */
-    verifyValues(sm, 'A', new float[] { 4, -1, -2, -2, 0, -1, -1, 0, -2,
-        -1,
-        -1, -1, -1, -2, -1, 1, 0, -3, -2, 0, -2, -1, 0 });
-    verifyValues(sm, 'R', new float[] { -1, 5, 0, -2, -3, 1, 0, -2, 0, -3,
-        -2, 2, -1, -3, -2, -1, -1, -3, -2, -3, -1, 0, -1 });
-    verifyValues(sm, 'N', new float[] { -2, 0, 6, 1, -3, 0, 0, 0, 1, -3,
-        -3,
-        0, -2, -3, -2, 1, 0, -4, -2, -3, 3, 0, -1 });
-    verifyValues(sm, 'D', new float[] { -2, -2, 1, 6, -3, 0, 2, -1, -1, -3,
-        -4, -1, -3, -3, -1, 0, -1, -4, -3, -3, 4, 1, -1 });
-    verifyValues(sm, 'C', new float[] { 0, -3, -3, -3, 9, -3, -4, -3, -3,
-        -1,
-        -1, -3, -1, -2, -3, -1, -1, -2, -2, -1, -3, -3, -2 });
-    verifyValues(sm, 'Q', new float[] { -1, 1, 0, 0, -3, 5, 2, -2, 0, -3,
-        -2,
-        1, 0, -3, -1, 0, -1, -2, -1, -2, 0, 3, -1 });
-    verifyValues(sm, 'E', new float[] { -1, 0, 0, 2, -4, 2, 5, -2, 0, -3,
-        -3,
-        1, -2, -3, -1, 0, -1, -3, -2, -2, 1, 4, -1 });
-    verifyValues(sm, 'G', new float[] { 0, -2, 0, -1, -3, -2, -2, 6, -2,
-        -4,
-        -4, -2, -3, -3, -2, 0, -2, -2, -3, -3, -1, -2, -1 });
-    verifyValues(sm, 'H', new float[] { -2, 0, 1, -1, -3, 0, 0, -2, 8, -3,
-        -3, -1, -2, -1, -2, -1, -2, -2, 2, -3, 0, 0, -1 });
-    verifyValues(sm, 'I', new float[] { -1, -3, -3, -3, -1, -3, -3, -4, -3,
-        4, 2, -3, 1, 0, -3, -2, -1, -3, -1, 3, -3, -3, -1 });
-    verifyValues(sm, 'L', new float[] { -1, -2, -3, -4, -1, -2, -3, -4, -3,
-        2, 4, -2, 2, 0, -3, -2, -1, -2, -1, 1, -4, -3, -1 });
-    verifyValues(sm, 'K', new float[] { -1, 2, 0, -1, -3, 1, 1, -2, -1, -3,
-        -2, 5, -1, -3, -1, 0, -1, -3, -2, -2, 0, 1, -1 });
-    verifyValues(sm, 'M', new float[] { -1, -1, -2, -3, -1, 0, -2, -3, -2,
-        1,
-        2, -1, 5, 0, -2, -1, -1, -1, -1, 1, -3, -1, -1 });
-    verifyValues(sm, 'F', new float[] { -2, -3, -3, -3, -2, -3, -3, -3, -1,
-        0, 0, -3, 0, 6, -4, -2, -2, 1, 3, -1, -3, -3, -1 });
-    verifyValues(sm, 'P', new float[] { -1, -2, -2, -1, -3, -1, -1, -2, -2,
-        -3, -3, -1, -2, -4, 7, -1, -1, -4, -3, -2, -2, -1, -2 });
-    verifyValues(sm, 'S', new float[] { 1, -1, 1, 0, -1, 0, 0, 0, -1, -2,
-        -2,
-        0, -1, -2, -1, 4, 1, -3, -2, -2, 0, 0, 0 });
-    verifyValues(sm, 'T', new float[] { 0, -1, 0, -1, -1, -1, -1, -2, -2,
-        -1,
-        -1, -1, -1, -2, -1, 1, 5, -2, -2, 0, -1, -1, 0 });
-    verifyValues(sm, 'W', new float[] { -3, -3, -4, -4, -2, -2, -3, -2, -2,
-        -3, -2, -3, -1, 1, -4, -3, -2, 11, 2, -3, -4, -3, -2 });
-    verifyValues(sm, 'Y', new float[] { -2, -2, -2, -3, -2, -1, -2, -3, 2,
-        -1, -1, -2, -1, 3, -3, -2, -2, 2, 7, -1, -3, -2, -1 });
-    verifyValues(sm, 'V', new float[] { 0, -3, -3, -3, -1, -2, -2, -3, -3,
-        3,
-        1, -2, 1, -1, -2, -2, 0, -3, -1, 4, -3, -2, -1 });
-    verifyValues(sm, 'B', new float[] { -2, -1, 3, 4, -3, 0, 1, -1, 0, -3,
-        -4, 0, -3, -3, -2, 0, -1, -4, -3, -3, 4, 1, -1 });
-    verifyValues(sm, 'Z', new float[] { -1, 0, 0, 1, -3, 3, 4, -2, 0, -3,
-        -3,
-        1, -1, -3, -1, 0, -1, -3, -2, -2, 1, 4, -1 });
-    verifyValues(sm, 'X', new float[] { 0, -1, -1, -1, -2, -1, -1, -1, -1,
-        -1, -1, -1, -1, -1, -2, 0, 0, -2, -1, -1, -1, -1, -1 });
+    verifyValues(sm, 'A',
+            new float[]
+            { 4, -1, -2, -2, 0, -1, -1, 0, -2, -1, -1, -1, -1, -2, -1, 1, 0,
+                -3, -2, 0, -2, -1, 0 });
+    verifyValues(sm, 'R',
+            new float[]
+            { -1, 5, 0, -2, -3, 1, 0, -2, 0, -3, -2, 2, -1, -3, -2, -1, -1,
+                -3, -2, -3, -1, 0, -1 });
+    verifyValues(sm, 'N',
+            new float[]
+            { -2, 0, 6, 1, -3, 0, 0, 0, 1, -3, -3, 0, -2, -3, -2, 1, 0, -4,
+                -2, -3, 3, 0, -1 });
+    verifyValues(sm, 'D',
+            new float[]
+            { -2, -2, 1, 6, -3, 0, 2, -1, -1, -3, -4, -1, -3, -3, -1, 0, -1,
+                -4, -3, -3, 4, 1, -1 });
+    verifyValues(sm, 'C',
+            new float[]
+            { 0, -3, -3, -3, 9, -3, -4, -3, -3, -1, -1, -3, -1, -2, -3, -1,
+                -1, -2, -2, -1, -3, -3, -2 });
+    verifyValues(sm, 'Q',
+            new float[]
+            { -1, 1, 0, 0, -3, 5, 2, -2, 0, -3, -2, 1, 0, -3, -1, 0, -1, -2,
+                -1, -2, 0, 3, -1 });
+    verifyValues(sm, 'E',
+            new float[]
+            { -1, 0, 0, 2, -4, 2, 5, -2, 0, -3, -3, 1, -2, -3, -1, 0, -1,
+                -3, -2, -2, 1, 4, -1 });
+    verifyValues(sm, 'G',
+            new float[]
+            { 0, -2, 0, -1, -3, -2, -2, 6, -2, -4, -4, -2, -3, -3, -2, 0,
+                -2, -2, -3, -3, -1, -2, -1 });
+    verifyValues(sm, 'H',
+            new float[]
+            { -2, 0, 1, -1, -3, 0, 0, -2, 8, -3, -3, -1, -2, -1, -2, -1, -2,
+                -2, 2, -3, 0, 0, -1 });
+    verifyValues(sm, 'I',
+            new float[]
+            { -1, -3, -3, -3, -1, -3, -3, -4, -3, 4, 2, -3, 1, 0, -3, -2,
+                -1, -3, -1, 3, -3, -3, -1 });
+    verifyValues(sm, 'L',
+            new float[]
+            { -1, -2, -3, -4, -1, -2, -3, -4, -3, 2, 4, -2, 2, 0, -3, -2,
+                -1, -2, -1, 1, -4, -3, -1 });
+    verifyValues(sm, 'K',
+            new float[]
+            { -1, 2, 0, -1, -3, 1, 1, -2, -1, -3, -2, 5, -1, -3, -1, 0, -1,
+                -3, -2, -2, 0, 1, -1 });
+    verifyValues(sm, 'M',
+            new float[]
+            { -1, -1, -2, -3, -1, 0, -2, -3, -2, 1, 2, -1, 5, 0, -2, -1, -1,
+                -1, -1, 1, -3, -1, -1 });
+    verifyValues(sm, 'F',
+            new float[]
+            { -2, -3, -3, -3, -2, -3, -3, -3, -1, 0, 0, -3, 0, 6, -4, -2,
+                -2, 1, 3, -1, -3, -3, -1 });
+    verifyValues(sm, 'P',
+            new float[]
+            { -1, -2, -2, -1, -3, -1, -1, -2, -2, -3, -3, -1, -2, -4, 7, -1,
+                -1, -4, -3, -2, -2, -1, -2 });
+    verifyValues(sm, 'S',
+            new float[]
+            { 1, -1, 1, 0, -1, 0, 0, 0, -1, -2, -2, 0, -1, -2, -1, 4, 1, -3,
+                -2, -2, 0, 0, 0 });
+    verifyValues(sm, 'T',
+            new float[]
+            { 0, -1, 0, -1, -1, -1, -1, -2, -2, -1, -1, -1, -1, -2, -1, 1,
+                5, -2, -2, 0, -1, -1, 0 });
+    verifyValues(sm, 'W',
+            new float[]
+            { -3, -3, -4, -4, -2, -2, -3, -2, -2, -3, -2, -3, -1, 1, -4, -3,
+                -2, 11, 2, -3, -4, -3, -2 });
+    verifyValues(sm, 'Y',
+            new float[]
+            { -2, -2, -2, -3, -2, -1, -2, -3, 2, -1, -1, -2, -1, 3, -3, -2,
+                -2, 2, 7, -1, -3, -2, -1 });
+    verifyValues(sm, 'V',
+            new float[]
+            { 0, -3, -3, -3, -1, -2, -2, -3, -3, 3, 1, -2, 1, -1, -2, -2, 0,
+                -3, -1, 4, -3, -2, -1 });
+    verifyValues(sm, 'B',
+            new float[]
+            { -2, -1, 3, 4, -3, 0, 1, -1, 0, -3, -4, 0, -3, -3, -2, 0, -1,
+                -4, -3, -3, 4, 1, -1 });
+    verifyValues(sm, 'Z',
+            new float[]
+            { -1, 0, 0, 1, -3, 3, 4, -2, 0, -3, -3, 1, -1, -3, -1, 0, -1,
+                -3, -2, -2, 1, 4, -1 });
+    verifyValues(sm, 'X',
+            new float[]
+            { 0, -1, -1, -1, -2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -2, 0,
+                0, -2, -1, -1, -1, -1, -1 });
   }
 
   /**
@@ -585,4 +635,76 @@ public class ScoreMatrixTest
             + "</table>";
     assertEquals(html, expected);
   }
+
+  @Test(groups = "Functional")
+  public void testIsSymmetric()
+  {
+    double delta = 0.0001d;
+    float[][] scores = new float[][] { { 1f, -2f }, { -2f, 3f } };
+    ScoreMatrix sm = new ScoreMatrix("Test", "AB".toCharArray(), scores);
+    assertTrue(sm.isSymmetric());
+
+    /*
+     * verify that with a symmetric score matrix,
+     * pairwise similarity matrix is also symmetric
+     * seq1.seq1 = 5*A.A + 3*B.B = 5+9 = 14
+     * seq1.seq2 = 3*A.A + 2*A.B + B.A + 2*B.B = 3 + -4 + -2 + 6 = 3
+     * seq2.seq1 = 3*A.A + A.B + 2*B.A + 2*B.B = 3 + -2 + -4 + 6 = 3   
+     * seq2.seq2 = 4*A.A + 4*B.B = 4 + 12 = 16   
+     */
+    SimilarityParamsI params = new SimilarityParams(true, true, true,
+            false);
+    String seq1 = "AAABBBAA";
+    String seq2 = "AABBABBA";
+    String[] seqs1 = new String[] { seq1, seq2 };
+    MatrixI res1 = sm.findSimilarities(seqs1, params);
+    assertTrue(
+            res1.equals(new Matrix(new double[][]
+            { { 14d, 3d }, { 3d, 16d } }), delta));
+
+    /*
+     * order of sequences affects diagonal, but not off-diagonal values
+     * [0, 0] is now seq2.seq2, [1, 1] is seq1.seq1
+     * [0, 1] is now seq2.seq1 = seq1.seq2 by symmetry
+     */
+    String[] seqs2 = new String[] { seq2, seq1 };
+    MatrixI res2 = sm.findSimilarities(seqs2, params);
+    assertFalse(res1.equals(res2));
+    assertTrue(res2.equals(new Matrix(new double[][]
+            { { 16d, 3d }, { 3d, 14d } }), delta));
+
+    /*
+     * now make the score matrix asymmetric
+     * seq1.seq1 = 5*A.A + 3*B.B = 5+9 = 14
+     * seq1.seq2 = 3*A.A + 2*A.B + B.A + 2*B.B = 3 + -4 + 2 + 6 = 7
+     * seq2.seq1 = 3*A.A + A.B + 2*B.A + 2*B.B = 3 + -2 + 4 + 6 = 11  
+     * seq2.seq2 = 4*A.A + 4*B.B = 4 + 12 = 16   
+     */
+    scores = new float[][] { { 1f, -2f }, { 2f, 3f } };
+    sm = new ScoreMatrix("Test", "AB".toCharArray(), scores);
+    assertFalse(sm.isSymmetric()); // [0, 1] != [1, 0]
+    res1 = sm.findSimilarities(seqs1, params);
+    assertTrue(res1.equals(new Matrix(new double[][]
+            { { 14d, 7d }, { 11d, 16d } }), delta));
+
+    /*
+     * reverse order of sequences
+     * - reverses order of main diagonal
+     * - reflects off-diagonal values
+     */
+    res2 = sm.findSimilarities(seqs2, params);
+    assertFalse(res1.equals(res2));
+    assertTrue(
+            res2.equals(new Matrix(new double[][]
+            { { 16d, 11d }, { 7d, 14d } }), delta));
+
+    /*
+     * verify that forcing an asymmetric matrix to use
+     * symmetric calculation gives a different (wrong) result
+     */
+    PA.setValue(sm, "symmetric", true);
+    assertTrue(sm.isSymmetric()); // it's not true!
+    res2 = sm.findSimilarities(seqs1, params);
+    assertFalse(res1.equals(res2, delta));
+  }
 }
index ffcd1a8..5e44d3d 100644 (file)
@@ -45,16 +45,16 @@ public class ScoreModelsTest
     assertTrue(sm instanceof SimilarityScoreModel);
     assertTrue(sm instanceof PairwiseScoreModelI);
     assertFalse(sm instanceof DistanceScoreModel);
-    assertEquals(sm.getName(), "PID");
-    assertEquals(((PairwiseScoreModelI) sm).getPairwiseScore('R', 'C'), 0f);
-    assertEquals(((PairwiseScoreModelI) sm).getPairwiseScore('R', 'r'), 1f);
+    assertEquals(sm.getName(), "DNA");
+    assertEquals(((PairwiseScoreModelI) sm).getPairwiseScore('c', 'x'), 1f);
 
     sm = models.next();
     assertTrue(sm instanceof SimilarityScoreModel);
     assertTrue(sm instanceof PairwiseScoreModelI);
     assertFalse(sm instanceof DistanceScoreModel);
-    assertEquals(sm.getName(), "DNA");
-    assertEquals(((PairwiseScoreModelI) sm).getPairwiseScore('c', 'x'), 1f);
+    assertEquals(sm.getName(), "PID");
+    assertEquals(((PairwiseScoreModelI) sm).getPairwiseScore('R', 'C'), 0f);
+    assertEquals(((PairwiseScoreModelI) sm).getPairwiseScore('R', 'r'), 1f);
 
     sm = models.next();
     assertFalse(sm instanceof SimilarityScoreModel);
index 4017931..483bb8b 100644 (file)
@@ -281,9 +281,8 @@ public class CommandLineOperations
             "Failed command : -open examples/uniref50.fa" },
         { "CMD [-nosortbytree] executed successfully!",
             "Failed command : -nosortbytree" },
-        { "CMD [-dasserver nickname=www.test.com] executed successfully!",
-            "Failed command : -dasserver nickname=www.test.com" },
-        { "CMD [-features examples/testdata/plantfdx.features]  executed successfully!",
+        {
+            "CMD [-features examples/testdata/plantfdx.features]  executed successfully!",
             "Failed command : -features examples/testdata/plantfdx.features" },
         { "CMD [-annotations examples/testdata/plantfdx.annotations] executed successfully!",
             "Failed command : -annotations examples/testdata/plantfdx.annotations" },
@@ -293,7 +292,7 @@ public class CommandLineOperations
         { "CMD [-nousagestats] executed successfully!",
             "Failed command : -nousagestats" },
         { "CMD [-noquestionnaire] executed successfully!",
-            "Failed command : -noquestionnaire nickname=www.test.com" } };
+            "Failed command : -noquestionnaire" } };
 
   }
 
index 155f00e..2160657 100644 (file)
@@ -21,8 +21,8 @@
 package jalview.commands;
 
 import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNull;
 import static org.testng.AssertJUnit.assertSame;
+import static org.testng.AssertJUnit.assertTrue;
 
 import jalview.commands.EditCommand.Action;
 import jalview.commands.EditCommand.Edit;
@@ -34,6 +34,8 @@ import jalview.datamodel.SequenceI;
 import jalview.datamodel.features.SequenceFeatures;
 import jalview.gui.JvOptionPane;
 
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.List;
 import java.util.Map;
 
@@ -50,6 +52,22 @@ import org.testng.annotations.Test;
  */
 public class EditCommandTest
 {
+  private static Comparator<SequenceFeature> BY_DESCRIPTION = new Comparator<SequenceFeature>()
+  {
+
+    @Override
+    public int compare(SequenceFeature o1, SequenceFeature o2)
+    {
+      return o1.getDescription().compareTo(o2.getDescription());
+    }
+  };
+
+  private EditCommand testee;
+
+  private SequenceI[] seqs;
+
+  private Alignment al;
+
   /*
    * compute n(n+1)/2 e.g. 
    * func(5) = 5 + 4 + 3 + 2 + 1 = 15
@@ -66,12 +84,6 @@ public class EditCommandTest
     JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
   }
 
-  private EditCommand testee;
-
-  private SequenceI[] seqs;
-
-  private Alignment al;
-
   @BeforeMethod(alwaysRun = true)
   public void setUp()
   {
@@ -141,18 +153,23 @@ public class EditCommandTest
   }
 
   /**
-   * Test a Paste action, where this adds sequences to an alignment.
+   * Test a Paste action, followed by Undo and Redo
    */
   @Test(groups = { "Functional" }, enabled = false)
-  // TODO fix so it works
-  public void testPaste_addToAlignment()
+  public void testPaste_undo_redo()
   {
+    // TODO code this test properly, bearing in mind that:
+    // Paste action requires something on the clipboard (Cut/Copy)
+    // - EditCommand.paste doesn't add sequences to the alignment
+    // ... that is done in AlignFrame.paste()
+    // ... unless as a Redo
+    // ...
+
     SequenceI[] newSeqs = new SequenceI[2];
     newSeqs[0] = new Sequence("newseq0", "ACEFKL");
     newSeqs[1] = new Sequence("newseq1", "JWMPDH");
 
-    Edit ec = testee.new Edit(Action.PASTE, newSeqs, 0, al.getWidth(), al);
-    EditCommand.paste(ec, new AlignmentI[] { al });
+    new EditCommand("Paste", Action.PASTE, newSeqs, 0, al.getWidth(), al);
     assertEquals(6, al.getSequences().size());
     assertEquals("1234567890", seqs[3].getSequenceAsString());
     assertEquals("ACEFKL", seqs[4].getSequenceAsString());
@@ -262,12 +279,123 @@ public class EditCommandTest
   {
     // seem to need a dataset sequence on the edited sequence here
     seqs[1].createDatasetSequence();
-    new EditCommand("", Action.REPLACE, "ZXY", new SequenceI[] { seqs[1] },
+    assertEquals("fghjklmnopq", seqs[1].getSequenceAsString());
+    // NB command.number holds end position for a Replace command
+    new EditCommand("", Action.REPLACE, "Z-xY", new SequenceI[] { seqs[1] },
             4, 8, al);
     assertEquals("abcdefghjk", seqs[0].getSequenceAsString());
+    assertEquals("fghjZ-xYopq", seqs[1].getSequenceAsString());
+    assertEquals("fghjZxYopq",
+            seqs[1].getDatasetSequence().getSequenceAsString());
     assertEquals("qrstuvwxyz", seqs[2].getSequenceAsString());
     assertEquals("1234567890", seqs[3].getSequenceAsString());
-    seqs[1] = new Sequence("seq1", "fghjZXYnopq");
+  }
+
+  /**
+   * Test the replace command (used to manually edit a sequence)
+   */
+  @Test(groups = { "Functional" })
+  public void testReplace_withGaps()
+  {
+    SequenceI seq = new Sequence("seq", "ABC--DEF");
+    seq.createDatasetSequence();
+    assertEquals("ABCDEF", seq.getDatasetSequence().getSequenceAsString());
+    assertEquals(1, seq.getStart());
+    assertEquals(6, seq.getEnd());
+
+    /*
+     * replace C- with XYZ
+     * NB arg4 = start column of selection for edit (base 0)
+     * arg5 = column after end of selection for edit
+     */
+    EditCommand edit = new EditCommand("", Action.REPLACE, "xyZ",
+            new SequenceI[]
+            { seq }, 2,
+            4, al);
+    assertEquals("ABxyZ-DEF", seq.getSequenceAsString());
+    assertEquals(1, seq.getStart());
+    assertEquals(8, seq.getEnd());
+    assertEquals("ABxyZDEF",
+            seq.getDatasetSequence().getSequenceAsString());
+    assertEquals(8, seq.getDatasetSequence().getEnd());
+
+    /*
+     * undo the edit
+     */
+    AlignmentI[] views = new AlignmentI[]
+    { new Alignment(new SequenceI[] { seq }) };
+    edit.undoCommand(views);
+
+    assertEquals("ABC--DEF", seq.getSequenceAsString());
+    assertEquals("ABCDEF", seq.getDatasetSequence().getSequenceAsString());
+    assertEquals(1, seq.getStart());
+    assertEquals(6, seq.getEnd());
+    assertEquals(6, seq.getDatasetSequence().getEnd());
+
+    /*
+     * redo the edit
+     */
+    edit.doCommand(views);
+
+    assertEquals("ABxyZ-DEF", seq.getSequenceAsString());
+    assertEquals(1, seq.getStart());
+    assertEquals(8, seq.getEnd());
+    assertEquals("ABxyZDEF",
+            seq.getDatasetSequence().getSequenceAsString());
+    assertEquals(8, seq.getDatasetSequence().getEnd());
+
+  }
+
+  /**
+   * Test replace command when it doesn't cause a sequence edit (see comment in
+   */
+  @Test(groups = { "Functional" })
+  public void testReplaceFirstResiduesWithGaps()
+  {
+    // test replace when gaps are inserted at start. Start/end should change
+    // w.r.t. original edited sequence.
+    SequenceI dsseq = seqs[1].getDatasetSequence();
+    EditCommand edit = new EditCommand("", Action.REPLACE, "----",
+            new SequenceI[]
+            { seqs[1] }, 0, 4, al);
+
+    // trimmed start
+    assertEquals("----klmnopq", seqs[1].getSequenceAsString());
+    // and ds is preserved
+    assertTrue(dsseq == seqs[1].getDatasetSequence());
+    // and it is unchanged
+    assertEquals("fghjklmnopq", dsseq.getSequenceAsString());
+    // and that alignment sequence start has been adjusted
+    assertEquals(5, seqs[1].getStart());
+    assertEquals(11, seqs[1].getEnd());
+
+    AlignmentI[] views = new AlignmentI[] { new Alignment(seqs) };
+    // and undo
+    edit.undoCommand(views);
+
+    // dataset sequence unchanged
+    assertTrue(dsseq == seqs[1].getDatasetSequence());
+    // restore sequence
+    assertEquals("fghjklmnopq", seqs[1].getSequenceAsString());
+    // and start/end numbering also restored
+    assertEquals(1, seqs[1].getStart());
+    assertEquals(11, seqs[1].getEnd());
+
+    // now redo
+    edit.undoCommand(views);
+
+    // and repeat asserts for the original edit
+
+    // trimmed start
+    assertEquals("----klmnopq", seqs[1].getSequenceAsString());
+    // and ds is preserved
+    assertTrue(dsseq == seqs[1].getDatasetSequence());
+    // and it is unchanged
+    assertEquals("fghjklmnopq", dsseq.getSequenceAsString());
+    // and that alignment sequence start has been adjusted
+    assertEquals(5, seqs[1].getStart());
+    assertEquals(11, seqs[1].getEnd());
+
   }
 
   /**
@@ -663,7 +791,7 @@ public class EditCommandTest
      * create sequence features before, after and overlapping
      * a cut of columns/residues 4-7
      */
-    SequenceI seq0 = seqs[0];
+    SequenceI seq0 = seqs[0]; // abcdefghjk/1-10
     seq0.addSequenceFeature(new SequenceFeature("before", "", 1, 3, 0f,
             null));
     seq0.addSequenceFeature(new SequenceFeature("overlap left", "", 2, 6,
@@ -675,29 +803,52 @@ public class EditCommandTest
     seq0.addSequenceFeature(new SequenceFeature("after", "", 8, 10, 0f,
             null));
 
+    /*
+     * add some contact features
+     */
+    SequenceFeature internalContact = new SequenceFeature("disulphide bond", "", 5,
+            6, 0f, null);
+    seq0.addSequenceFeature(internalContact); // should get deleted
+    SequenceFeature overlapLeftContact = new SequenceFeature(
+            "disulphide bond", "", 2, 6, 0f, null);
+    seq0.addSequenceFeature(overlapLeftContact); // should get deleted
+    SequenceFeature overlapRightContact = new SequenceFeature(
+            "disulphide bond", "", 5, 8, 0f, null);
+    seq0.addSequenceFeature(overlapRightContact); // should get deleted
+    SequenceFeature spanningContact = new SequenceFeature(
+            "disulphide bond", "", 2, 9, 0f, null);
+    seq0.addSequenceFeature(spanningContact); // should get shortened 3'
+
+    /*
+     * cut columns 3-6 (base 0), residues d-g 4-7
+     */
     Edit ec = testee.new Edit(Action.CUT, seqs, 3, 4, al); // cols 3-6 base 0
     EditCommand.cut(ec, new AlignmentI[] { al });
 
     List<SequenceFeature> sfs = seq0.getSequenceFeatures();
     SequenceFeatures.sortFeatures(sfs, true);
 
-    assertEquals(4, sfs.size()); // feature internal to cut has been deleted
+    assertEquals(5, sfs.size()); // features internal to cut were deleted
     SequenceFeature sf = sfs.get(0);
     assertEquals("before", sf.getType());
     assertEquals(1, sf.getBegin());
     assertEquals(3, sf.getEnd());
     sf = sfs.get(1);
+    assertEquals("disulphide bond", sf.getType());
+    assertEquals(2, sf.getBegin());
+    assertEquals(5, sf.getEnd()); // truncated by cut
+    sf = sfs.get(2);
     assertEquals("overlap left", sf.getType());
     assertEquals(2, sf.getBegin());
     assertEquals(3, sf.getEnd()); // truncated by cut
-    sf = sfs.get(2);
-    assertEquals("overlap right", sf.getType());
-    assertEquals(4, sf.getBegin()); // shifted left by cut
-    assertEquals(5, sf.getEnd()); // truncated by cut
     sf = sfs.get(3);
     assertEquals("after", sf.getType());
     assertEquals(4, sf.getBegin()); // shifted left by cut
     assertEquals(6, sf.getEnd()); // shifted left by cut
+    sf = sfs.get(4);
+    assertEquals("overlap right", sf.getType());
+    assertEquals(4, sf.getBegin()); // shifted left by cut
+    assertEquals(4, sf.getEnd()); // truncated by cut
   }
 
   /**
@@ -711,16 +862,28 @@ public class EditCommandTest
      * create a sequence features on each subrange of 1-5
      */
     SequenceI seq0 = new Sequence("seq", "ABCDE");
+    int start = 8;
+    int end = 12;
+    seq0.setStart(start);
+    seq0.setEnd(end);
     AlignmentI alignment = new Alignment(new SequenceI[] { seq0 });
     alignment.setDataset(null);
-    for (int from = 1; from <= seq0.getLength(); from++)
+
+    /*
+     * create a new alignment with shared dataset sequence
+     */
+    AlignmentI copy = new Alignment(
+            new SequenceI[]
+            { alignment.getDataset().getSequenceAt(0).deriveSequence() });
+    SequenceI copySeq0 = copy.getSequenceAt(0);
+
+    for (int from = start; from <= end; from++)
     {
-      for (int to = from; to <= seq0.getLength(); to++)
+      for (int to = from; to <= end; to++)
       {
         String desc = String.format("%d-%d", from, to);
         SequenceFeature sf = new SequenceFeature("test", desc, from, to,
-                0f,
-                null);
+                0f, null);
         sf.setValue("from", Integer.valueOf(from));
         sf.setValue("to", Integer.valueOf(to));
         seq0.addSequenceFeature(sf);
@@ -729,109 +892,234 @@ public class EditCommandTest
     // sanity check
     List<SequenceFeature> sfs = seq0.getSequenceFeatures();
     assertEquals(func(5), sfs.size());
+    assertEquals(sfs, copySeq0.getSequenceFeatures());
+    String copySequenceFeatures = copySeq0.getSequenceFeatures().toString();
 
     /*
-     * now perform all possible cuts of subranges of 1-5 (followed by Undo)
+     * now perform all possible cuts of subranges of columns 1-5
      * and validate the resulting remaining sequence features!
      */
     SequenceI[] sqs = new SequenceI[] { seq0 };
 
-    // goal is to have this passing for all from/to values!!
-    // for (int from = 0; from < seq0.getLength(); from++)
-    // {
-    // for (int to = from; to < seq0.getLength(); to++)
-    for (int from = 1; from < 3; from++)
+    for (int from = 0; from < seq0.getLength(); from++)
     {
-      for (int to = 2; to < 3; to++)
+      for (int to = from; to < seq0.getLength(); to++)
       {
-        testee.appendEdit(Action.CUT, sqs, from, (to - from + 1),
-                alignment, true);
+        EditCommand ec = new EditCommand("Cut", Action.CUT, sqs, from, (to
+                - from + 1), alignment);
+        final String msg = String.format("Cut %d-%d ", from + 1, to + 1);
+        boolean newDatasetSequence = copySeq0.getDatasetSequence() != seq0
+                .getDatasetSequence();
+
+        verifyCut(seq0, from, to, msg, start);
+
+        /*
+         * verify copy alignment dataset sequence unaffected
+         */
+        assertEquals("Original dataset sequence was modified",
+                copySequenceFeatures,
+                copySeq0.getSequenceFeatures().toString());
 
+        /*
+         * verify any new dataset sequence was added to the
+         * alignment dataset
+         */
+        assertEquals("Wrong Dataset size after " + msg,
+                newDatasetSequence ? 2 : 1,
+                alignment.getDataset().getHeight());
+
+        /*
+         * undo and verify all restored
+         */
+        AlignmentI[] views = new AlignmentI[] { alignment };
+        ec.undoCommand(views);
         sfs = seq0.getSequenceFeatures();
+        assertEquals("After undo of " + msg, func(5), sfs.size());
+        verifyUndo(from, to, sfs);
+
+        /*
+         * verify copy alignment dataset sequence still unaffected
+         * and alignment dataset has shrunk (if it was added to)
+         */
+        assertEquals("Original dataset sequence was modified",
+                copySequenceFeatures,
+                copySeq0.getSequenceFeatures().toString());
+        assertEquals("Wrong Dataset size after Undo of " + msg, 1,
+                alignment.getDataset().getHeight());
 
         /*
-         * confirm the number of features has reduced by the
-         * number of features within the cut region i.e. by
-         * func(length of cut)
+         * redo and verify
          */
-        String msg = String.format("Cut %d-%d ", from, to);
-        if (to - from == 4)
-        {
-          // all columns cut
-          assertNull(sfs);
-        }
-        else
-        {
-          assertEquals(msg + "wrong number of features left", func(5)
-                  - func(to - from + 1), sfs.size());
-        }
+        ec.doCommand(views);
+        verifyCut(seq0, from, to, msg, start);
 
         /*
-         * inspect individual features
+         * verify copy alignment dataset sequence unaffected
+         * and any new dataset sequence readded to alignment dataset
          */
-        if (sfs != null)
-        {
-          for (SequenceFeature sf : sfs)
-          {
-            checkFeatureRelocation(sf, from + 1, to + 1);
-          }
-        }
+        assertEquals("Original dataset sequence was modified",
+                copySequenceFeatures,
+                copySeq0.getSequenceFeatures().toString());
+        assertEquals("Wrong Dataset size after Redo of " + msg,
+                newDatasetSequence ? 2 : 1,
+                alignment.getDataset().getHeight());
+
         /*
          * undo ready for next cut
          */
-        testee.undoCommand(new AlignmentI[] { alignment });
-        assertEquals(func(5), seq0.getSequenceFeatures().size());
+        ec.undoCommand(views);
+
+        /*
+         * final verify that copy alignment dataset sequence is still unaffected
+         * and that alignment dataset has shrunk
+         */
+        assertEquals("Original dataset sequence was modified",
+                copySequenceFeatures,
+                copySeq0.getSequenceFeatures().toString());
+        assertEquals("Wrong Dataset size after final Undo of " + msg, 1,
+                alignment.getDataset().getHeight());
       }
     }
   }
 
   /**
+   * Verify by inspection that the sequence features left on the sequence after
+   * a cut match the expected results. The trick to this is that we can parse
+   * each feature's original start-end positions from its description.
+   * 
+   * @param seq0
+   * @param from
+   * @param to
+   * @param msg
+   * @param seqStart
+   */
+  protected void verifyCut(SequenceI seq0, int from, int to,
+          final String msg, int seqStart)
+  {
+    List<SequenceFeature> sfs;
+    sfs = seq0.getSequenceFeatures();
+
+    Collections.sort(sfs, BY_DESCRIPTION);
+
+    /*
+     * confirm the number of features has reduced by the
+     * number of features within the cut region i.e. by
+     * func(length of cut); exception is a cut at start or end of sequence, 
+     * which retains the original coordinates, dataset sequence 
+     * and all its features
+     */
+    boolean datasetRetained = from == 0 || to == 4;
+    if (datasetRetained)
+    {
+      // dataset and all features retained
+      assertEquals(msg, func(5), sfs.size());
+    }
+    else if (to - from == 4)
+    {
+      // all columns were cut
+      assertTrue(sfs.isEmpty());
+    }
+    else
+    {
+      // failure in checkFeatureRelocation is more informative!
+      assertEquals(msg + "wrong number of features left", func(5)
+              - func(to - from + 1), sfs.size());
+    }
+
+    /*
+     * inspect individual features
+     */
+    for (SequenceFeature sf : sfs)
+    {
+      verifyFeatureRelocation(sf, from + 1, to + 1, !datasetRetained,
+              seqStart);
+    }
+  }
+
+  /**
+   * Check that after Undo, every feature has start/end that match its original
+   * "start" and "end" properties
+   * 
+   * @param from
+   * @param to
+   * @param sfs
+   */
+  protected void verifyUndo(int from, int to, List<SequenceFeature> sfs)
+  {
+    for (SequenceFeature sf : sfs)
+    {
+      final int oldFrom = ((Integer) sf.getValue("from")).intValue();
+      final int oldTo = ((Integer) sf.getValue("to")).intValue();
+      String msg = String.format(
+              "Undo cut of [%d-%d], feature at [%d-%d] ", from + 1, to + 1,
+              oldFrom, oldTo);
+      assertEquals(msg + "start", oldFrom, sf.getBegin());
+      assertEquals(msg + "end", oldTo, sf.getEnd());
+    }
+  }
+
+  /**
    * Helper method to check a feature has been correctly relocated after a cut
    * 
    * @param sf
    * @param from
-   *          start of cut (first residue cut)
+   *          start of cut (first residue cut 1..)
    * @param to
-   *          end of cut (last residue cut)
+   *          end of cut (last residue cut 1..)
+   * @param newDataset
+   * @param seqStart
    */
-  private void checkFeatureRelocation(SequenceFeature sf, int from, int to)
+  private void verifyFeatureRelocation(SequenceFeature sf, int from, int to,
+ boolean newDataset, int seqStart)
   {
     // TODO handle the gapped sequence case as well
     int cutSize = to - from + 1;
-    int oldFrom = ((Integer) sf.getValue("from")).intValue();
-    int oldTo = ((Integer) sf.getValue("to")).intValue();
+    final int oldFrom = ((Integer) sf.getValue("from")).intValue();
+    final int oldTo = ((Integer) sf.getValue("to")).intValue();
+    final int oldFromPosition = oldFrom - seqStart + 1; // 1..
+    final int oldToPosition = oldTo - seqStart + 1; // 1..
 
     String msg = String.format(
             "Feature %s relocated to %d-%d after cut of %d-%d",
             sf.getDescription(), sf.getBegin(), sf.getEnd(), from, to);
-    if (oldTo < from)
+    if (!newDataset)
+    {
+      // dataset retained with all features unchanged
+      assertEquals("0: " + msg, oldFrom, sf.getBegin());
+      assertEquals("0: " + msg, oldTo, sf.getEnd());
+    }
+    else if (oldToPosition < from)
     {
       // before cut region so unchanged
       assertEquals("1: " + msg, oldFrom, sf.getBegin());
       assertEquals("2: " + msg, oldTo, sf.getEnd());
     }
-    else if (oldFrom > to)
+    else if (oldFromPosition > to)
     {
       // follows cut region - shift by size of cut
-      assertEquals("3: " + msg, oldFrom - cutSize, sf.getBegin());
-      assertEquals("4: " + msg, oldTo - cutSize, sf.getEnd());
+      assertEquals("3: " + msg, newDataset ? oldFrom - cutSize : oldFrom,
+              sf.getBegin());
+      assertEquals("4: " + msg, newDataset ? oldTo - cutSize : oldTo,
+              sf.getEnd());
     }
-    else if (oldFrom < from && oldTo > to)
+    else if (oldFromPosition < from && oldToPosition > to)
     {
       // feature encloses cut region - shrink it right
       assertEquals("5: " + msg, oldFrom, sf.getBegin());
       assertEquals("6: " + msg, oldTo - cutSize, sf.getEnd());
     }
-    else if (oldFrom < from)
+    else if (oldFromPosition < from)
     {
       // feature overlaps left side of cut region - truncated right
-      assertEquals("7: " + msg, from - 1, sf.getEnd());
+      assertEquals("7: " + msg, from - 1 + seqStart - 1, sf.getEnd());
     }
-    else if (oldTo > to)
+    else if (oldToPosition > to)
     {
       // feature overlaps right side of cut region - truncated left
-      assertEquals("8: " + msg, from, sf.getBegin());
-      assertEquals("9: " + msg, from + oldTo - to - 1, sf.getEnd());
+      assertEquals("8: " + msg, newDataset ? from + seqStart - 1 : to + 1,
+              sf.getBegin());
+      assertEquals("9: " + msg, newDataset ? from + oldTo - to - 1 : oldTo,
+              sf.getEnd());
     }
     else
     {
@@ -844,30 +1132,32 @@ public class EditCommandTest
    * Test a cut action's relocation of sequence features
    */
   @Test(groups = { "Functional" })
-  public void testCut_gappedWithFeatures()
+  public void testCut_withFeatures5prime()
   {
+    SequenceI seq0 = new Sequence("seq/8-11", "A-BCC");
+    seq0.createDatasetSequence();
+    assertEquals(8, seq0.getStart());
+    seq0.addSequenceFeature(new SequenceFeature("", "", 10, 11, 0f,
+            null));
+    SequenceI[] seqsArray = new SequenceI[] { seq0 };
+    AlignmentI alignment = new Alignment(seqsArray);
+
     /*
-     * create sequence features before, after and overlapping
-     * a cut of columns/residues 4-7
+     * cut columns of A-B; same dataset sequence is retained, aligned sequence
+     * start becomes 10
      */
-    SequenceI seq0 = new Sequence("seq", "A-BCC");
-    seq0.addSequenceFeature(new SequenceFeature("", "", 3, 4, 0f,
-            null));
-    AlignmentI alignment = new Alignment(new SequenceI[] { seq0 });
-    // cut columns of A-B
-    Edit ec = testee.new Edit(Action.CUT, seqs, 0, 3, alignment); // cols 0-3
-                                                                  // base 0
+    Edit ec = testee.new Edit(Action.CUT, seqsArray, 0, 3, alignment);
     EditCommand.cut(ec, new AlignmentI[] { alignment });
   
     /*
-     * feature on CC(3-4) should now be on CC(1-2)
+     * feature on CC(10-11) should still be on CC(10-11)
      */
+    assertSame(seq0, alignment.getSequenceAt(0));
+    assertEquals(10, seq0.getStart());
     List<SequenceFeature> sfs = seq0.getSequenceFeatures();
     assertEquals(1, sfs.size());
     SequenceFeature sf = sfs.get(0);
-    assertEquals(1, sf.getBegin());
-    assertEquals(2, sf.getEnd());
-
-    // TODO add further cases including Undo - see JAL-2541
+    assertEquals(10, sf.getBegin());
+    assertEquals(11, sf.getEnd());
   }
 }
index efee93b..7990d21 100644 (file)
@@ -26,6 +26,7 @@ import static org.testng.AssertJUnit.assertTrue;
 import jalview.analysis.Finder;
 import jalview.api.AlignViewControllerI;
 import jalview.api.FeatureColourI;
+import jalview.api.FinderI;
 import jalview.datamodel.Alignment;
 import jalview.datamodel.SearchResults;
 import jalview.datamodel.SearchResultsI;
@@ -147,7 +148,8 @@ public class AlignViewControllerTest
      * seq1 feature in columns 4-6 is hidden
      * seq2 feature in columns 6-7 is shown
      */
-    FeatureColourI fc = new FeatureColour(Color.red, Color.blue, 0f, 10f);
+    FeatureColourI fc = new FeatureColour(null, Color.red, Color.blue, null,
+            0f, 10f);
     fc.setAboveThreshold(true);
     fc.setThreshold(5f);
     af.getFeatureRenderer().setColour("Metal", fc);
@@ -222,10 +224,8 @@ public class AlignViewControllerTest
     /*
      *  test Match/Find works first
      */
-    Finder f = new Finder(af.getViewport().getAlignment(), null);
-    f.setFindAll(true);
-    f.setCaseSensitive(true);
-    f.find("M+");
+    FinderI f = new Finder(af.getViewport());
+    f.findAll("M+", true, false);
     assertEquals(
             "Finder found different set of results to manually created SearchResults",
             sr, f.getSearchResults());
index 1d1ebd6..dd19eb6 100644 (file)
@@ -1484,4 +1484,82 @@ public class AlignmentTest
     assertEquals(".JKLMNO", seq2.getSequenceAsString());
     assertEquals(".PQR...", seq3.getSequenceAsString());
   }
+
+  /**
+   * Test for setHiddenColumns, to check it returns true if the hidden columns
+   * have changed, else false
+   */
+  @Test(groups = { "Functional" })
+  public void testSetHiddenColumns()
+  {
+    AlignmentI al = new Alignment(new SequenceI[] {});
+    assertFalse(al.getHiddenColumns().hasHiddenColumns());
+
+    HiddenColumns hc = new HiddenColumns();
+    assertFalse(al.setHiddenColumns(hc)); // no change
+    assertSame(hc, al.getHiddenColumns());
+
+    hc.hideColumns(2, 4);
+    assertTrue(al.getHiddenColumns().hasHiddenColumns());
+
+    /*
+     * set a different object but with the same columns hidden
+     */
+    HiddenColumns hc2 = new HiddenColumns();
+    hc2.hideColumns(2, 4);
+    assertFalse(al.setHiddenColumns(hc2)); // no change
+    assertSame(hc2, al.getHiddenColumns());
+
+    assertTrue(al.setHiddenColumns(null));
+    assertNull(al.getHiddenColumns());
+    assertTrue(al.setHiddenColumns(hc));
+    assertSame(hc, al.getHiddenColumns());
+
+    al.getHiddenColumns().hideColumns(10, 12);
+    hc2.hideColumns(10, 12);
+    assertFalse(al.setHiddenColumns(hc2)); // no change
+
+    /*
+     * hide columns 15-16 then 17-18 in hc
+     * hide columns 15-18 in hc2
+     * these are not now 'equal' objects even though they
+     * represent the same set of columns
+     */
+    assertSame(hc2, al.getHiddenColumns());
+    hc.hideColumns(15, 16);
+    hc.hideColumns(17, 18);
+    hc2.hideColumns(15, 18);
+    assertFalse(hc.equals(hc2));
+    assertTrue(al.setHiddenColumns(hc)); // 'changed'
+  }
+
+  @Test(groups = { "Functional" })
+  public void testGetWidth()
+  {
+    SequenceI seq1 = new Sequence("seq1", "ABCDEF--");
+    SequenceI seq2 = new Sequence("seq2", "-JKLMNO--");
+    SequenceI seq3 = new Sequence("seq2", "-PQR");
+    AlignmentI a = new Alignment(new SequenceI[] { seq1, seq2, seq3 });
+
+    assertEquals(9, a.getWidth());
+
+    // width includes hidden columns
+    a.getHiddenColumns().hideColumns(2, 5);
+    assertEquals(9, a.getWidth());
+  }
+
+  @Test(groups = { "Functional" })
+  public void testGetVisibleWidth()
+  {
+    SequenceI seq1 = new Sequence("seq1", "ABCDEF--");
+    SequenceI seq2 = new Sequence("seq2", "-JKLMNO--");
+    SequenceI seq3 = new Sequence("seq2", "-PQR");
+    AlignmentI a = new Alignment(new SequenceI[] { seq1, seq2, seq3 });
+
+    assertEquals(9, a.getVisibleWidth());
+
+    // width excludes hidden columns
+    a.getHiddenColumns().hideColumns(2, 5);
+    assertEquals(5, a.getVisibleWidth());
+  }
 }
index 3942f0b..0dfcc21 100644 (file)
@@ -31,11 +31,11 @@ public class AllColsIteratorTest
 {
   HiddenColumns hiddenCols;
   
-  @BeforeClass
+  @BeforeClass(alwaysRun = true)
   public void setup()
   {
     hiddenCols = new HiddenColumns();
-   hiddenCols.hideColumns(2,4);
+    hiddenCols.hideColumns(2, 4);
   }
   
 
index aeff71d..90ed891 100644 (file)
@@ -36,7 +36,7 @@ public class AllRowsIteratorTest
 
   Hashtable<SequenceI, SequenceCollectionI> hiddenRepSequences = new Hashtable<>();
 
-  @BeforeClass
+  @BeforeClass(alwaysRun = true)
   public void setup()
   {
     // create random alignment
index 8709961..2dda4d3 100644 (file)
@@ -27,6 +27,9 @@ import static org.testng.AssertJUnit.fail;
 
 import jalview.analysis.AlignmentGenerator;
 import jalview.gui.JvOptionPane;
+import jalview.viewmodel.annotationfilter.AnnotationFilterParameter;
+import jalview.viewmodel.annotationfilter.AnnotationFilterParameter.SearchableAnnotationField;
+import jalview.viewmodel.annotationfilter.AnnotationFilterParameter.ThresholdType;
 
 import java.util.Arrays;
 import java.util.BitSet;
@@ -598,4 +601,129 @@ public class ColumnSelectionTest
     assertEquals(sg.getStartRes(), 10);
     assertEquals(sg.getEndRes(), 19);
   }
+
+  @Test(groups = { "Functional" })
+  public void testFilterAnnotations()
+  {
+    ColumnSelection cs = new ColumnSelection();
+
+    /*
+     * filter with no conditions clears the selection
+     */
+    Annotation[] anns = new Annotation[] { null };
+    AnnotationFilterParameter filter = new AnnotationFilterParameter();
+    cs.addElement(3);
+    int added = cs.filterAnnotations(anns, filter);
+    assertEquals(0, added);
+    assertTrue(cs.isEmpty());
+
+    /*
+     * select on description (regex)
+     */
+    filter.setRegexString("w.rld");
+    filter.addRegexSearchField(SearchableAnnotationField.DESCRIPTION);
+    Annotation helix = new Annotation("(", "hello", '<', 2f);
+    Annotation sheet = new Annotation("(", "world", '<', 2f);
+    added = cs.filterAnnotations(new Annotation[] { null, helix, sheet },
+            filter);
+    assertEquals(1, added);
+    assertTrue(cs.contains(2));
+
+    /*
+     * select on label (invalid regex, exact match)
+     */
+    filter = new AnnotationFilterParameter();
+    filter.setRegexString("(");
+    filter.addRegexSearchField(SearchableAnnotationField.DISPLAY_STRING);
+    added = cs.filterAnnotations(new Annotation[] { null, helix, sheet },
+            filter);
+    assertEquals(2, added);
+    assertTrue(cs.contains(1));
+    assertTrue(cs.contains(2));
+
+    /*
+     * select Helix (secondary structure symbol H)
+     */
+    filter = new AnnotationFilterParameter();
+    filter.setFilterAlphaHelix(true);
+    helix = new Annotation("x", "desc", 'H', 0f);
+    sheet = new Annotation("x", "desc", 'E', 1f);
+    Annotation turn = new Annotation("x", "desc", 'S', 2f);
+    Annotation ann4 = new Annotation("x", "desc", 'Y', 3f);
+    added = cs
+            .filterAnnotations(new Annotation[]
+            { null, helix, sheet, turn, ann4 },
+            filter);
+    assertEquals(1, added);
+    assertTrue(cs.contains(1));
+
+    /*
+     * select Helix and Sheet (E)
+     */
+    filter.setFilterBetaSheet(true);
+    added = cs
+            .filterAnnotations(new Annotation[]
+            { null, helix, sheet, turn, ann4 }, filter);
+    assertEquals(2, added);
+    assertTrue(cs.contains(1));
+    assertTrue(cs.contains(2));
+
+    /*
+     * select Sheet and Turn (S)
+     */
+    filter.setFilterAlphaHelix(false);
+    filter.setFilterTurn(true);
+    added = cs
+            .filterAnnotations(new Annotation[]
+            { null, helix, sheet, turn, ann4 }, filter);
+    assertEquals(2, added);
+    assertTrue(cs.contains(2));
+    assertTrue(cs.contains(3));
+
+    /*
+     * select value < 2f (ann1, ann2)
+     */
+    filter = new AnnotationFilterParameter();
+    filter.setThresholdType(ThresholdType.BELOW_THRESHOLD);
+    filter.setThresholdValue(2f);
+    added = cs
+            .filterAnnotations(new Annotation[]
+            { null, helix, sheet, turn, ann4 }, filter);
+    assertEquals(2, added);
+    assertTrue(cs.contains(1));
+    assertTrue(cs.contains(2));
+
+    /*
+     * select value > 2f (ann4 only)
+     */
+    filter.setThresholdType(ThresholdType.ABOVE_THRESHOLD);
+    added = cs
+            .filterAnnotations(new Annotation[]
+            { null, helix, sheet, turn, ann4 }, filter);
+    assertEquals(1, added);
+    assertTrue(cs.contains(4));
+
+    /*
+     * select >2f or Helix
+     */
+    filter.setFilterAlphaHelix(true);
+    added = cs
+            .filterAnnotations(new Annotation[]
+            { null, helix, sheet, turn, ann4 }, filter);
+    assertEquals(2, added);
+    assertTrue(cs.contains(1));
+    assertTrue(cs.contains(4));
+
+    /*
+     * select < 1f or Helix; one annotation matches both
+     * return value should only count it once
+     */
+    filter.setThresholdType(ThresholdType.BELOW_THRESHOLD);
+    filter.setThresholdValue(1f);
+    added = cs
+            .filterAnnotations(new Annotation[]
+            { null, helix, sheet, turn, ann4 }, filter);
+    assertEquals(1, added);
+    assertTrue(cs.contains(1));
+  }
 }
index f1a6e20..349b5d1 100644 (file)
@@ -186,6 +186,25 @@ public class SearchResultsTest
     assertEquals(5, m.getEnd());
   }
 
+  @Test(groups = { "Functional" })
+  public void testMatchContains()
+  {
+    SequenceI seq1 = new Sequence("", "abcdefghijklm");
+    SequenceI seq2 = new Sequence("", "abcdefghijklm");
+    SearchResultMatchI m = new SearchResults().new Match(seq1, 2, 5);
+
+    assertTrue(m.contains(seq1, 2, 5));
+    assertTrue(m.contains(seq1, 3, 5));
+    assertTrue(m.contains(seq1, 2, 4));
+    assertTrue(m.contains(seq1, 3, 3));
+
+    assertFalse(m.contains(seq1, 2, 6));
+    assertFalse(m.contains(seq1, 1, 5));
+    assertFalse(m.contains(seq1, 1, 8));
+    assertFalse(m.contains(seq2, 3, 3));
+    assertFalse(m.contains(null, 3, 3));
+  }
+
   /**
    * test markColumns for creating column selections
    */
@@ -268,4 +287,20 @@ public class SearchResultsTest
             "Didn't set expected number of columns in total for two successive marks",
             2, tbs.cardinality());
   }
+
+  /**
+   * Test to verify adding doesn't create duplicate results
+   */
+  @Test(groups = { "Functional" })
+  public void testAddResult()
+  {
+    SequenceI seq1 = new Sequence("", "abcdefghijklm");
+    SearchResultsI sr = new SearchResults();
+    sr.addResult(seq1, 3, 5);
+    assertEquals(1, sr.getSize());
+    sr.addResult(seq1, 3, 5);
+    assertEquals(1, sr.getSize());
+    sr.addResult(seq1, 3, 6);
+    assertEquals(2, sr.getSize());
+  }
 }
index b0af5c8..8419d4c 100644 (file)
@@ -14,12 +14,14 @@ import jalview.schemes.NucleotideColourScheme;
 import jalview.schemes.PIDColourScheme;
 
 import java.awt.Color;
+import java.util.ArrayList;
 import java.util.Collections;
-
-import junit.extensions.PA;
+import java.util.List;
 
 import org.testng.annotations.Test;
 
+import junit.extensions.PA;
+
 public class SequenceGroupTest
 {
   @Test(groups={"Functional"})
@@ -301,4 +303,36 @@ public class SequenceGroupTest
      */
     assertNull(sg2.getContext());
   }
+
+  @Test(groups = { "Functional" })
+  public void testConstructor_list()
+  {
+    SequenceI s1 = new Sequence("abcde", "fg");
+    SequenceI s2 = new Sequence("foo", "bar");
+    List<SequenceI> seqs = new ArrayList<SequenceI>();
+    seqs.add(s1);
+    seqs.add(s2);
+    SequenceGroup sg = new SequenceGroup(seqs);
+
+    /*
+     * verify sg has a copy of the original list
+     */
+    List<SequenceI> sgList = sg.getSequences();
+    assertNotSame(sgList, seqs);
+    assertEquals(sgList, seqs);
+
+    /*
+     * add to sgList, original is unchanged
+     */
+    sg.addSequence(new Sequence("bar", "foo"), false);
+    assertEquals(sgList.size(), 3);
+    assertEquals(seqs.size(), 2);
+
+    /*
+     * delete from original, sgList is unchanged
+     */
+    seqs.remove(s1);
+    assertEquals(sgList.size(), 3);
+    assertEquals(seqs.size(), 1);
+  }
 }
index 79bb2bb..c344645 100644 (file)
@@ -52,7 +52,6 @@ import junit.extensions.PA;
 
 public class SequenceTest
 {
-
   @BeforeClass(alwaysRun = true)
   public void setUpJvOptionPane()
   {
@@ -290,6 +289,61 @@ public class SequenceTest
     assertEquals(0, sq.findIndex(2));
   }
 
+  @Test(groups = { "Functional" })
+  public void testFindPositions()
+  {
+    SequenceI sq = new Sequence("test/8-13", "-ABC---DE-F--");
+
+    /*
+     * invalid inputs
+     */
+    assertNull(sq.findPositions(6, 5));
+    assertNull(sq.findPositions(0, 5));
+    assertNull(sq.findPositions(-1, 5));
+
+    /*
+     * all gapped ranges
+     */
+    assertNull(sq.findPositions(1, 1)); // 1-based columns
+    assertNull(sq.findPositions(5, 5));
+    assertNull(sq.findPositions(5, 6));
+    assertNull(sq.findPositions(5, 7));
+
+    /*
+     * all ungapped ranges
+     */
+    assertEquals(new Range(8, 8), sq.findPositions(2, 2)); // A
+    assertEquals(new Range(8, 9), sq.findPositions(2, 3)); // AB
+    assertEquals(new Range(8, 10), sq.findPositions(2, 4)); // ABC
+    assertEquals(new Range(9, 10), sq.findPositions(3, 4)); // BC
+
+    /*
+     * gap to ungapped range
+     */
+    assertEquals(new Range(8, 10), sq.findPositions(1, 4)); // ABC
+    assertEquals(new Range(11, 12), sq.findPositions(6, 9)); // DE
+
+    /*
+     * ungapped to gapped range
+     */
+    assertEquals(new Range(10, 10), sq.findPositions(4, 5)); // C
+    assertEquals(new Range(9, 13), sq.findPositions(3, 11)); // BCDEF
+
+    /*
+     * ungapped to ungapped enclosing gaps
+     */
+    assertEquals(new Range(10, 11), sq.findPositions(4, 8)); // CD
+    assertEquals(new Range(8, 13), sq.findPositions(2, 11)); // ABCDEF
+
+    /*
+     * gapped to gapped enclosing ungapped
+     */
+    assertEquals(new Range(8, 10), sq.findPositions(1, 5)); // ABC
+    assertEquals(new Range(11, 12), sq.findPositions(5, 10)); // DE
+    assertEquals(new Range(8, 13), sq.findPositions(1, 13)); // the lot
+    assertEquals(new Range(8, 13), sq.findPositions(1, 99));
+  }
+
   /**
    * Tests for the method that returns a dataset sequence position (start..) for
    * an aligned column position (base 0).
@@ -465,8 +519,7 @@ public class SequenceTest
     assertEquals("test:Pos13:Col10:startCol3:endCol10:tok0",
             PA.getValue(sq, "cursor").toString());
     sq.sequenceChanged();
-    assertEquals(12, sq.findPosition(8));
-    cursor = (SequenceCursor) PA.getValue(sq, "cursor");
+    assertEquals(12, sq.findPosition(8)); // E12
     // sequenceChanged() invalidates cursor.lastResidueColumn
     cursor = (SequenceCursor) PA.getValue(sq, "cursor");
     assertEquals("test:Pos12:Col9:startCol3:endCol0:tok1",
@@ -505,6 +558,13 @@ public class SequenceTest
     assertEquals(6, sq.getEnd());
     assertNull(PA.getValue(sq, "datasetSequence"));
 
+    sq = new Sequence("test", "ABCDE");
+    sq.deleteChars(0, 3);
+    assertEquals("DE", sq.getSequenceAsString());
+    assertEquals(4, sq.getStart());
+    assertEquals(5, sq.getEnd());
+    assertNull(PA.getValue(sq, "datasetSequence"));
+
     /*
      * delete at end
      */
@@ -514,6 +574,21 @@ public class SequenceTest
     assertEquals(1, sq.getStart());
     assertEquals(4, sq.getEnd());
     assertNull(PA.getValue(sq, "datasetSequence"));
+
+    /*
+     * delete more positions than there are
+     */
+    sq = new Sequence("test/8-11", "ABCD");
+    sq.deleteChars(0, 99);
+    assertEquals("", sq.getSequenceAsString());
+    assertEquals(12, sq.getStart()); // = findPosition(99) ?!?
+    assertEquals(11, sq.getEnd());
+
+    sq = new Sequence("test/8-11", "----");
+    sq.deleteChars(0, 99); // ArrayIndexOutOfBoundsException <= 2.10.2
+    assertEquals("", sq.getSequenceAsString());
+    assertEquals(8, sq.getStart());
+    assertEquals(11, sq.getEnd());
   }
 
   @Test(groups = { "Functional" })
@@ -1614,6 +1689,10 @@ public class SequenceTest
     // cursor should now be at [D 6]
     cursor = (SequenceCursor) PA.getValue(sq, "cursor");
     assertEquals(new SequenceCursor(sq, 11, 6, ++token), cursor);
+    assertEquals(0, cursor.lastColumnPosition); // not yet found
+    assertEquals(13, sq.findPosition(8)); // E13
+    cursor = (SequenceCursor) PA.getValue(sq, "cursor");
+    assertEquals(9, cursor.lastColumnPosition); // found
 
     /*
      * deleteChars should invalidate the cached cursor
@@ -1693,61 +1772,6 @@ public class SequenceTest
   }
 
   @Test(groups = { "Functional" })
-  public void testFindPositions()
-  {
-    SequenceI sq = new Sequence("test/8-13", "-ABC---DE-F--");
-
-    /*
-     * invalid inputs
-     */
-    assertNull(sq.findPositions(6, 5));
-    assertNull(sq.findPositions(0, 5));
-    assertNull(sq.findPositions(-1, 5));
-
-    /*
-     * all gapped ranges
-     */
-    assertNull(sq.findPositions(1, 1)); // 1-based columns
-    assertNull(sq.findPositions(5, 5));
-    assertNull(sq.findPositions(5, 6));
-    assertNull(sq.findPositions(5, 7));
-
-    /*
-     * all ungapped ranges
-     */
-    assertEquals(new Range(8, 8), sq.findPositions(2, 2)); // A
-    assertEquals(new Range(8, 9), sq.findPositions(2, 3)); // AB
-    assertEquals(new Range(8, 10), sq.findPositions(2, 4)); // ABC
-    assertEquals(new Range(9, 10), sq.findPositions(3, 4)); // BC
-
-    /*
-     * gap to ungapped range
-     */
-    assertEquals(new Range(8, 10), sq.findPositions(1, 4)); // ABC
-    assertEquals(new Range(11, 12), sq.findPositions(6, 9)); // DE
-
-    /*
-     * ungapped to gapped range
-     */
-    assertEquals(new Range(10, 10), sq.findPositions(4, 5)); // C
-    assertEquals(new Range(9, 13), sq.findPositions(3, 11)); // BCDEF
-
-    /*
-     * ungapped to ungapped enclosing gaps
-     */
-    assertEquals(new Range(10, 11), sq.findPositions(4, 8)); // CD
-    assertEquals(new Range(8, 13), sq.findPositions(2, 11)); // ABCDEF
-
-    /*
-     * gapped to gapped enclosing ungapped
-     */
-    assertEquals(new Range(8, 10), sq.findPositions(1, 5)); // ABC
-    assertEquals(new Range(11, 12), sq.findPositions(5, 10)); // DE
-    assertEquals(new Range(8, 13), sq.findPositions(1, 13)); // the lot
-    assertEquals(new Range(8, 13), sq.findPositions(1, 99));
-  }
-
-  @Test(groups = { "Functional" })
   public void testGapBitset()
   {
     SequenceI sq = new Sequence("test/8-13", "-ABC---DE-F--");
index db21c2f..c38cb1e 100644 (file)
@@ -2,6 +2,7 @@ package jalview.datamodel.features;
 
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertSame;
 import static org.testng.Assert.assertTrue;
 
 import jalview.datamodel.SequenceFeature;
@@ -184,58 +185,6 @@ public class FeatureStoreTest
     assertTrue(overlaps.contains(sf));
   }
 
-  /**
-   * Tests for the method that returns false for an attempt to add a feature
-   * that would enclose, or be enclosed by, another feature
-   */
-  @Test(groups = "Functional")
-  public void testAddNonNestedFeature()
-  {
-    FeatureStore fs = new FeatureStore();
-
-    String type = "Domain";
-    SequenceFeature sf1 = new SequenceFeature(type, type, 10, 20,
-            Float.NaN, null);
-    assertTrue(fs.addNonNestedFeature(sf1));
-
-    // co-located feature is ok
-    SequenceFeature sf2 = new SequenceFeature(type, type, 10, 20,
-            Float.NaN, null);
-    assertTrue(fs.addNonNestedFeature(sf2));
-
-    // overlap left is ok
-    SequenceFeature sf3 = new SequenceFeature(type, type, 5, 15, Float.NaN,
-            null);
-    assertTrue(fs.addNonNestedFeature(sf3));
-
-    // overlap right is ok
-    SequenceFeature sf4 = new SequenceFeature(type, type, 15, 25,
-            Float.NaN, null);
-    assertTrue(fs.addNonNestedFeature(sf4));
-
-    // add enclosing feature is not ok
-    SequenceFeature sf5 = new SequenceFeature(type, type, 10, 21,
-            Float.NaN, null);
-    assertFalse(fs.addNonNestedFeature(sf5));
-    SequenceFeature sf6 = new SequenceFeature(type, type, 4, 15, Float.NaN,
-            null);
-    assertFalse(fs.addNonNestedFeature(sf6));
-    SequenceFeature sf7 = new SequenceFeature(type, type, 1, 50, Float.NaN,
-            null);
-    assertFalse(fs.addNonNestedFeature(sf7));
-
-    // add enclosed feature is not ok
-    SequenceFeature sf8 = new SequenceFeature(type, type, 10, 19,
-            Float.NaN, null);
-    assertFalse(fs.addNonNestedFeature(sf8));
-    SequenceFeature sf9 = new SequenceFeature(type, type, 16, 25,
-            Float.NaN, null);
-    assertFalse(fs.addNonNestedFeature(sf9));
-    SequenceFeature sf10 = new SequenceFeature(type, type, 7, 7, Float.NaN,
-            null);
-    assertFalse(fs.addNonNestedFeature(sf10));
-  }
-
   @Test(groups = "Functional")
   public void testGetPositionalFeatures()
   {
@@ -462,9 +411,7 @@ public class FeatureStoreTest
     assertEquals(fs.getFeatureCount(true), 3);
     assertTrue(fs.delete(sf1));
     assertEquals(fs.getFeatureCount(true), 2);
-    // FeatureStore should now only contain features in the NCList
-    assertTrue(fs.nonNestedFeatures.isEmpty());
-    assertEquals(fs.nestedFeatures.size(), 2);
+    assertEquals(fs.features.size(), 2);
     assertFalse(fs.isEmpty());
     assertTrue(fs.delete(sf2));
     assertEquals(fs.getFeatureCount(true), 1);
@@ -693,7 +640,7 @@ public class FeatureStoreTest
   public void testListContains()
   {
     assertFalse(FeatureStore.listContains(null, null));
-    List<SequenceFeature> features = new ArrayList<SequenceFeature>();
+    List<SequenceFeature> features = new ArrayList<>();
     assertFalse(FeatureStore.listContains(features, null));
 
     SequenceFeature sf1 = new SequenceFeature("type1", "desc1", 20, 30, 3f,
@@ -774,7 +721,7 @@ public class FeatureStoreTest
   public void testShiftFeatures()
   {
     FeatureStore fs = new FeatureStore();
-    assertFalse(fs.shiftFeatures(1));
+    assertFalse(fs.shiftFeatures(0, 1)); // nothing to do
 
     SequenceFeature sf1 = new SequenceFeature("Cath", "", 2, 5, 0f, null);
     fs.addFeature(sf1);
@@ -790,9 +737,9 @@ public class FeatureStoreTest
     fs.addFeature(sf4);
 
     /*
-     * shift features right by 5
+     * shift all features right by 5
      */
-    assertTrue(fs.shiftFeatures(5));
+    assertTrue(fs.shiftFeatures(0, 5));
 
     // non-positional features untouched:
     List<SequenceFeature> nonPos = fs.getNonPositionalFeatures();
@@ -818,7 +765,7 @@ public class FeatureStoreTest
      * feature at [7-10] should be removed
      * feature at [13-19] should become [1-4] 
      */
-    assertTrue(fs.shiftFeatures(-15));
+    assertTrue(fs.shiftFeatures(0, -15));
     pos = fs.getPositionalFeatures();
     assertEquals(pos.size(), 2);
     SequenceFeatures.sortFeatures(pos, true);
@@ -826,6 +773,32 @@ public class FeatureStoreTest
     assertEquals(pos.get(0).getEnd(), 4);
     assertEquals(pos.get(1).getBegin(), 13);
     assertEquals(pos.get(1).getEnd(), 22);
+
+    /*
+     * shift right by 4 from position 2 onwards
+     * feature at [1-4] unchanged, feature at [13-22] shifts
+     */
+    assertTrue(fs.shiftFeatures(2, 4));
+    pos = fs.getPositionalFeatures();
+    assertEquals(pos.size(), 2);
+    SequenceFeatures.sortFeatures(pos, true);
+    assertEquals(pos.get(0).getBegin(), 1);
+    assertEquals(pos.get(0).getEnd(), 4);
+    assertEquals(pos.get(1).getBegin(), 17);
+    assertEquals(pos.get(1).getEnd(), 26);
+
+    /*
+     * shift right by 4 from position 18 onwards
+     * should be no change
+     */
+    SequenceFeature f1 = pos.get(0);
+    SequenceFeature f2 = pos.get(1);
+    assertFalse(fs.shiftFeatures(18, 4)); // no update
+    pos = fs.getPositionalFeatures();
+    assertEquals(pos.size(), 2);
+    SequenceFeatures.sortFeatures(pos, true);
+    assertSame(pos.get(0), f1);
+    assertSame(pos.get(1), f2);
   }
 
   @Test(groups = "Functional")
@@ -842,8 +815,8 @@ public class FeatureStoreTest
     assertEquals(features.size(), 2);
     assertTrue(features.contains(sf1));
     assertTrue(features.contains(sf2));
-    assertTrue(store.nonNestedFeatures.contains(sf1));
-    assertTrue(store.nestedFeatures.contains(sf2));
+    assertTrue(store.features.contains(sf1));
+    assertTrue(store.features.contains(sf2));
   
     /*
      * delete the first feature
diff --git a/test/jalview/datamodel/features/NCListTest.java b/test/jalview/datamodel/features/NCListTest.java
deleted file mode 100644 (file)
index 2c7f752..0000000
+++ /dev/null
@@ -1,682 +0,0 @@
-package jalview.datamodel.features;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertSame;
-import static org.testng.Assert.assertTrue;
-
-import jalview.datamodel.ContiguousI;
-import jalview.datamodel.Range;
-import jalview.datamodel.SequenceFeature;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
-import java.util.Random;
-
-import junit.extensions.PA;
-
-import org.testng.annotations.DataProvider;
-import org.testng.annotations.Test;
-
-public class NCListTest
-{
-
-  private Random random = new Random(107);
-
-  private Comparator<ContiguousI> sorter = new RangeComparator(true);
-
-  /**
-   * A basic sanity test of the constructor
-   */
-  @Test(groups = "Functional")
-  public void testConstructor()
-  {
-    List<Range> ranges = new ArrayList<Range>();
-    ranges.add(new Range(20, 20));
-    ranges.add(new Range(10, 20));
-    ranges.add(new Range(15, 30));
-    ranges.add(new Range(10, 30));
-    ranges.add(new Range(11, 19));
-    ranges.add(new Range(10, 20));
-    ranges.add(new Range(1, 100));
-
-    NCList<Range> ncl = new NCList<Range>(ranges);
-    String expected = "[1-100 [10-30 [10-20 [10-20 [11-19]]]], 15-30 [20-20]]";
-    assertEquals(ncl.toString(), expected);
-    assertTrue(ncl.isValid());
-
-    Collections.reverse(ranges);
-    ncl = new NCList<Range>(ranges);
-    assertEquals(ncl.toString(), expected);
-    assertTrue(ncl.isValid());
-  }
-
-  @Test(groups = "Functional")
-  public void testFindOverlaps()
-  {
-    List<Range> ranges = new ArrayList<Range>();
-    ranges.add(new Range(20, 50));
-    ranges.add(new Range(30, 70));
-    ranges.add(new Range(1, 100));
-    ranges.add(new Range(70, 120));
-  
-    NCList<Range> ncl = new NCList<Range>(ranges);
-
-    List<Range> overlaps = ncl.findOverlaps(121, 122);
-    assertEquals(overlaps.size(), 0);
-
-    overlaps = ncl.findOverlaps(21, 22);
-    assertEquals(overlaps.size(), 2);
-    assertEquals(((ContiguousI) overlaps.get(0)).getBegin(), 1);
-    assertEquals(((ContiguousI) overlaps.get(0)).getEnd(), 100);
-    assertEquals(((ContiguousI) overlaps.get(1)).getBegin(), 20);
-    assertEquals(((ContiguousI) overlaps.get(1)).getEnd(), 50);
-
-    overlaps = ncl.findOverlaps(110, 110);
-    assertEquals(overlaps.size(), 1);
-    assertEquals(((ContiguousI) overlaps.get(0)).getBegin(), 70);
-    assertEquals(((ContiguousI) overlaps.get(0)).getEnd(), 120);
-  }
-
-  @Test(groups = "Functional")
-  public void testAdd_onTheEnd()
-  {
-    List<Range> ranges = new ArrayList<Range>();
-    ranges.add(new Range(20, 50));
-    NCList<Range> ncl = new NCList<Range>(ranges);
-    assertEquals(ncl.toString(), "[20-50]");
-    assertTrue(ncl.isValid());
-
-    ncl.add(new Range(60, 70));
-    assertEquals(ncl.toString(), "[20-50, 60-70]");
-    assertTrue(ncl.isValid());
-  }
-
-  @Test(groups = "Functional")
-  public void testAdd_inside()
-  {
-    List<Range> ranges = new ArrayList<Range>();
-    ranges.add(new Range(20, 50));
-    NCList<Range> ncl = new NCList<Range>(ranges);
-    assertEquals(ncl.toString(), "[20-50]");
-    assertTrue(ncl.isValid());
-
-    ncl.add(new Range(30, 40));
-    assertEquals(ncl.toString(), "[20-50 [30-40]]");
-  }
-
-  @Test(groups = "Functional")
-  public void testAdd_onTheFront()
-  {
-    List<Range> ranges = new ArrayList<Range>();
-    ranges.add(new Range(20, 50));
-    NCList<Range> ncl = new NCList<Range>(ranges);
-    assertEquals(ncl.toString(), "[20-50]");
-    assertTrue(ncl.isValid());
-
-    ncl.add(new Range(5, 15));
-    assertEquals(ncl.toString(), "[5-15, 20-50]");
-    assertTrue(ncl.isValid());
-  }
-
-  @Test(groups = "Functional")
-  public void testAdd_enclosing()
-  {
-    List<Range> ranges = new ArrayList<Range>();
-    ranges.add(new Range(20, 50));
-    ranges.add(new Range(30, 60));
-    NCList<Range> ncl = new NCList<Range>(ranges);
-    assertEquals(ncl.toString(), "[20-50, 30-60]");
-    assertTrue(ncl.isValid());
-    assertEquals(ncl.getStart(), 20);
-
-    ncl.add(new Range(10, 70));
-    assertEquals(ncl.toString(), "[10-70 [20-50, 30-60]]");
-    assertTrue(ncl.isValid());
-  }
-
-  @Test(groups = "Functional")
-  public void testAdd_spanning()
-  {
-    List<Range> ranges = new ArrayList<Range>();
-    ranges.add(new Range(20, 40));
-    ranges.add(new Range(60, 70));
-    NCList<Range> ncl = new NCList<Range>(ranges);
-    assertEquals(ncl.toString(), "[20-40, 60-70]");
-    assertTrue(ncl.isValid());
-
-    ncl.add(new Range(30, 50));
-    assertEquals(ncl.toString(), "[20-40, 30-50, 60-70]");
-    assertTrue(ncl.isValid());
-
-    ncl.add(new Range(40, 65));
-    assertEquals(ncl.toString(), "[20-40, 30-50, 40-65, 60-70]");
-    assertTrue(ncl.isValid());
-  }
-
-  /**
-   * Provides the scales for pseudo-random NCLists i.e. the range of the maximal
-   * [0-scale] interval to be stored
-   * 
-   * @return
-   */
-  @DataProvider(name = "scalesOfLife")
-  public Object[][] getScales()
-  {
-    return new Object[][] { new Integer[] { 10 }, new Integer[] { 100 } };
-  }
-
-  /**
-   * Do a number of pseudo-random (reproducible) builds of an NCList, to
-   * exercise as many methods of the class as possible while generating the
-   * range of possible structure topologies
-   * <ul>
-   * <li>verify that add adds an entry and increments size</li>
-   * <li>...except where the entry is already contained (by equals test)</li>
-   * <li>verify that the structure is valid at all stages of construction</li>
-   * <li>generate, run and verify a range of overlap queries</li>
-   * <li>tear down the structure by deleting entries, verifying correctness at
-   * each stage</li>
-   * </ul>
-   */
-  @Test(groups = "Functional", dataProvider = "scalesOfLife")
-  public void test_pseudoRandom(Integer scale)
-  {
-    NCList<SequenceFeature> ncl = new NCList<SequenceFeature>();
-    List<SequenceFeature> features = new ArrayList<SequenceFeature>(scale);
-    
-    testAdd_pseudoRandom(scale, ncl, features);
-
-    /*
-     * sort the list of added ranges - this doesn't affect the test,
-     * just makes it easier to inspect the data in the debugger
-     */
-    Collections.sort(features, sorter);
-
-    testFindOverlaps_pseudoRandom(ncl, scale, features);
-
-    testDelete_pseudoRandom(ncl, features);
-  }
-
-  /**
-   * Pick randomly selected entries to delete in turn, checking the NCList size
-   * and validity at each stage, until it is empty
-   * 
-   * @param ncl
-   * @param features
-   */
-  protected void testDelete_pseudoRandom(NCList<SequenceFeature> ncl,
-          List<SequenceFeature> features)
-  {
-    int deleted = 0;
-
-    while (!features.isEmpty())
-    {
-      assertEquals(ncl.size(), features.size());
-      int toDelete = random.nextInt(features.size());
-      SequenceFeature entry = features.get(toDelete);
-      assertTrue(ncl.contains(entry), String.format(
-              "NCList doesn't contain entry [%d] '%s'!", deleted,
-              entry.toString()));
-
-      ncl.delete(entry);
-      assertFalse(ncl.contains(entry), String.format(
-              "NCList still contains deleted entry [%d] '%s'!", deleted,
-              entry.toString()));
-      features.remove(toDelete);
-      deleted++;
-
-      assertTrue(ncl.isValid(), String.format(
-              "NCList invalid after %d deletions, last deleted was '%s'",
-              deleted, entry.toString()));
-
-      /*
-       * brute force check that deleting one entry didn't delete any others
-       */
-      for (int i = 0; i < features.size(); i++)
-      {
-        SequenceFeature sf = features.get(i);
-        assertTrue(ncl.contains(sf), String.format(
-                        "NCList doesn't contain entry [%d] %s after deleting '%s'!",
-                        i, sf.toString(), entry.toString()));
-      }
-    }
-    assertEquals(ncl.size(), 0); // all gone
-  }
-
-  /**
-   * Randomly generate entries and add them to the NCList, checking its validity
-   * and size at each stage. A few entries should be duplicates (by equals test)
-   * so not get added.
-   * 
-   * @param scale
-   * @param ncl
-   * @param features
-   */
-  protected void testAdd_pseudoRandom(Integer scale,
-          NCList<SequenceFeature> ncl,
-          List<SequenceFeature> features)
-  {
-    int count = 0;
-    final int size = 50;
-
-    for (int i = 0; i < size; i++)
-    {
-      int r1 = random.nextInt(scale + 1);
-      int r2 = random.nextInt(scale + 1);
-      int from = Math.min(r1, r2);
-      int to = Math.max(r1, r2);
-
-      /*
-       * choice of two feature values means that occasionally an identical
-       * feature may be generated, in which case it should not be added 
-       */
-      float value = (float) i % 2;
-      SequenceFeature feature = new SequenceFeature("Pfam", "", from, to,
-              value, "group");
-
-      /*
-       * add to NCList - with duplicate entries (by equals) disallowed
-       */
-      ncl.add(feature, false);
-      if (features.contains(feature))
-      {
-        System.out.println("Duplicate feature generated "
-                + feature.toString());
-      }
-      else
-      {
-        features.add(feature);
-        count++;
-      }
-    
-      /*
-       * check list format is valid at each stage of its construction
-       */
-      assertTrue(ncl.isValid(),
-              String.format("Failed for scale = %d, i=%d", scale, i));
-      assertEquals(ncl.size(), count);
-    }
-    // System.out.println(ncl.prettyPrint());
-  }
-
-  /**
-   * A helper method that generates pseudo-random range queries and veries that
-   * findOverlaps returns the correct matches
-   * 
-   * @param ncl
-   *          the NCList to query
-   * @param scale
-   *          ncl maximal range is [0, scale]
-   * @param features
-   *          a list of the ranges stored in ncl
-   */
-  protected void testFindOverlaps_pseudoRandom(NCList<SequenceFeature> ncl,
-          int scale,
-          List<SequenceFeature> features)
-  {
-    int halfScale = scale / 2;
-    int minIterations = 20;
-
-    /*
-     * generates ranges in [-halfScale, scale+halfScale]
-     * - some should be internal to [0, scale] P = 1/4
-     * - some should lie before 0 P = 1/16
-     * - some should lie after scale P = 1/16
-     * - some should overlap left P = 1/4
-     * - some should overlap right P = 1/4
-     * - some should enclose P = 1/8
-     * 
-     * 50 iterations give a 96% probability of including the
-     * unlikeliest case; keep going until we have done all!
-     */
-    boolean inside = false;
-    boolean enclosing = false;
-    boolean before = false;
-    boolean after = false;
-    boolean overlapLeft = false;
-    boolean overlapRight = false;
-    boolean allCasesCovered = false;
-
-    int i = 0;
-    while (i < minIterations || !allCasesCovered)
-    {
-      i++;
-      int r1 = random.nextInt((scale + 1) * 2);
-      int r2 = random.nextInt((scale + 1) * 2);
-      int from = Math.min(r1, r2) - halfScale;
-      int to = Math.max(r1, r2) - halfScale;
-
-      /*
-       * ensure all cases of interest get covered
-       */
-      inside |= from >= 0 && to <= scale;
-      enclosing |= from <= 0 && to >= scale;
-      before |= to < 0;
-      after |= from > scale;
-      overlapLeft |= from < 0 && to >= 0 && to <= scale;
-      overlapRight |= from >= 0 && from <= scale && to > scale;
-      if (!allCasesCovered)
-      {
-        allCasesCovered |= inside && enclosing && before && after
-              && overlapLeft && overlapRight;
-        if (allCasesCovered)
-        {
-          System.out
-                  .println(String
-                          .format("Covered all findOverlaps cases after %d iterations for scale %d",
-                                  i, scale));
-        }
-      }
-
-      verifyFindOverlaps(ncl, from, to, features);
-    }
-  }
-
-  /**
-   * A helper method that verifies that overlaps found by interrogating an
-   * NCList correctly match those found by brute force search
-   * 
-   * @param ncl
-   * @param from
-   * @param to
-   * @param features
-   */
-  protected void verifyFindOverlaps(NCList<SequenceFeature> ncl, int from,
-          int to, List<SequenceFeature> features)
-  {
-    List<SequenceFeature> overlaps = ncl.findOverlaps(from, to);
-
-    /*
-     * check returned entries do indeed overlap from-to range
-     */
-    for (ContiguousI sf : overlaps)
-    {
-      int begin = sf.getBegin();
-      int end = sf.getEnd();
-      assertTrue(begin <= to && end >= from, String.format(
-              "[%d, %d] does not overlap query range [%d, %d]", begin, end,
-              from, to));
-    }
-
-    /*
-     * check overlapping ranges are included in the results
-     * (the test above already shows non-overlapping ranges are not)
-     */
-    for (ContiguousI sf : features)
-    {
-      int begin = sf.getBegin();
-      int end = sf.getEnd();
-      if (begin <= to && end >= from)
-      {
-        boolean found = overlaps.contains(sf);
-        assertTrue(found, String.format(
-                "[%d, %d] missing in query range [%d, %d]", begin, end,
-                from, to));
-      }
-    }
-  }
-
-  @Test(groups = "Functional")
-  public void testGetEntries()
-  {
-    List<Range> ranges = new ArrayList<Range>();
-    Range r1 = new Range(20, 20);
-    Range r2 = new Range(10, 20);
-    Range r3 = new Range(15, 30);
-    Range r4 = new Range(10, 30);
-    Range r5 = new Range(11, 19);
-    Range r6 = new Range(10, 20);
-    ranges.add(r1);
-    ranges.add(r2);
-    ranges.add(r3);
-    ranges.add(r4);
-    ranges.add(r5);
-    ranges.add(r6);
-  
-    NCList<Range> ncl = new NCList<Range>(ranges);
-    Range r7 = new Range(1, 100);
-    ncl.add(r7);
-
-    List<Range> contents = ncl.getEntries();
-    assertEquals(contents.size(), 7);
-    assertTrue(contents.contains(r1));
-    assertTrue(contents.contains(r2));
-    assertTrue(contents.contains(r3));
-    assertTrue(contents.contains(r4));
-    assertTrue(contents.contains(r5));
-    assertTrue(contents.contains(r6));
-    assertTrue(contents.contains(r7));
-
-    ncl = new NCList<Range>();
-    assertTrue(ncl.getEntries().isEmpty());
-  }
-
-  @Test(groups = "Functional")
-  public void testDelete()
-  {
-    List<Range> ranges = new ArrayList<Range>();
-    Range r1 = new Range(20, 30);
-    ranges.add(r1);
-    NCList<Range> ncl = new NCList<Range>(ranges);
-    assertTrue(ncl.getEntries().contains(r1));
-
-    Range r2 = new Range(20, 30);
-    assertFalse(ncl.delete(null)); // null argument
-    assertFalse(ncl.delete(r2)); // never added
-    assertTrue(ncl.delete(r1)); // success
-    assertTrue(ncl.getEntries().isEmpty());
-
-    /*
-     * tests where object.equals() == true
-     */
-    NCList<SequenceFeature> features = new NCList<SequenceFeature>();
-    SequenceFeature sf1 = new SequenceFeature("type", "desc", 1, 10, 2f,
-            "group");
-    SequenceFeature sf2 = new SequenceFeature("type", "desc", 1, 10, 2f,
-            "group");
-    features.add(sf1);
-    assertEquals(sf1, sf2); // sf1.equals(sf2)
-    assertFalse(features.delete(sf2)); // equality is not enough for deletion
-    assertTrue(features.getEntries().contains(sf1)); // still there!
-    assertTrue(features.delete(sf1));
-    assertTrue(features.getEntries().isEmpty()); // gone now
-
-    /*
-     * test with duplicate objects in NCList
-     */
-    features.add(sf1);
-    features.add(sf1);
-    assertEquals(features.getEntries().size(), 2);
-    assertSame(features.getEntries().get(0), sf1);
-    assertSame(features.getEntries().get(1), sf1);
-    assertTrue(features.delete(sf1)); // first match only is deleted
-    assertTrue(features.contains(sf1));
-    assertEquals(features.size(), 1);
-    assertTrue(features.delete(sf1));
-    assertTrue(features.getEntries().isEmpty());
-  }
-
-  @Test(groups = "Functional")
-  public void testAdd_overlapping()
-  {
-    List<Range> ranges = new ArrayList<Range>();
-    ranges.add(new Range(40, 50));
-    ranges.add(new Range(20, 30));
-    NCList<Range> ncl = new NCList<Range>(ranges);
-    assertEquals(ncl.toString(), "[20-30, 40-50]");
-    assertTrue(ncl.isValid());
-  
-    /*
-     * add range overlapping internally
-     */
-    ncl.add(new Range(25, 35));
-    assertEquals(ncl.toString(), "[20-30, 25-35, 40-50]");
-    assertTrue(ncl.isValid());
-
-    /*
-     * add range overlapping last range
-     */
-    ncl.add(new Range(45, 55));
-    assertEquals(ncl.toString(), "[20-30, 25-35, 40-50, 45-55]");
-    assertTrue(ncl.isValid());
-
-    /*
-     * add range overlapping first range
-     */
-    ncl.add(new Range(15, 25));
-    assertEquals(ncl.toString(), "[15-25, 20-30, 25-35, 40-50, 45-55]");
-    assertTrue(ncl.isValid());
-  }
-
-  /**
-   * Test the contains method (which uses object equals test)
-   */
-  @Test(groups = "Functional")
-  public void testContains()
-  {
-    NCList<SequenceFeature> ncl = new NCList<SequenceFeature>();
-    SequenceFeature sf1 = new SequenceFeature("type", "desc", 1, 10, 2f,
-            "group");
-    SequenceFeature sf2 = new SequenceFeature("type", "desc", 1, 10, 2f,
-            "group");
-    SequenceFeature sf3 = new SequenceFeature("type", "desc", 1, 10, 2f,
-            "anothergroup");
-    ncl.add(sf1);
-
-    assertTrue(ncl.contains(sf1));
-    assertTrue(ncl.contains(sf2)); // sf1.equals(sf2)
-    assertFalse(ncl.contains(sf3)); // !sf1.equals(sf3)
-
-    /*
-     * make some deeper structure in the NCList
-     */
-    SequenceFeature sf4 = new SequenceFeature("type", "desc", 2, 9, 2f,
-            "group");
-    ncl.add(sf4);
-    assertTrue(ncl.contains(sf4));
-    SequenceFeature sf5 = new SequenceFeature("type", "desc", 4, 5, 2f,
-            "group");
-    SequenceFeature sf6 = new SequenceFeature("type", "desc", 6, 8, 2f,
-            "group");
-    ncl.add(sf5);
-    ncl.add(sf6);
-    assertTrue(ncl.contains(sf5));
-    assertTrue(ncl.contains(sf6));
-  }
-
-  @Test(groups = "Functional")
-  public void testIsValid()
-  {
-    List<Range> ranges = new ArrayList<Range>();
-    Range r1 = new Range(40, 50);
-    ranges.add(r1);
-    NCList<Range> ncl = new NCList<Range>(ranges);
-    assertTrue(ncl.isValid());
-
-    Range r2 = new Range(42, 44);
-    ncl.add(r2);
-    assertTrue(ncl.isValid());
-    Range r3 = new Range(46, 48);
-    ncl.add(r3);
-    assertTrue(ncl.isValid());
-    Range r4 = new Range(43, 43);
-    ncl.add(r4);
-    assertTrue(ncl.isValid());
-
-    assertEquals(ncl.toString(), "[40-50 [42-44 [43-43], 46-48]]");
-    assertTrue(ncl.isValid());
-
-    PA.setValue(r1, "start", 43);
-    assertFalse(ncl.isValid()); // r2 not inside r1
-    PA.setValue(r1, "start", 40);
-    assertTrue(ncl.isValid());
-
-    PA.setValue(r3, "start", 41);
-    assertFalse(ncl.isValid()); // r3 should precede r2
-    PA.setValue(r3, "start", 46);
-    assertTrue(ncl.isValid());
-
-    PA.setValue(r4, "start", 41);
-    assertFalse(ncl.isValid()); // r4 not inside r2
-    PA.setValue(r4, "start", 43);
-    assertTrue(ncl.isValid());
-
-    PA.setValue(r4, "start", 44);
-    assertFalse(ncl.isValid()); // r4 has reverse range
-  }
-
-  @Test(groups = "Functional")
-  public void testPrettyPrint()
-  {
-    /*
-     * construct NCList from a list of ranges
-     * they are sorted then assembled into NCList subregions
-     * notice that 42-42 end up inside 41-46
-     */
-    List<Range> ranges = new ArrayList<Range>();
-    ranges.add(new Range(40, 50));
-    ranges.add(new Range(45, 55));
-    ranges.add(new Range(40, 45));
-    ranges.add(new Range(41, 46));
-    ranges.add(new Range(42, 42));
-    ranges.add(new Range(42, 42));
-    NCList<Range> ncl = new NCList<Range>(ranges);
-    assertTrue(ncl.isValid());
-    assertEquals(ncl.toString(),
-            "[40-50 [40-45], 41-46 [42-42 [42-42]], 45-55]");
-    String expected = "40-50\n  40-45\n41-46\n  42-42\n    42-42\n45-55\n";
-    assertEquals(ncl.prettyPrint(), expected);
-
-    /*
-     * repeat but now add ranges one at a time
-     * notice that 42-42 end up inside 40-50 so we get
-     * a different but equal valid NCList structure
-     */
-    ranges.clear();
-    ncl = new NCList<Range>(ranges);
-    ncl.add(new Range(40, 50));
-    ncl.add(new Range(45, 55));
-    ncl.add(new Range(40, 45));
-    ncl.add(new Range(41, 46));
-    ncl.add(new Range(42, 42));
-    ncl.add(new Range(42, 42));
-    assertTrue(ncl.isValid());
-    assertEquals(ncl.toString(),
-            "[40-50 [40-45 [42-42 [42-42]], 41-46], 45-55]");
-    expected = "40-50\n  40-45\n    42-42\n      42-42\n  41-46\n45-55\n";
-    assertEquals(ncl.prettyPrint(), expected);
-  }
-
-  /**
-   * A test that shows different valid trees can be constructed from the same
-   * set of ranges, depending on the order of construction
-   */
-  @Test(groups = "Functional")
-  public void testConstructor_alternativeTrees()
-  {
-    List<Range> ranges = new ArrayList<Range>();
-    ranges.add(new Range(10, 60));
-    ranges.add(new Range(20, 30));
-    ranges.add(new Range(40, 50));
-  
-    /*
-     * constructor with greedy traversal of sorted ranges to build nested
-     * containment lists results in 20-30 inside 10-60, 40-50 a sibling
-     */
-    NCList<Range> ncl = new NCList<Range>(ranges);
-    assertEquals(ncl.toString(), "[10-60 [20-30], 40-50]");
-    assertTrue(ncl.isValid());
-
-    /*
-     * adding ranges one at a time results in 40-50 
-     * a sibling of 20-30 inside 10-60
-     */
-    ncl = new NCList<Range>(new Range(10, 60));
-    ncl.add(new Range(20, 30));
-    ncl.add(new Range(40, 50));
-    assertEquals(ncl.toString(), "[10-60 [20-30, 40-50]]");
-    assertTrue(ncl.isValid());
-  }
-}
diff --git a/test/jalview/datamodel/features/NCNodeTest.java b/test/jalview/datamodel/features/NCNodeTest.java
deleted file mode 100644 (file)
index 4713084..0000000
+++ /dev/null
@@ -1,136 +0,0 @@
-package jalview.datamodel.features;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertTrue;
-
-import jalview.datamodel.Range;
-import jalview.datamodel.SequenceFeature;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import junit.extensions.PA;
-
-import org.testng.annotations.Test;
-
-public class NCNodeTest
-{
-  @Test(groups = "Functional")
-  public void testAdd()
-  {
-    Range r1 = new Range(10, 20);
-    NCNode<Range> node = new NCNode<Range>(r1);
-    assertEquals(node.getBegin(), 10);
-    Range r2 = new Range(10, 15);
-    node.add(r2);
-
-    List<Range> contents = new ArrayList<Range>();
-    node.getEntries(contents);
-    assertEquals(contents.size(), 2);
-    assertTrue(contents.contains(r1));
-    assertTrue(contents.contains(r2));
-  }
-
-  @Test(
-    groups = "Functional",
-    expectedExceptions = { IllegalArgumentException.class })
-  public void testAdd_invalidRangeStart()
-  {
-    Range r1 = new Range(10, 20);
-    NCNode<Range> node = new NCNode<Range>(r1);
-    assertEquals(node.getBegin(), 10);
-    Range r2 = new Range(9, 15);
-    node.add(r2);
-  }
-
-  @Test(
-    groups = "Functional",
-    expectedExceptions = { IllegalArgumentException.class })
-  public void testAdd_invalidRangeEnd()
-  {
-    Range r1 = new Range(10, 20);
-    NCNode<Range> node = new NCNode<Range>(r1);
-    assertEquals(node.getBegin(), 10);
-    Range r2 = new Range(12, 21);
-    node.add(r2);
-  }
-
-  @Test(groups = "Functional")
-  public void testGetEntries()
-  {
-    Range r1 = new Range(10, 20);
-    NCNode<Range> node = new NCNode<Range>(r1);
-    List<Range> entries = new ArrayList<Range>();
-
-    node.getEntries(entries);
-    assertEquals(entries.size(), 1);
-    assertTrue(entries.contains(r1));
-
-    // clearing the returned list does not affect the NCNode
-    entries.clear();
-    node.getEntries(entries);
-    assertEquals(entries.size(), 1);
-    assertTrue(entries.contains(r1));
-
-    Range r2 = new Range(15, 18);
-    node.add(r2);
-    entries.clear();
-    node.getEntries(entries);
-    assertEquals(entries.size(), 2);
-    assertTrue(entries.contains(r1));
-    assertTrue(entries.contains(r2));
-  }
-
-  /**
-   * Tests for the contains method (uses entry.equals() test)
-   */
-  @Test(groups = "Functional")
-  public void testContains()
-  {
-    SequenceFeature sf1 = new SequenceFeature("type", "desc", 1, 10, 2f,
-            "group");
-    SequenceFeature sf2 = new SequenceFeature("type", "desc", 1, 10, 2f,
-            "group");
-    SequenceFeature sf3 = new SequenceFeature("type", "desc", 1, 10, 2f,
-            "anothergroup");
-    NCNode<SequenceFeature> node = new NCNode<SequenceFeature>(sf1);
-
-    assertFalse(node.contains(null));
-    assertTrue(node.contains(sf1));
-    assertTrue(node.contains(sf2)); // sf1.equals(sf2)
-    assertFalse(node.contains(sf3)); // !sf1.equals(sf3)
-  }
-
-  /**
-   * Test method that checks for valid structure. Valid means that all
-   * subregions (if any) lie within the root range, and that all subregions have
-   * valid structure.
-   */
-  @Test(groups = "Functional")
-  public void testIsValid()
-  {
-    Range r1 = new Range(10, 20);
-    Range r2 = new Range(14, 15);
-    Range r3 = new Range(16, 17);
-    NCNode<Range> node = new NCNode<Range>(r1);
-    node.add(r2);
-    node.add(r3);
-
-    /*
-     * node has root range [10-20] and contains an
-     * NCList of [14-15, 16-17]
-     */
-    assertTrue(node.isValid());
-    PA.setValue(r1, "start", 15);
-    assertFalse(node.isValid()); // r2 not within r1
-    PA.setValue(r1, "start", 10);
-    assertTrue(node.isValid());
-    PA.setValue(r1, "end", 16);
-    assertFalse(node.isValid()); // r3 not within r1
-    PA.setValue(r1, "end", 20);
-    assertTrue(node.isValid());
-    PA.setValue(r3, "start", 12);
-    assertFalse(node.isValid()); // r3 should precede r2
-  }
-}
diff --git a/test/jalview/datamodel/features/RangeComparatorTest.java b/test/jalview/datamodel/features/RangeComparatorTest.java
deleted file mode 100644 (file)
index 4849b38..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-package jalview.datamodel.features;
-
-import static org.testng.Assert.assertEquals;
-
-import jalview.datamodel.ContiguousI;
-import jalview.datamodel.Range;
-
-import java.util.Comparator;
-
-import org.testng.annotations.Test;
-
-public class RangeComparatorTest
-{
-
-  @Test(groups = "Functional")
-  public void testCompare()
-  {
-    RangeComparator comp = new RangeComparator(true);
-
-    // same position, same length
-    assertEquals(comp.compare(10, 10, 20, 20), 0);
-    // same position, len1 > len2
-    assertEquals(comp.compare(10, 10, 20, 19), -1);
-    // same position, len1 < len2
-    assertEquals(comp.compare(10, 10, 20, 21), 1);
-    // pos1 > pos2
-    assertEquals(comp.compare(11, 10, 20, 20), 1);
-    // pos1 < pos2
-    assertEquals(comp.compare(10, 11, 20, 10), -1);
-  }
-
-  @Test(groups = "Functional")
-  public void testCompare_byStart()
-  {
-    Comparator<ContiguousI> comp = RangeComparator.BY_START_POSITION;
-
-    // same start position, same length
-    assertEquals(comp.compare(new Range(10, 20), new Range(10, 20)), 0);
-    // same start position, len1 > len2
-    assertEquals(comp.compare(new Range(10, 20), new Range(10, 19)), -1);
-    // same start position, len1 < len2
-    assertEquals(comp.compare(new Range(10, 18), new Range(10, 20)), 1);
-    // pos1 > pos2
-    assertEquals(comp.compare(new Range(11, 20), new Range(10, 20)), 1);
-    // pos1 < pos2
-    assertEquals(comp.compare(new Range(10, 20), new Range(11, 20)), -1);
-  }
-
-  @Test(groups = "Functional")
-  public void testCompare_byEnd()
-  {
-    Comparator<ContiguousI> comp = RangeComparator.BY_END_POSITION;
-
-    // same end position, same length
-    assertEquals(comp.compare(new Range(10, 20), new Range(10, 20)), 0);
-    // same end position, len1 > len2
-    assertEquals(comp.compare(new Range(10, 20), new Range(11, 20)), -1);
-    // same end position, len1 < len2
-    assertEquals(comp.compare(new Range(11, 20), new Range(10, 20)), 1);
-    // end1 > end2
-    assertEquals(comp.compare(new Range(10, 21), new Range(10, 20)), 1);
-    // end1 < end2
-    assertEquals(comp.compare(new Range(10, 20), new Range(10, 21)), -1);
-  }
-}
index 32987b0..29e76bb 100644 (file)
@@ -1161,7 +1161,7 @@ public class SequenceFeaturesTest
   public void testShiftFeatures()
   {
     SequenceFeatures store = new SequenceFeatures();
-    assertFalse(store.shiftFeatures(1));
+    assertFalse(store.shiftFeatures(0, 1));
 
     SequenceFeature sf1 = new SequenceFeature("Cath", "", 2, 5, 0f, null);
     store.add(sf1);
@@ -1179,7 +1179,7 @@ public class SequenceFeaturesTest
     /*
      * shift features right by 5
      */
-    assertTrue(store.shiftFeatures(5));
+    assertTrue(store.shiftFeatures(0, 5));
   
     // non-positional features untouched:
     List<SequenceFeature> nonPos = store.getNonPositionalFeatures();
@@ -1208,7 +1208,7 @@ public class SequenceFeaturesTest
      * feature at [7-10] should be removed
      * feature at [13-19] should become [1-4] 
      */
-    assertTrue(store.shiftFeatures(-15));
+    assertTrue(store.shiftFeatures(0, -15));
     pos = store.getPositionalFeatures();
     assertEquals(pos.size(), 2);
     SequenceFeatures.sortFeatures(pos, true);
@@ -1218,6 +1218,35 @@ public class SequenceFeaturesTest
     assertEquals(pos.get(1).getBegin(), 13);
     assertEquals(pos.get(1).getEnd(), 22);
     assertEquals(pos.get(1).getType(), "Disulfide bond");
+
+    /*
+     * shift right by 4 from column 2
+     * feature at [1-4] should be unchanged
+     * feature at [13-22] should become [17-26] 
+     */
+    assertTrue(store.shiftFeatures(2, 4));
+    pos = store.getPositionalFeatures();
+    assertEquals(pos.size(), 2);
+    SequenceFeatures.sortFeatures(pos, true);
+    assertEquals(pos.get(0).getBegin(), 1);
+    assertEquals(pos.get(0).getEnd(), 4);
+    assertEquals(pos.get(0).getType(), "Metal");
+    assertEquals(pos.get(1).getBegin(), 17);
+    assertEquals(pos.get(1).getEnd(), 26);
+    assertEquals(pos.get(1).getType(), "Disulfide bond");
+
+    /*
+     * shift right from column 18
+     * should be no updates
+     */
+    SequenceFeature f1 = pos.get(0);
+    SequenceFeature f2 = pos.get(1);
+    assertFalse(store.shiftFeatures(18, 6));
+    pos = store.getPositionalFeatures();
+    assertEquals(pos.size(), 2);
+    SequenceFeatures.sortFeatures(pos, true);
+    assertSame(pos.get(0), f1);
+    assertSame(pos.get(1), f2);
   }
 
   @Test(groups = "Functional")
@@ -1232,4 +1261,18 @@ public class SequenceFeaturesTest
     assertTrue(store.isOntologyTerm("junk", new String[] {}));
     assertTrue(store.isOntologyTerm("junk", (String[]) null));
   }
+
+  @Test(groups = "Functional")
+  public void testDeleteAll()
+  {
+    SequenceFeaturesI store = new SequenceFeatures();
+    assertFalse(store.hasFeatures());
+    store.deleteAll();
+    assertFalse(store.hasFeatures());
+    store.add(new SequenceFeature("Cath", "Desc", 12, 20, 0f, "Group"));
+    store.add(new SequenceFeature("Pfam", "Desc", 6, 12, 2f, "Group2"));
+    assertTrue(store.hasFeatures());
+    store.deleteAll();
+    assertFalse(store.hasFeatures());
+  }
 }
index c9d8deb..9e9d9a4 100644 (file)
@@ -79,19 +79,19 @@ public class EnsemblCdnaTest
     // exon at (start+10000) length 501
     SequenceFeature sf = new SequenceFeature("exon", "", 20000, 20500, 0f,
             null);
-    sf.setValue("Parent", "transcript:" + transcriptId);
+    sf.setValue("Parent", transcriptId);
     sf.setStrand("-");
     genomic.addSequenceFeature(sf);
 
     // exon (sub-type) at (start + exon_variant) length 101
     sf = new SequenceFeature("coding_exon", "", 10500, 10600, 0f, null);
-    sf.setValue("Parent", "transcript:" + transcriptId);
+    sf.setValue("Parent", transcriptId);
     sf.setStrand("-");
     genomic.addSequenceFeature(sf);
 
     // exon belonging to a different transcript doesn't count
     sf = new SequenceFeature("exon", "", 11500, 12600, 0f, null);
-    sf.setValue("Parent", "transcript:anotherOne");
+    sf.setValue("Parent", "anotherOne");
     genomic.addSequenceFeature(sf);
 
     // transcript feature doesn't count
@@ -134,19 +134,19 @@ public class EnsemblCdnaTest
     // exon at (start+10000) length 501
     SequenceFeature sf = new SequenceFeature("exon", "", 20000, 20500, 0f,
             null);
-    sf.setValue("Parent", "transcript:" + transcriptId);
+    sf.setValue("Parent", transcriptId);
     sf.setStrand("+");
     genomic.addSequenceFeature(sf);
 
     // exon (sub-type) at (start + exon_variant) length 101
     sf = new SequenceFeature("coding_exon", "", 10500, 10600, 0f, null);
-    sf.setValue("Parent", "transcript:" + transcriptId);
+    sf.setValue("Parent", transcriptId);
     sf.setStrand("+");
     genomic.addSequenceFeature(sf);
 
     // exon belonging to a different transcript doesn't count
     sf = new SequenceFeature("exon", "", 11500, 12600, 0f, null);
-    sf.setValue("Parent", "transcript:anotherOne");
+    sf.setValue("Parent", "anotherOne");
     genomic.addSequenceFeature(sf);
 
     // transcript feature doesn't count
@@ -226,14 +226,14 @@ public class EnsemblCdnaTest
     assertTrue(testee.retainFeature(sf, accId));
 
     // other feature with desired parent is retained
-    sf.setValue("Parent", "transcript:" + accId);
+    sf.setValue("Parent", accId);
     assertTrue(testee.retainFeature(sf, accId));
 
     // test is not case-sensitive
     assertTrue(testee.retainFeature(sf, accId.toLowerCase()));
 
     // feature with wrong parent is not retained
-    sf.setValue("Parent", "transcript:XYZ");
+    sf.setValue("Parent", "XYZ");
     assertFalse(testee.retainFeature(sf, accId));
   }
 
@@ -253,30 +253,30 @@ public class EnsemblCdnaTest
 
     // exon with wrong parent: not valid
     SequenceFeature sf2 = new SequenceFeature("exon", "", 1, 2, 0f, null);
-    sf2.setValue("Parent", "transcript:XYZ");
+    sf2.setValue("Parent", "XYZ");
     seq.addSequenceFeature(sf2);
 
     // exon with right parent is valid
     SequenceFeature sf3 = new SequenceFeature("exon", "", 1, 2, 0f, null);
-    sf3.setValue("Parent", "transcript:" + accId);
+    sf3.setValue("Parent", accId);
     seq.addSequenceFeature(sf3);
 
     // exon sub-type with right parent is valid
     SequenceFeature sf4 = new SequenceFeature("coding_exon", "", 1, 2, 0f,
             null);
-    sf4.setValue("Parent", "transcript:" + accId);
+    sf4.setValue("Parent", accId);
     seq.addSequenceFeature(sf4);
 
     // transcript not valid:
     SequenceFeature sf5 = new SequenceFeature("transcript", "", 1, 2, 0f,
             null);
-    sf5.setValue("Parent", "transcript:" + accId);
+    sf5.setValue("Parent", accId);
     seq.addSequenceFeature(sf5);
 
     // CDS not valid:
     SequenceFeature sf6 = new SequenceFeature("transcript", "", 1, 2, 0f,
             null);
-    sf6.setValue("Parent", "transcript:" + accId);
+    sf6.setValue("Parent", accId);
     seq.addSequenceFeature(sf6);
 
     List<SequenceFeature> sfs = new EnsemblCdna()
index a44ab7f..e7574eb 100644 (file)
@@ -78,19 +78,19 @@ public class EnsemblCdsTest
     // CDS at (start+10000) length 501
     SequenceFeature sf = new SequenceFeature("CDS", "", 20000, 20500, 0f,
             null);
-    sf.setValue("Parent", "transcript:" + transcriptId);
+    sf.setValue("Parent", transcriptId);
     sf.setStrand("+");
     genomic.addSequenceFeature(sf);
 
     // CDS (sub-type) at (start + 10500) length 101
     sf = new SequenceFeature("CDS_predicted", "", 10500, 10600, 0f, null);
-    sf.setValue("Parent", "transcript:" + transcriptId);
+    sf.setValue("Parent", transcriptId);
     sf.setStrand("+");
     genomic.addSequenceFeature(sf);
 
     // CDS belonging to a different transcript doesn't count
     sf = new SequenceFeature("CDS", "", 11500, 12600, 0f, null);
-    sf.setValue("Parent", "transcript:anotherOne");
+    sf.setValue("Parent", "anotherOne");
     genomic.addSequenceFeature(sf);
 
     // exon feature doesn't count
@@ -135,16 +135,16 @@ public class EnsemblCdsTest
     assertFalse(testee.retainFeature(sf, accId));
 
     // other feature with no parent is retained
-    sf = new SequenceFeature("CDS_psequence_variantredicted", "", 20000,
+    sf = new SequenceFeature("anotherType", "", 20000,
             20500, 0f, null);
     assertTrue(testee.retainFeature(sf, accId));
 
     // other feature with desired parent is retained
-    sf.setValue("Parent", "transcript:" + accId);
+    sf.setValue("Parent", accId);
     assertTrue(testee.retainFeature(sf, accId));
 
     // feature with wrong parent is not retained
-    sf.setValue("Parent", "transcript:XYZ");
+    sf.setValue("Parent", "XYZ");
     assertFalse(testee.retainFeature(sf, accId));
   }
 
@@ -164,29 +164,29 @@ public class EnsemblCdsTest
 
     // cds with wrong parent not valid
     SequenceFeature sf2 = new SequenceFeature("CDS", "", 1, 2, 0f, null);
-    sf2.setValue("Parent", "transcript:XYZ");
+    sf2.setValue("Parent", "XYZ");
     seq.addSequenceFeature(sf2);
 
     // cds with right parent is valid
     SequenceFeature sf3 = new SequenceFeature("CDS", "", 1, 2, 0f, null);
-    sf3.setValue("Parent", "transcript:" + accId);
+    sf3.setValue("Parent", accId);
     seq.addSequenceFeature(sf3);
 
     // cds sub-type with right parent is valid
     SequenceFeature sf4 = new SequenceFeature("CDS_predicted", "", 1, 2, 0f,
             null);
-    sf4.setValue("Parent", "transcript:" + accId);
+    sf4.setValue("Parent", accId);
     seq.addSequenceFeature(sf4);
 
     // transcript not valid:
     SequenceFeature sf5 = new SequenceFeature("transcript", "", 1, 2, 0f,
             null);
-    sf5.setValue("Parent", "transcript:" + accId);
+    sf5.setValue("Parent", accId);
     seq.addSequenceFeature(sf5);
 
     // exon not valid:
     SequenceFeature sf6 = new SequenceFeature("exon", "", 1, 2, 0f, null);
-    sf6.setValue("Parent", "transcript:" + accId);
+    sf6.setValue("Parent", accId);
     seq.addSequenceFeature(sf6);
 
     List<SequenceFeature> sfs = new EnsemblCds().getIdentifyingFeatures(seq,
index 446b4f7..8b1e840 100644 (file)
@@ -81,7 +81,7 @@ public class EnsemblGeneTest
     // gene at (start + 10500) length 101
     SequenceFeature sf = new SequenceFeature("gene", "", 10500, 10600, 0f,
             null);
-    sf.setValue("ID", "gene:" + geneId);
+    sf.setValue("id", geneId);
     sf.setStrand("+");
     genomic.addSequenceFeature(sf);
 
@@ -113,7 +113,7 @@ public class EnsemblGeneTest
     // gene at (start + 10500) length 101
     SequenceFeature sf = new SequenceFeature("gene", "", 10500, 10600, 0f,
             null);
-    sf.setValue("ID", "gene:" + geneId);
+    sf.setValue("id", geneId);
     sf.setStrand("+");
     genomic.addSequenceFeature(sf);
 
@@ -146,30 +146,30 @@ public class EnsemblGeneTest
     // transcript feature
     SequenceFeature sf1 = new SequenceFeature("transcript", "", 20000,
             20500, 0f, null);
-    sf1.setValue("Parent", "gene:" + geneId);
-    sf1.setValue("transcript_id", "transcript1");
+    sf1.setValue("Parent", geneId);
+    sf1.setValue("id", "transcript1");
     genomic.addSequenceFeature(sf1);
 
     // transcript sub-type feature
     SequenceFeature sf2 = new SequenceFeature("snRNA", "", 21000, 21500,
             0f, null);
-    sf2.setValue("Parent", "gene:" + geneId);
-    sf2.setValue("transcript_id", "transcript2");
+    sf2.setValue("Parent", geneId);
+    sf2.setValue("id", "transcript2");
     genomic.addSequenceFeature(sf2);
 
     // NMD_transcript_variant treated like transcript in Ensembl
     SequenceFeature sf3 = new SequenceFeature("NMD_transcript_variant", "",
             22000, 22500, 0f, null);
     // id matching should not be case-sensitive
-    sf3.setValue("Parent", "gene:" + geneId.toLowerCase());
-    sf3.setValue("transcript_id", "transcript3");
+    sf3.setValue("Parent", geneId.toLowerCase());
+    sf3.setValue("id", "transcript3");
     genomic.addSequenceFeature(sf3);
 
     // transcript for a different gene - ignored
     SequenceFeature sf4 = new SequenceFeature("snRNA", "", 23000, 23500,
             0f, null);
-    sf4.setValue("Parent", "gene:XYZ");
-    sf4.setValue("transcript_id", "transcript4");
+    sf4.setValue("Parent", "XYZ");
+    sf4.setValue("id", "transcript4");
     genomic.addSequenceFeature(sf4);
 
     EnsemblGene testee = new EnsemblGene();
@@ -196,24 +196,24 @@ public class EnsemblGeneTest
     EnsemblGene testee = new EnsemblGene();
     SequenceFeature sf = new SequenceFeature("gene", "", 20000, 20500, 0f,
             null);
-    sf.setValue("ID", "gene:" + geneId);
+    sf.setValue("id", geneId);
     assertFalse(testee.retainFeature(sf, geneId));
 
     sf = new SequenceFeature("transcript", "", 20000, 20500, 0f, null);
-    sf.setValue("Parent", "gene:" + geneId);
+    sf.setValue("Parent", geneId);
     assertTrue(testee.retainFeature(sf, geneId));
 
     sf = new SequenceFeature("mature_transcript", "", 20000, 20500, 0f,
             null);
-    sf.setValue("Parent", "gene:" + geneId);
+    sf.setValue("Parent", geneId);
     assertTrue(testee.retainFeature(sf, geneId));
 
     sf = new SequenceFeature("NMD_transcript_variant", "", 20000, 20500,
             0f, null);
-    sf.setValue("Parent", "gene:" + geneId);
+    sf.setValue("Parent", geneId);
     assertTrue(testee.retainFeature(sf, geneId));
 
-    sf.setValue("Parent", "gene:XYZ");
+    sf.setValue("Parent", "ßXYZ");
     assertFalse(testee.retainFeature(sf, geneId));
 
     sf = new SequenceFeature("anything", "", 20000, 20500, 0f, null);
@@ -235,28 +235,28 @@ public class EnsemblGeneTest
     seq.addSequenceFeature(sf1);
 
     // gene with wrong ID not valid
-    SequenceFeature sf2 = new SequenceFeature("gene", "", 1, 2, 0f, null);
-    sf2.setValue("ID", "gene:XYZ");
+    SequenceFeature sf2 = new SequenceFeature("gene", "a", 1, 2, 0f, null);
+    sf2.setValue("id", "XYZ");
     seq.addSequenceFeature(sf2);
 
     // gene with right ID is valid
-    SequenceFeature sf3 = new SequenceFeature("gene", "", 1, 2, 0f, null);
-    sf3.setValue("ID", "gene:" + accId);
+    SequenceFeature sf3 = new SequenceFeature("gene", "b", 1, 2, 0f, null);
+    sf3.setValue("id", accId);
     seq.addSequenceFeature(sf3);
 
     // gene sub-type with right ID is valid
     SequenceFeature sf4 = new SequenceFeature("snRNA_gene", "", 1, 2, 0f, null);
-    sf4.setValue("ID", "gene:" + accId);
+    sf4.setValue("id", accId);
     seq.addSequenceFeature(sf4);
 
     // transcript not valid:
     SequenceFeature sf5 = new SequenceFeature("transcript", "", 1, 2, 0f, null);
-    sf5.setValue("ID", "gene:" + accId);
+    sf5.setValue("id", accId);
     seq.addSequenceFeature(sf5);
 
     // exon not valid:
     SequenceFeature sf6 = new SequenceFeature("exon", "", 1, 2, 0f, null);
-    sf6.setValue("ID", "gene:" + accId);
+    sf6.setValue("id", accId);
     seq.addSequenceFeature(sf6);
     
     List<SequenceFeature> sfs = new EnsemblGene()
index 72ee492..11140f9 100644 (file)
@@ -77,13 +77,13 @@ public class EnsemblGenomeTest
     // transcript at (start+10000) length 501
     SequenceFeature sf = new SequenceFeature("transcript", "", 20000,
             20500, 0f, null);
-    sf.setValue("ID", "transcript:" + transcriptId);
+    sf.setValue("id", transcriptId);
     sf.setStrand("+");
     genomic.addSequenceFeature(sf);
 
     // transcript (sub-type) at (start + 10500) length 101
     sf = new SequenceFeature("ncRNA", "", 10500, 10600, 0f, null);
-    sf.setValue("ID", "transcript:" + transcriptId);
+    sf.setValue("id", transcriptId);
     sf.setStrand("+");
     genomic.addSequenceFeature(sf);
 
@@ -91,13 +91,13 @@ public class EnsemblGenomeTest
     // although strictly it is a sequence_variant in SO
     sf = new SequenceFeature("NMD_transcript_variant", "", 11000, 12000,
             0f, null);
-    sf.setValue("ID", "transcript:" + transcriptId);
+    sf.setValue("id", transcriptId);
     sf.setStrand("+");
     genomic.addSequenceFeature(sf);
 
     // transcript with a different ID doesn't count
     sf = new SequenceFeature("transcript", "", 11500, 12600, 0f, null);
-    sf.setValue("ID", "transcript:anotherOne");
+    sf.setValue("id", "anotherOne");
     genomic.addSequenceFeature(sf);
 
     // parent of transcript feature doesn't count
@@ -150,11 +150,11 @@ public class EnsemblGenomeTest
     assertTrue(testee.retainFeature(sf, accId));
 
     // other feature with correct parent is kept
-    sf.setValue("Parent", "transcript:" + accId);
+    sf.setValue("Parent", accId);
     assertTrue(testee.retainFeature(sf, accId));
 
     // other feature with wrong parent is not kept
-    sf.setValue("Parent", "transcript:XYZ");
+    sf.setValue("Parent", "XYZ");
     assertFalse(testee.retainFeature(sf, accId));
   }
 
@@ -174,36 +174,37 @@ public class EnsemblGenomeTest
     seq.addSequenceFeature(sf1);
 
     // transcript with wrong ID not valid
-    SequenceFeature sf2 = new SequenceFeature("transcript", "", 1, 2, 0f,
+    // NB change desc to avoid rejection of duplicate feature!
+    SequenceFeature sf2 = new SequenceFeature("transcript", "a", 1, 2, 0f,
             null);
-    sf2.setValue("ID", "transcript");
+    sf2.setValue("id", "transcript");
     seq.addSequenceFeature(sf2);
 
     // transcript with right ID is valid
-    SequenceFeature sf3 = new SequenceFeature("transcript", "", 1, 2, 0f,
+    SequenceFeature sf3 = new SequenceFeature("transcript", "b", 1, 2, 0f,
             null);
-    sf3.setValue("ID", "transcript:" + accId);
+    sf3.setValue("id", accId);
     seq.addSequenceFeature(sf3);
 
     // transcript sub-type with right ID is valid
     SequenceFeature sf4 = new SequenceFeature("ncRNA", "", 1, 2, 0f, null);
-    sf4.setValue("ID", "transcript:" + accId);
+    sf4.setValue("id", accId);
     seq.addSequenceFeature(sf4);
 
     // Ensembl treats NMD_transcript_variant as if a transcript
     SequenceFeature sf5 = new SequenceFeature("NMD_transcript_variant", "",
             1, 2, 0f, null);
-    sf5.setValue("ID", "transcript:" + accId);
+    sf5.setValue("id", accId);
     seq.addSequenceFeature(sf5);
 
     // gene not valid:
     SequenceFeature sf6 = new SequenceFeature("gene", "", 1, 2, 0f, null);
-    sf6.setValue("ID", "transcript:" + accId);
+    sf6.setValue("id", accId);
     seq.addSequenceFeature(sf6);
 
     // exon not valid:
     SequenceFeature sf7 = new SequenceFeature("exon", "", 1, 2, 0f, null);
-    sf7.setValue("ID", "transcript:" + accId);
+    sf7.setValue("id", accId);
     seq.addSequenceFeature(sf7);
 
     List<SequenceFeature> sfs = new EnsemblGenome()
index 69b2ad4..17e92c8 100644 (file)
@@ -234,30 +234,4 @@ public class EnsemblSeqProxyTest
     // verify attributes string is updated with reverse complement
     assertEquals("x=y,z;alleles=" + revcomp + ";a=b,c", sf.getAttributes());
   }
-
-  @Test(groups = "Functional")
-  public void testSortFeatures()
-  {
-    SequenceFeature sf1 = new SequenceFeature("", "", 10, 15, 0f, null);
-    SequenceFeature sf2 = new SequenceFeature("", "", 8, 12, 0f, null);
-    SequenceFeature sf3 = new SequenceFeature("", "", 8, 13, 0f, null);
-    SequenceFeature sf4 = new SequenceFeature("", "", 11, 11, 0f, null);
-    List<SequenceFeature> sfs = Arrays.asList(new SequenceFeature[] { sf1,
-        sf2, sf3, sf4 });
-
-    // sort by start position ascending (forward strand)
-    // sf2 and sf3 tie and should not be reordered by sorting
-    SequenceFeatures.sortFeatures(sfs, true);
-    assertSame(sfs.get(0), sf2);
-    assertSame(sfs.get(1), sf3);
-    assertSame(sfs.get(2), sf1);
-    assertSame(sfs.get(3), sf4);
-
-    // sort by end position descending (reverse strand)
-    SequenceFeatures.sortFeatures(sfs, false);
-    assertSame(sfs.get(0), sf1);
-    assertSame(sfs.get(1), sf3);
-    assertSame(sfs.get(2), sf2);
-    assertSame(sfs.get(3), sf4);
-  }
 }
index ad9bf03..69634a9 100644 (file)
@@ -103,10 +103,8 @@ public class TestHtsContigDb
       fail("Expected exception");
     } catch (IOException e)
     {
-      System.out.println(
-              "Caught IOException in testCreateFastaSequenceIndex");
-      e.printStackTrace();
-      // expected
+      // we expect an IO Exception because the pgmB.fasta.fai exists, since it
+      // was checked it in.
     }
 
     /*
index 4d904cf..99394dc 100644 (file)
@@ -41,7 +41,7 @@ public class ChimeraConnect
     JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
   }
 
-  @Test(groups = { "Functional" })
+  @Test(groups = { "External" })
   public void testLaunchAndExit()
   {
     final StructureManager structureManager = new StructureManager(true);
index bdda48d..454ff61 100644 (file)
@@ -20,6 +20,7 @@
  */
 package jalview.gui;
 
+import static org.junit.Assert.assertNotEquals;
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertFalse;
 import static org.testng.Assert.assertNotSame;
@@ -118,7 +119,8 @@ public class AlignFrameTest
      * seq1 feature in columns 1-5 is hidden
      * seq2 feature in columns 6-10 is shown
      */
-    FeatureColourI fc = new FeatureColour(Color.red, Color.blue, 0f, 10f);
+    FeatureColourI fc = new FeatureColour(null, Color.red, Color.blue, null,
+            0f, 10f);
     fc.setAboveThreshold(true);
     fc.setThreshold(5f);
     alignFrame.getFeatureRenderer().setColour("Metal", fc);
@@ -599,4 +601,26 @@ public class AlignFrameTest
     sp.valueChanged(22);
     assertEquals(av2.getResidueShading().getConservationInc(), 22);
   }
+
+  /**
+   * Verify that making a New View preserves the dataset reference for the
+   * alignment. Otherwise, see a 'duplicate jar entry' reference when trying to
+   * save alignments with multiple views, and codon mappings will not be shared
+   * across all panels in a split frame.
+   * 
+   * @see Jalview2xmlTests#testStoreAndRecoverColourThresholds()
+   */
+  @Test(groups = "Functional")
+  public void testNewView_dsRefPreserved()
+  {
+    AlignViewport av = af.getViewport();
+    AlignmentI al = av.getAlignment();
+    AlignmentI original_ds = al.getDataset();
+    af.newView_actionPerformed(null);
+    assertNotEquals("New view didn't select the a new panel", av,
+            af.getViewport());
+    org.testng.Assert.assertEquals(original_ds,
+            af.getViewport().getAlignment().getDataset(),
+            "Dataset was not preserved in new view");
+  }
 }
index 5ed0cac..959abb0 100644 (file)
@@ -23,6 +23,7 @@ package jalview.gui;
 import static org.testng.AssertJUnit.assertEquals;
 import static org.testng.AssertJUnit.assertFalse;
 import static org.testng.AssertJUnit.assertNotNull;
+import static org.testng.AssertJUnit.assertNotSame;
 import static org.testng.AssertJUnit.assertSame;
 import static org.testng.AssertJUnit.assertTrue;
 
@@ -33,8 +34,6 @@ import jalview.datamodel.Alignment;
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.Annotation;
-import jalview.datamodel.PDBEntry;
-import jalview.datamodel.PDBEntry.Type;
 import jalview.datamodel.SearchResults;
 import jalview.datamodel.SearchResultsI;
 import jalview.datamodel.Sequence;
@@ -42,6 +41,7 @@ import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
 import jalview.io.DataSourceType;
 import jalview.io.FileLoader;
+import jalview.schemes.ClustalxColourScheme;
 import jalview.schemes.ColourSchemeI;
 import jalview.schemes.PIDColourScheme;
 import jalview.structure.StructureSelectionManager;
@@ -277,7 +277,7 @@ public class AlignViewportTest
    * Test for JAL-1306 - conservation thread should run even when only Quality
    * (and not Conservation) is enabled in Preferences
    */
-  @Test(groups = { "Functional" })
+  @Test(groups = { "Functional" }, timeOut=2000)
   public void testUpdateConservation_qualityOnly()
   {
     Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS",
@@ -292,7 +292,24 @@ public class AlignViewportTest
             Boolean.FALSE.toString());
     AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
             "examples/uniref50.fa", DataSourceType.FILE);
-    AlignmentAnnotation[] anns = af.viewport.getAlignment()
+
+    /*
+     * wait for Conservation thread to complete
+     */
+    AlignViewport viewport = af.getViewport();
+    synchronized (this)
+    {
+      while (viewport.getAlignmentConservationAnnotation() != null)
+      {
+        try
+        {
+          wait(50);
+        } catch (InterruptedException e)
+        {
+        }
+      }
+    }
+    AlignmentAnnotation[] anns = viewport.getAlignment()
             .getAlignmentAnnotation();
     assertNotNull("No annotations found", anns);
     assertEquals("More than one annotation found", 1, anns.length);
@@ -316,9 +333,34 @@ public class AlignViewportTest
     AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
             "examples/uniref50.fa", DataSourceType.FILE);
     ColourSchemeI cs = new PIDColourScheme();
-    af.getViewport().setGlobalColourScheme(cs);
-    assertFalse(af.getViewport().getResidueShading()
+    AlignViewport viewport = af.getViewport();
+    viewport.setGlobalColourScheme(cs);
+    assertFalse(viewport.getResidueShading()
             .conservationApplied());
+
+    /*
+     * JAL-3201 groups have their own ColourSchemeI instances
+     */
+    AlignmentI aln = viewport.getAlignment();
+    SequenceGroup sg1 = new SequenceGroup();
+    sg1.addSequence(aln.getSequenceAt(0), false);
+    sg1.addSequence(aln.getSequenceAt(2), false);
+    SequenceGroup sg2 = new SequenceGroup();
+    sg2.addSequence(aln.getSequenceAt(1), false);
+    sg2.addSequence(aln.getSequenceAt(3), false);
+    aln.addGroup(sg1);
+    aln.addGroup(sg2);
+    viewport.setColourAppliesToAllGroups(true);
+    viewport.setGlobalColourScheme(new ClustalxColourScheme());
+    ColourSchemeI cs0 = viewport.getGlobalColourScheme();
+    ColourSchemeI cs1 = sg1.getColourScheme();
+    ColourSchemeI cs2 = sg2.getColourScheme();
+    assertTrue(cs0 instanceof ClustalxColourScheme);
+    assertTrue(cs1 instanceof ClustalxColourScheme);
+    assertTrue(cs2 instanceof ClustalxColourScheme);
+    assertNotSame(cs0, cs1);
+    assertNotSame(cs0, cs2);
+    assertNotSame(cs1, cs2);
   }
 
   @Test(groups = { "Functional" })
index 2819dbf..e84b87a 100644 (file)
@@ -222,7 +222,7 @@ public class AlignmentPanelTest
 
   /**
    * Test that update layout reverts to original (unwrapped) values for endRes
-   * and endSeq when switching from wrapped to unwrapped mode (JAL-2739)
+   * when switching from wrapped back to unwrapped mode (JAL-2739)
    */
   @Test(groups = "Functional")
   public void TestUpdateLayout_endRes()
@@ -235,14 +235,14 @@ public class AlignmentPanelTest
     af.alignPanel.getAlignViewport().setWrapAlignment(true);
     af.alignPanel.updateLayout();
 
-    // endRes changes
+    // endRes has changed
     assertNotEquals(ranges.getEndRes(), endres);
 
     // unwrap
     af.alignPanel.getAlignViewport().setWrapAlignment(false);
     af.alignPanel.updateLayout();
 
-    // endRes and endSeq back to original values
+    // endRes back to original value
     assertEquals(ranges.getEndRes(), endres);
 
   }
diff --git a/test/jalview/gui/AnnotationLabelsTest.java b/test/jalview/gui/AnnotationLabelsTest.java
new file mode 100644 (file)
index 0000000..616a1a6
--- /dev/null
@@ -0,0 +1,153 @@
+package jalview.gui;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNull;
+
+import jalview.datamodel.AlignmentAnnotation;
+import jalview.datamodel.Sequence;
+
+import org.testng.annotations.Test;
+
+public class AnnotationLabelsTest
+{
+  @Test(groups = "Functional")
+  public void testGetTooltip()
+  {
+    assertNull(AnnotationLabels.getTooltip(null));
+
+    /*
+     * simple description only
+     */
+    AlignmentAnnotation ann = new AlignmentAnnotation("thelabel", "thedesc",
+            null);
+    String expected = "<html>thedesc</html>";
+    assertEquals(AnnotationLabels.getTooltip(ann), expected);
+
+    /*
+     * description needing html encoding
+     * (no idea why '<' is encoded but '>' is not)
+     */
+    ann.description = "TCoffee scores < 56 and > 28";
+    expected = "<html>TCoffee scores &lt; 56 and > 28</html>";
+    assertEquals(AnnotationLabels.getTooltip(ann), expected);
+
+    /*
+     * description already html formatted
+     */
+    ann.description = "<html>hello world</html>";
+    assertEquals(AnnotationLabels.getTooltip(ann), ann.description);
+
+    /*
+     * simple description and score
+     */
+    ann.description = "hello world";
+    ann.setScore(2.34d);
+    expected = "<html>hello world<br/> Score: 2.34</html>";
+    assertEquals(AnnotationLabels.getTooltip(ann), expected);
+
+    /*
+     * html description and score
+     */
+    ann.description = "<html>hello world</html>";
+    ann.setScore(2.34d);
+    expected = "<html>hello world<br/> Score: 2.34</html>";
+    assertEquals(AnnotationLabels.getTooltip(ann), expected);
+
+    /*
+     * score, no description
+     */
+    ann.description = " ";
+    assertEquals(AnnotationLabels.getTooltip(ann),
+            "<html> Score: 2.34</html>");
+    ann.description = null;
+    assertEquals(AnnotationLabels.getTooltip(ann),
+            "<html> Score: 2.34</html>");
+    
+    /*
+     * sequenceref, simple description
+     */
+    ann.description = "Count < 12";
+    ann.sequenceRef = new Sequence("Seq1", "MLRIQST");
+    ann.hasScore = false;
+    ann.score = Double.NaN;
+    expected = "<html>Seq1 : Count &lt; 12</html>";
+    assertEquals(AnnotationLabels.getTooltip(ann), expected);
+
+    /*
+     * sequenceref, html description, score
+     */
+    ann.description = "<html>Score < 4.8</html>";
+    ann.sequenceRef = new Sequence("Seq1", "MLRIQST");
+    ann.setScore(-2.1D);
+    expected = "<html>Seq1 : Score < 4.8<br/> Score: -2.1</html>";
+    assertEquals(AnnotationLabels.getTooltip(ann), expected);
+
+    /*
+     * no score, null description
+     */
+    ann.description = null;
+    ann.hasScore = false;
+    ann.score = Double.NaN;
+    assertNull(AnnotationLabels.getTooltip(ann));
+
+    /*
+     * no score, empty description, sequenceRef
+     */
+    ann.description = "";
+    assertEquals(AnnotationLabels.getTooltip(ann), "<html>Seq1 :</html>");
+
+    /*
+     * no score, empty description, no sequenceRef
+     */
+    ann.sequenceRef = null;
+    assertNull(AnnotationLabels.getTooltip(ann));
+  }
+
+  @Test(groups = "Functional")
+  public void testGetStatusMessage()
+  {
+    assertNull(AnnotationLabels.getStatusMessage(null, null));
+
+    /*
+     * simple label
+     */
+    AlignmentAnnotation aa = new AlignmentAnnotation("IUPredWS Short",
+            "Protein disorder", null);
+    assertEquals(AnnotationLabels.getStatusMessage(aa, null),
+            "IUPredWS Short");
+
+    /*
+     * with sequence ref
+     */
+    aa.setSequenceRef(new Sequence("FER_CAPAA", "MIGRKQL"));
+    assertEquals(AnnotationLabels.getStatusMessage(aa, null),
+            "FER_CAPAA : IUPredWS Short");
+
+    /*
+     * with graph group (degenerate, one annotation only)
+     */
+    aa.graphGroup = 1;
+    AlignmentAnnotation aa2 = new AlignmentAnnotation("IUPredWS Long",
+            "Protein disorder", null);
+    assertEquals(
+            AnnotationLabels.getStatusMessage(aa, new AlignmentAnnotation[]
+            { aa, aa2 }), "FER_CAPAA : IUPredWS Short");
+
+    /*
+     * graph group with two members; note labels are appended in
+     * reverse order (matching rendering order on screen)
+     */
+    aa2.graphGroup = 1;
+    assertEquals(
+            AnnotationLabels.getStatusMessage(aa, new AlignmentAnnotation[]
+            { aa, aa2 }), "FER_CAPAA : IUPredWS Long, IUPredWS Short");
+
+    /*
+     * graph group with no sequence ref
+     */
+    aa.sequenceRef = null;
+    assertEquals(
+            AnnotationLabels.getStatusMessage(aa, new AlignmentAnnotation[]
+            { aa, aa2 }), "IUPredWS Long, IUPredWS Short");
+  }
+}
diff --git a/test/jalview/gui/AnnotationPanelTest.java b/test/jalview/gui/AnnotationPanelTest.java
new file mode 100644 (file)
index 0000000..5f7d5a7
--- /dev/null
@@ -0,0 +1,51 @@
+package jalview.gui;
+
+import static org.testng.Assert.assertEquals;
+
+import jalview.datamodel.AlignmentAnnotation;
+
+import org.testng.annotations.Test;
+
+public class AnnotationPanelTest
+{
+
+  @Test(groups = "Functional")
+  public void testGetRowIndex()
+  {
+    assertEquals(AnnotationPanel.getRowIndex(0, null), -1);
+
+    AlignmentAnnotation[] anns = new AlignmentAnnotation[] {};
+    assertEquals(AnnotationPanel.getRowIndex(0, anns), -1);
+
+    AlignmentAnnotation ann1 = new AlignmentAnnotation(null, null, null);
+    AlignmentAnnotation ann2 = new AlignmentAnnotation(null, null, null);
+    AlignmentAnnotation ann3 = new AlignmentAnnotation(null, null, null);
+    ann1.visible = true;
+    ann2.visible = true;
+    ann3.visible = true;
+    ann1.height = 10;
+    ann2.height = 20;
+    ann3.height = 30;
+    anns = new AlignmentAnnotation[] { ann1, ann2, ann3 };
+
+    assertEquals(AnnotationPanel.getRowIndex(0, anns), 0);
+    assertEquals(AnnotationPanel.getRowIndex(9, anns), 0);
+    assertEquals(AnnotationPanel.getRowIndex(10, anns), 1);
+    assertEquals(AnnotationPanel.getRowIndex(29, anns), 1);
+    assertEquals(AnnotationPanel.getRowIndex(30, anns), 2);
+    assertEquals(AnnotationPanel.getRowIndex(59, anns), 2);
+    assertEquals(AnnotationPanel.getRowIndex(60, anns), -1);
+
+    ann2.visible = false;
+    assertEquals(AnnotationPanel.getRowIndex(0, anns), 0);
+    assertEquals(AnnotationPanel.getRowIndex(9, anns), 0);
+    assertEquals(AnnotationPanel.getRowIndex(10, anns), 2);
+    assertEquals(AnnotationPanel.getRowIndex(39, anns), 2);
+    assertEquals(AnnotationPanel.getRowIndex(40, anns), -1);
+
+    ann1.visible = false;
+    assertEquals(AnnotationPanel.getRowIndex(0, anns), 2);
+    assertEquals(AnnotationPanel.getRowIndex(29, anns), 2);
+    assertEquals(AnnotationPanel.getRowIndex(30, anns), -1);
+  }
+}
diff --git a/test/jalview/gui/CalculationChooserTest.java b/test/jalview/gui/CalculationChooserTest.java
new file mode 100644 (file)
index 0000000..6c2e777
--- /dev/null
@@ -0,0 +1,98 @@
+package jalview.gui;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertSame;
+
+import jalview.analysis.scoremodels.ScoreModels;
+import jalview.api.analysis.ScoreModelI;
+import jalview.bin.Cache;
+
+import java.util.List;
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+public class CalculationChooserTest
+{
+  @BeforeClass(alwaysRun = true)
+  public void setUp()
+  {
+    // read-only Jalview properties
+    Cache.loadProperties("test/jalview/io/testProps.jvprops");
+    Cache.applicationProperties.setProperty("BLOSUM62_PCA_FOR_NUCLEOTIDE",
+            Boolean.FALSE.toString());
+  }
+
+  @Test(groups = "Functional")
+  public void testGetApplicableScoreModels()
+  {
+    ScoreModels models = ScoreModels.getInstance();
+    ScoreModelI blosum62 = models.getBlosum62();
+    ScoreModelI pam250 = models.getPam250();
+    ScoreModelI dna = models.getDefaultModel(false);
+
+    /*
+     * peptide models for PCA
+     */
+    List<ScoreModelI> filtered = CalculationChooser
+            .getApplicableScoreModels(false, true);
+    assertEquals(filtered.size(), 4);
+    assertSame(filtered.get(0), blosum62);
+    assertSame(filtered.get(1), pam250);
+    assertEquals(filtered.get(2).getName(), "PID");
+    assertEquals(filtered.get(3).getName(), "Sequence Feature Similarity");
+
+    /*
+     * peptide models for Tree are the same
+     */
+    filtered = CalculationChooser.getApplicableScoreModels(false, false);
+    assertEquals(filtered.size(), 4);
+    assertSame(filtered.get(0), blosum62);
+    assertSame(filtered.get(1), pam250);
+    assertEquals(filtered.get(2).getName(), "PID");
+    assertEquals(filtered.get(3).getName(), "Sequence Feature Similarity");
+
+    /*
+     * nucleotide models for PCA
+     */
+    filtered = CalculationChooser.getApplicableScoreModels(true, true);
+    assertEquals(filtered.size(), 3);
+    assertSame(filtered.get(0), dna);
+    assertEquals(filtered.get(1).getName(), "PID");
+    assertEquals(filtered.get(2).getName(), "Sequence Feature Similarity");
+
+    /*
+     * nucleotide models for Tree are the same
+     */
+    filtered = CalculationChooser.getApplicableScoreModels(true, false);
+    assertEquals(filtered.size(), 3);
+    assertSame(filtered.get(0), dna);
+    assertEquals(filtered.get(1).getName(), "PID");
+    assertEquals(filtered.get(2).getName(), "Sequence Feature Similarity");
+
+    /*
+     * enable inclusion of BLOSUM62 for nucleotide PCA (JAL-2962)
+     */
+    Cache.applicationProperties.setProperty("BLOSUM62_PCA_FOR_NUCLEOTIDE",
+            Boolean.TRUE.toString());
+
+    /*
+     * nucleotide models for Tree are unchanged
+     */
+    filtered = CalculationChooser.getApplicableScoreModels(true, false);
+    assertEquals(filtered.size(), 3);
+    assertSame(filtered.get(0), dna);
+    assertEquals(filtered.get(1).getName(), "PID");
+    assertEquals(filtered.get(2).getName(), "Sequence Feature Similarity");
+
+    /*
+     * nucleotide models for PCA add BLOSUM62 as last option
+     */
+    filtered = CalculationChooser.getApplicableScoreModels(true, true);
+    assertEquals(filtered.size(), 4);
+    assertSame(filtered.get(0), dna);
+    assertEquals(filtered.get(1).getName(), "PID");
+    assertEquals(filtered.get(2).getName(), "Sequence Feature Similarity");
+    assertSame(filtered.get(3), blosum62);
+  }
+}
diff --git a/test/jalview/gui/ColourMenuHelperTest.java b/test/jalview/gui/ColourMenuHelperTest.java
new file mode 100644 (file)
index 0000000..e685155
--- /dev/null
@@ -0,0 +1,263 @@
+package jalview.gui;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertSame;
+import static org.testng.Assert.assertTrue;
+
+import jalview.bin.Cache;
+import jalview.datamodel.Alignment;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.Sequence;
+import jalview.datamodel.SequenceI;
+import jalview.schemes.ClustalxColourScheme;
+import jalview.schemes.ColourSchemeI;
+import jalview.schemes.ColourSchemes;
+import jalview.schemes.NucleotideColourScheme;
+import jalview.schemes.PIDColourScheme;
+import jalview.schemes.ResidueColourScheme;
+import jalview.util.MessageManager;
+
+import java.util.Enumeration;
+import java.util.Iterator;
+
+import javax.swing.AbstractButton;
+import javax.swing.ButtonGroup;
+import javax.swing.JMenu;
+import javax.swing.JMenuItem;
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+public class ColourMenuHelperTest
+{
+  /**
+   * Use a properties file with a user-defined colour scheme
+   */
+  @BeforeClass(alwaysRun = true)
+  public void setUp()
+  {
+    Cache.loadProperties("test/jalview/io/testProps.jvprops");
+  }
+
+  @Test(groups = "Functional")
+  public void testAddMenuItems_peptide()
+  {
+    SequenceI s1 = new Sequence("s1", "KFRQSILM");
+    AlignmentI al = new Alignment(new SequenceI[] { s1 });
+    JMenu menu = new JMenu();
+
+    ButtonGroup bg = ColourMenuHelper.addMenuItems(menu, null, al, false);
+    Enumeration<AbstractButton> bgElements = bg.getElements();
+
+    /*
+     * first entry is 'No Colour' option
+     */
+    JMenuItem item = menu.getItem(0);
+    assertEquals(item.getName(), ResidueColourScheme.NONE);
+    assertEquals(item.getText(), MessageManager.getString("label.none"));
+    AbstractButton bgItem = bgElements.nextElement();
+    assertSame(bgItem, item);
+
+    /*
+     * check that each registered colour scheme is in the menu,
+     * and in the button group;
+     * nucleotide-only schemes should be disabled menu items
+     */
+    Iterator<ColourSchemeI> colourSchemes = ColourSchemes.getInstance()
+            .getColourSchemes().iterator();
+    final int items = menu.getItemCount();
+    for (int i = 1; i < items; i++)
+    {
+      item = menu.getItem(i);
+      bgItem = bgElements.nextElement();
+      assertSame(bgItem, item);
+      ColourSchemeI cs = colourSchemes.next();
+      String name = cs.getSchemeName();
+      assertEquals(item.getName(), name);
+      boolean enabled = item.isEnabled();
+      assertEquals(enabled, cs.isApplicableTo(al));
+      if (cs instanceof NucleotideColourScheme) // nucleotide only
+      {
+        assertFalse(enabled);
+      }
+      if (cs instanceof ClustalxColourScheme) // peptide only
+      {
+        assertTrue(enabled);
+      }
+      if (cs instanceof PIDColourScheme) // nucleotide or peptide
+      {
+        assertTrue(enabled);
+      }
+
+      /*
+       * check i18n for display name
+       */
+      String label = MessageManager.getStringOrReturn("label.colourScheme_",
+              name.toLowerCase().replace(" ", "_"));
+      assertEquals(item.getText(), label);
+    }
+
+    /*
+     * check nothing left over
+     */
+    assertFalse(colourSchemes.hasNext());
+    assertFalse(bgElements.hasMoreElements());
+  }
+
+  @Test(groups = "Functional")
+  public void testAddMenuItems_nucleotide()
+  {
+    SequenceI s1 = new Sequence("s1", "GAATAATCCATAACAG");
+    AlignmentI al = new Alignment(new SequenceI[] { s1 });
+    JMenu menu = new JMenu();
+    AlignFrame af = new AlignFrame(al, 500, 500);
+
+    /*
+     * menu for SequenceGroup excludes 'User Defined Colour'
+     */
+    PopupMenu popup = new PopupMenu(af.alignPanel, s1, null);
+    ButtonGroup bg = ColourMenuHelper.addMenuItems(menu, popup, al, false);
+    Enumeration<AbstractButton> bgElements = bg.getElements();
+  
+    /*
+     * first entry is 'No Colour' option
+     */
+    JMenuItem item = menu.getItem(0);
+    assertEquals(item.getName(), ResidueColourScheme.NONE);
+    assertEquals(item.getText(), MessageManager.getString("label.none"));
+    AbstractButton bgItem = bgElements.nextElement();
+    assertSame(bgItem, item);
+  
+    /*
+     * check that each registered colour scheme is in the menu,
+     * and in the button group;
+     * nucleotide-only schemes should be disabled menu items
+     */
+    Iterator<ColourSchemeI> colourSchemes = ColourSchemes.getInstance()
+            .getColourSchemes().iterator();
+    final int items = menu.getItemCount();
+    for (int i = 1; i < items; i++)
+    {
+      item = menu.getItem(i);
+      bgItem = bgElements.nextElement();
+      assertSame(bgItem, item);
+      ColourSchemeI cs = colourSchemes.next();
+      String name = cs.getSchemeName();
+      assertEquals(item.getName(), name);
+      boolean enabled = item.isEnabled();
+      assertEquals(enabled, cs.isApplicableTo(al));
+      if (cs instanceof NucleotideColourScheme) // nucleotide only
+      {
+        assertTrue(enabled);
+      }
+      if (cs instanceof ClustalxColourScheme) // peptide only
+      {
+        assertFalse(enabled);
+      }
+      if (cs instanceof PIDColourScheme) // nucleotide or peptide
+      {
+        assertTrue(enabled);
+      }
+  
+      /*
+       * check i18n for display name
+       */
+      String label = MessageManager.getStringOrReturn("label.colourScheme_",
+              name.toLowerCase().replace(" ", "_"));
+      assertEquals(item.getText(), label);
+    }
+  
+    /*
+     * check nothing left over
+     */
+    assertFalse(colourSchemes.hasNext());
+    assertFalse(bgElements.hasMoreElements());
+  }
+
+  /**
+   * 'Simple only' mode constructs colour menu for structures
+   * <ul>
+   * <li>no 'No Colour' option</li>
+   * <li>only simple colour schemes (colour per residue)</li>
+   * </ul>
+   */
+  @Test(groups = "Functional")
+  public void testAddMenuItems_simpleOnly()
+  {
+    SequenceI s1 = new Sequence("s1", "KFRQSILM");
+    AlignmentI al = new Alignment(new SequenceI[] { s1 });
+    JMenu menu = new JMenu();
+  
+    ButtonGroup bg = ColourMenuHelper.addMenuItems(menu, null, al, true);
+    Enumeration<AbstractButton> bgElements = bg.getElements();
+  
+    /*
+     * check that only 'simple' colour schemes are included
+     */
+    Iterator<ColourSchemeI> colourSchemes = ColourSchemes.getInstance()
+            .getColourSchemes().iterator();
+    int i = 0;
+    while (colourSchemes.hasNext())
+    {
+      ColourSchemeI cs = colourSchemes.next();
+      if (!cs.isSimple())
+      {
+        continue;
+      }
+      JMenuItem item = menu.getItem(i++);
+      AbstractButton bgItem = bgElements.nextElement();
+      assertSame(bgItem, item);
+    }
+  
+    /*
+     * check nothing left over
+     */
+    assertEquals(i, menu.getItemCount());
+    assertFalse(bgElements.hasMoreElements());
+  }
+
+  /*
+   * menu for AlignFrame includes 'User Defined Colour'
+   */
+  @Test(groups = "Functional")
+  public void testAddMenuItems_forAlignFrame()
+  {
+    SequenceI s1 = new Sequence("s1", "KFRQSILM");
+    AlignmentI al = new Alignment(new SequenceI[] { s1 });
+    AlignFrame af = new AlignFrame(al, 500, 500);
+    JMenu menu = new JMenu();
+  
+    ButtonGroup bg = ColourMenuHelper.addMenuItems(menu, af, al, false);
+    Enumeration<AbstractButton> bgElements = bg.getElements();
+  
+    /*
+     * check that each registered colour scheme is in the menu,
+     * (skipping over No Colour which is the first menu item),
+     * and in the button group
+     */
+    bgElements.nextElement(); // skip No Colour
+    Iterator<ColourSchemeI> colourSchemes = ColourSchemes.getInstance()
+            .getColourSchemes().iterator();
+    final int items = menu.getItemCount();
+    for (int i = 1; i < items - 1; i++)
+    {
+      JMenuItem item = menu.getItem(i);
+      AbstractButton bgItem = bgElements.nextElement();
+      assertSame(bgItem, item);
+      ColourSchemeI cs = colourSchemes.next();
+      assertEquals(item.getName(), cs.getSchemeName());
+    }
+  
+    /*
+     * check menu also has User Defined Colour
+     */
+    assertFalse(colourSchemes.hasNext());
+    JMenuItem item = menu.getItem(items - 1);
+    AbstractButton bgItem = bgElements.nextElement();
+    assertSame(bgItem, item);
+    assertEquals(item.getName(), ResidueColourScheme.USER_DEFINED_MENU);
+    assertEquals(item.getText(),
+            MessageManager.getString("action.user_defined"));
+  }
+}
index 6ddebf8..6d8a47e 100644 (file)
@@ -13,6 +13,7 @@ import jalview.datamodel.features.FeatureMatcherSetI;
 import jalview.io.DataSourceType;
 import jalview.io.FileLoader;
 import jalview.schemes.FeatureColour;
+import jalview.schemes.FeatureColourTest;
 import jalview.util.matcher.Condition;
 
 import java.awt.Color;
@@ -60,8 +61,8 @@ public class FeatureSettingsTest
     fr.setColour("type2", byLabel);
 
     // type3: by score above threshold
-    FeatureColourI byScore = new FeatureColour(Color.BLACK, Color.BLUE, 1,
-            10);
+    FeatureColourI byScore = new FeatureColour(null, Color.BLACK,
+            Color.BLUE, null, 1, 10);
     byScore.setAboveThreshold(true);
     byScore.setThreshold(2f);
     fr.setColour("type3", byScore);
@@ -73,8 +74,8 @@ public class FeatureSettingsTest
     fr.setColour("type4", byAF);
 
     // type5: by attribute CSQ:PolyPhen below threshold
-    FeatureColourI byPolyPhen = new FeatureColour(Color.BLACK, Color.BLUE,
-            1, 10);
+    FeatureColourI byPolyPhen = new FeatureColour(null, Color.BLACK,
+            Color.BLUE, null, 1, 10);
     byPolyPhen.setBelowThreshold(true);
     byPolyPhen.setThreshold(3f);
     byPolyPhen.setAttributeName("CSQ", "PolyPhen");
@@ -188,4 +189,50 @@ public class FeatureSettingsTest
     });
     seq.addSequenceFeature(sf);
   }
+
+  /**
+   * @see FeatureColourTest#testGetDescription()
+   * @throws IOException
+   */
+  @Test(groups = "Functional")
+  public void testGetColorTooltip() throws IOException
+  {
+    assertNull(FeatureSettings.getColorTooltip(null, false));
+
+    /*
+     * simple colour
+     */
+    FeatureColourI fc = new FeatureColour(Color.black);
+    String simpleTooltip = "Click to edit, right-click for menu";
+    assertEquals(FeatureSettings.getColorTooltip(fc, true), simpleTooltip);
+    assertNull(FeatureSettings.getColorTooltip(fc, false));
+
+    /*
+     * graduated colour tooltip includes description of colour
+     */
+    fc.setColourByLabel(true);
+    assertEquals(FeatureSettings.getColorTooltip(fc, false),
+            "<html>By Label</html>");
+    assertEquals(FeatureSettings.getColorTooltip(fc, true),
+            "<html>By Label<br>" + simpleTooltip + "</br></html>");
+
+    /*
+     * graduated colour with threshold is html-encoded
+     */
+    fc = new FeatureColour(null, Color.red, Color.blue, null, 2f, 10f);
+    fc.setBelowThreshold(true);
+    fc.setThreshold(4f);
+    assertEquals(FeatureSettings.getColorTooltip(fc, false),
+            "<html>By Score (&lt; 4.0)</html>");
+    assertEquals(FeatureSettings.getColorTooltip(fc, true),
+            "<html>By Score (&lt; 4.0)<br>" + simpleTooltip
+                    + "</br></html>");
+
+    fc.setAboveThreshold(true);
+    assertEquals(FeatureSettings.getColorTooltip(fc, false),
+            "<html>By Score (&gt; 4.0)</html>");
+    assertEquals(FeatureSettings.getColorTooltip(fc, true),
+            "<html>By Score (&gt; 4.0)<br>" + simpleTooltip
+                    + "</br></html>");
+  }
 }
index e93bfac..9b21274 100644 (file)
@@ -1,6 +1,7 @@
 package jalview.gui;
 
 import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
 import static org.testng.Assert.assertTrue;
 
 import jalview.analysis.AlignmentGenerator;
@@ -11,6 +12,7 @@ import jalview.datamodel.SequenceGroup;
 import jalview.io.DataSourceType;
 import jalview.io.FileLoader;
 
+import java.awt.event.MouseEvent;
 import java.io.File;
 import java.io.IOException;
 import java.io.PrintStream;
@@ -18,6 +20,8 @@ import java.io.PrintStream;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
+import junit.extensions.PA;
+
 public class FreeUpMemoryTest
 {
   private static final int ONE_MB = 1000 * 1000;
@@ -30,16 +34,12 @@ public class FreeUpMemoryTest
   {
     Jalview.main(new String[] { "-nonews", "-props",
         "test/jalview/testProps.jvprops" });
-    Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS",
-            Boolean.TRUE.toString());
-    Cache.applicationProperties.setProperty("SHOW_QUALITY",
-            Boolean.TRUE.toString());
-    Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
-            Boolean.TRUE.toString());
-    Cache.applicationProperties.setProperty("SHOW_OCCUPANCY",
-            Boolean.TRUE.toString());
-    Cache.applicationProperties.setProperty("SHOW_IDENTITY",
-            Boolean.TRUE.toString());
+    String True = Boolean.TRUE.toString();
+    Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS", True);
+    Cache.applicationProperties.setProperty("SHOW_QUALITY", True);
+    Cache.applicationProperties.setProperty("SHOW_CONSERVATION", True);
+    Cache.applicationProperties.setProperty("SHOW_OCCUPANCY", True);
+    Cache.applicationProperties.setProperty("SHOW_IDENTITY", True);
   }
 
   /**
@@ -84,18 +84,19 @@ public class FreeUpMemoryTest
   protected void checkUsedMemory(long expectedMax)
   {
     /*
-     * request garbage collection and wait briefly for it to run;
+     * request garbage collection and wait for it to run;
      * NB there is no guarantee when, or whether, it will do so
+     * wait time depends on JRE/processor, generous allowance here  
      */
     System.gc();
-    waitFor(100);
+    waitFor(1500);
 
     /*
      * a second gc() call should not be necessary - but it is!
      * the test passes with it, and fails without it
      */
     System.gc();
-    waitFor(100);
+    waitFor(1500);
 
     /*
      * check used memory is 'reasonably low'
@@ -142,6 +143,20 @@ public class FreeUpMemoryTest
     }
 
     /*
+     * open an Overview window
+     */
+    af.overviewMenuItem_actionPerformed(null);
+    assertNotNull(af.alignPanel.overviewPanel);
+
+    /*
+     * exercise the pop-up menu in the Overview Panel (JAL-2864)
+     */
+    Object[] args = new Object[] {
+        new MouseEvent(af, 0, 0, 0, 0, 0, 1, true) };
+    PA.invokeMethod(af.alignPanel.overviewPanel,
+            "showPopupMenu(java.awt.event.MouseEvent)", args);
+
+    /*
      * set a selection group - potential memory leak if it retains
      * a reference to the alignment
      */
diff --git a/test/jalview/gui/ScalePanelTest.java b/test/jalview/gui/ScalePanelTest.java
new file mode 100644 (file)
index 0000000..91b541c
--- /dev/null
@@ -0,0 +1,58 @@
+package jalview.gui;
+
+import static org.testng.Assert.assertTrue;
+
+import jalview.datamodel.Alignment;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.Sequence;
+import jalview.datamodel.SequenceGroup;
+import jalview.datamodel.SequenceI;
+
+import java.awt.event.MouseEvent;
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+public class ScalePanelTest
+{
+  @BeforeClass(alwaysRun = true)
+  public void setUpJvOptionPane()
+  {
+    JvOptionPane.setInteractiveMode(false);
+    JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
+  }
+
+  @Test(groups = "Functional")
+  public void testPreventNegativeStartColumn()
+  {
+    SequenceI seq1 = new Sequence("Seq1", "MATRESS");
+    SequenceI seq2 = new Sequence("Seq2", "MADNESS");
+    AlignmentI al = new Alignment(new SequenceI[] { seq1, seq2 });
+    
+    AlignFrame alignFrame = new AlignFrame(al, al.getWidth(),
+            al.getHeight());
+    ScalePanel scalePanel = new ScalePanel(
+            alignFrame.getViewport(), alignFrame.alignPanel
+    );
+    
+    MouseEvent mouse = new MouseEvent(
+            scalePanel, 0, 1, 0, 4, 0, 1, false
+    );
+    scalePanel.mousePressed(mouse);
+    scalePanel.mouseDragged(mouse);
+
+    // simulate dragging selection leftwards beyond the sequences giving
+    // negative X
+    mouse = new MouseEvent(scalePanel, 0, 1, 0, -30, 0, 1, false);
+
+    scalePanel.mouseReleased(mouse);
+
+    SequenceGroup sg = scalePanel.av.getSelectionGroup();
+    int startCol = sg.getStartRes();
+
+    assertTrue(startCol >= 0);
+
+
+  }
+
+}
index 5298680..73aeb79 100644 (file)
@@ -29,10 +29,10 @@ import jalview.io.FileLoader;
 import java.awt.Font;
 import java.awt.FontMetrics;
 
-import junit.extensions.PA;
-
 import org.testng.annotations.Test;
 
+import junit.extensions.PA;
+
 public class SeqCanvasTest
 {
   /**
@@ -97,8 +97,8 @@ public class SeqCanvasTest
     assertEquals(PA.getValue(testee, "wrappedVisibleWidths"), 3);
 
     /*
-     * reduce canvas height by 1 pixel - should not be enough height
-     * to draw 3 widths
+     * reduce canvas height by 1 pixel 
+     * - should not be enough height to draw 3 widths
      */
     canvasHeight -= 1;
     testee.calculateWrappedGeometry(canvasWidth, canvasHeight);
@@ -170,11 +170,11 @@ public class SeqCanvasTest
     canvasWidth += 8;
     wrappedWidth = testee.calculateWrappedGeometry(canvasWidth,
             canvasHeight);
-    assertEquals(wrappedWidth, 27);
+    assertEquals(wrappedWidth, 27); // 8px not enough
     canvasWidth += 1;
     wrappedWidth = testee.calculateWrappedGeometry(canvasWidth,
             canvasHeight);
-    assertEquals(wrappedWidth, 28);
+    assertEquals(wrappedWidth, 28); // 9px is enough
 
     /*
      * now West but not East scale - lose 39 pixels or 4 columns
@@ -190,11 +190,11 @@ public class SeqCanvasTest
     canvasWidth += 2;
     wrappedWidth = testee.calculateWrappedGeometry(canvasWidth,
             canvasHeight);
-    assertEquals(wrappedWidth, 24);
+    assertEquals(wrappedWidth, 24); // 2px not enough
     canvasWidth += 1;
     wrappedWidth = testee.calculateWrappedGeometry(canvasWidth,
             canvasHeight);
-    assertEquals(wrappedWidth, 25);
+    assertEquals(wrappedWidth, 25); // 3px is enough
 
     /*
      * turn off scales left and right, make width exactly 157 columns
@@ -256,15 +256,16 @@ public class SeqCanvasTest
             2 * charHeight);
     int repeatingHeight = (int) PA.getValue(testee, "wrappedRepeatHeightPx");
     assertEquals(repeatingHeight, charHeight * (2 + al.getHeight())
-            + annotationHeight);
+            + SeqCanvas.SEQS_ANNOTATION_GAP + annotationHeight);
     assertEquals(PA.getValue(testee, "wrappedVisibleWidths"), 1);
   
     /*
-     * repeat height is 17 * (2 + 15) = 289 + annotationHeight = 507
-     * make canvas height 2 * 289 + 3 * charHeight so just enough to
-     * draw 2 widths and the first sequence of a third
+     * repeat height is 17 * (2 + 15) = 289 + 3 + annotationHeight = 510
+     * make canvas height 2 of these plus 3 charHeights 
+     * so just enough to draw 2 widths, gap + scale + the first sequence of a third
      */
-    canvasHeight = charHeight * (17 * 2 + 3) + 2 * annotationHeight;
+    canvasHeight = charHeight * (17 * 2 + 3)
+            + 2 * (annotationHeight + SeqCanvas.SEQS_ANNOTATION_GAP);
     testee.calculateWrappedGeometry(canvasWidth, canvasHeight);
     assertEquals(PA.getValue(testee, "wrappedVisibleWidths"), 3);
   
@@ -287,7 +288,8 @@ public class SeqCanvasTest
      * reduce height to enough for 2 widths and not quite a third
      * i.e. two repeating heights + spacer + sequence - 1 pixel
      */
-    canvasHeight = charHeight * (16 * 2 + 2) + 2 * annotationHeight - 1;
+    canvasHeight = charHeight * (16 * 2 + 2)
+            + 2 * (annotationHeight + SeqCanvas.SEQS_ANNOTATION_GAP) - 1;
     testee.calculateWrappedGeometry(canvasWidth, canvasHeight);
     assertEquals(PA.getValue(testee, "wrappedVisibleWidths"), 2);
 
index a5d244d..0d49936 100644 (file)
 package jalview.gui;
 
 import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
 
+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;
 import jalview.datamodel.Alignment;
+import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceI;
+import jalview.gui.SeqPanel.MousePos;
+import jalview.io.DataSourceType;
+import jalview.io.FileLoader;
+import jalview.util.MessageManager;
 
+import java.awt.Event;
+import java.awt.EventQueue;
+import java.awt.event.MouseEvent;
+import java.lang.reflect.InvocationTargetException;
+
+import javax.swing.JLabel;
+
+import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
+import junit.extensions.PA;
+
 public class SeqPanelTest
 {
   AlignFrame af;
@@ -54,22 +77,24 @@ public class SeqPanelTest
     assertEquals(
             alignFrame.alignPanel.getSeqPanel().setStatusMessage(
                     visAl.getSequenceAt(1), 1, 1), 2);
-    assertEquals(alignFrame.statusBar.getText(),
+    assertEquals(((JLabel) PA.getValue(alignFrame, "statusBar")).getText(),
             "Sequence 2 ID: Seq2 Residue: ALA (2)");
     assertEquals(
             alignFrame.alignPanel.getSeqPanel().setStatusMessage(
                     visAl.getSequenceAt(1), 4, 1), 3);
-    assertEquals(alignFrame.statusBar.getText(),
+    assertEquals(((JLabel) PA.getValue(alignFrame, "statusBar")).getText(),
             "Sequence 2 ID: Seq2 Residue: GLU (3)");
     // no status message at a gap, returns next residue position to the right
     assertEquals(
             alignFrame.alignPanel.getSeqPanel().setStatusMessage(
                     visAl.getSequenceAt(1), 2, 1), 3);
-    assertEquals(alignFrame.statusBar.getText(), "Sequence 2 ID: Seq2");
+    assertEquals(((JLabel) PA.getValue(alignFrame, "statusBar")).getText(),
+            "Sequence 2 ID: Seq2");
     assertEquals(
             alignFrame.alignPanel.getSeqPanel().setStatusMessage(
                     visAl.getSequenceAt(1), 3, 1), 3);
-    assertEquals(alignFrame.statusBar.getText(), "Sequence 2 ID: Seq2");
+    assertEquals(((JLabel) PA.getValue(alignFrame, "statusBar")).getText(),
+            "Sequence 2 ID: Seq2");
   }
 
   @Test(groups = "Functional")
@@ -85,7 +110,794 @@ public class SeqPanelTest
     assertEquals(
             alignFrame.alignPanel.getSeqPanel().setStatusMessage(
                     visAl.getSequenceAt(1), 1, 1), 2);
-    assertEquals(alignFrame.statusBar.getText(),
+    assertEquals(((JLabel) PA.getValue(alignFrame, "statusBar")).getText(),
             "Sequence 2 ID: Seq2 Residue: B (2)");
   }
+
+  @Test(groups = "Functional")
+  public void testGetEditStatusMessage()
+  {
+    assertNull(SeqPanel.getEditStatusMessage(null));
+
+    EditCommand edit = new EditCommand(); // empty
+    assertNull(SeqPanel.getEditStatusMessage(edit));
+
+    SequenceI[] seqs = new SequenceI[] { new Sequence("a", "b") };
+    
+    // 1 gap
+    edit.addEdit(edit.new Edit(Action.INSERT_GAP, seqs, 1, 1, '-'));
+    String expected = MessageManager.formatMessage("label.insert_gap", "1");
+    assertEquals(SeqPanel.getEditStatusMessage(edit), expected);
+
+    // 3 more gaps makes +4
+    edit.addEdit(edit.new Edit(Action.INSERT_GAP, seqs, 1, 3, '-'));
+    expected = MessageManager.formatMessage("label.insert_gaps", "4");
+    assertEquals(SeqPanel.getEditStatusMessage(edit), expected);
+
+    // 2 deletes makes + 2
+    edit.addEdit(edit.new Edit(Action.DELETE_GAP, seqs, 1, 2, '-'));
+    expected = MessageManager.formatMessage("label.insert_gaps", "2");
+    assertEquals(SeqPanel.getEditStatusMessage(edit), expected);
+
+    // 2 more deletes makes 0 - no text
+    edit.addEdit(edit.new Edit(Action.DELETE_GAP, seqs, 1, 2, '-'));
+    assertNull(SeqPanel.getEditStatusMessage(edit));
+
+    // 1 more delete makes 1 delete
+    edit.addEdit(edit.new Edit(Action.DELETE_GAP, seqs, 1, 1, '-'));
+    expected = MessageManager.formatMessage("label.delete_gap", "1");
+    assertEquals(SeqPanel.getEditStatusMessage(edit), expected);
+
+    // 1 more delete makes 2 deletes
+    edit.addEdit(edit.new Edit(Action.DELETE_GAP, seqs, 1, 1, '-'));
+    expected = MessageManager.formatMessage("label.delete_gaps", "2");
+    assertEquals(SeqPanel.getEditStatusMessage(edit), expected);
+  }
+
+  /**
+   * Tests that simulate 'locked editing', where an inserted gap is balanced by
+   * a gap deletion in the selection group, and vice versa
+   */
+  @Test(groups = "Functional")
+  public void testGetEditStatusMessage_lockedEditing()
+  {
+    EditCommand edit = new EditCommand(); // empty
+    SequenceI[] seqs = new SequenceI[] { new Sequence("a", "b") };
+    
+    // 1 gap inserted, balanced by 1 delete
+    Edit e1 = edit.new Edit(Action.INSERT_GAP, seqs, 1, 1, '-');
+    edit.addEdit(e1);
+    Edit e2 = edit.new Edit(Action.DELETE_GAP, seqs, 5, 1, '-');
+    e2.setSystemGenerated(true);
+    edit.addEdit(e2);
+    String expected = MessageManager.formatMessage("label.insert_gap", "1");
+    assertEquals(SeqPanel.getEditStatusMessage(edit), expected);
+  
+    // 2 more gaps makes +3
+    Edit e3 = edit.new Edit(Action.INSERT_GAP, seqs, 1, 2, '-');
+    edit.addEdit(e3);
+    Edit e4 = edit.new Edit(Action.DELETE_GAP, seqs, 5, 2, '-');
+    e4.setSystemGenerated(true);
+    edit.addEdit(e4);
+    expected = MessageManager.formatMessage("label.insert_gaps", "3");
+    assertEquals(SeqPanel.getEditStatusMessage(edit), expected);
+  
+    // 2 deletes makes + 1
+    Edit e5 = edit.new Edit(Action.DELETE_GAP, seqs, 1, 2, '-');
+    edit.addEdit(e5);
+    Edit e6 = edit.new Edit(Action.INSERT_GAP, seqs, 5, 2, '-');
+    e6.setSystemGenerated(true);
+    edit.addEdit(e6);
+    expected = MessageManager.formatMessage("label.insert_gap", "1");
+    assertEquals(SeqPanel.getEditStatusMessage(edit), expected);
+  
+    // 1 more delete makes 0 - no text
+    Edit e7 = edit.new Edit(Action.DELETE_GAP, seqs, 1, 1, '-');
+    edit.addEdit(e7);
+    Edit e8 = edit.new Edit(Action.INSERT_GAP, seqs, 5, 1, '-');
+    e8.setSystemGenerated(true);
+    edit.addEdit(e8);
+    expected = MessageManager.formatMessage("label.insert_gaps", "2");
+    assertNull(SeqPanel.getEditStatusMessage(edit));
+  
+    // 1 more delete makes 1 delete
+    Edit e9 = edit.new Edit(Action.DELETE_GAP, seqs, 1, 1, '-');
+    edit.addEdit(e9);
+    Edit e10 = edit.new Edit(Action.INSERT_GAP, seqs, 5, 1, '-');
+    e10.setSystemGenerated(true);
+    edit.addEdit(e10);
+    expected = MessageManager.formatMessage("label.delete_gap", "1");
+    assertEquals(SeqPanel.getEditStatusMessage(edit), expected);
+  
+    // 2 more deletes makes 3 deletes
+    Edit e11 = edit.new Edit(Action.DELETE_GAP, seqs, 1, 2, '-');
+    edit.addEdit(e11);
+    Edit e12 = edit.new Edit(Action.INSERT_GAP, seqs, 5, 2, '-');
+    e12.setSystemGenerated(true);
+    edit.addEdit(e12);
+    expected = MessageManager.formatMessage("label.delete_gaps", "3");
+    assertEquals(SeqPanel.getEditStatusMessage(edit), expected);
+  }
+
+  public void testFindMousePosition_unwrapped()
+  {
+    String seqData = ">Seq1\nAACDE\n>Seq2\nAA--E\n";
+    AlignFrame alignFrame = new FileLoader().LoadFileWaitTillLoaded(seqData,
+            DataSourceType.PASTE);
+    AlignViewportI av = alignFrame.getViewport();
+    av.setShowAnnotation(true);
+    av.setWrapAlignment(false);
+    final int charHeight = av.getCharHeight();
+    final int charWidth = av.getCharWidth();
+    // sanity checks:
+    assertTrue(charHeight > 0);
+    assertTrue(charWidth > 0);
+    assertTrue(alignFrame.alignPanel.getSeqPanel().getWidth() > 0);
+
+    SeqPanel testee = alignFrame.alignPanel.getSeqPanel();
+    int x = 0;
+    int y = 0;
+
+    /*
+     * mouse at top left of unwrapped panel
+     */
+    MouseEvent evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y,
+            0, 0, 0, false, 0);
+    MousePos pos = testee.findMousePosition(evt);
+    assertEquals(pos.column, 0);
+    assertEquals(pos.seqIndex, 0);
+    assertEquals(pos.annotationIndex, -1);
+  }
+
+  @AfterMethod(alwaysRun = true)
+  public void tearDown()
+  {
+    Desktop.instance.closeAll_actionPerformed(null);
+  }
+
+  @Test(groups = "Functional")
+  public void testFindMousePosition_wrapped_annotations()
+  {
+    Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS", "true");
+    Cache.applicationProperties.setProperty("WRAP_ALIGNMENT", "true");
+    AlignFrame alignFrame = new FileLoader().LoadFileWaitTillLoaded(
+            "examples/uniref50.fa", DataSourceType.FILE);
+    AlignViewportI av = alignFrame.getViewport();
+    av.setScaleAboveWrapped(false);
+    av.setScaleLeftWrapped(false);
+    av.setScaleRightWrapped(false);
+    alignFrame.alignPanel.paintAlignment(false, false);
+    waitForSwing(); // for Swing thread
+
+    final int charHeight = av.getCharHeight();
+    final int charWidth = av.getCharWidth();
+    final int alignmentHeight = av.getAlignment().getHeight();
+    
+    // sanity checks:
+    assertTrue(charHeight > 0);
+    assertTrue(charWidth > 0);
+    assertTrue(alignFrame.alignPanel.getSeqPanel().getWidth() > 0);
+  
+    SeqPanel testee = alignFrame.alignPanel.getSeqPanel();
+    int x = 0;
+    int y = 0;
+  
+    /*
+     * mouse at top left of wrapped panel; there is a gap of charHeight
+     * above the alignment
+     */
+    MouseEvent evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y,
+            0, 0, 0, false, 0);
+    MousePos pos = testee.findMousePosition(evt);
+    assertEquals(pos.column, 0);
+    assertEquals(pos.seqIndex, -1); // above sequences
+    assertEquals(pos.annotationIndex, -1);
+
+    /*
+     * cursor at bottom of gap above
+     */
+    y = charHeight - 1;
+    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+            false, 0);
+    pos = testee.findMousePosition(evt);
+    assertEquals(pos.seqIndex, -1);
+    assertEquals(pos.annotationIndex, -1);
+
+    /*
+     * cursor over top of first sequence
+     */
+    y = charHeight;
+    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+            false, 0);
+    pos = testee.findMousePosition(evt);
+    assertEquals(pos.seqIndex, 0);
+    assertEquals(pos.annotationIndex, -1);
+
+    /*
+     * cursor at bottom of first sequence
+     */
+    y = 2 * charHeight - 1;
+    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+            false, 0);
+    pos = testee.findMousePosition(evt);
+    assertEquals(pos.seqIndex, 0);
+    assertEquals(pos.annotationIndex, -1);
+
+    /*
+     * cursor at top of second sequence
+     */
+    y = 2 * charHeight;
+    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+            false, 0);
+    pos = testee.findMousePosition(evt);
+    assertEquals(pos.seqIndex, 1);
+    assertEquals(pos.annotationIndex, -1);
+
+    /*
+     * cursor at bottom of second sequence
+     */
+    y = 3 * charHeight - 1;
+    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+            false, 0);
+    pos = testee.findMousePosition(evt);
+    assertEquals(pos.seqIndex, 1);
+    assertEquals(pos.annotationIndex, -1);
+
+    /*
+     * cursor at bottom of last sequence
+     */
+    y = charHeight * (1 + alignmentHeight) - 1;
+    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+            false, 0);
+    pos = testee.findMousePosition(evt);
+    assertEquals(pos.seqIndex, alignmentHeight - 1);
+    assertEquals(pos.annotationIndex, -1);
+
+    /*
+     * cursor below sequences, in 3-pixel gap above annotations
+     * method reports index of nearest sequence above
+     */
+    y += 1;
+    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+            false, 0);
+    pos = testee.findMousePosition(evt);
+    assertEquals(pos.seqIndex, alignmentHeight - 1);
+    assertEquals(pos.annotationIndex, -1);
+
+    /*
+     * cursor still in the gap above annotations, now at the bottom of it
+     */
+    y += SeqCanvas.SEQS_ANNOTATION_GAP - 1; // 3-1 = 2
+    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+            false, 0);
+    pos = testee.findMousePosition(evt);
+    assertEquals(pos.seqIndex, alignmentHeight - 1);
+    assertEquals(pos.annotationIndex, -1);
+
+    AlignmentAnnotation[] annotationRows = av.getAlignment()
+            .getAlignmentAnnotation();
+    for (int n = 0; n < annotationRows.length; n++)
+    {
+      /*
+       * cursor at the top of the n'th annotation  
+       */
+      y += 1;
+      evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+              false, 0);
+      pos = testee.findMousePosition(evt);
+      assertEquals(pos.seqIndex, alignmentHeight - 1);
+      assertEquals(pos.annotationIndex, n); // over n'th annotation
+
+      /*
+       * cursor at the bottom of the n'th annotation  
+       */
+      y += annotationRows[n].height - 1;
+      evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+              false, 0);
+      pos = testee.findMousePosition(evt);
+      assertEquals(pos.seqIndex, alignmentHeight - 1);
+      assertEquals(pos.annotationIndex, n);
+    }
+
+    /*
+     * cursor in gap between wrapped widths  
+     */
+    y += 1;
+    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+            false, 0);
+    pos = testee.findMousePosition(evt);
+    assertEquals(pos.seqIndex, -1);
+    assertEquals(pos.annotationIndex, -1);
+
+    /*
+     * cursor at bottom of gap between wrapped widths  
+     */
+    y += charHeight - 1;
+    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+            false, 0);
+    pos = testee.findMousePosition(evt);
+    assertEquals(pos.seqIndex, -1);
+    assertEquals(pos.annotationIndex, -1);
+
+    /*
+     * cursor at top of first sequence, second wrapped width  
+     */
+    y += 1;
+    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+            false, 0);
+    pos = testee.findMousePosition(evt);
+    assertEquals(pos.seqIndex, 0);
+    assertEquals(pos.annotationIndex, -1);
+  }
+
+  @Test(groups = "Functional")
+  public void testFindMousePosition_wrapped_scaleAbove()
+  {
+    Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS", "true");
+    Cache.applicationProperties.setProperty("WRAP_ALIGNMENT", "true");
+    AlignFrame alignFrame = new FileLoader().LoadFileWaitTillLoaded(
+            "examples/uniref50.fa", DataSourceType.FILE);
+    AlignViewportI av = alignFrame.getViewport();
+    av.setScaleAboveWrapped(true);
+    av.setScaleLeftWrapped(false);
+    av.setScaleRightWrapped(false);
+    alignFrame.alignPanel.paintAlignment(false, false);
+    waitForSwing();
+
+    final int charHeight = av.getCharHeight();
+    final int charWidth = av.getCharWidth();
+    final int alignmentHeight = av.getAlignment().getHeight();
+    
+    // sanity checks:
+    assertTrue(charHeight > 0);
+    assertTrue(charWidth > 0);
+    assertTrue(alignFrame.alignPanel.getSeqPanel().getWidth() > 0);
+  
+    SeqPanel testee = alignFrame.alignPanel.getSeqPanel();
+    int x = 0;
+    int y = 0;
+  
+    /*
+     * mouse at top left of wrapped panel; there is a gap of charHeight
+     * above the alignment
+     */
+    MouseEvent evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y,
+            0, 0, 0, false, 0);
+    MousePos pos = testee.findMousePosition(evt);
+    assertEquals(pos.column, 0);
+    assertEquals(pos.seqIndex, -1); // above sequences
+    assertEquals(pos.annotationIndex, -1);
+  
+    /*
+     * cursor at bottom of gap above
+     * two charHeights including scale panel
+     */
+    y = 2 * charHeight - 1;
+    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+            false, 0);
+    pos = testee.findMousePosition(evt);
+    assertEquals(pos.seqIndex, -1);
+    assertEquals(pos.annotationIndex, -1);
+  
+    /*
+     * cursor over top of first sequence
+     */
+    y += 1;
+    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+            false, 0);
+    pos = testee.findMousePosition(evt);
+    assertEquals(pos.seqIndex, 0);
+    assertEquals(pos.annotationIndex, -1);
+  
+    /*
+     * cursor at bottom of first sequence
+     */
+    y += charHeight - 1;
+    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+            false, 0);
+    pos = testee.findMousePosition(evt);
+    assertEquals(pos.seqIndex, 0);
+    assertEquals(pos.annotationIndex, -1);
+  
+    /*
+     * cursor at top of second sequence
+     */
+    y += 1;
+    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+            false, 0);
+    pos = testee.findMousePosition(evt);
+    assertEquals(pos.seqIndex, 1);
+    assertEquals(pos.annotationIndex, -1);
+  
+    /*
+     * cursor at bottom of second sequence
+     */
+    y += charHeight - 1;
+    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+            false, 0);
+    pos = testee.findMousePosition(evt);
+    assertEquals(pos.seqIndex, 1);
+    assertEquals(pos.annotationIndex, -1);
+  
+    /*
+     * cursor at bottom of last sequence
+     * (scale + gap + sequences)
+     */
+    y = charHeight * (2 + alignmentHeight) - 1;
+    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+            false, 0);
+    pos = testee.findMousePosition(evt);
+    assertEquals(pos.seqIndex, alignmentHeight - 1);
+    assertEquals(pos.annotationIndex, -1);
+  
+    /*
+     * cursor below sequences, in 3-pixel gap above annotations
+     */
+    y += 1;
+    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+            false, 0);
+    pos = testee.findMousePosition(evt);
+    assertEquals(pos.seqIndex, alignmentHeight - 1);
+    assertEquals(pos.annotationIndex, -1);
+  
+    /*
+     * cursor still in the gap above annotations, now at the bottom of it
+     * method reports index of nearest sequence above  
+     */
+    y += SeqCanvas.SEQS_ANNOTATION_GAP - 1; // 3-1 = 2
+    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+            false, 0);
+    pos = testee.findMousePosition(evt);
+    assertEquals(pos.seqIndex, alignmentHeight - 1);
+    assertEquals(pos.annotationIndex, -1);
+  
+    AlignmentAnnotation[] annotationRows = av.getAlignment().getAlignmentAnnotation();
+    for (int n = 0; n < annotationRows.length; n++)
+    {
+      /*
+       * cursor at the top of the n'th annotation  
+       */
+      y += 1;
+      evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+              false, 0);
+      pos = testee.findMousePosition(evt);
+      assertEquals(pos.seqIndex, alignmentHeight - 1);
+      assertEquals(pos.annotationIndex, n); // over n'th annotation
+
+      /*
+       * cursor at the bottom of the n'th annotation  
+       */
+      y += annotationRows[n].height - 1;
+      evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+              false, 0);
+      pos = testee.findMousePosition(evt);
+      assertEquals(pos.seqIndex, alignmentHeight - 1);
+      assertEquals(pos.annotationIndex, n);
+    }
+  
+    /*
+     * cursor in gap between wrapped widths  
+     */
+    y += 1;
+    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+            false, 0);
+    pos = testee.findMousePosition(evt);
+    assertEquals(pos.seqIndex, -1);
+    assertEquals(pos.annotationIndex, -1);
+  
+    /*
+     * cursor at bottom of gap between wrapped widths  
+     */
+    y += charHeight - 1;
+    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+            false, 0);
+    pos = testee.findMousePosition(evt);
+    assertEquals(pos.seqIndex, -1);
+    assertEquals(pos.annotationIndex, -1);
+  
+    /*
+     * cursor at top of scale, second wrapped width  
+     */
+    y += 1;
+    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+            false, 0);
+    pos = testee.findMousePosition(evt);
+    assertEquals(pos.seqIndex, -1);
+    assertEquals(pos.annotationIndex, -1);
+
+    /*
+     * cursor at bottom of scale, second wrapped width  
+     */
+    y += charHeight - 1;
+    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+            false, 0);
+    pos = testee.findMousePosition(evt);
+    assertEquals(pos.seqIndex, -1);
+    assertEquals(pos.annotationIndex, -1);
+
+    /*
+     * cursor at top of first sequence, second wrapped width  
+     */
+    y += 1;
+    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+            false, 0);
+    pos = testee.findMousePosition(evt);
+    assertEquals(pos.seqIndex, 0);
+    assertEquals(pos.annotationIndex, -1);
+  }
+
+  @Test(groups = "Functional")
+  public void testFindMousePosition_wrapped_noAnnotations()
+  {
+    Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS", "false");
+    Cache.applicationProperties.setProperty("WRAP_ALIGNMENT", "true");
+    AlignFrame alignFrame = new FileLoader().LoadFileWaitTillLoaded(
+            "examples/uniref50.fa", DataSourceType.FILE);
+    AlignViewportI av = alignFrame.getViewport();
+    av.setScaleAboveWrapped(false);
+    av.setScaleLeftWrapped(false);
+    av.setScaleRightWrapped(false);
+    alignFrame.alignPanel.paintAlignment(false, false);
+    waitForSwing();
+
+    final int charHeight = av.getCharHeight();
+    final int charWidth = av.getCharWidth();
+    final int alignmentHeight = av.getAlignment().getHeight();
+    
+    // sanity checks:
+    assertTrue(charHeight > 0);
+    assertTrue(charWidth > 0);
+    assertTrue(alignFrame.alignPanel.getSeqPanel().getWidth() > 0);
+  
+    SeqPanel testee = alignFrame.alignPanel.getSeqPanel();
+    int x = 0;
+    int y = 0;
+  
+    /*
+     * mouse at top left of wrapped panel; there is a gap of charHeight
+     * above the alignment
+     */
+    MouseEvent evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y,
+            0, 0, 0, false, 0);
+    MousePos pos = testee.findMousePosition(evt);
+    assertEquals(pos.column, 0);
+    assertEquals(pos.seqIndex, -1); // above sequences
+    assertEquals(pos.annotationIndex, -1);
+  
+    /*
+     * cursor over top of first sequence
+     */
+    y = charHeight;
+    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+            false, 0);
+    pos = testee.findMousePosition(evt);
+    assertEquals(pos.seqIndex, 0);
+    assertEquals(pos.annotationIndex, -1);
+
+    /*
+     * cursor at bottom of last sequence
+     */
+    y = charHeight * (1 + alignmentHeight) - 1;
+    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+            false, 0);
+    pos = testee.findMousePosition(evt);
+    assertEquals(pos.seqIndex, alignmentHeight - 1);
+    assertEquals(pos.annotationIndex, -1);
+  
+    /*
+     * cursor below sequences, at top of charHeight gap between widths
+     */
+    y += 1;
+    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+            false, 0);
+    pos = testee.findMousePosition(evt);
+    assertEquals(pos.seqIndex, -1);
+    assertEquals(pos.annotationIndex, -1);
+  
+    /*
+     * cursor below sequences, at top of charHeight gap between widths
+     */
+    y += charHeight - 1;
+    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+            false, 0);
+    pos = testee.findMousePosition(evt);
+    assertEquals(pos.seqIndex, -1);
+    assertEquals(pos.annotationIndex, -1);
+  
+    /*
+     * cursor at the top of the first sequence, second width  
+     */
+    y += 1;
+    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+            false, 0);
+    pos = testee.findMousePosition(evt);
+    assertEquals(pos.seqIndex, 0);
+    assertEquals(pos.annotationIndex, -1);
+  }
+
+  @Test(groups = "Functional")
+  public void testFindColumn_unwrapped()
+  {
+    Cache.applicationProperties.setProperty("WRAP_ALIGNMENT", "false");
+    AlignFrame alignFrame = new FileLoader().LoadFileWaitTillLoaded(
+            "examples/uniref50.fa", DataSourceType.FILE);
+    SeqPanel testee = alignFrame.alignPanel.getSeqPanel();
+    int x = 0;
+    final int charWidth = alignFrame.getViewport().getCharWidth();
+    assertTrue(charWidth > 0); // sanity check
+    assertEquals(alignFrame.getViewport().getRanges().getStartRes(), 0);
+
+    /*
+     * mouse at top left of unwrapped panel
+     */
+    MouseEvent evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0,
+            0, 0, 0, false, 0);
+    assertEquals(testee.findColumn(evt), 0);
+    
+    /*
+     * not quite one charWidth across
+     */
+    x = charWidth-1;
+    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0,
+            0, 0, 0, false, 0);
+    assertEquals(testee.findColumn(evt), 0);
+
+    /*
+     * one charWidth across
+     */
+    x = charWidth;
+    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0, 0, 0, 0,
+            false, 0);
+    assertEquals(testee.findColumn(evt), 1);
+
+    /*
+     * two charWidths across
+     */
+    x = 2 * charWidth;
+    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0, 0, 0, 0,
+            false, 0);
+    assertEquals(testee.findColumn(evt), 2);
+
+    /*
+     * limited to last column of seqcanvas
+     */
+    x = 20000;
+    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0, 0, 0, 0,
+            false, 0);
+    SeqCanvas seqCanvas = alignFrame.alignPanel.getSeqPanel().seqCanvas;
+    int w = seqCanvas.getWidth();
+    // limited to number of whole columns, base 0
+    int expected = w / charWidth - 1;
+    assertEquals(testee.findColumn(evt), expected);
+
+    /*
+     * hide columns 5-10 (base 1)
+     */
+    alignFrame.getViewport().hideColumns(4, 9);
+    x = 5 * charWidth + 2;
+    // x is in 6th visible column, absolute column 12, or 11 base 0
+    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0, 0, 0, 0,
+            false, 0);
+    assertEquals(testee.findColumn(evt), 11);
+  }
+
+  @Test(groups = "Functional")
+  public void testFindColumn_wrapped()
+  {
+    Cache.applicationProperties.setProperty("WRAP_ALIGNMENT", "true");
+    AlignFrame alignFrame = new FileLoader().LoadFileWaitTillLoaded(
+            "examples/uniref50.fa", DataSourceType.FILE);
+    AlignViewport av = alignFrame.getViewport();
+    av.setScaleAboveWrapped(false);
+    av.setScaleLeftWrapped(false);
+    av.setScaleRightWrapped(false);
+    alignFrame.alignPanel.paintAlignment(false, false);
+    // need to wait for repaint to finish!
+    waitForSwing();
+    SeqPanel testee = alignFrame.alignPanel.getSeqPanel();
+    int x = 0;
+    final int charWidth = av.getCharWidth();
+    assertTrue(charWidth > 0); // sanity check
+    assertEquals(av.getRanges().getStartRes(), 0);
+  
+    /*
+     * mouse at top left of wrapped panel, no West (left) scale
+     */
+    MouseEvent evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0,
+            0, 0, 0, false, 0);
+    assertEquals(testee.findColumn(evt), 0);
+    
+    /*
+     * not quite one charWidth across
+     */
+    x = charWidth-1;
+    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0,
+            0, 0, 0, false, 0);
+    assertEquals(testee.findColumn(evt), 0);
+  
+    /*
+     * one charWidth across
+     */
+    x = charWidth;
+    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0, 0, 0, 0,
+            false, 0);
+    assertEquals(testee.findColumn(evt), 1);
+
+    /*
+     * x over scale left (before drawn columns) results in -1
+     */
+    av.setScaleLeftWrapped(true);
+    alignFrame.alignPanel.paintAlignment(false, false);
+    waitForSwing();
+    SeqCanvas seqCanvas = testee.seqCanvas;
+    int labelWidth = (int) PA.getValue(seqCanvas, "labelWidthWest");
+    assertTrue(labelWidth > 0);
+    x = labelWidth - 1;
+    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0, 0, 0, 0,
+            false, 0);
+    assertEquals(testee.findColumn(evt), -1);
+
+    x = labelWidth;
+    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0, 0, 0, 0,
+            false, 0);
+    assertEquals(testee.findColumn(evt), 0);
+
+    /*
+     * x over right edge of last residue (including scale left)
+     */
+    int residuesWide = av.getRanges().getViewportWidth();
+    assertTrue(residuesWide > 0);
+    x = labelWidth + charWidth * residuesWide - 1;
+    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0, 0, 0, 0,
+            false, 0);
+    assertEquals(testee.findColumn(evt), residuesWide - 1);
+
+    /*
+     * x over scale right (beyond drawn columns) results in -1
+     */
+    av.setScaleRightWrapped(true);
+    alignFrame.alignPanel.paintAlignment(false, false);
+    waitForSwing();
+    labelWidth = (int) PA.getValue(seqCanvas, "labelWidthEast");
+    assertTrue(labelWidth > 0);
+    int residuesWide2 = av.getRanges().getViewportWidth();
+    assertTrue(residuesWide2 > 0);
+    assertTrue(residuesWide2 < residuesWide); // available width reduced
+    x += 1; // just over left edge of scale right
+    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0, 0, 0, 0,
+            false, 0);
+    assertEquals(testee.findColumn(evt), -1);
+    
+    // todo add startRes offset, hidden columns
+
+  }
+  @BeforeClass(alwaysRun = true)
+  public static void setUpBeforeClass() throws Exception
+  {
+    /*
+     * use read-only test properties file
+     */
+    Cache.loadProperties("test/jalview/io/testProps.jvprops");
+    Jalview.main(new String[] { "-nonews" });
+  }
+
+  /**
+   * waits for Swing event dispatch queue to empty
+   */
+  synchronized void waitForSwing()
+  {
+    try
+    {
+      EventQueue.invokeAndWait(new Runnable()
+      {
+        @Override
+        public void run()
+        {
+        }
+      });
+    } catch (InterruptedException | InvocationTargetException e)
+    {
+      e.printStackTrace();
+    }
+  }
 }
index 6a00cde..05ce22d 100644 (file)
@@ -70,7 +70,7 @@ public class AnnotationFileIOTest
     }
   }
 
-  AlignmentI readAlignmentFile(File f)
+  protected AlignmentI readAlignmentFile(File f)
   {
     System.out.println("Reading file: " + f);
     String ff = f.getPath();
diff --git a/test/jalview/io/BackupFilesTest.java b/test/jalview/io/BackupFilesTest.java
new file mode 100644 (file)
index 0000000..723279d
--- /dev/null
@@ -0,0 +1,414 @@
+package jalview.io;
+
+import jalview.bin.Cache;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.Sequence;
+import jalview.datamodel.SequenceI;
+import jalview.gui.AlignFrame;
+import jalview.gui.JvOptionPane;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.List;
+import java.util.TreeMap;
+
+import org.testng.Assert;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+public class BackupFilesTest
+{
+  @BeforeClass(alwaysRun = true)
+  public void setUpJvOptionPane()
+  {
+    JvOptionPane.setInteractiveMode(false);
+    JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
+  }
+
+  private static boolean actuallyDeleteTmpFiles = true;
+  private static String testDir = "examples";
+
+  private static String testBasename = "backupfilestest";
+
+  private static String testExt = ".fa";
+
+  private static String testFilename = testBasename + testExt;
+
+
+  private static String testFile = testDir + File.separatorChar
+          + testFilename;
+
+  private static String newBasename = testBasename + "Temp";
+
+  private static String newFilename = newBasename + testExt;
+
+  private static String newFile = testDir + File.separatorChar
+          + newFilename;
+
+  private static String sequenceName = "BACKUP_FILES";
+
+  private static String sequenceDescription = "backupfiles";
+
+  private static String sequenceData = "AAAARG";
+
+  private static String suffix = "_BACKUPTEST-%n";
+
+  private static int digits = 8;
+
+  private static int rollMax = 2;
+
+  private AlignFrame af;
+
+  // read and save with backupfiles disabled
+  @Test(groups = { "Functional" })
+  public void noBackupsEnabledTest() throws Exception
+  {
+    // set BACKUPFILES_ENABLED to false (i.e. turn off BackupFiles feature -- no
+    // backup files to be made when saving)
+    setBackupFilesOptions(false, true, true);
+
+    // init the newFile and backups (i.e. make sure newFile exists on its own
+    // and has no backups
+    initNewFileForTesting();
+
+    // now save again
+    save();
+
+    // check no backup files
+    File[] backupFiles = getBackupFiles();
+    Assert.assertTrue(backupFiles.length == 0);
+  }
+
+  // save keeping all backup files
+  @Test(groups = { "Functional" })
+  public void backupsEnabledNoRollMaxTest() throws Exception
+  {
+    // Enable BackupFiles and set noMax so all backupfiles get kept
+    setBackupFilesOptions(true, false, true);
+
+    // init the newFile and backups (i.e. make sure newFile exists on its own
+    // and has no backups)
+    initNewFileForTesting();
+
+    // now save a few times again. No rollMax so should have more than two
+    // backup files
+    int numSaves = 10;
+    for (int i = 0; i < numSaves; i++)
+    {
+      save();
+    }
+
+    // check 10 backup files
+    HashMap correctindexmap = new HashMap();
+    correctindexmap.put(1, "backupfilestestTemp.fa_BACKUPTEST-00000001");
+    correctindexmap.put(2, "backupfilestestTemp.fa_BACKUPTEST-00000002");
+    correctindexmap.put(3, "backupfilestestTemp.fa_BACKUPTEST-00000003");
+    correctindexmap.put(4, "backupfilestestTemp.fa_BACKUPTEST-00000004");
+    correctindexmap.put(5, "backupfilestestTemp.fa_BACKUPTEST-00000005");
+    correctindexmap.put(6, "backupfilestestTemp.fa_BACKUPTEST-00000006");
+    correctindexmap.put(7, "backupfilestestTemp.fa_BACKUPTEST-00000007");
+    correctindexmap.put(8, "backupfilestestTemp.fa_BACKUPTEST-00000008");
+    correctindexmap.put(9, "backupfilestestTemp.fa_BACKUPTEST-00000009");
+    correctindexmap.put(10, "backupfilestestTemp.fa_BACKUPTEST-00000010");
+    HashMap wrongindexmap = new HashMap();
+    wrongindexmap.put(1, "backupfilestestTemp.fa_BACKUPTEST-1");
+    wrongindexmap.put(2, "backupfilestestTemp.fa_BACKUPTEST-00000002");
+    wrongindexmap.put(3, "backupfilestestTemp.fa_BACKUPTEST-00000003");
+    wrongindexmap.put(4, "backupfilestestTemp.fa_BACKUPTEST-00000004");
+    wrongindexmap.put(5, "backupfilestestTemp.fa_BACKUPTEST-00000005");
+    wrongindexmap.put(6, "backupfilestestTemp.fa_BACKUPTEST-00000006");
+    wrongindexmap.put(7, "backupfilestestTemp.fa_BACKUPTEST-00000007");
+    wrongindexmap.put(8, "backupfilestestTemp.fa_BACKUPTEST-00000008");
+    wrongindexmap.put(9, "backupfilestestTemp.fa_BACKUPTEST-00000009");
+    wrongindexmap.put(10, "backupfilestestTemp.fa_BACKUPTEST-00000010");
+    int[] indexes2 = { 3, 4, 5, 6, 7, 8, 9, 10 };
+    int[] indexes3 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
+    Assert.assertTrue(checkBackupFiles(correctindexmap));
+    Assert.assertFalse(checkBackupFiles(wrongindexmap));
+    Assert.assertFalse(checkBackupFiles(indexes2));
+    Assert.assertFalse(checkBackupFiles(indexes3));
+  }
+
+  // save keeping only the last rollMax (2) backup files
+  @Test(groups = { "Functional" })
+  public void backupsEnabledRollMaxTest() throws Exception
+  {
+    // Enable BackupFiles and set noMax so all backupfiles get kept
+    setBackupFilesOptions(true, false, false);
+
+    // init the newFile and backups (i.e. make sure newFile exists on its own
+    // and has no backups)
+    initNewFileForTesting();
+
+    // now save a few times again. No rollMax so should have more than two
+    // backup files
+    int numSaves = 10;
+    for (int i = 0; i < numSaves; i++)
+    {
+      save();
+    }
+
+    // check there are "rollMax" backup files and they are all saved correctly
+    // check 10 backup files
+    HashMap correctindexmap = new HashMap();
+    correctindexmap.put(9, "backupfilestestTemp.fa_BACKUPTEST-00000009");
+    correctindexmap.put(10, "backupfilestestTemp.fa_BACKUPTEST-00000010");
+    int[] indexes2 = { 10 };
+    int[] indexes3 = { 8, 9, 10 };
+    Assert.assertTrue(checkBackupFiles(correctindexmap));
+    Assert.assertFalse(checkBackupFiles(indexes2));
+    Assert.assertFalse(checkBackupFiles(indexes3));
+  }
+
+  // save keeping only the last rollMax (2) backup files
+  @Test(groups = { "Functional" })
+  public void backupsEnabledReverseRollMaxTest() throws Exception
+  {
+    // Enable BackupFiles and set noMax so all backupfiles get kept
+    setBackupFilesOptions(true, true, false);
+
+    // init the newFile and backups (i.e. make sure newFile exists on its own
+    // and has no backups)
+    initNewFileForTesting();
+
+    // now save a few times again. No rollMax so should have more than two
+    // backup files
+    int numSaves = 10;
+    for (int i = 0; i < numSaves; i++)
+    {
+      save();
+    }
+
+    // check there are "rollMax" backup files and they are all saved correctly
+    // check 10 backup files
+    HashMap correctindexmap = new HashMap();
+    correctindexmap.put(1, "backupfilestestTemp.fa_BACKUPTEST-00000001");
+    correctindexmap.put(2, "backupfilestestTemp.fa_BACKUPTEST-00000002");
+    int[] indexes2 = { 1 };
+    int[] indexes3 = { 1, 2, 3 };
+    Assert.assertTrue(checkBackupFiles(correctindexmap));
+    Assert.assertFalse(checkBackupFiles(indexes2));
+    Assert.assertFalse(checkBackupFiles(indexes3));
+  }
+
+  private void setBackupFilesOptions()
+  {
+    setBackupFilesOptions(true, false, false);
+  }
+
+  private void setBackupFilesOptions(boolean enabled, boolean reverse,
+          boolean noMax)
+  {
+    Cache.loadProperties("test/jalview/io/testProps.jvprops");
+
+    Cache.applicationProperties.setProperty(BackupFiles.ENABLED,
+            Boolean.toString(enabled));
+    Cache.applicationProperties.setProperty(BackupFiles.SUFFIX, suffix);
+    Cache.applicationProperties.setProperty(BackupFiles.SUFFIX_DIGITS,
+            Integer.toString(digits));
+    Cache.applicationProperties.setProperty(BackupFiles.REVERSE_ORDER,
+            Boolean.toString(reverse));
+    Cache.applicationProperties.setProperty(BackupFiles.NO_MAX,
+            Boolean.toString(noMax));
+    Cache.applicationProperties.setProperty(BackupFiles.ROLL_MAX,
+            Integer.toString(rollMax));
+    Cache.applicationProperties.setProperty(BackupFiles.CONFIRM_DELETE_OLD,
+            "false");
+  }
+
+  private void save()
+  {
+    if (af != null)
+    {
+    af.saveAlignment(newFile, jalview.io.FileFormat.Fasta);
+    }
+  }
+
+  // this runs cleanTmpFiles and then writes the newFile once as a starting
+  // point for all tests
+  private void initNewFileForTesting() throws Exception
+  {
+    cleanupTmpFiles();
+
+    AppletFormatAdapter afa = new AppletFormatAdapter();
+    AlignmentI al = afa.readFile(testFile, DataSourceType.FILE,
+            jalview.io.FileFormat.Fasta);
+    List<SequenceI> l = al.getSequences();
+
+    // check this is right
+    if (l.size() != 1)
+    {
+      throw new Exception("single sequence from '" + testFile
+              + "' not read in correctly (should be a single short sequence). List<SequenceI> size is wrong.");
+    }
+    SequenceI s = l.get(0);
+    Sequence ref = new Sequence(sequenceName, sequenceData);
+    ref.setDescription(sequenceDescription);
+    if (!sequencesEqual(s, ref))
+    {
+      throw new Exception("single sequence from '" + testFile
+              + "' not read in correctly (should be a single short sequence). SequenceI name, description or data is wrong.");
+    }
+    // save alignment file to new filename -- this doesn't test backups disabled
+    // yet as this file shouldn't already exist
+    af = new AlignFrame(al, 0, 0);
+    af.saveAlignment(newFile, jalview.io.FileFormat.Fasta);
+  }
+
+  // this deletes the newFile (if it exists) and any saved backup file for it
+  @AfterClass(alwaysRun = true)
+  private void cleanupTmpFiles()
+  {
+    File newfile = new File(newFile);
+    if (newfile.exists())
+    {
+      newfile.delete();
+    }
+    File[] tmpFiles = getBackupFiles(newFile, suffix, digits);
+    for (int i = 0; i < tmpFiles.length; i++)
+    {
+      if (actuallyDeleteTmpFiles)
+      {
+        tmpFiles[i].delete();
+      }
+      else
+      {
+        System.out.println("Pretending to delete " + tmpFiles[i].getPath());
+      }
+    }
+  }
+
+  private static File[] getBackupFiles(String f, String s, int i)
+  {
+    TreeMap<Integer, File> bfTreeMap = BackupFiles.getBackupFilesAsTreeMap(f,
+            s, i);
+    File[] backupFiles = new File[bfTreeMap.size()];
+    bfTreeMap.values().toArray(backupFiles);
+    return backupFiles;
+  }
+
+  private static File[] getBackupFiles()
+  {
+    return getBackupFiles(newFile, suffix, digits);
+  }
+
+  private static boolean checkBackupFiles(HashMap<Integer, String> indexmap)
+          throws IOException
+  {
+    TreeMap<Integer, File> map = BackupFiles.getBackupFilesAsTreeMap(newFile,
+            suffix, digits);
+    Enumeration<Integer> indexesenum = Collections
+            .enumeration(indexmap.keySet());
+    while (indexesenum.hasMoreElements())
+    {
+      int i = indexesenum.nextElement();
+      String indexfilename = indexmap.get(i);
+      if (!map.containsKey(i))
+      {
+        return false;
+      }
+      File f = map.get(i);
+      if (!filesContentEqual(newFile, f.getPath()))
+      {
+        return false;
+      }
+      map.remove(i);
+      if (f == null)
+      {
+        return false;
+      }
+      if (!f.getName().equals(indexfilename))
+      {
+        return false;
+      }
+    }
+    // should be nothing left in map
+    if (map.size() > 0)
+    {
+      return false;
+    }
+
+    return true;
+  }
+
+  private static boolean checkBackupFiles(int[] indexes) throws IOException
+  {
+    TreeMap<Integer, File> map = BackupFiles.getBackupFilesAsTreeMap(newFile,
+            suffix, digits);
+    for (int m = 0; m < indexes.length; m++)
+    {
+      int i = indexes[m];
+      if (!map.containsKey(i))
+      {
+        return false;
+      }
+      File f = map.get(i);
+      if (!filesContentEqual(newFile, f.getPath()))
+      {
+        return false;
+      }
+      map.remove(i);
+      if (f == null)
+      {
+        return false;
+      }
+      // check the filename -- although this uses the same code to forumulate the filename so not much of a test!
+      String filename = BackupFilenameParts.getBackupFilename(i,
+              newBasename + testExt, suffix, digits);
+      if (!filename.equals(f.getName()))
+      {
+        System.out.println("Supposed filename '" + filename
+                + "' not equal to actual filename '" + f.getName() + "'");
+        return false;
+      }
+    }
+    // should be nothing left in map
+    if (map.size() > 0)
+    {
+      return false;
+    }
+
+    return true;
+  }
+
+  private static String[] getBackupFilesAsStrings()
+  {
+    File[] files = getBackupFiles(newFile, suffix, digits);
+    String[] filenames = new String[files.length];
+    for (int i = 0; i < files.length; i++)
+    {
+      filenames[i] = files[i].getPath();
+    }
+    return filenames;
+  }
+
+  public static boolean sequencesEqual(SequenceI s1, SequenceI s2) {
+    if (s1 == null && s2 == null) {
+      return true;
+    } else if (s1 == null || s2 == null) {
+      return false;
+    }
+    return (s1.getName().equals(s2.getName())
+            && s1.getDescription().equals(s2.getDescription())
+            && Arrays.equals(s1.getSequence(), s2.getSequence()));
+  }
+
+  public static boolean filesContentEqual(String fileName1,
+          String fileName2) throws IOException
+  {
+    Path file1 = Paths.get(fileName1);
+    Path file2 = Paths.get(fileName2);
+    byte[] bytes1 = Files.readAllBytes(file1);
+    byte[] bytes2 = Files.readAllBytes(file2);
+    return Arrays.equals(bytes1, bytes2);
+  }
+
+}
index 32ca841..77c18db 100644 (file)
@@ -45,12 +45,12 @@ import jalview.gui.JvOptionPane;
 import jalview.schemes.FeatureColour;
 import jalview.structure.StructureSelectionManager;
 import jalview.util.matcher.Condition;
+import jalview.viewmodel.seqfeatures.FeatureRendererModel;
+import jalview.viewmodel.seqfeatures.FeatureRendererModel.FeatureSettingsBean;
 
 import java.awt.Color;
 import java.io.File;
 import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -475,24 +475,22 @@ public class FeaturesFileTest
      * first with no features displayed, exclude non-positional features
      */
     FeatureRenderer fr = af.alignPanel.getFeatureRenderer();
-    Map<String, FeatureColourI> visible = fr.getDisplayedFeatureCols();
-    List<String> visibleGroups = new ArrayList<>(
-            Arrays.asList(new String[] {}));
-    String exported = featuresFile.printJalviewFormat(
-            al.getSequencesArray(), visible, null, visibleGroups, false);
+    String exported = featuresFile
+            .printJalviewFormat(al.getSequencesArray(), fr, false);
     String expected = "No Features Visible";
     assertEquals(expected, exported);
 
     /*
-     * include non-positional features
+     * include non-positional features, but still no positional features
      */
-    visibleGroups.add("uniprot");
-    exported = featuresFile.printJalviewFormat(al.getSequencesArray(),
-            visible, null, visibleGroups, true);
-    expected = "Cath\tFER_CAPAA\t-1\t0\t0\tDomain\t0.0\n"
-            + "desc1\tFER_CAPAN\t-1\t0\t0\tPfam\t1.3\n"
-            + "desc3\tFER1_SOLLC\t-1\t0\t0\tPfam\n" // NaN is not output
-            + "\nSTARTGROUP\tuniprot\nENDGROUP\tuniprot\n";
+    fr.setGroupVisibility("uniprot", true);
+    exported = featuresFile.printJalviewFormat(al.getSequencesArray(), fr,
+            true);
+    expected = "\nSTARTGROUP\tuniprot\n"
+            + "Cath\tFER_CAPAA\t-1\t0\t0\tDomain\t0.0\n"
+            + "ENDGROUP\tuniprot\n\n"
+            + "desc1\tFER_CAPAN\t-1\t0\t0\tPfam\t1.3\n\n"
+            + "desc3\tFER1_SOLLC\t-1\t0\t0\tPfam\n"; // NaN is not output
     assertEquals(expected, exported);
 
     /*
@@ -500,9 +498,8 @@ public class FeaturesFileTest
      */
     fr.setVisible("METAL");
     fr.setVisible("GAMMA-TURN");
-    visible = fr.getDisplayedFeatureCols();
-    exported = featuresFile.printJalviewFormat(al.getSequencesArray(),
-            visible, null, visibleGroups, false);
+    exported = featuresFile.printJalviewFormat(al.getSequencesArray(), fr,
+            false);
     expected = "METAL\tcc9900\n"
             + "GAMMA-TURN\tscore|ff0000|00ffff|noValueMin|20.0|95.0|below|66.0\n"
             + "\nSTARTGROUP\tuniprot\n"
@@ -515,11 +512,10 @@ public class FeaturesFileTest
      * now set Pfam visible
      */
     fr.setVisible("Pfam");
-    visible = fr.getDisplayedFeatureCols();
-    exported = featuresFile.printJalviewFormat(al.getSequencesArray(),
-            visible, null, visibleGroups, false);
+    exported = featuresFile.printJalviewFormat(al.getSequencesArray(), fr,
+            false);
     /*
-     * features are output within group, ordered by sequence and by type
+     * features are output within group, ordered by sequence and type
      */
     expected = "METAL\tcc9900\n"
             + "Pfam\tff0000\n"
@@ -529,9 +525,36 @@ public class FeaturesFileTest
             + "Iron\tFER_CAPAA\t-1\t39\t39\tMETAL\t0.0\n"
             + "<html>Pfam domain<a href=\"http://pfam.xfam.org/family/PF00111\">Pfam_3_4</a></html>\tFER_CAPAA\t-1\t20\t20\tPfam\t0.0\n"
             + "ENDGROUP\tuniprot\n"
-            // null / empty group features output after features in named
-            // groups:
+            // null / empty group features are output after named groups
+            + "\ndesc2\tFER_CAPAN\t-1\t4\t9\tPfam\n"
+            + "\ndesc4\tFER1_SOLLC\t-1\t5\t8\tPfam\t-2.6\n";
+    assertEquals(expected, exported);
+
+    /*
+     * hide uniprot group
+     */
+    fr.setGroupVisibility("uniprot", false);
+    expected = "METAL\tcc9900\n" + "Pfam\tff0000\n"
+            + "GAMMA-TURN\tscore|ff0000|00ffff|noValueMin|20.0|95.0|below|66.0\n"
+            + "\ndesc2\tFER_CAPAN\t-1\t4\t9\tPfam\n"
+            + "\ndesc4\tFER1_SOLLC\t-1\t5\t8\tPfam\t-2.6\n";
+    exported = featuresFile.printJalviewFormat(al.getSequencesArray(), fr,
+            false);
+    assertEquals(expected, exported);
+
+    /*
+     * include non-positional (overrides group not shown)
+     */
+    exported = featuresFile.printJalviewFormat(al.getSequencesArray(), fr,
+            true);
+    expected = "METAL\tcc9900\n" + "Pfam\tff0000\n"
+            + "GAMMA-TURN\tscore|ff0000|00ffff|noValueMin|20.0|95.0|below|66.0\n"
+            + "\nSTARTGROUP\tuniprot\n"
+            + "Cath\tFER_CAPAA\t-1\t0\t0\tDomain\t0.0\n"
+            + "ENDGROUP\tuniprot\n"
+            + "\ndesc1\tFER_CAPAN\t-1\t0\t0\tPfam\t1.3\n"
             + "desc2\tFER_CAPAN\t-1\t4\t9\tPfam\n"
+            + "\ndesc3\tFER1_SOLLC\t-1\t0\t0\tPfam\n"
             + "desc4\tFER1_SOLLC\t-1\t5\t8\tPfam\t-2.6\n";
     assertEquals(expected, exported);
   }
@@ -547,16 +570,14 @@ public class FeaturesFileTest
      * no features
      */
     FeaturesFile featuresFile = new FeaturesFile();
-    FeatureRenderer fr = af.alignPanel.getFeatureRenderer();
-    Map<String, FeatureColourI> visible = new HashMap<>();
-    List<String> visibleGroups = new ArrayList<>(
-            Arrays.asList(new String[] {}));
+    FeatureRendererModel fr = (FeatureRendererModel) af.alignPanel
+            .getFeatureRenderer();
     String exported = featuresFile.printGffFormat(al.getSequencesArray(),
-            visible, visibleGroups, false);
+            fr, false);
     String gffHeader = "##gff-version 2\n";
     assertEquals(gffHeader, exported);
-    exported = featuresFile.printGffFormat(al.getSequencesArray(), visible,
-            visibleGroups, true);
+    exported = featuresFile.printGffFormat(al.getSequencesArray(), fr,
+            true);
     assertEquals(gffHeader, exported);
 
     /*
@@ -578,18 +599,31 @@ public class FeaturesFileTest
     al.getSequenceAt(1).addSequenceFeature(sf);
 
     /*
+     * 'discover' features then hide all feature types
+     */
+    fr.findAllFeatures(true);
+    FeatureSettingsBean[] data = new FeatureSettingsBean[4];
+    FeatureColourI fc = new FeatureColour(Color.PINK);
+    data[0] = new FeatureSettingsBean("Domain", fc, null, false);
+    data[1] = new FeatureSettingsBean("METAL", fc, null, false);
+    data[2] = new FeatureSettingsBean("GAMMA-TURN", fc, null, false);
+    data[3] = new FeatureSettingsBean("Pfam", fc, null, false);
+    fr.setFeaturePriority(data);
+
+    /*
      * with no features displayed, exclude non-positional features
      */
-    exported = featuresFile.printGffFormat(al.getSequencesArray(), visible,
-            visibleGroups, false);
+    exported = featuresFile.printGffFormat(al.getSequencesArray(), fr,
+            false);
     assertEquals(gffHeader, exported);
 
     /*
      * include non-positional features
      */
-    visibleGroups.add("Uniprot");
-    exported = featuresFile.printGffFormat(al.getSequencesArray(), visible,
-            visibleGroups, true);
+    fr.setGroupVisibility("Uniprot", true);
+    fr.setGroupVisibility("s3dm", false);
+    exported = featuresFile.printGffFormat(al.getSequencesArray(), fr,
+            true);
     String expected = gffHeader
             + "FER_CAPAA\tUniprot\tDomain\t0\t0\t0.0\t.\t.\n";
     assertEquals(expected, exported);
@@ -600,9 +634,8 @@ public class FeaturesFileTest
      */
     fr.setVisible("METAL");
     fr.setVisible("GAMMA-TURN");
-    visible = fr.getDisplayedFeatureCols();
-    exported = featuresFile.printGffFormat(al.getSequencesArray(), visible,
-            visibleGroups, false);
+    exported = featuresFile.printGffFormat(al.getSequencesArray(), fr,
+            false);
     // METAL feature has null group: description used for column 2
     expected = gffHeader + "FER_CAPAA\tCath\tMETAL\t39\t39\t1.2\t.\t.\n";
     assertEquals(expected, exported);
@@ -610,9 +643,9 @@ public class FeaturesFileTest
     /*
      * set s3dm group visible
      */
-    visibleGroups.add("s3dm");
-    exported = featuresFile.printGffFormat(al.getSequencesArray(), visible,
-            visibleGroups, false);
+    fr.setGroupVisibility("s3dm", true);
+    exported = featuresFile.printGffFormat(al.getSequencesArray(), fr,
+            false);
     // METAL feature has null group: description used for column 2
     expected = gffHeader + "FER_CAPAA\tCath\tMETAL\t39\t39\t1.2\t.\t.\n"
             + "FER_CAPAN\ts3dm\tGAMMA-TURN\t36\t38\t2.1\t.\t.\n";
@@ -622,9 +655,8 @@ public class FeaturesFileTest
      * now set Pfam visible
      */
     fr.setVisible("Pfam");
-    visible = fr.getDisplayedFeatureCols();
-    exported = featuresFile.printGffFormat(al.getSequencesArray(), visible,
-            visibleGroups, false);
+    exported = featuresFile.printGffFormat(al.getSequencesArray(), fr,
+            false);
     // Pfam feature columns include strand(+), phase(2), attributes
     expected = gffHeader
             + "FER_CAPAA\tCath\tMETAL\t39\t39\t1.2\t.\t.\n"
@@ -704,7 +736,167 @@ public class FeaturesFileTest
     featureFilters.put("pfam", filter2);
     visible.put("foobar", new FeatureColour(Color.blue));
     ff.outputFeatureFilters(sb, visible, featureFilters);
-    String expected = "\nSTARTFILTERS\nfoobar\tLabel Present\npfam\t(CSQ:PolyPhen Present) AND (Score LE -2.4)\nENDFILTERS\n\n";
+    String expected = "\nSTARTFILTERS\nfoobar\tLabel Present\npfam\t(CSQ:PolyPhen Present) AND (Score LE -2.4)\nENDFILTERS\n";
     assertEquals(expected, sb.toString());
   }
+
+  /**
+   * Output as GFF should not include features which are not visible due to
+   * colour threshold or feature filter settings
+   * 
+   * @throws Exception
+   */
+  @Test(groups = { "Functional" })
+  public void testPrintGffFormat_withFilters() throws Exception
+  {
+    File f = new File("examples/uniref50.fa");
+    AlignmentI al = readAlignmentFile(f);
+    AlignFrame af = new AlignFrame(al, 500, 500);
+    SequenceFeature sf1 = new SequenceFeature("METAL", "Cath", 39, 39, 1.2f,
+            null);
+    sf1.setValue("clin_sig", "Likely Pathogenic");
+    sf1.setValue("AF", "24");
+    al.getSequenceAt(0).addSequenceFeature(sf1);
+    SequenceFeature sf2 = new SequenceFeature("METAL", "Cath", 41, 41, 0.6f,
+            null);
+    sf2.setValue("clin_sig", "Benign");
+    sf2.setValue("AF", "46");
+    al.getSequenceAt(0).addSequenceFeature(sf2);
+  
+    FeaturesFile featuresFile = new FeaturesFile();
+    FeatureRenderer fr = af.alignPanel.getFeatureRenderer();
+    final String gffHeader = "##gff-version 2\n";
+
+    fr.setVisible("METAL");
+    fr.setColour("METAL", new FeatureColour(Color.PINK));
+    String exported = featuresFile.printGffFormat(al.getSequencesArray(),
+            fr, false);
+    String expected = gffHeader
+            + "FER_CAPAA\tCath\tMETAL\t39\t39\t1.2\t.\t.\n"
+            + "FER_CAPAA\tCath\tMETAL\t41\t41\t0.6\t.\t.\n";
+    assertEquals(expected, exported);
+
+    /*
+     * now threshold to Score > 1.1 - should exclude sf2
+     */
+    FeatureColourI fc = new FeatureColour(null, Color.white, Color.BLACK,
+            Color.white, 0f, 2f);
+    fc.setAboveThreshold(true);
+    fc.setThreshold(1.1f);
+    fr.setColour("METAL", fc);
+    exported = featuresFile.printGffFormat(al.getSequencesArray(), fr,
+            false);
+    expected = gffHeader + "FER_CAPAA\tCath\tMETAL\t39\t39\t1.2\t.\t.\n";
+    assertEquals(expected, exported);
+
+    /*
+     * remove threshold and check sf2 is exported
+     */
+    fc.setAboveThreshold(false);
+    exported = featuresFile.printGffFormat(al.getSequencesArray(), fr,
+            false);
+    expected = gffHeader + "FER_CAPAA\tCath\tMETAL\t39\t39\t1.2\t.\t.\n"
+            + "FER_CAPAA\tCath\tMETAL\t41\t41\t0.6\t.\t.\n";
+    assertEquals(expected, exported);
+
+    /*
+     * filter on (clin_sig contains Benign) - should include sf2 and exclude sf1
+     */
+    FeatureMatcherSetI filter = new FeatureMatcherSet();
+    filter.and(FeatureMatcher.byAttribute(Condition.Contains, "benign",
+            "clin_sig"));
+    fr.setFeatureFilter("METAL", filter);
+    exported = featuresFile.printGffFormat(al.getSequencesArray(), fr,
+            false);
+    expected = gffHeader + "FER_CAPAA\tCath\tMETAL\t41\t41\t0.6\t.\t.\n";
+    assertEquals(expected, exported);
+  }
+
+  /**
+   * Output as Jalview should not include features which are not visible due to
+   * colour threshold or feature filter settings
+   * 
+   * @throws Exception
+   */
+  @Test(groups = { "Functional" })
+  public void testPrintJalviewFormat_withFilters() throws Exception
+  {
+    File f = new File("examples/uniref50.fa");
+    AlignmentI al = readAlignmentFile(f);
+    AlignFrame af = new AlignFrame(al, 500, 500);
+    SequenceFeature sf1 = new SequenceFeature("METAL", "Cath", 39, 39, 1.2f,
+            "grp1");
+    sf1.setValue("clin_sig", "Likely Pathogenic");
+    sf1.setValue("AF", "24");
+    al.getSequenceAt(0).addSequenceFeature(sf1);
+    SequenceFeature sf2 = new SequenceFeature("METAL", "Cath", 41, 41, 0.6f,
+            "grp2");
+    sf2.setValue("clin_sig", "Benign");
+    sf2.setValue("AF", "46");
+    al.getSequenceAt(0).addSequenceFeature(sf2);
+  
+    FeaturesFile featuresFile = new FeaturesFile();
+    FeatureRenderer fr = af.alignPanel.getFeatureRenderer();
+    fr.findAllFeatures(true);
+  
+    fr.setVisible("METAL");
+    fr.setColour("METAL", new FeatureColour(Color.PINK));
+    String exported = featuresFile.printJalviewFormat(
+            al.getSequencesArray(),
+            fr, false);
+    String expected = "METAL\tffafaf\n\nSTARTGROUP\tgrp1\n"
+            + "Cath\tFER_CAPAA\t-1\t39\t39\tMETAL\t1.2\n"
+            + "ENDGROUP\tgrp1\n\nSTARTGROUP\tgrp2\n"
+            + "Cath\tFER_CAPAA\t-1\t41\t41\tMETAL\t0.6\n"
+            + "ENDGROUP\tgrp2\n";
+    assertEquals(expected, exported);
+  
+    /*
+     * now threshold to Score > 1.1 - should exclude sf2
+     * (and there should be no empty STARTGROUP/ENDGROUP output)
+     */
+    FeatureColourI fc = new FeatureColour(null, Color.white, Color.BLACK,
+            Color.white, 0f, 2f);
+    fc.setAboveThreshold(true);
+    fc.setThreshold(1.1f);
+    fr.setColour("METAL", fc);
+    exported = featuresFile.printJalviewFormat(al.getSequencesArray(), fr,
+            false);
+    expected = "METAL\tscore|ffffff|000000|noValueMin|abso|0.0|2.0|above|1.1\n\n"
+            + "STARTGROUP\tgrp1\n"
+            + "Cath\tFER_CAPAA\t-1\t39\t39\tMETAL\t1.2\n"
+            + "ENDGROUP\tgrp1\n";
+    assertEquals(expected, exported);
+  
+    /*
+     * remove threshold and check sf2 is exported
+     */
+    fc.setAboveThreshold(false);
+    exported = featuresFile.printJalviewFormat(al.getSequencesArray(), fr,
+            false);
+    expected = "METAL\tscore|ffffff|000000|noValueMin|abso|0.0|2.0|none\n\n"
+            + "STARTGROUP\tgrp1\n"
+            + "Cath\tFER_CAPAA\t-1\t39\t39\tMETAL\t1.2\n"
+            + "ENDGROUP\tgrp1\n\nSTARTGROUP\tgrp2\n"
+            + "Cath\tFER_CAPAA\t-1\t41\t41\tMETAL\t0.6\n"
+            + "ENDGROUP\tgrp2\n";
+    assertEquals(expected, exported);
+  
+    /*
+     * filter on (clin_sig contains Benign) - should include sf2 and exclude sf1
+     */
+    FeatureMatcherSetI filter = new FeatureMatcherSet();
+    filter.and(FeatureMatcher.byAttribute(Condition.Contains, "benign",
+            "clin_sig"));
+    fr.setFeatureFilter("METAL", filter);
+    exported = featuresFile.printJalviewFormat(al.getSequencesArray(), fr,
+            false);
+    expected = "FER_CAPAA\tCath\tMETAL\t41\t41\t0.6\t.\t.\n";
+    expected = "METAL\tscore|ffffff|000000|noValueMin|abso|0.0|2.0|none\n\n"
+            + "STARTFILTERS\nMETAL\tclin_sig Contains benign\nENDFILTERS\n\n"
+            + "STARTGROUP\tgrp2\n"
+            + "Cath\tFER_CAPAA\t-1\t41\t41\tMETAL\t0.6\n"
+            + "ENDGROUP\tgrp2\n";
+    assertEquals(expected, exported);
+  }
 }
index 97349b5..254feaa 100644 (file)
@@ -13,11 +13,18 @@ import jalview.analysis.scoremodels.ScoreModels;
 import java.io.IOException;
 import java.net.MalformedURLException;
 
+import org.testng.annotations.AfterMethod;
 import org.testng.annotations.Test;
 
 public class ScoreMatrixFileTest
 {
 
+  @AfterMethod(alwaysRun=true)
+  public void tearDownAfterTest()
+  {
+    ScoreModels.getInstance().reset();
+  }
+
   /**
    * Test a successful parse of a (small) score matrix file
    * 
index 87e35c7..cf3c7e5 100644 (file)
@@ -37,11 +37,11 @@ import jalview.viewmodel.seqfeatures.FeatureRendererModel;
 import java.awt.Color;
 import java.util.Map;
 
-import junit.extensions.PA;
-
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
+import junit.extensions.PA;
+
 public class SequenceAnnotationReportTest
 {
 
@@ -158,7 +158,8 @@ public class SequenceAnnotationReportTest
     /*
      * then with colour by an attribute the feature lacks
      */
-    FeatureColourI fc = new FeatureColour(Color.white, Color.black, 5, 10);
+    FeatureColourI fc = new FeatureColour(null, Color.white, Color.black,
+            null, 5, 10);
     fc.setAttributeName("Pfam");
     fr.setColour("METAL", fc);
     sb.setLength(0);
@@ -187,7 +188,8 @@ public class SequenceAnnotationReportTest
 
     FeatureRendererModel fr = new FeatureRenderer(null);
     Map<String, float[][]> minmax = fr.getMinMax();
-    FeatureColourI fc = new FeatureColour(Color.white, Color.blue, 12, 22);
+    FeatureColourI fc = new FeatureColour(null, Color.white, Color.blue,
+            null, 12, 22);
     fc.setAttributeName("clinical_significance");
     fr.setColour("METAL", fc);
     minmax.put("METAL", new float[][] { { 0f, 1f }, null });
@@ -328,7 +330,8 @@ public class SequenceAnnotationReportTest
 
     // with showDbRefs = true, colour Variant features by clinical_significance
     sb.setLength(0);
-    FeatureColourI fc = new FeatureColour(Color.green, Color.pink, 2, 3);
+    FeatureColourI fc = new FeatureColour(null, Color.green, Color.pink,
+            null, 2, 3);
     fc.setAttributeName("clinical_significance");
     fr.setColour("Variant", fc);
     sar.createSequenceAnnotationReport(sb, seq, true, true, fr);
index dfd7973..010a4b2 100644 (file)
@@ -55,10 +55,9 @@ public class JvCacheableInputBoxTest
     cacheBox.updateCache();
     try
     {
-      // This 1ms delay is essential to prevent the
-      // assertion below from executing before
-      // cacheBox.updateCache() finishes updating the cache
-      Thread.sleep(100);
+      // This delay is to let
+      // cacheBox.updateCache() finish updating the cache
+      Thread.sleep(200);
     } catch (InterruptedException e)
     {
       e.printStackTrace();
index 96364e4..f180395 100644 (file)
@@ -1,5 +1,13 @@
 #---JalviewX Properties File---
 #Fri Apr 25 09:54:25 BST 2014
+#
+BACKUPFILES_ROLL_MAX=2
+BACKUPFILES_REVERSE_ORDER=false
+BACKUPFILES_SUFFIX=_BACKUPFILESTESTTMP%n
+BACKUPFILES_CONFIRM_DELETE_OLD=false
+BACKUPFILES_NO_MAX=false
+BACKUPFILES_ENABLED=true
+BACKUPFILES_SUFFIX_DIGITS=8
 SCREEN_Y=768
 SCREEN_X=936
 SHOW_WSDISCOVERY_ERRORS=true
index 7e3c0b4..9e0efe6 100644 (file)
@@ -66,7 +66,7 @@ public class VCFLoaderTest
       // insertion G/GA is transferred to nucleotide but not to peptide
       "17\t45051613\t.\tG\tGA,C\t1666.64\tRF\tAC=15;AF=3.0e-03,2.0e-03" };
 
-  @BeforeClass
+  @BeforeClass(alwaysRun = true)
   public void setUp()
   {
     /*
@@ -103,7 +103,9 @@ public class VCFLoaderTest
     assertEquals(sf.getFeatureGroup(), "VCF");
     assertEquals(sf.getBegin(), 2);
     assertEquals(sf.getEnd(), 2);
-    assertEquals(sf.getScore(), 4.0e-03, DELTA);
+    assertEquals(sf.getScore(), 0f);
+    assertEquals(Float.parseFloat((String) sf.getValue("AF")), 4.0e-03,
+            DELTA);
     assertEquals(sf.getValue(Gff3Helper.ALLELES), "A,C");
     assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
     sf = geneFeatures.get(1);
@@ -111,7 +113,9 @@ public class VCFLoaderTest
     assertEquals(sf.getBegin(), 2);
     assertEquals(sf.getEnd(), 2);
     assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
-    assertEquals(sf.getScore(), 5.0e-03, DELTA);
+    assertEquals(sf.getScore(), 0f);
+    assertEquals(Float.parseFloat((String) sf.getValue("AF")), 5.0e-03,
+            DELTA);
     assertEquals(sf.getValue(Gff3Helper.ALLELES), "A,T");
 
     sf = geneFeatures.get(2);
@@ -119,7 +123,9 @@ public class VCFLoaderTest
     assertEquals(sf.getBegin(), 4);
     assertEquals(sf.getEnd(), 4);
     assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
-    assertEquals(sf.getScore(), 2.0e-03, DELTA);
+    assertEquals(sf.getScore(), 0f);
+    assertEquals(Float.parseFloat((String) sf.getValue("AF")), 2.0e-03,
+            DELTA);
     assertEquals(sf.getValue(Gff3Helper.ALLELES), "G,C");
 
     sf = geneFeatures.get(3);
@@ -127,7 +133,9 @@ public class VCFLoaderTest
     assertEquals(sf.getBegin(), 4);
     assertEquals(sf.getEnd(), 4);
     assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
-    assertEquals(sf.getScore(), 3.0e-03, DELTA);
+    assertEquals(sf.getScore(), 0f);
+    assertEquals(Float.parseFloat((String) sf.getValue("AF")), 3.0e-03,
+            DELTA);
     assertEquals(sf.getValue(Gff3Helper.ALLELES), "G,GA");
 
     /*
@@ -141,14 +149,18 @@ public class VCFLoaderTest
     assertEquals(sf.getBegin(), 2);
     assertEquals(sf.getEnd(), 2);
     assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
-    assertEquals(sf.getScore(), 2.0e-03, DELTA);
+    assertEquals(sf.getScore(), 0f);
+    assertEquals(Float.parseFloat((String) sf.getValue("AF")), 2.0e-03,
+            DELTA);
     assertEquals(sf.getValue(Gff3Helper.ALLELES), "G,C");
     sf = transcriptFeatures.get(1);
     assertEquals(sf.getFeatureGroup(), "VCF");
     assertEquals(sf.getBegin(), 2);
     assertEquals(sf.getEnd(), 2);
     assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
-    assertEquals(sf.getScore(), 3.0e-03, DELTA);
+    assertEquals(sf.getScore(), 0f);
+    assertEquals(Float.parseFloat((String) sf.getValue("AF")), 3.0e-03,
+            DELTA);
     assertEquals(sf.getValue(Gff3Helper.ALLELES), "G,GA");
 
     /*
@@ -337,7 +349,9 @@ public class VCFLoaderTest
     assertEquals(sf.getBegin(), 24);
     assertEquals(sf.getEnd(), 24);
     assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
-    assertEquals(sf.getScore(), 5.0e-03, DELTA);
+    assertEquals(sf.getScore(), 0f);
+    assertEquals(Float.parseFloat((String) sf.getValue("AF")), 5.0e-03,
+            DELTA);
     assertEquals(sf.getValue(Gff3Helper.ALLELES), "T,A");
 
     /*
@@ -348,7 +362,9 @@ public class VCFLoaderTest
     assertEquals(sf.getBegin(), 24);
     assertEquals(sf.getEnd(), 24);
     assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
-    assertEquals(sf.getScore(), 4.0e-03, DELTA);
+    assertEquals(sf.getScore(), 0f);
+    assertEquals(Float.parseFloat((String) sf.getValue("AF")), 4.0e-03,
+            DELTA);
     assertEquals(sf.getValue(Gff3Helper.ALLELES), "T,G");
 
     /*
@@ -359,7 +375,9 @@ public class VCFLoaderTest
     assertEquals(sf.getBegin(), 22);
     assertEquals(sf.getEnd(), 22);
     assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
-    assertEquals(sf.getScore(), 2.0e-03, DELTA);
+    assertEquals(sf.getScore(), 0f);
+    assertEquals(Float.parseFloat((String) sf.getValue("AF")), 2.0e-03,
+            DELTA);
     assertEquals(sf.getValue(Gff3Helper.ALLELES), "C,G");
 
     /*
@@ -374,7 +392,9 @@ public class VCFLoaderTest
     assertEquals(sf.getBegin(), 21);
     assertEquals(sf.getEnd(), 21);
     assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
-    assertEquals(sf.getScore(), 3.0e-03, DELTA);
+    assertEquals(sf.getScore(), 0f);
+    assertEquals(Float.parseFloat((String) sf.getValue("AF")), 3.0e-03,
+            DELTA);
     assertEquals(sf.getValue(Gff3Helper.ALLELES), "G,GT");
 
     /*
@@ -392,7 +412,9 @@ public class VCFLoaderTest
     assertEquals(sf.getBegin(), 16);
     assertEquals(sf.getEnd(), 16);
     assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
-    assertEquals(sf.getScore(), 3.0e-03, DELTA);
+    assertEquals(sf.getScore(), 0f);
+    assertEquals(Float.parseFloat((String) sf.getValue("AF")), 3.0e-03,
+            DELTA);
     assertEquals(sf.getValue(Gff3Helper.ALLELES), "G,GT");
 
     /*
@@ -403,7 +425,9 @@ public class VCFLoaderTest
     assertEquals(sf.getBegin(), 17);
     assertEquals(sf.getEnd(), 17);
     assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
-    assertEquals(sf.getScore(), 2.0e-03, DELTA);
+    assertEquals(sf.getScore(), 0f);
+    assertEquals(Float.parseFloat((String) sf.getValue("AF")), 2.0e-03,
+            DELTA);
     assertEquals(sf.getValue(Gff3Helper.ALLELES), "C,G");
 
     /*
@@ -463,7 +487,8 @@ public class VCFLoaderTest
     SequenceFeature sf = geneFeatures.get(0);
     assertEquals(sf.getBegin(), 1);
     assertEquals(sf.getEnd(), 1);
-    assertEquals(sf.getScore(), 0.1f, DELTA);
+    assertEquals(sf.getScore(), 0f);
+    assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.1f, DELTA);
     assertEquals(sf.getValue("alleles"), "C,A");
     // gene features include Consequence for all transcripts
     Map map = (Map) sf.getValue("CSQ");
@@ -472,7 +497,8 @@ public class VCFLoaderTest
     sf = geneFeatures.get(1);
     assertEquals(sf.getBegin(), 5);
     assertEquals(sf.getEnd(), 5);
-    assertEquals(sf.getScore(), 0.2f, DELTA);
+    assertEquals(sf.getScore(), 0f);
+    assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.2f, DELTA);
     assertEquals(sf.getValue("alleles"), "C,T");
     map = (Map) sf.getValue("CSQ");
     assertEquals(map.size(), 9);
@@ -480,7 +506,8 @@ public class VCFLoaderTest
     sf = geneFeatures.get(2);
     assertEquals(sf.getBegin(), 9);
     assertEquals(sf.getEnd(), 11); // deletion over 3 positions
-    assertEquals(sf.getScore(), 0.3f, DELTA);
+    assertEquals(sf.getScore(), 0f);
+    assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.3f, DELTA);
     assertEquals(sf.getValue("alleles"), "CGG,C");
     map = (Map) sf.getValue("CSQ");
     assertEquals(map.size(), 9);
@@ -488,7 +515,8 @@ public class VCFLoaderTest
     sf = geneFeatures.get(3);
     assertEquals(sf.getBegin(), 13);
     assertEquals(sf.getEnd(), 13);
-    assertEquals(sf.getScore(), 0.5f, DELTA);
+    assertEquals(sf.getScore(), 0f);
+    assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.5f, DELTA);
     assertEquals(sf.getValue("alleles"), "C,T");
     map = (Map) sf.getValue("CSQ");
     assertEquals(map.size(), 9);
@@ -496,7 +524,8 @@ public class VCFLoaderTest
     sf = geneFeatures.get(4);
     assertEquals(sf.getBegin(), 13);
     assertEquals(sf.getEnd(), 13);
-    assertEquals(sf.getScore(), 0.4f, DELTA);
+    assertEquals(sf.getScore(), 0f);
+    assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.4f, DELTA);
     assertEquals(sf.getValue("alleles"), "C,G");
     map = (Map) sf.getValue("CSQ");
     assertEquals(map.size(), 9);
@@ -504,7 +533,8 @@ public class VCFLoaderTest
     sf = geneFeatures.get(5);
     assertEquals(sf.getBegin(), 17);
     assertEquals(sf.getEnd(), 17);
-    assertEquals(sf.getScore(), 0.7f, DELTA);
+    assertEquals(sf.getScore(), 0f);
+    assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.7f, DELTA);
     assertEquals(sf.getValue("alleles"), "A,G");
     map = (Map) sf.getValue("CSQ");
     assertEquals(map.size(), 9);
@@ -512,7 +542,8 @@ public class VCFLoaderTest
     sf = geneFeatures.get(6);
     assertEquals(sf.getBegin(), 17);
     assertEquals(sf.getEnd(), 17); // insertion
-    assertEquals(sf.getScore(), 0.6f, DELTA);
+    assertEquals(sf.getScore(), 0f);
+    assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.6f, DELTA);
     assertEquals(sf.getValue("alleles"), "A,AC");
     map = (Map) sf.getValue("CSQ");
     assertEquals(map.size(), 9);
@@ -530,7 +561,8 @@ public class VCFLoaderTest
     sf = transcriptFeatures.get(0);
     assertEquals(sf.getBegin(), 3);
     assertEquals(sf.getEnd(), 3);
-    assertEquals(sf.getScore(), 0.2f, DELTA);
+    assertEquals(sf.getScore(), 0f);
+    assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.2f, DELTA);
     assertEquals(sf.getValue("alleles"), "C,T");
     // transcript features only have Consequence for that transcripts
     map = (Map) sf.getValue("CSQ");
@@ -540,7 +572,8 @@ public class VCFLoaderTest
     sf = transcriptFeatures.get(1);
     assertEquals(sf.getBegin(), 11);
     assertEquals(sf.getEnd(), 11);
-    assertEquals(sf.getScore(), 0.7f, DELTA);
+    assertEquals(sf.getScore(), 0f);
+    assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.7f, DELTA);
     assertEquals(sf.getValue("alleles"), "A,G");
     assertEquals(map.size(), 9);
     assertEquals(sf.getValueAsString("CSQ", "Feature"), "transcript3");
@@ -548,7 +581,8 @@ public class VCFLoaderTest
     sf = transcriptFeatures.get(2);
     assertEquals(sf.getBegin(), 11);
     assertEquals(sf.getEnd(), 11);
-    assertEquals(sf.getScore(), 0.6f, DELTA);
+    assertEquals(sf.getScore(), 0f);
+    assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.6f, DELTA);
     assertEquals(sf.getValue("alleles"), "A,AC");
     assertEquals(map.size(), 9);
     assertEquals(sf.getValueAsString("CSQ", "Feature"), "transcript3");
@@ -595,7 +629,8 @@ public class VCFLoaderTest
     sf = transcriptFeatures.get(0);
     assertEquals(sf.getBegin(), 7);
     assertEquals(sf.getEnd(), 7);
-    assertEquals(sf.getScore(), 0.5f, DELTA);
+    assertEquals(sf.getScore(), 0f);
+    assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.5f, DELTA);
     assertEquals(sf.getValue("alleles"), "C,T");
     assertEquals(map.size(), 9);
     assertEquals(sf.getValueAsString("CSQ", "Feature"), "transcript4");
@@ -603,7 +638,8 @@ public class VCFLoaderTest
     sf = transcriptFeatures.get(1);
     assertEquals(sf.getBegin(), 7);
     assertEquals(sf.getEnd(), 7);
-    assertEquals(sf.getScore(), 0.4f, DELTA);
+    assertEquals(sf.getScore(), 0f);
+    assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.4f, DELTA);
     assertEquals(sf.getValue("alleles"), "C,G");
     assertEquals(map.size(), 9);
     assertEquals(sf.getValueAsString("CSQ", "Feature"), "transcript4");
@@ -611,7 +647,8 @@ public class VCFLoaderTest
     sf = transcriptFeatures.get(2);
     assertEquals(sf.getBegin(), 11);
     assertEquals(sf.getEnd(), 11);
-    assertEquals(sf.getScore(), 0.7f, DELTA);
+    assertEquals(sf.getScore(), 0f);
+    assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.7f, DELTA);
     assertEquals(sf.getValue("alleles"), "A,G");
     assertEquals(map.size(), 9);
     assertEquals(sf.getValueAsString("CSQ", "Feature"), "transcript4");
@@ -619,7 +656,8 @@ public class VCFLoaderTest
     sf = transcriptFeatures.get(3);
     assertEquals(sf.getBegin(), 11);
     assertEquals(sf.getEnd(), 11);
-    assertEquals(sf.getScore(), 0.6f, DELTA);
+    assertEquals(sf.getScore(), 0f);
+    assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.6f, DELTA);
     assertEquals(sf.getValue("alleles"), "A,AC");
     assertEquals(map.size(), 9);
     assertEquals(sf.getValueAsString("CSQ", "Feature"), "transcript4");
index 97ded5a..7dc3b9e 100644 (file)
@@ -1,6 +1,7 @@
 package jalview.math;
 
 import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
 import static org.testng.Assert.assertNotSame;
 import static org.testng.Assert.assertNull;
 import static org.testng.Assert.assertTrue;
@@ -188,9 +189,23 @@ public class MatrixTest
       }
     }
     Matrix m1 = new Matrix(in);
+
     Matrix m2 = (Matrix) m1.copy();
     assertNotSame(m1, m2);
     assertTrue(matrixEquals(m1, m2));
+    assertNull(m2.d);
+    assertNull(m2.e);
+
+    /*
+     * now add d and e vectors and recopy
+     */
+    m1.d = Arrays.copyOf(in[2], in[2].length);
+    m1.e = Arrays.copyOf(in[4], in[4].length);
+    m2 = (Matrix) m1.copy();
+    assertNotSame(m2.d, m1.d);
+    assertNotSame(m2.e, m1.e);
+    assertEquals(m2.d, m1.d);
+    assertEquals(m2.e, m1.e);
   }
 
   /**
@@ -356,7 +371,7 @@ public class MatrixTest
     assertMatricesMatch(m1, m2);
   }
 
-  private void assertMatricesMatch(MatrixI m1, MatrixI m2)
+  public static void assertMatricesMatch(MatrixI m1, MatrixI m2)
   {
     if (m1.height() != m2.height())
     {
@@ -378,8 +393,10 @@ public class MatrixTest
         }
       }
     }
-    ArrayAsserts.assertArrayEquals(m1.getD(), m2.getD(), 0.00001d);
-    ArrayAsserts.assertArrayEquals(m1.getE(), m2.getE(), 0.00001d);
+    ArrayAsserts.assertArrayEquals("D vector", m1.getD(), m2.getD(),
+            0.00001d);
+    ArrayAsserts.assertArrayEquals("E vector", m1.getE(), m2.getE(),
+            0.00001d);
   }
 
   @Test(groups = "Functional")
@@ -531,4 +548,30 @@ public class MatrixTest
     values[0][0] = -1d;
     assertEquals(m.getValue(0, 0), 1d, DELTA); // unchanged
   }
+
+  @Test(groups = "Functional")
+  public void testEquals()
+  {
+    double[][] values = new double[][] { { 1, 2, 3 }, { 4, 5, 6 } };
+    Matrix m1 = new Matrix(values);
+    double[][] values2 = new double[][] { { 1, 2, 3 }, { 4, 5, 6 } };
+    Matrix m2 = new Matrix(values2);
+
+    double delta = 0.0001d;
+    assertTrue(m1.equals(m1, delta));
+    assertTrue(m1.equals(m2, delta));
+    assertTrue(m2.equals(m1, delta));
+
+    double[][] values3 = new double[][] { { 1, 2, 3 }, { 4, 5, 7 } };
+    m2 = new Matrix(values3);
+    assertFalse(m1.equals(m2, delta));
+    assertFalse(m2.equals(m1, delta));
+
+    // must be same shape
+    values2 = new double[][] { { 1, 2, 3 } };
+    m2 = new Matrix(values2);
+    assertFalse(m2.equals(m1, delta));
+
+    assertFalse(m1.equals(null, delta));
+  }
 }
diff --git a/test/jalview/math/RotatableMatrixTest.java b/test/jalview/math/RotatableMatrixTest.java
new file mode 100644 (file)
index 0000000..06982d5
--- /dev/null
@@ -0,0 +1,157 @@
+package jalview.math;
+
+import static org.testng.Assert.assertEquals;
+
+import jalview.math.RotatableMatrix.Axis;
+
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+public class RotatableMatrixTest
+{
+  private RotatableMatrix rm;
+
+  @BeforeMethod(alwaysRun = true)
+  public void setUp()
+  {
+    rm = new RotatableMatrix();
+
+    /*
+     * 0.5 1.0 1.5
+     * 1.0 2.0 3.0
+     * 1.5 3.0 4.5
+     */
+    for (int i = 1; i <= 3; i++)
+    {
+      for (int j = 1; j <= 3; j++)
+      {
+        rm.setValue(i - 1, j - 1, i * j / 2f);
+      }
+    }
+  }
+
+  @Test(groups = "Functional")
+  public void testPreMultiply()
+  {
+    float[][] pre = new float[3][3];
+    int i = 1;
+    for (int j = 0; j < 3; j++)
+    {
+      for (int k = 0; k < 3; k++)
+      {
+        pre[j][k] = i++;
+      }
+    }
+
+    rm.preMultiply(pre);
+
+    /*
+     * check rm[i, j] is now the product of the i'th row of pre
+     * and the j'th column of (original) rm
+     */
+    for (int j = 0; j < 3; j++)
+    {
+      for (int k = 0; k < 3; k++)
+      {
+        float expected = 0f;
+        for (int l = 0; l < 3; l++)
+        {
+          float rm_l_k = (l + 1) * (k + 1) / 2f;
+          expected += pre[j][l] * rm_l_k;
+        }
+        assertEquals(rm.getValue(j, k), expected,
+                String.format("[%d, %d]", j, k));
+      }
+    }
+  }
+
+  @Test(groups = "Functional")
+  public void testVectorMultiply()
+  {
+    float[] result = rm.vectorMultiply(new float[] { 2f, 3f, 4.5f });
+
+    // vector times first column of matrix
+    assertEquals(result[0], 2f * 0.5f + 3f * 1f + 4.5f * 1.5f);
+
+    // vector times second column of matrix
+    assertEquals(result[1], 2f * 1.0f + 3f * 2f + 4.5f * 3f);
+
+    // vector times third column of matrix
+    assertEquals(result[2], 2f * 1.5f + 3f * 3f + 4.5f * 4.5f);
+  }
+
+  @Test(groups = "Functional")
+  public void testGetRotation()
+  {
+    float theta = 60f;
+    double cosTheta = Math.cos((theta * Math.PI / 180f));
+    double sinTheta = Math.sin((theta * Math.PI / 180f));
+
+    /*
+     * sanity check that sin(60) = sqrt(3) / 2, cos(60) = 1/2
+     */
+    double delta = 0.0001d;
+    assertEquals(cosTheta, 0.5f, delta);
+    assertEquals(sinTheta, Math.sqrt(3d) / 2d, delta);
+
+    /*
+     * so far so good, now verify rotations
+     * @see https://en.wikipedia.org/wiki/Rotation_matrix#Basic_rotations
+     */
+
+    /*
+     * 60 degrees about X axis should be
+     *  1   0   0 
+     *  0  cos -sin
+     *  0  sin cos
+     *  but code applies the negative of this
+     *  nb cos(-x) = cos(x), sin(-x) = -sin(x)
+     */
+    float[][] rot = RotatableMatrix.getRotation(theta, Axis.X);
+    assertEquals(rot[0][0], 1f, delta);
+    assertEquals(rot[0][1], 0f, delta);
+    assertEquals(rot[0][2], 0f, delta);
+    assertEquals(rot[1][0], 0f, delta);
+    assertEquals(rot[1][1], cosTheta, delta);
+    assertEquals(rot[1][2], sinTheta, delta);
+    assertEquals(rot[2][0], 0f, delta);
+    assertEquals(rot[2][1], -sinTheta, delta);
+    assertEquals(rot[2][2], cosTheta, delta);
+
+    /*
+     * 60 degrees about Y axis should be
+     *   cos 0 sin
+     *    0  1  0
+     *  -sin 0 cos
+     *  but code applies the negative of this
+     */
+    rot = RotatableMatrix.getRotation(theta, Axis.Y);
+    assertEquals(rot[0][0], cosTheta, delta);
+    assertEquals(rot[0][1], 0f, delta);
+    assertEquals(rot[0][2], -sinTheta, delta);
+    assertEquals(rot[1][0], 0f, delta);
+    assertEquals(rot[1][1], 1f, delta);
+    assertEquals(rot[1][2], 0f, delta);
+    assertEquals(rot[2][0], sinTheta, delta);
+    assertEquals(rot[2][1], 0f, delta);
+    assertEquals(rot[2][2], cosTheta, delta);
+
+    /*
+     * 60 degrees about Z axis should be
+     *  cos -sin 0
+     *  sin  cos 0
+     *   0    0  1
+     * - and it is!
+     */
+    rot = RotatableMatrix.getRotation(theta, Axis.Z);
+    assertEquals(rot[0][0], cosTheta, delta);
+    assertEquals(rot[0][1], -sinTheta, delta);
+    assertEquals(rot[0][2], 0f, delta);
+    assertEquals(rot[1][0], sinTheta, delta);
+    assertEquals(rot[1][1], cosTheta, delta);
+    assertEquals(rot[1][2], 0f, delta);
+    assertEquals(rot[2][0], 0f, delta);
+    assertEquals(rot[2][1], 0f, delta);
+    assertEquals(rot[2][2], 1f, delta);
+  }
+}
index f0fc3fd..d902fa2 100644 (file)
@@ -27,6 +27,7 @@ import static org.testng.Assert.assertNull;
 import static org.testng.Assert.assertSame;
 import static org.testng.Assert.assertTrue;
 
+import jalview.analysis.scoremodels.SimilarityParams;
 import jalview.api.AlignViewportI;
 import jalview.api.AlignmentViewPanel;
 import jalview.api.FeatureColourI;
@@ -49,6 +50,7 @@ import jalview.gui.AlignmentPanel;
 import jalview.gui.Desktop;
 import jalview.gui.FeatureRenderer;
 import jalview.gui.JvOptionPane;
+import jalview.gui.PCAPanel;
 import jalview.gui.PopupMenu;
 import jalview.gui.SliderPanel;
 import jalview.io.DataSourceType;
@@ -77,6 +79,8 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import javax.swing.JInternalFrame;
+
 import org.testng.Assert;
 import org.testng.AssertJUnit;
 import org.testng.annotations.BeforeClass;
@@ -105,65 +109,73 @@ public class Jalview2xmlTests extends Jalview2xmlBase
     assertNotNull(af, "Didn't read input file " + inFile);
     int olddsann = countDsAnn(af.getViewport());
     assertTrue(olddsann > 0, "Didn't find any dataset annotations");
-    af.changeColour_actionPerformed(JalviewColourScheme.RNAHelices
-            .toString());
+    af.changeColour_actionPerformed(
+            JalviewColourScheme.RNAHelices.toString());
     assertTrue(
-            af.getViewport().getGlobalColourScheme() instanceof RNAHelicesColour,
+            af.getViewport()
+                    .getGlobalColourScheme() instanceof RNAHelicesColour,
             "Couldn't apply RNA helices colourscheme");
     assertTrue(af.saveAlignment(tfile, FileFormat.Jalview),
             "Failed to store as a project.");
     af.closeMenuItem_actionPerformed(true);
     af = null;
-    af = new FileLoader()
-            .LoadFileWaitTillLoaded(tfile, DataSourceType.FILE);
+    af = new FileLoader().LoadFileWaitTillLoaded(tfile,
+            DataSourceType.FILE);
     assertNotNull(af, "Failed to import new project");
     int newdsann = countDsAnn(af.getViewport());
     assertEquals(olddsann, newdsann,
             "Differing numbers of dataset sequence annotation\nOriginally "
                     + olddsann + " and now " + newdsann);
-    System.out
-            .println("Read in same number of annotations as originally present ("
+    System.out.println(
+            "Read in same number of annotations as originally present ("
                     + olddsann + ")");
     assertTrue(
 
-    af.getViewport().getGlobalColourScheme() instanceof RNAHelicesColour,
+            af.getViewport()
+                    .getGlobalColourScheme() instanceof RNAHelicesColour,
             "RNA helices colourscheme was not applied on import.");
   }
 
   @Test(groups = { "Functional" })
   public void testTCoffeeScores() throws Exception
   {
-    String inFile = "examples/uniref50.fa", inAnnot = "examples/uniref50.score_ascii";
+    String inFile = "examples/uniref50.fa",
+            inAnnot = "examples/uniref50.score_ascii";
     String tfile = File.createTempFile("JalviewTest", ".jvp")
             .getAbsolutePath();
     AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile,
             DataSourceType.FILE);
     assertNotNull(af, "Didn't read input file " + inFile);
     af.loadJalviewDataFile(inAnnot, DataSourceType.FILE, null, null);
-    assertSame(af.getViewport().getGlobalColourScheme().getClass(),
+    AlignViewport viewport = af.getViewport();
+    assertSame(viewport.getGlobalColourScheme().getClass(),
             TCoffeeColourScheme.class, "Didn't set T-coffee colourscheme");
-    assertNotNull(ColourSchemeProperty.getColourScheme(af.getViewport()
-            .getAlignment(), af.getViewport().getGlobalColourScheme()
-            .getSchemeName()), "Recognise T-Coffee score from string");
+    assertNotNull(
+            ColourSchemeProperty.getColourScheme(viewport,
+                    viewport.getAlignment(),
+                    viewport.getGlobalColourScheme()
+                            .getSchemeName()),
+            "Recognise T-Coffee score from string");
 
     assertTrue(af.saveAlignment(tfile, FileFormat.Jalview),
             "Failed to store as a project.");
     af.closeMenuItem_actionPerformed(true);
     af = null;
-    af = new FileLoader()
-            .LoadFileWaitTillLoaded(tfile, DataSourceType.FILE);
+    af = new FileLoader().LoadFileWaitTillLoaded(tfile,
+            DataSourceType.FILE);
     assertNotNull(af, "Failed to import new project");
     assertSame(af.getViewport().getGlobalColourScheme().getClass(),
             TCoffeeColourScheme.class,
             "Didn't set T-coffee colourscheme for imported project.");
-    System.out
-            .println("T-Coffee score shading successfully recovered from project.");
+    System.out.println(
+            "T-Coffee score shading successfully recovered from project.");
   }
 
   @Test(groups = { "Functional" })
   public void testColourByAnnotScores() throws Exception
   {
-    String inFile = "examples/uniref50.fa", inAnnot = "examples/testdata/uniref50_iupred.jva";
+    String inFile = "examples/uniref50.fa",
+            inAnnot = "examples/testdata/uniref50_iupred.jva";
     String tfile = File.createTempFile("JalviewTest", ".jvp")
             .getAbsolutePath();
     AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile,
@@ -174,12 +186,12 @@ public class Jalview2xmlTests extends Jalview2xmlBase
             .getSequenceAt(0).getAnnotation("IUPredWS (Short)");
     assertTrue(
 
-    aa != null && aa.length > 0,
+            aa != null && aa.length > 0,
             "Didn't find any IUPred annotation to use to shade alignment.");
     AnnotationColourGradient cs = new AnnotationColourGradient(aa[0], null,
             AnnotationColourGradient.ABOVE_THRESHOLD);
-    AnnotationColourGradient gcs = new AnnotationColourGradient(aa[0],
-            null, AnnotationColourGradient.BELOW_THRESHOLD);
+    AnnotationColourGradient gcs = new AnnotationColourGradient(aa[0], null,
+            AnnotationColourGradient.BELOW_THRESHOLD);
     cs.setSeqAssociated(true);
     gcs.setSeqAssociated(true);
     af.changeColour(cs);
@@ -195,15 +207,15 @@ public class Jalview2xmlTests extends Jalview2xmlBase
             "Failed to store as a project.");
     af.closeMenuItem_actionPerformed(true);
     af = null;
-    af = new FileLoader()
-            .LoadFileWaitTillLoaded(tfile, DataSourceType.FILE);
+    af = new FileLoader().LoadFileWaitTillLoaded(tfile,
+            DataSourceType.FILE);
     assertNotNull(af, "Failed to import new project");
 
     // check for group and alignment colourschemes
 
     ColourSchemeI _rcs = af.getViewport().getGlobalColourScheme();
-    ColourSchemeI _rgcs = af.getViewport().getAlignment().getGroups()
-            .get(0).getColourScheme();
+    ColourSchemeI _rgcs = af.getViewport().getAlignment().getGroups().get(0)
+            .getColourScheme();
     assertNotNull(_rcs, "Didn't recover global colourscheme");
     assertTrue(_rcs instanceof AnnotationColourGradient,
             "Didn't recover annotation colour global scheme");
@@ -213,8 +225,8 @@ public class Jalview2xmlTests extends Jalview2xmlBase
 
     boolean diffseqcols = false, diffgseqcols = false;
     SequenceI[] sqs = af.getViewport().getAlignment().getSequencesArray();
-    for (int p = 0, pSize = af.getViewport().getAlignment().getWidth(); p < pSize
-            && (!diffseqcols || !diffgseqcols); p++)
+    for (int p = 0, pSize = af.getViewport().getAlignment()
+            .getWidth(); p < pSize && (!diffseqcols || !diffgseqcols); p++)
     {
       if (_rcs.findColour(sqs[0].getCharAt(p), p, sqs[0], null, 0f) != _rcs
               .findColour(sqs[5].getCharAt(p), p, sqs[5], null, 0f))
@@ -223,8 +235,8 @@ public class Jalview2xmlTests extends Jalview2xmlBase
       }
     }
     assertTrue(diffseqcols, "Got Different sequence colours");
-    System.out
-            .println("Per sequence colourscheme (Background) successfully applied and recovered.");
+    System.out.println(
+            "Per sequence colourscheme (Background) successfully applied and recovered.");
 
     assertNotNull(_rgcs, "Didn't recover group colourscheme");
     assertTrue(_rgcs instanceof AnnotationColourGradient,
@@ -233,25 +245,26 @@ public class Jalview2xmlTests extends Jalview2xmlBase
     assertTrue(__rcs.isSeqAssociated(),
             "Group Annotation colourscheme wasn't sequence associated");
 
-    for (int p = 0, pSize = af.getViewport().getAlignment().getWidth(); p < pSize
-            && (!diffseqcols || !diffgseqcols); p++)
+    for (int p = 0, pSize = af.getViewport().getAlignment()
+            .getWidth(); p < pSize && (!diffseqcols || !diffgseqcols); p++)
     {
-      if (_rgcs.findColour(sqs[1].getCharAt(p), p, sqs[1], null, 0f) != _rgcs
-              .findColour(sqs[2].getCharAt(p), p, sqs[2], null, 0f))
+      if (_rgcs.findColour(sqs[1].getCharAt(p), p, sqs[1], null,
+              0f) != _rgcs.findColour(sqs[2].getCharAt(p), p, sqs[2], null,
+                      0f))
       {
         diffgseqcols = true;
       }
     }
     assertTrue(diffgseqcols, "Got Different group sequence colours");
-    System.out
-            .println("Per sequence (Group) colourscheme successfully applied and recovered.");
+    System.out.println(
+            "Per sequence (Group) colourscheme successfully applied and recovered.");
   }
 
   @Test(groups = { "Functional" })
   public void gatherViewsHere() throws Exception
   {
-    int origCount = Desktop.getAlignFrames() == null ? 0 : Desktop
-            .getAlignFrames().length;
+    int origCount = Desktop.getAlignFrames() == null ? 0
+            : Desktop.getAlignFrames().length;
     AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
             "examples/exampleFile_2_7.jar", DataSourceType.FILE);
     assertNotNull(af, "Didn't read in the example file correctly.");
@@ -332,14 +345,14 @@ public class Jalview2xmlTests extends Jalview2xmlBase
           sq.findPosition(p);
           try
           {
-            assertTrue(
-                    (alaa.annotations[p] == null && refan.annotations[p] == null)
-                            || alaa.annotations[p].value == refan.annotations[p].value,
+            assertTrue((alaa.annotations[p] == null
+                    && refan.annotations[p] == null)
+                    || alaa.annotations[p].value == refan.annotations[p].value,
                     "Mismatch at alignment position " + p);
           } catch (NullPointerException q)
           {
-            Assert.fail("Mismatch of alignment annotations at position "
-                    + p + " Ref seq ann: " + refan.annotations[p]
+            Assert.fail("Mismatch of alignment annotations at position " + p
+                    + " Ref seq ann: " + refan.annotations[p]
                     + " alignment " + alaa.annotations[p]);
           }
         }
@@ -374,10 +387,10 @@ public class Jalview2xmlTests extends Jalview2xmlBase
     AssertJUnit.assertFalse(structureStyle.sameStyle(groupStyle));
 
     groups.getAlignViewport().setViewStyle(structureStyle);
-    AssertJUnit.assertFalse(groupStyle.sameStyle(groups.getAlignViewport()
-            .getViewStyle()));
-    Assert.assertTrue(structureStyle.sameStyle(groups.getAlignViewport()
-            .getViewStyle()));
+    AssertJUnit.assertFalse(
+            groupStyle.sameStyle(groups.getAlignViewport().getViewStyle()));
+    Assert.assertTrue(structureStyle
+            .sameStyle(groups.getAlignViewport().getViewStyle()));
 
   }
 
@@ -398,9 +411,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase
 
     // check FileLoader returned a reference to the one alignFrame that is
     // actually on the Desktop
-    assertSame(
-            af,
-            Desktop.getAlignFrameFor(af.getViewport()),
+    assertSame(af, Desktop.getAlignFrameFor(af.getViewport()),
             "Jalview2XML.loadAlignFrame() didn't return correct AlignFrame reference for multiple view window");
 
     Desktop.explodeViews(af);
@@ -427,11 +438,12 @@ public class Jalview2xmlTests extends Jalview2xmlBase
     af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
             DataSourceType.FILE);
     Assert.assertNotNull(af);
+    Assert.assertEquals(Desktop.getAlignFrames().length,
+            Desktop.getAlignmentPanels(
+                    af.getViewport().getSequenceSetId()).length);
     Assert.assertEquals(
-            Desktop.getAlignFrames().length,
-            Desktop.getAlignmentPanels(af.getViewport().getSequenceSetId()).length);
-    Assert.assertEquals(
-            Desktop.getAlignmentPanels(af.getViewport().getSequenceSetId()).length,
+            Desktop.getAlignmentPanels(
+                    af.getViewport().getSequenceSetId()).length,
             oldviews);
   }
 
@@ -533,8 +545,8 @@ public class Jalview2xmlTests extends Jalview2xmlBase
     assertTrue(Jalview2XML.isVersionStringLaterThan(null, "Test"));
     assertTrue(Jalview2XML.isVersionStringLaterThan(null, "TEST"));
     assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "Test"));
-    assertTrue(Jalview2XML
-            .isVersionStringLaterThan(null, "Automated Build"));
+    assertTrue(
+            Jalview2XML.isVersionStringLaterThan(null, "Automated Build"));
     assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3",
             "Automated Build"));
     assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3",
@@ -643,8 +655,8 @@ public class Jalview2xmlTests extends Jalview2xmlBase
 
       n++;
     }
-    File tfile = File
-            .createTempFile("testStoreAndRecoverGroupReps", ".jvp");
+    File tfile = File.createTempFile("testStoreAndRecoverGroupReps",
+            ".jvp");
     try
     {
       new Jalview2XML(false).saveState(tfile);
@@ -683,9 +695,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase
        */
       List<String> hidden = hiddenSeqNames.get(ap.getViewName());
       HiddenSequences hs = alignment.getHiddenSequences();
-      assertEquals(
-              hidden.size(),
-              hs.getSize(),
+      assertEquals(hidden.size(), hs.getSize(),
               "wrong number of restored hidden sequences in "
                       + ap.getViewName());
     }
@@ -727,14 +737,18 @@ public class Jalview2xmlTests extends Jalview2xmlBase
     pdbEntries[1] = new PDBEntry("3W5V", "B", Type.PDB, testFile);
     pdbEntries[2] = new PDBEntry("3W5V", "C", Type.PDB, testFile);
     pdbEntries[3] = new PDBEntry("3W5V", "D", Type.PDB, testFile);
-    Assert.assertEquals(seqs[0].getDatasetSequence().getAllPDBEntries()
-            .get(0), pdbEntries[0]);
-    Assert.assertEquals(seqs[1].getDatasetSequence().getAllPDBEntries()
-            .get(0), pdbEntries[1]);
-    Assert.assertEquals(seqs[2].getDatasetSequence().getAllPDBEntries()
-            .get(0), pdbEntries[2]);
-    Assert.assertEquals(seqs[3].getDatasetSequence().getAllPDBEntries()
-            .get(0), pdbEntries[3]);
+    Assert.assertEquals(
+            seqs[0].getDatasetSequence().getAllPDBEntries().get(0),
+            pdbEntries[0]);
+    Assert.assertEquals(
+            seqs[1].getDatasetSequence().getAllPDBEntries().get(0),
+            pdbEntries[1]);
+    Assert.assertEquals(
+            seqs[2].getDatasetSequence().getAllPDBEntries().get(0),
+            pdbEntries[2]);
+    Assert.assertEquals(
+            seqs[3].getDatasetSequence().getAllPDBEntries().get(0),
+            pdbEntries[3]);
 
     File tfile = File.createTempFile("testStoreAndRecoverPDBEntry", ".jvp");
     try
@@ -805,6 +819,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase
     /*
      * Colour alignment by Buried Index, Above 10% PID, By Conservation 20%
      */
+    av.setColourAppliesToAllGroups(false);
     af.changeColour_actionPerformed(JalviewColourScheme.Buried.toString());
     assertTrue(av.getGlobalColourScheme() instanceof BuriedColourScheme);
     af.abovePIDThreshold_actionPerformed(true);
@@ -830,8 +845,8 @@ public class Jalview2xmlTests extends Jalview2xmlBase
     sg.setEndRes(25);
     av.setSelectionGroup(sg);
     PopupMenu popupMenu = new PopupMenu(af.alignPanel, null, null);
-    popupMenu.changeColour_actionPerformed(JalviewColourScheme.Strand
-            .toString());
+    popupMenu.changeColour_actionPerformed(
+            JalviewColourScheme.Strand.toString());
     assertTrue(sg.getColourScheme() instanceof StrandColourScheme);
     assertEquals(al.getGroups().size(), 1);
     assertSame(al.getGroups().get(0), sg);
@@ -917,8 +932,8 @@ public class Jalview2xmlTests extends Jalview2xmlBase
     fr.setColour("type2", byLabel);
 
     // type3: by score above threshold
-    FeatureColourI byScore = new FeatureColour(Color.BLACK, Color.BLUE, 1,
-            10);
+    FeatureColourI byScore = new FeatureColour(null, Color.BLACK,
+            Color.BLUE, null, 1, 10);
     byScore.setAboveThreshold(true);
     byScore.setThreshold(2f);
     fr.setColour("type3", byScore);
@@ -930,8 +945,8 @@ public class Jalview2xmlTests extends Jalview2xmlBase
     fr.setColour("type4", byAF);
 
     // type5: by attribute CSQ:PolyPhen below threshold
-    FeatureColourI byPolyPhen = new FeatureColour(Color.BLACK, Color.BLUE,
-            1, 10);
+    FeatureColourI byPolyPhen = new FeatureColour(null, Color.BLACK,
+            Color.BLUE, null, 1, 10);
     byPolyPhen.setBelowThreshold(true);
     byPolyPhen.setThreshold(3f);
     byPolyPhen.setAttributeName("CSQ", "PolyPhen");
@@ -974,8 +989,8 @@ public class Jalview2xmlTests extends Jalview2xmlBase
      */
     af.closeMenuItem_actionPerformed(true);
     af = null;
-    af = new FileLoader()
-            .LoadFileWaitTillLoaded(filePath, DataSourceType.FILE);
+    af = new FileLoader().LoadFileWaitTillLoaded(filePath,
+            DataSourceType.FILE);
     assertNotNull(af, "Failed to import new project");
 
     /*
@@ -1038,4 +1053,130 @@ public class Jalview2xmlTests extends Jalview2xmlBase
     addFeature(seq, featureType, score++);
     addFeature(seq, featureType, score);
   }
+
+  /**
+   * pre 2.11 - jalview 2.10 erroneously created new dataset entries for each
+   * view (JAL-3171) this test ensures we can import and merge those views
+   */
+  @Test(groups = { "Functional" })
+  public void testMergeDatasetsforViews() throws IOException
+  {
+    // simple project - two views on one alignment
+    AlignFrame af = new FileLoader(false).LoadFileWaitTillLoaded(
+            "examples/testdata/projects/twoViews.jvp", DataSourceType.FILE);
+    assertNotNull(af);
+    assertTrue(af.getAlignPanels().size() > 1);
+    verifyDs(af);
+  }
+
+  /**
+   * pre 2.11 - jalview 2.10 erroneously created new dataset entries for each
+   * view (JAL-3171) this test ensures we can import and merge those views This
+   * is a more complex project
+   */
+  @Test(groups = { "Functional" })
+  public void testMergeDatasetsforManyViews() throws IOException
+  {
+    Desktop.instance.closeAll_actionPerformed(null);
+
+    // complex project - one dataset, several views on several alignments
+    AlignFrame af = new FileLoader(false).LoadFileWaitTillLoaded(
+            "examples/testdata/projects/manyViews.jvp",
+            DataSourceType.FILE);
+    assertNotNull(af);
+
+    AlignmentI ds = null;
+    for (AlignFrame alignFrame : Desktop.getAlignFrames())
+    {
+      if (ds == null)
+      {
+        ds = verifyDs(alignFrame);
+      }
+      else
+      {
+        // check that this frame's dataset matches the last
+        assertTrue(ds == verifyDs(alignFrame));
+      }
+    }
+  }
+
+  private AlignmentI verifyDs(AlignFrame af)
+  {
+    AlignmentI ds = null;
+    for (AlignmentViewPanel ap : af.getAlignPanels())
+    {
+      if (ds == null)
+      {
+        ds = ap.getAlignment().getDataset();
+      }
+      else
+      {
+        assertTrue(ap.getAlignment().getDataset() == ds,
+                "Dataset was not the same for imported 2.10.5 project with several alignment views");
+      }
+    }
+    return ds;
+  }
+
+  @Test(groups = "Functional")
+  public void testPcaViewAssociation() throws IOException
+  {
+    Desktop.instance.closeAll_actionPerformed(null);
+    final String PCAVIEWNAME = "With PCA";
+    // create a new tempfile
+    File tempfile = File.createTempFile("jvPCAviewAssoc", "jvp");
+
+    {
+      String exampleFile = "examples/uniref50.fa";
+      AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(exampleFile,
+              DataSourceType.FILE);
+      assertNotNull(af, "Didn't read in the example file correctly.");
+      AlignmentPanel origView = (AlignmentPanel) af.getAlignPanels().get(0);
+      AlignmentPanel newview = af.newView(PCAVIEWNAME, true);
+      // create another for good measure
+      af.newView("Not the PCA View", true);
+      PCAPanel pcaPanel = new PCAPanel(origView, "BLOSUM62",
+              new SimilarityParams(true, true, true, false));
+      // we're in the test exec thread, so we can just run synchronously here
+      pcaPanel.run();
+
+      // now switch the linked view
+      pcaPanel.selectAssociatedView(newview);
+
+      assertTrue(pcaPanel.getAlignViewport() == newview.getAlignViewport(),
+              "PCA should be associated with 'With PCA' view: test is broken");
+
+      // now save and reload project
+      Jalview2XML jv2xml = new jalview.project.Jalview2XML(false);
+      tempfile.delete();
+      jv2xml.saveState(tempfile);
+      assertTrue(jv2xml.errorMessage == null,
+              "Failed to save dummy project with PCA: test broken");
+    }
+
+    // load again.
+    Desktop.instance.closeAll_actionPerformed(null);
+    AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
+            tempfile.getCanonicalPath(), DataSourceType.FILE);
+    JInternalFrame[] frames = Desktop.instance.getAllFrames();
+    // PCA and the tabbed alignment view should be the only two windows on the
+    // desktop
+    assertEquals(frames.length, 2,
+            "PCA and the tabbed alignment view should be the only two windows on the desktop");
+    PCAPanel pcaPanel = (PCAPanel) frames[frames[0] == af ? 1 : 0];
+
+    AlignmentViewPanel restoredNewView = null;
+    for (AlignmentViewPanel alignpanel : Desktop.getAlignmentPanels(null))
+    {
+      if (alignpanel.getAlignViewport() == pcaPanel.getAlignViewport())
+      {
+        restoredNewView = alignpanel;
+      }
+    }
+    assertEquals(restoredNewView.getViewName(), PCAVIEWNAME);
+    assertTrue(
+            restoredNewView.getAlignViewport() == pcaPanel
+                    .getAlignViewport(),
+            "Didn't restore correct view association for the PCA view");
+  }
 }
index d8b905e..af7c2ed 100644 (file)
@@ -323,7 +323,7 @@ public class FeatureColourFinderTest
      */
     Color min = new Color(100, 50, 150);
     Color max = new Color(200, 0, 100);
-    FeatureColourI fc = new FeatureColour(min, max, 0, 10);
+    FeatureColourI fc = new FeatureColour(null, min, max, null, 0, 10);
     fr.setColour("kd", fc);
     fr.featuresAdded();
     av.setShowSequenceFeatures(true);
@@ -493,7 +493,7 @@ public class FeatureColourFinderTest
      */
     Color min = new Color(100, 50, 150);
     Color max = new Color(200, 0, 100);
-    FeatureColourI fc = new FeatureColour(min, max, 0, 10);
+    FeatureColourI fc = new FeatureColour(null, min, max, null, 0, 10);
     fc.setAboveThreshold(true);
     fc.setThreshold(5f);
     fr.setColour(kdFeature, fc);
index 11b129e..723f3b8 100644 (file)
@@ -285,8 +285,8 @@ public class FeatureRendererTest
      * give "Type3" features a graduated colour scheme
      * - first with no threshold
      */
-    FeatureColourI gc = new FeatureColour(Color.yellow, Color.red, null, 0f,
-            10f);
+    FeatureColourI gc = new FeatureColour(Color.green, Color.yellow,
+            Color.red, null, 0f, 10f);
     fr.getFeatureColours().put("Type3", gc);
     features = fr.findFeaturesAtColumn(seq, 8);
     assertTrue(features.contains(sf4));
@@ -328,18 +328,18 @@ public class FeatureRendererTest
     SequenceI seq = av.getAlignment().getSequenceAt(0);
     SequenceFeature sf1 = new SequenceFeature("Cath", "", 6, 8, Float.NaN,
             "group1");
-    seq.addSequenceFeature(sf1);
     SequenceFeature sf2 = new SequenceFeature("Cath", "", 5, 11, 2f,
             "group2");
-    seq.addSequenceFeature(sf2);
     SequenceFeature sf3 = new SequenceFeature("Cath", "", 5, 11, 3f,
             "group3");
-    seq.addSequenceFeature(sf3);
     SequenceFeature sf4 = new SequenceFeature("Cath", "", 6, 8, 4f,
             "group4");
-    seq.addSequenceFeature(sf4);
     SequenceFeature sf5 = new SequenceFeature("Cath", "", 6, 9, 5f,
             "group4");
+    seq.addSequenceFeature(sf1);
+    seq.addSequenceFeature(sf2);
+    seq.addSequenceFeature(sf3);
+    seq.addSequenceFeature(sf4);
     seq.addSequenceFeature(sf5);
 
     fr.findAllFeatures(true);
@@ -365,17 +365,17 @@ public class FeatureRendererTest
     assertTrue(features.contains(sf5));
 
     /*
-     * hide groups 2 and 3 makes no difference to this method
+     * features in hidden groups are removed
      */
     fr.setGroupVisibility("group2", false);
     fr.setGroupVisibility("group3", false);
     features = seq.getSequenceFeatures();
     fr.filterFeaturesForDisplay(features);
-    assertEquals(features.size(), 3);
+    assertEquals(features.size(), 2);
     assertTrue(features.contains(sf1) || features.contains(sf4));
     assertFalse(features.contains(sf1) && features.contains(sf4));
-    assertTrue(features.contains(sf2) || features.contains(sf3));
-    assertFalse(features.contains(sf2) && features.contains(sf3));
+    assertFalse(features.contains(sf2));
+    assertFalse(features.contains(sf3));
     assertTrue(features.contains(sf5));
 
     /*
@@ -428,8 +428,8 @@ public class FeatureRendererTest
      * graduated colour by score, no threshold, no score
      * 
      */
-    FeatureColourI gc = new FeatureColour(Color.yellow, Color.red,
-            Color.green, 1f, 11f);
+    FeatureColourI gc = new FeatureColour(Color.red, Color.yellow,
+            Color.red, Color.green, 1f, 11f);
     fr.getFeatureColours().put("Cath", gc);
     assertEquals(fr.getColour(sf1), Color.green);
 
@@ -453,7 +453,8 @@ public class FeatureRendererTest
      * threshold is min-max; now score 6 is 1/6 of the way from 5 to 11
      * or from yellow(255, 255, 0) to red(255, 0, 0)
      */
-    gc = new FeatureColour(Color.yellow, Color.red, Color.green, 5f, 11f);
+    gc = new FeatureColour(Color.red, Color.yellow, Color.red, Color.green,
+            5f, 11f);
     fr.getFeatureColours().put("Cath", gc);
     gc.setAutoScaled(false); // this does little other than save a checkbox setting!
     assertEquals(fr.getColour(sf2), new Color(255, 213, 0));
@@ -476,7 +477,8 @@ public class FeatureRendererTest
      * colour by feature attribute value
      * first with no value held
      */
-    gc = new FeatureColour(Color.yellow, Color.red, Color.green, 1f, 11f);
+    gc = new FeatureColour(Color.red, Color.yellow, Color.red, Color.green,
+            1f, 11f);
     fr.getFeatureColours().put("Cath", gc);
     gc.setAttributeName("AF");
     assertEquals(fr.getColour(sf2), Color.green);
@@ -535,4 +537,71 @@ public class FeatureRendererTest
     csqData.put("Feature", "ENST01234");
     assertEquals(fr.getColour(sf2), expected);
   }
+
+  @Test(groups = "Functional")
+  public void testIsVisible()
+  {
+    String seqData = ">s1\nMLQGIFPRS\n";
+    AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(seqData,
+            DataSourceType.PASTE);
+    AlignViewportI av = af.getViewport();
+    FeatureRenderer fr = new FeatureRenderer(av);
+    SequenceI seq = av.getAlignment().getSequenceAt(0);
+    SequenceFeature sf = new SequenceFeature("METAL", "Desc", 10, 10, 1f,
+            "Group");
+    sf.setValue("AC", "11");
+    sf.setValue("CLIN_SIG", "Likely Pathogenic");
+    seq.addSequenceFeature(sf);
+
+    assertFalse(fr.isVisible(null));
+
+    /*
+     * initial state FeatureRenderer hasn't 'found' feature
+     * and so its feature type has not yet been set visible
+     */
+    assertFalse(fr.getDisplayedFeatureCols().containsKey("METAL"));
+    assertFalse(fr.isVisible(sf));
+
+    fr.findAllFeatures(true);
+    assertTrue(fr.isVisible(sf));
+
+    /*
+     * feature group not visible
+     */
+    fr.setGroupVisibility("Group", false);
+    assertFalse(fr.isVisible(sf));
+    fr.setGroupVisibility("Group", true);
+    assertTrue(fr.isVisible(sf));
+
+    /*
+     * feature score outwith colour threshold (score > 2)
+     */
+    FeatureColourI fc = new FeatureColour(null, Color.white, Color.black,
+            Color.white, 0, 10);
+    fc.setAboveThreshold(true);
+    fc.setThreshold(2f);
+    fr.setColour("METAL", fc);
+    assertFalse(fr.isVisible(sf)); // score 1 is not above threshold 2
+    fc.setBelowThreshold(true);
+    assertTrue(fr.isVisible(sf)); // score 1 is below threshold 2
+
+    /*
+     * colour with threshold on attribute AC (value is 11)
+     */
+    fc.setAttributeName("AC");
+    assertFalse(fr.isVisible(sf)); // value 11 is not below threshold 2
+    fc.setAboveThreshold(true);
+    assertTrue(fr.isVisible(sf)); // value 11 is above threshold 2
+
+    fc.setAttributeName("AF"); // attribute AF is absent in sf
+    assertTrue(fr.isVisible(sf)); // feature is not excluded by threshold
+
+    FeatureMatcherSetI filter = new FeatureMatcherSet();
+    filter.and(FeatureMatcher.byAttribute(Condition.Contains, "pathogenic",
+            "CLIN_SIG"));
+    fr.setFeatureFilter("METAL", filter);
+    assertTrue(fr.isVisible(sf)); // feature matches filter
+    filter.and(FeatureMatcher.byScore(Condition.LE, "0.4"));
+    assertFalse(fr.isVisible(sf)); // feature doesn't match filter
+  }
 }
index b7a5164..c56da59 100644 (file)
@@ -124,6 +124,18 @@ public class AnnotationColourGradientTest
       Color result = testee.shadeCalculation(ann, col);
       assertEquals(result, expected, "for column " + col);
     }
+
+    /*
+     * test for boundary case threshold == graphMax (JAL-3206)
+     */
+    float thresh = ann.threshold.value;
+    ann.threshold.value = ann.graphMax;
+    Color result = testee.shadeCalculation(ann, WIDTH - 1);
+    assertEquals(result, maxColour);
+    testee.setThresholdIsMinMax(false);
+    result = testee.shadeCalculation(ann, WIDTH - 1);
+    assertEquals(result, maxColour);
+    ann.threshold.value = thresh; // reset
   }
 
   /**
@@ -174,6 +186,18 @@ public class AnnotationColourGradientTest
       Color result = testee.shadeCalculation(ann, col);
       assertEquals(result, expected, "for column " + col);
     }
+
+    /*
+     * test for boundary case threshold == graphMin (JAL-3206)
+     */
+    float thresh = ann.threshold.value;
+    ann.threshold.value = ann.graphMin;
+    Color result = testee.shadeCalculation(ann, 0);
+    assertEquals(result, minColour);
+    testee.setThresholdIsMinMax(false);
+    result = testee.shadeCalculation(ann, 0);
+    assertEquals(result, minColour);
+    ann.threshold.value = thresh; // reset
   }
 
   /**
@@ -184,15 +208,16 @@ public class AnnotationColourGradientTest
   {
     AnnotationColourGradient testee = new AnnotationColourGradient(ann,
             minColour, maxColour, AnnotationColourGradient.ABOVE_THRESHOLD);
-    testee = (AnnotationColourGradient) testee.getInstance(al, null);
+    testee = (AnnotationColourGradient) testee.getInstance(null, al);
 
     for (int col = 0; col < WIDTH; col++)
     {
       Color result = testee.findColour('a', col, seq);
       /*
-       * expect white below threshold of 5
+       * expect white at or below threshold of 5
        */
-      Color expected = col < 5 ? Color.white : new Color(50 + 10 * col,
+      Color expected = col <= 5 ? Color.white
+              : new Color(50 + 10 * col,
               200 - 10 * col,
               150 + 10 * col);
       assertEquals(result, expected, "for column " + col);
@@ -206,11 +231,12 @@ public class AnnotationColourGradientTest
     for (int col = 0; col < WIDTH; col++)
     {
       /*
-       * colours for values >= threshold are graduated
+       * colours for values > threshold are graduated
        * range is 6-10 so steps of 100/5 = 20
        */
       int factor = col - THRESHOLD_FIVE;
-      Color expected = col < 5 ? Color.white : new Color(50 + 20 * factor,
+      Color expected = col <= 5 ? Color.white
+              : new Color(50 + 20 * factor,
               200 - 20 * factor,
               150 + 20 * factor);
       Color result = testee.findColour('a', col, seq);
@@ -226,12 +252,13 @@ public class AnnotationColourGradientTest
   {
     AnnotationColourGradient testee = new AnnotationColourGradient(ann,
             minColour, maxColour, AnnotationColourGradient.BELOW_THRESHOLD);
-    testee = (AnnotationColourGradient) testee.getInstance(al, null);
+    testee = (AnnotationColourGradient) testee.getInstance(null, al);
   
     for (int col = 0; col < WIDTH; col++)
     {
       Color result = testee.findColour('a', col, seq);
-      Color expected = col > 5 ? Color.white : new Color(50 + 10 * col,
+      Color expected = col >= 5 ? Color.white
+              : new Color(50 + 10 * col,
               200 - 10 * col, 150 + 10 * col);
       assertEquals(result, expected, "for column " + col);
     }
@@ -244,10 +271,11 @@ public class AnnotationColourGradientTest
     for (int col = 0; col < WIDTH; col++)
     {
       /*
-       * colours for values <= threshold are graduated
+       * colours for values < threshold are graduated
        * range is 0-5 so steps of 100/5 = 20
        */
-      Color expected = col > 5 ? Color.white : new Color(50 + 20 * col,
+      Color expected = col >= 5 ? Color.white
+              : new Color(50 + 20 * col,
               200 - 20 * col, 150 + 20 * col);
       Color result = testee.findColour('a', col, seq);
       assertEquals(result, expected, "for column " + col);
@@ -259,7 +287,7 @@ public class AnnotationColourGradientTest
   {
     AnnotationColourGradient testee = new AnnotationColourGradient(ann,
             minColour, maxColour, AnnotationColourGradient.NO_THRESHOLD);
-    testee = (AnnotationColourGradient) testee.getInstance(al, null);
+    testee = (AnnotationColourGradient) testee.getInstance(null, al);
 
     for (int col = 0; col < WIDTH; col++)
     {
@@ -278,7 +306,7 @@ public class AnnotationColourGradientTest
   {
     AnnotationColourGradient testee = new AnnotationColourGradient(ann,
             minColour, maxColour, AnnotationColourGradient.NO_THRESHOLD);
-    testee = (AnnotationColourGradient) testee.getInstance(al, null);
+    testee = (AnnotationColourGradient) testee.getInstance(null, al);
 
     /*
      * flag corresponding to 'use original colours' checkbox
index 11562b8..f71d647 100644 (file)
@@ -76,51 +76,54 @@ public class ColourSchemePropertyTest
     SequenceI seq = new Sequence("Seq1", "abcd");
     AlignmentI al = new Alignment(new SequenceI[] { seq });
     // the strings here correspond to JalviewColourScheme.toString() values
-    ColourSchemeI cs = ColourSchemeProperty.getColourScheme(al, "Clustal");
+    ColourSchemeI cs = ColourSchemeProperty.getColourScheme(null, al,
+            "Clustal");
     assertTrue(cs instanceof ClustalxColourScheme);
     // not case-sensitive
-    cs = ColourSchemeProperty.getColourScheme(al, "CLUSTAL");
+    cs = ColourSchemeProperty.getColourScheme(null, al, "CLUSTAL");
     assertTrue(cs instanceof ClustalxColourScheme);
-    cs = ColourSchemeProperty.getColourScheme(al, "clustal");
+    cs = ColourSchemeProperty.getColourScheme(null, al, "clustal");
     assertTrue(cs instanceof ClustalxColourScheme);
-    cs = ColourSchemeProperty.getColourScheme(al, "Blosum62");
+    cs = ColourSchemeProperty.getColourScheme(null, al, "Blosum62");
     assertTrue(cs instanceof Blosum62ColourScheme);
-    cs = ColourSchemeProperty.getColourScheme(al, "% Identity");
+    cs = ColourSchemeProperty.getColourScheme(null, al, "% Identity");
     assertTrue(cs instanceof PIDColourScheme);
-    cs = ColourSchemeProperty.getColourScheme(al, "Zappo");
+    cs = ColourSchemeProperty.getColourScheme(null, al, "Zappo");
     assertTrue(cs instanceof ZappoColourScheme);
-    cs = ColourSchemeProperty.getColourScheme(al, "Taylor");
+    cs = ColourSchemeProperty.getColourScheme(null, al, "Taylor");
     assertTrue(cs instanceof TaylorColourScheme);
-    cs = ColourSchemeProperty.getColourScheme(al, "Hydrophobic");
+    cs = ColourSchemeProperty.getColourScheme(null, al, "Hydrophobic");
     assertTrue(cs instanceof HydrophobicColourScheme);
-    cs = ColourSchemeProperty.getColourScheme(al, "Helix Propensity");
+    cs = ColourSchemeProperty.getColourScheme(null, al, "Helix Propensity");
     assertTrue(cs instanceof HelixColourScheme);
-    cs = ColourSchemeProperty.getColourScheme(al, "Strand Propensity");
+    cs = ColourSchemeProperty.getColourScheme(null, al,
+            "Strand Propensity");
     assertTrue(cs instanceof StrandColourScheme);
-    cs = ColourSchemeProperty.getColourScheme(al, "Turn Propensity");
+    cs = ColourSchemeProperty.getColourScheme(null, al, "Turn Propensity");
     assertTrue(cs instanceof TurnColourScheme);
-    cs = ColourSchemeProperty.getColourScheme(al, "Buried Index");
+    cs = ColourSchemeProperty.getColourScheme(null, al, "Buried Index");
     assertTrue(cs instanceof BuriedColourScheme);
-    cs = ColourSchemeProperty.getColourScheme(al, "Nucleotide");
+    cs = ColourSchemeProperty.getColourScheme(null, al, "Nucleotide");
     assertTrue(cs instanceof NucleotideColourScheme);
-    cs = ColourSchemeProperty.getColourScheme(al, "Purine/Pyrimidine");
+    cs = ColourSchemeProperty.getColourScheme(null, al,
+            "Purine/Pyrimidine");
     assertTrue(cs instanceof PurinePyrimidineColourScheme);
-    cs = ColourSchemeProperty.getColourScheme(al, "T-Coffee Scores");
+    cs = ColourSchemeProperty.getColourScheme(null, al, "T-Coffee Scores");
     assertTrue(cs instanceof TCoffeeColourScheme);
-    cs = ColourSchemeProperty.getColourScheme(al, "RNA Helices");
+    cs = ColourSchemeProperty.getColourScheme(null, al, "RNA Helices");
     assertTrue(cs instanceof RNAHelicesColour);
     // 'None' is a special value
-    assertNull(ColourSchemeProperty.getColourScheme(al, "None"));
-    assertNull(ColourSchemeProperty.getColourScheme(al, "none"));
+    assertNull(ColourSchemeProperty.getColourScheme(null, al, "None"));
+    assertNull(ColourSchemeProperty.getColourScheme(null, al, "none"));
     // default is to convert the name into a fixed colour
-    cs = ColourSchemeProperty.getColourScheme(al, "elephants");
+    cs = ColourSchemeProperty.getColourScheme(null, al, "elephants");
     assertTrue(cs instanceof UserColourScheme);
 
     /*
      * explicit aa colours
      */
     UserColourScheme ucs = (UserColourScheme) ColourSchemeProperty
-            .getColourScheme(al,
+            .getColourScheme(null, al,
             "R,G=red;C=blue;c=green;Q=10,20,30;S,T=11ffdd");
     assertEquals(ucs.findColour('H'), Color.white);
     assertEquals(ucs.findColour('R'), Color.red);
index 0aaa38c..5db3743 100644 (file)
@@ -5,6 +5,7 @@ import static org.testng.Assert.assertFalse;
 import static org.testng.Assert.assertSame;
 import static org.testng.Assert.assertTrue;
 
+import jalview.api.AlignViewportI;
 import jalview.bin.Cache;
 import jalview.bin.Jalview;
 import jalview.datamodel.AnnotatedCollectionI;
@@ -54,8 +55,8 @@ public class ColourSchemesTest
     }
 
     @Override
-    public ColourSchemeI getInstance(AnnotatedCollectionI sg,
-            Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
+    public ColourSchemeI getInstance(AlignViewportI view,
+            AnnotatedCollectionI sg)
     {
       final ColourSchemeI cs1 = ColourSchemes.getInstance()
               .getColourScheme(JalviewColourScheme.Taylor.toString(),
@@ -144,10 +145,10 @@ public class ColourSchemesTest
     }
 
     @Override
-    public ColourSchemeI getInstance(AnnotatedCollectionI sg,
-            Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
+    public ColourSchemeI getInstance(AlignViewportI view,
+            AnnotatedCollectionI sg)
     {
-      return new MyClustal(sg,              hiddenRepSequences);
+      return new MyClustal(sg, view.getHiddenRepSequences());
     }
 
     @Override
diff --git a/test/jalview/schemes/DnaCodonTests.java b/test/jalview/schemes/DnaCodonTests.java
deleted file mode 100644 (file)
index 908d07b..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * 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 <http://www.gnu.org/licenses/>.
- * The Jalview Authors are detailed in the 'AUTHORS' file.
- */
-package jalview.schemes;
-
-import static org.testng.AssertJUnit.assertTrue;
-
-import jalview.gui.JvOptionPane;
-
-import java.util.Map;
-
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-
-public class DnaCodonTests
-{
-
-  @BeforeClass(alwaysRun = true)
-  public void setUpJvOptionPane()
-  {
-    JvOptionPane.setInteractiveMode(false);
-    JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
-  }
-
-  @Test(groups = { "Functional" })
-  public void testAmbiguityCodeGeneration()
-  {
-    assertTrue(ResidueProperties.ambiguityCodes.size() > 0);
-  }
-
-  @Test(groups = { "Functional" })
-  public void testAmbiguityCodon()
-  {
-    for (String ac : ResidueProperties.ambiguityCodes.keySet())
-    {
-      assertTrue("Couldn't resolve GGN as glycine codon",
-              ResidueProperties.codonHash2.get("GG" + ac).equals("G"));
-    }
-  }
-
-  @Test(groups = { "Functional" })
-  public void regenerateCodonTable()
-  {
-    for (Map.Entry<String, String> codon : ResidueProperties.codonHash2
-            .entrySet())
-    {
-      System.out.println("ResidueProperties.codonHash2.set(\""
-              + codon.getKey() + "\", \"" + codon.getValue() + "\");");
-    }
-  }
-}
index a96caec..52ca360 100644 (file)
@@ -38,8 +38,6 @@ import java.awt.Color;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
-import junit.extensions.PA;
-
 public class FeatureColourTest
 {
 
@@ -51,6 +49,30 @@ public class FeatureColourTest
   }
 
   @Test(groups = { "Functional" })
+  public void testConstructors()
+  {
+    FeatureColourI fc = new FeatureColour();
+    assertNull(fc.getColour());
+    assertTrue(fc.isSimpleColour());
+    assertFalse(fc.isColourByLabel());
+    assertFalse(fc.isGraduatedColour());
+    assertFalse(fc.isColourByAttribute());
+    assertEquals(Color.white, fc.getMinColour());
+    assertEquals(Color.black, fc.getMaxColour());
+
+    fc = new FeatureColour(Color.RED);
+    assertEquals(Color.red, fc.getColour());
+    assertTrue(fc.isSimpleColour());
+    assertFalse(fc.isColourByLabel());
+    assertFalse(fc.isGraduatedColour());
+    assertFalse(fc.isColourByAttribute());
+    assertEquals(ColorUtils.bleachColour(Color.RED, 0.9f),
+            fc.getMinColour());
+    assertEquals(Color.RED, fc.getMaxColour());
+
+  }
+
+  @Test(groups = { "Functional" })
   public void testCopyConstructor()
   {
     /*
@@ -67,7 +89,8 @@ public class FeatureColourTest
     /*
      * min-max colour
      */
-    fc = new FeatureColour(Color.gray, Color.black, 10f, 20f);
+    fc = new FeatureColour(null, Color.gray, Color.black, Color.gray, 10f,
+            20f);
     fc.setAboveThreshold(true);
     fc.setThreshold(12f);
     fc1 = new FeatureColour(fc);
@@ -86,12 +109,14 @@ public class FeatureColourTest
     /*
      * min-max-noValue colour
      */
-    fc = new FeatureColour(Color.gray, Color.black, Color.green, 10f, 20f);
+    fc = new FeatureColour(Color.red, Color.gray, Color.black, Color.green,
+            10f, 20f);
     fc.setAboveThreshold(true);
     fc.setThreshold(12f);
     fc1 = new FeatureColour(fc);
     assertTrue(fc1.isGraduatedColour());
     assertFalse(fc1.isColourByLabel());
+    assertFalse(fc1.isSimpleColour());
     assertFalse(fc1.isColourByAttribute());
     assertNull(fc1.getAttributeName());
     assertTrue(fc1.isAboveThreshold());
@@ -99,6 +124,7 @@ public class FeatureColourTest
     assertEquals(Color.gray, fc1.getMinColour());
     assertEquals(Color.black, fc1.getMaxColour());
     assertEquals(Color.green, fc1.getNoColour());
+    assertEquals(Color.red, fc1.getColour());
     assertEquals(10f, fc1.getMin());
     assertEquals(20f, fc1.getMax());
 
@@ -128,7 +154,8 @@ public class FeatureColourTest
     /*
      * colour by attribute (value)
      */
-    fc = new FeatureColour(Color.gray, Color.black, Color.green, 10f, 20f);
+    fc = new FeatureColour(Color.yellow, Color.gray, Color.black,
+            Color.green, 10f, 20f);
     fc.setAboveThreshold(true);
     fc.setThreshold(12f);
     fc.setAttributeName("AF");
@@ -136,104 +163,19 @@ public class FeatureColourTest
     assertTrue(fc1.isGraduatedColour());
     assertFalse(fc1.isColourByLabel());
     assertTrue(fc1.isColourByAttribute());
+    assertFalse(fc1.isSimpleColour());
     assertArrayEquals(new String[] { "AF" }, fc1.getAttributeName());
     assertTrue(fc1.isAboveThreshold());
     assertEquals(12f, fc1.getThreshold());
     assertEquals(Color.gray, fc1.getMinColour());
     assertEquals(Color.black, fc1.getMaxColour());
     assertEquals(Color.green, fc1.getNoColour());
+    assertEquals(Color.yellow, fc1.getColour());
     assertEquals(10f, fc1.getMin());
     assertEquals(20f, fc1.getMax());
   }
 
   @Test(groups = { "Functional" })
-  public void testCopyConstructor_minMax()
-  {
-    /*
-     * graduated colour
-     */
-    FeatureColour fc = new FeatureColour(Color.BLUE, Color.RED, 1f, 5f);
-    assertTrue(fc.isGraduatedColour());
-    assertFalse(fc.isColourByLabel());
-    assertFalse(fc.isColourByAttribute());
-    assertNull(fc.getAttributeName());
-    assertEquals(1f, fc.getMin());
-    assertEquals(5f, fc.getMax());
-
-    /*
-     * update min-max bounds
-     */
-    FeatureColour fc1 = new FeatureColour(fc, 2f, 6f);
-    assertTrue(fc1.isGraduatedColour());
-    assertFalse(fc1.isColourByLabel());
-    assertFalse(fc1.isColourByAttribute());
-    assertNull(fc1.getAttributeName());
-    assertEquals(2f, fc1.getMin());
-    assertEquals(6f, fc1.getMax());
-    assertFalse((boolean) PA.getValue(fc1, "isHighToLow"));
-
-    /*
-     * update min-max bounds - high to low
-     */
-    fc1 = new FeatureColour(fc, 23f, 16f);
-    assertTrue(fc1.isGraduatedColour());
-    assertFalse(fc1.isColourByLabel());
-    assertFalse(fc1.isColourByAttribute());
-    assertNull(fc1.getAttributeName());
-    assertEquals(23f, fc1.getMin());
-    assertEquals(16f, fc1.getMax());
-    assertTrue((boolean) PA.getValue(fc1, "isHighToLow"));
-
-    /*
-     * graduated colour by attribute
-     */
-    fc1.setAttributeName("AF");
-    fc1 = new FeatureColour(fc1, 13f, 36f);
-    assertTrue(fc1.isGraduatedColour());
-    assertFalse(fc1.isColourByLabel());
-    assertTrue(fc1.isColourByAttribute());
-    assertArrayEquals(new String[] { "AF" }, fc1.getAttributeName());
-    assertEquals(13f, fc1.getMin());
-    assertEquals(36f, fc1.getMax());
-    assertFalse((boolean) PA.getValue(fc1, "isHighToLow"));
-
-    /*
-     * colour by label
-     */
-    fc = new FeatureColour(Color.BLUE, Color.RED, 1f, 5f);
-    fc.setColourByLabel(true);
-    assertFalse(fc.isGraduatedColour());
-    assertTrue(fc.isColourByLabel());
-    assertFalse(fc.isColourByAttribute());
-    assertNull(fc.getAttributeName());
-    assertEquals(1f, fc.getMin());
-    assertEquals(5f, fc.getMax());
-
-    /*
-     * update min-max bounds
-     */
-    fc1 = new FeatureColour(fc, 2f, 6f);
-    assertFalse(fc1.isGraduatedColour());
-    assertTrue(fc1.isColourByLabel());
-    assertFalse(fc1.isColourByAttribute());
-    assertNull(fc1.getAttributeName());
-    assertEquals(2f, fc1.getMin());
-    assertEquals(6f, fc1.getMax());
-
-    /*
-     * colour by attribute text
-     */
-    fc1.setAttributeName("AC");
-    fc1 = new FeatureColour(fc1, 13f, 36f);
-    assertFalse(fc1.isGraduatedColour());
-    assertTrue(fc1.isColourByLabel());
-    assertTrue(fc1.isColourByAttribute());
-    assertArrayEquals(new String[] { "AC" }, fc1.getAttributeName());
-    assertEquals(13f, fc1.getMin());
-    assertEquals(36f, fc1.getMax());
-  }
-
-  @Test(groups = { "Functional" })
   public void testGetColor_simpleColour()
   {
     FeatureColour fc = new FeatureColour(Color.RED);
@@ -260,7 +202,8 @@ public class FeatureColourTest
      * score 0 to 100
      * gray(128, 128, 128) to red(255, 0, 0)
      */
-    FeatureColour fc = new FeatureColour(Color.GRAY, Color.RED, 0f, 100f);
+    FeatureColour fc = new FeatureColour(null, Color.GRAY, Color.RED, null,
+            0f, 100f);
     // feature score is 75 which is 3/4 of the way from GRAY to RED
     SequenceFeature sf = new SequenceFeature("type", "desc", 0, 20, 75f,
             null);
@@ -276,8 +219,8 @@ public class FeatureColourTest
   public void testGetColor_aboveBelowThreshold()
   {
     // gradient from [50, 150] from WHITE(255, 255, 255) to BLACK(0, 0, 0)
-    FeatureColour fc = new FeatureColour(Color.WHITE, Color.BLACK, 50f,
-            150f);
+    FeatureColour fc = new FeatureColour(null, Color.WHITE, Color.BLACK,
+            Color.white, 50f, 150f);
     SequenceFeature sf = new SequenceFeature("type", "desc", 0, 20, 70f,
             null);
 
@@ -371,7 +314,8 @@ public class FeatureColourTest
      * graduated colour by score, no threshold
      * - default constructor sets noValueColor = minColor
      */
-    fc = new FeatureColour(Color.GREEN, Color.RED, 12f, 25f);
+    fc = new FeatureColour(null, Color.GREEN, Color.RED, Color.GREEN, 12f,
+            25f);
     String greenHex = Format.getHexString(Color.GREEN);
     String expected = String.format(
             "domain\tscore|%s|%s|noValueMin|abso|12.0|25.0|none", greenHex,
@@ -381,7 +325,8 @@ public class FeatureColourTest
     /*
      * graduated colour by score, no threshold, no value gets min colour
      */
-    fc = new FeatureColour(Color.GREEN, Color.RED, Color.GREEN, 12f, 25f);
+    fc = new FeatureColour(Color.RED, Color.GREEN, Color.RED, Color.GREEN,
+            12f, 25f);
     expected = String.format(
             "domain\tscore|%s|%s|noValueMin|abso|12.0|25.0|none", greenHex,
             redHex);
@@ -390,7 +335,8 @@ public class FeatureColourTest
     /*
      * graduated colour by score, no threshold, no value gets max colour
      */
-    fc = new FeatureColour(Color.GREEN, Color.RED, Color.RED, 12f, 25f);
+    fc = new FeatureColour(Color.RED, Color.GREEN, Color.RED, Color.RED,
+            12f, 25f);
     expected = String.format(
             "domain\tscore|%s|%s|noValueMax|abso|12.0|25.0|none", greenHex,
             redHex);
@@ -687,8 +633,9 @@ public class FeatureColourTest
      * graduated colour based on attribute value for AF
      * given a min-max range of 0-100
      */
-    FeatureColour fc = new FeatureColour(new Color(50, 100, 150),
-            new Color(150, 200, 250), Color.yellow, 0f, 100f);
+    FeatureColour fc = new FeatureColour(Color.white,
+            new Color(50, 100, 150), new Color(150, 200, 250), Color.yellow,
+            0f, 100f);
     String attName = "AF";
     fc.setAttributeName(attName);
 
@@ -712,4 +659,142 @@ public class FeatureColourTest
     Color expected = new Color(70, 120, 170);
     assertEquals(expected, fc.getColor(sf));
   }
+
+  @Test(groups = { "Functional" })
+  public void testIsOutwithThreshold()
+  {
+    FeatureColourI fc = new FeatureColour(Color.red);
+    SequenceFeature sf = new SequenceFeature("METAL", "desc", 10, 12, 1.2f, "grp");
+    assertFalse(fc.isOutwithThreshold(null));
+    assertFalse(fc.isOutwithThreshold(sf));
+
+    fc = new FeatureColour(null, Color.white, Color.black, Color.green, 0f,
+            10f);
+    assertFalse(fc.isOutwithThreshold(sf)); // no threshold
+
+    fc.setAboveThreshold(true);
+    fc.setThreshold(1f);
+    assertFalse(fc.isOutwithThreshold(sf)); // feature score 1.2 is above 1
+
+    fc.setThreshold(2f);
+    assertTrue(fc.isOutwithThreshold(sf)); // feature score 1.2 is not above 2
+
+    fc.setBelowThreshold(true);
+    assertFalse(fc.isOutwithThreshold(sf)); // feature score 1.2 is below 2
+
+    fc.setThreshold(1f);
+    assertTrue(fc.isOutwithThreshold(sf)); // feature score 1.2 is not below 1
+
+    /*
+     * with attribute value threshold
+     */
+    fc.setAttributeName("AC");
+    assertFalse(fc.isOutwithThreshold(sf)); // missing attribute AC is ignored
+
+    sf.setValue("AC", "-1");
+    assertFalse(fc.isOutwithThreshold(sf)); // value -1 is below 1
+
+    sf.setValue("AC", "1");
+    assertTrue(fc.isOutwithThreshold(sf)); // value 1 is not below 1
+
+    sf.setValue("AC", "junk");
+    assertFalse(fc.isOutwithThreshold(sf)); // bad value is ignored
+  }
+
+  /**
+   * Test description of feature colour suitable for a tooltip
+   */
+  @Test(groups = { "Functional" })
+  public void testGetDescription()
+  {
+    /*
+     * plain colour
+     */
+    FeatureColour fc = new FeatureColour(Color.RED);
+    assertEquals(
+            String.format("r=%d,g=%d,b=%d", Color.RED.getRed(),
+                    Color.red.getGreen(), Color.red.getBlue()),
+            fc.getDescription());
+  
+    /*
+     * colour by label (no threshold)
+     */
+    fc = new FeatureColour();
+    fc.setColourByLabel(true);
+    assertEquals("By Label", fc.getDescription());
+  
+    /*
+     * colour by attribute text (no threshold)
+     */
+    fc = new FeatureColour();
+    fc.setColourByLabel(true);
+    fc.setAttributeName("CLIN_SIG");
+    assertEquals("By CLIN_SIG", fc.getDescription());
+  
+    /*
+     * colour by label (above score threshold) 
+     */
+    fc = new FeatureColour();
+    fc.setColourByLabel(true);
+    fc.setAutoScaled(false);
+    fc.setThreshold(12.5f);
+    fc.setAboveThreshold(true);
+    assertEquals("By Label (Score > 12.5)",
+            fc.getDescription());
+  
+    /*
+     * colour by label (below score threshold)
+     */
+    fc.setBelowThreshold(true);
+    assertEquals("By Label (Score < 12.5)",
+            fc.getDescription());
+  
+    /*
+     * colour by attributes text (below score threshold)
+     */
+    fc.setBelowThreshold(true);
+    fc.setAttributeName("CSQ", "Consequence");
+    assertEquals(
+            "By CSQ:Consequence (Score < 12.5)",
+            fc.getDescription());
+  
+    /*
+     * graduated colour by score, no threshold
+     */
+    fc = new FeatureColour(null, Color.GREEN, Color.RED, null, 12f, 25f);
+    assertEquals("By Score", fc.getDescription());
+  
+    /*
+     * graduated colour by score, below threshold
+     */
+    fc.setThreshold(12.5f);
+    fc.setBelowThreshold(true);
+    assertEquals("By Score (< 12.5)",
+            fc.getDescription());
+  
+    /*
+     * graduated colour by score, above threshold
+     */
+    fc.setThreshold(12.5f);
+    fc.setAboveThreshold(true);
+    fc.setAutoScaled(false);
+    assertEquals("By Score (> 12.5)",
+            fc.getDescription());
+
+    /*
+     * graduated colour by attribute, no threshold
+     */
+    fc.setAttributeName("CSQ", "AF");
+    fc.setAboveThreshold(false);
+    fc.setAutoScaled(false);
+    assertEquals("By CSQ:AF", fc.getDescription());
+  
+    /*
+     * graduated colour by attribute, above threshold
+     */
+    fc.setAboveThreshold(true);
+    fc.setAutoScaled(false);
+    assertEquals("By CSQ:AF (> 12.5)",
+            fc.getDescription());
+  }
 }
index d9403d2..e8a70e4 100644 (file)
@@ -24,6 +24,8 @@ public class JalviewColourSchemeTest
     assertTrue(JalviewColourScheme.PurinePyrimidine.getSchemeClass() == PurinePyrimidineColourScheme.class);
     assertTrue(JalviewColourScheme.TCoffee.getSchemeClass() == TCoffeeColourScheme.class);
     assertTrue(JalviewColourScheme.RNAHelices.getSchemeClass() == RNAHelicesColour.class);
+    assertTrue(JalviewColourScheme.IdColour
+            .getSchemeClass() == IdColourScheme.class);
   }
 
   @Test(groups = "Functional")
@@ -44,5 +46,6 @@ public class JalviewColourSchemeTest
             "Purine/Pyrimidine");
     assertEquals(JalviewColourScheme.TCoffee.toString(), "T-Coffee Scores");
     assertEquals(JalviewColourScheme.RNAHelices.toString(), "RNA Helices");
+    assertEquals(JalviewColourScheme.IdColour.toString(), "Sequence ID");
   }
 }
index 7fbad50..180deaf 100644 (file)
@@ -1569,6 +1569,16 @@ public class ResiduePropertiesTest
   }
 
   @Test(groups = { "Functional" })
+  public void testGetDssp3State()
+  {
+    assertNull(ResidueProperties.getDssp3state(null));
+    assertEquals("", ResidueProperties.getDssp3state(""));
+    String foo = "0123 []<>abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
+    String bar = "                                    E  E HHH                 ";
+    assertEquals(bar, ResidueProperties.getDssp3state(foo));
+  }
+
+  @Test(groups = { "Functional" })
   public void testPhysicoChemicalProperties()
   {
     checkProperty("aromatic", "FYWH-*");
index 0ef3c25..0368d1e 100644 (file)
@@ -21,7 +21,6 @@
 package jalview.util;
 
 import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertFalse;
 import static org.testng.AssertJUnit.assertNull;
 import static org.testng.AssertJUnit.assertSame;
 import static org.testng.AssertJUnit.assertTrue;
@@ -121,38 +120,6 @@ public class DBRefUtilsTest
     assertEquals("pfam", DBRefUtils.getCanonicalName("pfam"));
 
   }
-
-  @Test(groups = { "Functional" })
-  public void testIsDasCoordinateSystem()
-  {
-    assertFalse(DBRefUtils.isDasCoordinateSystem(null, null));
-    assertFalse(DBRefUtils.isDasCoordinateSystem("pdbresnum", null));
-    assertFalse(DBRefUtils.isDasCoordinateSystem(null, new DBRefEntry(
-            "PDB", "v1", "a1")));
-
-    assertTrue(DBRefUtils.isDasCoordinateSystem("pdbresnum",
-            new DBRefEntry("PDB", "v1", "a1")));
-    assertTrue(DBRefUtils.isDasCoordinateSystem("PDBRESNUM",
-            new DBRefEntry("PDB", "v1", "a1")));
-    // "pdb" is converted to upper-case in DBRefEntry constructor
-    assertTrue(DBRefUtils.isDasCoordinateSystem("pdbresnum",
-            new DBRefEntry("pdb", "v1", "a1")));
-    assertFalse(DBRefUtils.isDasCoordinateSystem("pdb", new DBRefEntry(
-            "pdb", "v1", "a1")));
-
-    assertTrue(DBRefUtils.isDasCoordinateSystem("UNIPROT", new DBRefEntry(
-            "Uniprot", "v1", "a1")));
-    assertTrue(DBRefUtils.isDasCoordinateSystem("Uniprot", new DBRefEntry(
-            "UNIPROT", "v1", "a1")));
-    assertFalse(DBRefUtils.isDasCoordinateSystem("UNIPROTKB",
-            new DBRefEntry("pdb", "v1", "a1")));
-
-    assertTrue(DBRefUtils.isDasCoordinateSystem("EMBL", new DBRefEntry(
-            "EMBL", "v1", "a1")));
-    assertTrue(DBRefUtils.isDasCoordinateSystem("embl", new DBRefEntry(
-            "embl", "v1", "a1")));
-  }
-
   /**
    * Test 'parsing' a DBRef - non PDB case
    */
diff --git a/test/jalview/util/JSONUtilsTest.java b/test/jalview/util/JSONUtilsTest.java
new file mode 100644 (file)
index 0000000..45f1c48
--- /dev/null
@@ -0,0 +1,26 @@
+package jalview.util;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNull;
+
+import org.json.JSONException;
+import org.json.simple.JSONArray;
+import org.testng.annotations.Test;
+
+public class JSONUtilsTest
+{
+  @Test(groups = "Functional")
+  public void testArrayToList() throws JSONException
+  {
+    assertNull(JSONUtils.arrayToList(null));
+
+    JSONArray ja = new JSONArray();
+    assertNull(JSONUtils.arrayToList(null));
+
+    ja.add("hello");
+    assertEquals(JSONUtils.arrayToList(ja), "hello");
+
+    ja.add("world");
+    assertEquals(JSONUtils.arrayToList(ja), "hello,world");
+  }
+}
index 26c3574..885cb71 100644 (file)
@@ -68,7 +68,7 @@ public class ViewStyleTest
     for (Field field : fields)
     {
       field.setAccessible(true);
-      if (!copyConstructorIgnores(field.getName()))
+      if (!copyConstructorIgnores(field))
       {
         changeValue(vs1, field);
       }
@@ -78,37 +78,49 @@ public class ViewStyleTest
 
     for (Field field1 : fields)
     {
-      final Object value1 = field1.get(vs1);
-      final Object value2 = field1.get(vs2);
-      String msg = "Mismatch in " + field1.getName() + "(" + value1 + "/"
+      if (!copyConstructorIgnores(field1))
+      {
+        final Object value1 = field1.get(vs1);
+        final Object value2 = field1.get(vs2);
+        String msg = "Mismatch in " + field1.getName() + "(" + value1 + "/"
               + value2 + ") - not set in copy constructor?";
-      assertEquals(msg, value1, value2);
+        assertEquals(msg, value1, value2);
+      }
     }
     assertEquals("Hashcode not equals", vs1.hashCode(), vs2.hashCode());
   }
 
   /**
-   * Add any field names in here that we expect to be ignored by the copy
-   * constructor
+   * Add tests here for any fields that we expect to be ignored by 
+   * the copy constructor
    * 
-   * @param name
+   * @param field
    * @return
    */
-  private boolean copyConstructorIgnores(String name)
+  private boolean copyConstructorIgnores(Field field)
   {
     /*
-     * currently none!
+     * ignore instrumentation added by jacoco for test coverage
      */
+    if (field.isSynthetic())
+    {
+      return true;
+    }
+    if (field.getType().toString().contains("com_atlassian_clover"))
+    {
+      return true;
+    }
+
     return false;
   }
-
+  
   /**
-   * Change the value of one field in a ViewStyle object
-   * 
-   * @param vs
-   * @param field
-   * @throws IllegalAccessException
-   */
+  * Change the value of one field in a ViewStyle object
+  * 
+  * @param vs
+  * @param field
+  * @throws IllegalAccessException
+  */
   protected void changeValue(ViewStyle vs, Field field)
           throws IllegalAccessException
   {
@@ -210,19 +222,22 @@ public class ViewStyleTest
     Field[] fields = ViewStyle.class.getDeclaredFields();
     for (Field field : fields)
     {
-      field.setAccessible(true);
-      Object oldValue = field.get(vs2);
-      changeValue(vs2, field);
-      assertFalse("equals method ignores " + field.getName(),
+      if (!copyConstructorIgnores(field))
+      {
+        field.setAccessible(true);
+        Object oldValue = field.get(vs2);
+        changeValue(vs2, field);
+        assertFalse("equals method ignores " + field.getName(),
               vs1.equals(vs2));
 
-      if (vs1.hashCode() == vs2.hashCode())
-      {
-        // uncomment next line to see which fields hashCode ignores
-        // System.out.println("hashCode ignores " + field.getName());
+        if (vs1.hashCode() == vs2.hashCode())
+        {
+          // uncomment next line to see which fields hashCode ignores
+          // System.out.println("hashCode ignores " + field.getName());
+        }
+        // restore original value before testing the next field
+        field.set(vs2, oldValue);
       }
-      // restore original value before testing the next field
-      field.set(vs2, oldValue);
     }
   }
 }
index e835724..86f5602 100644 (file)
@@ -216,6 +216,8 @@ public class UniprotTest
     SequenceI seq = new Uniprot().uniprotEntryToSequence(entry);
     assertNotNull(seq);
     assertEquals(6, seq.getDBRefs().length); // 2*Uniprot, PDB, PDBsum, 2*EMBL
+    assertEquals(seq.getSequenceAsString(),
+            seq.createDatasetSequence().getSequenceAsString());
 
   }
 
index e38064e..54f4e48 100644 (file)
@@ -1,6 +1,8 @@
 Checkstyle for Jalview
 ----------------------
 
+See
+https://issues.jalview.org/browse/JAL-1854
 http://checkstyle.sourceforge.net/
 GNU LGPL
 
@@ -9,8 +11,16 @@ To get the Eclipse Checkstyle plugin
        - Help | Eclipse Marketplace
        - search for checkstyle
        - install eclipse-cs checkstyle plugin
-The current version is 6.19.1 (August 2016).
 
+Change Log
+----------
+See http://checkstyle.sourceforge.net/releasenotes.html
+Aug 2016       Initial version used is 6.19.1
+Dec 2018       Updated to 8.12.0 (latest on Eclipse Marketplace, 8.15 is latest release)
+                       SuppressionCommentFilter relocated (changed in 8.1)
+                       FileContentsHolder removed (changed in 8.2)
+                       Updates to import-control.xml for code changes (htsjdk, stackoverflowusers)
+                       
 Config
 ------
 
@@ -37,6 +47,7 @@ How to use checkstyle
        Option 2: on demand on selected code
                - right-click on a class or package and Checkstyle | Check code with checkstyle
                - (or Clear Checkstyle violations to remove checkstyle warnings)
+               - recommended to use this as a QA step when changing or reviewing code
 
 Checkstyle rules
 ----------------
@@ -64,11 +75,11 @@ Suppressing findings
 Tips
 ----
        Sometimes checkstyle needs a kick before it will refresh its findings.
-       A whitespace edit in checkstyle.xml usually does this. There may be better ways.
+       Click the 'refresh' icon at top right in Eclipse | Preferences | Checkstyle.
        
        Invalid configuration files may result in checkstyle failing with an error reported
        in the Eclipse log file. 
-       Help | Installation Details | Configuration takes you to a screen with a 
+       Eclipse | About | Installation Details | Configuration takes you to a screen with a 
        'View Error Log' button.
        
        Sometimes checkstyle can fail silently. Try 'touching' (editing) config files, failing
index 122b8d0..29a3047 100644 (file)
@@ -26,6 +26,7 @@
     <suppress checks="[a-zA-Z0-9]*" files="[\\/]ext[\\/]edu*"/>
     <suppress checks="[a-zA-Z0-9]*" files="[\\/]ext[\\/]vamsas*"/>
     <suppress checks="[a-zA-Z0-9]*" files="[\\/]org[\\/]jibble*"/>
+    <suppress checks="[a-zA-Z0-9]*" files="[\\/]org[\\/]stackoverflowusers*"/>
     <suppress checks="[a-zA-Z0-9]*" files="[\\/]uk[\\/]ac*"/>
     
     <!-- 
index 85ac8e6..17946f7 100644 (file)
        </module>
 
        <!-- 
-               Allow suppression of rules by comments, e.g.:
-               // CHECKSTYLE.OFF: ParameterNumber
-               ..method declaration
-               // CHECKSTYLE.ON: ParameterNumber
-       -->
-       <module name="SuppressionCommentFilter">
-               <property name="offCommentFormat" value="CHECKSTYLE.OFF\: ([\w\|]+)"/>
-               <property name="onCommentFormat" value="CHECKSTYLE.ON\: ([\w\|]+)"/>
-               <property name="checkFormat" value="$1"/>
-       </module>
-
-       <!-- 
                Check language bundles have the same keys and no duplicates
                (ensure Checkstyle is configured to scan non-source files)
         -->
                <property name="tabWidth" value="4"/>
 
                <!-- 
-                       Enables parsing of suppressions comments
-                       see http://checkstyle.sourceforge.net/config_filters.html#SuppressionCommentFilter 
+                       Allow suppression of rules by comments, e.g.:
+                       // CHECKSTYLE.OFF: ParameterNumber
+                       ..method declaration
+                       // CHECKSTYLE.ON: ParameterNumber
                -->
-               <module name="FileContentsHolder"/>
+               <module name="SuppressionCommentFilter">
+                       <property name="offCommentFormat" value="CHECKSTYLE.OFF\: ([\w\|]+)"/>
+                       <property name="onCommentFormat" value="CHECKSTYLE.ON\: ([\w\|]+)"/>
+                       <property name="checkFormat" value="$1"/>
+               </module>
 
        <!-- ****************************** -->
        <!--         NAMING STANDARDS       -->
index c47aaec..478966f 100644 (file)
@@ -94,6 +94,7 @@
                <allow pkg="compbio.metadata" class="jalview.gui.WsJobParameters"/>
                <allow pkg="fr.orsay.lri.varna" class="jalview.gui.AppVarna"/>
                <allow pkg="fr.orsay.lri.varna" class="jalview.gui.AppVarnaBinding"/>
+               <allow pkg="org.stackoverflowusers.file" class="jalview.gui.Desktop"/>
                <allow pkg="uk.ac.vamsas" class="jalview.gui.VamsasApplication"/>
            </subpackage>
                
                <allow pkg="uk.ac.vamsas"/>
                <allow pkg="fr.orsay.lri.varna"/>
                <allow pkg="MCview"/>
+                       <subpackage name="vcf">
+                       <allow pkg="htsjdk\.*" regex="true"/>
+                       </subpackage>       
                </subpackage>       
                                
                <subpackage name="javascript">
index 01973d2..360a700 100755 (executable)
@@ -7,10 +7,14 @@
 
 <taskdef resource="net/sf/antcontrib/antcontrib.properties">
   <classpath>
-    <pathelement location="${basedir}/utils/ant-contrib-0.3.jar"/>
+    <pathelement location="${basedir}/utils/ant-contrib-1.0b3.jar"/>
+  </classpath>
+</taskdef>
+<taskdef resource="net/sf/antcontrib/antlib.xml">
+  <classpath>
+    <pathelement location="${basedir}/utils/ant-contrib-1.0b3.jar"/>
   </classpath>
 </taskdef>
-<taskdef resource="net/sf/antcontrib/antlib.xml"/>
  
 <target name="checkLang" description="Reports missing entries in language bundles compared to Message.properties">
        <!-- adapted from http://stackoverflow.com/questions/14381660/ant-task-to-compare-two-properties-files -->