tripal_analysis.module 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735
  1. <?php
  2. /**
  3. * @file
  4. * Contains all the main hook implementations for the tripal_analysis module
  5. *
  6. * @defgroup tripal_analysis Analysis Module
  7. * @{
  8. * Provides functions for managing chado analysis' including creating details pages for each one
  9. * @}
  10. * @ingroup tripal_modules
  11. */
  12. require('api/tripal_analysis.api.inc');
  13. require('includes/tripal_analysis_privacy.inc');
  14. /**
  15. * Add tripal javascript to page headers
  16. *
  17. * @ingroup tripal_analysis
  18. */
  19. function tripal_analysis_init() {
  20. drupal_add_js(drupal_get_path('theme', 'tripal') . '/js/tripal_analysis.js');
  21. }
  22. /**
  23. * Implementation of hook_menu().
  24. * Entry points and paths of the module
  25. *
  26. * @ingroup tripal_analysis
  27. */
  28. function tripal_analysis_menu() {
  29. //Sync analysis
  30. $items['chado_sync_analyses'] = array(
  31. 'title' => 'Sync Data',
  32. 'page callback' => 'tripal_analysis_sync_analyses',
  33. 'access arguments' => array('administer tripal analyses'),
  34. 'type' => MENU_CALLBACK
  35. );
  36. // Tripal Analysis administrative settings
  37. $items['admin/tripal/tripal_analysis'] = array(
  38. 'title' => 'Analyses',
  39. 'description' => 'Basic Description of Tripal Analysis Module Functionality.',
  40. 'page callback' => 'theme',
  41. 'page arguments' => array('tripal_analysis_admin'),
  42. 'access arguments' => array('administer tripal analyses'),
  43. 'type' => MENU_NORMAL_ITEM,
  44. 'file' => 'includes/tripal_analysis.admin.inc',
  45. );
  46. $items['admin/tripal/tripal_analysis/configuration'] = array(
  47. 'title' => 'Configuration',
  48. 'description' => 'Settings for the displays of analysis results.',
  49. 'page callback' => 'drupal_get_form',
  50. 'page arguments' => array('tripal_analysis_admin'),
  51. 'access arguments' => array('administer tripal analyses'),
  52. 'type' => MENU_NORMAL_ITEM,
  53. 'file' => 'includes/tripal_analysis.admin.inc',
  54. );
  55. return $items;
  56. }
  57. /**
  58. * Provide information to drupal about the node types that we're creating
  59. * in this module
  60. *
  61. * @ingroup tripal_analysis
  62. */
  63. function tripal_analysis_node_info() {
  64. $nodes = array();
  65. $nodes['chado_analysis'] = array(
  66. 'name' => t('Analysis'),
  67. 'module' => 'chado_analysis',
  68. 'description' => t('An analysis from the chado database'),
  69. 'has_title' => FALSE,
  70. 'title_label' => t('Analysis'),
  71. 'has_body' => FALSE,
  72. 'body_label' => t('Analysis Description'),
  73. 'locked' => TRUE
  74. );
  75. return $nodes;
  76. }
  77. /**
  78. * When a new chado_analysis node is created we also need to add information
  79. * to our chado_analysis table. This function is called on insert of a new
  80. * node of type 'chado_analysis' and inserts the necessary information.
  81. *
  82. * @ingroup tripal_analysis
  83. */
  84. function chado_analysis_insert($node) {
  85. global $user;
  86. // Create a timestamp so we can insert it into the chado database
  87. $time = $node->timeexecuted;
  88. $month = $time['month'];
  89. $day = $time['day'];
  90. $year = $time['year'];
  91. $timestamp = $month . '/' . $day . '/' . $year;
  92. // If this analysis already exists then don't recreate it in chado
  93. $analysis_id = $node->analysis_id;
  94. if ($analysis_id) {
  95. $values = array('analysis_id' => $node->analysis_id);
  96. $result = tripal_core_chado_select('analysis', array('analysis_id'), $values);
  97. if($result and count($result) > 0) {
  98. $analysis = $result[0];
  99. }
  100. }
  101. // If the analysis doesn't exist then let's create it in chado.
  102. if (!$analysis) {
  103. // insert and then get the newly inserted analysis record
  104. $values = array(
  105. 'name' => $node->analysisname,
  106. 'description' => $node->description,
  107. 'program' => $node->program,
  108. 'programversion' => $node->programversion,
  109. 'algorithm' => $node->algorithm,
  110. 'sourcename' => $node->sourcename,
  111. 'sourceversion' => $node->sourceversion,
  112. 'sourceuri' => $node->sourceuri,
  113. 'timeexecuted' => $timestamp
  114. );
  115. if (tripal_core_chado_insert('analysis', $values)) {
  116. $analysis = tripal_core_chado_select('analysis', array('*'), $values);
  117. $analysis_id = $analysis[0]->analysis_id;
  118. }
  119. }
  120. // Make sure the entry for this analysis doesn't already exist in the
  121. // chado_analysis table if it doesn't exist then we want to add it.
  122. $node_check_sql = "SELECT * FROM {chado_analysis} ".
  123. "WHERE analysis_id = %d";
  124. $node_check = db_fetch_object(db_query($node_check_sql, $analysis_id));
  125. if (!$node_check) {
  126. // next add the item to the drupal table
  127. $sql = "INSERT INTO {chado_analysis} (nid, vid, analysis_id) ".
  128. "VALUES (%d, %d, %d)";
  129. db_query($sql, $node->nid, $node->vid, $analysis_id);
  130. // Create a title for the analysis node using the unique keys so when the
  131. // node is saved, it will have a title
  132. $record = new stdClass();
  133. // If the analysis has a name, use it as the node title. If not, construct
  134. // the title using program, programversion, and sourcename
  135. if ($node->analysisname) {
  136. $record->title = $node->analysisname;
  137. }
  138. else {
  139. //Construct node title as "program (version)
  140. $record->title = "$node->program ($node->programversion)";
  141. }
  142. $record->nid = $node->nid;
  143. drupal_write_record('node', $record, 'nid');
  144. drupal_write_record('node_revisions', $record, 'nid');
  145. }
  146. // add the analysis to the node object for
  147. // use by other analysis modules that may be using this function
  148. $node->analysis = $analysis;
  149. $node->analysis_id = $analysis_id; // we need to set this for children
  150. }
  151. /**
  152. * Removes analysis from the chado database
  153. *
  154. * @param $node
  155. * The node object specifying which chado record to delete
  156. *
  157. * @ingroup tripal_analysis
  158. */
  159. function chado_analysis_delete($node) {
  160. $analysis_id = chado_get_id_for_node('analysis', $node);
  161. // if we don't have an organism id for this node then this isn't a node of
  162. // type chado_organism or the entry in the chado_organism table was lost.
  163. if (!$analysis_id) {
  164. return;
  165. }
  166. // Remove data from the {chado_analysis}, {node}, and {node_revisions} tables
  167. $sql_del = "DELETE FROM {chado_analysis} ".
  168. "WHERE nid = %d ".
  169. "AND vid = %d";
  170. db_query($sql_del, $node->nid, $node->vid);
  171. $sql_del = "DELETE FROM {node} ".
  172. "WHERE nid = %d ".
  173. "AND vid = %d";
  174. db_query($sql_del, $node->nid, $node->vid);
  175. $sql_del = "DELETE FROM {node_revisions} ".
  176. "WHERE nid = %d ".
  177. "AND vid = %d";
  178. db_query($sql_del, $node->nid, $node->vid);
  179. //Remove from analysis and analysisprop tables of chado database as well
  180. chado_query("DELETE FROM {analysis} WHERE analysis_id = %d", $analysis_id);
  181. }
  182. /**
  183. * Update analyses
  184. *
  185. * @param $node
  186. * The updated node object
  187. *
  188. * @ingroup tripal_analysis
  189. */
  190. function chado_analysis_update($node) {
  191. global $user;
  192. if ($node->revision) {
  193. // TODO -- decide what to do about revisions
  194. }
  195. // Create a timestamp so we can insert it into the chado database
  196. $time = $node->timeexecuted;
  197. $month = $time['month'];
  198. $day = $time['day'];
  199. $year = $time['year'];
  200. $timestamp = $month . '/' . $day . '/' . $year;
  201. // get the analysis_id for this node:
  202. $sql = "SELECT analysis_id ".
  203. "FROM {chado_analysis} ".
  204. "WHERE nid = %d";
  205. $analysis_id = db_fetch_object(db_query($sql, $node->nid))->analysis_id;
  206. $sql = "UPDATE {analysis} ".
  207. "SET name = '%s', ".
  208. " description = '%s', ".
  209. " program = '%s', ".
  210. " programversion = '%s', ".
  211. " algorithm = '%s', ".
  212. " sourcename = '%s', ".
  213. " sourceversion = '%s', ".
  214. " sourceuri = '%s', ".
  215. " timeexecuted = '%s' ".
  216. "WHERE analysis_id = %d ";
  217. chado_query($sql, $node->analysisname, $node->description, $node->program,
  218. $node->programversion, $node->algorithm, $node->sourcename,
  219. $node->sourceversion, $node->sourceuri, $timestamp, $analysis_id);
  220. // Create a title for the analysis node using the unique keys so when the
  221. // node is saved, it will have a title
  222. $record = new stdClass();
  223. // If the analysis has a name, use it as the node title. If not, construct
  224. // the title using program, programversion, and sourcename
  225. if ($node->analysisname) {
  226. $record->title = $node->analysisname;
  227. }
  228. else {
  229. //Construct node title as "program (version)
  230. $record->title = "$node->program ($node->programversion)";
  231. }
  232. $record->nid = $node->nid;
  233. drupal_write_record('node', $record, 'nid');
  234. drupal_write_record('node_revisions', $record, 'nid');
  235. }
  236. /**
  237. * When editing or creating a new node of type 'chado_analysis' we need
  238. * a form. This function creates the form that will be used for this.
  239. *
  240. * @ingroup tripal_analysis
  241. */
  242. function chado_analysis_form($node) {
  243. $analysis = $node->analysis;
  244. // add in the description column. It is a text field and may not be included
  245. // if the text is too big.
  246. $analysis = tripal_core_expand_chado_vars($analysis, 'field', 'analysis.description');
  247. // get form defaults
  248. $analysis_id = $node->analysis_id;
  249. if (!$analysis_id) {
  250. $analysis_id = $analysis->analysis_id;
  251. }
  252. $analysisname = $node->analysisname;
  253. if (!$analysisname) {
  254. $analysisname = $analysis->name;
  255. }
  256. $program = $node->program;
  257. if (!$program) {
  258. $program = $analysis->program;
  259. }
  260. $programversion = $node->programversion;
  261. if (!$programversion) {
  262. $programversion = $analysis->programversion;
  263. }
  264. $algorithm = $node->algorithm;
  265. if (!$algorithm) {
  266. $algorithm = $analysis->algorithm;
  267. }
  268. $sourcename = $node->sourcename;
  269. if (!$sourcename) {
  270. $sourcename = $analysis->sourcename;
  271. }
  272. $sourceversion = $node->sourceversion;
  273. if (!$sourceversion) {
  274. $sourceversion = $analysis->sourceversion;
  275. }
  276. $sourceuri = $node->sourceuri;
  277. if (!$sourceuri) {
  278. $sourceuri = $analysis->sourceuri;
  279. }
  280. $timeexecuted = $node->timeexecuted;
  281. if (!$timeexecuted) {
  282. $timeexecuted = $analysis->timeexecuted;
  283. }
  284. $description = $node->description;
  285. if (!$description) {
  286. $description = $analysis->description;
  287. }
  288. $form = array();
  289. $form['title']= array(
  290. '#type' => 'hidden',
  291. '#default_value' => $node->title,
  292. );
  293. $form['analysis_id']= array(
  294. '#type' => 'hidden',
  295. '#default_value' => $analysis_id,
  296. );
  297. $form['analysisname']= array(
  298. '#type' => 'textfield',
  299. '#title' => t('Analysis Name'),
  300. '#required' => TRUE,
  301. '#default_value' => $analysisname,
  302. '#description' => t("This should be a brief name that
  303. describes the analysis succintly. This name will helps the user find analyses."),
  304. );
  305. $form['program']= array(
  306. '#type' => 'textfield',
  307. '#title' => t('Program'),
  308. '#required' => TRUE,
  309. '#default_value' => $program,
  310. '#description' => t("Program name, e.g. blastx, blastp, sim4, genscan."),
  311. );
  312. $form['programversion']= array(
  313. '#type' => 'textfield',
  314. '#title' => t('Program Version'),
  315. '#required' => TRUE,
  316. '#default_value' => $programversion,
  317. '#description' => t("Version description, e.g. TBLASTX 2.0MP-WashU [09-Nov-2000]. Enter 'n/a' if no version is available."),
  318. );
  319. $form['algorithm']= array(
  320. '#type' => 'textfield',
  321. '#title' => t('Algorithm'),
  322. '#required' => FALSE,
  323. '#default_value' => $algorithm,
  324. '#description' => t("Algorithm name, e.g. blast."),
  325. );
  326. $form['sourcename']= array(
  327. '#type' => 'textfield',
  328. '#title' => t('Source Name'),
  329. '#required' => TRUE,
  330. '#default_value' => $sourcename,
  331. '#description' => t('The name of the source data. This could be a file name, data set name or a
  332. small description for how the data was collected. For long descriptions use the description field below'),
  333. );
  334. $form['sourceversion']= array(
  335. '#type' => 'textfield',
  336. '#title' => t('Source Version'),
  337. '#required' => FALSE,
  338. '#default_value' => $sourceversion,
  339. '#description' => t('If the source dataset has a version, include it here'),
  340. );
  341. $form['sourceuri']= array(
  342. '#type' => 'textfield',
  343. '#title' => t('Source URI'),
  344. '#required' => FALSE,
  345. '#default_value' => $sourceuri,
  346. '#description' => t("This is a permanent URL or URI for the source of the analysis.
  347. Someone could recreate the analysis directly by going to this URI and
  348. fetching the source data (e.g. the blast database, or the training model)."),
  349. );
  350. // Get time saved in chado
  351. $default_time = $timeexecuted;
  352. $year = preg_replace("/^(\d+)-\d+-\d+ .*/", "$1", $default_time);
  353. $month = preg_replace("/^\d+-0?(\d+)-\d+ .*/", "$1", $default_time);
  354. $day = preg_replace("/^\d+-\d+-0?(\d+) .*/", "$1", $default_time);
  355. // If the time is not set, use current time
  356. if (!$default_time) {
  357. $default_time = time();
  358. $year = format_date($default_time, 'custom', 'Y');
  359. $month = format_date($default_time, 'custom', 'n');
  360. $day = format_date($default_time, 'custom', 'j');
  361. }
  362. $form['timeexecuted']= array(
  363. '#type' => 'date',
  364. '#title' => t('Time Executed'),
  365. '#required' => TRUE,
  366. '#default_value' => array(
  367. 'year' => $year,
  368. 'month' => $month,
  369. 'day' => $day,
  370. ),
  371. );
  372. $form['description']= array(
  373. '#type' => 'textarea',
  374. '#rows' => 15,
  375. '#title' => t('Materials & Methods (Description and/or Program Settings)'),
  376. '#required' => FALSE,
  377. '#default_value' => $description,
  378. '#description' => t('Please provide all necessary information to allow
  379. someone to recreate the analysis, including materials and methods
  380. for collection of the source data and performing the analysis'),
  381. );
  382. return $form;
  383. }
  384. /**
  385. * When a node is requested by the user this function is called to allow us
  386. * to add auxiliary data to the node object.
  387. *
  388. * @ingroup tripal_analysis
  389. */
  390. function chado_analysis_load($node) {
  391. // get the feature details from chado
  392. $analysis_id = chado_get_id_for_node('analysis', $node);
  393. $values = array('analysis_id' => $analysis_id);
  394. $analysis = tripal_core_generate_chado_var('analysis', $values);
  395. $additions = new stdClass();
  396. $additions->analysis = $analysis;
  397. return $additions;
  398. }
  399. /**
  400. * This function customizes the view of the chado_analysis node. It allows
  401. * us to generate the markup.
  402. *
  403. * @ingroup tripal_analysis
  404. */
  405. function chado_analysis_view($node, $teaser = FALSE, $page = FALSE) {
  406. // use drupal's default node view:
  407. if (!$teaser) {
  408. $node = node_prepare($node, $teaser);
  409. // When previewing a node submitting form, it shows 'Array' instead of
  410. // correct date format. We need to format the date here
  411. $time = $node->timeexecuted;
  412. if (is_array($time)) {
  413. $month = $time['month'];
  414. $day = $time['day'];
  415. $year = $time['year'];
  416. $timestamp = $year . '-' . $month . '-' . $day;
  417. $node->timeexecuted = $timestamp;
  418. }
  419. }
  420. return $node;
  421. }
  422. /**
  423. * Validates the user input before creating an analysis node
  424. *
  425. * @ingroup tripal_analysis
  426. */
  427. function chado_analysis_validate($node, &$form) {
  428. // use the analysis parent to validate the node
  429. tripal_analysis_validate($node, $form);
  430. }
  431. /**
  432. * This validation is being used for three activities:
  433. * CASE A: Update a node that exists in both drupal and chado
  434. * CASE B: Synchronizing a node from chado to drupal
  435. * CASE C: Inserting a new node that exists in niether drupal nor chado
  436. *
  437. * @ingroup tripal_analysis
  438. */
  439. function tripal_analysis_validate($node, &$form) {
  440. // Only nodes being updated will have an nid already
  441. if (!is_null($node->nid)) {
  442. // CASE A: We are validating a form for updating an existing node
  443. // get the existing node
  444. $values = array('analysis_id' => $node->analysis_id);
  445. $result = tripal_core_chado_select('analysis', array('*'), $values);
  446. $analysis = $result[0];
  447. // if the name has changed make sure it doesn't conflict with an existing name
  448. if($analysis->name != $node->analysisname) {
  449. $values = array('name' => $node->analysisname);
  450. $result = tripal_core_chado_select('analysis', array('analysis_id'), $values);
  451. if($result and count($result) > 0) {
  452. form_set_error('analysisname', 'Cannot update the analysis with this analysis name. An analysis with this name already exists.');
  453. return;
  454. }
  455. }
  456. // if the unique constraint has changed check to make sure it doesn't conflict with an
  457. // existing record
  458. if($analysis->program != $node->program or $analysis->programversion != $node->programversion or
  459. $analysis->sourcename != $node->sourcename) {
  460. $values = array(
  461. 'program' => $node->program,
  462. 'programversion' => $node->programversion,
  463. 'sourcename' => $node->sourcename,
  464. );
  465. $result = tripal_core_chado_select('analysis', array('analysis_id'), $values);
  466. if ($result and count($result) > 0) {
  467. if ($analysis->program != $node->program) {
  468. $field = 'program';
  469. }
  470. if ($analysis->programversion != $node->programversion) {
  471. $field = 'programversion';
  472. }
  473. if ($analysis->sourcename != $node->sourcename) {
  474. $field = 'sourcename';
  475. }
  476. form_set_error($field, 'Cannot update the analysis with this program,
  477. program version and source name. An analysis with these values already exists.');
  478. return;
  479. }
  480. }
  481. }
  482. else{
  483. // To differentiate if we are syncing or creating a new analysis altogther, see if an
  484. // analysis_id already exists
  485. if ($node->analysis_id and $node->analysis_id != 0) {
  486. // CASE B: Synchronizing a node from chado to drupal
  487. // we don't need to do anything.
  488. }
  489. else {
  490. // CASE C: We are validating a form for inserting a new node
  491. // The unique constraint for the chado analysis table is: program, programversion, sourcename
  492. $values = array(
  493. 'program' => $node->program,
  494. 'programversion' => $node->programversion,
  495. 'sourcename' => $node->sourcename,
  496. );
  497. $analysis = tripal_core_chado_select('analysis', array('analysis_id'), $values);
  498. if ($analysis and count($analysis) > 0) {
  499. form_set_error('program', 'Cannot add the analysis with this program,
  500. program version and source name. An analysis with these values already exists.');
  501. return;
  502. }
  503. // make sure we have a unique analysis name. This is not a requirement
  504. // for the analysis table but we use the analysis name for the Drupal node
  505. // title, so it should be unique
  506. $values = array('name' => $node->analysisname);
  507. $result = tripal_core_chado_select('analysis', array('analysis_id'), $values);
  508. if($result and count($result) > 0) {
  509. form_set_error('analysisname', 'Cannot add the analysis with this analysis name. An analysis with this name already exists.');
  510. return;
  511. }
  512. }
  513. }
  514. }
  515. /**
  516. * Display help and module information
  517. * @param path which path of the site we're displaying help
  518. * @param arg array that holds the current path as would be returned from arg()
  519. * function
  520. * @return help text for the path
  521. *
  522. * @ingroup tripal_analysis
  523. */
  524. function tripal_analysis_help($path, $arg) {
  525. $output = '';
  526. switch ($path) {
  527. case "admin/help#tripal_analysis":
  528. $output = '<p>' .
  529. t("Displays links to nodes created on this date") .
  530. '</p>';
  531. break;
  532. }
  533. return $output;
  534. }
  535. /**
  536. * The following function proves access control for users trying to
  537. * perform actions on data managed by this module
  538. *
  539. * @ingroup tripal_analysis
  540. */
  541. function chado_analysis_access($op, $node, $account) {
  542. if ($op == 'create') {
  543. if (!user_access('create chado_analysis content', $account)) {
  544. return FALSE;
  545. }
  546. }
  547. if ($op == 'update') {
  548. if (!user_access('edit chado_analysis content', $account)) {
  549. return FALSE;
  550. }
  551. }
  552. if ($op == 'delete') {
  553. if (!user_access('delete chado_analysis content', $account)) {
  554. return FALSE;
  555. }
  556. }
  557. if ($op == 'view') {
  558. if (!user_access('access chado_analysis content', $account)) {
  559. return FALSE;
  560. }
  561. }
  562. return NULL;
  563. }
  564. /**
  565. * Set the permission types that the chado module uses. Essentially we
  566. * want permissionis that protect creation, editing and deleting of chado
  567. * data objects
  568. *
  569. * @ingroup tripal_analysis
  570. */
  571. function tripal_analysis_perm() {
  572. return array(
  573. 'access chado_analysis content',
  574. 'create chado_analysis content',
  575. 'delete chado_analysis content',
  576. 'edit chado_analysis content',
  577. 'administer tripal analyses',
  578. );
  579. }
  580. /**
  581. * We need to let drupal know about our theme functions and their arguments.
  582. * We create theme functions to allow users of the module to customize the
  583. * look and feel of the output generated in this module
  584. *
  585. * @ingroup tripal_analysis
  586. */
  587. function tripal_analysis_theme() {
  588. return array(
  589. 'tripal_analysis_base' => array(
  590. 'arguments' => array('node' => NULL),
  591. 'template' => 'tripal_analysis_base',
  592. ),
  593. 'tripal_feature_analyses' => array(
  594. 'template' => 'tripal_feature_analyses',
  595. 'arguments' => array('node' => NULL),
  596. ),
  597. 'tripal_analysis_admin' => array(
  598. 'template' => 'tripal_analysis_admin',
  599. 'arguments' => array(NULL),
  600. 'path' => drupal_get_path('module', 'tripal_analysis') . '/theme',
  601. ),
  602. );
  603. }
  604. /**
  605. *
  606. *
  607. * @ingroup tripal_feature
  608. */
  609. function tripal_analysis_block($op = 'list', $delta = 0, $edit=array()) {
  610. switch ($op) {
  611. case 'list':
  612. $blocks['base']['info'] = t('Tripal Analysis Details');
  613. $blocks['base']['cache'] = BLOCK_NO_CACHE;
  614. $blocks['featureblast']['info'] = t('Tripal Feature Analyses');
  615. $blocks['featureblast']['cache'] = BLOCK_NO_CACHE;
  616. return $blocks;
  617. case 'view':
  618. if (user_access('access chado_analysis content') and arg(0) == 'node' and is_numeric(arg(1))) {
  619. $nid = arg(1);
  620. $node = node_load($nid);
  621. $block = array();
  622. switch ($delta) {
  623. case 'base':
  624. $block['subject'] = t('Analysis Details');
  625. $block['content'] = theme('tripal_analysis_base', $node);
  626. break;
  627. case 'tripal_feature_analyses':
  628. $block['subject'] = t('Feature Analyses');
  629. $block['content'] = theme('tripal_feature_analyses', $node);
  630. break;
  631. default :
  632. }
  633. return $block;
  634. }
  635. }
  636. }
  637. /*******************************************************************************
  638. * tripal_analysis_nodeapi()
  639. * HOOK: Implementation of hook_nodeapi()
  640. * Display blast results for allowed node types
  641. */
  642. function tripal_analysis_nodeapi(&$node, $op, $teaser, $page) {
  643. switch ($op) {
  644. case 'view':
  645. if ($teaser) {
  646. return '';
  647. }
  648. // Abort if this node is not one of the types we should show.
  649. if (strcmp($node->type, 'chado_feature') == 0) {
  650. if ($node->build_mode == NODE_BUILD_SEARCH_INDEX) {
  651. // return results for searching
  652. }
  653. else {
  654. // return normal results
  655. $node->content['tripal_feature_analyses'] = array(
  656. '#value' => theme('tripal_feature_analyses', $node),
  657. '#weight' => 8
  658. );
  659. }
  660. }
  661. break;
  662. }
  663. }
  664. /**
  665. * Implements hook_views_api()
  666. * Purpose: Essentially this hook tells drupal that there is views support for
  667. * for this module which then includes tripal_analysis.views.inc where all the
  668. * views integration code is
  669. *
  670. * @ingroup tripal_analysis
  671. */
  672. function tripal_analysis_views_api() {
  673. return array(
  674. 'api' => 2.0,
  675. );
  676. }