示例#1
0
文件: SOTA.java 项目: SamGG/mev-tm4
  /** calculates HCL on SOTA cells (clusters) */
  private void calculateClusterHCL() throws AlgorithmException {

    AlgorithmEvent event = null;

    event =
        new AlgorithmEvent(
            this,
            AlgorithmEvent.SET_UNITS,
            numberOfClusters,
            "Calculate Hierarchical Trees SOTA Cluster Members");
    fireValueChanged(event);
    event.setIntValue(0);
    event.setId(AlgorithmEvent.PROGRESS_VALUE);
    fireValueChanged(event);

    Cluster result_cluster = new Cluster();
    NodeList nodeList = result_cluster.getNodeList();

    // clusters are formed after growSOT

    NodeList resultList = clusters.getNodeList();
    Node currNode;

    int[] probeIndexes;

    for (int i = 0; i < numberOfClusters; i++) {
      if (stop) {
        throw new AbortException();
      }
      currNode = resultList.getNode(i);
      probeIndexes = currNode.getProbesIndexes();

      Node node = new Node(probeIndexes);
      nodeList.addNode(node);

      node.setValues(
          calculateHierarchicalTree(probeIndexes, method, calculate_genes, calculate_experiments));
      event.setIntValue(i + 1);
      fireValueChanged(event);
    }

    if (result_cluster != null) inData.addCluster("hcl-result-clusters", result_cluster);
  }
示例#2
0
文件: SOTA.java 项目: SamGG/mev-tm4
  /** Calculates HCL tree over all genes */
  private void calcFullTreeHCL() throws AlgorithmException {

    AlgorithmEvent event = null;
    event =
        new AlgorithmEvent(
            this,
            AlgorithmEvent.SET_UNITS,
            1,
            "Calculate Hierarchical Tree, Clustering Experiments");
    fireValueChanged(event);
    event.setIntValue(0);
    event.setId(AlgorithmEvent.PROGRESS_VALUE);
    fireValueChanged(event);

    Cluster result_cluster = new Cluster();
    NodeList nodeList = result_cluster.getNodeList();

    int[] probesIndexes = new int[numberOfGenes];
    for (int i = 0; i < numberOfGenes; i++) {
      probesIndexes[i] = i;
    }

    int[] featuresIndexes = new int[numberOfSamples];
    for (int i = 0; i < numberOfSamples; i++) {
      featuresIndexes[i] = i;
    }

    if (stop) {
      throw new AbortException();
    }

    Node node = new Node(featuresIndexes);
    nodeList.addNode(node);

    node.setValues(calculateHierarchicalTree(probesIndexes, method, false, true));
    event.setIntValue(1);
    fireValueChanged(event);

    if (result_cluster != null) inData.addCluster("full-tree-sample-HCL", result_cluster);
  }
