Exemple #1
0
  public AlgorithmData getScriptParameters(IFramework framework) {

    this.experiment = framework.getData().getExperiment();
    exptNamesVector = new Vector<String>();
    int number_of_samples = experiment.getNumberOfSamples();
    // int number_of_genes = experiment.getNumberOfGenes();

    for (int i = 0; i < number_of_samples; i++) {
      exptNamesVector.add(framework.getData().getFullSampleName(experiment.getSampleIndex(i)));
    }

    DEGseqInitBox DEGseqDialog =
        new DEGseqInitBox(
            (JFrame) framework.getFrame(), true, exptNamesVector, framework.getClusterRepository(1)
            // framework.getClusterRepository(0)
            );
    DEGseqDialog.setVisible(true);

    if (!DEGseqDialog.isOkPressed()) return null;

    if (DEGseqDialog.getTestDesign() == DEGseqInitBox.TWO_CLASS) {
      if (DEGseqDialog.getSelectionDesign() == DEGseqInitBox.CLUSTER_SELECTION) {
        groupAssignments = DEGseqDialog.getClusterTwoClassAssignments();
      }
      if (DEGseqDialog.getSelectionDesign() == DEGseqInitBox.BUTTON_SELECTION) {
        groupAssignments = DEGseqDialog.getTwoClassAssignments();
      }
    }

    AlgorithmData data = new AlgorithmData();

    // alg name
    data.addParam("name", "DESeq");

    // alg type
    data.addParam("alg-type", "data-visualization");

    // output class
    data.addParam("output-class", "partition-output");

    // output nodes
    String[] outputNodes = new String[2];
    outputNodes[0] = "Significant Genes";
    outputNodes[1] = "Non-significant Genes";

    data.addStringArray("output-nodes", outputNodes);

    return data;
  }
Exemple #2
0
  public DefaultMutableTreeNode executeScript(
      IFramework framework, AlgorithmData algData, Experiment experiment)
      throws AlgorithmException {

    Listener listener = new Listener();
    this.experiment = experiment;
    this.data = framework.getData();
    // this.timeAssignments = algData.getIntArray("time_assignments");
    this.groupAssignments = algData.getIntArray("condition_assignments");

    exptNamesVector = new Vector<String>();
    int number_of_samples = experiment.getNumberOfSamples();

    for (int i = 0; i < number_of_samples; i++) {
      exptNamesVector.add(this.data.getFullSampleName(i));
    }

    try {
      algData.addMatrix("experiment", experiment.getMatrix());
      algorithm = framework.getAlgorithmFactory().getAlgorithm("MINET");
      algorithm.addAlgorithmListener(listener);

      this.progress = new Progress(framework.getFrame(), "Running MINET Analysis...", listener);
      this.progress.show();

      long start = System.currentTimeMillis();
      AlgorithmData result = algorithm.execute(algData);
      long time = System.currentTimeMillis() - start;

      AlgorithmParameters params = algData.getParams();

      GeneralInfo info = new GeneralInfo();
      return createResultTree(info);

    } finally {
      if (algorithm != null) {
        algorithm.removeAlgorithmListener(listener);
      }
      if (progress != null) {
        progress.dispose();
      }
    }
  }
