tripal_feature.module 41 KB

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