spficklin 14 năm trước cách đây
mục cha
commit
fcd2fe8079

+ 51 - 0
theme_tripal/tripal_feature/tripal_feature_unigenes.tpl.php

@@ -0,0 +1,51 @@
+<?php
+$node = $variables['node'];
+$feature = $node->feature;
+$unigenes = $feature->tripal_analysis_unigene->unigenes;
+
+//dpm($unigenes);
+?>
+<div id="tripal_feature-unigenes-box" class="tripal_feature-info-box tripal-info-box">
+  <div class="tripal_feature-info-box-title tripal-info-box-title">Unigenes</div>
+  <div class="tripal_feature-info-box-desc tripal-info-box-desc">This <?php print $feature->type_id->name ?> is part of the following unigenes:</div>
+  <?php if(count($unigenes) > 0){ ?>h
+  <table id="tripal_feature-unigenes-table" class="tripal_feature-table tripal-table tripal-table-horz">
+    <tr>
+      <th>Unigene Name</th>
+      <th>Analysis Name</th>
+      <th>Sequence type in Unigene</th>
+    </tr>
+    <?php
+    $i = 0; 
+    foreach ($unigenes as $unigene){
+      $class = 'tripal-table-odd-row';
+      if($i % 2 == 0 ){
+         $class = 'tripal-table-even-row';
+      }
+      ?>
+      <tr class="<?php print $class ?>">
+        <td>
+           <?php 
+           if($unigene->nid){
+              print "<a href=\"".url("node/$unigene->nid")."\">$unigene->unigene_name</a>";
+           } else {
+              print $unigene->unigene_name;
+           }?>
+        </td>
+        <td><?php print $unigene->name; ?></td>
+        <td nowrap><?php 
+           if($unigene->singlet){
+              print "Singlet";
+           } else {
+              print $feature->type_id->name;
+           }?>
+        </td>
+      </tr>
+      <?php
+      $i++;  
+    } ?>
+  </table>
+  <?php } else { ?>
+    <div class="tripal-no-results">There are no unigenes for this feature</div> 
+  <?php }?>
+</div>

+ 62 - 0
tripal_analysis_unigene/tripal_analysis_unigene.module

@@ -240,6 +240,12 @@ function tripal_analysis_unigene_nodeapi(&$node, $op, $teaser, $page) {
 						   '#weight' => 4
                   );
                }
+               if(strcmp($node->type,'chado_feature')==0){
+                  $node->content['tripal_feature_unigenes'] = array(
+					   	'#value' => theme('tripal_feature_unigenes', $node),
+						   '#weight' => 4
+                  );
+               }
             }
          }
       break;   
@@ -278,6 +284,15 @@ function tripal_analysis_unigene_preprocess_tripal_organism_unigenes(&$variables
    $unigenes = tripal_analysis_unigene_load_organism_unigenes($organism);
    $node->organism->tripal_analysis_unigene->unigenes =  $unigenes;
 }
