X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FAppletFormatAdapter.java;h=da784208d9aceae920bc2fe9b3ff82c40db8afc5;hb=429bbdae3d5229ec1b92ec59f4b5a25bcfcf13f8;hp=1bb7ba3508269494d5e7869e799f8c9b4a34ac39;hpb=95ebbef7b78bf266a8252bd479510be3c80cd234;p=jalview.git diff --git a/src/jalview/io/AppletFormatAdapter.java b/src/jalview/io/AppletFormatAdapter.java index 1bb7ba3..da78420 100755 --- a/src/jalview/io/AppletFormatAdapter.java +++ b/src/jalview/io/AppletFormatAdapter.java @@ -64,7 +64,7 @@ public class AppletFormatAdapter */ boolean serviceSecondaryStruct = false; - private AlignmentFileI alignFile = null; + private AlignmentFileReaderI alignFile = null; String inFile; @@ -85,8 +85,9 @@ public class AppletFormatAdapter public static String getSupportedFormats() { return "Formats currently supported are\n" - + prettyPrint(FileFormats.getInstance().getReadableFormats()); + + prettyPrint(FileFormats.getInstance().getReadableFormats()); } + public AppletFormatAdapter() { } @@ -146,6 +147,20 @@ public class AppletFormatAdapter public AlignmentI readFile(String file, DataSourceType sourceType, FileFormatI fileFormat) throws IOException { + if (alignFile == null) + { + prepareFileReader(file, sourceType, fileFormat); + } + else + { + alignFile.parse(); + } + return buildAlignmentFromFile(); + } + + public void prepareFileReader(String file, DataSourceType sourceType, + FileFormatI fileFormat) throws IOException + { this.inFile = file; try { @@ -154,8 +169,8 @@ public class AppletFormatAdapter String structureParser = StructureImportSettings .getDefaultPDBFileParser(); boolean isParseWithJMOL = structureParser.equalsIgnoreCase( - StructureImportSettings.StructureParser.JMOL_PARSER - .toString()); + StructureImportSettings.StructureParser.JMOL_PARSER + .toString()); StructureImportSettings.addSettings(annotFromStructure, localSecondaryStruct, serviceSecondaryStruct); if (isParseWithJMOL) @@ -170,21 +185,19 @@ public class AppletFormatAdapter localSecondaryStruct, serviceSecondaryStruct, inFile, sourceType); } - ((StructureFile) alignFile).setDbRefType(FileFormat.PDB - .equals(fileFormat) ? Type.PDB : Type.MMCIF); + ((StructureFile) alignFile).setDbRefType( + FileFormat.PDB.equals(fileFormat) ? Type.PDB : Type.MMCIF); } else { - // alignFile = fileFormat.getAlignmentFile(inFile, sourceType); - alignFile = fileFormat.getReader(new FileParse(inFile, - sourceType)); + alignFile = fileFormat.getReader(new FileParse(inFile, sourceType)); } - return buildAlignmentFromFile(); + return; } catch (Exception e) { e.printStackTrace(); - System.err.println("Failed to read alignment using the '" - + fileFormat + "' reader.\n" + e); + System.err.println("Failed to read alignment using the '" + fileFormat + + "' reader.\n" + e); if (e.getMessage() != null && e.getMessage().startsWith(INVALID_CHARACTERS)) @@ -200,7 +213,7 @@ public class AppletFormatAdapter // Possible sequence is just residues with no label alignFile = new FastaFile(">UNKNOWN\n" + inFile, DataSourceType.PASTE); - return buildAlignmentFromFile(); + return; } catch (Exception ex) { @@ -333,10 +346,10 @@ public class AppletFormatAdapter AlignmentViewPanel ap, boolean selectedOnly) { - AlignmentView selvew = ap.getAlignViewport().getAlignmentView( - selectedOnly, false); - AlignmentI aselview = selvew.getVisibleAlignment(ap.getAlignViewport() - .getGapCharacter()); + AlignmentView selvew = ap.getAlignViewport() + .getAlignmentView(selectedOnly, false); + AlignmentI aselview = selvew + .getVisibleAlignment(ap.getAlignViewport().getGapCharacter()); List ala = (ap.getAlignViewport() .getVisibleAlignmentAnnotation(selectedOnly)); if (ala != null) @@ -370,7 +383,7 @@ public class AppletFormatAdapter { try { - AlignmentFileI afile = format.getWriter(alignment); + AlignmentFileWriterI afile = format.getWriter(alignment); afile.setNewlineString(newline); afile.setExportSettings(exportSettings); @@ -399,23 +412,33 @@ public class AppletFormatAdapter } catch (Exception e) { System.err.println("Failed to write alignment as a '" - + format.getName() - + "' file\n"); + + format.getName() + "' file\n"); e.printStackTrace(); } return null; } - public static DataSourceType checkProtocol(String file) + /** + * Determines the protocol (i.e DataSourceType.{FILE|PASTE|URL}) for the input + * data + * + * @param data + * @return the protocol for the input data + */ + public static DataSourceType checkProtocol(String data) { - DataSourceType protocol = DataSourceType.FILE; - String ft = file.toLowerCase().trim(); + DataSourceType protocol = DataSourceType.PASTE; + String ft = data.toLowerCase().trim(); if (ft.indexOf("http:") == 0 || ft.indexOf("https:") == 0 || ft.indexOf("file:") == 0) { protocol = DataSourceType.URL; } + else if (new File(data).exists()) + { + protocol = DataSourceType.FILE; + } return protocol; } @@ -435,10 +458,9 @@ public class AppletFormatAdapter System.gc(); long memf = -r.totalMemory() + r.freeMemory(); long t1 = -System.currentTimeMillis(); - AlignmentI al = afa - .readFile(args[i], DataSourceType.FILE, - new IdentifyFile().identify(args[i], - DataSourceType.FILE)); + AlignmentI al = afa.readFile(args[i], DataSourceType.FILE, + new IdentifyFile().identify(args[i], + DataSourceType.FILE)); t1 += System.currentTimeMillis(); System.gc(); memf += r.totalMemory() - r.freeMemory(); @@ -448,12 +470,12 @@ public class AppletFormatAdapter + " sequences and " + al.getWidth() + " columns."); try { - System.out.println(new AppletFormatAdapter().formatSequences( - FileFormat.Fasta, al, true)); + System.out.println(new AppletFormatAdapter() + .formatSequences(FileFormat.Fasta, al, true)); } catch (Exception e) { - System.err - .println("Couln't format the alignment for output as a FASTA file."); + System.err.println( + "Couln't format the alignment for output as a FASTA file."); e.printStackTrace(System.err); } } @@ -462,8 +484,8 @@ public class AppletFormatAdapter System.out.println("Couldn't read alignment"); } System.out.println("Read took " + (t1 / 1000.0) + " seconds."); - System.out - .println("Difference between free memory now and before is " + System.out.println( + "Difference between free memory now and before is " + (memf / (1024.0 * 1024.0) * 1.0) + " MB"); } catch (Exception e) { @@ -547,8 +569,8 @@ public class AppletFormatAdapter { if (debug) { - System.out.println("Trying to get contents of resource as " - + protocol + ":"); + System.out.println( + "Trying to get contents of resource as " + protocol + ":"); } fp = new FileParse(file, protocol); if (!fp.isValid()) @@ -648,7 +670,7 @@ public class AppletFormatAdapter return null; } - public AlignmentFileI getAlignFile() + public AlignmentFileReaderI getAlignFile() { return alignFile; }