2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
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 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
18 package jalview.datamodel;
20 public class SearchResults
26 * This method replaces the old search results which merely held an alignment
27 * index of search matches. This broke when sequences were moved around the
37 public void addResult(SequenceI seq, int start, int end)
42 { new Match(seq, start, end) };
46 int mSize = matches.length;
48 Match[] tmp = new Match[mSize + 1];
50 for (m = 0; m < mSize; m++)
55 tmp[m] = new Match(seq, start, end);
61 * Quickly check if the given sequence is referred to in the search results
64 * (specific alignment sequence or a dataset sequence)
65 * @return true if the results involve sequence
67 public boolean involvesSequence(SequenceI sequence)
69 if (matches == null || matches.length == 0)
73 SequenceI ds = sequence.getDatasetSequence();
74 for (int m = 0; m < matches.length; m++)
76 if (matches[m].sequence != null
77 && (matches[m].sequence == sequence || matches[m].sequence == ds))
86 * This Method returns the search matches which lie between the start and end
87 * points of the sequence in question. It is optimised for returning objects
88 * for drawing on SequenceCanvas
90 public int[] getResults(SequenceI sequence, int start, int end)
99 int resultLength, matchStart = 0, matchEnd = 0;
101 for (int m = 0; m < matches.length; m++)
104 if (matches[m].sequence == sequence)
107 // locate aligned position
108 matchStart = sequence.findIndex(matches[m].start) - 1;
109 matchEnd = sequence.findIndex(matches[m].end) - 1;
111 else if (matches[m].sequence == sequence.getDatasetSequence())
114 // locate region in local context
115 matchStart = sequence.findIndex(matches[m].start) - 1;
116 matchEnd = sequence.findIndex(matches[m].end) - 1;
120 if (matchStart <= end && matchEnd >= start)
122 if (matchStart < start)
135 { matchStart, matchEnd };
139 resultLength = result.length;
140 tmp = new int[resultLength + 2];
141 System.arraycopy(result, 0, tmp, 0, resultLength);
143 result[resultLength] = matchStart;
144 result[resultLength + 1] = matchEnd;
150 // System.err.println("Outwith bounds!" + matchStart+">"+end +" or "
151 // + matchEnd+"<"+start);
160 return matches == null ? 0 : matches.length;
163 public SequenceI getResultSequence(int index)
165 return matches[index].sequence;
168 public int getResultStart(int index)
170 return matches[index].start;
173 public int getResultEnd(int index)
175 return matches[index].end;
186 public Match(SequenceI seq, int start, int end)