tripal_chado.module 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816
  1. <?php
  2. //
  3. // APPLICATION PROGRAMMER INTERFACE
  4. //
  5. // Generic Chado API functions
  6. require_once "api/tripal_chado.api.inc";
  7. require_once 'api/tripal_chado.property.api.inc';
  8. require_once 'api/tripal_chado.query.api.inc';
  9. require_once 'api/tripal_chado.variables.api.inc';
  10. require_once 'api/tripal_chado.schema.api.inc';
  11. require_once 'api/tripal_chado.custom_tables.api.inc';
  12. require_once 'api/tripal_chado.mviews.api.inc';
  13. require_once 'api/tripal_chado.schema_v1.3.api.inc';
  14. require_once 'api/tripal_chado.schema_v1.2.api.inc';
  15. require_once 'api/tripal_chado.schema_v1.11.api.inc';
  16. require_once 'api/tripal_chado.semweb.api.inc';
  17. require_once 'api/tripal_chado.views.api.inc';
  18. // Chado module specific API functions
  19. require_once 'api/modules/tripal_chado.analysis.api.inc';
  20. require_once 'api/modules/tripal_chado.contact.api.inc';
  21. require_once 'api/modules/tripal_chado.cv.api.inc';
  22. require_once 'api/modules/tripal_chado.db.api.inc';
  23. require_once 'api/modules/tripal_chado.feature.api.inc';
  24. require_once 'api/modules/tripal_chado.organism.api.inc';
  25. require_once 'api/modules/tripal_chado.pub.api.inc';
  26. require_once 'api/modules/tripal_chado.stock.api.inc';
  27. //
  28. // REQUIRED INCLUDE FILES
  29. //
  30. // These require files implement hooks and therefore must
  31. // ways be included when the module is interpreted.
  32. require_once "includes/tripal_chado.entity.inc";
  33. require_once "includes/tripal_chado.schema.inc";
  34. require_once "includes/tripal_chado.vocab_storage.inc";
  35. require_once "includes/tripal_chado.field_storage.inc";
  36. require_once "includes/tripal_chado.fields.inc";
  37. require_once "includes/tripal_chado.mapping.inc";
  38. require_once "includes/TripalFields/ChadoField.inc";
  39. require_once "includes/TripalFields/ChadoFieldWidget.inc";
  40. require_once "includes/TripalFields/ChadoFieldFormatter.inc";
  41. tripal_chado_set_globals();
  42. /**
  43. * This function is used to set the global Chado variables
  44. *
  45. * @ingroup tripal_chado
  46. */
  47. function tripal_chado_set_globals() {
  48. // these global variables are meant to be accessed by all Tripal
  49. // modules to find the chado version installed and if Chado is local.
  50. // these variables are stored as globals rather than using the drupal_set_variable
  51. // functions because the Drupal functions make databaes queries and for long
  52. // running loaders we don't want those queries repeatedly.
  53. $GLOBALS["chado_is_installed"] = chado_is_installed();
  54. if ($GLOBALS["chado_is_installed"]) {
  55. $GLOBALS["chado_is_local"] = chado_is_local();
  56. $GLOBALS["chado_version"] = chado_get_version();
  57. $GLOBALS["exact_chado_version"] = chado_get_version(TRUE);
  58. }
  59. }
  60. /**
  61. * Implements hook_init().
  62. * Used to set the search_path, create default content and set default variables.
  63. *
  64. * @ingroup tripal_chado
  65. */
  66. function tripal_chado_init() {
  67. if (user_access('administer tripal')) {
  68. if ($GLOBALS["chado_is_installed"]) {
  69. // Check to see if the Chado and Drupal have been prepared
  70. if (!variable_get('tripal_chado_is_prepared', FALSE)) {
  71. drupal_set_message('Chado is installed but Tripal has not yet prepared Drupal and Chado. Please ' .
  72. l('prepare both Drupal and Chado', 'admin/tripal/storage/chado/prepare') .
  73. ' before continuing.', 'warning');
  74. }
  75. }
  76. else {
  77. drupal_set_message('Tripal cannot find a Chado installation. Please ' .
  78. l('install Chado', 'admin/tripal/storage/chado/chado_install') .
  79. ' before continuing.', 'warning');
  80. }
  81. }
  82. }
  83. /**
  84. * Implements hook_views_api().
  85. *
  86. * Essentially this hook tells drupal that there is views support for
  87. * for this module which then includes tripal_db.views.inc where all the
  88. * views integration code is
  89. *
  90. * @ingroup tripal_feature
  91. */
  92. function tripal_chado_views_api() {
  93. return array(
  94. 'api' => 3.0,
  95. );
  96. }
  97. /**
  98. * Implements hook_menu().
  99. */
  100. function tripal_chado_menu() {
  101. $items = array();
  102. //////////////////////////////////////////////////////////////////////////////
  103. // Chado Storage Backend
  104. //////////////////////////////////////////////////////////////////////////////
  105. $items['admin/tripal/storage/chado'] = array(
  106. 'title' => 'Chado',
  107. 'description' => t("Integrates Chado with Tripal and includes tools to
  108. load data, and extend the chado schema through custom tables &
  109. materialized views."),
  110. 'weight' => -100,
  111. 'access arguments' => array('administer tripal'),
  112. );
  113. $items['admin/tripal/storage/chado/install'] = array(
  114. 'title' => 'Install Chado',
  115. 'description' => t('Installs the Chado database tables, views, etc., inside the current Drupal database'),
  116. 'page callback' => 'drupal_get_form',
  117. 'page arguments' => array('tripal_chado_load_form'),
  118. 'type' => MENU_NORMAL_ITEM,
  119. 'access arguments' => array('install chado'),
  120. 'file' => 'includes/tripal_chado.install.inc',
  121. 'file path' => drupal_get_path('module', 'tripal_chado'),
  122. 'weight' => -100
  123. );
  124. $items['admin/tripal/storage/chado/prepare'] = array(
  125. 'title' => 'Prepare Chado',
  126. 'description' => t('Prepares Drupal to use Chado.'),
  127. 'page callback' => 'drupal_get_form',
  128. 'page arguments' => array('tripal_chado_prepare_form'),
  129. 'type' => MENU_NORMAL_ITEM,
  130. 'access arguments' => array('install chado'),
  131. 'file' => 'includes/tripal_chado.setup.inc',
  132. 'file path' => drupal_get_path('module', 'tripal_chado'),
  133. 'weight' => -99
  134. );
  135. $items['admin/tripal/storage/chado/publish'] = array(
  136. 'title' => 'Publish',
  137. 'description' => t('Publish data that is present in Chado but which does
  138. not yet have a page on this site for viewing. In Tripal v2.0 or
  139. earlier this was refered to as "syncing".'),
  140. 'page callback' => 'drupal_get_form',
  141. 'page arguments' => array('tripal_chado_publish_form'),
  142. 'type' => MENU_NORMAL_ITEM,
  143. 'access arguments' => array('administer tripal'),
  144. 'file' => 'includes/tripal_chado.publish.inc',
  145. 'file path' => drupal_get_path('module', 'tripal_chado'),
  146. 'weight' => -99
  147. );
  148. // Adds a +Publish Chado Content link on the 'Tripal Content Types' page.
  149. $items['admin/structure/bio_data/publish'] = array(
  150. 'title' => 'Publish Chado Content',
  151. 'description' => t('Publish data that is present in Chado but which does
  152. not yet have a page on this site for viewing. In Tripal v2.0 or
  153. earlier this was refered to as "syncing".'),
  154. 'page callback' => 'drupal_get_form',
  155. 'page arguments' => array('tripal_chado_publish_form'),
  156. 'access arguments' => array('administer tripal'),
  157. 'file' => 'includes/tripal_chado.publish.inc',
  158. 'file path' => drupal_get_path('module', 'tripal_chado'),
  159. 'type' => MENU_LOCAL_ACTION,
  160. 'weight' => 2
  161. );
  162. //////////////////////////////////////////////////////////////////////////////
  163. // Materialized Views
  164. //////////////////////////////////////////////////////////////////////////////
  165. $items['admin/tripal/storage/chado/mviews'] = array(
  166. 'title' => 'Materialized Views',
  167. 'description' => t('Materialized views are used to improve speed of large or complex queries.'),
  168. 'page callback' => 'tripal_mview_admin_view',
  169. 'access arguments' => array('administer tripal'),
  170. 'type' => MENU_NORMAL_ITEM,
  171. 'file' => 'includes/tripal_chado.mviews.inc',
  172. 'file path' => drupal_get_path('module', 'tripal_chado'),
  173. 'weight' => -10
  174. );
  175. $items['admin/tripal/storage/chado/mviews/help'] = array(
  176. 'title' => 'Help',
  177. 'description' => t('Help for the materialized views management system'),
  178. 'page callback' => 'theme',
  179. 'page arguments' => array('tripal_mviews_help'),
  180. 'access arguments' => array('administer tripal'),
  181. 'type' => MENU_LOCAL_TASK,
  182. 'file' => 'includes/tripal_chado.mviews.inc',
  183. 'file path' => drupal_get_path('module', 'tripal_chado'),
  184. 'weight' => 10
  185. );
  186. $items['admin/tripal/storage/chado/mviews/report/%'] = array(
  187. 'title' => 'Materialized View',
  188. 'description' => t('Materialized views are used to improve speed of large or complex queries. These are database views as compared to Drupal views.'),
  189. 'page callback' => 'tripal_mview_report',
  190. 'page arguments' => array(6),
  191. 'access arguments' => array('administer tripal'),
  192. 'type' => MENU_CALLBACK,
  193. 'file' => 'includes/tripal_chado.mviews.inc',
  194. 'file path' => drupal_get_path('module', 'tripal_chado'),
  195. );
  196. $items['admin/tripal/storage/chado/mviews/new'] = array(
  197. 'title' => 'Create Materialized View',
  198. 'description' => t('Create a new materialized view.'),
  199. 'page callback' => 'drupal_get_form',
  200. 'page arguments' => array('tripal_mviews_form'),
  201. 'access arguments' => array('administer tripal'),
  202. 'type' => MENU_CALLBACK,
  203. 'file' => 'includes/tripal_chado.mviews.inc',
  204. 'file path' => drupal_get_path('module', 'tripal_chado'),
  205. );
  206. $items['admin/tripal/storage/chado/mviews/edit/%'] = array(
  207. 'title' => 'Edit Materialized View',
  208. 'page callback' => 'drupal_get_form',
  209. 'page arguments' => array('tripal_mviews_form', 6),
  210. 'access arguments' => array('administer tripal'),
  211. 'type' => MENU_CALLBACK,
  212. 'file' => 'includes/tripal_chado.mviews.inc',
  213. 'file path' => drupal_get_path('module', 'tripal_chado'),
  214. );
  215. $items['admin/tripal/storage/chado/mviews/update/%'] = array(
  216. 'title' => 'Create Materialized View',
  217. 'description' => t('Materialized views are used to improve speed of large or complex queries.'),
  218. 'page callback' => 'tripal_mviews_add_populate_job',
  219. 'page arguments' => array(6),
  220. 'access arguments' => array('administer tripal'),
  221. 'type' => MENU_CALLBACK,
  222. 'file' => 'includes/tripal_chado.mviews.inc',
  223. 'file path' => drupal_get_path('module', 'tripal_chado'),
  224. );
  225. $items['admin/tripal/storage/chado/mviews/delete/%'] = array(
  226. 'title' => 'Create Materialized View',
  227. 'description' => t('Materialized views are used to improve speed of large or complex queries.'),
  228. 'page callback' => 'drupal_get_form',
  229. 'page arguments' => array('tripal_mviews_delete_form', 5),
  230. 'access arguments' => array('administer tripal'),
  231. 'type' => MENU_CALLBACK,
  232. 'file' => 'includes/tripal_chado.mviews.inc',
  233. 'file path' => drupal_get_path('module', 'tripal_chado'),
  234. );
  235. // TODO: complete the code for exporting and importing of MViews.
  236. // Need to address security issues of sharing SQL.
  237. $items['admin/tripal/storage/chado/mviews/import'] = array(
  238. 'title' => 'Import MView',
  239. 'description' => 'Import a materialized view from another Tripal instance.',
  240. 'page callback' => 'drupal_get_form',
  241. 'page arguments' => array('tripal_mviews_import_form'),
  242. 'access arguments' => array('administer tripal'),
  243. 'type' => MENU_CALLBACK,
  244. 'file' => 'includes/tripal_chado.mviews.inc',
  245. 'file path' => drupal_get_path('module', 'tripal_chado'),
  246. );
  247. $items['admin/tripal/storage/chado/mviews/%tblid/export'] = array(
  248. 'title' => 'Export MView',
  249. 'description' => 'Export a materialized view for use by another Tripal instance.',
  250. 'page callback' => 'drupal_get_form',
  251. 'page arguments' => array('tripal_mviews_export_form', 5),
  252. 'access arguments' => array('administer tripal'),
  253. 'type' => MENU_CALLBACK,
  254. 'file' => 'includes/tripal_chado.mviews.inc',
  255. 'file path' => drupal_get_path('module', 'tripal_chado'),
  256. );
  257. //////////////////////////////////////////////////////////////////////////////
  258. // Custom Tables
  259. //////////////////////////////////////////////////////////////////////////////
  260. $items['admin/tripal/storage/chado/custom_tables'] = array(
  261. 'title' => 'Custom Tables',
  262. 'description' => t('Creation of custom tables that are added to Chado database.'),
  263. 'page callback' => 'tripal_custom_table_admin_view',
  264. 'access arguments' => array('administer tripal'),
  265. 'type' => MENU_NORMAL_ITEM,
  266. 'file' => 'includes/tripal_chado.custom_tables.inc',
  267. 'file path' => drupal_get_path('module', 'tripal_chado'),
  268. 'weight' => -10
  269. );
  270. $items['admin/tripal/storage/chado/custom_tables/help'] = array(
  271. 'title' => 'Help',
  272. 'description' => t('Help for the tripal job management system'),
  273. 'page callback' => 'theme',
  274. 'page arguments' => array('tripal_job_help'),
  275. 'access arguments' => array('administer tripal'),
  276. 'type' => MENU_LOCAL_TASK,
  277. 'file' => 'includes/tripal_chado.custom_tables.inc',
  278. 'file path' => drupal_get_path('module', 'tripal_chado'),
  279. 'weight' => 10
  280. );
  281. $items['admin/tripal/storage/chado/custom_tables/view/%'] = array(
  282. 'title' => 'Custom Tables',
  283. 'description' => t('Custom tables are added to Chado.'),
  284. 'page callback' => 'tripal_custom_table_view',
  285. 'page arguments' => array(6),
  286. 'access arguments' => array('administer tripal'),
  287. 'file' => 'includes/tripal_chado.custom_tables.inc',
  288. 'file path' => drupal_get_path('module', 'tripal_chado'),
  289. 'type' => MENU_CALLBACK,
  290. );
  291. $items['admin/tripal/storage/chado/custom_tables/new'] = array(
  292. 'title' => 'Create Custom Table',
  293. 'description' => t('An interface for creating your own custom tables.'),
  294. 'page callback' => 'tripal_custom_table_new_page',
  295. 'access arguments' => array('administer tripal'),
  296. 'file' => 'includes/tripal_chado.custom_tables.inc',
  297. 'file path' => drupal_get_path('module', 'tripal_chado'),
  298. 'type' => MENU_CALLBACK,
  299. );
  300. $items['admin/tripal/storage/chado/custom_tables/edit/%'] = array(
  301. 'title' => 'Edit Custom Table',
  302. 'page callback' => 'drupal_get_form',
  303. 'page arguments' => array('tripal_custom_tables_form', 6),
  304. 'access arguments' => array('administer tripal'),
  305. 'file' => 'includes/tripal_chado.custom_tables.inc',
  306. 'file path' => drupal_get_path('module', 'tripal_chado'),
  307. 'type' => MENU_CALLBACK,
  308. );
  309. $items['admin/tripal/storage/chado/custom_tables/delete/%'] = array(
  310. 'title' => 'Create Custom Table',
  311. 'description' => t('Custom tables are added to Chado.'),
  312. 'page callback' => 'drupal_get_form',
  313. 'page arguments' => array('tripal_custom_tables_delete_form', 6),
  314. 'access arguments' => array('administer tripal'),
  315. 'file' => 'includes/tripal_chado.custom_tables.inc',
  316. 'file path' => drupal_get_path('module', 'tripal_chado'),
  317. 'type' => MENU_CALLBACK,
  318. );
  319. $items['admin/tripal/storage/chado/custom_tables/views/tables/enable'] = array(
  320. 'title' => 'Enable Custom Tables Administrative View',
  321. 'page callback' => 'tripal_enable_view',
  322. 'page arguments' => array('tripal_admin_custom_table', 'admin/tripal/storage/chado/custom_tables'),
  323. 'access arguments' => array('administer tripal'),
  324. 'file' => 'includes/tripal_chado.custom_tables.inc',
  325. 'file path' => drupal_get_path('module', 'tripal_chado'),
  326. 'type' => MENU_CALLBACK,
  327. );
  328. //////////////////////////////////////////////////////////////////////////////
  329. // Data Loaders
  330. //////////////////////////////////////////////////////////////////////////////
  331. $items['admin/tripal/storage/chado/loaders'] = array(
  332. 'title' => 'Data Loaders',
  333. 'description' => t('Tools facilitating data import.'),
  334. 'access arguments' => array('administer tripal'),
  335. 'type' => MENU_NORMAL_ITEM,
  336. 'weight' => 6
  337. );
  338. $items['admin/tripal/storage/chado/loaders/fasta_loader'] = array(
  339. 'title' => 'FASTA file Loader',
  340. 'description' => 'Load sequences from a multi-FASTA file into Chado',
  341. 'page callback' => 'drupal_get_form',
  342. 'page arguments' => array('tripal_feature_fasta_load_form'),
  343. 'access arguments' => array('administer tripal feature'),
  344. 'file' => 'includes/loaders/tripal_chado.fasta_loader.inc',
  345. 'file path' => drupal_get_path('module', 'tripal_chado'),
  346. 'type' => MENU_NORMAL_ITEM,
  347. );
  348. $items['admin/tripal/storage/chado/loaders/gff3_load'] = array(
  349. 'title' => 'GFF3 file Loader',
  350. 'description' => 'Import a GFF3 file into Chado',
  351. 'page callback' => 'drupal_get_form',
  352. 'page arguments' => array('tripal_feature_gff3_load_form'),
  353. 'access arguments' => array('administer tripal feature'),
  354. 'file' => 'includes/loaders/tripal_chado.gff_loader.inc',
  355. 'file path' => drupal_get_path('module', 'tripal_chado'),
  356. 'type' => MENU_NORMAL_ITEM,
  357. );
  358. $items['admin/tripal/storage/chado/loaders/pub'] = array(
  359. 'title' => t('Publication Importers'),
  360. 'description' => t('Create and modify importers that can connect to and retreive publications from remote databases.'),
  361. 'page callback' => 'tripal_pub_importers_list',
  362. 'access arguments' => array('administer tripal pub'),
  363. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  364. 'file path' => drupal_get_path('module', 'tripal_chado'),
  365. 'type' => MENU_NORMAL_ITEM,
  366. 'weight' => 0
  367. );
  368. $items['admin/tripal/storage/chado/loaders/pub/new'] = array(
  369. 'title' => t('Add an Importer'),
  370. 'description' => t('Add a new publication importer.'),
  371. 'page callback' => 'tripal_pub_importer_setup_page',
  372. 'access arguments' => array('administer tripal pub'),
  373. 'type ' => MENU_CALLBACK,
  374. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  375. 'file path' => drupal_get_path('module', 'tripal_chado'),
  376. );
  377. $items['admin/tripal/storage/chado/loaders/pub/edit/%'] = array(
  378. 'page callback' => 'tripal_pub_importer_setup_page',
  379. 'page arguments' => array(6, 7),
  380. 'access arguments' => array('administer tripal pub'),
  381. 'type ' => MENU_CALLBACK,
  382. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  383. 'file path' => drupal_get_path('module', 'tripal_chado'),
  384. );
  385. $items['admin/tripal/storage/chado/loaders/pub/raw/%'] = array(
  386. 'title' => t('Raw Data From Publication Import'),
  387. 'page callback' => 'tripal_get_remote_pub_raw_page',
  388. 'page arguments' => array(6),
  389. 'access arguments' => array('administer tripal pub'),
  390. 'type ' => MENU_CALLBACK,
  391. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  392. 'file path' => drupal_get_path('module', 'tripal_chado'),
  393. );
  394. // add a second link for the importer on the data loaders page
  395. $items['admin/tripal/storage/chado/loaders/pub/import'] = array(
  396. 'title' => t('Publication Importers'),
  397. 'page callback' => 'tripal_pub_importers_list',
  398. 'access arguments' => array('administer tripal pub'),
  399. 'type' => MENU_CALLBACK,
  400. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  401. 'file path' => drupal_get_path('module', 'tripal_chado'),
  402. );
  403. $items['admin/tripal/storage/chado/loaders/pub/submit/%'] = array(
  404. 'page callback' => 'tripal_pub_importer_submit_job',
  405. 'page arguments' => array(7),
  406. 'access arguments' => array('administer tripal pub'),
  407. 'type ' => MENU_CALLBACK,
  408. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  409. 'file path' => drupal_get_path('module', 'tripal_chado'),
  410. );
  411. $items['admin/tripal/storage/chado/loaders/pub/delete/%'] = array(
  412. 'page callback' => 'tripal_pub_importer_delete',
  413. 'page arguments' => array(7),
  414. 'access arguments' => array('administer tripal pub'),
  415. 'type ' => MENU_CALLBACK,
  416. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  417. 'file path' => drupal_get_path('module', 'tripal_chado'),
  418. );
  419. $items['admin/tripal/storage/chado/loaders/pub/changedb'] = array(
  420. 'page callback' => 'tripal_pub_importer_setup_page_update_remotedb',
  421. 'page arguments' => array(),
  422. 'access arguments' => array('administer tripal pub'),
  423. 'type ' => MENU_CALLBACK,
  424. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  425. 'file path' => drupal_get_path('module', 'tripal_chado'),
  426. );
  427. $items['admin/tripal/storage/chado/loaders/pub/criteria/%/%'] = array(
  428. 'page callback' => 'tripal_pub_importer_setup_page_update_criteria',
  429. 'page arguments' => array(7, 8),
  430. 'access arguments' => array('administer tripal pub'),
  431. 'type ' => MENU_CALLBACK,
  432. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  433. 'file path' => drupal_get_path('module', 'tripal_chado'),
  434. );
  435. //////////////////////////////////////////////////////////////////////////////
  436. // Migrate Content
  437. //////////////////////////////////////////////////////////////////////////////
  438. $items['admin/tripal/storage/chado/migrate'] = array(
  439. 'title' => 'Migrate',
  440. 'description' => t('Migrate Tripal v2 content to Tripal v3'),
  441. 'page callback' => 'drupal_get_form',
  442. 'page arguments' => array('tripal_chado_migrate_form'),
  443. 'type' => MENU_NORMAL_ITEM,
  444. 'access arguments' => array('administer tripal'),
  445. 'file' => 'includes/tripal_chado.migrate.inc',
  446. 'file path' => drupal_get_path('module', 'tripal_chado'),
  447. 'weight' => 10
  448. );
  449. //////////////////////////////////////////////////////////////////////////////
  450. // Semantic Web Settings
  451. //////////////////////////////////////////////////////////////////////////////
  452. $items['admin/tripal/storage/chado/semweb'] = array(
  453. 'title' => 'Semantic Web',
  454. 'description' => t('Semantic web settings. Set terms used for the web services.'),
  455. 'page callback' => 'drupal_get_form',
  456. 'page arguments' => array('tripal_chado_semweb_form'),
  457. 'type' => MENU_NORMAL_ITEM,
  458. 'access arguments' => array('administer tripal'),
  459. 'file' => 'includes/tripal_chado.semweb.inc',
  460. 'file path' => drupal_get_path('module', 'tripal_chado'),
  461. 'weight' => 10
  462. );
  463. $items['admin/tripal/storage/chado/semweb/edit/%/%'] = array(
  464. 'title' => 'Edit Semantic Web Term',
  465. 'description' => t('Edit terms used for the web services.'),
  466. 'page callback' => 'drupal_get_form',
  467. 'page arguments' => array('tripal_chado_semweb_edit_form', 6, 7),
  468. 'type' => MENU_CALLBACK,
  469. 'access arguments' => array('administer tripal'),
  470. 'file' => 'includes/tripal_chado.semweb.inc',
  471. 'file path' => drupal_get_path('module', 'tripal_chado'),
  472. );
  473. $items['admin/tripal/storage/chado/semweb/reset/%/%'] = array(
  474. 'title' => 'Reset Semantic Web Term',
  475. 'description' => t('Edit terms used for the web services.'),
  476. 'page callback' => 'drupal_get_form',
  477. 'page arguments' => array('tripal_chado_semweb_reset_form', 6, 7),
  478. 'type' => MENU_CALLBACK,
  479. 'access arguments' => array('administer tripal'),
  480. 'file' => 'includes/tripal_chado.semweb.inc',
  481. 'file path' => drupal_get_path('module', 'tripal_chado'),
  482. );
  483. //////////////////////////////////////////////////////////////////////////////
  484. // Auto Completes
  485. //////////////////////////////////////////////////////////////////////////////
  486. $items['admin/tripal/storage/chado/auto_name/dbxref/%/%'] = array(
  487. 'page callback' => 'tripal_autocomplete_dbxref',
  488. 'page arguments' => array(6, 7),
  489. 'access arguments' => array('access content'),
  490. 'file' => 'api/modules/tripal_chado.db.api.inc',
  491. 'file path' => drupal_get_path('module', 'tripal_chado'),
  492. 'type' => MENU_CALLBACK,
  493. );
  494. $items['admin/tripal/storage/chado/auto_name/cvterm/%/%'] = array(
  495. 'page callback' => 'tripal_autocomplete_cvterm',
  496. 'page arguments' => array(6, 7),
  497. 'access arguments' => array('access content'),
  498. 'file' => 'api/modules/tripal_chado.db.api.inc',
  499. 'file path' => drupal_get_path('module', 'tripal_chado'),
  500. 'type' => MENU_CALLBACK,
  501. );
  502. $items['admin/tripal/storage/chado/auto_name/pub/%'] = array(
  503. 'page callback' => 'tripal_autocomplete_pub',
  504. 'page arguments' => array(6),
  505. 'access arguments' => array('access content'),
  506. 'file' => 'api/modules/tripal_chado.pub.api.inc',
  507. 'file path' => drupal_get_path('module', 'tripal_chado'),
  508. 'type' => MENU_CALLBACK,
  509. );
  510. $items['admin/tripal/storage/chado/auto_name/contact/%'] = array(
  511. 'page callback' => 'tripal_autocomplete_contact',
  512. 'page arguments' => array(6),
  513. 'access arguments' => array('access content'),
  514. 'file' => 'api/modules/tripal_chado.contact.api.inc',
  515. 'file path' => drupal_get_path('module', 'tripal_chado'),
  516. 'type' => MENU_CALLBACK,
  517. );
  518. $items['admin/tripal/storage/chado/auto_name/feature/%'] = array(
  519. 'page callback' => 'tripal_autocomplete_feature',
  520. 'page arguments' => array(6),
  521. 'access arguments' => array('access content'),
  522. 'file' => 'api/modules/tripal_chado.feature.api.inc',
  523. 'file path' => drupal_get_path('module', 'tripal_chado'),
  524. 'type' => MENU_CALLBACK,
  525. );
  526. return $items;
  527. }
  528. /**
  529. * Implements hook_permission().
  530. *
  531. * Set the permission types that the chado module uses. Essentially we
  532. * want permissionis that protect creation, editing and deleting of chado
  533. * data objects
  534. *
  535. * @ingroup tripal
  536. */
  537. function tripal_chado_permission() {
  538. return array(
  539. 'install chado' => array(
  540. 'title' => t('Install Chado'),
  541. 'description' => t('Allow the user to install or upgrade a Chado database in the existing Drupal database.')
  542. ),
  543. 'view chado_ids' => array(
  544. 'title' => t('View Internal IDs'),
  545. 'description' => t('On content pages Tripal will typically provide
  546. a table of information pulled from the Chado database but the
  547. primary key IDs for that data is typically not shown. The
  548. default Tripal templates can show the primary key ID inside of a
  549. blue shaded table row if this permission is enabled. This can
  550. be useful for site developers who might want these IDs when working
  551. with the underlying database.'),
  552. 'restrict access' => TRUE,
  553. )
  554. );
  555. }
  556. /**
  557. * Implements hook_theme().
  558. */
  559. function tripal_chado_theme($existing, $type, $theme, $path) {
  560. $themes = array(
  561. // Theme fields.
  562. 'data__accession_widget' => array(
  563. 'render element' => 'element',
  564. 'file' => 'includes/TripalFields/data__accession/data__accession_widget.inc',
  565. ),
  566. // 'chado_linker__dbxref_widget' => array(
  567. // 'render element' => 'element',
  568. // 'file' => 'includes/TripalFields/chado_linker__dbxref.inc',
  569. // ),
  570. // 'chado_linker__cvterm_widget' => array(
  571. // 'render element' => 'element',
  572. // 'file' => 'includes/TripalFields/chado_linker__cvterm.inc',
  573. // ),
  574. // 'chado_linker__synonym_widget' => array(
  575. // 'render element' => 'element',
  576. // 'file' => 'includes/TripalFields/chado_linker__synonym.inc',
  577. // ),
  578. // 'chado_linker__relationship_widget' => array(
  579. // 'render element' => 'element',
  580. // 'file' => 'includes/TripalFields/chado_linker__relationship.inc',
  581. // ),
  582. // 'chado_linker__relationship_instance_settings' => array(
  583. // 'render element' => 'element',
  584. // 'file' => 'includes/TripalFields/chado_linker__relationship.inc',
  585. // ),
  586. // 'chado_linker__pub_widget' => array(
  587. // 'render element' => 'element',
  588. // 'file' => 'includes/TripalFields/chado_linker__pub.inc',
  589. // ),
  590. // 'chado_linker__contact_widget' => array(
  591. // 'render element' => 'element',
  592. // 'file' => 'includes/TripalFields/chado_linker__contact.inc',
  593. // ),
  594. // 'chado_linker__prop_adder_widget' => array(
  595. // 'render element' => 'element',
  596. // 'file' => 'includes/TripalFields/chado_linker__prop_adder.inc',
  597. // ),
  598. 'tripal_chado_date_combo' => array(
  599. 'render element' => 'element',
  600. 'file' => 'theme/tripal_chado.theme.inc',
  601. ),
  602. // Themed forms
  603. 'tripal_pub_importer_setup_form_elements' => array(
  604. 'render element' => 'form',
  605. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  606. ),
  607. 'tripal_pub_search_setup_form_elements' => array(
  608. 'render element' => 'form',
  609. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  610. ),
  611. );
  612. // Override the theme for each entity to use the legacy modules
  613. // templates.
  614. if (module_exists('tripal_core')) {
  615. $core_path = drupal_get_path('module', 'tripal_core');
  616. // Get the list of node types that have legacy templates.
  617. $enabled_templates = variable_get('tripal_chado_enabled_legacy_templates', array());
  618. // Get the list of TripalEntity bundle.
  619. $bundles = db_select('tripal_bundle', 'tb')
  620. ->fields('tb')
  621. ->execute();
  622. // Iterate through all of the TripalEntity bundles and see which ones
  623. // map to tables that used had Tripal v2 nodes. For those, if the
  624. // legacy support is turned on then we want to use the legacy template.
  625. while ($bundle = $bundles->fetchObject()) {
  626. $term = tripal_load_term_entity(array('term_id' => $bundle->term_id));
  627. $vocab = $term->vocab;
  628. $params = array(
  629. 'vocabulary' => $vocab->vocabulary,
  630. 'accession' => $term->accession,
  631. );
  632. $mapped_table = chado_get_cvterm_mapping($params);
  633. $chado_table = $mapped_table->chado_table;
  634. $legacy_template = 'legacy_template--chado_' . $chado_table;
  635. if (key_exists($legacy_template, $enabled_templates) && $enabled_templates[$legacy_template]) {
  636. $themes['TripalEntity__' . $bundle->name] = array(
  637. 'template' => 'node--chado-generic',
  638. 'render element' => 'entity',
  639. 'base hook' => 'entity',
  640. 'path' => "$core_path/theme/templates",
  641. );
  642. }
  643. }
  644. }
  645. return $themes;
  646. }
  647. /**
  648. * Implements hook_preprocess().
  649. *
  650. * This function is used to support legacy Tripal v2 templates
  651. * for use with Tripal v3 entities.
  652. */
  653. function tripal_chado_preprocess(&$variables, $hook) {
  654. if ($hook == 'entity' and array_key_exists('TripalEntity', $variables)) {
  655. // The node--chado-generic template expets there to be a
  656. // teaser and node variables. So, we'll add them.
  657. $variables['teaser'] = FALSE;
  658. $variables['node'] = $variables['TripalEntity'];
  659. }
  660. }
  661. /**
  662. * Implements hook_exclude_type_by_default()
  663. *
  664. * This hooks allows fields of a specified type that match a specified criteria
  665. * to be excluded by default from any table when chado_generate_var() is called.
  666. * Keep in mind that if fields are excluded by default they can always be
  667. * expanded at a later date using chado_expand_var().
  668. *
  669. * Criteria are php strings that evaluate to either TRUE or FALSE. These
  670. * strings are evaluated using drupal_eval() which suppresses syntax errors and
  671. * throws watchdog entries of type php. There are also watchdog entries of type
  672. * tripal stating the exact criteria evaluated. Criteria can
  673. * contain the following tokens:
  674. * - <field_name>
  675. * Replaced by the name of the field to be excluded
  676. * - <field_value>
  677. * Replaced by the value of the field in the current record
  678. * Also keep in mind that if your criteria doesn't contain the
  679. * &gt;field_value&lt; token then it will be evaluated before the query is
  680. * executed and if the field is excluded it won't be included in the
  681. * query.
  682. *
  683. * @return
  684. * An array of type => criteria where the type is excluded if the criteria
  685. * evaluates to TRUE
  686. *
  687. * @ingroup tripal
  688. */
  689. function tripal_chado_exclude_type_by_default() {
  690. return array('text' => 'strlen("<field_value> ") > 250');
  691. }
  692. /**
  693. * Implements hook_job_describe_args().
  694. *
  695. * Describes the arguements for the tripal_populate_mview job to allow for
  696. * greater readability in the jobs details pages.
  697. *
  698. * @param $callback
  699. * The callback of the current tripal job (this is the function that will be
  700. * executed when tripal_launch_jobs.php is run.
  701. * @param $args
  702. * An array of arguments passed in when the job was registered.
  703. *
  704. * @return
  705. * A more readable $args array
  706. *
  707. * @ingroup tripal
  708. */
  709. function tripal_chado_job_describe_args($callback, $args) {
  710. $new_args = array();
  711. if ($callback == 'tripal_populate_mview') {
  712. // get this mview details
  713. $sql = "SELECT * FROM {tripal_mviews} WHERE mview_id = :mview_id ";
  714. $results = db_query($sql, array(':mview_id' => $args[0]));
  715. $mview = $results->fetchObject();
  716. $new_args['View Name'] = $mview->name;
  717. }
  718. elseif ($callback == 'tripal_install_chado') {
  719. $new_args['Action'] = $args[0];
  720. }
  721. return $new_args;
  722. }
  723. /**
  724. * Remove the nid from chado_entity if it exists when the node is deleted
  725. */
  726. function tripal_chado_node_delete($node) {
  727. $nid = $node->nid;
  728. $sql = "UPDATE chado_entity SET nid = NULL WHERE nid = :nid";
  729. db_query($sql, array('nid' => $nid));
  730. }
  731. /**
  732. *
  733. * Implements hook_form_FORM_ID_alter().
  734. *
  735. * The field_ui_field_edit_form is used for customizing the settings of
  736. * a field attached to an entity.
  737. *
  738. * This alter function disables some of the form widgets when the storage
  739. * backend indicates they are not appropriate.
  740. */
  741. function tripal_chado_form_field_ui_field_edit_form_alter(&$form, &$form_state, $form_id) {
  742. // For entity fields added by Tripal Entities we don't want the
  743. // the end-user to change the cardinality and the required fields
  744. // such that record can't be saved in Chado.
  745. // TODO: we shouldn't check for specific field types here
  746. // (e.g. chaod_linker_prop). That should be done via the TripalField
  747. // functions.
  748. if ($form['#instance']['entity_type'] == 'TripalEntity') {
  749. if ($form['#field']['storage']['type'] == 'field_chado_storage' and
  750. $form['#field']['type'] != 'chado_linker__prop') {
  751. $form['field']['cardinality']['#access'] = FALSE;
  752. $form['instance']['required']['#access'] = FALSE;
  753. }
  754. }
  755. // TODO: don't the the maximum length be larger than the field size.
  756. }
  757. /**
  758. * Implements hook_form_alter().
  759. */
  760. function tripal_chado_form_alter(&$form, $form_state, $form_id) {
  761. // If this is the field_ui_field_edit_form (i.e. the form that appears
  762. // when editing a field that is attached to an entity). Then we want
  763. // to add term settings for any field attached to a TripalEntity
  764. // content type.
  765. if ($form_id == 'field_ui_field_edit_form' and $form['#instance']['entity_type'] == 'TripalEntity') {
  766. tripal_chado_field_instance_settings_form_alter($form, $form_state);
  767. }
  768. }