X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fanalysis%2FFinder.java;h=41478d68c25712a0cc9cb2e9ac26bf100fed0539;hb=797df64fa2a0a30773d0f48f5494d4155e5a8be3;hp=756897c9b2fda95b4e0872dfa615790609ba32b2;hpb=506d60f0e188723ddc91c26824b41ac7034df3fe;p=jalview.git diff --git a/src/jalview/analysis/Finder.java b/src/jalview/analysis/Finder.java index 756897c..41478d6 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.7) + * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, 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,36 +76,17 @@ public class Finder searchString = searchString.toUpperCase(); } regex = new com.stevesoft.pat.Regex(searchString); + regex.setIgnoreCase(!caseSensitive); searchResults = new SearchResults(); idMatch = new Vector(); Sequence seq; String item = null; boolean found = false; + int end = alignment.getHeight(); - // //// is the searchString a residue number? - try - { - int res = Integer.parseInt(searchString); - found = true; - if (selection == null || selection.getSize() < 1) - { - seq = (Sequence) alignment.getSequenceAt(0); - } - else - { - seq = (Sequence) (selection.getSequenceAt(0)); - } - - searchResults.addResult(seq, res, res); - hasResults = true; - } catch (NumberFormatException ex) - { - } // ///////////////////////////////////////////// - int end = alignment.getHeight(); - if (selection != null) { if ((selection.getSize() < 1) @@ -110,19 +99,52 @@ public class Finder while (!found && (seqIndex < end)) { seq = (Sequence) alignment.getSequenceAt(seqIndex); - - if ((selection != null) + + if ((selection != null && selection.getSize() > 0) && !selection.getSequences(null).contains(seq)) { seqIndex++; - resIndex = 0; + resIndex = -1; continue; } + if (resIndex < 0) + { + resIndex = 0; + // test for one off matches - sequence position and sequence ID + // //// is the searchString a residue number? + try + { + int res = Integer.parseInt(searchString); + // possibly a residue number - check if valid for seq + if (seq.getEnd() >= res) + { + searchResults.addResult(seq, res, res); + hasResults = true; + //resIndex=seq.getLength(); + // seqIndex++; + if (!findAll) { + found = true; + break; + } + } + } catch (NumberFormatException ex) + { + } + 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 +179,7 @@ public class Finder { resIndex = regex.matchedFrom(); - if ((selection != null) + if ((selection != null && selection.getSize() > 0) && ((resIndex + Integer.parseInt(spaces.elementAt( resIndex).toString())) < selection.getStartRes())) { @@ -195,18 +217,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 +240,7 @@ public class Finder /** * @param alignment - * the alignment to set + * the alignment to set */ public void setAlignment(AlignmentI alignment) { @@ -237,7 +257,7 @@ public class Finder /** * @param caseSensitive - * the caseSensitive to set + * the caseSensitive to set */ public void setCaseSensitive(boolean caseSensitive) { @@ -254,7 +274,7 @@ public class Finder /** * @param findAll - * the findAll to set + * the findAll to set */ public void setFindAll(boolean findAll) { @@ -271,7 +291,7 @@ public class Finder /** * @param selection - * the selection to set + * the selection to set */ public void setSelection(jalview.datamodel.SequenceGroup selection) { @@ -312,7 +332,7 @@ public class Finder /** * @param resIndex - * the resIndex to set + * the resIndex to set */ public void setResIndex(int resIndex) { @@ -329,7 +349,7 @@ public class Finder /** * @param seqIndex - * the seqIndex to set + * the seqIndex to set */ public void setSeqIndex(int seqIndex) {