tripal_featuremap.api.inc 4.8 KB

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