controller
Class DataHandler

java.lang.Object
  extended by controller.DataHandler
All Implemented Interfaces:
IDataHandler

public class DataHandler
extends java.lang.Object
implements IDataHandler

Title: Bioinformatics Project

Description: Genomes Comparacent

Copyright: Copyright (c) 2005-2006

DataHandler is the controller of the system. DataHandler holds the data view, which events it handles, and an interface of the database, which it manipulates.

Version:
1.0
Author:
Shadi Ibrahem.

Field Summary
(package private)  java.util.LinkedList genomeArray
          A List containing genomes-objects (which contains genome information).
private  boolean isComplex
          True if the language encoding is Right-to-Left
private  java.util.ResourceBundle message
          The Bundle which translates keys into strings of the chosen language.
private  IDataManager model_
          The database - model
private  DataView view_
          The data view
 
Constructor Summary
DataHandler(IDataManager dm, java.lang.String[] args)
          Creates a controller of the model and the view, it creats the view and takes the model as a parameter.
 
Method Summary
 long checkField(java.lang.String str, org.eclipse.swt.widgets.Shell shell)
          Returns true if the given string includes only numbers
 boolean checkPath(java.lang.String text)
          Returns true if the given path is legal and does exist.
 void CopyFile(java.lang.String file1, java.lang.String file2)
          Copy file given by the path "from" to the file given by path "to"
 java.lang.String CreateDir(java.lang.String dir, java.lang.String Gen1, java.lang.String Gen2, java.lang.String phase)
          Creates a new history directory containing the mapping/preprocessing results.
 void deleteFileOrDirectory(java.lang.String para)
          Deletes a file or a Directory recursively.
 void deleteRowsinTable(SWTTable HistoryTable, int[] selectedIndices, java.lang.String chosenDir, java.lang.String ChosenPart)
          Deletes Rows from given table which indices are in selectedIndices.
 void deleteRowsinTable(SWTTable historyTable, int itemCount, java.lang.String chosenDir, java.lang.String ChosenPart)
          Deletes ALL Rows from given table.
 org.eclipse.swt.widgets.Display getDisplay()
          Returns view display, for asynchronious execution of runnables that updates the shell.
private  Genome getGenome(java.lang.String SymbolName)
          Returns the genome object containing information about the genome that its short name is given.
 long getGenomeLength(java.lang.String gen1)
          Lookup given genome by symbolic name and returns it length.
 java.lang.String getGenomeName(java.lang.String SymbolName)
          Finds genome by symbolic (short) name and returns it full name.
 java.lang.String[] getGenomeNames()
          Returns an array containing genomes full names.
 java.lang.String getGenomeProp(java.lang.String gen)
          Returns the genome "prop" file path.
 java.lang.String getGenomeSymbolName(java.lang.String RealName)
          Finds genome by real (Full) name and returns it symbolic name.
 java.lang.String getInputDirectory()
          Returns the input directory.
 java.lang.String[] getMapParameters(SWTTable table1, SWTTable table2, SWTTable table3)
          Put the parameters taken from the mapping parameters table into an array of strings.
 java.util.ResourceBundle getMessageLang()
          Returns the message bundle.
private  java.lang.String getNum(java.lang.String str)
          Removes the last char' of a string value of a number if it's not digit.
private  java.lang.String getNumber(java.lang.String text)
          Cuts the tail of a string which contains charactars other than digits, for extracting the only number.
 java.lang.String getOutputDirectory()
          Returns the output directory.
 void getParametersINI(java.lang.String para, SWTTable[] table)
          Loads parameters from a settings.ini file into given array of tables.
 java.lang.String[] getPreParameters(SWTTable table1, SWTTable table2, SWTTable table3)
          Put the parameters taken from the pre-processing parameters table into an array of strings.
 java.lang.String getProcessState(java.lang.String string)
          Returns a number between 0-100 from the trace file.
private  long getRowsNumber(java.io.FileReader fr)
          Returns number of rows in a file.
 int getSelectedLang()
          Returns the index of the chosen language.
 java.util.Vector getVectorFromFile(java.lang.String file, long length, long length2, boolean HEADLINE)
          The Method take a file path as a parameter passes it to the model throught the data IDataManager interface.
 boolean isComplex()
          Returns true if the language encoding is Right-to-left.
 java.lang.String ReadLine(java.io.FileReader fileR, char[] c)
          Reads a line from the file.
 void removeGenome(java.lang.String name)
          Removes a genome input directory.
 int runMappingProcess(java.lang.String dir, java.lang.String gen1, java.lang.String gen2, java.lang.String out, java.lang.String g1prop, java.lang.String g2prop, java.lang.String[] prm)
          Runs the mapping process.
 void runPreProcessing(java.lang.String gen1, java.lang.String gen2, java.lang.String outDir, java.lang.String[] str, boolean mapping, GRunTab parent, java.lang.String MapoutDir, java.lang.String[] strM)
          Runs the pre-processing phase in a NEW PROCESS outside of VM.
 void setGenomes(java.lang.String OrgDir)
          Sets the controller genome array with genome information taken from the files in the directory
 void setLanguage(int selectionIndex)
          Sets Language according to and index.
 void setMessageLang()
          Sets the language from the view/database.
 void setParametersINI(java.lang.String OutputIni, SWTTable[] table)
          Stores parameters in a settings.ini file (taken from given array of tables).
 void setView(DataView view)
          Sets the controller reference to the logical view.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

