2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
32 public class IdentifyFile
37 * @param file DOCUMENT ME!
38 * @param protocol DOCUMENT ME!
40 * @return DOCUMENT ME!
42 public String Identify(String file, String protocol)
44 String reply = "PFAM";
45 String error = "FILE NOT FOUND";
48 BufferedReader reader = null;
50 if (protocol.equals(AppletFormatAdapter.FILE))
52 reader = new BufferedReader(new FileReader(file));
54 else if (protocol.equals(AppletFormatAdapter.URL))
56 error = "URL NOT FOUND";
57 URL url = new URL(file);
58 reader = new BufferedReader(new InputStreamReader(
62 else if (protocol.equals(AppletFormatAdapter.PASTE))
64 reader = new BufferedReader(new StringReader(file));
66 else if (protocol.equals(AppletFormatAdapter.CLASSLOADER))
68 java.io.InputStream is = getClass().getResourceAsStream("/" +
70 reader = new BufferedReader(new java.io.InputStreamReader(is));
75 while ((data = reader.readLine()) != null)
77 data = data.toUpperCase();
79 if ( (data.indexOf("# STOCKHOLM") > -1))
86 if ((data.indexOf("#") == 0) || (data.length() < 1))
91 if (data.indexOf("PILEUP") > -1)
98 if ((data.indexOf("//") == 0) ||
99 ((data.indexOf("!!") > -1) &&
100 (data.indexOf("!!") < data.indexOf(
101 "_MULTIPLE_ALIGNMENT "))))
107 else if (data.indexOf("CLUSTAL") > -1)
113 else if ((data.indexOf(">P1;") > -1) ||
114 (data.indexOf(">DL;") > -1))
120 else if (data.indexOf(">") > -1)
122 // could be BLC file, read next line to confirm
123 data = reader.readLine();
125 if (data.indexOf(">") > -1 || data.indexOf("*") >-1 )
136 else if (data.indexOf("HEADER") > -1 ||
137 data.indexOf("ATOM") > -1)
142 else if (data.indexOf(":") < data.indexOf(",")) // && data.indexOf(",")<data.indexOf(",", data.indexOf(",")))
144 // file looks like a concise JNet file
154 System.err.println("File Identification failed!\n" + ex);