Esempio n. 1
0
  /**
   * Called from bicat.gui.window.GenePairAnalysis
   *
   * @throws Exception
   */
  public void genePairAnalysis(
      int data, int list, int idx, int minCoocScore, int minCommonScore, boolean byCooc)
      throws Exception {

    Dataset BcR = (Dataset) engine.getDatasetList().get(data);
    LinkedList biclusterList = (LinkedList) BcR.getBCsList(list).get(idx);

    HashMap gpa = new HashMap();

    if (engine.isDebug()) {
      System.out.println("Starting gene pair analysis ...");
      System.out.println("Hashmap for biclusterList: " + biclusterList.toString());
    }

    if (byCooc) gpa = gpaByCoocurrence(biclusterList, minCoocScore, BcR);
    else gpa = gpaByCommonChips(biclusterList, minCommonScore);

    if (engine.isDebug()) System.out.println("Hashmap size for gpa: " + gpa.size());
    // do management ...
    BcR.updateAnalysisBiclustersLists(gpa, list, idx);

    if (owner != null) {
      owner.updateAnalysisMenu();
      owner.buildTree();

      owner.getTree().setSelectionPath(owner.getPreprocessedPath());
      owner.getTree().setSelectionPath(owner.getPreprocessedPath());
      int row = owner.getTree().getRowCount() - 1;
      while (row >= 0) {
        owner.getTree().collapseRow(row);
        row--;
      }
    }
  }
Esempio n. 2
0
  /** Called from bicat.gui.window.Filter */
  public void filter(
      int data, int list, int idx, int minG, int maxG, int minC, int maxC, int nrBCs, int overlap) {

    if (engine.isDebug()) System.out.println("Starting filter ...");

    Dataset BcR = (Dataset) engine.getDatasetList().get(data);

    LinkedList biclusterList = (LinkedList) BcR.getBCsList(list).get(idx);
    int limit_G = BcR.getGeneCount();
    int limit_C = BcR.getWorkingChipCount();

    biclusterList = filterBySize(biclusterList, minG, maxG, minC, maxC, limit_G, limit_C);
    biclusterList = filterByOverlap(biclusterList, nrBCs, overlap);

    // do management ...
    BcR.updateFilterBiclustersLists(biclusterList, list, idx);

    if (owner != null) {
      owner.updateFilterMenu();
      owner.buildTree();

      owner.getTree().setSelectionPath(owner.getPreprocessedPath());
      int row = owner.getTree().getRowCount() - 1;
      while (row >= 0) {
        owner.getTree().collapseRow(row);
        row--;
      }
    }
  }
Esempio n. 3
0
  /** Called from bicat.gui.window.Search */
  public void search(int data, int list, int idx, String genes, String chips, boolean andSearch) {

    if (engine.isDebug()) System.out.println("Starting search ...");

    Dataset BcR = (Dataset) engine.getDatasetList().get(data);
    LinkedList biclusterList = (LinkedList) BcR.getBCsList(list).get(idx);

    biclusterList = search(biclusterList, genes, chips, andSearch);

    // do management ...
    BcR.updateSearchBiclustersLists(biclusterList, list, idx);

    if (owner != null) {
      owner.updateSearchMenu();
      owner.buildTree();

      owner.getTree().setSelectionPath(owner.getPreprocessedPath());
      owner.getTree().setSelectionPath(owner.getPreprocessedPath());
      int row = owner.getTree().getRowCount() - 1;
      while (row >= 0) {
        owner.getTree().collapseRow(row);
        row--;
      }
    }
  }
