001/** 002 * Copyright (C) 2010-2015 The Roslin Institute <contact andy.law@roslin.ed.ac.uk> 003 * 004 * This file is part of JEnsembl: a Java API to Ensembl data sources developed by the 005 * Bioinformatics Group at The Roslin Institute, The Royal (Dick) School of 006 * Veterinary Studies, University of Edinburgh. 007 * 008 * Project hosted at: http://jensembl.sourceforge.net 009 * 010 * This is free software: you can redistribute it and/or modify 011 * it under the terms of the GNU General Public License (version 3) as published by 012 * the Free Software Foundation. 013 * 014 * This software is distributed in the hope that it will be useful, 015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 017 * GNU General Public License for more details. 018 * 019 * You should have received a copy of the GNU General Public License 020 * in this software distribution. If not, see: http://opensource.org/licenses/gpl-3.0.html 021 */ 022package uk.ac.roslin.ensembl.datasourceaware; 023 024import java.util.TreeSet; 025import org.slf4j.Logger; 026import org.slf4j.LoggerFactory; 027import uk.ac.roslin.ensembl.config.EnsemblCoreObjectType; 028import uk.ac.roslin.ensembl.dao.factory.DAOCoreFactory; 029import uk.ac.roslin.ensembl.exception.DAOException; 030import uk.ac.roslin.ensembl.model.Evidence; 031import uk.ac.roslin.ensembl.model.ExternalDB; 032import uk.ac.roslin.ensembl.model.ObjectType; 033import uk.ac.roslin.ensembl.model.XRef; 034 035/** 036 * 037 * @author tpaterso 038 */ 039public class DAXRef extends DAObject implements XRef { 040 041 private ExternalDB dB = null ; 042 protected String version = null ; 043 private String description = null ; 044 private String infoType = null; 045 private String info = null; 046 private String displayID = null ; 047 private String primaryAccession = null ; 048 protected boolean initialized = false; 049 private TreeSet<String> synonyms = null; 050 final static Logger LOGGER = LoggerFactory.getLogger(DAXRef.class); 051 private Evidence evidence = null; 052 053 @Override 054 public DAOCoreFactory getDaoFactory() { 055 return (daoFactory!=null && daoFactory instanceof DAOCoreFactory)?(DAOCoreFactory) daoFactory:null; 056 } 057 058 @Override 059 public ExternalDB getDB() { 060 if (dB==null) { 061 this.reinitialize(); 062 } 063 return dB; 064 } 065 066 public void setDB(ExternalDB dB) { 067 this.dB = dB; 068 } 069 070 @Override 071 public String getDescription() { 072 if (description==null) { 073 this.reinitialize(); 074 } 075 return description; 076 } 077 078 public void setDescription(String description) { 079 this.description = description; 080 } 081 082 @Override 083 public String getDisplayID() { 084 if (displayID==null) { 085 this.reinitialize(); 086 } 087 return displayID; 088 } 089 090 public void setDisplayID(String displayID) { 091 this.displayID = displayID; 092 } 093 094 @Override 095 public String getInfo() { 096 if (info==null) { 097 this.reinitialize(); 098 } 099 return info; 100 } 101 102 public void setInfo(String info) { 103 this.info = info; 104 } 105 106 @Override 107 public String getInfoType() { 108 if (infoType==null) { 109 this.reinitialize(); 110 } 111 return infoType; 112 } 113 114 public void setInfoType(String infoType) { 115 this.infoType = infoType; 116 } 117 118 @Override 119 public String getVersion() { 120 if (version==null) { 121 this.reinitialize(); 122 } 123 return version; 124 } 125 126 public void setVersion(String version) { 127 this.version = version; 128 } 129 130 @Override 131 public String getDBDisplayName() { 132 return (this.getDB()!=null)?dB.getDBDisplayName():""; 133 } 134 135 @Override 136 public ObjectType getType() { 137 return EnsemblCoreObjectType.xref; 138 } 139 140 @Override 141 public String getPrimaryAccession() { 142 if (primaryAccession==null) { 143 this.reinitialize(); 144 } 145 return primaryAccession; 146 } 147 148 public void setPrimaryAccession(String primaryAccession) { 149 this.primaryAccession = primaryAccession; 150 } 151 152 153 private void reinitialize() { 154 if (this.isInitialized()) { 155 return; 156 } 157 try { 158 //nb getDaoFactory() will try and make a factory if we have at least species and ensembl version 159 this.getDaoFactory().getXRefDAO().reInitialize(this); 160 161 } catch (Exception ex) { 162 LOGGER.info("Failed to reinitialize the XRef from the Database (using its xref_id: " 163 +this.getId()+").", ex); 164 } finally { 165 //always set this so dont try again 166 this.setInitialized(true); 167 } 168 169 } 170 171 public boolean isInitialized() { 172 return initialized; 173 } 174 175 public void setInitialized(boolean init) { 176 this.initialized = init; 177 } 178 179 @Override 180 public TreeSet<String> getSynonyms() { 181 182 if (synonyms!=null) { 183 return synonyms; 184 } 185 this.reinitialize(); 186 if (this.getDaoFactory() != null) { 187 try { 188 synonyms = this.getDaoFactory().getXRefDAO().getSynonyms(this); 189 } catch (DAOException ex) { 190 LOGGER.debug("Failed to getSynonyms for an XRef", ex); 191 } 192 } 193 if (synonyms==null) { 194 synonyms = new TreeSet<String>(); 195 } 196 return synonyms; 197 } 198 199 @Override 200 public Evidence getEvidence() { 201 if (this.evidence==null) { 202 this.reinitialize(); 203 } 204 return this.evidence; 205 } 206 207 public void setEvidence(Evidence evidence) { 208 this.evidence = evidence; 209 } 210}