X-Git-Url: http://source.jalview.org/gitweb/?p=jalviewjs.git;a=blobdiff_plain;f=site%2Fj2s%2Fjalview%2Fio%2FFastaFile.js;h=865ab133db81ecc006fbcc67e19ed3f7d101a764;hp=2b0172f097362afb95a75816e6135c9d8fcea7fa;hb=b9b7a352eee79b7764c3b09c9d19663075061d8c;hpb=8ffd05b3abe52c0b6b79b011c0966361f82d5fe6 diff --git a/site/j2s/jalview/io/FastaFile.js b/site/j2s/jalview/io/FastaFile.js index 2b0172f..865ab13 100644 --- a/site/j2s/jalview/io/FastaFile.js +++ b/site/j2s/jalview/io/FastaFile.js @@ -1,94 +1,94 @@ -Clazz.declarePackage ("jalview.io"); -Clazz.load (["jalview.io.AlignFile"], "jalview.io.FastaFile", ["jalview.datamodel.AlignmentAnnotation", "$.Annotation", "java.lang.StringBuffer"], function () { -c$ = Clazz.decorateAsClass (function () { -this.len = 72; -this.out = null; -Clazz.instantialize (this, arguments); -}, jalview.io, "FastaFile", jalview.io.AlignFile); -Clazz.makeConstructor (c$, -function () { -Clazz.superConstructor (this, jalview.io.FastaFile, []); -}); -Clazz.overrideMethod (c$, "parse", -function () { -var sb = new StringBuffer (); -var firstLine = true; -var line; -var uline; -var seq = null; -var annotation = false; -while ((uline = this.nextLine ()) != null) { -line = uline.trim (); -if (line.length > 0) { -if (line.charAt (0) == '>') { -if (line.startsWith (">#_")) { -if (annotation) { -this.annotations.addElement (this.makeAnnotation (seq, sb)); -}} else { -annotation = false; -}if (!firstLine) { -seq.setSequence (sb.toString ()); -if (!annotation) { -this.seqs.addElement (seq); -}}seq = this.parseId (line.substring (1)); -firstLine = false; -sb = new StringBuffer (); -if (line.startsWith (">#_")) { -annotation = true; -}} else { -sb.append (annotation ? uline : line); -}}} -if (annotation) { -this.annotations.addElement (this.makeAnnotation (seq, sb)); -} else if (!firstLine) { -seq.setSequence (sb.toString ()); -this.seqs.addElement (seq); -}}); -Clazz.defineMethod (c$, "makeAnnotation", - function (seq, sb) { -var anots = new Array (sb.length ()); -var cb; -for (var i = 0; i < anots.length; i++) { -var cn = sb.charAt (i); -if (cn != ' ') { -anots[i] = new jalview.datamodel.Annotation ("" + cn, null, ' ', NaN); -}} -var aa = new jalview.datamodel.AlignmentAnnotation (seq.getName ().substring (2), seq.getDescription (), anots); -return aa; -}, "jalview.datamodel.SequenceI,StringBuffer"); -Clazz.defineMethod (c$, "addAnnotations", -function (al) { -this.addProperties (al); -for (var i = 0; i < this.annotations.size (); i++) { -var aa = this.annotations.elementAt (i); -aa.setPadGaps (true, al.getGapCharacter ()); -al.addAnnotation (aa); -} -}, "jalview.datamodel.Alignment"); -Clazz.defineMethod (c$, "print", -function (s) { -this.out = new StringBuffer (); -var i = 0; -while ((i < s.length) && (s[i] != null)) { -this.out.append (">" + this.printId (s[i])); -if (s[i].getDescription () != null) { -this.out.append (" " + s[i].getDescription ()); -}this.out.append (this.newline); -var nochunks = (Clazz.doubleToInt (s[i].getLength () / this.len)) + 1; -for (var j = 0; j < nochunks; j++) { -var start = j * this.len; -var end = start + this.len; -if (end < s[i].getLength ()) { -this.out.append (s[i].getSequenceAsString (start, end) + this.newline); -} else if (start < s[i].getLength ()) { -this.out.append (s[i].getSequenceAsString (start, s[i].getLength ()) + this.newline); -}} -i++; -} -return this.out.toString (); -}, "~A"); -Clazz.defineMethod (c$, "print", -function () { -return this.print (this.getSeqsAsArray ()); -}); -}); +Clazz.declarePackage ("jalview.io"); +Clazz.load (["jalview.io.AlignFile"], "jalview.io.FastaFile", ["jalview.datamodel.AlignmentAnnotation", "$.Annotation", "java.lang.StringBuffer"], function () { +c$ = Clazz.decorateAsClass (function () { +this.len = 72; +this.out = null; +Clazz.instantialize (this, arguments); +}, jalview.io, "FastaFile", jalview.io.AlignFile); +Clazz.makeConstructor (c$, +function () { +Clazz.superConstructor (this, jalview.io.FastaFile, []); +}); +Clazz.overrideMethod (c$, "parse", +function () { +var sb = new StringBuffer (); +var firstLine = true; +var line; +var uline; +var seq = null; +var annotation = false; +while ((uline = this.nextLine ()) != null) { +line = uline.trim (); +if (line.length > 0) { +if (line.charAt (0) == '>') { +if (line.startsWith (">#_")) { +if (annotation) { +this.annotations.addElement (this.makeAnnotation (seq, sb)); +}} else { +annotation = false; +}if (!firstLine) { +seq.setSequence (sb.toString ()); +if (!annotation) { +this.seqs.addElement (seq); +}}seq = this.parseId (line.substring (1)); +firstLine = false; +sb = new StringBuffer (); +if (line.startsWith (">#_")) { +annotation = true; +}} else { +sb.append (annotation ? uline : line); +}}} +if (annotation) { +this.annotations.addElement (this.makeAnnotation (seq, sb)); +} else if (!firstLine) { +seq.setSequence (sb.toString ()); +this.seqs.addElement (seq); +}}); +Clazz.defineMethod (c$, "makeAnnotation", + function (seq, sb) { +var anots = new Array (sb.length ()); +var cb; +for (var i = 0; i < anots.length; i++) { +var cn = sb.charAt (i); +if (cn != ' ') { +anots[i] = new jalview.datamodel.Annotation ("" + cn, null, ' ', NaN); +}} +var aa = new jalview.datamodel.AlignmentAnnotation (seq.getName ().substring (2), seq.getDescription (), anots); +return aa; +}, "jalview.datamodel.SequenceI,StringBuffer"); +Clazz.defineMethod (c$, "addAnnotations", +function (al) { +this.addProperties (al); +for (var i = 0; i < this.annotations.size (); i++) { +var aa = this.annotations.elementAt (i); +aa.setPadGaps (true, al.getGapCharacter ()); +al.addAnnotation (aa); +} +}, "jalview.datamodel.Alignment"); +Clazz.defineMethod (c$, "print", +function (s) { +this.out = new StringBuffer (); +var i = 0; +while ((i < s.length) && (s[i] != null)) { +this.out.append (">" + this.printId (s[i])); +if (s[i].getDescription () != null) { +this.out.append (" " + s[i].getDescription ()); +}this.out.append (this.newline); +var nochunks = (Clazz.doubleToInt (s[i].getLength () / this.len)) + 1; +for (var j = 0; j < nochunks; j++) { +var start = j * this.len; +var end = start + this.len; +if (end < s[i].getLength ()) { +this.out.append (s[i].getSequenceAsString (start, end) + this.newline); +} else if (start < s[i].getLength ()) { +this.out.append (s[i].getSequenceAsString (start, s[i].getLength ()) + this.newline); +}} +i++; +} +return this.out.toString (); +}, "~A"); +Clazz.defineMethod (c$, "print", +function () { +return this.print (this.getSeqsAsArray ()); +}); +});