public static Genome loadGenome(String genomeFileOrID) throws IOException {
String rootDir = FileUtils.getInstallDirectory();
final GenomeManager genomeManager = GenomeManager.getInstance();
Genome genome = genomeManager.getCurrentGenome();
if (genome != null && genome.getId().equals(genomeFileOrID)) {
return genome;
}
File genomeFile = new File(genomeFileOrID);
if (!genomeFile.exists()) {
genomeFile = new File(rootDir, "genomes" + File.separator + genomeFileOrID + ".genome");
}
if(!genomeFile.exists()) {
genomeFile = new File(rootDir, "genomes" + File.separator + genomeFileOrID + ".chrom.sizes");
}
if (!genomeFile.exists()) {
genomeFile = new File(rootDir, "genomes" + File.separator + genomeFileOrID);
}
if (!genomeFile.exists()) {
throw new PreprocessingException("Genome definition file not found for: " + genomeFileOrID);
}
//TODO Prevents loading genome again if loading from path.
//May or may not want this, for now we just use it for testing
if (Globals.isTesting() && genomeFile.getAbsolutePath().endsWith(".genome")) {
GenomeDescriptor genomeDescriptor = GenomeManager.parseGenomeArchiveFile(genomeFile);
if (genome != null && genomeDescriptor.getId().equals(genome.getId())) {
return genome;
}
}
genome = genomeManager.loadGenome(genomeFile.getAbsolutePath(), null);
if (genome == null) {
throw new PreprocessingException("Error loading: " + genomeFileOrID);
}
return genome;
}