DTP Warehouse Programming Examples

This document provides annotated examples of the use of the JAVA classes associated with the DTP Datawarehouse model. These examples are not intended to be complete, runnable programs. For examples of complete programs, see the CVS repository.

Use of the DTP JAVA classes requires DTPDatawarehouse.jar and the JDBC drivers for the database(s) that will be used (oracle.jar and/or postgresql.jar). If chemical structures are used, additional jars are necessary: DTPcml2.jar, xmlParserAPIs.jar, and xercesImpl.jar. The last two jars are from Apache XML Project. The first is part of the CML Document Object Model (CML DOM) from the Chemical Markup Language project. The integration of these jars with the DTP Datawarehouse project is still being worked on and subject to change. Contact Dan Zaharevitz for up to the minute details.

Connecting to a database

Import the jdbc classes
                import gov.nih.nci.dtp.jdbc.*;


Create a read only connection to the default database (the webdb instance on iv1prod.ncifcrf.gov)
		DTPConnect db = new DTPConnect();
		db.makeConnect();
Note: the identity of the default database is contained in the gov.nih.nci.dtp.jdbc.DTPjdbc.properties file. This file can be changed without the need to recompile the class.


create a connection specifying
		DTPConnect db = new DTPConnect(host, datab, port, usr, pwd, dtype);
		db.makeConnect();


request a pop-up dialog that lets the user enter connection information
                DTPConnect db = new DTPConnect();
		DbLogin dlog = new DbLogin(null);
		dlog.showDialog(db);
		db.makeConnect();

Create identifier objects

import the base package
                import gov.nih.nci.dtp.*;


NSC number
                NSC nsc1 = new NSC(123127);
		String strg = "123127";
		NSC nsc2 = new NSC(strg);


CAS registry number
                CAS cas1 = new CAS(59052);
		String strg = "59-05-2";
		CAS cas2 = new CAS(strg);


NCI Cell Line
                NCICellLine cell1 = new NCICellLine(5,14,"Breast","T-47D");

Create access object for a particular set of data

import database package
                import gov.nih.nci.dtp.db.*;


Set up a testmaster object for chemical name data
		DTPConnect db = new DTPConnect();
		db.makeConnect();
	        DTPTestmaster chemnames = new DTPTestmaster(DTPConstants.CHEMNAMEDATA, db);
for more constants that predefine standard data sets, see DTPConstants

Doing searches

Search for chemical names for NSC 123127 and output results
		DTPConnect db = new DTPConnect();
		db.makeConnect();
	        DTPTestmaster chemnames = new DTPTestmaster(DTPConstants.CHEMNAMEDATA, db);
		
		DTPResultSearch search = new DTPResultSearch();

                NSC nsc1 = new NSC(123127);
        	DTPTestResult [] names = search.getData(chemnames, nsc1);

		for ( int idx=0; idx < names.length; idx++)
		   {
		      System.out.println("Chemical Name is " + names[idx].getTextResult() );
		   }


Search for 2D chemical structure for NSC 740 and write out MDL mol file. This requires importing both the DTP CML package:
                import gov.nih.nci.dtp.structures.DBStoCML;
and the classes from the CML-DOM

                import org.xmlcml.cml.CMLMolecule; 
                import org.xmlcml.cmlimpl.DocumentFactoryImpl;
                import org.xmlcml.cml.CMLException;
                import org.xmlcml.legacy.molecule.MDLConverter;
		import org.xmlcml.cml.CMLList;


		DTPConnect db = new DTPConnect();
		db.makeConnect();
	        DTPTestmaster chem2D = new DTPTestmaster(DTPConstants.CHEM_2DDATA, db);
		
		DTPResultSearch search = new DTPResultSearch();

                NSC nsc1 = new NSC(123127);
        	DBStoCML dbsReader = new DBStoCML(db);
	        AbstractCMLDocument multiDoc = (AbstractCMLDocument) DocumentFactoryImpl.newInstance().createDocument();


		DTPTestResult [] result_2D = search.getData(chem2D, nsc1);
		if ( result_2D.length > 0 )
                 {
		  /* Note that there may be more than one structure returned for this call.
                     Use of the priority field means that the first one will be the "best"
                     version almost certainly the structure to use when one structure is called for,
                     but it is possible to get all the structures and compare.
		   */
		   StructureNbr snbr = result_2D[0].getStructNbr();
		   if ( snbr.idValue() != 0 )
		    {
		      CMLMolecule mol = null;
		      try
		       {
		         mol = dbsReader.ReadStructure(snbr);
		       }
		      catch (Exception ex)
		       {
		         System.out.println("2D structure retrieve failed\n" + ex.getMessage());
		       }
		       
		      if ( mol != null )
		       {
		          /* write out as CML */
		          mol.writeXML(xmlfile);
			  
			  /* write out as MDL mol file */
			  MDLConverter mdlcv = new MDLConverter();
			  try
			    {
			      mdlcv.write(mdlfile, mol);
			    }
			  catch (Exception ex)
			    {
		              System.out.println("ERROR writing Mol file");
			      System.out.print(ex);
			    }
		       }
		      else
		       {
		         System.out.println("Null 2D structure retrieved for NSC " + nsc1.idValue());
		       }
		    }
		   else
		    {
		      System.out.println("2D Structure number is zero for NSC " + nsc1.idValue());
		    }
		  }
		else
		  {
		    System.out.println("No 2D structures found for NSC " + idValue());
		  }



Note: for more extensive examples of using this code, see the code for the servlets on the DTP web pages.