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.HashMap;
025import java.util.List;
026import uk.ac.roslin.ensembl.config.DBConnection.DataSource;
027import uk.ac.roslin.ensembl.dao.compara.HomologyDAO;
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.DAChromosome;
032import uk.ac.roslin.ensembl.datasourceaware.core.DADNASequence;
033import uk.ac.roslin.ensembl.datasourceaware.core.DAGene;
034import uk.ac.roslin.ensembl.model.Coordinate;
035import uk.ac.roslin.ensembl.model.Mapping;
036import uk.ac.roslin.ensembl.model.MappingSet;
037
038/**
039 *
040 * @author tpaterso
041 */
042public class PlantsSyntenies {
043
044    //demonstrating ability to find regions of conserved synteny between 
045    //one species and another
046    
047    public static void main(String[] args) throws Exception {
048
049        DBRegistry eReg =  DBRegistry.createRegistryForDataSource(DataSource.ENSEMBLGENOMES);
050
051        DBSpecies rice = eReg.getSpeciesByAlias("oryza_sativa");
052        DBSpecies sorghum = eReg.getSpeciesByAlias("sorghum");
053
054        DAChromosome mChr3 = sorghum.getChromosomeByName("3");
055        HomologyDAO dao = mChr3.getComparaFactory().getHomologyDAO();
056
057        HashMap<DADNASequence, MappingSet> syntenies =
058                (HashMap<DADNASequence, MappingSet>)
059                    dao.getRegionsOfConservedSynteny(mChr3, new Coordinate(1, 1000000), rice);
060
061        System.out.println("_________________\r\n");
062
063        for ( DADNASequence dna: syntenies.keySet()) {
064
065
066            System.out.println(dna.getCoordSystem().getType().toString()
067                        +" "
068                        +dna.getName()+ " "+syntenies.get(dna).getExtent().toString());
069
070            for (Mapping mp : syntenies.get(dna)) {
071                System.out.println("\t"+((DAGene) mp.getTarget()).getStableID()
072                        +" : "+mp.getSourceCoordinates().toString());
073            }
074
075        }
076
077        List<DAGene> genes = mChr3.getGenesOnRegion(1, 1000000);
078
079        for (DAGene g : genes) {
080
081            System.out.println(g.getSpecies().getCommonName()+" Gene "+g.getStableID()
082                    +" "+rice.getCommonName()+ " homologues:");
083
084
085
086            for (DAHomologyPairRelationship hpr : g.getHomologies(rice)) {
087
088                DAGene target = hpr.getTarget();
089                MappingSet mappings = target.getAnnotationLevelMappings();
090
091                for (Mapping m : mappings) {
092
093                System.out.println("\t"+hpr.getType().toString()+" : "
094                        +target.getStableID()+" ["+m.getTargetType().toString()
095                        +" "+((DADNASequence) m.getTarget()).getName()
096                        +":"+m.getTargetCoordinates().toString()+"]");
097                }
098            }
099        }
100
101        System.out.println("\n\n*************************\nCOMPLETED FUNCTIONAL TEST\n*************************\n");
102
103
104    }
105
106}