X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FIdentifyFile.java;h=f4beccb42d77ccad84cbd77cd53c9c17d981fe59;hb=8d3d3b4edf47e543b8b352c1b2c247cfc59122a4;hp=f1cf1e0bc94529e16b6ba2af4ef1c21b9e36fa3d;hpb=99c58ee0ae2a848f982552e53feaf6d5cb9925e5;p=jalview.git diff --git a/src/jalview/io/IdentifyFile.java b/src/jalview/io/IdentifyFile.java index f1cf1e0..f4beccb 100755 --- a/src/jalview/io/IdentifyFile.java +++ b/src/jalview/io/IdentifyFile.java @@ -16,83 +16,120 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ - package jalview.io; import java.io.*; + import java.net.*; + +/** + * DOCUMENT ME! + * + * @author $author$ + * @version $Revision$ + */ public class IdentifyFile { - public static String Identify(String file, String protocol) - { - String reply = "PFAM"; - try{ - - BufferedReader reader = null; - - if(protocol.equals("File")) - reader = new BufferedReader(new FileReader(file)); - - else if (protocol.equals("URL")) - { - reply = "URL NOT FOUND"; - URL url = new URL(file); - reader = new BufferedReader(new InputStreamReader( url.openStream() ) ); - reply = "error"; - } - else if( protocol.equals("Paste")) - reader = new BufferedReader( new StringReader(file) ); - - - String data; - while( (data=reader.readLine())!=null) - { - data = data.toUpperCase(); - if(data.indexOf("#")==0 || data.length()<1) - continue; - - if(data.indexOf("PILEUP")>-1) - { - reply = "PileUp"; - break; - } - if((data.indexOf("//")==0) - || ((data.indexOf("!!")>-1) - && (data.indexOf("!!")-1) - { - reply = "CLUSTAL"; - break; - } - else if(data.indexOf(">P1;")>-1 || data.indexOf(">DL;")>-1) + /** + * DOCUMENT ME! + * + * @param file DOCUMENT ME! + * @param protocol DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public static String Identify(String file, String protocol) + { + String reply = "PFAM"; + String error = "FILE NOT FOUND"; + + try { - reply = "PIR"; - break; + BufferedReader reader = null; + + if (protocol.equalsIgnoreCase("File")) + { + reader = new BufferedReader(new FileReader(file)); + } + else if (protocol.equalsIgnoreCase("URL")) + { + error = "URL NOT FOUND"; + URL url = new URL(file); + reader = new BufferedReader(new InputStreamReader( + url.openStream())); + + } + else if (protocol.equalsIgnoreCase("Paste")) + { + reader = new BufferedReader(new StringReader(file)); + } + + String data; + + while ((data = reader.readLine()) != null) + { + data = data.toUpperCase(); + + if ((data.indexOf("#") == 0) || (data.length() < 1)) + { + continue; + } + + if (data.indexOf("PILEUP") > -1) + { + reply = "PileUp"; + + break; + } + + if ((data.indexOf("//") == 0) || + ((data.indexOf("!!") > -1) && + (data.indexOf("!!") < data.indexOf( + "_MULTIPLE_ALIGNMENT ")))) + { + reply = "MSF"; + + break; + } + else if (data.indexOf("CLUSTAL") > -1) + { + reply = "CLUSTAL"; + + break; + } + else if ((data.indexOf(">P1;") > -1) || + (data.indexOf(">DL;") > -1)) + { + reply = "PIR"; + + break; + } + else if (data.indexOf(">") > -1) + { + // could be BLC file, read next line to confirm + data = reader.readLine(); + + if (data.indexOf(">") > -1 || data.indexOf("*") >-1 ) + { + reply = "BLC"; + } + else + { + reply = "FASTA"; + } + + break; + } + } + + reader.close(); } - else if(data.indexOf(">")>-1) + catch (Exception ex) { - // could be BLC file, read next line to confirm - data = reader.readLine(); - if(data.indexOf(">")>-1) - reply = "BLC"; - else - reply = "FASTA"; - - break; + System.err.println("File Identification failed!\n" + ex); + return error; } - } - reader.close(); + return reply; } - catch(Exception ex){ - System.err.println("File Identification failed!\n"+ex);} - - return reply; - } - - }