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.io.File; 025import java.nio.charset.Charset; 026import java.nio.file.Files; 027import java.nio.file.Paths; 028import java.util.List; 029import uk.ac.roslin.ensembl.config.DBConnection.DataSource; 030import uk.ac.roslin.ensembl.config.EnsemblDBType; 031import uk.ac.roslin.ensembl.config.RegistryConfiguration; 032import uk.ac.roslin.ensembl.dao.database.DBDatabase; 033import uk.ac.roslin.ensembl.dao.database.DBRegistry; 034import uk.ac.roslin.ensembl.dao.database.DBSingleSpeciesCoreDatabase; 035import uk.ac.roslin.ensembl.dao.database.DBSpecies; 036import uk.ac.roslin.ensembl.model.core.ProteinFeature; 037import uk.ac.roslin.ensembl.model.database.SingleSpeciesCoreDatabase; 038 039public class ArchivesConnection { 040 041 //Demonstrating typical connection to archives of the Ensembl (Vertebrate) datasource, 042 //Registry autoconfiguration and basic data retrieval functions. 043 public static void main(String[] args) throws Exception { 044 045 File fileMR = new File("src/main/resources/example_local_configuration.properties"); 046 047 RegistryConfiguration conf = new RegistryConfiguration(DataSource.ENSEMBLDB_ARCHIVES); 048 conf.setSchemaByFile(fileMR); 049 DBRegistry registry = DBRegistry.createRegistryForConfiguration(conf); 050 051 //this way fails to set the schema mappings and known version 052 //DBRegistry registry = new DBRegistry(DataSource.ENSEMBLDB_ARCHIVES); 053 054 System.out.println(registry.getBriefRegistryReport()); 055 System.out.println("ensemblarchives registry report: "); 056 System.out.println("******************************* "); 057 058 File f = registry.getRegistryReport(); 059 List<String> lines = Files.readAllLines(Paths.get(f.getCanonicalPath()), Charset.forName("UTF-8")); 060 for (String l:lines) { 061 System.out.println(l); 062 } 063 064 System.out.println("species count : " + registry.getSpecies().size()); 065 int i = 1; 066 for (DBSpecies s : registry.getSpecies()) { 067 System.out.println(i++ + ": " + s.getSpeciesBinomial()); 068 069 for (DBDatabase d : s.getDatabasesByType(EnsemblDBType.core)) { 070 071 System.out.println(d.getdBName() + " : " + d.getBuild()); 072 } 073 } 074 075 String human = "human"; // relies on alias look up 076 String release47 = "47"; 077 int translationID = 1; 078 079 SingleSpeciesCoreDatabase db = (SingleSpeciesCoreDatabase) registry.getDatabase(human); 080 if (db != null) { 081 082 System.out.println("current human top level: " + db.getTopLevelCoordSystem().getId()); 083 System.out.println("current human chromosome level: " + db.getChromosomeLevelCoordSystem().getId()); 084 System.out.println("current human sequence level: " + db.getSequenceLevelCoordSystem().getId()); 085 086 } 087 088 System.out.println("Get features from Ensembl release 47 for human translation id =" + translationID); 089 090 List<? extends ProteinFeature> result47 = 091 ((DBSingleSpeciesCoreDatabase) registry.getDatabase(human, EnsemblDBType.core, release47)) 092 .getCoreFactory().getProteinFeatureDAO().getProteinFeaturesByTranslationID(translationID); 093 094 095 System.out.println("retrieved: " + result47.size() + " features."); 096 097 System.out.println("\n\n*****************************\n* COMPLETED FUNCTIONAL TEST *\n*****************************\n"); 098 099 } 100}