|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectde.unibi.techfak.jpredictor.operator.States
de.unibi.techfak.jpredictor.operator.DefaultCommunicator
public class DefaultCommunicator
Class for controlling the functionality of motifs on sequences, for using the communicator as parameter deliverer and as output receiver.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class de.unibi.techfak.jpredictor.operator.States |
|---|
States.SequenceStore |
| Field Summary | |
|---|---|
protected int |
flag
The flag buffer. |
protected java.util.Vector |
queue
The list of result elements. |
private int |
timesThreadSlept
THIS VARIABLE MAY ONLY BE USED IN METHOD RECEIVErESULTS. |
| Fields inherited from class de.unibi.techfak.jpredictor.operator.States |
|---|
allowThreadRunning, distanceMode, err, fixedCutoff, fixedCutoffDefault, globalBackground, globalCharacterDistributionDefault, graphicalOutput, motifList, motifOccurrenceVector, out, rand, scorePlotVector, seed, sequenceLengthNormalization, sequenceLengthNormalizationDefault, sequenceStore, STORE_NEGATIVE_TRAINING_SET, STORE_POSITIVE_TRAINING_SET, STORE_SEQUENCE, ver, windowShift, windowShiftDefault, windowWidth, windowWidthDefault |
| Fields inherited from interface de.unibi.techfak.jpredictor.operator.ICommunicator |
|---|
DISTANCE_ADJACENT, DISTANCE_ADJACENT73, DISTANCE_ANYSPACE, DISTANCE_BELOW220, DISTANCE_ONETURN, DISTANCE_SINGLE, DISTANCE_TWOTURNS, FLAG_B, FLAG_F, FLAG_M, OBJECT_FASTA_MODIFIER, OBJECT_FILENAME, OBJECT_FILENAME_FASTA, OBJECT_NOTYPE, OBJECT_READER, OBJECT_READER_FASTA, OBJECT_SEQUENCE, OBJECT_STRING, OBJECT_STRING_FASTA |
| Constructor Summary | |
|---|---|
DefaultCommunicator()
|
|
| Method Summary | |
|---|---|
void |
allowRunning()
Sets a flag that signals all running threads started by the operator that they are allowed to run. |
java.io.PrintStream |
err()
Returns the output stream to which error messages should be sent. |
boolean |
flag(int flags)
Using this method you can test various settings, whether they occured or not. |
double |
getCutoff()
Gets the cutoff. |
java.lang.String |
getDistanceMode()
Gets the previously set distance mode. |
double[] |
getGlobalBackground()
Gives the background distribution over a character set. |
boolean |
getGraphicalOutput()
|
MotifList |
getMotifList()
Gets the previoulsy set MotifList. |
java.util.Vector |
getMotifOccurrenceVector()
If the graphical output is activated, the operator stores information of found motifs in this vector. |
java.lang.Object |
getNegativeTrainingSequence()
Gets the sequence object meant as negative training set. |
int |
getNegativeTrainingSequenceType()
|
java.lang.Object |
getNextResult()
The user interface requests for the next results. |
java.lang.Object |
getPositiveTrainingSequence()
Gets the sequence object meant as positive training set. |
int |
getPositiveTrainingSequenceType()
|
java.util.Vector |
getScorePlotVector()
If the graphical output is activated, the operator stores information for the score plot in this vector. |
long |
getSeed()
The seed, the random number generator was initialized with is returned. |
java.lang.Object |
getSequence()
Gets the sequence object. |
SequenceEnumeration |
getSequenceEnumeration(java.lang.Object o,
int type)
Checks for the type and builds a SequenceEnumerator
from the object given. |
boolean |
getSequenceLengthNormalization()
|
int |
getSequenceType()
|
int |
getSequenceWindowShift()
|
int |
getSequenceWindowWidth()
|
boolean |
hasNextResult()
The user interface asks whether the result queue has elements to fetch. |
boolean |
isRunningAllowed()
Returns the flag for search and score threads of the operator whether they are allow to proceed or must stop on next occasion. |
java.io.PrintStream |
out()
Returns the output stream to which normal output should be sent. |
boolean |
outputForScoreSequence(IOperator op,
boolean best)
Scores sequences using weighted motifs and generates and prints the appropriate output. |
boolean |
outputForSearchMotifs(IOperator op,
boolean count)
Searches motifs on sequences and generates and prints the appropriate output. |
boolean |
outputForWeightMotifs(IOperator op)
Weights motifs and generates and prints the appropriate output. |
java.util.Random |
rand()
Returns the random number generator which is initialized when the communicator object was created. |
double |
random()
Returns a double random number generated with the intern random number generator. |
int |
receiveResults(java.lang.Object o)
The communicator receives the next result, which is to be stored in a queue-like structure until the user interface requests for the next result by calling getNextResult(). |
void |
setCutoff(double cutoff)
Sets a cutoff. |
boolean |
setDistanceMode(java.lang.String distance)
Sets the distance mode. |
void |
setErrorStream(java.io.PrintStream ps)
This method sets a PrintStream as new error message
output stream. |
void |
setGlobalBackground(double[] newBackground)
Sets the new character occurrence distribution. |
void |
setGraphicalOutput(boolean graphout)
The graphical output is activated or deactivated. |
void |
setMotifList(MotifList ml)
Sets a MotifList. |
void |
setNegativeTrainingSequence(java.lang.Object sequ,
int type)
Sets a sequence object (CharSequence, filename or stream) meant as negative training set. |
void |
setOutputStream(java.io.PrintStream ps)
This method sets a PrintStream as new output stream. |
void |
setPositiveTrainingSequence(java.lang.Object sequ,
int type)
Sets a sequence object (CharSequence, filename or stream) meant as positive training set. |
void |
setSeed(long seed)
Sets a new seed for the random number generator. |
void |
setSequence(java.lang.Object sequ,
int type)
Sets a sequence ( CharSequence, filename or stream) to
perform searching and scoring on. |
void |
setSequenceLengthNormalization(boolean norm)
Sets, whether the occurrences on the positive and negativ training set, respectively, are normalized by the sequence length of the set. |
void |
setSequenceWindowShift(int shift)
Sets the sequence window's shift. |
void |
setSequenceWindowWidth(int width)
Sets the sequence window width. |
void |
setVerboseStream(java.io.PrintStream ps)
This method sets a PrintStream as new verbose message
output stream. |
void |
stopRunning()
Sets a flag that signals all running threads started by the operator to stop as soon as possible. |
protected void |
testForSequenceClass(java.lang.Object sequ,
int type)
Tests for the type of the object, whether it is equal to the type type says. |
java.io.PrintStream |
ver()
Returns the output stream to which verbose messages should be sent. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected java.util.Vector queue
receiveResults to store the results and by the method
getNextResult the deliver the results to the user
interface on request. Note, that if it is overwritten, it must
be a synchronized object.
ICommunicator.receiveResults(Object),
ICommunicator.getNextResult()private int timesThreadSlept
OutOfMemoryError occurs in the method
receiveResults the calling thread is sent to sleep for a short
while to ensure that the wrapping thread empties the queue.
protected int flag
| Constructor Detail |
|---|
public DefaultCommunicator()
| Method Detail |
|---|
protected void testForSequenceClass(java.lang.Object sequ,
int type)
throws java.lang.IllegalArgumentException
type says. Valid values for type are
OBJECT_FILENAME, OBJECT_READER or
OBJECT_SEQUENCE. As filename sequ must be
a string, as reader it must be any Reader and as
sequence it must be either a sequences.Sequence or a
sequences.MappedCharSequence.
sequ - The sequence object.type - The type of the sequence object.
java.lang.IllegalArgumentException - If type does
not correctly specify the type of the object.
public SequenceEnumeration getSequenceEnumeration(java.lang.Object o,
int type)
ICommunicatorSequenceEnumerator
from the object given. Example call: getSequenceEnumeration(
ICommunicator.getSequence(), ICommunicator.getSequenceType()).
getSequenceEnumeration in interface ICommunicatoro - The sequence (CharSequence, Reader or Sequence).type - The type of sequence, get it from the ICommunicator.
null in case of any error, otherwise an
enumerator over all possible sequences.SequenceEnumerator,
SequenceEnumeration
public void setSequence(java.lang.Object sequ,
int type)
throws java.lang.IllegalArgumentException
ICommunicatorCharSequence, filename or stream) to
perform searching and scoring on. Valid values for type
are the OBJECT_-variables of this class. Recommended to
give are either a filename or a Sequence-Object.
FLAG_F is set. But if you give
null as the object's value, any previously set sequence
and the FLAG_F are cleared.
setSequence in interface ICommunicatorsequ - The sequence object, either a String, a
Reader or a Sequence from package
sequences.type - The type definition for the object.
java.lang.IllegalArgumentException - If the object's type is
inequal to what type suggests.ICommunicator.FLAG_F,
ICommunicator.OBJECT_FILENAME,
ICommunicator.OBJECT_FILENAME_FASTA,
ICommunicator.OBJECT_NOTYPE,
ICommunicator.OBJECT_READER,
ICommunicator.OBJECT_READER_FASTA,
ICommunicator.OBJECT_SEQUENCE,
ICommunicator.OBJECT_STRING,
ICommunicator.OBJECT_STRING_FASTApublic java.lang.Object getSequence()
ICommunicator
getSequence in interface ICommunicatornull if it was not set.ICommunicator.setSequence(Object, int),
ICommunicator.getSequenceEnumeration(Object, int)public int getSequenceType()
getSequenceType in interface ICommunicatorOBJECT_NOTYPE
if it was not set.ICommunicator.setSequence(Object, int),
ICommunicator.getSequenceEnumeration(Object, int)
public void setPositiveTrainingSequence(java.lang.Object sequ,
int type)
throws java.lang.IllegalArgumentException
ICommunicatorsetSequence(Object, int) for the parameter's meaning.
FLAG_M is set. But if you give
null as the object's value, any previously set sequence
and the FLAG_M is cleared.
setPositiveTrainingSequence in interface ICommunicatorsequ - The sequence object.type - The type definition for the object.
java.lang.IllegalArgumentException - If the object's type is inequal to
what type suggests.ICommunicator.FLAG_M,
ICommunicator.setSequence(Object, int),
ICommunicator.getSequenceEnumeration(Object, int)public java.lang.Object getPositiveTrainingSequence()
ICommunicator
getPositiveTrainingSequence in interface ICommunicatornull if it was not set.ICommunicator.setPositiveTrainingSequence(Object, int),
ICommunicator.getSequenceEnumeration(Object, int)public int getPositiveTrainingSequenceType()
getPositiveTrainingSequenceType in interface ICommunicatorOBJECT_NOTYPE if it was not set.ICommunicator.setPositiveTrainingSequence(Object, int),
ICommunicator.getSequenceEnumeration(Object, int)
public void setNegativeTrainingSequence(java.lang.Object sequ,
int type)
throws java.lang.IllegalArgumentException
ICommunicatorsetSequence(Object, int) for the parameter's meaning.
FLAG_B is set. But if you give
null as the object's value, any previously set sequence
and the FLAG_B is cleared.
setNegativeTrainingSequence in interface ICommunicatorsequ - The sequence object.type - The type definition for the object.
java.lang.IllegalArgumentException - If the object's type is inequal
to what type suggests.ICommunicator.FLAG_B,
ICommunicator.setSequence(Object, int),
ICommunicator.getSequenceEnumeration(Object, int)public java.lang.Object getNegativeTrainingSequence()
ICommunicator
getNegativeTrainingSequence in interface ICommunicatornull if it was not set.ICommunicator.setNegativeTrainingSequence(Object, int),
ICommunicator.getSequenceEnumeration(Object, int)public int getNegativeTrainingSequenceType()
getNegativeTrainingSequenceType in interface ICommunicatorOBJECT_NOTYPE if it was not set.ICommunicator.setNegativeTrainingSequence(Object, int),
ICommunicator.getSequenceEnumeration(Object, int)public void setSequenceWindowWidth(int width)
ICommunicator
setSequenceWindowWidth in interface ICommunicatorwidth - The width of the sequence window.public int getSequenceWindowWidth()
getSequenceWindowWidth in interface ICommunicatorICommunicator.setSequenceWindowWidth(int)public void setSequenceWindowShift(int shift)
ICommunicator
setSequenceWindowShift in interface ICommunicatorshift - The number of characters the sequence window is shifted
by.public int getSequenceWindowShift()
getSequenceWindowShift in interface ICommunicatorICommunicator.setSequenceWindowShift(int)public void setMotifList(MotifList ml)
ICommunicatorMotifList. The motifs in the list are searched
on a sequence and using the occurrences the motifs are weigthed or
the sequence is scored.
setMotifList in interface ICommunicatorml - A list of motifs as MotifList.public MotifList getMotifList()
ICommunicatorMotifList.
getMotifList in interface ICommunicatornull, if no
MotifList was set before.ICommunicator.setMotifList(MotifList)public void setCutoff(double cutoff)
ICommunicatorcutoff. This value is used when a sequence is
scored. If not Double.NaN is set as cutoff the scores
are comprised to bands, for which the score is higher than the
cutoff. Otherwise, for every sequence window the scores are output.
setCutoff in interface ICommunicatorcutoff - The new cutoff or Double.NaN to
switch comprising off.States.fixedCutoffDefaultpublic double getCutoff()
ICommunicatorDouble.isNaN(cutoff)==true)
or off.
getCutoff in interface ICommunicatorICommunicator.setCutoff(double)
public void setGlobalBackground(double[] newBackground)
throws java.lang.NullPointerException,
java.lang.IllegalArgumentException
ICommunicatorSets the new character occurrence distribution. For every assumed character a probability has to be given, which represents the occurrence frequency of that character in a sequence.
The given double array is cloned, and the cloned version is recalculated such that all values sum up to one (normalization). Thus, the given background is not changed in any way.
setGlobalBackground in interface ICommunicatornewBackground - The new background character distribution.
Note, that it must not be null nor empty.
java.lang.NullPointerException - If the given background is
null.
java.lang.IllegalArgumentException - If the given background is empty
or if at least one value is less than zero or if the sum over all
probabilities (or counts) is zero.public double[] getGlobalBackground()
ICommunicator
getGlobalBackground in interface ICommunicatorICommunicator.setGlobalBackground(double[])
public int receiveResults(java.lang.Object o)
throws java.lang.IllegalStateException
ICommunicatorgetNextResult().
receiveResults in interface ICommunicatoro - This object is to be stored as part of the result stream.
java.lang.IllegalStateException - If the communicator was unable
to store the object for any reason.ICommunicator.getNextResult()
public java.lang.Object getNextResult()
throws java.lang.IllegalStateException
ICommunicatorIOperator for
a notion on what the Objects might be.
getNextResult in interface ICommunicatornull if no
results are available in the queue.
java.lang.IllegalStateException - If the communicator was unable
to read an object for any reason.ICommunicator.hasNextResult(),
IOperator.searchMotifs(boolean),
IOperator.weightMotifs(),
IOperator.scoreSequence()public boolean hasNextResult()
ICommunicatorfalse, a
consecutive call to getNextResult() might return
other than null because the task-performing thread may
have send a result in the meanwhile. What can be assured of is, that
in case of a returned true a call to
getNextResult() will not return null.
hasNextResult in interface ICommunicatortrue if a result is in the queue and
can be fetched by calling getNextresult(),
false if actually no result is in the queue.ICommunicator.getNextResult()public void setSequenceLengthNormalization(boolean norm)
ICommunicator
setSequenceLengthNormalization in interface ICommunicatornorm - true if normalization should be done,
false otherwise.public boolean getSequenceLengthNormalization()
getSequenceLengthNormalization in interface ICommunicatortrue, if normalization is wished,
false otherwise.ICommunicator.setSequenceLengthNormalization(boolean)public boolean setDistanceMode(java.lang.String distance)
ICommunicator
setDistanceMode in interface ICommunicatordistance - The distance mode as String.
true, if the distance mode could be recognized,
false otherwise. If the distance mode was not recognized,
it is not set.public java.lang.String getDistanceMode()
ICommunicator
getDistanceMode in interface ICommunicatorString.ICommunicator.setDistanceMode(String)public boolean flag(int flags)
ICommunicatorICommunicator.flag( FLAG_B | FLAG_M ) would return
true.
flag in interface ICommunicatorflags - The flag or flags to be tested.
true, if at least one flag is set,
false otherwise.public void allowRunning()
ICommunicator
allowRunning in interface ICommunicatorpublic void stopRunning()
ICommunicator
stopRunning in interface ICommunicatorpublic boolean isRunningAllowed()
ICommunicator
isRunningAllowed in interface ICommunicatortrue, if the threads are allowed to run,
false if they must stop as soon as possible.public void setOutputStream(java.io.PrintStream ps)
ICommunicatorPrintStream as new output stream.
For common access to that stream use the method out().
If ps=null the NilOutputStream is set.
setOutputStream in interface ICommunicatorps - The new stream for directing the output to it.ICommunicator.out(),
NilOutputStreampublic void setErrorStream(java.io.PrintStream ps)
ICommunicatorPrintStream as new error message
output stream.
For common access to that stream use the method err().
If ps=null the NilOutputStream is set.
setErrorStream in interface ICommunicatorps - The new stream for directing the output to it.ICommunicator.err(),
NilOutputStreampublic void setVerboseStream(java.io.PrintStream ps)
ICommunicatorPrintStream as new verbose message
output stream.
For common access to that stream use the method ver().
If ps=null the NilOutputStream is set.
setVerboseStream in interface ICommunicatorps - The new stream for directing the output to it.ICommunicator.ver(),
NilOutputStreampublic java.io.PrintStream out()
ICommunicatorSystem.out.
out in interface ICommunicatorICommunicator.setOutputStream(PrintStream)public java.io.PrintStream err()
ICommunicatorSystem.err as default.
err in interface ICommunicatorICommunicator.setErrorStream(PrintStream)public java.io.PrintStream ver()
ICommunicatorNilOutputStream as default.
ver in interface ICommunicatorICommunicator.setVerboseStream(PrintStream),
NilOutputStream
public boolean outputForSearchMotifs(IOperator op,
boolean count)
ICommunicator
Searches motifs on sequences and generates and prints the appropriate
output. This method uses the given IOperator to start
the searchMotifs(boolean)-method, which will get its
necessary informations from the ICommunicator the given
operator was created with and the parameter count.
The output created and send to comm.out() is the
following. First all motif names are printed, followed by a line
with '//'. Every next line holds one sequence name followed by
the number of occurrences of each motif on that sequence. if
count is true, then the sequence' name is printed
and then for any sequence section the motif's name with its
occurrences within this section.
At the beginning and at the end, some messages are created for
the verbose stream comm.ver(). This messages contains
the time this output method has waited for the thread to finish.
Also an error message is sent to comm.err() if the
thread could not be started.
outputForSearchMotifs in interface ICommunicatorop - The IOperator to start the method
searchMotifs(boolean) from.count - The method searchMotifs(boolean) get
this value as parameter and it is also used to slightly change the
output sent to comm.out().
false if an error occured and no motifs
were searched, true otherwise.IOperator.searchMotifs(boolean)public boolean outputForWeightMotifs(IOperator op)
ICommunicator
Weights motifs and generates and prints the appropriate output.
This method uses the given IOperator to call the
weightMotifs()-method, which will get its necessary
informations from the ICommunicator the given operator
was created with.
The output created and sent to comm.out() is the
following. First two matrices are output, one for the positive
training set named 'Raw model fingerprints' and one for the
negative training set named 'Raw background fingerprints'.
Every line (row) stands for a sequence from the corresponding
training set. Within the rows the values (column) correspond
with the motifs and give the occurrences. After both matrices a
block named 'Scores:' follows holding within every line the
motifs name and its calculated weight/score.
At the beginning and at the end, some messages are created for
the verbose stream comm.ver(). This messages contains
the time this output method has waited for the thread to finish.
Also an error message is sent to comm.err() if the
thread could not be started.
outputForWeightMotifs in interface ICommunicatorop - The IOperator to start the method
weightMotifs() from.
false if an error occured and no motif
was weighted, true otherwise.IOperator.weightMotifs()
public boolean outputForScoreSequence(IOperator op,
boolean best)
ICommunicator
Scores sequences using weighted motifs and generates and prints the
appropriate output. This method uses the given IOperator
to start the scoreSequence()-method, which will get its
necessary informations from the ICommunicator the given
operator was created with.
For every sequence scored the sequence name in FASTA format is output.
For the sequence window scores itself their are two possible output
mechanisms. If a cutoff other than Double.NaN was set
with the given ICommunicator, the scores are comprised
to bands where each band is maximal in width, does not overlap with
other bands and has scores above the cutoff. For each found band
the output is sequenceCounter: start-end: maximumScore;
minimumScore; meanScore, e.g. 0:700210-701040: 191.3644;
126.2205; 173.7372. If no cutoff was set in the given
ICommunicator or if Double.NaN was set,
each line of the output contains the middle position of a sequence
window together with its score.
At the beginning and at the end, some messages are created for
the verbose stream comm.ver(). This messages contains
the time this output method has waited for the thread to finish.
Also an error message is sent to comm.err() if the
thread could not be started.
outputForScoreSequence in interface ICommunicatorop - The IOperator to start the method
weightMotifs() from.best - If true, only the best score for every sequence is
output. Cannot be mixed with a comprised output.
false if an error occured and no sequence
was scored, true otherwise.IOperator.scoreSequence()public void setGraphicalOutput(boolean graphout)
ICommunicator
The graphical output is activated or deactivated. If it is activated,
the result data are stored in several vectors, e.g. the one to hold
score plot data can be obtained by calling
getScorePlotVector.
What is stored in the respective vector relies on the methods of the
operator filling it. Every call to this method sets back all vectors,
either to the empty state, if the graphical output is activated or to
null in case of deactivation.
setGraphicalOutput in interface ICommunicatorgraphout - If true, the graphical output will be
activated, otherwise deactivated.ICommunicator.getScorePlotVector(),
ICommunicator.getMotifOccurrenceVector()public boolean getGraphicalOutput()
getGraphicalOutput in interface ICommunicatortrue if the graphical output is wished,
false otherwise.ICommunicator.setGraphicalOutput(boolean)public java.util.Vector getScorePlotVector()
ICommunicatorIf the graphical output is activated, the operator stores
information for the score plot in this vector. For every score
on the sequence a Integer for the index and a
Double for the score is stored. If the operator
ends the scoring a -1 is stored.
getScorePlotVector in interface ICommunicatorVector containing score plot data. Ends
with a -1.ICommunicator.setGraphicalOutput(boolean),
ScoredSequenceStructpublic java.util.Vector getMotifOccurrenceVector()
ICommunicatorIf the graphical output is activated, the operator stores
information of found motifs in this vector. For every motif
found an Integer for the index of the motif in the
motif list and an Integer for its position on the
sequence (negativ for rev/comp) is stored.
getMotifOccurrenceVector in interface ICommunicatorVector containing data about found motifs.ICommunicator.setGraphicalOutput(boolean),
FoundMotifStructpublic java.util.Random rand()
ICommunicator
rand in interface ICommunicatorjava.util.Random.public double random()
ICommunicator
random in interface ICommunicatorpublic void setSeed(long seed)
ICommunicator
setSeed in interface ICommunicatorRandompublic long getSeed()
ICommunicator
getSeed in interface ICommunicator
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||