2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 package jalview.datamodel;
21 public class SearchResults
27 * This method replaces the old search results which merely
28 * held an alignment index of search matches. This broke
29 * when sequences were moved around the alignment
34 public void addResult(SequenceI seq, int start, int end)
40 new Match(seq, start, end)};
44 int mSize = matches.length;
46 Match[] tmp = new Match[mSize + 1];
48 for (m = 0; m < mSize; m++)
53 tmp[m] = new Match(seq, start, end);
59 * This Method returns the search matches which lie between the
60 * start and end points of the sequence in question. It is
61 * optimised for returning objects for drawing on SequenceCanvas
63 public int[] getResults(SequenceI sequence, int start, int end)
72 int resultLength, matchStart=0, matchEnd=0;
74 for (int m = 0; m < matches.length; m++)
77 if (matches[m].sequence == sequence)
80 // locate aligned position
81 matchStart = sequence.findIndex(matches[m].start) - 1;
82 matchEnd = sequence.findIndex(matches[m].end) - 1;
84 else if (matches[m].sequence == sequence.getDatasetSequence()) {
86 // locate region in local context
87 matchStart = sequence.findIndex(matches[m].start) - 1;
88 matchEnd = sequence.findIndex(matches[m].end) - 1;
91 if (matchStart <= end && matchEnd >= start)
93 if (matchStart < start)
107 matchStart, matchEnd};
111 resultLength = result.length;
112 tmp = new int[resultLength + 2];
113 System.arraycopy(result, 0, tmp, 0, resultLength);
115 result[resultLength] = matchStart;
116 result[resultLength + 1] = matchEnd;
126 return matches == null ? 0 : matches.length;
129 public SequenceI getResultSequence(int index)
131 return matches[index].sequence;
134 public int getResultStart(int index)
136 return matches[index].start;
139 public int getResultEnd(int index)
141 return matches[index].end;
150 public Match(SequenceI seq, int start, int end)