de.unibi.techfak.jpredictor.operator
Class Operator

java.lang.Object
  extended by de.unibi.techfak.jpredictor.operator.Operator
All Implemented Interfaces:
IOperator

public class Operator
extends java.lang.Object
implements IOperator

Class for controlling the functionality of motifs on sequences, for using the communicator as parameter deliverer and as output receiver.


Nested Class Summary
(package private)  class Operator.SearchThread
          Class which gets a MotifList and either a CharSequence or a SequenceReader (from which the CharSequences are obtained) and which searches the motifs in the list in all sequences by calling for every motif the searchAll-method.
 
Field Summary
(package private)  ICommunicator comm
          The communicator object this operator gets options from.
private static int METHOD_CALC
           
private static int METHOD_COUNT
           
private static int METHOD_SCORE
           
private static int METHOD_SEARCH
           
private  int[] mOcc
          The motif's occurrences are stored here.
private  java.util.Vector[] occ
          The occurrence vector, there is a vector for every motif with its occurrences.
protected  java.util.Vector seqLengths
          For every sequence processed the length is stored here as Integer.
protected  java.util.Vector seqNames
          For every sequence processed the name is stored here as Integer.
 
Constructor Summary
Operator(ICommunicator comm)
          Inits the operator and sets the communicator, from which all options and parameters come.
 
Method Summary
private  void calculateScoresResults(java.util.LinkedList[] l, int seqLength)
          Called by the search thread, when METHOD_CALC was set as methodToCall.
 long getSequenceLength(int seqNr)
          While searching or scoring the length of every searched sequence can be obtained.
 java.lang.String getSequenceName(int seqNr)
          While searching or scoring the name of every searched sequence can be obtained.
 int getSequenceNumber()
          After searching or scoring the number of sequences that has gone through can be obtained with this method.
 java.lang.String scoreSequence()
          A sequence is window-by-window scored by summing-up the motifs weigths.
private  void scoreSequenceResults(java.util.LinkedList[] l, int windowStart, int windowWidth, MotifList ml)
          Called by the search thread, when METHOD_SCORE was set as methodToCall.
 java.lang.String searchMotifs(boolean count)
          Search for motifs on a sequence.
private  void searchMotifsCount(java.util.LinkedList[] l, int windowStart, int nextWindowStart)
          Called by the search thread, when METHOD_COUNT was set as methodToCall.
private  void searchMotifsResults(java.util.LinkedList[] l, int windowStart, int nextWindowStart)
          Called by the search thread, when METHOD_SEARCH was set as methodToCall.
private  java.lang.String setSequence(java.lang.Object o, int type, Operator.SearchThread p)
          Checks the type of the sequence in comparison to the ones set in the communicator
 java.lang.String weightMotifs()
          Weight motifs by searching them on two training sets.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

comm

ICommunicator comm
The communicator object this operator gets options from.


seqLengths

protected java.util.Vector seqLengths
For every sequence processed the length is stored here as Integer. That is counted by SearchThread and used by getSequenceLength(int) and getSequenceNumber().


seqNames

protected java.util.Vector seqNames
For every sequence processed the name is stored here as Integer. That is counted by SearchThread and used by getSequenceName(int).


METHOD_SEARCH

private static final int METHOD_SEARCH
See Also:
Constant Field Values

METHOD_COUNT

private static final int METHOD_COUNT
See Also:
Constant Field Values

METHOD_CALC

private static final int METHOD_CALC
See Also:
Constant Field Values

METHOD_SCORE

private static final int METHOD_SCORE
See Also:
Constant Field Values

mOcc

private int[] mOcc
The motif's occurrences are stored here. This field is set by searchMotifs and used by searchMotifsCount.


occ

private java.util.Vector[] occ
The occurrence vector, there is a vector for every motif with its occurrences. Set by ScoreThread and used by calculateScoresResults.

Constructor Detail

Operator

public Operator(ICommunicator comm)
Inits the operator and sets the communicator, from which all options and parameters come.

Parameters:
comm - The ICommunicator needed for communication with the user interfaces.
Method Detail

getSequenceNumber

public int getSequenceNumber()
Description copied from interface: IOperator
After searching or scoring the number of sequences that has gone through can be obtained with this method.
In case of scoring it is returned the total number of sequences processed in both positive and negative training set. For instance, if you give as positive training set a fasta file with 6 sequences, and as negative training set a String, than 7 is returned.

Specified by:
getSequenceNumber in interface IOperator
Returns:
The number of sequences processed.

getSequenceLength

public long getSequenceLength(int seqNr)
Description copied from interface: IOperator
While searching or scoring the length of every searched sequence can be obtained. If seqNr is negative or greater or equal then getSequenceNumber() the total length over all sequences is calculated and returned.

Specified by:
getSequenceLength in interface IOperator
Parameters:
seqNr - The sequence thats length is of interest.
Returns:
The length of one sequence processed, or the total length of all sequences.

getSequenceName

public java.lang.String getSequenceName(int seqNr)
Description copied from interface: IOperator
While searching or scoring the name of every searched sequence can be obtained. If seqNr is negative or greater or equal then getSequenceNumber() null is returned.

Specified by:
getSequenceName in interface IOperator
Parameters:
seqNr - The sequence whos name is of interest.
Returns:
The name of a sequence processed, or null, if seqNr is out of range.

setSequence

private java.lang.String setSequence(java.lang.Object o,
                                     int type,
                                     Operator.SearchThread p)
