Search in sources :

Example 1 with ProgressDialog

use of uk.ac.babraham.SeqMonk.Dialogs.ProgressDialog.ProgressDialog in project SeqMonk by s-andrews.

the class HeatmapProbeListWindow method progressComplete.

public void progressComplete(String command, Object result) {
    if (command.equals("heatmap")) {
        if (matrix.interactions().length == 0) {
            JOptionPane.showMessageDialog(SeqMonkApplication.getInstance(), "No interactions were found", "Interaction Result", JOptionPane.INFORMATION_MESSAGE);
            dispose();
            return;
        }
        heatmapPanel = new HeatmapProbeListPanelCollection(data, probeLists, matrix, genome);
        getContentPane().setLayout(new BorderLayout());
        getContentPane().add(heatmapPanel, BorderLayout.CENTER);
        filterOptions = new HeatmapFilterOptions(matrix);
        getContentPane().add(filterOptions, BorderLayout.WEST);
        JPanel buttonPanel = new JPanel();
        JButton closeButton = new JButton("Close");
        closeButton.setActionCommand("close");
        closeButton.addActionListener(this);
        buttonPanel.add(closeButton);
        JButton saveImageButton = new JButton("Save Image");
        saveImageButton.setActionCommand("save_image");
        saveImageButton.addActionListener(this);
        buttonPanel.add(saveImageButton);
        JButton saveProbesButton = new JButton("Save Probe List");
        saveProbesButton.setActionCommand("save_probes");
        saveProbesButton.addActionListener(this);
        buttonPanel.add(saveProbesButton);
        JButton makeReportButton = new JButton("Make Report");
        makeReportButton.setActionCommand("make_report");
        makeReportButton.addActionListener(this);
        buttonPanel.add(makeReportButton);
        clusterButton = new JButton("Cluster Interactions");
        clusterButton.setActionCommand("cluster");
        clusterButton.addActionListener(this);
        buttonPanel.add(clusterButton);
        saveClustersButton = new JButton("Save current clusters");
        saveClustersButton.setActionCommand("save_clusters");
        saveClustersButton.addActionListener(this);
        saveClustersButton.setEnabled(false);
        buttonPanel.add(saveClustersButton);
        getContentPane().add(buttonPanel, BorderLayout.SOUTH);
        setSize(800, 500);
        setLocationRelativeTo(SeqMonkApplication.getInstance());
        setVisible(true);
    } else if (command.equals("interaction_cluster_matrix")) {
        // We can start the actual clustering
        HierarchicalClusterSet clusterSet = new HierarchicalClusterSet((InteractionClusterMatrix) result);
        clusterSet.addListener(new ProgressDialog(this, "HiC Interaction Clustering", clusterSet));
        clusterSet.addListener(this);
        clusterSet.startClustering();
    } else if (command.equals("interaction_cluster")) {
        matrix.setCluster((ClusterPair) result);
        clusterButton.setText("Remove clustering");
        clusterButton.setEnabled(true);
        saveClustersButton.setEnabled(true);
    }
}
Also used : JPanel(javax.swing.JPanel) BorderLayout(java.awt.BorderLayout) InteractionClusterMatrix(uk.ac.babraham.SeqMonk.DataTypes.Interaction.InteractionClusterMatrix) JButton(javax.swing.JButton) ProgressDialog(uk.ac.babraham.SeqMonk.Dialogs.ProgressDialog.ProgressDialog) HierarchicalClusterSet(uk.ac.babraham.SeqMonk.DataTypes.Cluster.HierarchicalClusterSet)

Example 2 with ProgressDialog

use of uk.ac.babraham.SeqMonk.Dialogs.ProgressDialog.ProgressDialog in project SeqMonk by s-andrews.

the class RNAQCPreferencesDialog method actionPerformed.

