Merge branch 'releases/Release_2_11_1_Branch' into merge/JAL_1842+JAL-3509+releases_R... merge/JAL_1842+JAL-3509+releases_Release_2_11_1_Branch
authorBen Soares <b.soares@dundee.ac.uk>
Thu, 27 Aug 2020 09:09:13 +0000 (10:09 +0100)
committerBen Soares <b.soares@dundee.ac.uk>
Thu, 27 Aug 2020 09:09:13 +0000 (10:09 +0100)
75 files changed:
build.gradle
doc/building.md
gradle.properties
help/help/html/features/clarguments.html
help/help/html/features/commandline.html
help/help/html/features/search.html
help/help/html/features/search.png
help/help/html/logging.html [new file with mode: 0644]
help/help/html/memory.html
help/help/html/releases.html
resources/lang/Messages.properties
resources/lang/Messages_es.properties
src/jalview/analysis/Finder.java
src/jalview/api/AlignViewportI.java
src/jalview/api/FinderI.java
src/jalview/appletgui/AlignmentPanel.java
src/jalview/appletgui/Finder.java
src/jalview/bin/Cache.java
src/jalview/bin/Jalview.java
src/jalview/datamodel/SearchResults.java
src/jalview/datamodel/SearchResultsI.java
src/jalview/fts/core/GFTSPanel.java
src/jalview/gui/AlignFrame.java
src/jalview/gui/AlignViewport.java
src/jalview/gui/AnnotationColumnChooser.java
src/jalview/gui/Console.java
src/jalview/gui/Finder.java
src/jalview/gui/IdCanvas.java
src/jalview/gui/OptsAndParamsPage.java
src/jalview/gui/PCAPanel.java
src/jalview/gui/SeqPanel.java
src/jalview/gui/Slider.java
src/jalview/gui/SplitFrame.java
src/jalview/gui/TreePanel.java
src/jalview/io/BackupFiles.java
src/jalview/io/BackupFilesPresetEntry.java
src/jalview/io/EmblFlatFile.java [new file with mode: 0644]
src/jalview/io/FeaturesFile.java
src/jalview/io/FileFormats.java
src/jalview/io/FileParse.java
src/jalview/io/FormatAdapter.java
src/jalview/io/IdentifyFile.java
src/jalview/io/JPredFile.java
src/jalview/io/JnetAnnotationMaker.java
src/jalview/io/MSFfile.java
src/jalview/io/ScoreMatrixFile.java
src/jalview/io/cache/JvCacheableInputBox.java
src/jalview/io/packed/ParsePackedSet.java
src/jalview/io/vcf/VCFLoader.java
src/jalview/jbgui/GFinder.java
src/jalview/renderer/AnnotationRenderer.java
src/jalview/util/MappingUtils.java
src/jalview/viewmodel/AlignmentViewport.java
src/jalview/ws/dbsources/EmblCdsSource.java
src/jalview/ws/dbsources/EmblFlatfileSource.java [new file with mode: 0644]
src/jalview/ws/dbsources/EmblSource.java
src/jalview/ws/dbsources/EmblXmlSource.java
src/jalview/ws/ebi/EBIFetchClient.java
src/jalview/ws/sifts/SiftsClient.java
test/jalview/analysis/FinderTest.java
test/jalview/bin/CommandLineOperations.java
test/jalview/controller/AlignViewControllerTest.java
test/jalview/datamodel/SearchResultsTest.java
test/jalview/gui/FreeUpMemoryTest.java
test/jalview/io/BackupFilesTest.java
test/jalview/io/EmblFlatFileTest.java [new file with mode: 0644]
test/jalview/io/FileIOTester.java
test/jalview/io/J03321.embl.txt [new file with mode: 0644]
test/jalview/io/cache/JvCacheableInputBoxTest.java
test/jalview/util/MappingUtilsTest.java
test/jalview/ws/dbsources/EmblXmlSourceTest.java [moved from test/jalview/ws/dbsources/EmblSourceTest.java with 93% similarity]
test/jalview/ws/ebi/EBIFetchClientTest.java
utils/clover/lib/clover-ant-4.4.1.jar [new file with mode: 0644]
utils/cmd-nox.sh [new file with mode: 0755]
utils/gradle-nox.sh [new symlink]

index 2c7f138..682b5c2 100644 (file)
@@ -1,3 +1,6 @@
+/* Convention for properties.  Read from gradle.properties, use lower_case_underlines for property names.
+ * For properties set within build.gradle, use camelCaseNoSpace.
+ */
 import org.apache.tools.ant.filters.ReplaceTokens
 import org.gradle.internal.os.OperatingSystem
 import org.gradle.plugins.ide.eclipse.model.Output
@@ -13,9 +16,6 @@ buildscript {
     mavenCentral()
     mavenLocal()
   }
-  dependencies {
-    classpath 'org.openclover:clover:4.4.1'
-  }
 }
 
 
@@ -130,21 +130,25 @@ ext {
   sourceDir = string("${jalviewDir}/${bareSourceDir}")
   resourceDir = string("${jalviewDir}/${resource_dir}")
   bareTestSourceDir = string(test_source_dir)
-  testSourceDir = string("${jalviewDir}/${bareTestSourceDir}")
+  testDir = string("${jalviewDir}/${bareTestSourceDir}")
 
-  // clover
-  cloverInstrDir = file("${buildDir}/${cloverSourcesInstrDir}")
-  cloverDb = string("${buildDir}/clover/clover.db")
   classesDir = string("${jalviewDir}/${classes_dir}")
-  if (clover.equals("true")) {
-    use_clover = true
-    classesDir = string("${buildDir}/${cloverClassesDir}")
-  } else {
-    use_clover = false
-    classesDir = string("${jalviewDir}/${classes_dir}")
-  }
 
-  classes = classesDir
+  // clover
+  useClover = clover.equals("true")
+  cloverBuildDir = "${buildDir}/clover"
+  cloverInstrDir = file("${cloverBuildDir}/clover-instr")
+  cloverClassesDir = file("${cloverBuildDir}/clover-classes")
+  cloverReportDir = file("${buildDir}/reports/clover")
+  cloverTestInstrDir = file("${cloverBuildDir}/clover-test-instr")
+  cloverTestClassesDir = file("${cloverBuildDir}/clover-test-classes")
+  //cloverTestClassesDir = cloverClassesDir
+  cloverDb = string("${cloverBuildDir}/clover.db")
+
+  resourceClassesDir = useClover ? cloverClassesDir : classesDir
+
+  testSourceDir = useClover ? cloverTestInstrDir : testDir
+  testClassesDir = useClover ? cloverTestClassesDir : "${jalviewDir}/${test_output_dir}"
 
   getdownWebsiteDir = string("${jalviewDir}/${getdown_website_dir}/${JAVA_VERSION}")
   buildDist = true
@@ -173,8 +177,8 @@ ext {
     getdownAppBase = string("${bamboo_channelbase}/${bamboo_planKey}${bamboo_getdown_channel_suffix}/${JAVA_VERSION}")
     jvlChannelName += "_${getdownChannelName}"
     // automatically add the test group Not-bamboo for exclusion 
-    if ("".equals(testngExcludedGroups)) { 
-      testngExcludedGroups = "Not-bamboo"
+    if ("".equals(testng_excluded_groups)) { 
+      testng_excluded_groups = "Not-bamboo"
     }
     install4jExtraScheme = "jalviewb"
     break
@@ -192,10 +196,10 @@ ext {
     getdownChannelName = CHANNEL.toLowerCase()+"/${JALVIEW_VERSION}"
     getdownDir = string("${getdownChannelName}/${JAVA_VERSION}")
     getdownAppBase = string("${getdown_channel_base}/${getdownDir}")
-    if (!file("${ARCHIVEDIR}/${packageDir}").exists()) {
+    if (!file("${ARCHIVEDIR}/${package_dir}").exists()) {
       throw new GradleException("Must provide an ARCHIVEDIR value to produce an archive distribution")
     } else {
-      packageDir = string("${ARCHIVEDIR}/${packageDir}")
+      package_dir = string("${ARCHIVEDIR}/${package_dir}")
       buildProperties = string("${ARCHIVEDIR}/${classes_dir}/${build_properties_file}")
       buildDist = false
     }
@@ -207,10 +211,10 @@ ext {
     getdownChannelName = string("archive/${JALVIEW_VERSION}")
     getdownDir = string("${getdownChannelName}/${JAVA_VERSION}")
     getdownAppBase = file(getdownWebsiteDir).toURI().toString()
-    if (!file("${ARCHIVEDIR}/${packageDir}").exists()) {
+    if (!file("${ARCHIVEDIR}/${package_dir}").exists()) {
       throw new GradleException("Must provide an ARCHIVEDIR value to produce an archive distribution")
     } else {
-      packageDir = string("${ARCHIVEDIR}/${packageDir}")
+      package_dir = string("${ARCHIVEDIR}/${package_dir}")
       buildProperties = string("${ARCHIVEDIR}/${classes_dir}/${build_properties_file}")
       buildDist = false
     }
@@ -409,8 +413,8 @@ ext {
 
 
 
-  buildingHTML = string("${jalviewDir}/${docDir}/building.html")
-  helpFile = string("${classesDir}/${help_dir}/help.jhm")
+  buildingHTML = string("${jalviewDir}/${doc_dir}/building.html")
+  helpFile = string("${resourceClassesDir}/${help_dir}/help.jhm")
   helpParentDir = string("${jalviewDir}/${help_parent_dir}")
   helpSourceDir = string("${helpParentDir}/${help_dir}")
 
@@ -453,10 +457,9 @@ sourceSets {
       srcDirs += helpParentDir
     }
 
-    jar.destinationDir = file("${jalviewDir}/${packageDir}")
+    jar.destinationDir = file("${jalviewDir}/${package_dir}")
 
     compileClasspath = files(sourceSets.main.java.outputDir)
-    //compileClasspath += files(sourceSets.main.resources.srcDirs)
     compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
 
     runtimeClasspath = compileClasspath
@@ -464,18 +467,19 @@ sourceSets {
 
   clover {
     java {
-      srcDirs = [ cloverInstrDir ]
-      outputDir = file("${buildDir}/${cloverClassesDir}")
+      srcDirs cloverInstrDir
+      outputDir = cloverClassesDir
     }
 
     resources {
       srcDirs = sourceSets.main.resources.srcDirs
     }
-    compileClasspath = configurations.cloverRuntime + files( sourceSets.clover.java.outputDir )
-    compileClasspath += files(sourceSets.main.java.outputDir)
-    compileClasspath += sourceSets.main.compileClasspath
-    compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}", include: ["**/*.jar"])
+
+    compileClasspath = files( sourceSets.clover.java.outputDir )
+    //compileClasspath += files( testClassesDir )
     compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
+    compileClasspath += fileTree(dir: "${jalviewDir}/${clover_lib_dir}", include: ["*.jar"])
+    compileClasspath += fileTree(dir: "${jalviewDir}/${utils_dir}/testnglibs", include: ["**/*.jar"])
 
     runtimeClasspath = compileClasspath
   }
@@ -483,41 +487,20 @@ sourceSets {
   test {
     java {
       srcDirs testSourceDir
-      outputDir = file("${jalviewDir}/${testOutputDir}")
+      outputDir = file(testClassesDir)
     }
 
     resources {
-      srcDirs = sourceSets.main.resources.srcDirs
+      srcDirs = useClover ? sourceSets.clover.resources.srcDirs : sourceSets.main.resources.srcDirs
     }
 
     compileClasspath = files( sourceSets.test.java.outputDir )
-
-    if (use_clover) {
-      compileClasspath = sourceSets.clover.compileClasspath
-    } else {
-      compileClasspath += files(sourceSets.main.java.outputDir)
-    }
-
-    compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
-    compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}/testnglibs", include: ["**/*.jar"])
-    compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}/testlibs", include: ["**/*.jar"])
+    compileClasspath += useClover ? sourceSets.clover.compileClasspath : sourceSets.main.compileClasspath
+    compileClasspath += fileTree(dir: "${jalviewDir}/${utils_dir}/testnglibs", include: ["**/*.jar"])
 
     runtimeClasspath = compileClasspath
   }
-}
-
 
-// clover bits
-dependencies {
-  if (use_clover) {
-    cloverCompile 'org.openclover:clover:4.4.1'
-    testCompile 'org.openclover:clover:4.4.1'
-  }
-}
-
-configurations {
-  cloverRuntime
-  cloverRuntime.extendsFrom cloverCompile
 }
 
 
@@ -656,61 +639,209 @@ eclipse {
 }
 
 
-task cloverInstr {
-  // only instrument source, we build test classes as normal
-  inputs.files files (sourceSets.main.allJava,sourceSets.test.allJava) // , fileTree(dir:"$jalviewDir/$testSourceDir", include: ["**/*.java"]))
-  outputs.dir cloverInstrDir
+// clover bits
 
+
+task cleanClover {
   doFirst {
-    delete cloverInstrDir
-    def argsList = [
-      "--initstring",
-      cloverDb,
-      "-d",
-      cloverInstrDir.getPath(),
-    ]
-    argsList.addAll(
-      inputs.files.files.collect(
-        { file -> file.absolutePath }
-      )
+    delete cloverBuildDir
+    delete cloverReportDir
+  }
+}
+
+
+task cloverInstrJava(type: JavaExec) {
+  group = "Verification"
+  description = "Create clover instrumented source java files"
+
+  dependsOn cleanClover
+
+  inputs.files(sourceSets.main.allJava)
+  outputs.dir(cloverInstrDir)
+
+  //classpath = fileTree(dir: "${jalviewDir}/${clover_lib_dir}", include: ["*.jar"])
+  classpath = sourceSets.clover.compileClasspath
+  main = "com.atlassian.clover.CloverInstr"
+
+  def argsList = [
+    "--encoding",
+    "UTF-8",
+    "--initstring",
+    cloverDb,
+    "--destdir",
+    cloverInstrDir.getPath(),
+  ]
+  def srcFiles = sourceSets.main.allJava.files
+  argsList.addAll(
+    srcFiles.collect(
+      { file -> file.absolutePath }
     )
-    String[] args = argsList.toArray()
-    println("About to instrument "+args.length +" files")
-    com.atlassian.clover.CloverInstr.mainImpl(args)
+  )
+  args argsList.toArray()
+
+  doFirst {
+    delete cloverInstrDir
+    println("Clover: About to instrument "+srcFiles.size() +" files")
   }
 }
 
 
+task cloverInstrTests(type: JavaExec) {
+  group = "Verification"
+  description = "Create clover instrumented source test files"
+
+  dependsOn cleanClover
+
+  inputs.files(testDir)
+  outputs.dir(cloverTestInstrDir)
+
+  classpath = sourceSets.clover.compileClasspath
+  main = "com.atlassian.clover.CloverInstr"
+
+  def argsList = [
+    "--encoding",
+    "UTF-8",
+    "--initstring",
+    cloverDb,
+    "--srcdir",
+    testDir,
+    "--destdir",
+    cloverTestInstrDir.getPath(),
+  ]
+  args argsList.toArray()
+
+  doFirst {
+    delete cloverTestInstrDir
+    println("Clover: About to instrument test files")
+  }
+}
+
+
+task cloverInstr {
+  group = "Verification"
+  description = "Create clover instrumented all source files"
+
+  dependsOn cloverInstrJava
+  dependsOn cloverInstrTests
+}
+
+
 cloverClasses.dependsOn cloverInstr
 
 
-task cloverReport {
+task cloverConsoleReport(type: JavaExec) {
   group = "Verification"
-  description = "Creates the Clover report"
-  inputs.dir "${buildDir}/clover"
-  outputs.dir "${reportsDir}/clover"
+  description = "Creates clover console report"
+
   onlyIf {
     file(cloverDb).exists()
   }
-  doFirst {
-    def argsList = [
-      "--initstring",
-      cloverDb,
-      "-o",
-      "${reportsDir}/clover"
-    ]
-    String[] args = argsList.toArray()
-    com.atlassian.clover.reporters.html.HtmlReporter.runReport(args)
-
-    // and generate ${reportsDir}/clover/clover.xml
-    args = [
-      "--initstring",
-      cloverDb,
-      "-o",
-      "${reportsDir}/clover/clover.xml"
-    ].toArray()
-    com.atlassian.clover.reporters.xml.XMLReporter.runReport(args)
+
+  inputs.dir cloverClassesDir
+
+  classpath = sourceSets.clover.runtimeClasspath
+  main = "com.atlassian.clover.reporters.console.ConsoleReporter"
+
+  if (cloverreport_mem.length() > 0) {
+    maxHeapSize = cloverreport_mem
   }
+  if (cloverreport_jvmargs.length() > 0) {
+    jvmArgs Arrays.asList(cloverreport_jvmargs.split(" "))
+  }
+
+  def argsList = [
+    "--alwaysreport",
+    "--initstring",
+    cloverDb,
+    "--unittests"
+  ]
+
+  args argsList.toArray()
+}
+
+
+task cloverHtmlReport(type: JavaExec) {
+  group = "Verification"
+  description = "Creates clover HTML report"
+
+  onlyIf {
+    file(cloverDb).exists()
+  }
+
+  def cloverHtmlDir = cloverReportDir
+  inputs.dir cloverClassesDir
+  outputs.dir cloverHtmlDir
+
+  classpath = sourceSets.clover.runtimeClasspath
+  main = "com.atlassian.clover.reporters.html.HtmlReporter"
+
+  if (cloverreport_mem.length() > 0) {
+    maxHeapSize = cloverreport_mem
+  }
+  if (cloverreport_jvmargs.length() > 0) {
+    jvmArgs Arrays.asList(cloverreport_jvmargs.split(" "))
+  }
+
+  def argsList = [
+    "--alwaysreport",
+    "--initstring",
+    cloverDb,
+    "--outputdir",
+    cloverHtmlDir
+  ]
+
+  if (cloverreport_html_options.length() > 0) {
+    argsList += cloverreport_html_options.split(" ")
+  }
+
+  args argsList.toArray()
+}
+
+
+task cloverXmlReport(type: JavaExec) {
+  group = "Verification"
+  description = "Creates clover XML report"
+
+  onlyIf {
+    file(cloverDb).exists()
+  }
+
+  def cloverXmlFile = "${cloverReportDir}/clover.xml"
+  inputs.dir cloverClassesDir
+  outputs.file cloverXmlFile
+
+  classpath = sourceSets.clover.runtimeClasspath
+  main = "com.atlassian.clover.reporters.xml.XMLReporter"
+
+  if (cloverreport_mem.length() > 0) {
+    maxHeapSize = cloverreport_mem
+  }
+  if (cloverreport_jvmargs.length() > 0) {
+    jvmArgs Arrays.asList(cloverreport_jvmargs.split(" "))
+  }
+
+  def argsList = [
+    "--alwaysreport",
+    "--initstring",
+    cloverDb,
+    "--outfile",
+    cloverXmlFile
+  ]
+
+  if (cloverreport_xml_options.length() > 0) {
+    argsList += cloverreport_xml_options.split(" ")
+  }
+
+  args argsList.toArray()
+}
+
+
+task cloverReport {
+  group = "Verification"
+  description = "Creates clover reports"
+
+  dependsOn cloverXmlReport
+  dependsOn cloverHtmlReport
 }
 
 
@@ -722,15 +853,7 @@ compileCloverJava {
     options.compilerArgs += additional_compiler_args
     print ("Setting target compatibility to "+targetCompatibility+"\n")
   }
-  classpath += configurations.cloverRuntime
-}
-
-
-task cleanClover {
-  doFirst {
-    delete cloverInstrDir
-    delete cloverDb
-  }
+  //classpath += configurations.cloverRuntime
 }
 // end clover bits
 
@@ -748,12 +871,6 @@ compileJava {
 
 
 compileTestJava {
-  if (use_clover) {
-    dependsOn compileCloverJava
-    classpath += configurations.cloverRuntime
-  } else {
-    classpath += sourceSets.main.runtimeClasspath
-  }
   doFirst {
     sourceCompatibility = compile_source_compatibility
     targetCompatibility = compile_target_compatibility
@@ -832,8 +949,8 @@ task cleanBuildingHTML(type: Delete) {
 
 task convertBuildingMD(type: Exec) {
   dependsOn cleanBuildingHTML
-  def buildingMD = "${jalviewDir}/${docDir}/building.md"
-  def css = "${jalviewDir}/${docDir}/github.css"
+  def buildingMD = "${jalviewDir}/${doc_dir}/building.md"
+  def css = "${jalviewDir}/${doc_dir}/github.css"
 
   def pandoc = null
   pandoc_exec.split(",").each {
@@ -875,8 +992,8 @@ clean {
 
 task syncDocs(type: Sync) {
   dependsOn convertBuildingMD
-  def syncDir = "${classesDir}/${docDir}"
-  from fileTree("${jalviewDir}/${docDir}")
+  def syncDir = "${resourceClassesDir}/${doc_dir}"
+  from fileTree("${jalviewDir}/${doc_dir}")
   into syncDir
 
 }
@@ -884,7 +1001,7 @@ task syncDocs(type: Sync) {
 
 task copyHelp(type: Copy) {
   def inputDir = helpSourceDir
-  def outputDir = "${classesDir}/${help_dir}"
+  def outputDir = "${resourceClassesDir}/${help_dir}"
   from(inputDir) {
     exclude '**/*.gif'
     exclude '**/*.jpg'
@@ -912,7 +1029,7 @@ task copyHelp(type: Copy) {
 
 
 task syncLib(type: Sync) {
-  def syncDir = "${classesDir}/${libDistDir}"
+  def syncDir = "${resourceClassesDir}/${libDistDir}"
   from fileTree("${jalviewDir}/${libDistDir}")
   into syncDir
 }
@@ -921,7 +1038,7 @@ task syncLib(type: Sync) {
 task syncResources(type: Sync) {
   from resourceDir
   include "**/*.*"
-  into "${classesDir}"
+  into "${resourceClassesDir}"
   preserve {
     include "**"
   }
@@ -938,18 +1055,17 @@ task prepare {
 //testReportDirName = "test-reports" // note that test workingDir will be $jalviewDir
 test {
   dependsOn prepare
-  dependsOn compileJava
-  if (use_clover) {
-    dependsOn cloverInstr
-  }
+  //dependsOn compileJava ////? DELETE
 
-  if (use_clover) {
-    print("Running tests " + (use_clover?"WITH":"WITHOUT") + " clover [clover="+use_clover+"]\n")
+  if (useClover) {
+    dependsOn cloverClasses
+   } else { //?
+     dependsOn compileJava //?
   }
 
   useTestNG() {
-    includeGroups testngGroups
-    excludeGroups testngExcludedGroups
+    includeGroups testng_groups
+    excludeGroups testng_excluded_groups
     preserveOrder true
     useDefaultListeners=true
   }
@@ -972,6 +1088,11 @@ test {
   targetCompatibility = compile_target_compatibility
   jvmArgs += additional_compiler_args
 
+  doFirst {
+    if (useClover) {
+      println("Running tests " + (useClover?"WITH":"WITHOUT") + " clover")
+    }
+  }
 }
 
 
@@ -997,22 +1118,22 @@ task buildIndices(type: JavaExec) {
 
 task compileLinkCheck(type: JavaCompile) {
   options.fork = true
-  classpath = files("${jalviewDir}/${utilsDir}")
-  destinationDir = file("${jalviewDir}/${utilsDir}")
-  source = fileTree(dir: "${jalviewDir}/${utilsDir}", include: ["HelpLinksChecker.java", "BufferedLineReader.java"])
-
-  inputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.java")
-  inputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.java")
-  outputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.class")
-  outputs.file("${jalviewDir}/${utilsDir}/BufferedLineReader.class")
+  classpath = files("${jalviewDir}/${utils_dir}")
+  destinationDir = file("${jalviewDir}/${utils_dir}")
+  source = fileTree(dir: "${jalviewDir}/${utils_dir}", include: ["HelpLinksChecker.java", "BufferedLineReader.java"])
+
+  inputs.file("${jalviewDir}/${utils_dir}/HelpLinksChecker.java")
+  inputs.file("${jalviewDir}/${utils_dir}/HelpLinksChecker.java")
+  outputs.file("${jalviewDir}/${utils_dir}/HelpLinksChecker.class")
+  outputs.file("${jalviewDir}/${utils_dir}/BufferedLineReader.class")
 }
 
 
 task linkCheck(type: JavaExec) {
   dependsOn prepare, compileLinkCheck
 
-  def helpLinksCheckerOutFile = file("${jalviewDir}/${utilsDir}/HelpLinksChecker.out")
-  classpath = files("${jalviewDir}/${utilsDir}")
+  def helpLinksCheckerOutFile = file("${jalviewDir}/${utils_dir}/HelpLinksChecker.out")
+  classpath = files("${jalviewDir}/${utils_dir}")
   main = "HelpLinksChecker"
   workingDir = jalviewDir
   args = [ "${classesDir}/${help_dir}", "-nointernet" ]
@@ -1033,12 +1154,12 @@ task linkCheck(type: JavaExec) {
 // import the pubhtmlhelp target
 ant.properties.basedir = "${jalviewDir}"
 ant.properties.helpBuildDir = "${jalviewDirAbsolutePath}/${classes_dir}/${help_dir}"
-ant.importBuild "${utilsDir}/publishHelp.xml"
+ant.importBuild "${utils_dir}/publishHelp.xml"
 
 
 task cleanPackageDir(type: Delete) {
   doFirst {
-    delete fileTree(dir: "${jalviewDir}/${packageDir}", include: "*.jar")
+    delete fileTree(dir: "${jalviewDir}/${package_dir}", include: "*.jar")
   }
 }
 
@@ -1048,13 +1169,13 @@ jar {
   dependsOn createBuildProperties
 
   manifest {
-    attributes "Main-Class": mainClass,
+    attributes "Main-Class": main_class,
     "Permissions": "all-permissions",
     "Application-Name": "Jalview Desktop",
     "Codebase": application_codebase
   }
 
-  destinationDir = file("${jalviewDir}/${packageDir}")
+  destinationDir = file("${jalviewDir}/${package_dir}")
   archiveName = rootProject.name+".jar"
 
   exclude "cache*/**"
@@ -1064,20 +1185,20 @@ jar {
   exclude "**/*.jar.*"
 
   inputs.dir(classesDir)
-  outputs.file("${jalviewDir}/${packageDir}/${archiveName}")
+  outputs.file("${jalviewDir}/${package_dir}/${archiveName}")
 }
 
 
 task copyJars(type: Copy) {
   from fileTree(dir: classesDir, include: "**/*.jar").files
-  into "${jalviewDir}/${packageDir}"
+  into "${jalviewDir}/${package_dir}"
 }
 
 
 // doing a Sync instead of Copy as Copy doesn't deal with "outputs" very well
 task syncJars(type: Sync) {
   from fileTree(dir: "${jalviewDir}/${libDistDir}", include: "**/*.jar").files
-  into "${jalviewDir}/${packageDir}"
+  into "${jalviewDir}/${package_dir}"
   preserve {
     include jar.archiveName
   }
@@ -1093,7 +1214,7 @@ task makeDist {
   dependsOn cleanPackageDir
   dependsOn syncJars
   dependsOn jar
-  outputs.dir("${jalviewDir}/${packageDir}")
+  outputs.dir("${jalviewDir}/${package_dir}")
 }
 
 
@@ -1114,7 +1235,7 @@ shadowJar {
   manifest {
     attributes 'Implementation-Version': JALVIEW_VERSION
   }
-  mainClassName = shadowJarMainClass
+  mainClassName = shadow_jar_main_class
   mergeServiceFiles()
   classifier = "all-"+JALVIEW_VERSION+"-j"+JAVA_VERSION
   minimize()
@@ -1206,7 +1327,7 @@ task getdownWebsite() {
     }
 
     def codeFiles = []
-    fileTree(file(packageDir)).each{ f ->
+    fileTree(file(package_dir)).each{ f ->
       if (f.isDirectory()) {
         def files = fileTree(dir: f, include: ["*"]).getFiles()
         codeFiles += files
@@ -1243,7 +1364,7 @@ task getdownWebsite() {
     // getdown-launcher.jar should not be in main application class path so the main application can move it when updated.  Listed as a resource so it gets updated.
     //getdownTextString += "class = " + file(getdownLauncher).getName() + "\n"
     getdownTextString += "resource = ${getdown_launcher_new}\n"
-    getdownTextString += "class = ${mainClass}\n"
+    getdownTextString += "class = ${main_class}\n"
 
     def getdown_txt = file("${getdownWebsiteDir}/getdown.txt")
     getdown_txt.write(getdownTextString)
@@ -1301,7 +1422,7 @@ task getdownWebsite() {
   }
 
   if (buildDist) {
-    inputs.dir("${jalviewDir}/${packageDir}")
+    inputs.dir("${jalviewDir}/${package_dir}")
   }
   outputs.dir(getdownWebsiteDir)
   outputs.dir(getdownFilesDir)
index ad19979..855f966 100644 (file)
@@ -276,8 +276,8 @@ although without the many and compelling benefits of the `getdown` launcher.
 We have made significant customisations to the `getdown` launcher which you can find 
 in `getdown/src/getdown`.
 
-> You don't need to build this afresh as the required `gradle-core.jar` 
-and `gradle-launcher.jar` files are already distributed in `j11lib` and `getdown/lib` but if you want to, then 
+> You don't need to build this afresh as the required `getdown-core.jar` 
+and `getdown-launcher.jar` files are already distributed in `j11lib` and `getdown/lib` but if you want to, then 
 you'll need a working Maven and also a Java 8 JDK.  Ensure the Java 8 `javac` is forefront 
 in your path and do
 >
@@ -285,9 +285,9 @@ in your path and do
 >cd getdown/src/getdown
 >mvn clean package -Dgetdown.host.whitelist="jalview.org,*.jalview.org"
 >```
-> and you will find the required `.jar` files in `core/target/gradle-core-XXX.jar` 
-and `launcher/target/gradle-launcher-XXX.jar`.  The `gradle-core.jar` should then be copied 
-to all three of the `j8lib`, `j11lib` and `getdown/lib` folders, whilst the `gradle-launcher.jar` only 
+> and you will find the required `.jar` files in `core/target/getdown-core-XXX.jar` 
+and `launcher/target/getdown-launcher-XXX.jar`.  The `getdown-core.jar` should then be copied 
+to all three of the `j8lib`, `j11lib` and `getdown/lib` folders, whilst the `getdown-launcher.jar` only 
 needs to be copied to `getdown/lib`.
 >
 >The `mvn` command should ideally include the `-Dgetdown.host.whitelist=*.jalview.org` setting. 
@@ -318,6 +318,7 @@ java -jar getdown/files/11/getdown-launcher.jar getdown/files/11/ jalview
 getdown, and the final argument, "`jalview`", is a getdown application id (only "`jalview`" 
 is defined here).
 
+The command line sequence for building and relocating the getdown artifacts can be executed as a script via `getdown/src/getdown/mvn_cmd`. Please make sure this script is kept up to date should the getdown build instructions change.
 
 ### Running tests
 
index 782a495..dbf124b 100644 (file)
@@ -1,4 +1,6 @@
-org.gradle.jvmargs=-Xmx1536m -Xms512m
+# Convention for properties.  Read from gradle.properties, use lower_case_underlines for property names.
+# For properties set within build.gradle, use camelCaseNoSpace.
+#
 
 jalviewDir = .
 
@@ -23,38 +25,35 @@ proxyHost = sqid
 jalview_keyalg = SHA1withRSA
 jalview_keydig = SHA1
 
-testngGroups = Functional
-testngExcludedGroups = 
+testng_groups = Functional
+testng_excluded_groups = 
 
 j8libDir = j8lib
 j11libDir = j11lib
 resource_dir = resources
 help_parent_dir = help
 help_dir = help
-docDir = doc
-schemaDir = schemas
+doc_dir = doc
 classes_dir = classes
-examplesDir = examples
 clover = false
-use_clover = false
-cloverReportJVMHeap = 2g
-cloverReportJVMArgs = -Dfile.encoding=UTF-8
-cloverReportHTMLOptions = 
-cloverReportXMLOptions =
-cloverClassesDir = clover-classes
-cloverSourcesInstrDir = sources-instr
-packageDir = dist
+clover_classes_dir = clover-classes
+clover_sources_instr_dir = clover-instr
+clover_report_dir = clover-report
+clover_lib_dir = utils/clover/lib
+cloverreport_mem = 2g
+cloverreport_jvmargs = -Dfile.encoding=UTF-8
+cloverreport_html_options = 
+cloverreport_xml_options =
+package_dir = dist
 ARCHIVEDIR =
-outputJar = jalview.jar
 
-testOutputDir = tests
-utilsDir = utils
+test_output_dir = tests
+utils_dir = utils
 
 build_properties_file = .build_properties
 application_codebase = *.jalview.org
-mainClass = jalview.bin.Jalview
-shadowJarMainClass = jalview.bin.Launcher
-launcherClass = jalview.bin.Jalview
+main_class = jalview.bin.Jalview
+shadow_jar_main_class = jalview.bin.Launcher
 
 jalview_name = Jalview
 
index 60db069..1eecfb9 100644 (file)
   parameters, then include it at the beginning of the command line to
   ensure they are processed before any remaining arguments.
   <br>
+  Typical command line execution follows the following pattern:
+  <pre>
+  jalview -open &lt;Alignment File/URL&gt; [additional import arguments] [export arguments]
+  </pre>
+  
   <table width="100%" border="1" cellspacing="0" cellpadding="0">
     <tr>
       <td width="27%"><div align="center">-nodisplay</div></td>
           User Interface. (automatically disables questionnaire, version
           and usage stats checks)</div></td>
     </tr>
-
+    <tr>
+      <td><div align="center">-open FILE/URL</div></td>
+      <td><div align="left">Specify the alignment file to
+          open or process by providing additional arguments.</div></td>
+    </tr>
     <tr>
       <td><div align="center">-props FILE/URL</div></td>
       <td><div align="left">Use the given Jalview properties
           </div>
       </td>
     </tr>
+    <tr>
+      <td><div align="center">-jvmmempc=PERCENT</div></td>
+      <td><div align="left"><em>Only available with standalone executable jar or jalview.bin.Launcher.</em>
+          Limit maximum heap size (memory) to PERCENT% of total physical memory detected.
+         This defaults to 90 if total physical memory can be detected.
+         See <a href="../memory.html">Memory usage settings for Jalview</a> for more details.
+          </div>
+      </td>
+    </tr>
+    <tr>
+      <td><div align="center">-jvmmemmax=MAXMEMORY</div></td>
+      <td><div align="left"><em>Only available with standalone executable jar or jalview.bin.Launcher.</em>
+          Limit maximum heap size (memory) to MAXMEMORY. MAXMEMORY can be specified in bytes, kilobytes(k), megabytes(m),
+         gigabytes(g) or if you're lucky enough, terabytes(t).
+         This defaults to 32g if total physical memory can be detected, or to 8g if total physical memory cannot be detected.
+         See <a href="../memory.html">Memory usage settings for Jalview</a> for more details.
+          </div>
+      </td>
+    </tr>
   </table>
 </body>
 </html>
index e00d390..f0e04d5 100644 (file)
@@ -65,10 +65,31 @@ open /Applications/Jalview.app --args -open ~/myalignment.fa</pre><em>(put
   </p>
   <p>
     <strong>Passing JVM Arguments to Jalview</strong><br /> If you need
-    to modify parameters for Jalview's Java Virtual Machine, then take a
-    look at the instructions for how to <a href="../memory.html#jvm">setting
-      the JVM's maximum memory</a>.
+    to modify parameters for Jalview's Java Virtual Machine, or
+    configure system properties, then take a look at the instructions
+    for how to <a href="../memory.html#jvm">setting the JVM's
+      maximum memory</a>.<br /> 
+  <p>
+    <strong>Changing Jalview's 'Look and Feel'</strong> <br />If you
+    are experiencing issues with the font size or layout of Jalview's
+    GUI, you can try changing Jalview's 'Look and feel' by
+    specifying a custom system property 'laf' on startup (see <a
+      href="../memory.html#jvm">setting the JVM's memory</a> for
+    instructions on how to do this for your platform). <br />For the
+    Jalview standalone executable jar, simply provide one of the
+    property settings before the -jar argument
   </p>
+  <ul>
+    <li>-Dlaf=system (default look and feel for the OS)</li>
+    <li>-Dlaf=crossplatform (Java's Metal Look and Feel)</li>
+    <li>-Dlaf=nimbus (Java's alternative Nimbus Look and Feel)</li>
+    <li>-Dlaf=mac (only has an effect on OSX)</li>
+    <li>-Dlaf=gtk (only has an effect on Linux)</li>
+  </ul>
+  The currently configured look and feel is logged to Jalview's console.
+  Once the look and feel has been changed, it will be stored in
+  Jalview's .jalview_properties file for future Jalview sessions.
+
   <p>&nbsp;</p>
   <p>&nbsp;</p>
 </body>
index eec68ee..837d7b3 100755 (executable)
@@ -36,7 +36,7 @@ td {
   </p>
   <p>The search box is displayed by pressing Control and F or
     selecting &quot;Find...&quot; from the &quot;Search&quot; menu.</p>
-  <img src="search.png" width="398" height="124">
+  <img src="search.png" width="400" height="152">
   <p>&quot;Find next&quot; will find the next occurrence of the
     specified and adjust the alignment window view to show it, and
     &quot;Find all&quot; highlights all matches for a pattern. The
@@ -48,18 +48,19 @@ td {
       of posix and perl style regex - see below for a summary)</li>
     <li>Gaps are ignored when matching the query to the sequences
       in the alignment.</li>
+    <li>Hidden columns can optionally be ignored (<em>since Jalview 2.11</em>)</li>
     <li>The search is applied to both sequences and their IDs, and
       optionally also to the description string (<em>since Jalview
         2.10</em>)
     </li>
     <li>If a region is selected, then search will <strong>only</strong>
-      be performed on that region.
+      be performed on that region.<br />
+    <em>Tip: to quickly clear the current selection, click the
+        alignment view you wish to search, then press 'Escape'.</em>
     </li>
-    <li>To quickly clear the current selection, press the
-      &quot;Escape&quot; key.</li>
     <li>Tick the &quot;Match Case&quot; box to perform a case
       sensitive search.</li>
-    <li>To access a <a ref="#queryhistory">previously used
+    <li>To access a <a href="#queryhistory">previously used
         query</a> press the down arrow or click on the button on the right
       of the text field.
   </ul>
@@ -155,12 +156,13 @@ td {
     stored along with your Jalview user preferences. To open the search
     history, click on the button to the right of the query field, or
     press the down arrow key.</p>
-  <img src="searchhist.png" width="404" height="185" align="left" />
-  <p>The search history keeps up to 99 queries by default. To clear
+  <p><img src="searchhist.png" width="404" height="185" />
+  </p><p>The search history keeps up to 99 queries by default. To clear
     the history, or modify the size of the history, right-click the text
     box.</p>
-  <img src="searchclearhist.png" width="402" height="127" align="left" />
-  <p>
+  <p><img src="searchclearhist.png" width="402" height="127"/>
+  </p>
+<p width="100%">
     <strong>Other dialogs that provide a query history</strong>
   </p>
   <p>
index 89adb1a..47c18f4 100644 (file)
Binary files a/help/help/html/features/search.png and b/help/help/html/features/search.png differ
diff --git a/help/help/html/logging.html b/help/help/html/logging.html
new file mode 100644 (file)
index 0000000..2993370
--- /dev/null
@@ -0,0 +1,66 @@
+<html>
+<!--
+ * 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.
+ -->
+<head>
+<title>Logging and Reporting Bugs</title>
+</head>
+<body>
+  <h2>
+    <center>
+      <strong>Logging and Reporting Bugs</strong>
+    </center>
+  </h2>
+  
+  <h3>Logging</h3>
+  <p>
+  Jalview creates logs that can be extremely useful for diagnosing, or help to provide a workaround for, specific problems that you might encounter.
+  </p>
+  <p>
+  The primary place to look for logs is in the <a href="#java_console">Java Console</a> which you can open from within Jalview by going to the <em>Tools</em> menu and checking the box next to <em>Show Java Console</em>.  This option is stored in your Jalview preferences file and so is remembered across Jalview sessions.
+  </p>
+  <p>
+  The Java Console will show you information about what the Jalview application is doing (often in the background) whilst it is running.
+  </p>
+  <p>
+  However, it is possible that some early logging information from when Jalview is initially launched, is not shown in the Java Console:
+  <br/>
+  If you are using a version of Jalview installed from one of our install4j installers, then Jalview's initial launch logging can be found in
+  <pre>JALVIEW_APP_DIR/launcher.log</pre>
+  where <em>JALVIEW_APP_DIR</em> is the directory that Jalview's application was installed into.
+  <br/>
+  For Jalview 2.11.0 onwards:
+  <ul>
+    <li>In Windows this is <em>%APPDATA%\Local\Jalview</em> by default</li>
+    <li>In macOS this is <em>/Applications/Jalview.app/Contents/Resources/app</em> by default</li>
+    <li>In Linux and other Unix OSes this is <em>~/opt/jalview</em> by default</li>
+  </ul>
+  <br/>
+  Whereas if you are using the Jalview executable jar file (also used by bioconda installations) then a minimised launcher will output logging information to STDOUT and STDERR.
+  </p>
+  
+  <h3><a name="java_console">Java Console and Log Level</a></h3>
+  
+  
+  <h3>Reporting Bugs</h3>
+
+
+</body>
+</html>
index 81190a9..0374dcb 100755 (executable)
     <li><em><font size="3">Maximum memory limit</em><br/>
       Since 2.11.1.0, Jalview's configuration includes a 'maximum memory limit':
       <pre>jalview.jvmmemmax = 32G</pre>
-      Adjusting this default (via a JVL file, above) will allow larger amounts of memory to be allocated to Jalview in connjunction with the jalview.jvmmempc setting. 
+      Adjusting this default (via a JVL file, above) will allow larger amounts (or can limit the amount) of memory to be allocated to Jalview in conjunction with the jalview.jvmmempc setting. 
+      <br/><br/>
+    </li>
+    <li><em><font size="3"><a name="jar">Command line arguments when using the executable jar (jalview-all.jar) or jalview.bin.Launcher</a></em><br/>
+      If you are using the Jalview standalone executable jar (usually named <em>jalview-all-....jar</em> with a Jalview and Java version designation) or using <em>jalview.bin.Launcher</em> to start Jalview,
+      then you can set the <em>jvmmempc</em> and <em>jvmmemmax</em> values using application command line arguments <em>-jvmmempc=PERCENT</em>
+      and <em>-jvmmemmax=MAXMEMORY</em> respectively.  <em>PERCENT</em> should be an integer between 1 and 100, and MAXMEMORY should be an amount of memory in bytes, or you can append a "k", "m", "g", or "t" to use units of kilobytes, megabytes, gigabytes or terabytes, e.g.
+      <pre>java -jar jalview-all-2.11.1.0-j1.8.jar -jvmmempc=50 -jvmmemmax=20g</pre>
+      (this example will launch Jalview with a maximum heap size of the smaller of 20GB or 50% of physical memory detected).
+      <br/>The default value for jvmmempc is 90, whilst the default value for jvmmemmax is 32g if Jalview can determine a total physical memory size of the host system, and a more cautious 8g if Jalview is unable to determine a total physical memory size.
+      <br/><br/>
     </li>
     <li><em><font size="3"><a name="jvm"/>Directly opening Jalview
           with a JVM</font></em> <br /> Launching Jalview directly with a JVM is
index 3512375..5d08641 100755 (executable)
@@ -58,7 +58,7 @@ li:before {
     <tr>
       <td width="60" align="center" nowrap><strong><a
           id="Jalview.2.11.1">2.11.1</a><a id="Jalview.2.11.1.1">.1</a><br />
-          <em>13/07/2020</em></strong></td>
+          <em>11/08/2020</em></strong></td>
       <td align="left" valign="top">
         <ul>
           <!-- -->
@@ -76,23 +76,64 @@ li:before {
             improved compatibility with JalviewJS
           </li>
           <li>
-          <!-- JAL-3615 -->Retrieve GZipped stockholm formatted alignments from Pfam and Rfam
+            <!-- JAL-3615 -->Retrieve GZipped stockholm formatted
+            alignments from Pfam and Rfam
           </li>
           <li>
-          <!-- JAL-2656 -->Recognise GZipped content for URLs and File import (no longer based on .gz extension)
+            <!-- JAL-2656 -->Recognise GZipped content for URLs and File
+            import (no longer based on .gz extension)
+          </li>
+          <li>
+            <!-- JAL-3570 -->Updated Spanish Translation for 2.11.1
+          </li>
+          <li>
+            <!-- JAL-3692 -->Migrate EMBL record retrieval to use latest
+            ENA Browser (https://www.ebi.ac.uk/ena/browser/home) and
+            EMBL flat file
+          </li>
+          <li>
+            <!-- JAL-3667 -->Improved warning messages, debug logging
+            and fixed Retry action when Jalview encounters errors when
+            saving or making backup files.
+          </li>
+          <li>
+            <!-- JAL-3676 -->Enhanced Jalview Java Console:
+            <ul>
+              <li>Jalview's logging level can be configured</li>
+              <li>Copy to Clipboard Buttion</li>
+            </ul>
+          </li>
+          <li>
+            <!-- JAL-3541 -->Improved support for Hi-DPI (4K) screens
+            when running on Linux (Requires Java 11+)
+          </li>
+        </ul> <em>Launching Jalview</em>
+        <ul>
+          <li>
+            <!-- JAL-3608 -->Configure Jalview Desktop's look and feel
+            through a system property
+          </li>
+          <li>
+            <!-- JAL-3477 -->Improved built-in documentation and command
+            line help for configuring Jalview's memory
           </li>
-          <li></li>
         </ul>
       </td>
       <td align="left" valign="top">
         <ul>
           <li>
+            <!-- JAL-3691 -->Conservation and Quality tracks are shown
+            but not calculated and no protein or DNA score models are
+            available for tree/PCA calculation when launched with
+            Turkish language locale
+          </li>
+          <li>
             <!-- JAL-3493 -->Escape does not clear highlights on the
             alignment (Since Jalview 2.10.3)
           </li>
           <li>
             <!--  JAL-3680 -->Alt+Left or Right arrow in cursor mode
-            doesn't slide selected sequences
+            doesn't slide selected sequences, just sequence under cursor
           </li>
           <li>
             <!-- JAL-3613 -->Peptide-to-CDS tracking broken when
@@ -108,6 +149,65 @@ li:before {
             when there are both local and complementary features mapped
             to the position under the cursor
           </li>
+          <li>
+            <!-- JAL-3673 -->Sequence ID for reference sequence is
+            clipped when Right align Sequence IDs enabled
+          </li>
+          <li>
+            <!-- JAL-2983 -->Slider with negative range values not
+            rendered correctly in VAqua4 (Since 2.10.4)
+          </li>
+          <li>
+            <!-- JAL-3685 -->Single quotes not displayed correctly in
+            internationalised text for some messages and log output
+          </li>
+          <li>
+            <!-- JAL-3490 -->Find doesn't report matches that span
+            hidden gapped columns
+          </li>
+          <li>
+            <!-- JAL-3597 -->Resolved memory leaks in Tree and PCA
+            panels, Alignment viewport and annotation renderer.
+          </li>
+          <li>
+            <!-- JAL-3561 -->Jalview ignores file format parameter
+            specifying output format when exporting an alignment via the
+            command line
+          </li>
+        </ul> <em>Developing Jalview</em>
+        <ul>
+          <li>
+            <!-- JAL-3541 -->Fixed issue with cleaning up old coverage
+            data, causing cloverReport gradle task to fail with an
+            OutOfMemory error.
+          </li>
+        </ul> <em>New Known defects</em>
+        <ul>
+          <li>
+            <!-- JAL-3576 -->Co-located features exported and re-imported
+            are ordered differently when shown on alignment and in
+            tooltips. (Also affects v2.11.1.0)
+          </li>
+          <li>
+            <!-- JAL-3667 -->Windows 10: For a minority of users, if
+            backups are not enabled, Jalview sometimes fails to
+            overwrite an existing file and raises a warning dialog.
+            Workaround is to try to save the file again, and if that
+            fails, delete the original file and save in place.
+          </li>
+          <li>
+            <!-- JAL-3702 -->Drag and drop of alignment file onto
+            alignment window not working correctly when in a HiDPI
+            scaled mode in Linux
+          </li>
+          <li>
+            <!-- JAL-3701 -->Stale build data in jalview standalone jar
+            builds (only affects 2.11.1.1 branch)
+          </li>
+          <li>
+            <!-- JAL-3127 -->Sequence ID colourscheme not re-applied
+            when alignment view restored from project (since Jalview 2.11.0)
+          </li>
         </ul>
       </td>
     </tr>
index a4b24ed..496fad0 100644 (file)
@@ -377,7 +377,7 @@ label.example = Example
 label.example_param = Example: {0}
 label.select_file_format_before_saving = You must select a file format before saving!
 label.file_format_not_specified = File format not specified
-label.couldnt_save_file = Couldn't save file: {0}
+label.couldnt_save_file = Couldn''t save file: {0}
 label.error_saving_file = Error Saving File
 label.remove_from_default_list = Remove from default list?
 label.remove_user_defined_colour = Remove user defined colour
@@ -406,11 +406,11 @@ label.pdb_entries_couldnt_be_retrieved = The following pdb entries could not be
 label.couldnt_load_file = Couldn't load file
 label.couldnt_find_pdb_id_in_file = Couldn't find a PDB id in the file supplied. Please enter an Id to identify this structure.
 label.no_pdb_id_in_file = No PDB Id in File
-label.couldnt_read_pasted_text = Couldn't read the pasted text {0}
+label.couldnt_read_pasted_text = Couldn''t read the pasted text {0}
 label.error_parsing_text = Error parsing text
 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.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 = Could not locate {0}
 label.url_not_found = URL not found
@@ -855,7 +855,7 @@ label.invalid_name = Invalid name
 label.set_proxy_settings = Please set up your proxy settings in the 'Connections' tab of the Preferences window
 label.proxy_authorization_failed = Proxy Authorization Failed
 label.internal_jalview_error = Internal Jalview Error
-label.secondary_structure_prediction_service_couldnt_be_located = The Secondary Structure Prediction Service named {0} at {1} couldn't be located.
+label.secondary_structure_prediction_service_couldnt_be_located = The Secondary Structure Prediction Service named {0} at {1} couldn''t be located.
 label.service_called_is_not_msa_service = The Service called \n{0}\nis not a \nMultiple Sequence Alignment Service\!
 label.msa_service_is_unknown = The Multiple Sequence Alignment Service named {0} is unknown
 label.service_called_is_not_seq_search_service = The Service called \n{0}\nis not a \nSequence Search Service\!
@@ -985,7 +985,7 @@ error.cannot_set_arguments_to_jabaws_param_set = Cannot set arguments to a JabaW
 error.implementation_error_runner_config_not_available = Implementation Error: Runner Config not available for a JABAWS service of type {0} ({1})
 error.implementation_error_cannot_handle_jaba_param = Implementation Error: Cannot handle Jaba parameter object {0}
 error.implementation_error_attempt_to_delete_service_preset = Implementation error: Attempt to delete a service preset!
-error.implementation_error_cannot_locate_oldname_presetname = Implementation error: Can't locate either oldname ({0}) or presetName ({1}in the datastore!"
+error.implementation_error_cannot_locate_oldname_presetname = Implementation error: Can''t locate either oldname ({0}) or presetName ({1}in the datastore!"
 error.implementation_error_jabaws_param_set_only_handled_by = Implementation error: JabaWsParamSets can only be handled by JabaParamStore
 error.cannot_set_source_file_for = Cannot set source file for {0}
 error.mismatch_service_instance_preset = Probable mismatch between service instance and preset!
@@ -993,7 +993,7 @@ error.cannot_set_params_for_ws_preset = Cannot set Parameters for a Jaba Web ser
 error.implementation_error_can_only_instantiate_jaba_param_sets = Implementation error: Can only instantiate Jaba parameter sets
 error.no_aacon_service_found = No AACon service found
 error.implementation_error_couldnt_copy_value_constraint = Implementation error: could not copy ValueConstrain!
-error.couldnt_encode_as_utf8 = Couldn't encode {0} as UTF-8.
+error.couldnt_encode_as_utf8 = Couldn''t encode {0} as UTF-8.
 error.tree_inputtype_not_yet_implemented = Tree InputType not yet implemented
 error.implementation_error_need_to_have_httpresponse = Implementation Error: need to have an HttpResponse to process
 error.dbrefsource_implementation_exception =DBRefSource Implementation Exception
@@ -1049,18 +1049,18 @@ error.implementation_error_reset_called_for_invalid_source = Implementation Erro
 exception.number_of_residues_in_query_sequence_differ_from_prediction = Number of residues in {0} supposed query sequence ({1}\n{2})\ndiffer from number of prediction sites in prediction ({3})
 label.mapped = mapped
 exception.jpredconcide_entry_has_unexpected_number_of_columns = JPredConcise: Entry ({0}) has an unexpected number of columns
-exception.couldnt_parse_concise_annotation_for_prediction = Couldn't parse concise annotation for prediction profile.\n{0}
+exception.couldnt_parse_concise_annotation_for_prediction = Couldn''t parse concise annotation for prediction profile.\n{0}
 exception.newfile = NewickFile\: {0}\n
 label.no_tree_read_in = No Tree read in
-exception.rnaml_couldnt_access_datasource = Couldn't access datasource ({0})
-exception.ranml_couldnt_process_data = Couldn't process data as RNAML file ({0})
+exception.rnaml_couldnt_access_datasource = Couldn''t access datasource ({0})
+exception.ranml_couldnt_process_data = Couldn''t process data as RNAML file ({0})
 exception.ranml_invalid_file = Invalid RNAML file ({0})
 exception.ranml_problem_parsing_data = Problem parsing data as RNAML ({0})
 exception.pfam_no_sequences_found = No sequences found (PFAM input)
 exception.stockholm_invalid_format = This file is not in valid STOCKHOLM format: First line does not contain '# STOCKHOLM'
 exception.couldnt_parse_sequence_line = Could not parse sequence line: {0}
 exception.unknown_annotation_detected = Unknown annotation detected: {0} {1}
-exception.couldnt_store_sequence_mappings = Couldn't store sequence mappings for {0}
+exception.couldnt_store_sequence_mappings = Couldn''t store sequence mappings for {0}
 exception.matrix_too_many_iteration = Too many iterations in {0} (max is {1})
 exception.browser_not_found = Exception in finding browser: {0}
 exception.browser_unable_to_locate = Unable to locate browser: {0}
@@ -1071,7 +1071,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.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
 exception.couldnt_recover_sequence_properties_for_alignment = Couldn't recover sequence properties for alignment
@@ -1094,7 +1093,7 @@ warn.service_not_supported = Service not supported!
 warn.input_is_too_big = Input is too big!
 warn.invalid_job_param_set = Invalid job parameter set!
 warn.oneseq_msainput_selection = The current selection only contains a single sequence. Do you want to submit all sequences for alignment instead ?   
-info.job_couldnt_be_run_server_doesnt_support_program = Job could not be run because the server doesn't support this program.\n{0}
+info.job_couldnt_be_run_server_doesnt_support_program = Job could not be run because the server doesn''t support this program.\n{0}
 info.job_couldnt_be_run_exceeded_hard_limit = Job could not be run because it exceeded a hard limit on the server.\n{0}
 info.job_couldnt_be_run_incorrect_param_setting = Job could not be run because some of the parameter settings are not supported by the server.\n{0}\nPlease check to make sure you have used the correct parameter set for this service\!\n
 info.no_jobs_ran = No jobs ran
@@ -1346,6 +1345,7 @@ 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.continue_operation = Continue operation?
 label.backups = Backups
 label.backup = Backup
 label.backup_files = Backup Files
@@ -1412,3 +1412,9 @@ label.include_linked_features = Include {0} features
 label.include_linked_tooltip = Include visible {0} features<br>converted to local sequence coordinates
 label.features_not_shown = {0} feature(s) not shown
 label.no_features_to_sort_by = No features to sort by
+label.log_level = Log level
+label.log_level_tooltip = Temporarily set the log level for this console. The log level will revert to {0} when this Java console is closed.
+label.copy_to_clipboard = Copy to clipboard
+label.copy_to_clipboard_tooltip = Copy all of the log text in this console to the system clipboard
+label.ignore_hidden = Ignore hidden columns
+label.ignore_hidden_tooltip = Ignore any characters in hidden columns when matching
index 3d7065b..6364f5e 100644 (file)
@@ -995,7 +995,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.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
 exception.couldnt_recover_sequence_properties_for_alignment = No es posible recuperar las propiedades de la secuencia para el alineamiento
@@ -1347,6 +1346,7 @@ 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.continue_operation = Â¿Continuar operación?
 label.backups = Respaldos
 label.backup = Respaldo
 label.backup_files = Archivos de respaldos
@@ -1413,3 +1413,9 @@ label.include_linked_features = Incluir caracter
 label.include_linked_tooltip = Incluir características de {0}<br>convertidas a coordenadas de secuencia local
 label.features_not_shown = {0} característica(s) no mostradas
 label.no_features_to_sort_by = No hay características para ordenar
+label.log_level = Nivel del registro
+label.log_level_tooltip = Establezca temporalmente el nivel de registro para esta consola. El nivel de registro volverá a {0} cuando se cierre esta consola de Java.
+label.copy_to_clipboard = Copiar en el portapapeles
+label.copy_to_clipboard_tooltip = Copie todo el texto de registro en esta consola al portapapeles del sistema
+label.ignore_hidden = Ignorar columnas ocultas
+label.ignore_hidden_tooltip = Ignorar caracteres en columnas ocultas
index 3cbef6d..c545c7f 100644 (file)
@@ -23,17 +23,18 @@ 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 jalview.util.MapList;
 
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
 import java.util.List;
-import java.util.Vector;
 
 import com.stevesoft.pat.Regex;
 
@@ -50,7 +51,7 @@ public class Finder implements FinderI
   /*
    * sequences matched by id or description
    */
-  private Vector<SequenceI> idMatches;
+  private List<SequenceI> idMatches;
 
   /*
    * the viewport to search over
@@ -63,11 +64,24 @@ public class Finder implements FinderI
   private int sequenceIndex;
 
   /*
-   * 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)
+   * position offset in sequence to search from, base 0
+   * (position after start of last match for a 'find next')
    */
-  private int columnIndex;
+  private int residueIndex;
+
+  /*
+   * the true sequence position of the start of the 
+   * last sequence searched (when 'ignore hidden regions' does not apply)
+   */
+  private int searchedSequenceStartPosition;
+
+  /*
+   * when 'ignore hidden regions' applies, this holds the mapping from
+   * the visible sequence positions (1, 2, ...) to true sequence positions
+   */
+  private MapList searchedSequenceMap;
+
+  private String seqToSearch;
 
   /**
    * Constructor for searching a viewport
@@ -78,33 +92,35 @@ public class Finder implements FinderI
   {
     this.viewport = av;
     this.sequenceIndex = 0;
-    this.columnIndex = -1;
+    this.residueIndex = -1;
   }
 
   @Override
   public void findAll(String theSearchString, boolean matchCase,
-          boolean searchDescription)
+          boolean searchDescription, boolean ignoreHidden)
   {
     /*
      * search from the start
      */
     sequenceIndex = 0;
-    columnIndex = -1;
+    residueIndex = -1;
 
-    doFind(theSearchString, matchCase, searchDescription, true);
+    doFind(theSearchString, matchCase, searchDescription, true,
+            ignoreHidden);
 
     /*
      * reset to start for next search
      */
     sequenceIndex = 0;
-    columnIndex = -1;
+    residueIndex = -1;
   }
 
   @Override
   public void findNext(String theSearchString, boolean matchCase,
-          boolean searchDescription)
+          boolean searchDescription, boolean ignoreHidden)
   {
-    doFind(theSearchString, matchCase, searchDescription, false);
+    doFind(theSearchString, matchCase, searchDescription, false,
+            ignoreHidden);
     
     if (searchResults.isEmpty() && idMatches.isEmpty())
     {
@@ -112,7 +128,7 @@ public class Finder implements FinderI
        * search failed - reset to start for next search
        */
       sequenceIndex = 0;
-      columnIndex = -1;
+      residueIndex = -1;
     }
   }
 
@@ -123,18 +139,19 @@ public class Finder implements FinderI
    * @param matchCase
    * @param searchDescription
    * @param findAll
+   * @param ignoreHidden
    */
   protected void doFind(String theSearchString, boolean matchCase,
-          boolean searchDescription, boolean findAll)
+          boolean searchDescription, boolean findAll, boolean ignoreHidden)
   {
+    searchResults = new SearchResults();
+    idMatches = new ArrayList<>();
+
     String searchString = matchCase ? theSearchString
             : theSearchString.toUpperCase();
     Regex searchPattern = new Regex(searchString);
     searchPattern.setIgnoreCase(!matchCase);
 
-    searchResults = new SearchResults();
-    idMatches = new Vector<>();
-
     SequenceGroup selection = viewport.getSelectionGroup();
     if (selection != null && selection.getSize() < 1)
     {
@@ -144,108 +161,202 @@ public class Finder implements FinderI
     AlignmentI alignment = viewport.getAlignment();
     int end = alignment.getHeight();
 
-    while (sequenceIndex < end)
+    getSequence(ignoreHidden);
+
+    boolean found = false;
+    while ((!found || findAll) && sequenceIndex < end)
     {
-      SequenceI seq = alignment.getSequenceAt(sequenceIndex);
-      boolean found = findNextMatch(seq, searchString, searchPattern,
-              searchDescription);
-      if (found && !findAll)
+      found = findNextMatch(searchString, searchPattern, searchDescription,
+              ignoreHidden);
+    }
+  }
+
+  /**
+   * Calculates and saves the sequence string to search. The string is restricted
+   * to the current selection region if there is one, and is saved with all gaps
+   * removed.
+   * <p>
+   * If there are hidden columns, and option {@ignoreHidden} is selected, then
+   * only visible positions of the sequence are included, and a mapping is also
+   * constructed from the returned string positions to the true sequence
+   * positions.
+   * <p>
+   * Note we have to do this each time {@code findNext} or {@code findAll} is
+   * called, in case the alignment, selection group or hidden columns have
+   * changed. In particular, if the sequence at offset {@code sequenceIndex} in
+   * the alignment is (no longer) in the selection group, search is advanced to
+   * the next sequence that is.
+   * <p>
+   * Sets sequence string to the empty string if there are no more sequences (in
+   * selection group if any) at or after {@code sequenceIndex}.
+   * <p>
+   * Returns true if a sequence could be found, false if end of alignment was
+   * reached
+   * 
+   * @param ignoreHidden
+   * @return
+   */
+  private boolean getSequence(boolean ignoreHidden)
+  {
+    AlignmentI alignment = viewport.getAlignment();
+    if (sequenceIndex >= alignment.getHeight())
+    {
+      seqToSearch = "";
+      return false;
+    }
+    SequenceI seq = alignment.getSequenceAt(sequenceIndex);
+    SequenceGroup selection = viewport.getSelectionGroup();
+    if (selection != null && !selection.contains(seq))
+    {
+      if (!nextSequence(ignoreHidden))
       {
-        return;
+        return false;
       }
-      if (!found)
+      seq = alignment.getSequenceAt(sequenceIndex);
+    }
+
+    String seqString = null;
+    if (ignoreHidden)
+    {
+      seqString = getVisibleSequence(seq);
+      this.searchedSequenceStartPosition = 1;
+    }
+    else
+    {
+      int startCol = 0;
+      int endCol = seq.getLength() - 1;
+      this.searchedSequenceStartPosition = seq.getStart();
+      if (selection != null)
       {
-        sequenceIndex++;
-        columnIndex = -1;
+        startCol = selection.getStartRes();
+        endCol = Math.min(endCol, selection.getEndRes());
+        this.searchedSequenceStartPosition = seq.findPosition(startCol);
       }
+      seqString = seq.getSequenceAsString(startCol, endCol + 1);
     }
+
+    /*
+     * remove gaps; note that even if this leaves an empty string, we 'search'
+     * the sequence anyway (for possible match on name or description)
+     */
+    String ungapped = AlignSeq.extractGaps(Comparison.GapChars, seqString);
+    this.seqToSearch = ungapped;
+
+    return true;
   }
 
   /**
-   * 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>.
+   * Returns a string consisting of only the visible residues of {@code seq} from
+   * alignment column {@ fromColumn}, restricted to the current selection region
+   * if there is one.
+   * <p>
+   * As a side-effect, also computes the mapping from the true sequence positions
+   * to the positions (1, 2, ...) of the returned sequence. This is to allow
+   * search matches in the visible sequence to be converted to sequence positions.
+   * 
+   * @param seq
+   * @return
    */
-  protected Range getNextVisibleSequenceRegion(SequenceI sequence,
-          int column)
+  private String getVisibleSequence(SequenceI seq)
   {
-    int seqColStart = column;
-    int seqColEnd = sequence.getLength() - 1;
-
     /*
-     * restrict search to (next) visible column region, 
-     * in case there are hidden columns
+     * get start / end columns of sequence and convert to base 0
+     * (so as to match the visible column ranges)
      */
-    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]);
+    int seqStartCol = seq.findIndex(seq.getStart()) - 1;
+    int seqEndCol = seq.findIndex(seq.getStart() + seq.getLength() - 1) - 1;
+    Iterator<int[]> visibleColumns = viewport.getViewAsVisibleContigs(true);
+    StringBuilder visibleSeq = new StringBuilder(seqEndCol - seqStartCol);
+    List<int[]> fromRanges = new ArrayList<>();
 
-    /*
-     * restrict search to selected region if there is one
-     */
-    SequenceGroup selection = viewport.getSelectionGroup();
-    if (selection != null)
+    while (visibleColumns.hasNext())
     {
-      int selectionStart = selection.getStartRes();
-      int selectionEnd = selection.getEndRes();
-      if (selectionStart > seqColEnd || selectionEnd < seqColStart)
+      int[] range = visibleColumns.next();
+      if (range[0] > seqEndCol)
+      {
+        // beyond the end of the sequence
+        break;
+      }
+      if (range[1] < seqStartCol)
+      {
+        // before the start of the sequence
+        continue;
+      }
+      String subseq = seq.getSequenceAsString(range[0], range[1] + 1);
+      String ungapped = AlignSeq.extractGaps(Comparison.GapChars, subseq);
+      visibleSeq.append(ungapped);
+      if (!ungapped.isEmpty())
       {
         /*
-         * sequence region doesn't overlap selection region 
+         * visible region includes at least one non-gap character,
+         * so add the range to the mapping being constructed
          */
-        columnIndex = seqColEnd + 1;
-        return null;
+        int seqResFrom = seq.findPosition(range[0]);
+        int seqResTo = seqResFrom + ungapped.length() - 1;
+        fromRanges.add(new int[] { seqResFrom, seqResTo });
       }
-      seqColStart = Math.max(seqColStart, selectionStart);
-      seqColEnd = Math.min(seqColEnd, selectionEnd);
     }
 
-    return new Range(seqColStart, seqColEnd);
+    /*
+     * construct the mapping
+     * from: visible sequence positions 1..length
+     * to:   true residue positions of the alignment sequence
+     */
+    List<int[]> toRange = Arrays
+            .asList(new int[]
+            { 1, visibleSeq.length() });
+    searchedSequenceMap = new MapList(fromRanges, toRange, 1, 1);
+
+    return visibleSeq.toString();
   }
 
   /**
-   * 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.
+   * Advances the search to the next sequence in the alignment. Sequences not in
+   * the current selection group (if there is one) are skipped. The (sub-)sequence
+   * to be searched is extracted, gaps removed, and saved, or set to null if there
+   * are no more sequences to search.
+   * <p>
+   * Returns true if a sequence could be found, false if end of alignment was
+   * reached
    * 
-   * @param seq
+   * @param ignoreHidden
+   */
+  private boolean nextSequence(boolean ignoreHidden)
+  {
+    sequenceIndex++;
+    residueIndex = -1;
+
+    return getSequence(ignoreHidden);
+  }
+
+  /**
+   * Finds the next match in the given sequence, starting at offset
+   * {@code residueIndex}. Answers true if a match is found, else false.
+   * <p>
+   * If a match is found, {@code residueIndex} is advanced to the position after
+   * the start of the matched region, ready for the next search.
+   * <p>
+   * If no match is found, {@code sequenceIndex} is advanced ready to search the
+   * next sequence.
+   * 
+   * @param seqToSearch
    * @param searchString
    * @param searchPattern
    * @param matchDescription
+   * @param ignoreHidden
    * @return
    */
-  protected boolean findNextMatch(SequenceI seq, String searchString,
-          Regex searchPattern, boolean matchDescription)
+  protected boolean findNextMatch(String searchString,
+          Regex searchPattern, boolean matchDescription,
+          boolean ignoreHidden)
   {
-    SequenceGroup selection = viewport.getSelectionGroup();
-    if (selection != null && !selection.contains(seq))
-    {
-      /*
-       * this sequence is not in the selection - advance to next sequence
-       */
-      return false;
-    }
-
-    if (columnIndex < 0)
+    if (residueIndex < 0)
     {
       /*
        * at start of sequence; try find by residue number, in sequence id,
        * or (optionally) in sequence description
        */
-      if (doNonMotifSearches(seq, searchString, searchPattern,
+      if (doNonMotifSearches(searchString, searchPattern,
               matchDescription))
       {
         return true;
@@ -255,83 +366,66 @@ public class Finder implements FinderI
     /*
      * search for next match in sequence string
      */
-    int end = seq.getLength();
-    while (columnIndex < end)
+    int end = seqToSearch.length();
+    while (residueIndex < end)
     {
-      if (searchNextVisibleRegion(seq, searchPattern))
+      boolean matched = searchPattern.searchFrom(seqToSearch, residueIndex);
+      if (matched)
       {
-        return true;
+        if (recordMatch(searchPattern, ignoreHidden))
+        {
+          return true;
+        }
+      }
+      else
+      {
+        residueIndex = Integer.MAX_VALUE;
       }
-    }
-    return false;
-  }
-
-  /**
-   * 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
-   */
-  protected boolean searchNextVisibleRegion(SequenceI seq, Regex searchPattern)
-  {
-    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);
-
-    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;
     }
 
+    nextSequence(ignoreHidden);
     return false;
   }
 
   /**
    * 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
+   * recorded. <code>residueIndex</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.
+   * <p>
+   * Matches that lie entirely within hidden regions of the alignment are not
+   * added.
    * 
-   * @param seq
    * @param searchPattern
-   * @param firstResiduePosition
+   * @param ignoreHidden
    * @return
    */
-  protected boolean recordMatch(SequenceI seq, Regex searchPattern,
-          int firstResiduePosition)
+  protected boolean recordMatch(Regex searchPattern, boolean ignoreHidden)
   {
+    SequenceI seq = viewport.getAlignment().getSequenceAt(sequenceIndex);
+
     /*
-     * get start/end of the match in sequence coordinates
+     * convert start/end of the match to sequence coordinates
      */
     int offset = searchPattern.matchedFrom();
-    int matchStartPosition = firstResiduePosition + offset;
+    int matchStartPosition = this.searchedSequenceStartPosition + offset;
     int matchEndPosition = matchStartPosition
             + searchPattern.charsMatched() - 1;
 
     /*
-     * update columnIndex to next column after the start of the match
+     * update residueIndex to next position after the start of the match
      * (findIndex returns a value base 1, columnIndex is held base 0)
      */
-    columnIndex = seq.findIndex(matchStartPosition);
+    residueIndex += offset + 1;
+
+    /*
+     * return false if the match is entirely in a hidden region
+     */
+    if (allHidden(seq, matchStartPosition, matchEndPosition))
+    {
+      return false;
+    }
 
     /*
      * check that this match is not a subset of the previous one (JAL-2302)
@@ -343,7 +437,7 @@ public class Finder implements FinderI
     if (lastMatch == null || !lastMatch.contains(seq, matchStartPosition,
             matchEndPosition))
     {
-      searchResults.addResult(seq, matchStartPosition, matchEndPosition);
+      addMatch(seq, matchStartPosition, matchEndPosition, ignoreHidden);
       return true;
     }
 
@@ -351,6 +445,60 @@ public class Finder implements FinderI
   }
 
   /**
+   * Adds one match to the stored list. If hidden residues are being skipped, then
+   * the match may need to be split into contiguous positions of the sequence (so
+   * it does not include skipped residues).
+   * 
+   * @param seq
+   * @param matchStartPosition
+   * @param matchEndPosition
+   * @param ignoreHidden
+   */
+  private void addMatch(SequenceI seq, int matchStartPosition,
+          int matchEndPosition, boolean ignoreHidden)
+  {
+    if (!ignoreHidden)
+    {
+      /*
+       * simple case
+       */
+      searchResults.addResult(seq, matchStartPosition, matchEndPosition);
+      return;
+    }
+
+    /*
+     *  get start-end contiguous ranges in underlying sequence
+     */
+    int[] truePositions = searchedSequenceMap
+            .locateInFrom(matchStartPosition, matchEndPosition);
+    searchResults.addResult(seq, truePositions);
+  }
+
+  /**
+   * Returns true if all residues are hidden, else false
+   * 
+   * @param seq
+   * @param fromPos
+   * @param toPos
+   * @return
+   */
+  private boolean allHidden(SequenceI seq, int fromPos, int toPos)
+  {
+    if (!viewport.hasHiddenColumns())
+    {
+      return false;
+    }
+    for (int res = fromPos; res <= toPos; res++)
+    {
+      if (isVisible(seq, res))
+      {
+        return false;
+      }
+    }
+    return true;
+  }
+
+  /**
    * Does searches other than for residue patterns. Currently this includes
    * <ul>
    * <li>find residue by position (if search string is a number)</li>
@@ -359,24 +507,29 @@ public class Finder implements FinderI
    * </ul>
    * Answers true if a match is found, else false.
    * 
-   * @param seq
    * @param searchString
    * @param searchPattern
    * @param includeDescription
    * @return
    */
-  protected boolean doNonMotifSearches(SequenceI seq, String searchString,
+  protected boolean doNonMotifSearches(String searchString,
           Regex searchPattern, boolean includeDescription)
   {
+    SequenceI seq = viewport.getAlignment().getSequenceAt(sequenceIndex);
+
     /*
      * position sequence search to start of sequence
      */
-    columnIndex = 0;
-
-    if (searchForResidueNumber(seq, searchString))
+    residueIndex = 0;
+    try
     {
-      return true;
+      int res = Integer.parseInt(searchString);
+      return searchForResidueNumber(seq, res);
+    } catch (NumberFormatException ex)
+    {
+      // search pattern is not a number
     }
+
     if (searchSequenceName(seq, searchPattern))
     {
       return true;
@@ -402,7 +555,7 @@ public class Finder implements FinderI
     String desc = seq.getDescription();
     if (desc != null && searchPattern.search(desc) && !idMatches.contains(seq))
     {
-      idMatches.addElement(seq);
+      idMatches.add(seq);
       return true;
     }
     return false;
@@ -421,45 +574,56 @@ public class Finder implements FinderI
   {
     if (searchPattern.search(seq.getName()) && !idMatches.contains(seq))
     {
-      idMatches.addElement(seq);
+      idMatches.add(seq);
       return true;
     }
     return false;
   }
 
   /**
-   * 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
+   * If the residue position is valid for the sequence, and in a visible column,
+   * adds the position to the search results and returns true, else answers false.
+   * 
+   * @param seq
+   * @param resNo
+   * @return
    */
-  protected boolean searchForResidueNumber(SequenceI seq, String searchString)
+  protected boolean searchForResidueNumber(SequenceI seq, int resNo)
   {
-    try
+    if (seq.getStart() <= resNo && seq.getEnd() >= resNo)
     {
-      int res = Integer.parseInt(searchString);
-      if (seq.getStart() <= res && seq.getEnd() >= res)
+      if (isVisible(seq, resNo))
       {
-        searchResults.addResult(seq, res, res);
+        searchResults.addResult(seq, resNo, resNo);
         return true;
       }
-    } catch (NumberFormatException ex)
-    {
     }
     return false;
   }
 
-  /* (non-Javadoc)
-   * @see jalview.analysis.FinderI#getIdMatch()
+  /**
+   * Returns true if the residue is in a visible column, else false
+   * 
+   * @param seq
+   * @param res
+   * @return
    */
+  private boolean isVisible(SequenceI seq, int res)
+  {
+    if (!viewport.hasHiddenColumns())
+    {
+      return true;
+    }
+    int col = seq.findIndex(res); // base 1
+    return viewport.getAlignment().getHiddenColumns().isVisible(col - 1); // base 0
+  }
+
   @Override
-  public Vector<SequenceI> getIdMatches()
+  public List<SequenceI> getIdMatches()
   {
     return idMatches;
   }
 
-  /* (non-Javadoc)
-   * @see jalview.analysis.FinderI#getSearchResults()
-   */
   @Override
   public SearchResultsI getSearchResults()
   {
index 785dd14..56d25d5 100644 (file)
@@ -38,6 +38,7 @@ import jalview.viewmodel.ViewportRanges;
 import java.awt.Color;
 import java.awt.Font;
 import java.util.Hashtable;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
@@ -528,4 +529,16 @@ public interface AlignViewportI extends ViewStyleI
    *          - a group defined on sequences in the alignment held by the view
    */
   void addSequenceGroup(SequenceGroup sequenceGroup);
+
+  /**
+   * Returns an interator over the [start, end] column positions of the visible
+   * regions of the alignment
+   * 
+   * @param selectedRegionOnly
+   *                             if true, and the view has a selection region,
+   *                             then only the intersection of visible columns
+   *                             with the selection region is returned
+   * @return
+   */
+  Iterator<int[]> getViewAsVisibleContigs(boolean selectedRegionOnly);
 }
index 71b35ef..8f6232e 100644 (file)
@@ -34,35 +34,48 @@ 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().
+   * 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().
+   * <p>
+   * If {@code ignoreHidden} is true, then any residues in hidden columns are
+   * ignored (skipped) when matching, so for example pattern {@code KRT} would
+   * match sequence {@code KRqmT} (where {@code qm} are in hidden columns).
+   * <p>
+   * Matches of entirely hidden patterns are not returned. Matches that span
+   * hidden regions on one or both sides may be returned.
    * 
    * @param theSearchString
    * @param caseSensitive
    * @param searchDescription
+   * @param ignoreHidden
    * @return
    */
   void findAll(String theSearchString, boolean caseSensitive,
-          boolean searchDescription);
+          boolean searchDescription, boolean ignoreHidden);
 
   /**
    * 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.
+   * 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().
+   * <p>
+   * If {@code ignoreHidden} is true, any hidden residues are skipped (matches may
+   * span them). If false, they are included for matching purposes. In either
+   * cases, entirely hidden matches are not returned.
    * 
    * @param theSearchString
    * @param caseSensitive
    * @param searchDescription
+   * @param ignoreHidden
    * @return
    */
   void findNext(String theSearchString, boolean caseSensitive,
-          boolean searchDescription);
+          boolean searchDescription, boolean ignoreHidden);
 
   /**
    * Returns the (possibly empty) list of sequences matched on sequence name or
index e9081b0..365f886 100644 (file)
@@ -344,7 +344,7 @@ public class AlignmentPanel extends Panel
           int verticalOffset, boolean redrawOverview, boolean centre)
   {
     // do we need to scroll the panel?
-    if (results != null && results.getSize() > 0)
+    if (results != null && results.getCount() > 0)
     {
       AlignmentI alignment = av.getAlignment();
       int seqIndex = alignment.findIndex(results);
index 2fc3441..a78e41c 100644 (file)
@@ -171,11 +171,13 @@ public class Finder extends Panel implements ActionListener
     boolean doSearchDescription = searchDescription.getState();
     if (doFindAll)
     {
-      finder.findAll(searchString, isCaseSensitive, doSearchDescription);
+      finder.findAll(searchString, isCaseSensitive, doSearchDescription,
+              false);
     }
     else
     {
-      finder.findNext(searchString, isCaseSensitive, doSearchDescription);
+      finder.findNext(searchString, isCaseSensitive, doSearchDescription,
+              false);
     }
 
     searchResults = finder.getSearchResults();
@@ -209,13 +211,13 @@ public class Finder extends Panel implements ActionListener
         String message = (idMatches.size() > 0) ? "" + idMatches.size() + " IDs"
                 : "";
         if (idMatches.size() > 0 && searchResults != null
-                && searchResults.getSize() > 0)
+                && searchResults.getCount() > 0)
         {
           message += " and ";
         }
         if (searchResults != null)
         {
-          message += searchResults.getSize() + " subsequence matches.";
+          message += searchResults.getCount() + " subsequence matches.";
         }
         ap.alignFrame.statusBar.setText(MessageManager
                 .formatMessage("label.search_results", new String[]
index 751461f..ba28717 100755 (executable)
@@ -27,6 +27,8 @@ import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.io.StringWriter;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.util.Collections;
@@ -313,6 +315,9 @@ public class Cache
       // lcastor = Logger.getLogger("org.exolab.castor.xml.Marshaller");
       // lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level",
       // Level.INFO.toString())));
+      // we shouldn't need to do this
+      org.apache.log4j.Logger.getRootLogger().setLevel(org.apache.log4j.Level.INFO); 
+
       jalview.bin.Cache.log.setLevel(Level.toLevel(Cache
               .getDefault("logs.Jalview.level", Level.INFO.toString())));
       // laxis.addAppender(ap);
@@ -440,8 +445,7 @@ public class Cache
     String jnlpVersion = System.getProperty("jalview.version");
 
     // jnlpVersion will be null if a latest version check for the channel needs
-    // to
-    // be done
+    // to be done
     // Dont do this check if running in headless mode
 
     if (jnlpVersion == null && getDefault("VERSION_CHECK", true)
@@ -1104,20 +1108,23 @@ public class Cache
   public static String getVersionDetailsForConsole()
   {
     StringBuilder sb = new StringBuilder();
-    sb.append("Jalview Version: "
-            + jalview.bin.Cache.getDefault("VERSION", "TEST"));
+    sb.append("Jalview Version: ");
+    sb.append(jalview.bin.Cache.getDefault("VERSION", "TEST"));
     sb.append("\n");
-    sb.append("Jalview Installation: "
-            + jalview.bin.Cache.getDefault("INSTALLATION", "unknown"));
+    sb.append("Jalview Installation: ");
+    sb.append(jalview.bin.Cache.getDefault("INSTALLATION", "unknown"));
     sb.append("\n");
-    sb.append("Build Date: "
-            + jalview.bin.Cache.getDefault("BUILD_DATE", "unknown"));
+    sb.append("Build Date: ");
+    sb.append(jalview.bin.Cache.getDefault("BUILD_DATE", "unknown"));
     sb.append("\n");
-    sb.append("Java version: " + System.getProperty("java.version"));
+    sb.append("Java version: ");
+    sb.append(System.getProperty("java.version"));
     sb.append("\n");
-    sb.append(System.getProperty("os.arch") + " "
-            + System.getProperty("os.name") + " "
-            + System.getProperty("os.version"));
+    sb.append(System.getProperty("os.arch"));
+    sb.append(" ");
+    sb.append(System.getProperty("os.name"));
+    sb.append(" ");
+    sb.append(System.getProperty("os.version"));
     sb.append("\n");
     appendIfNotNull(sb, "Install4j version: ",
             System.getProperty("sys.install4jVersion"), "\n", null);
@@ -1126,11 +1133,18 @@ public class Cache
     appendIfNotNull(sb, "Launcher version: ",
             System.getProperty("launcher_version"), "\n", null);
     LookAndFeel laf = UIManager.getLookAndFeel();
-    String lafName = laf == null?"Not obtained":laf.getName();
-    String lafClass = laf == null?"unknown":laf.getClass().getName();
-    appendIfNotNull(sb, "LookAndFeel: ", lafName+" ("+lafClass+")", "\n", null);
-    // Not displayed in release version ( determined by possible version number regex 9[9.]*9[.-_a9]* )
-    if (Pattern.matches("^\\d[\\d\\.]*\\d[\\.\\-\\w]*$", jalview.bin.Cache.getDefault("VERSION", "TEST"))) {
+    String lafName = laf == null ? "Not obtained" : laf.getName();
+    String lafClass = laf == null ? "unknown" : laf.getClass().getName();
+    sb.append("LookAndFeel: ");
+    sb.append(lafName);
+    sb.append(" (");
+    sb.append(lafClass);
+    sb.append(")\n");
+    // Not displayed in release version ( determined by possible version number
+    // regex 9[9.]*9[.-_a9]* )
+    if (Pattern.matches("^\\d[\\d\\.]*\\d[\\.\\-\\w]*$",
+            jalview.bin.Cache.getDefault("VERSION", "TEST")))
+    {
       appendIfNotNull(sb, "Getdown appdir: ",
               System.getProperty("getdownappdir"), "\n", null);
       appendIfNotNull(sb, "Java home: ", System.getProperty("java.home"),
@@ -1149,4 +1163,12 @@ public class Cache
     // eg 'built from Source' or update channel
     return jalview.bin.Cache.getDefault("INSTALLATION", "unknown");
   }
+
+  public static String getStackTraceString(Throwable t)
+  {
+    StringWriter sw = new StringWriter();
+    PrintWriter pw = new PrintWriter(sw);
+    t.printStackTrace(pw);
+    return sw.toString();
+  }
 }
index 021aad6..341bcba 100755 (executable)
  */
 package jalview.bin;
 
+import jalview.ext.so.SequenceOntology;
+import jalview.gui.AlignFrame;
+import jalview.gui.Desktop;
+import jalview.gui.PromptUserConfig;
+import jalview.io.AppletFormatAdapter;
+import jalview.io.BioJsHTMLOutput;
+import jalview.io.DataSourceType;
+import jalview.io.FileFormat;
+import jalview.io.FileFormatException;
+import jalview.io.FileFormatI;
+import jalview.io.FileFormats;
+import jalview.io.FileLoader;
+import jalview.io.HtmlSvgOutput;
+import jalview.io.IdentifyFile;
+import jalview.io.NewickFile;
+import jalview.io.gff.SequenceOntologyFactory;
+import jalview.schemes.ColourSchemeI;
+import jalview.schemes.ColourSchemeProperty;
+import jalview.util.MessageManager;
+import jalview.util.Platform;
+import jalview.ws.jws2.Jws2Discoverer;
+
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileOutputStream;
@@ -297,90 +319,7 @@ public class Jalview
 
     desktop = null;
 
-    // property laf = "crossplatform", "system", "gtk", "metal" or "mac"
-    // If not set (or chosen laf fails), use the normal SystemLaF and if on Mac,
-    // try Quaqua/Vaqua.
-    String lafProp = System.getProperty("laf");
-    String lafSetting = Cache.getDefault("PREFERRED_LAF", null);
-    String laf = "none";
-    if (lafProp != null)
-    {
-      laf = lafProp;
-    }
-    else if (lafSetting != null)
-    {
-      laf = lafSetting;
-    }
-    boolean lafSet = false;
-    switch (laf)
-    {
-    case "crossplatform":
-      lafSet = setCrossPlatformLookAndFeel();
-      if (!lafSet)
-      {
-        System.err.println("Could not set requested laf=" + laf);
-      }
-      break;
-    case "system":
-      lafSet = setSystemLookAndFeel();
-      if (!lafSet)
-      {
-        System.err.println("Could not set requested laf=" + laf);
-      }
-      break;
-    case "gtk":
-      lafSet = setGtkLookAndFeel();
-    {
-      System.err.println("Could not set requested laf=" + laf);
-    }
-      break;
-    case "metal":
-      lafSet = setMetalLookAndFeel();
-    {
-      System.err.println("Could not set requested laf=" + laf);
-    }
-      break;
-    case "nimbus":
-      lafSet = setNimbusLookAndFeel();
-    {
-      System.err.println("Could not set requested laf=" + laf);
-    }
-      break;
-    case "quaqua":
-      lafSet = setQuaquaLookAndFeel();
-    {
-      System.err.println("Could not set requested laf=" + laf);
-    }
-      break;
-    case "vaqua":
-      lafSet = setVaquaLookAndFeel();
-    {
-      System.err.println("Could not set requested laf=" + laf);
-    }
-      break;
-    case "mac":
-      lafSet = setMacLookAndFeel();
-      if (!lafSet)
-      {
-        System.err.println("Could not set requested laf=" + laf);
-      }
-      break;
-    case "none":
-      break;
-    default:
-      System.err.println("Requested laf=" + laf + " not implemented");
-    }
-    if (!lafSet)
-    {
-      setSystemLookAndFeel();
-      if (Platform.isLinux()) {
-        setMetalLookAndFeel();
-      }
-      if (Platform.isAMac())
-      {
-        setMacLookAndFeel();
-      }
-    }
+    setLookAndFeel();
 
     /*
      * configure 'full' SO model if preferences say to, else use the default (SO
@@ -402,11 +341,13 @@ public class Jalview
         JalviewTaskbar.setTaskbar(this);
       } catch (Exception e)
       {
-        System.out.println("Cannot set Taskbar");
+        Cache.log.info("Cannot set Taskbar");
+        Cache.log.error(e.getMessage());
         // e.printStackTrace();
       } catch (Throwable t)
       {
-        System.out.println("Cannot set Taskbar");
+        Cache.log.info("Cannot set Taskbar");
+        Cache.log.error(t.getMessage());
         // t.printStackTrace();
       }
 
@@ -707,18 +648,34 @@ public class Jalview
             af.createEPS(outputFile);
             continue;
           }
-
-          if (af.saveAlignment(file, format))
-          {
-            System.out.println("Written alignment in " + format
-                    + " format to " + file);
+          FileFormatI outFormat=null;
+          try {
+            outFormat = FileFormats.getInstance().forName(outputFormat);
+          } catch (Exception formatP) {
+            System.out.println("Couldn't parse "+outFormat+" as a valid Jalview format string.");
           }
-          else
+          if (outFormat != null)
           {
-            System.out.println("Error writing file " + file + " in "
-                    + format + " format!!");
+            if (!outFormat.isWritable())
+            {
+              System.out.println(
+                      "This version of Jalview does not support alignment export as "
+                              + outputFormat);
+            }
+            else
+            {
+              if (af.saveAlignment(file, outFormat))
+              {
+                System.out.println("Written alignment in " + format
+                        + " format to " + file);
+              }
+              else
+              {
+                System.out.println("Error writing file " + file + " in "
+                        + format + " format!!");
+              }
+            }
           }
-
         }
 
         while (aparser.getSize() > 0)
@@ -801,33 +758,125 @@ public class Jalview
     }
   }
 
-  private static boolean setCrossPlatformLookAndFeel()
+  private static void setLookAndFeel()
   {
-    boolean set = false;
-    try
+    // property laf = "crossplatform", "system", "gtk", "metal", "nimbus" or
+    // "mac"
+    // If not set (or chosen laf fails), use the normal SystemLaF and if on Mac,
+    // try Quaqua/Vaqua.
+    String lafProp = System.getProperty("laf");
+    String lafSetting = Cache.getDefault("PREFERRED_LAF", null);
+    String laf = "none";
+    if (lafProp != null)
     {
-      UIManager.setLookAndFeel(
-              UIManager.getCrossPlatformLookAndFeelClassName());
-      set = true;
-    } catch (Exception ex)
+      laf = lafProp;
+    }
+    else if (lafSetting != null)
     {
-      System.err.println("Unexpected Look and Feel Exception");
-      ex.printStackTrace();
+      laf = lafSetting;
     }
-    return set;
+    boolean lafSet = false;
+    switch (laf)
+    {
+    case "crossplatform":
+      lafSet = setCrossPlatformLookAndFeel();
+      if (!lafSet)
+      {
+        Cache.log.error("Could not set requested laf=" + laf);
+      }
+      break;
+    case "system":
+      lafSet = setSystemLookAndFeel();
+      if (!lafSet)
+      {
+        Cache.log.error("Could not set requested laf=" + laf);
+      }
+      break;
+    case "gtk":
+      lafSet = setGtkLookAndFeel();
+      if (!lafSet)
+      {
+        Cache.log.error("Could not set requested laf=" + laf);
+      }
+      break;
+    case "metal":
+      lafSet = setMetalLookAndFeel();
+      if (!lafSet)
+      {
+        Cache.log.error("Could not set requested laf=" + laf);
+      }
+      break;
+    case "nimbus":
+      lafSet = setNimbusLookAndFeel();
+      if (!lafSet)
+      {
+        Cache.log.error("Could not set requested laf=" + laf);
+      }
+      break;
+    case "quaqua":
+      lafSet = setQuaquaLookAndFeel();
+      if (!lafSet)
+      {
+        Cache.log.error("Could not set requested laf=" + laf);
+      }
+      break;
+    case "vaqua":
+      lafSet = setVaquaLookAndFeel();
+      if (!lafSet)
+      {
+        Cache.log.error("Could not set requested laf=" + laf);
+      }
+      break;
+    case "mac":
+      lafSet = setMacLookAndFeel();
+      if (!lafSet)
+      {
+        Cache.log.error("Could not set requested laf=" + laf);
+      }
+      break;
+    case "none":
+      break;
+    default:
+      Cache.log.error("Requested laf=" + laf + " not implemented");
+    }
+    if (!lafSet)
+    {
+      setSystemLookAndFeel();
+      if (Platform.isLinux())
+      {
+        setMetalLookAndFeel();
+      }
+      if (Platform.isAMac())
+      {
+        setMacLookAndFeel();
+      }
+    }
+  }
+
+  private static boolean setCrossPlatformLookAndFeel()
+  {
+    return setGenericLookAndFeel(false);
   }
 
   private static boolean setSystemLookAndFeel()
   {
+    return setGenericLookAndFeel(true);
+  }
+
+  private static boolean setGenericLookAndFeel(boolean system)
+  {
     boolean set = false;
     try
     {
-      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
+      UIManager.setLookAndFeel(
+              system ? UIManager.getSystemLookAndFeelClassName()
+                      : UIManager.getCrossPlatformLookAndFeelClassName());
       set = true;
     } catch (Exception ex)
     {
-      System.err.println("Unexpected Look and Feel Exception");
-      ex.printStackTrace();
+      Cache.log.error("Unexpected Look and Feel Exception");
+      Cache.log.error(ex.getMessage());
+      Cache.log.debug(Cache.getStackTraceString(ex));
     }
     return set;
   }
@@ -853,8 +902,9 @@ public class Jalview
       set = true;
     } catch (Exception ex)
     {
-      System.err.println("Unexpected Look and Feel Exception");
-      ex.printStackTrace();
+      Cache.log.error("Unexpected Look and Feel Exception");
+      Cache.log.error(ex.getMessage());
+      Cache.log.debug(Cache.getStackTraceString(ex));
     }
     return set;
   }
@@ -944,6 +994,8 @@ public class Jalview
                     + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
                     + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
                     + "-groovy FILE\tExecute groovy script in FILE, after all other arguments have been processed (if FILE is the text 'STDIN' then the file will be read from STDIN)\n"
+                    + "-jvmmempc=PERCENT\tOnly available with standalone executable jar or jalview.bin.Launcher. Limit maximum heap size (memory) to PERCENT% of total physical memory detected. This defaults to 90 if total physical memory can be detected. See https://www.jalview.org/help/html/memory.html for more details.\n"
+                    + "-jvmmemmax=MAXMEMORY\tOnly available with standalone executable jar or jalview.bin.Launcher. Limit maximum heap size (memory) to MAXMEMORY. MAXMEMORY can be specified in bytes, kilobytes(k), megabytes(m), gigabytes(g) or if you're lucky enough, terabytes(t). This defaults to 32g if total physical memory can be detected, or to 8g if total physical memory cannot be detected. See https://www.jalview.org/help/html/memory.html for more details.\n"
                     + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
   }
 
index 0074d2a..7c3bba7 100755 (executable)
@@ -33,6 +33,7 @@ import java.util.List;
  */
 public class SearchResults implements SearchResultsI
 {
+  private int count;
 
   private List<SearchResultMatchI> matches = new ArrayList<>();
 
@@ -168,11 +169,30 @@ public class SearchResults implements SearchResultsI
     if (!matches.contains(m))
     {
       matches.add(m);
+      count++;
     }
     return m;
   }
 
   @Override
+  public void addResult(SequenceI seq, int[] positions)
+  {
+    /*
+     * we only increment the match count by 1 - or not at all,
+     * if the matches are all duplicates of existing
+     */
+    int beforeCount = count;
+    for (int i = 0; i < positions.length - 1; i += 2)
+    {
+      addResult(seq, positions[i], positions[i + 1]);
+    }
+    if (count > beforeCount)
+    {
+      count = beforeCount + 1;
+    }
+  }
+
+  @Override
   public boolean involvesSequence(SequenceI sequence)
   {
     final int start = sequence.getStart();
@@ -286,9 +306,9 @@ public class SearchResults implements SearchResultsI
   }
 
   @Override
-  public int getSize()
+  public int getCount()
   {
-    return matches.size();
+    return count;
   }
 
   @Override
index 3c3ad4e..c89f363 100644 (file)
@@ -41,6 +41,17 @@ public interface SearchResultsI
   SearchResultMatchI addResult(SequenceI seq, int start, int end);
 
   /**
+   * Adds one ore more [start, end] ranges to the results (unless already added
+   * to avoid duplicates). This method only increments the match count by 1.
+   * This is for the case where a match spans ignored hidden residues - it is
+   * formally two or more contiguous matches, but only counted as one match.
+   * 
+   * @param seq
+   * @param positions
+   */
+  void addResult(SequenceI seq, int[] positions);
+
+  /**
    * adds all match results in the argument to this set
    * 
    * @param toAdd
@@ -74,11 +85,13 @@ public interface SearchResultsI
   int[] getResults(SequenceI sequence, int start, int end);
 
   /**
-   * Returns the number of matches found
+   * Returns the number of matches found. Note that if a match straddles ignored
+   * hidden residues, it is counted as one match, although formally recorded as
+   * two (or more) contiguous matched sequence regions
    * 
    * @return
    */
-  int getSize();
+  int getCount();
 
   /**
    * Returns true if no search result matches are held.
index 232561c..54b2989 100644 (file)
@@ -296,7 +296,7 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI
   private void jbInit() throws Exception
   {
 
-    txt_search = new JvCacheableInputBox<>(getCacheKey());
+    txt_search = new JvCacheableInputBox<>(getCacheKey(), 45);
     populateCmbSearchTargetOptions();
     Integer width = getTempUserPrefs().get("FTSPanel.width") == null ? 800
             : getTempUserPrefs().get("FTSPanel.width");
index d03b2c7..5e16397 100644 (file)
  */
 package jalview.gui;
 
+import java.awt.BorderLayout;
+import java.awt.Component;
+import java.awt.Rectangle;
+import java.awt.Toolkit;
+import java.awt.datatransfer.Clipboard;
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.StringSelection;
+import java.awt.datatransfer.Transferable;
+import java.awt.dnd.DnDConstants;
+import java.awt.dnd.DropTargetDragEvent;
+import java.awt.dnd.DropTargetDropEvent;
+import java.awt.dnd.DropTargetEvent;
+import java.awt.dnd.DropTargetListener;
+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.KeyAdapter;
+import java.awt.event.KeyEvent;
+import java.awt.event.MouseEvent;
+import java.awt.print.PageFormat;
+import java.awt.print.PrinterJob;
+import java.beans.PropertyChangeEvent;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Deque;
+import java.util.Enumeration;
+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;
+import javax.swing.JLayeredPane;
+import javax.swing.JMenu;
+import javax.swing.JMenuItem;
+import javax.swing.JScrollPane;
+import javax.swing.SwingUtilities;
+
 import jalview.analysis.AlignmentSorter;
 import jalview.analysis.AlignmentUtils;
 import jalview.analysis.CrossRef;
@@ -91,6 +139,7 @@ import jalview.schemes.ColourSchemes;
 import jalview.schemes.ResidueColourScheme;
 import jalview.schemes.TCoffeeColourScheme;
 import jalview.util.MessageManager;
+import jalview.util.Platform;
 import jalview.viewmodel.AlignmentViewport;
 import jalview.viewmodel.ViewportRanges;
 import jalview.ws.DBRefFetcher;
@@ -100,53 +149,6 @@ import jalview.ws.jws2.Jws2Discoverer;
 import jalview.ws.jws2.jabaws2.Jws2Instance;
 import jalview.ws.seqfetcher.DbSourceProxy;
 
-import java.awt.BorderLayout;
-import java.awt.Component;
-import java.awt.Rectangle;
-import java.awt.Toolkit;
-import java.awt.datatransfer.Clipboard;
-import java.awt.datatransfer.DataFlavor;
-import java.awt.datatransfer.StringSelection;
-import java.awt.datatransfer.Transferable;
-import java.awt.dnd.DnDConstants;
-import java.awt.dnd.DropTargetDragEvent;
-import java.awt.dnd.DropTargetDropEvent;
-import java.awt.dnd.DropTargetEvent;
-import java.awt.dnd.DropTargetListener;
-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.KeyAdapter;
-import java.awt.event.KeyEvent;
-import java.awt.event.MouseEvent;
-import java.awt.print.PageFormat;
-import java.awt.print.PrinterJob;
-import java.beans.PropertyChangeEvent;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.PrintWriter;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Deque;
-import java.util.Enumeration;
-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;
-import javax.swing.JLayeredPane;
-import javax.swing.JMenu;
-import javax.swing.JMenuItem;
-import javax.swing.JScrollPane;
-import javax.swing.SwingUtilities;
-
 /**
  * DOCUMENT ME!
  * 
@@ -1169,7 +1171,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
 
       statusBar.setText(MessageManager.formatMessage(
               "label.successfully_saved_to_file_in_format", new Object[]
-              { fileName, format }));
+              { file, format }));
 
     }
     else
@@ -1198,39 +1200,66 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       else
       {
         // create backupfiles object and get new temp filename destination
+        Cache.log.trace("ALIGNFRAME making backupfiles object for " + file);
         BackupFiles backupfiles = new BackupFiles(file);
 
         try
         {
-          PrintWriter out = new PrintWriter(
-                  new FileWriter(backupfiles.getTempFilePath()));
+          String tempFilePath = backupfiles.getTempFilePath();
+          Cache.log.trace(
+                  "ALIGNFRAME setting PrintWriter to " + tempFilePath);
+          PrintWriter out = new PrintWriter(new FileWriter(tempFilePath));
+
+          Cache.log.trace(
+                  "ALIGNFRAME about to write to temp file " + tempFilePath);
 
           out.print(output);
+          Cache.log.trace("ALIGNFRAME about to close file");
           out.close();
+          Cache.log.trace("ALIGNFRAME closed file");
           this.setTitle(file);
           statusBar.setText(MessageManager.formatMessage(
                   "label.successfully_saved_to_file_in_format", new Object[]
-                  { fileName, format.getName() }));
+                  { file, format.getName() }));
+        } catch (IOException e)
+        {
+          success = false;
+          Cache.log.error(
+                  "ALIGNFRAME Something happened writing the temp file");
+          Cache.log.error(e.getMessage());
+          Cache.log.debug(Cache.getStackTraceString(e));
+
         } catch (Exception ex)
         {
           success = false;
-          ex.printStackTrace();
+          Cache.log.error(
+                  "ALIGNFRAME Something unexpected happened writing the temp file");
+          Cache.log.error(ex.getMessage());
+          Cache.log.debug(Cache.getStackTraceString(ex));
         }
 
         backupfiles.setWriteSuccess(success);
+        Cache.log.debug("ALIGNFRAME writing temp file was "
+                + (success ? "" : "NOT ") + "successful");
         // do the backup file roll and rename the temp file to actual file
+        Cache.log.trace("ALIGNFRAME about to rollBackupsAndRenameTempFile");
         success = backupfiles.rollBackupsAndRenameTempFile();
+        Cache.log.debug("ALIGNFRAME performed rollBackupsAndRenameTempFile "
+                + (success ? "" : "un") + "successfully");
 
       }
     }
 
     if (!success)
     {
-      JvOptionPane.showInternalMessageDialog(this, MessageManager
-              .formatMessage("label.couldnt_save_file", new Object[]
-              { fileName }),
-              MessageManager.getString("label.error_saving_file"),
-              JvOptionPane.WARNING_MESSAGE);
+      if (!Platform.isHeadless())
+      {
+        JvOptionPane.showInternalMessageDialog(this, MessageManager
+                .formatMessage("label.couldnt_save_file", new Object[]
+                { file }),
+                MessageManager.getString("label.error_saving_file"),
+                JvOptionPane.WARNING_MESSAGE);
+      }
     }
 
     return success;
@@ -2688,15 +2717,14 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   }
 
   /**
-   * DOCUMENT ME!
+   * Opens a Finder dialog
    * 
    * @param e
-   *          DOCUMENT ME!
    */
   @Override
   public void findMenuItem_actionPerformed(ActionEvent e)
   {
-    new Finder();
+    new Finder(alignPanel);
   }
 
   /**
@@ -2737,8 +2765,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"));
     }
 
     /*
@@ -3367,8 +3395,8 @@ 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());
+            viewport, viewport.getAlignment(),
+            viewport.getHiddenRepSequences());
     changeColour(cs);
   }
 
@@ -5695,6 +5723,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   }
 
   private Rectangle lastFeatureSettingsBounds = null;
+
   @Override
   public void setFeatureSettingsGeometry(Rectangle bounds)
   {
index e6ac07e..8e12ff5 100644 (file)
@@ -59,7 +59,6 @@ import java.awt.FontMetrics;
 import java.awt.Rectangle;
 import java.util.ArrayList;
 import java.util.Hashtable;
-import java.util.Iterator;
 import java.util.List;
 
 import javax.swing.JInternalFrame;
@@ -446,31 +445,6 @@ public class AlignViewport extends AlignmentViewport
   }
 
   /**
-   * returns the visible column regions of the alignment
-   * 
-   * @param selectedRegionOnly
-   *          true to just return the contigs intersecting with the selected
-   *          area
-   * @return
-   */
-  public Iterator<int[]> getViewAsVisibleContigs(boolean selectedRegionOnly)
-  {
-    int start = 0;
-    int end = 0;
-    if (selectedRegionOnly && selectionGroup != null)
-    {
-      start = selectionGroup.getStartRes();
-      end = selectionGroup.getEndRes() + 1;
-    }
-    else
-    {
-      end = alignment.getWidth();
-    }
-    return (alignment.getHiddenColumns().getVisContigsIterator(start, end,
-            false));
-  }
-
-  /**
    * get hash of undo and redo list for the alignment
    * 
    * @return long[] { historyList.hashCode, redoList.hashCode };
index 82ec0e7..d941107 100644 (file)
@@ -718,7 +718,7 @@ public class AnnotationColumnChooser extends AnnotationRowFilter
     private static final String FILTER_BY_ANN_CACHE_KEY = "CACHE.SELECT_FILTER_BY_ANNOT";
 
     public JvCacheableInputBox<String> searchBox = new JvCacheableInputBox<>(
-            FILTER_BY_ANN_CACHE_KEY);
+            FILTER_BY_ANN_CACHE_KEY, 23);
 
     public SearchPanel(AnnotationColumnChooser aColChooser)
     {
@@ -728,7 +728,6 @@ public class AnnotationColumnChooser extends AnnotationRowFilter
       this.setBorder(new TitledBorder(
               MessageManager.getString("label.search_filter")));
 
-      searchBox.setPrototypeDisplayValue("XXXXXXXXXXXXXXXXXXXXXXX");
       searchBox.setToolTipText(
               MessageManager.getString("info.enter_search_text_here"));
       searchBox.getEditor().getEditorComponent()
index 4c019a6..6cd8106 100644 (file)
  */
 package jalview.gui;
 
-import jalview.util.MessageManager;
-
 import java.awt.BorderLayout;
+import java.awt.Color;
 import java.awt.Dimension;
 import java.awt.GraphicsEnvironment;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
 import java.awt.Rectangle;
 import java.awt.Toolkit;
+import java.awt.datatransfer.Clipboard;
+import java.awt.datatransfer.StringSelection;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
 import java.awt.event.WindowAdapter;
 import java.awt.event.WindowEvent;
 import java.awt.event.WindowListener;
@@ -38,12 +43,19 @@ import java.io.PipedOutputStream;
 import java.io.PrintStream;
 
 import javax.swing.JButton;
+import javax.swing.JComboBox;
 import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
 import javax.swing.JScrollPane;
 import javax.swing.JTextArea;
 
+import org.apache.log4j.Level;
 import org.apache.log4j.SimpleLayout;
 
+import jalview.bin.Cache;
+import jalview.util.MessageManager;
+
 /**
  * Simple Jalview Java Console. Version 1 - allows viewing of console output
  * after desktop is created. Acquired with thanks from RJHM's site
@@ -88,6 +100,10 @@ public class Console extends WindowAdapter
 
   private int MIN_HEIGHT = 250;
 
+  private JComboBox<Level> logLevelCombo = new JComboBox<Level>();
+
+  protected Level startingLogLevel = Level.INFO;
+
   public Console()
   {
     // create all components and add them
@@ -115,17 +131,107 @@ public class Console extends WindowAdapter
     // textArea = cpt.getTextArea();
     textArea = new JTextArea();
     textArea.setEditable(false);
-    JButton button = new JButton(MessageManager.getString("action.clear"));
+    JButton clearButton = new JButton(
+            MessageManager.getString("action.clear"));
+    JButton copyToClipboardButton = new JButton(
+            MessageManager.getString("label.copy_to_clipboard"));
+    copyToClipboardButton.addActionListener(new ActionListener()
+    {
+      public void actionPerformed(ActionEvent e)
+      {
+        copyConsoleTextToClipboard();
+      }
+    });
+    copyToClipboardButton.addMouseListener(new MouseAdapter()
+    {
+      private Color bg = textArea.getBackground();
+
+      private Color fg = textArea.getForeground();
+
+      public void mousePressed(MouseEvent e)
+      {
+        textArea.setBackground(textArea.getSelectionColor());
+        textArea.setForeground(textArea.getSelectedTextColor());
+      }
+
+      public void mouseReleased(MouseEvent e)
+      {
+        textArea.setBackground(bg);
+        textArea.setForeground(fg);
+      }
+
+    });
+    copyToClipboardButton.setToolTipText(
+            MessageManager.getString("label.copy_to_clipboard_tooltip"));
+
+    JLabel logLevelLabel = new JLabel(
+            MessageManager.getString("label.log_level") + ":");
+
+    // logLevelCombo.addItem(Level.ALL);
+    logLevelCombo.addItem(Level.TRACE);
+    logLevelCombo.addItem(Level.DEBUG);
+    logLevelCombo.addItem(Level.INFO);
+    logLevelCombo.addItem(Level.WARN);
+    // logLevelCombo.addItem(Level.ERROR);
+    // logLevelCombo.addItem(Level.FATAL);
+    // logLevelCombo.addItem(Level.OFF);
+    // set startingLogLevel
+    startingLogLevel = Cache.log == null ? Level.INFO
+            : Cache.log.getLevel();
+    setChosenLogLevelCombo();
+    logLevelCombo.addActionListener(new ActionListener()
+    {
+      public void actionPerformed(ActionEvent e)
+      {
+        if (Cache.log != null)
+        {
+          Cache.log.setLevel((Level) logLevelCombo.getSelectedItem());
+        }
+      }
+
+    });
 
     // frame = cpt;
     frame.getContentPane().setLayout(new BorderLayout());
     frame.getContentPane().add(new JScrollPane(textArea),
             BorderLayout.CENTER);
-    frame.getContentPane().add(button, BorderLayout.SOUTH);
+    JPanel southPanel = new JPanel();
+    southPanel.setLayout(new GridBagLayout());
+
+    JPanel logLevelPanel = new JPanel();
+    logLevelPanel.setAlignmentX(JPanel.LEFT_ALIGNMENT);
+    logLevelPanel.add(logLevelLabel);
+    logLevelPanel.add(logLevelCombo);
+    String logLevelTooltip = MessageManager.formatMessage(
+            "label.log_level_tooltip", startingLogLevel.toString());
+    logLevelLabel.setToolTipText(logLevelTooltip);
+    logLevelCombo.setToolTipText(logLevelTooltip);
+
+    GridBagConstraints gbc = new GridBagConstraints();
+    gbc.gridx = 0;
+    gbc.gridy = 0;
+    gbc.gridwidth = 1;
+    gbc.gridheight = 1;
+    gbc.weightx = 0.1;
+    southPanel.add(logLevelPanel, gbc);
+
+    gbc.gridx++;
+    gbc.weightx = 0.8;
+    gbc.fill = GridBagConstraints.HORIZONTAL;
+    southPanel.add(clearButton, gbc);
+
+    gbc.gridx++;
+    gbc.weightx = 0.1;
+    gbc.fill = GridBagConstraints.NONE;
+    southPanel.add(copyToClipboardButton, gbc);
+
+    southPanel.setVisible(true);
+    frame.getContentPane().add(southPanel, BorderLayout.SOUTH);
     frame.setVisible(visible);
     updateConsole = visible;
     frame.addWindowListener(this);
-    button.addActionListener(this);
+    clearButton.addActionListener(this);
+
     if (redirect)
     {
       redirectStreams();
@@ -151,6 +257,53 @@ public class Console extends WindowAdapter
     textAppender.start();
   }
 
+  private void setChosenLogLevelCombo()
+  {
+    setChosenLogLevelCombo(startingLogLevel);
+  }
+
+  private void setChosenLogLevelCombo(Level setLogLevel)
+  {
+    logLevelCombo.setSelectedItem(setLogLevel);
+    if (!logLevelCombo.getSelectedItem().equals(setLogLevel))
+    {
+      // setLogLevel not (yet) in list
+      if (setLogLevel != null && setLogLevel instanceof Level)
+      {
+        // add new item to list (might be set via .jalview_properties)
+        boolean added = false;
+        for (int i = 0; i < logLevelCombo.getItemCount(); i++)
+        {
+          Level l = (Level) logLevelCombo.getItemAt(i);
+          if (l.isGreaterOrEqual(setLogLevel))
+          {
+            logLevelCombo.insertItemAt(setLogLevel, i);
+            added = true;
+            break;
+          }
+        }
+        if (!added) // lower priority than others or some confusion -- add to
+                    // end of list
+        {
+          logLevelCombo.addItem(setLogLevel);
+        }
+        logLevelCombo.setSelectedItem(setLogLevel);
+      }
+      else
+      {
+        logLevelCombo.setSelectedItem(Level.INFO);
+      }
+    }
+  }
+
+  private void copyConsoleTextToClipboard()
+  {
+    String consoleText = textArea.getText();
+    StringSelection consoleTextSelection = new StringSelection(consoleText);
+    Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
+    cb.setContents(consoleTextSelection, null);
+  }
+
   PipedOutputStream pout = null, perr = null;
 
   public void redirectStreams()
@@ -644,12 +797,19 @@ public class Console extends WindowAdapter
     frame.setVisible(selected);
     if (selected == true)
     {
+      setChosenLogLevelCombo();
       redirectStreams();
       updateConsole = true;
       frame.toFront();
     }
     else
     {
+      // reset log level to what it was before
+      if (Cache.log != null)
+      {
+        Cache.log.setLevel(startingLogLevel);
+      }
+
       unredirectStreams();
       updateConsole = false;
     }
index a4d7ad0..537c323 100755 (executable)
@@ -28,9 +28,9 @@ import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
 import jalview.jbgui.GFinder;
 import jalview.util.MessageManager;
-import jalview.viewmodel.AlignmentViewport;
 
 import java.awt.Dimension;
+import java.awt.Graphics;
 import java.awt.event.ActionEvent;
 import java.awt.event.KeyEvent;
 import java.util.ArrayList;
@@ -65,7 +65,7 @@ public class Finder extends GFinder
 
   private static final int MIN_HEIGHT = 120;
 
-  private static final int MY_HEIGHT = 120;
+  private static final int MY_HEIGHT = 150;
 
   private static final int MY_WIDTH = 400;
 
@@ -82,33 +82,17 @@ public class Finder extends GFinder
 
   private 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. Each Find
-   * or Find Next action will act on whichever viewport has focus at the time.
-   */
-  public Finder()
-  {
-    this(null, null);
-  }
-
   /**
-   * Constructor given an associated viewport and alignment panel. Constructs
-   * and displays an internal frame where the user can enter a search string.
+   * Constructor given an associated alignment panel. Constructs and displays an
+   * internal frame where the user can enter a search string.
    * 
-   * @param viewport
    * @param alignPanel
    */
-  public Finder(AlignmentViewport viewport, AlignmentPanel alignPanel)
+  public Finder(AlignmentPanel alignPanel)
   {
-    av = viewport;
+    av = alignPanel.getAlignViewport();
     ap = alignPanel;
     finders = new HashMap<>();
-    focusfixed = viewport != null;
     frame = new JInternalFrame();
     frame.setContentPane(this);
     frame.setLayer(JLayeredPane.PALETTE_LAYER);
@@ -122,6 +106,7 @@ public class Finder extends GFinder
               }
             });
     addEscapeHandler();
+
     Desktop.addInternalFrame(frame, MessageManager.getString("label.find"),
             MY_WIDTH, MY_HEIGHT);
     frame.setMinimumSize(new Dimension(MIN_WIDTH, MIN_HEIGHT));
@@ -172,13 +157,14 @@ public class Finder extends GFinder
   /**
    * 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
+   * accordingly. Also sets the 'ignore hidden' checkbox disabled if the viewport
+   * has no hidden columns.
    * 
    * @return false if no alignment window was found
    */
   boolean getFocusedViewport()
   {
-    if (focusfixed || Desktop.desktop == null)
+    if (Desktop.desktop == null)
     {
       if (ap != null && av != null)
       {
@@ -198,6 +184,7 @@ public class Finder extends GFinder
       {
         av = ((AlignFrame) alignFrame).viewport;
         ap = ((AlignFrame) alignFrame).alignPanel;
+        ignoreHidden.setEnabled(av.hasHiddenColumns());
         return true;
       }
     }
@@ -274,13 +261,16 @@ public class Finder extends GFinder
 
     boolean isCaseSensitive = caseSensitive.isSelected();
     boolean doSearchDescription = searchDescription.isSelected();
+    boolean skipHidden = ignoreHidden.isSelected();
     if (doFindAll)
     {
-      finder.findAll(searchString, isCaseSensitive, doSearchDescription);
+      finder.findAll(searchString, isCaseSensitive, doSearchDescription,
+              skipHidden);
     }
     else
     {
-      finder.findNext(searchString, isCaseSensitive, doSearchDescription);
+      finder.findNext(searchString, isCaseSensitive, doSearchDescription,
+              skipHidden);
     }
 
     searchResults = finder.getSearchResults();
@@ -314,11 +304,11 @@ public class Finder extends GFinder
                 : "";
         if (searchResults != null)
         {
-          if (idMatch.size() > 0 && searchResults.getSize() > 0)
+          if (idMatch.size() > 0 && searchResults.getCount() > 0)
           {
             message += " and ";
           }
-          message += searchResults.getSize()
+          message += searchResults.getCount()
                   + " subsequence matches found.";
         }
         JvOptionPane.showInternalMessageDialog(this, message, null,
@@ -388,4 +378,15 @@ public class Finder extends GFinder
       ap.alignFrame.requestFocus();
     }
   }
+
+  @Override
+  protected void paintComponent(Graphics g)
+  {
+    /*
+     * enable 'hidden regions' option only if
+     * 'top' viewport has hidden columns
+     */
+    getFocusedViewport();
+    super.paintComponent(g);
+  }
 }
index a925227..541c253 100755 (executable)
@@ -320,6 +320,7 @@ public class IdCanvas extends JPanel implements ViewportListenerI
       if (hasHiddenRows || alignViewport.isDisplayReferenceSeq())
       {
         g.setFont(getHiddenFont(sequence, alignViewport));
+        fm = g.getFontMetrics();
       }
 
       // Selected sequence colours
index 0f4d0e7..92b612a 100644 (file)
@@ -92,7 +92,7 @@ public class OptsAndParamsPage
 
     JLabel optlabel = new JLabel();
 
-    JComboBox val = new JComboBox();
+    JComboBox<String> val = new JComboBox<>();
 
     public OptionBox(OptionI opt)
     {
@@ -126,7 +126,7 @@ public class OptsAndParamsPage
         }
       }
       add(enabled, BorderLayout.NORTH);
-      for (Object str : opt.getPossibleValues())
+      for (String str : opt.getPossibleValues())
       {
         val.addItem(str);
       }
@@ -588,7 +588,7 @@ public class OptsAndParamsPage
       {
         if (choice)
         {
-          choicebox = new JComboBox();
+          choicebox = new JComboBox<>();
           choicebox.addActionListener(this);
           controlPanel.add(choicebox, BorderLayout.CENTER);
         }
@@ -622,7 +622,9 @@ public class OptsAndParamsPage
             }
           });
           valueField.setPreferredSize(new Dimension(60, 25));
+          valueField.setText(parm.getValue());
           slider = makeSlider(parm.getValidValue());
+          updateSliderFromValueField();
           slider.addChangeListener(this);
 
           controlPanel.add(slider, BorderLayout.WEST);
index 4f660a2..3512e42 100644 (file)
@@ -141,6 +141,12 @@ public class PCAPanel extends GPCAPanel
   protected void close_actionPerformed()
   {
     setPcaModel(null);
+    if (this.rc != null)
+    {
+      this.rc.sequencePoints = null;
+      this.rc.setAxisEndPoints(null);
+      this.rc = null;
+    }
   }
 
   @Override
index 92f221c..bb85948 100644 (file)
@@ -926,11 +926,12 @@ public class SeqPanel extends JPanel
     AlignFrame af = Desktop.getAlignFrameFor(complement);
     FeatureRendererModel fr2 = af.getFeatureRenderer();
 
-    int j = results.getSize();
+    List<SearchResultMatchI> matches = results.getResults();
+    int j = matches.size();
     List<String> infos = new ArrayList<>();
     for (int i = 0; i < j; i++)
     {
-      SearchResultMatchI match = results.getResults().get(i);
+      SearchResultMatchI match = matches.get(i);
       int pos = match.getStart();
       if (pos == match.getEnd())
       {
index c8f673d..714e770 100644 (file)
@@ -16,6 +16,12 @@ import javax.swing.JSlider;
 public class Slider extends JSlider
 {
   /*
+   * the number of nominal positions the slider represents
+   * (higher number = more fine-grained positioning)
+   */
+  private static final int SCALE_TICKS = 1000;
+
+  /*
    * 'true' value corresponding to zero on the slider
    */
   private float trueMin;
@@ -57,11 +63,9 @@ public class Slider extends JSlider
     trueMin = min;
     trueMax = max;
     setMinimum(0);
-    sliderScaleFactor = 100f / (max - min);
+    sliderScaleFactor = SCALE_TICKS / (max - min);
     int sliderMax = (int) ((max - min) * sliderScaleFactor);
-    int extent = 1;
-    setExtent(extent);
-    setMaximum(sliderMax + extent);
+    setMaximum(sliderMax);
     setSliderValue(value);
   }
 
index 574cf04..f7c93db 100644 (file)
@@ -814,7 +814,7 @@ public class SplitFrame extends GSplitFrame implements SplitContainerI
         if (c != null && c instanceof AlignFrame)
         {
           AlignFrame af = (AlignFrame) c;
-          new Finder(af.viewport, af.alignPanel);
+          new Finder(af.alignPanel);
         }
       }
     };
index ca4f84e..6c9c892 100755 (executable)
@@ -159,6 +159,7 @@ public class TreePanel extends GTreePanel
         {
           getViewport().removePropertyChangeListener(listener);
         }
+        releaseReferences();
       }
     });
 
@@ -168,6 +169,17 @@ public class TreePanel extends GTreePanel
   }
 
   /**
+   * Ensure any potentially large object references are nulled
+   */
+  public void releaseReferences()
+  {
+    this.tree = null;
+    this.treeCanvas.tree = null;
+    this.treeCanvas.nodeHash = null;
+    this.treeCanvas.nameHash = null;
+  }
+
+  /**
    * @return
    */
   protected PropertyChangeListener addAlignmentListener()
index 0150579..2acd6cc 100644 (file)
  */
 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.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.TreeMap;
 
+import jalview.bin.Cache;
+import jalview.gui.Desktop;
+import jalview.gui.JvOptionPane;
+import jalview.util.MessageManager;
+import jalview.util.Platform;
+
 /*
  * BackupFiles used for manipulating (naming rolling/deleting) backup/version files when an alignment or project file is saved.
  * User configurable options are:
@@ -95,6 +100,10 @@ public class BackupFiles
   private static final SimpleDateFormat sdf = new SimpleDateFormat(
           "yyyy-MM-dd HH:mm:ss");
 
+  private static final String newTempFileSuffix = "_newfile";
+
+  private static final String oldTempFileSuffix = "_oldfile_tobedeleted";
+
   public BackupFiles(String filename)
   {
     this(new File(filename));
@@ -106,7 +115,8 @@ public class BackupFiles
   {
     classInit();
     this.file = file;
-    BackupFilesPresetEntry bfpe = BackupFilesPresetEntry.getSavedBackupEntry();
+    BackupFilesPresetEntry bfpe = BackupFilesPresetEntry
+            .getSavedBackupEntry();
     this.suffix = bfpe.suffix;
     this.noMax = bfpe.keepAll;
     this.max = bfpe.rollMax;
@@ -121,30 +131,48 @@ public class BackupFiles
       {
         String tempfilename = file.getName();
         File tempdir = file.getParentFile();
-        temp = File.createTempFile(tempfilename, TEMP_FILE_EXT + "_newfile",
-                tempdir);
+        Cache.log.trace(
+                "BACKUPFILES [file!=null] attempting to create temp file for "
+                        + tempfilename + " in dir " + tempdir);
+        temp = File.createTempFile(tempfilename,
+                TEMP_FILE_EXT + newTempFileSuffix, tempdir);
+        Cache.log.debug(
+                "BACKUPFILES using temp file " + temp.getAbsolutePath());
       }
       else
       {
+        Cache.log.trace(
+                "BACKUPFILES [file==null] attempting to create default temp file "
+                        + DEFAULT_TEMP_FILE + " with extension "
+                        + TEMP_FILE_EXT);
         temp = File.createTempFile(DEFAULT_TEMP_FILE, TEMP_FILE_EXT);
       }
     } catch (IOException e)
     {
-      System.out.println(
-              "Could not create temp file to save into (IOException)");
+      Cache.log
+              .error("Could not create temp file to save to (IOException)");
+      Cache.log.error(e.getMessage());
+      Cache.log.debug(Cache.getStackTraceString(e));
     } catch (Exception e)
     {
-      System.out.println("Exception ctreating temp file for saving");
+      Cache.log.error("Exception ctreating temp file for saving");
+      Cache.log.debug(Cache.getStackTraceString(e));
     }
     this.setTempFile(temp);
   }
 
   public static void classInit()
   {
-    setEnabled(Cache.getDefault(ENABLED, true));
+    Cache.initLogger();
+    Cache.log.trace("BACKUPFILES classInit");
+    boolean e = Cache.getDefault(ENABLED, true);
+    setEnabled(e);
+    Cache.log.trace("BACKUPFILES " + (e ? "enabled" : "disabled"));
     BackupFilesPresetEntry bfpe = BackupFilesPresetEntry
             .getSavedBackupEntry();
+    Cache.log.trace("BACKUPFILES preset scheme " + bfpe.toString());
     setConfirmDelete(bfpe.confirmDelete);
+    Cache.log.trace("BACKUPFILES confirm delete " + bfpe.confirmDelete);
   }
 
   public static void setEnabled(boolean flag)
@@ -188,9 +216,10 @@ public class BackupFiles
       path = this.getTempFile().getCanonicalPath();
     } catch (IOException e)
     {
-      System.out.println(
+      Cache.log.error(
               "IOException when getting Canonical Path of temp file '"
                       + this.getTempFile().getName() + "'");
+      Cache.log.debug(Cache.getStackTraceString(e));
     }
     return path;
   }
@@ -209,7 +238,7 @@ public class BackupFiles
 
   public boolean renameTempFile()
   {
-    return tempFile.renameTo(file);
+    return moveFileToFile(tempFile, file);
   }
 
   // roll the backupfiles
@@ -226,24 +255,35 @@ public class BackupFiles
             || suffix.length() == 0)
     {
       // nothing to do
+      Cache.log.debug("BACKUPFILES rollBackupFiles nothing to do." + ", "
+              + "filename: " + (file != null ? file.getName() : "null")
+              + ", " + "file exists: " + file.exists() + ", " + "enabled: "
+              + enabled + ", " + "max: " + max + ", " + "suffix: '" + suffix
+              + "'");
       return true;
     }
 
+    Cache.log.trace("BACKUPFILES rollBackupFiles starting");
+
     String dir = "";
     File dirFile;
     try
     {
       dirFile = file.getParentFile();
       dir = dirFile.getCanonicalPath();
+      Cache.log.trace("BACKUPFILES dir: " + dir);
     } catch (Exception e)
     {
-      System.out.println(
+      Cache.log.error(
               "Could not get canonical path for file '" + file + "'");
+      Cache.log.error(e.getMessage());
+      Cache.log.debug(Cache.getStackTraceString(e));
       return false;
     }
     String filename = file.getName();
     String basename = filename;
 
+    Cache.log.trace("BACKUPFILES filename is " + filename);
     boolean ret = true;
     // Create/move backups up one
 
@@ -255,9 +295,13 @@ public class BackupFiles
     File[] backupFiles = dirFile.listFiles(bff);
     int nextIndexNum = 0;
 
+    Cache.log
+            .trace("BACKUPFILES backupFiles.length: " + backupFiles.length);
     if (backupFiles.length == 0)
     {
       // No other backup files. Just need to move existing file to backupfile_1
+      Cache.log.trace(
+              "BACKUPFILES no existing backup files, setting index to 1");
       nextIndexNum = 1;
     }
     else
@@ -270,7 +314,7 @@ public class BackupFiles
       if (reverseOrder)
       {
         // backup style numbering
-
+        Cache.log.trace("BACKUPFILES rolling files in reverse order");
 
         int tempMax = noMax ? -1 : max;
         // noMax == true means no limits
@@ -287,7 +331,7 @@ public class BackupFiles
             tempMax = i;
           }
         }
-        
+
         File previousFile = null;
         File fileToBeDeleted = null;
         for (int n = tempMax; n > 0; n--)
@@ -302,6 +346,7 @@ public class BackupFiles
             // no "oldest" file to delete
             previousFile = backupfile_n;
             fileToBeDeleted = null;
+            Cache.log.trace("BACKUPFILES No oldest file to delete");
             continue;
           }
 
@@ -312,19 +357,23 @@ public class BackupFiles
             File replacementFile = backupfile_n;
             long fileToBeDeletedLMT = fileToBeDeleted.lastModified();
             long replacementFileLMT = replacementFile.lastModified();
+            Cache.log.trace("BACKUPFILES fileToBeDeleted is "
+                    + fileToBeDeleted.getAbsolutePath());
+            Cache.log.trace("BACKUPFILES replacementFile is "
+                    + backupfile_n.getAbsolutePath());
 
             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 "
+                Cache.log.warn("WARNING! I am set to delete backupfile "
                         + fileToBeDeleted.getName()
                         + " has modification time "
                         + fileToBeDeletedLMTString
@@ -335,6 +384,11 @@ public class BackupFiles
 
                 boolean delete = confirmNewerDeleteFile(fileToBeDeleted,
                         replacementFile, true);
+                Cache.log.trace("BACKUPFILES "
+                        + (delete ? "confirmed" : "not") + " deleting file "
+                        + fileToBeDeleted.getAbsolutePath()
+                        + " which is newer than "
+                        + replacementFile.getAbsolutePath());
 
                 if (delete)
                 {
@@ -343,21 +397,27 @@ public class BackupFiles
                 }
                 else
                 {
-                  fileToBeDeleted.renameTo(oldestTempFile);
+                  Cache.log.debug("BACKUPFILES moving "
+                          + fileToBeDeleted.getAbsolutePath() + " to "
+                          + oldestTempFile.getAbsolutePath());
+                  moveFileToFile(fileToBeDeleted, oldestTempFile);
                 }
               }
               else
               {
-                fileToBeDeleted.renameTo(oldestTempFile);
+                Cache.log.debug("BACKUPFILES going to move "
+                        + fileToBeDeleted.getAbsolutePath() + " to "
+                        + oldestTempFile.getAbsolutePath());
+                moveFileToFile(fileToBeDeleted, oldestTempFile);
                 addDeleteFile(oldestTempFile);
               }
 
             } catch (Exception e)
             {
-              System.out.println(
+              Cache.log.error(
                       "Error occurred, probably making new temp file for '"
                               + fileToBeDeleted.getName() + "'");
-              e.printStackTrace();
+              Cache.log.error(Cache.getStackTraceString(e));
             }
 
             // reset
@@ -372,7 +432,9 @@ public class BackupFiles
           {
             if (previousFile != null)
             {
-              ret = ret && backupfile_n.renameTo(previousFile);
+              // using boolean '&' instead of '&&' as don't want moveFileToFile
+              // attempt to be conditional (short-circuit)
+              ret = ret & moveFileToFile(backupfile_n, previousFile);
             }
           }
 
@@ -382,19 +444,37 @@ public class BackupFiles
         // index to use for the latest backup
         nextIndexNum = 1;
       }
-      else
+      else // not reverse numbering
       {
         // version style numbering (with earliest file deletion if max files
         // reached)
 
         bfTreeMap.values().toArray(backupFiles);
+        StringBuilder bfsb = new StringBuilder();
+        for (int i = 0; i < backupFiles.length; i++)
+        {
+          if (bfsb.length() > 0)
+          {
+            bfsb.append(", ");
+          }
+          bfsb.append(backupFiles[i].getName());
+        }
+        Cache.log.trace("BACKUPFILES backupFiles: " + bfsb.toString());
 
         // noMax == true means keep all backup files
         if ((!noMax) && bfTreeMap.size() >= max)
         {
+          Cache.log.trace("BACKUPFILES noMax: " + noMax + ", " + "max: "
+                  + max + ", " + "bfTreeMap.size(): " + bfTreeMap.size());
           // need to delete some files to keep number of backups to designated
-          // max
-          int numToDelete = bfTreeMap.size() - max + 1;
+          // max.
+          // Note that if the suffix is not numbered then do not delete any
+          // backup files later or we'll delete the new backup file (there can
+          // be only one).
+          int numToDelete = suffix.indexOf(NUM_PLACEHOLDER) > -1
+                  ? bfTreeMap.size() - max + 1
+                  : 0;
+          Cache.log.trace("BACKUPFILES numToDelete: " + numToDelete);
           // the "replacement" file is the latest backup file being kept (it's
           // not replacing though)
           File replacementFile = numToDelete < backupFiles.length
@@ -407,6 +487,9 @@ public class BackupFiles
             File fileToBeDeleted = backupFiles[i];
             boolean delete = true;
 
+            Cache.log.trace(
+                    "BACKUPFILES fileToBeDeleted: " + fileToBeDeleted);
+
             boolean newer = false;
             if (replacementFile != null)
             {
@@ -421,14 +504,13 @@ public class BackupFiles
                 String replacementFileLMTString = sdf
                         .format(replacementFileLMT);
 
-                System.out
-                        .println("WARNING! I am set to delete backupfile '"
-                                + fileToBeDeleted.getName()
-                                + "' has modification time "
+                Cache.log.warn("WARNING! I am set to delete backupfile '"
+                        + fileToBeDeleted.getName()
+                        + "' has modification time "
                         + fileToBeDeletedLMTString
-                                + " which is newer than the oldest backupfile being kept '"
+                        + " which is newer than the oldest backupfile being kept '"
                         + replacementFile.getName()
-                                + "' with modification time "
+                        + "' with modification time "
                         + replacementFileLMTString);
 
                 delete = confirmNewerDeleteFile(fileToBeDeleted,
@@ -437,17 +519,23 @@ public class BackupFiles
                 {
                   // User has confirmed delete -- no need to add it to the list
                   fileToBeDeleted.delete();
+                  Cache.log.debug("BACKUPFILES deleting fileToBeDeleted: "
+                          + fileToBeDeleted);
                   delete = false;
                 }
                 else
                 {
                   // keeping file, nothing to do!
+                  Cache.log.debug("BACKUPFILES keeping fileToBeDeleted: "
+                          + fileToBeDeleted);
                 }
               }
             }
             if (delete)
             {
               addDeleteFile(fileToBeDeleted);
+              Cache.log.debug("BACKUPFILES addDeleteFile(fileToBeDeleted): "
+                      + fileToBeDeleted);
             }
 
           }
@@ -462,10 +550,17 @@ public class BackupFiles
     String latestBackupFilename = dir + File.separatorChar
             + BackupFilenameParts.getBackupFilename(nextIndexNum, basename,
                     suffix, digits);
-    ret |= file.renameTo(new File(latestBackupFilename));
-
+    Cache.log.trace("BACKUPFILES Moving old file [" + file
+            + "] to latestBackupFilename [" + latestBackupFilename + "]");
+    // using boolean '&' instead of '&&' as don't want moveFileToFile attempt to
+    // be conditional (short-circuit)
+    ret = ret & moveFileToFile(file, new File(latestBackupFilename));
+    Cache.log.debug(
+            "BACKUPFILES moving " + file + " to " + latestBackupFilename
+                    + " was " + (ret ? "" : "NOT ") + "successful");
     if (tidyUp)
     {
+      Cache.log.debug("BACKUPFILES tidying up files");
       tidyUpFiles();
     }
 
@@ -521,7 +616,7 @@ public class BackupFiles
         saveFile = nextTempFile(ftbd.getName(), ftbd.getParentFile());
       } catch (Exception e)
       {
-        System.out.println(
+        Cache.log.error(
                 "Error when confirming to keep backup file newer than other backup files.");
         e.printStackTrace();
       }
@@ -529,19 +624,27 @@ public class BackupFiles
               "label.newerdelete_replacement_line", new String[]
               { ftbd.getName(), rf.getName(), ftbdLMT, rfLMT, ftbdSize,
                   rfSize }));
+      // "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}).""
       messageSB.append("\n\n");
       messageSB.append(MessageManager.formatMessage(
               "label.confirm_deletion_or_rename", new String[]
               { ftbd.getName(), saveFile.getName() }));
+      // "Confirm deletion of ''{0}'' or rename to ''{1}''?"
       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]);
+      confirmButton = Platform.isHeadless() ? JvOptionPane.YES_OPTION
+              : JvOptionPane.showOptionDialog(Desktop.desktop,
+                      messageSB.toString(),
+                      MessageManager.getString(
+                              "label.backupfiles_confirm_delete"),
+                      // "Confirm delete"
+                      JvOptionPane.YES_NO_OPTION,
+                      JvOptionPane.WARNING_MESSAGE, null, options,
+                      options[0]);
     }
     else
     {
@@ -549,22 +652,29 @@ public class BackupFiles
               .formatMessage("label.newerdelete_line", new String[]
               { ftbd.getName(), rf.getName(), ftbdLMT, rfLMT, ftbdSize,
                   rfSize }));
+      // "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})."
       messageSB.append("\n\n");
       messageSB.append(MessageManager
               .formatMessage("label.confirm_deletion", new String[]
               { ftbd.getName() }));
+      // "Confirm deletion of ''{0}''?"
       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]);
+      confirmButton = Platform.isHeadless() ? JvOptionPane.YES_OPTION
+              : JvOptionPane.showOptionDialog(Desktop.desktop,
+                      messageSB.toString(),
+                      MessageManager.getString(
+                              "label.backupfiles_confirm_delete"),
+                      // "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);
   }
@@ -580,6 +690,8 @@ public class BackupFiles
         messageSB = new StringBuilder();
         messageSB.append(MessageManager
                 .getString("label.backupfiles_confirm_delete_old_files"));
+        // "Delete the following older backup files? (see the Backups tab in
+        // Preferences for more options)"
         for (int i = 0; i < deleteFiles.size(); i++)
         {
           File df = deleteFiles.get(i);
@@ -590,13 +702,17 @@ public class BackupFiles
                   new String[]
                   { sdf.format(df.lastModified()),
                       Long.toString(df.length()) }));
+          // "(modified {0}, size {1})"
         }
 
-        int confirmButton = JvOptionPane.showConfirmDialog(Desktop.desktop,
-                messageSB.toString(),
-                MessageManager
-                        .getString("label.backupfiles_confirm_delete"),
-                JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE);
+        int confirmButton = Platform.isHeadless() ? JvOptionPane.YES_OPTION
+                : JvOptionPane.showConfirmDialog(Desktop.desktop,
+                        messageSB.toString(),
+                        MessageManager.getString(
+                                "label.backupfiles_confirm_delete"),
+                        // "Confirm delete"
+                        JvOptionPane.YES_NO_OPTION,
+                        JvOptionPane.WARNING_MESSAGE);
 
         doDelete = (confirmButton == JvOptionPane.YES_OPTION);
       }
@@ -610,8 +726,10 @@ public class BackupFiles
         for (int i = 0; i < deleteFiles.size(); i++)
         {
           File fileToDelete = deleteFiles.get(i);
+          Cache.log.trace("BACKUPFILES about to delete fileToDelete:"
+                  + fileToDelete);
           fileToDelete.delete();
-          System.out.println("DELETING '" + fileToDelete.getName() + "'");
+          Cache.log.warn("deleted '" + fileToDelete.getName() + "'");
         }
       }
 
@@ -621,8 +739,7 @@ public class BackupFiles
   }
 
   private TreeMap<Integer, File> sortBackupFilesAsTreeMap(
-          File[] backupFiles,
-          String basename)
+          File[] backupFiles, String basename)
   {
     // sort the backup files (based on integer found in the suffix) using a
     // precomputed Hashmap for speed
@@ -647,7 +764,7 @@ public class BackupFiles
     boolean rename = false;
     if (write)
     {
-      roll = this.rollBackupFiles(false);
+      roll = this.rollBackupFiles(false); // tidyUpFiles at the end
       rename = this.renameTempFile();
     }
 
@@ -661,7 +778,9 @@ public class BackupFiles
     if (!okay)
     {
       StringBuilder messageSB = new StringBuilder();
-      messageSB.append(MessageManager.getString( "label.backupfiles_confirm_save_file_backupfiles_roll_wrong"));
+      messageSB.append(MessageManager.getString(
+              "label.backupfiles_confirm_save_file_backupfiles_roll_wrong"));
+      // "Something possibly went wrong with the backups of this file."
       if (rename)
       {
         if (messageSB.length() > 0)
@@ -670,6 +789,7 @@ public class BackupFiles
         }
         messageSB.append(MessageManager.getString(
                 "label.backupfiles_confirm_save_new_saved_file_ok"));
+        // "The new saved file seems okay."
       }
       else
       {
@@ -679,13 +799,22 @@ public class BackupFiles
         }
         messageSB.append(MessageManager.getString(
                 "label.backupfiles_confirm_save_new_saved_file_not_ok"));
+        // "The new saved file might not be okay."
       }
-
-      int confirmButton = JvOptionPane.showConfirmDialog(Desktop.desktop,
-              messageSB.toString(),
-              MessageManager
-                      .getString("label.backupfiles_confirm_save_file"),
-              JvOptionPane.OK_OPTION, JvOptionPane.WARNING_MESSAGE);
+      if (messageSB.length() > 0)
+      {
+        messageSB.append("\n");
+      }
+      messageSB
+              .append(MessageManager.getString("label.continue_operation"));
+
+      int confirmButton = Platform.isHeadless() ? JvOptionPane.OK_OPTION
+              : JvOptionPane.showConfirmDialog(Desktop.desktop,
+                      messageSB.toString(),
+                      MessageManager.getString(
+                              "label.backupfiles_confirm_save_file"),
+                      // "Confirm save file"
+                      JvOptionPane.OK_OPTION, JvOptionPane.WARNING_MESSAGE);
       okay = confirmButton == JvOptionPane.OK_OPTION;
     }
     if (okay)
@@ -709,7 +838,7 @@ public class BackupFiles
       dirFile = file.getParentFile();
     } catch (Exception e)
     {
-      System.out.println(
+      Cache.log.error(
               "Could not get canonical path for file '" + file + "'");
       return new TreeMap<>();
     }
@@ -751,13 +880,49 @@ public class BackupFiles
     int pos = deleteFiles.indexOf(fileToBeDeleted);
     if (pos > -1)
     {
+      Cache.log.debug("BACKUPFILES not adding file "
+              + fileToBeDeleted.getAbsolutePath()
+              + " to the delete list (already at index" + pos + ")");
       return true;
     }
     else
     {
+      Cache.log.debug("BACKUPFILES adding file "
+              + fileToBeDeleted.getAbsolutePath() + " to the delete list");
       deleteFiles.add(fileToBeDeleted);
     }
     return ret;
   }
 
+  public static boolean moveFileToFile(File oldFile, File newFile)
+  {
+    Cache.initLogger();
+    boolean ret = false;
+    Path oldPath = Paths.get(oldFile.getAbsolutePath());
+    Path newPath = Paths.get(newFile.getAbsolutePath());
+    try
+    {
+      // delete destination file - not usually necessary but Just In Case...
+      Cache.log.trace("BACKUPFILES deleting " + newFile.getAbsolutePath());
+      newFile.delete();
+      Cache.log.trace("BACKUPFILES moving " + oldFile.getAbsolutePath()
+              + " to " + newFile.getAbsolutePath());
+      Files.move(oldPath, newPath, StandardCopyOption.REPLACE_EXISTING);
+      ret = true;
+      Cache.log.trace("BACKUPFILES move seems to have succeeded");
+    } catch (IOException e)
+    {
+      Cache.log.warn("Could not move file '" + oldPath.toString() + "' to '"
+              + newPath.toString() + "'");
+      Cache.log.error(e.getMessage());
+      Cache.log.debug(Cache.getStackTraceString(e));
+      ret = false;
+    } catch (Exception e)
+    {
+      Cache.log.error(e.getMessage());
+      Cache.log.debug(Cache.getStackTraceString(e));
+      ret = false;
+    }
+    return ret;
+  }
 }
index 69130d0..ff8a5e6 100644 (file)
  */
 package jalview.io;
 
-import jalview.bin.Cache;
-import jalview.util.MessageManager;
-
 import java.util.HashMap;
 import java.util.Map;
 import java.util.StringTokenizer;
 
+import jalview.bin.Cache;
+import jalview.util.MessageManager;
+
 public class BackupFilesPresetEntry
 {
 
diff --git a/src/jalview/io/EmblFlatFile.java b/src/jalview/io/EmblFlatFile.java
new file mode 100644 (file)
index 0000000..bfae4ed
--- /dev/null
@@ -0,0 +1,900 @@
+package jalview.io;
+
+import java.io.IOException;
+import java.text.ParseException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.TreeMap;
+
+import jalview.bin.Cache;
+import jalview.datamodel.DBRefEntry;
+import jalview.datamodel.DBRefSource;
+import jalview.datamodel.FeatureProperties;
+import jalview.datamodel.Mapping;
+import jalview.datamodel.Sequence;
+import jalview.datamodel.SequenceFeature;
+import jalview.datamodel.SequenceI;
+import jalview.util.DBRefUtils;
+import jalview.util.DnaUtils;
+import jalview.util.MapList;
+import jalview.util.MappingUtils;
+
+/**
+ * A class that provides selective parsing of the EMBL flatfile format.
+ * <p>
+ * The initial implementation is limited to extracting fields used by Jalview
+ * after fetching an EMBL or EMBLCDS entry:
+ * 
+ * <pre>
+ * accession, version, sequence, xref
+ * and (for CDS feature) location, protein_id, product, codon_start, translation
+ * </pre>
+ * 
+ * For a complete parser, it may be best to adopt that provided in
+ * https://github.com/enasequence/sequencetools/tree/master/src/main/java/uk/ac/ebi/embl/flatfile
+ * (but note this has a dependency on the Apache Commons library)
+ * 
+ * @author gmcarstairs
+ * @see ftp://ftp.ebi.ac.uk/pub/databases/ena/sequence/release/doc/usrman.txt
+ * @see ftp://ftp.ebi.ac.uk/pub/databases/embl/doc/FT_current.html
+ */
+public class EmblFlatFile extends AlignFile // FileParse
+{
+  private static final String QUOTE = "\"";
+
+  private static final String DOUBLED_QUOTE = QUOTE + QUOTE;
+
+  /**
+   * A data bean class to hold values parsed from one CDS Feature (FT)
+   */
+  class CdsData
+  {
+    String translation; // from CDS feature /translation
+
+    String cdsLocation; // CDS /location raw value
+
+    int codonStart = 1; // from CDS /codon_start
+
+    String proteinName; // from CDS /product; used for protein description
+
+    String proteinId; // from CDS /protein_id
+
+    List<DBRefEntry> xrefs = new ArrayList<>(); // from CDS /db_xref qualifiers
+
+    Map<String, String> cdsProps = new Hashtable<>(); // CDS other qualifiers
+  }
+
+  private static final String WHITESPACE = "\\s+";
+
+  private String sourceDb;
+
+  /*
+   * values parsed from the EMBL flatfile record
+   */
+  private String accession; // from ID (first token)
+
+  private String version; // from ID (second token)
+
+  private String description; // from (first) DE line
+
+  private int length = 128; // from ID (7th token), with usable default
+
+  private List<DBRefEntry> dbrefs; // from DR
+
+  private String sequenceString; // from SQ lines
+
+  /*
+   * parsed CDS data fields, keyed by protein_id
+   */
+  private Map<String, CdsData> cds;
+
+  /**
+   * Constructor
+   * 
+   * @param fp
+   * @param sourceId
+   * @throws IOException
+   */
+  public EmblFlatFile(FileParse fp, String sourceId) throws IOException
+  {
+    super(false, fp); // don't parse immediately
+    this.sourceDb = sourceId;
+    dbrefs = new ArrayList<>();
+
+    /*
+     * using TreeMap gives CDS sequences in alphabetical, so readable, order
+     */
+    cds = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
+  }
+
+  /**
+   * Parses the flatfile, and if successful, saves as an annotated sequence
+   * which may be retrieved by calling {@code getSequence()}
+   * 
+   * @throws IOException
+   */
+  @Override
+  public void parse() throws IOException
+  {
+    String line = nextLine();
+    while (line != null)
+    {
+      if (line.startsWith("ID"))
+      {
+        line = parseID(line);
+      }
+      else if (line.startsWith("DE"))
+      {
+        line = parseDE(line);
+      }
+      else if (line.startsWith("DR"))
+      {
+        line = parseDR(line);
+      }
+      else if (line.startsWith("SQ"))
+      {
+        line = parseSQ();
+      }
+      else if (line.startsWith("FT"))
+      {
+        line = parseFT(line);
+      }
+      else
+      {
+        line = nextLine();
+      }
+    }
+    buildSequence();
+  }
+
+  /**
+   * Extracts and saves the primary accession and version (SV value) from an ID
+   * line, or null if not found. Returns the next line after the one processed.
+   * 
+   * @param line
+   * @throws IOException
+   */
+  String parseID(String line) throws IOException
+  {
+    String[] tokens = line.substring(2).split(";");
+
+    /*
+     * first is primary accession
+     */
+    String token = tokens[0].trim();
+    if (!token.isEmpty())
+    {
+      this.accession = token;
+    }
+
+    /*
+     * second token is 'SV versionNo'
+     */
+    if (tokens.length > 1)
+    {
+      token = tokens[1].trim();
+      if (token.startsWith("SV"))
+      {
+        String[] bits = token.trim().split(WHITESPACE);
+        this.version = bits[bits.length - 1];
+      }
+    }
+
+    /*
+     * seventh token is 'length BP'
+     */
+    if (tokens.length > 6)
+    {
+      token = tokens[6].trim();
+      String[] bits = token.trim().split(WHITESPACE);
+      try
+      {
+        this.length = Integer.valueOf(bits[0]);
+      } catch (NumberFormatException e)
+      {
+        Cache.log.error("bad length read in flatfile, line: " + line);
+      }
+    }
+
+    return nextLine();
+  }
+
+  /**
+   * Reads sequence description from the first DE line found. Any trailing
+   * period is discarded. If there are multiple DE lines, only the first (short
+   * description) is read, the rest are ignored.
+   * 
+   * @param line
+   * @return
+   * @throws IOException
+   */
+  String parseDE(String line) throws IOException
+  {
+    String desc = line.substring(2).trim();
+    if (desc.endsWith("."))
+    {
+      desc = desc.substring(0, desc.length() - 1);
+    }
+    this.description = desc;
+
+    /*
+     * pass over any additional DE lines
+     */
+    while ((line = nextLine()) != null)
+    {
+      if (!line.startsWith("DE"))
+      {
+        break;
+      }
+    }
+
+    return line;
+  }
+
+  /**
+   * Processes one DR line and saves as a DBRefEntry cross-reference. Returns
+   * the line following the line processed.
+   * 
+   * @param line
+   * @throws IOException
+   */
+  String parseDR(String line) throws IOException
+  {
+    String[] tokens = line.substring(2).split(";");
+    if (tokens.length > 1)
+    {
+      /*
+       * ensure UniProtKB/Swiss-Prot converted to UNIPROT
+       */
+      String db = tokens[0].trim();
+      db = DBRefUtils.getCanonicalName(db);
+      String acc = tokens[1].trim();
+      if (acc.endsWith("."))
+      {
+        acc = acc.substring(0, acc.length() - 1);
+      }
+      String version = "0";
+      if (tokens.length > 2)
+      {
+        String secondaryId = tokens[2].trim();
+        if (!secondaryId.isEmpty())
+        {
+          // todo: is this right? secondary id is not a version number
+          // version = secondaryId;
+        }
+      }
+      this.dbrefs.add(new DBRefEntry(db, version, acc));
+    }
+
+    return nextLine();
+  }
+
+  /**
+   * Reads and saves the sequence, read from the lines following the SQ line.
+   * Whitespace and position counters are discarded. Returns the next line
+   * following the sequence data (the next line that doesn't start with
+   * whitespace).
+   * 
+   * @throws IOException
+   */
+  String parseSQ() throws IOException
+  {
+    StringBuilder sb = new StringBuilder(this.length);
+    String line = nextLine();
+    while (line != null && line.startsWith(" "))
+    {
+      line = line.trim();
+      String[] blocks = line.split(WHITESPACE);
+
+      /*
+       * omit the last block (position counter) on each line
+       */
+      for (int i = 0; i < blocks.length - 1; i++)
+      {
+        sb.append(blocks[i]);
+      }
+      line = nextLine();
+    }
+    this.sequenceString = sb.toString();
+
+    return line;
+  }
+
+  /**
+   * Processes an FT line. If it declares a feature type of interest (currently,
+   * only CDS is processed), processes all of the associated lines (feature
+   * qualifiers), and returns the next line after that, otherwise simply returns
+   * the next line.
+   * 
+   * @param line
+   * @return
+   * @throws IOException
+   */
+  String parseFT(String line) throws IOException
+  {
+    String[] tokens = line.split(WHITESPACE);
+    if (tokens.length < 3 || !"CDS".equals(tokens[1]))
+    {
+      return nextLine();
+    }
+
+    /*
+     * parse location - which may be over more than one line e.g. EAW51554
+     */
+    CdsData data = new CdsData();
+    StringBuilder sb = new StringBuilder().append(tokens[2]);
+    line = parseFeatureQualifier(sb, "CDS");
+    data.cdsLocation = sb.toString();
+
+    while (line != null)
+    {
+      if (!line.startsWith("FT    ")) // 4 spaces
+      {
+        // e.g. start of next feature "FT source..."
+        break;
+      }
+
+      /*
+       * extract qualifier, e.g. FT    /protein_id="CAA37824.1"
+       * - the value may extend over more than one line
+       * - if the value has enclosing quotes, these are removed
+       * - escaped double quotes ("") are reduced to a single character
+       */
+      int slashPos = line.indexOf('/');
+      if (slashPos == -1)
+      {
+        Cache.log.error("Unexpected EMBL line ignored: " + line);
+        line = nextLine();
+        continue;
+      }
+      int eqPos = line.indexOf('=', slashPos + 1);
+      if (eqPos == -1)
+      {
+        // can happen, e.g. /ribosomal_slippage
+        // Cache.log.error("Unexpected EMBL line ignored: " + line);
+        line = nextLine();
+        continue;
+      }
+      String qualifier = line.substring(slashPos + 1, eqPos);
+      String value = line.substring(eqPos + 1);
+      value = removeQuotes(value);
+      sb = new StringBuilder().append(value);
+      line = parseFeatureQualifier(sb, qualifier);
+      String featureValue = sb.toString();
+
+      if ("protein_id".equals(qualifier))
+      {
+        data.proteinId = featureValue;
+      }
+      else if ("codon_start".equals(qualifier))
+      {
+        try
+        {
+          data.codonStart = Integer.parseInt(featureValue.trim());
+        } catch (NumberFormatException e)
+        {
+          Cache.log.error("Invalid codon_start in XML for " + this.accession
+                  + ": " + e.getMessage());
+        }
+      }
+      else if ("db_xref".equals(qualifier))
+      {
+        String[] parts = featureValue.split(":");
+        if (parts.length == 2)
+        {
+          String db = parts[0].trim();
+          db = DBRefUtils.getCanonicalName(db);
+          DBRefEntry dbref = new DBRefEntry(db, "0", parts[1].trim());
+          data.xrefs.add(dbref);
+        }
+      }
+      else if ("product".equals(qualifier))
+      {
+        data.proteinName = featureValue;
+      }
+      else if ("translation".equals(qualifier))
+      {
+        data.translation = featureValue;
+      }
+      else if (!"".equals(featureValue))
+      {
+        // throw anything else into the additional properties hash
+        data.cdsProps.put(qualifier, featureValue);
+      }
+    }
+
+    if (data.proteinId != null)
+    {
+      this.cds.put(data.proteinId, data);
+    }
+    else
+    {
+      Cache.log.error("Ignoring CDS feature with no protein_id for "
+              + sourceDb + ":" + accession);
+    }
+
+    return line;
+  }
+
+  /**
+   * Removes leading or trailing double quotes (") unless doubled, and changes
+   * any 'escaped' (doubled) double quotes to single characters. As per the
+   * Feature Table specification for Qualifiers, Free Text.
+   * 
+   * @param value
+   * @return
+   */
+  static String removeQuotes(String value)
+  {
+    if (value == null)
+    {
+      return null;
+    }
+    if (value.startsWith(QUOTE) && !value.startsWith(DOUBLED_QUOTE))
+    {
+      value = value.substring(1);
+    }
+    if (value.endsWith(QUOTE) && !value.endsWith(DOUBLED_QUOTE))
+    {
+      value = value.substring(0, value.length() - 1);
+    }
+    value = value.replace(DOUBLED_QUOTE, QUOTE);
+    return value;
+  }
+
+  /**
+   * Reads the value of a feature (FT) qualifier from one or more lines of the
+   * file, and returns the next line after that. Values are appended to the
+   * string buffer, which should be already primed with the value read from the
+   * first line for the qualifier (with any leading double quote removed).
+   * Enclosing double quotes are removed, and escaped (repeated) double quotes
+   * reduced to one only. For example for
+   * 
+   * <pre>
+   * FT      /note="gene_id=hCG28070.3 
+   * FT      ""foobar"" isoform=CRA_b"
+   * the returned value is
+   * gene_id=hCG28070.3 "foobar" isoform=CRA_b
+   * </pre>
+   * 
+   * Note the side-effect of this method, to advance data reading to the next
+   * line after the feature qualifier.
+   * 
+   * @param sb
+   *          a string buffer primed with the first line of the value
+   * @param qualifierName
+   * @return
+   * @throws IOException
+   */
+  String parseFeatureQualifier(StringBuilder sb, String qualifierName)
+          throws IOException
+  {
+    String line;
+    while ((line = nextLine()) != null)
+    {
+      if (!line.startsWith("FT    "))
+      {
+        break; // reached next feature or other input line
+      }
+      String[] tokens = line.split(WHITESPACE);
+      if (tokens.length < 2)
+      {
+        Cache.log.error("Ignoring bad EMBL line for " + this.accession
+                + ": " + line);
+        break;
+      }
+      if (tokens[1].startsWith("/"))
+      {
+        break; // next feature qualifier
+      }
+
+      /*
+       * heuristic rule: most multi-line value (e.g. /product) are text,
+       * so add a space for word boundary at a new line; not for translation
+       */
+      if (!"translation".equals(qualifierName)
+              && !"CDS".equals(qualifierName))
+      {
+        sb.append(" ");
+      }
+
+      /*
+       * remove trailing " and unescape doubled ""
+       */
+      String data = removeQuotes(tokens[1]);
+      sb.append(data);
+    }
+
+    return line;
+  }
+
+  /**
+   * Constructs and saves the sequence from parsed components
+   */
+  void buildSequence()
+  {
+    if (this.accession == null || this.sequenceString == null)
+    {
+      Cache.log.error("Failed to parse data from EMBL");
+      return;
+    }
+
+    String name = this.accession;
+    if (this.sourceDb != null)
+    {
+      name = this.sourceDb + "|" + name;
+    }
+    SequenceI seq = new Sequence(name, this.sequenceString);
+    seq.setDescription(this.description);
+
+    /*
+     * add a DBRef to itself
+     */
+    DBRefEntry selfRef = new DBRefEntry(sourceDb, version, accession);
+    int[] startEnd = new int[] { 1, seq.getLength() };
+    selfRef.setMap(new Mapping(null, startEnd, startEnd, 1, 1));
+    seq.addDBRef(selfRef);
+
+    for (DBRefEntry dbref : this.dbrefs)
+    {
+      seq.addDBRef(dbref);
+    }
+
+    processCDSFeatures(seq);
+
+    seq.deriveSequence();
+
+    addSequence(seq);
+  }
+
+  /**
+   * Process the CDS features, including generation of cross-references and
+   * mappings to the protein products (translation)
+   * 
+   * @param seq
+   */
+  protected void processCDSFeatures(SequenceI seq)
+  {
+    /*
+     * record protein products found to avoid duplication i.e. >1 CDS with 
+     * the same /protein_id [though not sure I can find an example of this]
+     */
+    Map<String, SequenceI> proteins = new HashMap<>();
+    for (CdsData data : cds.values())
+    {
+      processCDSFeature(seq, data, proteins);
+    }
+  }
+
+  /**
+   * Processes data for one parsed CDS feature to
+   * <ul>
+   * <li>create a protein product sequence for the translation</li>
+   * <li>create a cross-reference to protein with mapping from dna</li>
+   * <li>add a CDS feature to the sequence for each CDS start-end range</li>
+   * <li>add any CDS dbrefs to the sequence and to the protein product</li>
+   * </ul>
+   * 
+   * @param SequenceI
+   *          dna
+   * @param proteins
+   *          map of protein products so far derived from CDS data
+   */
+  void processCDSFeature(SequenceI dna, CdsData data,
+          Map<String, SequenceI> proteins)
+  {
+    /*
+     * parse location into a list of [start, end, start, end] positions
+     */
+    int[] exons = getCdsRanges(this.accession, data.cdsLocation);
+
+    MapList maplist = buildMappingToProtein(dna, exons, data);
+
+    int exonNumber = 0;
+
+    for (int xint = 0; exons != null && xint < exons.length - 1; xint += 2)
+    {
+      int exonStart = exons[xint];
+      int exonEnd = exons[xint + 1];
+      int begin = Math.min(exonStart, exonEnd);
+      int end = Math.max(exonStart, exonEnd);
+      exonNumber++;
+      String desc = String.format("Exon %d for protein EMBLCDS:%s",
+              exonNumber, data.proteinId);
+
+      SequenceFeature sf = new SequenceFeature("CDS", desc, begin, end,
+              this.sourceDb);
+      for (Entry<String, String> val : data.cdsProps.entrySet())
+      {
+        sf.setValue(val.getKey(), val.getValue());
+      }
+
+      sf.setEnaLocation(data.cdsLocation);
+      boolean forwardStrand = exonStart <= exonEnd;
+      sf.setStrand(forwardStrand ? "+" : "-");
+      sf.setPhase(String.valueOf(data.codonStart - 1));
+      sf.setValue(FeatureProperties.EXONPOS, exonNumber);
+      sf.setValue(FeatureProperties.EXONPRODUCT, data.proteinName);
+
+      dna.addSequenceFeature(sf);
+    }
+
+    boolean hasUniprotDbref = false;
+    for (DBRefEntry xref : data.xrefs)
+    {
+      dna.addDBRef(xref);
+      if (xref.getSource().equals(DBRefSource.UNIPROT))
+      {
+        /*
+         * construct (or find) the sequence for (data.protein_id, data.translation)
+         */
+        SequenceI protein = buildProteinProduct(dna, xref, data, proteins);
+        Mapping map = new Mapping(protein, maplist);
+        map.setMappedFromId(data.proteinId);
+        xref.setMap(map);
+
+        /*
+         * add DBRefs with mappings from dna to protein and the inverse
+         */
+        DBRefEntry db1 = new DBRefEntry(sourceDb, version, accession);
+        db1.setMap(new Mapping(dna, maplist.getInverse()));
+        protein.addDBRef(db1);
+
+        hasUniprotDbref = true;
+      }
+    }
+
+    /*
+     * if we have a product (translation) but no explicit Uniprot dbref
+     * (example: EMBL M19487 protein_id AAB02592.1)
+     * then construct mappings to an assumed EMBLCDSPROTEIN accession
+     */
+    if (!hasUniprotDbref)
+    {
+      SequenceI protein = proteins.get(data.proteinId);
+      if (protein == null)
+      {
+        protein = new Sequence(data.proteinId, data.translation);
+        protein.setDescription(data.proteinName);
+        proteins.put(data.proteinId, protein);
+      }
+      // assuming CDSPROTEIN sequence version = dna version (?!)
+      DBRefEntry db1 = new DBRefEntry(DBRefSource.EMBLCDSProduct,
+              this.version, data.proteinId);
+      protein.addDBRef(db1);
+
+      DBRefEntry dnaToEmblProteinRef = new DBRefEntry(
+              DBRefSource.EMBLCDSProduct, this.version, data.proteinId);
+      Mapping map = new Mapping(protein, maplist);
+      map.setMappedFromId(data.proteinId);
+      dnaToEmblProteinRef.setMap(map);
+      dna.addDBRef(dnaToEmblProteinRef);
+    }
+
+    /*
+     * comment brought forward from EmblXmlSource, lines 447-451:
+     * TODO: if retrieved from EMBLCDS, add a DBRef back to the parent EMBL
+     * sequence with the exon  map; if given a dataset reference, search
+     * dataset for parent EMBL sequence if it exists and set its map;
+     * make a new feature annotating the coding contig
+     */
+  }
+
+  /**
+   * Computes a mapping from CDS positions in DNA sequence to protein product
+   * positions, with allowance for stop codon or incomplete start codon
+   * 
+   * @param dna
+   * @param exons
+   * @param data
+   * @return
+   */
+  MapList buildMappingToProtein(final SequenceI dna, final int[] exons,
+          final CdsData data)
+  {
+    MapList dnaToProteinMapping = null;
+    int peptideLength = data.translation.length();
+
+    int[] proteinRange = new int[] { 1, peptideLength };
+    if (exons != null && exons.length > 0)
+    {
+      /*
+       * We were able to parse 'location'; do a final 
+       * product length truncation check
+       */
+      int[] cdsRanges = adjustForProteinLength(peptideLength, exons);
+      dnaToProteinMapping = new MapList(cdsRanges, proteinRange, 3, 1);
+    }
+    else
+    {
+      /*
+       * workaround until we handle all 'location' formats fully
+       * e.g. X53828.1:60..1058 or <123..>289
+       */
+      Cache.log.error(String.format(
+              "Implementation Notice: EMBLCDS location '%s'not properly supported yet"
+                      + " - Making up the CDNA region of (%s:%s)... may be incorrect",
+              data.cdsLocation, sourceDb, this.accession));
+
+      int completeCodonsLength = 1 - data.codonStart + dna.getLength();
+      int mappedDnaEnd = dna.getEnd();
+      if (peptideLength * 3 == completeCodonsLength)
+      {
+        // this might occur for CDS sequences where no features are marked
+        Cache.log.warn("Assuming no stop codon at end of cDNA fragment");
+        mappedDnaEnd = dna.getEnd();
+      }
+      else if ((peptideLength + 1) * 3 == completeCodonsLength)
+      {
+        Cache.log.warn("Assuming stop codon at end of cDNA fragment");
+        mappedDnaEnd = dna.getEnd() - 3;
+      }
+
+      if (mappedDnaEnd != -1)
+      {
+        int[] cdsRanges = new int[] {
+            dna.getStart() + (data.codonStart - 1), mappedDnaEnd };
+        dnaToProteinMapping = new MapList(cdsRanges, proteinRange, 3, 1);
+      }
+    }
+
+    return dnaToProteinMapping;
+  }
+
+  /**
+   * Constructs a sequence for the protein product for the CDS data (if there is
+   * one), and dbrefs with mappings from CDS to protein and the reverse
+   * 
+   * @param dna
+   * @param xref
+   * @param data
+   * @param proteins
+   * @return
+   */
+  SequenceI buildProteinProduct(SequenceI dna, DBRefEntry xref,
+          CdsData data, Map<String, SequenceI> proteins)
+  {
+    /*
+     * check we have some data to work with
+     */
+    if (data.proteinId == null || data.translation == null)
+    {
+      return null;
+    }
+
+    /*
+     * Construct the protein sequence (if not already seen)
+     */
+    String proteinSeqName = xref.getSource() + "|" + xref.getAccessionId();
+    SequenceI protein = proteins.get(proteinSeqName);
+    if (protein == null)
+    {
+      protein = new Sequence(proteinSeqName, data.translation, 1,
+              data.translation.length());
+      protein.setDescription(data.proteinName != null ? data.proteinName
+              : "Protein Product from " + sourceDb);
+      proteins.put(proteinSeqName, protein);
+    }
+
+    return protein;
+  }
+
+  /**
+   * Returns the CDS location as a single array of [start, end, start, end...]
+   * positions. If on the reverse strand, these will be in descending order.
+   * 
+   * @param accession
+   * @param location
+   * @return
+   */
+  protected int[] getCdsRanges(String accession, String location)
+  {
+    if (location == null)
+    {
+      return new int[] {};
+    }
+
+    try
+    {
+      List<int[]> ranges = DnaUtils.parseLocation(location);
+      return MappingUtils.listToArray(ranges);
+    } catch (ParseException e)
+    {
+      Cache.log.warn(
+              String.format("Not parsing inexact CDS location %s in ENA %s",
+                      location, accession));
+      return new int[] {};
+    }
+  }
+
+  /**
+   * Output (print) is not implemented for EMBL flat file format
+   */
+  @Override
+  public String print(SequenceI[] seqs, boolean jvsuffix)
+  {
+    return null;
+  }
+
+  /**
+   * Truncates (if necessary) the exon intervals to match 3 times the length of
+   * the protein; also accepts 3 bases longer (for stop codon not included in
+   * protein)
+   * 
+   * @param proteinLength
+   * @param exon
+   *          an array of [start, end, start, end...] intervals
+   * @return the same array (if unchanged) or a truncated copy
+   */
+  static int[] adjustForProteinLength(int proteinLength, int[] exon)
+  {
+    if (proteinLength <= 0 || exon == null)
+    {
+      return exon;
+    }
+    int expectedCdsLength = proteinLength * 3;
+    int exonLength = MappingUtils.getLength(Arrays.asList(exon));
+
+    /*
+     * if exon length matches protein, or is shorter, or longer by the 
+     * length of a stop codon (3 bases), then leave it unchanged
+     */
+    if (expectedCdsLength >= exonLength
+            || expectedCdsLength == exonLength - 3)
+    {
+      return exon;
+    }
+
+    int origxon[];
+    int sxpos = -1;
+    int endxon = 0;
+    origxon = new int[exon.length];
+    System.arraycopy(exon, 0, origxon, 0, exon.length);
+    int cdspos = 0;
+    for (int x = 0; x < exon.length; x += 2)
+    {
+      cdspos += Math.abs(exon[x + 1] - exon[x]) + 1;
+      if (expectedCdsLength <= cdspos)
+      {
+        // advanced beyond last codon.
+        sxpos = x;
+        if (expectedCdsLength != cdspos)
+        {
+          // System.err
+          // .println("Truncating final exon interval on region by "
+          // + (cdspos - cdslength));
+        }
+
+        /*
+         * shrink the final exon - reduce end position if forward
+         * strand, increase it if reverse
+         */
+        if (exon[x + 1] >= exon[x])
+        {
+          endxon = exon[x + 1] - cdspos + expectedCdsLength;
+        }
+        else
+        {
+          endxon = exon[x + 1] + cdspos - expectedCdsLength;
+        }
+        break;
+      }
+    }
+
+    if (sxpos != -1)
+    {
+      // and trim the exon interval set if necessary
+      int[] nxon = new int[sxpos + 2];
+      System.arraycopy(exon, 0, nxon, 0, sxpos + 2);
+      nxon[sxpos + 1] = endxon; // update the end boundary for the new exon
+                                // set
+      exon = nxon;
+    }
+    return exon;
+  }
+}
index 92473ec..7e62f6b 100755 (executable)
@@ -28,6 +28,7 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.TreeMap;
@@ -346,7 +347,8 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI
     String line;
     while ((line = nextLine()) != null)
     {
-      if (line.toUpperCase().startsWith(ENDFILTERS))
+      // TODO: use .trim().equalsIgnoreCase here instead ? 
+      if (line.toUpperCase(Locale.ROOT).startsWith(ENDFILTERS))
       {
         return;
       }
index aadcdb9..de83e9b 100644 (file)
@@ -24,6 +24,7 @@ import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.LinkedHashMap;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
 
@@ -102,7 +103,7 @@ public class FileFormats
   protected void registerFileFormat(FileFormatI format,
           boolean isIdentifiable)
   {
-    String name = format.getName().toUpperCase();
+    String name = format.getName().toUpperCase(Locale.ROOT);
     if (formats.containsKey(name))
     {
       System.err.println("Overwriting file format: " + format.getName());
@@ -121,7 +122,7 @@ public class FileFormats
    */
   public void deregisterFileFormat(String name)
   {
-    FileFormatI ff = formats.remove(name.toUpperCase());
+    FileFormatI ff = formats.remove(name.toUpperCase(Locale.ROOT));
     identifiable.remove(ff);
   }
 
@@ -174,7 +175,7 @@ public class FileFormats
    */
   public FileFormatI forName(String format)
   {
-    return format == null ? null : formats.get(format.toUpperCase());
+    return format == null ? null : formats.get(format.toUpperCase(Locale.ROOT));
   }
 
   /**
index f1d79fe..3013c0b 100755 (executable)
@@ -24,6 +24,7 @@ import jalview.api.AlignExportSettingI;
 import jalview.api.AlignViewportI;
 import jalview.api.AlignmentViewPanel;
 import jalview.api.FeatureSettingsModelI;
+import jalview.bin.Cache;
 import jalview.util.MessageManager;
 
 import java.io.BufferedInputStream;
@@ -201,18 +202,41 @@ public class FileParse
     }
     return error;
   }
-  
+
   /**
-   * Recognise the 2-byte magic header for gzip streams
+   * Recognise the 2-byte magic header indicating a gzipped stream
    * 
+   * see
    * https://recalll.co/ask/v/topic/java-How-to-check-if-InputStream-is-Gzipped/555aadd62bd27354438b90f6
    * 
-   * @param bytes - at least two bytes 
-   * @return 
+   * @param input
+   *          - input stream that supports mark and contains at least two bytes
+   * 
+   * @return false if mark not supported or no magic header found
+   *
+   * @throws IOException
    */
-  private static boolean isGzipStream(byte[] bytes) {
-    int head = ((int) bytes[0] & 0xff) | ((bytes[1] << 8) & 0xff00);
-    return (GZIPInputStream.GZIP_MAGIC == head);
+  public static boolean isGzipStream(InputStream input) throws IOException
+  {
+    if (!input.markSupported())
+    {
+      Cache.log.error(
+              "FileParse.izGzipStream: input stream must support mark/reset");
+      return false;
+    }
+    input.mark(4);
+
+    // get first 2 bytes or return false
+    byte[] bytes = new byte[2];
+    int read = input.read(bytes);
+    input.reset();
+    if (read != bytes.length)
+    {
+      return false;
+    }
+
+    int header = (bytes[0] & 0xff) | ((bytes[1] << 8) & 0xff00);
+    return (GZIPInputStream.GZIP_MAGIC == header);
   }
 
   /**
@@ -226,16 +250,11 @@ public class FileParse
 
     // NB: stackoverflow https://stackoverflow.com/questions/4818468/how-to-check-if-inputstream-is-gzipped
     // could use a PushBackInputStream rather than a BufferedInputStream
-    
-    BufferedInputStream bufinput;
+        
     if (!input.markSupported()) {
-       bufinput= new BufferedInputStream(input,16);
-       input = bufinput;
+       input = new BufferedInputStream(input,16);
     }
-    input.mark(4);
-    byte[] bytes=input.readNBytes(2);
-    input.reset();
-    if (bytes.length==2 && isGzipStream(bytes)) {
+    if (isGzipStream(input)) {
       return getGzipReader(input);
     }
     // return a buffered reader for the stream.
index 6d3c18a..4d8794f 100755 (executable)
@@ -33,6 +33,7 @@ import jalview.datamodel.SequenceI;
 import jalview.util.Comparison;
 
 import java.io.IOException;
+import java.util.Locale;
 
 /**
  * Additional formatting methods used by the application in a number of places.
@@ -161,7 +162,7 @@ public class FormatAdapter extends AppletFormatAdapter
 
   public boolean getCacheSuffixDefault(FileFormatI format)
   {
-    return Cache.getDefault(format.getName().toUpperCase() + "_JVSUFFIX",
+    return Cache.getDefault(format.getName().toUpperCase(Locale.ROOT) + "_JVSUFFIX",
             true);
   }
 
index ff959b0..ed1c29f 100755 (executable)
@@ -21,6 +21,7 @@
 package jalview.io;
 
 import java.io.IOException;
+import java.util.Locale;
 
 /**
  * DOCUMENT ME!
@@ -143,7 +144,7 @@ public class IdentifyFile
             break;
           }
         }
-        data = data.toUpperCase();
+        data = data.toUpperCase(Locale.ROOT);
 
         if (data.startsWith(ScoreMatrixFile.SCOREMATRIX))
         {
@@ -284,7 +285,7 @@ public class IdentifyFile
         if ((lessThan > -1)) // possible Markup Language data i.e HTML,
                              // RNAML, XML
         {
-          String upper = data.toUpperCase();
+          String upper = data.toUpperCase(Locale.ROOT);
           if (upper.substring(lessThan).startsWith("<HTML"))
           {
             reply = FileFormat.Html;
index 6732e82..8f93b48 100755 (executable)
@@ -33,6 +33,7 @@ import jalview.util.MessageManager;
 
 import java.io.IOException;
 import java.util.Hashtable;
+import java.util.Locale;
 import java.util.StringTokenizer;
 import java.util.Vector;
 
@@ -408,7 +409,7 @@ public class JPredFile extends AlignFile
     // check that no stray annotations have been added at the end.
     {
       SequenceI sq = seqs.elementAt(j - 1);
-      if (sq.getName().toUpperCase().startsWith("JPRED"))
+      if (sq.getName().toUpperCase(Locale.ROOT).startsWith("JPRED"))
       {
         annotSeqs.addElement(sq);
         seqs.removeElementAt(--j);
index 6828202..27fc869 100755 (executable)
@@ -20,6 +20,8 @@
  */
 package jalview.io;
 
+import java.util.Locale;
+
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.Annotation;
@@ -88,7 +90,7 @@ public class JnetAnnotationMaker
 
     while (i < preds.length)
     {
-      String id = preds[i].getName().toUpperCase();
+      String id = preds[i].getName().toUpperCase(Locale.ROOT);
 
       if (id.startsWith("LUPAS") || id.startsWith("JNET")
               || id.startsWith("JPRED"))
index df2bed2..db29848 100755 (executable)
@@ -29,6 +29,7 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Hashtable;
 import java.util.List;
+import java.util.Locale;
 import java.util.StringTokenizer;
 
 /**
@@ -184,7 +185,7 @@ public class MSFfile extends AlignFile
   public int checkSum(String seq)
   {
     int check = 0;
-    String sequence = seq.toUpperCase();
+    String sequence = seq.toUpperCase(Locale.ROOT);
 
     for (int i = 0; i < sequence.length(); i++)
     {
index 0b70dce..ee7503d 100644 (file)
  */
 package jalview.io;
 
+import java.io.IOException;
+import java.util.StringTokenizer;
+
 import jalview.analysis.scoremodels.ScoreMatrix;
 import jalview.analysis.scoremodels.ScoreModels;
 import jalview.datamodel.SequenceI;
 
-import java.io.IOException;
-import java.util.StringTokenizer;
-
 /**
  * A class that can parse a file containing a substitution matrix and register
  * it for use in Jalview
@@ -131,7 +131,8 @@ public class ScoreMatrixFile extends AlignFile
       {
         continue;
       }
-      if (data.toUpperCase().startsWith(SCOREMATRIX))
+      // equivalent to data.startsWithIgnoreCase(SCOREMATRIX)
+      if (data.regionMatches(true, 0, SCOREMATRIX, 0, SCOREMATRIX.length()))
       {
         /*
          * Parse name from ScoreMatrix <name>
index beef3e7..71e7c62 100644 (file)
@@ -25,8 +25,8 @@ import jalview.util.MessageManager;
 
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
+import java.awt.event.KeyAdapter;
 import java.awt.event.KeyEvent;
-import java.awt.event.KeyListener;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
@@ -64,12 +64,19 @@ public class JvCacheableInputBox<E> extends JComboBox<String>
     return enterWasPressed;
   }
 
-  public JvCacheableInputBox(String newCacheKey)
+  /**
+   * Constructor given the key to cached values, and the (approximate) length in
+   * characters of the input field
+   * 
+   * @param newCacheKey
+   * @param length
+   */
+  public JvCacheableInputBox(String newCacheKey, int length)
   {
     super();
     this.cacheKey = newCacheKey;
     setEditable(true);
-    addKeyListener(new KeyListener()
+    addKeyListener(new KeyAdapter()
     {
 
       @Override
@@ -82,23 +89,16 @@ public class JvCacheableInputBox<E> extends JComboBox<String>
         }
         // let event bubble up
       }
-
-      @Override
-      public void keyReleased(KeyEvent e)
-      {
-        // TODO Auto-generated method stub
-
-      }
-
-      @Override
-      public void keyPressed(KeyEvent e)
+    });
+    if (length > 0)
+    {
+      StringBuilder sb = new StringBuilder();
+      for (int i = 0; i < length; i++)
       {
-        // TODO Auto-generated method stub
-
+        sb.append("X");
       }
-    });
-    setPrototypeDisplayValue(
-            "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
+      setPrototypeDisplayValue(sb.toString());
+    }
     appCache = AppCache.getInstance();
     initCachePopupMenu();
     initCache(newCacheKey);
index 1635682..91575bf 100644 (file)
@@ -34,6 +34,7 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Locale;
 
 public class ParsePackedSet
 {
@@ -234,7 +235,7 @@ public class ParsePackedSet
       String type = args[i++];
       final String file = args[i++];
       final JvDataType jtype = DataProvider.JvDataType
-              .valueOf(type.toUpperCase());
+              .valueOf(type.toUpperCase(Locale.ROOT));
       if (jtype != null)
       {
         final FileParse fp;
@@ -253,7 +254,7 @@ public class ParsePackedSet
       else
       {
         System.out.println("Couldn't parse source type token '"
-                + type.toUpperCase() + "'");
+                + type.toUpperCase(Locale.ROOT) + "'");
       }
     }
     if (i < args.length)
index 13d7ae8..d6a530b 100644 (file)
@@ -48,6 +48,7 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
@@ -569,7 +570,7 @@ public class VCFLoader
   {
     for (Pattern p : filters)
     {
-      if (p.matcher(id.toUpperCase()).matches())
+      if (p.matcher(id.toUpperCase(Locale.ROOT)).matches())
       {
         return true;
       }
@@ -663,7 +664,7 @@ public class VCFLoader
     {
       try
       {
-      patterns.add(Pattern.compile(token.toUpperCase()));
+      patterns.add(Pattern.compile(token.toUpperCase(Locale.ROOT)));
       } catch (PatternSyntaxException e)
       {
         System.err.println("Invalid pattern ignored: " + token);
index b433570..1600b75 100755 (executable)
@@ -28,11 +28,11 @@ import jalview.io.cache.JvCacheableInputBox;
 import jalview.util.MessageManager;
 
 import java.awt.BorderLayout;
-import java.awt.Dimension;
 import java.awt.Font;
 import java.awt.GridLayout;
-import java.awt.Insets;
 import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.KeyAdapter;
 import java.awt.event.KeyEvent;
 
 import javax.swing.JButton;
@@ -47,19 +47,26 @@ import javax.swing.text.JTextComponent;
 
 public class GFinder extends JPanel
 {
-  private static final java.awt.Font VERDANA_12 = new java.awt.Font("Verdana", 0,
-          12);
+  private static final java.awt.Font VERDANA_12 = new Font("Verdana",
+          Font.PLAIN, 12);
 
   private static final String FINDER_CACHE_KEY = "CACHE.FINDER";
 
-  protected JButton createFeatures = new JButton();
+  /*
+   * if more checkboxes are wanted, increase this value
+   * and add to centrePanel in jbInit()  
+   */
+  private static final int PANEL_ROWS = 4;
+
+  protected JButton createFeatures;
 
-  protected JvCacheableInputBox<String> searchBox = new JvCacheableInputBox<>(
-          getCacheKey());
+  protected JvCacheableInputBox<String> searchBox;
 
-  protected JCheckBox caseSensitive = new JCheckBox();
+  protected JCheckBox caseSensitive;
 
-  protected JCheckBox searchDescription = new JCheckBox();
+  protected JCheckBox searchDescription;
+
+  protected JCheckBox ignoreHidden;
 
   public GFinder()
   {
@@ -72,20 +79,98 @@ public class GFinder extends JPanel
     }
   }
 
+  /**
+   * Constructs the widgets and adds them to the layout
+   */
   private void jbInit() throws Exception
   {
-    BorderLayout mainBorderLayout = new BorderLayout();
-    this.setLayout(mainBorderLayout);
-    mainBorderLayout.setHgap(5);
-    mainBorderLayout.setVgap(5);
+    /*
+     * border layout
+     * West: 4 rows
+     *   first row 'Find'
+     *   remaining rows empty
+     * Center: 4 rows
+     *   first row search box
+     *   second row 'match case' checkbox
+     *   third row 'include description' checkbox
+     *   fourth row 'ignore hidden' checkbox
+     * East: four rows
+     *   first row 'find next' button
+     *   second row 'find all' button
+     *   third row 'new feature' button
+     *   fourth row empty
+     */
+    this.setLayout(new BorderLayout());
+    JPanel eastPanel = new JPanel();
+    eastPanel.setLayout(new GridLayout(PANEL_ROWS, 1));
+    this.add(eastPanel, BorderLayout.EAST);
+    JPanel centrePanel = new JPanel();
+    centrePanel.setLayout(new GridLayout(PANEL_ROWS, 1));
+    this.add(centrePanel, BorderLayout.CENTER);
+    JPanel westPanel = new JPanel();
+    westPanel.setLayout(new GridLayout(PANEL_ROWS, 1));
+    this.add(westPanel, BorderLayout.WEST);
 
-    JLabel jLabelFind = new JLabel(MessageManager.getString("label.find"));
-    jLabelFind.setFont(VERDANA_12);
+    /*
+     * 'Find' prompt goes top left
+     */
+    JLabel findLabel = new JLabel(
+            " " + MessageManager.getString("label.find") + " ");
+    findLabel.setFont(VERDANA_12);
+    westPanel.add(findLabel);
 
+    /*
+     * search box
+     */
+    searchBox = new JvCacheableInputBox<>(FINDER_CACHE_KEY, 25);
+    searchBox.setFont(VERDANA_12);
+    ((JTextComponent) searchBox.getEditor().getEditorComponent())
+            .addCaretListener(new CaretListener()
+            {
+              @Override
+              public void caretUpdate(CaretEvent e)
+              {
+                textfield_caretUpdate();
+              }
+            });
+    searchBox.getEditor().getEditorComponent()
+            .addKeyListener(new KeyAdapter()
+            {
+              @Override
+              public void keyPressed(KeyEvent e)
+              {
+                textfield_keyPressed(e);
+              }
+            });
+    centrePanel.add(searchBox);
+
+    /*
+     * search options checkboxes
+     */
+    caseSensitive = new JCheckBox();
+    caseSensitive.setHorizontalAlignment(SwingConstants.LEFT);
+    caseSensitive.setText(MessageManager.getString("label.match_case"));
+
+    searchDescription = new JCheckBox();
+    searchDescription
+            .setText(MessageManager.getString("label.include_description"));
+
+    ignoreHidden = new JCheckBox();
+    ignoreHidden.setText(MessageManager.getString("label.ignore_hidden"));
+    ignoreHidden.setToolTipText(
+            MessageManager.getString("label.ignore_hidden_tooltip"));
+    
+    centrePanel.add(caseSensitive);
+    centrePanel.add(searchDescription);
+    centrePanel.add(ignoreHidden);
+
+    /*
+     * action buttons
+     */
     JButton findAll = new JButton(
             MessageManager.getString("action.find_all"));
     findAll.setFont(VERDANA_12);
-    findAll.addActionListener(new java.awt.event.ActionListener()
+    findAll.addActionListener(new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
@@ -93,11 +178,10 @@ public class GFinder extends JPanel
         findAll_actionPerformed();
       }
     });
-
     JButton findNext = new JButton(
             MessageManager.getString("action.find_next"));
     findNext.setFont(VERDANA_12);
-    findNext.addActionListener(new java.awt.event.ActionListener()
+    findNext.addActionListener(new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
@@ -105,19 +189,11 @@ public class GFinder extends JPanel
         findNext_actionPerformed();
       }
     });
-
-    JPanel actionsPanel = new JPanel();
-    GridLayout gridLayout1 = new GridLayout();
-    actionsPanel.setLayout(gridLayout1);
-    gridLayout1.setHgap(0);
-    gridLayout1.setRows(3);
-    gridLayout1.setVgap(2);
-
+    createFeatures = new JButton();
     createFeatures.setEnabled(false);
     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()
+    createFeatures.addActionListener(new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
@@ -125,60 +201,9 @@ public class GFinder extends JPanel
         createFeatures_actionPerformed();
       }
     });
-    searchBox.setFont(new java.awt.Font("Verdana", Font.PLAIN, 12));
-    ((JTextComponent) searchBox.getEditor().getEditorComponent())
-            .addCaretListener(new CaretListener()
-            {
-              @Override
-              public void caretUpdate(CaretEvent e)
-              {
-                textfield_caretUpdate();
-              }
-            });
-    searchBox.getEditor().getEditorComponent()
-            .addKeyListener(new java.awt.event.KeyAdapter()
-            {
-              @Override
-              public void keyPressed(KeyEvent e)
-              {
-                textfield_keyPressed(e);
-              }
-            });
-
-    caseSensitive.setHorizontalAlignment(SwingConstants.LEFT);
-    caseSensitive.setText(MessageManager.getString("label.match_case"));
-
-    searchDescription
-            .setText(MessageManager.getString("label.include_description"));
-
-    actionsPanel.add(findNext, null);
-    actionsPanel.add(findAll, null);
-    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);
-    jPanel4.add(searchBox, java.awt.BorderLayout.NORTH);
-
-    JPanel optionsPanel = new JPanel();
-
-    GridLayout optionsGridLayout = new GridLayout();
-    optionsGridLayout.setHgap(0);
-    optionsGridLayout.setRows(2);
-    optionsGridLayout.setVgap(2);
-    optionsPanel.setLayout(optionsGridLayout);
-    optionsPanel.add(caseSensitive, null);
-    optionsPanel.add(searchDescription, null);
-
-    jPanel4.add(optionsPanel, java.awt.BorderLayout.WEST);
+    eastPanel.add(findNext);
+    eastPanel.add(findAll);
+    eastPanel.add(createFeatures);
   }
 
   protected void textfield_keyPressed(KeyEvent e)
@@ -236,15 +261,4 @@ public class GFinder extends JPanel
     }
   }
 
-  /**
-   * Returns unique key used for storing Finder cache items in the cache data
-   * structure
-   * 
-   * @return
-   */
-  public String getCacheKey()
-  {
-    return FINDER_CACHE_KEY;
-  }
-
 }
index adca17e..671bf6b 100644 (file)
@@ -150,6 +150,7 @@ public class AnnotationRenderer
    */
   public void dispose()
   {
+    hiddenColumns = null;
     hconsensus = null;
     complementConsensus = null;
     hStrucConsensus = null;
index b552c21..915293e 100644 (file)
@@ -1020,4 +1020,23 @@ public final class MappingUtils
       }
     }
   }
+
+  /**
+   * Converts a list of [start, end] ranges to a single array of [start, end,
+   * start, end ...]
+   * 
+   * @param ranges
+   * @return
+   */
+  public static int[] listToArray(List<int[]> ranges)
+  {
+    int[] result = new int[ranges.size() * 2];
+    int i = 0;
+    for (int[] range : ranges)
+    {
+      result[i++] = range[0];
+      result[i++] = range[1];
+    }
+    return result;
+  }
 }
index 8dcd1b3..c9a3a80 100644 (file)
@@ -959,6 +959,7 @@ public abstract class AlignmentViewport
     ranges = null;
     currentTree = null;
     selectionGroup = null;
+    colSel = null;
     setAlignment(null);
   }
 
@@ -3044,4 +3045,22 @@ public abstract class AlignmentViewport
       codingComplement.setUpdateStructures(needToUpdateStructureViews);
     }
   }
+
+  @Override
+  public Iterator<int[]> getViewAsVisibleContigs(boolean selectedRegionOnly)
+  {
+    int start = 0;
+    int end = 0;
+    if (selectedRegionOnly && selectionGroup != null)
+    {
+      start = selectionGroup.getStartRes();
+      end = selectionGroup.getEndRes() + 1;
+    }
+    else
+    {
+      end = alignment.getWidth();
+    }
+    return (alignment.getHiddenColumns().getVisContigsIterator(start, end,
+            false));
+  }
 }
index a73af61..d02910c 100644 (file)
@@ -23,9 +23,7 @@ package jalview.ws.dbsources;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.DBRefSource;
 
-import com.stevesoft.pat.Regex;
-
-public class EmblCdsSource extends EmblXmlSource
+public class EmblCdsSource extends EmblFlatfileSource // was EmblXmlSource
 {
 
   public EmblCdsSource()
@@ -34,31 +32,12 @@ public class EmblCdsSource extends EmblXmlSource
   }
 
   @Override
-  public String getAccessionSeparator()
-  {
-    return null;
-  }
-
-  @Override
-  public Regex getAccessionValidator()
-  {
-    return new Regex("^[A-Z]+[0-9]+");
-  }
-
-  @Override
   public String getDbSource()
   {
     return DBRefSource.EMBLCDS;
   }
 
   @Override
-  public String getDbVersion()
-  {
-    return "0"; // TODO : this is dynamically set for a returned record - not
-    // tied to proxy
-  }
-
-  @Override
   public AlignmentI getSequenceRecords(String queries) throws Exception
   {
     if (queries.indexOf(".") > -1)
@@ -68,15 +47,6 @@ public class EmblCdsSource extends EmblXmlSource
     return getEmblSequenceRecords(DBRefSource.EMBLCDS, queries);
   }
 
-  @Override
-  public boolean isValidReference(String accession)
-  {
-    // most embl CDS refs look like ..
-    // TODO: improve EMBLCDS regex
-    return (accession == null || accession.length() < 2) ? false
-            : getAccessionValidator().search(accession);
-  }
-
   /**
    * cDNA for LDHA_CHICK swissprot sequence
    */
@@ -92,10 +62,4 @@ public class EmblCdsSource extends EmblXmlSource
     return "EMBL (CDS)";
   }
 
-  @Override
-  public int getTier()
-  {
-    return 0;
-  }
-
 }
diff --git a/src/jalview/ws/dbsources/EmblFlatfileSource.java b/src/jalview/ws/dbsources/EmblFlatfileSource.java
new file mode 100644 (file)
index 0000000..6536958
--- /dev/null
@@ -0,0 +1,121 @@
+package jalview.ws.dbsources;
+
+import java.io.File;
+import java.io.IOException;
+
+import com.stevesoft.pat.Regex;
+
+import jalview.bin.Cache;
+import jalview.datamodel.Alignment;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.SequenceI;
+import jalview.io.DataSourceType;
+import jalview.io.EmblFlatFile;
+import jalview.io.FileParse;
+import jalview.ws.ebi.EBIFetchClient;
+
+/**
+ * A class that does partial parsing of an EMBL flatfile.
+ * 
+ * @author gmcarstairs
+ *
+ */
+public abstract class EmblFlatfileSource extends EbiFileRetrievedProxy
+{
+  private static final Regex ACCESSION_REGEX = new Regex("^[A-Z]+[0-9]+");
+
+  @Override
+  public String getDbVersion()
+  {
+    return "0";
+  }
+
+  @Override
+  public String getAccessionSeparator()
+  {
+    return null;
+  }
+
+  @Override
+  public Regex getAccessionValidator()
+  {
+    return ACCESSION_REGEX;
+  }
+
+  @Override
+  public boolean isValidReference(String accession)
+  {
+    if (accession == null || accession.length() < 2)
+    {
+      return false;
+    }
+    return getAccessionValidator().search(accession);
+  }
+
+  @Override
+  public AlignmentI getSequenceRecords(String queries) throws Exception
+  {
+    return null;
+  }
+
+  @Override
+  public int getTier()
+  {
+    return 0;
+  }
+
+  protected AlignmentI getEmblSequenceRecords(String dbName, String query)
+          throws Exception
+  {
+    startQuery();
+    EBIFetchClient dbFetch = new EBIFetchClient();
+    File reply;
+    try
+    {
+      reply = dbFetch.fetchDataAsFile(
+              dbName.toLowerCase() + ":" + query.trim(), null, "gz");
+    } catch (Exception e)
+    {
+      stopQuery();
+      throw new Exception(
+              String.format("EBI EMBL retrieval failed for %s:%s",
+                      dbName.toLowerCase(), query.trim()),
+              e);
+    }
+    return getEmblSequenceRecords(dbName, query, reply);
+  }
+
+  private AlignmentI getEmblSequenceRecords(String dbName, String query,
+          File reply) throws IOException
+  {
+    AlignmentI al = null;
+
+    if (reply != null && reply.exists())
+    {
+      file = reply.getAbsolutePath();
+      FileParse fp = new FileParse(file, DataSourceType.FILE);
+      EmblFlatFile emblParser = new EmblFlatFile(fp, getDbSource());
+      emblParser.parse();
+      SequenceI[] seqs = emblParser.getSeqsAsArray();
+      if (seqs.length > 0)
+      {
+        al = new Alignment(seqs);
+      }
+
+      if (al == null)
+      {
+        Cache.log.error(
+                "No record found for '" + dbName + ":" + query + "'");
+      }
+    }
+
+    stopQuery();
+    return al;
+  }
+
+  @Override
+  public boolean isDnaCoding()
+  {
+    return true;
+  }
+}
index 6bbe2e1..df43bc3 100644 (file)
@@ -23,13 +23,11 @@ package jalview.ws.dbsources;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.DBRefSource;
 
-import com.stevesoft.pat.Regex;
-
 /**
  * @author JimP
  * 
  */
-public class EmblSource extends EmblXmlSource
+public class EmblSource extends EmblFlatfileSource // was EmblXmlSource
 {
 
   public EmblSource()
@@ -40,29 +38,6 @@ public class EmblSource extends EmblXmlSource
   /*
    * (non-Javadoc)
    * 
-   * @see jalview.ws.DbSourceProxy#getAccessionSeparator()
-   */
-  @Override
-  public String getAccessionSeparator()
-  {
-    // TODO Auto-generated method stub
-    return null;
-  }
-
-  /*
-   * (non-Javadoc)
-   * 
-   * @see jalview.ws.DbSourceProxy#getAccessionValidator()
-   */
-  @Override
-  public Regex getAccessionValidator()
-  {
-    return new Regex("^[A-Z]+[0-9]+");
-  }
-
-  /*
-   * (non-Javadoc)
-   * 
    * @see jalview.ws.DbSourceProxy#getDbSource()
    */
   @Override
@@ -74,18 +49,6 @@ public class EmblSource extends EmblXmlSource
   /*
    * (non-Javadoc)
    * 
-   * @see jalview.ws.DbSourceProxy#getDbVersion()
-   */
-  @Override
-  public String getDbVersion()
-  {
-    // TODO Auto-generated method stub
-    return "0";
-  }
-
-  /*
-   * (non-Javadoc)
-   * 
    * @see jalview.ws.DbSourceProxy#getSequenceRecords(java.lang.String[])
    */
   @Override
@@ -94,21 +57,6 @@ public class EmblSource extends EmblXmlSource
     return getEmblSequenceRecords(DBRefSource.EMBL, queries);
   }
 
-  /*
-   * (non-Javadoc)
-   * 
-   * @see jalview.ws.DbSourceProxy#isValidReference(java.lang.String)
-   */
-  @Override
-  public boolean isValidReference(String accession)
-  {
-    // most embl refs look like ..
-
-    return (accession == null || accession.length() < 2) ? false
-            : getAccessionValidator().search(accession);
-
-  }
-
   /**
    * return LHD_CHICK coding gene
    */
@@ -123,10 +71,4 @@ public class EmblSource extends EmblXmlSource
   {
     return "EMBL"; // getDbSource();
   }
-
-  @Override
-  public int getTier()
-  {
-    return 0;
-  }
 }
index a420d9f..97d7c9f 100644 (file)
  */
 package jalview.ws.dbsources;
 
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.text.ParseException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.JAXBException;
+import javax.xml.stream.FactoryConfigurationError;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import com.stevesoft.pat.Regex;
+
 import jalview.analysis.SequenceIdMatcher;
 import jalview.bin.Cache;
 import jalview.datamodel.Alignment;
@@ -35,33 +56,23 @@ import jalview.util.DBRefUtils;
 import jalview.util.DnaUtils;
 import jalview.util.MapList;
 import jalview.util.MappingUtils;
-import jalview.util.MessageManager;
 import jalview.ws.ebi.EBIFetchClient;
 import jalview.xml.binding.embl.EntryType;
 import jalview.xml.binding.embl.EntryType.Feature;
 import jalview.xml.binding.embl.EntryType.Feature.Qualifier;
+import jalview.xml.binding.embl.ROOT;
 import jalview.xml.binding.embl.XrefType;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStream;
-import java.text.ParseException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Hashtable;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBException;
-import javax.xml.stream.FactoryConfigurationError;
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-
+/**
+ * Provides XML binding and parsing of EMBL or EMBLCDS records retrieved from
+ * (e.g.) {@code https://www.ebi.ac.uk/ena/data/view/x53828&display=xml}.
+ * 
+ * @deprecated endpoint withdrawn August 2020 (JAL-3692), use EmblFlatfileSource
+ */
 public abstract class EmblXmlSource extends EbiFileRetrievedProxy
 {
+  private static final Regex ACCESSION_REGEX = new Regex("^[A-Z]+[0-9]+");
+
   /*
    * JAL-1856 Embl returns this text for query not found
    */
@@ -96,9 +107,10 @@ public abstract class EmblXmlSource extends EbiFileRetrievedProxy
     } catch (Exception e)
     {
       stopQuery();
-      throw new Exception(MessageManager.formatMessage(
-              "exception.ebiembl_retrieval_failed_on", new String[]
-              { emprefx.toLowerCase(), query.trim() }), e);
+      throw new Exception(
+              String.format("EBI EMBL XML retrieval failed for %s:%s",
+                      emprefx.toLowerCase(), query.trim()),
+              e);
     }
     return getEmblSequenceRecords(emprefx, query, reply);
   }
@@ -180,8 +192,9 @@ public abstract class EmblXmlSource extends EbiFileRetrievedProxy
       XMLStreamReader streamReader = XMLInputFactory.newInstance()
               .createXMLStreamReader(is);
       javax.xml.bind.Unmarshaller um = jc.createUnmarshaller();
-      jalview.xml.binding.embl.ROOT root = (jalview.xml.binding.embl.ROOT) um
-              .unmarshal(streamReader);
+      JAXBElement<ROOT> rootElement = um.unmarshal(streamReader,
+              ROOT.class);
+      ROOT root = rootElement.getValue();
 
       /*
        * document root contains either "entry" or "entrySet"
@@ -561,6 +574,7 @@ public abstract class EmblXmlSource extends EbiFileRetrievedProxy
               proteinSeq = new Sequence(proteinSeqName,
                       product.getSequenceAsString());
               matcher.add(proteinSeq);
+              proteinSeq.setDescription(product.getDescription());
               peptides.add(proteinSeq);
             }
             dnaToProteinMapping.setTo(proteinSeq);
@@ -614,8 +628,7 @@ public abstract class EmblXmlSource extends EbiFileRetrievedProxy
               && dnaToProteinMapping.getTo() != null)
       {
         DBRefEntry dnaToEmblProteinRef = new DBRefEntry(
-                DBRefSource.EMBLCDSProduct, sequenceVersion,
-                proteinId);
+                DBRefSource.EMBLCDSProduct, sequenceVersion, proteinId);
         dnaToEmblProteinRef.setMap(dnaToProteinMapping);
         dnaToProteinMapping.setMappedFromId(proteinId);
         dna.addDBRef(dnaToEmblProteinRef);
@@ -644,7 +657,7 @@ public abstract class EmblXmlSource extends EbiFileRetrievedProxy
     {
       return new int[] {};
     }
-  
+
     try
     {
       List<int[]> ranges = DnaUtils.parseLocation(location);
@@ -708,6 +721,40 @@ public abstract class EmblXmlSource extends EbiFileRetrievedProxy
     return sf;
   }
 
+  @Override
+  public String getAccessionSeparator()
+  {
+    return null;
+  }
+
+  @Override
+  public Regex getAccessionValidator()
+  {
+    return ACCESSION_REGEX;
+  }
+
+  @Override
+  public String getDbVersion()
+  {
+    return "0";
+  }
+
+  @Override
+  public int getTier()
+  {
+    return 0;
+  }
+
+  @Override
+  public boolean isValidReference(String accession)
+  {
+    if (accession == null || accession.length() < 2)
+    {
+      return false;
+    }
+    return getAccessionValidator().search(accession);
+  }
+
   /**
    * Truncates (if necessary) the exon intervals to match 3 times the length of
    * the protein; also accepts 3 bases longer (for stop codon not included in
@@ -726,7 +773,7 @@ public abstract class EmblXmlSource extends EbiFileRetrievedProxy
     }
     int expectedCdsLength = proteinLength * 3;
     int exonLength = MappingUtils.getLength(Arrays.asList(exon));
-  
+
     /*
      * if exon length matches protein, or is shorter, or longer by the 
      * length of a stop codon (3 bases), then leave it unchanged
@@ -736,7 +783,7 @@ public abstract class EmblXmlSource extends EbiFileRetrievedProxy
     {
       return exon;
     }
-  
+
     int origxon[];
     int sxpos = -1;
     int endxon = 0;
@@ -756,7 +803,7 @@ public abstract class EmblXmlSource extends EbiFileRetrievedProxy
           // .println("Truncating final exon interval on region by "
           // + (cdspos - cdslength));
         }
-  
+
         /*
          * shrink the final exon - reduce end position if forward
          * strand, increase it if reverse
@@ -772,7 +819,7 @@ public abstract class EmblXmlSource extends EbiFileRetrievedProxy
         break;
       }
     }
-  
+
     if (sxpos != -1)
     {
       // and trim the exon interval set if necessary
index 07a9df4..8ab5fbb 100644 (file)
@@ -27,6 +27,7 @@ import java.io.BufferedInputStream;
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileOutputStream;
+import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.net.HttpURLConnection;
@@ -91,7 +92,7 @@ public class EBIFetchClient
    *          the query formatted as db:query1;query2;query3
    * @param format
    *          the format wanted
-   * @param extension
+   * @param ext
    *          for the temporary file to hold response (without separator)
    * @return the file holding the response
    * @throws OutOfMemoryError
@@ -201,7 +202,8 @@ public class EBIFetchClient
   {
     // long time = System.currentTimeMillis();
     String url = buildUrl(ids, database, format);
-
+    InputStream is = null;
+    BufferedReader br = null;
     try
     {
       URL rcall = new URL(url);
@@ -213,7 +215,7 @@ public class EBIFetchClient
         System.err.println("Warning: response code " + responseCode
                 + " for " + url);
       }
-      InputStream is = new BufferedInputStream(conn.getInputStream());
+      is = new BufferedInputStream(conn.getInputStream());
       if (outFile != null)
       {
         FileOutputStream fio = new FileOutputStream(outFile);
@@ -228,7 +230,7 @@ public class EBIFetchClient
       }
       else
       {
-        BufferedReader br = new BufferedReader(new InputStreamReader(is));
+        br = new BufferedReader(new InputStreamReader(is));
         String rtn;
         List<String> arl = new ArrayList<String>();
         while ((rtn = br.readLine()) != null)
@@ -257,6 +259,24 @@ public class EBIFetchClient
     {
       // System.err.println("EBIFetch took " + (System.currentTimeMillis() -
       // time) + " ms");
+      if (is != null)
+      {
+        try
+        {
+          is.close();
+        } catch (IOException e)
+        {
+        }
+      }
+      if (br != null)
+      {
+        try
+        {
+          br.close();
+        } catch (IOException e)
+        {
+        }
+      }
     }
     return null;
   }
@@ -275,8 +295,8 @@ public class EBIFetchClient
     if (database.equalsIgnoreCase(DBRefSource.EMBL)
             || database.equalsIgnoreCase(DBRefSource.EMBLCDS))
     {
-      url = "https://www.ebi.ac.uk/ena/data/view/" + ids.toLowerCase()
-              + (format != null ? "&" + format : "");
+      url = "https://www.ebi.ac.uk/ena/browser/api/embl/"
+              + ids.toLowerCase() + "?download=true&gzip=true";
     }
     else
     {
index b5f9653..9790f79 100644 (file)
  */
 package jalview.ws.sifts;
 
-import jalview.analysis.AlignSeq;
-import jalview.analysis.scoremodels.ScoreMatrix;
-import jalview.analysis.scoremodels.ScoreModels;
-import jalview.api.DBRefEntryI;
-import jalview.api.SiftsClientI;
-import jalview.datamodel.DBRefEntry;
-import jalview.datamodel.DBRefSource;
-import jalview.datamodel.SequenceI;
-import jalview.io.StructureFile;
-import jalview.schemes.ResidueProperties;
-import jalview.structure.StructureMapping;
-import jalview.util.Comparison;
-import jalview.util.DBRefUtils;
-import jalview.util.Format;
-import jalview.xml.binding.sifts.Entry;
-import jalview.xml.binding.sifts.Entry.Entity;
-import jalview.xml.binding.sifts.Entry.Entity.Segment;
-import jalview.xml.binding.sifts.Entry.Entity.Segment.ListMapRegion.MapRegion;
-import jalview.xml.binding.sifts.Entry.Entity.Segment.ListResidue.Residue;
-import jalview.xml.binding.sifts.Entry.Entity.Segment.ListResidue.Residue.CrossRefDb;
-import jalview.xml.binding.sifts.Entry.Entity.Segment.ListResidue.Residue.ResidueDetail;
-
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
@@ -73,6 +51,28 @@ import javax.xml.stream.XMLStreamReader;
 
 import MCview.Atom;
 import MCview.PDBChain;
+import jalview.analysis.AlignSeq;
+import jalview.analysis.scoremodels.ScoreMatrix;
+import jalview.analysis.scoremodels.ScoreModels;
+import jalview.api.DBRefEntryI;
+import jalview.api.SiftsClientI;
+import jalview.datamodel.DBRefEntry;
+import jalview.datamodel.DBRefSource;
+import jalview.datamodel.SequenceI;
+import jalview.io.BackupFiles;
+import jalview.io.StructureFile;
+import jalview.schemes.ResidueProperties;
+import jalview.structure.StructureMapping;
+import jalview.util.Comparison;
+import jalview.util.DBRefUtils;
+import jalview.util.Format;
+import jalview.xml.binding.sifts.Entry;
+import jalview.xml.binding.sifts.Entry.Entity;
+import jalview.xml.binding.sifts.Entry.Entity.Segment;
+import jalview.xml.binding.sifts.Entry.Entity.Segment.ListMapRegion.MapRegion;
+import jalview.xml.binding.sifts.Entry.Entity.Segment.ListResidue.Residue;
+import jalview.xml.binding.sifts.Entry.Entity.Segment.ListResidue.Residue.CrossRefDb;
+import jalview.xml.binding.sifts.Entry.Entity.Segment.ListResidue.Residue.ResidueDetail;
 
 public class SiftsClient implements SiftsClientI
 {
@@ -123,6 +123,7 @@ public class SiftsClient implements SiftsClientI
   private enum CoordinateSys
   {
     UNIPROT("UniProt"), PDB("PDBresnum"), PDBe("PDBe");
+
     private String name;
 
     private CoordinateSys(String name)
@@ -140,6 +141,7 @@ public class SiftsClient implements SiftsClientI
   {
     NAME_SEC_STRUCTURE("nameSecondaryStructure"),
     CODE_SEC_STRUCTURE("codeSecondaryStructure"), ANNOTATION("Annotation");
+
     private String code;
 
     private ResidueDetailType(String code)
@@ -225,7 +227,7 @@ public class SiftsClient implements SiftsClientI
               SiftsSettings.getCacheThresholdInDays()))
       {
         File oldSiftsFile = new File(siftsFileName + "_old");
-        siftsFile.renameTo(oldSiftsFile);
+        BackupFiles.moveFileToFile(siftsFile, oldSiftsFile);
         try
         {
           siftsFile = downloadSiftsFile(pdbId.toLowerCase());
@@ -234,7 +236,7 @@ public class SiftsClient implements SiftsClientI
         } catch (IOException e)
         {
           e.printStackTrace();
-          oldSiftsFile.renameTo(siftsFile);
+          BackupFiles.moveFileToFile(oldSiftsFile, siftsFile);
           return new File(siftsFileName);
         }
       }
@@ -461,7 +463,7 @@ public class SiftsClient implements SiftsClientI
           SequenceI seq, java.io.PrintStream os) throws SiftsException
   {
     List<Integer> omitNonObserved = new ArrayList<>();
-    int nonObservedShiftIndex = 0,pdbeNonObserved=0;
+    int nonObservedShiftIndex = 0, pdbeNonObserved = 0;
     // System.out.println("Generating mappings for : " + entityId);
     Entity entity = null;
     entity = getEntityById(entityId);
@@ -492,7 +494,7 @@ public class SiftsClient implements SiftsClientI
     TreeMap<Integer, String> resNumMap = new TreeMap<Integer, String>();
     List<Segment> segments = entity.getSegment();
     SegmentHelperPojo shp = new SegmentHelperPojo(seq, mapping, resNumMap,
-            omitNonObserved, nonObservedShiftIndex,pdbeNonObserved);
+            omitNonObserved, nonObservedShiftIndex, pdbeNonObserved);
     processSegments(segments, shp);
     try
     {
@@ -514,18 +516,20 @@ public class SiftsClient implements SiftsClientI
     {
       throw new SiftsException("SIFTS mapping failed");
     }
-    // also construct a mapping object between the seq-coord sys and the PDB seq's coord sys
+    // also construct a mapping object between the seq-coord sys and the PDB
+    // seq's coord sys
 
     Integer[] keys = mapping.keySet().toArray(new Integer[0]);
     Arrays.sort(keys);
     seqStart = keys[0];
     seqEnd = keys[keys.length - 1];
-    List<int[]> from=new ArrayList<>(),to=new ArrayList<>();
-    int[]_cfrom=null,_cto=null;
+    List<int[]> from = new ArrayList<>(), to = new ArrayList<>();
+    int[] _cfrom = null, _cto = null;
     String matchedSeq = originalSeq;
-    if (seqStart != UNASSIGNED) // fixme! seqStart can map to -1 for a pdb sequence that starts <-1
+    if (seqStart != UNASSIGNED) // fixme! seqStart can map to -1 for a pdb
+                                // sequence that starts <-1
     {
-      for (int seqps:keys)
+      for (int seqps : keys)
       {
         int pdbpos = mapping.get(seqps)[PDBE_POS];
         if (pdbpos == UNASSIGNED)
@@ -533,19 +537,23 @@ public class SiftsClient implements SiftsClientI
           // not correct - pdbpos might be -1, but leave it for now
           continue;
         }
-        if (_cfrom==null || seqps!=_cfrom[1]+1)
+        if (_cfrom == null || seqps != _cfrom[1] + 1)
         {
-          _cfrom = new int[] { seqps,seqps};
+          _cfrom = new int[] { seqps, seqps };
           from.add(_cfrom);
           _cto = null; // discontinuity
-        } else {
-          _cfrom[1]= seqps;
         }
-        if (_cto==null || pdbpos!=1+_cto[1])
+        else
+        {
+          _cfrom[1] = seqps;
+        }
+        if (_cto == null || pdbpos != 1 + _cto[1])
         {
-          _cto = new int[] { pdbpos,pdbpos};
+          _cto = new int[] { pdbpos, pdbpos };
           to.add(_cto);
-        } else {
+        }
+        else
+        {
           _cto[1] = pdbpos;
         }
       }
@@ -567,8 +575,7 @@ public class SiftsClient implements SiftsClientI
       ;
 
       seqFromPdbMapping = new jalview.datamodel.Mapping(null, _cto, _cfrom,
-              1,
-              1);
+              1, 1);
       pdbStart = mapping.get(seqStart)[PDB_RES_POS];
       pdbEnd = mapping.get(seqEnd)[PDB_RES_POS];
       int orignalSeqStart = seq.getStart();
@@ -699,12 +706,12 @@ public class SiftsClient implements SiftsClientI
         }
         // if (currSeqIndex >= seq.getStart() && currSeqIndex <= seqlength) //
         // true
-                                                                         // numbering
-                                                                         // is
-                                                                         // not
-                                                                         // up
-                                                                         // to
-                                                                         // seq.getEnd()
+        // numbering
+        // is
+        // not
+        // up
+        // to
+        // seq.getEnd()
         {
 
           int resNum = (pdbRefDb == null)
@@ -1044,6 +1051,7 @@ public class SiftsClient implements SiftsClientI
     {
       return pdbeNonObserved;
     }
+
     public SequenceI getSeq()
     {
       return seq;
index 5f64b28..95e6c0d 100644 (file)
@@ -71,8 +71,13 @@ public class FinderTest
     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";
+    //@formatter:off
+    String seqData = 
+        "seq1/8-18 ABCD--EF-GHIJI\n" + 
+        "seq2      A--BCDefHI\n" + 
+        "seq3      --bcdEFH\n" + 
+        "seq4      aa---aMMMMMaaa\n";
+    //@formatter:on
     af = new FileLoader().LoadFileWaitTillLoaded(seqData,
             DataSourceType.PASTE);
     av = af.getViewport();
@@ -95,20 +100,20 @@ public class FinderTest
      * find next match only
      */
     Finder f = new Finder(av);
-    f.findNext("E.H", false, false); // 'E, any character, H'
+    f.findNext("E.H", false, false, false); // 'E, any character, H'
     // should match seq2 efH only
     SearchResultsI sr = f.getSearchResults();
-    assertEquals(sr.getSize(), 1);
+    assertEquals(sr.getCount(), 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'
+    f.findAll("E.H", false, false, false); // 'E, any character, H'
     // should match seq2 efH and seq3 EFH
     sr = f.getSearchResults();
-    assertEquals(sr.getSize(), 2);
+    assertEquals(sr.getCount(), 2);
     matches = sr.getResults();
     assertSame(matches.get(0).getSequence(), al.getSequenceAt(1));
     assertSame(matches.get(1).getSequence(), al.getSequenceAt(2));
@@ -129,9 +134,9 @@ public class FinderTest
     /*
      * find first match should return seq1 residue 9
      */
-    f.findNext("9", false, false);
+    f.findNext("9", false, false, false);
     SearchResultsI sr = f.getSearchResults();
-    assertEquals(sr.getSize(), 1);
+    assertEquals(sr.getCount(), 1);
     List<SearchResultMatchI> matches = sr.getResults();
     assertSame(matches.get(0).getSequence(), al.getSequenceAt(0));
     assertEquals(matches.get(0).getStart(), 9);
@@ -139,11 +144,14 @@ public class FinderTest
 
     /*
      * find all matches should return seq1 and seq4 (others are too short)
+     * (and not matches in sequence ids)
      */
     f = new Finder(av);
-    f.findAll("9", false, false);
+    String name = al.getSequenceAt(0).getName();
+    al.getSequenceAt(0).setName("Q9XA0");
+    f.findAll("9", false, false, false);
     sr = f.getSearchResults();
-    assertEquals(sr.getSize(), 2);
+    assertEquals(sr.getCount(), 2);
     matches = sr.getResults();
     assertSame(matches.get(0).getSequence(), al.getSequenceAt(0));
     assertSame(matches.get(1).getSequence(), al.getSequenceAt(3));
@@ -151,12 +159,13 @@ public class FinderTest
     assertEquals(matches.get(0).getEnd(), 9);
     assertEquals(matches.get(1).getStart(), 9);
     assertEquals(matches.get(1).getEnd(), 9);
+    al.getSequenceAt(0).setName(name);
 
     /*
      * parsing of search string as integer is strict
      */
     f = new Finder(av);
-    f.findNext(" 9", false, false);
+    f.findNext(" 9", false, false, false);
     assertTrue(f.getSearchResults().isEmpty());
   }
 
@@ -167,41 +176,41 @@ public class FinderTest
   public void testFindNext()
   {
     /*
-     * start at second sequence; colIndex of -1
+     * start at second sequence; residueIndex of -1
      * means sequence id / description is searched
      */
     Finder f = new Finder(av);
     PA.setValue(f, "sequenceIndex", 1);
-    PA.setValue(f, "columnIndex", -1);
-    f.findNext("e", false, false); // matches id
+    PA.setValue(f, "residueIndex", -1);
+    f.findNext("e", false, false, false); // matches id
 
     assertTrue(f.getSearchResults().isEmpty());
     assertEquals(f.getIdMatches().size(), 1);
     assertSame(f.getIdMatches().get(0), al.getSequenceAt(1));
 
-    // colIndex is now 0 - for use in next find next
+    // residueIndex is now 0 - for use in next find next
     // searching A--BCDefHI
-    assertEquals(PA.getValue(f, "columnIndex"), 0);
+    assertEquals(PA.getValue(f, "residueIndex"), 0);
     f = new Finder(av);
     PA.setValue(f, "sequenceIndex", 1);
-    PA.setValue(f, "columnIndex", 0);
-    f.findNext("e", false, false); // matches in sequence
+    PA.setValue(f, "residueIndex", 0);
+    f.findNext("e", false, false, false); // matches in sequence
     assertTrue(f.getIdMatches().isEmpty());
-    assertEquals(f.getSearchResults().getSize(), 1);
+    assertEquals(f.getSearchResults().getCount(), 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(PA.getValue(f, "sequenceIndex"), 1);
-    // next column position to search from is 7
-    assertEquals(PA.getValue(f, "columnIndex"), 7);
+    // next residue offset to search from is 5
+    assertEquals(PA.getValue(f, "residueIndex"), 5);
 
     // find next from end of sequence - finds next sequence id
     f = new Finder(av);
     PA.setValue(f, "sequenceIndex", 1);
-    PA.setValue(f, "columnIndex", 7);
-    f.findNext("e", false, false);
+    PA.setValue(f, "residueIndex", 7);
+    f.findNext("e", false, false, false);
     assertEquals(f.getIdMatches().size(), 1);
     assertSame(f.getIdMatches().get(0), al.getSequenceAt(2));
     assertTrue(f.getSearchResults().isEmpty());
@@ -223,7 +232,7 @@ public class FinderTest
      * find first match only
      */
     Finder f = new Finder(av2);
-    f.findNext("rAF", false, true);
+    f.findNext("rAF", false, true, false);
     assertEquals(f.getIdMatches().size(), 1);
     assertSame(f.getIdMatches().get(0), al2.getSequenceAt(0));
     assertTrue(f.getSearchResults().isEmpty());
@@ -232,7 +241,7 @@ public class FinderTest
      * find all matches
      */
     f = new Finder(av2);
-    f.findAll("rAF", false, true);
+    f.findAll("rAF", false, true, false);
     assertEquals(f.getIdMatches().size(), 2);
     assertSame(f.getIdMatches().get(0), al2.getSequenceAt(0));
     assertSame(f.getIdMatches().get(1), al2.getSequenceAt(1));
@@ -242,7 +251,7 @@ public class FinderTest
      * case sensitive
      */
     f = new Finder(av2);
-    f.findAll("RAF", true, true);
+    f.findAll("RAF", true, true, false);
     assertEquals(f.getIdMatches().size(), 1);
     assertSame(f.getIdMatches().get(0), al2.getSequenceAt(0));
     assertTrue(f.getSearchResults().isEmpty());
@@ -258,12 +267,12 @@ public class FinderTest
     /*
      * sequence matches should have no duplicates
      */
-    f.findAll("EFH", false, true);
+    f.findAll("EFH", false, true, false);
     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);
+    assertEquals(f.getSearchResults().getCount(), 2);
     SearchResultMatchI match = f.getSearchResults().getResults().get(0);
     assertSame(match.getSequence(), al2.getSequenceAt(1));
     assertEquals(match.getStart(), 5);
@@ -286,7 +295,7 @@ public class FinderTest
      * case insensitive; seq1 occurs twice in sequence id but
      * only one match should be returned
      */
-    f.findAll("SEQ1", false, false);
+    f.findAll("SEQ1", false, false, false);
     assertEquals(f.getIdMatches().size(), 1);
     assertSame(f.getIdMatches().get(0), al.getSequenceAt(0));
     SearchResultsI searchResults = f.getSearchResults();
@@ -296,7 +305,7 @@ public class FinderTest
      * case sensitive
      */
     f = new Finder(av);
-    f.findAll("SEQ1", true, false);
+    f.findAll("SEQ1", true, false, false);
     searchResults = f.getSearchResults();
     assertTrue(searchResults.isEmpty());
 
@@ -307,11 +316,11 @@ public class FinderTest
     AlignViewportI av2 = new AlignViewport(al2);
     al2.addSequence(new Sequence("aBz", "xyzabZpqrAbZ"));
     f = new Finder(av2);
-    f.findAll("ABZ", false, false);
+    f.findAll("ABZ", false, false, false);
     assertEquals(f.getIdMatches().size(), 1);
     assertSame(f.getIdMatches().get(0), al2.getSequenceAt(4));
     searchResults = f.getSearchResults();
-    assertEquals(searchResults.getSize(), 2);
+    assertEquals(searchResults.getCount(), 2);
     SearchResultMatchI match = searchResults.getResults().get(0);
     assertSame(match.getSequence(), al2.getSequenceAt(4));
     assertEquals(match.getStart(), 4);
@@ -328,13 +337,17 @@ public class FinderTest
   @Test(groups = "Functional")
   public void testFind_findNext()
   {
+    // "seq1/8-18 ABCD--EF-GHIJI\n" +
+    // "seq2 A--BCDefHI\n" +
+    // "seq3 --bcdEFH\n" +
+    // "seq4 aa---aMMMMMaaa\n";
     /*
      * efh should be matched in seq2 only
      */
     FinderI f = new Finder(av);
-    f.findNext("EfH", false, false);
+    f.findNext("EfH", false, false, false);
     SearchResultsI searchResults = f.getSearchResults();
-    assertEquals(searchResults.getSize(), 1);
+    assertEquals(searchResults.getCount(), 1);
     SearchResultMatchI match = searchResults.getResults().get(0);
     assertSame(match.getSequence(), al.getSequenceAt(1));
     assertEquals(match.getStart(), 5);
@@ -344,39 +357,39 @@ public class FinderTest
      * I should be found in seq1 (twice) and seq2 (once)
      */
     f = new Finder(av);
-    f.findNext("I", false, false); // find next: seq1/16
+    f.findNext("I", false, false, false); // find next: seq1/16
     searchResults = f.getSearchResults();
-    assertEquals(searchResults.getSize(), 1);
+    assertEquals(searchResults.getCount(), 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
+    f.findNext("I", false, false, false); // find next: seq1/18
     searchResults = f.getSearchResults();
-    assertEquals(searchResults.getSize(), 1);
+    assertEquals(searchResults.getCount(), 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
+    f.findNext("I", false, false, false); // find next: seq2/8
     searchResults = f.getSearchResults();
-    assertEquals(searchResults.getSize(), 1);
+    assertEquals(searchResults.getCount(), 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);
+    f.findNext("I", false, 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
+    f.findNext("I", false, false, false); // find next: seq1/16
     searchResults = f.getSearchResults();
-    assertEquals(searchResults.getSize(), 1);
+    assertEquals(searchResults.getCount(), 1);
     match = searchResults.getResults().get(0);
     assertSame(match.getSequence(), al.getSequenceAt(0));
     assertEquals(match.getStart(), 16);
@@ -388,12 +401,12 @@ public class FinderTest
    * result
    */
   @Test(groups = "Functional")
-  public void testFind_maximalResultOnly()
+  public void testFindAll_maximalResultOnly()
   {
     Finder f = new Finder(av);
-    f.findAll("M+", false, false);
+    f.findAll("M+", false, false, false);
     SearchResultsI searchResults = f.getSearchResults();
-    assertEquals(searchResults.getSize(), 1);
+    assertEquals(searchResults.getCount(), 1);
     SearchResultMatchI match = searchResults.getResults().get(0);
     assertSame(match.getSequence(), al.getSequenceAt(3));
     assertEquals(match.getStart(), 4); // dataset sequence positions
@@ -404,12 +417,12 @@ public class FinderTest
    * Test finding all matches of a sequence pattern in an alignment
    */
   @Test(groups = "Functional")
-  public void testFind_findAll()
+  public void testFindAll()
   {
     Finder f = new Finder(av);
-    f.findAll("EfH", false, false);
+    f.findAll("EfH", false, false, false);
     SearchResultsI searchResults = f.getSearchResults();
-    assertEquals(searchResults.getSize(), 2);
+    assertEquals(searchResults.getCount(), 2);
     SearchResultMatchI match = searchResults.getResults().get(0);
     assertSame(match.getSequence(), al.getSequenceAt(1));
     assertEquals(match.getStart(), 5);
@@ -422,9 +435,9 @@ public class FinderTest
     /*
      * find all I should find 2 positions in seq1, 1 in seq2
      */
-    f.findAll("I", false, false);
+    f.findAll("I", false, false, false);
     searchResults = f.getSearchResults();
-    assertEquals(searchResults.getSize(), 3);
+    assertEquals(searchResults.getCount(), 3);
     match = searchResults.getResults().get(0);
     assertSame(match.getSequence(), al.getSequenceAt(0));
     assertEquals(match.getStart(), 16);
@@ -443,16 +456,16 @@ public class FinderTest
    * Test finding all matches, case-sensitive
    */
   @Test(groups = "Functional")
-  public void testFind_findAllCaseSensitive()
+  public void testFindAll_caseSensitive()
   {
     Finder f = new Finder(av);
 
     /*
      * BC should match seq1/9-10 and seq2/2-3
      */
-    f.findAll("BC", true, false);
+    f.findAll("BC", true, false, false);
     SearchResultsI searchResults = f.getSearchResults();
-    assertEquals(searchResults.getSize(), 2);
+    assertEquals(searchResults.getCount(), 2);
     SearchResultMatchI match = searchResults.getResults().get(0);
     assertSame(match.getSequence(), al.getSequenceAt(0));
     assertEquals(match.getStart(), 9);
@@ -466,15 +479,15 @@ public class FinderTest
      * bc should match seq3/1-2
      */
     f = new Finder(av);
-    f.findAll("bc", true, false);
+    f.findAll("bc", true, false, false);
     searchResults = f.getSearchResults();
-    assertEquals(searchResults.getSize(), 1);
+    assertEquals(searchResults.getCount(), 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);
+    f.findAll("bC", true, false, false);
     assertTrue(f.getSearchResults().isEmpty());
   }
 
@@ -482,7 +495,7 @@ public class FinderTest
    * Test finding next match of a sequence pattern in a selection group
    */
   @Test(groups = "Functional")
-  public void testFind_inSelection()
+  public void testFindNext_inSelection()
   {
     /*
      * select sequences 2 and 3, columns 4-6 which contains
@@ -497,10 +510,10 @@ public class FinderTest
     av.setSelectionGroup(sg);
 
     FinderI f = new Finder(av);
-    f.findNext("b", false, false);
+    f.findNext("b", false, false, false);
     assertTrue(f.getIdMatches().isEmpty());
     SearchResultsI searchResults = f.getSearchResults();
-    assertEquals(searchResults.getSize(), 1);
+    assertEquals(searchResults.getCount(), 1);
     SearchResultMatchI match = searchResults.getResults().get(0);
     assertSame(match.getSequence(), al.getSequenceAt(1));
     assertEquals(match.getStart(), 2);
@@ -509,23 +522,23 @@ public class FinderTest
     /*
      * a second Find should not return the 'b' in seq3 as outside the selection
      */
-    f.findNext("b", false, false);
+    f.findNext("b", false, false, false);
     assertTrue(f.getSearchResults().isEmpty());
     assertTrue(f.getIdMatches().isEmpty());
 
     f = new Finder(av);
-    f.findNext("d", false, false);
+    f.findNext("d", false, false, false);
     assertTrue(f.getIdMatches().isEmpty());
     searchResults = f.getSearchResults();
-    assertEquals(searchResults.getSize(), 1);
+    assertEquals(searchResults.getCount(), 1);
     match = searchResults.getResults().get(0);
     assertSame(match.getSequence(), al.getSequenceAt(1));
     assertEquals(match.getStart(), 4);
     assertEquals(match.getEnd(), 4);
-    f.findNext("d", false, false);
+    f.findNext("d", false, false, false);
     assertTrue(f.getIdMatches().isEmpty());
     searchResults = f.getSearchResults();
-    assertEquals(searchResults.getSize(), 1);
+    assertEquals(searchResults.getCount(), 1);
     match = searchResults.getResults().get(0);
     assertSame(match.getSequence(), al.getSequenceAt(2));
     assertEquals(match.getStart(), 3);
@@ -536,7 +549,7 @@ public class FinderTest
    * Test finding all matches of a search pattern in a selection group
    */
   @Test(groups = "Functional")
-  public void testFind_findAllInSelection()
+  public void testFindAll_inSelection()
   {
     /*
      * select sequences 2 and 3, columns 4-6 which contains
@@ -554,12 +567,12 @@ public class FinderTest
      * search for 'e' should match two sequence ids and one residue
      */
     Finder f = new Finder(av);
-    f.findAll("e", false, false);
+    f.findAll("e", false, 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);
+    assertEquals(searchResults.getCount(), 1);
     SearchResultMatchI match = searchResults.getResults().get(0);
     assertSame(match.getSequence(), al.getSequenceAt(2));
     assertEquals(match.getStart(), 4);
@@ -569,7 +582,7 @@ public class FinderTest
      * search for 'Q' should match two sequence ids only
      */
     f = new Finder(av);
-    f.findAll("Q", false, false);
+    f.findAll("Q", false, false, false);
     assertEquals(f.getIdMatches().size(), 2);
     assertSame(f.getIdMatches().get(0), al.getSequenceAt(1));
     assertSame(f.getIdMatches().get(1), al.getSequenceAt(2));
@@ -600,10 +613,10 @@ public class FinderTest
      * search for 'I' should match two sequence positions
      */
     Finder f = new Finder(av);
-    f.findAll("I", false, false);
+    f.findAll("I", false, false, false);
     assertTrue(f.getIdMatches().isEmpty());
     SearchResultsI searchResults = f.getSearchResults();
-    assertEquals(searchResults.getSize(), 2);
+    assertEquals(searchResults.getCount(), 2);
     SearchResultMatchI match = searchResults.getResults().get(0);
     assertSame(match.getSequence(), al.getSequenceAt(0));
     assertEquals(match.getStart(), 16);
@@ -615,7 +628,8 @@ public class FinderTest
   }
 
   /**
-   * Test that find does not report hidden positions
+   * Test that find does not report hidden positions, but does report matches that
+   * span hidden gaps
    */
   @Test(groups = "Functional")
   public void testFind_withHiddenColumns()
@@ -629,43 +643,92 @@ public class FinderTest
      */
 
     /*
-     * hide 2-4 (CD- -BC bcd ---)
+     * hide column 3 only, search for aaa
+     * should find two matches: aa-[-]-aa and trailing aaa
      */
     HiddenColumns hc = new HiddenColumns();
-    hc.hideColumns(2, 4);
+    hc.hideColumns(3, 3);
     al.setHiddenColumns(hc);
+    Finder f = new Finder(av);
+    f.findAll("aaa", false, false, false);
+    SearchResultsI searchResults = f.getSearchResults();
+    assertEquals(searchResults.getCount(), 2);
+    SearchResultMatchI match = searchResults.getResults().get(0);
+    assertSame(match.getSequence(), al.getSequenceAt(3));
+    assertEquals(match.getStart(), 1);
+    assertEquals(match.getEnd(), 3);
+    match = searchResults.getResults().get(1);
+    assertSame(match.getSequence(), al.getSequenceAt(3));
+    assertEquals(match.getStart(), 9);
+    assertEquals(match.getEnd(), 11);
+
+    /*
+     * hide 2-4 (CD- -BC bcd ---)
+     */
+    hc.hideColumns(2, 4);
 
     /*
      * 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);
+    f = new Finder(av);
+    f.findAll("D", false, false, false);
+    searchResults = f.getSearchResults();
+    assertEquals(searchResults.getCount(), 1);
+    match = searchResults.getResults().get(0);
     assertSame(match.getSequence(), al.getSequenceAt(1));
     assertEquals(match.getStart(), 4);
     assertEquals(match.getEnd(), 4);
 
     /*
+     * search for AD should fail although these are now
+     * consecutive in the visible columns
+     */
+    f = new Finder(av);
+    f.findAll("AD", false, false, false);
+    searchResults = f.getSearchResults();
+    assertTrue(searchResults.isEmpty());
+
+    /*
+     * find all 'aaa' should find both start and end of seq4
+     * (first run includes hidden gaps)
+     */
+    f = new Finder(av);
+    f.findAll("aaa", false, false, false);
+    searchResults = f.getSearchResults();
+    assertEquals(searchResults.getCount(), 2);
+    match = searchResults.getResults().get(0);
+    assertSame(match.getSequence(), al.getSequenceAt(3));
+    assertEquals(match.getStart(), 1);
+    assertEquals(match.getEnd(), 3);
+    match = searchResults.getResults().get(1);
+    assertSame(match.getSequence(), al.getSequenceAt(3));
+    assertEquals(match.getStart(), 9);
+    assertEquals(match.getEnd(), 11);
+
+    /*
      * hide columns 2-5:
-     * find all 'aaa' should find end of seq4 only
+     * find all 'aaa' should match twice in seq4
+     * (first match partly hidden, second all visible)
      */
     hc.hideColumns(2, 5);
     f = new Finder(av);
-    f.findAll("aaa", false, false);
+    f.findAll("aaa", false, false, false);
     searchResults = f.getSearchResults();
-    assertEquals(searchResults.getSize(), 1);
+    assertEquals(searchResults.getCount(), 2);
     match = searchResults.getResults().get(0);
     assertSame(match.getSequence(), al.getSequenceAt(3));
+    assertEquals(match.getStart(), 1);
+    assertEquals(match.getEnd(), 3);
+    match = searchResults.getResults().get(1);
+    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);
+    f.findAll("BE", false, false, false);
     assertTrue(f.getSearchResults().isEmpty());
 
     /*
@@ -675,9 +738,9 @@ public class FinderTest
     hc.revealAllHiddenColumns(new ColumnSelection());
     hc.hideColumns(8, 13);
     f = new Finder(av);
-    f.findNext("H", false, false);
+    f.findNext("H", false, false, false);
     searchResults = f.getSearchResults();
-    assertEquals(searchResults.getSize(), 1);
+    assertEquals(searchResults.getCount(), 1);
     match = searchResults.getResults().get(0);
     assertSame(match.getSequence(), al.getSequenceAt(2));
     assertEquals(match.getStart(), 6);
@@ -718,9 +781,9 @@ public class FinderTest
      * should match seq2/1, seq2/7, not seq3/6
      */
     Finder f = new Finder(av);
-    f.findAll("[AH]", false, false);
+    f.findAll("[AH]", false, false, false);
     SearchResultsI searchResults = f.getSearchResults();
-    assertEquals(searchResults.getSize(), 2);
+    assertEquals(searchResults.getCount(), 2);
     SearchResultMatchI match = searchResults.getResults().get(0);
     assertSame(match.getSequence(), al.getSequenceAt(1));
     assertEquals(match.getStart(), 1);
@@ -730,4 +793,123 @@ public class FinderTest
     assertEquals(match.getStart(), 7);
     assertEquals(match.getEnd(), 7);
   }
+
+  @Test(groups = "Functional")
+  public void testFind_ignoreHiddenColumns()
+  {
+    /*
+     * 0    5   9
+     * ABCD--EF-GHI
+     * A--BCDefHI
+     * --bcdEFH
+     * aa---aMMMMMaaa
+     */
+    HiddenColumns hc = new HiddenColumns();
+    hc.hideColumns(2, 4);
+    hc.hideColumns(7, 7);
+    al.setHiddenColumns(hc);
+
+    /*
+     * now have
+     * 015689
+     * AB-E-GHI
+     * A-DeHI
+     * --EF
+     * aaaMMMMaaa
+     */
+    Finder f = new Finder(av);
+    f.findAll("abe", false, false, true); // true = ignore hidden
+    SearchResultsI searchResults = f.getSearchResults();
+
+    /*
+     * match of seq1 ABE made up of AB and E
+     * note only one match is counted
+     */
+    assertEquals(searchResults.getCount(), 1);
+    assertEquals(searchResults.getResults().size(), 2);
+    SearchResultMatchI match = searchResults.getResults().get(0);
+    assertSame(match.getSequence(), al.getSequenceAt(0));
+    assertEquals(match.getStart(), 8); // A
+    assertEquals(match.getEnd(), 9); // B
+    match = searchResults.getResults().get(1);
+    assertSame(match.getSequence(), al.getSequenceAt(0));
+    assertEquals(match.getStart(), 12); // E
+    assertEquals(match.getEnd(), 12);
+
+    f = new Finder(av);
+    f.findNext("a.E", false, false, true);
+    searchResults = f.getSearchResults();
+    assertEquals(searchResults.getCount(), 1);
+    assertEquals(searchResults.getResults().size(), 2);
+    match = searchResults.getResults().get(0);
+    assertSame(match.getSequence(), al.getSequenceAt(0));
+    assertEquals(match.getStart(), 8); // A
+    assertEquals(match.getEnd(), 9); // B
+    match = searchResults.getResults().get(1);
+    assertSame(match.getSequence(), al.getSequenceAt(0));
+    assertEquals(match.getStart(), 12); // E
+    assertEquals(match.getEnd(), 12);
+
+    f.findNext("a.E", false, false, true);
+    searchResults = f.getSearchResults();
+    assertEquals(searchResults.getCount(), 1);
+    assertEquals(searchResults.getResults().size(), 2);
+    match = searchResults.getResults().get(0);
+    assertSame(match.getSequence(), al.getSequenceAt(1));
+    assertEquals(match.getStart(), 1); // a
+    assertEquals(match.getEnd(), 1);
+    match = searchResults.getResults().get(1);
+    assertSame(match.getSequence(), al.getSequenceAt(1));
+    assertEquals(match.getStart(), 4); // D
+    assertEquals(match.getEnd(), 5); // e
+
+    /*
+     * find all matching across two hidden column regions
+     * note one 'match' is returned as three contiguous matches
+     */
+    f.findAll("BEG", false, false, true);
+    searchResults = f.getSearchResults();
+    assertEquals(searchResults.getCount(), 1);
+    assertEquals(searchResults.getResults().size(), 3);
+    match = searchResults.getResults().get(0);
+    assertSame(match.getSequence(), al.getSequenceAt(0));
+    assertEquals(match.getStart(), 9); // B
+    assertEquals(match.getEnd(), 9);
+    match = searchResults.getResults().get(1);
+    assertSame(match.getSequence(), al.getSequenceAt(0));
+    assertEquals(match.getStart(), 12); // E
+    assertEquals(match.getEnd(), 12);
+    match = searchResults.getResults().get(2);
+    assertSame(match.getSequence(), al.getSequenceAt(0));
+    assertEquals(match.getStart(), 14); // G
+    assertEquals(match.getEnd(), 14);
+
+    /*
+     * now select columns 0-9 and search for A.*H
+     * this should match in the second sequence (split as 3 matches)
+     * but not the first (as H is outside the selection)
+     */
+    SequenceGroup selection = new SequenceGroup();
+    selection.setStartRes(0);
+    selection.setEndRes(9);
+    al.getSequences().forEach(seq -> selection.addSequence(seq, false));
+    av.setSelectionGroup(selection);
+    f.findAll("A.*H", false, false, true);
+    searchResults = f.getSearchResults();
+    assertEquals(searchResults.getCount(), 1);
+    assertEquals(searchResults.getResults().size(), 3);
+    // match made of contiguous matches A, DE, H
+    match = searchResults.getResults().get(0);
+    assertSame(match.getSequence(), al.getSequenceAt(1));
+    assertEquals(match.getStart(), 1); // A
+    assertEquals(match.getEnd(), 1);
+    match = searchResults.getResults().get(1);
+    assertSame(match.getSequence(), al.getSequenceAt(1));
+    assertEquals(match.getStart(), 4); // D
+    assertEquals(match.getEnd(), 5); // E
+    match = searchResults.getResults().get(2);
+    assertSame(match.getSequence(), al.getSequenceAt(1));
+    assertEquals(match.getStart(), 7); // H (there is no G)
+    assertEquals(match.getEnd(), 7);
+  }
 }
index 59fc79d..a5067be 100644 (file)
  */
 package jalview.bin;
 
+import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertNotNull;
 import static org.testng.Assert.assertTrue;
 
 import jalview.gui.JvOptionPane;
+import jalview.io.DataSourceType;
+import jalview.io.FileFormat;
+import jalview.io.FileFormatException;
+import jalview.io.FileFormatI;
+import jalview.io.FileFormats;
+import jalview.io.IdentifyFile;
 
 import java.io.BufferedReader;
 import java.io.File;
@@ -279,7 +286,7 @@ public class CommandLineOperations
     dataProvider = "headlessModeOutputOperationsData")
   public void testHeadlessModeOutputOperations(String harg, String type,
           String fileName, boolean withAWT, int expectedMinFileSize,
-          int timeout)
+          int timeout, String fileFormatType)
   {
     String cmd = harg + type + " " + fileName;
     // System.out.println(">>>>>>>>>>>>>>>> Command : " + cmd);
@@ -291,6 +298,25 @@ public class CommandLineOperations
     assertTrue(file.exists(), msg);
     FileAssert.assertFile(file, msg);
     FileAssert.assertMinLength(file, expectedMinFileSize);
+    if (fileFormatType!=null && fileFormatType.length()>0)
+    {
+      FileFormatI format = FileFormats.getInstance()
+              .forName(fileFormatType);
+      if (format!=null)
+      {
+        try
+        {
+          FileFormatI exportedType = new IdentifyFile()
+                  .identify(file.getAbsolutePath(), DataSourceType.FILE);
+          assertEquals(exportedType, format,
+                  "Exported file type was wrong");
+        } catch (FileFormatException e)
+        {
+          Assert.fail("Couldn't identify file " + file
+                  + " as an alignment format", e);
+        }
+      }
+    }
     if (worker != null && worker.exit == null)
     {
       worker.interrupt();
@@ -343,51 +369,51 @@ public class CommandLineOperations
     String workingDir = "test/jalview/bin/";
     return new Object[][] { { "nodisplay -open examples/uniref50.fa",
         " -eps", workingDir + "test_uniref50_out.eps", true,
-        MINFILESIZE_BIG, TEST_TIMEOUT },
+        MINFILESIZE_BIG, TEST_TIMEOUT, null },
         { "nodisplay -open examples/uniref50.fa", " -eps",
             workingDir + "test_uniref50_out.eps", false,
-            MINFILESIZE_BIG, TEST_TIMEOUT },
+            MINFILESIZE_BIG, TEST_TIMEOUT, null },
         { "nogui -open examples/uniref50.fa", " -eps",
             workingDir + "test_uniref50_out.eps", true, MINFILESIZE_BIG,
-            TEST_TIMEOUT },
+            TEST_TIMEOUT, null },
         { "nogui -open examples/uniref50.fa", " -eps",
             workingDir + "test_uniref50_out.eps", false,
-            MINFILESIZE_BIG, TEST_TIMEOUT },
+            MINFILESIZE_BIG, TEST_TIMEOUT, null },
         { "headless -open examples/uniref50.fa", " -eps",
             workingDir + "test_uniref50_out.eps", true, MINFILESIZE_BIG,
-            TEST_TIMEOUT },
+            TEST_TIMEOUT, null },
         { "headless -open examples/uniref50.fa", " -svg",
             workingDir + "test_uniref50_out.svg", false,
-            MINFILESIZE_BIG, TEST_TIMEOUT },
+            MINFILESIZE_BIG, TEST_TIMEOUT, null },
         { "headless -open examples/uniref50.fa", " -png",
             workingDir + "test_uniref50_out.png", true, MINFILESIZE_BIG,
-            TEST_TIMEOUT },
+            TEST_TIMEOUT, null },
         { "headless -open examples/uniref50.fa", " -html",
             workingDir + "test_uniref50_out.html", true,
-            MINFILESIZE_BIG, TEST_TIMEOUT },
+            MINFILESIZE_BIG, TEST_TIMEOUT, null },
         { "headless -open examples/uniref50.fa", " -fasta",
             workingDir + "test_uniref50_out.mfa", true, MINFILESIZE_SMALL,
-            TEST_TIMEOUT },
+            TEST_TIMEOUT, FileFormat.Fasta.toString() },
         { "headless -open examples/uniref50.fa", " -clustal",
             workingDir + "test_uniref50_out.aln", true, MINFILESIZE_SMALL,
-            TEST_TIMEOUT },
+            TEST_TIMEOUT, FileFormat.Clustal.toString() },
         { "headless -open examples/uniref50.fa", " -msf",
             workingDir + "test_uniref50_out.msf", true, MINFILESIZE_SMALL,
-            TEST_TIMEOUT },
+            TEST_TIMEOUT, FileFormat.MSF.toString() },
         { "headless -open examples/uniref50.fa", " -pileup",
             workingDir + "test_uniref50_out.aln", true, MINFILESIZE_SMALL,
-            TEST_TIMEOUT },
+            TEST_TIMEOUT, FileFormat.Pileup.toString() },
         { "headless -open examples/uniref50.fa", " -pir",
             workingDir + "test_uniref50_out.pir", true, MINFILESIZE_SMALL,
-            TEST_TIMEOUT },
+            TEST_TIMEOUT, FileFormat.PIR.toString() },
         { "headless -open examples/uniref50.fa", " -pfam",
             workingDir + "test_uniref50_out.pfam", true, MINFILESIZE_SMALL,
-            TEST_TIMEOUT },
+            TEST_TIMEOUT, FileFormat.Pfam.toString() },
         { "headless -open examples/uniref50.fa", " -blc",
             workingDir + "test_uniref50_out.blc", true, MINFILESIZE_SMALL,
-            TEST_TIMEOUT },
+            TEST_TIMEOUT, FileFormat.BLC.toString() },
         { "headless -open examples/uniref50.fa", " -jalview",
             workingDir + "test_uniref50_out.jvp", true, MINFILESIZE_SMALL,
-            TEST_TIMEOUT }, };
+            TEST_TIMEOUT, FileFormat.Jalview.toString() }, };
   }
 }
index 7990d21..fde4da1 100644 (file)
@@ -225,7 +225,7 @@ public class AlignViewControllerTest
      *  test Match/Find works first
      */
     FinderI f = new Finder(af.getViewport());
-    f.findAll("M+", true, false);
+    f.findAll("M+", true, false, false);
     assertEquals(
             "Finder found different set of results to manually created SearchResults",
             sr, f.getSearchResults());
index a302d6e..838b259 100644 (file)
@@ -297,11 +297,11 @@ public class SearchResultsTest
     SequenceI seq1 = new Sequence("", "abcdefghijklm");
     SearchResultsI sr = new SearchResults();
     sr.addResult(seq1, 3, 5);
-    assertEquals(1, sr.getSize());
+    assertEquals(1, sr.getCount());
     sr.addResult(seq1, 3, 5);
-    assertEquals(1, sr.getSize());
+    assertEquals(1, sr.getCount());
     sr.addResult(seq1, 3, 6);
-    assertEquals(2, sr.getSize());
+    assertEquals(2, sr.getCount());
   }
 
   /**
index 24697c0..3a5a9e4 100644 (file)
@@ -1,17 +1,8 @@
 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;
-import jalview.bin.Cache;
-import jalview.bin.Jalview;
-import jalview.datamodel.AlignmentI;
-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;
@@ -20,20 +11,96 @@ import java.io.PrintStream;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
+import jalview.analysis.AlignmentGenerator;
+import jalview.bin.Cache;
+import jalview.bin.Jalview;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.SequenceGroup;
+import jalview.io.DataSourceType;
+import jalview.io.FileLoader;
 import junit.extensions.PA;
 
+/**
+ * Provides a simple test that memory is released when all windows are closed.
+ * <ul>
+ * <li>generates a reasonably large alignment and loads it</li>
+ * <li>performs various operations on the alignment</li>
+ * <li>closes all windows</li>
+ * <li>requests garbage collection</li>
+ * <li>asserts that the remaining memory footprint (heap usage) is 'not large'
+ * </li>
+ * </ul>
+ * If the test fails, this means that reference(s) to large object(s) have
+ * failed to be garbage collected. In this case:
+ * <ul>
+ * <li>set a breakpoint just before the test assertion in
+ * {@code checkUsedMemory}</li>
+ * <li>if the test fails intermittently, make this breakpoint conditional on
+ * {@code usedMemory > expectedMax}</li>
+ * <li>run the test to this point (and check that it is about to fail i.e.
+ * {@code usedMemory > expectedMax})</li>
+ * <li>use <a href="https://visualvm.github.io/">visualvm</a> to obtain a heap
+ * dump from the suspended process (and kill the test or let it fail)</li>
+ * <li>inspect the heap dump using visualvm for large objects and their
+ * referers</li>
+ * <li>Tips:</li>
+ * <ul>
+ * <li>Perform GC from the Monitor view in visualvm before requesting the heap
+ * dump - test failure might be simply a delay to GC</li>
+ * <li>View 'Objects' and filter classes to {@code jalview}. Sort columns by
+ * Count, or Size, and look for anything suspicious. For example, if the object
+ * count for {@code Sequence} is non-zero (it shouldn't be), pick any instance,
+ * and follow the chain of {@code references} to find which class(es) still hold
+ * references to sequence objects</li>
+ * <li>If this chain is impracticably long, re-run the test with a smaller
+ * alignment (set width=100, height=10 in {@code generateAlignment()}), to
+ * capture a heap which is qualitatively the same, but much smaller, so easier
+ * to analyse; note this requires an unconditional breakpoint</li>
+ * </ul>
+ * </ul>
+ * <p>
+ * <h2>Fixing memory leaks</h2>
+ * <p>
+ * Experience shows that often a reference is retained (directly or indirectly)
+ * by a Swing (or related) component (for example a {@code MouseListener} or
+ * {@code ActionListener}). There are two possible approaches to fixing:
+ * <ul>
+ * <li>Purist: ensure that all listeners and similar objects are removed when no
+ * longer needed. May be difficult, to achieve and to maintain as code
+ * changes.</li>
+ * <li>Pragmatic: null references to potentially large objects from Jalview
+ * application classes when no longer needed, typically when a panel is closed.
+ * This ensures that even if the JVM keeps a reference to a panel or viewport,
+ * it does not retain a large heap footprint. This is the approach taken in, for
+ * example, {@code AlignmentPanel.closePanel()} and
+ * {@code AnnotationPanel.dispose()}.</li>
+ * <li>Adjust code if necessary; for example an {@code ActionListener} should
+ * act on {@code av.getAlignment()} and not directly on {@code alignment}, as
+ * the latter pattern could leave persistent references to the alignment</li>
+ * </ul>
+ * Add code to 'null unused large object references' until the test passes. For
+ * a final sanity check, capture the heap dump for a passing test, and satisfy
+ * yourself that only 'small' or 'harmless' {@code jalview} object instances
+ * (such as enums or singletons) are left in the heap.
+ */
 public class FreeUpMemoryTest
 {
   private static final int ONE_MB = 1000 * 1000;
 
+  /*
+   * maximum retained heap usage (in MB) for a passing test
+   */
+  private static int MAX_RESIDUAL_HEAP = 45;
+
   /**
    * Configure (read-only) Jalview property settings for test
    */
   @BeforeClass(alwaysRun = true)
   public void setUp()
   {
-    Jalview.main(new String[] { "-nonews", "-props",
-        "test/jalview/testProps.jvprops" });
+    Jalview.main(
+            new String[]
+            { "-nonews", "-props", "test/jalview/testProps.jvprops" });
     String True = Boolean.TRUE.toString();
     Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS", True);
     Cache.applicationProperties.setProperty("SHOW_QUALITY", True);
@@ -42,98 +109,79 @@ public class FreeUpMemoryTest
     Cache.applicationProperties.setProperty("SHOW_IDENTITY", True);
   }
 
-  /**
-   * A simple test that memory is released when all windows are closed.
-   * <ul>
-   * <li>generates a reasonably large alignment and loads it</li>
-   * <li>performs various operations on the alignment</li>
-   * <li>closes all windows</li>
-   * <li>requests garbage collection</li>
-   * <li>asserts that the remaining memory footprint (heap usage) is 'not large'
-   * </li>
-   * </ul>
-   * If the test fails, this suggests that a reference to some large object
-   * (perhaps the alignment data, or some annotation / Tree / PCA data) has
-   * failed to be garbage collected. If this is the case, the heap will need to
-   * be inspected manually (suggest using jvisualvm) in order to track down
-   * where large objects are still referenced. The code (for example
-   * AlignmentViewport.dispose()) should then be updated to ensure references to
-   * large objects are set to null when they are no longer required.
-   * 
-   * @throws IOException
-   */
   @Test(groups = "Memory")
   public void testFreeMemoryOnClose() throws IOException
   {
     File f = generateAlignment();
     f.deleteOnExit();
 
-    long expectedMin = 35L;
-    long usedMemoryAtStart=getUsedMemory();
-    if (usedMemoryAtStart>expectedMin)
-    {
-      System.err.println("used memory before test is "+usedMemoryAtStart+" > "+expectedMin+"MB .. adjusting minimum.");
-      expectedMin = usedMemoryAtStart;
-    }
     doStuffInJalview(f);
 
     Desktop.instance.closeAll_actionPerformed(null);
 
-    checkUsedMemory(expectedMin);
+    checkUsedMemory(MAX_RESIDUAL_HEAP);
   }
 
-  private static long getUsedMemory()
+  /**
+   * Returns the current total used memory (available memory - free memory),
+   * rounded down to the nearest MB
+   * 
+   * @return
+   */
+  private static int getUsedMemory()
   {
-    long availableMemory = Runtime.getRuntime().totalMemory() / ONE_MB;
-    long freeMemory = Runtime.getRuntime().freeMemory() / ONE_MB;
+    long availableMemory = Runtime.getRuntime().totalMemory();
+    long freeMemory = Runtime.getRuntime().freeMemory();
     long usedMemory = availableMemory - freeMemory;
-    return usedMemory;
+
+    return (int) (usedMemory / ONE_MB);
   }
+
   /**
    * Requests garbage collection and then checks whether remaining memory in use
    * is less than the expected value (in Megabytes)
    * 
    * @param expectedMax
    */
-  protected void checkUsedMemory(long expectedMax)
+  protected void checkUsedMemory(int expectedMax)
   {
     /*
-     * request garbage collection and wait for it to run;
+     * request garbage collection and wait for it to run (up to 3 times);
      * NB there is no guarantee when, or whether, it will do so
-     * wait time depends on JRE/processor, generous allowance here  
      */
-    System.gc();
-    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(1500);
-
-    /*
-     * check used memory is 'reasonably low'
-     */
-    long usedMemory = getUsedMemory();
-    /*
-     * sanity check - fails if any frame was added after
-     * closeAll_actionPerformed
-     */
-    assertEquals(Desktop.instance.getAllFrames().length, 0);
+    long usedMemory = 0L;
+    Long minUsedMemory = null;
+    int gcCount = 0;
+    while (gcCount < 3)
+    {
+      gcCount++;
+      System.gc();
+      waitFor(1500);
+      usedMemory = getUsedMemory();
+      if (minUsedMemory == null || usedMemory < minUsedMemory)
+      {
+        minUsedMemory = usedMemory;
+      }
+      if (usedMemory < expectedMax)
+      {
+        break;
+      }
+    }
 
     /*
-     * if this assertion fails
-     * - set a breakpoint here
-     * - run jvisualvm to inspect a heap dump of Jalview
-     * - identify large objects in the heap and their referers
+     * if this assertion fails (reproducibly!)
+     * - set a breakpoint here, conditional on (usedMemory > expectedMax)
+     * - run VisualVM to inspect the heap usage, and run GC from VisualVM to check 
+     *   it is not simply delayed garbage collection causing the test failure 
+     * - take a heap dump and identify large objects in the heap and their referers
      * - fix code as necessary to null the references on close
      */
-    System.out.println("Used memory after gc = " + usedMemory + "MB");
-    assertTrue(usedMemory < expectedMax, String.format(
+    System.out.println("(Minimum) Used memory after " + gcCount
+            + " call(s) to gc() = " + minUsedMemory + "MB (should be <="
+            + expectedMax + ")");
+    assertTrue(usedMemory <= expectedMax, String.format(
             "Used memory %d should be less than %d (Recommend running test manually to verify)",
-            usedMemory,
-            expectedMax));
+            usedMemory, expectedMax));
   }
 
   /**
@@ -193,7 +241,7 @@ public class FreeUpMemoryTest
      * wait until Tree and PCA have been computed
      */
     while (af.viewport.getCurrentTree() == null
-            && dialog.getPcaPanel().isWorking())
+            || dialog.getPcaPanel().isWorking())
     {
       waitFor(10);
     }
@@ -237,6 +285,7 @@ public class FreeUpMemoryTest
     int width = 100000;
     int height = 100;
     ag.generate(width, height, 0, 10, 15);
+    ps.close();
     return f;
   }
 }
index 64cf902..1386bfe 100644 (file)
@@ -209,6 +209,7 @@ public class BackupFilesTest
           boolean noMax)
   {
     Cache.loadProperties("test/jalview/io/testProps.jvprops");
+    Cache.initLogger();
 
     BackupFilesPresetEntry bfpe = new BackupFilesPresetEntry(suffix, digits,
             reverse, noMax, rollMax, false);
diff --git a/test/jalview/io/EmblFlatFileTest.java b/test/jalview/io/EmblFlatFileTest.java
new file mode 100644 (file)
index 0000000..5d8ef21
--- /dev/null
@@ -0,0 +1,347 @@
+package jalview.io;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+import static org.testng.AssertJUnit.assertNotNull;
+import static org.testng.AssertJUnit.assertNull;
+import static org.testng.AssertJUnit.assertSame;
+import static org.testng.AssertJUnit.fail;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Set;
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import jalview.bin.Cache;
+import jalview.datamodel.DBRefEntry;
+import jalview.datamodel.Mapping;
+import jalview.datamodel.SequenceFeature;
+import jalview.datamodel.SequenceI;
+import jalview.datamodel.features.SequenceFeatures;
+import jalview.util.MapList;
+
+public class EmblFlatFileTest
+{
+  @BeforeClass(alwaysRun = true)
+  public void setUp()
+  {
+    Cache.initLogger();
+  }
+
+  /**
+   * A fairly tough test, using J03321 (circular DNA), which has 8 CDS features,
+   * one of them reverse strand
+   * 
+   * @throws MalformedURLException
+   * @throws IOException
+   */
+  @Test(groups = "Functional")
+  public void testParse() throws MalformedURLException, IOException
+  {
+    File dataFile = new File("test/jalview/io/J03321.embl.txt");
+    FileParse fp = new FileParse(dataFile.getAbsolutePath(), DataSourceType.FILE);
+    EmblFlatFile parser = new EmblFlatFile(fp, "EmblTest");
+    parser.parse();
+    List<SequenceI> seqs = parser.getSeqs();
+
+    assertEquals(seqs.size(), 1);
+    SequenceI seq = seqs.get(0);
+    assertEquals(seq.getName(), "EmblTest|J03321");
+    assertEquals(seq.getLength(), 7502);
+    assertEquals(seq.getDescription(),
+            "Chlamydia trachomatis plasmid pCHL1, complete sequence");
+
+    /*
+     * should be 9 CDS features (one is a 'join' of two exons)
+     */
+    Set<String> featureTypes = seq.getFeatures().getFeatureTypes();
+    assertEquals(featureTypes.size(), 1);
+    assertTrue(featureTypes.contains("CDS"));
+
+    /*
+     * inspect some features (sorted just for convenience of test assertions)
+     */
+    List<SequenceFeature> features = seq.getFeatures()
+            .getAllFeatures("CDS");
+    SequenceFeatures.sortFeatures(features, true);
+    assertEquals(features.size(), 9);
+
+    SequenceFeature sf = features.get(0);
+    assertEquals(sf.getBegin(), 1);
+    assertEquals(sf.getEnd(), 437);
+    assertEquals(sf.getDescription(),
+            "Exon 2 for protein EMBLCDS:AAA91567.1");
+    assertEquals(sf.getFeatureGroup(), "EmblTest");
+    assertEquals(sf.getEnaLocation(), "join(7022..7502,1..437)");
+    assertEquals(sf.getPhase(), "0");
+    assertEquals(sf.getStrand(), 1);
+    assertEquals(sf.getValue("note"), "pGP7-D");
+    // this is the second exon of circular CDS!
+    assertEquals(sf.getValue("exon number"), 2);
+    assertEquals(sf.getValue("product"), "hypothetical protein");
+    assertEquals(sf.getValue("transl_table"), "11");
+
+    sf = features.get(1);
+    assertEquals(sf.getBegin(), 488);
+    assertEquals(sf.getEnd(), 1480);
+    assertEquals(sf.getDescription(),
+            "Exon 1 for protein EMBLCDS:AAA91568.1");
+    assertEquals(sf.getFeatureGroup(), "EmblTest");
+    assertEquals(sf.getEnaLocation(), "complement(488..1480)");
+    assertEquals(sf.getPhase(), "0");
+    assertEquals(sf.getStrand(), -1); // reverse strand!
+    assertEquals(sf.getValue("note"), "pGP8-D");
+    assertEquals(sf.getValue("exon number"), 1);
+    assertEquals(sf.getValue("product"), "hypothetical protein");
+
+    sf = features.get(7);
+    assertEquals(sf.getBegin(), 6045);
+    assertEquals(sf.getEnd(), 6788);
+    assertEquals(sf.getDescription(),
+            "Exon 1 for protein EMBLCDS:AAA91574.1");
+    assertEquals(sf.getFeatureGroup(), "EmblTest");
+    assertEquals(sf.getEnaLocation(), "6045..6788");
+    assertEquals(sf.getPhase(), "0");
+    assertEquals(sf.getStrand(), 1);
+    assertEquals(sf.getValue("note"), "pGP6-D (gtg start codon)");
+    assertEquals(sf.getValue("exon number"), 1);
+    assertEquals(sf.getValue("product"), "hypothetical protein");
+
+    /*
+     * CDS at 7022-7502 is the first exon of the circular CDS
+     */
+    sf = features.get(8);
+    assertEquals(sf.getBegin(), 7022);
+    assertEquals(sf.getEnd(), 7502);
+    assertEquals(sf.getDescription(),
+            "Exon 1 for protein EMBLCDS:AAA91567.1");
+    assertEquals(sf.getFeatureGroup(), "EmblTest");
+    assertEquals(sf.getEnaLocation(), "join(7022..7502,1..437)");
+    assertEquals(sf.getPhase(), "0");
+    assertEquals(sf.getStrand(), 1);
+    assertEquals(sf.getValue("note"), "pGP7-D");
+    assertEquals(sf.getValue("exon number"), 1);
+    assertEquals(sf.getValue("product"), "hypothetical protein");
+
+    /*
+     * Verify DBRefs, whether declared in the file or added by Jalview.
+     * There are 4 'direct' (DR) dbrefs, and numerous CDS /db_xref entries 
+     * (some e.g. INTERPRO are duplicates). Jalview adds a dbref to 'self'.
+     * Sample a few here. Note DBRefEntry constructor capitalises source.
+     */
+    List<DBRefEntry> dbrefs = Arrays.asList(seq.getDBRefs());
+
+    assertEquals(dbrefs.size(), 32);
+    // xref to 'self':
+    DBRefEntry selfRef = new DBRefEntry("EMBLTEST", "1", "J03321");
+    int[] range = new int[] { 1, seq.getLength() };
+    selfRef.setMap(new Mapping(null, range, range, 1, 1));
+    assertTrue(dbrefs.contains(selfRef));
+
+    // 1st DR line; note trailing period is removed
+    assertTrue(dbrefs.contains(new DBRefEntry("MD5", "0",
+            "d4c4942a634e3df4995fd5ac75c26a61")));
+    // the 4th DR line:
+    assertTrue(
+            dbrefs.contains(new DBRefEntry("EUROPEPMC", "0", "PMC87941")));
+    // from the first CDS feature
+    assertTrue(dbrefs.contains(new DBRefEntry("GOA", "0", "P0CE19")));
+    // from the last CDS feature
+    assertTrue(
+            dbrefs.contains(new DBRefEntry("INTERPRO", "0", "IPR005350")));
+
+    /*
+     * verify mappings to, and sequences for, UNIPROT proteins
+     */
+    int uniprotCount = 0;
+    List<int[]> ranges;
+    for (DBRefEntry dbref : dbrefs)
+    {
+      if ("UNIPROT".equals(dbref.getSource()))
+      {
+        uniprotCount++;
+        Mapping mapping = dbref.getMap();
+        assertNotNull(mapping);
+        MapList map = mapping.getMap();
+        String mappedToName = mapping.getTo().getName();
+        if ("UNIPROT|P0CE16".equals(mappedToName))
+        {
+          assertEquals((ranges = map.getFromRanges()).size(), 1);
+          assertEquals(ranges.get(0)[0], 1579);
+          assertEquals(ranges.get(0)[1], 2934);
+          assertEquals((ranges = map.getToRanges()).size(), 1);
+          assertEquals(ranges.get(0)[0], 1);
+          assertEquals(ranges.get(0)[1], 451);
+          // CDS /product carries over as protein product description
+          assertEquals(mapping.getTo().getDescription(),
+                  "hypothetical protein");
+        }
+        else if ("UNIPROT|P0CE17".equals(mappedToName))
+        {
+          assertEquals((ranges = map.getFromRanges()).size(), 1);
+          assertEquals(ranges.get(0)[0], 2928);
+          assertEquals(ranges.get(0)[1], 3992);
+          assertEquals((ranges = map.getToRanges()).size(), 1);
+          assertEquals(ranges.get(0)[0], 1);
+          assertEquals(ranges.get(0)[1], 354);
+        }
+        else if ("UNIPROT|P0CE18".equals(mappedToName))
+        {
+          assertEquals((ranges = map.getFromRanges()).size(), 1);
+          assertEquals(ranges.get(0)[0], 4054);
+          assertEquals(ranges.get(0)[1], 4848);
+          assertEquals((ranges = map.getToRanges()).size(), 1);
+          assertEquals(ranges.get(0)[0], 1);
+          assertEquals(ranges.get(0)[1], 264);
+        }
+        else if ("UNIPROT|P0CE19".equals(mappedToName))
+        {
+          // join(7022..7502,1..437)
+          assertEquals((ranges = map.getFromRanges()).size(), 2);
+          assertEquals(ranges.get(0)[0], 7022);
+          assertEquals(ranges.get(0)[1], 7502);
+          assertEquals(ranges.get(1)[0], 1);
+          assertEquals(ranges.get(1)[1], 437);
+          assertEquals((ranges = map.getToRanges()).size(), 1);
+          assertEquals(ranges.get(0)[0], 1);
+          assertEquals(ranges.get(0)[1], 305);
+        }
+        else if ("UNIPROT|P0CE20".equals(mappedToName))
+        {
+          // complement(488..1480)
+          assertEquals((ranges = map.getFromRanges()).size(), 1);
+          assertEquals(ranges.get(0)[0], 1480);
+          assertEquals(ranges.get(0)[1], 488);
+          assertEquals((ranges = map.getToRanges()).size(), 1);
+          assertEquals(ranges.get(0)[0], 1);
+          assertEquals(ranges.get(0)[1], 330);
+        }
+        else if (!"UNIPROT|P0CE23".equals(mappedToName)
+                && !"UNIPROT|P10559".equals(mappedToName)
+                && !"UNIPROT|P10560".equals(mappedToName))
+        {
+          fail("Unexpected UNIPROT dbref to " + mappedToName);
+        }
+      }
+    }
+    assertEquals(uniprotCount, 8);
+  }
+
+  @Test(groups = "Functional")
+  public void testParse_codonStartNot1()
+  {
+    // TODO verify CDS-to-protein mapping for CDS with /codon_start=2
+    // example: https://www.ebi.ac.uk/ena/browser/api/embl/EU498516
+  }
+
+  /**
+   * Test for the case that the EMBL CDS has no UNIPROT xref. In this case
+   * Jalview should synthesize an xref to EMBLCDSPROTEIN in the hope this will
+   * allow Get Cross-References.
+   * 
+   * @throws IOException
+   */
+  @Test(groups = "Functional")
+  public void testParse_noUniprotXref() throws IOException
+  {
+    // MN908947 cut down to 40BP, one CDS, length 5 peptide for test purposes
+    // plus an additional (invented) test case:
+    // - multi-line /product qualifier including escaped quotes
+    String data = "ID   MN908947; SV 3; linear; genomic RNA; STD; VRL; 20 BP.\n"
+            + "DE   Severe acute respiratory syndrome coronavirus 2 isolate Wuhan-Hu-1,\n"
+            + "FT   CDS             3..17\n"
+            + "FT                   /protein_id=\"QHD43415.1\"\n"
+            + "FT                   /product=\"orf1ab polyprotein\n"
+            + "FT                   \"\"foobar\"\" \"\n"
+            + "FT                   /translation=\"MRKLD\n"
+            + "SQ   Sequence 7496 BP; 2450 A; 1290 C; 1434 G; 2322 T; 0 other;\n"
+            + "     ggatGcgtaa gttagacgaa attttgtctt tgcgcacaga        40\n";
+    FileParse fp = new FileParse(data, DataSourceType.PASTE);
+    EmblFlatFile parser = new EmblFlatFile(fp, "EmblTest");
+    parser.parse();
+    List<SequenceI> seqs = parser.getSeqs();
+    assertEquals(seqs.size(), 1);
+    SequenceI seq = seqs.get(0);
+    List<DBRefEntry> dbrefs = Arrays.asList(seq.getDBRefs());
+
+    /*
+     * dna should have dbref to itself, and to inferred EMBLCDSPROTEIN:QHD43415.1
+     */
+    assertEquals(dbrefs.size(), 2);
+    
+    // dbref to self
+    DBRefEntry dbref = dbrefs.get(0);
+    assertEquals(dbref.getSource(), "EMBLTEST");
+    assertEquals(dbref.getAccessionId(), "MN908947");
+    Mapping mapping = dbref.getMap();
+    assertNull(mapping.getTo());
+    MapList map = mapping.getMap();
+    assertEquals(map.getFromLowest(), 1);
+    assertEquals(map.getFromHighest(), 40);
+    assertEquals(map.getToLowest(), 1);
+    assertEquals(map.getToHighest(), 40);
+    assertEquals(map.getFromRatio(), 1);
+    assertEquals(map.getToRatio(), 1);
+    
+    // dbref to inferred EMBLCDSPROTEIN:
+    dbref = dbrefs.get(1);
+    assertEquals(dbref.getSource(), "EMBLCDSPROTEIN");
+    assertEquals(dbref.getAccessionId(), "QHD43415.1");
+    mapping = dbref.getMap();
+    SequenceI mapTo = mapping.getTo();
+    assertEquals(mapTo.getName(), "QHD43415.1");
+    // the /product qualifier transfers to protein product description
+    assertEquals(mapTo.getDescription(), "orf1ab polyprotein \"foobar\"");
+    assertEquals(mapTo.getSequenceAsString(), "MRKLD");
+    map = mapping.getMap();
+    assertEquals(map.getFromLowest(), 3);
+    assertEquals(map.getFromHighest(), 17);
+    assertEquals(map.getToLowest(), 1);
+    assertEquals(map.getToHighest(), 5);
+    assertEquals(map.getFromRatio(), 3);
+    assertEquals(map.getToRatio(), 1);
+  }
+
+  @Test(groups = "Functional")
+  public void testAdjustForProteinLength()
+  {
+    int[] exons = new int[] { 11, 15, 21, 25, 31, 38 }; // 18 bp
+
+    // exact length match:
+    assertSame(exons, EmblFlatFile.adjustForProteinLength(6, exons));
+
+    // match if we assume exons include stop codon not in protein:
+    assertSame(exons, EmblFlatFile.adjustForProteinLength(5, exons));
+
+    // truncate last exon by 6bp
+    int[] truncated = EmblFlatFile.adjustForProteinLength(4, exons);
+    assertEquals("[11, 15, 21, 25, 31, 32]", Arrays.toString(truncated));
+
+    // remove last exon and truncate preceding by 1bp (so 3bp in total)
+    truncated = EmblFlatFile.adjustForProteinLength(3, exons);
+    assertEquals("[11, 15, 21, 24]", Arrays.toString(truncated));
+
+    // exact removal of exon case:
+    exons = new int[] { 11, 15, 21, 27, 33, 38 }; // 18 bp
+    truncated = EmblFlatFile.adjustForProteinLength(4, exons);
+    assertEquals("[11, 15, 21, 27]", Arrays.toString(truncated));
+
+    // what if exons are too short for protein?
+    truncated = EmblFlatFile.adjustForProteinLength(7, exons);
+    assertSame(exons, truncated);
+  }
+
+  @Test(groups = "Functional")
+  public void testRemoveQuotes()
+  {
+    assertNull(EmblFlatFile.removeQuotes(null));
+    assertEquals(EmblFlatFile.removeQuotes("No quotes here"), "No quotes here");
+    assertEquals(EmblFlatFile.removeQuotes("\"Enclosing quotes\""), "Enclosing quotes");
+    assertEquals(EmblFlatFile.removeQuotes("\"Escaped \"\"quotes\"\" example\""), "Escaped \"quotes\" example");
+  }
+}
index f6480a6..04d01b0 100644 (file)
  */
 package jalview.io;
 
-import jalview.gui.JvOptionPane;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
 
+import java.io.BufferedInputStream;
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.IOException;
+import java.io.InputStream;
 
 import org.testng.AssertJUnit;
 import org.testng.annotations.AfterClass;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
+import jalview.bin.Cache;
+import jalview.gui.JvOptionPane;
+
 /**
  * @author jimp
  * 
@@ -50,6 +57,7 @@ public class FileIOTester
   @BeforeClass(alwaysRun = true)
   public static void setUpBeforeClass() throws Exception
   {
+    Cache.initLogger();
   }
 
   /**
@@ -88,8 +96,9 @@ public class FileIOTester
   public void testStarsInFasta1() throws IOException
   {
     String uri;
-    FileParse fp = new FileParse(uri = STARS_FA_FILE1.getAbsoluteFile()
-            .toString(), DataSourceType.FILE);
+    FileParse fp = new FileParse(
+            uri = STARS_FA_FILE1.getAbsoluteFile().toString(),
+            DataSourceType.FILE);
     assertValidFormat(FileFormat.Fasta, uri, fp);
   }
 
@@ -97,8 +106,9 @@ public class FileIOTester
   public void testStarsInFasta2() throws IOException
   {
     String uri;
-    FileParse fp = new FileParse(uri = STARS_FA_FILE2.getAbsoluteFile()
-            .toString(), DataSourceType.FILE);
+    FileParse fp = new FileParse(
+            uri = STARS_FA_FILE2.getAbsoluteFile().toString(),
+            DataSourceType.FILE);
     assertValidFormat(FileFormat.Fasta, uri, fp);
   }
 
@@ -106,8 +116,9 @@ public class FileIOTester
   public void testGzipIo() throws IOException
   {
     String uri;
-    FileParse fp = new FileParse(uri = ALIGN_FILE.getAbsoluteFile().toURI()
-            .toString(), DataSourceType.URL);
+    FileParse fp = new FileParse(
+            uri = ALIGN_FILE.getAbsoluteFile().toURI().toString(),
+            DataSourceType.URL);
     assertValidFormat(FileFormat.Fasta, uri, fp);
   }
 
@@ -115,17 +126,36 @@ public class FileIOTester
   public void testGziplocalFileIO() throws IOException
   {
     String filepath;
-    FileParse fp = new FileParse(filepath = ALIGN_FILE.getAbsoluteFile()
-            .toString(), DataSourceType.FILE);
+    FileParse fp = new FileParse(
+            filepath = ALIGN_FILE.getAbsoluteFile().toString(),
+            DataSourceType.FILE);
     assertValidFormat(FileFormat.Fasta, filepath, fp);
   }
 
   @Test(groups = { "Functional" })
+  public void testIsGzipInputStream() throws IOException
+  {
+    InputStream is = new FileInputStream(ALIGN_FILE);
+    
+    /*
+     * first try fails - FileInputStream does not support mark/reset
+     */
+    assertFalse(FileParse.isGzipStream(is));
+    
+    /*
+     * wrap in a BufferedInputStream and try again
+     */
+    is = new BufferedInputStream(is, 16);
+    assertTrue(FileParse.isGzipStream(is));
+  }
+
+  @Test(groups = { "Functional" })
   public void testNonGzipURLIO() throws IOException
   {
     String uri;
-    FileParse fp = new FileParse(uri = NOTGZALIGN_FILE.getAbsoluteFile()
-            .toURI().toString(), DataSourceType.URL);
+    FileParse fp = new FileParse(
+            uri = NOTGZALIGN_FILE.getAbsoluteFile().toURI().toString(),
+            DataSourceType.URL);
     assertValidFormat(FileFormat.Fasta, uri, fp);
   }
 
@@ -133,8 +163,9 @@ public class FileIOTester
   public void testNonGziplocalFileIO() throws IOException
   {
     String filepath;
-    FileParse fp = new FileParse(filepath = NOTGZALIGN_FILE
-            .getAbsoluteFile().toString(), DataSourceType.FILE);
+    FileParse fp = new FileParse(
+            filepath = NOTGZALIGN_FILE.getAbsoluteFile().toString(),
+            DataSourceType.FILE);
     assertValidFormat(FileFormat.Fasta, filepath, fp);
   }
 }
diff --git a/test/jalview/io/J03321.embl.txt b/test/jalview/io/J03321.embl.txt
new file mode 100644 (file)
index 0000000..b0bc512
--- /dev/null
@@ -0,0 +1,306 @@
+ID   J03321; SV 1; circular; genomic DNA; STD; PRO; 7502 BP.
+XX
+AC   J03321;
+XX
+DT   27-JUL-1990 (Rel. 24, Created)
+DT   10-APR-2020 (Rel. 144, Last updated, Version 9)
+XX
+DE   Chlamydia trachomatis plasmid pCHL1, complete sequence.
+XX
+KW   .
+XX
+OS   Chlamydia trachomatis
+OC   Bacteria; Chlamydiae; Chlamydiales; Chlamydiaceae;
+OC   Chlamydia/Chlamydophila group; Chlamydia.
+OG   Plasmid pCHL1
+XX
+RN   [1]
+RP   1-7502
+RX   DOI; 10.1016/0147-619X(90)90034-A.
+RX   PUBMED; 2194229.
+RA   Comanducci M., Ricci S., Cevenini R., Ratti G.;
+RT   "Diversity of the Chlamydia trachomatis common plasmid in biovars with
+RT   different pathogenicity";
+RL   Plasmid 23(2):149-154(1990).
+XX
+RN   [2]
+RP   1-7502
+RA   Comanducci M., Ricci S., Cevenini R., Ratti G.;
+RT   ;
+RL   Submitted (23-JUN-2010) to the INSDC.
+RL   Sclavo Research Centre, Siena, Italy
+XX
+DR   MD5; d4c4942a634e3df4995fd5ac75c26a61.
+DR   BioSample; SAMN14225621.
+DR   EuropePMC; PMC4450983; 26031715.
+DR   EuropePMC; PMC87941; 11283058.
+XX
+CC   Draft entry and computer-readable sequence kindly submitted by
+CC   G.Ratti, 28-MAR-1990.
+XX
+XX   ! first CDS location below split across two lines for test purposes !
+FH   Key             Location/Qualifiers
+FH
+FT   source          1..7502
+FT                   /organism="Chlamydia trachomatis"
+FT                   /plasmid="pCHL1"
+FT                   /isolate="G0/86"
+FT                   /serotype="D"
+FT                   /mol_type="genomic DNA"
+FT                   /isolation_source="trachoma"
+FT                   /db_xref="taxon:813"
+FT   CDS             join(7022..7502,
+FT                   1..437)
+FT                   /codon_start=1
+FT                   /transl_table=11
+FT                   /product="hypothetical protein"
+FT                   /note="pGP7-D"
+FT                   /db_xref="GOA:P0CE19"
+FT                   /db_xref="InterPro:IPR002104"
+FT                   /db_xref="InterPro:IPR011010"
+FT                   /db_xref="InterPro:IPR013762"
+FT                   /db_xref="UniProtKB/Swiss-Prot:P0CE19"
+FT                   /protein_id="AAA91567.1"
+FT                   /translation="MGSMAFHKSRLFLTFGDASEIWLSTLSYLTRKNYASGINFLVSLE
+FT                   ILDLSETLIKAISLDHSESLFKIKSLDVFNGKVVSEASKQARAACYISFTKFLYRLTKG
+FT                   YIKPAIPLKDFGNTTFFKIRDKIKTESISKQEWTVFFEALRIVNYRDYLIGKLIVQGIR
+FT                   KLDEILSLRTDDLFFASNQISFRIKKRQNKETKILITFPISLMEELQKYTCGRNGRVFV
+FT                   SKIGIPVTTSQVAHNFRLAEFHSAMKIKITPRVLRASALIHLKQIGLKDEEIMRISCLS
+FT                   SRQSVCSYCSGEEVIPLVQTPTIL"
+FT   CDS             complement(488..1480)
+FT                   /codon_start=1
+FT                   /transl_table=11
+FT                   /product="hypothetical protein"
+FT                   /note="pGP8-D"
+FT                   /db_xref="GOA:P0CE20"
+FT                   /db_xref="InterPro:IPR002104"
+FT                   /db_xref="InterPro:IPR011010"
+FT                   /db_xref="InterPro:IPR013762"
+FT                   /db_xref="UniProtKB/Swiss-Prot:P0CE20"
+FT                   /protein_id="AAA91568.1"
+FT                   /translation="MGKGILSLQQEMSLEYSEKSYQEVLKIRQESYWKRMKSFSLFEVI
+FT                   MHWTASLNKHTCRSYRGSFLSLEKIGLLSLDMNLQEFSLLNHNLILDAIKKVSSAKTSW
+FT                   TEGTKQVRAASYISLTRFLNRMTQGIVAIAQPSKQENSRTFFKTREIVKTDAMNSLQTA
+FT                   SFLKELKKINARDWLIAQTMLQGGKRSSEVLSLEISQICFQQATISFSQLKNRQTEKRI
+FT                   IITYPQKFMHFLQEYIGQRRGFVFVTRSGKMVGLRQIARTFSQAGLQAAIPFKITPHVL
+FT                   RATAVTEYKRLGCSDSDIMKVTGHATAKMIFAYDKSSREDNASKKMALI"
+FT   CDS             1579..2934
+FT                   /codon_start=1
+FT                   /transl_table=11
+FT                   /product="hypothetical protein"
+FT                   /note="pGP1-D"
+FT                   /db_xref="GOA:P0CE16"
+FT                   /db_xref="InterPro:IPR003593"
+FT                   /db_xref="InterPro:IPR007693"
+FT                   /db_xref="InterPro:IPR007694"
+FT                   /db_xref="InterPro:IPR027417"
+FT                   /db_xref="InterPro:IPR036185"
+FT                   /db_xref="UniProtKB/Swiss-Prot:P0CE16"
+FT                   /protein_id="AAA91569.1"
+FT                   /translation="MKTRSEIENRMQDIEYALLGKALIFEDSTEYILRQLANYEFKCSH
+FT                   HKNIFIVFKHLKDNGLPITVDSAWEELLRRRIKDMDKSYLGLMLHDALSNDKLRSVSHT
+FT                   VFLDDLSVCSAEENLSNFIFRSFNEYNENPLRRSPFLLLERIKGRLDSAIAKTFSIRSA
+FT                   RGRSIYDIFSQSEIGVLARIKKRRVAFSENQNSFFDGFPTGYKDIDDKGVILAKGNFVI
+FT                   IAARPSIGKTALAIDMAINLAVTQQRRVGFLSLEMSAGQIVERIIANLTGISGEKLQRG
+FT                   DLSKEELFRVEEAGETVRESHFYICSDSQYKLNLIANQIRLLRKEDRVDVIFIDYLQLI
+FT                   NSSVGENRQNEIADISRTLRGLASELNIPIVCLSQLSRKVEDRANKVPMLSDLRDSGQI
+FT                   EQDADVILFINRKESSSNCEITVGKNRHGSVFSSVLHFDPKISKFSAIKKVW"
+FT   CDS             2928..3992
+FT                   /codon_start=1
+FT                   /transl_table=11
+FT                   /product="hypothetical protein"
+FT                   /note="pGP2-D"
+FT                   /db_xref="InterPro:IPR040719"
+FT                   /db_xref="UniProtKB/Swiss-Prot:P0CE17"
+FT                   /protein_id="AAA91570.1"
+FT                   /translation="MVNYSNCHFIKSPIHLENQKFGRRPGQSIKISPKLAQNGMVEVIG
+FT                   LDFLSSHYHALAAIQRLLTATNYKGNTKGVVLSRESNSFQFEGWIPRIRFTKTEFLEAY
+FT                   GVKRYKTSRNKYEFSGKEAETALEALYHLGHQPFLIVATRTRWTNGTQIVDRYQTLSPI
+FT                   IRIYEGWEGLTDEENIDIDLTPFNSPPTRKHKGFVVEPCPILVDQIESYFVIKPANVYQ
+FT                   EIKMRFPNASKYAYTFIDWVITAAAKKRRKLTKDNSWPENLLLNVNVKSLAYILRMNRY
+FT                   ICTRNWKKIELAIDKCIEIAIQLGWLSRRKRIEFLDSSKLSKKEILYLNKERFEEITKK
+FT                   SKEQMEQLEQESIN"
+FT   CDS             4054..4848
+FT                   /codon_start=1
+FT                   /transl_table=11
+FT                   /product="hypothetical protein"
+FT                   /note="pGP3-D"
+FT                   /db_xref="InterPro:IPR008444"
+FT                   /db_xref="InterPro:IPR033758"
+FT                   /db_xref="InterPro:IPR038264"
+FT                   /db_xref="PDB:6GJT"
+FT                   /db_xref="UniProtKB/Swiss-Prot:P0CE18"
+FT                   /protein_id="AAA91571.1"
+FT                   /translation="MGNSGFYLYNTENCVFADNIKVGQMTEPLKDQQIILGTTSTPVAA
+FT                   KMTASDGISLTVSNNSSTNASITIGLDAEKAYQLILEKLGDQILDGIADTIVDSTVQDI
+FT                   LDKIKTDPSLGLLKAFNNFPITNKIQCNGLFTPSNIETLLGGTEIGKFTVTPKSSGSMF
+FT                   LVSADIIASRMEGGVVLALVREGDSKPCAISYGYSSGIPNLCSLRTSITNTGLTPTTYS
+FT                   LRVGGLESGVVWVNALSNGNDILGITNTSNVSFLEVIPQTNA"
+FT   CDS             4918..5226
+FT                   /codon_start=1
+FT                   /transl_table=11
+FT                   /product="hypothetical protein"
+FT                   /note="pGP4-D"
+FT                   /db_xref="UniProtKB/Swiss-Prot:P0CE23"
+FT                   /protein_id="AAA91572.1"
+FT                   /translation="MQNKRKVRDDFIKIVKDVKKDFPELDLKIRVNKEKVTFLNSPLEL
+FT                   YHKSVSLILGLLQQIENSLGLFPDSPVLEKLEDNSLKLKKALIMLILSRKDMFSKAE"
+FT   CDS             5317..6048
+FT                   /codon_start=1
+FT                   /transl_table=11
+FT                   /product="hypothetical protein"
+FT                   /note="pGP5-D (gtg start codon)"
+FT                   /db_xref="GOA:P10559"
+FT                   /db_xref="InterPro:IPR025669"
+FT                   /db_xref="InterPro:IPR027417"
+FT                   /db_xref="UniProtKB/Swiss-Prot:P10559"
+FT                   /protein_id="AAA91573.1"
+FT                   /translation="MGCNLAQFLGKKVLLADLDPQSNLSSGLGASVRSDQKGLHDIVYT
+FT                   SNDLKSIICETKKDSVDLIPASFSSEQFRELDIHRGPSNNLKLFLNEYCAPFYDICIID
+FT                   TPPSLGGLTKEAFVAGDKLIACLTPEPFSILGLQKIREFLSSVGKPEEEHILGIALSFW
+FT                   DDRNSTNQMYIDIIESIYKNKLFSTKIRRDISLSRSLLKEDSVANVYPNSRAAEDILKL
+FT                   THEIANILHIEYERDYSQRTT"
+FT   CDS             6045..6788
+FT                   /codon_start=1
+FT                   /transl_table=11
+FT                   /product="hypothetical protein"
+FT                   /note="pGP6-D (gtg start codon)"
+FT                   /db_xref="InterPro:IPR005350"
+FT                   /db_xref="UniProtKB/Swiss-Prot:P10560"
+FT                   /protein_id="AAA91574.1"
+FT                   /translation="MNKLKKEADVFFKKNQTAASLDFKKTLPSIELFSATLNSEESQSL
+FT                   DRLFLSESQNYSDEEFYQEDILAVKLLTGQIKSIQKQHVLLLGEKIYNARKILSKDHFS
+FT                   STTFSSWIELVFRTKSSAYNALAYYELFINLPNQTLQKEFQSIPYKSAYILAARKGDLK
+FT                   TKVDVIGKVCGMSNSSAIRVLDQFLPSSRNKDVRETIDKSDSEKNRQLSDFLIEILRIM
+FT                   CSGVSLSSYNENLLQQLFELFKQKS"
+FT   repeat_region   6857..6945
+FT                   /note="four tandem 22bp repeats"
+XX
+SQ   Sequence 7502 BP; 2460 A; 1285 C; 1433 G; 2324 T; 0 other;
+     ggatccgtaa gttagacgaa attttgtctt tgcgcacaga cgatctattt tttgcatcca        60
+     atcagatttc ctttcgcatt aaaaaaagac agaataaaga aaccaaaatt ctaatcacat       120
+     ttcctatcag cttaatggaa gagttgcaaa aatacacttg tgggagaaat gggagagtat       180
+     ttgtttctaa aatagggatt cctgtaacaa caagtcaggt tgcgcataat tttaggcttg       240
+     cagagttcca tagtgctatg aaaataaaaa ttactcccag agtacttcgt gcaagcgctt       300
+     tgattcattt aaagcaaata ggattaaaag atgaggaaat catgcgtatt tcctgtcttt       360
+     catcgagaca aagtgtgtgt tcttattgtt ctggggaaga ggtaattcct ctagtacaaa       420
+     cacccacaat attgtgatat aattaaaatt atattcatat tctgttgcca gaaaaaacac       480
+     ctttaggcta tattagagcc atcttctttg aagcgttgtc ttctcgagaa gatttatcgt       540
+     acgcaaatat catctttgcg gttgcgtgtc ctgtgacctt cattatgtcg gagtctgagc       600
+     accctaggcg tttgtactcc gtcacagcgg ttgctcgaag cacgtgcggg gttattttaa       660
+     aagggattgc agcttgtagt cctgcttgag agaacgtgcg ggcgatttgc cttaacccca       720
+     ccatttttcc ggagcgagtt acgaagacaa aacctcttcg ttgaccgatg tactcttgta       780
+     gaaagtgcat aaacttctga ggataagtta taataatcct cttttctgtc tgacggttct       840
+     taagctggga gaaagaaatg gtagcttgtt ggaaacaaat ctgactaatc tccaagctta       900
+     agacttcaga ggagcgttta cctccttgga gcattgtctg ggcgatcaac caatcccggg       960
+     cattgatttt ttttagctct tttaggaagg atgctgtttg caaactgttc atcgcatccg      1020
+     tttttactat ttccctggtt ttaaaaaatg ttcgactatt ttcttgttta gaaggttgcg      1080
+     ctatagcgac tattccttga gtcatcctgt ttaggaatct tgttaaggaa atatagcttg      1140
+     ctgctcgaac ttgtttagta ccttcggtcc aagaagtctt ggcagaggaa acttttttaa      1200
+     tcgcatctag gattagatta tgatttaaaa gggaaaactc ttgcagattc atatccaagg      1260
+     acaatagacc aatcttttct aaagacaaaa aagatcctcg atatgatcta caagtatgtt      1320
+     tgttgagtga tgcggtccaa tgcataataa cttcgaataa ggagaagctt ttcatgcgtt      1380
+     tccaatagga ttcttggcga atttttaaaa cttcctgata agacttttca ctatattcta      1440
+     acgacatttc ttgctgcaaa gataaaatcc ctttacccat gaaatccctc gtgatataac      1500
+     ctatccgtaa aatgtcctga ttagtgaaat aatcaggttg ttaacaggat agcacgctcg      1560
+     gtattttttt atataaacat gaaaactcgt tccgaaatag aaaatcgcat gcaagatatc      1620
+     gagtatgcgt tgttaggtaa agctctgata tttgaagact ctactgagta tattctgagg      1680
+     cagcttgcta attatgagtt taagtgttct catcataaaa acatattcat agtatttaaa      1740
+     cacttaaaag acaatggatt acctataact gtagactcgg cttgggaaga gcttttgcgg      1800
+     cgtcgtatca aagatatgga caaatcgtat ctcgggttaa tgttgcatga tgctttatca      1860
+     aatgacaagc ttagatccgt ttctcatacg gttttcctcg atgatttgag cgtgtgtagc      1920
+     gctgaagaaa atttgagtaa tttcattttc cgctcgttta atgagtacaa tgaaaatcca      1980
+     ttgcgtagat ctccgtttct attgcttgag cgtataaagg gaaggcttga tagtgctata      2040
+     gcaaagactt tttctattcg cagcgctaga ggccggtcta tttatgatat attctcacag      2100
+     tcagaaattg gagtgctggc tcgtataaaa aaaagacgag tagcgttctc tgagaatcaa      2160
+     aattctttct ttgatggctt cccaacagga tacaaggata ttgatgataa aggagttatc      2220
+     ttagctaaag gtaatttcgt gattatagca gctagaccat ctatagggaa aacagcttta      2280
+     gctatagaca tggcgataaa tcttgcggtt actcaacagc gtagagttgg tttcctatct      2340
+     ctagaaatga gcgcaggtca aattgttgag cggattattg ctaatttaac aggaatatct      2400
+     ggtgaaaaat tacaaagagg ggatctctct aaagaagaat tattccgagt agaagaagct      2460
+     ggagaaacgg ttagagaatc acatttttat atctgcagtg atagtcagta taagcttaac      2520
+     ttaatcgcga atcagatccg gttgctgaga aaagaagatc gagtagacgt aatatttatc      2580
+     gattacttgc agttgatcaa ctcatcggtt ggagaaaatc gtcaaaatga aatagcagat      2640
+     atatctagaa ccttaagagg tttagcctca gagctaaaca ttcctatagt ttgtttatcc      2700
+     caactatcta gaaaagttga ggatagagca aataaagttc ccatgctttc agatttgcga      2760
+     gacagcggtc aaatagagca agacgcagat gtgattttgt ttatcaatag gaaggaatcg      2820
+     tcttctaatt gtgagataac tgttgggaaa aatagacatg gatcggtttt ctcttcggta      2880
+     ttacatttcg atccaaaaat tagtaaattc tccgctatta aaaaagtatg gtaaattata      2940
+     gtaactgcca cttcatcaaa agtcctatcc accttgaaaa tcagaagttt ggaagaagac      3000
+     ctggtcaatc tattaagata tctcccaaat tggctcaaaa tgggatggta gaagttatag      3060
+     gtcttgattt tctttcatct cattaccatg cattagcagc tatccaaaga ttactgaccg      3120
+     caacgaatta caaggggaac acaaaagggg ttgttttatc cagagaatca aatagttttc      3180
+     aatttgaagg atggatacca agaatccgtt ttacaaaaac tgaattctta gaggcttatg      3240
+     gagttaagcg gtataaaaca tccagaaata agtatgagtt tagtggaaaa gaagctgaaa      3300
+     ctgctttaga agccttatac catttaggac atcaaccgtt tttaatagtg gcaactagaa      3360
+     ctcgatggac taatggaaca caaatagtag accgttacca aactctttct ccgatcatta      3420
+     ggatttacga aggatgggaa ggtttaactg acgaagaaaa tatagatata gacttaacac      3480
+     cttttaattc accacctaca cggaaacata aagggttcgt tgtagagcca tgtcctatct      3540
+     tggtagatca aatagaatcc tactttgtaa tcaagcctgc aaatgtatac caagaaataa      3600
+     aaatgcgttt cccaaatgca tcaaagtatg cttacacatt tatcgactgg gtgattacag      3660
+     cagctgcgaa aaagagacga aaattaacta aggataattc ttggccagaa aacttgttat      3720
+     taaacgttaa cgttaaaagt cttgcatata ttttaaggat gaatcggtac atctgtacaa      3780
+     ggaactggaa aaaaatcgag ttagctatcg ataaatgtat agaaatcgcc attcagcttg      3840
+     gctggttatc tagaagaaaa cgcattgaat ttctggattc ttctaaactc tctaaaaaag      3900
+     aaattctata tctaaataaa gagcgctttg aagaaataac taagaaatct aaagaacaaa      3960
+     tggaacaatt agaacaagaa tctattaatt aatagcaagc ttgaaactaa aaacctaatt      4020
+     tatttaaagc tcaaaataaa aaagagtttt aaaatgggaa attctggttt ttatttgtat      4080
+     aacactgaaa actgcgtctt tgctgataat atcaaagttg ggcaaatgac agagccgctc      4140
+     aaggaccagc aaataatcct tgggacaaca tcaacacctg tcgcagccaa aatgacagct      4200
+     tctgatggaa tatctttaac agtctccaat aattcatcaa ccaatgcttc tattacaatt      4260
+     ggtttggatg cggaaaaagc ttaccagctt attctagaaa agttgggaga tcaaattctt      4320
+     gatggaattg ctgatactat tgttgatagt acagtccaag atattttaga caaaatcaaa      4380
+     acagaccctt ctctaggttt gttgaaagct tttaacaact ttccaatcac taataaaatt      4440
+     caatgcaacg ggttattcac tcccagtaac attgaaactt tattaggagg aactgaaata      4500
+     ggaaaattca cagtcacacc caaaagctct gggagcatgt tcttagtctc agcagatatt      4560
+     attgcatcaa gaatggaagg cggcgttgtt ctagctttgg tacgagaagg tgattctaag      4620
+     ccctgcgcga ttagttatgg atactcatca ggcattccta atttatgtag tctaagaacc      4680
+     agtattacta atacaggatt gactccgaca acgtattcat tacgtgtagg cggtttagaa      4740
+     agcggtgtgg tatgggttaa tgccctttct aatggcaatg atattttagg aataacaaat      4800
+     acttctaatg tatctttttt agaggtaata cctcaaacaa acgcttaaac aatttttatt      4860
+     ggatttttct tataggtttt atatttagag aaaacagttc gaattacggg gtttgttatg      4920
+     caaaataaaa gaaaagtgag ggacgatttt attaaaattg ttaaagatgt gaaaaaagat      4980
+     ttccccgaat tagacctaaa aatacgagta aacaaggaaa aagtaacttt cttaaattct      5040
+     cccttagaac tctaccataa aagtgtctca ctaattctag gactgcttca acaaatagaa      5100
+     aactctttag gattattccc agactctcct gttcttgaaa aattagagga taacagttta      5160
+     aagctaaaaa aggctttgat tatgcttatc ttgtctagaa aagacatgtt ttccaaggct      5220
+     gaatagacaa cttactctaa cgttggagtt gatttgcaca ccttagtttt ttgctctttt      5280
+     aagggaggaa ctggaaaaac aacactttct ctaaacgtgg gatgcaactt ggcccaattt      5340
+     ttagggaaaa aagtgttact tgctgaccta gacccgcaat ccaatttatc ttctggattg      5400
+     ggggctagtg tcagaagtga ccaaaaaggc ttgcacgaca tagtatacac atcaaacgat      5460
+     ttaaaatcaa tcatttgcga aacaaaaaaa gatagtgtgg acctaattcc tgcatcattt      5520
+     tcatccgaac agtttagaga attggatatt catagaggac ctagtaacaa cttaaagtta      5580
+     tttctgaatg agtactgcgc tcctttttat gacatctgca taatagacac tccacctagc      5640
+     ctaggagggt taacgaaaga agcttttgtt gcaggagaca aattaattgc ttgtttaact      5700
+     ccagaacctt tttctattct agggttacaa aagatacgtg aattcttaag ttcggtcgga      5760
+     aaacctgaag aagaacacat tcttggaata gctttgtctt tttgggatga tcgtaactcg      5820
+     actaaccaaa tgtatataga cattatcgag tctatttaca aaaacaagct tttttcaaca      5880
+     aaaattcgtc gagatatttc tctcagccgt tctcttctta aagaagattc tgtagctaat      5940
+     gtctatccaa attctagggc cgcagaagat attctgaagt taacgcatga aatagcaaat      6000
+     attttgcata tcgaatatga acgagattac tctcagagga caacgtgaac aaactaaaaa      6060
+     aagaagcgga tgtctttttt aaaaaaaatc aaactgccgc ttctctagat tttaagaaga      6120
+     cgcttccctc cattgaacta ttctcagcaa ctttgaattc tgaggaaagt cagagtttgg      6180
+     atcgattatt tttatcagag tcccaaaact attcggatga agaattttat caagaagaca      6240
+     tcctagcggt aaaactgctt actggtcaga taaaatccat acagaagcaa cacgtacttc      6300
+     ttttaggaga aaaaatctat aatgctagaa aaatcctgag taaggatcac ttctcctcaa      6360
+     caactttttc atcttggata gagttagttt ttagaactaa gtcttctgct tacaatgctc      6420
+     ttgcatatta cgagcttttt ataaacctcc ccaaccaaac tctacaaaaa gagtttcaat      6480
+     cgatccccta taaatccgca tatattttgg ccgctagaaa aggcgattta aaaaccaagg      6540
+     tcgatgtgat agggaaagta tgtggaatgt cgaactcatc ggcgataagg gtgttggatc      6600
+     aatttcttcc ttcatctaga aacaaagacg ttagagaaac gatagataag tctgattcag      6660
+     agaagaatcg ccaattatct gatttcttaa tagagatact tcgcatcatg tgttccggag      6720
+     tttctttgtc ctcctataac gaaaatcttc tacaacagct ttttgaactt tttaagcaaa      6780
+     agagctgatc ctccgtcagc tcatatatat atatctatta tatatatata tttagggatt      6840
+     tgatttcacg agagagattt gcaactcttg gtggtagact ttgcaactct tggtggtaga      6900
+     ctttgcaact cttggtggta gactttgcaa ctcttggtgg tagacttggt cataatggac      6960
+     ttttgttaaa aaatttatta aaatcttaga gctccgattt tgaatagctt tggttaagaa      7020
+     aatgggctcg atggctttcc ataaaagtag attgttttta acttttgggg acgcgtcgga      7080
+     aatttggtta tctactttat cttatctaac tagaaaaaat tatgcgtctg ggattaactt      7140
+     tcttgtttct ttagagattc tggatttatc ggaaaccttg ataaaggcta tttctcttga      7200
+     ccacagcgaa tctttgttta aaatcaagtc tctagatgtt tttaatggaa aagttgtttc      7260
+     agaggcatct aaacaggcta gagcggcatg ctacatatct ttcacaaagt ttttgtatag      7320
+     attgaccaag ggatatatta aacccgctat tccattgaaa gattttggaa acactacatt      7380
+     ttttaaaatc cgagacaaaa tcaaaacaga atcgatttct aagcaggaat ggacagtttt      7440
+     ttttgaagcg ctccggatag tgaattatag agactattta atcggtaaat tgattgtaca      7500
+     ag                                                                     7502
+//
index 010a4b2..9b899e2 100644 (file)
@@ -13,8 +13,8 @@ public class JvCacheableInputBoxTest
 
   private static final String TEST_CACHE_KEY = "CACHE.UNIT_TEST";
 
-  private JvCacheableInputBox<String> cacheBox = new JvCacheableInputBox<String>(
-          TEST_CACHE_KEY);
+  private JvCacheableInputBox<String> cacheBox = new JvCacheableInputBox<>(
+          TEST_CACHE_KEY, 20);
 
   @BeforeClass(alwaysRun = true)
   private void setUpCache()
index 097ccd4..dd789d6 100644 (file)
@@ -24,6 +24,7 @@ import static org.testng.AssertJUnit.assertEquals;
 import static org.testng.AssertJUnit.assertFalse;
 import static org.testng.AssertJUnit.assertSame;
 import static org.testng.AssertJUnit.assertTrue;
+import static org.testng.AssertJUnit.fail;
 
 import jalview.api.AlignViewportI;
 import jalview.commands.EditCommand;
@@ -1284,4 +1285,33 @@ public class MappingUtilsTest
     assertEquals(1, ranges.size());
     assertEquals(9, ranges.get(0)[1]);
   }
+  
+  @Test(groups = "Functional")
+  public void testListToArray()
+  {
+    List<int[]> ranges = new ArrayList<>();
+    
+    int[] result = MappingUtils.listToArray(ranges);
+    assertEquals(result.length, 0);
+    ranges.add(new int[] {24, 12});
+    result = MappingUtils.listToArray(ranges);
+    assertEquals(result.length, 2);
+    assertEquals(result[0], 24);
+    assertEquals(result[1], 12);
+    ranges.add(new int[] {-7, 30});
+    result = MappingUtils.listToArray(ranges);
+    assertEquals(result.length, 4);
+    assertEquals(result[0], 24);
+    assertEquals(result[1], 12);
+    assertEquals(result[2], -7);
+    assertEquals(result[3], 30);
+    try
+    {
+      MappingUtils.listToArray(null);
+      fail("Expected exception");
+    } catch (NullPointerException e)
+    {
+      // expected
+    }
+  }
 }
@@ -26,6 +26,7 @@ import static org.testng.AssertJUnit.assertNull;
 import static org.testng.AssertJUnit.assertSame;
 import static org.testng.AssertJUnit.assertTrue;
 
+import jalview.datamodel.AlignmentI;
 import jalview.datamodel.DBRefEntry;
 import jalview.datamodel.DBRefSource;
 import jalview.datamodel.SequenceI;
@@ -40,9 +41,10 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
+import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
-public class EmblSourceTest
+public class EmblXmlSourceTest
 {
 
   // adapted from http://www.ebi.ac.uk/ena/data/view/X07547&display=xml
@@ -95,16 +97,49 @@ public class EmblSourceTest
           + "ACCCCCAATATTGTGATATAATTAAAAACATAGCAT"
           + "</sequence></entry></ROOT>";
 
+  private EmblXmlSource testee;
+
+  @BeforeClass(alwaysRun = true)
+  public void setUp()
+  {
+    testee = new EmblXmlSource()
+    {
+
+      @Override
+      public String getDbSource()
+      {
+        return null;
+      }
+
+      @Override
+      public String getDbName()
+      {
+        return null;
+      }
+
+      @Override
+      public String getTestQuery()
+      {
+        return null;
+      }
+
+      @Override
+      public AlignmentI getSequenceRecords(String queries) throws Exception
+      {
+        return null;
+      }
+    };
+  }
+
   @Test(groups = "Functional")
   public void testGetCdsRanges()
   {
-    EmblSource testee = new EmblSource();
-
     /*
      * Make a (CDS) Feature with 5 locations
      */
     Feature cds = new Feature();
-    cds.setLocation("join(10..20,complement(30..40),50..60,70..80,complement(110..120))");
+    cds.setLocation(
+            "join(10..20,complement(30..40),50..60,70..80,complement(110..120))");
 
     int[] exons = testee.getCdsRanges("EMBL", cds);
     assertEquals("[10, 20, 40, 30, 50, 60, 70, 80, 120, 110]",
@@ -116,10 +151,9 @@ public class EmblSourceTest
   {
     // not the whole sequence but enough for this test...
     List<SequenceI> peptides = new ArrayList<>();
-    List<EntryType> entries = EmblSourceTest.getEmblEntries();
+    List<EntryType> entries = getEmblEntries();
     assertEquals(1, entries.size());
     EntryType entry = entries.get(0);
-    EmblSource testee = new EmblSource();
     String sourceDb = "EMBL";
     SequenceI dna = testee.getSequence(sourceDb, entry, peptides);
 
@@ -165,8 +199,9 @@ public class EmblSourceTest
             3, 1);
     MapList cds2Map = new MapList(new int[] { 4, 15 }, new int[] { 1, 4 },
             3, 1);
-    MapList cds3Map = new MapList(new int[] { 4, 6, 10, 15 }, new int[] {
-        1, 3 }, 3, 1);
+    MapList cds3Map = new MapList(new int[] { 4, 6, 10, 15 },
+            new int[]
+            { 1, 3 }, 3, 1);
 
     DBRefEntry[] dbrefs = dna.getDBRefs();
     assertEquals(7, dbrefs.length);
@@ -222,10 +257,12 @@ public class EmblSourceTest
      * - to EMBLCDS (with 1:3 mapping)
      * - direct (no mapping) to other protein accessions
      */
-    MapList proteinToCdsMap1 = new MapList(new int[] { 1, 4 }, new int[] {
-        1, 12 }, 1, 3);
-    MapList proteinToCdsMap2 = new MapList(new int[] { 1, 3 }, new int[] {
-        1, 9 }, 1, 3);
+    MapList proteinToCdsMap1 = new MapList(new int[] { 1, 4 },
+            new int[]
+            { 1, 12 }, 1, 3);
+    MapList proteinToCdsMap2 = new MapList(new int[] { 1, 3 },
+            new int[]
+            { 1, 9 }, 1, 3);
 
     // dbrefs for first CDS EMBL product CAA30420.1
     dbrefs = peptides.get(0).getDBRefs();
@@ -339,10 +376,10 @@ public class EmblSourceTest
   @Test(groups = { "Functional" })
   public void testGetEmblEntries()
   {
-    List<EntryType> entries = EmblSourceTest.getEmblEntries();
+    List<EntryType> entries = getEmblEntries();
     assertEquals(1, entries.size());
     EntryType entry = entries.get(0);
-  
+
     assertEquals("X07547", entry.getAccession());
     assertEquals("C. trachomatis plasmid", entry.getDescription());
     assertEquals("STD", entry.getDataClass());
@@ -359,7 +396,7 @@ public class EmblSourceTest
     assertEquals(2, entry.getKeyword().size());
     assertEquals("plasmid", entry.getKeyword().get(0));
     assertEquals("unidentified reading frame", entry.getKeyword().get(1));
-  
+
     /*
      * dbrefs
      */
@@ -372,7 +409,7 @@ public class EmblSourceTest
     assertEquals("MD5", dbref.getDb());
     assertEquals("ac73317", dbref.getId());
     assertNull(dbref.getSecondaryId());
-  
+
     /*
      * three sequence features for CDS
      */
@@ -403,7 +440,7 @@ public class EmblSourceTest
     q = ef.getQualifier().get(2);
     assertEquals("translation", q.getName());
     assertEquals("MLCF", q.getValue());
-  
+
     /*
      * second CDS
      */
@@ -422,7 +459,7 @@ public class EmblSourceTest
     q = ef.getQualifier().get(1);
     assertEquals("translation", q.getName());
     assertEquals("MSSS", q.getValue());
-  
+
     /*
      * third CDS
      */
@@ -438,16 +475,14 @@ public class EmblSourceTest
     q = ef.getQualifier().get(1);
     assertEquals("translation", q.getName());
     assertEquals("MSS", q.getValue());
-  
+
     /*
      * Sequence - raw data before removal of newlines
      */
     String seq = entry.getSequence();
-    assertEquals(
-            "GGTATGTCCTCTAGTACAAAC\n"
-                    + "ACCCCCAATATTGTGATATAATTAAAAACATAGCAT",
-            seq);
-  
+    assertEquals("GGTATGTCCTCTAGTACAAAC\n"
+            + "ACCCCCAATATTGTGATATAATTAAAAACATAGCAT", seq);
+
     /*
      * getSequence() converts empty DBRefEntry.version to "0"
      */
@@ -455,9 +490,9 @@ public class EmblSourceTest
     assertNull(entry.getFeature().get(0).getXref().get(1).getSecondaryId());
   }
 
-  static List<EntryType> getEmblEntries()
+  List<EntryType> getEmblEntries()
   {
-    return new EmblSource()
+    return testee
             .getEmblEntries(new ByteArrayInputStream(TESTDATA.getBytes()));
   }
 }
index c559966..c3fae6c 100644 (file)
@@ -47,13 +47,13 @@ public class EBIFetchClientTest
     /*
      * EMBL
      */
-    assertEquals("https://www.ebi.ac.uk/ena/data/view/x53838&display=xml",
+    assertEquals("https://www.ebi.ac.uk/ena/browser/api/embl/x53838?download=true&gzip=true",
             EBIFetchClient.buildUrl("X53838", "EMBL", "display=xml"));
 
     /*
      * EMBLCDS
      */
-    assertEquals("https://www.ebi.ac.uk/ena/data/view/caa37824&display=xml",
+    assertEquals("https://www.ebi.ac.uk/ena/browser/api/embl/caa37824?download=true&gzip=true",
             EBIFetchClient.buildUrl("CAA37824", "EMBL", "display=xml"));
 
     /*
diff --git a/utils/clover/lib/clover-ant-4.4.1.jar b/utils/clover/lib/clover-ant-4.4.1.jar
new file mode 100644 (file)
index 0000000..4f92395
Binary files /dev/null and b/utils/clover/lib/clover-ant-4.4.1.jar differ
diff --git a/utils/cmd-nox.sh b/utils/cmd-nox.sh
new file mode 100755 (executable)
index 0000000..bd615bd
--- /dev/null
@@ -0,0 +1,8 @@
+#!/usr/bin/env bash
+
+CMD=$(basename $0)
+CMD=${CMD%-nox.sh}
+
+echo "Running '$CMD' headlessly"
+
+xvfb-run -s "-screen 0 1280x800x16" -e /dev/stdout -a $CMD ${@}
diff --git a/utils/gradle-nox.sh b/utils/gradle-nox.sh
new file mode 120000 (symlink)
index 0000000..4abb9a2
--- /dev/null
@@ -0,0 +1 @@
+cmd-nox.sh
\ No newline at end of file