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