+ /**
+ * Tests that exercise
+ * <ul>
+ * <li>opening an unindexed fasta file</li>
+ * <li>creating a .fai index</li>
+ * <li>opening the fasta file, now using the index</li>
+ * <li>error on creating index if overwrite not allowed</li>
+ * </ul>
+ *
+ * @throws IOException
+ */
+ @Test(groups = "Functional")
+ public void testCreateFastaSequenceIndex() throws IOException
+ {
+ File fasta = new File("test/jalview/ext/htsjdk/pgmb.fasta");
+
+ /*
+ * create .fai with no overwrite fails if it exists
+ */
+ try {
+ HtsContigDb.createFastaSequenceIndex(fasta.toPath(), false);
+ fail("Expected exception");
+ } catch (IOException e)
+ {
+ // expected
+ }
+
+ /*
+ * create a copy of the .fasta (as a temp file)
+ */
+ File copyFasta = File.createTempFile("copyFasta", ".fasta");
+ copyFasta.deleteOnExit();
+ assertTrue(copyFasta.exists());
+ Files.copy(fasta.toPath(), copyFasta.toPath(),
+ StandardCopyOption.REPLACE_EXISTING);
+
+ /*
+ * open the Fasta file - not indexed, as no .fai file yet exists
+ */
+ HtsContigDb db = new HtsContigDb("ADB", copyFasta);
+ assertTrue(db.isValid());
+ assertFalse(db.isIndexed());
+ db.close();
+
+ /*
+ * create the .fai index, re-open the .fasta file - now indexed
+ */
+ HtsContigDb.createFastaSequenceIndex(copyFasta.toPath(), true);
+ db = new HtsContigDb("ADB", copyFasta);
+ assertTrue(db.isValid());
+ assertTrue(db.isIndexed());
+ db.close();
+ }
+
+ /**
+ * A convenience 'test' that may be run to create a .fai file for any given
+ * fasta file
+ *
+ * @throws IOException
+ */
+ @Test(enabled = false)
+ public void testCreateIndex() throws IOException
+ {
+
+ File fasta = new File("test/jalview/io/vcf/contigs.fasta");
+ HtsContigDb.createFastaSequenceIndex(fasta.toPath(), true);
+ }