/** Invoked by the framework when this viewer is selected. */ public void onSelected(IFramework framework) { geneClusterCB.removeAllItems(); for (int i = 0; i < framework.getClusterRepository(0).size(); i++) { if (framework.getClusterRepository(0).getCluster(i + 1) == null) break; Cluster cluster = framework.getClusterRepository(0).getCluster(i + 1); geneClusterCB.addItem( "Cluster #: " + cluster.getSerialNumber() + ", " + cluster.getClusterLabel()); } }
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; }
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(); } } }
/** * Constructs a <code>Box/Bar Chart Viewer</code> for insertion into ClusterTable * * @param experiment the data of an experiment. */ public BoxChartViewer(IFramework fm, Cluster[] clusterArray) { inAnalysis = false; framework = fm; this.experiment = framework.getData().getExperiment(); setClusters(clusterArray); populateGeneListComboBoxes(); generateSettingsComponents(); createComponentLayout(); init(); }
private void populateGeneListComboBoxes() { geneClusterCB = new JComboBox(); geneClusterCB.removeAllItems(); for (int i = 0; i < framework.getClusterRepository(0).size(); i++) { if (framework.getClusterRepository(0).getCluster(i + 1) == null) break; Cluster cluster = framework.getClusterRepository(0).getCluster(i + 1); geneClusterCB.addItem( "Cluster #: " + cluster.getSerialNumber() + ", " + cluster.getClusterLabel()); } geneClusterCB.setVisible(false); geneClusterCB.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { repaint(); } }); geneAnnotationCB = new JComboBox(framework.getData().getAllFilledAnnotationFields()); geneAnnotationCB.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { if (chartTypeCB.getSelectedIndex() > 1) // this method only applies for single gene return; geneCB.removeAllItems(); int selected = Math.max(geneAnnotationCB.getSelectedIndex(), 0); int numGenes = framework .getData() .getAnnotationList(framework.getData().getAllFilledAnnotationFields()[selected]) .length; StringExt[] stringext = new StringExt[numGenes]; String[] geneNames = framework .getData() .getAnnotationList( framework.getData().getAllFilledAnnotationFields()[selected]); for (int i = 0; i < numGenes; i++) stringext[i] = new StringExt(geneNames[i]); DefaultComboBoxModel cbm = new DefaultComboBoxModel(stringext); geneCB.setModel(cbm); } }); geneCB = new JComboBox( framework .getData() .getAnnotationList(framework.getData().getAllFilledAnnotationFields()[0])); geneCB.setMaximumSize(new Dimension(150, geneCB.getHeight())); geneCB.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { repaint(); } }); }
/** * Constructs a <code>Box/Bar Chart Viewer</code> for use in analyses * * @param experiment the data of an experiment. */ public BoxChartViewer( IFramework fm, int[][] sampleArray, int[] geneArray, String geneClusterLabel, String[] sampleClusterNames) { this.sampleClusterNames = sampleClusterNames; inAnalysis = true; framework = fm; this.geneClusterLabel = geneClusterLabel; this.experiment = framework.getData().getExperiment(); setClusters(sampleArray); geneIndices = geneArray; populateGeneListComboBoxes(); generateSettingsComponents(); createComponentLayout(); init(); }
/** * 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(); } } }
public void paint(Graphics g) { super.paint(g); if (clusterCount == 0) return; boolean ismultigene = !isSingleGene; Graphics2D g2 = (Graphics2D) g; multigeneCount = 1; Cluster cluster = null; if (ismultigene) { try { if (!inAnalysis) { int begin = geneClusterCB.getSelectedItem().toString().indexOf(":"); int end = geneClusterCB.getSelectedItem().toString().indexOf(","); sn = geneClusterCB.getSelectedItem().toString().substring(begin + 2, end); cluster = framework.getClusterRepository(0).getCluster(Integer.parseInt(sn)); geneIndices = cluster.getIndices(); } } catch (Exception e) { e.printStackTrace(); System.out.println("Gene Cluster Problem"); return; } if (geneIndices == null || geneIndices.length < 1) return; if (aggregateGeneCluster) multigeneCount = 1; else multigeneCount = geneIndices.length; } int chartTop = chartTopHeight; lowerOutliers = new float[multigeneCount][][]; upperOutliers = new float[multigeneCount][][]; expressionSDs = new float[multigeneCount][]; expressionAverages = new float[multigeneCount][]; expressionMedian = new float[multigeneCount][]; expressionQ1 = new float[multigeneCount][]; expressionQ3 = new float[multigeneCount][]; expressionIQR = new float[multigeneCount][]; expressionLowerWhisker = new float[multigeneCount][]; expressionUpperWhisker = new float[multigeneCount][]; chartTitles = new String[multigeneCount]; int maxString = 0; for (int i = 0; i < clusterNames.length; i++) { maxString = Math.max(maxString, g.getFontMetrics().stringWidth(clusterNames[i])); } chartGap = maxString + 50; // for only drawing the visible area- dramatic speed improvements Rectangle bounds = g.getClipBounds(); int indexBegin = (int) Math.max(-3 + bounds.y / (chartHeight + chartGap), 0f); int indexEnd = (int) Math.min(multigeneCount, 3 + (bounds.y + bounds.height) / (chartHeight + chartGap)); for (int multigeneIndex = indexBegin; multigeneIndex < indexEnd; multigeneIndex++) { if (ismultigene) { if (aggregateGeneCluster) { getChartData(geneIndices, multigeneIndex); if (inAnalysis) chartTitles[multigeneIndex] = geneClusterLabel; else chartTitles[multigeneIndex] = cluster.getClusterLabel(); } else { getChartData(geneIndices[multigeneIndex], multigeneIndex); chartTitles[multigeneIndex] = framework.getData() .getElementAnnotation( geneIndices[multigeneIndex], framework.getData().getFieldNames()[0])[0]; } } else { getChartData(geneCB.getSelectedIndex(), multigeneIndex); chartTitles[multigeneIndex] = geneCB.getSelectedItem().toString(); } float maxHeight = 0; float minHeight = Float.POSITIVE_INFINITY; for (int i = 0; i < clusterCount; i++) { if (this.isBoxPlot) { for (int j = 0; j < this.upperOutliers[multigeneIndex][i].length; j++) { maxHeight = Math.max(upperOutliers[multigeneIndex][i][j], maxHeight); } maxHeight = Math.max(expressionUpperWhisker[multigeneIndex][i], maxHeight); } else { maxHeight = Math.max( expressionAverages[multigeneIndex][i] + this.expressionSDs[multigeneIndex][i], maxHeight); } } for (int i = 0; i < clusterCount; i++) { if (this.isBoxPlot) { for (int j = 0; j < this.lowerOutliers[multigeneIndex][i].length; j++) { minHeight = Math.min(lowerOutliers[multigeneIndex][i][j], minHeight); } minHeight = Math.min(expressionLowerWhisker[multigeneIndex][i], minHeight); } else minHeight = 0f; // Math.min(expressionAverages[i], minHeight); } maxHeight++; float topgridline; float bottomgridline; if (this.autoScale) { topgridline = (int) maxHeight + (int) maxHeight % 2; bottomgridline = (int) minHeight - (int) minHeight % 2 - 2; if (!isBoxPlot) bottomgridline = 0f; fixedTop = topgridline; fixedBottom = bottomgridline; } else { topgridline = fixedTop; bottomgridline = fixedBottom; if (!isBoxPlot) bottomgridline = 0f; } float gridrange = topgridline - bottomgridline; // draw everything // grid g2.setColor(Color.black); g2.drawLine( chartleft - 5, chartHeight + chartTop, chartleft + clusterCount * chartIncrement, chartHeight + chartTop); // horizontal line bottom g2.drawLine(chartleft, chartTop, chartleft, chartHeight + chartTop + 5); // vertical line left g2.setColor(Color.gray); g2.drawLine(chartleft - 7, chartTop, chartleft, chartTop); // horizontal line ticktop g2.drawLine( chartleft - 5, chartTop + chartHeight / 4, chartleft, chartTop + chartHeight / 4); // horizontal line tick75% g2.drawLine( chartleft - 7, chartTop + chartHeight / 2, chartleft, chartTop + chartHeight / 2); // horizontal line tickMid g2.drawLine( chartleft - 5, chartTop + 3 * chartHeight / 4, chartleft, chartTop + 3 * chartHeight / 4); // horizontal line tick25% if (showGridlines) { g2.setColor(Color.gray); g2.drawLine( chartleft, chartTop, chartleft + chartIncrement * clusterCount, chartTop); // horizontal line grid g2.drawLine( chartleft, chartTop + chartHeight / 4, chartleft + chartIncrement * clusterCount, chartTop + chartHeight / 4); // horizontal line grid g2.drawLine( chartleft, chartTop + chartHeight / 2, chartleft + chartIncrement * clusterCount, chartTop + chartHeight / 2); // horizontal line grid g2.drawLine( chartleft, chartTop + 3 * chartHeight / 4, chartleft + chartIncrement * clusterCount, chartTop + 3 * chartHeight / 4); // horizontal line grid } g2.setColor(Color.black); g2.drawString( Float.toString(bottomgridline + gridrange), chartleft - 40, chartTop + 3); // vertical axis label g2.drawString( Float.toString(bottomgridline + gridrange * 3f / 4f), chartleft - 40, (chartTop + 3) + chartHeight / 4); // vertical axis label g2.drawString( Float.toString(bottomgridline + gridrange / 2f), chartleft - 40, (chartTop + 3) + chartHeight / 2); // vertical axis label g2.drawString( Float.toString(bottomgridline + gridrange / 4f), chartleft - 40, (chartTop + 3) + (3 * chartHeight / 4)); // vertical axis label g2.drawString( Float.toString(bottomgridline), chartleft - 40, (chartTop + 3) + (chartHeight)); // vertical axis label Font font = g2.getFont(); g2.setFont(new Font("Helvetica", Font.BOLD, 16)); g2.drawString( chartTitles[multigeneIndex], chartleft + chartIncrement / 2, chartTop - 15); // Gene/group Name label g2.setFont(font); g2.rotate(-Math.PI / 2); g2.drawString( "Expression", -((chartTop + 3) + 2 * chartHeight / 3), (chartleft - 60)); // y-axis Label g2.rotate(Math.PI / 2); for (int i = 0; i < this.clusterCount; i++) { int xorigin = (int) ((.25f + (float) i) * chartIncrement) + chartleft; int yorigin = chartHeight + chartTop; int barWidth = chartIncrement / 2; int barHeight = (int) ((expressionAverages[multigeneIndex][i]) * ((float) chartHeight) / gridrange); int errorBarHeight = (int) (expressionSDs[multigeneIndex][i] * ((float) chartHeight) / gridrange); int boxBottom = (int) ((-bottomgridline + expressionQ1[multigeneIndex][i]) * ((float) chartHeight) / gridrange); int boxTop = (int) ((-bottomgridline + expressionQ3[multigeneIndex][i]) * ((float) chartHeight) / gridrange); int boxMedian = (int) ((-bottomgridline + expressionMedian[multigeneIndex][i]) * ((float) chartHeight) / gridrange); int boxLowerWhisker = (int) ((-bottomgridline + expressionLowerWhisker[multigeneIndex][i]) * ((float) chartHeight) / gridrange); int boxUpperWhisker = (int) ((-bottomgridline + expressionUpperWhisker[multigeneIndex][i]) * ((float) chartHeight) / gridrange); g2.setColor(Color.gray); g2.drawLine( xorigin + 3 * barWidth / 2, yorigin, xorigin + 3 * barWidth / 2, yorigin + 5); // vertical tickmark g2.setColor(Color.black); g2.rotate(-Math.PI / 2); g2.drawString( clusterNames[i], -(yorigin + 5) - g.getFontMetrics().stringWidth(clusterNames[i]), (xorigin + barWidth / 2)); // cluster names g2.rotate(Math.PI / 2); if (!isBoxPlot) { // bar graph g2.setColor(clusterColors[i]); g2.fillRect(xorigin, yorigin - barHeight, barWidth, barHeight); // box g2.setColor(Color.black); g2.drawRect(xorigin, yorigin - barHeight, barWidth, barHeight); // box outline g2.drawLine( xorigin + barWidth / 2, yorigin - barHeight - errorBarHeight, xorigin + barWidth / 2, yorigin - barHeight); // vertical errorbar g2.drawLine( xorigin + barWidth / 4, yorigin - barHeight - errorBarHeight, xorigin + 3 * barWidth / 4, yorigin - barHeight - errorBarHeight); // horizontal error bar } else if (isBoxPlot) { // box plot g2.setColor(clusterColors[i]); g2.fillRect(xorigin, yorigin - boxTop, barWidth, boxTop - boxBottom); // box g2.setColor(Color.black); g2.drawRect(xorigin, yorigin - boxTop, barWidth, boxTop - boxBottom); // box outline g2.drawLine( xorigin, yorigin - boxMedian, xorigin + barWidth, yorigin - boxMedian); // median line g2.drawLine( xorigin + barWidth / 2, yorigin - boxTop, xorigin + barWidth / 2, yorigin - boxUpperWhisker); // vertical whisker upper g2.drawLine( xorigin + barWidth / 2, yorigin - boxBottom, xorigin + barWidth / 2, yorigin - boxLowerWhisker); // vertical whisker lower g2.drawLine( xorigin + barWidth / 4, yorigin - boxUpperWhisker, xorigin + 3 * barWidth / 4, yorigin - boxUpperWhisker); // horizontal whisker upper g2.drawLine( xorigin + barWidth / 4, yorigin - boxLowerWhisker, xorigin + 3 * barWidth / 4, yorigin - boxLowerWhisker); // horizontal whisker lower // draw outliers int circleWidth = 6; for (int j = 0; j < upperOutliers[multigeneIndex][i].length; j++) { g2.drawOval( xorigin + barWidth / 2 - circleWidth / 2, yorigin - (int) ((float) ((-bottomgridline + upperOutliers[multigeneIndex][i][j])) * ((float) chartHeight) / gridrange) - circleWidth / 2, circleWidth, circleWidth); } for (int j = 0; j < lowerOutliers[multigeneIndex][i].length; j++) { g2.drawOval( xorigin + barWidth / 2 - circleWidth / 2, yorigin - (int) ((float) ((-bottomgridline + lowerOutliers[multigeneIndex][i][j])) * ((float) chartHeight) / gridrange) - circleWidth / 2, circleWidth, circleWidth); } } else { System.out.println("unknown chart type"); } } chartTop = chartTopHeight + (multigeneIndex + 1) * (chartHeight + chartGap); // moves top down for next graph } jScrollBar.setUnitIncrement(chartHeight + chartGap); int viewerHeight = chartTopHeight + (multigeneCount) * (chartHeight + chartGap); this.setSize(new Dimension(this.getWidth(), viewerHeight)); this.setPreferredSize(new Dimension(this.getWidth(), viewerHeight)); }
/** 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(); } } }