tripal_feature.module 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182
  1. <?php
  2. /**
  3. * @file
  4. * @todo Add file header description
  5. */
  6. /**
  7. * @defgroup tripal_feature Feature Module
  8. * @ingroup tripal_modules
  9. * @{
  10. * Provides functions for managing chado features including creating details pages for each feature
  11. * @}
  12. */
  13. require_once "api/tripal_feature.api.inc";
  14. require_once "api/tripal_feature.schema.api.inc";
  15. require_once "theme/tripal_feature.theme.inc";
  16. require_once "includes/tripal_feature.admin.inc";
  17. require_once "includes/tripal_feature.sync_features.inc";
  18. require_once "includes/tripal_feature.fasta_loader.inc";
  19. require_once "includes/tripal_feature.gff_loader.inc";
  20. require_once "includes/tripal_feature.seq_extract.inc";
  21. require_once "includes/tripal_feature.delete.inc";
  22. require_once "includes/tripal_feature.chado_node.inc";
  23. require_once "includes/tripal_feature.blocks.inc";
  24. /**
  25. *
  26. * @ingroup tripal_feature
  27. */
  28. function tripal_feature_init() {
  29. drupal_add_css(drupal_get_path('module', 'tripal_feature') . '/theme/css/tripal_feature.css');
  30. drupal_add_js(drupal_get_path('module', 'tripal_feature') . '/theme/js/tripal_feature.js');
  31. }
  32. /**
  33. * Implements hook_views_api()
  34. *
  35. * Purpose: Essentially this hook tells drupal that there is views support for
  36. * for this module which then includes tripal_db.views.inc where all the
  37. * views integration code is
  38. *
  39. * @ingroup tripal_feature
  40. */
  41. function tripal_feature_views_api() {
  42. return array(
  43. 'api' => 2.0,
  44. );
  45. }
  46. /**
  47. * Display help and module information
  48. *
  49. * @param
  50. * path which path of the site we're displaying help
  51. * @param
  52. * arg array that holds the current path as would be returned from arg() function
  53. *
  54. * @return
  55. * help text for the path
  56. *
  57. * @ingroup tripal_feature
  58. */
  59. function tripal_feature_help($path, $arg) {
  60. $output = '';
  61. switch ($path) {
  62. case "admin/help#tripal_feature":
  63. $output='<p>' . t("Displays links to nodes created on this date") . '</p>';
  64. break;
  65. }
  66. return $output;
  67. }
  68. /**
  69. * Set the permission types that the chado module uses. Essentially we
  70. * want permissionis that protect creation, editing and deleting of chado
  71. * data objects
  72. *
  73. * @ingroup tripal_feature
  74. */
  75. function tripal_feature_permissions() {
  76. return array(
  77. 'access chado_feature content' => array(
  78. 'title' => t('View Features'),
  79. 'description' => t('Allow users to view feature pages.'),
  80. ),
  81. 'create chado_feature content' => array(
  82. 'title' => t('Create Features'),
  83. 'description' => t('Allow users to create new feature pages.'),
  84. ),
  85. 'delete chado_feature content' => array(
  86. 'title' => t('Delete Features'),
  87. 'description' => t('Allow users to delete feature pages.'),
  88. ),
  89. 'edit chado_feature content' => array(
  90. 'title' => t('Edit Features'),
  91. 'description' => t('Allow users to edit feature pages.'),
  92. ),
  93. 'adminster tripal feature' => array(
  94. 'title' => t('Administer Features'),
  95. 'description' => t('Allow users to administer all features.'),
  96. ),
  97. );
  98. }
  99. /**
  100. * Menu items are automatically added for the new node types created
  101. * by this module to the 'Create Content' Navigation menu item. This function
  102. * adds more menu items needed for this module.
  103. *
  104. * @ingroup tripal_feature
  105. */
  106. function tripal_feature_menu() {
  107. $items = array();
  108. // the administative settings menu
  109. $items['find/sequences'] = array(
  110. 'title' => 'Sequence Retrieval',
  111. 'description' => 'Download a file of sequences',
  112. 'page callback' => 'tripal_feature_seq_extract_page',
  113. 'access arguments' => array('access chado_feature content'),
  114. 'type' => MENU_CALLBACK,
  115. );
  116. $items['find/sequences/ajax'] = array(
  117. 'title' => 'Sequence Retrieval',
  118. 'page callback' => 'tripal_feature_seq_extract_form_ahah_update',
  119. 'access arguments' => array('access chado_feature content'),
  120. 'type' => MENU_CALLBACK,
  121. );
  122. // the administative settings menu
  123. $items['admin/tripal/chado/tripal_feature'] = array(
  124. 'title' => 'Features',
  125. 'description' => 'A biological sequence or a section of a biological sequence, or a collection of such sections.',
  126. 'page callback' => 'tripal_feature_admin_feature_view',
  127. 'access arguments' => array('administer tripal features'),
  128. 'type' => MENU_NORMAL_ITEM,
  129. );
  130. $items['admin/tripal/chado/tripal_feature/sync'] = array(
  131. 'title' => 'Sync',
  132. 'description' => 'Sync features from Chado with Drupal',
  133. 'page callback' => 'drupal_get_form',
  134. 'page arguments' => array('tripal_feature_sync_form'),
  135. 'access arguments' => array('administer tripal features'),
  136. 'type' => MENU_LOCAL_TASK,
  137. 'weight' => 0
  138. );
  139. $items['admin/tripal/chado/tripal_feature/delete'] = array(
  140. 'title' => ' Delete',
  141. 'description' => 'Delete multiple features from Chado',
  142. 'page callback' => 'drupal_get_form',
  143. 'page arguments' => array('tripal_feature_delete_form'),
  144. 'access arguments' => array('administer tripal features'),
  145. 'type' => MENU_LOCAL_TASK,
  146. 'weight' => 2
  147. );
  148. $items['admin/tripal/chado/tripal_feature/configuration'] = array(
  149. 'title' => 'Settings',
  150. 'description' => 'Configure the Tripal Feature module.',
  151. 'page callback' => 'drupal_get_form',
  152. 'page arguments' => array('tripal_feature_admin'),
  153. 'access arguments' => array('administer tripal features'),
  154. 'type' => MENU_LOCAL_TASK,
  155. 'weight' => 5
  156. );
  157. $items['admin/tripal/chado/tripal_feature/help'] = array(
  158. 'title' => 'Help',
  159. 'description' => 'Help with the Tripal Feature module.',
  160. 'page callback' => 'theme',
  161. 'page arguments' => array('tripal_feature_help'),
  162. 'access arguments' => array('administer tripal features'),
  163. 'type' => MENU_LOCAL_TASK,
  164. 'weight' => 10
  165. );
  166. /** Loaders */
  167. $items['admin/tripal/loaders/fasta_loader'] = array(
  168. 'title' => 'Multi-FASTA file Loader',
  169. 'description' => 'Load sequences from a multi-FASTA file into Chado',
  170. 'page callback' => 'drupal_get_form',
  171. 'page arguments' => array('tripal_feature_fasta_load_form'),
  172. 'access arguments' => array('administer tripal features'),
  173. 'type' => MENU_NORMAL_ITEM,
  174. );
  175. $items['admin/tripal/loaders/gff3_load'] = array(
  176. 'title' => 'GFF3 file Loader',
  177. 'description' => 'Import a GFF3 file into Chado',
  178. 'page callback' => 'drupal_get_form',
  179. 'page arguments' => array('tripal_feature_gff3_load_form'),
  180. 'access arguments' => array('administer tripal features'),
  181. 'type' => MENU_NORMAL_ITEM,
  182. );
  183. // the menu link for addressing any feature (by name, uniquename, synonym)
  184. $items['feature/%'] = array(
  185. 'page callback' => 'tripal_feature_match_features_page',
  186. 'page arguments' => array(1),
  187. 'access arguments' => array('access chado_feature content'),
  188. 'type' => MENU_LOCAL_TASK,
  189. );
  190. // Enable admin view
  191. $items['admin/tripal/chado/tripal_feature/views/features/enable'] = array(
  192. 'title' => 'Enable feature Administrative View',
  193. 'page callback' => 'tripal_views_admin_enable_view',
  194. 'page arguments' => array('tripal_feature_admin_features', 'admin/tripal/chado/tripal_feature'),
  195. 'access arguments' => array('administer tripal feature'),
  196. 'type' => MENU_CALLBACK,
  197. );
  198. return $items;
  199. }
  200. /**
  201. * We need to let drupal know about our theme functions and their arguments.
  202. * We create theme functions to allow users of the module to customize the
  203. * look and feel of the output generated in this module
  204. *
  205. * @ingroup tripal_feature
  206. */
  207. function tripal_feature_theme($existing, $type, $theme, $path) {
  208. $core_path = drupal_get_path('module', 'tripal_core');
  209. $items = array(
  210. 'node__chado_feature' => array(
  211. 'template' => 'node--chado-generic',
  212. 'render element' => 'node',
  213. 'base hook' => 'node',
  214. 'path' => "$core_path/theme",
  215. ),
  216. 'tripal_feature_alignments' => array(
  217. 'variables' => array('node' => NULL),
  218. 'template' => 'tripal_feature_alignments',
  219. 'path' => "$path/theme/tripal_feature",
  220. ),
  221. 'tripal_feature_analyses' => array(
  222. 'variables' => array('node' => NULL),
  223. 'template' => 'tripal_feature_analyses',
  224. 'path' => "$path/theme/tripal_feature",
  225. ),
  226. 'tripal_feature_base' => array(
  227. 'variables' => array('node' => NULL),
  228. 'template' => 'tripal_feature_base',
  229. 'path' => "$path/theme/tripal_feature",
  230. ),
  231. 'tripal_feature_featurepos' => array(
  232. 'arguments' => array('node' => NULL),
  233. 'template' => 'tripal_feature_featurepos',
  234. 'path' => "$path/theme/tripal_feature",
  235. ),
  236. 'tripal_feature_sequence' => array(
  237. 'variables' => array('node' => NULL),
  238. 'template' => 'tripal_feature_sequence',
  239. 'path' => "$path/theme/tripal_feature",
  240. ),
  241. 'tripal_feature_proteins' => array(
  242. 'variables' => array('node' => NULL),
  243. 'template' => 'tripal_feature_proteins',
  244. 'path' => "$path/theme/tripal_feature",
  245. ),
  246. 'tripal_feature_publications' => array(
  247. 'variables' => array('node' => NULL),
  248. 'template' => 'tripal_feature_publications',
  249. 'path' => "$path/theme/tripal_feature",
  250. ),
  251. 'tripal_feature_synonyms' => array(
  252. 'variables' => array('node' => NULL),
  253. 'template' => 'tripal_feature_synonyms',
  254. 'path' => "$path/theme/tripal_feature",
  255. ),
  256. 'tripal_feature_references' => array(
  257. 'variables' => array('node' => NULL),
  258. 'template' => 'tripal_feature_references',
  259. 'path' => "$path/theme/tripal_feature",
  260. ),
  261. 'tripal_feature_properties' => array(
  262. 'variables' => array('node' => NULL),
  263. 'template' => 'tripal_feature_properties',
  264. 'path' => "$path/theme/tripal_feature",
  265. ),
  266. 'tripal_feature_terms' => array(
  267. 'variables' => array('node' => NULL),
  268. 'template' => 'tripal_feature_terms',
  269. 'path' => "$path/theme/tripal_feature",
  270. ),
  271. 'tripal_feature_relationships' => array(
  272. 'variables' => array('node' => NULL),
  273. 'template' => 'tripal_feature_relationships',
  274. 'path' => "$path/theme/tripal_feature",
  275. ),
  276. 'tripal_feature_help' => array(
  277. 'template' => 'tripal_feature_help',
  278. 'variables' => array(NULL),
  279. 'path' => drupal_get_path('module', 'tripal_feature') . '/theme'
  280. ),
  281. // template for the organism page
  282. 'tripal_organism_feature_browser' => array(
  283. 'variables' => array('node' => NULL),
  284. 'template' => 'tripal_organism_feature_browser',
  285. 'path' => "$path/theme/tripal_organism",
  286. ),
  287. 'tripal_organism_feature_counts' => array(
  288. 'variables' => array('node' => NULL),
  289. 'template' => 'tripal_organism_feature_counts',
  290. 'path' => "$path/theme/tripal_organism",
  291. ),
  292. // themed forms
  293. 'tripal_feature_seq_extract_form' => array(
  294. 'arguments' => array('form'),
  295. ),
  296. // themed teaser
  297. 'tripal_feature_teaser' => array(
  298. 'variables' => array('node' => NULL),
  299. 'template' => 'tripal_feature_teaser',
  300. 'path' => "$path/theme/tripal_feature",
  301. ),
  302. );
  303. return $items;
  304. }
  305. /**
  306. *
  307. *
  308. * @ingroup tripal_feature
  309. */
  310. function tripal_feature_load_featurelocs($feature_id, $side = 'as_parent', $aggregate = 1) {
  311. $sql = "
  312. SELECT
  313. F.name, F.feature_id, F.uniquename,
  314. FS.name as src_name, FS.feature_id as src_feature_id, FS.uniquename as src_uniquename,
  315. CVT.name as cvname, CVT.cvterm_id,
  316. CVTS.name as src_cvname, CVTS.cvterm_id as src_cvterm_id,
  317. FL.fmin, FL.fmax, FL.is_fmin_partial, FL.is_fmax_partial,FL.strand, FL.phase
  318. FROM {featureloc} FL
  319. INNER JOIN {feature} F ON FL.feature_id = F.feature_id
  320. INNER JOIN {feature} FS ON FS.feature_id = FL.srcfeature_id
  321. INNER JOIN {cvterm} CVT ON F.type_id = CVT.cvterm_id
  322. INNER JOIN {cvterm} CVTS ON FS.type_id = CVTS.cvterm_id
  323. ";
  324. if (strcmp($side, 'as_parent')==0) {
  325. $sql .= "WHERE FL.srcfeature_id = :feature_id ";
  326. }
  327. if (strcmp($side, 'as_child')==0) {
  328. $sql .= "WHERE FL.feature_id = :feature_id ";
  329. }
  330. $flresults = chado_query($sql, array(':feature_id' => $feature_id));
  331. // copy the results into an array
  332. $i=0;
  333. $featurelocs = array();
  334. while ($loc = $flresults->fetchObject()) {
  335. // if a drupal node exists for this feature then add the nid to the
  336. // results object
  337. $loc->fnid = chado_get_node_id('feature', $loc->feature_id);
  338. $loc->snid = chado_get_node_id('feature', $loc->src_feature_id);
  339. // add the result to the array
  340. $featurelocs[$i++] = $loc;
  341. }
  342. // Add the relationship feature locs if aggregate is turned on
  343. if ($aggregate and strcmp($side, 'as_parent')==0) {
  344. // get the relationships for this feature without substituting any children
  345. // for the parent. We want all relationships
  346. $relationships = tripal_feature_get_aggregate_relationships($feature_id, 0);
  347. foreach ($relationships as $rindex => $rel) {
  348. // get the featurelocs for each of the relationship features
  349. $rel_featurelocs = tripal_feature_load_featurelocs($rel->subject_id, 'as_child', 0);
  350. foreach ($rel_featurelocs as $findex => $rfloc) {
  351. $featurelocs[$i++] = $rfloc;
  352. }
  353. }
  354. }
  355. usort($featurelocs, 'tripal_feature_sort_locations');
  356. return $featurelocs;
  357. }
  358. /**
  359. * used to sort the feature locs by start position
  360. *
  361. * @ingroup tripal_feature
  362. */
  363. function tripal_feature_sort_locations($a, $b) {
  364. return strnatcmp($a->fmin, $b->fmin);
  365. }
  366. /**
  367. *
  368. *
  369. * @ingroup tripal_feature
  370. */
  371. function tripal_feature_load_relationships($feature_id, $side = 'as_subject') {
  372. // get the relationships for this feature. The query below is used for both
  373. // querying the object and subject relationships
  374. $sql = "
  375. SELECT
  376. FS.name as subject_name, FS.uniquename as subject_uniquename,
  377. CVTS.name as subject_type, CVTS.cvterm_id as subject_type_id,
  378. FR.subject_id, FR.type_id as relationship_type_id, FR.object_id, FR.rank,
  379. CVT.name as rel_type,
  380. FO.name as object_name, FO.uniquename as object_uniquename,
  381. CVTO.name as object_type, CVTO.cvterm_id as object_type_id
  382. FROM {feature_relationship} FR
  383. INNER JOIN {cvterm} CVT ON FR.type_id = CVT.cvterm_id
  384. INNER JOIN {feature} FS ON FS.feature_id = FR.subject_id
  385. INNER JOIN {feature} FO ON FO.feature_id = FR.object_id
  386. INNER JOIN {cvterm} CVTO ON FO.type_id = CVTO.cvterm_id
  387. INNER JOIN {cvterm} CVTS ON FS.type_id = CVTS.cvterm_id
  388. ";
  389. if (strcmp($side, 'as_object')==0) {
  390. $sql .= " WHERE FR.object_id = :feature_id";
  391. }
  392. if (strcmp($side, 'as_subject')==0) {
  393. $sql .= " WHERE FR.subject_id = :feature_id";
  394. }
  395. $sql .= " ORDER BY FR.rank";
  396. // get the relationships
  397. $results = chado_query($sql, array(':feature_id' => $feature_id));
  398. // iterate through the relationships, put these in an array and add
  399. // in the Drupal node id if one exists
  400. $i=0;
  401. $nodesql = "SELECT nid FROM {chado_feature} WHERE feature_id = :feature_id";
  402. $relationships = array();
  403. while ($rel = $results->fetchObject()) {
  404. $node = db_query($nodesql, array(':feature_id' => $rel->subject_id))->fetchObject();
  405. if ($node) {
  406. $rel->subject_nid = $node->nid;
  407. }
  408. $node = db_query($nodesql, array(':feature_id' => $rel->object_id))->fetchObject();
  409. if ($node) {
  410. $rel->object_nid = $node->nid;
  411. }
  412. $relationships[$i++] = $rel;
  413. }
  414. return $relationships;
  415. }
  416. /**
  417. *
  418. *
  419. * @ingroup tripal_feature
  420. */
  421. function tripal_feature_get_aggregate_relationships($feature_id, $substitute=1,
  422. $levels=0, $base_type_id=NULL, $depth=0) {
  423. // we only want to recurse to as many levels deep as indicated by the
  424. // $levels variable, but only if this variable is > 0. If 0 then we
  425. // recurse until we reach the end of the relationships tree.
  426. if ($levels > 0 and $levels == $depth) {
  427. return NULL;
  428. }
  429. // first get the relationships for this feature
  430. return tripal_feature_load_relationships($feature_id, 'as_object');
  431. }
  432. /**
  433. *
  434. *
  435. * @ingroup tripal_feature
  436. */
  437. function tripal_feature_load_featureloc_sequences($feature_id, $featurelocs) {
  438. // if we don't have any featurelocs then no point in continuing
  439. if (!$featurelocs) {
  440. return array();
  441. }
  442. // get the list of relationships (including any aggregators) and iterate
  443. // through each one to find information needed to color-code the reference sequence
  444. $relationships = tripal_feature_get_aggregate_relationships($feature_id);
  445. if (!$relationships) {
  446. return array();
  447. }
  448. // iterate through each of the realtionships features and get their
  449. // locations
  450. foreach ($relationships as $rindex => $rel) {
  451. // get the featurelocs for each of the relationship features
  452. $rel_featurelocs = tripal_feature_load_featurelocs($rel->subject_id, 'as_child', 0);
  453. foreach ($rel_featurelocs as $rfindex => $rel_featureloc) {
  454. // keep track of this unique source feature
  455. $src = $rel_featureloc->src_feature_id . "-" . $rel_featureloc->src_cvterm_id;
  456. // copy over the results to the relationship object. Since there can
  457. // be more than one feature location for each relationship feature we
  458. // use the '$src' variable to keep track of these.
  459. $rel->featurelocs = new stdClass();
  460. $rel->featurelocs->$src = new stdClass();
  461. $rel->featurelocs->$src->src_uniquename = $rel_featureloc->src_uniquename;
  462. $rel->featurelocs->$src->src_cvterm_id = $rel_featureloc->src_cvterm_id;
  463. $rel->featurelocs->$src->src_cvname = $rel_featureloc->src_cvname;
  464. $rel->featurelocs->$src->fmin = $rel_featureloc->fmin;
  465. $rel->featurelocs->$src->fmax = $rel_featureloc->fmax;
  466. $rel->featurelocs->$src->src_name = $rel_featureloc->src_name;
  467. // keep track of the individual parts for each relationship
  468. $start = $rel->featurelocs->$src->fmin;
  469. $end = $rel->featurelocs->$src->fmax;
  470. $type = $rel->subject_type;
  471. $rel_locs[$src]['parts'][$start][$type]['start'] = $start;
  472. $rel_locs[$src]['parts'][$start][$type]['end'] = $end;
  473. $rel_locs[$src]['parts'][$start][$type]['type'] = $type;
  474. }
  475. }
  476. // the featurelocs array provided to the function contains the locations
  477. // where this feature is found. We want to get the sequence for each
  478. // location and then annotate it with the parts found from the relationships
  479. // locations determiend above.
  480. $floc_sequences = array();
  481. foreach ($featurelocs as $featureloc) {
  482. // build the src name so we can keep track of the different parts for each feature
  483. $src = $featureloc->srcfeature_id->feature_id . "-" . $featureloc->srcfeature_id->type_id->cvterm_id;
  484. // orient the parts to the beginning of the feature sequence
  485. if (!empty($rel_locs[$src]['parts'])) {
  486. $parts = $rel_locs[$src]['parts'];
  487. $rparts = array(); // we will fill this up if we're on the reverse strand
  488. foreach ($parts as $start => $types) {
  489. foreach ($types as $type_name => $type) {
  490. if ($featureloc->strand >= 0) {
  491. // this is on the forward strand. We need to convert the start on the src feature to the
  492. // start on this feature's sequence
  493. $parts[$start][$type_name]['start'] = $parts[$start][$type_name]['start'] - $featureloc->fmin;
  494. $parts[$start][$type_name]['end'] = $parts[$start][$type_name]['end'] - $featureloc->fmin;
  495. $parts[$start][$type_name]['type'] = $type_name;
  496. }
  497. else {
  498. // this is on the reverse strand. We need to swap the start and stop and calculate from the
  499. // begining of the reverse sequence
  500. $size = ($featureloc->fmax - $featureloc->fmin);
  501. $start_orig = $parts[$start][$type_name]['start'];
  502. $end_orig = $parts[$start][$type_name]['end'];
  503. $new_start = $size - ($end_orig - $featureloc->fmin);
  504. $new_end = $size - ($start_orig - $featureloc->fmin);
  505. $rparts[$new_start][$type_name]['start'] = $new_start;
  506. $rparts[$new_start][$type_name]['end'] = $new_end;
  507. $rparts[$new_start][$type_name]['type'] = $type_name;
  508. }
  509. }
  510. }
  511. // now sort the parts
  512. // if we're on the reverse strand we need to resort
  513. if ($featureloc->strand >= 0) {
  514. usort($parts, 'tripal_feature_sort_rel_parts_by_start');
  515. }
  516. else {
  517. usort($rparts, 'tripal_feature_sort_rel_parts_by_start');
  518. $parts = $rparts;
  519. }
  520. $floc_sequences[$src]['src'] = $src;
  521. $floc_sequences[$src]['type'] = $featureloc->feature_id->type_id->name;
  522. $args = array(':feature_id' => $featureloc->srcfeature_id->feature_id);
  523. $start = $featureloc->fmin + 1;
  524. $size = $featureloc->fmax - $featureloc->fmin;
  525. // TODO: fix the hard coded $start and $size
  526. // the $start and $size variables are hard-coded in the SQL statement
  527. // because the db_query function places quotes around all placeholders
  528. // (e.g. :start & :size) and screws up the substring function
  529. $sql = "
  530. SELECT substring(residues from $start for $size) as residues
  531. FROM {feature}
  532. WHERE feature_id = :feature_id
  533. ";
  534. $sequence = chado_query($sql, $args)->fetchObject();
  535. $residues = $sequence->residues;
  536. if ($featureloc->strand < 0) {
  537. $residues = tripal_feature_reverse_complement($residues);
  538. }
  539. $strand = '.';
  540. if ($featureloc->strand == 1) {
  541. $strand = '+';
  542. }
  543. elseif ($featureloc->strand == -1) {
  544. $strand = '-';
  545. }
  546. $defline = $featureloc->feature_id->name . " " . $featureloc->srcfeature_id->name . ":" . ($featureloc->fmin + 1) . ".." . $featureloc->fmax . " " . $strand;
  547. $floc_sequences[$src]['formatted_seq'] = tripal_feature_color_sequence($residues, $parts, $defline);
  548. }
  549. }
  550. return $floc_sequences;
  551. }
  552. /**
  553. *
  554. *
  555. * @ingroup tripal_feature
  556. */
  557. function tripal_feature_get_matched_alignments($feature) {
  558. // This function is for features that align through an intermediate such
  559. // as 'EST_match' or 'match'. This occurs in the case where two sequences
  560. // align but where one does not align perfectly. Some ESTs may be in a contig
  561. // but not all of the EST. Portions may overhang and not be included in the
  562. // consensus if quality is bad.
  563. // For example:
  564. //
  565. // Feature 1: Contig --------------------
  566. // Feature 2: EST_match -------
  567. // Feature 3: EST ---------
  568. //
  569. // The feature provided to the function will always be the feature 1. The
  570. // featureloc columns prefixed with 'right' (e.g. right_fmin) belong to the
  571. // alignment of feature 3 with feature 2
  572. //
  573. // Features may align to more than one feature and are not matches. We do
  574. // not want to include these, so we have to filter on the SO terms:
  575. // match, or %_match
  576. //
  577. $sql = "
  578. SELECT
  579. FL1.featureloc_id as left_featureloc_id,
  580. FL1.srcfeature_id as left_srcfeature_id,
  581. FL1.feature_id as left_feature_id,
  582. FL1.fmin as left_fmin,
  583. FL1.is_fmin_partial as left_is_fmin_partial,
  584. FL1.fmax as left_fmax,
  585. FL1.is_fmax_partial as left_is_fmax_partial,
  586. FL1.strand as left_strand,
  587. FL1.phase as left_phase,
  588. FL1.locgroup as left_locgroup,
  589. FL1.rank as left_rank,
  590. FL2.featureloc_id as right_featureloc_id,
  591. FL2.srcfeature_id as right_srcfeature_id,
  592. FL2.feature_id as right_feature_id,
  593. FL2.fmin as right_fmin,
  594. FL2.is_fmin_partial as right_is_fmin_partial,
  595. FL2.fmax as right_fmax,
  596. FL2.is_fmax_partial as right_is_fmax_partial,
  597. FL2.strand as right_strand,
  598. FL2.phase as right_phase,
  599. FL2.locgroup as right_locgroup,
  600. FL2.rank as right_rank
  601. FROM {feature} F1
  602. INNER JOIN {featureloc} FL1 on FL1.srcfeature_id = F1.feature_id
  603. INNER JOIN {feature} F2 on FL1.feature_id = F2.feature_id
  604. INNER JOIN {featureloc} FL2 on FL2.feature_id = F2.feature_id
  605. INNER JOIN {cvterm} CVT2 on F2.type_id = CVT2.cvterm_id
  606. WHERE
  607. F1.feature_id = :feature_id AND
  608. (CVT2.name = 'match' or CVT2.name like '%_match')
  609. ORDER BY FL1.fmin
  610. ";
  611. $results = chado_query($sql, array(':feature_id' => $feature->feature_id));
  612. // iterate through the results and add them to our featurelocs array
  613. $featurelocs = array();
  614. while ($fl = $results->fetchObject()) {
  615. // ignore featurelocs where the left and right srcfeature is the same
  616. if (strcmp($fl->left_srcfeature_id, $fl->right_srcfeature_id) == 0) {
  617. continue;
  618. }
  619. $featurelocs[] = $fl ;
  620. }
  621. return $featurelocs;
  622. }
  623. /**
  624. *
  625. *
  626. * @ingroup tripal_feature
  627. */
  628. function tripal_feature_load_organism_feature_counts($organism) {
  629. // don't show the browser if the settings in the admin page is turned off
  630. // instead return the array indicating the status of the browser
  631. $show_counts = variable_get('tripal_feature_summary_setting', 'show_feature_summary');
  632. if (strcmp($show_counts, 'show_feature_summary')!=0) {
  633. return array('enabled' => FALSE );
  634. }
  635. $args = array();
  636. $names = array();
  637. $order = array();
  638. // build the where clause for the SQL statement if we have a custom term list
  639. // we'll also keep track of the names the admin provided (if any) and the
  640. // order that the terms should appear.
  641. $is_custom = 0;
  642. $temp = rtrim(variable_get('tripal_feature_summary_report_mapping', ''));
  643. $where = '';
  644. if ($temp) {
  645. $is_custom = 1;
  646. $temp = explode("\n", $temp);
  647. $i = 0;
  648. foreach ($temp as $key => $value) {
  649. // separate the key value pairs
  650. $temp2 = explode("=", $value);
  651. $feature_type = rtrim($temp2[0]);
  652. $args[] = $feature_type;
  653. $order[] = $feature_type;
  654. // if a new name is provided then use that otherwise just
  655. // use the feature type
  656. if (count($temp2) == 2) {
  657. $names[":name$i"] = rtrim($temp2[1]);
  658. }
  659. else {
  660. $names[":name$i"] = $feature_type;
  661. }
  662. $where .= " OFC.feature_type = :name$i OR ";
  663. $i++;
  664. }
  665. if ($where) {
  666. $where = drupal_substr($where, 0, -5); # remove OR from the end
  667. $where = "($where) AND";
  668. }
  669. }
  670. // get the feature counts. This is dependent on a materialized view
  671. // installed with the organism module
  672. $sql = "
  673. SELECT OFC.num_features,OFC.feature_type,CVT.definition
  674. FROM {organism_feature_count} OFC
  675. INNER JOIN {cvterm} CVT on OFC.cvterm_id = CVT.cvterm_id
  676. WHERE $where organism_id = :organism_id
  677. ORDER BY num_features desc
  678. ";
  679. $args[':organism_id'] = $organism->organism_id;
  680. $org_features = chado_query($sql, $args);
  681. // iterate through the types
  682. $types = array();
  683. while ($type = $org_features->fetchObject()) {
  684. $types[$type->feature_type] = $type;
  685. // if we don't have an order this means we didn't go through the loop
  686. // above to set the names, so do that now
  687. if (!$is_custom) {
  688. $names[] = $type->feature_type;
  689. $order[] = $type->feature_type;
  690. }
  691. }
  692. # now reorder the types
  693. $ordered_types = array();
  694. foreach ($order as $type) {
  695. $ordered_types[] = $types[$type];
  696. }
  697. return array( 'types' => $ordered_types, 'names' => $names, 'enabled' => TRUE );
  698. }
  699. /**
  700. * used to sort the list of relationship parts by start position
  701. *
  702. * @ingroup tripal_feature
  703. */
  704. function tripal_feature_sort_rel_parts_by_start($a, $b) {
  705. foreach ($a as $type_name => $details) {
  706. $astart = $a[$type_name]['start'];
  707. break;
  708. }
  709. foreach ($b as $type_name => $details) {
  710. $bstart = $b[$type_name]['start'];
  711. break;
  712. }
  713. return strnatcmp($astart, $bstart);
  714. }
  715. /**
  716. * used to sort the list of relationship parts by start position
  717. *
  718. * @ingroup tripal_feature
  719. */
  720. function tripal_feature_sort_rel_parts_by_end($a, $b) {
  721. $val = strnatcmp($b['end'], $a['end']);
  722. if ($val == 0) {
  723. return strcmp($a['type'], $b['type']);
  724. }
  725. return $val;
  726. }
  727. /**
  728. *
  729. *
  730. * @ingroup tripal_feature
  731. */
  732. function tripal_feature_color_sequence($sequence, $parts, $defline) {
  733. $types = array();
  734. // first get the list of types so we can create a color legend
  735. foreach ($parts as $index => $t) {
  736. foreach ($t as $type_name => $details) {
  737. $types[$type_name] = 1;
  738. }
  739. }
  740. $newseq = "<div id=\"tripal_feature-featureloc_sequence-legend\">Legend: ";
  741. foreach ($types as $type_name => $present) {
  742. $newseq .= "<span id=\"tripal_feature-legend-$type_name\" class=\"tripal_feature-legend-item tripal_feature-featureloc_sequence-$type_name\" script=\"\">$type_name</span>";
  743. }
  744. $newseq .= "</div>Hold the cursor over a type above to highlight its positions in the sequence below. The colors in the sequence below merge when types overlap.";
  745. // set the background color of the rows based on the type
  746. $pos = 0;
  747. $newseq .= "<pre id=\"tripal_feature-featureloc_sequence\">";
  748. $newseq .= ">$defline\n";
  749. // iterate through the parts. They should be in order.
  750. $ends = array();
  751. $seqcount = 0;
  752. foreach ($parts as $index => $types) {
  753. // get the start for this part. All types in this part start at the
  754. // same position so we only need the first record
  755. foreach ($types as $type => $child) {
  756. $start = $child['start'];
  757. break;
  758. }
  759. // add in the sequence up to the start of this part
  760. for ($i = $pos; $i < $start; $i++) {
  761. $newseq .= $sequence{$pos};
  762. $seqcount++;
  763. if ($seqcount % 50 == 0) {
  764. $newseq .= "\n";
  765. }
  766. if (array_key_exists($pos, $ends)) {
  767. foreach ($ends[$pos] as $end) {
  768. $newseq .= "</span>";
  769. }
  770. }
  771. $pos++;
  772. }
  773. // we want to sort the parts by their end. We want the span tag to
  774. // to be added in the order the parts end.
  775. usort($types, 'tripal_feature_sort_rel_parts_by_end');
  776. // now add the child span for all types that start at this position
  777. foreach ($types as $type) {
  778. $class = "tripal_feature-featureloc_sequence-" . $type['type'];
  779. $newseq .= "<span class=\"$class\">";
  780. // add the end position
  781. $end = $type['end'];
  782. $ends[$end][] = $end;
  783. }
  784. }
  785. // add in rest of the sequence
  786. for ($i = $pos; $i < strlen($sequence); $i++) {
  787. $newseq .= $sequence{$pos};
  788. $seqcount++;
  789. if ($seqcount % 50 == 0) {
  790. $newseq .= "\n";
  791. }
  792. if (array_key_exists($pos, $ends)) {
  793. foreach ($ends[$pos] as $end) {
  794. $newseq .= "</span>";
  795. }
  796. }
  797. $pos++;
  798. }
  799. $newseq .= "</pre>";
  800. return $newseq;
  801. }
  802. /**
  803. *
  804. *
  805. * @ingroup tripal_feature
  806. */
  807. function tripal_feature_cv_chart($chart_id) {
  808. // we only want the chart to show feature types setup by the admin
  809. $temp = rtrim(variable_get('tripal_feature_summary_report_mapping', ''));
  810. $where = '';
  811. if ($temp) {
  812. $temp = explode("\n", $temp);
  813. foreach ($temp as $key => $value) {
  814. $temp2 = explode("=", $value);
  815. $feature_type = rtrim($temp2[0]);
  816. $where .= "CNT.feature_type = '$feature_type' OR \n";
  817. }
  818. if ($where) {
  819. $where = drupal_substr($where, 0, -5); # remove OR from the end
  820. $where = "($where) AND";
  821. }
  822. }
  823. $organism_id = preg_replace("/^tripal_feature_cv_chart_(\d+)$/", "$1", $chart_id);
  824. // The CV module will create the JSON array necessary for buillding a
  825. // pie chart using jgChart and Google Charts. We have to pass to it
  826. // a table that contains count information, tell it which column
  827. // contains the cvterm_id and provide a filter for getting the
  828. // results we want from the table.
  829. $options = array(
  830. count_mview => 'organism_feature_count',
  831. cvterm_id_column => 'cvterm_id',
  832. count_column => 'num_features',
  833. size => '550x200',
  834. filter => "$where CNT.organism_id = $organism_id",
  835. );
  836. return $options;
  837. }
  838. /**
  839. *
  840. *
  841. * @ingroup tripal_feature
  842. */
  843. function tripal_feature_cv_tree($tree_id) {
  844. // The CV module will create the JSON array necessary for buillding a
  845. // pie chart using jgChart and Google Charts. We have to pass to it
  846. // a table that contains count information, tell it which column
  847. // contains the cvterm_id and provide a filter for getting the
  848. // results we want from the table.
  849. $organism_id = preg_replace("/^tripal_feature_cv_tree_(\d+)$/", "$1", $tree_id);
  850. $options = array(
  851. cv_id => tripal_cv_get_cv_id('sequence'),
  852. count_mview => 'organism_feature_count',
  853. cvterm_id_column => 'cvterm_id',
  854. count_column => 'num_features',
  855. filter => "CNT.organism_id = $organism_id",
  856. label => 'Features',
  857. );
  858. return $options;
  859. }
  860. /**
  861. *
  862. *
  863. * @ingroup tripal_feature
  864. */
  865. function tripal_feature_del_vocabulary() {
  866. //include the file containing the required functions for adding taxonomy vocabs
  867. module_load_include('inc', 'taxonomy', 'taxonomy.admin');
  868. // get the vocabularies
  869. $vocabularies = taxonomy_get_vocabularies();
  870. // These taxonomic terms are hard coded because we
  871. // know we have these relationships in the chado tables
  872. // through foreign key relationships. The tripal
  873. // modules that correspond to these chado "modules" don't
  874. // need to be installed for the taxonomy to work.
  875. foreach ($vocabularies as $vocab) {
  876. if ($vocab->name == 'Feature Type') {
  877. taxonomy_vocabulary_delete($vocab->vid);
  878. }
  879. if ($vocab->name == 'Organism') {
  880. taxonomy_vocabulary_delete($vocab->vid);
  881. }
  882. if ($vocab->name == 'Library') {
  883. taxonomy_vocabulary_delete($vocab->vid);
  884. }
  885. if ($vocab->name == 'Analysis') {
  886. taxonomy_vocabulary_delete($vocab->vid);
  887. }
  888. }
  889. }
  890. /**
  891. *
  892. *
  893. * @ingroup tripal_feature
  894. */
  895. function tripal_feature_job_describe_args($callback, $args) {
  896. $new_args = array();
  897. if ($callback == 'tripal_feature_load_fasta') {
  898. $new_args['FASTA file'] = $args[0];
  899. $organism = tripal_core_chado_select('organism', array('genus', 'species'), array('organism_id' => $args[1]));
  900. $new_args['Organism'] = $organism[0]->genus . " " . $organism[0]->species;
  901. $new_args['Sequence Type'] = $args[2];
  902. $new_args['Name Match Type'] = $args[14];
  903. $new_args['Name RE'] = $args[4];
  904. $new_args['Unique Name RE'] = $args[5];
  905. // add in the relationship arguments
  906. $new_args['Relationship Type'] = $args[8];
  907. $new_args['Relationship Parent RE'] = $args[9];
  908. $new_args['Relationship Parent Type'] = $args[10];
  909. // add in the database reference arguments
  910. if ($args[7]) {
  911. $db = tripal_core_chado_select('db', array('name'), array('db_id' => $args[7]));
  912. }
  913. $new_args['Database Reference'] = $db[0]->name;
  914. $new_args['Accession RE'] = $args[6];
  915. $new_args['Method'] = $args[11];
  916. // add in the analysis
  917. if ($args[13]) {
  918. $analysis = tripal_core_chado_select('analysis', array('name'), array('analysis_id' => $args[13]));
  919. }
  920. $new_args['Analysis'] = $analysis[0]->name;
  921. }
  922. if ($callback == 'tripal_feature_delete_features') {
  923. if ($args[0]) {
  924. $organism = tripal_core_chado_select('organism', array('genus', 'species'), array('organism_id' => $args[0]));
  925. $new_args['Organism'] = $organism[0]->genus . " " . $organism[0]->species;
  926. }
  927. else {
  928. $new_args['Organism'] = '';
  929. }
  930. if ($args[1]) {
  931. $analysis = tripal_core_chado_select('analysis', array('name'), array('analysis_id' => $args[1]));
  932. $new_args['Analysis'] = $analysis[0]->name;
  933. }
  934. else {
  935. $new_args['Analysis'] = '';
  936. }
  937. $new_args['Sequence Type'] = $args[2];
  938. $new_args['Is Unique Name'] = $args[3];
  939. $new_args['Features Names'] = $args[4];
  940. }
  941. elseif ($callback == 'tripal_feature_load_gff3') {
  942. $new_args['GFF File'] = $args[0];
  943. $organism = tripal_core_chado_select('organism', array('genus', 'species'), array('organism_id' => $args[1]));
  944. $new_args['Organism'] = $organism[0]->genus . " " . $organism[0]->species;
  945. $analysis = tripal_core_chado_select('analysis', array('name'), array('analysis_id' => $args[2]));
  946. $new_args['Analysis'] = $analysis[0]->name;
  947. $new_args['Use a Transaction'] = ($args[7] == 1) ? "Yes" : "No";
  948. $new_args['Import only new features'] = ($args[3] == 1) ? "Yes" : "No";
  949. $new_args['Import all and update'] = ($args[4] == 1) ? "Yes" : "No";
  950. $new_args['Import all and replace'] = ($args[5] == 1) ? "Yes" : "No";
  951. $new_args['Delete features'] = ($args[6] == 1) ? "Yes" : "No";
  952. if ($args[8]) {
  953. $target_organism = tripal_core_chado_select('organism', array('genus', 'species'), array('organism_id' => $args[8]));
  954. $new_args['Target organism'] = $target_organism[0]->genus . " " . $target_organism[0]->species;
  955. }
  956. else {
  957. $new_args['Target organism'] = '';
  958. }
  959. $new_args['Target type'] = $args[9];
  960. $new_args['Create target'] = ($args[10] == 1) ? "Yes" : "No";
  961. $new_args['Starting line'] = $args[11];
  962. $new_args['Landmark Type'] = $args[12];
  963. $new_args['Alternate ID attribute'] = $args[13];
  964. $new_args['Create Organism'] = ($args[14] == 1) ? "Yes" : "No";
  965. }
  966. if ($callback == 'tripal_feature_sync_features') {
  967. if ($args[0]) {
  968. $organism = tripal_core_chado_select('organism', array('genus', 'species'), array('organism_id' => $args[0]));
  969. $new_args['Organism'] = $organism[0]->genus . " " . $organism[0]->species;
  970. }
  971. else {
  972. $new_args['Organism'] = '';
  973. }
  974. $new_args['Feature Types'] = $args[1];
  975. }
  976. return $new_args;
  977. }
  978. /**
  979. * Implements hook_coder_ignore().
  980. * Defines the path to the file (tripal_core.coder_ignores.txt) where ignore rules for coder are stored
  981. */
  982. function tripal_feature_coder_ignore() {
  983. return array(
  984. 'path' => drupal_get_path('module', 'tripal_feature'),
  985. 'line prefix' => drupal_get_path('module', 'tripal_feature'),
  986. );
  987. }
  988. /*
  989. * Uses the value provided in the $id argument to find all features that match
  990. * that ID by name, featurename or synonym. If it matches uniquenly to a single
  991. * feature it will redirect to that feature page, otherwise, a list of matching
  992. * features is shown.
  993. */
  994. function tripal_feature_match_features_page($id) {
  995. // if the URL alias configuration is set such that the URL
  996. // always begins with 'feature' then we want to use the ID as it is and
  997. // forward it on. Otherwise, try to find the matching feature.
  998. $url_alias = variable_get('chado_feature_url_string', '/feature/[genus]/[species]/[type]/[uniquename]');
  999. if (!$url_alias) {
  1000. $url_alias = '/feature/[genus]/[species]/[type]/[uniquename]';
  1001. }
  1002. $url_alias = preg_replace('/^\//', '', $url_alias); // remove any preceeding forward slash
  1003. if (preg_match('/^feature\//', $url_alias)) {
  1004. drupal_goto($id);
  1005. }
  1006. $sql = "
  1007. SELECT
  1008. F.name, F.uniquename, F.feature_id,
  1009. O.genus, O.species, O.organism_id,
  1010. CVT.cvterm_id, CVT.name as type_name,
  1011. CF.nid,
  1012. array_agg(S.name) as synonyms
  1013. FROM {feature} F
  1014. INNER JOIN {organism} O on F.organism_id = O.organism_id
  1015. INNER JOIN {cvterm} CVT on CVT.cvterm_id = F.type_id
  1016. LEFT JOIN {feature_synonym} FS on FS.feature_id = F.feature_id
  1017. LEFT JOIN {synonym} S on S.synonym_id = FS.synonym_id
  1018. INNER JOIN public.chado_feature CF on CF.feature_id = F.feature_id
  1019. WHERE
  1020. F.uniquename = :uname or
  1021. F.name = :fname' or
  1022. S.name = :sname
  1023. GROUP BY F.name, F.uniquename, F.feature_id, O.genus, O.species,
  1024. O.organism_id, CVT.cvterm_id, CVT.name, CF.nid
  1025. ";
  1026. $results = chado_query($sql, array(':uname' => $id, ':fname' => $id, ':sname' => $id));
  1027. $num_matches = 0;
  1028. // iterate through the matches and build the table for showing matches
  1029. $header = array('Uniquename', 'Name', 'Type', 'Species', 'Synonyms');
  1030. $rows = array();
  1031. $curr_match;
  1032. while ($match = $results->fetchObject()) {
  1033. $curr_match = $match;
  1034. $synonyms = $match->synonyms;
  1035. $synonyms = preg_replace('/[\"\{\}]/', '', $synonyms);
  1036. $rows[] = array(
  1037. $match->uniquename,
  1038. "<a href=\"" . url("node/" . $match->nid) . "\">" . $match->name . "</a>",
  1039. $match->type_name,
  1040. '<i>' . $match->genus . ' ' . $match->species . '</i>',
  1041. $synonyms,
  1042. );
  1043. $num_matches++;
  1044. }
  1045. // if we have more than one match then generate the table, otherwise, redirect
  1046. // to the matched feature
  1047. if ($num_matches == 1) {
  1048. drupal_goto("node/" . $curr_match->nid);
  1049. }
  1050. if ($num_matches == 0) {
  1051. return "<p>No features matched the given name '$id'</p>";
  1052. }
  1053. $table_attrs = array(
  1054. 'class' => 'tripal-table tripal-table-horz'
  1055. );
  1056. $output = "<p>The following features match the name '$id'.</p>";
  1057. $output .= theme_table($header, $rows, $table_attrs, $caption);
  1058. return $output;
  1059. }
  1060. /**
  1061. * Implementation of hook_form_alter()
  1062. *
  1063. * @param $form
  1064. * @param $form_state
  1065. * @param $form_id
  1066. */
  1067. function tripal_feature_form_alter(&$form, &$form_state, $form_id) {
  1068. if ($form_id == "tripal_feature_seq_extract_form") {
  1069. // updating the form through the ahah callback sets the action of
  1070. // the form to the ahah callback URL. We need to set it back
  1071. // to the normal form URL
  1072. $form['#action'] = url("find/sequences");
  1073. }
  1074. // turn off preview button for insert/updates
  1075. if ($form_id == "chado_feature_node_form") {
  1076. $form['actions']['preview']['#access'] = FALSE;
  1077. }
  1078. }