From 4815037f13748676b04b91dc761b73cf6f2d6ecd Mon Sep 17 00:00:00 2001 From: gmungoc Date: Thu, 24 Nov 2016 15:42:52 +0000 Subject: [PATCH] Further tweaks to get tests passing --- src/jalview/gui/AlignFrame.java | 3 +- src/jalview/gui/CutAndPasteTransfer.java | 2 +- src/jalview/gui/Preferences.java | 10 ++++-- src/jalview/io/AlignFile.java | 2 +- src/jalview/io/AppletFormatAdapter.java | 2 +- src/jalview/io/FileFormat.java | 53 +++++++++++++++--------------- src/jalview/io/FileFormatI.java | 6 ++-- src/jalview/io/FormatAdapter.java | 2 +- src/jalview/io/IdentifyFile.java | 2 -- src/jalview/io/JalviewFileChooser.java | 31 ++++++++++++++--- test/jalview/io/IdentifyFileTest.java | 50 ++++++++++++++-------------- 11 files changed, 96 insertions(+), 67 deletions(-) diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index e585e28..453fd3a 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -5281,7 +5281,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, viewport.setColumnSelection(cs); isAnnotation = true; } - else if (IdentifyFile.FeaturesFile.equals(format)) + // else if (IdentifyFile.FeaturesFile.equals(format)) + else if (format == FileFormat.Features) { if (parseFeaturesFile(file, sourceType)) { diff --git a/src/jalview/gui/CutAndPasteTransfer.java b/src/jalview/gui/CutAndPasteTransfer.java index 4e5ef40..8b21058 100644 --- a/src/jalview/gui/CutAndPasteTransfer.java +++ b/src/jalview/gui/CutAndPasteTransfer.java @@ -260,7 +260,7 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer { String title = MessageManager.formatMessage( "label.input_cut_paste_params", - new String[] { format.getShortDescription() }); + new String[] { format.toString() }); FeatureSettingsModelI proxyColourScheme = source .getFeatureColourScheme(); diff --git a/src/jalview/gui/Preferences.java b/src/jalview/gui/Preferences.java index 1ac17e4..4f4dcd0 100755 --- a/src/jalview/gui/Preferences.java +++ b/src/jalview/gui/Preferences.java @@ -24,6 +24,7 @@ import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder; import jalview.bin.Cache; import jalview.gui.Help.HelpId; import jalview.gui.StructureViewer.ViewerType; +import jalview.io.FileFormatI; import jalview.io.JalviewFileChooser; import jalview.io.JalviewFileView; import jalview.jbgui.GPreferences; @@ -699,9 +700,12 @@ public class Preferences extends GPreferences if (value == JalviewFileChooser.APPROVE_OPTION) { - Cache.applicationProperties.setProperty("DEFAULT_FILE_FORMAT", - chooser - .getSelectedFormat().toString()); + FileFormatI format = chooser.getSelectedFormat(); + if (format != null) + { + Cache.applicationProperties.setProperty("DEFAULT_FILE_FORMAT", + format.toString()); + } startupFileTextfield.setText(chooser.getSelectedFile() .getAbsolutePath()); } diff --git a/src/jalview/io/AlignFile.java b/src/jalview/io/AlignFile.java index d333c64..4de510a 100755 --- a/src/jalview/io/AlignFile.java +++ b/src/jalview/io/AlignFile.java @@ -65,7 +65,7 @@ public abstract class AlignFile extends FileParse implements AlignmentFileI /** * Properties to be added to generated alignment object */ - protected Hashtable properties; + private Hashtable properties; long start; diff --git a/src/jalview/io/AppletFormatAdapter.java b/src/jalview/io/AppletFormatAdapter.java index e0a607b..5f40713 100755 --- a/src/jalview/io/AppletFormatAdapter.java +++ b/src/jalview/io/AppletFormatAdapter.java @@ -435,7 +435,7 @@ public class AppletFormatAdapter { try { - AlignmentFileI afile = format.getAlignmentFile(); + AlignmentFileI afile = format.getAlignmentFile(alignment); afile.setNewlineString(newline); afile.setExportSettings(exportSettings); diff --git a/src/jalview/io/FileFormat.java b/src/jalview/io/FileFormat.java index 770f762..a43bc22 100644 --- a/src/jalview/io/FileFormat.java +++ b/src/jalview/io/FileFormat.java @@ -1,5 +1,6 @@ package jalview.io; +import jalview.datamodel.AlignmentI; import jalview.datamodel.PDBEntry; import jalview.ext.jmol.JmolParser; import jalview.structure.StructureImportSettings; @@ -29,7 +30,7 @@ public enum FileFormat implements FileFormatI } @Override - public AlignmentFileI getAlignmentFile() + public AlignmentFileI getAlignmentFile(AlignmentI al) { return new FastaFile(); } @@ -51,7 +52,7 @@ public enum FileFormat implements FileFormatI } @Override - public AlignmentFileI getAlignmentFile() + public AlignmentFileI getAlignmentFile(AlignmentI al) { return new PfamFile(); } @@ -72,9 +73,9 @@ public enum FileFormat implements FileFormatI } @Override - public AlignmentFileI getAlignmentFile() + public AlignmentFileI getAlignmentFile(AlignmentI al) { - return new StockholmFile(); + return new StockholmFile(al); } }, @@ -95,7 +96,7 @@ public enum FileFormat implements FileFormatI } @Override - public AlignmentFileI getAlignmentFile() + public AlignmentFileI getAlignmentFile(AlignmentI al) { return new PIRFile(); } @@ -115,7 +116,7 @@ public enum FileFormat implements FileFormatI } @Override - public AlignmentFileI getAlignmentFile() + public AlignmentFileI getAlignmentFile(AlignmentI al) { return new BLCFile(); } @@ -137,9 +138,9 @@ public enum FileFormat implements FileFormatI } @Override - public AlignmentFileI getAlignmentFile() + public AlignmentFileI getAlignmentFile(AlignmentI al) { - return new BLCFile(); + return new AMSAFile(al); } }, Html("HTML", "html", true, false) @@ -157,7 +158,7 @@ public enum FileFormat implements FileFormatI } @Override - public AlignmentFileI getAlignmentFile() + public AlignmentFileI getAlignmentFile(AlignmentI al) { return new HtmlFile(); } @@ -184,7 +185,7 @@ public enum FileFormat implements FileFormatI } @Override - public AlignmentFileI getAlignmentFile() + public AlignmentFileI getAlignmentFile(AlignmentI al) { return new RnamlFile(); } @@ -205,7 +206,7 @@ public enum FileFormat implements FileFormatI } @Override - public AlignmentFileI getAlignmentFile() + public AlignmentFileI getAlignmentFile(AlignmentI al) { return new JSONFile(); } @@ -232,7 +233,7 @@ public enum FileFormat implements FileFormatI } @Override - public AlignmentFileI getAlignmentFile() + public AlignmentFileI getAlignmentFile(AlignmentI al) { return new PileUpfile(); } @@ -253,7 +254,7 @@ public enum FileFormat implements FileFormatI } @Override - public AlignmentFileI getAlignmentFile() + public AlignmentFileI getAlignmentFile(AlignmentI al) { return new MSFfile(); } @@ -274,7 +275,7 @@ public enum FileFormat implements FileFormatI } @Override - public AlignmentFileI getAlignmentFile() + public AlignmentFileI getAlignmentFile(AlignmentI al) { return new ClustalFile(); } @@ -296,7 +297,7 @@ public enum FileFormat implements FileFormatI } @Override - public AlignmentFileI getAlignmentFile() + public AlignmentFileI getAlignmentFile(AlignmentI al) { return new PhylipFile(); } @@ -322,7 +323,7 @@ public enum FileFormat implements FileFormatI } @Override - public AlignmentFileI getAlignmentFile() + public AlignmentFileI getAlignmentFile(AlignmentI al) { return null; // todo is this called? } @@ -345,7 +346,7 @@ public enum FileFormat implements FileFormatI } @Override - public AlignmentFileI getAlignmentFile() + public AlignmentFileI getAlignmentFile(AlignmentI al) { return new FeaturesFile(); } @@ -408,7 +409,7 @@ public enum FileFormat implements FileFormatI } @Override - public AlignmentFileI getAlignmentFile() + public AlignmentFileI getAlignmentFile(AlignmentI al) { return new JmolParser(); // todo or null? } @@ -439,7 +440,7 @@ public enum FileFormat implements FileFormatI } @Override - public AlignmentFileI getAlignmentFile() + public AlignmentFileI getAlignmentFile(AlignmentI al) { return new JmolParser(); // todo or null? } @@ -462,7 +463,7 @@ public enum FileFormat implements FileFormatI } @Override - public AlignmentFileI getAlignmentFile() + public AlignmentFileI getAlignmentFile(AlignmentI al) { return null; } @@ -533,12 +534,6 @@ public enum FileFormat implements FileFormatI return false; } - @Override - public String getShortDescription() - { - return toString(); - } - /** * Returns the file format with the given name, or null if format is null or * invalid. Unlike valueOf(), this is not case-sensitive, to be kind to @@ -595,4 +590,10 @@ public enum FileFormat implements FileFormatI { return name; } + + @Override + public AlignmentFileI getAlignmentFile() + { + return getAlignmentFile((AlignmentI) null); + } } diff --git a/src/jalview/io/FileFormatI.java b/src/jalview/io/FileFormatI.java index f594a36..082d9f1 100644 --- a/src/jalview/io/FileFormatI.java +++ b/src/jalview/io/FileFormatI.java @@ -1,5 +1,7 @@ package jalview.io; +import jalview.datamodel.AlignmentI; + import java.io.IOException; public interface FileFormatI @@ -10,12 +12,12 @@ public interface FileFormatI AlignmentFileI getAlignmentFile(FileParse source) throws IOException; + AlignmentFileI getAlignmentFile(AlignmentI al); + AlignmentFileI getAlignmentFile(); boolean isComplexAlignFile(); - String getShortDescription(); - /** * Returns a comma-separated list of file extensions associated with the * format diff --git a/src/jalview/io/FormatAdapter.java b/src/jalview/io/FormatAdapter.java index 724170e..1dbfdef 100755 --- a/src/jalview/io/FormatAdapter.java +++ b/src/jalview/io/FormatAdapter.java @@ -158,7 +158,7 @@ public class FormatAdapter extends AppletFormatAdapter // // try // { - boolean withSuffix = getCacheSuffixDefault(format); + boolean withSuffix = getCacheSuffixDefault(format); return format.getAlignmentFile().print(seqs, withSuffix); // null; // diff --git a/src/jalview/io/IdentifyFile.java b/src/jalview/io/IdentifyFile.java index bc91e09..f8d8415 100755 --- a/src/jalview/io/IdentifyFile.java +++ b/src/jalview/io/IdentifyFile.java @@ -30,8 +30,6 @@ import java.io.IOException; */ public class IdentifyFile { - public static final String FeaturesFile = "GFF or Jalview features"; - /** * Identify a datasource's file content. * diff --git a/src/jalview/io/JalviewFileChooser.java b/src/jalview/io/JalviewFileChooser.java index 7e1aaa1..e4317bd 100755 --- a/src/jalview/io/JalviewFileChooser.java +++ b/src/jalview/io/JalviewFileChooser.java @@ -76,7 +76,7 @@ public class JalviewFileChooser extends JFileChooser if (format.isReadable()) { extensions.add(format.getExtensions()); - descs.add(format.getShortDescription()); + descs.add(format.toString()); } } return new JalviewFileChooser(directory, @@ -106,7 +106,7 @@ public class JalviewFileChooser extends JFileChooser if (format.isWritable()) { extensions.add(format.getExtensions()); - descs.add(format.getShortDescription()); + descs.add(format.toString()); } } return new JalviewFileChooser(directory, @@ -233,6 +233,11 @@ public class JalviewFileChooser extends JFileChooser } } + /** + * Returns the selected file format, or null if none selected + * + * @return + */ public FileFormatI getSelectedFormat() { if (getFileFilter() == null) @@ -240,9 +245,27 @@ public class JalviewFileChooser extends JFileChooser return null; } + /* + * logic here depends on option description being formatted as + * formatName (extension, extension...) + * or the 'no option selected' value + * All Files + * @see JalviewFileFilter.getDescription + */ String format = getFileFilter().getDescription(); - format = format.substring(0, format.indexOf("(") - 1); - return FileFormat.valueOf(format); + int parenPos = format.indexOf("("); + if (parenPos > 0) + { + format = format.substring(0, parenPos).trim(); + try + { + return FileFormat.valueOf(format); + } catch (IllegalArgumentException e) + { + System.err.println("Unexpected format: " + format); + } + } + return null; } @Override diff --git a/test/jalview/io/IdentifyFileTest.java b/test/jalview/io/IdentifyFileTest.java index d693a6c..0a3ff94 100644 --- a/test/jalview/io/IdentifyFileTest.java +++ b/test/jalview/io/IdentifyFileTest.java @@ -20,8 +20,8 @@ */ package jalview.io; -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 org.testng.Assert; @@ -32,13 +32,13 @@ public class IdentifyFileTest { @Test(groups = { "Functional" }, dataProvider = "identifyFiles") - public void testIdentify(String data, String expectedFileType) + public void testIdentify(String data, FileFormatI expectedFileType) throws FileFormatException { DataSourceType protocol = DataSourceType.FILE; IdentifyFile ider = new IdentifyFile(); - String actualFiletype = ider.identify(data, protocol).toString(); - Assert.assertEquals(actualFiletype, expectedFileType, + FileFormatI actualFiletype = ider.identify(data, protocol); + Assert.assertSame(actualFiletype, expectedFileType, "File identification Failed!"); } @@ -57,7 +57,7 @@ public class IdentifyFileTest */ String data = "Iron-sulfur (2Fe-2S)\tFER_CAPAA\t-1\t39\t39\tMETAL\n" + "Iron-phosphorus (2Fe-P)\tID_NOT_SPECIFIED\t2\t86\t87\tMETALLIC\n"; - assertEquals(IdentifyFile.FeaturesFile, + assertSame(FileFormat.Features, ider.identify(data, DataSourceType.PASTE)); /* @@ -65,14 +65,14 @@ public class IdentifyFileTest */ data = "METAL\tcc9900\n" + "GFF\n" + "FER_CAPAA\tuniprot\tMETAL\t44\t45\t4.0\t.\t.\n"; - assertEquals(IdentifyFile.FeaturesFile, + assertSame(FileFormat.Features, ider.identify(data, DataSourceType.PASTE)); /* * Feature with '<' in the name (JAL-2098) */ data = "kD < 3\tred\n" + "Low kD\tFER_CAPAA\t-1\t39\t39\tkD < 3\n"; - assertEquals(IdentifyFile.FeaturesFile, + assertSame(FileFormat.Features, ider.identify(data, DataSourceType.PASTE)); } @@ -80,26 +80,26 @@ public class IdentifyFileTest public Object[][] IdentifyFileDP() { return new Object[][] { - { "examples/example.json", "JSON" }, - { "examples/plantfdx.fa", "FASTA" }, - { "examples/dna_interleaved.phy", "PHYLIP" }, - { "examples/2GIS.pdb", "PDB" }, - { "examples/rf00031_folded.stk", "STH" }, - { "examples/testdata/test.rnaml", "RNAML" }, - { "examples/testdata/test.aln", "CLUSTAL" }, - { "examples/testdata/test.pfam", "PFAM" }, - { "examples/testdata/test.msf", "MSF" }, - { "examples/testdata/test.pir", "PIR" }, - { "examples/testdata/test.html", "HTML" }, - { "examples/testdata/test.pileup", "PileUp" }, - { "examples/testdata/test.blc", "BLC" }, - { "examples/exampleFeatures.txt", IdentifyFile.FeaturesFile }, - { "examples/testdata/simpleGff3.gff", IdentifyFile.FeaturesFile }, - { "examples/testdata/test.jvp", "Jalview" }, - { "examples/testdata/test.cif", "mmCIF" }, + { "examples/example.json", FileFormat.Json }, + { "examples/plantfdx.fa", FileFormat.Fasta }, + { "examples/dna_interleaved.phy", FileFormat.Phylip }, + { "examples/2GIS.pdb", FileFormat.PDB }, + { "examples/rf00031_folded.stk", FileFormat.Stockholm }, + { "examples/testdata/test.rnaml", FileFormat.Rnaml }, + { "examples/testdata/test.aln", FileFormat.Clustal }, + { "examples/testdata/test.pfam", FileFormat.Pfam }, + { "examples/testdata/test.msf", FileFormat.MSF }, + { "examples/testdata/test.pir", FileFormat.PIR }, + { "examples/testdata/test.html", FileFormat.Html }, + { "examples/testdata/test.pileup", FileFormat.Pileup }, + { "examples/testdata/test.blc", FileFormat.BLC }, + { "examples/exampleFeatures.txt", FileFormat.Features }, + { "examples/testdata/simpleGff3.gff", FileFormat.Features }, + { "examples/testdata/test.jvp", FileFormat.Jalview }, + { "examples/testdata/test.cif", FileFormat.MMCif }, { "examples/testdata/cullpdb_pc25_res3.0_R0.3_d150729_chains9361.fasta.15316", - "FASTA" }, + FileFormat.Fasta }, // { "examples/testdata/test.amsa", "AMSA" }, // { "examples/test.jnet", "JnetFile" }, -- 1.7.10.2