1 Clazz.declarePackage ("jalview.analysis");
2 Clazz.load (null, "jalview.analysis.Finder", ["jalview.datamodel.SearchResults", "jalview.jsdev.RegExp", "jalview.util.Comparison", "java.lang.StringBuffer", "java.util.Vector"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.searchResults = null;
8 this.caseSensitive = false;
9 this.includeDescription = false;
14 Clazz.instantialize (this, arguments);
15 }, jalview.analysis, "Finder");
16 Clazz.makeConstructor (c$,
17 function (alignment, selection) {
18 this.alignment = alignment;
19 this.selection = selection;
20 }, "jalview.datamodel.AlignmentI,jalview.datamodel.SequenceGroup");
21 Clazz.makeConstructor (c$,
22 function (alignment, selectionGroup, seqIndex, resIndex) {
23 this.construct (alignment, selectionGroup);
24 this.seqIndex = seqIndex;
25 this.resIndex = resIndex;
26 }, "jalview.datamodel.AlignmentI,jalview.datamodel.SequenceGroup,~N,~N");
27 Clazz.defineMethod (c$, "find",
28 function (searchString) {
29 var hasResults = false;
30 if (!this.caseSensitive) {
31 searchString = searchString.toUpperCase ();
32 }this.regex = jalview.jsdev.RegExp.newRegex ([searchString]);
33 this.regex.setIgnoreCase (!this.caseSensitive);
34 this.searchResults = new jalview.datamodel.SearchResults ();
35 this.idMatch = new java.util.Vector ();
39 var end = this.alignment.getHeight ();
40 if (this.selection != null) {
41 if ((this.selection.getSize () < 1) || ((this.selection.getEndRes () - this.selection.getStartRes ()) < 2)) {
42 this.selection = null;
43 }}while (!found && (this.seqIndex < end)) {
44 seq = this.alignment.getSequenceAt (this.seqIndex);
45 if ((this.selection != null && this.selection.getSize () > 0) && !this.selection.getSequences (null).contains (seq)) {
49 }if (this.resIndex < 0) {
52 var res = Integer.parseInt (searchString);
53 if (seq.getEnd () >= res) {
54 this.searchResults.addResult (seq, res, res);
60 if (Clazz.exceptionOf (ex, NumberFormatException)) {
65 if (this.regex.search (seq.getName ())) {
66 this.idMatch.addElement (seq);
71 }}if (this.isIncludeDescription () && seq.getDescription () != null && this.regex.search (seq.getDescription ())) {
72 this.idMatch.addElement (seq);
77 }}}item = seq.getSequenceAsString ();
78 if ((this.selection != null) && (this.selection.getEndRes () < this.alignment.getWidth () - 1)) {
79 item = item.substring (0, this.selection.getEndRes () + 1);
80 }var noGapsSB = new StringBuffer ();
82 var spaces = new java.util.Vector ();
83 for (var j = 0; j < item.length; j++) {
84 if (!jalview.util.Comparison.isGap (item.charAt (j))) {
85 noGapsSB.append (item.charAt (j));
86 spaces.addElement ( new Integer (insertCount));
90 var noGaps = noGapsSB.toString ();
91 for (var r = this.resIndex; r < noGaps.length; r++) {
92 if (this.regex.searchFrom (noGaps, r)) {
93 this.resIndex = this.regex.matchedFrom ();
94 if ((this.selection != null && this.selection.getSize () > 0) && ((this.resIndex + Integer.parseInt (spaces.elementAt (this.resIndex).toString ())) < this.selection.getStartRes ())) {
96 }var sres = seq.findPosition (this.resIndex + Integer.parseInt (spaces.elementAt (this.resIndex).toString ()));
97 var eres = seq.findPosition (this.regex.matchedTo () - 1 + Integer.parseInt (spaces.elementAt (this.regex.matchedTo () - 1).toString ()));
98 this.searchResults.addResult (seq, sres, eres);
114 Clazz.defineMethod (c$, "getAlignment",
116 return this.alignment;
118 Clazz.defineMethod (c$, "setAlignment",
119 function (alignment) {
120 this.alignment = alignment;
121 }, "jalview.datamodel.AlignmentI");
122 Clazz.defineMethod (c$, "isCaseSensitive",
124 return this.caseSensitive;
126 Clazz.defineMethod (c$, "setCaseSensitive",
127 function (caseSensitive) {
128 this.caseSensitive = caseSensitive;
130 Clazz.defineMethod (c$, "isFindAll",
134 Clazz.defineMethod (c$, "setFindAll",
136 this.findAll = findAll;
138 Clazz.defineMethod (c$, "getSelection",
140 return this.selection;
142 Clazz.defineMethod (c$, "setSelection",
143 function (selection) {
144 this.selection = selection;
145 }, "jalview.datamodel.SequenceGroup");
146 Clazz.defineMethod (c$, "getIdMatch",
150 Clazz.defineMethod (c$, "getRegex",
154 Clazz.defineMethod (c$, "getSearchResults",
156 return this.searchResults;
158 Clazz.defineMethod (c$, "getResIndex",
160 return this.resIndex;
162 Clazz.defineMethod (c$, "setResIndex",
163 function (resIndex) {
164 this.resIndex = resIndex;
166 Clazz.defineMethod (c$, "getSeqIndex",
168 return this.seqIndex;
170 Clazz.defineMethod (c$, "setSeqIndex",
171 function (seqIndex) {
172 this.seqIndex = seqIndex;
174 Clazz.defineMethod (c$, "isIncludeDescription",
176 return this.includeDescription;
178 Clazz.defineMethod (c$, "setIncludeDescription",
179 function (includeDescription) {
180 this.includeDescription = includeDescription;