2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.1)
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 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/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
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 * Quickly check if the given sequence is referred to in the search results
65 * (specific alignment sequence or a dataset sequence)
66 * @return true if the results involve sequence
68 public boolean involvesSequence(SequenceI sequence)
70 if (matches == null || matches.length == 0)
74 SequenceI ds = sequence.getDatasetSequence();
75 for (int m = 0; m < matches.length; m++)
77 if (matches[m].sequence != null
78 && (matches[m].sequence == sequence || matches[m].sequence == ds))
87 * This Method returns the search matches which lie between the start and end
88 * points of the sequence in question. It is optimised for returning objects
89 * for drawing on SequenceCanvas
91 public int[] getResults(SequenceI sequence, int start, int end)
100 int resultLength, matchStart = 0, matchEnd = 0;
102 for (int m = 0; m < matches.length; m++)
105 if (matches[m].sequence == sequence)
108 // locate aligned position
109 matchStart = sequence.findIndex(matches[m].start) - 1;
110 matchEnd = sequence.findIndex(matches[m].end) - 1;
112 else if (matches[m].sequence == sequence.getDatasetSequence())
115 // locate region in local context
116 matchStart = sequence.findIndex(matches[m].start) - 1;
117 matchEnd = sequence.findIndex(matches[m].end) - 1;
121 if (matchStart <= end && matchEnd >= start)
123 if (matchStart < start)
136 { matchStart, matchEnd };
140 resultLength = result.length;
141 tmp = new int[resultLength + 2];
142 System.arraycopy(result, 0, tmp, 0, resultLength);
144 result[resultLength] = matchStart;
145 result[resultLength + 1] = matchEnd;
151 // System.err.println("Outwith bounds!" + matchStart+">"+end +" or "
152 // + matchEnd+"<"+start);
161 return matches == null ? 0 : matches.length;
164 public SequenceI getResultSequence(int index)
166 return matches[index].sequence;
169 public int getResultStart(int index)
171 return matches[index].start;
174 public int getResultEnd(int index)
176 return matches[index].end;
187 public Match(SequenceI seq, int start, int end)