From 1ec9d94e07c346fa2094908074a1d2518861ffe3 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Sun, 30 Oct 2016 13:05:35 +0000 Subject: [PATCH] JAL-345 JAL-1738 SearchResultI method to mark columns in a bitset for highlighted regions. Needs tests (but works enough to use) --- src/jalview/datamodel/SearchResults.java | 26 ++++++++++++++++++++++++++ src/jalview/datamodel/SearchResultsI.java | 12 ++++++++++++ 2 files changed, 38 insertions(+) diff --git a/src/jalview/datamodel/SearchResults.java b/src/jalview/datamodel/SearchResults.java index 2f62991..a5bf8aa 100755 --- a/src/jalview/datamodel/SearchResults.java +++ b/src/jalview/datamodel/SearchResults.java @@ -22,6 +22,7 @@ package jalview.datamodel; import java.util.ArrayList; import java.util.Arrays; +import java.util.BitSet; import java.util.List; /** @@ -270,6 +271,31 @@ public class SearchResults implements SearchResultsI return result; } + @Override + public int markColumns(SequenceCollectionI sqcol, BitSet bs) + { + int count = 0; + for (SequenceI s : sqcol.getSequences()) + { + BitSet mask = new BitSet(); + int[] cols = getResults(s, sqcol.getStartRes(), sqcol.getEndRes()); + if (cols != null) + { + for (int pair = 0; pair < cols.length; pair += 2) + { + mask.set(cols[pair], cols[pair + 1] + 1); + } + } + // find columns that were already selected + BitSet compl = (BitSet) mask.clone(); + compl.and(bs); + count += compl.cardinality(); + // and mark ranges not already marked + bs.or(mask); + } + return count; + } + /* (non-Javadoc) * @see jalview.datamodel.SearchResultsI#getSize() */ diff --git a/src/jalview/datamodel/SearchResultsI.java b/src/jalview/datamodel/SearchResultsI.java index dc18bb8..d59f453 100644 --- a/src/jalview/datamodel/SearchResultsI.java +++ b/src/jalview/datamodel/SearchResultsI.java @@ -2,6 +2,7 @@ package jalview.datamodel; import jalview.datamodel.SearchResults.Match; +import java.util.BitSet; import java.util.List; public interface SearchResultsI @@ -79,4 +80,15 @@ public interface SearchResultsI */ public abstract List getResults(); + /** + * Set bits in a bitfield for all columns in the given sequence collection + * that are highlighted + * + * @param sqcol + * the set of sequences to search for highlighted regions + * @param bs + * bitset to set + * @return number of bits set + */ + public abstract int markColumns(SequenceCollectionI sqcol, BitSet bs); } \ No newline at end of file -- 1.7.10.2