Search in sources :

Example 6 with ProgressDialog

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

the class SeqMonkApplication method loadGenome.

/**
 * Loads a genome assembly.  This will fail if the genome isn't currently
 * in the local cache and downloadGenome should be set first in this case.
 *
 * @param baseLocation The folder containing the requested genome.
 */
public void loadGenome(File[] baseLocations) {
    GotoDialog.clearRecentLocations();
    GenomeParser parser = new GenomeParser();
    ProgressDialog pd = new ProgressDialog(this, "Loading genome...");
    parser.addProgressListener(pd);
    parser.addProgressListener(this);
    parser.parseGenome(baseLocations);
    pd.requestFocus();
}
Also used : GenomeParser(uk.ac.babraham.SeqMonk.AnnotationParsers.GenomeParser) ProgressDialog(uk.ac.babraham.SeqMonk.Dialogs.ProgressDialog.ProgressDialog)

Example 7 with ProgressDialog

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

the class SeqMonkInformationPanel method actionPerformed.

public void actionPerformed(ActionEvent e) {
    if (e.getActionCommand().equals("set_temp_dir")) {
        JFileChooser chooser = new JFileChooser();
        chooser.setDialogTitle("Select a Cache Directory");
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
            SeqMonkPreferences.getInstance().setTempDirectory(chooser.getSelectedFile());
            try {
                SeqMonkPreferences.getInstance().savePreferences();
                populatePanel();
            } catch (IOException ioe) {
                throw new IllegalStateException(ioe);
            }
        }
    } else if (e.getActionCommand().equals("set_genomes_dir")) {
        JFileChooser chooser = new JFileChooser();
        chooser.setDialogTitle("Select a Genomes Directory");
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
            SeqMonkPreferences.getInstance().setGenomeBase(chooser.getSelectedFile());
            try {
                SeqMonkPreferences.getInstance().savePreferences();
                populatePanel();
            } catch (IOException ioe) {
                throw new IllegalStateException(ioe);
            }
        }
    } else if (e.getActionCommand().equals("set_r")) {
        // First try to autodetect the location
        String autoDetect = RVersionTest.autoDetectRLocation();
        if (autoDetect != null) {
            int answer = JOptionPane.showConfirmDialog(this, "Found an R installation at '" + autoDetect + "' use this?", "R detected", JOptionPane.YES_NO_OPTION);
            if (answer == JOptionPane.YES_OPTION) {
                SeqMonkPreferences.getInstance().setRLocation(autoDetect);
                try {
                    SeqMonkPreferences.getInstance().savePreferences();
                    populatePanel();
                    return;
                } catch (IOException ioe) {
                    throw new IllegalStateException(ioe);
                }
            }
        }
        // If we can't auto-detect, or if they don't want to use that, then let them
        // choose where R is.
        JOptionPane.showMessageDialog(this, "Couldn't auto-detect an R installation.  Please manually select the location of the R executable");
        JFileChooser chooser = new JFileChooser();
        chooser.setDialogTitle("Find R executable");
        chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
            SeqMonkPreferences.getInstance().setRLocation(chooser.getSelectedFile().getAbsolutePath());
            try {
                SeqMonkPreferences.getInstance().savePreferences();
                populatePanel();
            } catch (IOException ioe) {
                throw new IllegalStateException(ioe);
            }
        }
    } else if (e.getActionCommand().equals("install_r")) {
        // R sucks
        // 
        // If the user has R installed as an admin user, but they're running as a normal
        // user then a non-interactive session (such as the ones we use here), won't
        // put up a prompt to create a local library.
        // 
        // To get around this we can create the local library folder within the R script,
        // which is great, except that R checks for the existence of this library at
        // the start of the session, so making it during the session still doesn't allow
        // us to install anything.  We therefore have to run a completely separate script
        // just to make the directory
        // Do the local library script first
        // Now do the actual package install
        Thread t = new Thread(new Runnable() {

            public void run() {
                try {
                    File tempDir = TempDirectory.createTempDirectory();
                    // Get the template script
                    Template template = new Template(ClassLoader.getSystemResource("uk/ac/babraham/SeqMonk/create_local_library.r"));
                    // Write the script file
                    File scriptFile = new File(tempDir.getAbsoluteFile() + "/script.r");
                    PrintWriter pr = new PrintWriter(scriptFile);
                    pr.print(template.toString());
                    pr.close();
                    RScriptRunner runner = new RScriptRunner(tempDir);
                    RProgressListener listener = new RProgressListener(runner);
                    runner.addProgressListener(new ProgressRecordDialog("R Session", runner));
                    runner.runScript();
                    while (true) {
                        if (listener.cancelled()) {
                            return;
                        }
                        if (listener.exceptionReceived()) {
                            return;
                        }
                        if (listener.complete())
                            break;
                        Thread.sleep(500);
                    }
                    runner.cleanUp();
                    File tempDir2 = TempDirectory.createTempDirectory();
                    // Get the template script
                    Template template2 = new Template(ClassLoader.getSystemResource("uk/ac/babraham/SeqMonk/load_required_modules.r"));
                    // Write the script file
                    File scriptFile2 = new File(tempDir2.getAbsoluteFile() + "/script.r");
                    PrintWriter pr2 = new PrintWriter(scriptFile2);
                    pr2.print(template2.toString());
                    pr2.close();
                    RScriptRunner runner2 = new RScriptRunner(tempDir2);
                    RProgressListener listener2 = new RProgressListener(runner2);
                    runner2.addProgressListener(new ProgressRecordDialog("R Session", runner2));
                    runner2.runScript();
                    while (true) {
                        if (listener2.cancelled()) {
                            return;
                        }
                        if (listener2.exceptionReceived()) {
                            return;
                        }
                        if (listener2.complete())
                            break;
                        Thread.sleep(500);
                    }
                    runner2.cleanUp();
                    populatePanel();
                } catch (Exception ex) {
                    throw new IllegalStateException(ex);
                }
            }
        });
        t.start();
    } else if (e.getActionCommand().equals("clean_cache")) {
        Thread t = new Thread(new Runnable() {

            public void run() {
                ProgressDialog pd = new ProgressDialog("Cleaning the cache");
                File[] tempFiles = SeqMonkPreferences.getInstance().tempDirectory().listFiles();
                for (int f = 0; f < tempFiles.length; f++) {
                    pd.progressUpdated("Deleting file " + (f + 1) + " out of " + tempFiles.length, f, tempFiles.length);
                    if (Calendar.getInstance().getTimeInMillis() - tempFiles[f].lastModified() < 1000L * 60 * 60 * 12) {
                        // We only deal with things which are at least 12 hours old
                        continue;
                    }
                    // This might be a simple temp data file
                    if (tempFiles[f].isFile() && tempFiles[f].getName().startsWith("seqmonk") && tempFiles[f].getName().endsWith(".temp")) {
                        tempFiles[f].delete();
                    } else // This might be a temp directory
                    if (tempFiles[f].isDirectory() && tempFiles[f].getName().startsWith("seqmonk") && tempFiles[f].getName().contains("temp")) {
                        File[] files = tempFiles[f].listFiles();
                        for (int g = 0; g < files.length; g++) {
                            if (!files[g].delete()) {
                                throw new IllegalStateException(new IOException("Failed to delete " + files[g].getAbsolutePath()));
                            }
                        }
                        // Now remove the directory
                        tempFiles[f].delete();
                    }
                }
                pd.progressComplete("cache_clean", null);
                populatePanel();
            }
        });
        t.start();
    } else if (e.getActionCommand().equals("update_genomes")) {
        updateGenomesButton.setEnabled(false);
        GenomeUpgrader upgrader = new GenomeUpgrader();
        upgrader.addProgressListener(new ProgressDialog("Updating installed genomes"));
        upgrader.addProgressListener(new ProgressListener() {

            public void progressWarningReceived(Exception e) {
            }

            public void progressUpdated(String message, int current, int max) {
            }

            public void progressExceptionReceived(Exception e) {
            }

            public void progressComplete(String command, Object result) {
                updateGenomesButton.setVisible(false);
                updates = null;
                genomeUpdateLabel.setIcon(tickIcon);
                genomeUpdateLabelText.setText("All of your installed genomes are up to date");
            }

            public void progressCancelled() {
            }
        });
        upgrader.upgradeGenomes(updates);
    } else {
        throw new IllegalArgumentException("Didn't understand action '" + e.getActionCommand() + "'");
    }
}
Also used : GenomeUpgrader(uk.ac.babraham.SeqMonk.Network.GenomeUpgrader) IOException(java.io.IOException) ProgressDialog(uk.ac.babraham.SeqMonk.Dialogs.ProgressDialog.ProgressDialog) RProgressListener(uk.ac.babraham.SeqMonk.R.RProgressListener) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) SeqMonkException(uk.ac.babraham.SeqMonk.SeqMonkException) Template(uk.ac.babraham.SeqMonk.Utilities.Templates.Template) ProgressRecordDialog(uk.ac.babraham.SeqMonk.Dialogs.ProgressRecordDialog) JFileChooser(javax.swing.JFileChooser) RProgressListener(uk.ac.babraham.SeqMonk.R.RProgressListener) ProgressListener(uk.ac.babraham.SeqMonk.DataTypes.ProgressListener) File(java.io.File) RScriptRunner(uk.ac.babraham.SeqMonk.R.RScriptRunner) PrintWriter(java.io.PrintWriter)

