public class FilterUtils extends Object
Modifier and Type | Class and Description |
---|---|
class |
FilterUtils.DelegatingTransformer
An implementation of FilterTransformer that attempts to transform by one transformer,
and if that fails, by another.
|
static interface |
FilterUtils.FilterTransformer
An object able to transform some FeatureFilter instances sytematically into others.
|
Modifier and Type | Method and Description |
---|---|
static FeatureFilter |
all()
Return a filter which matches all features.
|
static FeatureFilter |
and(FeatureFilter[] filters)
Constructs a new filter which matches the intersection of a set of filters.
|
static FeatureFilter |
and(FeatureFilter c1,
FeatureFilter c2)
Construct a new filter which matches the intersection of two other
filters.
|
static boolean |
areDisjoint(FeatureFilter a,
FeatureFilter b)
Determines if two queries can be proven to be disjoint.
|
static boolean |
areEqual(FeatureFilter f1,
FeatureFilter f2)
Decide if two feature filters accept exactly the same set of features.
|
static boolean |
areProperSubset(FeatureFilter sub,
FeatureFilter sup)
Determines if the set of features matched by sub can be
proven to be a
proper subset of the features matched by sup. |
static FeatureFilter |
byAncestor(FeatureFilter ancestorFilter)
Match features where at least one of the ancestors matches the specified
filter.
|
static FeatureFilter |
byAnnotation(Object key,
Object value)
Match features where the annotation property named
key is
equal to value . |
static FeatureFilter |
byAnnotationType(AnnotationType type)
Match features with annotations matching the specified
AnnotationType |
static FeatureFilter |
byAnnotationType(Object key,
Class valClass)
Match features where the annotation property named
key is
an instance of valClass . |
static FeatureFilter |
byChild(FeatureFilter childFilter)
Match features where at least one child feature matches the supplied filter.
|
static FeatureFilter |
byClass(Class clazz)
Construct a filter which matches features which are assignable to the
specified class or interface.
|
static FeatureFilter |
byComponentName(String compName)
Construct a filter which matches all features which implement the
ComponentFeature interface and have a componentName
property equal to the specified value |
static FeatureFilter |
byDescendant(FeatureFilter descFilter)
Match features where at least one decendant feature -- possibly but not necessarily an
immediate child -- matches the specified filter.
|
static FeatureFilter |
byFrame(FramedFeature.ReadingFrame frame)
Construct a filter which matches FramedFeatures with the specified reading
frame.
|
static FeatureFilter |
byPairwiseScore(double minScore,
double maxScore)
Match SeqSimilaritiy features with scores in the specified range.
|
static FeatureFilter |
byParent(FeatureFilter parentFilter)
Match features where the parent feature matches the specified filter.
|
static FeatureFilter |
bySequenceName(String name)
Match features attached to sequences with a specified name.
|
static FeatureFilter |
bySource(String source)
Construct a filter which matches features with a specific
source
value. |
static FeatureFilter |
byStrand(StrandedFeature.Strand strand)
Match StrandedFeatures on the specified strand.
|
static FeatureFilter |
byType(String type)
Construct a filter which matches features with a specific
type
value. |
static FeatureFilter |
containedByLocation(Location loc)
Construct a filter which matches features with locations wholly contained
by the specified
Location . |
static Location |
extractOverlappingLocation(FeatureFilter ff)
Try to determine the minimal location which all features matching a given
filter must overlap.
|
static FeatureFilter |
hasAnnotation(Object key)
Match features where the property
key has been defined as having
some value, regardless of the exact value. |
static FeatureFilter |
leaf()
Return a filter which matches features with zero children.
|
static FeatureFilter |
none()
Return a filter which matches no features.
|
static FeatureFilter |
not(FeatureFilter filter)
Construct a new filter which is the negation of
filter . |
static FeatureFilter |
onlyChildren(FeatureFilter child)
Construct a filter which matches features whose children all match the
specified filter.
|
static FeatureFilter |
onlyDescendants(FeatureFilter desc)
Construct a filter which matches features whose decendants all match the
specified filter.
|
static FeatureFilter |
optimize(FeatureFilter filter)
Attempts to reduce a FeatureFilter to an equivalent FeatureFilter with
fewer terms.
|
static FeatureFilter |
or(FeatureFilter[] filters)
Construct a new filter which matches the intersection of two filters.
|
static FeatureFilter |
or(FeatureFilter c1,
FeatureFilter c2)
Construct a new filter which matches the union of two filters.
|
static FeatureFilter |
overlapsLocation(Location loc)
Construct a filter which matches features with locations contained by or
overlapping the specified
Location . |
static FeatureFilter |
shadowContainedByLocation(Location loc)
Construct a filter which matches features with locations where the interval
between the
min and max positions are contained by
the specified Location . |
static FeatureFilter |
shadowOverlapsLocation(Location loc)
Construct a filter which matches features with locations where the interval
between the
min and max positions are contained by or
overlap the specified Location . |
static FeatureFilter |
topLevel()
Return a filter which matches all top-level features.
|
static FeatureFilter |
transformFilter(FeatureFilter ff,
FilterUtils.FilterTransformer trans)
This is a general framework method for transforming one filter into another.
|
static Object |
visitFilter(FeatureFilter filter,
Visitor visitor)
Applies a visitor to a filter, and returns the visitor's result or null.
|
public static boolean areProperSubset(FeatureFilter sub, FeatureFilter sup)
proven
to be a
proper subset of the features matched by sup.
If the filter sub matches only features that are matched by sup, then it is a proper subset. It is still a proper subset if it does not match every feature in sup, as long as no feature matches sub that is rejected by sup.
sub
- the subset filtersup
- the superset filtertrue
if sub
is a proper subset of sup
public static boolean areDisjoint(FeatureFilter a, FeatureFilter b)
They are disjoint if there is no element that is matched by both filters - that is, they have an empty intersection. Order of arguments to this method is not significant.
a
- the first FeatureFilterb
- the second FeatureFiltertrue
if they are proved to be disjoint, false
otherwisepublic static Location extractOverlappingLocation(FeatureFilter ff)
ff
- A feature filterff
must overlap, or null
if no proof is possible
(normally indicates that the filter has nothing to do with
location).public static final boolean areEqual(FeatureFilter f1, FeatureFilter f2)
Two feature filters are equal if it can be proven that
f1.accept(feature) == f2.accept(feature)
for all values of
feature
. If areEqual returns false, this may indicate that
they accept clearly different sets of features. It may also, howerver,
indicate that the method was unable to prove that they were equal.
Note that given a finite set of features, f1 and f2 may match the same sub-set of those features even if they are not equal.
f1
- the first filterf2
- the second filterpublic static final FeatureFilter byType(String type)
type
value.public static final FeatureFilter bySource(String source)
source
value.public static final FeatureFilter byClass(Class clazz) throws ClassCastException
ClassCastException
public static final FeatureFilter containedByLocation(Location loc)
Location
.public static final FeatureFilter overlapsLocation(Location loc)
Location
.public static final FeatureFilter shadowOverlapsLocation(Location loc)
min
and max
positions are contained by or
overlap the specified Location
.public static final FeatureFilter shadowContainedByLocation(Location loc)
min
and max
positions are contained by
the specified Location
.public static final FeatureFilter bySequenceName(String name)
public static final FeatureFilter not(FeatureFilter filter)
filter
.public static final FeatureFilter and(FeatureFilter c1, FeatureFilter c2)
public static final FeatureFilter and(FeatureFilter[] filters)
public static final FeatureFilter or(FeatureFilter c1, FeatureFilter c2)
public static final FeatureFilter or(FeatureFilter[] filters)
public static final FeatureFilter byAnnotationType(AnnotationType type)
AnnotationType
public static final FeatureFilter byAnnotation(Object key, Object value)
key
is
equal to value
.public static final FeatureFilter byAnnotationType(Object key, Class valClass)
key
is
an instance of valClass
.public static final FeatureFilter hasAnnotation(Object key)
key
has been defined as having
some value, regardless of the exact value.public static final FeatureFilter byStrand(StrandedFeature.Strand strand)
public static final FeatureFilter byParent(FeatureFilter parentFilter)
public static final FeatureFilter byAncestor(FeatureFilter ancestorFilter)
public static final FeatureFilter byChild(FeatureFilter childFilter)
public static final FeatureFilter byDescendant(FeatureFilter descFilter)
public static final FeatureFilter onlyChildren(FeatureFilter child)
public static final FeatureFilter onlyDescendants(FeatureFilter desc)
public static final FeatureFilter byFrame(FramedFeature.ReadingFrame frame)
public static final FeatureFilter byPairwiseScore(double minScore, double maxScore)
public static final FeatureFilter byComponentName(String compName)
ComponentFeature
interface and have a componentName
property equal to the specified valuepublic static final FeatureFilter topLevel()
Sequence
rather than another
Feature
.public static final FeatureFilter leaf()
public static final FeatureFilter all()
public static final FeatureFilter none()
public static final FeatureFilter optimize(FeatureFilter filter)
This will attempt to push all leaf constraints as far from the root of the filter expression as possible, in an attept to prove an empty or universal set. It will then propogate these through the logical operators in an attempt to reduce the entire expression to the empty or universal set. If filters can be combined (for example, overlapping constraints), then this will happen on the way.
The resulting filter is guaranteed to accept exactly the same set of\
features that is accepted by the argument. In particular,
areEqual(filter, optimize(filter))
is always true.
filter
- the FeatureFilter to optimizepublic static FeatureFilter transformFilter(FeatureFilter ff, FilterUtils.FilterTransformer trans)
This is a general framework method for transforming one filter into another. This method will handle the logical elements of a query (and, or, not) and delegate all the domain-specific munging to a FilterTransformer object.
The transformer could flip strands and locations of elements of a filter, add or remove attributes required in annotations, or systematically alter feature types or sources.
ff
- the FeatureFilter to transformtrans
- a FilterTransformer encapsulating rules about how to transform filterspublic static Object visitFilter(FeatureFilter filter, Visitor visitor) throws BioException
filter
- the filter to scanvisitor
- the visitor to scan withBioException
- if the required walker could not be createdCopyright © 2014 BioJava. All rights reserved.