2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3 * Copyright (C) 2008 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 held an alignment
28 * index of search matches. This broke when sequences were moved around the
38 public void addResult(SequenceI seq, int start, int end)
43 { new Match(seq, start, end) };
47 int mSize = matches.length;
49 Match[] tmp = new Match[mSize + 1];
51 for (m = 0; m < mSize; m++)
56 tmp[m] = new Match(seq, start, end);
62 * This Method returns the search matches which lie between the start and end
63 * points of the sequence in question. It is optimised for returning objects
64 * for drawing on SequenceCanvas
66 public int[] getResults(SequenceI sequence, int start, int end)
75 int resultLength, matchStart = 0, matchEnd = 0;
77 for (int m = 0; m < matches.length; m++)
80 if (matches[m].sequence == sequence)
83 // locate aligned position
84 matchStart = sequence.findIndex(matches[m].start) - 1;
85 matchEnd = sequence.findIndex(matches[m].end) - 1;
87 else if (matches[m].sequence == sequence.getDatasetSequence())
90 // locate region in local context
91 matchStart = sequence.findIndex(matches[m].start) - 1;
92 matchEnd = sequence.findIndex(matches[m].end) - 1;
96 if (matchStart <= end && matchEnd >= start)
98 if (matchStart < start)
111 { matchStart, matchEnd };
115 resultLength = result.length;
116 tmp = new int[resultLength + 2];
117 System.arraycopy(result, 0, tmp, 0, resultLength);
119 result[resultLength] = matchStart;
120 result[resultLength + 1] = matchEnd;
130 return matches == null ? 0 : matches.length;
133 public SequenceI getResultSequence(int index)
135 return matches[index].sequence;
138 public int getResultStart(int index)
140 return matches[index].start;
143 public int getResultEnd(int index)
145 return matches[index].end;
156 public Match(SequenceI seq, int start, int end)