X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FIdentifyFile.java;h=b062e5d5a13b28beb99fec562dfd43e9de0c1043;hb=838e4f91d4a53dd315640dbc9ff6ef7a815ee576;hp=aa9c354fd798c05206ed0b6059b30f9c0aabafe9;hpb=50ff87bdae1829a7a7471ec393142ae659b40a11;p=jalview.git diff --git a/src/jalview/io/IdentifyFile.java b/src/jalview/io/IdentifyFile.java index aa9c354..b062e5d 100755 --- a/src/jalview/io/IdentifyFile.java +++ b/src/jalview/io/IdentifyFile.java @@ -1,6 +1,6 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2) - * Copyright (C) 2014 The Jalview Authors + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9.0b1) + * Copyright (C) 2015 The Jalview Authors * * This file is part of Jalview. * @@ -30,6 +30,8 @@ import java.io.IOException; */ public class IdentifyFile { + public static final String GFF3File = "GFF v2 or v3"; + /** * Identify a datasource's file content. * @@ -96,7 +98,7 @@ public class IdentifyFile } while ((data = source.nextLine()) != null) { - length += data.length(); + length += data.trim().length(); if (!lineswereskipped) { for (int i = 0; !isBinary && i < data.length(); i++) @@ -130,54 +132,18 @@ public class IdentifyFile } data = data.toUpperCase(); - if ((data.indexOf("# STOCKHOLM") > -1)) - { - reply = "STH"; - - break; - } - if (data.matches("<(\"[^\"]*\"|'[^']*'|[^'\">])*>")) - { - reply = HtmlFile.FILE_DESC; - break; - } - - if ((data.indexOf("<") > -1)) - { - reply = "RNAML"; - - break; - } - - if ((data.length() < 1) || (data.indexOf("#") == 0)) - { - lineswereskipped = true; - continue; - } - - if (data.indexOf("PILEUP") > -1) - { - reply = "PileUp"; - - break; - } - - if ((data.indexOf("//") == 0) - || ((data.indexOf("!!") > -1) && (data.indexOf("!!") < data - .indexOf("_MULTIPLE_ALIGNMENT ")))) + if (data.startsWith("##GFF-VERSION")) { - reply = "MSF"; - + reply = GFF3File; break; } - else if (data.indexOf("CLUSTAL") > -1) + if (data.indexOf("# STOCKHOLM") > -1) { - reply = "CLUSTAL"; - + reply = "STH"; break; } - - else if (data.indexOf(">") > -1) + // if (data.indexOf(">") > -1) + if (data.startsWith(">")) { // FASTA, PIR file or BLC file boolean checkPIR = false, starterm = false; @@ -269,6 +235,70 @@ public class IdentifyFile // read as a FASTA (probably) break; } + if ((data.indexOf("<") > -1)) // possible Markup Language data i.e HTML, + // RNAML, XML + { + boolean identified = false; + do + { + if (data.matches("<(?i)html(\"[^\"]*\"|'[^']*'|[^'\">])*>")) + { + reply = HtmlFile.FILE_DESC; + identified = true; + break; + } + + if (data.matches("<(?i)rnaml (\"[^\"]*\"|'[^']*'|[^'\">])*>")) + { + reply = "RNAML"; + identified = true; + break; + } + } while ((data = source.nextLine()) != null); + + if (identified) + { + break; + } + if (data == null) + { + break; + } + } + + if (data.indexOf("{\"") > -1) + { + reply = JSONFile.FILE_DESC; + break; + } + if ((data.length() < 1) || (data.indexOf("#") == 0)) + { + lineswereskipped = true; + 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("HEADER") == 0 || data.indexOf("ATOM") == 0) { reply = "PDB"; @@ -280,19 +310,18 @@ public class IdentifyFile break; } - /* * // TODO comment out SimpleBLAST identification for Jalview 2.4.1 else * if (!lineswereskipped && data.indexOf("BLAST")<4) { reply = * "SimpleBLAST"; break; - * + * * } // end comments for Jalview 2.4.1 */ else if (!lineswereskipped && data.charAt(0) != '*' && data.charAt(0) != ' ' && data.indexOf(":") < data.indexOf(",")) // && - // data.indexOf(",")