Class FilterUtils
- Since:
- 1.2
- Author:
- Matthew Pocock, Thomas Down
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclass
An implementation of FilterTransformer that attempts to transform by one transformer, and if that fails, by another.static interface
An object able to transform some FeatureFilter instances sytematically into others. -
Method Summary
Modifier and TypeMethodDescriptionstatic final FeatureFilter
all()
Return a filter which matches all features.static final FeatureFilter
and
(FeatureFilter[] filters) Constructs a new filter which matches the intersection of a set of filters.static final FeatureFilter
and
(FeatureFilter c1, FeatureFilter c2) Construct a new filter which matches the intersection of two other filters.static boolean
Determines if two queries can be proven to be disjoint.static final 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 beproven
to be a proper subset of the features matched by sup.static final FeatureFilter
byAncestor
(FeatureFilter ancestorFilter) Match features where at least one of the ancestors matches the specified filter.static final FeatureFilter
byAnnotation
(Object key, Object value) Match features where the annotation property namedkey
is equal tovalue
.static final FeatureFilter
byAnnotationType
(Object key, Class valClass) Match features where the annotation property namedkey
is an instance ofvalClass
.static final FeatureFilter
Match features with annotations matching the specifiedAnnotationType
static final FeatureFilter
byChild
(FeatureFilter childFilter) Match features where at least one child feature matches the supplied filter.static final FeatureFilter
Construct a filter which matches features which are assignable to the specified class or interface.static final FeatureFilter
byComponentName
(String compName) Construct a filter which matches all features which implement theComponentFeature
interface and have acomponentName
property equal to the specified valuestatic final FeatureFilter
byDescendant
(FeatureFilter descFilter) Match features where at least one decendant feature -- possibly but not necessarily an immediate child -- matches the specified filter.static final FeatureFilter
Construct a filter which matches FramedFeatures with the specified reading frame.static final FeatureFilter
byPairwiseScore
(double minScore, double maxScore) Match SeqSimilaritiy features with scores in the specified range.static final FeatureFilter
byParent
(FeatureFilter parentFilter) Match features where the parent feature matches the specified filter.static final FeatureFilter
bySequenceName
(String name) Match features attached to sequences with a specified name.static final FeatureFilter
Construct a filter which matches features with a specificsource
value.static final FeatureFilter
byStrand
(StrandedFeature.Strand strand) Match StrandedFeatures on the specified strand.static final FeatureFilter
Construct a filter which matches features with a specifictype
value.static final FeatureFilter
Construct a filter which matches features with locations wholly contained by the specifiedLocation
.static Location
Try to determine the minimal location which all features matching a given filter must overlap.static final FeatureFilter
hasAnnotation
(Object key) Match features where the propertykey
has been defined as having some value, regardless of the exact value.static final FeatureFilter
leaf()
Return a filter which matches features with zero children.static final FeatureFilter
none()
Return a filter which matches no features.static final FeatureFilter
not
(FeatureFilter filter) Construct a new filter which is the negation offilter
.static final FeatureFilter
onlyChildren
(FeatureFilter child) Construct a filter which matches features whose children all match the specified filter.static final FeatureFilter
onlyDescendants
(FeatureFilter desc) Construct a filter which matches features whose decendants all match the specified filter.static final FeatureFilter
optimize
(FeatureFilter filter) Attempts to reduce a FeatureFilter to an equivalent FeatureFilter with fewer terms.static final FeatureFilter
or
(FeatureFilter[] filters) Construct a new filter which matches the intersection of two filters.static final FeatureFilter
or
(FeatureFilter c1, FeatureFilter c2) Construct a new filter which matches the union of two filters.static final FeatureFilter
overlapsLocation
(Location loc) Construct a filter which matches features with locations contained by or overlapping the specifiedLocation
.static final FeatureFilter
Construct a filter which matches features with locations where the interval between themin
andmax
positions are contained by the specifiedLocation
.static final FeatureFilter
Construct a filter which matches features with locations where the interval between themin
andmax
positions are contained by or overlap the specifiedLocation
.static final FeatureFilter
topLevel()
Return a filter which matches all top-level features.static FeatureFilter
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.
-
Method Details
-
areProperSubset
Determines if the set of features matched by sub can beproven
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.
- Parameters:
sub
- the subset filtersup
- the superset filter- Returns:
true
ifsub
is a proper subset ofsup
-
areDisjoint
Determines if two queries can be proven to be disjoint.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.
- Parameters:
a
- the first FeatureFilterb
- the second FeatureFilter- Returns:
true
if they are proved to be disjoint,false
otherwise
-
extractOverlappingLocation
Try to determine the minimal location which all features matching a given filter must overlap.- Parameters:
ff
- A feature filter- Returns:
- the minimal location which any features matching
ff
must overlap, ornull
if no proof is possible (normally indicates that the filter has nothing to do with location). - Since:
- 1.2
-
areEqual
Decide if two feature filters accept exactly the same set of features.Two feature filters are equal if it can be proven that
f1.accept(feature) == f2.accept(feature)
for all values offeature
. 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.
- Parameters:
f1
- the first filterf2
- the second filter- Returns:
- true if they can be proven to be equivalent
-
byType
Construct a filter which matches features with a specifictype
value. -
bySource
Construct a filter which matches features with a specificsource
value. -
byClass
Construct a filter which matches features which are assignable to the specified class or interface.- Throws:
ClassCastException
-
containedByLocation
Construct a filter which matches features with locations wholly contained by the specifiedLocation
. -
overlapsLocation
Construct a filter which matches features with locations contained by or overlapping the specifiedLocation
. -
shadowOverlapsLocation
Construct a filter which matches features with locations where the interval between themin
andmax
positions are contained by or overlap the specifiedLocation
. -
shadowContainedByLocation
Construct a filter which matches features with locations where the interval between themin
andmax
positions are contained by the specifiedLocation
. -
bySequenceName
Match features attached to sequences with a specified name. -
not
Construct a new filter which is the negation offilter
. -
and
Construct a new filter which matches the intersection of two other filters. -
and
Constructs a new filter which matches the intersection of a set of filters. -
or
Construct a new filter which matches the union of two filters. -
or
Construct a new filter which matches the intersection of two filters. -
byAnnotationType
Match features with annotations matching the specifiedAnnotationType
-
byAnnotation
Match features where the annotation property namedkey
is equal tovalue
. -
byAnnotationType
Match features where the annotation property namedkey
is an instance ofvalClass
. -
hasAnnotation
Match features where the propertykey
has been defined as having some value, regardless of the exact value. -
byStrand
Match StrandedFeatures on the specified strand. -
byParent
Match features where the parent feature matches the specified filter. This cannot match top-level features. -
byAncestor
Match features where at least one of the ancestors matches the specified filter. This cannot match top-level features. -
byChild
Match features where at least one child feature matches the supplied filter. This does not match leafFeatures. -
byDescendant
Match features where at least one decendant feature -- possibly but not necessarily an immediate child -- matches the specified filter. -
onlyChildren
Construct a filter which matches features whose children all match the specified filter. This filter always matches leaf features. -
onlyDescendants
Construct a filter which matches features whose decendants all match the specified filter. This filter always matches leaf features. -
byFrame
Construct a filter which matches FramedFeatures with the specified reading frame. -
byPairwiseScore
Match SeqSimilaritiy features with scores in the specified range. -
byComponentName
Construct a filter which matches all features which implement theComponentFeature
interface and have acomponentName
property equal to the specified value -
topLevel
Return a filter which matches all top-level features. These are features which are direct children of aSequence
rather than anotherFeature
. -
leaf
Return a filter which matches features with zero children. -
all
Return a filter which matches all features. -
none
Return a filter which matches no features. -
optimize
Attempts to reduce a FeatureFilter to an equivalent FeatureFilter with fewer terms.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.- Parameters:
filter
- the FeatureFilter to optimize- Returns:
- an optimized version
-
transformFilter
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.
- Parameters:
ff
- the FeatureFilter to transformtrans
- a FilterTransformer encapsulating rules about how to transform filters
-
visitFilter
Applies a visitor to a filter, and returns the visitor's result or null.- Parameters:
filter
- the filter to scanvisitor
- the visitor to scan with- Returns:
- the result of the visitor or null
- Throws:
BioException
- if the required walker could not be created
-