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