Esempio n. 4
0
  /**
   * First dim (data.length) is the number of items to cluster. Dementspreched is the second dim
   * (data[0].length) number of attributes.
   *
   * <p>Add the labeling management. + Outputting (joins)
   *
   * <p>OUTPUT format: C.nr_joins.dist\n L x1 L x2
   *
   * <p>C.nr_joins.dist\n L x3 C N1 ...
   *
   * @param distMetr
   */
  public void runAgglomerative(float[][] data, int distMetr) {

    StringBuffer sb = new StringBuffer(); // at the end, write it OUT
    distance_metric = distMetr;
    int nr_genes = data.length;
    int nr_joins = 0; // numbering of clusters begins @ 1
    int[] back_translation = new int[nr_genes]; // current L idx -> original
    Vector clusters = new Vector(); // contains extended view of the
    // clusters, as they are created

    if (DEBUG) System.out.println("nr_items = " + nr_genes);

    // INIT: compute the distance matrix, and create the singletons:
    double[][] distance_matrix = new double[nr_genes][nr_genes];
    if (MethodConstants.debug) System.out.println("The distance metric is: " + distance_metric);

    for (int i = 0; i < nr_genes; i++) {
      distance_matrix[i][i] = 0.0;
      for (int j = i + 1; j < nr_genes; j++) {

        switch (distance_metric) {
          case MethodConstants.EUCLIDEAN_DISTANCE:
            distance_matrix[i][j] = Util.computeEuclideanDistance(data[i], data[j]);
            break;

          case MethodConstants.PEARSON_CORRELATION:
            distance_matrix[i][j] = Util.computePearsonCorrelationDistance(data[i], data[j]);
            break;

          case MethodConstants.MANHATTAN_DISTANCE:
            distance_matrix[i][j] = Util.computeManhattanDistance(data[i], data[j]);
            break;

          case MethodConstants.MINKOWSKI_DISTANCE:
            distance_matrix[i][j] = Util.computeMinkowskiDistance(data[i], data[j]);
            break;

          case MethodConstants.COSINE_DISTANCE:
            distance_matrix[i][j] = Util.computeCosineDistance(data[i], data[j]);
            break;

          default:
            break; /* not foreseen */
        }

        distance_matrix[j][i] = distance_matrix[i][j];
        if (MethodConstants.debug)
          System.out.println(
              "i: " + i + " j: " + j + " distance Matrix[i][j]: " + distance_matrix[i][j]);
      }
    }

    Vector cluster_idxs = new Vector();
    for (int i = 0; i < nr_genes; i++) {
      int[] cl = new int[1];
      cl[0] = i;
      cluster_idxs.add(cl);
    }

    Vector cluster_dists = new Vector();
    for (int i = 0; i < nr_genes; i++) {
      Vector distance_vector = new Vector();
      for (int j = 0; j < nr_genes; j++) distance_vector.add(new Double(distance_matrix[i][j]));
      cluster_dists.add(distance_vector);
    }

    for (int i = 0; i < nr_genes; i++) {
      back_translation[i] = i;
    }

    while (cluster_idxs.size() > N) {

      // 2. merge (into) clusters
      int[] idxs = findMinDistancePair(cluster_dists); // 2 (i,j)

      // if(DEBUG) System.out.println("cl_dists size = " +
      // cluster_dists.size());

      int[] cl_1 = (int[]) cluster_idxs.get(idxs[0]);
      int[] cl_2 = (int[]) cluster_idxs.get(idxs[1]);

      if (DEBUG) {
        if (idxs[0] >= idxs[1]) {
          System.out.println("ATTENTION: idxs[0] >= idxs[1] ");
        }
      }
      // --- Management Ops:
      nr_joins++;
      sb.append("C " + nr_joins + " " + curr_distance + " ");
      if (((int[]) cluster_idxs.get(idxs[0])).length == 1) // sb.append("L
      sb.append("L " + back_translation[idxs[0]] + " ");
      else {
        int[] cl_0 = ((int[]) cluster_idxs.get(idxs[0]));
        int N = findClusterIdx(cl_0, clusters);
        sb.append("C " + N + " "); // \n");
      }
      if (((int[]) cluster_idxs.get(idxs[1])).length == 1)
        sb.append("L " + back_translation[idxs[1]] + " "); // \n\n");
      else {
        int[] cl_0 = ((int[]) cluster_idxs.get(idxs[1]));
        int N = findClusterIdx(cl_0, clusters);
        sb.append("C " + N + " "); // \n\n");
      }

      Vector new_cl = new Vector();
      int[] new_arr = appendArrays(cl_1, cl_2);
      for (int i = 0; i < new_arr.length; i++) new_cl.add(new Integer(new_arr[i]));
      clusters.add(new_cl); // its idx is -1 of the ""official"" idx

      cluster_idxs.remove(idxs[1]);
      cluster_idxs.set(idxs[0], appendArrays(cl_1, cl_2));

      // mngmt op:
      for (int j = idxs[1]; j < cluster_idxs.size(); j++)
        back_translation[j] = back_translation[j + 1];
      for (int j = cluster_idxs.size(); j < nr_genes; j++) back_translation[j] = -1;

      // 3. recompute the distances
      for (int j = 0; j < cluster_idxs.size(); j++) {
        switch (linkage_method) {
          case MethodConstants.SINGLE_LINKAGE:
            ((Vector) cluster_dists.get(idxs[0]))
                .set(
                    j,
                    min(
                        (Double) ((Vector) cluster_dists.get(idxs[0])).get(j),
                        (Double) ((Vector) cluster_dists.get(idxs[1])).get(j)));
            break;

          case MethodConstants.COMPLETE_LINKAGE:
            ((Vector) cluster_dists.get(idxs[0]))
                .set(
                    j,
                    max(
                        (Double) ((Vector) cluster_dists.get(idxs[0])).get(j),
                        (Double) ((Vector) cluster_dists.get(idxs[1])).get(j)));
            break;

          case MethodConstants.AVERAGE_LINKAGE:
            ((Vector) cluster_dists.get(idxs[0]))
                .set(
                    j,
                    avg(
                        (Double) ((Vector) cluster_dists.get(idxs[0])).get(j),
                        (Double) ((Vector) cluster_dists.get(idxs[1])).get(j),
                        cl_1.length,
                        cl_2.length));
            break;

          default:
            break; /* not foreseen! */
        }
      }
      for (int i = 0; i <= cluster_idxs.size(); i++)
        ((Vector) cluster_dists.get(i)).remove(idxs[1]);

      cluster_dists.remove(idxs[1]);

      for (int i = 0; i < cluster_idxs.size(); i++) {
        if (i != idxs[0])
          ((Vector) cluster_dists.get(i))
              .set(idxs[0], ((Vector) cluster_dists.get(idxs[0])).get(i));
      }

      // repeat 2 and 3 until all items are in a single cluster
    }

    HCL_output = sb.toString();

    if (MethodConstants.debug)
      System.out.println("nr_items, nr_joins: " + nr_genes + ", " + nr_joins);

    System.out.println("Here and GUI is : " + owner + ", and engine is : " + engine);
    int[] chipsTemplate = new int[engine.getPre().getWorkingChipCount()];
    System.out.println("lenght of array is : " + chipsTemplate.length);
    for (int i = 0; i < chipsTemplate.length; i++) chipsTemplate[i] = i;

    // ....
    quasi_bi_clusters = new LinkedList();
    for (int i = 0; i < cluster_idxs.size(); i++) {

      int[] genes = (int[]) cluster_idxs.get(i);
      int[] chips = chipsTemplate.clone();
      bicat.biclustering.Bicluster bc = new bicat.biclustering.Bicluster(i + 1, genes, chips);
      quasi_bi_clusters.add(bc);
    }
    if (engine == null) System.out.println("Engine is null!");

    engine.setData(engine.getPre().getPreprocessedData());
    if (owner != null) {
      owner.getPp().setData(engine.getRawData());
      int[] temp = (int[]) cluster_idxs.get(0);
      bicat.biclustering.Bicluster selection =
          new bicat.biclustering.Bicluster(0, temp.clone(), chipsTemplate);
      engine.setCurrentBiclusterSelection(owner.getPp().setTranslationTable(selection));

      owner.getMatrixScrollPane().repaint();
      owner.readjustPictureSize();
      owner.getPp().repaint();
    }
  }