mev-4.0.01/source/org/tigr/microarray/mev/cluster/clusterUtil/ClusterRepository.java

Code
Comments
Other
Rev Date Author Line
2 26 Feb 07 jari 1 /*
2 26 Feb 07 jari 2 Copyright @ 1999-2004, The Institute for Genomic Research (TIGR).
2 26 Feb 07 jari 3 All rights reserved.
2 26 Feb 07 jari 4  */
2 26 Feb 07 jari 5 /*
2 26 Feb 07 jari 6  * $RCSfile: ClusterRepository.java,v $
2 26 Feb 07 jari 7  * $Revision: 1.14 $
2 26 Feb 07 jari 8  * $Date: 2006/05/02 16:56:57 $
2 26 Feb 07 jari 9  * $Author: eleanorahowe $
2 26 Feb 07 jari 10  * $State: Exp $
2 26 Feb 07 jari 11  */
2 26 Feb 07 jari 12
2 26 Feb 07 jari 13 package org.tigr.microarray.mev.cluster.clusterUtil;
2 26 Feb 07 jari 14
2 26 Feb 07 jari 15 import java.awt.Color;
2 26 Feb 07 jari 16 import java.io.IOException;
2 26 Feb 07 jari 17 import java.io.ObjectInputStream;
2 26 Feb 07 jari 18 import java.io.ObjectOutputStream;
2 26 Feb 07 jari 19 import java.util.Hashtable;
2 26 Feb 07 jari 20 import java.util.Vector;
2 26 Feb 07 jari 21
2 26 Feb 07 jari 22 import javax.swing.JOptionPane;
2 26 Feb 07 jari 23 import javax.swing.tree.DefaultMutableTreeNode;
2 26 Feb 07 jari 24
2 26 Feb 07 jari 25 import org.tigr.microarray.mev.ISlideData;
2 26 Feb 07 jari 26 import org.tigr.microarray.mev.SearchResultDialog;
2 26 Feb 07 jari 27 import org.tigr.microarray.mev.cluster.clusterUtil.submit.SubmissionManager;
2 26 Feb 07 jari 28 import org.tigr.microarray.mev.cluster.gui.Experiment;
2 26 Feb 07 jari 29 import org.tigr.microarray.mev.cluster.gui.IData;
2 26 Feb 07 jari 30 import org.tigr.microarray.mev.cluster.gui.IFramework;
2 26 Feb 07 jari 31 import org.tigr.microarray.mev.cluster.gui.helpers.ExperimentUtil;
2 26 Feb 07 jari 32
2 26 Feb 07 jari 33 /** The ClusterRepository contains ClusterList objects created for
2 26 Feb 07 jari 34  * holding saved clusters particular analysis results.
2 26 Feb 07 jari 35  */
2 26 Feb 07 jari 36 public class ClusterRepository extends Vector {
2 26 Feb 07 jari 37     
2 26 Feb 07 jari 38     public static final int GENE_CLUSTER = 0;
2 26 Feb 07 jari 39     public static final int EXPERIMENT_CLUSTER = 1;
2 26 Feb 07 jari 40     
2 26 Feb 07 jari 41     private int numberOfElements;
2 26 Feb 07 jari 42     /** Maintains a ClusterList array for each data element.
2 26 Feb 07 jari 43      * If an element is a member of a cluster then that element will
2 26 Feb 07 jari 44      * have a reference to it's cluster object.
2 26 Feb 07 jari 45      */
2 26 Feb 07 jari 46     private ClusterList [] elementClusters;
2 26 Feb 07 jari 47     
2 26 Feb 07 jari 48     /** A counter to assign cluster serial numbers as they are
2 26 Feb 07 jari 49      * added to the repository.
2 26 Feb 07 jari 50      */
2 26 Feb 07 jari 51     private int clusterSerialCounter = 0;
2 26 Feb 07 jari 52     /** true if the repository maintains gene clusters
2 26 Feb 07 jari 53      */
2 26 Feb 07 jari 54     private boolean geneClusterRepository = false;
2 26 Feb 07 jari 55     
2 26 Feb 07 jari 56     /** IFramework implementation
2 26 Feb 07 jari 57      */
2 26 Feb 07 jari 58     private IFramework framework;
2 26 Feb 07 jari 59     
2 26 Feb 07 jari 60     /**
2 26 Feb 07 jari 61      * Used by XMLEncoder/XMLDecoder in conjunction with getPersistenceDelegateArgs()
2 26 Feb 07 jari 62      * @param isGeneClusterRepository
2 26 Feb 07 jari 63      * @param numberOfElements
2 26 Feb 07 jari 64      * @param elementClusters
2 26 Feb 07 jari 65      * @param clusterSerialCounter
2 26 Feb 07 jari 66      */
2 26 Feb 07 jari 67     public ClusterRepository(Boolean isGeneClusterRepository, Integer numberOfElements, Integer clusterSerialCounter, ClusterList[] elementClusters) {
2 26 Feb 07 jari 68       this.geneClusterRepository = isGeneClusterRepository.booleanValue();
2 26 Feb 07 jari 69       this.numberOfElements = numberOfElements.intValue();
2 26 Feb 07 jari 70       this.elementClusters = elementClusters;
2 26 Feb 07 jari 71       this.clusterSerialCounter = clusterSerialCounter.intValue();
2 26 Feb 07 jari 72     }
2 26 Feb 07 jari 73     
2 26 Feb 07 jari 74     /** Creates new ClusterRepository with a specified element count
2 26 Feb 07 jari 75      */
2 26 Feb 07 jari 76     public ClusterRepository(int numberOfElements, IFramework framework) {
2 26 Feb 07 jari 77         this.numberOfElements = numberOfElements;
2 26 Feb 07 jari 78         this.framework = framework;
2 26 Feb 07 jari 79         this.elementClusters = new ClusterList[numberOfElements];
2 26 Feb 07 jari 80         this.addClusterList(new ClusterList("Cluster Ops."));
2 26 Feb 07 jari 81     }
2 26 Feb 07 jari 82     
2 26 Feb 07 jari 83     /** Creates new ClusterRepository with specified cluster type*/
2 26 Feb 07 jari 84     public ClusterRepository(int numberOfElements, IFramework framework, boolean isGeneClusterRepository) {
2 26 Feb 07 jari 85         this.numberOfElements = numberOfElements;
2 26 Feb 07 jari 86         this.framework = framework;
2 26 Feb 07 jari 87         this.elementClusters = new ClusterList[numberOfElements];
2 26 Feb 07 jari 88         this.geneClusterRepository = isGeneClusterRepository;
2 26 Feb 07 jari 89         this.addClusterList(new ClusterList("Cluster Ops."));
2 26 Feb 07 jari 90     }
2 26 Feb 07 jari 91     
2 26 Feb 07 jari 92         
2 26 Feb 07 jari 93     //EH getter methods added to support constructer used by XMLEncoder/XMLDecoder
2 26 Feb 07 jari 94     
2 26 Feb 07 jari 95     public int getNumberOfElements(){return numberOfElements;}
2 26 Feb 07 jari 96     public ClusterList[] getElementClusters(){
2 26 Feb 07 jari 97       return elementClusters;
2 26 Feb 07 jari 98     }
2 26 Feb 07 jari 99     public int getClusterSerialCounter() {return clusterSerialCounter;}
2 26 Feb 07 jari 100       /*
2 26 Feb 07 jari 101      * Returns a Hashtable of all the Experiments contained within this ClusterRepository
2 26 Feb 07 jari 102      * indexed on the Experiment.getId();
2 26 Feb 07 jari 103        */
2 26 Feb 07 jari 104     public Hashtable getAllExperiments() {
2 26 Feb 07 jari 105       Hashtable allExpts = new Hashtable();
2 26 Feb 07 jari 106       for(int i=0; i<elementClusters.length; i++) {
2 26 Feb 07 jari 107         try {
2 26 Feb 07 jari 108           for(int j=0; j<elementClusters[i].size(); j++){
2 26 Feb 07 jari 109               Cluster c = (Cluster)elementClusters[i].get(j);
2 26 Feb 07 jari 110               allExpts.put(new Integer(c.getExptID()), c.getExperiment());
2 26 Feb 07 jari 111           }
2 26 Feb 07 jari 112         } catch (NullPointerException npe){}
2 26 Feb 07 jari 113       }
2 26 Feb 07 jari 114       return allExpts;
2 26 Feb 07 jari 115     }
2 26 Feb 07 jari 116     
2 26 Feb 07 jari 117     public void populateExperiments(Hashtable allExpts){
2 26 Feb 07 jari 118       for(int i=0; i<elementClusters.length; i++) {
2 26 Feb 07 jari 119         try {
2 26 Feb 07 jari 120           for(int j=0; j<elementClusters[i].size(); j++){
2 26 Feb 07 jari 121               Cluster c = (Cluster)elementClusters[i].get(j);
2 26 Feb 07 jari 122               c.setExperiment((Experiment)allExpts.get(new Integer(c.getExptID())));
2 26 Feb 07 jari 123           }
2 26 Feb 07 jari 124         } catch (NullPointerException npe){}
2 26 Feb 07 jari 125       }    
2 26 Feb 07 jari 126     }
2 26 Feb 07 jari 127     
2 26 Feb 07 jari 128     /**
2 26 Feb 07 jari 129      *  Sets the repository's framework field
2 26 Feb 07 jari 130      */
2 26 Feb 07 jari 131     public void setFramework(IFramework framework) {
2 26 Feb 07 jari 132         this.framework = framework;
2 26 Feb 07 jari 133     }
2 26 Feb 07 jari 134     /** Returns the color of the last cluster to which the element
2 26 Feb 07 jari 135      * (index) was assigned
2 26 Feb 07 jari 136      */
2 26 Feb 07 jari 137     public Color getColor(int index){
2 26 Feb 07 jari 138         if(elementClusters[index] == null  || elementClusters[index].size() == 0)
2 26 Feb 07 jari 139             return null;
2 26 Feb 07 jari 140         Color color = elementClusters[index].lastCluster().getClusterColor();
2 26 Feb 07 jari 141         
2 26 Feb 07 jari 142         //if last color is showing color return the color
2 26 Feb 07 jari 143         if(color != null)
2 26 Feb 07 jari 144             return color;
2 26 Feb 07 jari 145             
2 26 Feb 07 jari 146         //if the last cluster is supressing color, then check earlier clusters.
2 26 Feb 07 jari 147         else {  
2 26 Feb 07 jari 148             //check for previous cluster colors
2 26 Feb 07 jari 149             Color [] colors = getColors(index);
2 26 Feb 07 jari 150             
2 26 Feb 07 jari 151             //jump out if only one cluster
2 26 Feb 07 jari 152             if(colors.length <= 1)
2 26 Feb 07 jari 153                 return null;
2 26 Feb 07 jari 154             
2 26 Feb 07 jari 155             else {
2 26 Feb 07 jari 156                 //skip last and try earlier clusters
2 26 Feb 07 jari 157                 for(int i = colors.length-2; i >= 0; i--) {
2 26 Feb 07 jari 158                     if(colors[i] != null)
2 26 Feb 07 jari 159                         return colors[i];
2 26 Feb 07 jari 160                 }
2 26 Feb 07 jari 161             }
2 26 Feb 07 jari 162         }
2 26 Feb 07 jari 163         return null;
2 26 Feb 07 jari 164     }
2 26 Feb 07 jari 165     
2 26 Feb 07 jari 166     /** Returns all cluster colors for the clusters to which
2 26 Feb 07 jari 167      * the element (index) was assigned
2 26 Feb 07 jari 168      */
2 26 Feb 07 jari 169     public Color [] getColors(int index){
2 26 Feb 07 jari 170         if(elementClusters[index] == null)
2 26 Feb 07 jari 171             return null;
2 26 Feb 07 jari 172         ClusterList list  = elementClusters[index];
2 26 Feb 07 jari 173         Color [] colors = new Color[list.size()];
2 26 Feb 07 jari 174         for(int i = 0; i < colors.length; i++){
2 26 Feb 07 jari 175             colors[i] = list.getClusterAt(i).getClusterColor();
2 26 Feb 07 jari 176         }
2 26 Feb 07 jari 177         return colors;
2 26 Feb 07 jari 178     }
2 26 Feb 07 jari 179     
2 26 Feb 07 jari 180     /** Returns the number of elements in the data set corresponding to
2 26 Feb 07 jari 181      * the repository.  (number of spots or experiments)
2 26 Feb 07 jari 182      */
2 26 Feb 07 jari 183     public int getDataElementCount(){
2 26 Feb 07 jari 184         return this.numberOfElements;
2 26 Feb 07 jari 185     }
2 26 Feb 07 jari 186     
2 26 Feb 07 jari 187     /** Returns true if the repository maintains gene clusters.
2 26 Feb 07 jari 188      */
2 26 Feb 07 jari 189     public boolean isGeneClusterRepository(){ return this.geneClusterRepository; }
2 26 Feb 07 jari 190     
2 26 Feb 07 jari 191     /** Returns a cluster list for the specified result index.
2 26 Feb 07 jari 192      */
2 26 Feb 07 jari 193     public ClusterList getClusterList(int index){
2 26 Feb 07 jari 194         if(isInRange(index))
2 26 Feb 07 jari 195             return ((ClusterList)elementAt(index));
2 26 Feb 07 jari 196         return null;
2 26 Feb 07 jari 197     }
2 26 Feb 07 jari 198     
2 26 Feb 07 jari 199     /** adds a provided Clusterlist
2 26 Feb 07 jari 200      */
2 26 Feb 07 jari 201     public void addClusterList(ClusterList list){
2 26 Feb 07 jari 202         add(list);
2 26 Feb 07 jari 203     }
2 26 Feb 07 jari 204     
2 26 Feb 07 jari 205     
2 26 Feb 07 jari 206     /** Adds a cluster to a specified ClusterList
2 26 Feb 07 jari 207      */
2 26 Feb 07 jari 208     public void addCluster(ClusterList list, Cluster cluster){
2 26 Feb 07 jari 209         if(cluster == null)
2 26 Feb 07 jari 210             return;
2 26 Feb 07 jari 211         
2 26 Feb 07 jari 212         //if not a cluster operation and cluster exists, modify cluster
2 26 Feb 07 jari 213         if(!((cluster.getSource()).equals("Cluster Op.")) && list.isClusterSaved(cluster.getClusterID(), cluster.getIndices())){
2 26 Feb 07 jari 214             Cluster savedCluster = list.getCluster(cluster.getClusterID());
2 26 Feb 07 jari 215             if(savedCluster == null){   //safety net
2 26 Feb 07 jari 216                 list.addCluster(cluster);
2 26 Feb 07 jari 217                 updateClusterMembership(cluster);
2 26 Feb 07 jari 218                 return;
2 26 Feb 07 jari 219             }
2 26 Feb 07 jari 220             savedCluster.setClusterColor(cluster.getClusterColor());
2 26 Feb 07 jari 221             savedCluster.setClusterLabel(cluster.getClusterLabel());
2 26 Feb 07 jari 222             savedCluster.setClusterDescription(cluster.getClusterDescription());
2 26 Feb 07 jari 223             this.setClusterSerialCounter(this.getMaxClusterSerialNumber()-1);  //rollback counter
2 26 Feb 07 jari 224             moveClusterToEndInMembershipLists(savedCluster);
2 26 Feb 07 jari 225         } else {
2 26 Feb 07 jari 226             if(list == null){ // null cluster list for cluster operations. make one
2 26 Feb 07 jari 227                 list = new ClusterList("Cluster Ops.");
2 26 Feb 07 jari 228                 this.addClusterList(list);
2 26 Feb 07 jari 229             }
2 26 Feb 07 jari 230             list.addCluster(cluster);
2 26 Feb 07 jari 231             updateClusterMembership(cluster);
2 26 Feb 07 jari 232         }
2 26 Feb 07 jari 233     }
2 26 Feb 07 jari 234     
2 26 Feb 07 jari 235     /** Adds a cluster to a specified ClusterList
2 26 Feb 07 jari 236      */
2 26 Feb 07 jari 237     public void addSubCluster(ClusterList list, Cluster cluster){
2 26 Feb 07 jari 238         if(cluster == null)
2 26 Feb 07 jari 239             return;
2 26 Feb 07 jari 240 /*
2 26 Feb 07 jari 241         if(!((cluster.getSource()).equals("Cluster Op.")) && list.isClusterSaved(cluster.getClusterID())){
2 26 Feb 07 jari 242             Cluster savedCluster = list.getCluster(cluster.getClusterID());
2 26 Feb 07 jari 243             if(savedCluster == null){   //safety net
2 26 Feb 07 jari 244                 list.addCluster(cluster);
2 26 Feb 07 jari 245                 updateClusterMembership(cluster);
2 26 Feb 07 jari 246                 return;
2 26 Feb 07 jari 247             }
2 26 Feb 07 jari 248             savedCluster.setClusterColor(cluster.getClusterColor());
2 26 Feb 07 jari 249             savedCluster.setClusterLabel(cluster.getClusterLabel());
2 26 Feb 07 jari 250             savedCluster.setClusterDescription(cluster.getClusterDescription());
2 26 Feb 07 jari 251             this.setClusterSerialCounter(this.getMaxClusterSerialNumber()-1);  //rollback counter
2 26 Feb 07 jari 252         } else {
2 26 Feb 07 jari 253  **/
2 26 Feb 07 jari 254         list.addCluster(cluster);
2 26 Feb 07 jari 255         updateClusterMembership(cluster);
2 26 Feb 07 jari 256         //  }
2 26 Feb 07 jari 257     }
2 26 Feb 07 jari 258     
2 26 Feb 07 jari 259     /** Adds a cluster to elements cluster list for elements
2 26 Feb 07 jari 260      * contained in a cluster
2 26 Feb 07 jari 261      */
2 26 Feb 07 jari 262     private void updateClusterMembership(Cluster cluster){
2 26 Feb 07 jari 263         int [] indices = cluster.getIndices();
2 26 Feb 07 jari 264         for(int i = 0; i < indices.length; i++){
2 26 Feb 07 jari 265             if(elementClusters[indices[i]] == null)
2 26 Feb 07 jari 266                 elementClusters[indices[i]] = new ClusterList("element "+indices[i]);
2 26 Feb 07 jari 267             elementClusters[indices[i]].add(cluster);
2 26 Feb 07 jari 268         }
2 26 Feb 07 jari 269     }
2 26 Feb 07 jari 270     
2 26 Feb 07 jari 271     /** Moves a cluster to the rear of the elementCluster lists ClusterList
2 26 Feb 07 jari 272      * (This is so that getColor() commands for gene color get the latest color
2 26 Feb 07 jari 273      * assigned rather than the color of the last cluster assigned.  This is to handle
2 26 Feb 07 jari 274      * modification of an existing cluster's color attribute.)
2 26 Feb 07 jari 275      */
2 26 Feb 07 jari 276     private void moveClusterToEndInMembershipLists(Cluster cluster){
2 26 Feb 07 jari 277         int [] indices = cluster.getIndices();
2 26 Feb 07 jari 278         for(int i = 0; i < indices.length; i++){
2 26 Feb 07 jari 279             if(elementClusters[indices[i]] == null)
2 26 Feb 07 jari 280                 elementClusters[indices[i]] = new ClusterList("element "+indices[i]);
2 26 Feb 07 jari 281             //if it's in the list (and is should always be) remove it and put it back in
2 26 Feb 07 jari 282             //at the end.
2 26 Feb 07 jari 283             if(elementClusters[indices[i]].contains(cluster)){
2 26 Feb 07 jari 284                 elementClusters[indices[i]].removeElement(cluster);
2 26 Feb 07 jari 285                 elementClusters[indices[i]].addElement(cluster);
2 26 Feb 07 jari 286             }
2 26 Feb 07 jari 287         }
2 26 Feb 07 jari 288     }
2 26 Feb 07 jari 289     
2 26 Feb 07 jari 290     /** Removes clusters from the cluster list of each element
2 26 Feb 07 jari 291      * contained in the specified cluster.
2 26 Feb 07 jari 292      */
2 26 Feb 07 jari 293     private void removeClusterMembership(Cluster cluster){
2 26 Feb 07 jari 294         int [] indices = cluster.getIndices();
2 26 Feb 07 jari 295         for(int i = 0; i < indices.length; i++){
2 26 Feb 07 jari 296             if(elementClusters[indices[i]] != null)
2 26 Feb 07 jari 297                 elementClusters[indices[i]].removeElement(cluster);
2 26 Feb 07 jari 298         }
2 26 Feb 07 jari 299     }
2 26 Feb 07 jari 300     
2 26 Feb 07 jari 301     /** Clears all cluster lists.
2 26 Feb 07 jari 302      */
2 26 Feb 07 jari 303     public void clearClusterLists(){
2 26 Feb 07 jari 304         for(int i = 0; i < size(); i++)
2 26 Feb 07 jari 305             this.getClusterList(i).clear();
2 26 Feb 07 jari 306         clearElementClusters();
2 26 Feb 07 jari 307         if(this.isGeneClusterRepository())
2 26 Feb 07 jari 308             framework.getData().deleteColors();
2 26 Feb 07 jari 309         else
2 26 Feb 07 jari 310             framework.getData().deleteExperimentColors();
2 26 Feb 07 jari 311     }
2 26 Feb 07 jari 312     
2 26 Feb 07 jari 313     /** Clears the cluster lists for all elements.
2 26 Feb 07 jari 314      * Postcondition is that all elements do not have
2 26 Feb 07 jari 315      * references to any clusters.
2 26 Feb 07 jari 316      */
2 26 Feb 07 jari 317     private void clearElementClusters(){
2 26 Feb 07 jari 318         for(int i = 0; i < numberOfElements; i++)
2 26 Feb 07 jari 319             this.elementClusters[i] = null;
2 26 Feb 07 jari 320     }
2 26 Feb 07 jari 321     
2 26 Feb 07 jari 322     public boolean isEmpty(){
2 26 Feb 07 jari 323         for(int i = 0; i < size(); i++)
2 26 Feb 07 jari 324             if(this.getClusterList(i).size() > 0)
2 26 Feb 07 jari 325                 return false;
2 26 Feb 07 jari 326         return true;
2 26 Feb 07 jari 327     }
2 26 Feb 07 jari 328     
2 26 Feb 07 jari 329     /** Returns true if an index for a cluster list is in range.
2 26 Feb 07 jari 330      */
2 26 Feb 07 jari 331     protected boolean isInRange(int index){
2 26 Feb 07 jari 332         return (index > -1 && index < size());
2 26 Feb 07 jari 333     }
2 26 Feb 07 jari 334     
2 26 Feb 07 jari 335     /** Stores a cluster given the passed parameters.
2 26 Feb 07 jari 336      */
2 26 Feb 07 jari 337     public Cluster storeCluster(int algorithmIndex, String algorithmName, String clusterID, int [] indices, Experiment experiment){
2 26 Feb 07 jari 338         
2 26 Feb 07 jari 339         ClusterList list =  findClusterList(algorithmName);
2 26 Feb 07 jari 340         
2 26 Feb 07 jari 341         if(list == null){
2 26 Feb 07 jari 342             list = new ClusterList(algorithmName);
2 26 Feb 07 jari 343             this.addClusterList(list);
2 26 Feb 07 jari 344         } else if(list.isClusterSaved(clusterID, indices)){
2 26 Feb 07 jari 345             JOptionPane pane = new JOptionPane("Cluster has already been saved.  Would you like to " +
2 26 Feb 07 jari 346             "replace the existing attributes?", JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION);
2 26 Feb 07 jari 347             pane.setVisible(true);
2 26 Feb 07 jari 348             int option = pane.getOptionType();
2 26 Feb 07 jari 349             if(option == JOptionPane.CANCEL_OPTION || option == JOptionPane.NO_OPTION)
2 26 Feb 07 jari 350                 return null;
2 26 Feb 07 jari 351         }
2 26 Feb 07 jari 352         
2 26 Feb 07 jari 353         ClusterAttributesDialog dialog = new ClusterAttributesDialog("Store Cluster Attributes", algorithmName, clusterID);
2 26 Feb 07 jari 354         if(dialog.showModal() != JOptionPane.OK_OPTION){
2 26 Feb 07 jari 355             return null;
2 26 Feb 07 jari 356         }
2 26 Feb 07 jari 357         
2 26 Feb 07 jari 358         Color clusterColor = dialog.getColor();
2 26 Feb 07 jari 359         String clusterLabel = dialog.getLabel();
2 26 Feb 07 jari 360         String clusterDescription = dialog.getDescription();
2 26 Feb 07 jari 361         this.clusterSerialCounter++;
2 26 Feb 07 jari 362         Cluster cluster = new Cluster(indices, "Algorithm", clusterLabel, algorithmName, clusterID, clusterDescription, algorithmIndex, this.clusterSerialCounter, clusterColor, experiment);
2 26 Feb 07 jari 363         addCluster(list, cluster);
2 26 Feb 07 jari 364         
2 26 Feb 07 jari 365         return cluster;
2 26 Feb 07 jari 366     }
2 26 Feb 07 jari 367     
2 26 Feb 07 jari 368     /** Stores a clsuter given the supplied parameters.
2 26 Feb 07 jari 369      */
2 26 Feb 07 jari 370     public Cluster storeCluster(int algorithmIndex, String algorithmName, String clusterID, int [] indices, DefaultMutableTreeNode clusterNode, Experiment experiment){
2 26 Feb 07 jari 371         
2 26 Feb 07 jari 372         ClusterList list =  findClusterList(algorithmName);
2 26 Feb 07 jari 373         
2 26 Feb 07 jari 374         if(list == null){
2 26 Feb 07 jari 375             list = new ClusterList(algorithmName);
2 26 Feb 07 jari 376             this.addClusterList(list);
2 26 Feb 07 jari 377         } else if(list.isClusterSaved(clusterID, indices)){
2 26 Feb 07 jari 378             int option = JOptionPane.showConfirmDialog(new java.awt.Frame(), "Cluster has already been saved.  Would you like to " +
2 26 Feb 07 jari 379             "modify the existing attributes?", "Cluster Saved Alert", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
2 26 Feb 07 jari 380             
2 26 Feb 07 jari 381             if(option == JOptionPane.NO_OPTION)
2 26 Feb 07 jari 382                 return null;
2 26 Feb 07 jari 383         }
2 26 Feb 07 jari 384         
2 26 Feb 07 jari 385         ClusterAttributesDialog dialog = new ClusterAttributesDialog("Store Cluster Attributes", algorithmName, clusterID);
2 26 Feb 07 jari 386         if(dialog.showModal() != JOptionPane.OK_OPTION){
2 26 Feb 07 jari 387             return null;
2 26 Feb 07 jari 388         }
2 26 Feb 07 jari 389         
2 26 Feb 07 jari 390         Color clusterColor = dialog.getColor();
2 26 Feb 07 jari 391         String clusterLabel = dialog.getLabel();
2 26 Feb 07 jari 392         String clusterDescription = dialog.getDescription();
2 26 Feb 07 jari 393         this.clusterSerialCounter++;
2 26 Feb 07 jari 394         Cluster cluster = new Cluster(indices, "Algorithm", clusterLabel, algorithmName, clusterID, clusterDescription, algorithmIndex, this.clusterSerialCounter, clusterColor, clusterNode, experiment);
2 26 Feb 07 jari 395         addCluster(list, cluster);
2 26 Feb 07 jari 396         
2 26 Feb 07 jari 397         return cluster;
2 26 Feb 07 jari 398     }
2 26 Feb 07 jari 399     
2 26 Feb 07 jari 400     /**
2 26 Feb 07 jari 401      * Stores a clsuter given the supplied parameters.
2 26 Feb 07 jari 402      */
2 26 Feb 07 jari 403     public Cluster storeSubCluster(int algorithmIndex, String algorithmName, String clusterID, int [] indices, DefaultMutableTreeNode clusterNode, Experiment experiment){
2 26 Feb 07 jari 404         
2 26 Feb 07 jari 405         ClusterList list =  findClusterList(algorithmName);
2 26 Feb 07 jari 406         boolean modification = false;
2 26 Feb 07 jari 407         
2 26 Feb 07 jari 408         if(list == null){
2 26 Feb 07 jari 409             list = new ClusterList(algorithmName);
2 26 Feb 07 jari 410             this.addClusterList(list);
2 26 Feb 07 jari 411         } else if(list.isClusterSaved(clusterID, indices)){
2 26 Feb 07 jari 412             if(list.getCluster(clusterID).doIndicesMatch(indices)){
2 26 Feb 07 jari 413                 int option = JOptionPane.showConfirmDialog(new java.awt.Frame(), "Cluster has already been saved.  Would you like to " +
2 26 Feb 07 jari 414                 "modify the existing attributes?", "Cluster Saved Alert", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
2 26 Feb 07 jari 415                 modification = true;
2 26 Feb 07 jari 416                 if(option == JOptionPane.NO_OPTION)
2 26 Feb 07 jari 417                     return null;
2 26 Feb 07 jari 418             }
2 26 Feb 07 jari 419         }
2 26 Feb 07 jari 420         
2 26 Feb 07 jari 421         ClusterAttributesDialog dialog = new ClusterAttributesDialog("Store Cluster Attributes", algorithmName, clusterID);
2 26 Feb 07 jari 422         if(dialog.showModal() != JOptionPane.OK_OPTION){
2 26 Feb 07 jari 423             return null;
2 26 Feb 07 jari 424         }
2 26 Feb 07 jari 425         
2 26 Feb 07 jari 426         Color clusterColor = dialog.getColor();
2 26 Feb 07 jari 427         String clusterLabel = dialog.getLabel();
2 26 Feb 07 jari 428         String clusterDescription = dialog.getDescription();
2 26 Feb 07 jari 429         this.clusterSerialCounter++;
2 26 Feb 07 jari 430         Cluster cluster = new Cluster(indices, "Algorithm", clusterLabel, algorithmName, clusterID, clusterDescription, algorithmIndex, this.clusterSerialCounter, clusterColor, clusterNode, experiment);
2 26 Feb 07 jari 431         if(modification)
2 26 Feb 07 jari 432             addCluster(list, cluster);
2 26 Feb 07 jari 433         else
2 26 Feb 07 jari 434             addSubCluster(list, cluster);
2 26 Feb 07 jari 435         
2 26 Feb 07 jari 436         return cluster;
2 26 Feb 07 jari 437     }
2 26 Feb 07 jari 438     
2 26 Feb 07 jari 439     /** Returns the ClusterList given an algorithm result name
2 26 Feb 07 jari 440      * (i.e. KMC(2))
2 26 Feb 07 jari 441      */
2 26 Feb 07 jari 442     private ClusterList findClusterList(String algName){
2 26 Feb 07 jari 443         ClusterList curr;
2 26 Feb 07 jari 444         for(int i = 0; i < size(); i++){
2 26 Feb 07 jari 445             curr = this.getClusterList(i);
2 26 Feb 07 jari 446             if(curr.getAlgorithmName().equals(algName))
2 26 Feb 07 jari 447                 return curr;
2 26 Feb 07 jari 448         }
2 26 Feb 07 jari 449         return null;
2 26 Feb 07 jari 450     }
2 26 Feb 07 jari 451     
2 26 Feb 07 jari 452     /** Returns a specialized cluster list responsible for holding
2 26 Feb 07 jari 453      * results from cluster operations.
2 26 Feb 07 jari 454      */
2 26 Feb 07 jari 455     public ClusterList getClusterOperationsList(){
2 26 Feb 07 jari 456         return findClusterList("Cluster Ops.");
2 26 Feb 07 jari 457     }
2 26 Feb 07 jari 458     
2 26 Feb 07 jari 459     /** Remove  a cluster given supplied parameters
2 26 Feb 07 jari 460      */
2 26 Feb 07 jari 461     public boolean removeCluster(int [] indices, String algorithmName, String clusterID){
2 26 Feb 07 jari 462         ClusterList list = findClusterList(algorithmName);
2 26 Feb 07 jari 463         if(list == null || list.size() == 0)
2 26 Feb 07 jari 464             return false;
2 26 Feb 07 jari 465         Cluster cluster = list.getCluster(clusterID);
2 26 Feb 07 jari 466         if(cluster != null){
2 26 Feb 07 jari 467             int serialNumber = cluster.getSerialNumber();
2 26 Feb 07 jari 468             if(this.isGeneClusterRepository()){
2 26 Feb 07 jari 469                 framework.getData().setProbesColor(indices, null);
2 26 Feb 07 jari 470                 framework.addHistory("Remove Gene Cluster From Repository: Serial # "+String.valueOf(serialNumber));
2 26 Feb 07 jari 471             } else {
2 26 Feb 07 jari 472                 framework.getData().setExperimentColor(indices, null);
2 26 Feb 07 jari 473                 framework.addHistory("Remove Experiment Cluster From Repository: Serial # "+String.valueOf(serialNumber));
2 26 Feb 07 jari 474             }
2 26 Feb 07 jari 475         } else {
2 26 Feb 07 jari 476             return false;
2 26 Feb 07 jari 477         }
2 26 Feb 07 jari 478         list.removeCluster(clusterID);
2 26 Feb 07 jari 479         removeElementClusters(indices, cluster);
2 26 Feb 07 jari 480         return true;
2 26 Feb 07 jari 481     }
2 26 Feb 07 jari 482     
2 26 Feb 07 jari 483     /** Remove  a cluster given supplied parameters
2 26 Feb 07 jari 484      */
2 26 Feb 07 jari 485     public boolean removeSubCluster(int [] indices, String algorithmName, String clusterID){
2 26 Feb 07 jari 486         ClusterList list = findClusterList(algorithmName);
2 26 Feb 07 jari 487         if(list == null || list.size() == 0)
2 26 Feb 07 jari 488             return false;
2 26 Feb 07 jari 489         
2 26 Feb 07 jari 490         Cluster cluster = null;
2 26 Feb 07 jari 491         Cluster temp = null;
2 26 Feb 07 jari 492         for(int i = 0; i < list.size(); i++){
2 26 Feb 07 jari 493             temp = list.getClusterAt(i);
2 26 Feb 07 jari 494             if(temp.doIndicesMatch(indices))
2 26 Feb 07 jari 495                 cluster = temp;
2 26 Feb 07 jari 496         }
2 26 Feb 07 jari 497         if(cluster == null)
2 26 Feb 07 jari 498             return false;
2 26 Feb 07 jari 499         
2 26 Feb 07 jari 500         int serialNumber = cluster.getSerialNumber();
2 26 Feb 07 jari 501         if(this.isGeneClusterRepository()){
2 26 Feb 07 jari 502             framework.getData().setProbesColor(indices, null);
2 26 Feb 07 jari 503             framework.addHistory("Remove Gene Cluster From Repository: Serial # "+String.valueOf(serialNumber));
2 26 Feb 07 jari 504         } else {
2 26 Feb 07 jari 505             framework.getData().setExperimentColor(indices, null);
2 26 Feb 07 jari 506             framework.addHistory("Remove Experiment Cluster From Repository: Serial # "+String.valueOf(serialNumber));
2 26 Feb 07 jari 507         }
2 26 Feb 07 jari 508         
2 26 Feb 07 jari 509         list.removeCluster(cluster);
2 26 Feb 07 jari 510         removeElementClusters(indices, cluster);
2 26 Feb 07 jari 511         return true;
2 26 Feb 07 jari 512     }
2 26 Feb 07 jari 513     
2 26 Feb 07 jari 514     
2 26 Feb 07 jari 515     /** Removes a cluster from elenets cluster lists.
2 26 Feb 07 jari 516      */
2 26 Feb 07 jari 517     private void removeElementClusters(int [] indices, Cluster cluster){
2 26 Feb 07 jari 518         for(int i = 0; i < indices.length; i++){
2 26 Feb 07 jari 519             this.elementClusters[indices[i]].remove(cluster);
2 26 Feb 07 jari 520         }
2 26 Feb 07 jari 521     }
2 26 Feb 07 jari 522     
2 26 Feb 07 jari 523     /** Alters the color of a specified cluster (cluster serial number)
2 26 Feb 07 jari 524      */
2 26 Feb 07 jari 525     public void updateClusterColor(int serialNumber, Color color){
2 26 Feb 07 jari 526         Cluster cluster = getCluster(serialNumber);
2 26 Feb 07 jari 527         if(cluster != null){
2 26 Feb 07 jari 528             cluster.setClusterColor(color);
2 26 Feb 07 jari 529         }
2 26 Feb 07 jari 530     }
2 26 Feb 07 jari 531     
2 26 Feb 07 jari 532     /** Returns the cluster specified by the provided
2 26 Feb 07 jari 533      * serial number.
2 26 Feb 07 jari 534      */
2 26 Feb 07 jari 535     public Cluster getCluster(int serialNumber){
2 26 Feb 07 jari 536         Cluster cluster = null;
2 26 Feb 07 jari 537         ClusterList list = null;
2 26 Feb 07 jari 538         for(int i = 0; i < size(); i++){
2 26 Feb 07 jari 539             list = this.getClusterList(i);
2 26 Feb 07 jari 540             for(int j = 0; j < list.size(); j++){
2 26 Feb 07 jari 541                 cluster = list.getClusterAt(j);
2 26 Feb 07 jari 542                 if(serialNumber == cluster.getSerialNumber())
2 26 Feb 07 jari 543                     return cluster;
2 26 Feb 07 jari 544             }
2 26 Feb 07 jari 545         }
2 26 Feb 07 jari 546         return cluster;
2 26 Feb 07 jari 547     }
2 26 Feb 07 jari 548     
2 26 Feb 07 jari 549     /** Removes cluster specified by the serial number
2 26 Feb 07 jari 550      */
2 26 Feb 07 jari 551     public boolean removeCluster(int serialNumber){
2 26 Feb 07 jari 552         Cluster cluster = getCluster(serialNumber);
2 26 Feb 07 jari 553         if(cluster == null)
2 26 Feb 07 jari 554             return false;
2 26 Feb 07 jari 555         
2 26 Feb 07 jari 556         ClusterList list;
2 26 Feb 07 jari 557         for(int i = 0; i < size(); i++){
2 26 Feb 07 jari 558             list = this.getClusterList(i);
2 26 Feb 07 jari 559             for(int j = 0; j < list.size(); j++){
2 26 Feb 07 jari 560                 if(list.getClusterAt(j) == cluster){
2 26 Feb 07 jari 561                     list.removeCluster(serialNumber);
2 26 Feb 07 jari 562                 }
2 26 Feb 07 jari 563             }
2 26 Feb 07 jari 564         }
2 26 Feb 07 jari 565         int [] indices = cluster.getIndices();
2 26 Feb 07 jari 566         removeClusterMembership(cluster);
2 26 Feb 07 jari 567         
2 26 Feb 07 jari 568         if(this.isGeneClusterRepository()){
2 26 Feb 07 jari 569             framework.getData().setProbesColor(indices, null);
2 26 Feb 07 jari 570             framework.addHistory("Remove Gene Cluster From Repository: Serial # "+String.valueOf(serialNumber));
2 26 Feb 07 jari 571         } else {
2 26 Feb 07 jari 572             framework.getData().setExperimentColor(indices, null);
2 26 Feb 07 jari 573             framework.addHistory("Remove Experiment Cluster From Repository: Serial # "+String.valueOf(serialNumber));
2 26 Feb 07 jari 574         }
2 26 Feb 07 jari 575         return true;
2 26 Feb 07 jari 576     }
2 26 Feb 07 jari 577     
2 26 Feb 07 jari 578     /** Returns the next availible cluster serial
2 26 Feb 07 jari 579      * number and reserves it's use.
2 26 Feb 07 jari 580      */
2 26 Feb 07 jari 581     public int takeNextClusterSerialNumber(){
2 26 Feb 07 jari 582         this.clusterSerialCounter++;
2 26 Feb 07 jari 583         return clusterSerialCounter;
2 26 Feb 07 jari 584     }
2 26 Feb 07 jari 585     
2 26 Feb 07 jari 586     /**
2 26 Feb 07 jari 587      *  Returns the value of the maximum serial number
2 26 Feb 07 jari 588      */
2 26 Feb 07 jari 589     public int getMaxClusterSerialNumber(){
2 26 Feb 07 jari 590         return clusterSerialCounter;
2 26 Feb 07 jari 591     }
2 26 Feb 07 jari 592     
2 26 Feb 07 jari 593     /**
2 26 Feb 07 jari 594      *  Sets the cluster serial number, next reserved number is value + 1
2 26 Feb 07 jari 595      */
2 26 Feb 07 jari 596     public void setClusterSerialCounter(int value){
2 26 Feb 07 jari 597         this.clusterSerialCounter = value;
2 26 Feb 07 jari 598     }
2 26 Feb 07 jari 599     
2 26 Feb 07 jari 600     /** Prints out a summary of the repository.
2 26 Feb 07 jari 601      */
2 26 Feb 07 jari 602     public void printRepository(){
2 26 Feb 07 jari 603     }
2 26 Feb 07 jari 604     
2 26 Feb 07 jari 605     /** Saves the specified cluster
2 26 Feb 07 jari 606      */
2 26 Feb 07 jari 607     public void saveCluster(int serialNumber){
2 26 Feb 07 jari 608         Cluster cluster = getCluster(serialNumber);
2 26 Feb 07 jari 609         try{
2 26 Feb 07 jari 610             if(geneClusterRepository)
2 26 Feb 07 jari 611                 ExperimentUtil.saveGeneCluster(framework.getFrame(), framework.getData(), cluster.getIndices());
2 26 Feb 07 jari 612             else
2 26 Feb 07 jari 613                 ExperimentUtil.saveExperimentCluster(framework.getFrame(), cluster.getExperiment(), framework.getData(), cluster.getIndices());
2 26 Feb 07 jari 614         } catch (Exception e){
2 26 Feb 07 jari 615             JOptionPane.showMessageDialog(framework.getFrame(), "Error saving cluster.  Cluster not saved.", "Save Error", JOptionPane.WARNING_MESSAGE);
2 26 Feb 07 jari 616             e.printStackTrace();
2 26 Feb 07 jari 617         }
2 26 Feb 07 jari 618     }
2 26 Feb 07 jari 619     
2 26 Feb 07 jari 620     
2 26 Feb 07 jari 621         
2 26 Feb 07 jari 622     /** Creates a cluster by importing a gene list         
2 26 Feb 07 jari 623      */
2 26 Feb 07 jari 624     public Cluster createClusterFromList() {
2 26 Feb 07 jari 625         ListImportDialog dialog;
2 26 Feb 07 jari 626         String [] ids;
2 26 Feb 07 jari 627         String key;
2 26 Feb 07 jari 628         int [] newIndices;
2 26 Feb 07 jari 629         boolean [] matches;
2 26 Feb 07 jari 630         Experiment experiment = framework.getData().getExperiment();
2 26 Feb 07 jari 631         
2 26 Feb 07 jari 632         
2 26 Feb 07 jari 633         if(this.isGeneClusterRepository()) {
2 26 Feb 07 jari 634             dialog = new ListImportDialog(framework.getFrame(), this.framework.getData().getFieldNames(), true);
2 26 Feb 07 jari 635             if(dialog.showModal() == JOptionPane.OK_OPTION) {
2 26 Feb 07 jari 636                 key = dialog.getFieldName();
2 26 Feb 07 jari 637                 ids = dialog.getList();
2 26 Feb 07 jari 638                 
2 26 Feb 07 jari 639                 //look for matches for ids
2 26 Feb 07 jari 640                 matches = new boolean[ids.length];
2 26 Feb 07 jari 641                 
2 26 Feb 07 jari 642                 newIndices = getMatchingIndices(experiment, key, ids, matches, true);
2 26 Feb 07 jari 643                 
2 26 Feb 07 jari 644                 if(newIndices != null && newIndices.length > 0) {
2 26 Feb 07 jari 645
2 26 Feb 07 jari 646                     SearchResultDialog resultDialog = new SearchResultDialog(framework, newIndices, ids, matches, true);
2 26 Feb 07 jari 647                     
2 26 Feb 07 jari 648                     if(resultDialog.showModal() == JOptionPane.OK_OPTION) {
2 26 Feb 07 jari 649                         
2 26 Feb 07 jari 650                         int [] selectedIndices = resultDialog.getSelectedIndices();
2 26 Feb 07 jari 651                         
2 26 Feb 07 jari 652                         if(selectedIndices == null || selectedIndices.length < 1) {
2 26 Feb 07 jari 653                             return null;
2 26 Feb 07 jari 654                         }
2 26 Feb 07 jari 655                         
2 26 Feb 07 jari 656                         ClusterAttributesDialog clusterDialog = new ClusterAttributesDialog("Store Cluster Attributes", "List Import", "Gene List");
2 26 Feb 07 jari 657                         if(clusterDialog.showModal() != JOptionPane.OK_OPTION){
2 26 Feb 07 jari 658                             return null;
2 26 Feb 07 jari 659                         }
2 26 Feb 07 jari 660                         
2 26 Feb 07 jari 661                         ClusterList list = getClusterOperationsList();
2 26 Feb 07 jari 662                         Color clusterColor = clusterDialog.getColor();
2 26 Feb 07 jari 663                         String clusterLabel = clusterDialog.getLabel();
2 26 Feb 07 jari 664                         String clusterDescription = clusterDialog.getDescription();
2 26 Feb 07 jari 665                         this.clusterSerialCounter++;
2 26 Feb 07 jari 666                         Cluster cluster = new Cluster(selectedIndices, "Cluster Op.", clusterLabel, "List Import", "N/A", clusterDescription, list.getAlgorithmIndex(), this.clusterSerialCounter, clusterColor, experiment);
2 26 Feb 07 jari 667                         
2 26 Feb 07 jari 668                         addCluster(list, cluster);
2 26 Feb 07 jari 669                         return cluster;
2 26 Feb 07 jari 670                     } else {
2 26 Feb 07 jari 671                         return null;
2 26 Feb 07 jari 672                     }
2 26 Feb 07 jari 673                     
2 26 Feb 07 jari 674                 } else {
2 26 Feb 07 jari 675                     JOptionPane.showMessageDialog(framework.getFrame(), "No genes matching the list entries were found.", "No Matches Found", JOptionPane.INFORMATION_MESSAGE);
2 26 Feb 07 jari 676                 }
2 26 Feb 07 jari 677             }
2 26 Feb 07 jari 678         } else{
2 26 Feb 07 jari 679             ISlideData slide = this.framework.getData().getFeature(0);
2 26 Feb 07 jari 680             if(slide == null)
2 26 Feb 07 jari 681                 return null;
2 26 Feb 07 jari 682             
2 26 Feb 07 jari 683             Vector slideNameKeys = slide.getSlideDataKeys();
2 26 Feb 07 jari 684             String [] slideNames = new String[slideNameKeys.size()];
2 26 Feb 07 jari 685             for(int i = 0; i < slideNames.length; i++) {
2 26 Feb 07 jari 686                 slideNames[i] = (String)(slideNameKeys.elementAt(i));
2 26 Feb 07 jari 687             }
2 26 Feb 07 jari 688             
2 26 Feb 07 jari 689             dialog = new ListImportDialog(framework.getFrame(), slideNames, false);
2 26 Feb 07 jari 690             
2 26 Feb 07 jari 691             if(dialog.showModal() == JOptionPane.OK_OPTION) {
2 26 Feb 07 jari 692                 
2 26 Feb 07 jari 693                 key = dialog.getFieldName();
2 26 Feb 07 jari 694                 ids = dialog.getList();
2 26 Feb 07 jari 695                 
2 26 Feb 07 jari 696                 //look for matches for ids
2 26 Feb 07 jari 697                 matches = new boolean[ids.length];
2 26 Feb 07 jari 698                 
2 26 Feb 07 jari 699                 newIndices = getMatchingIndices(experiment, key, ids, matches, false);
2 26 Feb 07 jari 700                 if(newIndices != null && newIndices.length > 0) {
2 26 Feb 07 jari 701                     
2 26 Feb 07 jari 702                     SearchResultDialog resultDialog = new SearchResultDialog(framework, newIndices, ids, matches, false);
2 26 Feb 07 jari 703                     
2 26 Feb 07 jari 704                     
2 26 Feb 07 jari 705                     if(resultDialog.showModal() == JOptionPane.OK_OPTION) {
2 26 Feb 07 jari 706                        int [] selectedIndices = resultDialog.getSelectedIndices();
2 26 Feb 07 jari 707                         
2 26 Feb 07 jari 708                         if(selectedIndices == null || selectedIndices.length < 1) {
2 26 Feb 07 jari 709                             return null;
2 26 Feb 07 jari 710                         }                        
2 26 Feb 07 jari 711                         
2 26 Feb 07 jari 712                         ClusterAttributesDialog clusterDialog = new ClusterAttributesDialog("Store Cluster Attributes", "List Import", "Sample List");
2 26 Feb 07 jari 713                         if(clusterDialog.showModal() != JOptionPane.OK_OPTION){
2 26 Feb 07 jari 714                             return null;
2 26 Feb 07 jari 715                         }
2 26 Feb 07 jari 716                         
2 26 Feb 07 jari 717                         ClusterList list = getClusterOperationsList();
2 26 Feb 07 jari 718                         Color clusterColor = clusterDialog.getColor();
2 26 Feb 07 jari 719                         String clusterLabel = clusterDialog.getLabel();
2 26 Feb 07 jari 720                         String clusterDescription = clusterDialog.getDescription();
2 26 Feb 07 jari 721                         this.clusterSerialCounter++;
2 26 Feb 07 jari 722                         Cluster cluster = new Cluster(selectedIndices, "List Import", clusterLabel, "List Import", "N/A", clusterDescription, list.getAlgorithmIndex(), this.clusterSerialCounter, clusterColor, experiment);
2 26 Feb 07 jari 723                         
2 26 Feb 07 jari 724                         addCluster(list, cluster);
2 26 Feb 07 jari 725                         return cluster;
2 26 Feb 07 jari 726                     }
2 26 Feb 07 jari 727                 } else {
2 26 Feb 07 jari 728                     JOptionPane.showMessageDialog(framework.getFrame(), "No samples matching the list entries were found.", "No Matches Found", JOptionPane.INFORMATION_MESSAGE);
2 26 Feb 07 jari 729                 }
2 26 Feb 07 jari 730             }
2 26 Feb 07 jari 731         }
2 26 Feb 07 jari 732         return null;
2 26 Feb 07 jari 733     }
2 26 Feb 07 jari 734     
2 26 Feb 07 jari 735
2 26 Feb 07 jari 736     
2 26 Feb 07 jari 737     private int [] getMatchingIndices(Experiment experiment, String key, String [] ids, boolean geneIndices) {
2 26 Feb 07 jari 738         int [] indices = null;
2 26 Feb 07 jari 739         int [] allIndices;
2 26 Feb 07 jari 740         String [] annList;
2 26 Feb 07 jari 741         Vector indicesVector = new Vector();
2 26 Feb 07 jari 742         IData data = framework.getData();
2 26 Feb 07 jari 743         
2 26 Feb 07 jari 744         if(geneIndices) {
2 26 Feb 07 jari 745             allIndices = experiment.getRowMappingArrayCopy();
2 26 Feb 07 jari 746             annList = framework.getData().getAnnotationList(key, allIndices);
2 26 Feb 07 jari 747             Vector idVector = new Vector(annList.length);
2 26 Feb 07 jari 748             for(int i = 0 ; i < ids.length; i++) {
2 26 Feb 07 jari 749                 idVector.addElement(ids[i]);
2 26 Feb 07 jari 750             }
2 26 Feb 07 jari 751             for(int i = 0; i < annList.length; i++) {
2 26 Feb 07 jari 752                 if(idVector.contains(annList[i]))
2 26 Feb 07 jari 753                     indicesVector.addElement(new Integer(allIndices[i]));
2 26 Feb 07 jari 754             }
2 26 Feb 07 jari 755             indices = new int[indicesVector.size()];
2 26 Feb 07 jari 756             for(int i = 0; i < indices.length; i++) {
2 26 Feb 07 jari 757                 indices[i] = ((Integer)(indicesVector.elementAt(i))).intValue();
2 26 Feb 07 jari 758             }
2 26 Feb 07 jari 759             
2 26 Feb 07 jari 760         } else {
2 26 Feb 07 jari 761             allIndices = experiment.getColumnIndicesCopy();
2 26 Feb 07 jari 762             annList = new String[experiment.getNumberOfSamples()];
2 26 Feb 07 jari 763             data.setSampleLabelKey(key);
2 26 Feb 07 jari 764             
2 26 Feb 07 jari 765             Vector idVector = new Vector(annList.length);
2 26 Feb 07 jari 766             for(int i = 0; i < ids.length; i++) {
2 26 Feb 07 jari 767                 idVector.addElement(ids[i]);
2 26 Feb 07 jari 768             }
2 26 Feb 07 jari 769             
2 26 Feb 07 jari 770             for(int i = 0; i < allIndices.length; i++) {
2 26 Feb 07 jari 771                 annList[i] = data.getFullSampleName(i);
2 26 Feb 07 jari 772             }
2 26 Feb 07 jari 773             
2 26 Feb 07 jari 774             for(int i = 0; i < annList.length; i++) {
2 26 Feb 07 jari 775                 if(idVector.contains(annList[i]))
2 26 Feb 07 jari 776                     indicesVector.addElement(new Integer(allIndices[i]));
2 26 Feb 07 jari 777             }
2 26 Feb 07 jari 778             
2 26 Feb 07 jari 779             indices = new int[indicesVector.size()];
2 26 Feb 07 jari 780             for(int i = 0; i < indices.length; i++) {
2 26 Feb 07 jari 781                 indices[i] = ((Integer)(indicesVector.elementAt(i))).intValue();
2 26 Feb 07 jari 782             }
2 26 Feb 07 jari 783             
2 26 Feb 07 jari 784             
2 26 Feb 07 jari 785         }
2 26 Feb 07 jari 786         return indices;
2 26 Feb 07 jari 787     }
2 26 Feb 07 jari 788     
2 26 Feb 07 jari 789     private int [] getMatchingIndices(Experiment experiment, String key, String [] ids, boolean [] matches, boolean geneIndices) {
2 26 Feb 07 jari 790         int [] indices = null;
2 26 Feb 07 jari 791         int [] allIndices;
2 26 Feb 07 jari 792         String [] annList;
2 26 Feb 07 jari 793         Vector indicesVector = new Vector();
2 26 Feb 07 jari 794         IData data = framework.getData();
2 26 Feb 07 jari 795         int idIndex;
2 26 Feb 07 jari 796         
2 26 Feb 07 jari 797         if(geneIndices) {
2 26 Feb 07 jari 798             allIndices = experiment.getRowMappingArrayCopy();
2 26 Feb 07 jari 799             annList = framework.getData().getAnnotationList(key, allIndices);
2 26 Feb 07 jari 800             Vector idVector = new Vector(annList.length);
2 26 Feb 07 jari 801             for(int i = 0 ; i < ids.length; i++) {
2 26 Feb 07 jari 802                 idVector.addElement(ids[i]);
2 26 Feb 07 jari 803             }
2 26 Feb 07 jari 804             for(int i = 0; i < annList.length; i++) {
2 26 Feb 07 jari 805                 if(idVector.contains(annList[i])) {
2 26 Feb 07 jari 806                     indicesVector.addElement(new Integer(allIndices[i]));
2 26 Feb 07 jari 807                     
2 26 Feb 07 jari 808                     //don't do this because it doesn't handle duplicate entries in the index list
2 26 Feb 07 jari 809                     //idIndex = idVector.indexOf(annList[i]);
2 26 Feb 07 jari 810                     //if(idIndex > -1 && idIndex < matches.length)
2 26 Feb 07 jari 811                     //    matches[idIndex] = true;
2 26 Feb 07 jari 812                     
2 26 Feb 07 jari 813                     //loop through to find all indices to mark all that are found
2 26 Feb 07 jari 814                     for(int j = 0; j < idVector.size(); j++) {
2 26 Feb 07 jari 815                         if(annList[i].equals((String)(idVector.elementAt(j))))
2 26 Feb 07 jari 816                             matches[j] = true;
2 26 Feb 07 jari 817                     }
2 26 Feb 07 jari 818                     
2 26 Feb 07 jari 819                 }
2 26 Feb 07 jari 820             }
2 26 Feb 07 jari 821             indices = new int[indicesVector.size()];
2 26 Feb 07 jari 822             for(int i = 0; i < indices.length; i++) {
2 26 Feb 07 jari 823                 indices[i] = ((Integer)(indicesVector.elementAt(i))).intValue();
2 26 Feb 07 jari 824             }
2 26 Feb 07 jari 825             
2 26 Feb 07 jari 826         } else {
2 26 Feb 07 jari 827             allIndices = experiment.getColumnIndicesCopy();
2 26 Feb 07 jari 828             annList = new String[experiment.getNumberOfSamples()];
2 26 Feb 07 jari 829             data.setSampleLabelKey(key);
2 26 Feb 07 jari 830             
2 26 Feb 07 jari 831             Vector idVector = new Vector(annList.length);
2 26 Feb 07 jari 832             for(int i = 0; i < ids.length; i++) {
2 26 Feb 07 jari 833                 idVector.addElement(ids[i]);
2 26 Feb 07 jari 834             }
2 26 Feb 07 jari 835             
2 26 Feb 07 jari 836             for(int i = 0; i < allIndices.length; i++) {
2 26 Feb 07 jari 837                 annList[i] = data.getFullSampleName(i);
2 26 Feb 07 jari 838             }
2 26 Feb 07 jari 839             
2 26 Feb 07 jari 840             for(int i = 0; i < annList.length; i++) {
2 26 Feb 07 jari 841                 if(idVector.contains(annList[i])) {
2 26 Feb 07 jari 842                     indicesVector.addElement(new Integer(allIndices[i]));
2 26 Feb 07 jari 843                     //loop to id all indices that match in case of duplicates, see gene section above for alt.
2 26 Feb 07 jari 844                     for(int j = 0; j < idVector.size(); j++) {
2 26 Feb 07 jari 845                         if(annList[i].equals((String)(idVector.elementAt(j))))
2 26 Feb 07 jari 846                             matches[j] = true;
2 26 Feb 07 jari 847                     }
2 26 Feb 07 jari 848                 }
2 26 Feb 07 jari 849             }
2 26 Feb 07 jari 850             
2 26 Feb 07 jari 851             indices = new int[indicesVector.size()];
2 26 Feb 07 jari 852             for(int i = 0; i < indices.length; i++) {
2 26 Feb 07 jari 853                 indices[i] = ((Integer)(indicesVector.elementAt(i))).intValue();
2 26 Feb 07 jari 854             }
2 26 Feb 07 jari 855             
2 26 Feb 07 jari 856             
2 26 Feb 07 jari 857         }
2 26 Feb 07 jari 858         return indices;
2 26 Feb 07 jari 859     }
2 26 Feb 07 jari 860     
2 26 Feb 07 jari 861     public void submitCluster( Cluster cluster ) {
2 26 Feb 07 jari 862         SubmissionManager subManager = new SubmissionManager(this.framework, this);
2 26 Feb 07 jari 863         subManager.submit(cluster);
2 26 Feb 07 jari 864     }
2 26 Feb 07 jari 865     
2 26 Feb 07 jari 866 }