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