/*
* EuroCarbDB, a framework for carbohydrate bioinformatics
*
* Copyright (c) 2006-2009, Eurocarb project, or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
* A copy of this license accompanies this distribution in the file LICENSE.txt.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* Last commit: $Rev: 1932 $ by $Author: glycoslave $ on $Date:: 2010-08-05 #$
*/
package org.eurocarbdb.dataaccess.core;
// Generated 3/08/2006 16:48:24 by Hibernate Tools 3.1.0.beta4
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import java.util.List;
import java.util.ArrayList;
import java.io.Serializable;
import java.util.Collections;
import org.apache.log4j.Logger;
import org.eurocarbdb.util.mesh.MeshReference;
import org.eurocarbdb.dataaccess.EntityManager;
import static org.eurocarbdb.dataaccess.Eurocarb.getEntityManager;
/* class Perturbation *//******************************************
*<p>
* Perturbation is the general name for experimental treatments that
* modify a biological sample. This includes the addition of synthetic
* or naturally-derived chemicals, hormones, exposure to altered chemical
* environments or conditions, heat/cold, as well as anything else that
* <em>perturbs</em> the native condition of a biological sample.
*</p>
*<p>
* Our current working vocabulary for perturbations is the MeSH
* "Chemicals and Drugs" tree, although in actuality this is a subset of
* the range of possible perturbations listed above (since MeSH does not
* comprise vocabularies for conditions involving altered temperature/pressure
* for example).
*</p>
*<p>
* This class was initially auto-generated by the Hibernate hbm2java tool.
*</p>
* @author mjh <glycoslave@gmail.com>
* @version $rev$
*/
public class Perturbation extends MeshReference implements Serializable, Comparable
{
//~~~~~~~~~~~~~~~~~~~~~~ STATIC FIELDS ~~~~~~~~~~~~~~~~~~~~~~~~//
/** Logging handle. */
protected static final Logger log = Logger.getLogger( Perturbation.class );
/** Named query for getting diseases by name or synonym.
* @see the Disease.hbm.xml mapping file. */
private static final String Q = Perturbation.class.getName() + '.';
// = "org.eurocarbdb.dataaccess.core.Perturbation.MATCHING_NAME_OR_SYNONYM";
//~~~~~~~~~~~~~~~~~~~~~~~~~~ FIELDS ~~~~~~~~~~~~~~~~~~~~~~~~~~~//
/** EurocarbDB-supplied unique perturbation id. */
private int perturbationId;
/** Name of this perturbation, as determined by MeSH. */
private String perturbationName;
/** MeSH-determined unique ID. */
private String meshId;
/** Description of this perturbation; anywhere from zero text to a
* paragraph or 2. This information also comes from MeSH.
*/
private String description;
/** Date this entry was last modified in the EurocarbDB (whether by MeSH
* or for any other reason).
*/
private Date dateLastModified;
/** Set of all PerturbationContexts that refer to this Perturbation. */
private Set<PerturbationContext> perturbationContexts
= new HashSet<PerturbationContext>(0);
/** Set of hierachical information for this perturbation using an
* implementation of Nested Sets.
*/
private Set<PerturbationRelations> perturbationRelations
= new HashSet<PerturbationRelations>(0);
/** Direct parent of this perturbation. */
private Perturbation parentPerturbation;
/** Set of direct children of this perturbation. */
private Set<Perturbation> childPerturbations = new HashSet<Perturbation>(0);
//~~~~~~~~~~~~~~~~~~~~~~ CONSTRUCTORS ~~~~~~~~~~~~~~~~~~~~~~~~~//
/** Default constructor */
public Perturbation() {}
/** Minimal constructor */
public Perturbation(String perturbationName, String meshId)
{
this.perturbationName = perturbationName;
this.meshId = meshId;
}
/** Full constructor */
public Perturbation( Perturbation parentPerturbation,
String perturbationName,
String meshId,
String description,
Date dateLastModified,
Set<Perturbation> childPerturbations,
Set<PerturbationContext> perturbationContexts,
Set<PerturbationRelations> perturbationRelations
)
{
this.parentPerturbation = parentPerturbation;
this.perturbationName = perturbationName;
this.meshId = meshId;
this.description = description;
this.dateLastModified = dateLastModified;
this.childPerturbations = childPerturbations;
this.perturbationContexts = perturbationContexts;
this.perturbationRelations = perturbationRelations;
}
//~~~~~~~~~~~~~~~~~~~~~~ STATIC METHODS ~~~~~~~~~~~~~~~~~~~~~~~//
/* lookupByMeshId *//******************************************
*
* Returns the Perturbation with the given mesh id, or null if nothing
* matches.
*
* @throws IllegalArgumentException if the given {@link String}
* is not a valid MESH id.
* @see MeshReference
*/
public static Perturbation lookupByMeshId( String mesh_id )
{
if ( mesh_id == null || mesh_id.length() < 3 )
throw new IllegalArgumentException(
"Invalid MESH id string '" + mesh_id + "'");
if ( log.isDebugEnabled() )
log.debug( "looking up perturbation matching mesh id=" + mesh_id );
EntityManager em = getEntityManager();
Object result = em.getQuery( Q + "by_mesh_id" )
.setParameter( "mesh_id", mesh_id )
.uniqueResult();
return (Perturbation) result;
}
/* lookupNameOrSynonym *//*************************************
*
* Returns the list of diseases whose name or synonym fields
* match the passed search string. Throws an UnsupportedOperationException
* if search string is null or shorter than 3 characters.
*/
@SuppressWarnings("unchecked") // needed because Hibernate does not have generics
public static List<Perturbation> lookupNameOrSynonym( String search_string )
throws UnsupportedOperationException
{
if ( search_string == null || search_string.length() < 3 )
throw new UnsupportedOperationException(
"Perturbation name/synonym searches of < 3 chars not supported");
if ( log.isDebugEnabled() )
log.debug( "looking up perturbations whose name or synonym matches '"
+ search_string
+ "'" );
EntityManager em = getEntityManager();
List result = em.getQuery( Q + "MATCHING_NAME_OR_SYNONYM" )
.setParameter( "perturbation_name", '%' + search_string + '%' )
.list();
return (List<Perturbation>) result;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~ METHODS ~~~~~~~~~~~~~~~~~~~~~~~~~~~//
/** Returns EurocarbDB-given unique Perturbation ID. */
public int getPerturbationId()
{
return this.perturbationId;
}
/** Sets unique Perturbation ID - should be used with caution!!! */
public void setPerturbationId( int perturbationId )
{
this.perturbationId = perturbationId;
}
/** Returns the perturbation that is the direct parent of this perturbation. */
public Perturbation getParentPerturbation()
{
return this.parentPerturbation;
}
/** Sets the parent of this perturbation. */
public void setParentPerturbation( Perturbation parentPerturbation )
{
this.parentPerturbation = parentPerturbation;
}
/** Returns perturbation name, this is the descriptive title given
* to this perturbation from MeSH.
*/
public String getPerturbationName()
{
return this.perturbationName;
}
/** Sets perturbation name. */
public void setPerturbationName( String perturbationName )
{
this.perturbationName = perturbationName;
}
/** Returns the unique MeSH ID for this perturbation entry. */
public String getMeshId()
{
return this.meshId;
}
/** Sets MeSH ID - use with caution!!! */
public void setMeshId( String meshId )
{
this.meshId = meshId;
}
/** Returns up to a paragraph of descriptive text for this perturbation. */
public String getDescription()
{
return this.description;
}
/** Sets the description of this perturbation. */
public void setDescription( String description )
{
this.description = description;
}
/** Returns the date this perturbation was last modified
* <em>in the EurocarbDB</em>.
*/
public Date getDateLastModified()
{
return this.dateLastModified;
}
/** Sets the date this entry was last modified in the EurocarbDB. */
public void setDateLastModified( Date dateLastModified )
{
this.dateLastModified = dateLastModified;
}
/** Returns the set of perturbations that are direct descendants of
* this perturbation.
*/
public Set<Perturbation> getChildPerturbations()
{
return this.childPerturbations;
}
/** Sets the set of direct children of this perturbation. */
public void setChildPerturbations( Set<Perturbation> childPerturbations )
{
this.childPerturbations = childPerturbations;
}
/** Returns the full set of links to biological contexts that include
* this perturbation.
*/
public Set<PerturbationContext> getPerturbationContexts()
{
return this.perturbationContexts;
}
/** Sets the set of links to biological contexts that include
* this perturbation.
*/
public void setPerturbationContexts( Set<PerturbationContext> bc2p_set )
{
this.perturbationContexts = perturbationContexts;
}
/** Returns the set of information that specifies the position
* of this perturbation in the perturbation tree hierachy.
*/
public Set<PerturbationRelations> getPerturbationRelations()
{
return this.perturbationRelations;
}
/** Sets hierachical information for this perturbation. */
public void setPerturbationRelations( Set<PerturbationRelations> pr_set )
{
this.perturbationRelations = perturbationRelations;
}
//~~~ ADDED CONVENIENCE FUNCTIONS ~~~//
/* getAllParentTaxonomies *//**********************************
*
* Returns a list of all the parent perturbations of this
* perturbation up to the root of the hierachy such that the root
* perturbation will be element 0, and the immediate parent of
* this perturbation as the last element in the list. Returns an
* empty list if this perturbation has no parents.
*
* @author mjh
*/
public List<Perturbation> getAllParentPerturbations()
{
List<Perturbation> list = new ArrayList<Perturbation>();
Perturbation cursor = this.getParentPerturbation();
while ( cursor != null )
{
list.add( 0, cursor );
cursor = cursor.getParentPerturbation();
if ( list.get( 0 ) == cursor ) break;
}
return list;
}
public List<Object[]> getListOfSubPerturbationsGlycanSequenceCount()
{
EntityManager em = getEntityManager();
try
{
Object result = em.getQuery( Perturbation.class.getName()
+ ".count_structures_for_sub_perturbations" )
.setComment( "Perturbation.getListOfSubPerturbationsGlycanSequenceCount")
.setParameter( "perturbation_id", this.getPerturbationId() )
.list();
if ( result == null )
return Collections.emptyList();
assert result instanceof List;
List<Object[]> result_list = (List<Object[]>) result;
return result_list;
}
catch ( Exception e )
{
log.warn( "Caught exception while counting sequences for perturbation", e );
return Collections.emptyList();//Collections.emptyMap();
}
}
/**
* Returns a count {@link GlycanSequence}s associated to this
* {@link Disease} and all its sub-diseases.
*/
public int getSubPerturbationsGlycanSequenceCount()
{
EntityManager em = getEntityManager();
try
{
Object result = em.getQuery( "org.eurocarbdb.dataaccess.core.Perturbation."
+ "count_structures_for_this_perturbation" )
.setParameter( "perturbation_id", this.getPerturbationId() )
.list();
if ( result == null )
return 0;
assert result instanceof List;
List result_list = (List) result;
if( result_list.size()==0 )
return 0;
return (Integer)result_list.iterator().next();
}
catch ( Exception e )
{
log.warn( "Caught exception while counting sequences for perturbation ", e );
return 0;
}
}
/** Returns true if this Perturbation is the root of the Perturbation hierachy. */
public boolean isRoot()
{
return this.perturbationId == 1;
}
public int compareTo( Object obj )
{
return this.toString().compareTo( obj.toString() );
}
public String toString()
{
return this.getPerturbationName();
}
} // end class