123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514 |
- <?php
- /**
- * @file
- * Installation of the phylotree module
- */
- /**
- * Implements hook_install().
- *
- * @ingroup tripal_phylogeny
- */
- function tripal_phylogeny_install() {
- // Add the vocabularies used by the feature module.
- tripal_phylogeny_add_cvterms();
- // Set the default vocabularies.
- tripal_set_default_cv('phylonode', 'type_id', 'tripal_phylogeny');
- tripal_set_default_cv('phylotree', 'type_id', 'sequence');
- // Add the materializedviews.
- tripal_phylogeny_add_mview();
- // We want to integrate the materialized views so that they
- // are available for Drupal Views, upon which our search forms are built.
- tripal_phylogeny_integrate_view();
- $mview_id = tripal_get_mview_id('phylotree_count');
- // SPF: commented out automatic populate of MView. If the query fails
- // for some reason the install will not properly complete.
- // tripal_populate_mview($mview_id);
- // Add the custom tables.
- tripal_phylogeny_add_custom_tables();
- // Add an index on the phylonode table.
- $exists = chado_index_exists('phylonode', 'parent_phylonode_id');
- if (!$exists) {
- chado_add_index('phylonode', 'parent_phylonode_id', array('parent_phylonode_id'));
- }
- // Add in the variables that this module will use to store properties for
- // loading of the tree files.
- tripal_insert_variable('phylotree_name_re', 'The regular expression for matching a name in a string.');
- tripal_insert_variable('phylotree_use_uniquename', 'Set to 1 if features should be matched using the unqiuename rather than the name.');
- tripal_insert_variable('phylotree_tree_file', 'Holds the Drupal file ID for the uploaded tree file.');
- }
- /**
- * Implements hook_disable().
- *
- * Disable default views when module is disabled
- *
- * @ingroup tripal_phylogeny
- */
- function tripal_phylogeny_disable() {
- // Disable all default views provided by this module
- require_once("tripal_phylogeny.views_default.inc");
- $views = tripal_phylogeny_views_default_views();
- foreach (array_keys($views) as $view_name) {
- tripal_disable_view($view_name,FALSE,array('suppress_error' => TRUE));
- }
- }
- /**
- * Implementation of hook_requirements().
- *
- * @ingroup tripal_phylogeny
- */
- function tripal_phylogeny_requirements($phase) {
- $requirements = array();
- if ($phase == 'install') {
- // Make sure chado is installed.
- if (!$GLOBALS["chado_is_installed"]) {
- $requirements ['tripal_phylogeny'] = array(
- 'title' => "tripal_phylogeny",
- 'value' => "ERROR: Chado must be installed before this module can be enabled",
- 'severity' => REQUIREMENT_ERROR,
- );
- }
- }
- return $requirements;
- }
- /**
- * Implementation of hook_schema().
- * Standard tripal linker table between a node and a phylotree record.
- * @ingroup tripal_phylogeny
- */
- function tripal_phylogeny_schema() {
- $schema['chado_phylotree'] = 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
- ),
- 'phylotree_id' => array(
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0
- )
- ),
- 'indexes' => array(
- 'chado_phylotree_idx1' => array('phylotree_id')
- ),
- 'unique keys' => array(
- 'chado_phylotree_uq1' => array('nid', 'vid'),
- 'chado_phylotree_uq2' => array('vid')
- ),
- 'primary key' => array('nid'),
- );
- return $schema;
- }
- /**
- * Adds controlled vocabulary terms needed by this module.
- *
- * @ingroup tripal_phylogeny
- */
- function tripal_phylogeny_add_cvterms() {
- tripal_insert_cv(
- 'tripal_phylogeny',
- 'Terms used by the Tripal phylotree module for phylogenetic and taxonomic trees.'
- );
- // Add the terms used to identify nodes in the tree.
- tripal_insert_cvterm(
- array(
- 'name' => 'phylo_leaf',
- 'definition' => 'A leaf node in a phylogenetic tree.',
- 'cv_name' => 'tripal_phylogeny',
- 'is_relationship' => 0,
- 'db_name' => 'tripal'
- ),
- array('update_existing' => TRUE)
- );
- // Add the terms used to identify nodes in the tree.
- tripal_insert_cvterm(
- array(
- 'name' => 'phylo_root',
- 'definition' => 'The root node of a phylogenetic tree.',
- 'cv_name' => 'tripal_phylogeny',
- 'is_relationship' => 0,
- 'db_name' => 'tripal'
- ),
- array('update_existing' => TRUE)
- );
- // Add the terms used to identify nodes in the tree.
- tripal_insert_cvterm(
- array(
- 'name' => 'phylo_interior',
- 'definition' => 'An interior node in a phylogenetic tree.',
- 'cv_name' => 'tripal_phylogeny',
- 'is_relationship' => 0,
- 'db_name' => 'tripal'
- ),
- array('update_existing' => TRUE)
- );
- // Add the terms used to identify nodes in the tree.
- tripal_insert_cvterm(
- array(
- 'name' => 'taxonomy',
- 'definition' => 'A term used to indicate if a phylotree is a taxonomic tree',
- 'cv_name' => 'tripal_phylogeny',
- 'is_relationship' => 0,
- 'db_name' => 'tripal'
- ),
- array('update_existing' => TRUE)
- );
- tripal_insert_cvterm(
- array(
- 'name' => 'rank',
- 'definition' => 'A taxonmic rank',
- 'cv_name' => 'tripal_phylogeny',
- 'is_relationship' => 0,
- 'db_name' => 'tripal'
- ),
- array('update_existing' => TRUE)
- );
- // // ----------------------------------------------
- // // Add the terms for importing NCBI taxonomy data
- // $values = array(
- // 'name' => 'taxonomy',
- // 'description' => 'The NCBI Taxonomy Database is a curated classification and nomenclature for all of the organisms in the public sequence databases. This currently represents about 10% of the described species of life on the planet.',
- // 'url' => 'http://www.ncbi.nlm.nih.gov/taxonomy',
- // 'urlprefix' => 'http://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?id=',
- // );
- // tripal_insert_db($values);
- // tripal_insert_cv('taxonomy', 'A taxonomy for NCBI taxonomy ranks');
- // $terms = array('rank', 'taxid', 'class', 'cohort', 'family', 'forma', 'genus', 'infraclass',
- // 'infraorder', 'kingdom', 'no rank', 'order', 'parvorder', 'phylum',
- // 'species', 'species group', 'species subgroup', 'subclass', 'subcohort',
- // 'subfamily', 'subgenus', 'subkingdom', 'suborder', 'subphylum',
- // 'subspecies', 'subtribe', 'superclass', 'superfamily', 'superkingdom',
- // 'superorder', 'superphylum', 'tribe', 'varietas');
- // $options = array('update_existing' => TRUE);
- // foreach ($terms as $term) {
- // $value = array(
- // 'name' => $term,
- // 'definition' => '',
- // 'cv_name' => 'taxonomy',
- // 'is_relationship' => 0,
- // 'db_name' => 'taxonomy'
- // );
- // tripal_insert_cvterm($value, $options);
- // }
- $terms = array(
- 'lineage',
- 'genetic_code',
- 'genetic_code_name',
- 'mitochondrial_genetic_code',
- 'mitochondrial_genetic_code_name',
- 'division',
- 'genbank_common_name',
- 'synonym',
- 'other_name',
- 'equivalent_name',
- 'anamorph'
- );
- $options = array('update_existing' => TRUE);
- foreach ($terms as $term) {
- $value = array(
- 'name' => $term,
- 'definition' => '',
- 'cv_name' => 'organism_property',
- 'is_relationship' => 0,
- 'db_name' => 'tripal'
- );
- tripal_insert_cvterm($value, $options);
- }
- }
- /**
- * Implementation of hook_uninstall().
- */
- function tripal_phylogeny_uninstall() {
- // Drop the MView table if it exists
- $mview_id = tripal_get_mview_id('phylotree_count');
- if ($mview_id) {
- tripal_delete_mview($mview_id);
- }
- // Remove views integration.
- // Note: tripal_remove_views_intergration accepts table_name and priority in a key value form.
- $delete_view=array(
- 'table_name' => 'phylotree_count',
- 'priority' => '-1',
- );
- tripal_remove_views_integration($delete_view);
- }
- function tripal_phylogeny_add_mview(){
- // Materialized view addition.
- $sql_query="
- WITH count_genes as
- (SELECT count(*) count, t.phylotree_id
- FROM phylotree t, phylonode n
- WHERE n.phylotree_id = t.phylotree_id AND n.label is NOT NULL
- GROUP BY t.phylotree_id)
- SELECT
- phylotree.phylotree_id AS phylotree_phylotree_id,
- phylotree.name AS phylotree_name,
- phylotree.comment AS phylotree_comment,
- count_genes.count AS total_count
- FROM chado.phylotree phylotree
- LEFT JOIN chado_phylotree chado_phylotree ON phylotree.phylotree_id = chado_phylotree.phylotree_id
- LEFT JOIN count_genes count_genes ON phylotree.phylotree_id = count_genes.phylotree_id
- ";
- // Table Phylotree User Search description.
- $schema = array (
- 'table' => 'phylotree_count',
- 'fields' => array(
- 'phylotree_phylotree_id' => array(
- 'type' => 'int',
- 'not null' => FALSE,
- ),
- 'phylotree_name' => array(
- 'type' => 'text',
- 'not null' => FALSE,
- ),
- 'phylotree_comment' => array(
- 'type' => 'text',
- 'not null' => FALSE,
- ),
- 'total_count' => array(
- 'type' => 'int',
- 'not null' => TRUE,
- ),
- ),
- 'primary key' => array('phylotree_phylotree_id'),
- );
- // Add a comment to make sure this view makes sense to the site administator.
- $comment = t('This view is used to provide a table for Phylotree User Search with total count.');
- tripal_add_mview('phylotree_count', 'tripal_phylogeny', $schema, $sql_query, $comment);
- }
- /**
- * Integrate the qtl_search materialized view for use by Drupal Views and
- * our search form
- */
- function tripal_phylogeny_integrate_view(){
- $integration = array (
- 'table' => 'phylotree_count',
- 'name' => 'phylotree_count',
- 'type' => 'chado',
- 'description' => '',
- 'priority' => '-1',
- 'base_table' => '1',
- 'fields' => array (
- 'phylotree_phylotree_id' => array (
- 'name' => 'phylotree_phylotree_id',
- 'title' => 'Phylotree ID',
- 'description' => 'Phylotree ID',
- 'type' => 'int',
- 'handlers' => array (
- 'filter' => array (
- 'name' => 'views_handler_filter_numeric'
- ),
- 'field' => array (
- 'name' => 'views_handler_field_numeric'
- ),
- 'sort' => array (
- 'name' => 'views_handler_sort'
- ),
- 'argument' => array (
- 'name' => 'views_handler_argument_numeric'
- ),
- 'relationship' => array (
- 'name' => 'views_handler_relationship'
- )
- ),
- 'joins' => array ()
- ),
- 'phylotree_name' => array (
- 'name' => 'phylotree_name',
- 'title' => 'Family ID',
- 'description' => 'Family ID',
- 'type' => 'text',
- 'handlers' => array (
- 'filter' => array (
- 'name' => 'tripal_views_handler_filter_select_string'
- ),
- 'field' => array (
- 'name' => 'views_handler_field'
- ),
- 'sort' => array (
- 'name' => 'views_handler_sort'
- ),
- 'argument' => array (
- 'name' => 'views_handler_argument_string'
- ),
- 'relationship' => array (
- 'name' => 'views_handler_relationship'
- )
- ),
- 'joins' => array ()
- ),
- 'phylotree_comment' => array (
- 'name' => 'phylotree_comment',
- 'title' => 'Description',
- 'description' => 'Description',
- 'type' => 'text',
- 'handlers' => array (
- 'filter' => array (
- 'name' => 'tripal_views_handler_filter_select_string'
- ),
- 'field' => array (
- 'name' => 'views_handler_field'
- ),
- 'sort' => array (
- 'name' => 'views_handler_sort'
- ),
- 'argument' => array (
- 'name' => 'views_handler_argument_string'
- ),
- 'relationship' => array (
- 'name' => 'views_handler_relationship'
- )
- ),
- 'joins' => array ()
- ),
- 'total_count' => array (
- 'name' => 'total_count',
- 'title' => 'Total count',
- 'description' => 'Total count',
- 'type' => 'int',
- 'handlers' => array (
- 'filter' => array (
- 'name' => 'views_handler_filter_numeric'
- ),
- 'field' => array (
- 'name' => 'views_handler_field'
- ),
- 'sort' => array (
- 'name' => 'views_handler_sort'
- ),
- 'argument' => array (
- 'name' => 'views_handler_argument_numeric'
- ),
- 'relationship' => array (
- 'name' => 'views_handler_relationship'
- )
- ),
- 'joins' => array ()
- )
- )
- );
- // Add the array above that will integrate our qtl_search materialized view
- // for use with Drupal Views.
- tripal_add_views_integration($integration);
- }
- /**
- * Add any custom tables needed by this module.
- * - phylotreeprop: keep track of properties of phylotree
- *
- * @ingroup tripal_phylogeny
- */
- function tripal_phylogeny_add_custom_tables() {
- $schema = array (
- 'table' => 'phylotreeprop',
- 'fields' => array (
- 'phylotreeprop_id' => array (
- 'type' => 'serial',
- 'not null' => true,
- ),
- 'phylotree_id' => array (
- 'type' => 'int',
- 'not null' => true,
- ),
- 'type_id' => array (
- 'type' => 'int',
- 'not null' => true,
- ),
- 'value' => array (
- 'type' => 'text',
- 'not null' => false,
- ),
- 'rank' => array (
- 'type' => 'int',
- 'not null' => true,
- 'default' => 0,
- ),
- ),
- 'primary key' => array (
- 0 => 'phylotreeprop_id',
- ),
- 'unique keys' => array (
- 'phylotreeprop_c1' => array (
- 0 => 'phylotree_id',
- 1 => 'type_id',
- 2 => 'rank',
- ),
- ),
- 'indexes' => array (
- 'phylotreeprop_idx1' => array (
- 0 => 'phylotree_id',
- ),
- 'phylotreeprop_idx2' => array (
- 0 => 'type_id',
- ),
- ),
- 'foreign keys' => array (
- 'cvterm' => array (
- 'table' => 'cvterm',
- 'columns' => array (
- 'type_id' => 'cvterm_id',
- ),
- ),
- 'phylotree' => array (
- 'table' => 'phylotree',
- 'columns' => array (
- 'phylotree_id' => 'phylotree_id',
- ),
- ),
- ),
- );
- chado_create_custom_table('phylotreeprop', $schema, TRUE);
- }
- /**
- * Adds the vocabulary needed for storing taxonmies.
- */
- function tripal_phylogeny_update_7200() {
- try {
- tripal_phylogeny_add_cvterms();
- }
- catch (\PDOException $e) {
- $error = $e->getMessage();
- throw new DrupalUpdateException('Failed to complete update' . $error);
- }
- }
|