1 Clazz.declarePackage ("jalview.io");
2 Clazz.load (null, "jalview.io.IdentifyFile", ["jalview.io.FileParse"], function () {
3 c$ = Clazz.declareType (jalview.io, "IdentifyFile");
4 Clazz.defineMethod (c$, "Identify",
5 function (file, protocol) {
6 var emessage = "UNIDENTIFIED FILE PARSING ERROR";
9 parser = new jalview.io.FileParse (file, protocol);
10 if (parser.isValid ()) {
11 return this.Identify (parser);
13 if (Clazz.exceptionOf (e, Exception)) {
14 System.err.println ("Error whilst identifying");
15 e.printStackTrace (System.err);
16 emessage = e.getMessage ();
22 return parser.errormessage;
25 Clazz.defineMethod (c$, "Identify",
27 return this.Identify (source, true);
28 }, "jalview.io.FileParse");
29 Clazz.defineMethod (c$, "Identify",
30 function (source, closeSource) {
34 var lineswereskipped = false;
39 }while ((data = source.nextLine ()) != null) {
40 length += data.trim ().length;
41 if (!lineswereskipped) {
42 for (var i = 0; !isBinary && i < data.length; i++) {
43 var c = data.charAt (i);
44 isBinary = (c.charCodeAt (0) < 32 && c != '\t' && c != '\n' && c != '\r' && c.charCodeAt (0) != 5 && c.charCodeAt (0) != 27);
47 if (source.inFile != null) {
48 var fileStr = source.inFile.getName ();
49 if (fileStr.lastIndexOf (".jar") > -1 || fileStr.lastIndexOf (".zip") > -1) {
51 }}if (!lineswereskipped && data.startsWith ("PK")) {
54 }}data = data.toUpperCase ();
55 if (data.startsWith ("##GFF-VERSION")) {
56 reply = "GFF v2 or v3";
58 }if (data.indexOf ("# STOCKHOLM") > -1) {
61 }if (data.matches ("<HTML(\"[^\"]*\"|'[^']*'|[^'\">])*>")) {
64 }if (data.matches ("<RNAML (\"[^\"]*\"|'[^']*'|[^'\">])*>")) {
67 }if (data.indexOf ("{\"") > -1) {
70 }if ((data.length < 1) || (data.indexOf ("#") == 0)) {
71 lineswereskipped = true;
73 }if (data.indexOf ("PILEUP") > -1) {
76 }if ((data.indexOf ("//") == 0) || ((data.indexOf ("!!") > -1) && (data.indexOf ("!!") < data.indexOf ("_MULTIPLE_ALIGNMENT ")))) {
79 } else if (data.indexOf ("CLUSTAL") > -1) {
82 } else if (data.indexOf (">") > -1) {
85 if ((data.indexOf (">P1;") > -1) || (data.indexOf (">DL;") > -1)) {
88 }data = source.nextLine ();
89 if (data.indexOf (">") > -1) {
92 var data1 = source.nextLine ();
93 var data2 = source.nextLine ();
96 starterm = (data1 != null && data1.indexOf ("*") > -1) || (data2 != null && data2.indexOf ("*") > -1);
97 }if (data2 != null && (c1 = data.indexOf ("*")) > -1) {
98 if (c1 == 0 && c1 == data2.indexOf ("*")) {
111 dta = source.nextLine ();
113 if (Clazz.exceptionOf (ex, java.io.IOException)) {
118 ;if (dta != null && dta.indexOf ("*") > -1) {
120 }} while (dta != null && !starterm);
127 } else if (data.indexOf ("HEADER") == 0 || data.indexOf ("ATOM") == 0) {
130 } else if (data.matches ("\\s*\\d+\\s+\\d+\\s*")) {
133 } else if (!lineswereskipped && data.charAt (0) != '*' && data.charAt (0) != ' ' && data.indexOf (":") < data.indexOf (",")) {
136 }lineswereskipped = true;
143 if (Clazz.exceptionOf (ex, Exception)) {
144 System.err.println ("File Identification failed!\n" + ex);
145 return source.errormessage;
151 System.err.println ("File Identification failed! - Empty file was read.");
152 return "EMPTY DATA FILE";
154 }, "jalview.io.FileParse,~B");
155 Clazz.defineStatics (c$,
156 "GFF3File", "GFF v2 or v3");