示例#3
0
文件: SOTA.java 项目: SamGG/mev-tm4
  // Note that leaves are threaded from left to right.
  // This means that if displayed top to bottom, centroids would be reversed
  // Therefore, accumulate in reverse order into AlgorithmData
  private void getResults() {

    SOTACell curr = head;
    int numCells = 0;
    FloatMatrix centroidFM = new FloatMatrix(numberOfClusters, numberOfSamples);
    FloatMatrix varianceFM = new FloatMatrix(numberOfClusters, numberOfSamples);

    int[] clusterSize = new int[numberOfClusters];
    FloatMatrix clusterDiversity = new FloatMatrix(numberOfClusters, 1);
    int numDiv = cycleDiversity.size();
    FloatMatrix cycleDivFM = new FloatMatrix(numDiv, 1);

    int[] clusterOrder = new int[numberOfClusters];

    clusters = new Cluster();
    NodeList nodeList = clusters.getNodeList();
    Node newNode;
    int[] clusterMembership;
    int clusterPop;

    // move to tail
    while (curr.succ != null) curr = curr.succ;

    // now curr is at the tail
    while (numCells <= numberOfClusters && curr != null) {

      for (int i = 0; i < numberOfSamples; i++) {
        centroidFM.set(numCells, i, curr.centroidGene.get(0, i));
        varianceFM.set(numCells, i, curr.getColumnVar(i));
      }
      clusterPop = curr.members.size();
      clusterSize[numCells] = clusterPop;
      clusterDiversity.set(
          numCells,
          0,
          (float) curr.cellDiversity
              * (float) myFactor); // alter poloarity by myFactor based on metric
      clusterOrder[numCells] = numCells;

      // accumulate cluster probe indicies
      clusterMembership = new int[clusterPop];
      for (int i = 0; i < clusterPop; i++) {
        clusterMembership[i] = ((Integer) (curr.members.elementAt(i))).intValue();
      }

      newNode = new Node();
      newNode.setProbesIndexes(clusterMembership);
      nodeList.addNode(newNode);

      numCells++;
      curr = curr.pred;
    }

    // now accumlate cycle divresity information
    if (myFactor == 1) {
      float initDiv = ((Float) (cycleDiversity.elementAt(0))).floatValue();
      for (int i = 0; i < numDiv; i++) {
        cycleDivFM.set(i, 0, (((Float) (cycleDiversity.elementAt(i))).floatValue()) / initDiv);
      }
    } else {
      float lowerLim = numberOfGenes * myFactor;
      float initDiv = ((Float) (cycleDiversity.elementAt(0))).floatValue() + Math.abs(lowerLim);
      for (int i = 0; i < numDiv; i++) {
        cycleDivFM.set(
            i,
            0,
            (((Float) (cycleDiversity.elementAt(i))).floatValue() + Math.abs(lowerLim)) / initDiv);
      }
    }
    // put all important information into AlgorithmData
    inData.addParam("cycles", String.valueOf(numberOfClusters));
    inData.addCluster("cluster", clusters);
    inData.addMatrix("centroid-matrix", centroidFM);
    inData.addMatrix("cluster-variances", varianceFM);
    inData.addMatrix("cluster-diversity", clusterDiversity);
    inData.addMatrix("cycle-diversity", cycleDivFM);
    inData.addIntArray("cluster-population", clusterSize);

    // Additions to AlgorithmData to allow drawing arrays
    float[] nodeHeight = new float[numberOfClusters * 2];
    int[] nodePopulation = new int[numberOfClusters * 2];
    int[] leftChild = new int[nodeHeight.length * 2];
    int[] rightChild = new int[nodeHeight.length * 2];

    initializeReturnValues(nodeHeight, nodePopulation, leftChild, rightChild);
    utilCounter = 0;
    loadReturnValues(root, 0, nodeHeight, nodePopulation, leftChild, rightChild);
    inData.addMatrix("node-heights", new FloatMatrix(nodeHeight, nodeHeight.length));
    inData.addIntArray("left-child", leftChild);
    inData.addIntArray("right-child", rightChild);
    inData.addIntArray("node-population", nodePopulation);

    if (useClusterVariance) inData.addParam("computed-var-cutoff", String.valueOf(endCriteria));
    return;
  }
