org.peace_tools.data
Class OverlapModel

java.lang.Object
  extended by org.peace_tools.data.OverlapModel
All Implemented Interfaces:
javax.swing.ComboBoxModel, javax.swing.ListModel

public class OverlapModel
extends java.lang.Object
implements javax.swing.ComboBoxModel

A custom data model to provide pre-alignment information using MST and clustering data.

This class servers as a light weight wrapper to adapt the in-memory MST and clustering representation to be displayed in a custom view. The term "model" is being used in the context of the Model-View-Controller (MVC) pattern. The custom view provides a high-level summary information about the type of alignment that is to be expected from the clustering data. The MST and clustering data are used in the following manner:

This data model combines and provides access to the following two distinct sets of information:
  1. First it provides a list of clusters and associated coloring information for each cluster. This information is exposed via the ComboBoxModel interface.
  2. It exposes the data required to draw various EST entries in a 2-dimensional matrix kind-of a layout.


Field Summary
private  ClusterFile clusterFile
          Reference to the cluster file that contains the cluster information that was used to generate this pre-alignment model.
private  java.util.ArrayList<ClusterNode> clusterList
          This list contains the list of clusters (that may be sorted) being displayed to the user.
private  java.util.ArrayList<ESTEntry> estEntryList
          The list of EST entry objects encapsulated by this data model.
private  java.util.ArrayList<java.util.ArrayList<ESTEntry>> estEntryTable
          A table (A sparse 2-dimensional array) of ESTEntries.
private  ESTList estList
          Reference to the EST file that contains the fragment data that is to be adapted and presented by this model.
private  java.util.ArrayList<javax.swing.event.ListDataListener> listListeners
          The set of list model listeners that were added to this model.
private  int maxCol
          The widest row in the estEntryTable.
private  int selectedCluster
          Instance variable to track the currently selected/visible cluster entry in a combo box.
private  MSTClusterData wsEntry
          A handy reference to the workspace entry from which the data for this overlap model was partially obtained.
 
Constructor Summary
OverlapModel(ClusterFile clusters, ESTList ests, MSTClusterData wsEntry)
          The constructor.
 
Method Summary
 void addListDataListener(javax.swing.event.ListDataListener ldl)
          Adds a listener to be notified when the data associated with the model changes.
private  void addToESTEntryTable(int row, ESTEntry entry)
          Add an entry to the specified row in the estEntryTable.
private  void buildClusterList(ClusterFile clusterFile)
          Helper method to populate local list of clusters from a cluster file.
static OverlapModel create(ClusterFile clusters, ESTList ests, MST mst, MSTClusterData wsEntry)
          The constructor.
protected  void fireDataChanged()
          Helper method to notify listeners whenever data changes.
private static void generateClusterLookupTable(int parentClusterID, ClusterNode node, int[] clusterIDList)
          Helper method to build a table (simple array) that provides clusterID for each fragment.
private  void generateESTEntries(MSTNode parent, int startPos, int[] clusterIDList, int prevClusterID, int lastRow, java.util.ArrayList<java.lang.Long> rowUsage)
          Recursive method to generate ESTEntry objects with alignment information.
 ClusterFile getClusterFile()
          Obtain the cluster file information from where this pre-alignment model was built.
 ClusterNode getElementAt(int index)
          Obtain the cluster node in the combo box list at a given index.
 ESTList getESTList()
          Obtain the list of ESTs associated with this model.
private  int getFarthestPos(MSTNode parent)
          Helper method to determine how far-left the pre-alignment extends given the root is at logical position zero.
 int getMaxCol()
          Obtain the last column where a nucleotide is present.
 int getMaxRow()
          Determine the maximum number of rows in this overlap model.
 java.util.ArrayList<ESTEntry> getRow(int row)
          Obtain the list of EST entries on a given row in the model.
