Search in sources :

Example 1 with HTMLFileFilter

use of uk.ac.babraham.SeqMonk.Utilities.FileFilters.HTMLFileFilter in project SeqMonk by s-andrews.

the class ChromosomeViewReport method run.

/* (non-Javadoc)
	 * @see java.lang.Runnable#run()
	 */
public void run() {
    int upstreamContext = 0;
    if (upstreamContextField.getText().length() > 0) {
        upstreamContext = Integer.parseInt(upstreamContextField.getText());
    }
    int downstreamContext = 0;
    if (downstreamContextField.getText().length() > 0) {
        downstreamContext = Integer.parseInt(downstreamContextField.getText());
    }
    // We need an HTML file we're going to make into an index
    JFileChooser chooser = new JFileChooser(SeqMonkPreferences.getInstance().getSaveLocation());
    chooser.setMultiSelectionEnabled(false);
    chooser.addChoosableFileFilter(new HTMLFileFilter());
    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(".html") || file.getPath().toLowerCase().endsWith(".html"))) {
        file = new File(file.getPath() + ".html");
    }
    // Check if we're stepping on anyone's toes...
    if (file.exists()) {
        int answer = JOptionPane.showOptionDialog(SeqMonkApplication.getInstance(), 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;
        }
    }
    // We need to make a folder from the file
    File outputFolder = new File(file.getAbsolutePath().replace(".html", "_files"));
    outputFolder.mkdir();
    System.err.println("Output file is " + file.getAbsolutePath() + " output folder is " + outputFolder.getAbsolutePath());
    Chromosome[] chrs = collection.genome().getAllChromosomes();
    // Save the starting location so we can go back there after we're done
    Chromosome currentChr = DisplayPreferences.getInstance().getCurrentChromosome();
    long currentLocation = DisplayPreferences.getInstance().getCurrentLocation();
    for (int c = 0; c < chrs.length; c++) {
        progressUpdated("Processing Chr" + chrs[c].name(), c, chrs.length);
        Probe[] probes = collection.probeSet().getActiveList().getProbesForChromosome(chrs[c]);
        // We can now step through the probes making the image for each one
        for (int p = 0; p < probes.length; p++) {
            if (cancel) {
                progressCancelled();
                return;
            }
            int start = probes[p].start();
            int end = probes[p].end();
            start -= upstreamContext;
            end += downstreamContext;
            if (start < 1)
                start = 1;
            if (end < 1)
                end = 1;
            if (start > chrs[c].length())
                start = chrs[c].length();
            if (end > chrs[c].length())
                end = chrs[c].length();
            if (end - start < 100) {
                progressWarningReceived(new SeqMonkException("View for " + probes[p].name() + " was too small to export"));
                continue;
            }
            DisplayPreferences.getInstance().setLocation(chrs[c], SequenceRead.packPosition(start, end, Location.FORWARD));
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e1) {
            }
            File saveFile = new File(outputFolder.getAbsolutePath() + "/" + probes[p].name() + ".png");
            try {
                ImageSaver.savePNG(SeqMonkApplication.getInstance().chromosomeViewer(), saveFile);
            } catch (IOException e) {
                progressExceptionReceived(e);
                return;
            }
        }
    }
    DisplayPreferences.getInstance().setLocation(currentChr, currentLocation);
    reportComplete(null);
}
Also used : JFileChooser(javax.swing.JFileChooser) HTMLFileFilter(uk.ac.babraham.SeqMonk.Utilities.FileFilters.HTMLFileFilter) Chromosome(uk.ac.babraham.SeqMonk.DataTypes.Genome.Chromosome) SeqMonkException(uk.ac.babraham.SeqMonk.SeqMonkException) IOException(java.io.IOException) Probe(uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe) File(java.io.File)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 JFileChooser (javax.swing.JFileChooser)1 Chromosome (uk.ac.babraham.SeqMonk.DataTypes.Genome.Chromosome)1 Probe (uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe)1 SeqMonkException (uk.ac.babraham.SeqMonk.SeqMonkException)1 HTMLFileFilter (uk.ac.babraham.SeqMonk.Utilities.FileFilters.HTMLFileFilter)1