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.demo; 023 024 025import java.util.List; 026import java.util.Set; 027import uk.ac.roslin.ensembl.config.DBConnection.DataSource; 028import uk.ac.roslin.ensembl.dao.database.DBRegistry; 029import uk.ac.roslin.ensembl.dao.database.DBSpecies; 030import uk.ac.roslin.ensembl.datasourceaware.compara.DAHomologyPairRelationship; 031import uk.ac.roslin.ensembl.datasourceaware.core.DADNASequence; 032import uk.ac.roslin.ensembl.datasourceaware.core.DAGene; 033import uk.ac.roslin.ensembl.exception.DAOException; 034import uk.ac.roslin.ensembl.model.Mapping; 035import uk.ac.roslin.ensembl.model.MappingSet; 036import uk.ac.roslin.ensembl.model.core.Species; 037 038/** 039 * 040 * @author tpaterso 041 */ 042public class BacterialGeneHomologues { 043 044 //retrieving all the homologue for a gene 045 //and comparing the mapping data for this gene in Compara - with 046 //that pulled out of correct core database 047 048 public static void main(String[] args) throws Exception { 049 050 DBRegistry eReg = DBRegistry.createRegistryForDataSourceCurrentRelease(DataSource.ENSEMBLBACTERIA); 051 Set<DBSpecies> panComparaSpecies = eReg.getPanComparaSpecies(null); 052 String release = ""+eReg.getHighestReleaseVersion(); 053 054 System.out.println("DBVersion "+release +" pan compara species: ["+panComparaSpecies.size() +" in total]:"); 055 for (DBSpecies sp: panComparaSpecies) { 056 System.out.println("\t"+sp.getSpeciesBinomial()+ 057 "\t\t"+sp.getComparaName(release)); 058 } 059 System.out.println(""); 060 061 DBSpecies sp = eReg 062 .getSpeciesByAlias("bacillus_pumilus_safr_032"); 063 064 065 //from release17 - only 100 odd species are in compara - and this is now the pancompara - not a bacterial compara 066 DAGene g = sp.getGeneByStableID("BPUM_0001"); 067 068 List<DAHomologyPairRelationship> out = g.getHomologies(); //pumilis is not in pan compara 069 System.out.println(g.getSpecies().getCommonName() + " gene " + g.getStableID() + " version "+g.getDBVersion() +" has " + out.size() + " homologies."); 070 System.out.println("_____________________________________________\r\n"); 071 072 073 DBSpecies sp2 = eReg 074 .getSpeciesByAlias("bacillus_subtilis_subsp_subtilis_str_168");//should be in pan compara 075 DAGene gs = sp2.getGeneByStableID("BSU00010"); 076 out = gs.getHomologies(); 077 System.out.println(gs.getSpecies().getCommonName() + " gene " + gs.getStableID() + "version "+gs.getDBVersion() +" has " + out.size() + " homologies."); 078 System.out.println("_____________________________________________\r\n"); 079 080 081 for (DAHomologyPairRelationship h : out) { 082 083 System.out.print(h.getTargetProperties().getSpeciesName()); 084 System.out.print(" gene: " + h.getTarget().getStableID()); 085 System.out.println(" [" + h.getType().toString() + "] (last common ancestor: " + h.getLastCommonAncestor() + ")"); 086 087 System.out.println("MAPPING DATA IN COMPARA"); 088 System.out.println("'chromosome' name: " + h.getTargetProperties().getSequenceName() 089 + " [" + h.getTargetProperties().getCoords().toString() + "]"); 090 091 092 System.out.println("MAPPING DATA LAZY LOADED FROM CORE"); 093 094 MappingSet m = null; 095 096 Species sppp = h.getSource().getRegistry().getSpeciesByAlias(h.getTargetProperties().getSpeciesName()); 097 098 try { 099 m = h.getTarget().getAnnotationLevelMappings(); 100 } catch (DAOException dAOException) { 101 } 102 103 System.out.print("ANNOTATION LEVEL: "); 104 if (m != null && !m.isEmpty()) { 105 for (Mapping mp : m) { 106 System.out.println(mp.getTarget().getClass().getSimpleName() 107 + " name: " 108 + ((DADNASequence) mp.getTarget()).getName() 109 + " id: " + mp.getTarget().getId() + " [" 110 + mp.getTargetCoordinates().toString() + "]"); 111 112 if (!h.getTargetProperties().getSequenceName().contentEquals(((DADNASequence) mp.getTarget()).getName())) { 113 System.out.println("\n\n\n*********ERROR in name"); 114 } 115 if (h.getTargetProperties().getCoords().getStart() - mp.getTargetCoordinates().getStart() != 0) { 116 System.out.println("\n\n\n*********ERROR in start coord"); 117 } 118 if (h.getTargetProperties().getCoords().getEnd() - mp.getTargetCoordinates().getEnd() != 0) { 119 System.out.println("\n\n\n*********ERROR in end coord"); 120 } 121 if (!h.getTargetProperties().getCoords().getStrand().equals(mp.getTargetCoordinates().getStrand())) { 122 System.out.println("\n\n\n*********ERROR in strande"); 123 } 124 125 } 126 } else { 127 System.out.println(""); 128 } 129 130 try { 131 m = h.getTarget().getBuildLevelMappings(); 132 } catch (DAOException dAOException) { 133 } 134 135 System.out.print("BUILD LEVEL: "); 136 if (m != null && !m.isEmpty()) { 137 138 for (Mapping mp : m) { 139 System.out.println(mp.getTarget().getClass().getSimpleName() 140 + " name: " 141 + ((DADNASequence) mp.getTarget()).getName() 142 + " id: " + mp.getTarget().getId() + " [" 143 + mp.getTargetCoordinates().toString() + "]"); 144 145 if (!h.getTargetProperties().getSequenceName().contentEquals(((DADNASequence) mp.getTarget()).getName())) { 146 System.out.println("\n\n\n*********ERROR in name"); 147 } 148 if (h.getTargetProperties().getCoords().getStart() - mp.getTargetCoordinates().getStart() != 0) { 149 System.out.println("\n\n\n*********ERROR in start coord"); 150 } 151 if (h.getTargetProperties().getCoords().getEnd() - mp.getTargetCoordinates().getEnd() != 0) { 152 System.out.println("\n\n\n*********ERROR in end coord"); 153 } 154 if (!h.getTargetProperties().getCoords().getStrand().equals(mp.getTargetCoordinates().getStrand())) { 155 System.out.println("\n\n\n*********ERROR in strande"); 156 } 157 158 } 159 } else { 160 System.out.println(""); 161 } 162 163 try { 164 m = h.getTarget().getTopLevelMappings(); 165 } catch (DAOException dAOException) { 166 } 167 System.out.print("TOP LEVEL: "); 168 if (m != null && !m.isEmpty()) { 169 for (Mapping mp : m) { 170 System.out.println(mp.getTarget().getClass().getSimpleName() 171 + " name: " 172 + ((DADNASequence) mp.getTarget()).getName() 173 + " id: " + mp.getTarget().getId() + " [" 174 + mp.getTargetCoordinates().toString() + "]"); 175 176 if (!h.getTargetProperties().getSequenceName().contentEquals(((DADNASequence) mp.getTarget()).getName())) { 177 System.out.println("\n\n\n*********ERROR in name"); 178 } 179 if (h.getTargetProperties().getCoords().getStart() - mp.getTargetCoordinates().getStart() != 0) { 180 System.out.println("\n\n\n*********ERROR in start coord"); 181 } 182 if (h.getTargetProperties().getCoords().getEnd() - mp.getTargetCoordinates().getEnd() != 0) { 183 System.out.println("\n\n\n*********ERROR in end coord"); 184 } 185 if (!h.getTargetProperties().getCoords().getStrand().equals(mp.getTargetCoordinates().getStrand())) { 186 System.out.println("\n\n\n*********ERROR in strande"); 187 } 188 189 } 190 } else { 191 System.out.println(""); 192 } 193 System.out.println("___________________________________________________"); 194 System.out.println(""); 195 } 196 197 System.out.println("\n\n*************************\nCOMPLETED FUNCTIONAL TEST\n*************************\n"); 198 199 } 200}