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.EnsemblDBType; 030import uk.ac.roslin.ensembl.config.RegistryConfiguration; 031import uk.ac.roslin.ensembl.dao.database.DBDatabase; 032import uk.ac.roslin.ensembl.dao.database.DBRegistry; 033import uk.ac.roslin.ensembl.dao.database.DBSingleSpeciesCoreDatabase; 034import uk.ac.roslin.ensembl.dao.database.DBSpecies; 035import uk.ac.roslin.ensembl.model.core.Chromosome; 036import uk.ac.roslin.ensembl.model.core.ProteinFeature; 037import uk.ac.roslin.ensembl.model.core.Species; 038import uk.ac.roslin.ensembl.model.database.SingleSpeciesCoreDatabase; 039 040/** 041 * 042 * @author tpaterso 043 */ 044public class LoadLocalConfigurationProperties { 045 046 //demonstrated use of a local configuration.properties file instead of using the 047 //file in-place in the configuration module 048 049 //also uses a local db properties file 050 051 public static void main(String[] args) throws Exception { 052 053 054 File fileMR = new File("src/main/resources/example_local_configuration.properties"); 055 File fileDB = new File("src/main/resources/example_archive_config.properties"); 056 057 RegistryConfiguration conf = new RegistryConfiguration(); 058 conf.setDBByFile(fileDB); 059 conf.setSchemaByFile(fileMR); 060 DBRegistry eReg = DBRegistry.createRegistryForConfiguration(conf); 061 Species sp = eReg.getSpeciesByAlias("chicken"); 062 063 Chromosome chr = sp.getChromosomeByName("25", "47"); 064 065 System.out.println("Chromosome: "+chr.getChromosomeName()+", length: "+chr.getLength()); 066 067 System.out.println(eReg.getBriefRegistryReport()); 068 069 070 System.out.println("ensemblarchives registry report: "); 071 System.out.println("******************************* "); 072 073 074 File f = eReg.getRegistryReport(); 075 List<String> lines = Files.readAllLines(Paths.get(f.getCanonicalPath()), Charset.forName("UTF-8")); 076 for (String l:lines) { 077 System.out.println(l); 078 } 079 080 081 System.out.println("species count : "+eReg.getSpecies().size()); 082 int i = 1; 083 for (DBSpecies s: eReg.getSpecies()) { 084 System.out.println(i++ +": "+s.getSpeciesBinomial()); 085 086 for(DBDatabase d : s.getDatabasesByType(EnsemblDBType.core)) { 087 088 System.out.println(d.getdBName()+ " : "+d.getBuild()); 089 } 090 091 092 } 093 094 String human = "human"; // relies on alias look up 095 String release47 = "47"; 096 int translationID = 1; 097 098 SingleSpeciesCoreDatabase db = (SingleSpeciesCoreDatabase) eReg.getDatabase(human); 099 100 //DBSpecies homo = (DBSpecies) ensembldbRegistry.getSpeciesByAlias("human"); 101 102 103 if (db!=null) { 104 105 System.out.println("current human top level: "+db.getTopLevelCoordSystem().getId()); 106 System.out.println("current human chromosome level: "+db.getChromosomeLevelCoordSystem().getId()); 107 System.out.println("current human sequence level: "+db.getSequenceLevelCoordSystem().getId()); 108 109 } 110 111 System.out.println("Get features from Ensembl release 47 for human translation id ="+translationID); 112 113 List<? extends ProteinFeature> result47 = ((DBSingleSpeciesCoreDatabase) eReg 114 .getDatabase(human, EnsemblDBType.core, release47)) 115 .getCoreFactory() 116 .getProteinFeatureDAO() 117 .getProteinFeaturesByTranslationID(translationID); 118 119 120 System.out.println("retrieved: "+result47.size()+" features."); 121 122 System.out.println("\n\n*************************\nCOMPLETED FUNCTIONAL TEST\n*************************\n"); 123 124 } 125}