mev-4.0.01/source/org/tigr/microarray/mev/cluster/gui/impl/svm/SVMInfoViewer.java

Code
Comments
Other
Rev Date Author Line
2 26 Feb 07 jari 1 /*
2 26 Feb 07 jari 2 Copyright @ 1999-2004, The Institute for Genomic Research (TIGR).
2 26 Feb 07 jari 3 All rights reserved.
2 26 Feb 07 jari 4 */
2 26 Feb 07 jari 5 /*
2 26 Feb 07 jari 6  * $RCSfile: SVMInfoViewer.java,v $
2 26 Feb 07 jari 7  * $Revision: 1.6 $
2 26 Feb 07 jari 8  * $Date: 2006/03/24 15:51:53 $
2 26 Feb 07 jari 9  * $Author: eleanorahowe $
2 26 Feb 07 jari 10  * $State: Exp $
2 26 Feb 07 jari 11  */
2 26 Feb 07 jari 12 package org.tigr.microarray.mev.cluster.gui.impl.svm;
2 26 Feb 07 jari 13
2 26 Feb 07 jari 14 import java.awt.Color;
2 26 Feb 07 jari 15 import java.awt.Dimension;
2 26 Feb 07 jari 16 import java.awt.GridBagConstraints;
2 26 Feb 07 jari 17 import java.awt.GridBagLayout;
2 26 Feb 07 jari 18 import java.awt.Insets;
2 26 Feb 07 jari 19
2 26 Feb 07 jari 20 import javax.swing.JComponent;
2 26 Feb 07 jari 21 import javax.swing.JLabel;
2 26 Feb 07 jari 22 import javax.swing.JPanel;
2 26 Feb 07 jari 23 import javax.swing.JTextArea;
2 26 Feb 07 jari 24
2 26 Feb 07 jari 25 import org.tigr.microarray.mev.cluster.gui.impl.ViewerAdapter;
2 26 Feb 07 jari 26
2 26 Feb 07 jari 27 public class SVMInfoViewer extends ViewerAdapter implements java.io.Serializable {
2 26 Feb 07 jari 28     public static final long serialVersionUID = 202018050001L;
2 26 Feb 07 jari 29     
2 26 Feb 07 jari 30     private JComponent header;
2 26 Feb 07 jari 31     private JTextArea  content;
2 26 Feb 07 jari 32     private boolean classifyGenes = true;
2 26 Feb 07 jari 33     private int svmMode = 0;
2 26 Feb 07 jari 34     
2 26 Feb 07 jari 35     
2 26 Feb 07 jari 36     
2 26 Feb 07 jari 37     private int numberOfPositives = 0;
2 26 Feb 07 jari 38     private int numberOfTruePositives = 0;
2 26 Feb 07 jari 39     private int numberOfFalseNegatives = 0;
2 26 Feb 07 jari 40     
2 26 Feb 07 jari 41     private int numberOfNegatives = 0;
2 26 Feb 07 jari 42     private int numberOfTrueNegatives = 0;
2 26 Feb 07 jari 43     private int numberOfFalsePositives = 0;
2 26 Feb 07 jari 44     
2 26 Feb 07 jari 45     
2 26 Feb 07 jari 46     /**
2 26 Feb 07 jari 47      * Constructs a <code>SVMInfoViewer</code>
2 26 Feb 07 jari 48      */
2 26 Feb 07 jari 49     public SVMInfoViewer(int numPosExamples, int numNegExamples, int numNeutExamples, int numPos, int numTruePos, int numFalseNeg, int numNeg, int numTrueNeg, int numFalsePos, int numPosRecFromNeut, int numNegRecFromNeut, boolean classifyGenes, int svmMode) {
2 26 Feb 07 jari 50         header  = createHeader();
2 26 Feb 07 jari 51         this.classifyGenes = classifyGenes;
2 26 Feb 07 jari 52         this.svmMode = svmMode;
2 26 Feb 07 jari 53         content = createContent(numPosExamples, numNegExamples, numNeutExamples, numPos, numTruePos, numFalseNeg, numNeg, numTrueNeg, numFalsePos, numPosRecFromNeut, numNegRecFromNeut);
2 26 Feb 07 jari 54         setMaxWidth(content, header);
2 26 Feb 07 jari 55     }
2 26 Feb 07 jari 56     public SVMInfoViewer(JTextArea content, JComponent header){
2 26 Feb 07 jari 57       this.content = content;
2 26 Feb 07 jari 58       this.header = header;
2 26 Feb 07 jari 59         setMaxWidth(content, header);
2 26 Feb 07 jari 60     }
2 26 Feb 07 jari 61     
2 26 Feb 07 jari 62     /**
2 26 Feb 07 jari 63      * Constructs a <code>SVMInfoViewer</code>  when initial classification is unknown, SVMMode == CLASSIFY_ONLY
2 26 Feb 07 jari 64      */
2 26 Feb 07 jari 65     public SVMInfoViewer(int numPos, int numNeg, boolean classifyGenes, int svmMode) {
2 26 Feb 07 jari 66         header  = createHeader();
2 26 Feb 07 jari 67         this.classifyGenes = classifyGenes;
2 26 Feb 07 jari 68         this.svmMode = svmMode;
2 26 Feb 07 jari 69         content = createContent(0, 0, 0, numPos, 0, 0, numNeg, 0, 0, 0, 0);
2 26 Feb 07 jari 70         setMaxWidth(content, header);
2 26 Feb 07 jari 71     }
2 26 Feb 07 jari 72     
2 26 Feb 07 jari 73     /**
2 26 Feb 07 jari 74      * Returns component to be inserted into the framework scroll pane.
2 26 Feb 07 jari 75      */
2 26 Feb 07 jari 76     public JComponent getContentComponent() {
2 26 Feb 07 jari 77         return content;
2 26 Feb 07 jari 78     }
2 26 Feb 07 jari 79     
2 26 Feb 07 jari 80     /**
2 26 Feb 07 jari 81      * Returns the viewer header.
2 26 Feb 07 jari 82      */
2 26 Feb 07 jari 83     public JComponent getHeaderComponent() {
2 26 Feb 07 jari 84         return header;
2 26 Feb 07 jari 85     }
2 26 Feb 07 jari 86     
2 26 Feb 07 jari 87     /**
2 26 Feb 07 jari 88      * Creates the viewer header.
2 26 Feb 07 jari 89      */
2 26 Feb 07 jari 90     private JComponent createHeader() {
2 26 Feb 07 jari 91         JPanel panel = new JPanel(new GridBagLayout());
2 26 Feb 07 jari 92         panel.setBackground(Color.white);
2 26 Feb 07 jari 93         GridBagConstraints gbc = new GridBagConstraints();
2 26 Feb 07 jari 94         gbc.fill = GridBagConstraints.HORIZONTAL;
2 26 Feb 07 jari 95         gbc.insets = new Insets(10, 0, 10, 0);
2 26 Feb 07 jari 96         panel.add(new JLabel("<html><body bgcolor='#FFFFFF'><font face='serif' size='5' color='#000080'><b>Classification Information</b></font></body></html>"), gbc);
2 26 Feb 07 jari 97         return panel;
2 26 Feb 07 jari 98     }
2 26 Feb 07 jari 99     
2 26 Feb 07 jari 100     /**
2 26 Feb 07 jari 101      * Creates the viewer content component.
2 26 Feb 07 jari 102      */
2 26 Feb 07 jari 103     private JTextArea createContent(int numPosExamples, int numNegExamples, int numNeutExamples, int numPos, int numTruePos, int numFalseNeg, int numNeg, int numTrueNeg, int numFalsePos, int numPosRecFromNeut, int numNegRecFromNeut) {
2 26 Feb 07 jari 104         JTextArea area = new JTextArea(20, 20);
2 26 Feb 07 jari 105         area.setMargin(new Insets(0, 10, 0, 0));
2 26 Feb 07 jari 106         area.setEditable(false);
2 26 Feb 07 jari 107         StringBuffer sb = new StringBuffer(800);
2 26 Feb 07 jari 108         if(svmMode == SVMGUI.TRAIN_AND_CLASSIFY)
2 26 Feb 07 jari 109             sb.append("SVM Mode: Training and Classification\n\n");
2 26 Feb 07 jari 110         else
2 26 Feb 07 jari 111             sb.append("SVM Mode: Classification using SVM Weight File\n\n");
2 26 Feb 07 jari 112         
2 26 Feb 07 jari 113         if(classifyGenes){
2 26 Feb 07 jari 114             sb.append("Total Number of Genes: "+ (numPos + numNeg)+"\n\n");
2 26 Feb 07 jari 115             sb.append("Positive Genes\n");
2 26 Feb 07 jari 116             if(svmMode == SVMGUI.TRAIN_AND_CLASSIFY)
2 26 Feb 07 jari 117                 sb.append("# of Genes initially selected as Positive examples: "+numPosExamples+"\n");
2 26 Feb 07 jari 118             
2 26 Feb 07 jari 119             sb.append("# of Genes classified as Positive (Total Positives): "+numPos+"\n");
2 26 Feb 07 jari 120             if(svmMode == SVMGUI.TRAIN_AND_CLASSIFY){
2 26 Feb 07 jari 121                 sb.append("# of Genes retained in Positive class (True Positives): " + numTruePos+"\n");
2 26 Feb 07 jari 122                 sb.append("# of Genes recruited into Positive class from Negatives (False Negatives): " + numFalseNeg+"\n");
2 26 Feb 07 jari 123                 if(numNeutExamples > 0)
2 26 Feb 07 jari 124                     sb.append("# of Genes recruited into Positive class from Neutrals: " + numPosRecFromNeut+"\n");
2 26 Feb 07 jari 125             }
2 26 Feb 07 jari 126             sb.append("\n");
2 26 Feb 07 jari 127             
2 26 Feb 07 jari 128             sb.append("Negative Genes\n");
2 26 Feb 07 jari 129             if(svmMode == SVMGUI.TRAIN_AND_CLASSIFY)
2 26 Feb 07 jari 130                 sb.append("# of Genes initially selected as negative examples: "+numNegExamples+"\n");
2 26 Feb 07 jari 131             
2 26 Feb 07 jari 132             sb.append("# of Genes classified as negative (Total Negatives): "+numNeg+"\n");
2 26 Feb 07 jari 133             if(svmMode == SVMGUI.TRAIN_AND_CLASSIFY){
2 26 Feb 07 jari 134                 sb.append("# of Genes retained in negative class (True Negatives): " + numTrueNeg+"\n");
2 26 Feb 07 jari 135                 sb.append("# of Genes recruited into negative class from Positives (False Positives): " + numFalsePos+"\n");
2 26 Feb 07 jari 136                 if(numNeutExamples > 0)
2 26 Feb 07 jari 137                     sb.append("# of Genes recruited into Negative class from Neutrals: " + numNegRecFromNeut+"\n");
2 26 Feb 07 jari 138             }
2 26 Feb 07 jari 139             sb.append("\n");
2 26 Feb 07 jari 140             if(numNeutExamples != 0){
2 26 Feb 07 jari 141                 sb.append("Neutral Genes");
2 26 Feb 07 jari 142                 sb.append("\n");
2 26 Feb 07 jari 143                 sb.append("# of Genes initially selected as neutral examples: "+numNeutExamples+"\n");
2 26 Feb 07 jari 144                 sb.append("\n");
2 26 Feb 07 jari 145             }
2 26 Feb 07 jari 146             
2 26 Feb 07 jari 147         }
2 26 Feb 07 jari 148         else{
2 26 Feb 07 jari 149             sb.append("Total Number of Experiments: "+ (numPos + numNeg)+"\n\n");
2 26 Feb 07 jari 150             sb.append("Positive Experiments");
2 26 Feb 07 jari 151             sb.append("\n");
2 26 Feb 07 jari 152             if(svmMode == SVMGUI.TRAIN_AND_CLASSIFY)
2 26 Feb 07 jari 153                 sb.append("# of Experiments initially selected as positive examples: "+numPosExamples+"\n");
2 26 Feb 07 jari 154             
2 26 Feb 07 jari 155             sb.append("# of Experiments classified as positive (Total Positives): "+numPos+"\n");
2 26 Feb 07 jari 156             if(svmMode == SVMGUI.TRAIN_AND_CLASSIFY){
2 26 Feb 07 jari 157                 sb.append("# of Experiments retained in positive class (True Positives): " + numTruePos+"\n");
2 26 Feb 07 jari 158                 sb.append("# of Experiments recruited into positive class from Negatives (False Negatives): " + numFalseNeg+"\n");
2 26 Feb 07 jari 159                 if(numNeutExamples > 0)
2 26 Feb 07 jari 160                     sb.append("# of Experiments recruited into Positive class from Neutrals: " + numPosRecFromNeut+"\n");
2 26 Feb 07 jari 161             }
2 26 Feb 07 jari 162             sb.append("\n");
2 26 Feb 07 jari 163             
2 26 Feb 07 jari 164             sb.append("Negative Experiments");
2 26 Feb 07 jari 165             sb.append("\n");
2 26 Feb 07 jari 166             if(svmMode == SVMGUI.TRAIN_AND_CLASSIFY)
2 26 Feb 07 jari 167                 sb.append("# of Experiments initially selected as negative examples: "+numNegExamples+"\n");
2 26 Feb 07 jari 168             
2 26 Feb 07 jari 169             sb.append("# of Experiments classified as negative (Total Negatives): "+numNeg+"\n");
2 26 Feb 07 jari 170             if(svmMode == SVMGUI.TRAIN_AND_CLASSIFY){
2 26 Feb 07 jari 171                 sb.append("# of Experiments retained in negative class (True Negatives): " + numTrueNeg+"\n");
2 26 Feb 07 jari 172                 sb.append("# of Experiments recruited into negative class from Positives (False Positives): " + numFalsePos+"\n");
2 26 Feb 07 jari 173                 if(numNeutExamples > 0)
2 26 Feb 07 jari 174                     sb.append("# of Experiments recruited into Positive class from Neutrals: " + numNegRecFromNeut+"\n");
2 26 Feb 07 jari 175             }
2 26 Feb 07 jari 176             sb.append("\n");
2 26 Feb 07 jari 177             if(numNeutExamples != 0 && svmMode == SVMGUI.TRAIN_AND_CLASSIFY){
2 26 Feb 07 jari 178                 sb.append("Neutral Experiments");
2 26 Feb 07 jari 179                 sb.append("\n");
2 26 Feb 07 jari 180                 sb.append("# of Experiments initially selected as neutral examples: "+numNeutExamples+"\n");
2 26 Feb 07 jari 181                 sb.append("\n");
2 26 Feb 07 jari 182             }
2 26 Feb 07 jari 183         }
2 26 Feb 07 jari 184         area.setText(sb.toString());
2 26 Feb 07 jari 185         area.setCaretPosition(0);
2 26 Feb 07 jari 186         return area;
2 26 Feb 07 jari 187     }
2 26 Feb 07 jari 188     
2 26 Feb 07 jari 189     /**
2 26 Feb 07 jari 190      * Synchronize content and header sizes.
2 26 Feb 07 jari 191      */
2 26 Feb 07 jari 192     private void setMaxWidth(JComponent content, JComponent header) {
2 26 Feb 07 jari 193         int c_width = content.getPreferredSize().width;
2 26 Feb 07 jari 194         int h_width = header.getPreferredSize().width;
2 26 Feb 07 jari 195         if (c_width > h_width) {
2 26 Feb 07 jari 196             header.setPreferredSize(new Dimension(c_width, header.getPreferredSize().height));
2 26 Feb 07 jari 197         } else {
2 26 Feb 07 jari 198             content.setPreferredSize(new Dimension(h_width, content.getPreferredSize().height));
2 26 Feb 07 jari 199         }
2 26 Feb 07 jari 200     }
2 26 Feb 07 jari 201     
2 26 Feb 07 jari 202     /** Returns a component to be inserted into the scroll pane row header
2 26 Feb 07 jari 203      */
2 26 Feb 07 jari 204     public JComponent getRowHeaderComponent() {
2 26 Feb 07 jari 205         return null;
2 26 Feb 07 jari 206     }
2 26 Feb 07 jari 207     
2 26 Feb 07 jari 208 }