123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400 |
- <?php
- function tripal_phylogeny_install() {
-
- tripal_phylogeny_add_cvterms();
-
- tripal_set_default_cv('phylonode', 'type_id', 'tripal_phylogeny');
- tripal_set_default_cv('phylotree', 'type_id', 'sequence');
-
- tripal_phylogeny_add_mview();
-
-
- tripal_phylogeny_integrate_view();
- $mview_id = tripal_get_mview_id('phylotree_count');
-
-
-
-
- tripal_phylogeny_add_custom_tables();
-
- $exists = chado_index_exists('phylonode', 'parent_phylonode_id');
- if (!$exists) {
- chado_add_index('phylonode', 'parent_phylonode_id', array('parent_phylonode_id'));
- }
-
-
- 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.');
- }
- function tripal_phylogeny_disable() {
-
- 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));
- }
- }
- function tripal_phylogeny_requirements($phase) {
- $requirements = array();
- if ($phase == 'install') {
-
- 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;
- }
- 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;
- }
- function tripal_phylogeny_add_cvterms() {
- }
- function tripal_phylogeny_uninstall() {
-
- $mview_id = tripal_get_mview_id('phylotree_count');
- if ($mview_id) {
- tripal_delete_mview($mview_id);
- }
-
-
- $delete_view=array(
- 'table_name' => 'phylotree_count',
- 'priority' => '-1',
- );
- tripal_remove_views_integration($delete_view);
- }
- function tripal_phylogeny_add_mview(){
-
- $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
- ";
-
- $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'),
- );
-
- $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);
- }
- 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 ()
- )
- )
- );
-
-
- tripal_add_views_integration($integration);
- }
- 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);
- }
- function tripal_phylogeny_update_7200() {
- try {
- tripal_phylogeny_add_cvterms();
- }
- catch (\PDOException $e) {
- $error = $e->getMessage();
- throw new DrupalUpdateException('Failed to complete update' . $error);
- }
- }
|