tripal_featuremap.api.inc

File

tripal_featuremap/api/tripal_featuremap.api.inc
View source
  1. <?php
  2. /**
  3. * Retrieve properties of a given type for a given featuremap
  4. *
  5. * @param $featuremap_id
  6. * The featuremap_id of the properties you would like to retrieve
  7. * @param $property
  8. * The cvterm name of the properties to retrieve
  9. *
  10. * @return
  11. * An featuremap chado variable with the specified properties expanded
  12. *
  13. * @ingroup tripal_featuremap_api
  14. */
  15. function tripal_featuremap_get_property($featuremap_id, $property) {
  16. return tripal_core_get_property('featuremap', $featuremap_id, $property, 'featuremap_property');
  17. }
  18. /**
  19. * Insert a given property
  20. *
  21. * @param $featuremap_id
  22. * The featuremap_id of the property to insert
  23. * @param $property
  24. * The cvterm name of the property to insert
  25. * @param $value
  26. * The value of the property to insert
  27. * @param $update_if_present
  28. * A boolean indicated whether to update the record if it's already present
  29. *
  30. * @return
  31. * True of success, False otherwise
  32. *
  33. * @ingroup tripal_featuremap_api
  34. */
  35. function tripal_featuremap_insert_property($featuremap_id, $property, $value, $update_if_present = 0) {
  36. return tripal_core_insert_property('featuremap', $featuremap_id, $property, 'featuremap_property', $value, $update_if_present);
  37. }
  38. /**
  39. * Update a given property
  40. *
  41. * @param $featuremap_id
  42. * The featuremap_id of the property to update
  43. * @param $property
  44. * The cvterm name of the property to update
  45. * @param $value
  46. * The value of the property to update
  47. * @param $insert_if_missing
  48. * A boolean indicated whether to insert the record if it's absent
  49. *
  50. * Note: The property will be identified using the unique combination of the $featuremap_id and $property
  51. * and then it will be updated with the supplied value
  52. *
  53. * @return
  54. * True of success, False otherwise
  55. *
  56. * @ingroup tripal_featuremap_api
  57. */
  58. function tripal_featuremap_update_property($featuremap_id, $property, $value, $insert_if_missing = 0) {
  59. return tripal_core_update_property('featuremap', $featuremap_id, $property, 'featuremap_property', $value, $insert_if_missing);
  60. }
  61. /**
  62. * Delete a given property
  63. *
  64. * @param $featuremap_id
  65. * The featuremap_id of the property to delete
  66. * @param $property
  67. * The cvterm name of the property to delete
  68. *
  69. * Note: The property will be identified using the unique combination of the $featuremap_id and $property
  70. * and then it will be deleted
  71. *
  72. * @return
  73. * True of success, False otherwise
  74. *
  75. * @ingroup tripal_featuremap_api
  76. */
  77. function tripal_featuremap_delete_property($featuremap_id, $property) {
  78. return tripal_core_delete_property('featuremap', $featuremap_id, $property, 'featuremap_property');
  79. }
  80. /*
  81. *
  82. */
  83. function tripal_featuremap_add_featuremap_dbxref($featuremap_id, $featuremap_dbxref) {
  84. // break apart the dbxref
  85. $dbname = '';
  86. $accession = '';
  87. if(preg_match('/^(.*?):(.*?)$/', $featuremap_dbxref, $matches)) {
  88. $dbname = $matches[1];
  89. $accession = $matches[2];
  90. }
  91. else {
  92. return FALSE;
  93. }
  94. // check to see if the featuremap_dbxref record already exist
  95. $values = array(
  96. 'dbxref_id' => array(
  97. 'accession' => $accession,
  98. 'db_id' => array(
  99. 'name' => $dbname,
  100. ),
  101. ),
  102. 'featuremap_id' => $featuremap_id,
  103. );
  104. $options = array('statement_name' => 'sel_featuremapdbxref_dbpu');
  105. $results = tripal_core_chado_select('featuremap_dbxref', array('*'), $values, $options);
  106. // if the featuremap_dbxref record exist then we don't need to re-add it.
  107. if(count($results) > 0) {
  108. return $results[0];
  109. }
  110. // make sure our database already exists
  111. $db = tripal_db_add_db($dbname);
  112. // get the database cross-reference
  113. $dbxvalues = array(
  114. 'accession' => $accession,
  115. 'db_id' => $db->db_id,
  116. );
  117. $dbxoptions = array('statement_name' => 'sel_dbxref_acdb');
  118. $results = tripal_core_chado_select('dbxref', array('dbxref_id'), $dbxvalues, $dbxoptions);
  119. // if the accession doesn't exist then add it
  120. if(count($results) == 0){
  121. $dbxref = tripal_db_add_dbxref($db->db_id, $accession);
  122. }
  123. else {
  124. $dbxref = $results[0];
  125. }
  126. // now add the record
  127. $options = array('statement_name' => 'ins_featuremapdbxref_dbpu');
  128. $results = tripal_core_chado_insert('featuremap_dbxref', $values, $options);
  129. if (!$results) {
  130. watchdog('t_featuremap', "Cannot add map dbxref: %db:%accession.",
  131. array('%db' => $dbname, '%accession' => $accession). WATCHDOG_ERROR);
  132. return FALSE;
  133. }
  134. return $results;
  135. }