tripal_feature.module 41 KB

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