2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2006 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("# STOCKHOLM") > -1))
\r
86 if ((data.indexOf("#") == 0) || (data.length() < 1))
\r
91 if (data.indexOf("PILEUP") > -1)
\r
98 if ((data.indexOf("//") == 0) ||
\r
99 ((data.indexOf("!!") > -1) &&
\r
100 (data.indexOf("!!") < data.indexOf(
\r
101 "_MULTIPLE_ALIGNMENT "))))
\r
107 else if (data.indexOf("CLUSTAL") > -1)
\r
113 else if ((data.indexOf(">P1;") > -1) ||
\r
114 (data.indexOf(">DL;") > -1))
\r
120 else if (data.indexOf(">") > -1)
\r
122 // could be BLC file, read next line to confirm
\r
123 data = reader.readLine();
\r
125 if (data.indexOf(">") > -1)
\r
131 //Is this a single line BLC file?
\r
133 String data2 = reader.readLine();
\r
135 && data.indexOf("*")>-1
\r
136 && data.indexOf("*")==data2.indexOf("*"))
\r
148 else if (data.indexOf("HEADER") > -1 ||
\r
149 data.indexOf("ATOM") > -1)
\r
154 else if (data.indexOf(":") < data.indexOf(",")) // && data.indexOf(",")<data.indexOf(",", data.indexOf(",")))
\r
156 // file looks like a concise JNet file
\r
157 reply = "JnetFile";
\r
164 catch (Exception ex)
\r
166 System.err.println("File Identification failed!\n" + ex);
\r