tripal_feature.module 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761
  1. <?php
  2. /**
  3. * @file
  4. * @todo Add file header description
  5. */
  6. /**
  7. * @defgroup tripal_feature Feature Module
  8. * @ingroup tripal_modules
  9. * @{
  10. * Provides functions for managing chado features including creating details pages for each feature
  11. * @}
  12. */
  13. require_once "api/tripal_feature.api.inc";
  14. require_once "api/tripal_feature.schema.api.inc";
  15. require_once "theme/tripal_feature.theme.inc";
  16. require_once "includes/tripal_feature.admin.inc";
  17. require_once "includes/tripal_feature.sync_features.inc";
  18. require_once "includes/tripal_feature.fasta_loader.inc";
  19. require_once "includes/tripal_feature.gff_loader.inc";
  20. require_once "includes/tripal_feature.seq_extract.inc";
  21. require_once "includes/tripal_feature.delete.inc";
  22. require_once "includes/tripal_feature.form.inc";
  23. /**
  24. *
  25. * @ingroup tripal_feature
  26. */
  27. function tripal_feature_init() {
  28. drupal_add_css(drupal_get_path('module', 'tripal_feature') . '/theme/css/tripal_feature.css');
  29. drupal_add_js(drupal_get_path('module', 'tripal_feature') . '/theme/js/tripal_feature.js');
  30. }
  31. /**
  32. * Implements hook_views_api()
  33. *
  34. * Purpose: Essentially this hook tells drupal that there is views support for
  35. * for this module which then includes tripal_db.views.inc where all the
  36. * views integration code is
  37. *
  38. * @ingroup tripal_feature
  39. */
  40. function tripal_feature_views_api() {
  41. return array(
  42. 'api' => 2.0,
  43. );
  44. }
  45. /**
  46. * Display help and module information
  47. *
  48. * @param
  49. * path which path of the site we're displaying help
  50. * @param
  51. * arg array that holds the current path as would be returned from arg() function
  52. *
  53. * @return
  54. * help text for the path
  55. *
  56. * @ingroup tripal_feature
  57. */
  58. function tripal_feature_help($path, $arg) {
  59. $output = '';
  60. switch ($path) {
  61. case "admin/help#tripal_feature":
  62. $output='<p>' . t("Displays links to nodes created on this date") . '</p>';
  63. break;
  64. }
  65. return $output;
  66. }
  67. /**
  68. * Provide information to drupal about the node types that we're creating
  69. * in this module
  70. *
  71. * @ingroup tripal_feature
  72. */
  73. function tripal_feature_node_info() {
  74. $nodes = array();
  75. $nodes['chado_feature'] = array(
  76. 'name' => t('Feature'),
  77. 'base' => 'chado_feature',
  78. 'description' => t('A feature from the chado database'),
  79. 'has_title' => FALSE,
  80. 'title_label' => t('Feature'),
  81. 'has_body' => FALSE,
  82. 'body_label' => t('Feature Description'),
  83. 'locked' => TRUE
  84. );
  85. return $nodes;
  86. }
  87. /**
  88. * Set the permission types that the chado module uses. Essentially we
  89. * want permissionis that protect creation, editing and deleting of chado
  90. * data objects
  91. *
  92. * @ingroup tripal_feature
  93. */
  94. function tripal_feature_permissions() {
  95. return array(
  96. 'access chado_feature content' => array(
  97. 'title' => t('View Features'),
  98. 'description' => t('Allow users to view feature pages.'),
  99. ),
  100. 'create chado_feature content' => array(
  101. 'title' => t('Create Features'),
  102. 'description' => t('Allow users to create new feature pages.'),
  103. ),
  104. 'delete chado_feature content' => array(
  105. 'title' => t('Delete Features'),
  106. 'description' => t('Allow users to delete feature pages.'),
  107. ),
  108. 'edit chado_feature content' => array(
  109. 'title' => t('Edit Features'),
  110. 'description' => t('Allow users to edit feature pages.'),
  111. ),
  112. 'adminster tripal feature' => array(
  113. 'title' => t('Administer Features'),
  114. 'description' => t('Allow users to administer all features.'),
  115. ),
  116. );
  117. }
  118. /**
  119. * Implement hook_access().
  120. *
  121. * This hook allows node modules to limit access to the node types they define.
  122. *
  123. * @param $node
  124. * The node on which the operation is to be performed, or, if it does not yet exist, the
  125. * type of node to be created
  126. *
  127. * @param $op
  128. * The operation to be performed
  129. *
  130. * @param $account
  131. * A user object representing the user for whom the operation is to be performed
  132. *
  133. * @return
  134. * If the permission for the specified operation is not set then return FALSE. If the
  135. * permission is set then return NULL as this allows other modules to disable
  136. * access. The only exception is when the $op == 'create'. We will always
  137. * return TRUE if the permission is set.
  138. *
  139. * @ingroup tripal_feature
  140. */
  141. function chado_feature_node_access($node, $op, $account) {
  142. if ($op == 'create') {
  143. if (!user_access('create chado_feature content', $account)) {
  144. return FALSE;
  145. }
  146. return TRUE;
  147. }
  148. if ($op == 'update') {
  149. if (!user_access('edit chado_feature content', $account)) {
  150. return FALSE;
  151. }
  152. }
  153. if ($op == 'delete') {
  154. if (!user_access('delete chado_feature content', $account)) {
  155. return FALSE;
  156. }
  157. }
  158. if ($op == 'view') {
  159. if (!user_access('access chado_feature content', $account)) {
  160. return FALSE;
  161. }
  162. }
  163. return NULL;
  164. }
  165. /**
  166. * Menu items are automatically added for the new node types created
  167. * by this module to the 'Create Content' Navigation menu item. This function
  168. * adds more menu items needed for this module.
  169. *
  170. * @ingroup tripal_feature
  171. */
  172. function tripal_feature_menu() {
  173. $items = array();
  174. // the administative settings menu
  175. $items['find/sequences'] = array(
  176. 'title' => 'Sequence Retrieval',
  177. 'description' => 'Download a file of sequences',
  178. 'page callback' => 'tripal_feature_seq_extract_page',
  179. 'access arguments' => array('access chado_feature content'),
  180. 'type' => MENU_CALLBACK,
  181. );
  182. $items['find/sequences/ajax'] = array(
  183. 'title' => 'Sequence Retrieval',
  184. 'page callback' => 'tripal_feature_seq_extract_form_ahah_update',
  185. 'access arguments' => array('access chado_feature content'),
  186. 'type' => MENU_CALLBACK,
  187. );
  188. // the administative settings menu
  189. $items['admin/tripal/chado/tripal_feature'] = array(
  190. 'title' => 'Features',
  191. 'description' => 'A biological sequence or a section of a biological sequence, or a collection of such sections.',
  192. 'page callback' => 'tripal_feature_admin_feature_view',
  193. 'access arguments' => array('administer tripal features'),
  194. 'type' => MENU_NORMAL_ITEM,
  195. );
  196. $items['admin/tripal/chado/tripal_feature/sync'] = array(
  197. 'title' => 'Sync',
  198. 'description' => 'Sync features from Chado with Drupal',
  199. 'page callback' => 'drupal_get_form',
  200. 'page arguments' => array('tripal_feature_sync_form'),
  201. 'access arguments' => array('administer tripal features'),
  202. 'type' => MENU_LOCAL_TASK,
  203. 'weight' => 0
  204. );
  205. $items['admin/tripal/chado/tripal_feature/delete'] = array(
  206. 'title' => ' Delete',
  207. 'description' => 'Delete multiple features from Chado',
  208. 'page callback' => 'drupal_get_form',
  209. 'page arguments' => array('tripal_feature_delete_form'),
  210. 'access arguments' => array('administer tripal features'),
  211. 'type' => MENU_LOCAL_TASK,
  212. 'weight' => 2
  213. );
  214. $items['admin/tripal/chado/tripal_feature/configuration'] = array(
  215. 'title' => 'Settings',
  216. 'description' => 'Configure the Tripal Feature module.',
  217. 'page callback' => 'drupal_get_form',
  218. 'page arguments' => array('tripal_feature_admin'),
  219. 'access arguments' => array('administer tripal features'),
  220. 'type' => MENU_LOCAL_TASK,
  221. 'weight' => 5
  222. );
  223. $items['admin/tripal/chado/tripal_feature/help'] = array(
  224. 'title' => 'Help',
  225. 'description' => 'Help with the Tripal Feature module.',
  226. 'page callback' => 'theme',
  227. 'page arguments' => array('tripal_feature_help'),
  228. 'access arguments' => array('administer tripal features'),
  229. 'type' => MENU_LOCAL_TASK,
  230. 'weight' => 10
  231. );
  232. /** Loaders */
  233. $items['admin/tripal/loaders/fasta_loader'] = array(
  234. 'title' => 'Multi-FASTA file Loader',
  235. 'description' => 'Load sequences from a multi-FASTA file into Chado',
  236. 'page callback' => 'drupal_get_form',
  237. 'page arguments' => array('tripal_feature_fasta_load_form'),
  238. 'access arguments' => array('administer tripal features'),
  239. 'type' => MENU_NORMAL_ITEM,
  240. );
  241. $items['admin/tripal/loaders/gff3_load'] = array(
  242. 'title' => 'GFF3 file Loader',
  243. 'description' => 'Import a GFF3 file into Chado',
  244. 'page callback' => 'drupal_get_form',
  245. 'page arguments' => array('tripal_feature_gff3_load_form'),
  246. 'access arguments' => array('administer tripal features'),
  247. 'type' => MENU_NORMAL_ITEM,
  248. );
  249. // the menu link for addressing any feature (by name, uniquename, synonym)
  250. $items['feature/%'] = array(
  251. 'page callback' => 'tripal_feature_match_features_page',
  252. 'page arguments' => array(1),
  253. 'access arguments' => array('access chado_feature content'),
  254. 'type' => MENU_LOCAL_TASK,
  255. );
  256. // Enable admin view
  257. $items['admin/tripal/chado/tripal_feature/views/features/enable'] = array(
  258. 'title' => 'Enable feature Administrative View',
  259. 'page callback' => 'tripal_views_admin_enable_view',
  260. 'page arguments' => array('tripal_feature_admin_features', 'admin/tripal/chado/tripal_feature'),
  261. 'access arguments' => array('administer tripal feature'),
  262. 'type' => MENU_CALLBACK,
  263. );
  264. return $items;
  265. }
  266. /**
  267. * We need to let drupal know about our theme functions and their arguments.
  268. * We create theme functions to allow users of the module to customize the
  269. * look and feel of the output generated in this module
  270. *
  271. * @ingroup tripal_feature
  272. */
  273. function tripal_feature_theme($existing, $type, $theme, $path) {
  274. $core_path = drupal_get_path('module', 'tripal_core');
  275. $items = array(
  276. 'node__chado_feature' => array(
  277. 'template' => 'node--chado-generic',
  278. 'render element' => 'node',
  279. 'base hook' => 'node',
  280. 'path' => "$core_path/theme",
  281. ),
  282. 'tripal_feature_alignments' => array(
  283. 'variables' => array('node' => NULL),
  284. 'template' => 'tripal_feature_alignments',
  285. 'path' => "$path/theme/tripal_feature",
  286. ),
  287. 'tripal_feature_analyses' => array(
  288. 'variables' => array('node' => NULL),
  289. 'template' => 'tripal_feature_analyses',
  290. 'path' => "$path/theme/tripal_feature",
  291. ),
  292. 'tripal_feature_base' => array(
  293. 'variables' => array('node' => NULL),
  294. 'template' => 'tripal_feature_base',
  295. 'path' => "$path/theme/tripal_feature",
  296. ),
  297. 'tripal_feature_featurepos' => array(
  298. 'arguments' => array('node' => NULL),
  299. 'template' => 'tripal_feature_featurepos',
  300. 'path' => "$path/theme/tripal_feature",
  301. ),
  302. 'tripal_feature_sequence' => array(
  303. 'variables' => array('node' => NULL),
  304. 'template' => 'tripal_feature_sequence',
  305. 'path' => "$path/theme/tripal_feature",
  306. ),
  307. 'tripal_feature_proteins' => array(
  308. 'variables' => array('node' => NULL),
  309. 'template' => 'tripal_feature_proteins',
  310. 'path' => "$path/theme/tripal_feature",
  311. ),
  312. 'tripal_feature_publications' => array(
  313. 'variables' => array('node' => NULL),
  314. 'template' => 'tripal_feature_publications',
  315. 'path' => "$path/theme/tripal_feature",
  316. ),
  317. 'tripal_feature_synonyms' => array(
  318. 'variables' => array('node' => NULL),
  319. 'template' => 'tripal_feature_synonyms',
  320. 'path' => "$path/theme/tripal_feature",
  321. ),
  322. 'tripal_feature_references' => array(
  323. 'variables' => array('node' => NULL),
  324. 'template' => 'tripal_feature_references',
  325. 'path' => "$path/theme/tripal_feature",
  326. ),
  327. 'tripal_feature_properties' => array(
  328. 'variables' => array('node' => NULL),
  329. 'template' => 'tripal_feature_properties',
  330. 'path' => "$path/theme/tripal_feature",
  331. ),
  332. 'tripal_feature_terms' => array(
  333. 'variables' => array('node' => NULL),
  334. 'template' => 'tripal_feature_terms',
  335. 'path' => "$path/theme/tripal_feature",
  336. ),
  337. 'tripal_feature_relationships' => array(
  338. 'variables' => array('node' => NULL),
  339. 'template' => 'tripal_feature_relationships',
  340. 'path' => "$path/theme/tripal_feature",
  341. ),
  342. 'tripal_feature_help' => array(
  343. 'template' => 'tripal_feature_help',
  344. 'variables' => array(NULL),
  345. 'path' => drupal_get_path('module', 'tripal_feature') . '/theme'
  346. ),
  347. // template for the organism page
  348. 'tripal_organism_feature_browser' => array(
  349. 'variables' => array('node' => NULL),
  350. 'template' => 'tripal_organism_feature_browser',
  351. 'path' => "$path/theme/tripal_organism",
  352. ),
  353. 'tripal_organism_feature_counts' => array(
  354. 'variables' => array('node' => NULL),
  355. 'template' => 'tripal_organism_feature_counts',
  356. 'path' => "$path/theme/tripal_organism",
  357. ),
  358. // themed forms
  359. 'tripal_feature_seq_extract_form' => array(
  360. 'arguments' => array('form'),
  361. ),
  362. // themed teaser
  363. 'tripal_feature_teaser' => array(
  364. 'variables' => array('node' => NULL),
  365. 'template' => 'tripal_feature_teaser',
  366. 'path' => "$path/theme/tripal_feature",
  367. ),
  368. );
  369. return $items;
  370. }
  371. /**
  372. *
  373. *
  374. * @ingroup tripal_feature
  375. */
  376. function tripal_feature_block_info() {
  377. $blocks['references']['info'] = t('Tripal Feature References');
  378. $blocks['references']['cache'] = 'BLOCK_NO_CACHE';
  379. $blocks['base']['info'] = t('Tripal Feature Details');
  380. $blocks['base']['cache'] = 'BLOCK_NO_CACHE';
  381. $blocks['sequence']['info'] = t('Tripal Feature Sequence');
  382. $blocks['sequence']['cache'] = 'BLOCK_NO_CACHE';
  383. $blocks['featureloc_sequences']['info'] = t('Tripal Feature Annotated Sequence');
  384. $blocks['featureloc_sequences']['cache'] = 'BLOCK_NO_CACHE';
  385. $blocks['synonyms']['info'] = t('Tripal Feature Synonyms');
  386. $blocks['synonyms']['cache'] = 'BLOCK_NO_CACHE';
  387. $blocks['properties']['info'] = t('Tripal Feature Properties');
  388. $blocks['properties']['cache'] = 'BLOCK_NO_CACHE';;
  389. $blocks['terms']['info'] = t('Tripal Annotated Terms');
  390. $blocks['terms']['cache'] = 'BLOCK_NO_CACHE';;
  391. $blocks['alignments']['info'] = t('Tripal Feature Alignments');
  392. $blocks['alignments']['cache'] = 'BLOCK_NO_CACHE';
  393. $blocks['relationships']['info'] = t('Tripal Feature Relationships');
  394. $blocks['relationships']['cache'] = 'BLOCK_NO_CACHE';
  395. $blocks['org_feature_counts']['info'] = t('Tripal Organism Feature Counts');
  396. $blocks['org_feature_counts']['cache'] = 'BLOCK_NO_CACHE';
  397. $blocks['org_feature_browser']['info'] = t('Tripal Organism Feature Browser');
  398. $blocks['org_feature_browser']['cache'] = 'BLOCK_NO_CACHE';
  399. return $blocks;
  400. }
  401. /**
  402. *
  403. *
  404. * @ingroup tripal_feature
  405. */
  406. function tripal_feature_block_view($delta = '') {
  407. if (user_access('access chado_feature content') and arg(0) == 'node' and is_numeric(arg(1))) {
  408. $nid = arg(1);
  409. $node = node_load($nid);
  410. $block = array();
  411. switch ($delta) {
  412. case 'references':
  413. $block['subject'] = t('References');
  414. $block['content'] = theme('tripal_feature_references', $node);
  415. break;
  416. case 'base':
  417. $block['subject'] = t('Feature Details');
  418. $block['content'] = theme('tripal_feature_base', $node);
  419. break;
  420. case 'synonyms':
  421. $block['subject'] = t('Synonyms');
  422. $block['content'] = theme('tripal_feature_synonyms', $node);
  423. break;
  424. case 'properties':
  425. $block['subject'] = t('Properties');
  426. $block['content'] = theme('tripal_feature_properties', $node);
  427. break;
  428. case 'terms':
  429. $block['subject'] = t('Annotated Terms');
  430. $block['content'] = theme('tripal_feature_terms', $node);
  431. break;
  432. case 'sequence':
  433. $block['subject'] = t('Sequence');
  434. $block['content'] = theme('tripal_feature_sequence', $node);
  435. break;
  436. case 'featureloc_sequences':
  437. $block['subject'] = t('Formatted Sequences');
  438. $block['content'] = theme('tripal_feature_featureloc_sequences', $node);
  439. break;
  440. case 'alignments':
  441. $block['subject'] = t('Alignments');
  442. $block['content'] = theme('tripal_feature_alignments', $node);
  443. break;
  444. case 'relationships':
  445. $block['subject'] = t('Relationships');
  446. $block['content'] = theme('tripal_feature_relationships', $node);
  447. break;
  448. case 'org_feature_counts':
  449. $block['subject'] = t('Feature Type Summary');
  450. $block['content'] = theme('tripal_organism_feature_counts', array('node' => $node));
  451. break;
  452. case 'org_feature_browser':
  453. $block['subject'] = t('Feature Browser');
  454. $block['content'] = theme('tripal_organism_feature_browser', array('node' => $node));
  455. break;
  456. case 'library_feature_browser':
  457. $block['subject'] = t('Library Feature Browser');
  458. $block['content'] = theme('tripal_library_feature_browser', $node);
  459. break;
  460. case 'analysis_feature_browser':
  461. $block['subject'] = t('Analysis Feature Browser');
  462. $block['content'] = theme('tripal_analysis_feature_browser', $node);
  463. break;
  464. default :
  465. }
  466. return $block;
  467. }
  468. }
  469. /**
  470. * When a new chado_feature node is created we also need to add information
  471. * to our chado_feature table. This function is called on insert of a new node
  472. * of type 'chado_feature' and inserts the necessary information.
  473. *
  474. * @ingroup tripal_feature
  475. */
  476. function chado_feature_insert($node) {
  477. $node->uniquename = trim($node->uniquename);
  478. $node->fname = trim($node->fname);
  479. $node->feature_type = trim($node->feature_type);
  480. $node->residues = trim($node->residues);
  481. // remove spaces, newlines from residues
  482. $residues = preg_replace("/[\n\r\s]/", "", $node->residues);
  483. $obsolete = 'FALSE';
  484. if ($node->is_obsolete) {
  485. $obsolete = 'TRUE';
  486. }
  487. $feature_id = '';
  488. // if there is an feature_id in the $node object then this must be a sync so
  489. // we can skip adding the feature as it is already there, although
  490. // we do need to proceed with the rest of the insert
  491. if (!property_exists($node, 'feature_id')) {
  492. $values = array(
  493. 'organism_id' => $node->organism_id,
  494. 'name' => $node->fname,
  495. 'uniquename' => $node->uniquename,
  496. 'residues' => $residues,
  497. 'seqlen' => drupal_strlen($residues),
  498. 'is_obsolete' => $obsolete,
  499. 'type_id' => $type[0]->cvterm_id,
  500. 'md5checksum' => md5($residues)
  501. );
  502. $feature = tripal_core_chado_select('feature', array('*'), $values);
  503. if (!$feature) {
  504. drupal_set_message(t('Unable to add feature.'), 'warning');
  505. watchdog('tripal_feature', 'Insert feature: Unable to create feature where values: %values',
  506. array('%values' => print_r($values, TRUE)), WATCHDOG_WARNING);
  507. return;
  508. }
  509. $feature_id = $feature->feature_id;
  510. // add the genbank accession and synonyms
  511. chado_feature_add_synonyms($node->synonyms, $node->feature_id);
  512. }
  513. else {
  514. $feature_id = $node->feature_id;
  515. }
  516. // Make sure the entry for this feature doesn't already exist in the
  517. // chado_feature table if it doesn't exist then we want to add it.
  518. $check_org_id = chado_get_id_for_node('feature', $node->nid);
  519. if (!$check_org_id) {
  520. $record = new stdClass();
  521. $record->nid = $node->nid;
  522. $record->vid = $node->vid;
  523. $record->feature_id = $feature_id;
  524. drupal_write_record('chado_feature', $record);
  525. }
  526. }
  527. /**
  528. *
  529. *
  530. * @ingroup tripal_feature
  531. */
  532. function chado_feature_update($node) {
  533. $node->uniquename = trim($node->uniquename);
  534. $node->fname = trim($node->fname);
  535. $node->feature_type = trim($node->feature_type);
  536. $node->residues = trim($node->residues);
  537. if ($node->revision) {
  538. // there is no way to handle revisions in Chado but leave
  539. // this here just to make not we've addressed it.
  540. }
  541. $residues = preg_replace("/[\n\r\s]/", "", $node->residues);
  542. $obsolete = 'FALSE';
  543. if ($node->is_obsolete) {
  544. $obsolete = 'TRUE';
  545. }
  546. // get the feature type id
  547. $values = array(
  548. 'cv_id' => array(
  549. 'name' => 'sequence'
  550. ),
  551. 'name' => $node->feature_type
  552. );
  553. $type = tripal_core_chado_select('cvterm', array('cvterm_id'), $values);
  554. $feature_id = chado_get_id_for_node('feature', $node->nid) ;
  555. if (sizeof($type) > 0) {
  556. $match = array(
  557. 'feature_id' => $feature_id,
  558. );
  559. $values = array(
  560. 'organism_id' => $node->organism_id,
  561. 'name' => $node->fname,
  562. 'uniquename' => $node->uniquename,
  563. 'residues' => $residues,
  564. 'seqlen' => drupal_strlen($residues),
  565. 'is_obsolete' => $obsolete,
  566. 'type_id' => $type[0]->cvterm_id,
  567. 'md5checksum' => md5($residues)
  568. );
  569. $options = array('return_record' => TRUE);
  570. $status = tripal_core_chado_update('feature', $match, $values, $options);
  571. // add the genbank synonyms
  572. chado_feature_add_synonyms($node->synonyms, $feature_id);
  573. }
  574. else {
  575. drupal_set_message(t('Unable to update feature.'), 'warning');
  576. watchdog('tripal_feature',
  577. 'Update feature: Unable to update feature where values: %values',
  578. array('%values' => print_r($values, TRUE)),
  579. WATCHDOG_WARNING
  580. );
  581. }
  582. }
  583. /**
  584. *
  585. *
  586. * @ingroup tripal_feature
  587. */
  588. function chado_feature_delete($node) {
  589. $feature_id = chado_get_id_for_node('feature', $node->nid);
  590. // if we don't have a library id for this node then this isn't a node of
  591. // type chado_library or the entry in the chado_library table was lost.
  592. if (!$feature_id) {
  593. return;
  594. }
  595. // remove the drupal content
  596. $sql_del = "DELETE FROM {chado_feature} WHERE nid = :nid AND vid = :vid";
  597. db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
  598. $sql_del = "DELETE FROM {node} WHERE nid = :nid AND vid = :vid";
  599. db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
  600. $sql_del = "DELETE FROM {node_revision} WHERE nid = :nid AND vid = :vid";
  601. db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
  602. // Remove data from feature tables of chado database. This will
  603. // cause a cascade delete and remove all data in referencing tables
  604. // for this feature
  605. chado_query("DELETE FROM {feature} WHERE feature_id = :feature_id", array(':feature_id' => $feature_id));
  606. drupal_set_message(t("The feature and all associated data were removed from") .
  607. "chado");
  608. }
  609. /**
  610. *
  611. *
  612. * @ingroup tripal_feature
  613. */
  614. function chado_feature_add_synonyms($synonyms, $feature_id) {
  615. // separate synomys by carriage returns
  616. $synonyms = preg_replace("/[\n\r]+/", " ", $synonyms);
  617. // split the synonyms into an array based on a space as the delimieter
  618. $syn_array = array();
  619. $syn_array = explode(" ", $synonyms);
  620. // remove any old synonyms
  621. $feature_syn_dsql = "DELETE FROM {feature_synonym} WHERE feature_id = :feature_id";
  622. if (!chado_query($feature_syn_dsql, array(':feature_id' => $feature_id))) {
  623. watchdog('tripal_feature', "Could not remove synonyms from feature. ", array(), WATCHDOG_ERROR);
  624. return;
  625. }
  626. // return if we don't have any synonmys to add
  627. if (!$synonyms) {
  628. return;
  629. }
  630. // iterate through each synonym and add it to the database
  631. foreach ($syn_array as $syn) {
  632. // skip this item if it's empty
  633. if (!$syn) {
  634. break;
  635. }
  636. // check to see if we have this accession number already in the database
  637. // if so then don't add it again. it messes up drupal if the insert fails.
  638. // It is possible for the accession number to be present and not the feature
  639. $synonym_sql = "SELECT synonym_id FROM {synonym} WHERE name = :name";
  640. $synonym = chado_query($synonym_sql, array(':name' => $syn))->fetchObject();
  641. if (!$synonym) {
  642. $synonym_isql = "
  643. INSERT INTO {synonym} (name, synonym_sgml, type_id)
  644. VALUES (:name, :synonym_sgml,
  645. (SELECT cvterm_id
  646. FROM {cvterm} CVT
  647. INNER JOIN {cv} ON CVT.cv_id = CV.cv_id
  648. WHERE CV.name = 'feature_property' and CVT.name = 'synonym')
  649. )
  650. ";
  651. if (!chado_query($synonym_isql, array(':name' => $syn, ':synonym_sgml' => $syn))) {
  652. watchdog('tripal_feature', "Could not add synonym. ", array(), WATCHDOG_WARNING);
  653. return;
  654. }
  655. // now get the synonym we just added
  656. $synonym_sql = "SELECT synonym_id FROM {synonym} WHERE name = :name";
  657. $synonym = chado_query($synonym_sql, array(':name' => $syn))->fetchObject();
  658. }
  659. // now add in our new sysnonym
  660. $feature_syn_isql = "
  661. INSERT INTO {feature_synonym} (synonym_id,feature_id,pub_id)
  662. VALUES (:synonym_id, :feature_id, :pub_id)";
  663. $args = array(':synonym_id' => $synonym->synonym_id, ':feature_id' => $feature_id, ':pub_id'=> 1);
  664. if (!chado_query($feature_syn_isql, $args)) {
  665. watchdog('tripal_feature', "Could not associate synonym with feature. ", array(), WATCHDOG_WARNING);
  666. return;
  667. }
  668. }
  669. }
  670. /**
  671. * When a node is requested by the user this function is called to allow us
  672. * to add auxiliary data to the node object.
  673. *
  674. * @ingroup tripal_feature
  675. */
  676. function chado_feature_load($nodes) {
  677. foreach ($nodes as $nid => $node) {
  678. // find the feature and add in the details
  679. $feature_id = chado_get_id_for_node('feature', $nid);
  680. // build the feature variable
  681. $values = array('feature_id' => $feature_id);
  682. $feature = tripal_core_generate_chado_var('feature', $values);
  683. $nodes[$nid]->feature = $feature;
  684. // by default, the titles are saved using the unique constraint. We will
  685. // keep it the same, but remove the duplicate name if the unique name and name
  686. // are identical. This doesn't change the title saved in the database, just what is shown
  687. // to the user on the page
  688. $title_type = variable_get('chado_feature_title', 'unique_constraint');
  689. if ($title_type == 'unique_constraint') {
  690. if (strcmp($feature->name, $feature->uniquename)==0) {
  691. $node->title = $feature->name . " (" . $feature->type_id->name . ") " . $feature->organism_id->genus . " " . $feature->organism_id->species ;
  692. }
  693. // in previous version of Tripal, the feature title was simply the unique name.
  694. // so, we recreate the title just to be sure all of our feature pages are consistent
  695. else {
  696. $node->title = $feature->name . ", " . $feature->uniquename . " (" . $feature->type_id->name . ") " . $feature->organism_id->genus . " " . $feature->organism_id->species ;
  697. }
  698. }
  699. // set the title to be the feature name or uniquename as configured
  700. if ($title_type == 'feature_name') {
  701. $node->title = $feature->name;
  702. }
  703. if ($title_type == 'feature_unique_name') {
  704. $node->title = $feature->uniquename;
  705. }
  706. }
  707. }
  708. /**
  709. *
  710. *
  711. * @ingroup tripal_feature
  712. */
  713. function tripal_feature_load_featurelocs($feature_id, $side = 'as_parent', $aggregate = 1) {
  714. $sql = "
  715. SELECT
  716. F.name, F.feature_id, F.uniquename,
  717. FS.name as src_name, FS.feature_id as src_feature_id, FS.uniquename as src_uniquename,
  718. CVT.name as cvname, CVT.cvterm_id,
  719. CVTS.name as src_cvname, CVTS.cvterm_id as src_cvterm_id,
  720. FL.fmin, FL.fmax, FL.is_fmin_partial, FL.is_fmax_partial,FL.strand, FL.phase
  721. FROM {featureloc} FL
  722. INNER JOIN {feature} F ON FL.feature_id = F.feature_id
  723. INNER JOIN {feature} FS ON FS.feature_id = FL.srcfeature_id
  724. INNER JOIN {cvterm} CVT ON F.type_id = CVT.cvterm_id
  725. INNER JOIN {cvterm} CVTS ON FS.type_id = CVTS.cvterm_id
  726. ";
  727. if (strcmp($side, 'as_parent')==0) {
  728. $sql .= "WHERE FL.srcfeature_id = :feature_id ";
  729. }
  730. if (strcmp($side, 'as_child')==0) {
  731. $sql .= "WHERE FL.feature_id = :feature_id ";
  732. }
  733. $flresults = chado_query($sql, array(':feature_id' => $feature_id));
  734. // copy the results into an array
  735. $i=0;
  736. $featurelocs = array();
  737. while ($loc = $flresults->fetchObject()) {
  738. // if a drupal node exists for this feature then add the nid to the
  739. // results object
  740. $loc->fnid = chado_get_node_id('feature', $loc->feature_id);
  741. $loc->snid = chado_get_node_id('feature', $loc->src_feature_id);
  742. // add the result to the array
  743. $featurelocs[$i++] = $loc;
  744. }
  745. // Add the relationship feature locs if aggregate is turned on
  746. if ($aggregate and strcmp($side, 'as_parent')==0) {
  747. // get the relationships for this feature without substituting any children
  748. // for the parent. We want all relationships
  749. $relationships = tripal_feature_get_aggregate_relationships($feature_id, 0);
  750. foreach ($relationships as $rindex => $rel) {
  751. // get the featurelocs for each of the relationship features
  752. $rel_featurelocs = tripal_feature_load_featurelocs($rel->subject_id, 'as_child', 0);
  753. foreach ($rel_featurelocs as $findex => $rfloc) {
  754. $featurelocs[$i++] = $rfloc;
  755. }
  756. }
  757. }
  758. usort($featurelocs, 'tripal_feature_sort_locations');
  759. return $featurelocs;
  760. }
  761. /**
  762. * used to sort the feature locs by start position
  763. *
  764. * @ingroup tripal_feature
  765. */
  766. function tripal_feature_sort_locations($a, $b) {
  767. return strnatcmp($a->fmin, $b->fmin);
  768. }
  769. /**
  770. *
  771. *
  772. * @ingroup tripal_feature
  773. */
  774. function tripal_feature_load_relationships($feature_id, $side = 'as_subject') {
  775. // get the relationships for this feature. The query below is used for both
  776. // querying the object and subject relationships
  777. $sql = "
  778. SELECT
  779. FS.name as subject_name, FS.uniquename as subject_uniquename,
  780. CVTS.name as subject_type, CVTS.cvterm_id as subject_type_id,
  781. FR.subject_id, FR.type_id as relationship_type_id, FR.object_id, FR.rank,
  782. CVT.name as rel_type,
  783. FO.name as object_name, FO.uniquename as object_uniquename,
  784. CVTO.name as object_type, CVTO.cvterm_id as object_type_id
  785. FROM {feature_relationship} FR
  786. INNER JOIN {cvterm} CVT ON FR.type_id = CVT.cvterm_id
  787. INNER JOIN {feature} FS ON FS.feature_id = FR.subject_id
  788. INNER JOIN {feature} FO ON FO.feature_id = FR.object_id
  789. INNER JOIN {cvterm} CVTO ON FO.type_id = CVTO.cvterm_id
  790. INNER JOIN {cvterm} CVTS ON FS.type_id = CVTS.cvterm_id
  791. ";
  792. if (strcmp($side, 'as_object')==0) {
  793. $sql .= " WHERE FR.object_id = :feature_id";
  794. }
  795. if (strcmp($side, 'as_subject')==0) {
  796. $sql .= " WHERE FR.subject_id = :feature_id";
  797. }
  798. $sql .= " ORDER BY FR.rank";
  799. // get the relationships
  800. $results = chado_query($sql, array(':feature_id' => $feature_id));
  801. // iterate through the relationships, put these in an array and add
  802. // in the Drupal node id if one exists
  803. $i=0;
  804. $nodesql = "SELECT nid FROM {chado_feature} WHERE feature_id = :feature_id";
  805. $relationships = array();
  806. while ($rel = $results->fetchObject()) {
  807. $node = db_query($nodesql, array(':feature_id' => $rel->subject_id))->fetchObject();
  808. if ($node) {
  809. $rel->subject_nid = $node->nid;
  810. }
  811. $node = db_query($nodesql, array(':feature_id' => $rel->object_id))->fetchObject();
  812. if ($node) {
  813. $rel->object_nid = $node->nid;
  814. }
  815. $relationships[$i++] = $rel;
  816. }
  817. return $relationships;
  818. }
  819. /**
  820. *
  821. *
  822. * @ingroup tripal_feature
  823. */
  824. function tripal_feature_get_aggregate_relationships($feature_id, $substitute=1,
  825. $levels=0, $base_type_id=NULL, $depth=0) {
  826. // we only want to recurse to as many levels deep as indicated by the
  827. // $levels variable, but only if this variable is > 0. If 0 then we
  828. // recurse until we reach the end of the relationships tree.
  829. if ($levels > 0 and $levels == $depth) {
  830. return NULL;
  831. }
  832. // first get the relationships for this feature
  833. return tripal_feature_load_relationships($feature_id, 'as_object');
  834. }
  835. /**
  836. *
  837. *
  838. * @ingroup tripal_feature
  839. */
  840. function tripal_feature_load_featureloc_sequences($feature_id, $featurelocs) {
  841. // if we don't have any featurelocs then no point in continuing
  842. if (!$featurelocs) {
  843. return array();
  844. }
  845. // get the list of relationships (including any aggregators) and iterate
  846. // through each one to find information needed to color-code the reference sequence
  847. $relationships = tripal_feature_get_aggregate_relationships($feature_id);
  848. if (!$relationships) {
  849. return array();
  850. }
  851. // iterate through each of the realtionships features and get their
  852. // locations
  853. foreach ($relationships as $rindex => $rel) {
  854. // get the featurelocs for each of the relationship features
  855. $rel_featurelocs = tripal_feature_load_featurelocs($rel->subject_id, 'as_child', 0);
  856. foreach ($rel_featurelocs as $rfindex => $rel_featureloc) {
  857. // keep track of this unique source feature
  858. $src = $rel_featureloc->src_feature_id . "-" . $rel_featureloc->src_cvterm_id;
  859. // copy over the results to the relationship object. Since there can
  860. // be more than one feature location for each relationship feature we
  861. // use the '$src' variable to keep track of these.
  862. $rel->featurelocs = new stdClass();
  863. $rel->featurelocs->$src = new stdClass();
  864. $rel->featurelocs->$src->src_uniquename = $rel_featureloc->src_uniquename;
  865. $rel->featurelocs->$src->src_cvterm_id = $rel_featureloc->src_cvterm_id;
  866. $rel->featurelocs->$src->src_cvname = $rel_featureloc->src_cvname;
  867. $rel->featurelocs->$src->fmin = $rel_featureloc->fmin;
  868. $rel->featurelocs->$src->fmax = $rel_featureloc->fmax;
  869. $rel->featurelocs->$src->src_name = $rel_featureloc->src_name;
  870. // keep track of the individual parts for each relationship
  871. $start = $rel->featurelocs->$src->fmin;
  872. $end = $rel->featurelocs->$src->fmax;
  873. $type = $rel->subject_type;
  874. $rel_locs[$src]['parts'][$start][$type]['start'] = $start;
  875. $rel_locs[$src]['parts'][$start][$type]['end'] = $end;
  876. $rel_locs[$src]['parts'][$start][$type]['type'] = $type;
  877. }
  878. }
  879. // the featurelocs array provided to the function contains the locations
  880. // where this feature is found. We want to get the sequence for each
  881. // location and then annotate it with the parts found from the relationships
  882. // locations determiend above.
  883. $floc_sequences = array();
  884. foreach ($featurelocs as $featureloc) {
  885. // build the src name so we can keep track of the different parts for each feature
  886. $src = $featureloc->srcfeature_id->feature_id . "-" . $featureloc->srcfeature_id->type_id->cvterm_id;
  887. // orient the parts to the beginning of the feature sequence
  888. if (!empty($rel_locs[$src]['parts'])) {
  889. $parts = $rel_locs[$src]['parts'];
  890. $rparts = array(); // we will fill this up if we're on the reverse strand
  891. foreach ($parts as $start => $types) {
  892. foreach ($types as $type_name => $type) {
  893. if ($featureloc->strand >= 0) {
  894. // this is on the forward strand. We need to convert the start on the src feature to the
  895. // start on this feature's sequence
  896. $parts[$start][$type_name]['start'] = $parts[$start][$type_name]['start'] - $featureloc->fmin;
  897. $parts[$start][$type_name]['end'] = $parts[$start][$type_name]['end'] - $featureloc->fmin;
  898. $parts[$start][$type_name]['type'] = $type_name;
  899. }
  900. else {
  901. // this is on the reverse strand. We need to swap the start and stop and calculate from the
  902. // begining of the reverse sequence
  903. $size = ($featureloc->fmax - $featureloc->fmin);
  904. $start_orig = $parts[$start][$type_name]['start'];
  905. $end_orig = $parts[$start][$type_name]['end'];
  906. $new_start = $size - ($end_orig - $featureloc->fmin);
  907. $new_end = $size - ($start_orig - $featureloc->fmin);
  908. $rparts[$new_start][$type_name]['start'] = $new_start;
  909. $rparts[$new_start][$type_name]['end'] = $new_end;
  910. $rparts[$new_start][$type_name]['type'] = $type_name;
  911. }
  912. }
  913. }
  914. // now sort the parts
  915. // if we're on the reverse strand we need to resort
  916. if ($featureloc->strand >= 0) {
  917. usort($parts, 'tripal_feature_sort_rel_parts_by_start');
  918. }
  919. else {
  920. usort($rparts, 'tripal_feature_sort_rel_parts_by_start');
  921. $parts = $rparts;
  922. }
  923. $floc_sequences[$src]['src'] = $src;
  924. $floc_sequences[$src]['type'] = $featureloc->feature_id->type_id->name;
  925. $args = array(':feature_id' => $featureloc->srcfeature_id->feature_id);
  926. $start = $featureloc->fmin + 1;
  927. $size = $featureloc->fmax - $featureloc->fmin;
  928. // TODO: fix the hard coded $start and $size
  929. // the $start and $size variables are hard-coded in the SQL statement
  930. // because the db_query function places quotes around all placeholders
  931. // (e.g. :start & :size) and screws up the substring function
  932. $sql = "
  933. SELECT substring(residues from $start for $size) as residues
  934. FROM {feature}
  935. WHERE feature_id = :feature_id
  936. ";
  937. $sequence = chado_query($sql, $args)->fetchObject();
  938. $residues = $sequence->residues;
  939. if ($featureloc->strand < 0) {
  940. $residues = tripal_feature_reverse_complement($residues);
  941. }
  942. $strand = '.';
  943. if ($featureloc->strand == 1) {
  944. $strand = '+';
  945. }
  946. elseif ($featureloc->strand == -1) {
  947. $strand = '-';
  948. }
  949. $defline = $featureloc->feature_id->name . " " . $featureloc->srcfeature_id->name . ":" . ($featureloc->fmin + 1) . ".." . $featureloc->fmax . " " . $strand;
  950. $floc_sequences[$src]['formatted_seq'] = tripal_feature_color_sequence($residues, $parts, $defline);
  951. }
  952. }
  953. return $floc_sequences;
  954. }
  955. /**
  956. *
  957. *
  958. * @ingroup tripal_feature
  959. */
  960. function tripal_feature_get_matched_alignments($feature) {
  961. // This function is for features that align through an intermediate such
  962. // as 'EST_match' or 'match'. This occurs in the case where two sequences
  963. // align but where one does not align perfectly. Some ESTs may be in a contig
  964. // but not all of the EST. Portions may overhang and not be included in the
  965. // consensus if quality is bad.
  966. // For example:
  967. //
  968. // Feature 1: Contig --------------------
  969. // Feature 2: EST_match -------
  970. // Feature 3: EST ---------
  971. //
  972. // The feature provided to the function will always be the feature 1. The
  973. // featureloc columns prefixed with 'right' (e.g. right_fmin) belong to the
  974. // alignment of feature 3 with feature 2
  975. //
  976. // Features may align to more than one feature and are not matches. We do
  977. // not want to include these, so we have to filter on the SO terms:
  978. // match, or %_match
  979. //
  980. $sql = "
  981. SELECT
  982. FL1.featureloc_id as left_featureloc_id,
  983. FL1.srcfeature_id as left_srcfeature_id,
  984. FL1.feature_id as left_feature_id,
  985. FL1.fmin as left_fmin,
  986. FL1.is_fmin_partial as left_is_fmin_partial,
  987. FL1.fmax as left_fmax,
  988. FL1.is_fmax_partial as left_is_fmax_partial,
  989. FL1.strand as left_strand,
  990. FL1.phase as left_phase,
  991. FL1.locgroup as left_locgroup,
  992. FL1.rank as left_rank,
  993. FL2.featureloc_id as right_featureloc_id,
  994. FL2.srcfeature_id as right_srcfeature_id,
  995. FL2.feature_id as right_feature_id,
  996. FL2.fmin as right_fmin,
  997. FL2.is_fmin_partial as right_is_fmin_partial,
  998. FL2.fmax as right_fmax,
  999. FL2.is_fmax_partial as right_is_fmax_partial,
  1000. FL2.strand as right_strand,
  1001. FL2.phase as right_phase,
  1002. FL2.locgroup as right_locgroup,
  1003. FL2.rank as right_rank
  1004. FROM {feature} F1
  1005. INNER JOIN {featureloc} FL1 on FL1.srcfeature_id = F1.feature_id
  1006. INNER JOIN {feature} F2 on FL1.feature_id = F2.feature_id
  1007. INNER JOIN {featureloc} FL2 on FL2.feature_id = F2.feature_id
  1008. INNER JOIN {cvterm} CVT2 on F2.type_id = CVT2.cvterm_id
  1009. WHERE
  1010. F1.feature_id = :feature_id AND
  1011. (CVT2.name = 'match' or CVT2.name like '%_match')
  1012. ORDER BY FL1.fmin
  1013. ";
  1014. $results = chado_query($sql, array(':feature_id' => $feature->feature_id));
  1015. // iterate through the results and add them to our featurelocs array
  1016. $featurelocs = array();
  1017. while ($fl = $results->fetchObject()) {
  1018. // ignore featurelocs where the left and right srcfeature is the same
  1019. if (strcmp($fl->left_srcfeature_id, $fl->right_srcfeature_id) == 0) {
  1020. continue;
  1021. }
  1022. $featurelocs[] = $fl ;
  1023. }
  1024. return $featurelocs;
  1025. }
  1026. /**
  1027. *
  1028. *
  1029. * @ingroup tripal_feature
  1030. */
  1031. function tripal_feature_load_organism_feature_counts($organism) {
  1032. // don't show the browser if the settings in the admin page is turned off
  1033. // instead return the array indicating the status of the browser
  1034. $show_counts = variable_get('tripal_feature_summary_setting', 'show_feature_summary');
  1035. if (strcmp($show_counts, 'show_feature_summary')!=0) {
  1036. return array('enabled' => FALSE );
  1037. }
  1038. $args = array();
  1039. $names = array();
  1040. $order = array();
  1041. // build the where clause for the SQL statement if we have a custom term list
  1042. // we'll also keep track of the names the admin provided (if any) and the
  1043. // order that the terms should appear.
  1044. $is_custom = 0;
  1045. $temp = rtrim(variable_get('tripal_feature_summary_report_mapping', ''));
  1046. $where = '';
  1047. if ($temp) {
  1048. $is_custom = 1;
  1049. $temp = explode("\n", $temp);
  1050. $i = 0;
  1051. foreach ($temp as $key => $value) {
  1052. // separate the key value pairs
  1053. $temp2 = explode("=", $value);
  1054. $feature_type = rtrim($temp2[0]);
  1055. $args[] = $feature_type;
  1056. $order[] = $feature_type;
  1057. // if a new name is provided then use that otherwise just
  1058. // use the feature type
  1059. if (count($temp2) == 2) {
  1060. $names[":name$i"] = rtrim($temp2[1]);
  1061. }
  1062. else {
  1063. $names[":name$i"] = $feature_type;
  1064. }
  1065. $where .= " OFC.feature_type = :name$i OR ";
  1066. $i++;
  1067. }
  1068. if ($where) {
  1069. $where = drupal_substr($where, 0, -5); # remove OR from the end
  1070. $where = "($where) AND";
  1071. }
  1072. }
  1073. // get the feature counts. This is dependent on a materialized view
  1074. // installed with the organism module
  1075. $sql = "
  1076. SELECT OFC.num_features,OFC.feature_type,CVT.definition
  1077. FROM {organism_feature_count} OFC
  1078. INNER JOIN {cvterm} CVT on OFC.cvterm_id = CVT.cvterm_id
  1079. WHERE $where organism_id = :organism_id
  1080. ORDER BY num_features desc
  1081. ";
  1082. $args[':organism_id'] = $organism->organism_id;
  1083. $org_features = chado_query($sql, $args);
  1084. // iterate through the types
  1085. $types = array();
  1086. while ($type = $org_features->fetchObject()) {
  1087. $types[$type->feature_type] = $type;
  1088. // if we don't have an order this means we didn't go through the loop
  1089. // above to set the names, so do that now
  1090. if (!$is_custom) {
  1091. $names[] = $type->feature_type;
  1092. $order[] = $type->feature_type;
  1093. }
  1094. }
  1095. # now reorder the types
  1096. $ordered_types = array();
  1097. foreach ($order as $type) {
  1098. $ordered_types[] = $types[$type];
  1099. }
  1100. return array( 'types' => $ordered_types, 'names' => $names, 'enabled' => TRUE );
  1101. }
  1102. /**
  1103. * used to sort the list of relationship parts by start position
  1104. *
  1105. * @ingroup tripal_feature
  1106. */
  1107. function tripal_feature_sort_rel_parts_by_start($a, $b) {
  1108. foreach ($a as $type_name => $details) {
  1109. $astart = $a[$type_name]['start'];
  1110. break;
  1111. }
  1112. foreach ($b as $type_name => $details) {
  1113. $bstart = $b[$type_name]['start'];
  1114. break;
  1115. }
  1116. return strnatcmp($astart, $bstart);
  1117. }
  1118. /**
  1119. * used to sort the list of relationship parts by start position
  1120. *
  1121. * @ingroup tripal_feature
  1122. */
  1123. function tripal_feature_sort_rel_parts_by_end($a, $b) {
  1124. $val = strnatcmp($b['end'], $a['end']);
  1125. if ($val == 0) {
  1126. return strcmp($a['type'], $b['type']);
  1127. }
  1128. return $val;
  1129. }
  1130. /**
  1131. *
  1132. *
  1133. * @ingroup tripal_feature
  1134. */
  1135. function tripal_feature_color_sequence($sequence, $parts, $defline) {
  1136. $types = array();
  1137. // first get the list of types so we can create a color legend
  1138. foreach ($parts as $index => $t) {
  1139. foreach ($t as $type_name => $details) {
  1140. $types[$type_name] = 1;
  1141. }
  1142. }
  1143. $newseq = "<div id=\"tripal_feature-featureloc_sequence-legend\">Legend: ";
  1144. foreach ($types as $type_name => $present) {
  1145. $newseq .= "<span id=\"tripal_feature-legend-$type_name\" class=\"tripal_feature-legend-item tripal_feature-featureloc_sequence-$type_name\" script=\"\">$type_name</span>";
  1146. }
  1147. $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.";
  1148. // set the background color of the rows based on the type
  1149. $pos = 0;
  1150. $newseq .= "<pre id=\"tripal_feature-featureloc_sequence\">";
  1151. $newseq .= ">$defline\n";
  1152. // iterate through the parts. They should be in order.
  1153. $ends = array();
  1154. $seqcount = 0;
  1155. foreach ($parts as $index => $types) {
  1156. // get the start for this part. All types in this part start at the
  1157. // same position so we only need the first record
  1158. foreach ($types as $type => $child) {
  1159. $start = $child['start'];
  1160. break;
  1161. }
  1162. // add in the sequence up to the start of this part
  1163. for ($i = $pos; $i < $start; $i++) {
  1164. $newseq .= $sequence{$pos};
  1165. $seqcount++;
  1166. if ($seqcount % 50 == 0) {
  1167. $newseq .= "\n";
  1168. }
  1169. if (array_key_exists($pos, $ends)) {
  1170. foreach ($ends[$pos] as $end) {
  1171. $newseq .= "</span>";
  1172. }
  1173. }
  1174. $pos++;
  1175. }
  1176. // we want to sort the parts by their end. We want the span tag to
  1177. // to be added in the order the parts end.
  1178. usort($types, 'tripal_feature_sort_rel_parts_by_end');
  1179. // now add the child span for all types that start at this position
  1180. foreach ($types as $type) {
  1181. $class = "tripal_feature-featureloc_sequence-" . $type['type'];
  1182. $newseq .= "<span class=\"$class\">";
  1183. // add the end position
  1184. $end = $type['end'];
  1185. $ends[$end][] = $end;
  1186. }
  1187. }
  1188. // add in rest of the sequence
  1189. for ($i = $pos; $i < strlen($sequence); $i++) {
  1190. $newseq .= $sequence{$pos};
  1191. $seqcount++;
  1192. if ($seqcount % 50 == 0) {
  1193. $newseq .= "\n";
  1194. }
  1195. if (array_key_exists($pos, $ends)) {
  1196. foreach ($ends[$pos] as $end) {
  1197. $newseq .= "</span>";
  1198. }
  1199. }
  1200. $pos++;
  1201. }
  1202. $newseq .= "</pre>";
  1203. return $newseq;
  1204. }
  1205. /**
  1206. *
  1207. * @ingroup tripal_feature
  1208. */
  1209. function tripal_feature_node_presave($node) {
  1210. // set the title to ensure it is always unique
  1211. switch ($node->type) {
  1212. case 'chado_feature':
  1213. $values = array('organism_id' => $node->organism_id);
  1214. $organism = tripal_core_chado_select('organism', array('genus', 'species'), $values);
  1215. $node->title = $node->fname . ', ' . $node->uniquename . ' (' . $node->feature_type . ') ' . $organism[0]->genus . ' ' . $organism[0]->species;
  1216. break;
  1217. }
  1218. }
  1219. /**
  1220. *
  1221. * @ingroup tripal_feature
  1222. */
  1223. function tripal_feature_node_insert($node) {
  1224. // set the URL path after inserting. We do it here because we do not
  1225. // know the feature_id in the presave
  1226. switch ($node->type) {
  1227. case 'chado_feature':
  1228. if (!$node->feature_id) {
  1229. $sql = "SELECT * FROM {chado_feature} WHERE nid = :nid";
  1230. $chado_feature = db_query($sql, array(':nid' => $node->nid))->fetchObject();
  1231. $node->feature_id = $chado_feature->feature_id;
  1232. }
  1233. // remove any previous alias
  1234. db_query("DELETE FROM {url_alias} WHERE source = :source", array(':source' => "node/$node->nid"));
  1235. // set the URL for this feature page
  1236. $url_alias = tripal_feature_get_feature_url($node);
  1237. $path_alias = array("source" => "node/$node->nid", "alias" => $url_alias);
  1238. path_save($path_alias);
  1239. break;
  1240. }
  1241. }
  1242. /**
  1243. *
  1244. * @ingroup tripal_feature
  1245. */
  1246. function tripal_feature_node_view($node, $view_mode, $langcode) {
  1247. switch ($node->type) {
  1248. case 'chado_feature':
  1249. // Show feature browser and counts
  1250. if ($view_mode == 'full') {
  1251. $node->content['tripal_feature_alignments'] = array(
  1252. '#value' => theme('tripal_feature_alignments', array('node' => $node)),
  1253. );
  1254. $node->content['tripal_feature_analyses'] = array(
  1255. '#value' => theme('tripal_feature_analyses', array('node' => $node)),
  1256. );
  1257. $node->content['tripal_feature_base'] = array(
  1258. '#value' => theme('tripal_feature_base', array('node' => $node)),
  1259. );
  1260. $node->content['tripal_feature_featurepos'] = array(
  1261. '#value' => theme('tripal_feature_featurepos', array('node' => $node)),
  1262. );
  1263. $node->content['tripal_feature_properties'] = array(
  1264. '#value' => theme('tripal_feature_properties', array('node' => $node)),
  1265. );
  1266. $node->content['tripal_feature_publications'] = array(
  1267. '#value' => theme('tripal_feature_properties', array('node' => $node)),
  1268. );
  1269. $node->content['tripal_feature_references'] = array(
  1270. '#value' => theme('tripal_feature_references', array('node' => $node)),
  1271. );
  1272. $node->content['tripal_feature_relationships'] = array(
  1273. '#value' => theme('tripal_feature_relationships', array('node' => $node)),
  1274. );
  1275. $node->content['tripal_feature_seqence'] = array(
  1276. '#value' => theme('tripal_feature_sequence', array('node' => $node)),
  1277. );
  1278. $node->content['tripal_feature_synonyms'] = array(
  1279. '#value' => theme('tripal_feature_synonyms', array('node' => $node)),
  1280. );
  1281. $node->content['tripal_feature_terms'] = array(
  1282. '#value' => theme('tripal_feature_terms', array('node' => $node)),
  1283. );
  1284. }
  1285. if ($view_mode == 'teaser') {
  1286. $node->content['tripal_feature_teaser'] = array(
  1287. '#value' => theme('tripal_feature_teaser', array('node' => $node)),
  1288. );
  1289. }
  1290. break;
  1291. case 'chado_organism':
  1292. // Show feature browser and counts
  1293. if ($view_mode == 'full') {
  1294. $node->content['tripal_organism_feature_counts'] = array(
  1295. '#value' => theme('tripal_organism_feature_counts', array('node' => $node)),
  1296. );
  1297. $node->content['tripal_organism_feature_browser'] = array(
  1298. '#value' => theme('tripal_organism_feature_browser', array('node' => $node)),
  1299. );
  1300. }
  1301. break;
  1302. // TODO: handle these node types. Should we also have a feature browser?
  1303. case 'chado_library':
  1304. break;
  1305. case 'chado_stock':
  1306. break;
  1307. case 'chado_analysis':
  1308. break;
  1309. }
  1310. }
  1311. /**
  1312. *
  1313. * @ingroup tripal_feature
  1314. */
  1315. function tripal_feature_node_update($node) {
  1316. // add items to other nodes, build index and search results
  1317. switch ($node->type) {
  1318. case 'chado_feature':
  1319. // remove any previous alias
  1320. db_query("DELETE FROM {url_alias} WHERE source = :source", array(':source' => "node/$node->nid"));
  1321. // set the URL for this feature page
  1322. $url_alias = tripal_feature_get_feature_url($node);
  1323. $path_alias = array("source" => "node/$node->nid", "alias" => $url_alias);
  1324. path_save($path_alias);
  1325. break;
  1326. }
  1327. }
  1328. /**
  1329. *
  1330. *
  1331. * @ingroup tripal_feature
  1332. */
  1333. function tripal_feature_cv_chart($chart_id) {
  1334. // we only want the chart to show feature types setup by the admin
  1335. $temp = rtrim(variable_get('tripal_feature_summary_report_mapping', ''));
  1336. $where = '';
  1337. if ($temp) {
  1338. $temp = explode("\n", $temp);
  1339. foreach ($temp as $key => $value) {
  1340. $temp2 = explode("=", $value);
  1341. $feature_type = rtrim($temp2[0]);
  1342. $where .= "CNT.feature_type = '$feature_type' OR \n";
  1343. }
  1344. if ($where) {
  1345. $where = drupal_substr($where, 0, -5); # remove OR from the end
  1346. $where = "($where) AND";
  1347. }
  1348. }
  1349. $organism_id = preg_replace("/^tripal_feature_cv_chart_(\d+)$/", "$1", $chart_id);
  1350. // The CV module will create the JSON array necessary for buillding a
  1351. // pie chart using jgChart and Google Charts. We have to pass to it
  1352. // a table that contains count information, tell it which column
  1353. // contains the cvterm_id and provide a filter for getting the
  1354. // results we want from the table.
  1355. $options = array(
  1356. count_mview => 'organism_feature_count',
  1357. cvterm_id_column => 'cvterm_id',
  1358. count_column => 'num_features',
  1359. size => '550x200',
  1360. filter => "$where CNT.organism_id = $organism_id",
  1361. );
  1362. return $options;
  1363. }
  1364. /**
  1365. *
  1366. *
  1367. * @ingroup tripal_feature
  1368. */
  1369. function tripal_feature_cv_tree($tree_id) {
  1370. // The CV module will create the JSON array necessary for buillding a
  1371. // pie chart using jgChart and Google Charts. We have to pass to it
  1372. // a table that contains count information, tell it which column
  1373. // contains the cvterm_id and provide a filter for getting the
  1374. // results we want from the table.
  1375. $organism_id = preg_replace("/^tripal_feature_cv_tree_(\d+)$/", "$1", $tree_id);
  1376. $options = array(
  1377. cv_id => tripal_cv_get_cv_id('sequence'),
  1378. count_mview => 'organism_feature_count',
  1379. cvterm_id_column => 'cvterm_id',
  1380. count_column => 'num_features',
  1381. filter => "CNT.organism_id = $organism_id",
  1382. label => 'Features',
  1383. );
  1384. return $options;
  1385. }
  1386. /**
  1387. *
  1388. *
  1389. * @ingroup tripal_feature
  1390. */
  1391. function tripal_feature_del_vocabulary() {
  1392. //include the file containing the required functions for adding taxonomy vocabs
  1393. module_load_include('inc', 'taxonomy', 'taxonomy.admin');
  1394. // get the vocabularies
  1395. $vocabularies = taxonomy_get_vocabularies();
  1396. // These taxonomic terms are hard coded because we
  1397. // know we have these relationships in the chado tables
  1398. // through foreign key relationships. The tripal
  1399. // modules that correspond to these chado "modules" don't
  1400. // need to be installed for the taxonomy to work.
  1401. foreach ($vocabularies as $vocab) {
  1402. if ($vocab->name == 'Feature Type') {
  1403. taxonomy_vocabulary_delete($vocab->vid);
  1404. }
  1405. if ($vocab->name == 'Organism') {
  1406. taxonomy_vocabulary_delete($vocab->vid);
  1407. }
  1408. if ($vocab->name == 'Library') {
  1409. taxonomy_vocabulary_delete($vocab->vid);
  1410. }
  1411. if ($vocab->name == 'Analysis') {
  1412. taxonomy_vocabulary_delete($vocab->vid);
  1413. }
  1414. }
  1415. }
  1416. /**
  1417. *
  1418. *
  1419. * @ingroup tripal_feature
  1420. */
  1421. function tripal_feature_job_describe_args($callback, $args) {
  1422. $new_args = array();
  1423. if ($callback == 'tripal_feature_load_fasta') {
  1424. $new_args['FASTA file'] = $args[0];
  1425. $organism = tripal_core_chado_select('organism', array('genus', 'species'), array('organism_id' => $args[1]));
  1426. $new_args['Organism'] = $organism[0]->genus . " " . $organism[0]->species;
  1427. $new_args['Sequence Type'] = $args[2];
  1428. $new_args['Name Match Type'] = $args[14];
  1429. $new_args['Name RE'] = $args[4];
  1430. $new_args['Unique Name RE'] = $args[5];
  1431. // add in the relationship arguments
  1432. $new_args['Relationship Type'] = $args[8];
  1433. $new_args['Relationship Parent RE'] = $args[9];
  1434. $new_args['Relationship Parent Type'] = $args[10];
  1435. // add in the database reference arguments
  1436. if ($args[7]) {
  1437. $db = tripal_core_chado_select('db', array('name'), array('db_id' => $args[7]));
  1438. }
  1439. $new_args['Database Reference'] = $db[0]->name;
  1440. $new_args['Accession RE'] = $args[6];
  1441. $new_args['Method'] = $args[11];
  1442. // add in the analysis
  1443. if ($args[13]) {
  1444. $analysis = tripal_core_chado_select('analysis', array('name'), array('analysis_id' => $args[13]));
  1445. }
  1446. $new_args['Analysis'] = $analysis[0]->name;
  1447. }
  1448. if ($callback == 'tripal_feature_delete_features') {
  1449. if ($args[0]) {
  1450. $organism = tripal_core_chado_select('organism', array('genus', 'species'), array('organism_id' => $args[0]));
  1451. $new_args['Organism'] = $organism[0]->genus . " " . $organism[0]->species;
  1452. }
  1453. else {
  1454. $new_args['Organism'] = '';
  1455. }
  1456. if ($args[1]) {
  1457. $analysis = tripal_core_chado_select('analysis', array('name'), array('analysis_id' => $args[1]));
  1458. $new_args['Analysis'] = $analysis[0]->name;
  1459. }
  1460. else {
  1461. $new_args['Analysis'] = '';
  1462. }
  1463. $new_args['Sequence Type'] = $args[2];
  1464. $new_args['Is Unique Name'] = $args[3];
  1465. $new_args['Features Names'] = $args[4];
  1466. }
  1467. elseif ($callback == 'tripal_feature_load_gff3') {
  1468. $new_args['GFF File'] = $args[0];
  1469. $organism = tripal_core_chado_select('organism', array('genus', 'species'), array('organism_id' => $args[1]));
  1470. $new_args['Organism'] = $organism[0]->genus . " " . $organism[0]->species;
  1471. $analysis = tripal_core_chado_select('analysis', array('name'), array('analysis_id' => $args[2]));
  1472. $new_args['Analysis'] = $analysis[0]->name;
  1473. $new_args['Use a Transaction'] = ($args[7] == 1) ? "Yes" : "No";
  1474. $new_args['Import only new features'] = ($args[3] == 1) ? "Yes" : "No";
  1475. $new_args['Import all and update'] = ($args[4] == 1) ? "Yes" : "No";
  1476. $new_args['Import all and replace'] = ($args[5] == 1) ? "Yes" : "No";
  1477. $new_args['Delete features'] = ($args[6] == 1) ? "Yes" : "No";
  1478. if ($args[8]) {
  1479. $target_organism = tripal_core_chado_select('organism', array('genus', 'species'), array('organism_id' => $args[8]));
  1480. $new_args['Target organism'] = $target_organism[0]->genus . " " . $target_organism[0]->species;
  1481. }
  1482. else {
  1483. $new_args['Target organism'] = '';
  1484. }
  1485. $new_args['Target type'] = $args[9];
  1486. $new_args['Create target'] = ($args[10] == 1) ? "Yes" : "No";
  1487. $new_args['Starting line'] = $args[11];
  1488. $new_args['Landmark Type'] = $args[12];
  1489. $new_args['Alternate ID attribute'] = $args[13];
  1490. $new_args['Create Organism'] = ($args[14] == 1) ? "Yes" : "No";
  1491. }
  1492. if ($callback == 'tripal_feature_sync_features') {
  1493. if ($args[0]) {
  1494. $organism = tripal_core_chado_select('organism', array('genus', 'species'), array('organism_id' => $args[0]));
  1495. $new_args['Organism'] = $organism[0]->genus . " " . $organism[0]->species;
  1496. }
  1497. else {
  1498. $new_args['Organism'] = '';
  1499. }
  1500. $new_args['Feature Types'] = $args[1];
  1501. }
  1502. return $new_args;
  1503. }
  1504. /**
  1505. * Implements hook_coder_ignore().
  1506. * Defines the path to the file (tripal_core.coder_ignores.txt) where ignore rules for coder are stored
  1507. */
  1508. function tripal_feature_coder_ignore() {
  1509. return array(
  1510. 'path' => drupal_get_path('module', 'tripal_feature'),
  1511. 'line prefix' => drupal_get_path('module', 'tripal_feature'),
  1512. );
  1513. }
  1514. /*
  1515. * Uses the value provided in the $id argument to find all features that match
  1516. * that ID by name, featurename or synonym. If it matches uniquenly to a single
  1517. * feature it will redirect to that feature page, otherwise, a list of matching
  1518. * features is shown.
  1519. */
  1520. function tripal_feature_match_features_page($id) {
  1521. // if the URL alias configuration is set such that the URL
  1522. // always begins with 'feature' then we want to use the ID as it is and
  1523. // forward it on. Otherwise, try to find the matching feature.
  1524. $url_alias = variable_get('chado_feature_url_string', '/feature/[genus]/[species]/[type]/[uniquename]');
  1525. if (!$url_alias) {
  1526. $url_alias = '/feature/[genus]/[species]/[type]/[uniquename]';
  1527. }
  1528. $url_alias = preg_replace('/^\//', '', $url_alias); // remove any preceeding forward slash
  1529. if (preg_match('/^feature\//', $url_alias)) {
  1530. drupal_goto($id);
  1531. }
  1532. $sql = "
  1533. SELECT
  1534. F.name, F.uniquename, F.feature_id,
  1535. O.genus, O.species, O.organism_id,
  1536. CVT.cvterm_id, CVT.name as type_name,
  1537. CF.nid,
  1538. array_agg(S.name) as synonyms
  1539. FROM {feature} F
  1540. INNER JOIN {organism} O on F.organism_id = O.organism_id
  1541. INNER JOIN {cvterm} CVT on CVT.cvterm_id = F.type_id
  1542. LEFT JOIN {feature_synonym} FS on FS.feature_id = F.feature_id
  1543. LEFT JOIN {synonym} S on S.synonym_id = FS.synonym_id
  1544. INNER JOIN public.chado_feature CF on CF.feature_id = F.feature_id
  1545. WHERE
  1546. F.uniquename = :uname or
  1547. F.name = :fname' or
  1548. S.name = :sname
  1549. GROUP BY F.name, F.uniquename, F.feature_id, O.genus, O.species,
  1550. O.organism_id, CVT.cvterm_id, CVT.name, CF.nid
  1551. ";
  1552. $results = chado_query($sql, array(':uname' => $id, ':fname' => $id, ':sname' => $id));
  1553. $num_matches = 0;
  1554. // iterate through the matches and build the table for showing matches
  1555. $header = array('Uniquename', 'Name', 'Type', 'Species', 'Synonyms');
  1556. $rows = array();
  1557. $curr_match;
  1558. while ($match = $results->fetchObject()) {
  1559. $curr_match = $match;
  1560. $synonyms = $match->synonyms;
  1561. $synonyms = preg_replace('/[\"\{\}]/', '', $synonyms);
  1562. $rows[] = array(
  1563. $match->uniquename,
  1564. "<a href=\"" . url("node/" . $match->nid) . "\">" . $match->name . "</a>",
  1565. $match->type_name,
  1566. '<i>' . $match->genus . ' ' . $match->species . '</i>',
  1567. $synonyms,
  1568. );
  1569. $num_matches++;
  1570. }
  1571. // if we have more than one match then generate the table, otherwise, redirect
  1572. // to the matched feature
  1573. if ($num_matches == 1) {
  1574. drupal_goto("node/" . $curr_match->nid);
  1575. }
  1576. if ($num_matches == 0) {
  1577. return "<p>No features matched the given name '$id'</p>";
  1578. }
  1579. $table_attrs = array(
  1580. 'class' => 'tripal-table tripal-table-horz'
  1581. );
  1582. $output = "<p>The following features match the name '$id'.</p>";
  1583. $output .= theme_table($header, $rows, $table_attrs, $caption);
  1584. return $output;
  1585. }
  1586. /**
  1587. * Implementation of hook_form_alter()
  1588. *
  1589. * @param $form
  1590. * @param $form_state
  1591. * @param $form_id
  1592. */
  1593. function tripal_feature_form_alter(&$form, &$form_state, $form_id) {
  1594. if ($form_id == "tripal_feature_seq_extract_form") {
  1595. // updating the form through the ahah callback sets the action of
  1596. // the form to the ahah callback URL. We need to set it back
  1597. // to the normal form URL
  1598. $form['#action'] = url("find/sequences");
  1599. }
  1600. // turn off preview button for insert/updates
  1601. if ($form_id == "chado_feature_node_form") {
  1602. $form['actions']['preview']['#access'] = FALSE;
  1603. }
  1604. }