private static int getRow(int start, int end, int startRow, java.util.ArrayList<java.lang.Long> rowUsage)
          This is a helper method that is used to determine the row on which a fragment can be accommodated.
 ClusterNode getSelectedItem()
          Obtain the currently displayed cluster in the combo box.
 int getSize()
          Obtain the number of entries to be displayed in the combo box.
 MSTClusterData getWsEntry()
          Obtain the actual workspace entry whose data is contained in this model.
 void removeListDataListener(javax.swing.event.ListDataListener ldl)
          Removes a listener from the list of listeners maintained by this class.
 void setSelectedItem(java.lang.Object anItem)
          Set the selected (item being displayed) item in a combo box.
 void sort(int order)
          Method to change the order in which clusters are ordered.
private static long toLong(int hiInt, int lowInt)
          A simple helper method to combine two integers into a long.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

estList

private final ESTList estList
Reference to the EST file that contains the fragment data that is to be adapted and presented by this model. This value is set in the constructor and is never changed during the life time of this class.


clusterFile

private final ClusterFile clusterFile
Reference to the cluster file that contains the cluster information that was used to generate this pre-alignment model. This value is set in the constructor and is never changed during the life time of this object.


wsEntry

private final MSTClusterData wsEntry
A handy reference to the workspace entry from which the data for this overlap model was partially obtained. This information can be used by "view" classes to create additional views as needed.


estEntryTable

private java.util.ArrayList<java.util.ArrayList<ESTEntry>> estEntryTable
A table (A sparse 2-dimensional array) of ESTEntries. This array list is organized as a 2-dimensional array of ESTEntries. Each entry in the estEntryTable corresponds to a set of entries to be displayed as a single row. Accordingly, each row consists of a list of ESTEntries. The array is populated by the generateESTEntries(MSTNode, int, int[], int, int, ArrayList) method. Note The ESTEntry objects in each row of this table are sorted based on the starting column of each entry. This information is used by the view to optimize rendering.


maxCol

private int maxCol
The widest row in the estEntryTable. This instance variable is used to track the widest row in the estEntryTable. This value indicates the highest column where a nucleotide from some fragment needs to be rendered. This value is computed and updated each time a new entry is added to the estEntryTable.


estEntryList

private java.util.ArrayList<ESTEntry> estEntryList
The list of EST entry objects encapsulated by this data model. This list of objects is generated by the generateESTEntries method when an instance of this data model is created.

See Also:
generateESTEntries(MSTNode, int, int[], int, int, ArrayList)

clusterList

private java.util.ArrayList<ClusterNode> clusterList
This list contains the list of clusters (that may be sorted) being displayed to the user. This list is populated initially when this data model is created. After that the order of entries in this list may change whenever the list is (re)sorted.


listListeners

private java.util.ArrayList<javax.swing.event.ListDataListener> listListeners
The set of list model listeners that were added to this model. This list is used to notify listeners whenever the data in the list model has changed. The data changes whenever the user chooses to resort the list of clusters based on their cluster size.


selectedCluster

private int selectedCluster
Instance variable to track the currently selected/visible cluster entry in a combo box. This instance variable is used to implement the functionality associated with the two methods defined in the ComboBoxModel interface class.

Constructor Detail

OverlapModel

public OverlapModel(ClusterFile clusters,
                    ESTList ests,
                    MSTClusterData wsEntry)
The constructor. The constructor merely initializes the necessary data members in this data model.

Parameters:
clusters - The set of clusters to be displayed by this class.
ests - The set of ESTs that contain information about each EST in the clusters.
wsEntry - The clustering data work space entry from where the overlap view was launched.
Method Detail

create

public static OverlapModel create(ClusterFile clusters,
                                  ESTList ests,
                                  MST mst,
                                  MSTClusterData wsEntry)
The constructor. The constructor merely initializes the necessary data members in this data model.

Parameters:
clusters - The set of clusters to be displayed by this class.
ests - The set of ESTs that contain information about each EST in the clusters.
wsEntry - The clustering data work space entry from where the overlap view was launched.

getSelectedItem

public ClusterNode getSelectedItem()
Obtain the currently displayed cluster in the combo box. This method can be used to obtain the current cluster being displayed (or to be displayed) in a combo box. This method implements the corresponding interface method defined in the ComboBoxModel.

Specified by:
getSelectedItem in interface javax.swing.ComboBoxModel
Returns:
This method returns the currently selected item in the list.