Example 8 with ProgressDialog

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

the class SmallRNAQCPreferencesDialog method actionPerformed.

public void actionPerformed(ActionEvent ae) {
    if (ae.getActionCommand().equals("plot")) {
        Object[] featureObjects = featureList.getSelectedValues();
        String[] features = new String[featureObjects.length];
        for (int i = 0; i < featureObjects.length; i++) {
            features[i] = (String) featureObjects[i];
        }
        Object[] selectedObjects = dataList.getSelectedValues();
        if (selectedObjects.length == 0) {
            JOptionPane.showMessageDialog(this, "No data stores were selected", "Oops", JOptionPane.ERROR_MESSAGE);
            return;
        }
        DataStore[] selectedStores = new DataStore[selectedObjects.length];
        for (int i = 0; i < selectedObjects.length; i++) {
            selectedStores[i] = (DataStore) selectedObjects[i];
        }
        int minLength = 20;
        int maxLength = 30;
        if (minLengthField.getText().trim().length() > 0) {
            minLength = Integer.parseInt(minLengthField.getText().trim());
        }
        if (maxLengthField.getText().trim().length() > 0) {
            maxLength = Integer.parseInt(maxLengthField.getText().trim());
        }
        if (minLength > maxLength) {
            int temp = minLength;
            minLength = maxLength;
            maxLength = temp;
        }
        lowLength = minLength;
        highLength = maxLength;
        SmallRNAQCCalcualtor calc = new SmallRNAQCCalcualtor(collection, features, minLength, maxLength, selectedStores);
        calc.addListener(this);
        calc.addListener(new ProgressDialog("Small RNA QC Plot", calc));
        calc.startCalculating();
        setVisible(false);
    }
}
Also used : DataStore(uk.ac.babraham.SeqMonk.DataTypes.DataStore) ProgressDialog(uk.ac.babraham.SeqMonk.Dialogs.ProgressDialog.ProgressDialog)

