/* * Created on Jun 20, 2005 * * TODO To change the template for this generated file go to * Window - Preferences - Java - Code Style - Code Templates */ /* The Broad Institute SOFTWARE COPYRIGHT NOTICE AGREEMENT This software and its documentation are copyright (2006) by the Broad Institute/Massachusetts Institute of Technology. All rights are reserved. This software is supplied without any warranty or guaranteed support whatsoever. Neither the Broad Institute nor MIT can be responsible for its use, misuse, or functionality. */ package calhoun.gebo.internal.db; import java.awt.Color; import java.sql.ResultSet; import java.util.HashSet; import java.util.Set; import calhoun.gebo.model.Identified; import calhoun.gebo.util.ColorFactory; import calhoun.gebo.util.Informer; /** * @author reinhard * * TODO To change the template for this generated type comment go to Window - * Preferences - Java - Code Style - Code Templates */ public class CalhounTrackType extends Identified { private static Informer I = new Informer(CalhounTrackType.class); /** * @param id * @param label */ public CalhounTrackType(CalhounTrackManager trackManager, String id, String label, String subclass, Identified ontologyTerm, Color color, int sortKey, String view, String componentView, String url) { super(id, label); m_subclass = subclass; m_ontologyTerm = ontologyTerm; m_color = color; m_sortKey = sortKey; m_view = view; m_trackManager = trackManager; m_componentView = componentView; if (url != null) { m_url = url.replaceAll("\"", ""); } } public CalhounTrackManager getTrackManager() { return m_trackManager; } public String getSubclass() { if ( m_subclass == null){ return "SUBFEATURE"; } return m_subclass; } public Identified getOntologyTerm() { return m_ontologyTerm; } public String getName() { return getLabel(); } public Color getColor() { return m_color; } public int getSortKey() { return m_sortKey; } public String getView() { return m_view; } public String getComponentView() { return m_componentView; } public String getURL() { return m_url; } public String toString() { return getLabel() + " (" + getId() + ")"; } public CalhounTrackType getComponentTrackType() { if (m_componentTrackType == null) { m_componentTrackType = new CalhounTrackType(getTrackManager(), getId() + "_component", null, null, null, ColorFactory .getComplementaryColor(getColor()), getSortKey(), getComponentView(), null, null); } return m_componentTrackType; } public boolean isBlast() { return getSubclass().matches("BALGN|BCLUST"); } public boolean isHmmer(){ return getSubclass().matches("HMMHIT"); } public boolean isNonAnnotatedTranscript(){ if ( getSubclass() == null ) { I.warn("null subclass for track " + this); return false; } return getSubclass().matches("TRNSCR"); } public boolean isAlignmentSpan() { if ( getSubclass() == null ) { I.warn("null subclass for track " + this); return false; } return getSubclass().matches("ALSPN"); } public boolean isRepeat(){ if ( getSubclass() == null ) { I.warn("null subclass for track " + this); return false; } return getSubclass().matches("RPT"); } public boolean hasCustomFeatureMapView() { return isBlast() || isHmmer();// || isAlignmentSpan(); } public String getFeatureMapTable() { if (hasCustomFeatureMapView()) { return "AP_" + getSubclass() + "_FEATURE_MAP_VIEW"; } return "AP_FEATURE"; } public String getHint() { if (isBlast()) { return " /*+ index(AP_FEATURE ix_feature_seq_pos) */ "; } return ""; } public String getLabelColumn() { if (isBlast()) { return "ap_label as ap_name"; } return "ap_name"; } public String getDensityFeatureSelect() { return "SELECT " + getHint() + " ap_start,ap_stop FROM " + getFeatureMapTable(); } public String getMinimalApFeatureSelect() { // if ( ) return "SELECT " + getHint() + " ap_start,ap_stop,ap_id as ap_feature_id,ap_strand," + getLabelColumn() + ",ap_assigned_id,ap_stop - ap_start as ap_length FROM " + getFeatureMapTable(); } public CalhounDatabaseColumn[] getDatabaseColumns() { if (m_databaseColumns == null) { String tableNamePattern = null; try { Set columnSet = new HashSet(); tableNamePattern = getFeatureMapTable().replaceAll("_", "/_"); // I.warn("Trackmanager is: " + m_trackManager); // I.warn("Metadata is: " + m_trackManager.getMetaData()); ResultSet resultSet = m_trackManager.getMetaData().getColumns( null, null, tableNamePattern, null); Set criterionSet = new HashSet(); columnSet.add(new CalhounDatabaseColumn("AP_LENGTH", "NUMBER")); if ( isHmmer()){ columnSet.add(new CalhounDatabaseColumn("AP_FAM_ACCESSION","STRING")); } while (resultSet.next()) { String key = resultSet.getString(4); String typeString = resultSet.getString(6); columnSet.add(new CalhounDatabaseColumn(key, typeString)); } resultSet.close(); m_databaseColumns = (CalhounDatabaseColumn[]) columnSet .toArray(new CalhounDatabaseColumn[0]); } catch (Throwable t) { I.error("Unable to grab database columns for " + tableNamePattern, t); } } return m_databaseColumns; } public boolean hasDynamicProperties(){ return getSubclass().equals("GFTR"); } /** * Should we bother checking the db for subfeatures? * * @return a boolean value */ public boolean isCompound() { if (m_componentView == null || m_componentView.equals("")) { return false; } else { return true; } } public static CalhounTrackType getGenericTrackType() { if (GENERIC_TRACK_TYPE == null) { GENERIC_TRACK_TYPE = new CalhounTrackType(CalhounTrackManager .getInstance(), "0", "Generic", "*", new Identified("0", "*"), Color.LIGHT_GRAY, 100, "AP_GENERIC_FEATURE_VIEW", "AP_GENERIC_FEATURE_VIEW", null); } return GENERIC_TRACK_TYPE; } private static CalhounTrackType GENERIC_TRACK_TYPE; private CalhounTrackType m_componentTrackType; private CalhounTrackManager m_trackManager; private Color m_color; private int m_sortKey; private String m_view; private String m_componentView; private String m_subclass; private String m_url; private Identified m_ontologyTerm; private CalhounDatabaseColumn[] m_databaseColumns; }