public void actionPerformed(ActionEvent ae) {
    if (ae.getActionCommand().equals("plot")) {
        String geneFeatures = (String) geneFeaturesBox.getSelectedItem();
        String transcriptFeatures = null;
        if (measureTranscriptsBox.isSelected()) {
            transcriptFeatures = (String) transcriptFeaturesBox.getSelectedItem();
        }
        String rRNAFeatures = null;
        if (measureRRNABox.isSelected()) {
            rRNAFeatures = (String) rRNAFeaturesBox.getSelectedItem();
        }
        Object[] selectedChromosomes = chromosomeList.getSelectedValues();
        Chromosome[] chromosomes = new Chromosome[selectedChromosomes.length];
        for (int c = 0; c < chromosomes.length; c++) {
            chromosomes[c] = (Chromosome) selectedChromosomes[c];
        }
        RNAQCCalcualtor calc = new RNAQCCalcualtor(collection, geneFeatures, transcriptFeatures, rRNAFeatures, chromosomes, stores);
        calc.addListener(this);
        calc.addListener(new ProgressDialog("RNA-Seq QC Plot", calc));
        calc.startCalculating();
        setVisible(false);
    }
}
Also used : Chromosome(uk.ac.babraham.SeqMonk.DataTypes.Genome.Chromosome) ProgressDialog(uk.ac.babraham.SeqMonk.Dialogs.ProgressDialog.ProgressDialog)

Example 3 with ProgressDialog

use of uk.ac.babraham.SeqMonk.Dialogs.ProgressDialog.ProgressDialog in project SeqMonk by s-andrews.

the class QuantitationTrendPlotDialog method setupFrame.

