Search in sources :

Example 1 with GeneSetScatterPlotPanel

use of uk.ac.babraham.SeqMonk.Filters.GeneSetFilter.GeneSetScatterPlotPanel in project SeqMonk by s-andrews.

the class GeneSetDisplay method valueChanged.

public void valueChanged(ListSelectionEvent ae) {
    int viewRow = table.getSelectedRow();
    if (viewRow >= 0) {
        int modelRow = table.convertRowIndexToModel(viewRow);
        ProbeList tempProbeList = new ProbeList(startingProbeList, filterResultsPVals[modelRow].mappedGeneSet.name(), "temp list", "z score");
        Probe[] tempProbes = filterResultsPVals[modelRow].mappedGeneSet.getProbes();
        for (int j = 0; j < tempProbes.length; j++) {
            tempProbeList.addProbe(tempProbes[j], (float) 0);
        }
        if (currentSelectedProbeList != null) {
            currentSelectedProbeList[0].delete();
        }
        currentSelectedProbeList = new ProbeList[1];
        currentSelectedProbeList[0] = tempProbeList;
    } else {
        if (currentSelectedProbeList != null) {
            currentSelectedProbeList[0].delete();
        }
        currentSelectedProbeList = null;
    }
    if (scatterPlotPanel instanceof GeneSetScatterPlotPanel) {
        System.err.println("trying to update the scatter plot");
        plotPanel.remove((GeneSetScatterPlotPanel) scatterPlotPanel);
        // plotPanel.repaint();
        scatterPlotPanel = new GeneSetScatterPlotPanel(fromStore, toStore, startingProbeList, currentSelectedProbeList, true, dotSizeSlider.getValue(), customRegressionValues, simpleRegression);
        // here
        plotPanel.add(scatterPlotPanel, BorderLayout.CENTER);
        plotPanel.revalidate();
        plotPanel.repaint();
    } else if (scatterPlotPanel instanceof ZScoreScatterPlotPanel) {
        ((ZScoreScatterPlotPanel) scatterPlotPanel).setSubLists(currentSelectedProbeList);
    }
// Check to see if we can add anything...
// if (availableList.getSelectedIndices().length>0) {
// System.out.println("Selected index = " + availableList.getSelectedIndices().toString());
// }
}
Also used : GeneSetScatterPlotPanel(uk.ac.babraham.SeqMonk.Filters.GeneSetFilter.GeneSetScatterPlotPanel) ProbeList(uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeList) Probe(uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe)

Example 2 with GeneSetScatterPlotPanel

use of uk.ac.babraham.SeqMonk.Filters.GeneSetFilter.GeneSetScatterPlotPanel in project SeqMonk by s-andrews.

the class GeneSetDisplay method actionPerformed.

