"tripal_analysis", 'value' => "ERROR: Chado most be installed before this module can be enabled", 'severity' => REQUIREMENT_ERROR, ); } } return $requirements; } /** * Implementation of hook_install(). */ function tripal_analysis_install() { // create the module's data directory tripal_create_moddir('tripal_analysis'); // we may need the analysisfeatureprop table if it doesn't already exist tripal_analysis_create_analysisfeatureprop(); // add cvterms tripal_analysis_add_cvterms(); // add materialized views tripal_analysis_add_mview_analysis_organism(); } /** * Implementation of hook_uninstall(). */ function tripal_analysis_uninstall() { // Remove analysis nodes from drupal. $sql_ana_id = " SELECT nid, vid FROM {node} WHERE type like 'chado_analysi%' "; $result = db_query($sql_ana_id); while ($ana = $result->fetchObject()) { node_delete($ana->nid); } } /* * */ function tripal_analysis_create_analysisfeatureprop() { // Create analysisfeatureprop table in chado. This is needed for Chado // version 1.11, the table exists in Chado 1.2. if (!db_table_exists('chado.analysisfeatureprop')) { $sql = " CREATE TABLE chado.analysisfeatureprop ( analysisfeatureprop_id SERIAL PRIMARY KEY, analysisfeature_id INTEGER NOT NULL REFERENCES chado.analysisfeature(analysisfeature_id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, type_id INTEGER NOT NULL REFERENCES chdo.cvterm(cvterm_id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, value TEXT, rank INTEGER NOT NULL, CONSTRAINT analysisfeature_id_type_id_rank UNIQUE(analysisfeature_id, type_id, rank) ) "; chado_query($sql); } } /* * */ function tripal_analysis_add_cvterms() { tripal_cv_add_cv('tripal_analysis', 'Terms used for managing analyses in Tripal'); // add analysis_type. This goes in the 'tripal_analysis' CV so that site admins // change change this property $term = array( 'name' => 'analysis_type', 'def' => 'The type of analysis was performed. This value is automatically set by ' . 'each Tripal Analysis module and should be equal to the module name ' . '(e.g. tripal_analysis_blast, tripal_analysis_go).' ); tripal_cv_add_cvterm($term, 'tripal_analysis', 0, 1, 'tripal'); // add analysis_date. This is no longer used (as far as we can tell) but we don't // get rid of it in case it is used, so just keep it in the Tripal CV $term = array( 'name' => 'analysis_date', 'def' => 'The date that an analysis was performed.' ); tripal_cv_add_cvterm($term, 'tripal', 0, 1, 'tripal'); // add analysis_short_name. This is no longer used (as far as we can tell) but we don't // get rid of it in case it is used, so just keep it in the Tripal CV $term = array( 'name' => 'analysis_short_name', 'def' => 'A computer legible (no spaces or special characters) abbreviation for the analysis.' ); tripal_cv_add_cvterm($term, 'tripal', 0, 1 , 'tripal'); // the 'analysis_property' vocabulary is for user definable properties. Even though we already have // an analysis_type term in the 'tripal_analysis' vocabular we duplicate it here because the // tripal_analysis vocabulary is intended for use by the extension modules. user's should not be able // to directly modify properties set by extension modules for an analysis. tripal_cv_add_cvterm(array('name' => 'Analysis Type', 'def' => 'The type of analysis was performed.'), 'analysis_property', 0, 1, 'tripal'); } /** * Implementation of hook_schema() creates two tables. * * - chado_analysis table * stores nodes that are also saved in the analysis table of chado database. * - tripal_analysis table * stores the sub-module names, such as tripal_analysis_blast, that are registered * with this module. */ function tripal_analysis_schema() { // chado_analysis table $schema['chado_analysis'] = array( 'fields' => array( 'vid' => array( 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0 ), 'nid' => array( 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0 ), 'analysis_id' => array( 'type' => 'int', 'not null' => TRUE, 'default' => 0 ) ), 'indexes' => array( 'analysis_id' => array('analysis_id') ), 'unique keys' => array( 'nid_vid' => array('nid', 'vid'), 'vid' => array('vid') ), 'primary key' => array('nid'), ); // tripal_analysis table $schema['tripal_analysis'] = array( 'description' => 'Table to store analysis sub-modules', 'fields' => array( 'modulename' => array( 'type' => 'text', 'size' => 'small', 'not null' => TRUE, 'description' => 'The module name. Tripal Analysis will use the module name to call module_setting_form()' ) ), 'unique keys' => array( 'modulename' => array('modulename') ) ); return $schema; } /* * * @ingroup tripal_network */ function tripal_analysis_add_mview_analysis_organism() { $view_name = 'analysis_organism'; $comment = t('This view is for associating an organism (via it\'s associated features) to an analysis.'); // this is the SQL used to identify the organism to which an analsysis // has been used. This is obtained though the analysisfeature -> feature -> organism // joins $sql = " SELECT DISTINCT A.analysis_id, O.organism_id FROM analysis A INNER JOIN analysisfeature AF ON A.analysis_id = AF.analysis_id INNER JOIN feature F ON AF.feature_id = F.feature_id INNER JOIN organism O ON O.organism_id = F.organism_id "; // the schema array for describing this view $schema = array( 'table' => $view_name, 'description' => $comment, 'fields' => array( 'analysis_id' => array( 'type' => 'int', 'not null' => TRUE, ), 'organism_id' => array( 'type' => 'int', 'not null' => TRUE, ), ), 'indexes' => array( 'networkmod_qtl_indx0' => array('analysis_id'), 'networkmod_qtl_indx1' => array('organism_id'), ), 'foreign keys' => array( 'analysis' => array( 'table' => 'analysis', 'columns' => array( 'analysis_id' => 'analysis_id', ), ), 'organism' => array( 'table' => 'organism', 'columns' => array( 'organism_id' => 'organism_id', ), ), ), ); // add the view tripal_add_mview($view_name, 'tripal_analysis', $schema, $sql, $comment); }