001 /** 002 * Copyright (C) 2010 The Roslin Institute <contact andy.law@roslin.ed.ac.uk> 003 * 004 * This file is part of the Ensembl Java API demonstration project developed by the 005 * Bioinformatics Group at The Roslin Institute, The Royal (Dick) School of 006 * Veterinary Studies, University of Edinburgh. 007 * 008 * This is free software: you can redistribute it and/or modify 009 * it under the terms of the GNU General Public License (version 3) as published by 010 * the Free Software Foundation. 011 * 012 * This software is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 015 * GNU General Public License for more details. 016 * 017 * You should have received a copy of the GNU General Public License 018 * in this software distribution. If not, see <http://www.gnu.org/licenses/gpl-3.0.html/>. 019 */ 020 021 package uk.ac.roslin.ensembl.dao.database; 022 023 import uk.ac.roslin.ensembl.exception.ConfigurationException; 024 import uk.ac.roslin.ensembl.model.core.Species; 025 import uk.ac.roslin.ensembl.model.database.SingleSpeciesDatabase; 026 import uk.ac.roslin.ensembl.config.EnsemblDBType; 027 import uk.ac.roslin.ensembl.exception.DAOException; 028 import uk.ac.roslin.ensembl.model.database.Registry; 029 030 /** 031 * 032 * @author tpaterso 033 */ 034 035 036 // will make this abstract once we fill in all the subtypes 037 038 public class DBSingleSpeciesDatabase extends DBDatabase implements SingleSpeciesDatabase { 039 040 protected DBSpecies species = null; 041 protected String dbSpeciesName; 042 protected String assembly = null; 043 044 045 public DBSingleSpeciesDatabase(String db_name, EnsemblDBType type, Registry registry) throws ConfigurationException { 046 super(db_name, type, registry); 047 init(); 048 } 049 050 private void init() throws ConfigurationException { 051 052 //ensembdbl are of style species_genus_type_version_build (i.e. 2 suffixes after type) 053 //ensemblgenomes are of style species_genus_type_version_ensembldbversion_build (ie 3 suffixes after type) 054 055 //this code will fall over if the magic conventions of db naming change! 056 //or if we have both styles in the same database! 057 //see DBRegistry line 215 058 059 this.dbSpeciesName = dBName.substring(0, dBName.indexOf("_" + this.type.toString())); 060 String sub = dBName.replace(dbSpeciesName + "_" + type.toString() + "_", ""); 061 062 //does the suffix have >1 token 063 if (sub.contains("_")) { 064 this.dbVersion = sub.substring(0, sub.indexOf("_")); 065 intDBVersion = Integer.parseInt(dbVersion); 066 067 //check if it has three suffixes 068 sub = sub.replace(dbVersion + "_", ""); 069 //does suffix have >2 tokens 070 if (sub.contains("_")) { 071 this.schemaVersion = sub.substring(0, sub.indexOf("_")); 072 this.intSchemaVersion = Integer.parseInt(schemaVersion); 073 build = sub.replace(schemaVersion + "_", ""); 074 075 } else //suffix has 2 tokens, therefore second is build 076 { 077 schemaVersion = dbVersion; 078 intSchemaVersion = intDBVersion; 079 build = sub; 080 } 081 082 } else //suffix has only one token, the ensembl release 083 { 084 this.dbVersion = sub; 085 intDBVersion = Integer.parseInt(dbVersion); 086 this.schemaVersion = dbVersion; 087 this.intSchemaVersion = intDBVersion; 088 } 089 090 } 091 092 @Override 093 public String getDbSpeciesName() { 094 return dbSpeciesName; 095 } 096 097 @Override 098 public void setDbSpeciesName(String species) { 099 this.dbSpeciesName = species; 100 } 101 102 103 @Override 104 public void setSpecies(Species species) { 105 this.species = (DBSpecies) species; 106 } 107 108 @Override 109 public DBSpecies getSpecies() { 110 return this.species; 111 } 112 113 @Override 114 public String getAssembly() { 115 if (assembly == null) { 116 try { 117 this.lazyLoadAssembly(); 118 } catch (DAOException e) { 119 //probably should throw this 120 } 121 } 122 return assembly; 123 } 124 125 public void lazyLoadAssembly() throws DAOException { 126 assembly = this.getRegistry().getAssembly(this); 127 } 128 }