1 /*

  2  * GDPC: The Genomic Diversity and Phenotype Connection

  3  * for more information: http://www.maizegenetics.net/gdpc/index.html

  4  *

  5  * Copyright (C) 2003  Terry Casstevens

  6  *

  7  * This library is free software; you can redistribute it and/or

  8  * modify it under the terms of the GNU Lesser General Public

  9  * License as published by the Free Software Foundation; either

 10  * version 2.1 of the License, or (at your option) any later version.

 11  *

 12  * This library is distributed in the hope that it will be useful,

 13  * but WITHOUT ANY WARRANTY; without even the implied warranty of

 14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU

 15  * Lesser General Public License for more details.

 16  */

 17

 18 /*

 19  * TestGDPC.java

 20  *

 21  * Created on October 11, 2003

 22  */

 23

 24 package gov.usda.gdpc.test;

 25

 26 import gov.usda.gdpc.*;

 27 import gov.usda.gdpc.axis.DBConnectionProxy;

 28 import java.util.List;

 29

 30

 31

 32 /**

 33  * This class demonstrates the use of The Genomic

 34  * Diversity and Phenotype Connection (GDPC) API.

 35  *

 36  * @author  terryc

 37  */

 38 public class TestGDPC {

 39    

 40     /** The GDPC gateway */

 41     private final DBGateway myDBGateway = DefaultDBGateway.getInstance();

 42    

 43     /** Creates a new instance of TestGDPC */

 44     public TestGDPC() {

 45     }

 46    

 47     /** main */

 48     public static void main(String[] args) {

 49         

 50         // create test object

 51         TestGDPC test = new TestGDPC();

 52        

 53         // make data source connections to gateway

 54         test.makeConnections();

 55        

 56         // test gateway methods

 57         test.testGetGenotypeExperimentGroup();

 58         test.testGetEnvironmentExperimentGroup();

 59         test.testGetLocusGroup();

 60         test.testGetPhenotypeOntologyGroup();

 61         test.testGetPhenotypetable();

 62         test.testGetGenotypetable();

 63        

 64         // Get and print out list of taxa received

 65         TaxonGroup group = test.testGetTaxonGroup();

 66         for (int i=0, n=group.size(); i<n; i++) {

 67             System.out.println(group.get(i));

 68         }

 69        

 70     }

 71    

 72    

 73     /**

 74      * This creates and adds a database connection

 75      * (Panzea database) to the GDPC gateway.

 76      */

 77     public void makeConnections() {

 78        

 79         // this shows how you could connect to a private database

 80         // DBConnection connection = new PanzeaDBConnection(

 81         // "oracle.jdbc.driver.OracleDriver", "Panzea database",

 82         // "oracle.jdbc.driver.OracleDriver",

 83         // "jdbc:oracle:thin:@gaut.statgen.ncsu.edu:1521:panzea", "??", "??");

 84        

 85         // instantiate connection to web service for the panzea database

 86         DBConnection connection = new DBConnectionProxy("PanzeaConnection",

 87         "http://152.14.14.27:8080/axis/services/PanzeaConnection");

 88        

 89         // add connection to gateway

 90         myDBGateway.addDBConnection(connection);

 91        

 92     }

 93    

 94    

 95     /**

 96      * Tests the gateway method to get a taxon group.

 97      *

 98      * @return taxon group

 99      */

100     public TaxonGroup testGetTaxonGroup() {

101        

102         // taxon properties

103         TaxonProperty [] props = new TaxonProperty[2];

104         props[0] = TaxonProperty.SUBSPECIES;

105         props[1] = TaxonProperty.GENUS;

106        

107         // get distinct values for given taxon properties

108         DistinctPropertyValues values = myDBGateway.getDistinctProperties(props);

109         

110         // get distinct values for specified property

111         // from previously return object

112         List distinctSubspecies = values.getValues(TaxonProperty.SUBSPECIES);

113         List distinctGenus = values.getValues(TaxonProperty.GENUS);

114        

115         // create taxon filter

116         TaxonFilter filter = new TaxonFilter();

117        

118         // add values to the filter

119         filter.addValue(new FilterSingleValue(TaxonProperty.SUBSPECIES, "mexicana"));

120         filter.addValue(new FilterSingleValue(TaxonProperty.SUBSPECIES, distinctSubspecies.get(2)));

121         filter.addValue(new FilterSingleValue(TaxonProperty.GENUS, distinctGenus.get(1)));

122         filter.addValue(new FilterSingleValue(TaxonProperty.GENUS, "genus"));

123        

124         // retrieve taxon group using filter

125         TaxonGroup group = myDBGateway.getTaxonGroup(filter);

126        

127         return group;

128        

129     }

130    

131    

132     /**

133      * Tests the gateway method to get a locus group.

134      *

135      * @return locus group

136      */

137     public LocusGroup testGetLocusGroup() {

138        

139         // locus properties

140         LocusProperty [] props = new LocusProperty[2];

141         props[0] = LocusProperty.CHROMOSOME_NUMBER;

142         props[1] = LocusProperty.LOCUS_TYPE;

143        

144         // get distinct values for specified locus properties

145         DistinctPropertyValues values = myDBGateway.getDistinctProperties(props);

146        

147         // get distinct values for specified property

148         // from previously return object

149         List distinctChromosomeNumbers = values.getValues(LocusProperty.CHROMOSOME_NUMBER);

150         List distinctTypes = values.getValues(LocusProperty.LOCUS_TYPE);

151        

152         // create locus filter

153         LocusFilter filter = new LocusFilter();

154        

155         // add values to the filter

156         filter.addValue(new FilterSingleValue(LocusProperty.CHROMOSOME_NUMBER, distinctChromosomeNumbers.get(1)));

157         filter.addValue(new FilterSingleValue(LocusProperty.CHROMOSOME_NUMBER, new Integer(5)));

158         filter.addValue(new FilterSingleValue(LocusProperty.LOCUS_TYPE, distinctTypes.get(1)));

159         filter.addValue(new FilterSingleValue(LocusProperty.LOCUS_TYPE, distinctTypes.get(2)));

160        

161         // retrieve locus group using filter

162         LocusGroup group = myDBGateway.getLocusGroup(filter);

163        

164         return group;

165        

166     }

167    

168    

169     /**

170      * Tests the gateway method to get an environment experiment group.

171      *

172      * @return environment experiment group

173      */

174     public EnvironmentExperimentGroup testGetEnvironmentExperimentGroup() {

175        

176         // environment experiment properties

177         EnvironmentExperimentProperty [] props = new EnvironmentExperimentProperty[1];

178         props[0] = EnvironmentExperimentProperty.PLANT_DATE;

179        

180         // get distinct values for specified environment experiment properties

181         DistinctPropertyValues values = myDBGateway.getDistinctProperties(props);

182         

183         // get distinct values for specified property

184         // from previously return object

185         List properties = values.getValues(EnvironmentExperimentProperty.PLANT_DATE);

186        

187         // create environment experiment filter

188         EnvironmentExperimentFilter filter = new EnvironmentExperimentFilter();

189        

190         // add values to the filter

191         filter.addValue(new FilterSingleValue(EnvironmentExperimentProperty.PLANT_DATE, properties.get(1)));

192         filter.addValue(new FilterSingleValue(EnvironmentExperimentProperty.PLANT_DATE, properties.get(2)));

193         filter.addValue(new FilterRangeValue(EnvironmentExperimentProperty.PLANT_DATE, (Comparable)properties.get(3),  (Comparable)properties.get(5)));

194        

195         // retrieve environment experiment group using filter

196         EnvironmentExperimentGroup group = myDBGateway.getEnvironmentExperimentGroup(filter);

197        

198         return group;

199         

200     }

201    

202    

203     /**

204      * Tests the gateway method to get a genotype experiment group.

205      *

206      * @return genotype experiment group

207      */

208     public GenotypeExperimentGroup testGetGenotypeExperimentGroup() {

209        

210         // genotype experiment properties

211         GenotypeExperimentProperty [] props = new GenotypeExperimentProperty[1];

212         props[0] = GenotypeExperimentProperty.ID;

213        

214         // get distinct values for specified genotype experiment properties

215         DistinctPropertyValues values = myDBGateway.getDistinctProperties(props);

216        

217         // get distinct values for specified property

218         // from previously return object

219         List properties = values.getValues(GenotypeExperimentProperty.ID);

220        

221         // create genotype experiment filter

222         GenotypeExperimentFilter filter = new GenotypeExperimentFilter();

223        

224         // add values to the filter

225         filter.addValue(new FilterSingleValue(GenotypeExperimentProperty.ID, properties.get(1)));

226         filter.addValue(new FilterSingleValue(GenotypeExperimentProperty.ID, properties.get(2)));

227        

228         // retrieve genotype experiment group using filter

229         GenotypeExperimentGroup group = myDBGateway.getGenotypeExperimentGroup(filter);

230        

231         return group;

232        

233     }

234    

235    

236     /**

237      * Tests the gateway method to get a phenotype ontology group.

238      *

239      * @return phenotype ontology group

240      */

241     public PhenotypeOntologyGroup testGetPhenotypeOntologyGroup() {

242        

243         // create phenotype ontology filter

244         PhenotypeOntologyFilter filter = new PhenotypeOntologyFilter();

245        

246         // add value to filter

247         filter.addValue(new FilterSingleValue(PhenotypeOntologyProperty.NAME, "DSILK"));

248        

249         // retrieve phenotype ontology group using filter

250         PhenotypeOntologyGroup group = myDBGateway.getPhenotypeOntologyGroup(filter);

251        

252         return group;

253     }

254    

255    

256     /**

257      * Tests the gateway method to get a phenotype table.

258      *

259      * @return phenotype table

260      */

261     public PhenotypeTable testGetPhenotypetable() {

262        

263         // use other test methods to get an environment experiment group,

264         // a taxon group, and phenotype ontology group

265         EnvironmentExperimentGroup envGroup = testGetEnvironmentExperimentGroup();

266         TaxonGroup taxonGroup = testGetTaxonGroup();

267         PhenotypeOntologyGroup ontologyGroup = testGetPhenotypeOntologyGroup();

268        

269         // get the phenotype group

270         PhenotypeGroup group = myDBGateway.getPhenotypeGroup(envGroup, taxonGroup, ontologyGroup);

271        

272         // create a phenotype table based on phenotype group and

273         // particular phenotype ontology

274         PhenotypeOntology ontology = (PhenotypeOntology) ontologyGroup.get(0);

275         PhenotypeTable table = PhenotypeTable.getInstance(group, ontology);

276        

277         return table;

278        

279     }

280    

281    

282     /**

283      * Tests the gateway method to get a genotype table.

284      *

285      * @return genotype table

286      */

287     public GenotypeTable testGetGenotypetable() {

288         

289         // use other test methods to get an genotype experiment group

290         // and a taxon group.

291         GenotypeExperimentGroup expGroup = testGetGenotypeExperimentGroup();

292         TaxonGroup taxonGroup = testGetTaxonGroup();

293        

294         // get genotype group

295         GenotypeGroup group = myDBGateway.getGenotypeGroup(expGroup, taxonGroup);

296        

297         // create genotype table

298         GenotypeTable table = GenotypeTable.getInstance(group);

299        

300         return table;

301        

302     }

303    

304 }