+ }
+
+ // If we get to this stage, the format was not supported
+ throw new java.io.IOException(SUPPORTED_FORMATS);
+ }
+ }
+
+ /**
+ * Constructs the correct filetype parser for an already open datasource
+ *
+ * @param source
+ * an existing datasource
+ * @param format
+ * File format of data that will be provided by datasource
+ *
+ * @return DOCUMENT ME!
+ */
+ public AlignmentI readFromFile(FileParse source, String format)
+ throws java.io.IOException
+ {
+ // TODO: generalise mapping between format string and io. class instances
+ // using Constructor.invoke reflection
+ // This is exactly the same as the readFile method except we substitute
+ // 'inFile, type' with 'source'
+ this.inFile = source.getInFile();
+ String type = source.type;
+ try
+ {
+ Alignment al;
+ if (format.equals("FASTA"))
+ {
+ alignFile = new FastaFile(source);
+ }
+ else if (format.equals("MSF"))
+ {
+ alignFile = new MSFfile(source);
+ }
+ else if (format.equals("PileUp"))
+ {
+ alignFile = new PileUpfile(source);
+ }
+ else if (format.equals("CLUSTAL"))
+ {
+ alignFile = new ClustalFile(source);
+ }
+ else if (format.equals("BLC"))
+ {
+ alignFile = new BLCFile(source);
+ }
+ else if (format.equals("PIR"))
+ {
+ alignFile = new PIRFile(source);
+ }
+ else if (format.equals("PFAM"))
+ {
+ alignFile = new PfamFile(source);
+ }
+ else if (format.equals("JnetFile"))
+ {
+ alignFile = new JPredFile(source);
+ ((JPredFile) alignFile).removeNonSequences();
+ }
+ else if (format.equals("PDB"))
+ {
+ alignFile = new MCview.PDBfile(annotFromStructure,
+ localSecondaryStruct, serviceSecondaryStruct, source);
+ }
+ else if (format.equals("STH"))
+ {
+ alignFile = new StockholmFile(source);
+ }
+ else if (format.equals("RNAML"))
+ {
+ alignFile = new RnamlFile(source);
+ }
+ else if (format.equals("SimpleBLAST"))
+ {
+ alignFile = new SimpleBlastFile(source);
+ }
+ else if (format.equals(PhylipFile.FILE_DESC))
+ {
+ alignFile = new PhylipFile(source);
+ }
+ else if (format.equals(JSONFile.FILE_DESC))
+ {
+ alignFile = new JSONFile(source);
+ // ((JSONFile) afile).setViewport(viewport);
+ al = new Alignment(alignFile.getSeqsAsArray());
+ alignFile.addAnnotations(al);
+ alignFile.addSeqGroups(al);
+ return al;
+ }
+ else if (format.equals(HtmlFile.FILE_DESC))
+ {
+ alignFile = new HtmlFile(source);
+ }
+ al = new Alignment(alignFile.getSeqsAsArray());
+ alignFile.addAnnotations(al);
+
+ return al;
+ } 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"))
+ {
+ try
+ {
+ // Possible sequence is just residues with no label
+ alignFile = new FastaFile(">UNKNOWN\n" + inFile, "Paste");
+ Alignment al = new Alignment(alignFile.getSeqsAsArray());
+ alignFile.addAnnotations(al);
+ alignFile.addSeqGroups(al);
+ return al;
+
+ } catch (Exception ex)