de.unibi.techfak.jpredictor.motifs
Interface MotifSearcher

All Known Subinterfaces:
MotifSearchWithError, MotifSearchWithThreshold, SequenceWindowScorer
All Known Implementing Classes:
DoubleMotif, Motif, MotifSearchAdapter, MultiMotif, PSPMotif, PSSMotif, RegularExpressionMotif, SequenceMotif

public interface MotifSearcher

This interface should be implemented by classes that wants to define methods for searching motifs. If possible, classes should extend the MotifSearchAdapter-class, where all methods except the search(int, int)-method are implemented.

See Also:
MotifSearchAdapter

Field Summary
static int SEARCH_ALL_ORIENTATIONS
          This flag is used when the motif is to search or when the motif was found.
static int SEARCH_DIRECTION_MAX
          Gives the highest free power of two.
static int SEARCH_DIRECTION_MINUS
          This flag is used when the motif is to search or when the motif was found.
static int SEARCH_DIRECTION_PLUS
          This flag is used when the motif is to search or when the motif was found.
 
Method Summary
 int getSearchMode()
          The returned bit field holds a set bit if the appropriate search mode is used or a zero otherwise.
 int initSearch(java.lang.CharSequence sequence)
          Inits the search by saving a reference on the search sequence.
 FoundMotifStruct search(int seqStart, int seqWidth)
          Runs through the sequence already given in the initialization method initSearch and matches the motif on this CharSequence with respect to the search mode and the search window determined by the two parameters seqStart and seqWidth.
 java.util.LinkedList searchAll(int seqStart, int seqWidth)
          Runs through the sequence already given in the initialization method initSearch and matches the motif on that CharSequence with respect to the search mode and the sequence window.
 void setSearchMode(int searchMode)
          Sets the mode how a motif is searched.
 

Field Detail

SEARCH_DIRECTION_PLUS

static final int SEARCH_DIRECTION_PLUS
This flag is used when the motif is to search or when the motif was found. For a 'plus' search direction, the motif must match a part of the sequence as it is.

See Also:
setSearchMode(int), getSearchMode(), Constant Field Values

SEARCH_DIRECTION_MINUS

static final int SEARCH_DIRECTION_MINUS
This flag is used when the motif is to search or when the motif was found. For a 'minus' search direction, the motif must match a part of the sequence after its order was reversed and all of the motif's characters were complemented.

See Also:
setSearchMode(int), getSearchMode(), Constant Field Values

SEARCH_ALL_ORIENTATIONS

static final int SEARCH_ALL_ORIENTATIONS
This flag is used when the motif is to search or when the motif was found. 'All orientations' mean 'plus' as well as 'minus'. This flag is the disjunction of SEARCH_DIRECTION_MINUS and SEARCH_DIRECTION_PLUS.

See Also:
setSearchMode(int), getSearchMode(), SEARCH_DIRECTION_MINUS, SEARCH_DIRECTION_PLUS, Constant Field Values

SEARCH_DIRECTION_MAX

static final int SEARCH_DIRECTION_MAX
Gives the highest free power of two. This might be importent to build the search direction flags into a bitfield. Or to comprise two or more search directions into one bit field.

See Also:
Constant Field Values
Method Detail

initSearch

int initSearch(java.lang.CharSequence sequence)
Inits the search by saving a reference on the search sequence. Also, all search states are reset, that includes the result vectors of previously done searches, which is set to null and the search window, which is set to the maximum width.

Parameters:
sequence - the sequence for all search methods to search on.
Returns:
Zero in case of no error, any other number in case of error
See Also:
search(int, int), searchAll(int, int)

search

FoundMotifStruct search(int seqStart,
                        int seqWidth)
                        throws MissingCharSequenceException,
                               MissingMotifException
Runs through the sequence already given in the initialization method initSearch and matches the motif on this CharSequence with respect to the search mode and the search window determined by the two parameters seqStart and seqWidth.
The first occurance of the motif on the sequence is returned as FoundMotifStruct with positions absolute to the sequence window. Note, that this method verifies no previous searches, instead it searches always new. If the motif was not found, null is returned.
The id of the returned struct is misused as a flag determining the search direction (search mode) the found motif was (any combination of SEARCH_DIRECTION_PLUS and SEARCH_DIRECTION_MINUS). Note, that it is possible, that a motif can occur more than once at the same position, e.g. the regular expression motif CNGCCATNDNND and its reversed complemented part HNNHNATGGCTG can both be matched on the sequence CGGCCATGGCTG. In case both search direction occur, the motif start and end position is always for plus direction. For a reversed complemented motif end is less than start.
If an error occured reading the sequence or if this method tried to read further than the sequence's size or if the motif could not be found on the sequence, null is returned.

Parameters:
seqStart - Search starts with this index.
seqWidth - The width of the subsequence to search on.
Returns:
The first occurance of the motif on the subsequence or null if the motif could not be found on the sequence.
Throws:
MissingCharSequenceException - If no sequence to search on was set.
MissingMotifException - If no motif to search for was set.
See Also:
initSearch(CharSequence), SEARCH_DIRECTION_PLUS, SEARCH_DIRECTION_MINUS

searchAll

java.util.LinkedList searchAll(int seqStart,
                               int seqWidth)
                               throws MissingCharSequenceException,
                                      MissingMotifException
Runs through the sequence already given in the initialization method initSearch and matches the motif on that CharSequence with respect to the search mode and the sequence window. A LinkedList of all occurances found is generated and returned. That list is ordered. Every element in that list is of FoundMotifStruct
A re-search on the same sequence is not performed until a different sequence window is given. If you call this method again with an overlapping search window, it trys to keep some search results from the previous saved list and to not search the whole window again.
It is recommended that the list returned is not changed. If a re-search is done on the same sequence window that changed list is returned, because a local reference to the list was saved. On the other side, one might want to take advantage from that behavior. It is possible to clear the list and then search in an overlapping window. Thus it is garantied that no result is returned twice because the method will not search the whole window again, but only the not overlapping section.

Parameters:
seqStart - Search starts with this index.
seqWidth - The width of the subsequence to search on.
Returns:
A list containing FoundMotifStruct's of all positions in the sequence' window, where the motif matches. If the motif is a MultiMotif there is one struct per whole match with the starting positions of all single motifs. The list is empty, if no match was found.
Throws:
MissingCharSequenceException - If no sequence to search on was set previously.
MissingMotifException - If no motif to search for is set.
See Also:
initSearch(CharSequence), search(int, int)

setSearchMode

void setSearchMode(int searchMode)
                   throws java.lang.IllegalArgumentException
Sets the mode how a motif is searched. Use the flags SEARCH_DIRECTION_PLUS, SEARCH_DIRECTION_MINUS or SEARCH_ALL_ORIENTATIONS as parameters.

Parameters:
searchMode - The search mode.
Throws:
java.lang.IllegalArgumentException - If searchMode is unknown.
See Also:
SEARCH_DIRECTION_PLUS, SEARCH_DIRECTION_MINUS, SEARCH_ALL_ORIENTATIONS

getSearchMode

int getSearchMode()
The returned bit field holds a set bit if the appropriate search mode is used or a zero otherwise. Known bits are SEARCH_DIRECTION_PLUS , SEARCH_DIRECTION_MINUS, or SEARCH_ALL_ORIENTATIONS. Use the IOTools.test(int,int) to test for various bits.

Returns:
Returns the search mode.
See Also:
setSearchMode(int), SEARCH_DIRECTION_PLUS, SEARCH_DIRECTION_MINUS, SEARCH_ALL_ORIENTATIONS, IOTools.test(int, int)