X-Git-Url: http://source.jalview.org/gitweb/?p=jalviewjs.git;a=blobdiff_plain;f=bin%2Fjalview%2Fanalysis%2FFinder.js;h=5d20c2ce47620c76995b42dfbacc6111355717f4;hp=cf1d8f9318072aff786a23f48d91bff1f865aae4;hb=7301a2415adab88038b291fc54caeeb3a5a47a44;hpb=6154cb57a6eac3bb1344b8342495f5bb701ee921 diff --git a/bin/jalview/analysis/Finder.js b/bin/jalview/analysis/Finder.js index cf1d8f9..5d20c2c 100644 --- a/bin/jalview/analysis/Finder.js +++ b/bin/jalview/analysis/Finder.js @@ -1,182 +1,182 @@ -Clazz.declarePackage ("jalview.analysis"); -Clazz.load (null, "jalview.analysis.Finder", ["jalview.datamodel.SearchResults", "jalview.jsdev.RegExp", "jalview.util.Comparison", "java.lang.StringBuffer", "java.util.Vector"], function () { -c$ = Clazz.decorateAsClass (function () { -this.searchResults = null; -this.alignment = null; -this.selection = null; -this.idMatch = null; -this.caseSensitive = false; -this.includeDescription = false; -this.findAll = false; -this.regex = null; -this.seqIndex = 0; -this.resIndex = -1; -Clazz.instantialize (this, arguments); -}, jalview.analysis, "Finder"); -Clazz.makeConstructor (c$, -function (alignment, selection) { -this.alignment = alignment; -this.selection = selection; -}, "jalview.datamodel.AlignmentI,jalview.datamodel.SequenceGroup"); -Clazz.makeConstructor (c$, -function (alignment, selectionGroup, seqIndex, resIndex) { -this.construct (alignment, selectionGroup); -this.seqIndex = seqIndex; -this.resIndex = resIndex; -}, "jalview.datamodel.AlignmentI,jalview.datamodel.SequenceGroup,~N,~N"); -Clazz.defineMethod (c$, "find", -function (searchString) { -var hasResults = false; -if (!this.caseSensitive) { -searchString = searchString.toUpperCase (); -}this.regex = jalview.jsdev.RegExp.newRegex ([searchString]); -this.regex.setIgnoreCase (!this.caseSensitive); -this.searchResults = new jalview.datamodel.SearchResults (); -this.idMatch = new java.util.Vector (); -var seq; -var item = null; -var found = false; -var end = this.alignment.getHeight (); -if (this.selection != null) { -if ((this.selection.getSize () < 1) || ((this.selection.getEndRes () - this.selection.getStartRes ()) < 2)) { -this.selection = null; -}}while (!found && (this.seqIndex < end)) { -seq = this.alignment.getSequenceAt (this.seqIndex); -if ((this.selection != null && this.selection.getSize () > 0) && !this.selection.getSequences (null).contains (seq)) { -this.seqIndex++; -this.resIndex = -1; -continue; -}if (this.resIndex < 0) { -this.resIndex = 0; -try { -var res = Integer.parseInt (searchString); -if (seq.getEnd () >= res) { -this.searchResults.addResult (seq, res, res); -hasResults = true; -if (!this.findAll) { -found = true; -break; -}}} catch (ex) { -if (Clazz.exceptionOf (ex, NumberFormatException)) { -} else { -throw ex; -} -} -if (this.regex.search (seq.getName ())) { -this.idMatch.addElement (seq); -hasResults = true; -if (!this.findAll) { -found = true; -break; -}}if (this.isIncludeDescription () && seq.getDescription () != null && this.regex.search (seq.getDescription ())) { -this.idMatch.addElement (seq); -hasResults = true; -if (!this.findAll) { -found = true; -break; -}}}item = seq.getSequenceAsString (); -if ((this.selection != null) && (this.selection.getEndRes () < this.alignment.getWidth () - 1)) { -item = item.substring (0, this.selection.getEndRes () + 1); -}var noGapsSB = new StringBuffer (); -var insertCount = 0; -var spaces = new java.util.Vector (); -for (var j = 0; j < item.length; j++) { -if (!jalview.util.Comparison.isGap (item.charAt (j))) { -noGapsSB.append (item.charAt (j)); -spaces.addElement ( new Integer (insertCount)); -} else { -insertCount++; -}} -var noGaps = noGapsSB.toString (); -for (var r = this.resIndex; r < noGaps.length; r++) { -if (this.regex.searchFrom (noGaps, r)) { -this.resIndex = this.regex.matchedFrom (); -if ((this.selection != null && this.selection.getSize () > 0) && ((this.resIndex + Integer.parseInt (spaces.elementAt (this.resIndex).toString ())) < this.selection.getStartRes ())) { -continue; -}var sres = seq.findPosition (this.resIndex + Integer.parseInt (spaces.elementAt (this.resIndex).toString ())); -var eres = seq.findPosition (this.regex.matchedTo () - 1 + Integer.parseInt (spaces.elementAt (this.regex.matchedTo () - 1).toString ())); -this.searchResults.addResult (seq, sres, eres); -hasResults = true; -if (!this.findAll) { -found = true; -this.resIndex++; -break; -}r = this.resIndex; -} else { -break; -}} -if (!found) { -this.seqIndex++; -this.resIndex = -1; -}} -return hasResults; -}, "~S"); -Clazz.defineMethod (c$, "getAlignment", -function () { -return this.alignment; -}); -Clazz.defineMethod (c$, "setAlignment", -function (alignment) { -this.alignment = alignment; -}, "jalview.datamodel.AlignmentI"); -Clazz.defineMethod (c$, "isCaseSensitive", -function () { -return this.caseSensitive; -}); -Clazz.defineMethod (c$, "setCaseSensitive", -function (caseSensitive) { -this.caseSensitive = caseSensitive; -}, "~B"); -Clazz.defineMethod (c$, "isFindAll", -function () { -return this.findAll; -}); -Clazz.defineMethod (c$, "setFindAll", -function (findAll) { -this.findAll = findAll; -}, "~B"); -Clazz.defineMethod (c$, "getSelection", -function () { -return this.selection; -}); -Clazz.defineMethod (c$, "setSelection", -function (selection) { -this.selection = selection; -}, "jalview.datamodel.SequenceGroup"); -Clazz.defineMethod (c$, "getIdMatch", -function () { -return this.idMatch; -}); -Clazz.defineMethod (c$, "getRegex", -function () { -return this.regex; -}); -Clazz.defineMethod (c$, "getSearchResults", -function () { -return this.searchResults; -}); -Clazz.defineMethod (c$, "getResIndex", -function () { -return this.resIndex; -}); -Clazz.defineMethod (c$, "setResIndex", -function (resIndex) { -this.resIndex = resIndex; -}, "~N"); -Clazz.defineMethod (c$, "getSeqIndex", -function () { -return this.seqIndex; -}); -Clazz.defineMethod (c$, "setSeqIndex", -function (seqIndex) { -this.seqIndex = seqIndex; -}, "~N"); -Clazz.defineMethod (c$, "isIncludeDescription", -function () { -return this.includeDescription; -}); -Clazz.defineMethod (c$, "setIncludeDescription", -function (includeDescription) { -this.includeDescription = includeDescription; -}, "~B"); -}); +Clazz.declarePackage ("jalview.analysis"); +Clazz.load (null, "jalview.analysis.Finder", ["jalview.datamodel.SearchResults", "jalview.jsdev.RegExp", "jalview.util.Comparison", "java.lang.StringBuffer", "java.util.Vector"], function () { +c$ = Clazz.decorateAsClass (function () { +this.searchResults = null; +this.alignment = null; +this.selection = null; +this.idMatch = null; +this.caseSensitive = false; +this.includeDescription = false; +this.findAll = false; +this.regex = null; +this.seqIndex = 0; +this.resIndex = -1; +Clazz.instantialize (this, arguments); +}, jalview.analysis, "Finder"); +Clazz.makeConstructor (c$, +function (alignment, selection) { +this.alignment = alignment; +this.selection = selection; +}, "jalview.datamodel.AlignmentI,jalview.datamodel.SequenceGroup"); +Clazz.makeConstructor (c$, +function (alignment, selectionGroup, seqIndex, resIndex) { +this.construct (alignment, selectionGroup); +this.seqIndex = seqIndex; +this.resIndex = resIndex; +}, "jalview.datamodel.AlignmentI,jalview.datamodel.SequenceGroup,~N,~N"); +Clazz.defineMethod (c$, "find", +function (searchString) { +var hasResults = false; +if (!this.caseSensitive) { +searchString = searchString.toUpperCase (); +}this.regex = jalview.jsdev.RegExp.newRegex ([searchString]); +this.regex.setIgnoreCase (!this.caseSensitive); +this.searchResults = new jalview.datamodel.SearchResults (); +this.idMatch = new java.util.Vector (); +var seq; +var item = null; +var found = false; +var end = this.alignment.getHeight (); +if (this.selection != null) { +if ((this.selection.getSize () < 1) || ((this.selection.getEndRes () - this.selection.getStartRes ()) < 2)) { +this.selection = null; +}}while (!found && (this.seqIndex < end)) { +seq = this.alignment.getSequenceAt (this.seqIndex); +if ((this.selection != null && this.selection.getSize () > 0) && !this.selection.getSequences (null).contains (seq)) { +this.seqIndex++; +this.resIndex = -1; +continue; +}if (this.resIndex < 0) { +this.resIndex = 0; +try { +var res = Integer.parseInt (searchString); +if (seq.getEnd () >= res) { +this.searchResults.addResult (seq, res, res); +hasResults = true; +if (!this.findAll) { +found = true; +break; +}}} catch (ex) { +if (Clazz.exceptionOf (ex, NumberFormatException)) { +} else { +throw ex; +} +} +if (this.regex.search (seq.getName ())) { +this.idMatch.addElement (seq); +hasResults = true; +if (!this.findAll) { +found = true; +break; +}}if (this.isIncludeDescription () && seq.getDescription () != null && this.regex.search (seq.getDescription ())) { +this.idMatch.addElement (seq); +hasResults = true; +if (!this.findAll) { +found = true; +break; +}}}item = seq.getSequenceAsString (); +if ((this.selection != null) && (this.selection.getEndRes () < this.alignment.getWidth () - 1)) { +item = item.substring (0, this.selection.getEndRes () + 1); +}var noGapsSB = new StringBuffer (); +var insertCount = 0; +var spaces = new java.util.Vector (); +for (var j = 0; j < item.length; j++) { +if (!jalview.util.Comparison.isGap (item.charAt (j))) { +noGapsSB.append (item.charAt (j)); +spaces.addElement ( new Integer (insertCount)); +} else { +insertCount++; +}} +var noGaps = noGapsSB.toString (); +for (var r = this.resIndex; r < noGaps.length; r++) { +if (this.regex.searchFrom (noGaps, r)) { +this.resIndex = this.regex.matchedFrom (); +if ((this.selection != null && this.selection.getSize () > 0) && ((this.resIndex + Integer.parseInt (spaces.elementAt (this.resIndex).toString ())) < this.selection.getStartRes ())) { +continue; +}var sres = seq.findPosition (this.resIndex + Integer.parseInt (spaces.elementAt (this.resIndex).toString ())); +var eres = seq.findPosition (this.regex.matchedTo () - 1 + Integer.parseInt (spaces.elementAt (this.regex.matchedTo () - 1).toString ())); +this.searchResults.addResult (seq, sres, eres); +hasResults = true; +if (!this.findAll) { +found = true; +this.resIndex++; +break; +}r = this.resIndex; +} else { +break; +}} +if (!found) { +this.seqIndex++; +this.resIndex = -1; +}} +return hasResults; +}, "~S"); +Clazz.defineMethod (c$, "getAlignment", +function () { +return this.alignment; +}); +Clazz.defineMethod (c$, "setAlignment", +function (alignment) { +this.alignment = alignment; +}, "jalview.datamodel.AlignmentI"); +Clazz.defineMethod (c$, "isCaseSensitive", +function () { +return this.caseSensitive; +}); +Clazz.defineMethod (c$, "setCaseSensitive", +function (caseSensitive) { +this.caseSensitive = caseSensitive; +}, "~B"); +Clazz.defineMethod (c$, "isFindAll", +function () { +return this.findAll; +}); +Clazz.defineMethod (c$, "setFindAll", +function (findAll) { +this.findAll = findAll; +}, "~B"); +Clazz.defineMethod (c$, "getSelection", +function () { +return this.selection; +}); +Clazz.defineMethod (c$, "setSelection", +function (selection) { +this.selection = selection; +}, "jalview.datamodel.SequenceGroup"); +Clazz.defineMethod (c$, "getIdMatch", +function () { +return this.idMatch; +}); +Clazz.defineMethod (c$, "getRegex", +function () { +return this.regex; +}); +Clazz.defineMethod (c$, "getSearchResults", +function () { +return this.searchResults; +}); +Clazz.defineMethod (c$, "getResIndex", +function () { +return this.resIndex; +}); +Clazz.defineMethod (c$, "setResIndex", +function (resIndex) { +this.resIndex = resIndex; +}, "~N"); +Clazz.defineMethod (c$, "getSeqIndex", +function () { +return this.seqIndex; +}); +Clazz.defineMethod (c$, "setSeqIndex", +function (seqIndex) { +this.seqIndex = seqIndex; +}, "~N"); +Clazz.defineMethod (c$, "isIncludeDescription", +function () { +return this.includeDescription; +}); +Clazz.defineMethod (c$, "setIncludeDescription", +function (includeDescription) { +this.includeDescription = includeDescription; +}, "~B"); +});