X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FAppletFormatAdapter.java;h=8d2d796ae98cff03a278d8d13c64b99e2b9a73e5;hb=b0af1c02bc91ec74e941dfc8220b52f591d5df1a;hp=f8b809ea2a4b6cf77c608c628a2ef5ff1f7c2e80;hpb=55e2e9b22b133db8b9ff0979b0338a33081fc8fd;p=jalview.git diff --git a/src/jalview/io/AppletFormatAdapter.java b/src/jalview/io/AppletFormatAdapter.java index f8b809e..8d2d796 100755 --- a/src/jalview/io/AppletFormatAdapter.java +++ b/src/jalview/io/AppletFormatAdapter.java @@ -34,6 +34,11 @@ /** DOCUMENT ME!! */ public static final Vector formats = new Vector(); + public static String INVALID_CHARACTERS = "Contains invalid characters"; + + public static String SUPPORTED_FORMATS = "Formats currently supported are\n" + + "Fasta, MSF, Clustal, BLC, PIR, MSP, and PFAM"; + static { formats.addElement("BLC"); @@ -43,9 +48,17 @@ formats.addElement("PileUp"); formats.addElement("PIR"); formats.addElement("PFAM"); + formats.addElement("PDB"); } + + public static String FILE = "File"; + public static String URL = "URL"; + public static String PASTE = "Paste"; + public static String CLASSLOADER = "ClassLoader"; + AlignFile afile = null; + String inFile; /** * DOCUMENT ME! @@ -57,45 +70,60 @@ * @return DOCUMENT ME! */ public SequenceI[] readFile(String inFile, String type, String format) + throws java.io.IOException { + this.inFile = inFile; try { - if (format.equals("FASTA")) - { - afile = new FastaFile(inFile, type); - } - else if (format.equals("MSF")) - { - afile = new MSFfile(inFile, type); - } - else if (format.equals("PileUp")) - { - afile = new PileUpfile(inFile, type); - } - else if (format.equals("CLUSTAL")) - { - afile = new ClustalFile(inFile, type); - } - else if (format.equals("BLC")) - { - afile = new BLCFile(inFile, type); - } - else if (format.equals("PIR")) - { - afile = new PIRFile(inFile, type); - } - else if (format.equals("PFAM")) - { - afile = new PfamFile(inFile, type); - } + if (format.equals("FASTA")) + { + afile = new FastaFile(inFile, type); + } + else if (format.equals("MSF")) + { + afile = new MSFfile(inFile, type); + } + else if (format.equals("PileUp")) + { + afile = new PileUpfile(inFile, type); + } + else if (format.equals("CLUSTAL")) + { + afile = new ClustalFile(inFile, type); + } + else if (format.equals("BLC")) + { + afile = new BLCFile(inFile, type); + } + else if (format.equals("PIR")) + { + afile = new PIRFile(inFile, type); + } + else if (format.equals("PFAM")) + { + afile = new PfamFile(inFile, type); + } + else if (format.equals("JnetFile")) + { + afile = new JPredFile(inFile, type); + ( (JPredFile) afile).removeNonSequences(); + } + else if (format.equals("PDB")) + { + afile = new MCview.PDBfile(inFile, type); + } - return afile.getSeqsAsArray(); + return afile.getSeqsAsArray(); } catch (Exception e) { + e.printStackTrace(); System.err.println("Failed to read alignment using the '" + format + "' reader.\n"+e); + if(e.getMessage()!=null && e.getMessage().startsWith(INVALID_CHARACTERS)) + throw new java.io.IOException(e.getMessage()); + // Finally test if the user has pasted just the sequence, no id if(type.equalsIgnoreCase("Paste")) { @@ -103,16 +131,19 @@ // Possible sequence is just residues with no label afile = new FastaFile(">UNKNOWN\n" + inFile, "Paste"); return afile.getSeqsAsArray(); - }catch(Exception ex) + } + catch(Exception ex) { - System.err.println("Failed to read alignment using the 'FASTA' reader.\n"+e); + if(ex.toString().startsWith(INVALID_CHARACTERS)) + throw new java.io.IOException(e.getMessage()); + ex.printStackTrace(); } - } - } - return null; + // If we get to this stage, the format was not supported + throw new java.io.IOException(SUPPORTED_FORMATS); + } }