genomeArray

java.util.LinkedList genomeArray
A List containing genomes-objects (which contains genome information).


model_

private IDataManager model_
The database - model


view_

private DataView view_
The data view


message

private java.util.ResourceBundle message
The Bundle which translates keys into strings of the chosen language.


isComplex

private boolean isComplex
True if the language encoding is Right-to-Left

Constructor Detail

DataHandler

public DataHandler(IDataManager dm,
                   java.lang.String[] args)
Creates a controller of the model and the view, it creats the view and takes the model as a parameter.

Parameters:
dm - IDataManager: the model's inteface.
args - String[] user's run-time arguments.
Method Detail

getVectorFromFile

public java.util.Vector getVectorFromFile(java.lang.String file,
                                          long length,
                                          long length2,
                                          boolean HEADLINE)
Description copied from interface: IDataHandler
The Method take a file path as a parameter passes it to the model throught the data IDataManager interface.

Specified by:
getVectorFromFile in interface IDataHandler
Parameters:
file - String the output file path.
length - long second genome length.
length2 - long first genome length.
Returns:
Vector of lines with includes the Genomes coordinates

runMappingProcess

public int runMappingProcess(java.lang.String dir,
                             java.lang.String gen1,
                             java.lang.String gen2,
                             java.lang.String out,
                             java.lang.String g1prop,
                             java.lang.String g2prop,
                             java.lang.String[] prm)
Description copied from interface: IDataHandler
Runs the mapping process.

Specified by:
runMappingProcess in interface IDataHandler
Parameters:
dir - String : the directory including the pre-processing output.
gen1 - String : 1st genome name.
gen2 - String : 2nd genome name.
out - String : the directory that will include the mappping output.
g1prop - String : 1st genome prop file.
g2prop - String : 2nd genome prop file.
prm - String[] : The mapping parameters.
Returns:
int: a number indicating the errors in mapping in case they happen.

runPreProcessing

public void runPreProcessing(java.lang.String gen1,
                             java.lang.String gen2,
                             java.lang.String outDir,
                             java.lang.String[] str,
                             boolean mapping,
                             GRunTab parent,
                             java.lang.String MapoutDir,
                             java.lang.String[] strM)
                      throws java.io.FileNotFoundException
Description copied from interface: IDataHandler
Runs the pre-processing phase in a NEW PROCESS outside of VM.

Specified by:
runPreProcessing in interface IDataHandler
Parameters:
gen1 - String: 1st genome full name.
gen2 - String: 2nd genome full name.
outDir - String: the pre-processing output directory.
str - String[]: pre-processing parameters.
mapping - boolean: indicating if it should run the pre
parent - GRunTab: refernece to the view component that invoked pre-processing.
MapoutDir - String: mapping output directory.
strM - String[]: mapping parameters.
Throws:
java.io.FileNotFoundException

getRowsNumber

private long getRowsNumber(java.io.FileReader fr)
Returns number of rows in a file.

Parameters:
fr - FileReader: opened file.
Returns:
number of rows in a file.

setView

public void setView(DataView view)
Description copied from interface: IDataHandler
Sets the controller reference to the logical view.

Specified by:
setView in interface IDataHandler
Parameters:
view - DataView : MAGIC logical view object.

deleteRowsinTable

public void deleteRowsinTable(SWTTable HistoryTable,
                              int[] selectedIndices,
                              java.lang.String chosenDir,
                              java.lang.String ChosenPart)
                       throws java.io.IOException
Description copied from interface: IDataHandler
Deletes Rows from given table which indices are in selectedIndices. Chosen Part/Dir are to indicate if its the mapping history table or the pre processing table.

Specified by:
deleteRowsinTable in interface IDataHandler
Parameters:
HistoryTable - SWTTable :given table.
selectedIndices - int[] :and array of integer which contain the indices.
chosenDir - String : the dirctory which includes the history that will removed. (PreOutput/MapoutPut).
ChosenPart - String: "MAP"/"PRE" to determine how to find the related histoy.
Throws:
java.io.IOException

