Browse Source

Fixed problem with installing tripal_obo_temp and tripal_gff_temp. Also moved analysisfeatureprop table from tripal_core.schema_v1.11.api.inc to tripal_analysis.schema.api.inc.

Stephen Ficklin 11 years ago
parent
commit
504e2fbf91

+ 69 - 0
tripal_analysis/api/tripal_analysis.schema.api.inc

@@ -0,0 +1,69 @@
+<?php
+
+/**
+ * Implements hook_chado_schema_v1_11_analysisfeatureprop()
+ * Purpose: To describe the structure of 'analysisfeatureprop' to tripal
+ * @see tripal_core_chado_insert()
+ * @see tripal_core_chado_update()
+ * @see tripal_core_chado_select()
+ *
+ * @return
+ *    An array describing the 'analysisfeatureprop' table
+ *
+ * @ingroup tripal_chado_v1.11_schema_api
+ *
+ */
+function tripal_core_chado_schema_v1_11_analysisfeatureprop() {
+  $description =  array(
+    'table' => 'analysisfeatureprop',
+    'fields' => array(
+      'analysisfeatureprop_id' => array(
+        'type' => 'serial',
+        'not NULL' => '1',
+      ),
+      'analysisfeature_id' => array(
+        'type' => 'int',
+        'not NULL' => '1',
+      ),
+      'type_id' => array(
+        'type' => 'int',
+        'not NULL' => '1',
+      ),
+      'value' => array(
+        'type' => 'text',
+        'not NULL' => '',
+      ),
+      'rank' => array(
+        'type' => 'int',
+        'not NULL' => '1',
+      ),
+    ),
+    'primary key' => array(
+      0 => 'analysisfeatureprop_id',
+    ),
+    'unique keys' => array(
+      'analysisfeature_id_type_id_rank' => array(
+        0 => 'analysisfeature_id',
+        1 => 'type_id',
+        2 => 'rank',
+      ),
+    ),
+    'indexes' => array(
+    ),
+    'foreign keys' => array(
+      'cvterm' => array(
+        'table' => 'cvterm',
+        'columns' => array(
+          'type_id' => 'cvterm_id',
+        ),
+      ),
+      'analysisfeature' => array(
+        'table' => 'analysisfeature',
+        'columns' => array(
+          'analysisfeature_id' => 'analysisfeature_id',
+        ),
+      ),
+    ),
+  );
+  return $description;
+}

+ 11 - 15
tripal_analysis/tripal_analysis.install

@@ -59,19 +59,13 @@ function tripal_analysis_install() {
  */
 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);
+  // remove the materialized view
+  if ($mview = tripal_mviews_get_mview_id('analysis_organism')) {
+    tripal_mviews_action('delete', $mview);
   }
 }
