Search in sources :

Example 1 with StarWars

use of uk.ac.babraham.SeqMonk.Analysis.Statistics.StarWars in project SeqMonk by s-andrews.

the class MultiStarWarsDialog method actionPerformed.

public void actionPerformed(ActionEvent ae) {
    if (ae.getActionCommand().equals("close")) {
        setVisible(false);
        dispose();
    } else if (ae.getActionCommand().equals("save")) {
        ImageSaver.saveImage(graphPanel);
    } else if (ae.getActionCommand().equals("save_data")) {
        JFileChooser chooser = new JFileChooser(SeqMonkPreferences.getInstance().getSaveLocation());
        chooser.setMultiSelectionEnabled(false);
        chooser.setFileFilter(new FileFilter() {

            public String getDescription() {
                return "Text Files";
            }

            public boolean accept(File f) {
                if (f.isDirectory() || f.getName().toLowerCase().endsWith(".txt")) {
                    return true;
                }
                return false;
            }
        });
        int result = chooser.showSaveDialog(MultiStarWarsDialog.this);
        if (result == JFileChooser.CANCEL_OPTION)
            return;
        File file = chooser.getSelectedFile();
        SeqMonkPreferences.getInstance().setLastUsedSaveLocation(file);
        if (file.isDirectory())
            return;
        if (!file.getPath().toLowerCase().endsWith(".txt")) {
            file = new File(file.getPath() + ".txt");
        }
        // Check if we're stepping on anyone's toes...
        if (file.exists()) {
            int answer = JOptionPane.showOptionDialog(MultiStarWarsDialog.this, file.getName() + " exists.  Do you want to overwrite the existing file?", "Overwrite file?", 0, JOptionPane.QUESTION_MESSAGE, null, new String[] { "Overwrite and Save", "Cancel" }, "Overwrite and Save");
            if (answer > 0) {
                return;
            }
        }
        // Now write out the results
        try {
            PrintWriter pr = new PrintWriter(file);
            pr.println("ProbeList\tDataStore\tMean\tStdErr");
            StringBuffer br;
            // Now do all of the data stores
            for (int s = 0; s < stores.length; s++) {
                for (int p = 0; p < probes.length; p++) {
                    br = new StringBuffer();
                    StarWars sw = whiskers[p][s];
                    br.append(probes[p].name());
                    br.append("\t");
                    br.append(stores[s].name());
                    br.append("\t");
                    br.append(sw.mean());
                    br.append("\t");
                    br.append(sw.standard_error());
                    pr.println(br.toString());
                }
            }
            pr.close();
        } catch (IOException ioe) {
            throw new IllegalStateException(ioe);
        }
    } else if (ae.getActionCommand().equals("xaxis")) {
        if (!xAxisChoice.getSelectedItem().equals(currentChoice)) {
            currentChoice = (String) xAxisChoice.getSelectedItem();
            updateGraphs();
        }
    } else {
        throw new IllegalStateException("Unknown command " + ae.getActionCommand());
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) StarWars(uk.ac.babraham.SeqMonk.Analysis.Statistics.StarWars) IOException(java.io.IOException) FileFilter(javax.swing.filechooser.FileFilter) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 2 with StarWars

use of uk.ac.babraham.SeqMonk.Analysis.Statistics.StarWars in project SeqMonk by s-andrews.

the class MultiStarWarsDialog method run.

public void run() {
    whiskers = new StarWars[probes.length][stores.length];
    try {
        for (int p = 0; p < probes.length; p++) {
            for (int s = 0; s < stores.length; s++) {
                whiskers[p][s] = new StarWars(stores[s], probes[p]);
                if (p == 0 && s == 0) {
                    min = (float) whiskers[p][s].lowerBound();
                    max = (float) whiskers[p][s].upperBound();
                }
                if (whiskers[p][s].lowerBound() < min) {
                    min = (float) whiskers[p][s].lowerBound();
                }
                if (whiskers[p][s].upperBound() > max) {
                    max = (float) whiskers[p][s].upperBound();
                }
            }
        }
        updateGraphs();
        setVisible(true);
    } catch (SeqMonkException sme) {
        throw new IllegalStateException(sme);
    }
}
Also used : StarWars(uk.ac.babraham.SeqMonk.Analysis.Statistics.StarWars) SeqMonkException(uk.ac.babraham.SeqMonk.SeqMonkException)

Example 3 with StarWars

use of uk.ac.babraham.SeqMonk.Analysis.Statistics.StarWars in project SeqMonk by s-andrews.

the class MultiStarWarsDialog method updateGraphs.

private void updateGraphs() {
    boolean useProbesOnXAxis = true;
    if (xAxisChoice.getSelectedItem().equals("Data Stores")) {
        useProbesOnXAxis = false;
    }
    int rows;
    int cols;
    if (useProbesOnXAxis) {
        rows = (int) Math.sqrt(stores.length);
        cols = stores.length / rows;
        if (stores.length % rows > 0) {
            cols++;
        }
    } else {
        rows = (int) Math.sqrt(probes.length);
        cols = probes.length / rows;
        if (probes.length % rows > 0) {
            cols++;
        }
    }
    graphPanel.removeAll();
    graphPanel.setLayout(new GridLayout(rows, cols));
    if (useProbesOnXAxis) {
        String[] panelNames = new String[probes.length];
        for (int p = 0; p < probes.length; p++) {
            panelNames[p] = probes[p].name();
        }
        for (int g = 0; g < stores.length; g++) {
            String groupName = stores[g].name();
            StarWars[] theseWhiskers = new StarWars[probes.length];
            for (int p = 0; p < probes.length; p++) {
                theseWhiskers[p] = whiskers[p][g];
            }
            MultiStarWarsPanel graph = new MultiStarWarsPanel(theseWhiskers, panelNames, groupName, min, max);
            graph.setBorder(BorderFactory.createLineBorder(Color.BLACK));
            graphPanel.add(graph);
        }
    } else {
        String[] panelNames = new String[stores.length];
        for (int s = 0; s < stores.length; s++) {
            panelNames[s] = stores[s].name();
        }
        for (int p = 0; p < probes.length; p++) {
            String groupName = probes[p].name();
            StarWars[] theseWhiskers = new StarWars[stores.length];
            for (int s = 0; s < stores.length; s++) {
                theseWhiskers[s] = whiskers[p][s];
            }
            MultiStarWarsPanel graph = new MultiStarWarsPanel(theseWhiskers, panelNames, groupName, min, max);
            graph.setBorder(BorderFactory.createLineBorder(Color.BLACK));
            graphPanel.add(graph);
        }
    }
    graphPanel.revalidate();
    graphPanel.repaint();
}
Also used : GridLayout(java.awt.GridLayout) StarWars(uk.ac.babraham.SeqMonk.Analysis.Statistics.StarWars)

Aggregations

StarWars (uk.ac.babraham.SeqMonk.Analysis.Statistics.StarWars)3 GridLayout (java.awt.GridLayout)1 File (java.io.File)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 JFileChooser (javax.swing.JFileChooser)1 FileFilter (javax.swing.filechooser.FileFilter)1 SeqMonkException (uk.ac.babraham.SeqMonk.SeqMonkException)1