tripal_analysis.api.inc 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. /****************************************************************************
  3. * @section Chado Table Descriptions
  4. ****************************************************************************/
  5. /****************************************************************************
  6. * Implements hook_chado_analysisfeature_schema()
  7. * Purpose: To add descriptions and foreign keys to default table description
  8. * Note: This array will be merged with the array from all other implementations
  9. *
  10. * @return
  11. * Array describing the analysisfeature table
  12. */
  13. function tripal_analysis_chado_analysisfeature_schema() {
  14. $description = array();
  15. $description['foreign keys']['feature'] = array(
  16. 'table' => 'feature',
  17. 'columns' => array(
  18. 'feature_id' => 'feature_id',
  19. ),
  20. );
  21. $description['foreign keys']['analysis'] = array(
  22. 'table' => 'analysis',
  23. 'columns' => array(
  24. 'analysis_id' => 'analysis_id',
  25. ),
  26. );
  27. return $description;
  28. }
  29. /****************************************************************************
  30. * Implements hook_chado_analysisprop_schema()
  31. * Purpose: To add descriptions and foreign keys to default table description
  32. * Note: This array will be merged with the array from all other implementations
  33. *
  34. * @return
  35. * Array describing the analysisprop table
  36. */
  37. function tripal_analysis_chado_analysisprop_schema() {
  38. $description = array();
  39. $description['foreign keys']['cvterm'] = array(
  40. 'table' => 'cvterm',
  41. 'columns' => array(
  42. 'type_id' => 'cvterm_id',
  43. ),
  44. );
  45. $description['foreign keys']['analysis'] = array(
  46. 'table' => 'analysis',
  47. 'columns' => array(
  48. 'analysis_id' => 'analysis_id',
  49. ),
  50. );
  51. return $description;
  52. }
  53. /**
  54. * Adds a single property to an existing analysis record.
  55. *
  56. * @ingroup tripal_api
  57. */
  58. function tripal_analysis_get_property($analysis_id,$property){
  59. // construct the array of values to be inserted
  60. $values = array (
  61. 'analysis_id' => $analysis_id,
  62. 'type_id' => array (
  63. 'cv_id' => array (
  64. 'name' => 'tripal',
  65. ),
  66. 'name' => $property,
  67. 'is_obsolete' => 0
  68. ),
  69. );
  70. $columns = array('type_id','value');
  71. $results = tripal_core_chado_select('analysisprop',$columns,$values);
  72. // this next bit is a hack until we get the recursive add vars routine written
  73. foreach($results as $prop){
  74. $prop->type_id = new stdClass();
  75. $prop->type_id->table_name = 'cvterm';
  76. $prop->type_id->name = $property;
  77. }
  78. return $results;
  79. }
  80. /**
  81. * Adds a single property to an existing analysis record.
  82. *
  83. * @ingroup tripal_api
  84. */
  85. function tripal_analysis_insert_property($analysis_id,$property,$value){
  86. // construct the array of values to be inserted
  87. $values = array (
  88. 'analysis_id' => $analysis_id,
  89. 'type_id' => array (
  90. 'cv_id' => array (
  91. 'name' => 'tripal',
  92. ),
  93. 'name' => $property,
  94. 'is_obsolete' => 0
  95. ),
  96. 'value' => $value,
  97. 'rank' => 0,
  98. );
  99. return tripal_core_chado_insert('analysisprop',$values);
  100. }
  101. /**
  102. * Adds a single property to an existing analysis record.
  103. *
  104. * @ingroup tripal_api
  105. */
  106. function tripal_analysis_update_property($analysis_id,$property,$value){
  107. // construct the array that will match the exact record to update
  108. $match = array (
  109. 'analysis_id' => $analysis_id,
  110. 'type_id' => array (
  111. 'cv_id' => array (
  112. 'name' => 'tripal',
  113. ),
  114. 'name' => $property,
  115. ),
  116. );
  117. // construct the array of values to be updated
  118. $values = array (
  119. 'value' => $value,
  120. );
  121. return tripal_core_chado_update('analysisprop',$match,$values);
  122. }