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.test; 023 024import java.util.List; 025import static org.junit.Assert.*; 026import uk.ac.roslin.ensembl.dao.database.DBRegistry; 027import uk.ac.roslin.ensembl.dao.database.DBSpecies; 028import uk.ac.roslin.ensembl.datasourceaware.core.DAChromosome; 029import uk.ac.roslin.ensembl.datasourceaware.variation.DAVariation; 030import uk.ac.roslin.ensembl.exception.NonUniqueException; 031import uk.ac.roslin.ensembl.model.Mapping; 032 033public class Variation { 034 035 static DBRegistry reg; 036 037 static DAChromosome chr20_75; 038 static DAChromosome chr20_76; 039 static DBSpecies hs; 040 041 042 public Variation() throws NonUniqueException { 043 reg = RegistryProvider.geteReg(); 044 assertNotNull(reg); 045 046 047 hs = reg.getSpeciesByAlias("human"); 048 assertNotNull(hs); 049 050 try { 051 chr20_76 = hs.getChromosomeByName("20", "76"); 052 } catch (Exception e) { 053 AssertionError ae = new AssertionError( 054 "Failed to get chromosome by name"); 055 ae.initCause(e); 056 throw ae; 057 } 058 assertNotNull(chr20_76); 059 060 try { 061 chr20_75 = hs.getChromosomeByName("20", "75"); 062 } catch (Exception e) { 063 AssertionError ae = new AssertionError( 064 "Failed to get chromosome by name"); 065 ae.initCause(e); 066 throw ae; 067 } 068 assertNotNull(chr20_75); 069 } 070 071 public void testChromosomeVariations() { 072 List<DAVariation> variationsOnRegion = null; 073 074 try { 075 variationsOnRegion = chr20_75.getVariationsOnRegion(1, 100000); 076 } catch (Exception e) { 077 AssertionError ae = new AssertionError( 078 "Failed to get variations on Chromosome"); 079 ae.initCause(e); 080 throw ae; 081 } 082 083 assertNotNull(variationsOnRegion); 084 assertFalse(variationsOnRegion.isEmpty()); 085 086 DAVariation var = variationsOnRegion.get(0); 087 assertTrue(var.getChromosomeMappings().size()==1); 088 089 Mapping mapping = null; 090 try { 091 mapping =var.getChromosomeMapping(); 092 } catch (NonUniqueException e) { 093 AssertionError ae = new AssertionError( 094 "Chromosome mapping of this variation was not unique."); 095 ae.initCause(e); 096 throw ae; 097 } 098 assertNotNull(mapping); 099 100 try { 101 variationsOnRegion = chr20_76.getVariationsOnRegion(1, 100000); 102 } catch (Exception e) { 103 AssertionError ae = new AssertionError( 104 "Failed to get variations on Chromosome"); 105 ae.initCause(e); 106 throw ae; 107 } 108 109 assertNotNull(variationsOnRegion); 110 assertFalse(variationsOnRegion.isEmpty()); 111 112 var = variationsOnRegion.get(0); 113 assertTrue(var.getChromosomeMappings().size()==1); 114 115 mapping = null; 116 try { 117 mapping =var.getChromosomeMapping(); 118 } catch (NonUniqueException e) { 119 AssertionError ae = new AssertionError( 120 "Chromosome mapping of this variation was not unique."); 121 ae.initCause(e); 122 throw ae; 123 } 124 assertNotNull(mapping); 125 126 127 } 128 129 public static void main(String[] args) throws NonUniqueException, Exception { 130 Variation v = new Variation(); 131 try { 132 v.testChromosomeVariations(); 133 } catch (Exception e) { 134 System.out.println(e.getMessage()); 135 throw new Exception(e); 136 } 137 138 System.out.println("Successfuly completes Variation.java"); 139 } 140}