-/*
- *
+/**
+ * 
  */
 function tripal_analysis_create_analysisfeatureprop() {
 
@@ -79,13 +73,15 @@ function tripal_analysis_create_analysisfeatureprop() {
   // version 1.11, the table exists in Chado 1.2.
   if (!db_table_exists('chado.analysisfeatureprop')) {
     $sql = "
-      CREATE TABLE chado.analysisfeatureprop (
+      CREATE TABLE {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,
+        analysisfeature_id     INTEGER NOT NULL,
+        type_id                INTEGER NOT NULL,
         value                  TEXT,
         rank                   INTEGER NOT NULL,
-        CONSTRAINT analysisfeature_id_type_id_rank UNIQUE(analysisfeature_id, type_id, rank)
+        CONSTRAINT analysisfeature_id_type_id_rank UNIQUE (analysisfeature_id, type_id, rank),
+        CONSTRAINT analysisfeatureprop_analysisfeature_id_fkey FOREIGN KEY (analysisfeature_id) REFERENCES {analysisfeature}(analysisfeature_id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
+        CONSTRAINT analysisfeatureprop_type_id_fkey FOREIGN KEY (type_id) REFERENCES {cvterm}(cvterm_id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
       )
     ";
     chado_query($sql);

+ 6 - 5
tripal_analysis/tripal_analysis.module

@@ -14,11 +14,12 @@
  *
  */
 
-require('api/tripal_analysis.api.inc');
-require('includes/tripal_analysis_privacy.inc');
-require('includes/tripal_analysis.admin.inc');
-require('includes/tripal_analysis.form.inc');
-require('includes/tripal_analysis.sync.inc');
+require_once 'api/tripal_analysis.api.inc';
+require_once 'includes/tripal_analysis_privacy.inc';
+require_once 'includes/tripal_analysis.admin.inc';
+require_once 'includes/tripal_analysis.form.inc';
+require_once 'includes/tripal_analysis.sync.inc';
+require_once "api/tripal_analysis.schema.api.inc";
 
 
 /**

+ 58 - 121
tripal_core/api/tripal_core.schema_v1.11.api.inc

@@ -368,111 +368,30 @@ function tripal_core_chado_schema_v1_11_analysis() {
   return $description;
 }
 /**
- * Implements hook_chado_schema_v1_11_analysisfeature()
- * Purpose: To describe the structure of 'analysisfeature' to tripal
- * @see tripal_core_chado_insert()
- * @see tripal_core_chado_update()
- * @see tripal_core_chado_select()
- *
- * @return
- *    An array describing the 'analysisfeature' table
+ * Implements hook_chado_schema_v1_11_analysisprop()
  *
- * @ingroup tripal_chado_v1.11_schema_api
+ * Purpose: To describe the structure of 'analysisprop' to tripal.  This table doesn't
+ * exist in Chado v1.1 (it does in v1.2), so we need to describe it here
  *
- */
-function tripal_core_chado_schema_v1_11_analysisfeature() {
-  $description =  array(
-    'table' => 'analysisfeature',
-    'fields' => array(
-      'analysisfeature_id' => array(
-        'type' => 'serial',
-        'not NULL' => '1',
-      ),
-      'feature_id' => array(
-        'type' => 'int',
-        'not NULL' => '1',
-      ),
-      'analysis_id' => array(
-        'type' => 'int',
-        'not NULL' => '1',
-      ),
-      'rawscore' => array(
-        'type' => 'float',
-        'size' => 'big',
-        'not NULL' => '',
-      ),
-      'normscore' => array(
-        'type' => 'float',
-        'size' => 'big',
-        'not NULL' => '',
-      ),
-      'significance' => array(
-        'type' => 'float',
-        'size' => 'big',
-        'not NULL' => '',
-      ),
-      'identity' => array(
-        'type' => 'float',
-        'size' => 'big',
-        'not NULL' => '',
-      ),
-    ),
-    'primary key' => array(
-      0 => 'analysisfeature_id',
-    ),
-    'unique keys' => array(
-      'analysisfeature_c1' => array(
-        0 => 'feature_id',
-        1 => 'analysis_id',
-      ),
-    ),
-    'indexes' => array(
-      'analysisfeature_idx1' => array(
-        0 => 'feature_id',
-      ),
-      'analysisfeature_idx2' => array(
-        0 => 'analysis_id',
-      ),
-    ),
-    'foreign keys' => array(
-      'feature' => array(
-        'table' => 'feature',
-        'columns' => array(
-          'feature_id' => 'feature_id',
-        ),
-      ),
-      'analysis' => array(
-        'table' => 'analysis',
-        'columns' => array(
-          'analysis_id' => 'analysis_id',
-        ),
-      ),
-    ),
-  );
-  return $description;
-}
-/**
- * Implements hook_chado_schema_v1_11_analysisfeatureprop()
- * Purpose: To describe the structure of 'analysisfeatureprop' to tripal
  * @see tripal_core_chado_insert()
  * @see tripal_core_chado_update()
  * @see tripal_core_chado_select()
  *
  * @return
- *    An array describing the 'analysisfeatureprop' table
+ *    An array describing the 'analysisprop' table
  *
  * @ingroup tripal_chado_v1.11_schema_api
  *
  */
-function tripal_core_chado_schema_v1_11_analysisfeatureprop() {
+function tripal_core_chado_schema_v1_11_analysisprop() {
   $description =  array(
-    'table' => 'analysisfeatureprop',
+    'table' => 'analysisprop',
     'fields' => array(
-      'analysisfeatureprop_id' => array(
+      'analysisprop_id' => array(
         'type' => 'serial',
         'not NULL' => '1',
       ),
-      'analysisfeature_id' => array(
+      'analysis_id' => array(
         'type' => 'int',
         'not NULL' => '1',
       ),
@@ -484,22 +403,23 @@ function tripal_core_chado_schema_v1_11_analysisfeatureprop() {
         'type' => 'text',
         'not NULL' => '',
       ),
-      'rank' => array(
-        'type' => 'int',
-        'not NULL' => '1',
-      ),
     ),
     'primary key' => array(
-      0 => 'analysisfeatureprop_id',
+      0 => 'analysisprop_id',
     ),
     'unique keys' => array(
-      'analysisfeature_id_type_id_rank' => array(
-        0 => 'analysisfeature_id',
+      'analysisprop_c1' => array(
+        0 => 'analysis_id',
         1 => 'type_id',
-        2 => 'rank',
       ),
     ),
     'indexes' => array(
+      'analysisprop_idx1' => array(
+        0 => 'analysis_id',
+      ),
+      'analysisprop_idx2' => array(
+        0 => 'type_id',
+      ),
     ),
     'foreign keys' => array(
       'cvterm' => array(
@@ -508,10 +428,10 @@ function tripal_core_chado_schema_v1_11_analysisfeatureprop() {
           'type_id' => 'cvterm_id',
         ),
       ),
-      'analysisfeature' => array(
-        'table' => 'analysisfeature',
+      'analysis' => array(
+        'table' => 'analysis',
         'columns' => array(
-          'analysisfeature_id' => 'analysisfeature_id',
+          'analysis_id' => 'analysis_id',
         ),
       ),
     ),
@@ -519,61 +439,77 @@ function tripal_core_chado_schema_v1_11_analysisfeatureprop() {
   return $description;
 }
 /**
- * Implements hook_chado_schema_v1_11_analysisprop()
- * Purpose: To describe the structure of 'analysisprop' to tripal
+ * Implements hook_chado_schema_v1_11_analysisfeature()
+ * Purpose: To describe the structure of 'analysisfeature' to tripal
  * @see tripal_core_chado_insert()
  * @see tripal_core_chado_update()
  * @see tripal_core_chado_select()
  *
  * @return
- *    An array describing the 'analysisprop' table
+ *    An array describing the 'analysisfeature' table
  *
  * @ingroup tripal_chado_v1.11_schema_api
  *
  */
-function tripal_core_chado_schema_v1_11_analysisprop() {
+function tripal_core_chado_schema_v1_11_analysisfeature() {
   $description =  array(
-    'table' => 'analysisprop',
+    'table' => 'analysisfeature',
     'fields' => array(
-      'analysisprop_id' => array(
+      'analysisfeature_id' => array(
         'type' => 'serial',
         'not NULL' => '1',
       ),
-      'analysis_id' => array(
+      'feature_id' => array(
         'type' => 'int',
         'not NULL' => '1',
       ),
-      'type_id' => array(
+      'analysis_id' => array(
         'type' => 'int',
         'not NULL' => '1',
       ),
-      'value' => array(
-        'type' => 'text',
+      'rawscore' => array(
+        'type' => 'float',
+        'size' => 'big',
+        'not NULL' => '',
+      ),
+      'normscore' => array(
+        'type' => 'float',
+        'size' => 'big',
+        'not NULL' => '',
+      ),
+      'significance' => array(
+        'type' => 'float',
+        'size' => 'big',
+        'not NULL' => '',
+      ),
+      'identity' => array(
+        'type' => 'float',
+        'size' => 'big',
         'not NULL' => '',
       ),
     ),
     'primary key' => array(
-      0 => 'analysisprop_id',
+      0 => 'analysisfeature_id',
     ),
     'unique keys' => array(
-      'analysisprop_c1' => array(
-        0 => 'analysis_id',
-        1 => 'type_id',
+      'analysisfeature_c1' => array(
+        0 => 'feature_id',
+        1 => 'analysis_id',
       ),
     ),
     'indexes' => array(
-      'analysisprop_idx1' => array(
-        0 => 'analysis_id',
+      'analysisfeature_idx1' => array(
+        0 => 'feature_id',
       ),
-      'analysisprop_idx2' => array(
-        0 => 'type_id',
+      'analysisfeature_idx2' => array(
+        0 => 'analysis_id',
       ),
     ),
     'foreign keys' => array(
-      'cvterm' => array(
-        'table' => 'cvterm',
+      'feature' => array(
+        'table' => 'feature',
         'columns' => array(
-          'type_id' => 'cvterm_id',
+          'feature_id' => 'feature_id',
         ),
       ),
       'analysis' => array(
@@ -586,6 +522,7 @@ function tripal_core_chado_schema_v1_11_analysisprop() {
   );
   return $description;
 }
+
 /**
  * Implements hook_chado_schema_v1_11_arraydesign()
  * Purpose: To describe the structure of 'arraydesign' to tripal

+ 27 - 3
tripal_cv/api/tripal_cv.schema.api.inc

@@ -14,7 +14,31 @@
  *
  */
 function tripal_cv_chado_schema_v1_2_tripal_obo_temp() {
-  $schema = tripal_cv_get_custom_tables('tripal_obo_temp');
-  $description = $schema['tripal_obo_temp'];
-  return $description;
+  $schema = array(
+    'table' => 'tripal_obo_temp',
+    'fields' => array(
+      'id' => array(
+        'type' => 'varchar',
+        'length' => '255',
+        'not null' => TRUE,
+      ),
+      'stanza' => array(
+        'type' => 'text',
+        'not null' => TRUE,
+      ),
+      'type' => array(
+        'type' => 'varchar',
+        'length' => '50',
+        'not null' => TRUE,
+      ),
+    ),
+    'indexes' => array(
+      'tripal_obo_temp_idx0' => array('id'),
+      'tripal_obo_temp_idx0' => array('type'),
+    ),
+    'unique keys' => array(
+      'tripal_obo_temp_uq0' => array('id'),
+    ),
+  );
+  return $schema;
 }

+ 33 - 39
tripal_cv/tripal_cv.install

@@ -52,8 +52,8 @@ function tripal_cv_install() {
   // add defaults to the tables that correlate OBO files/references with a chado CV
   tripal_cv_add_obo_defaults();
   
-  // add the custom tables to Chado
-  tripal_cv_add_custom_tables();
+  // create the temp table we will use for loading OBO files
+  tripal_cv_create_tripal_obo_temp();
 }
 /**
  * Implementation of hook_uninstall().
@@ -62,14 +62,41 @@ function tripal_cv_install() {
  */
 function tripal_cv_uninstall() {
   // remove the materialized view
-  // D7 @todo Fix tripal_mviews_get_mview_id()
-  /**
   if ($mview = tripal_mviews_get_mview_id('cv_root_mview')) {
     tripal_mviews_action('delete', $mview);
   }
-  */
+  
+  // drop the tripal_obo_temp table
+  if (db_table_exists('chado.tripal_obo_temp')) {
+    $sql = "DROP TABLE {tripal_obo_temp}";
+    chado_query($sql);
+  }
+}
+/**
+ *
+ */
+function tripal_cv_create_tripal_obo_temp() {
+  // the tripal_obo_temp table is used for temporary housing of records when loading OBO files
+  // we create it here using plain SQL because we want it to be in the chado schema but we 
+  // do not want to use the Tripal Custom Table API because we don't want it to appear in the 
+  // list of custom tables.  It needs to be available for the Tripal Chado API so we create it 
+  // here and then define it in the tripal_cv/api/tripal_cv.schema.api.inc
+  if (!db_table_exists('chado.tripal_obo_temp')) {
+    $sql = "
+      CREATE TABLE {tripal_obo_temp} (
+        id character varying(255) NOT NULL,
+        stanza text NOT NULL,
+        type character varying(50) NOT NULL,
+        CONSTRAINT tripal_obo_temp_uq0 UNIQUE (id)
+      );      
+    ";
+    chado_query($sql);
+    $sql = "CREATE INDEX tripal_obo_temp_idx0 ON {tripal_obo_temp} USING btree (id)";
+    chado_query($sql);
+    $sql = "CREATE INDEX tripal_obo_temp_idx1 ON {tripal_obo_temp} USING btree (type)";
+    chado_query($sql);
+  }
 }
-
 /**
  * Implementation of hook_schema().
  *
@@ -173,37 +200,4 @@ function tripal_cv_add_obo_defaults() {
   foreach ($ontologies as $o) {
     db_query("INSERT INTO {tripal_cv_obo} (name,path) VALUES (:name, :path)", array(':name' => $o[0], ':path' => $o[1]));
   }
-}
-
-/**
- * 
- */
-function tripal_cv_add_custom_tables() {
-  $schema = array(
-    'table' => 'tripal_obo_temp',
-    'fields' => array(
-      'id' => array(
-        'type' => 'varchar',
-        'length' => '255',
-        'not null' => TRUE,
-      ),
-      'stanza' => array(
-        'type' => 'text',
-        'not null' => TRUE,
-      ),
-      'type' => array(
-        'type' => 'varchar',
-        'length' => '50',
-        'not null' => TRUE,
-      ),
-    ),
-    'indexes' => array(
-      'tripal_obo_temp_idx0' => array('id'),
-      'tripal_obo_temp_idx0' => array('type'),
-    ),
-    'unique keys' => array(
-      'tripal_obo_temp_uq0' => array('id'),
-    ),
-  );
-  tripal_core_create_custom_table('tripal_obo_temp', $schema, TRUE);
 }

+ 49 - 0
tripal_feature/api/tripal_feature.schema.api.inc

@@ -0,0 +1,49 @@
+<?php
+
+/**
+ * Implements hook_chado_schema_v1_2_tripal_gff_temp()
+ * Purpose: To describe the structure of 'tripal_gff_temp' to tripal
+ * @see tripal_core_chado_insert()
+ * @see tripal_core_chado_update()
+ * @see tripal_core_chado_select()
+ *
+ * @return
+ *    An array describing the 'tripal_gff_temp' table
+ *
+ * @ingroup tripal_chado_v1.2_schema_api
+ *
+ */
+function tripal_feature_chado_schema_v1_2_tripal_gff_temp() {
+  $schema = array(
+    'table' => 'tripal_gff_temp',
+    'fields' => array(
+      'feature_id' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+      ),
+      'organism_id' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+      ),
+      'uniquename' => array(
+        'type' => 'text',
+        'not null' => TRUE,
+      ),
+      'type_name' => array(
+        'type' => 'varchar',
+        'length' => '1024',
+        'not null' => TRUE,
+      ),
+    ),
+    'indexes' => array(
+      'tripal_gff_temp_idx0' => array('feature_id'),
+      'tripal_gff_temp_idx0' => array('organism_id'),
+      'tripal_gff_temp_idx1' => array('uniquename'),
+    ),
+    'unique keys' => array(
+      'tripal_gff_temp_uq0' => array('feature_id'),
+      'tripal_gff_temp_uq1' => array('uniquename', 'organism_id', 'type_name'),
+    ),
+  );
+  return $schema;
+}

+ 34 - 44
tripal_feature/tripal_feature.install

@@ -27,7 +27,7 @@ function tripal_feature_requirements($phase) {
     // make sure chado is installed
     if (!tripal_core_is_chado_installed()) {
       $requirements ['tripal_feature'] = array(
-          'title' => "tripal_feature",
+          'title' => "t ripal_feature",
           'value' => "ERROR: Chado most be installed before this module can be enabled",
           'severity' => REQUIREMENT_ERROR,
       );
@@ -54,8 +54,8 @@ function tripal_feature_install() {
     tripal_mviews_action('update', $mview_id);
   }
   
-  // add the custom tables to Chado
-  tripal_feature_add_custom_tables();
+  // create the temp table we will use for loading GFF files
+  tripal_cv_create_tripal_gff_temp();
 }
 
 /**
@@ -66,11 +66,40 @@ function tripal_feature_install() {
 function tripal_feature_uninstall() {
   // Drop the MView table if it exists
   // D7 @todo Fix tripal_mviews_get_mview_id()
-  /**
   if ($mview_id = tripal_mviews_get_mview_id('organism_feature_count')) {
     tripal_mviews_action("delete", $mview_id);
   }
-  */
+  
+}
+
+/**
+ * 
+ */
+function tripal_cv_create_tripal_gff_temp() {
+  // the tripal_obo_temp table is used for temporary housing of records when loading OBO files
+  // we create it here using plain SQL because we want it to be in the chado schema but we
+  // do not want to use the Tripal Custom Table API because we don't want it to appear in the
+  // list of custom tables.  It needs to be available for the Tripal Chado API so we create it
+  // here and then define it in the tripal_cv/api/tripal_cv.schema.api.inc
+  if (!db_table_exists('chado.tripal_gff_temp')) {
+    $sql = "
+      CREATE TABLE {tripal_gff_temp} (
+        feature_id integer NOT NULL,
+        organism_id integer NOT NULL,
+        uniquename text NOT NULL,
+        type_name character varying(1024) NOT NULL,
+        CONSTRAINT tripal_gff_temp_uq0 UNIQUE (feature_id),
+        CONSTRAINT tripal_gff_temp_uq1 UNIQUE (uniquename, organism_id, type_name)
+      );
+    ";
+    chado_query($sql);
+    $sql = "CREATE INDEX tripal_gff_temp_idx0 ON {tripal_gff_temp} USING btree (feature_id)";
+    chado_query($sql);
+    $sql = "CREATE INDEX tripal_gff_temp_idx1 ON {tripal_gff_temp} USING btree (organism_id)";
+    chado_query($sql);
+    $sql = "CREATE INDEX tripal_gff_temp_idx2 ON {tripal_gff_temp} USING btree (uniquename)";
+    chado_query($sql);
+  }
 }
 
 /**
@@ -184,42 +213,3 @@ function tripal_feature_add_organism_count_mview() {
 
   tripal_add_mview($view_name, 'tripal_feature', $schema, $sql, $comment);
 }
-
-/**
- * 
- */
-function tripal_feature_add_custom_tables() {
-  
-  $schema['tripal_gff_temp'] = array(
-    'table' => 'tripal_gff_temp',
-    'fields' => array(
-      'feature_id' => array(
-        'type' => 'int',
-        'not null' => TRUE,
-      ),
-      'organism_id' => array(
-        'type' => 'int',
-        'not null' => TRUE,
-      ),
-      'uniquename' => array(
-        'type' => 'text',
-        'not null' => TRUE,
-      ),
-      'type_name' => array(
-        'type' => 'varchar',
-        'length' => '1024',
-        'not null' => TRUE,
-      ),
-    ),
-    'indexes' => array(
-      'tripal_gff_temp_idx0' => array('feature_id'),
-      'tripal_gff_temp_idx0' => array('organism_id'),
-      'tripal_gff_temp_idx1' => array('uniquename'),
-    ),
-    'unique keys' => array(
-      'tripal_gff_temp_uq0' => array('feature_id'),
-      'tripal_gff_temp_uq1' => array('uniquename', 'organism_id', 'type_name'),
-    ),
-  );
-  tripal_core_create_custom_table('tripal_gff_temp', $schema, TRUE);
-}

+ 1 - 0
tripal_feature/tripal_feature.module

@@ -21,6 +21,7 @@ require_once "includes/gff_loader.inc";
 require_once "includes/seq_extract.inc";
 require_once "includes/tripal_feature-delete.inc";
 require_once "includes/tripal_feature.form.inc";
+require_once "api/tripal_feature.schema.api.inc";
 
 /**
  *