JAL-1807 test
[jalviewjs.git] / bin / jalview / io / PIRFile.js
1 Clazz.declarePackage ("jalview.io");
2 Clazz.load (["jalview.io.AlignFile", "java.util.Vector"], "jalview.io.PIRFile", ["jalview.io.ModellerDescription", "jalview.util.Comparison", "java.lang.StringBuffer"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.words = null;
5 Clazz.instantialize (this, arguments);
6 }, jalview.io, "PIRFile", jalview.io.AlignFile);
7 Clazz.prepareFields (c$, function () {
8 this.words =  new java.util.Vector ();
9 });
10 Clazz.makeConstructor (c$, 
11 function () {
12 Clazz.superConstructor (this, jalview.io.PIRFile, []);
13 });
14 Clazz.overrideMethod (c$, "parse", 
15 function () {
16 var sequence;
17 var line = null;
18 var md;
19 while ((line = this.nextLine ()) != null) {
20 if (line.length == 0) {
21 continue;
22 }if (line.indexOf ("C;") == 0 || line.indexOf ("#") == 0) {
23 continue;
24 }var newSeq = this.parseId (line.substring (line.indexOf (";") + 1));
25 sequence =  new StringBuffer ();
26 newSeq.setDescription (this.nextLine ());
27 var starFound = false;
28 while (!starFound) {
29 line = this.nextLine ();
30 sequence.append (line);
31 if (line == null) {
32 break;
33 }if (line.indexOf ("*") > -1) {
34 starFound = true;
35 }}
36 if (sequence.length () > 0) {
37 sequence.setLength (sequence.length () - 1);
38 newSeq.setSequence (sequence.toString ());
39 this.seqs.addElement (newSeq);
40 md =  new jalview.io.ModellerDescription (newSeq.getDescription ());
41 md.updateSequenceI (newSeq);
42 }}
43 });
44 Clazz.defineMethod (c$, "print", 
45 function () {
46 return this.print (this.getSeqsAsArray ());
47 });
48 Clazz.defineMethod (c$, "print", 
49 function (s) {
50 var is_NA = jalview.util.Comparison.isNucleotide (s);
51 var len = 72;
52 var out =  new StringBuffer ();
53 var i = 0;
54 var md;
55 while ((i < s.length) && (s[i] != null)) {
56 var seq = s[i].getSequenceAsString ();
57 seq = seq + "*";
58 if (is_NA) {
59 out.append (">N1;" + s[i].getName ());
60 out.append (this.newline);
61 if (s[i].getDescription () == null) {
62 out.append (s[i].getName () + " " + (s[i].getEnd () - s[i].getStart () + 1));
63 out.append (is_NA ? " bases" : " residues");
64 out.append (this.newline);
65 } else {
66 out.append (s[i].getDescription ());
67 out.append (this.newline);
68 }} else {
69 if (jalview.io.PIRFile.useModellerOutput) {
70 out.append (">P1;" + s[i].getName ());
71 out.append (this.newline);
72 md =  new jalview.io.ModellerDescription (s[i]);
73 out.append (md.getDescriptionLine ());
74 out.append (this.newline);
75 } else {
76 out.append (">P1;" + this.printId (s[i]));
77 out.append (this.newline);
78 if (s[i].getDescription () != null) {
79 out.append (s[i].getDescription ());
80 out.append (this.newline);
81 } else {
82 out.append (s[i].getName () + " " + (s[i].getEnd () - s[i].getStart () + 1) + " residues");
83 out.append (this.newline);
84 }}}var nochunks = (Clazz.doubleToInt (seq.length / len)) + 1;
85 for (var j = 0; j < nochunks; j++) {
86 var start = j * len;
87 var end = start + len;
88 if (end < seq.length) {
89 out.append (seq.substring (start, end));
90 out.append (this.newline);
91 } else if (start < seq.length) {
92 out.append (seq.substring (start));
93 out.append (this.newline);
94 }}
95 i++;
96 }
97 return out.toString ();
98 }, "~A");
99 Clazz.defineStatics (c$,
100 "useModellerOutput", false);
101 });