deleteRowsinTable

public void deleteRowsinTable(SWTTable historyTable,
                              int itemCount,
                              java.lang.String chosenDir,
                              java.lang.String ChosenPart)
                       throws java.io.IOException
Description copied from interface: IDataHandler
Deletes ALL Rows from given table. Chosen Part/Dir are to indicate if its the mapping history table or the pre processing table.

Specified by:
deleteRowsinTable in interface IDataHandler
Parameters:
historyTable - SWTTable :given table.
itemCount - int: the number of rows in the given table.
chosenDir - String : the dirctory which includes the history that will removed. (PreOutput/MapoutPut).
ChosenPart - String : "MAP"/"PRE" to determine how to find the related histoy.
Throws:
java.io.IOException

deleteFileOrDirectory

public void deleteFileOrDirectory(java.lang.String para)
                           throws java.io.IOException
Description copied from interface: IDataHandler
Deletes a file or a Directory recursively.

Specified by:
deleteFileOrDirectory in interface IDataHandler
Parameters:
para - String: the file/directory path.
Throws:
java.io.IOException - in case of deletion faliure.

checkPath

public boolean checkPath(java.lang.String text)
Description copied from interface: IDataHandler
Returns true if the given path is legal and does exist.

Specified by:
checkPath in interface IDataHandler
Parameters:
text - String: given string.
Returns:
true if the given path is legal, false otherwise.

getOutputDirectory

public java.lang.String getOutputDirectory()
Description copied from interface: IDataHandler
Returns the output directory.

Specified by:
getOutputDirectory in interface IDataHandler
Returns:
output directory.

getInputDirectory

public java.lang.String getInputDirectory()
Description copied from interface: IDataHandler
Returns the input directory.

Specified by:
getInputDirectory in interface IDataHandler
Returns:
input directory.

getParametersINI

public void getParametersINI(java.lang.String para,
                             SWTTable[] table)
Description copied from interface: IDataHandler
Loads parameters from a settings.ini file into given array of tables.

Specified by:
getParametersINI in interface IDataHandler
Parameters:
para - String: the settings.ini file path.
table - SWTTable[]: an array including 6 tables for the parameters.

ReadLine

public java.lang.String ReadLine(java.io.FileReader fileR,
                                 char[] c)
Reads a line from the file.

Parameters:
fileR - FileReader: opened file.
c - char[]: buffer.
Returns:
String.

getGenomeNames

public java.lang.String[] getGenomeNames()
Description copied from interface: IDataHandler
Returns an array containing genomes full names.

Specified by:
getGenomeNames in interface IDataHandler
Returns:
Returns an array containing genomes full names.

setGenomes

public void setGenomes(java.lang.String OrgDir)
Description copied from interface: IDataHandler
Sets the controller genome array with genome information taken from the files in the directory

Specified by:
setGenomes in interface IDataHandler
Parameters:
OrgDir - String: a dircetory including the organizims

getGenomeName

public java.lang.String getGenomeName(java.lang.String SymbolName)
Description copied from interface: IDataHandler
Finds genome by symbolic (short) name and returns it full name.

Specified by:
getGenomeName in interface IDataHandler
Parameters:
SymbolName - String: genome short name.
Returns:
Genome full name.

getGenomeSymbolName

public java.lang.String getGenomeSymbolName(java.lang.String RealName)
Description copied from interface: IDataHandler
Finds genome by real (Full) name and returns it symbolic name.

Specified by:
getGenomeSymbolName in interface IDataHandler
Parameters:
RealName - String: genome full name.
Returns:
Genome symbolic name name.

getGenome

private Genome getGenome(java.lang.String SymbolName)
Returns the genome object containing information about the genome that its short name is given.

Parameters:
SymbolName - String: genome short name.
Returns:
Genome object.

CreateDir

public java.lang.String CreateDir(java.lang.String dir,
                                  java.lang.String Gen1,
                                  java.lang.String Gen2,
                                  java.lang.String phase)
Description copied from interface: IDataHandler
Creates a new history directory containing the mapping/preprocessing results.

Specified by:
CreateDir in interface IDataHandler
Parameters:
dir - String:
Gen1 - String: 1st genome symbolic name.
Gen2 - String: 2nd genome symbolic name.
phase - String: "MAP"/"PRE".
Returns:
the new directory path.

setParametersINI

public void setParametersINI(java.lang.String OutputIni,
                             SWTTable[] table)
Description copied from interface: IDataHandler
Stores parameters in a settings.ini file (taken from given array of tables).