private void setupFrame(ProbeList probeList, DataStore[] stores, QuantitationTrendPlotPreferencesPanel prefs) {
    // The trend panel is now going to be made of a number of different components,
    // all arranged horizontally.
    /*
		 * 1) A y-axis
		 * 
		 * 2) An upstream fixed width region (if there is one)
		 * 
		 * 3) A central fixed or variable region (if there is one)
		 * 
		 * 4) A downstream fixed width region (if there is one)
		 */
    trendPanel = new JPanel();
    trendPanel.setLayout(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.weightx = 0.5;
    gbc.weighty = 0.5;
    gbc.gridx = 1;
    gbc.gridy = 1;
    gbc.fill = GridBagConstraints.BOTH;
    // Upstream panel
    Probe[] upstreamProbes = prefs.getUpstreamProbes();
    if (upstreamProbes != null) {
        waitingCounter.increment();
        upstreamTrendPanel = new QuantitationTrendPlotPanel(upstreamProbes, stores, probeList.getAllProbes(), prefs.selectedFeatureTypes()[0]);
        trendPanel.add(upstreamTrendPanel, gbc);
        gbc.gridx++;
    }
    // Central panel
    Probe[] centralProbes = prefs.getCoreProbes();
    if (centralProbes != null) {
        waitingCounter.increment();
        centralTrendPanel = new QuantitationTrendPlotPanel(centralProbes, stores, probeList.getAllProbes(), prefs.selectedFeatureTypes()[0]);
        trendPanel.add(centralTrendPanel, gbc);
        gbc.gridx++;
    }
    // Downstream panel
    Probe[] downstreamProbes = prefs.getDownstreamProbes();
    if (downstreamProbes != null) {
        waitingCounter.increment();
        downstreamTrendPanel = new QuantitationTrendPlotPanel(downstreamProbes, stores, probeList.getAllProbes(), prefs.selectedFeatureTypes()[0]);
        trendPanel.add(downstreamTrendPanel, gbc);
        gbc.gridx++;
    }
    // Figure out which is the leftmost panel
    if (upstreamProbes != null) {
        upstreamTrendPanel.setLeftmost(true);
    } else if (centralProbes != null) {
        centralTrendPanel.setLeftmost(true);
    } else {
        downstreamTrendPanel.setLeftmost(true);
    }
    // Figure out which is the rightmost panel
    if (downstreamProbes != null) {
        downstreamTrendPanel.setRightmost(true);
    } else if (centralProbes != null) {
        centralTrendPanel.setRightmost(true);
    } else {
        upstreamTrendPanel.setRightmost(true);
    }
    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(trendPanel, BorderLayout.CENTER);
    smoothingSlider = new JSlider(JSlider.VERTICAL, 1, 1000, 1);
    // This call is left in to work around a bug in the Windows 7 LAF
    // which makes the slider stupidly thin in ticks are not drawn.
    smoothingSlider.setPaintTicks(true);
    smoothingSlider.addChangeListener(this);
    getContentPane().add(smoothingSlider, BorderLayout.EAST);
    JPanel buttonPanel = new JPanel();
    JButton closeButton = new JButton("Close");
    closeButton.setActionCommand("close");
    closeButton.addActionListener(this);
    buttonPanel.add(closeButton);
    // I may not put this back, but it's broken at the moment anyway.
    // JButton saveDataButton = new JButton("Save Data");
    // saveDataButton.setActionCommand("save_data");
    // saveDataButton.addActionListener(this);
    // buttonPanel.add(saveDataButton);
    JButton saveImageButton = new JButton("Save Image");
    saveImageButton.setActionCommand("save_image");
    saveImageButton.addActionListener(this);
    buttonPanel.add(saveImageButton);
    JButton saveDataButton = new JButton("Save Data");
    saveDataButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent ae) {
            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(QuantitationTrendPlotDialog.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(QuantitationTrendPlotDialog.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 pr = new PrintWriter(file);
                boolean addHeader = true;
                if (upstreamTrendPanel != null) {
                    upstreamTrendPanel.saveData(pr, addHeader);
                    addHeader = false;
                }
                if (centralTrendPanel != null) {
                    centralTrendPanel.saveData(pr, addHeader);
                    addHeader = false;
                }
                if (downstreamTrendPanel != null) {
                    downstreamTrendPanel.saveData(pr, addHeader);
                    addHeader = false;
                }
                pr.close();
            } catch (IOException ioe) {
                throw new IllegalStateException(ioe);
            }
        }
    });
    buttonPanel.add(saveDataButton);
    getContentPane().add(buttonPanel, BorderLayout.SOUTH);
    // setSize(800,600);
    setSize(700, 350);
    setLocationRelativeTo(SeqMonkApplication.getInstance());
    boolean addedProgress = false;
    if (upstreamTrendPanel != null) {
        upstreamTrendPanel.addProgressListener(this);
        if (!addedProgress) {
            upstreamTrendPanel.addProgressListener(new ProgressDialog("Quantitation Trend Plot", upstreamTrendPanel));
            addedProgress = true;
        }
        upstreamTrendPanel.startCalculating();
    }
    if (centralTrendPanel != null) {
        centralTrendPanel.addProgressListener(this);
        if (!addedProgress) {
            centralTrendPanel.addProgressListener(new ProgressDialog("Quantitation Trend Plot", centralTrendPanel));
            addedProgress = true;
        }
        centralTrendPanel.startCalculating();
    }
    if (downstreamTrendPanel != null) {
        downstreamTrendPanel.addProgressListener(this);
        if (!addedProgress) {
            downstreamTrendPanel.addProgressListener(new ProgressDialog("Quantitation Trend Plot", downstreamTrendPanel));
            addedProgress = true;
        }
        downstreamTrendPanel.startCalculating();
    }
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) IOException(java.io.IOException) Probe(uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe) ProgressDialog(uk.ac.babraham.SeqMonk.Dialogs.ProgressDialog.ProgressDialog) BorderLayout(java.awt.BorderLayout) ActionListener(java.awt.event.ActionListener) JFileChooser(javax.swing.JFileChooser) JSlider(javax.swing.JSlider) FileFilter(javax.swing.filechooser.FileFilter) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 4 with ProgressDialog

use of uk.ac.babraham.SeqMonk.Dialogs.ProgressDialog.ProgressDialog in project SeqMonk by s-andrews.

the class SeqMonkParser method parseGenome.

/**
 * Parses the genome line.
 *
 * @param sections The tab split sections from the genome line
 * @throws SeqMonkException
 */
