tripal_feature.module 40 KB

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