edu.upenn.crimson.io
Class Queries

java.lang.Object
  extended by edu.upenn.crimson.io.Queries

public class Queries
extends java.lang.Object

Functions related to QUERIES table.

Version:
$Id: Queries.java,v 1.66 2009/07/21 01:19:12 fisher Exp $
Notes:
Should see if can optimize db access by maintaining one Statement that is created every time a database connection is made.

Field Summary
(package private) static boolean DEBUG_OUTPUT
          If true, then whenever a (bp or codon) position selection query is run, the list of positions selected will be output to the file 'positions.list'.
(package private) static int SPECIES_CHUNK
          When writing data to a NEXUS file ('run()'), this is the number of species queried per SQL statement.
 
Constructor Summary
Queries()
           
 
Method Summary
static boolean dbContains(java.lang.String id)
          This will return true if a query exists in QUERIES with an id equal to 'id'.
static java.util.ArrayList dbList()
          This will return an ArrayList with id's for all queries in the QUERIES table.
static boolean delete(java.lang.String id)
          Removes a query from the database.
static java.util.TreeSet expandPositions(java.util.HashSet positionSet, boolean isCodons)
          This will convert a set of bp ranges to bp positions.
private static java.util.TreeSet getRandomPositions(int partitionLength, int numSamples, boolean isCodons)
           
static void load(java.lang.String id)
          This will load the specified query from the QUERIES table in the current database.
static void publish(Query query)
          This will publish the specified query in the QUERIES table in the current database.
static void publish(Query query, java.lang.String id, boolean overwrite)
          This will publish the specified query in the QUERIES table in the current database.
static Tree run(java.lang.String queryID, java.lang.String filename, boolean incSequence, boolean incCrimson, int incTree, boolean incNotes)
          This will perform a tree query, generating a NEXUS file.
static void run(java.lang.String queryID, java.lang.String filename, boolean incSequence, int numRuns)
          This will repeatedly run a query, generating a NEXUS file for each run.
static Tree runPhylip(java.lang.String queryID, java.lang.String filename, int incTree)
          This will perform a tree query, generating a phylip formatted file.
 java.lang.String toString()
          Returns the non-Clob columns in the QUERIES table.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEBUG_OUTPUT

static final boolean DEBUG_OUTPUT
If true, then whenever a (bp or codon) position selection query is run, the list of positions selected will be output to the file 'positions.list'.

See Also:
Constant Field Values

SPECIES_CHUNK

static final int SPECIES_CHUNK
When writing data to a NEXUS file ('run()'), this is the number of species queried per SQL statement. If more than 'SPECIES_CHUNK' number of species to query, than multiple queries will be performed, each one with 'SPECIES_CHUNK' number of species.

See Also:
Constant Field Values
Constructor Detail

Queries

public Queries()
Method Detail

load

public static void load(java.lang.String id)
This will load the specified query from the QUERIES table in the current database. If no query is specified then all queries will be loaded.


publish

public static void publish(Query query)
This will publish the specified query in the QUERIES table in the current database. It will overwrite any query already in the table with the same name.


publish

public static void publish(Query query,
                           java.lang.String id,
                           boolean overwrite)
This will publish the specified query in the QUERIES table in the current database. If 'overwrite' is true then this will replace any query object with the same name, already in the table. If 'id' is not empty, then it will be used, instead of query.id, as the name of the query to be published (ie. QUERIES.id).


dbList

public static java.util.ArrayList dbList()
This will return an ArrayList with id's for all queries in the QUERIES table.


dbContains

public static boolean dbContains(java.lang.String id)
This will return true if a query exists in QUERIES with an id equal to 'id'.


delete

public static boolean delete(java.lang.String id)
Removes a query from the database.


run

public static void run(java.lang.String queryID,
                       java.lang.String filename,
                       boolean incSequence,
                       int numRuns)
This will repeatedly run a query, generating a NEXUS file for each run. The output will be a NEXUS file that includes the Crimson and tree blocks. Query notes will not be included.

Parameters:
queryID - string ID for query to be run
filename - filename for NEXUS output
incSequence - when true, inner sequence IDs will be included in the NEXUS file
numRuns - number of runs

run

public static Tree run(java.lang.String queryID,
                       java.lang.String filename,
                       boolean incSequence,
                       boolean incCrimson,
                       int incTree,
                       boolean incNotes)
This will perform a tree query, generating a NEXUS file. If Query.onlyStruct is true then incCrimson and incTree will be ignored.

Parameters:
queryID - string ID for query to be run
filename - filename for NEXUS output
incSequence - when true, inner sequence IDs will be included in the NEXUS file
incCrimson - when true, the CRIMSON block will be included in the NEXUS file
incTree - There are multiple options dictated by incTree: 0 = no tree will be output; 1 = tree is included in NEXUS file; 2 = tree ouptut to second NEXUS file ("*.tree"); 3 = rooted tree ouptut to a newick file ("*.newick"); 4 = unrooted tree ouptut to a newick file ("*.newick")
incNotes - When true, the Query.notes will be appended to the end of the NEXUS file. The notes can, for example, contain a PAUP block. It is assumed that the notes are properly formatted for the NEXUS file.
Returns:
The found tree object is returned (null when errors).

runPhylip

public static Tree runPhylip(java.lang.String queryID,
                             java.lang.String filename,
                             int incTree)
This will perform a tree query, generating a phylip formatted file.

Parameters:
queryID - string ID for query to be run
filename - filename for NEXUS output
incTree - There are multiple options dictated by incTree: 0 = no tree will be output; 1 = no tree will be output; 2 = tree ouptut to second NEXUS file ("*.tree"); 3 = rooted tree ouptut to a newick file ("*.newick"); 4 = unrooted tree ouptut to a newick file ("*.newick")
Returns:
The found tree object is returned (null when errors).

getRandomPositions

private static java.util.TreeSet getRandomPositions(int partitionLength,
                                                    int numSamples,
                                                    boolean isCodons)

expandPositions

public static java.util.TreeSet expandPositions(java.util.HashSet positionSet,
                                                boolean isCodons)
This will convert a set of bp ranges to bp positions. If the set is codons, the underlying bp positions for the codons we be used. Note that the user enters positions going from (1 to N) but when we access the data we go from (0 to N-1). So we shift the user specified positions down by 1.


toString

public java.lang.String toString()
Returns the non-Clob columns in the QUERIES table. Each table record will be separated by a '\n' in the output.

Overrides:
toString in class java.lang.Object



Copyright 2006 Stephen Fisher, Susan Davidson, and Junhyong Kim, University of Pennsylvania.