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