public void actionPerformed(ActionEvent ae) {
    if (ae.getActionCommand().equals("save_image")) {
        ImageSaver.saveImage(scatterPlotPanel);
    } else if (ae.getActionCommand().equals("swap_plot")) {
        if (storesQuantitated()) {
            plotPanel.remove(scatterPlotPanel);
            if (scatterPlotPanel instanceof GeneSetScatterPlotPanel) {
                scatterPlotPanel = new ZScoreScatterPlotPanel(fromStore, toStore, probes, currentSelectedProbeList, dotSizeSlider.getValue(), zScoreLookupTable);
                plotPanel.add(scatterPlotPanel, BorderLayout.CENTER);
                swapPlotButton.setText("Display standard scatterplot");
            } else if (scatterPlotPanel instanceof ZScoreScatterPlotPanel) {
                scatterPlotPanel = new GeneSetScatterPlotPanel(fromStore, toStore, startingProbeList, currentSelectedProbeList, true, dotSizeSlider.getValue(), customRegressionValues, simpleRegression);
                plotPanel.add(scatterPlotPanel, BorderLayout.CENTER);
                swapPlotButton.setText("Display z-score plot");
            }
        }
    } else if (ae.getActionCommand().equals("close")) {
        /*	if(currentSelectedProbeList != null){
				currentSelectedProbeList[0].delete();
				//currentSelectedProbeList = null;
				
			}
		*/
        this.dispose();
    } else if (ae.getActionCommand().equals("select_all")) {
        if (selectAllButton.isSelected()) {
            for (int i = 0; i < tableModel.selected.length; i++) {
                tableModel.selected[i] = true;
                tableModel.fireTableCellUpdated(i, 0);
            }
            selectAllButton.setText("deselect all");
        } else {
            for (int i = 0; i < tableModel.selected.length; i++) {
                tableModel.selected[i] = false;
                tableModel.fireTableCellUpdated(i, 0);
            }
            selectAllButton.setText("select all");
        }
    } else if (ae.getActionCommand().equals("save_selected_probelists")) {
        boolean[] selectedListsBoolean = tableModel.selected;
        if (selectedListsBoolean.length != filterResultsPVals.length) {
            System.err.println("not adding up here");
        } else {
            ArrayList<MappedGeneSetTTestValue> selectedListsArrayList = new ArrayList<MappedGeneSetTTestValue>();
            for (int i = 0; i < selectedListsBoolean.length; i++) {
                if (selectedListsBoolean[i] == true) {
                    selectedListsArrayList.add(filterResultsPVals[i]);
                }
            }
            MappedGeneSetTTestValue[] selectedLists = selectedListsArrayList.toArray(new MappedGeneSetTTestValue[0]);
            if (selectedLists.length == 0) {
                JOptionPane.showMessageDialog(SeqMonkApplication.getInstance(), "No probe lists were selected", "No probe lists selected", JOptionPane.INFORMATION_MESSAGE);
                return;
            }
            saveProbeLists(selectedLists);
            if (currentSelectedProbeList != null) {
                currentSelectedProbeList[0].delete();
                currentSelectedProbeList = null;
            }
        }
    } else if (ae.getActionCommand().equals("save_table")) {
        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;
                } else {
                    return false;
                }
            }
        });
        int result = chooser.showSaveDialog(this);
        if (result == JFileChooser.CANCEL_OPTION)
            return;
        File file = chooser.getSelectedFile();
        if (!file.getPath().toLowerCase().endsWith(".txt")) {
            file = new File(file.getPath() + ".txt");
        }
        SeqMonkPreferences.getInstance().setLastUsedSaveLocation(file);
        // Check if we're stepping on anyone's toes...
        if (file.exists()) {
            int answer = JOptionPane.showOptionDialog(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;
            }
        }
        try {
            PrintWriter p = new PrintWriter(new FileWriter(file));
            TableModel model = table.getModel();
            int rowCount = model.getRowCount();
            int colCount = model.getColumnCount();
            // Do the headers first
            StringBuffer b = new StringBuffer();
            for (int c = 1; c < colCount; c++) {
                b.append(model.getColumnName(c));
                if (c + 1 != colCount) {
                    b.append("\t");
                }
            }
            p.println(b);
            for (int r = 0; r < rowCount; r++) {
                b = new StringBuffer();
                for (int c = 1; c < colCount; c++) {
                    b.append(model.getValueAt(r, c));
                    if (c + 1 != colCount) {
                        b.append("\t");
                    }
                }
                p.println(b);
            }
            p.close();
        } catch (FileNotFoundException e) {
            throw new IllegalStateException(e);
        } catch (IOException e) {
            throw new IllegalStateException(e);
        }
    } else {
        throw new IllegalArgumentException("Unknown command " + ae.getActionCommand());
    }
}
Also used : GeneSetScatterPlotPanel(uk.ac.babraham.SeqMonk.Filters.GeneSetFilter.GeneSetScatterPlotPanel) FileWriter(java.io.FileWriter) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) MappedGeneSetTTestValue(uk.ac.babraham.SeqMonk.Analysis.Statistics.MappedGeneSetTTestValue) JFileChooser(javax.swing.JFileChooser) FileFilter(javax.swing.filechooser.FileFilter) File(java.io.File) TableModel(javax.swing.table.TableModel) AbstractTableModel(javax.swing.table.AbstractTableModel) PrintWriter(java.io.PrintWriter)

Aggregations

GeneSetScatterPlotPanel (uk.ac.babraham.SeqMonk.Filters.GeneSetFilter.GeneSetScatterPlotPanel)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 ArrayList (java.util.ArrayList)1 JFileChooser (javax.swing.JFileChooser)1 FileFilter (javax.swing.filechooser.FileFilter)1 AbstractTableModel (javax.swing.table.AbstractTableModel)1 TableModel (javax.swing.table.TableModel)1 MappedGeneSetTTestValue (uk.ac.babraham.SeqMonk.Analysis.Statistics.MappedGeneSetTTestValue)1 Probe (uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe)1 ProbeList (uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeList)1