Specified by:
setParametersINI in interface IDataHandler
Parameters:
OutputIni - String: the settings.ini file path.
table - SWTTable[]: an array including 6 tables for the parameters.

getNum

private java.lang.String getNum(java.lang.String str)
Removes the last char' of a string value of a number if it's not digit.

Parameters:
str - String: given string value of a number.
Returns:
String value of the number without any attached char'.

getGenomeLength

public long getGenomeLength(java.lang.String gen1)
Description copied from interface: IDataHandler
Lookup given genome by symbolic name and returns it length.

Specified by:
getGenomeLength in interface IDataHandler
Parameters:
gen1 - String: genome symbolic name.
Returns:
Genome Length.

getProcessState

public java.lang.String getProcessState(java.lang.String string)
Description copied from interface: IDataHandler
Returns a number between 0-100 from the trace file.

Specified by:
getProcessState in interface IDataHandler
Parameters:
string - String: a path to a trace file.
Returns:
the read value.

setMessageLang

public void setMessageLang()
Description copied from interface: IDataHandler
Sets the language from the view/database.

Specified by:
setMessageLang in interface IDataHandler

getMessageLang

public java.util.ResourceBundle getMessageLang()
Description copied from interface: IDataHandler
Returns the message bundle.

Specified by:
getMessageLang in interface IDataHandler
Returns:
ResourceBundle.

getSelectedLang

public int getSelectedLang()
Returns the index of the chosen language.

Specified by:
getSelectedLang in interface IDataHandler
Returns:
index of the language.

setLanguage

public void setLanguage(int selectionIndex)
Description copied from interface: IDataHandler
Sets Language according to and index.

Specified by:
setLanguage in interface IDataHandler
Parameters:
selectionIndex - int: the language index.

isComplex

public boolean isComplex()
Description copied from interface: IDataHandler
Returns true if the language encoding is Right-to-left.

Specified by:
isComplex in interface IDataHandler
Returns:
true if the language encoding is Right-to-Left other wise false.

checkField

public long checkField(java.lang.String str,
                       org.eclipse.swt.widgets.Shell shell)
Description copied from interface: IDataHandler
Returns true if the given string includes only numbers

Specified by:
checkField in interface IDataHandler
Parameters:
str - String : given string.
shell - Shell : Current shell.
Returns:
true if the given string includes only numbers, false otherwise.

CopyFile

public void CopyFile(java.lang.String file1,
                     java.lang.String file2)
Description copied from interface: IDataHandler
Copy file given by the path "from" to the file given by path "to"

Specified by:
CopyFile in interface IDataHandler
Parameters:
file1 - String: source path.
file2 - String: destination path.

getGenomeProp

public java.lang.String getGenomeProp(java.lang.String gen)
Description copied from interface: IDataHandler
Returns the genome "prop" file path.

Specified by:
getGenomeProp in interface IDataHandler
Parameters:
gen - String: the genome symbolic name.
Returns:
genome prop file path.

getMapParameters

public java.lang.String[] getMapParameters(SWTTable table1,
                                           SWTTable table2,
                                           SWTTable table3)
Description copied from interface: IDataHandler
Put the parameters taken from the mapping parameters table into an array of strings.

Specified by:
getMapParameters in interface IDataHandler
Parameters:
table1 - SWTTable: 1st mapping parameters table.
table2 - SWTTable: 2nd mapping parameters table.
table3 - SWTTable: 3rd mapping parameters table.
Returns:
String[]: an array of Strings.

getNumber

private java.lang.String getNumber(java.lang.String text)
Cuts the tail of a string which contains charactars other than digits, for extracting the only number.

Parameters:
text - String: given string.
Returns:
String: including only digits.

getPreParameters

public java.lang.String[] getPreParameters(SWTTable table1,
                                           SWTTable table2,
                                           SWTTable table3)
Description copied from interface: IDataHandler
Put the parameters taken from the pre-processing parameters table into an array of strings.

Specified by:
getPreParameters in interface IDataHandler
Parameters:
table1 - SWTTable: 1st mapping parameters table.
table2 - SWTTable: 2nd mapping parameters table.
table3 - SWTTable: 3rd mapping parameters table.
Returns:
String[]: an array of Strings.

getDisplay

public org.eclipse.swt.widgets.Display getDisplay()
Description copied from interface: IDataHandler
Returns view display, for asynchronious execution of runnables that updates the shell.

Specified by:
getDisplay in interface IDataHandler
Returns:
view's display.

removeGenome

public void removeGenome(java.lang.String name)
Description copied from interface: IDataHandler
Removes a genome input directory.

Specified by:
removeGenome in interface IDataHandler
Parameters:
name - String: genome input path.