From: gmungoc Date: Thu, 24 Nov 2016 13:06:38 +0000 (+0000) Subject: FileFormatI further tweaks, clean compile X-Git-Tag: Release_2_10_3b1~409 X-Git-Url: http://source.jalview.org/gitweb/?p=jalview.git;a=commitdiff_plain;h=74b531f56bbaad5c5e06a4744980256fe8110923 FileFormatI further tweaks, clean compile --- diff --git a/src/jalview/appletgui/APopupMenu.java b/src/jalview/appletgui/APopupMenu.java index abb6848..1b66e9c 100644 --- a/src/jalview/appletgui/APopupMenu.java +++ b/src/jalview/appletgui/APopupMenu.java @@ -217,10 +217,9 @@ public class APopupMenu extends java.awt.PopupMenu implements e.printStackTrace(); } - for (int i = 0; i < jalview.io.AppletFormatAdapter.WRITEABLE_FORMATS.length; i++) + for (String ff : FileFormat.getWritableFormats()) { - MenuItem item = new MenuItem( - jalview.io.AppletFormatAdapter.WRITEABLE_FORMATS[i]); + MenuItem item = new MenuItem(ff); item.addActionListener(this); outputmenu.add(item); diff --git a/src/jalview/appletgui/AlignFrame.java b/src/jalview/appletgui/AlignFrame.java index 2ee86f1..e1b01a8 100644 --- a/src/jalview/appletgui/AlignFrame.java +++ b/src/jalview/appletgui/AlignFrame.java @@ -3241,11 +3241,9 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, inputText.addActionListener(this); Menu outputTextboxMenu = new Menu( MessageManager.getString("label.out_to_textbox")); - for (int i = 0; i < jalview.io.AppletFormatAdapter.WRITEABLE_FORMATS.length; i++) + for (String ff : FileFormat.getWritableFormats()) { - - MenuItem item = new MenuItem( - jalview.io.AppletFormatAdapter.WRITEABLE_FORMATS[i]); + MenuItem item = new MenuItem(ff); item.addActionListener(new java.awt.event.ActionListener() { diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 38223c7..e585e28 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -1263,9 +1263,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, protected void outputText_actionPerformed(ActionEvent e) { - FileFormat fileFormat = FileFormat.valueOf(e.getActionCommand()); - AlignmentExportData exportData = getAlignmentForExport( -fileFormat, + FileFormatI fileFormat = FileFormat.forName(e.getActionCommand()); + AlignmentExportData exportData = getAlignmentForExport(fileFormat, viewport, null); if (exportData.getSettings().isCancelled()) { diff --git a/src/jalview/gui/PopupMenu.java b/src/jalview/gui/PopupMenu.java index 52a0d41..4d9dc4d 100644 --- a/src/jalview/gui/PopupMenu.java +++ b/src/jalview/gui/PopupMenu.java @@ -258,10 +258,9 @@ public class PopupMenu extends JPopupMenu colours.add(purinePyrimidineColour); colours.add(RNAInteractionColour); - for (int i = 0; i < jalview.io.FormatAdapter.WRITEABLE_FORMATS.length; i++) + for (String ff : FileFormat.getWritableFormats()) { - JMenuItem item = new JMenuItem( - jalview.io.FormatAdapter.WRITEABLE_FORMATS[i]); + JMenuItem item = new JMenuItem(ff); item.addActionListener(new java.awt.event.ActionListener() { diff --git a/src/jalview/io/AMSAFile.java b/src/jalview/io/AMSAFile.java index 798249f..34eace4 100644 --- a/src/jalview/io/AMSAFile.java +++ b/src/jalview/io/AMSAFile.java @@ -24,6 +24,8 @@ import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; import jalview.datamodel.SequenceI; +import java.io.IOException; + public class AMSAFile extends jalview.io.FastaFile { @@ -37,11 +39,23 @@ public class AMSAFile extends jalview.io.FastaFile this.al = al; } + public AMSAFile(String inFile, DataSourceType sourceType) + throws IOException + { + super(inFile, sourceType); + } + + public AMSAFile(FileParse source) throws IOException + { + super(source); + } + /** * DOCUMENT ME! * * @return DOCUMENT ME! */ + @Override public String print(SequenceI[] sqs, boolean jvsuffix) { super.print(sqs, jvsuffix); diff --git a/src/jalview/io/AppletFormatAdapter.java b/src/jalview/io/AppletFormatAdapter.java index 04d68e8..e0a607b 100755 --- a/src/jalview/io/AppletFormatAdapter.java +++ b/src/jalview/io/AppletFormatAdapter.java @@ -78,58 +78,59 @@ public class AppletFormatAdapter /** * List of valid format strings used in the isValidFormat method */ - public static final String[] READABLE_FORMATS = new String[] { "BLC", - "CLUSTAL", "FASTA", "MSF", "PileUp", "PIR", "PFAM", "STH", "PDB", - "JnetFile", "RNAML", "PHYLIP", "JSON", - IdentifyFile.FeaturesFile, "HTML", "mmCIF" }; + // public static final String[] READABLE_FORMATS = new String[] { "BLC", + // "CLUSTAL", "FASTA", "MSF", "PileUp", "PIR", "PFAM", "STH", "PDB", + // "JnetFile", "RNAML", "PHYLIP", "JSON", + // IdentifyFile.FeaturesFile, "HTML", "mmCIF" }; /** * List of readable format file extensions by application in order * corresponding to READABLE_FNAMES */ - public static final String[] READABLE_EXTENSIONS = new String[] { - "fa, fasta, mfa, fastq", "aln", "pfam", "msf", "pir", "blc", "amsa", - "sto,stk", "xml,rnaml", "phy", "json", - ".gff2,gff3", "jar,jvp", "html", "cif" }; - - /** - * List of readable formats by application in order corresponding to - * READABLE_EXTENSIONS - */ - public static final String[] READABLE_FNAMES = new String[] { "Fasta", - "Clustal", "PFAM", "MSF", "PIR", "BLC", "AMSA", "Stockholm", "RNAML", - "PHYLIP", "JSON", IdentifyFile.FeaturesFile, - "Jalview", HtmlFile.FILE_DESC, "mmCIF" }; + // public static final String[] READABLE_EXTENSIONS = new String[] { + // "fa, fasta, mfa, fastq", "aln", "pfam", "msf", "pir", "blc", "amsa", + // "sto,stk", "xml,rnaml", "phy", "json", ".gff2,gff3", "jar,jvp", + // "html", "cif" }; + + // + // /** + // * List of readable formats by application in order corresponding to + // * READABLE_EXTENSIONS + // */ + // public static final String[] READABLE_FNAMES = new String[] { "Fasta", + // "Clustal", "PFAM", "MSF", "PIR", "BLC", "AMSA", "Stockholm", "RNAML", + // "PHYLIP", "JSON", IdentifyFile.FeaturesFile, + // "Jalview", HtmlFile.FILE_DESC, "mmCIF" }; /** * List of valid format strings for use by callers of the formatSequences * method */ - public static final String[] WRITEABLE_FORMATS = new String[] { "BLC", - "CLUSTAL", "FASTA", "MSF", "PileUp", "PIR", "PFAM", "AMSA", "STH", - "PHYLIP", "JSON" }; + // public static final String[] WRITEABLE_FORMATS = new String[] { "BLC", + // "CLUSTAL", "FASTA", "MSF", "PileUp", "PIR", "PFAM", "AMSA", "STH", + // "PHYLIP", "JSON" }; /** * List of extensions corresponding to file format types in WRITABLE_FNAMES * that are writable by the application. */ - public static final String[] WRITABLE_EXTENSIONS = new String[] { - "fa, fasta, mfa, fastq", "aln", "pfam", "msf", "pir", "blc", "amsa", - "sto,stk", "phy", "json", "jvp" }; + // public static final String[] WRITABLE_EXTENSIONS = new String[] { + // "fa, fasta, mfa, fastq", "aln", "pfam", "msf", "pir", "blc", "amsa", + // "sto,stk", "phy", "json", "jvp" }; /** * List of writable formats by the application. Order must correspond with the * WRITABLE_EXTENSIONS list of formats. */ - public static final String[] WRITABLE_FNAMES = new String[] { "Fasta", - "Clustal", "PFAM", "MSF", "PIR", "BLC", "AMSA", "STH", - "PHYLIP", "JSON", "Jalview" }; + // public static final String[] WRITABLE_FNAMES = new String[] { "Fasta", + // "Clustal", "PFAM", "MSF", "PIR", "BLC", "AMSA", "STH", "PHYLIP", + // "JSON", "Jalview" }; public static String INVALID_CHARACTERS = "Contains invalid characters"; // TODO: make these messages dynamic public static String SUPPORTED_FORMATS = "Formats currently supported are\n" - + prettyPrint(READABLE_FORMATS); + + prettyPrint(FileFormat.getReadableFormats()); public AppletFormatAdapter() { @@ -148,19 +149,21 @@ public class AppletFormatAdapter } /** - * - * @param els - * @return grammatically correct(ish) list consisting of els elements. + * Formats a grammatically correct(ish) list consisting of the given objects + * + * @param things + * @return */ - public static String prettyPrint(String[] els) + public static String prettyPrint(List things) { StringBuffer list = new StringBuffer(); - for (int i = 0, iSize = els.length - 1; i < iSize; i++) + for (int i = 0, iSize = things.size() - 1; i < iSize; i++) { - list.append(els[i]); + list.append(things.get(i).toString()); list.append(", "); } - list.append(" and " + els[els.length - 1] + "."); + // could i18n 'and' here + list.append(" and " + things.get(things.size() - 1).toString() + "."); return list.toString(); } @@ -224,29 +227,28 @@ public class AppletFormatAdapter { alignFile = fileFormat.getAlignmentFile(inFile, sourceType); } - // new FastaFile(inFile, sourceType); - // new MSFfile(inFile, sourceType); - // new PileUpfile(inFile, sourceType); - // new ClustalFile(inFile, sourceType); - // new BLCFile(inFile, sourceType); - // new PIRFile(inFile, sourceType); - // new PfamFile(inFile, sourceType); - // alignFile = new JPredFile(inFile, sourceType); - // ((JPredFile) alignFile).removeNonSequences(); - // new StockholmFile(inFile, sourceType); - // new SimpleBlastFile(inFile, sourceType); - // new PhylipFile(inFile, sourceType); - // new JSONFile(inFile, sourceType); - // new HtmlFile(inFile, sourceType); - // new RnamlFile(inFile, sourceType); -// alignFile = new FeaturesFile(true, inFile, sourceType); + // new FastaFile(inFile, sourceType); + // new MSFfile(inFile, sourceType); + // new PileUpfile(inFile, sourceType); + // new ClustalFile(inFile, sourceType); + // new BLCFile(inFile, sourceType); + // new PIRFile(inFile, sourceType); + // new PfamFile(inFile, sourceType); + // alignFile = new JPredFile(inFile, sourceType); + // ((JPredFile) alignFile).removeNonSequences(); + // new StockholmFile(inFile, sourceType); + // new SimpleBlastFile(inFile, sourceType); + // new PhylipFile(inFile, sourceType); + // new JSONFile(inFile, sourceType); + // new HtmlFile(inFile, sourceType); + // new RnamlFile(inFile, sourceType); + // alignFile = new FeaturesFile(true, inFile, sourceType); return buildAlignmentFromFile(); } catch (Exception e) { e.printStackTrace(); System.err.println("Failed to read alignment using the '" - + fileFormat - + "' reader.\n" + e); + + fileFormat + "' reader.\n" + e); if (e.getMessage() != null && e.getMessage().startsWith(INVALID_CHARACTERS)) @@ -666,8 +668,7 @@ public class AppletFormatAdapter { try { - FileFormatI idformat = new IdentifyFile().identify(file, - protocol); + FileFormatI idformat = new IdentifyFile().identify(file, protocol); if (idformat == null) { if (debug) diff --git a/src/jalview/io/FeaturesFile.java b/src/jalview/io/FeaturesFile.java index 20c44bc..07a3b25 100755 --- a/src/jalview/io/FeaturesFile.java +++ b/src/jalview/io/FeaturesFile.java @@ -712,7 +712,8 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI dataset = new Alignment(new SequenceI[] {}); } - boolean parseResult = parse(dataset, null, false, true); + Map featureColours = new HashMap(); + boolean parseResult = parse(dataset, featureColours, false, true); if (!parseResult) { // pass error up somehow diff --git a/src/jalview/io/FileFormat.java b/src/jalview/io/FileFormat.java index a7113f6..770f762 100644 --- a/src/jalview/io/FileFormat.java +++ b/src/jalview/io/FileFormat.java @@ -5,12 +5,14 @@ import jalview.ext.jmol.JmolParser; import jalview.structure.StructureImportSettings; import java.io.IOException; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; public enum FileFormat implements FileFormatI { - Fasta("FASTA", "fa, fasta, mfa, fastq", true, true) + Fasta("Fasta", "fa, fasta, mfa, fastq", true, true) { @Override public AlignmentFileI getAlignmentFile(String inFile, @@ -54,7 +56,7 @@ public enum FileFormat implements FileFormatI return new PfamFile(); } }, - Stockholm("STH", "sto,stk", true, true) + Stockholm("Stockholm", "sto,stk", true, true) { @Override public AlignmentFileI getAlignmentFile(String inFile, @@ -118,6 +120,28 @@ public enum FileFormat implements FileFormatI return new BLCFile(); } }, + AMSA("AMSA", "amsa", true, true) + { + @Override + public AlignmentFileI getAlignmentFile(String inFile, + DataSourceType sourceType) throws IOException + { + return new AMSAFile(inFile, sourceType); + } + + @Override + public AlignmentFileI getAlignmentFile(FileParse source) + throws IOException + { + return new AMSAFile(source); + } + + @Override + public AlignmentFileI getAlignmentFile() + { + return new BLCFile(); + } + }, Html("HTML", "html", true, false) { @Override @@ -193,7 +217,7 @@ public enum FileFormat implements FileFormatI } }, - Pileup("PileUp", "?", false, false) + Pileup("PileUp", "pileup", false, true) { @Override public AlignmentFileI getAlignmentFile(String inFile, @@ -235,7 +259,7 @@ public enum FileFormat implements FileFormatI } }, - Clustal("CLUSTAL", "aln", true, true) + Clustal("Clustal", "aln", true, true) { @Override public AlignmentFileI getAlignmentFile(String inFile, @@ -465,6 +489,44 @@ public enum FileFormat implements FileFormatI private String name; + /** + * Answers a list of writeable file formats (as string, corresponding to the + * toString() and forName() methods) + * + * @return + */ + public static List getWritableFormats() + { + List l = new ArrayList(); + for (FileFormatI ff : values()) + { + if (ff.isWritable()) + { + l.add(ff.toString()); + } + } + return l; + } + + /** + * Answers a list of readable file formats (as string, corresponding to the + * toString() and forName() methods) + * + * @return + */ + public static List getReadableFormats() + { + List l = new ArrayList(); + for (FileFormatI ff : values()) + { + if (ff.isReadable()) + { + l.add(ff.toString()); + } + } + return l; + } + @Override public boolean isComplexAlignFile() { @@ -527,4 +589,10 @@ public enum FileFormat implements FileFormatI { return extensions; } + + @Override + public String toString() + { + return name; + } } diff --git a/src/jalview/io/FileLoader.java b/src/jalview/io/FileLoader.java index 88f9ae5..e17fe04 100755 --- a/src/jalview/io/FileLoader.java +++ b/src/jalview/io/FileLoader.java @@ -317,7 +317,7 @@ public class FileLoader implements Runnable if (source != null) { // read from the provided source - al = new FormatAdapter().readFromFile(source, format); + al = new FormatAdapter().readFromFile(source, format); } else { diff --git a/src/jalview/io/FormatAdapter.java b/src/jalview/io/FormatAdapter.java index 1408cd1..724170e 100755 --- a/src/jalview/io/FormatAdapter.java +++ b/src/jalview/io/FormatAdapter.java @@ -242,14 +242,6 @@ public class FormatAdapter extends AppletFormatAdapter getCacheSuffixDefault(format), colSel, null); } - public String formatSequences(FileFormatI format, AlignmentI alignment, - String[] omitHidden, int[] exportRange, ColumnSelection colSel, - SequenceGroup sgp) - { - return formatSequences(format, alignment, omitHidden, exportRange, - getCacheSuffixDefault(format), colSel, sgp); - } - /** * hack function to replace seuqences with visible sequence strings before * generating a string of the alignment in the given format. @@ -337,4 +329,12 @@ public class FormatAdapter extends AppletFormatAdapter selectedOnly); } + public AlignmentI readFromFile(AlignmentFileI source, FileFormatI format) + throws IOException + { + FileParse fp = new FileParse(source.getInFile(), + source.getDataSourceType()); + return readFromFile(fp, format); + } + } diff --git a/src/jalview/io/IdentifyFile.java b/src/jalview/io/IdentifyFile.java index 89fc3cd..bc91e09 100755 --- a/src/jalview/io/IdentifyFile.java +++ b/src/jalview/io/IdentifyFile.java @@ -74,6 +74,13 @@ public class IdentifyFile // preserves original behaviour prior to version 2.3 } + public FileFormatI identify(AlignmentFileI file, boolean closeSource) + throws IOException + { + FileParse fp = new FileParse(file.getInFile(), file.getDataSourceType()); + return identify(fp, closeSource); + } + /** * Identify contents of source, closing it or resetting source to start * afterwards. @@ -343,6 +350,7 @@ public class IdentifyFile .println("File Identification failed! - Empty file was read."); throw new FileFormatException("EMPTY DATA FILE"); } + System.out.println("File format identified as " + reply.toString()); return reply; } diff --git a/src/jalview/io/JalviewFileChooser.java b/src/jalview/io/JalviewFileChooser.java index a4362dc..7e1aaa1 100755 --- a/src/jalview/io/JalviewFileChooser.java +++ b/src/jalview/io/JalviewFileChooser.java @@ -241,6 +241,7 @@ public class JalviewFileChooser extends JFileChooser } String format = getFileFilter().getDescription(); + format = format.substring(0, format.indexOf("(") - 1); return FileFormat.valueOf(format); } diff --git a/src/jalview/jbgui/GAlignFrame.java b/src/jalview/jbgui/GAlignFrame.java index d7def6b..73d1b3c 100755 --- a/src/jalview/jbgui/GAlignFrame.java +++ b/src/jalview/jbgui/GAlignFrame.java @@ -25,6 +25,7 @@ import jalview.api.SplitContainerI; import jalview.bin.Cache; import jalview.gui.JvSwingUtils; import jalview.gui.Preferences; +import jalview.io.FileFormat; import jalview.schemes.ColourSchemeProperty; import jalview.util.MessageManager; @@ -244,10 +245,9 @@ public class GAlignFrame extends JInternalFrame setJMenuBar(alignFrameMenuBar); // dynamically fill save as menu with available formats - for (int i = 0; i < jalview.io.FormatAdapter.WRITEABLE_FORMATS.length; i++) + for (String ff : FileFormat.getWritableFormats()) { - JMenuItem item = new JMenuItem( - jalview.io.FormatAdapter.WRITEABLE_FORMATS[i]); + JMenuItem item = new JMenuItem(ff); item.addActionListener(new ActionListener() { diff --git a/src/jalview/ws/rest/params/Alignment.java b/src/jalview/ws/rest/params/Alignment.java index c78bced..08a242d 100644 --- a/src/jalview/ws/rest/params/Alignment.java +++ b/src/jalview/ws/rest/params/Alignment.java @@ -38,7 +38,6 @@ import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.UnsupportedEncodingException; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import org.apache.http.entity.mime.content.ContentBody; @@ -199,13 +198,27 @@ public class Alignment extends InputType writeAsFile, null)); lst.add(new Option("format", "Alignment upload format", true, - FileFormat.Fasta.toString(), - format.toString(), Arrays - .asList(jalview.io.FormatAdapter.WRITEABLE_FORMATS), + FileFormat.Fasta.toString(), format.toString(), getWritableFormats(), null)); lst.add(createMolTypeOption("type", "Sequence type", false, type, null)); return lst; } + /** + * @return + */ + protected List getWritableFormats() + { + List formats = new ArrayList(); + for (FileFormatI ff : FileFormat.values()) + { + if (ff.isWritable()) + { + formats.add(ff.toString()); + } + } + return formats; + } + }