tripal_chado.module 33 KB

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