X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fanalysis%2FFinder.java;h=41d3185f1899a94ade34b309589e9729b67f14d2;hb=153dd62dc91da13ae732600e6ea55ddbe15eab39;hp=9f813b51cb7e1b8c9fd5157f6d5ca6ab9da6162c;hpb=4f3aa2d5b87614be76e66ab42f525b439378b850;p=jalview.git diff --git a/src/jalview/analysis/Finder.java b/src/jalview/analysis/Finder.java index 9f813b5..41d3185 100644 --- a/src/jalview/analysis/Finder.java +++ b/src/jalview/analysis/Finder.java @@ -1,20 +1,19 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4) - * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6) + * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. + * This file is part of Jalview. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with Jalview. If not, see . */ package jalview.analysis; @@ -44,7 +43,7 @@ public class Finder /** * hold's last-searched position between calles to find(false) */ - int seqIndex = 0, resIndex = 0; + int seqIndex = 0, resIndex = -1; public Finder(AlignmentI alignment, SequenceGroup selection) { @@ -52,6 +51,15 @@ public class Finder this.selection = selection; } + /** + * restart search at given sequence and residue on alignment and (optionally) + * contained in selection + * + * @param alignment + * @param selectionGroup + * @param seqIndex + * @param resIndex + */ public Finder(AlignmentI alignment, SequenceGroup selectionGroup, int seqIndex, int resIndex) { @@ -68,6 +76,7 @@ public class Finder searchString = searchString.toUpperCase(); } regex = new com.stevesoft.pat.Regex(searchString); + regex.setIgnoreCase(!caseSensitive); searchResults = new SearchResults(); idMatch = new Vector(); Sequence seq; @@ -111,18 +120,30 @@ public class Finder { seq = (Sequence) alignment.getSequenceAt(seqIndex); - if ((selection != null && selection.getSize()>0) + if ((selection != null && selection.getSize() > 0) && !selection.getSequences(null).contains(seq)) { seqIndex++; - resIndex = 0; + resIndex = -1; continue; } - + if (resIndex < 0) + { + resIndex = 0; + if (regex.search(seq.getName())) + { + idMatch.addElement(seq); + hasResults = true; + if (!findAll) + { + // stop and return the match + found = true; + break; + } + } + } item = seq.getSequenceAsString(); - if (!caseSensitive) - item = item.toUpperCase(); if ((selection != null) && (selection.getEndRes() < alignment.getWidth() - 1)) @@ -157,7 +178,7 @@ public class Finder { resIndex = regex.matchedFrom(); - if ((selection != null && selection.getSize()>0) + if ((selection != null && selection.getSize() > 0) && ((resIndex + Integer.parseInt(spaces.elementAt( resIndex).toString())) < selection.getStartRes())) { @@ -195,18 +216,16 @@ public class Finder if (!found) { seqIndex++; - resIndex = 0; + resIndex = -1; } } - for (int id = 0; id < alignment.getHeight(); id++) - { - if (regex.search(alignment.getSequenceAt(id).getName())) - { - idMatch.addElement(alignment.getSequenceAt(id)); - hasResults = true; - } - } + /** + * We now search the Id string in the main search loop. for (int id = 0; id + * < alignment.getHeight(); id++) { if + * (regex.search(alignment.getSequenceAt(id).getName())) { + * idMatch.addElement(alignment.getSequenceAt(id)); hasResults = true; } } + */ return hasResults; } @@ -220,7 +239,7 @@ public class Finder /** * @param alignment - * the alignment to set + * the alignment to set */ public void setAlignment(AlignmentI alignment) { @@ -237,7 +256,7 @@ public class Finder /** * @param caseSensitive - * the caseSensitive to set + * the caseSensitive to set */ public void setCaseSensitive(boolean caseSensitive) { @@ -254,7 +273,7 @@ public class Finder /** * @param findAll - * the findAll to set + * the findAll to set */ public void setFindAll(boolean findAll) { @@ -271,7 +290,7 @@ public class Finder /** * @param selection - * the selection to set + * the selection to set */ public void setSelection(jalview.datamodel.SequenceGroup selection) { @@ -312,7 +331,7 @@ public class Finder /** * @param resIndex - * the resIndex to set + * the resIndex to set */ public void setResIndex(int resIndex) { @@ -329,7 +348,7 @@ public class Finder /** * @param seqIndex - * the seqIndex to set + * the seqIndex to set */ public void setSeqIndex(int seqIndex) {