SequenceI[] sequences = null;\r
\r
String format = IdentifyFile.Identify(text, "Paste");\r
- sequences = new AppletFormatAdapter().readFile(text, "Paste", format);\r
-\r
+ try{\r
+ sequences = new AppletFormatAdapter().readFile(text, "Paste", format);\r
+ }catch(java.io.IOException ex)\r
+ {\r
+ ex.printStackTrace();\r
+ }\r
if (sequences != null)\r
{\r
AlignFrame af = new AlignFrame(new Alignment(sequences), applet,\r
if (!jalview.schemes.ResidueProperties.aaHash.containsKey(\r
String.valueOf(sequence.charAt(i))))\r
{\r
+ invalidCharacter = sequence.charAt(i);\r
return false;\r
}\r
\r
return true;\r
}\r
\r
+ char invalidCharacter;\r
+\r
/**\r
* This method must be implemented to parse the contents of the file.\r
*/\r
/** DOCUMENT ME!! */\r
public static final Vector formats = new Vector();\r
\r
+ public static String INVALID_CHARACTERS = "Contains invalid characters";\r
+\r
+ public static String SUPPORTED_FORMATS = "Formats currently supported are\n" +\r
+ "Fasta, MSF, Clustal, BLC, PIR, MSP, and PFAM";\r
+\r
static\r
{\r
formats.addElement("BLC");\r
* @return DOCUMENT ME!\r
*/\r
public SequenceI[] readFile(String inFile, String type, String format)\r
+ throws java.io.IOException\r
{\r
try\r
{\r
System.err.println("Failed to read alignment using the '" + format +\r
"' reader.\n"+e);\r
\r
+ if(e.getMessage()!=null && e.getMessage().startsWith(INVALID_CHARACTERS))\r
+ throw new java.io.IOException(e.getMessage());\r
+\r
// Finally test if the user has pasted just the sequence, no id\r
if(type.equalsIgnoreCase("Paste"))\r
{\r
// Possible sequence is just residues with no label\r
afile = new FastaFile(">UNKNOWN\n" + inFile, "Paste");\r
return afile.getSeqsAsArray();\r
- }catch(Exception ex)\r
+ }\r
+ catch(Exception ex)\r
{\r
- System.err.println("Failed to read alignment using the 'FASTA' reader.\n"+e);\r
+ if(ex.toString().startsWith(INVALID_CHARACTERS))\r
+ throw new java.io.IOException(e.getMessage());\r
+\r
ex.printStackTrace();\r
}\r
-\r
}\r
- }\r
\r
- return null;\r
+ // If we get to this stage, the format was not supported\r
+ throw new java.io.IOException(SUPPORTED_FORMATS);\r
+ }\r
}\r
\r
\r
/**\r
* DOCUMENT ME!\r
*/\r
- public void parse()\r
+ public void parse() throws IOException\r
{\r
boolean idsFound = false;\r
Vector ids = new Vector();\r
\r
String line = null;\r
\r
- try\r
- {\r
do\r
{\r
line = nextLine();\r
\r
for (int i = 0; i < ids.size(); i++)\r
{\r
- Sequence newSeq = new Sequence(ids.elementAt(i).toString(),\r
- seqstrings[i].toString(),\r
- Integer.parseInt(starts.elementAt(i).toString()),\r
- Integer.parseInt(ends.elementAt(i).toString()));\r
+ Sequence newSeq = new Sequence(ids.elementAt(i).toString(),\r
+ seqstrings[i].toString(),\r
+ Integer.parseInt(starts.elementAt(i).\r
+ toString()),\r
+ Integer.parseInt(ends.elementAt(i).toString()));\r
+\r
+ if (!isValidProteinSequence(newSeq.getSequence()))\r
+ {\r
+ throw new IOException(AppletFormatAdapter.INVALID_CHARACTERS\r
+ +" : "+ newSeq.getName()\r
+ +" : "+invalidCharacter);\r
+\r
+ }\r
+\r
seqs.addElement(newSeq);\r
}\r
- }\r
- catch (Exception ex)\r
- {\r
- ex.printStackTrace();\r
- }\r
+\r
}\r
\r
/**\r
super.initData();\r
}\r
\r
- public void parse()\r
+ public void parse() throws IOException\r
{\r
int i = 0;\r
boolean flag = false;\r
Sequence newSeq = parseId(headers.elementAt(i).toString());\r
newSeq.setSequence( seqhash.get(headers.elementAt(i).toString()).toString() );\r
\r
+ if (!isValidProteinSequence(newSeq.getSequence()))\r
+ {\r
+ throw new IOException(AppletFormatAdapter.INVALID_CHARACTERS\r
+ + " : " + newSeq.getName()\r
+ + " : " + invalidCharacter);\r
+ }\r
+\r
+\r
seqs.addElement(newSeq);\r
}\r
else\r
{\r
if (count != 0)\r
{\r
+ if (!isValidProteinSequence(sb.toString()))\r
+ {\r
+ throw new IOException(AppletFormatAdapter.INVALID_CHARACTERS\r
+ +" : "+seq.getName()\r
+ +" : "+invalidCharacter);\r
+ }\r
+\r
seq.setSequence(sb.toString());\r
seqs.addElement(seq);\r
}\r
\r
if (count > 0)\r
{\r
- if (!isValidProteinSequence(sb.toString().toUpperCase()))\r
+ if (!isValidProteinSequence(sb.toString()))\r
{\r
- throw new IOException("Invalid protein sequence");\r
+ throw new IOException(AppletFormatAdapter.INVALID_CHARACTERS\r
+ +" : "+seq.getName()\r
+ +" : "+invalidCharacter);\r
}\r
\r
seq.setSequence(sb.toString());\r
}\r
else\r
{\r
+ String errorMessage = AppletFormatAdapter.SUPPORTED_FORMATS;\r
+\r
if (FormatAdapter.formats.contains(format))\r
{\r
- sequences = new FormatAdapter().readFile(file, protocol, format);\r
+ try{\r
+ sequences = new FormatAdapter().readFile(file, protocol, format);\r
+ }catch(java.io.IOException ex)\r
+ {\r
+ errorMessage = ex.getMessage();\r
+ }\r
}\r
\r
if ( (sequences != null) && (sequences.length > 0))\r
else\r
{\r
JOptionPane.showInternalMessageDialog(Desktop.desktop,\r
- "Couldn't open file.\n" +\r
- "Formats currently supported are\n" +\r
- "Fasta, MSF, Clustal, BLC, PIR, MSP, and PFAM" // JBPNote - message should be generated through FormatAdapter!\r
- , "Error loading file",\r
+ "Couldn't load file "+file+"\n"\r
+ +errorMessage,\r
+ "Error loading file",\r
JOptionPane.WARNING_MESSAGE);\r
}\r
}\r
if (!Symscores.containsKey(ids.elementAt(i)) &&\r
!isValidProteinSequence(newSeq.getSequence()))\r
{\r
- throw new IOException(\r
- "JPredConcise: Not a valid protein sequence - (" +\r
- ids.elementAt(i).toString() + ")");\r
+ throw new IOException("JPredConcise: "\r
+ +AppletFormatAdapter.INVALID_CHARACTERS +" : "\r
+ +ids.elementAt(i).toString() + ")");\r
}\r
\r
if (maxLength != seq_entries.elementAt(i).toString().length())\r
/**\r
* DOCUMENT ME!\r
*/\r
- public void parse()\r
+ public void parse() throws IOException\r
{\r
int i = 0;\r
boolean seqFlag = false;\r
String head = headers.elementAt(i).toString();\r
String seq = seqhash.get(head).toString();\r
\r
- int start = -1;\r
- int end = -1;\r
-\r
if (maxLength < head.length())\r
{\r
maxLength = head.length();\r
\r
// Replace ~ with a sensible gap character\r
seq = seq.replace('~', '-');\r
+ if (!isValidProteinSequence(seq))\r
+ {\r
+ throw new IOException(AppletFormatAdapter.\r
+ INVALID_CHARACTERS\r
+ + " : " + head\r
+ + " : " + invalidCharacter);\r
+ }\r
+\r
\r
Sequence newSeq = parseId(head);\r
+\r
newSeq.setSequence(seq);\r
\r
seqs.addElement(newSeq);\r
import java.io.*;\r
import java.util.*;\r
\r
-import jalview.analysis.*;\r
import jalview.datamodel.*;\r
\r
public class PIRFile\r
super(inFile, type);\r
}\r
\r
- public void parse()\r
+ public void parse() throws IOException\r
{\r
- try\r
- {\r
StringBuffer sequence;\r
String line = null;\r
\r
{\r
sequence.setLength(sequence.length() - 1);\r
newSeq.setSequence(sequence.toString());\r
+ if (!isValidProteinSequence(newSeq.getSequence()))\r
+ {\r
+ throw new IOException(AppletFormatAdapter.INVALID_CHARACTERS\r
+ +" : "+ newSeq.getName()\r
+ +" : "+invalidCharacter);\r
+ }\r
+\r
seqs.addElement(newSeq);\r
ModellerDescription md = new ModellerDescription(newSeq.\r
getDescription());\r
md.updateSequenceI(newSeq);\r
}\r
}\r
- }\r
- catch (Exception ex)\r
- {\r
- ex.printStackTrace();\r
- }\r
}\r
\r
public String print()\r
super.initData();\r
}\r
\r
- public void parse()\r
- throws IOException\r
+ public void parse() throws IOException\r
{\r
int i = 0;\r
String line;\r
\r
if (!isValidProteinSequence(newSeq.getSequence()))\r
{\r
- throw new IOException(\r
- "Not a valid protein sequence - (PFAM input)");\r
+ throw new IOException(AppletFormatAdapter.INVALID_CHARACTERS\r
+ +" : "+ newSeq.getName()\r
+ +" : "+invalidCharacter);\r
}\r
}\r
else\r