setSelectedItem

public void setSelectedItem(java.lang.Object anItem)
Set the selected (item being displayed) item in a combo box. As per the API requirement this method should notifies all registered ListDataListeners that the contents have changed.

Specified by:
setSelectedItem in interface javax.swing.ComboBoxModel
Parameters:
anItem - The item to be displayed in the combo box.

addListDataListener

public void addListDataListener(javax.swing.event.ListDataListener ldl)
Adds a listener to be notified when the data associated with the model changes. This method is part of the ListModel interface class.

Specified by:
addListDataListener in interface javax.swing.ListModel
Parameters:
ldl - The listener to be added to the list of listeners to be notified when the data associated with the workspace changes.
See Also:
ListModel

removeListDataListener

public void removeListDataListener(javax.swing.event.ListDataListener ldl)
Removes a listener from the list of listeners maintained by this class. This method is part of the ListModel interface class.

Specified by:
removeListDataListener in interface javax.swing.ListModel
Parameters:
ldl - The listener to be removed from the list of listeners to receive updates.
See Also:
ListModel

getElementAt

public ClusterNode getElementAt(int index)
Obtain the cluster node in the combo box list at a given index. This method implements the interface method in ListModel to return the appropriate cluster entry at a given index. Note that the actual cluster node returned may vary depending on how the list is sorted.

Specified by:
getElementAt in interface javax.swing.ListModel
Parameters:
index - The index of the entry whose element is to be returned by this method. This value must be in the range 0 ≤ index < getSize()
Returns:
The element at the requested index. If the index is not valid then this method returns null.

getSize

public int getSize()
Obtain the number of entries to be displayed in the combo box. This method implements the corresponding interface method in the ListModel. It returns the number of clusters involved in this data model. Note that clusters with names (that currently represent dummy clusters) are not included in this list.

Specified by:
getSize in interface javax.swing.ListModel
Returns:
The number of actual clusters to be displayed in this model.

getESTList

public ESTList getESTList()
Obtain the list of ESTs associated with this model.

Returns:
The EST list set for use by this model.

getClusterFile

public ClusterFile getClusterFile()
Obtain the cluster file information from where this pre-alignment model was built.

Returns:
The cluster file (containing cluster information and other meta data) set for use by this model.

getMaxCol

public int getMaxCol()
Obtain the last column where a nucleotide is present. This method can be used to determine the logical width of this model. This value is typically used to determine the overall viewing area required to display the model.

Returns:
The last column where a nucleotide is present. This value is at least 1.

getMaxRow

public int getMaxRow()
Determine the maximum number of rows in this overlap model. This method must be used to determine the maximum number of rows in this overlap model.

Returns:
The maximum number of rows in this overlap model.

getRow

public java.util.ArrayList<ESTEntry> getRow(int row)
Obtain the list of EST entries on a given row in the model. This method may be used to obtain the list of fragment entries on a specific row of the model.

Parameters:
row - The row for which the list of fragments are to be returned.
Returns:
An array list containing the list of fragments on a given row. If the row was invalid, then this method return null.

getWsEntry

public MSTClusterData getWsEntry()
Obtain the actual workspace entry whose data is contained in this model. A handy reference to the workspace entry from which the data for this overlap model was actually obtained. This information can be used by "view" classes to create additional views as needed.

Returns:
The reference to the MSTClusterData workspace entry whose data is "modeled" by this class.

fireDataChanged

protected void fireDataChanged()
Helper method to notify listeners whenever data changes. This method is used by other methods in this class to notify all list listeners whenever the data associated with the combo model changes. This method currently reports that the contents has changed to all registered listeners.


sort

public void sort(int order)
Method to change the order in which clusters are ordered. This method resets the order in which clusters are delivered to the view using this model.

Parameters:
order - The order in which the clusters are to be sorted. The following values are valid for this parameter: 0: no sorting, 1: smaller clusters first, 2: smaller clusters last.

getFarthestPos

private int getFarthestPos(MSTNode parent)
Helper method to determine how far-left the pre-alignment extends given the root is at logical position zero. This method recursively calls itself to determine the left-most fragment position. Essentially, this method first determines the farthest positions of each child node (given the parent node) and returns the minimum of the position values. The recursion terminates each time a leaf node in the MST is encountered.

