tripal_featuremap.api.inc 4.5 KB

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