2 * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
3 * Copyright (C) 2009 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);
61 * Quickly check if the given sequence is referred to in the search results
62 * @param sequence (specific alignment sequence or a dataset sequence)
63 * @return true if the results involve sequence
65 public boolean involvesSequence(SequenceI sequence)
67 if (matches==null || matches.length==0)
71 SequenceI ds = sequence.getDatasetSequence();
72 for (int m=0; m<matches.length; m++)
74 if (matches[m].sequence!=null &&
75 (matches[m].sequence==sequence
76 || matches[m].sequence==ds))
84 * This Method returns the search matches which lie between the start and end
85 * points of the sequence in question. It is optimised for returning objects
86 * for drawing on SequenceCanvas
88 public int[] getResults(SequenceI sequence, int start, int end)
97 int resultLength, matchStart = 0, matchEnd = 0;
99 for (int m = 0; m < matches.length; m++)
102 if (matches[m].sequence == sequence)
105 // locate aligned position
106 matchStart = sequence.findIndex(matches[m].start) - 1;
107 matchEnd = sequence.findIndex(matches[m].end) - 1;
109 else if (matches[m].sequence == sequence.getDatasetSequence())
112 // locate region in local context
113 matchStart = sequence.findIndex(matches[m].start) - 1;
114 matchEnd = sequence.findIndex(matches[m].end) - 1;
118 if (matchStart <= end && matchEnd >= start)
120 if (matchStart < start)
133 { matchStart, matchEnd };
137 resultLength = result.length;
138 tmp = new int[resultLength + 2];
139 System.arraycopy(result, 0, tmp, 0, resultLength);
141 result[resultLength] = matchStart;
142 result[resultLength + 1] = matchEnd;
152 return matches == null ? 0 : matches.length;
155 public SequenceI getResultSequence(int index)
157 return matches[index].sequence;
160 public int getResultStart(int index)
162 return matches[index].start;
165 public int getResultEnd(int index)
167 return matches[index].end;
178 public Match(SequenceI seq, int start, int end)