Search in sources :

Example 1 with GenomeDownloader

use of uk.ac.babraham.SeqMonk.Network.GenomeDownloader 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 2 with GenomeDownloader

use of uk.ac.babraham.SeqMonk.Network.GenomeDownloader in project SeqMonk by s-andrews.

the class SeqMonkApplication method downloadGenome.

/**
 * This method is usually called from data gathered by the genome selector
 * which will provide the required values for the assembly name.  This does
 * not actually load the specified genome, but just downloads it from the
 * online genome repository.
 *
 * @param species Species name
 * @param assembly Assembly name
 * @param size The size of the compressed genome file in bytes
 */
public void downloadGenome(String species, String assembly, int size) {
    GenomeDownloader d = new GenomeDownloader();
    d.addProgressListener(this);
    ProgressDialog pd = new ProgressDialog(this, "Downloading genome...");
    d.addProgressListener(pd);
    d.downloadGenome(species, assembly, size, true);
    pd.requestFocus();
}
Also used : GenomeDownloader(uk.ac.babraham.SeqMonk.Network.GenomeDownloader) ProgressDialog(uk.ac.babraham.SeqMonk.Dialogs.ProgressDialog.ProgressDialog)

Aggregations

ProgressDialog (uk.ac.babraham.SeqMonk.Dialogs.ProgressDialog.ProgressDialog)2 GenomeDownloader (uk.ac.babraham.SeqMonk.Network.GenomeDownloader)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 GenomeParser (uk.ac.babraham.SeqMonk.AnnotationParsers.GenomeParser)1 SeqMonkException (uk.ac.babraham.SeqMonk.SeqMonkException)1