Example 9 with ProgressDialog

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

the class FindFeaturesByNameDialog method run.

/* (non-Javadoc)
	 * @see java.lang.Runnable#run()
	 */
public void run() {
    spd = new ProgressDialog("Searching...", this);
    spd.progressUpdated("Starting Search...", 0, 1);
    makeFeatureList();
}
Also used : ProgressDialog(uk.ac.babraham.SeqMonk.Dialogs.ProgressDialog.ProgressDialog)

Example 10 with ProgressDialog

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

the class SeqMonkApplication method importData.

/**
 * Begins the import of new SequenceRead data
 *
 * @param parser A DataParser which will actually do the importing.
 */
public void importData(DataParser parser) {
    parser.addProgressListener(this);
    JFileChooser chooser = new JFileChooser(SeqMonkPreferences.getInstance().getDataLocation());
    chooser.setMultiSelectionEnabled(true);
    FileFilter filter = parser.getFileFilter();
    if (filter != null) {
        chooser.setFileFilter(parser.getFileFilter());
        int result = chooser.showOpenDialog(this);
        /*
			 * There seems to be a bug in the file chooser which allows the user to
			 * select no files, but not cancel if the control+double click on a file
			 */
        if (result == JFileChooser.CANCEL_OPTION || chooser.getSelectedFile() == null) {
            return;
        }
        SeqMonkPreferences.getInstance().setLastUsedDataLocation(chooser.getSelectedFile());
        parser.setFiles(chooser.getSelectedFiles());
    }
    // See if we need to display any options
    if (parser.hasOptionsPanel()) {
        DataParserOptionsDialog optionsDialog = new DataParserOptionsDialog(parser);
        optionsDialog.setLocationRelativeTo(this);
        boolean goAhead = optionsDialog.view();
        if (!goAhead) {
            return;
        }
    }
    ProgressDialog pd = new ProgressDialog(this, "Loading data...", parser);
    parser.addProgressListener(pd);
    try {
        parser.parseData();
    } catch (SeqMonkException ex) {
        throw new IllegalStateException(ex);
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) FileFilter(javax.swing.filechooser.FileFilter) ProgressDialog(uk.ac.babraham.SeqMonk.Dialogs.ProgressDialog.ProgressDialog) DataParserOptionsDialog(uk.ac.babraham.SeqMonk.Dialogs.DataParser.DataParserOptionsDialog)

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