Browse Source

Added new analysis_organism materialized view and updated seq_extract form to use it

spficklin 12 years ago
parent
commit
365a00ff31
2 changed files with 122 additions and 39 deletions
  1. 77 0
      tripal_analysis/tripal_analysis.install
  2. 45 39
      tripal_feature/includes/seq_extract.inc

+ 77 - 0
tripal_analysis/tripal_analysis.install

@@ -20,6 +20,25 @@ function tripal_analysis_install() {
   
   // add cvterms
   tripal_analysis_add_cvterms();
+  
+  // add materialized views
+  tripal_analysis_add_mview_analysis_organism();
+}
+
+/**
+ *  Update for Drupal 6.x, Tripal 1.1, Analysis Module 1.1
+ *  This update adds a new analysis_organism materialized view
+ *
+ */
+function tripal_analysis_update_6100() {
+  // add the new materialized view
+  tripal_analysis_add_mview_analysis_organism();
+  
+  $ret = array(
+    '#finished' => 1,
+  );
+
+  return $ret;
 }
 /*
  * 
@@ -174,4 +193,62 @@ function tripal_analysis_requirements($phase) {
     }
   }
   return $requirements;
+}
+
+/*
+ * 
+ * @ingroup tripal_network
+ */
+function tripal_analysis_add_mview_analysis_organism() {
+  
+  // 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' => 'analysis_organism',
+    '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 a comment to make sure this view makes sense to the site administator
+  $comment = t('This view is for associating an organism (via it\'s associated features) to an analaysis.');
+  
+  // add the view
+  tripal_add_mview('analysis_organism', 'tripal_analysis', NULL, NULL, NULL,
+    $sql, NULL, $comment, $schema);
 }

+ 45 - 39
tripal_feature/includes/seq_extract.inc

@@ -4,49 +4,56 @@
  */
 function tripal_feature_seq_extract_page() {
   // generate the search form 
-  $form = drupal_get_form('tripal_feature_seq_extract_form');  
-  $output .= $form;
+  $output .= '';
+  if (user_access('access administration pages')) { 
+    $output .= "
+      <div class=\"tripal-no-results\">
+        <p>Administrators, the " . l('organism_feature_count', 'admin/tripal/mviews') . " and 
+        " . l('analysis_organism', 'admin/tripal/mviews') . " materialized
+        views must be populated before using this form.  Those views should be re-populated 
+        when new data is added.</p>         
+      </div>
+    ";
+  }
+  $output .= drupal_get_form('tripal_feature_seq_extract_form');  
   return $output;
 }
 /*
  * 
  */
 function theme_tripal_feature_seq_extract_form($form) {
-  $rows = array();
- 
-  $rows[] = array(
-    drupal_render($form['genus']),
-    drupal_render($form['species']) ,
-    drupal_render($form['ftypes']) ,
-  );
-  $rows[] = array(
-    drupal_render($form['analysis']) ,
-    drupal_render($form['upstream']) ,
-    drupal_render($form['downstream']) ,
-  );
-  $rows[] = array(
-    drupal_render($form['format']),
-    array(
-      'data' =>  drupal_render($form['fname']),
-      'colspan' => 2,
+  $rows = array(
+    0 => array(
+      drupal_render($form['genus']),
+      drupal_render($form['species']) ,
+      drupal_render($form['ftypes']) ,
+    ),
+    1 => array(
+      array('data' => drupal_render($form['analysis']), 'colspan' => 2),
+      drupal_render($form['format']),    
+    ),
+    2 => array(     
+      array('data' =>  drupal_render($form['fname']), 'colspan' => 2),
+      drupal_render($form['upstream']) . drupal_render($form['downstream']) ,
+    ),
+    3 => array(
+      array(
+        'data' =>  drupal_render($form['advanced']),
+        'colspan' => 3,
+      ),    
+    ),
+    4 => array(
+      array(
+        'data' =>  drupal_render($form['retrieve_btn']),
+        'colspan' => 3,
+      ),    
     ),
-  );
-  $rows[] = array(
-    array(
-      'data' =>  drupal_render($form['advanced']),
-      'colspan' => 3,
-    ),    
-  );
-  $rows[] = array(
-    array(
-      'data' =>  drupal_render($form['retrieve_btn']),
-      'colspan' => 3,
-    ),    
   );
   $headers = array();
   $table = theme('table', $headers, $rows, array('id' => 'tripal-feature-seq-extract-form-table', 'border' => '0'));   
   
-  $markup = $table;
+  $markup = ''; 
+  $markup .= $table;
   $form['criteria'] = array(
     '#type' => 'markup',
     '#value' =>  $markup,
@@ -168,23 +175,21 @@ function tripal_feature_seq_extract_form(&$form_state = NULL) {
   $ftypes = array();
   if ($dgenus) {  
     $sql = "
-      SELECT DISTINCT CVT.cvterm_id, CVT.name
-      FROM {cvterm} CVT 
-        INNER JOIN {feature} F on CVT.cvterm_id = F.type_id
-        INNER JOIN {organism} O on O.organism_id = F.organism_id
-      WHERE O.genus = '%s'
+      SELECT DISTINCT OFC.cvterm_id, OFC.feature_type
+      FROM {organism_feature_count} OFC 
+      WHERE OFC.genus = '%s'
     ";
     $args = array();
     $args[] = $dgenus;
     if ($dspecies) {
-      $sql .= " AND O.species = '%s'";
+      $sql .= " AND OFC.species = '%s'";
       $args[] = $dspecies;
     }
     $results = chado_query($sql, $args);
     
     $ftypes[] = '';
     while ($type = db_fetch_object($results)) {
-      $ftypes[$type->cvterm_id] = $type->name;  
+      $ftypes[$type->cvterm_id] = $type->feature_type;  
     }
   }
   $form['ftypes'] = array(
@@ -201,6 +206,7 @@ function tripal_feature_seq_extract_form(&$form_state = NULL) {
     '#type'          => 'textarea',
     '#default_value' => $dfname,
     '#description'   => t('The names of the features to retrieve. Separate each with a space. Leave blank to retrieve all features matching other criteria.'),
+    '#rows'          => 8
   );
   $form['upstream'] = array(
     '#title'         => t('Upstream Bases'),