X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FIdentifyFile.java;h=4ec5329d31aeb19b03cf136eedba5edda8262627;hb=db93a1adcbe0a4eaaf06e0a70ade0d6c5c1961c3;hp=9e2a4e695aff2c31f6463ea94b47839e8294cac7;hpb=a90e2fe3cc3b779521a81cf8de410936f3a777c1;p=jalview.git diff --git a/src/jalview/io/IdentifyFile.java b/src/jalview/io/IdentifyFile.java index 9e2a4e6..4ec5329 100755 --- a/src/jalview/io/IdentifyFile.java +++ b/src/jalview/io/IdentifyFile.java @@ -30,7 +30,7 @@ import java.io.IOException; */ public class IdentifyFile { - public static final String GFF3File = "GFF v2 or v3"; + public static final String FeaturesFile = "GFF or Jalview features"; /** * Identify a datasource's file content. @@ -44,7 +44,7 @@ public class IdentifyFile * DOCUMENT ME! * @return ID String */ - public String Identify(String file, String protocol) + public String identify(String file, String protocol) { String emessage = "UNIDENTIFIED FILE PARSING ERROR"; FileParse parser = null; @@ -53,7 +53,7 @@ public class IdentifyFile parser = new FileParse(file, protocol); if (parser.isValid()) { - return Identify(parser); + return identify(parser); } } catch (Exception e) { @@ -68,9 +68,9 @@ public class IdentifyFile return emessage; } - public String Identify(FileParse source) + public String identify(FileParse source) { - return Identify(source, true); // preserves original behaviour prior to + return identify(source, true); // preserves original behaviour prior to // version 2.3 } @@ -82,11 +82,12 @@ public class IdentifyFile * @param closeSource * @return filetype string */ - public String Identify(FileParse source, boolean closeSource) + public String identify(FileParse source, boolean closeSource) { String reply = "PFAM"; String data; - int length = 0; + int bytesRead = 0; + int trimmedLength = 0; boolean lineswereskipped = false; boolean isBinary = false; // true if length is non-zero and non-printable // characters are encountered @@ -98,7 +99,8 @@ public class IdentifyFile } while ((data = source.nextLine()) != null) { - length += data.trim().length(); + bytesRead += data.length(); + trimmedLength += data.trim().length(); if (!lineswereskipped) { for (int i = 0; !isBinary && i < data.length(); i++) @@ -134,7 +136,13 @@ public class IdentifyFile if (data.startsWith("##GFF-VERSION")) { - reply = GFF3File; + // GFF - possibly embedded in a Jalview features file! + reply = FeaturesFile; + break; + } + if (looksLikeFeatureData(data)) + { + reply = FeaturesFile; break; } if (data.indexOf("# STOCKHOLM") > -1) @@ -142,6 +150,13 @@ public class IdentifyFile reply = "STH"; break; } + if (data.indexOf("_ENTRY.ID") > -1 + || data.indexOf("_AUDIT_AUTHOR.NAME") > -1 + || data.indexOf("_ATOM_SITE.") > -1) + { + reply = "mmCIF"; + break; + } // if (data.indexOf(">") > -1) if (data.startsWith(">")) { @@ -215,7 +230,6 @@ public class IdentifyFile } catch (IOException ex) { } - ; if (dta != null && dta.indexOf("*") > -1) { starterm = true; @@ -235,33 +249,19 @@ public class IdentifyFile // read as a FASTA (probably) break; } - if ((data.indexOf("<") > -1)) // possible Markup Language data i.e HTML, - // RNAML, XML + int lessThan = data.indexOf("<"); + if ((lessThan > -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) + String upper = data.toUpperCase(); + if (upper.substring(lessThan).startsWith(" -1 + && commaPos > -1 && colonPos < commaPos; + // && data.indexOf(",")