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; }
private void setClusters(int[][] sampleArray) { if (sampleArray == null || sampleArray.length == 0) sampleArray = new int[1][]; clusterCount = sampleArray.length; clusterNames = new String[clusterCount]; clusterColors = new Color[clusterCount]; clusters = new int[clusterCount][]; for (int i = 0; i < clusterCount; i++) { if (sampleArray[i] == null) { int numSamps = experiment.getNumberOfSamples(); clusters[i] = new int[numSamps]; for (int j = 0; j < numSamps; j++) { clusters[i][j] = j; } clusterColors[i] = Color.white; clusterNames[i] = "All Samples"; } else { clusters[i] = sampleArray[i]; clusterColors[i] = createClusterColor(i); if (sampleClusterNames == null || sampleClusterNames[i].length() < 1) { clusterNames[i] = "(Group " + (i + 1) + ")"; } else { clusterNames[i] = sampleClusterNames[i]; } } } }
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(); } } }
public void setClusters(Cluster[] clusterArray) { if (clusterArray == null || clusterArray.length == 0) clusterArray = new Cluster[1]; clusterCount = clusterArray.length; clusterNames = new String[clusterCount]; clusterColors = new Color[clusterCount]; clusters = new int[clusterCount][]; for (int i = 0; i < clusterCount; i++) { if (clusterArray[i] == null) { int numSamps = experiment.getNumberOfSamples(); clusters[i] = new int[numSamps]; for (int j = 0; j < numSamps; j++) { clusters[i][j] = j; } clusterColors[i] = Color.white; clusterNames[i] = "All Samples"; } else { clusters[i] = clusterArray[i].getIndices(); clusterColors[i] = clusterArray[i].getClusterColor(); clusterNames[i] = clusterArray[i].getClusterLabel(); if (clusterNames[i].length() < 1) clusterNames[i] = "(Cluster " + (i + 1) + ")"; } } }
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(); }
/** * Gathers data for a set of genes * * @param geneIndices */ private void getChartData(int[] geneIndices, int multigeneIndex) { try { lowerOutliers[multigeneIndex] = new float[clusterCount][]; upperOutliers[multigeneIndex] = new float[clusterCount][]; expressionSDs[multigeneIndex] = new float[clusterCount]; expressionAverages[multigeneIndex] = new float[clusterCount]; expressionMedian[multigeneIndex] = new float[clusterCount]; expressionQ1[multigeneIndex] = new float[clusterCount]; expressionQ3[multigeneIndex] = new float[clusterCount]; expressionIQR[multigeneIndex] = new float[clusterCount]; expressionLowerWhisker[multigeneIndex] = new float[clusterCount]; expressionUpperWhisker[multigeneIndex] = new float[clusterCount]; for (int i = 0; i < clusterCount; i++) { float average = 0; float sum = 0; int membership = 0; for (int j = 0; j < clusters[i].length; j++) { for (int k = 0; k < geneIndices.length; k++) { average = average + experiment.get(geneIndices[k], clusters[i][j]); membership++; } } average = average / (float) membership; expressionAverages[multigeneIndex][i] = average; for (int j = 0; j < clusters[i].length; j++) { for (int k = 0; k < geneIndices.length; k++) { sum = sum + (float) Math.pow(experiment.get(geneIndices[k], clusters[i][j]) - average, 2); } } sum = sum / (float) membership; expressionSDs[multigeneIndex][i] = (float) Math.sqrt(sum); // get box plot stuff float[] expression = new float[clusters[i].length * geneIndices.length]; int expindex = 0; for (int j = 0; j < clusters[i].length; j++) { for (int k = 0; k < geneIndices.length; k++) { expression[expindex++] = (experiment.get(geneIndices[k], clusters[i][j])); } } Arrays.sort(expression); expressionMedian[multigeneIndex][i] = getMedian(expression); float[] lower = new float[expression.length / 2]; float[] upper = new float[expression.length / 2]; for (int j = 0; j < lower.length; j++) { lower[j] = expression[j]; upper[upper.length - 1 - j] = expression[expression.length - 1 - j]; } expressionQ1[multigeneIndex][i] = getMedian(lower); expressionQ3[multigeneIndex][i] = getMedian(upper); expressionIQR[multigeneIndex][i] = expressionQ3[multigeneIndex][i] - expressionQ1[multigeneIndex][i]; expressionLowerWhisker[multigeneIndex][i] = expressionQ1[multigeneIndex][i] - 1.5f * expressionIQR[multigeneIndex][i]; expressionUpperWhisker[multigeneIndex][i] = expressionQ3[multigeneIndex][i] + 1.5f * expressionIQR[multigeneIndex][i]; int upperCount = 0; int lowerCount = 0; for (int index = 0; index < expression.length; index++) { if (expression[index] < expressionLowerWhisker[multigeneIndex][i]) lowerCount++; if (expression[index] > expressionUpperWhisker[multigeneIndex][i]) upperCount++; } lowerOutliers[multigeneIndex][i] = new float[lowerCount]; upperOutliers[multigeneIndex][i] = new float[upperCount]; for (int j = 0; j < lowerOutliers[multigeneIndex][i].length; j++) { lowerOutliers[multigeneIndex][i][j] = expression[j]; } for (int j = 0; j < upperOutliers[multigeneIndex][i].length; j++) { upperOutliers[multigeneIndex][i][j] = expression[expression.length - 1 - j]; } } } catch (Exception e) { System.out.println("data problem"); e.printStackTrace(); for (int i = 0; i < clusterCount; i++) { expressionAverages[multigeneIndex][i] = (float) Math.random(); expressionSDs[multigeneIndex][i] = (float) Math.random() / 10f; } } }
/** 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(); } } }