+/*******************************************************************************
+ *  
+ */
+function tripal_analysis_unigene_preprocess_tripal_feature_unigenes(&$variables){
+   $node = $variables['node'];
+   $feature = $node->feature;
+   $unigenes = tripal_analysis_unigene_load_feature_unigenes($feature);
+   $node->feature->tripal_analysis_unigene->unigenes =  $unigenes;
+}
 /************************************************************************
  *  This function is an extension of the chado_feature_view by providing
  *  the markup for the feature object THAT WILL BE INDEXED.
@@ -635,6 +650,53 @@ function tripal_analysis_unigene_load_organism_unigenes($organism){
    }
    return $unigenes;
 }
+/************************************************************************
+*
+*/   
+function tripal_analysis_unigene_load_feature_unigenes($feature){
+
+   // first get all the unigene analyses for this organism
+   $sql = "SELECT * FROM {organism_unigene_mview} OUM ".
+          "  INNER JOIN {analysis} A  ON A.analysis_id = OUM.analysis_id ".
+          "WHERE OUM.organism_id = %d ".
+          "ORDER BY A.timeexecuted DESC";
+   $previous_db = tripal_db_set_active('chado');  // use chado database
+   $results = db_query($sql,$feature->organism_id->organism_id);
+   tripal_db_set_active($previous_db);  // now use drupal database
+
+   // iterate through the unigenes and find those that use this feature
+   $unigenes = array();
+   $i=0;
+   $sql = "SELECT nid FROM {chado_analysis} WHERE analysis_id = %d";
+   while($unigene = db_fetch_object($results)){
+      $analysis_id = $unigene->analysis_id;
+
+      // check if this feature is present in the unigene
+      $values = (
+         'feature_id' => $feature->feature_id,
+         'analysis_id' => $analysis_id,
+      );
+      $hasFeature = tripal_core_chado_select('featureprop',array('*'),$values);
+      
+      // if the feature is present then get information about it
+      if(sizeof($hasFeature) > 0){
+         // see if there is a drupal node for this unigene
+         $c_node = db_fetch_object(db_query($sql,$analysis_id));
+         if($c_node){  
+            $unigene->nid = $c_node->nid;
+         }
+         // add in the properties
+         $unigene_name = tripal_analysis_get_property($analysis_id,'analysis_unigene_name');
+         $singlet = tripal_core_get_property('analysisfeature',$analysis_id,'singlet','tripal');       
+         
+         $unigene->unigene_name = $unigene_name->value;    
+         $unigene->singlet = $num_singlets->value;
+
+         $unigenes[$i++] = $unigene;
+      }
+   }
+   return $unigenes;
+}
 /*******************************************************************************
  * Tripal Unigene administrative setting form. This function is called by
  * tripal_analysis module which asks for an admin form to show on the page

+ 109 - 0
tripal_core/tripal_core.api.inc

@@ -1263,3 +1263,112 @@ function chado_get_id_for_node ($table, $node) {
 function chado_get_node_id ($table, $id) {
 	 return db_result(db_query("SELECT nid FROM {chado_".$table."} WHERE $table"."_id = $id"));
 }
+
+/**
+* Adds a single property to an existing library record.
+*
+* @ingroup tripal_api
+*/
+function tripal_core_get_property($basetable, $record_id, $property,$cv_name,){
+
+   $table_desc = module_invoke_all('chado_'.$basetable.'prop_schema');
+   $fkcol = key($table_desc['foreign_keys'][$basetable]['columns']);
+
+   // construct the array of values to be inserted  
+   $values = array (
+      $fkcol => $record_id,
+      'type_id' => array ( 
+         'cv_id' => array (
+            'name' => $cv_name,
+         ),
+         'name' => $property,
+         'is_obsolete' => 0
+      ),
+   );
+   $results = tripal_core_generate_chado_var($basetable.'prop',$values);
+   $results = tripal_core_expand_chado_vars($results,'field',$basetable.'prop.value');
+   return $results;
+}
+/**
+* Adds a single property to an existing record.
+*
+* @ingroup tripal_core.api
+*/
+function tripal_core_insert_property($proptable, $feature_id,$property,$value,$update_if_present = 0){
+   // first see if the property already exists, if so we can't insert
+   $prop = tripal_feature_get_property($feature_id,$property);
+   if(count($prop)>0){
+      if($update_if_present){
+        return tripal_feature_update_property($feature_id,$property,$value) ;
+      } else {
+        return FALSE;
+      }
+   }
+
+   // construct the array of values to be inserted  
+   $values = array (
+      'feature_id' => $feature_id,
+      'type_id' => array ( 
+         'cv_id' => array (
+            'name' => 'tripal',
+         ),
+         'name' => $property,
+         'is_obsolete' => 0
+      ),
+      'value' => $value, 
+      'rank' => 0,
+   );
+   return tripal_core_chado_insert('featureprop',$values);
+}
+/**
+* Adds a single property to an existing feature record.
+*
+* @ingroup tripal_api
+*/
+function tripal_core_update_property($proptable, $feature_id,$property,$value,$insert_if_missing = 0){
+
+   // first see if the property is missing (we can't update a missing property
+   $prop = tripal_feature_get_property($feature_id,$property);
+   if(count($prop)==0){
+      if($insert_if_missing){
+        return tripal_feature_insert_property($feature_id,$property,$value);
+      } else {
+        return FALSE;
+      }
+   }
+
+   // construct the array that will match the exact record to update
+   $match = array (
+      'feature_id' => $feature_id,
+      'type_id' => array ( 
+         'cv_id' => array (
+            'name' => 'tripal',
+         ),
+         'name' => $property,
+      ),
+   );
+   // construct the array of values to be updated
+   $values = array (      
+      'value' => $value, 
+   );
+   return tripal_core_chado_update('featureprop',$match,$values);
+}
+/**
+* Adds a single property to an existing feature record.
+*
+* @ingroup tripal_api
+*/
+function tripal_core_delete_property($proptable, $feature_id,$property){
+
+   // construct the array that will match the exact record to update
+   $match = array (
+      'feature_id' => $feature_id,
+      'type_id' => array ( 
+         'cv_id' => array (
+            'name' => 'tripal',
+         ),
+         'name' => $property,
+      ),
+   );
+   return tripal_core_chado_delete('featureprop',$match);
+}