Search in sources :

Example 1 with MultiGenome

use of uk.ac.babraham.SeqMonk.DataTypes.Genome.MultiGenome in project SeqMonk by s-andrews.

the class GenomeParser method run.

/* (non-Javadoc)
	 * @see java.lang.Runnable#run()
	 */
public void run() {
    try {
        singleGenomes = new SingleGenome[baseLocations.length];
        for (int i = 0; i < baseLocations.length; i++) {
            singleGenomes[i] = new SingleGenome(baseLocations[i]);
        }
    } catch (SeqMonkException ex) {
        Enumeration<ProgressListener> en = listeners.elements();
        while (en.hasMoreElements()) {
            en.nextElement().progressExceptionReceived(ex);
            return;
        }
    }
    for (int g = 0; g < singleGenomes.length; g++) {
        File cacheCompleteFile = new File(baseLocations[g].getAbsoluteFile() + "/cache/cache.complete");
        if (cacheCompleteFile.exists()) {
            boolean cacheFailed = false;
            try {
                // Check the version inside the cache.complete file
                BufferedReader br = new BufferedReader(new FileReader(cacheCompleteFile));
                String line = br.readLine();
                br.close();
                if (line == null || line.length() == 0) {
                    // If there's no version in there then re-parse
                    cacheFailed = true;
                }
                // We re-parse if the cache was made by a different version
                if (!SeqMonkApplication.VERSION.equals(line)) {
                    System.err.println("Version mismatch between cache ('" + line + "') and current version ('" + SeqMonkApplication.VERSION + "') - reparsing");
                    cacheFailed = true;
                }
            } catch (IOException ioe) {
                cacheFailed = true;
            }
            // Check to see if the .dat files have changed since the cache
            // file was saved
            File[] files = baseLocations[g].listFiles(new FileFilter() {

                public boolean accept(File f) {
                    if (f.getName().toLowerCase().endsWith(".dat") || f.getName().toLowerCase().endsWith(".gff") || f.getName().toLowerCase().endsWith(".gff3") || f.getName().toLowerCase().endsWith(".gtf") || f.getName().toLowerCase().endsWith(".gff.gz") || f.getName().toLowerCase().endsWith(".gff3.gz") || f.getName().toLowerCase().endsWith(".gtf.gz")) {
                        return true;
                    } else {
                        return false;
                    }
                }
            });
            boolean datFilesUpdated = false;
            for (int f = 0; f < files.length; f++) {
                if (files[f].lastModified() > cacheCompleteFile.lastModified()) {
                    System.err.println("Modification on " + files[f] + " is newer than on " + cacheCompleteFile + " " + files[f].lastModified() + " vs " + cacheCompleteFile.lastModified());
                    datFilesUpdated = true;
                    break;
                }
            }
            if (cacheFailed || datFilesUpdated) {
                if (!cacheCompleteFile.delete()) {
                    System.err.println("Failed to delete the existing cache.complete file");
                }
                // System.err.println("Dat files updated - reparsing");
                parseGenomeFiles(singleGenomes[g], baseLocations[g]);
            } else {
                reloadCacheFiles(singleGenomes[g], baseLocations[g]);
            }
        } else {
            System.err.println("File '" + cacheCompleteFile + "' doesn't exist - reparsing");
            parseGenomeFiles(singleGenomes[g], baseLocations[g]);
        }
        File aliasesFile = new File(baseLocations[g].getAbsoluteFile() + "/aliases.txt");
        if (aliasesFile.exists()) {
            try {
                readAliases(aliasesFile, singleGenomes[g]);
            } catch (IOException e) {
                throw new IllegalStateException(e);
            }
        }
    }
    Genome genomeToReturn;
    if (singleGenomes.length == 1) {
        genomeToReturn = singleGenomes[0];
    } else {
        genomeToReturn = new MultiGenome(singleGenomes);
    }
    Enumeration<ProgressListener> en = listeners.elements();
    while (en.hasMoreElements()) {
        en.nextElement().progressComplete("load_genome", genomeToReturn);
    }
}
Also used : SingleGenome(uk.ac.babraham.SeqMonk.DataTypes.Genome.SingleGenome) Enumeration(java.util.Enumeration) MultiGenome(uk.ac.babraham.SeqMonk.DataTypes.Genome.MultiGenome) IOException(java.io.IOException) ProgressListener(uk.ac.babraham.SeqMonk.DataTypes.ProgressListener) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) SeqMonkException(uk.ac.babraham.SeqMonk.SeqMonkException) FileFilter(java.io.FileFilter) SingleGenome(uk.ac.babraham.SeqMonk.DataTypes.Genome.SingleGenome) Genome(uk.ac.babraham.SeqMonk.DataTypes.Genome.Genome) MultiGenome(uk.ac.babraham.SeqMonk.DataTypes.Genome.MultiGenome) File(java.io.File)

Aggregations

BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileFilter (java.io.FileFilter)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 Enumeration (java.util.Enumeration)1 Genome (uk.ac.babraham.SeqMonk.DataTypes.Genome.Genome)1 MultiGenome (uk.ac.babraham.SeqMonk.DataTypes.Genome.MultiGenome)1 SingleGenome (uk.ac.babraham.SeqMonk.DataTypes.Genome.SingleGenome)1 ProgressListener (uk.ac.babraham.SeqMonk.DataTypes.ProgressListener)1 SeqMonkException (uk.ac.babraham.SeqMonk.SeqMonkException)1