tripal_feature.module 41 KB

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