private void parseGenome(String[] sections) throws Exception {
    if (sections.length != 3) {
        throw new SeqMonkException("Genome line didn't contain 3 sections");
    }
    if (!sections[0].equals("Genome")) {
        throw new SeqMonkException("First line of file was not the genome description");
    }
    // If we have a multi genome then sections 1 and 2 will be sub-divided with bar characters
    String[] speciesStrings = sections[1].split("\\|");
    String[] assemblyStrings = sections[2].split("\\|");
    if (speciesStrings.length != assemblyStrings.length) {
        throw new SeqMonkException("Got different number of species and assembly names from '" + sections[1] + "' and '" + sections[2] + "'");
    }
    File[] files = new File[speciesStrings.length];
    for (int g = 0; g < speciesStrings.length; g++) {
        try {
            files[g] = new File(SeqMonkPreferences.getInstance().getGenomeBase().getAbsoluteFile() + "/" + speciesStrings[g] + "/" + assemblyStrings[g]);
        } catch (FileNotFoundException e) {
            throw new SeqMonkException("Couldn't find the folder which should contain the genome files.  Please check your file preferences.");
        }
        if (!files[g].exists()) {
            // The user doesn't have this genome - yet...
            // If the user has lost network connection or is using a custom genome
            // this can generate errors which we don't want to put up a crash reporter
            // for.  We therefore disable the crash reporter in our progress dialog and
            // we'll have custom code in our exceptionReceived method to handle these
            // cases nicely.
            // This variable is only used for error messages
            genomeToLoad = speciesStrings[g] + " " + assemblyStrings[g];
            GenomeDownloader d = new GenomeDownloader();
            d.addProgressListener(this);
            ProgressDialog pd = new ProgressDialog(application, "Downloading genome...");
            pd.setIgnoreExceptions(true);
            d.addProgressListener(pd);
            // Bit of a hack here, since we don't know the size of the genome
            // being downloaded we have to put an approximate value in so the
            // progress bar does something sensible.
            d.downloadGenome(speciesStrings[g], assemblyStrings[g], 25000000, true);
            pd.requestFocus();
            pauseWhilstLoadingGenome = true;
            while (pauseWhilstLoadingGenome) {
                if (exceptionReceived != null)
                    throw exceptionReceived;
                // This sleep *has* to be left in place.  If it doesn't then this thread gets
                // deadlocked and the flag is never reset once the new genome is downloaded
                // and the processing of the downloaded genome never starts.
                Thread.sleep(200);
            }
            if (exceptionReceived != null) {
                // Do we need to say we cancelled?
                return;
            }
        }
    }
    GenomeParser parser = new GenomeParser();
    parser.addProgressListener(this);
    parser.parseGenome(files);
    while (!genomeLoaded) {
        if (exceptionReceived != null)
            throw exceptionReceived;
        try {
            Thread.sleep(1000);
        } catch (InterruptedException ie) {
        }
    }
}
Also used : GenomeDownloader(uk.ac.babraham.SeqMonk.Network.GenomeDownloader) FileNotFoundException(java.io.FileNotFoundException) GenomeParser(uk.ac.babraham.SeqMonk.AnnotationParsers.GenomeParser) SeqMonkException(uk.ac.babraham.SeqMonk.SeqMonkException) ProgressDialog(uk.ac.babraham.SeqMonk.Dialogs.ProgressDialog.ProgressDialog) File(java.io.File)

Example 5 with ProgressDialog

use of uk.ac.babraham.SeqMonk.Dialogs.ProgressDialog.ProgressDialog in project SeqMonk by s-andrews.

the class BedGraphDataWriter method startProcessing.