Parameters:
parent - The parent node whose farthest child position is to be determined. This method is typically invoked with the root of the MST tree.
Returns:
This method returns the base-pair position of the lest-most fragment in the MST

buildClusterList

private void buildClusterList(ClusterFile clusterFile)
Helper method to populate local list of clusters from a cluster file. This method is a helper method that is used to process a given ClusterFile and add non-dummy cluster nodes to the local list of clusters maintained by this class. This method is used only once while the PreAlignmentModel is being populated.

Parameters:
clusterFile - The cluster file to be processed by this method to extract the list of clusters to be managed by this class.

addToESTEntryTable

private void addToESTEntryTable(int row,
                                ESTEntry entry)
Add an entry to the specified row in the estEntryTable. This method is a helper method that is invoked from the generateESTEntries method to add a new entry to the estEntryTable. This method also tracks and updates maxCol instance variable to reflect the farthest nucleotide in the table (across all rows).

Parameters:
row - The row in the estEntryTable to which the given entry is to be added.
entry - The newly created entry to be added to the estEntryTable at the specified row.

generateESTEntries

private void generateESTEntries(MSTNode parent,
                                int startPos,
                                int[] clusterIDList,
                                int prevClusterID,
                                int lastRow,
                                java.util.ArrayList<java.lang.Long> rowUsage)
Recursive method to generate ESTEntry objects with alignment information. This method is invoked to perform the actual core alignment task using the input fragments from a FASTA file along with the MST (with alignment information). This method uses the startPos value provided by the caller to recursively position fragments and generate ESTEntry objects with alignment information for each fragment.

Parameters:
parent - The MST node (and its children) that must be aligned by this method. This method is initially invoked on the root of the MST.
startPos - The starting base pair position relative to which the parent and its child nodes are to be positioned.
clusterIDList - The lookup table that has been populated by the generateClusterLookupTable(int, ClusterNode, int[]) method. This method uses the look up table to determine the cluster ID when generating ESTEntry objects for each fragment.
prevClusterID - This parameter is used to track the ID of the previous cluster to which an entry was added. When moving from one cluster to another, the lastRow value is reset to 0.
lastRow - The last row in the rowUsage list where the previous entry was placed.
rowUsage - The array of row usage information that is used to determine when a row is available to accommodate a given entry.

generateClusterLookupTable

private static void generateClusterLookupTable(int parentClusterID,
                                               ClusterNode node,
                                               int[] clusterIDList)
Helper method to build a table (simple array) that provides clusterID for each fragment. This method is a recursive helper method that is used to build a look-up table to map a fragment to its cluster ID. The look-up table is simply an integer array. The index into this array is the index of the fragment whose cluster ID is to be determined. The array contains the cluster ID for each fragment read from a given FASTA file.

Parameters:
parentClusterID - The logical cluster ID of the parent cluster to which the given child node logically belongs.
node - The child node in the cluster hierarchy whose leaf fragment entries are to be cataloged in the lookup table.
clusterIDList - The lookup table being populated by this method. The array must be exactly the same size as the number of fragments in the FASTA file.
See Also:
generateESTEntries(MSTNode, int, int[], int, int, ArrayList)

toLong

private static long toLong(int hiInt,
                           int lowInt)
A simple helper method to combine two integers into a long. This is a helper method that is used in the getRow method to combine two integers into a long value.

Parameters:
hiInt - The high 32-bit value to be stored in the long.
lowInt - The low 32-bit value to be stored in the long.
Returns:
The long that contains the hiInt and lowInt values combined into one.

getRow

private static int getRow(int start,
                          int end,
                          int startRow,
                          java.util.ArrayList<java.lang.Long> rowUsage)
This is a helper method that is used to determine the row on which a fragment can be accommodated.

Parameters:
start - The starting column where the fragment is to be placed.
end - The ending column where the fragment will end.
startRow - The starting row from where the search is to be done. This value must be 0.
rowUsage - The row
Returns:
The row where the fragment can be accommodated.