Checks the type of the sequence in comparison to the ones set in the communicator

Parameters:
o - The sequence (CharSequence, Reader or Sequence).
type - The type of sequence.
p - The SearchThread to set the sequence to.
Returns:
null in case of no error, otherwise a String with a short explaination about the error.

searchMotifs

public java.lang.String searchMotifs(boolean count)
Description copied from interface: IOperator
Search for motifs on a sequence. Both, the MotifList and the information about the sequence are taken from the Communicator this operater was initialized with. The search is done using the sequence window that is shifted on the sequence.
The output depends on the parameter. If count=false for every occurrence one FoundMotifStruct is output, which id gives the motif's number in the list. Note, that the findings are ordered first by position and than by id. If count=true the occurrences are counted for the motifs. After every searched sequence a FoundMotifStruct is output with id=motifNumber and start[0]=occurrences. Note, that the occurrences are output in order the motifs are arranged in the motif list.
If a sequence was completely searched, a FoundMotifStruct with id=-1 and start[0]=0 is output. If the search is all done, a FoundMotifStruct with id=-1 and start[0]=-1 is output.

Specified by:
searchMotifs in interface IOperator
Parameters:
count - false if all occurrences should be sent to the communicator, true if they are counted for every motif.
Returns:
null iff the search was initiated, otherwise a String with the error number followed by a short explaination, why the search could not be started.

searchMotifsResults

private void searchMotifsResults(java.util.LinkedList[] l,
                                 int windowStart,
                                 int nextWindowStart)
Called by the search thread, when METHOD_SEARCH was set as methodToCall. Evaluates the search results and sends them to the communicator.
This method outputs all results stored in the LinkedList within the borders [windowStart,nextWindowStart[, because that results are discarded when a new search is preformed. If windowStart==-1 all results that are greater than nextWindowStart are send to the communicator due to end of sequence. If l==null the search assumed to be ready.

Parameters:
l - A LinkedList of the results as FoundMotifStruct
windowStart -
nextWindowStart -

searchMotifsCount

private void searchMotifsCount(java.util.LinkedList[] l,
                               int windowStart,
                               int nextWindowStart)
Called by the search thread, when METHOD_COUNT was set as methodToCall. Counts up for every motif the occurrences and sends them to the communicator
if windowStart == -1. If l == null the search assumed to be ready.

Parameters:
l - A LinkedList of the results as FoundMotifStruct
windowStart -
nextWindowStart -

weightMotifs

public java.lang.String weightMotifs()
Description copied from interface: IOperator
Weight motifs by searching them on two training sets. Both, the MotifList and the sequence informations are taken from the Communicator this operater was initialized with. The motifs are searched first on the sequences of the positive training set and afterwards on the sequences of the negative training sets. Both training sets are taken from the Communicator. The sequences are searched as a whole, thus windowWidth and windowShift are not needed.
This method calculates for every motif the weight from the occurrences of each motif in both training sets. Its a log odd score. The method MotifList.setScores(MotifList, Vector[], Vector[]) is taken for calculation, after a required sequence normalization is done.
The output through the previously set Communicator is the following: first, for every motif the occurrences (as Integer ) on the sequences of the positive training set is sent, followed by a -1. Second, the same for the negative training set is done. The last number sent is the return value of the method Motif.setScores(MotifList, Vector[], Vector[]), which shows whether calculation was successful or not. The motif's scores are stored in the motifs and can be read using getScore().

Specified by:
weightMotifs in interface IOperator
Returns:
null iff the calculation was initiated, otherwise a String with the error number followed by a short explaination, why the calculation could not be started.
See Also:
MotifList.setScores(Vector[], Vector[]), Motif.getWeight()

calculateScoresResults

private void calculateScoresResults(java.util.LinkedList[] l,
                                    int seqLength)
Called by the search thread, when METHOD_CALC was set as methodToCall. Evaluates the search results.
If windowStart == -1 or l == null this method returns without doing anything. This is because scoring is done on the whole sequence, thus only once.

Parameters:
l - A LinkedList of the results as FoundMotifStruct
seqLength - - The length of the processed sequence.

scoreSequence

public java.lang.String scoreSequence()
Description copied from interface: IOperator
A sequence is window-by-window scored by summing-up the motifs weigths. Both, the MotifList and the sequence information are taken from the Communicator this operater was initialized with. The sequence given can be either a file (e.g. FASTA-format) or a CharSequence. Searching is done by shifting a window of defined width on the sequence. These sequence windows are scored by summing up the weights of found motifs within the window.
For every window a ScoredSequenceStruct-object is sent to the communicator, which holds the sequence number, the start and end of the sequence and the corresponding score.
When scoring is ended, the communicator receives a ScoredSequenceStruct-object with -1 as sequence number.

Specified by:
scoreSequence in interface IOperator
Returns:
null iff scoring was initiated, otherwise a String with the error number followed by a short explaination, why the scoring could not be started.

scoreSequenceResults

private void scoreSequenceResults(java.util.LinkedList[] l,
                                  int windowStart,
                                  int windowWidth,
                                  MotifList ml)
Called by the search thread, when METHOD_SCORE was set as methodToCall. Evaluates the search results by calculating the scores for the sequence window, that are send to the communicator If windowStart == -1 the function does nothing. If l == null the search is assumed to be ready.

Parameters:
l - A array of linked lists (one for every motif), containing the search results as FoundMotifStruct
windowStart -
windowWidth -
ml -