Exemple #3
0
  /**
   * This method should return a tree with calculation results or null, if analysis start was
   * canceled.
   *
   * @param framework the reference to <code>IFramework</code> implementation, which is used to
   *     obtain an initial analysis data and parameters.
   * @throws AlgorithmException if calculation was failed.
   * @throws AbortException if calculation was canceled.
   * @see IFramework
   */
  public DefaultMutableTreeNode execute(IFramework framework) throws AlgorithmException {
    if (sysMsg("R 2.11.x", "DEGSeq") != JOptionPane.OK_OPTION) return null;
    this.data = framework.getData();
    exptNamesVector = new Vector<String>();
    for (int i = 0; i < this.data.getFeaturesCount(); i++) {
      exptNamesVector.add(framework.getData().getFullSampleName(i));
    }

    DEGseqInitBox DEGseqDialog =
        new DEGseqInitBox(
            (JFrame) framework.getFrame(),
            true,
            exptNamesVector,
            framework.getClusterRepository(1));
    DEGseqDialog.setVisible(true);

    if (!DEGseqDialog.isOkPressed()) return null;

    infMethod = DEGseqDialog.getMethodName();
    sigMethod = DEGseqDialog.getCutOffField();
    sigCutOff = DEGseqDialog.getPValue();
    dataDesign = DEGseqDialog.getTestDesign();

    if (DEGseqDialog.getTestDesign() == DEGseqInitBox.TWO_CLASS) {
      groupAssignments = DEGseqDialog.getTwoClassAssignments();
      if (DEGseqDialog.getSelectionDesign() == DEGseqInitBox.CLUSTER_SELECTION) {
        groupAssignments = DEGseqDialog.getClusterTwoClassAssignments();
      }
      if (DEGseqDialog.getSelectionDesign() == DEGseqInitBox.BUTTON_SELECTION) {
        groupAssignments = DEGseqDialog.getTwoClassAssignments();
      }
    }

    // count # of samples used in analysis
    int samplesUsed = 0;
    for (int i = 0; i < groupAssignments.length; i++) {
      if (groupAssignments[i] != 0) samplesUsed++;
    }
    // get samples indices used
    int sampleIndices[] = new int[samplesUsed];
    for (int i = 0, ii = 0; i < groupAssignments.length; i++) {
      if (groupAssignments[i] != 0) sampleIndices[ii++] = i;
    }

    // set up the group struct for algo
    int[] twoClassGrps = new int[samplesUsed];
    for (int i = 0, ii = 0; i < groupAssignments.length; i++) {
      if (groupAssignments[i] != 0) twoClassGrps[ii++] = groupAssignments[i];
    }

    // Test
    int grp1 = 0;
    int grp2 = 0;
    String grp1ColIndStr = "";
    String grp2ColIndStr = "";
    for (int i = 0; i < twoClassGrps.length; i++) {
      if (twoClassGrps[i] == 1) {
        grp1++;
        grp1ColIndStr += String.valueOf(i + 2) + ","; // 1 for 0 based index, 1 for UID col in file
      }
      if (twoClassGrps[i] == 2) {
        grp2++;
        grp2ColIndStr += String.valueOf(i + 2) + ",";
      }
    }
    // remove last ","
    grp1ColIndStr = grp1ColIndStr.substring(0, grp1ColIndStr.lastIndexOf(","));
    grp2ColIndStr = grp2ColIndStr.substring(0, grp2ColIndStr.lastIndexOf(","));

    System.out.println("groupAssignments: " + Arrays.toString(groupAssignments));
    System.out.println("twoClassGrps: " + Arrays.toString(twoClassGrps));
    System.out.println(
        samplesUsed
            + " out of "
            + groupAssignments.length
            + " used. Sample indices: "
            + Arrays.toString(sampleIndices));
    System.out.println("grp1ColInd: " + grp1ColIndStr);
    System.out.println("grp2ColInd: " + grp2ColIndStr);

    this.experiment = framework.getData().getExperiment();
    // int number_of_samples = this.data.getFeaturesCount();//experiment.getNumberOfSamples();
    // int [] columnIndices = experiment.getColumnIndicesCopy();

    sampleLabels = new ArrayList<String>();
    geneLabels = new ArrayList<String>();
    for (int i = 0; i < samplesUsed; i++) {
      sampleLabels.add(framework.getData().getFullSampleName(sampleIndices[i])); // Raktim
    }

    // Raktim Use probe index as the gene labels in R
    for (int i = 0; i < this.data.getFeaturesSize(); /*experiment.getNumberOfGenes();*/ i++) {
      // geneLabels.add(framework.getData().getElementAnnotation(i,
      // AnnotationFieldConstants.PROBE_ID)[0]); //Raktim
      geneLabels.add(String.valueOf(i));
    }

    // Make Count Matrix  based on data
    int numGenes = this.data.getFeaturesSize();
    System.out.println(
        "data.getFeaturesCount(): "
            + this.data.getFeaturesCount()
            + " data.getFeaturesSize(): "
            + this.data.getFeaturesSize());
    ArrayList<IRNASeqSlide> temp = (ArrayList<IRNASeqSlide>) data.getFeaturesList();
    // TEst Code from EH
    RNASeqChipAnnotation chipAnnotation = (RNASeqChipAnnotation) data.getChipAnnotation();
    System.out.println("Library size, first sample: " + temp.get(0).getLibrarySize());
    System.out.println("Library size, last sample: " + temp.get(temp.size() - 1).getLibrarySize());
    System.out.println("\n");

    System.out.println("Read length: " + chipAnnotation.getReadLength());
    System.out.println("\n");

    System.out.println("first count value for first slide: " + temp.get(0).getCount(0));
    System.out.println(
        "last count value for first slide: " + temp.get(0).getCount(temp.get(0).getSize() - 1));
    System.out.println("\n");

    System.out.println(
        "first count value for last slide: " + temp.get(temp.size() - 1).getCount(0));
    System.out.println(
        "last count value for last slide: "
            + temp.get(temp.size() - 1).getCount(temp.get(0).getSize() - 1));
    System.out.println("\n");

    System.out.println(
        "transcript length 0,0: "
            + ((RNASeqElement) (temp.get(0).getSlideDataElement(0))).getTranscriptLength());
    System.out.println(
        "classcode for  0,0: "
            + ((RNASeqElement) (temp.get(0).getSlideDataElement(0))).getClasscode());
    // End EH Test Code

    // My test code
    // System.out.println("transcript length 0,0: " +
    // ((RNASeqElement)(temp.get(0).getSlideDataElement(9))).getTranscriptLength());
    // System.out.println("classcode for  0,0: " +
    // ((RNASeqElement)(temp.get(0).getSlideDataElement(9))).getClasscode());
    // End my test code

    /** ArrayList<IRNASeqSlide> temp = (ArrayList<IRNASeqSlide>)data.getFeaturesList(); */
    int[][] countMatrix = new int[numGenes][samplesUsed];
    int[] libSize = new int[samplesUsed];
    for (int row = 0; row < numGenes; row++) {
      for (int col = 0; col < sampleIndices.length; col++) {
        // get count value
        countMatrix[row][col] = temp.get(sampleIndices[col]).getCount(row);
      }
      // get transcript len for each gene
      // transcriptLen[row] =
      // ((RNASeqElement)(temp.get(row).getSlideDataElement(row))).getTranscriptLength();
      // transcriptLen[row] =
      // ((RNASeqElement)(temp.get(0).getSlideDataElement(row))).getTranscriptLength();
    }

    // get lib size for each sample used
    for (int col = 0; col < sampleIndices.length; col++) {
      // get count value
      libSize[col] = temp.get(sampleIndices[col]).getLibrarySize();
    }

    // System.out.println("CountMatrix: " + Arrays.deepToString(countMatrix));
    // System.out.println("transcriptLen: " + Arrays.toString(transcriptLen));
    // System.out.println("libSize: " + Arrays.toString(libSize));

    Listener listener = new Listener();

    try {
      algorithm = framework.getAlgorithmFactory().getAlgorithm("DEGSEQ");
      algorithm.addAlgorithmListener(listener);

      this.progress = new Progress(framework.getFrame(), "Running DEGseq ...", listener);
      this.progress.show();

      AlgorithmData data = new AlgorithmData();

      data.addIntMatrix("experiment", countMatrix);
      data.addParam("dataDesign", String.valueOf(dataDesign));
      data.addIntArray("group_assignments", twoClassGrps);
      data.addParam("grp1ColIndStr", grp1ColIndStr);
      data.addParam("grp2ColIndStr", grp2ColIndStr);
      data.addIntArray("libSize", libSize);
      data.addParam("numGenes", String.valueOf(numGenes));
      data.addParam("numExps", String.valueOf(samplesUsed));
      data.addParam("grp1", String.valueOf(grp1));
      data.addParam("grp2", String.valueOf(grp2));
      data.addParam("infMethod", infMethod);
      data.addStringArray("geneLabels", geneLabels.toArray(new String[geneLabels.size()]));
      data.addStringArray("sampleLabels", sampleLabels.toArray(new String[sampleLabels.size()]));

      // run algorithm
      long start = System.currentTimeMillis();
      AlgorithmData result = algorithm.execute(data);
      long time = System.currentTimeMillis() - start;

      // getting the results
      resultMatrix = result.getMatrix("result");
      resultRowNames = result.getStringArray("rownames");
      // System.out.println(Arrays.toString(resultRowNames));
      // Process results
      createHeaderNames();
      createAuxData();
      createResultClusters();

      GeneralInfo info = new GeneralInfo();
      info.time = time;

      System.out.println("Creating Viewers for DEGSeq...");
      return createResultTree(info);

    } finally {
      if (algorithm != null) {
        algorithm.removeAlgorithmListener(listener);
      }
      if (progress != null) {
        progress.dispose();
      }
    }
  }
Exemple #4
0
  /** 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();
      }
    }
  }