示例#4
0
文件: DAMGUI.java 项目: SamGG/mev-tm4
  /** Initialize the algorithm's parameters and execute it. */
  public DefaultMutableTreeNode execute(IFramework framework) throws AlgorithmException {
    this.framework = framework;
    this.experiment = framework.getData().getExperiment();
    this.iData = framework.getData();

    Listener listener = new Listener();

    try {

      DAMInitDialog damInitDialog = new DAMInitDialog(framework.getFrame(), true);

      if (damInitDialog.showModal() != JOptionPane.OK_OPTION) {
        return null;
      }

      classifyGenes = damInitDialog.isEvaluateGenesSelected();
      algorithmSelection = damInitDialog.getAssessmentSelection();
      isPDA = damInitDialog.isPDASelected();
      numberOfClasses = damInitDialog.getNumClasses();
      kValue = damInitDialog.getKValue();
      alpha = damInitDialog.getAlphaValue();

      preSelectGenes = !(damInitDialog.getSkipGeneSelectionValue());

      DAMClassificationEditor damClassEditor =
          new DAMClassificationEditor(framework, classifyGenes, numberOfClasses);
      damClassEditor.setVisible(true);

      while (!damClassEditor.isNextPressed()) {
        if (damClassEditor.isCancelPressed()) {
          return null;
        } else {
          continue;
        }
      }

      AlgorithmData data = new AlgorithmData();

      boolean useGenes = damInitDialog.isEvaluateGenesSelected();
      if (useGenes) {
        mode = 1;
        data.addParam("dam-mode", "1");
      } else {
        mode = 3;
        data.addParam("dam-mode", "3");
      }

      classificationVector = damClassEditor.getClassification();
      trainingIndices = new int[classificationVector[0].size()];
      classes = new int[classificationVector[1].size()];
      testIndices = new int[classificationVector[2].size()];

      for (int i = 0; i < trainingIndices.length; i++) {
        trainingIndices[i] = ((Integer) (classificationVector[0].get(i))).intValue();
        classes[i] = ((Integer) (classificationVector[1].get(i))).intValue();
      }

      for (int i = 0; i < testIndices.length; i++) {
        testIndices[i] = ((Integer) (classificationVector[2].get(i))).intValue();
      }

      algorithm = framework.getAlgorithmFactory().getAlgorithm("DAM");
      algorithm.addAlgorithmListener(listener);

      logger = new Logger(framework.getFrame(), "DAM Log Window", listener);
      logger.show();
      logger.append("Starting DAM calculation\n");

      FloatMatrix Cov;
      Experiment experiment = framework.getData().getExperiment();

      if (classifyGenes) {
        // Problem here: if the program has a gene cluster (maybe also if it
        // has an experiment cluster) the matrix returned is null.
        FloatMatrix temp;
        temp = (experiment.getMatrix()).transpose();
        //                System.out.println("floatmatrix size: " + temp.m + ", " + temp.n);
        data.addMatrix("experiment", temp);

      } else {
        data.addMatrix("experiment", experiment.getMatrix());
      }

      data.addParam("distance-factor", String.valueOf(1.0f));
      IDistanceMenu menu = framework.getDistanceMenu();
      data.addParam("distance-absolute", String.valueOf(menu.isAbsoluteDistance()));

      data.addParam("algorithmSelection", String.valueOf(algorithmSelection));
      data.addParam("isPDA", String.valueOf(isPDA));
      data.addParam("preSelectGenes", String.valueOf(preSelectGenes));
      data.addParam("numberOfClasses", String.valueOf(numberOfClasses));
      data.addParam("kValue", String.valueOf(kValue));
      data.addParam("alpha", String.valueOf(alpha));

      data.addIntArray("trainingIndices", trainingIndices);
      data.addIntArray("classes", classes);
      data.addIntArray("testIndices", testIndices);

      int function = menu.getDistanceFunction();
      if (function == Algorithm.DEFAULT) {
        function = Algorithm.COVARIANCE;
      }
      data.addParam("distance-function", String.valueOf(function));
      data.addParam("dam-mode", String.valueOf(mode));

      AlgorithmData result = null;
      DefaultMutableTreeNode node = null;
      long start = System.currentTimeMillis();
      switch (mode) {
        case 1: // Spots
          data.addParam("distance-function", String.valueOf(function));
          result = algorithm.execute(data);
          matrixS = result.getMatrix("S");
          matrix3D = result.getMatrix("matrix3D");
          usedGeneIndices = result.getIntArray("usedGeneIndices");
          unusedGeneIndices = result.getIntArray("unusedGeneIndices");
          node = new DefaultMutableTreeNode("DAM - genes");
          break;
        case 3: // Experiments
          result = algorithm.execute(data);
          matrixS = result.getMatrix("S");
          matrix3D = result.getMatrix("matrix3D");
          usedGeneIndices = result.getIntArray("usedGeneIndices");
          unusedGeneIndices = result.getIntArray("unusedGeneIndices");

          /*
                      if (preSelectGenes) {
                          System.out.println("DAMGUI.java: usedGeneIndices size: " + usedGeneIndices.length);
                          for(int i=0; i< usedGeneIndices.length; i++) {
                              System.out.print(usedGeneIndices[i] + ", ");
                          }
                          System.out.println(" ");
                          System.out.println(" ");
                          System.out.println("DAMGUI.java: unusedGeneIndices size: " + unusedGeneIndices.length);
                          for(int i=0; i< unusedGeneIndices.length; i++) {
                              System.out.print(unusedGeneIndices[i] + ", ");
                          }
                          System.out.println(" ");
                          System.out.println(" ");
                      }
          */

          node = new DefaultMutableTreeNode("DAM - samples");
          break;
        default:
          break;
      }

      Cluster result_cluster = result.getCluster("cluster");
      NodeList nodeList = result_cluster.getNodeList();

      int k = numberOfClasses * 3;
      this.clusters = new int[k][];

      //          System.out.println(" ");
      for (int i = 0; i < k; i++) {
        clusters[i] = nodeList.getNode(i).getFeaturesIndexes();
      }

      Cluster gene_cluster = result.getCluster("geneCluster");
      nodeList = gene_cluster.getNodeList();

      this.geneClusters = new int[2][];

      //          System.out.println(" ");
      for (int i = 0; i < 2; i++) {
        geneClusters[i] = nodeList.getNode(i).getFeaturesIndexes();
      }

      this.means = result.getMatrix("clusters_means");
      this.variances = result.getMatrix("clusters_variances");

      this.means_used = result.getMatrix("clusters_means_used");
      this.variances_used = result.getMatrix("clusters_variances_used");

      this.means_unused = result.getMatrix("clusters_means_unused");
      this.variances_unused = result.getMatrix("clusters_variances_unused");

      columns = new int[(experiment.getMatrix()).getColumnDimension()];
      for (int i = 0; i < columns.length; i++) {
        columns[i] = i;
      }

      rows = new int[(experiment.getMatrix()).getRowDimension()];
      for (int i = 0; i < rows.length; i++) {
        rows[i] = i;
      }

      if (classifyGenes) {
        usedExperiment =
            new Experiment(
                (experiment.getMatrix()).getMatrix(rows, usedGeneIndices), usedGeneIndices, rows);
        unusedExperiment =
            new Experiment(
                (experiment.getMatrix()).getMatrix(rows, unusedGeneIndices),
                unusedGeneIndices,
                rows);
      } else {
        usedExperiment =
            new Experiment(
                (experiment.getMatrix()).getMatrix(usedGeneIndices, columns),
                columns,
                usedGeneIndices);
        unusedExperiment =
            new Experiment(
                (experiment.getMatrix()).getMatrix(unusedGeneIndices, columns),
                columns,
                unusedGeneIndices);
      }

      /*
                     System.out.println("DAMGUI.java - means: " + means.getRowDimension() + " X " + means.getColumnDimension());
                     System.out.println("DAMGUI.java - variances: " + variances.getRowDimension() + " X " + variances.getColumnDimension());

                     System.out.println("DAMGUI.java - matrix3D " + matrix3D.getRowDimension() + " X " + matrix3D.getColumnDimension());
                     for(int i=0; i< matrix3D.getRowDimension(); i++) {
                         for(int j=0; j< matrix3D.getColumnDimension(); j++) {
                             System.out.print(matrix3D.get(i, j) + ", ");
                         }
                         System.out.println(" ");
                     }
      */

      logger.append("Creating the result viewers\n");
      long time = System.currentTimeMillis() - start;
      if (algorithmSelection == A3) // only classification
      addClassificationResultNodes(
            framework.getFrame(), node, time, menu.getFunctionName(function), experiment);
      else
        addValidationResultNodes(
            framework.getFrame(), node, time, menu.getFunctionName(function), experiment);

      return node;
    } finally {
      if (algorithm != null) {
        algorithm.removeAlgorithmListener(listener);
      }
      if (logger != null) {
        logger.dispose();
      }
    }
  }