2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.datamodel;
23 public class SearchResults
29 * This method replaces the old search results which merely held an alignment
30 * index of search matches. This broke when sequences were moved around the
40 public void addResult(SequenceI seq, int start, int end)
45 { new Match(seq, start, end) };
49 int mSize = matches.length;
51 Match[] tmp = new Match[mSize + 1];
53 for (m = 0; m < mSize; m++)
58 tmp[m] = new Match(seq, start, end);
64 * Quickly check if the given sequence is referred to in the search results
67 * (specific alignment sequence or a dataset sequence)
68 * @return true if the results involve sequence
70 public boolean involvesSequence(SequenceI sequence)
72 if (matches == null || matches.length == 0)
76 SequenceI ds = sequence.getDatasetSequence();
77 for (int m = 0; m < matches.length; m++)
79 if (matches[m].sequence != null
80 && (matches[m].sequence == sequence || matches[m].sequence == ds))
89 * This Method returns the search matches which lie between the start and end
90 * points of the sequence in question. It is optimised for returning objects
91 * for drawing on SequenceCanvas
93 public int[] getResults(SequenceI sequence, int start, int end)
102 int resultLength, matchStart = 0, matchEnd = 0;
104 for (int m = 0; m < matches.length; m++)
107 if (matches[m].sequence == sequence)
110 // locate aligned position
111 matchStart = sequence.findIndex(matches[m].start) - 1;
112 matchEnd = sequence.findIndex(matches[m].end) - 1;
114 else if (matches[m].sequence == sequence.getDatasetSequence())
117 // locate region in local context
118 matchStart = sequence.findIndex(matches[m].start) - 1;
119 matchEnd = sequence.findIndex(matches[m].end) - 1;
123 if (matchStart <= end && matchEnd >= start)
125 if (matchStart < start)
138 { matchStart, matchEnd };
142 resultLength = result.length;
143 tmp = new int[resultLength + 2];
144 System.arraycopy(result, 0, tmp, 0, resultLength);
146 result[resultLength] = matchStart;
147 result[resultLength + 1] = matchEnd;
153 // System.err.println("Outwith bounds!" + matchStart+">"+end +" or "
154 // + matchEnd+"<"+start);
163 return matches == null ? 0 : matches.length;
166 public SequenceI getResultSequence(int index)
168 return matches[index].sequence;
171 public int getResultStart(int index)
173 return matches[index].start;
176 public int getResultEnd(int index)
178 return matches[index].end;
189 public Match(SequenceI seq, int start, int end)