protected void addTableViews(DefaultMutableTreeNode root) { DefaultMutableTreeNode node = new DefaultMutableTreeNode("Table Views"); IViewer tabViewer = new ClusterTableViewer(data.getExperiment(), (int[][]) null, data, headerNames, auxData); node.add(new DefaultMutableTreeNode(new LeafInfo("Gene List", tabViewer, new Integer(0)))); // Create sig and non-sig table views tabViewer = new ClusterTableViewer(data.getExperiment(), clusters, data, headerNames, auxData); node.add( new DefaultMutableTreeNode( new LeafInfo("Significant Gene List", tabViewer, new Integer(0)))); node.add( new DefaultMutableTreeNode( new LeafInfo("Non-Significant Gene List", tabViewer, new Integer(1)))); root.add(node); }
private void saveCluster(File file, Experiment experiment, IData data, int[] rows) throws Exception { PrintWriter out = new PrintWriter(new FileOutputStream(file)); String[] fieldNames = data.getFieldNames(); out.print("Original row"); out.print("\t"); for (int i = 0; i < fieldNames.length; i++) { out.print(fieldNames[i]); // if (i < fieldNames.length - 1) { out.print("\t"); // } } for (int i = 0; i < geneGroupMeans[0].length; i++) { out.print("Group" + (i + 1) + " mean\t"); out.print("Group" + (i + 1) + " std.dev.\t"); } // out.print("\t"); out.print("F ratio"); out.print("\t"); out.print("SS(Groups)\t"); out.print("SS(Error)\t"); out.print("df (Groups)\t"); out.print("df (Error)\t"); out.print("raw p value\t"); out.print("adj p value"); // out.print("UniqueID\tName"); for (int i = 0; i < experiment.getNumberOfSamples(); i++) { out.print("\t"); out.print(data.getFullSampleName(experiment.getSampleIndex(i))); } out.print("\n"); for (int i = 0; i < rows.length; i++) { out.print(Integer.toString(experiment.getGeneIndexMappedToData(rows[i]) + 1)); // out.print(data.getUniqueId(rows[i])); out.print("\t"); // out.print(data.getGeneName(rows[i])); for (int k = 0; k < fieldNames.length; k++) { out.print(data.getElementAttribute(experiment.getGeneIndexMappedToData(rows[i]), k)); // if (k < fieldNames.length - 1) { out.print("\t"); // } } for (int j = 0; j < geneGroupMeans[rows[i]].length; j++) { out.print(geneGroupMeans[rows[i]][j] + "\t"); out.print(geneGroupSDs[rows[i]][j] + "\t"); } // out.print("\t"); out.print("" + ((Float) fValues.get(rows[i])).floatValue()); out.print("\t"); out.print("" + ((Float) ssGroups.get(rows[i])).floatValue()); out.print("\t"); out.print("" + ((Float) ssError.get(rows[i])).floatValue()); out.print("\t"); out.print("" + ((Float) dfNumValues.get(rows[i])).floatValue()); out.print("\t"); out.print("" + ((Float) dfDenomValues.get(rows[i])).floatValue()); out.print("\t"); out.print("" + ((Float) rawPValues.get(rows[i])).floatValue()); out.print("\t"); out.print("" + ((Float) adjPValues.get(rows[i])).floatValue()); for (int j = 0; j < experiment.getNumberOfSamples(); j++) { out.print("\t"); out.print(Float.toString(experiment.get(rows[i], j))); } out.print("\n"); } out.flush(); out.close(); }
/** * 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(); } } }