public void startProcessing() {
    JFileChooser chooser = new JFileChooser(SeqMonkPreferences.getInstance().getSaveLocation());
    chooser.setMultiSelectionEnabled(false);
    chooser.setFileFilter(new FileFilter() {

        public String getDescription() {
            return "BedGraph";
        }

        public boolean accept(File f) {
            if (f.isDirectory() || f.getName().toLowerCase().endsWith(".bg")) {
                return true;
            }
            return false;
        }
    });
    int result = chooser.showSaveDialog(SeqMonkApplication.getInstance());
    if (result == JFileChooser.CANCEL_OPTION)
        return;
    File file = chooser.getSelectedFile();
    SeqMonkPreferences.getInstance().setLastUsedSaveLocation(file);
    if (file.isDirectory())
        return;
    if (!file.getPath().toLowerCase().endsWith(".bg")) {
        file = new File(file.getPath() + ".bg");
    }
    // We're going to make custom files for each of the data stores we're processing
    // so let's check whether these are going to cause problems.
    // We might have duplicated store names, or we might have names which aren't
    // compatible with being turned into filenames so we need to fix both of those.
    String[] fileFriendlyNames = new String[data.length];
    HashSet<String> seenNames = new HashSet<String>();
    for (int i = 0; i < data.length; i++) {
        String name = data[i].name();
        name = name.replaceAll("[^\\w\\d\\._-]+", "_");
        if (seenNames.contains(name)) {
            // We need to add a suffix to make this work
            int suffixCount = 1;
            while (true) {
                if (seenNames.contains("" + name + "_" + suffixCount)) {
                    ++suffixCount;
                } else {
                    break;
                }
            }
            name = name + "_" + suffixCount;
        }
        seenNames.add(name);
        fileFriendlyNames[i] = name;
    }
    files = new File[data.length];
    ArrayList<String> existingFiles = new ArrayList<String>();
    for (int i = 0; i < data.length; i++) {
        String path = file.getAbsolutePath();
        path = path.replaceAll("\\.bg$", "");
        path += "_" + fileFriendlyNames[i] + ".bg";
        files[i] = new File(path);
        if (files[i].exists()) {
            existingFiles.add(path);
        }
    }
    chrSizeFile = new File(file.getParentFile().getAbsolutePath() + "/chr_sizes.txt");
    if (chrSizeFile.exists()) {
        existingFiles.add(chrSizeFile.getAbsolutePath());
    }
    // Check if we're stepping on anyone's toes...
    if (!existingFiles.isEmpty()) {
        StringBuffer sb = new StringBuffer();
        for (String path : existingFiles) {
            sb.append(path);
            sb.append("\n");
        }
        int answer = JOptionPane.showOptionDialog(SeqMonkApplication.getInstance(), sb.toString() + " exists.  Do you want to overwrite the existing file(s)?", "Overwrite file(s)?", 0, JOptionPane.QUESTION_MESSAGE, null, new String[] { "Overwrite and Save", "Cancel" }, "Overwrite and Save");
        if (answer > 0) {
            return;
        }
    }
    addProgressListener(new ProgressDialog("Saving BEDGraph Files", this));
    Thread t = new Thread(this);
    t.start();
}
Also used : ArrayList(java.util.ArrayList) ProgressDialog(uk.ac.babraham.SeqMonk.Dialogs.ProgressDialog.ProgressDialog) JFileChooser(javax.swing.JFileChooser) FileFilter(javax.swing.filechooser.FileFilter) File(java.io.File) HashSet(java.util.HashSet)

Aggregations

ProgressDialog (uk.ac.babraham.SeqMonk.Dialogs.ProgressDialog.ProgressDialog)19 File (java.io.File)5 JFileChooser (javax.swing.JFileChooser)5 BorderLayout (java.awt.BorderLayout)4 JButton (javax.swing.JButton)4 JPanel (javax.swing.JPanel)4 InteractionClusterMatrix (uk.ac.babraham.SeqMonk.DataTypes.Interaction.InteractionClusterMatrix)4 FileFilter (javax.swing.filechooser.FileFilter)3 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 PrintWriter (java.io.PrintWriter)2 JSlider (javax.swing.JSlider)2 GenomeParser (uk.ac.babraham.SeqMonk.AnnotationParsers.GenomeParser)2 HierarchicalClusterSet (uk.ac.babraham.SeqMonk.DataTypes.Cluster.HierarchicalClusterSet)2 Chromosome (uk.ac.babraham.SeqMonk.DataTypes.Genome.Chromosome)2 ProbeList (uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeList)2 InteractionReportOptions (uk.ac.babraham.SeqMonk.Displays.Report.InteractionReport.InteractionReportOptions)2 GenomeDownloader (uk.ac.babraham.SeqMonk.Network.GenomeDownloader)2 AnnotatedInteractionReport (uk.ac.babraham.SeqMonk.Reports.Interaction.AnnotatedInteractionReport)2 SeqMonkException (uk.ac.babraham.SeqMonk.SeqMonkException)2