ソースを参照

Tripal Genetic aheres to Drupal coding standards

Pubudu Basnayaka 12 年 前
コミット
d24a2af4d1

+ 18 - 17
tripal_genetic/tripal_genetic.api.inc

@@ -1,9 +1,9 @@
-<?php 
+<?php
 
 /**
  *
  */
-function tripal_genetic_get_genotypes_by_feature_id ($feature_id) {
+function tripal_genetic_get_genotypes_by_feature_id($feature_id) {
 
   /**
   $sql = 'SELECT nd_experiment_id FROM nd_experiment_genotype WHERE genotype_id IN (SELECT genotype_id FROM feature_genotype WHERE feature_id=%d)';
@@ -13,24 +13,25 @@ function tripal_genetic_get_genotypes_by_feature_id ($feature_id) {
   while ($r = db_fetch_object($resource)) {
     $values['nd_experiment_id'][] = $r->nd_experiment_id;
   }
-  
+
   $object = tripal_core_generate_chado_var('nd_experiment',$values);
   $object = tripal_core_expand_chado_vars($object, 'table', 'nd_experiment_genotype');
   $object = tripal_core_expand_chado_vars($object, 'table', 'feature_genotype');
   $object = tripal_core_expand_chado_vars($object, 'table', 'nd_experiment_stock');
   */
 
-  $sql = 'SELECT genotype_id FROM genotype WHERE genotype_id IN (SELECT genotype_id FROM feature_genotype WHERE feature_id=%d)';
+  $sql = 'SELECT genotype_id FROM {genotype} WHERE genotype_id IN (SELECT genotype_id FROM {feature_genotype} WHERE feature_id=%d)';
   $resource = db_query($sql, $feature_id);
 
   $values['genotype_id'] = array();
   while ($r = db_fetch_object($resource)) {
     $values['genotype_id'][] = $r->genotype_id;
   }
-  
+
   if (!empty($values['genotype_id'])) {
-    $object = tripal_core_generate_chado_var('genotype',$values);  
-  } else {
+    $object = tripal_core_generate_chado_var('genotype', $values);
+  }
+  else {
     $object = array();
   }
   return $object;
@@ -47,9 +48,9 @@ function tripal_genetic_get_genotypes_by_feature_id ($feature_id) {
  *
  * @ingroup tripal_schema_api
  */
-function tripal_genetic_chado_genotype_schema () {
+function tripal_genetic_chado_genotype_schema() {
   $description = array();
- 
+
   $referring_tables = array('analysisfeature',
     'feature_genotype',
     'phendesc',
@@ -58,9 +59,9 @@ function tripal_genetic_chado_genotype_schema () {
     'stock_genotype',
   );
   $description['referring_tables'] = $referring_tables;
-  
+
   return $description;
-  
+
 }
 
 /**
@@ -73,7 +74,7 @@ function tripal_genetic_chado_genotype_schema () {
  *
  * @ingroup tripal_schema_api
  */
-function tripal_genetic_chado_feature_genotype_schema () {
+function tripal_genetic_chado_feature_genotype_schema() {
   $description = array();
 
   $description['foreign keys']['feature'] = array(
@@ -82,14 +83,14 @@ function tripal_genetic_chado_feature_genotype_schema () {
           'feature_id' => 'feature_id',
           'chromosome_id' => 'feature_id',
         ),
-  ); 
+  );
 
   $description['foreign keys']['genotype'] = array(
         'table' => 'genotype',
         'columns' => array(
           'genotype_id' => 'genotype_id',
         ),
-  );  
+  );
 
   $description['foreign keys']['cvterm'] = array(
         'table' => 'cvterm',
@@ -97,7 +98,7 @@ function tripal_genetic_chado_feature_genotype_schema () {
           'cvterm_id' => 'cvterm_id',
         ),
   );
-  
+
   return $description;
-  
-}
+
+}

+ 10 - 10
tripal_genetic/tripal_genetic.module

@@ -3,9 +3,9 @@
 /**
  *  @file
  * This file contains the basic functions needed for this drupal module.
- * The drupal tripal_genetic module maps directly to the chado X module. 
+ * The drupal tripal_genetic module maps directly to the chado X module.
  *
- * For documentation regarding the Chado X module: 
+ * For documentation regarding the Chado X module:
  * @see http://gmod.org/wiki/Chado_General_Module
  */
 
@@ -16,7 +16,7 @@ require('tripal_genetic.api.inc');
  * Purpose: Essentially this hook tells drupal that there is views support for
  *  for this module which then includes tripal_genetic.views.inc where all the
  *  views integration code is
- */ 
+ */
 function tripal_genetic_views_api() {
    return array(
       'api' => 2.0,
@@ -25,17 +25,17 @@ function tripal_genetic_views_api() {
 
 function tripal_genetic_theme() {
   return array(
-    'tripal_feature_genotypes' => array (
-       'arguments' => array('node'=> null),
+    'tripal_feature_genotypes' => array(
+       'arguments' => array('node' => NULL),
        'template' => 'tripal_feature_genotypes',
-    ),  
+    ),
   );
 }
 
 /**
  *
  */
-function tripal_genetic_nodeapi (&$node, $op, $teaser, $page) {
+function tripal_genetic_nodeapi(&$node, $op, $teaser, $page) {
   switch ($op) {
     case 'view':
       if ($node->type == 'chado_feature') {
@@ -51,7 +51,7 @@ function tripal_genetic_nodeapi (&$node, $op, $teaser, $page) {
 /**
  *
  */
-function tripal_genetic_preprocess_tripal_feature_genotypes(&$variables){
-    $feature = $variables['node']->feature;   
+function tripal_genetic_preprocess_tripal_feature_genotypes(&$variables) {
+    $feature = $variables['node']->feature;
     $variables['tripal_feature']['genotypes'] = tripal_genetic_get_genotypes_by_feature_id($feature->feature_id);
-}
+}

+ 23 - 23
tripal_genetic/views/genotype.views.inc

@@ -1,5 +1,5 @@
-<?php 
- 
+<?php
+
 /**
  *  @file
  *  This file defines the data array for a given chado table. This array
@@ -7,12 +7,12 @@
  *  with this module in:
  *  @see tripal_genetic.views.inc --in tripal_genetic_views_data()
  *
- *  Documentation on views integration can be found at 
+ *  Documentation on views integration can be found at
  *  http://views2.logrus.com/doc/html/index.html.
  */
 
 /*************************************************************************
- * Purpose: this function returns the portion of the data array 
+ * Purpose: this function returns the portion of the data array
  *   which describes the genotype table, it's fields and any joins between it and other tables
  * @see tripal_genetic_views_data() --in tripal_genetic.views.inc
  *
@@ -28,33 +28,33 @@
   // if the chado database is not local to the drupal database
   // then we need to set the database name.  This should always
   // be 'chado'.
-  if(is_array($db_url) and array_key_exists('chado',$db_url)){
+  if (is_array($db_url) and array_key_exists('chado', $db_url)) {
     $database = 'chado';
   }
-   
+
   //Basic table definition-----------------------------------
   $data['genotype']['table']['group'] = t('Chado Genotype');
-  
+
   $data['genotype']['table']['base'] = array(
     'field' => 'genotype_id',
     'title' => t('Chado Genotype'),
     'help' => t('A genotype is defined by a collection of features, mutations, balancers, deficiencies, haplotype blocks, or engineered constructs.'),
   );
-  if($database){
+  if ($database) {
      $data['genotype']['table']['base']['database'] = $database;
   }
 
-  
+
   //Relationship Definitions---------------------------------
 
   //Join: feature => feature_genotype => feature
   // This relationship should be described in both directions
-  // in the appropriate files (ie: for feature => library 
+  // in the appropriate files (ie: for feature => library
   // describe in both feature.views.inc and library.views.inc)
   $data['feature']['table']['join']['feature_genotype'] = array(
     'left_field' => 'feature_id',
     'field' => 'feature_id',
-  );  
+  );
   $data['feature']['table']['join']['genotype'] = array(
     'left_table' => 'feature_genotype',
     'left_field' => 'feature_id',
@@ -67,12 +67,12 @@
 
   //Join: feature => feature_genotype => feature
   // This relationship should be described in both directions
-  // in the appropriate files (ie: for feature => library 
+  // in the appropriate files (ie: for feature => library
   // describe in both feature.views.inc and library.views.inc)
   $data['genotype']['table']['join']['feature_genotype'] = array(
     'left_field' => 'genotype_id',
     'field' => 'genotype_id',
-  );  
+  );
   $data['genotype']['table']['join']['feature'] = array(
     'left_table' => 'feature_genotype',
     'left_field' => 'genotype_id',
@@ -82,15 +82,15 @@
     'left_field' => 'feature_id',
     'field' => 'feature_id',
   );
-  
+
    //Join: stock => stock_genotype => stock
   // This relationship should be described in both directions
-  // in the appropriate files (ie: for stock => library 
+  // in the appropriate files (ie: for stock => library
   // describe in both stock.views.inc and library.views.inc)
   $data['stock']['table']['join']['stock_genotype'] = array(
     'left_field' => 'stock_id',
     'field' => 'stock_id',
-  );  
+  );
   $data['stock']['table']['join']['genotype'] = array(
     'left_table' => 'stock_genotype',
     'left_field' => 'stock_id',
@@ -100,9 +100,9 @@
     'left_field' => 'genotype_id',
     'field' => 'genotype_id',
   );
-  
+
   //Table Field Definitions----------------------------------
-      
+
   //Field: genotype_id (primary key)
   $data['genotype']['genotype_id'] = array(
     'title' => t('Genotype Primary Key'),
@@ -119,7 +119,7 @@
     ),
   );
 
-  //Field: name (text)  
+  //Field: name (text)
   $data['genotype']['name'] = array(
     'title' => t('Name'),
     'help' => t('Human-readable Name of the genotype.'),
@@ -138,7 +138,7 @@
     ),
   );
 
-  //Field: uniquename (text)  
+  //Field: uniquename (text)
   $data['genotype']['uniquename'] = array(
     'title' => t('Unique Name'),
     'help' => t('Unique Name of the genotype.'),
@@ -157,7 +157,7 @@
     ),
   );
 
-  //Field: description (varchar -255)   
+  //Field: description (varchar -255)
   $data['genotype']['description'] = array(
     'title' => t('Description/Value'),
     'help' => t('A Description of the genotype.'),
@@ -175,6 +175,6 @@
       'handler' => 'views_handler_argument_string',
     ),
   );
-    
+
   return $data;
-}
+}

+ 28 - 28
tripal_genetic/views/template.node_join.views.inc

@@ -5,18 +5,18 @@
  *
  *  - simply replace all XXX with the original chado table you want to join to it's drupal nodes.
  *    (ie: If you want to join features to their drupal nodes then XXX=feature)
- * 
- *  NOTE: Creating the table definition file is not enough. You also need to call the 
+ *
+ *  NOTE: Creating the table definition file is not enough. You also need to call the
  *        retrieve_XXX_views_data() function from ../tripal_genetic.views.inc:tripal_genetic_views_data()
  *        by adding the following line:
  *           $data = array_merge($data, retrieve_XXX_views_data());
- *        to the function and including the file directly above the function (blow the function 
+ *        to the function and including the file directly above the function (blow the function
  *        header by adding:
  *           require_once('views/XXX.views.inc');
  *
  *  REMOVE THIS COMMENT IN THE COPY!
- */ 
- 
+ */
+
 /**
  *  @file
  *  This file defines the data array for a given chado table. This array
@@ -24,31 +24,31 @@
  *  with this module in:
  *  @see tripal_genetic.views.inc --in tripal_genetic_views_data()
  *
- *  Note: All chado tables are joined to their drupal nodes through the chado_XXX linking table. 
+ *  Note: All chado tables are joined to their drupal nodes through the chado_XXX linking table.
  *        This file simply defines this linking table and joins the three tables together.
  *        No modification of XXX.views.inc is needed.
  *
- *  Documentation on views integration can be found at 
+ *  Documentation on views integration can be found at
  *  http://views2.logrus.com/doc/html/index.html.
  */
- 
+
 /**
- * Purpose: this function returns the portion of the data array 
- *   which describes the chado_XXX drupal table, it's fields and any joins between it 
+ * Purpose: this function returns the portion of the data array
+ *   which describes the chado_XXX drupal table, it's fields and any joins between it
  *   and other tables
  * @see tripal_genetic_views_data() --in tripal_genetic.views.inc
  *
  * The main need for description of this table to views is to join chado data with drupal nodes
  *
  */
-function retrieve_chado_XXX_views_data () {
-	global $db_url;
+function retrieve_chado_XXX_views_data() {
+  global $db_url;
   $data = array();
-  
+
   // if the chado database is not local to the drupal database
   // then we need to set the database name.  This should always
   // be 'chado'.
-  if(is_array($db_url) and array_key_exists('chado',$db_url)){
+  if (is_array($db_url) and array_key_exists('chado', $db_url)) {
      // return empty data array b/c if chado is external then no join to the nodetable can be made
      return $data;
   }
@@ -57,28 +57,28 @@ function retrieve_chado_XXX_views_data () {
   $data['chado_XXX']['table'] = array(
     'field' => 'nid',
   );
-  
+
   //Relationship Definitions---------------------------------
   // Note: No joins need to be made from $data['XXX']['table']
-  
+
   // Join the chado_XXX table to XXX
   $data['chado_XXX']['table']['join']['XXX'] = array(
-  	'left_field' => 'XXX_id',
-  	'field' => 'XXX_id',
+    'left_field' => 'XXX_id',
+    'field' => 'XXX_id',
   );
-  
+
   // Join the node table to chado_XXX
   $data['node']['table']['join']['chado_XXX'] = array(
-  	'left_field' => 'nid',
-  	'field' => 'nid',
+    'left_field' => 'nid',
+    'field' => 'nid',
   );
-  
+
   // Join the node table to XXX
   $data['node']['table']['join']['XXX'] = array(
-  	'left_table' => 'chado_XXX',
-  	'left_field' => 'nid',
-  	'field' => 'nid',
-  );  
+    'left_table' => 'chado_XXX',
+    'left_field' => 'nid',
+    'field' => 'nid',
+  );
 
-	return $data;
-}
+  return $data;
+}

+ 27 - 27
tripal_genetic/views/template.table_defn.views.inc

@@ -5,7 +5,7 @@
  *
  *   - Every instance of XXX should be replaced with the name of your table
  *   - If this is a base table (you want a view where every row is a row from this table)
- *     then change $data['XXX']['table'] to $data['XXX']['table']['base'] 
+ *     then change $data['XXX']['table'] to $data['XXX']['table']['base']
  *     and $data['XXX']['table']['database'] to $data['XXX']['table']['base']['database']
  *   - Relationships between this table and others: YYY is the table you are trying to join to this
  *     one. You want to join a table to this one if this table contains a foreign key to the other
@@ -15,18 +15,18 @@
  *   - Create a field definition for each field in this table using the example fields already
  *     listed. Match the type of the database field to the field definition listed below.
  *     (ie: for a text/varchar field from the database use plain_text_field below)
- * 
- *  NOTE: Creating the table definition file is not enough. You also need to call the 
+ *
+ *  NOTE: Creating the table definition file is not enough. You also need to call the
  *        retrieve_XXX_views_data() function from ../tripal_genetic.views.inc:tripal_genetic_views_data()
  *        by adding the following line:
  *           $data = array_merge($data, retrieve_XXX_views_data());
- *        to the function and including the file directly above the function (blow the function 
+ *        to the function and including the file directly above the function (blow the function
  *        header by adding:
  *           require_once('views/XXX.views.inc');
  *
  *  REMOVE THIS COMMENT IN THE COPY!
- */ 
- 
+ */
+
 /**
  *  @file
  *  This file defines the data array for a given chado table. This array
@@ -34,12 +34,12 @@
  *  with this module in:
  *  @see tripal_genetic.views.inc --in tripal_genetic_views_data()
  *
- *  Documentation on views integration can be found at 
+ *  Documentation on views integration can be found at
  *  http://views2.logrus.com/doc/html/index.html.
  */
 
 /*************************************************************************
- * Purpose: this function returns the portion of the data array 
+ * Purpose: this function returns the portion of the data array
  *   which describes the XXX table, it's fields and any joins between it and other tables
  * @see tripal_genetic_views_data() --in tripal_genetic.views.inc
  *
@@ -55,23 +55,23 @@
   // if the chado database is not local to the drupal database
   // then we need to set the database name.  This should always
   // be 'chado'.
-  if(is_array($db_url) and array_key_exists('chado',$db_url)){
+  if (is_array($db_url) and array_key_exists('chado', $db_url)) {
     $database = 'chado';
   }
-   
+
   //Basic table definition-----------------------------------
   $data['XXX']['table']['group'] = t('Chado XXX');
-  
+
   $data['XXX']['table'] = array(
     'field' => 'primary_id',
     'title' => t('Chado XXX'),
     'help' => t('Enter some user-friendly description of this tables purpose to the user.'),
   );
-  if($database){
+  if ($database) {
      $data['XXX']['table']['database'] = $database;
   }
 
-  
+
   //Relationship Definitions---------------------------------
   //Join: YYY => XXX
   // Notice that this relationship tells the primary table to show it's fields to the
@@ -80,16 +80,16 @@
   $data['XXX']['table']['join']['YYY'] = array(
     'left_field' => 'foreign key in YYY table',
     'field' => 'primary key in XXX table',
-  );  
-  
+  );
+
   //Join: XXX => XY => YYY
   // This relationship should be described in both directions
-  // in the appropriate files (ie: for feature => library 
+  // in the appropriate files (ie: for feature => library
   // describe in both feature.views.inc and library.views.inc)
   $data['XXX']['table']['join']['XY'] = array(
     'left_field' => 'matching XXX key in the XY table',
     'field' => 'primary key in XXX table',
-  );  
+  );
   $data['XXX']['table']['join']['YYY'] = array(
     'left_table' => 'XY',
     'left_field' => 'matching XXX key in the XY table',
@@ -99,9 +99,9 @@
     'left_field' => 'primary key in YYY table',
     'field' => 'matching YYY key in the XY table',
   );
-   
+
   //Table Field Definitions----------------------------------
-      
+
   //Field: XXX_id (primary key)
   $data['XXX']['field_name'] = array(
     'title' => t('XXX Primary Key'),
@@ -123,7 +123,7 @@
    * Remove this section when done
    */
 
-  //Field: plain_text_field (chado datatype)   
+  //Field: plain_text_field (chado datatype)
   $data['XXX']['plain_text_field'] = array(
     'title' => t('Human-Readable Name'),
     'help' => t('Description of this field.'),
@@ -142,7 +142,7 @@
     ),
   );
 
-  //Field: numeric_field (chado datatype)   
+  //Field: numeric_field (chado datatype)
   $data['XXX']['numeric_field'] = array(
     'title' => t('Human-Readable Name'),
     'help' => t('Description of this field.'),
@@ -158,7 +158,7 @@
     ),
   );
 
-  //Field: boolean_field (chado datatype)   
+  //Field: boolean_field (chado datatype)
   $data['XXX']['boolean_field'] = array(
     'title' => t('Human-Readable Name'),
     'help' => t('Description of this field.'),
@@ -174,7 +174,7 @@
     ),
   );
 
-  //Field: unix_timestamp (chado datatype)   
+  //Field: unix_timestamp (chado datatype)
   $data['XXX']['unix_timestamp'] = array(
     'title' => t('Human-Readable Name'),
     'help' => t('Description of this field.'),
@@ -190,7 +190,7 @@
     ),
   );
 
-  //Field: human_readable_date (chado datatype)   
+  //Field: human_readable_date (chado datatype)
   $data['XXX']['human_readable_date'] = array(
     'title' => t('Human-Readable Name'),
     'help' => t('Description of this field.'),
@@ -202,10 +202,10 @@
       'handler' => 'views_handler_sort_date',
     ),
   );
-   
+
    /*
     * End of Example Field definitions
     */
-    
+
   return $data;
-}
+}