tripal_feature.module 96 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835
  1. <?php
  2. /**
  3. * @file
  4. * @todo Add file header description
  5. */
  6. /**
  7. * @defgroup tripal_feature Feature
  8. * @{
  9. * Provides functions for managing chado features including creating details pages for each feature
  10. * @}
  11. * @ingroup tripal_modules
  12. */
  13. require_once "includes/tripal_feature.admin.inc";
  14. require_once "includes/syncFeatures.inc";
  15. require_once "includes/indexFeatures.inc";
  16. require_once "includes/fasta_loader.inc";
  17. require_once "includes/gff_loader.inc";
  18. require_once "api/tripal_feature.api.inc";
  19. require_once "includes/tripal_feature-delete.inc";
  20. require_once "includes/tripal_feature-secondary_tables.inc";
  21. require_once "includes/tripal_feature-properties.inc";
  22. require_once "includes/tripal_feature-relationships.inc";
  23. require_once "includes/tripal_feature-db_references.inc";
  24. /**
  25. *
  26. * @ingroup tripal_feature
  27. */
  28. function tripal_feature_init() {
  29. // add the jGCharts JS and CSS
  30. drupal_add_js(drupal_get_path('theme', 'tripal') . '/js/tripal_feature.js');
  31. drupal_add_js(drupal_get_path('theme', 'tripal') . '/js/jgcharts/jgcharts.js');
  32. drupal_add_css(drupal_get_path('theme', 'tripal') .
  33. '/css/tripal_feature.css');
  34. }
  35. /**
  36. * Implements hook_views_api()
  37. *
  38. * Purpose: Essentially this hook tells drupal that there is views support for
  39. * for this module which then includes tripal_db.views.inc where all the
  40. * views integration code is
  41. *
  42. * @ingroup tripal_feature
  43. */
  44. function tripal_feature_views_api() {
  45. return array(
  46. 'api' => 2.0,
  47. );
  48. }
  49. /**
  50. * Display help and module information
  51. *
  52. * @param
  53. * path which path of the site we're displaying help
  54. * @param
  55. * arg array that holds the current path as would be returned from arg() function
  56. *
  57. * @return
  58. * help text for the path
  59. *
  60. * @ingroup tripal_feature
  61. */
  62. function tripal_feature_help($path, $arg) {
  63. $output = '';
  64. switch ($path) {
  65. case "admin/help#tripal_feature":
  66. $output='<p>' . t("Displays links to nodes created on this date") . '</p>';
  67. break;
  68. }
  69. return $output;
  70. }
  71. /**
  72. * Provide information to drupal about the node types that we're creating
  73. * in this module
  74. *
  75. * @ingroup tripal_feature
  76. */
  77. function tripal_feature_node_info() {
  78. $nodes = array();
  79. $nodes['chado_feature'] = array(
  80. 'name' => t('Feature'),
  81. 'module' => 'chado_feature',
  82. 'description' => t('A feature from the chado database'),
  83. 'has_title' => FALSE,
  84. 'title_label' => t('Feature'),
  85. 'has_body' => FALSE,
  86. 'body_label' => t('Feature Description'),
  87. 'locked' => TRUE
  88. );
  89. return $nodes;
  90. }
  91. /**
  92. * Set the permission types that the chado module uses. Essentially we
  93. * want permissionis that protect creation, editing and deleting of chado
  94. * data objects
  95. *
  96. * @ingroup tripal_feature
  97. */
  98. function tripal_feature_perm() {
  99. return array(
  100. 'access chado_feature content',
  101. 'create chado_feature content',
  102. 'delete chado_feature content',
  103. 'edit chado_feature content',
  104. 'manage chado_feature aggregator',
  105. );
  106. }
  107. /**
  108. * Set the permission types that the module uses.
  109. *
  110. * @ingroup tripal_feature
  111. */
  112. function chado_feature_access($op, $node, $account) {
  113. if ($op == 'create') {
  114. if (!user_access('create chado_feature content', $account)) {
  115. return FALSE;
  116. }
  117. }
  118. if ($op == 'update') {
  119. if (!user_access('edit chado_feature content', $account)) {
  120. return FALSE;
  121. }
  122. }
  123. if ($op == 'delete') {
  124. if (!user_access('delete chado_feature content', $account)) {
  125. return FALSE;
  126. }
  127. }
  128. if ($op == 'view') {
  129. if (!user_access('access chado_feature content', $account)) {
  130. return FALSE;
  131. }
  132. }
  133. return NULL;
  134. }
  135. /**
  136. * Menu items are automatically added for the new node types created
  137. * by this module to the 'Create Content' Navigation menu item. This function
  138. * adds more menu items needed for this module.
  139. *
  140. * @ingroup tripal_feature
  141. */
  142. function tripal_feature_menu() {
  143. $items = array();
  144. // the administative settings menu
  145. $items['admin/tripal/tripal_feature'] = array(
  146. 'title' => 'Features',
  147. 'description' => 'Basic Description of Tripal Organism Module Functionality',
  148. 'page callback' => 'tripal_feature_module_description_page',
  149. 'access arguments' => array('administer site configuration'),
  150. 'type' => MENU_NORMAL_ITEM,
  151. );
  152. $items['admin/tripal/tripal_feature/configuration'] = array(
  153. 'title' => 'Feature Configuration',
  154. 'description' => 'Settings for Chado Features',
  155. 'page callback' => 'drupal_get_form',
  156. 'page arguments' => array('tripal_feature_admin'),
  157. 'access arguments' => array('administer site configuration'),
  158. 'type' => MENU_NORMAL_ITEM,
  159. );
  160. $items['admin/tripal/tripal_feature/fasta_loader'] = array(
  161. 'title' => 'Import a multi-FASTA file',
  162. 'description' => 'Load sequences from a multi-FASTA file into Chado',
  163. 'page callback' => 'drupal_get_form',
  164. 'page arguments' => array('tripal_feature_fasta_load_form'),
  165. 'access arguments' => array('administer site configuration'),
  166. 'type' => MENU_NORMAL_ITEM,
  167. );
  168. $items['admin/tripal/tripal_feature/gff3_load'] = array(
  169. 'title' => 'Import a GFF3 file',
  170. 'description' => 'Import a GFF3 file into Chado',
  171. 'page callback' => 'drupal_get_form',
  172. 'page arguments' => array('tripal_feature_gff3_load_form'),
  173. 'access arguments' => array('access administration pages'),
  174. 'type' => MENU_NORMAL_ITEM,
  175. );
  176. $items['admin/tripal/tripal_feature/delete'] = array(
  177. 'title' => ' Delete Features',
  178. 'description' => 'Delete multiple features from Chado',
  179. 'page callback' => 'drupal_get_form',
  180. 'page arguments' => array('tripal_feature_delete_form'),
  181. 'access arguments' => array('access administration pages'),
  182. 'type' => MENU_NORMAL_ITEM,
  183. );
  184. $items['admin/tripal/tripal_feature/sync'] = array(
  185. 'title' => ' Sync Features',
  186. 'description' => 'Sync features from Chado with Drupal',
  187. 'page callback' => 'drupal_get_form',
  188. 'page arguments' => array('tripal_feature_sync_form'),
  189. 'access arguments' => array('access administration pages'),
  190. 'type' => MENU_NORMAL_ITEM,
  191. );
  192. // Adding Secondary Properties
  193. /**
  194. $items['node/%tf_node/tf_properties'] = array(
  195. 'title' => t('Add Properties & Synonyms'),
  196. 'description' => t('Settings for Features'),
  197. 'page callback' => 'tripal_feature_add_ALL_property_page',
  198. 'page arguments' => array(1),
  199. 'access arguments' => array('create chado_feature content'),
  200. 'type' => MENU_CALLBACK
  201. );
  202. $items['node/%tf_node/tf_db_references'] = array(
  203. 'title' => t('Add Database References'),
  204. 'description' => t('Settings for Features'),
  205. 'page callback' => 'tripal_feature_add_ALL_dbreferences_page',
  206. 'page arguments' => array(1),
  207. 'access arguments' => array('create chado_feature content'),
  208. 'type' => MENU_CALLBACK
  209. );
  210. $items['node/%tf_node/tf_relationships'] = array(
  211. 'title' => t('Add Relationships'),
  212. 'description' => t('Settings for Features'),
  213. 'page callback' => 'tripal_feature_add_ALL_relationships_page',
  214. 'page arguments' => array(1),
  215. 'access arguments' => array('create chado_feature content'),
  216. 'type' => MENU_CALLBACK
  217. );
  218. */
  219. //Edit/Deleting Secondary Properties-------------
  220. $items['node/%tf_node/edit_feature_properties'] = array(
  221. 'title' => 'Edit Properties',
  222. 'description' => 'Settings for Features',
  223. 'page callback' => 'tripal_feature_edit_ALL_properties_page',
  224. 'page arguments' => array(1),
  225. 'access arguments' => array('edit chado_feature content'),
  226. 'type' => MENU_LOCAL_TASK,
  227. 'weight' => 8,
  228. );
  229. /**
  230. $items['node/%tf_node/tf_edit_relationships'] = array(
  231. 'title' => t('Edit Relationships'),
  232. 'description' => t('Settings for Feature'),
  233. 'page callback' => 'tripal_feature_edit_ALL_relationships_page',
  234. 'page arguments' => array(1),
  235. 'access arguments' => array('edit chado_feature content'),
  236. 'type' => MENU_LOCAL_TASK,
  237. 'weight' => 9,
  238. );
  239. */
  240. $items['node/%tf_node/tf_edit_db_references'] = array(
  241. 'title' => 'Edit References',
  242. 'description' => 'Settings for Feature',
  243. 'page callback' => 'tripal_feature_edit_ALL_dbreferences_page',
  244. 'page arguments' => array(1),
  245. 'access arguments' => array('edit chado_feature content'),
  246. 'type' => MENU_LOCAL_TASK,
  247. 'weight' => 10,
  248. );
  249. // managing relationship aggregates
  250. $items['admin/tripal/tripal_feature/aggregate'] = array(
  251. 'title' => 'Feature Relationship Aggegators',
  252. 'description' => 'Features have relationships with other features and it may be desirable to aggregate the content from one ore more child or parent feature.',
  253. 'page callback' => 'tripal_feature_aggregator_page',
  254. 'access arguments' => array('manage chado_feature aggregator'),
  255. 'type' => MENU_NORMAL_ITEM,
  256. );
  257. $items['admin/tripal/tripal_feature/aggregate/new'] = array(
  258. 'title' => 'Add an Aggregator',
  259. 'page callback' => 'drupal_get_form',
  260. 'page arguments' => array('tripal_feature_aggregator_form'),
  261. 'access arguments' => array('manage chado_feature aggregator'),
  262. 'type' => MENU_NORMAL_ITEM,
  263. );
  264. $items['admin/tripal/tripal_feature/aggregate/edit/js'] = array(
  265. 'title' => 'Edit an Aggegator',
  266. 'page callback' => 'tripal_feature_aggregator_ajax_edit',
  267. 'access arguments' => array('manage chado_feature aggregator'),
  268. 'type' => MENU_CALLBACK,
  269. );
  270. return $items;
  271. }
  272. /**
  273. * Implements Menu wildcard_load hook
  274. * Purpose: Allows the node ID of a chado feature to be dynamically
  275. * pulled from the path. The node is loaded from this node ID
  276. * and supplied to the page as an arguement
  277. *
  278. * @ingroup tripal_feature
  279. */
  280. function tf_node_load($nid) {
  281. if (is_numeric($nid)) {
  282. $node = node_load($nid);
  283. if ($node->type == 'chado_feature') {
  284. return $node;
  285. }
  286. }
  287. return FALSE;
  288. }
  289. /**
  290. *
  291. *
  292. * @ingroup tripal_feature
  293. */
  294. function tripal_feature_block($op = 'list', $delta = 0, $edit=array()) {
  295. switch ($op) {
  296. case 'list':
  297. $blocks['references']['info'] = t('Tripal Feature References');
  298. $blocks['references']['cache'] = BLOCK_NO_CACHE;
  299. $blocks['base']['info'] = t('Tripal Feature Details');
  300. $blocks['base']['cache'] = BLOCK_NO_CACHE;
  301. $blocks['sequence']['info'] = t('Tripal Feature Sequence');
  302. $blocks['sequence']['cache'] = BLOCK_NO_CACHE;
  303. $blocks['featureloc_sequences']['info'] = t('Tripal Feature Annotated Sequence');
  304. $blocks['featureloc_sequences']['cache'] = BLOCK_NO_CACHE;
  305. $blocks['synonyms']['info'] = t('Tripal Feature Synonyms');
  306. $blocks['synonyms']['cache'] = BLOCK_NO_CACHE;
  307. $blocks['properties']['info'] = t('Tripal Feature Properties');
  308. $blocks['properties']['cache'] = BLOCK_NO_CACHE;;
  309. $blocks['alignments']['info'] = t('Tripal Feature Alignments');
  310. $blocks['alignments']['cache'] = BLOCK_NO_CACHE;
  311. $blocks['relationships']['info'] = t('Tripal Feature Relationships');
  312. $blocks['relationships']['cache'] = BLOCK_NO_CACHE;
  313. $blocks['org_feature_counts']['info'] = t('Tripal Organism Feature Counts');
  314. $blocks['org_feature_counts']['cache'] = BLOCK_NO_CACHE;
  315. $blocks['org_feature_browser']['info'] = t('Tripal Organism Feature Browser');
  316. $blocks['org_feature_browser']['cache'] = BLOCK_NO_CACHE;
  317. $blocks['library_feature_browser']['info'] = t('Tripal Library Feature Browser');
  318. $blocks['library_feature_browser']['cache'] = BLOCK_NO_CACHE;
  319. $blocks['analysis_feature_browser']['info'] = t('Tripal Analysis Feature Browser');
  320. $blocks['analysis_feature_browser']['cache'] = BLOCK_NO_CACHE;
  321. return $blocks;
  322. case 'view':
  323. if (user_access('access chado_feature content') and arg(0) == 'node' and is_numeric(arg(1))) {
  324. $nid = arg(1);
  325. $node = node_load($nid);
  326. $block = array();
  327. switch ($delta) {
  328. case 'references':
  329. $block['subject'] = t('References');
  330. $block['content'] = theme('tripal_feature_references', $node);
  331. break;
  332. case 'base':
  333. $block['subject'] = t('Feature Details');
  334. $block['content'] = theme('tripal_feature_base', $node);
  335. break;
  336. case 'synonyms':
  337. $block['subject'] = t('Synonyms');
  338. $block['content'] = theme('tripal_feature_synonyms', $node);
  339. break;
  340. case 'properties':
  341. $block['subject'] = t('Properties');
  342. $block['content'] = theme('tripal_feature_properties', $node);
  343. break;;
  344. case 'sequence':
  345. $block['subject'] = t('Sequence');
  346. $block['content'] = theme('tripal_feature_sequence', $node);
  347. break;
  348. case 'featureloc_sequences':
  349. $block['subject'] = t('Formatted Sequences');
  350. $block['content'] = theme('tripal_feature_featureloc_sequences', $node);
  351. break;
  352. case 'alignments':
  353. $block['subject'] = t('Alignments');
  354. $block['content'] = theme('tripal_feature_alignments', $node);
  355. break;
  356. case 'relationships':
  357. $block['subject'] = t('Relationships');
  358. $block['content'] = theme('tripal_feature_relationships', $node);
  359. break;
  360. case 'org_feature_counts':
  361. $block['subject'] = t('Feature Type Summary');
  362. $block['content'] = theme('tripal_organism_feature_counts', $node);
  363. break;
  364. case 'org_feature_browser':
  365. $block['subject'] = t('Feature Browser');
  366. $block['content'] = theme('tripal_organism_feature_browser', $node);
  367. break;
  368. case 'library_feature_browser':
  369. $block['subject'] = t('Library Feature Browser');
  370. $block['content'] = theme('tripal_library_feature_browser', $node);
  371. break;
  372. case 'analysis_feature_browser':
  373. $block['subject'] = t('Analysis Feature Browser');
  374. $block['content'] = theme('tripal_analysis_feature_browser', $node);
  375. break;
  376. default :
  377. }
  378. return $block;
  379. }
  380. }
  381. }
  382. /**
  383. * When a new chado_feature node is created we also need to add information
  384. * to our chado_feature table. This function is called on insert of a new node
  385. * of type 'chado_feature' and inserts the necessary information.
  386. *
  387. * @ingroup tripal_feature
  388. */
  389. function chado_feature_insert($node) {
  390. // remove spaces, newlines from residues
  391. $residues = preg_replace("/[\n\r\s]/", "", $node->residues);
  392. $obsolete = 'FALSE';
  393. if ($node->is_obsolete) {
  394. $obsolete = 'TRUE';
  395. }
  396. $values = array(
  397. 'cv_id' => array(
  398. 'name' => 'sequence'
  399. ),
  400. 'name' => $node->feature_type
  401. );
  402. $type = tripal_core_chado_select('cvterm', array('cvterm_id'), $values);
  403. $values = array(
  404. 'organism_id' => $node->organism_id,
  405. 'name' => $node->fname,
  406. 'uniquename' => $node->uniquename,
  407. 'residues' => $residues,
  408. 'seqlen' => drupal_strlen($residues),
  409. 'is_obsolete' => $obsolete,
  410. 'type_id' => $type[0]->cvterm_id,
  411. 'md5checksum' => md5($residues)
  412. );
  413. $istatus = tripal_core_chado_insert('feature', $values);
  414. if (!$istatus) {
  415. drupal_set_message(t('Unable to add feature.'), 'warning');
  416. watchdog('tripal_feature',
  417. 'Insert feature: Unable to create feature where values: %values',
  418. array('%values' => print_r($values, TRUE)),
  419. WATCHDOG_WARNING
  420. );
  421. }
  422. $values = array(
  423. 'organism_id' => $node->organism_id,
  424. 'uniquename' => $node->uniquename,
  425. 'type_id' => $type[0]->cvterm_id,
  426. );
  427. $feature = tripal_core_chado_select('feature', array('feature_id'), $values);
  428. // add the genbank accession and synonyms
  429. chado_feature_add_synonyms($node->synonyms, $feature[0]->feature_id);
  430. // make sure the entry for this feature doesn't already exist in the chado_feature table
  431. // if it doesn't exist then we want to add it.
  432. $node_check_sql = "SELECT * FROM {chado_feature} " .
  433. "WHERE feature_id = '%s'";
  434. $node_check = db_fetch_object(db_query($node_check_sql, $feature[0]->feature_id));
  435. if (!$node_check) {
  436. // next add the item to the drupal table
  437. $sql = "INSERT INTO {chado_feature} (nid, vid, feature_id, sync_date) ".
  438. "VALUES (%d, %d, %d, " . time() . ")";
  439. db_query($sql, $node->nid, $node->vid, $feature[0]->feature_id);
  440. }
  441. }
  442. /**
  443. *
  444. *
  445. * @ingroup tripal_feature
  446. */
  447. function chado_feature_update($node) {
  448. if ($node->revision) {
  449. // TODO -- decide what to do about revisions
  450. }
  451. else {
  452. $residues = preg_replace("/[\n\r\s]/", "", $node->residues);
  453. $obsolete = 'FALSE';
  454. if ($node->is_obsolete) {
  455. $obsolete = 'TRUE';
  456. }
  457. // get the feature type id
  458. $values = array(
  459. 'cv_id' => array(
  460. 'name' => 'sequence'
  461. ),
  462. 'name' => $node->feature_type
  463. );
  464. $type = tripal_core_chado_select('cvterm', array('cvterm_id'), $values);
  465. $feature_id = chado_get_id_for_node('feature', $node) ;
  466. if (sizeof($type) > 0) {
  467. $match = array(
  468. 'feature_id' => $feature_id,
  469. );
  470. $values = array(
  471. 'organism_id' => $node->organism_id,
  472. 'name' => $node->fname,
  473. 'uniquename' => $node->uniquename,
  474. 'residues' => $residues,
  475. 'seqlen' => drupal_strlen($residues),
  476. 'is_obsolete' => $obsolete,
  477. 'type_id' => $type[0]->cvterm_id,
  478. 'md5checksum' => md5($residues)
  479. );
  480. $status = tripal_core_chado_update('feature', $match, $values);
  481. // add the genbank synonyms
  482. chado_feature_add_synonyms($node->synonyms, $feature_id);
  483. }
  484. else {
  485. drupal_set_message(t('Unable to update feature.'), 'warning');
  486. watchdog('tripal_feature',
  487. 'Update feature: Unable to update feature where values: %values',
  488. array('%values' => print_r($values, TRUE)),
  489. WATCHDOG_WARNING
  490. );
  491. }
  492. }
  493. }
  494. /**
  495. *
  496. *
  497. * @ingroup tripal_feature
  498. */
  499. function chado_feature_delete($node) {
  500. $feature_id = chado_get_id_for_node('feature', $node);
  501. // remove the drupal content
  502. $sql_del = "DELETE FROM {chado_feature} ".
  503. "WHERE nid = %d ".
  504. "AND vid = %d";
  505. db_query($sql_del, $node->nid, $node->vid);
  506. $sql_del = "DELETE FROM {node} ".
  507. "WHERE nid = %d ".
  508. "AND vid = %d";
  509. db_query($sql_del, $node->nid, $node->vid);
  510. $sql_del = "DELETE FROM {node_revisions} ".
  511. "WHERE nid = %d ".
  512. "AND vid = %d";
  513. db_query($sql_del, $node->nid, $node->vid);
  514. // Remove data from feature tables of chado database. This will
  515. // cause a cascade delete and remove all data in referencing tables
  516. // for this feature
  517. $previous_db = tripal_db_set_active('chado');
  518. db_query("DELETE FROM {feature} WHERE feature_id = %d", $feature_id);
  519. tripal_db_set_active($previous_db);
  520. drupal_set_message(t("The feature and all associated data were removed from") .
  521. "chado");
  522. }
  523. /**
  524. *
  525. *
  526. * @ingroup tripal_feature
  527. */
  528. function chado_feature_add_synonyms($synonyms, $feature_id) {
  529. // make sure we only have a single space between each synonym
  530. $synonyms = preg_replace("/[\s\n\r]+/", " ", $synonyms);
  531. // split the synonyms into an array based on a space as the delimieter
  532. $syn_array = array();
  533. $syn_array = explode(" ", $synonyms);
  534. // use the chado database
  535. $previous_db = tripal_db_set_active('chado');
  536. // remove any old synonyms
  537. $feature_syn_dsql = "DELETE FROM {feature_synonym} WHERE feature_id = %d";
  538. if (!db_query($feature_syn_dsql, $feature_id)) {
  539. $error .= "Could not remove synonyms from feature. ";
  540. }
  541. // return if we don't have any synonmys to add
  542. if (!$synonyms) {
  543. tripal_db_set_active($previous_db);
  544. return;
  545. }
  546. // iterate through each synonym and add it to the database
  547. foreach ($syn_array as $syn) {
  548. // skip this item if it's empty
  549. if (!$syn) {
  550. break; }
  551. // check to see if we have this accession number already in the database
  552. // if so then don't add it again. it messes up drupal if the insert fails.
  553. // It is possible for the accession number to be present and not the feature
  554. $synonym_sql = "SELECT synonym_id FROM {synonym} ".
  555. "WHERE name = '%s'";
  556. $synonym = db_fetch_object(db_query($synonym_sql, $syn));
  557. if (!$synonym) {
  558. $synonym_isql = "INSERT INTO {synonym} (name,synonym_sgml,type_id) ".
  559. "VALUES ('%s','%s', ".
  560. " (SELECT cvterm_id ".
  561. " FROM {CVTerm} CVT ".
  562. " INNER JOIN CV ON CVT.cv_id = CV.cv_id ".
  563. " WHERE CV.name = 'feature_property' and CVT.name = 'synonym'))";
  564. if (!db_query($synonym_isql, $syn, $syn)) {
  565. $error .= "Could not add synonym. ";
  566. }
  567. // now get the synonym we just added
  568. $synonym_sql = "SELECT synonym_id FROM {synonym} ".
  569. "WHERE name = '%s'";
  570. $synonym = db_fetch_object(db_query($synonym_sql, $syn));
  571. }
  572. // now add in our new sysnonym
  573. $feature_syn_isql = "INSERT INTO {feature_synonym} (synonym_id,feature_id,pub_id) ".
  574. "VALUES (%d,%d,1)";
  575. if (!db_query($feature_syn_isql, $synonym->synonym_id, $feature_id)) {
  576. $error .= "Could not add synonyms to feature. ";
  577. }
  578. }
  579. // return to the drupal database
  580. tripal_db_set_active($previous_db);
  581. return $error;
  582. }
  583. /**
  584. *
  585. *
  586. * @ingroup tripal_feature
  587. */
  588. function chado_feature_add_gbaccession($accession, $feature_id) {
  589. // use chado database
  590. $previous_db = tripal_db_set_active('chado');
  591. // remove any old accession from genbank dbEST
  592. $fdbxref_dsql = "DELETE FROM {feature_dbxref} ".
  593. "WHERE feature_id = %d and dbxref_id IN ".
  594. " (SELECT DBX.dbxref_id FROM {dbxref} DBX ".
  595. " INNER JOIN DB ON DB.db_id = DBX.db_id ".
  596. " INNER JOIN feature_dbxref FDBX ON DBX.dbxref_id = FDBX.dbxref_id ".
  597. " WHERE DB.name = 'DB:Genbank' and FDBX.feature_id = %d)";
  598. if (!db_query($fdbxref_dsql, $feature_id, $feature_id)) {
  599. $error .= "Could not remove accession from feature. ";
  600. }
  601. // if we don't have an accession number to add then just return
  602. if (!$accession) {
  603. tripal_db_set_active($previous_db);
  604. return;
  605. }
  606. // get the db_id
  607. $db_sql = "SELECT db_id FROM {DB} ".
  608. "WHERE name = 'DB:Genbank_est'";
  609. $db = db_fetch_object(db_query($db_sql));
  610. // check to see if we have this accession number already in the database
  611. // if so then don't add it again. it messes up drupal if the insert fails.
  612. // It is possible for the accession number to be present and not the feature
  613. $dbxref_sql = "SELECT dbxref_id FROM {dbxref} ".
  614. "WHERE db_id = %d and accession = '%s'";
  615. $dbxref = db_fetch_object(db_query($dbxref_sql, $db->db_id, $accession));
  616. if (!$dbxref) {
  617. // add the accession number
  618. $dbxref_isql = "INSERT INTO {dbxref} (db_id,accession) ".
  619. " VALUES (%d, '%s') ";
  620. if (!db_query($dbxref_isql, $db->db_id, $accession)) {
  621. $error .= 'Could not add accession as a database reference ';
  622. }
  623. // get the dbxref_id for the just added accession number
  624. $dbxref_sql = "SELECT dbxref_id FROM {dbxref} ".
  625. "WHERE db_id = %d and accession = '%s'";
  626. $dbxref = db_fetch_object(db_query($dbxref_sql, $db->db_id, $accession));
  627. }
  628. // associate the accession number with the feature
  629. $feature_dbxref_isql = "INSERT INTO {feature_dbxref} (feature_id,dbxref_id) ".
  630. " VALUES (%d, %d) ";
  631. if (!db_query($feature_dbxref_isql, $feature_id, $dbxref->dbxref_id)) {
  632. $error .= 'Could not add feature database reference. ';
  633. }
  634. tripal_db_set_active($previous_db);
  635. return $error;
  636. }
  637. /**
  638. *
  639. *
  640. * @ingroup tripal_feature
  641. */
  642. function chado_feature_form($node, $param) {
  643. $type = node_get_types('type', $node);
  644. $form = array();
  645. $feature = $node->feature;
  646. // add the residues to the feature object
  647. $feature = tripal_core_expand_chado_vars($feature, 'field', 'feature.residues');
  648. // if the node has synonyms then use that as the form may be returning
  649. // from an error. Otherwise try to find synonyms from the database
  650. $synonyms = $node->synonyms;
  651. $feature = tripal_core_expand_chado_vars($feature, 'table', 'feature_synonym');
  652. $feature_synonyms = $feature->feature_synonym;
  653. if (!$synonyms) {
  654. if (!is_array($feature_synonyms)) {
  655. $synonyms = $feature_synonyms->synonym_id->name;
  656. }
  657. elseif (is_array($feature_synonyms)) {
  658. foreach ($feature_synonyms as $index => $synonym) {
  659. $synonyms .= $synonym->synonym_id->name . "\n";
  660. }
  661. }
  662. }
  663. $analyses = $node->analyses;
  664. $references = $node->references;
  665. // We need to pass above variables for preview to show
  666. $form['feature'] = array(
  667. '#type' => 'value',
  668. '#value' => $feature
  669. );
  670. // This field is read when previewing a node
  671. $form['synonyms'] = array(
  672. '#type' => 'value',
  673. '#value' => $synonyms
  674. );
  675. // This field is read when previewing a node
  676. $form['analyses'] = array(
  677. '#type' => 'value',
  678. '#value' => $analyses
  679. );
  680. // This field is read when previewing a node
  681. $form['references'] = array(
  682. '#type' => 'value',
  683. '#value' => $references
  684. );
  685. // keep track of the feature id if we have one. If we do have one then
  686. // this would indicate an update as opposed to an insert.
  687. $form['feature_id'] = array(
  688. '#type' => 'value',
  689. '#value' => $feature->feature_id,
  690. );
  691. $form['title']= array(
  692. '#type' => 'textfield',
  693. '#title' => t('Title'),
  694. '#required' => TRUE,
  695. '#default_value' => $node->title,
  696. '#description' => t('The title must be a unique identifier for this feature. It is recommended to use a combination of uniquename, organism and feature type in the title as this is guranteed to be unique.'),
  697. '#weight' => 1,
  698. '#maxlength' => 255
  699. );
  700. $form['uniquename']= array(
  701. '#type' => 'textfield',
  702. '#title' => t('Unique Feature Name'),
  703. '#required' => TRUE,
  704. '#default_value' => $feature->uniquename,
  705. '#description' => t('Enter a unique name for this feature. This name must be unique for the organism and feature type.'),
  706. '#weight' => 1,
  707. '#maxlength' => 255
  708. );
  709. $form['fname']= array(
  710. '#type' => 'textfield',
  711. '#title' => t('Feature Name'),
  712. '#required' => TRUE,
  713. '#default_value' => $feature->name,
  714. '#description' => t('Enter the name used by humans to refer to this feature.'),
  715. '#weight' => 1,
  716. '#maxlength' => 255
  717. );
  718. // get the list of supported feature types
  719. $ftypes = array();
  720. $ftypes[''] = '';
  721. $supported_ftypes = split("[ \n]", variable_get('tripal_feature_type_setting', 'gene mRNA EST contig'));
  722. foreach ($supported_ftypes as $ftype) {
  723. $ftypes["$ftype"] = $ftype;
  724. }
  725. $form['feature_type'] = array(
  726. '#title' => t('Feature Type'),
  727. '#type' => t('select'),
  728. '#description' => t("Choose the feature type."),
  729. '#required' => TRUE,
  730. '#default_value' => $feature->type_id->name,
  731. '#options' => $ftypes,
  732. '#weight' => 2
  733. );
  734. // get the list of organisms
  735. $sql = "SELECT * FROM {Organism} ORDER BY genus, species";
  736. $previous_db = tripal_db_set_active('chado'); // use chado database
  737. $org_rset = db_query($sql);
  738. tripal_db_set_active($previous_db); // now use drupal database
  739. //
  740. $organisms = array();
  741. $organisms[''] = '';
  742. while ($organism = db_fetch_object($org_rset)) {
  743. $organisms[$organism->organism_id] = "$organism->genus $organism->species ($organism->common_name)";
  744. }
  745. $form['organism_id'] = array(
  746. '#title' => t('Organism'),
  747. '#type' => t('select'),
  748. '#description' => t("Choose the organism with which this feature is associated"),
  749. '#required' => TRUE,
  750. '#default_value' => $feature->organism_id->organism_id,
  751. '#options' => $organisms,
  752. '#weight' => 3,
  753. );
  754. // Get synonyms
  755. if ($synonyms) {
  756. if (is_array($synonyms)) {
  757. foreach ($synonyms as $synonym) {
  758. $syn_text .= "$synonym->name\n";
  759. }
  760. }
  761. else {
  762. $syn_text = $synonyms;
  763. }
  764. }
  765. $form['synonyms']= array(
  766. '#type' => 'textarea',
  767. '#title' => t('Synonyms'),
  768. '#required' => FALSE,
  769. '#default_value' => $syn_text,
  770. '#description' => t('Enter alternate names (synonmys) for this feature to help in searching and identification. You may enter as many alternate names as needed separated by spaces or on different lines.'),
  771. '#weight' => 5,
  772. );
  773. $form['residues']= array(
  774. '#type' => 'textarea',
  775. '#title' => t('Residues'),
  776. '#required' => FALSE,
  777. '#default_value' => $feature->residues,
  778. '#description' => t('Enter the nucelotide sequences for this feature'),
  779. '#weight' => 6
  780. );
  781. $checked = '';
  782. if ($feature->is_obsolete == 't') {
  783. $checked = '1';
  784. }
  785. $form['is_obsolete']= array(
  786. '#type' => 'checkbox',
  787. '#title' => t('Is Obsolete'),
  788. '#required' => FALSE,
  789. '#default_value' => $checked,
  790. '#description' => t('Check this box if this sequence should be retired and no longer included in further analysis.'),
  791. '#weight' => 8
  792. );
  793. return $form;
  794. }
  795. /**
  796. *
  797. *
  798. * @ingroup tripal_feature
  799. */
  800. function chado_feature_validate($node) {
  801. $result = 0;
  802. // if this is an update, we want to make sure that a different feature for
  803. // the organism doesn't already have this uniquename. We don't want to give
  804. // two sequences the same uniquename
  805. if ($node->feature_id) {
  806. $sql = "SELECT *
  807. FROM {Feature} F
  808. INNER JOIN {cvterm} CVT ON F.type_id = CVT.cvterm_id
  809. WHERE uniquename = '%s'
  810. AND organism_id = %d AND CVT.name = '%s' AND NOT feature_id = %d";
  811. $previous_db = tripal_db_set_active('chado');
  812. $result = db_fetch_object(db_query($sql, $node->uniquename, $node->organism_id, $node->feature_type, $node->feature_id));
  813. tripal_db_set_active($previous_db);
  814. if ($result) {
  815. form_set_error('uniquename', t("Feature update cannot proceed. The feature name '$node->uniquename' is not unique for this organism. Please provide a unique name for this feature."));
  816. }
  817. }
  818. // if this is an insert then we just need to make sure this name doesn't
  819. // already exist for this organism if it does then we need to throw an error
  820. else {
  821. $sql = "SELECT *
  822. FROM {Feature} F
  823. INNER JOIN {cvterm} CVT ON F.type_id = CVT.cvterm_id
  824. WHERE uniquename = '%s'
  825. AND organism_id = %d AND CVT.name = '%s'";
  826. $previous_db = tripal_db_set_active('chado');
  827. $result = db_fetch_object(db_query($sql, $node->uniquename, $node->organism_id, $node->feature_type));
  828. tripal_db_set_active($previous_db);
  829. if ($result) {
  830. form_set_error('uniquename', t("Feature insert cannot proceed. The feature name '$node->uniquename' already exists for this organism. Please provide a unique name for this feature."));
  831. }
  832. }
  833. // we want to remove all characters except IUPAC nucleotide characters from the
  834. // the residues. however, residues are not required so if blank then we'll skip
  835. // this step
  836. if ($node->residues) {
  837. $residues = preg_replace("/[^\w]/", '', $node->residues);
  838. if (!preg_match("/^[ACTGURYMKSWBDHVN]+$/i", $residues)) {
  839. form_set_error('residues', t("The residues in feature $node->name contains more than the nucleotide IUPAC characters. Only the following characters are allowed: A,C,T,G,U,R,Y,M,K,S,W,B,D,H,V,N: '" . $residues . "'"));
  840. }
  841. }
  842. // we don't allow a genbank accession number for a contig
  843. if ($node->feature_type == 'contig' and $node->gbaccession) {
  844. form_set_error('gbaccession', t("Contigs cannot have a genbank accession number. Please change the feature type or remove the accession number"));
  845. }
  846. }
  847. /**
  848. * When a node is requested by the user this function is called to allow us
  849. * to add auxiliary data to the node object.
  850. *
  851. * @ingroup tripal_feature
  852. */
  853. function chado_feature_load($node) {
  854. // get the feature details from chado
  855. $feature_id = chado_get_id_for_node('feature', $node);
  856. $values = array('feature_id' => $feature_id);
  857. $feature = tripal_core_generate_chado_var('feature', $values);
  858. if(strcmp($feature->name,$feature->uniquename)==0){
  859. $node->title = $feature->name ." (" . $feature->type_id->name . ") " . $feature->organism_id->genus . " " . $feature->organism_id->species ;
  860. }
  861. $additions = new stdClass();
  862. $additions->feature = $feature;
  863. return $additions;
  864. }
  865. /**
  866. *
  867. *
  868. * @ingroup tripal_feature
  869. */
  870. function tripal_feature_load_organism($organism_id) {
  871. // add organism details
  872. $sql = "SELECT * FROM {organism} WHERE organism_id = %d";
  873. $previous_db = tripal_db_set_active('chado'); // use chado database
  874. $organism = db_fetch_object(db_query($sql, $organism_id));
  875. tripal_db_set_active($previous_db); // now use drupal database
  876. return $organism;
  877. }
  878. /**
  879. *
  880. *
  881. * @ingroup tripal_feature
  882. */
  883. function tripal_feature_load_synonyms($feature_id) {
  884. $sql = "SELECT S.name ".
  885. "FROM {Feature_Synonym} FS ".
  886. " INNER JOIN {Synonym} S ".
  887. " ON FS.synonym_id = S.Synonym_id ".
  888. "WHERE FS.feature_id = %d ".
  889. "ORDER BY S.name ";
  890. $previous_db = tripal_db_set_active('chado'); // use chado database
  891. $results = db_query($sql, $feature_id);
  892. tripal_db_set_active($previous_db); // now use drupal database
  893. $synonyms = array();
  894. $i=0;
  895. while ($synonym = db_fetch_object($results)) {
  896. $synonyms[$i++] = $synonym;
  897. }
  898. return $synonyms;
  899. }
  900. /**
  901. *
  902. *
  903. * @ingroup tripal_feature
  904. */
  905. function tripal_feature_load_properties($feature_id) {
  906. $sql = "SELECT CVT.name as cvname, FS.type_id, FS.value, FS.rank,
  907. CVT.definition, CVT.is_obsolete,
  908. DBX.dbxref_id,DBX.accession,DB.name as dbname,
  909. DB.urlprefix, DB.description as db_description, DB.url
  910. FROM {featureprop} FS
  911. INNER JOIN {cvterm} CVT ON FS.type_id = CVT.cvterm_id
  912. INNER JOIN {dbxref} DBX ON CVT.dbxref_id = DBX.dbxref_id
  913. INNER JOIN {db} DB ON DB.db_id = DBX.db_id
  914. WHERE FS.feature_id = %d
  915. ORDER BY FS.rank ASC";
  916. $previous_db = tripal_db_set_active('chado'); // use chado database
  917. $results = db_query($sql, $feature_id);
  918. tripal_db_set_active($previous_db); // now use drupal database
  919. $i=0;
  920. $properties = array();
  921. while ($property = db_fetch_object($results)) {
  922. $properties[$i++] = $property;
  923. }
  924. return $properties;
  925. }
  926. /**
  927. *
  928. *
  929. * @ingroup tripal_feature
  930. */
  931. function tripal_feature_load_references($feature_id) {
  932. $sql = "SELECT F.uniquename,F.Feature_id,DBX.accession,DB.description as dbdesc, ".
  933. " DB.db_id, DB.name as db_name, DB.urlprefix,DBX.dbxref_id ".
  934. "FROM {feature} F ".
  935. " INNER JOIN {feature_dbxref} FDBX on F.feature_id = FDBX.feature_id ".
  936. " INNER JOIN {dbxref} DBX on DBX.dbxref_id = FDBX.dbxref_id ".
  937. " INNER JOIN {db} on DB.db_id = DBX.db_id ".
  938. "WHERE F.feature_id = %d ".
  939. "ORDER BY DB.name ";
  940. $previous_db = tripal_db_set_active('chado'); // use chado database
  941. $results = db_query($sql, $feature_id);
  942. tripal_db_set_active($previous_db); // now use drupal database
  943. $references = array();
  944. $i=0;
  945. while ($accession = db_fetch_object($results)) {
  946. $references[$i++] = $accession;
  947. }
  948. return $references;
  949. }
  950. /**
  951. *
  952. *
  953. * @ingroup tripal_feature
  954. */
  955. function tripal_feature_load_featurelocs($feature_id, $side = 'as_parent', $aggregate = 1) {
  956. $sql = "SELECT
  957. F.name, F.feature_id, F.uniquename,
  958. FS.name as src_name,
  959. FS.feature_id as src_feature_id,
  960. FS.uniquename as src_uniquename,
  961. CVT.name as cvname, CVT.cvterm_id,
  962. CVTS.name as src_cvname, CVTS.cvterm_id as src_cvterm_id,
  963. FL.fmin, FL.fmax, FL.is_fmin_partial, FL.is_fmax_partial,FL.strand,
  964. FL.phase
  965. FROM {featureloc} FL
  966. INNER JOIN {feature} F on FL.feature_id = F.feature_id
  967. INNER JOIN {feature} FS on FS.feature_id = FL.srcfeature_id
  968. INNER JOIN {cvterm} CVT on F.type_id = CVT.cvterm_id
  969. INNER JOIN {cvterm} CVTS on FS.type_id = CVTS.cvterm_id
  970. ";
  971. if (strcmp($side, 'as_parent')==0) {
  972. $sql .= "WHERE FL.srcfeature_id = %d ";
  973. }
  974. if (strcmp($side, 'as_child')==0) {
  975. $sql .= "WHERE FL.feature_id = %d ";
  976. }
  977. $previous_db = tripal_db_set_active('chado'); // use chado database
  978. $flresults = db_query($sql, $feature_id);
  979. tripal_db_set_active($previous_db); // now use drupal database
  980. // copy the results into an array
  981. $i=0;
  982. $featurelocs = array();
  983. while ($loc = db_fetch_object($flresults)) {
  984. // if a drupal node exists for this feature then add the nid to the
  985. // results object
  986. $sql = 'SELECT nid FROM {chado_feature} WHERE feature_id = %d';
  987. $ffeature = db_fetch_object(db_query($sql, $loc->feature_id));
  988. $sfeature = db_fetch_object(db_query($sql, $loc->src_feature_id));
  989. $loc->fnid = $ffeature->nid;
  990. $loc->snid = $sfeature->nid;
  991. // add the result to the array
  992. $featurelocs[$i++] = $loc;
  993. }
  994. // Add the relationship feature locs if aggregate is turned on
  995. if ($aggregate and strcmp($side, 'as_parent')==0) {
  996. // get the relationships for this feature without substituting any children
  997. // for the parent. We want all relationships
  998. $relationships = tripal_feature_get_aggregate_relationships($feature_id, 0);
  999. foreach ($relationships as $rindex => $rel) {
  1000. // get the featurelocs for each of the relationship features
  1001. $rel_featurelocs = tripal_feature_load_featurelocs($rel->subject_id, 'as_child', 0);
  1002. foreach ($rel_featurelocs as $findex => $rfloc) {
  1003. $featurelocs[$i++] = $rfloc;
  1004. }
  1005. }
  1006. }
  1007. usort($featurelocs, 'tripal_feature_sort_locations');
  1008. return $featurelocs;
  1009. }
  1010. /**
  1011. * used to sort the feature locs by start position
  1012. *
  1013. * @ingroup tripal_feature
  1014. */
  1015. function tripal_feature_sort_locations($a, $b) {
  1016. return strnatcmp($a->fmin, $b->fmin);
  1017. }
  1018. /**
  1019. *
  1020. *
  1021. * @ingroup tripal_feature
  1022. */
  1023. function tripal_feature_load_relationships($feature_id, $side = 'as_subject') {
  1024. // get the relationships for this feature. The query below is used for both
  1025. // querying the object and subject relationships
  1026. $sql = "SELECT
  1027. FS.name as subject_name,
  1028. FS.uniquename as subject_uniquename,
  1029. CVTS.name as subject_type,
  1030. CVTS.cvterm_id as subject_type_id,
  1031. FR.subject_id,
  1032. FR.type_id as relationship_type_id,
  1033. CVT.name as rel_type,
  1034. FO.name as object_name,
  1035. FO.uniquename as object_uniquename,
  1036. CVTO.name as object_type,
  1037. CVTO.cvterm_id as object_type_id,
  1038. FR.object_id,
  1039. FR.rank
  1040. FROM {feature_relationship} FR
  1041. INNER JOIN {cvterm} CVT ON FR.type_id = CVT.cvterm_id
  1042. INNER JOIN {feature} FS ON FS.feature_id = FR.subject_id
  1043. INNER JOIN {feature} FO ON FO.feature_id = FR.object_id
  1044. INNER JOIN {cvterm} CVTO ON FO.type_id = CVTO.cvterm_id
  1045. INNER JOIN {cvterm} CVTS ON FS.type_id = CVTS.cvterm_id
  1046. ";
  1047. if (strcmp($side, 'as_object')==0) {
  1048. $sql .= " WHERE FR.object_id = %d";
  1049. }
  1050. if (strcmp($side, 'as_subject')==0) {
  1051. $sql .= " WHERE FR.subject_id = %d";
  1052. }
  1053. $sql .= " ORDER BY FR.rank";
  1054. // get the relationships
  1055. $previous_db = tripal_db_set_active('chado'); // use chado database
  1056. $results = db_query($sql, $feature_id);
  1057. tripal_db_set_active($previous_db); // now use drupal database
  1058. // iterate through the relationships, put these in an array and add
  1059. // in the Drupal node id if one exists
  1060. $i=0;
  1061. $nodesql = "SELECT nid FROM {chado_feature} WHERE feature_id = %d";
  1062. $relationships = array();
  1063. while ($rel = db_fetch_object($results)) {
  1064. $node = db_fetch_object(db_query($nodesql, $rel->subject_id));
  1065. if ($node) {
  1066. $rel->subject_nid = $node->nid;
  1067. }
  1068. $node = db_fetch_object(db_query($nodesql, $rel->object_id));
  1069. if ($node) {
  1070. $rel->object_nid = $node->nid;
  1071. }
  1072. $relationships[$i++] = $rel;
  1073. }
  1074. return $relationships;
  1075. }
  1076. /**
  1077. *
  1078. *
  1079. * @ingroup tripal_feature
  1080. */
  1081. function tripal_feature_get_aggregate_types($feature_id) {
  1082. // get the feature details
  1083. $sql = 'SELECT type_id FROM {feature} WHERE feature_id = %d';
  1084. $previous_db = tripal_db_set_active('chado'); // use chado database
  1085. $feature = db_fetch_object(db_query($sql, $feature_id));
  1086. tripal_db_set_active($previous_db); // now use drupal database
  1087. // check to see if this feature is of a type with an aggregate
  1088. $sql = "SELECT * FROM {tripal_feature_relagg} WHERE type_id = %d";
  1089. $types = array();
  1090. $results = db_query($sql, $feature->type_id);
  1091. while ($agg = db_fetch_object($results)) {
  1092. $types[] = $agg->rel_type_id;
  1093. }
  1094. return $types;
  1095. }
  1096. /**
  1097. *
  1098. *
  1099. * @ingroup tripal_feature
  1100. */
  1101. function tripal_feature_get_aggregate_relationships($feature_id, $substitute=1,
  1102. $levels=0, $base_type_id=NULL, $depth=0) {
  1103. // we only want to recurse to as many levels deep as indicated by the
  1104. // $levels variable, but only if this variable is > 0. If 0 then we
  1105. // recurse until we reach the end of the relationships tree.
  1106. if ($levels > 0 and $levels == $depth) {
  1107. return NULL;
  1108. }
  1109. // first get the relationships for this feature
  1110. $relationships = tripal_feature_load_relationships($feature_id, 'as_object');
  1111. // next, iterate through these relationships and descend, adding in those
  1112. // that are specified by the aggregator.
  1113. $i=0;
  1114. $new_relationships = array();
  1115. foreach ($relationships as $rindex => $rel) {
  1116. // set the base type id
  1117. if (!$base_type_id) {
  1118. $base_type_id = $rel->object_type_id;
  1119. }
  1120. // check to see if we have an aggregator for this base type
  1121. $sql = "SELECT * FROM {tripal_feature_relagg} WHERE type_id = %d and rel_type_id = %d";
  1122. $agg = db_fetch_object(db_query($sql, $base_type_id, $rel->subject_type_id));
  1123. if ($agg) {
  1124. // if we're not going to substitute the resulting relationships for the
  1125. // parent then we need to add the parent to our list
  1126. if (!$substitute) {
  1127. $new_relationships[$i++] = $rel;
  1128. }
  1129. // recurse all relationships
  1130. $agg_relationships = tripal_feature_get_aggregate_relationships(
  1131. $rel->subject_id, $levels, $base_type_id, $depth++);
  1132. // if we have an aggregate defined but we have no relationships beyond
  1133. // this point then there's nothing we can substitute
  1134. if (!$agg_relationships and $substitute) {
  1135. $new_relationships[$i++] = $rel;
  1136. }
  1137. // merge all relationships into one array
  1138. foreach ($agg_relationships as $aindex => $arel) {
  1139. $new_relationships[$i++] = $arel;
  1140. }
  1141. }
  1142. else {
  1143. // if we don't have an aggregate then keep the current relationship
  1144. $new_relationships[$i++] = $rel;
  1145. }
  1146. }
  1147. return $new_relationships;
  1148. }
  1149. /**
  1150. *
  1151. *
  1152. * @ingroup tripal_feature
  1153. */
  1154. function tripal_feature_load_featureloc_sequences($feature_id, $featurelocs) {
  1155. // if we don't have any featurelocs then no point in continuing
  1156. if (!$featurelocs) {
  1157. return array();
  1158. }
  1159. // get the list of relationships (including any aggregators) and iterate
  1160. // through each one to find information needed to color-code the reference sequence
  1161. $relationships = tripal_feature_get_aggregate_relationships($feature_id);
  1162. if (!$relationships) {
  1163. return array();
  1164. }
  1165. // iterate through each of the realtionships features and get their
  1166. // locations
  1167. foreach ($relationships as $rindex => $rel) {
  1168. // get the featurelocs for each of the relationship features
  1169. $rel_featurelocs = tripal_feature_load_featurelocs($rel->subject_id, 'as_child', 0);
  1170. foreach ($rel_featurelocs as $rfindex => $rel_featureloc) {
  1171. // keep track of this unique source feature
  1172. $src = $rel_featureloc->src_feature_id ."-". $rel_featureloc->src_cvterm_id;
  1173. // copy over the results to the relationship object. Since there can
  1174. // be more than one feature location for each relationship feature we
  1175. // use the '$src' variable to keep track of these.
  1176. $rel->featurelocs->$src->src_uniquename = $rel_featureloc->src_uniquename;
  1177. $rel->featurelocs->$src->src_cvterm_id = $rel_featureloc->src_cvterm_id;
  1178. $rel->featurelocs->$src->src_cvname = $rel_featureloc->src_cvname;
  1179. $rel->featurelocs->$src->fmin = $rel_featureloc->fmin;
  1180. $rel->featurelocs->$src->fmax = $rel_featureloc->fmax;
  1181. $rel->featurelocs->$src->src_name = $rel_featureloc->src_name;
  1182. // keep track of the individual parts for each relationship
  1183. $start = $rel->featurelocs->$src->fmin;
  1184. $end = $rel->featurelocs->$src->fmax;
  1185. $type = $rel->subject_type;
  1186. $rel_locs[$src]['parts'][$start][$type]['start'] = $start;
  1187. $rel_locs[$src]['parts'][$start][$type]['end'] = $end;
  1188. $rel_locs[$src]['parts'][$start][$type]['type'] = $type;
  1189. }
  1190. }
  1191. // the featurelocs array provided to the function contains the locations
  1192. // where this feature is found. We want to get the sequence for each
  1193. // location and then annotate it with the parts found from the relationships
  1194. // locations determiend above.
  1195. $sql = "SELECT substring(residues from %d for %d) as residues ".
  1196. "FROM {feature} ".
  1197. "WHERE feature_id = %d";
  1198. $floc_sequences = array();
  1199. foreach ($featurelocs as $featureloc) {
  1200. // build the src name so we can keep track of the different parts for each feature
  1201. $src = $featureloc->srcfeature_id->feature_id ."-". $featureloc->srcfeature_id->type_id->cvterm_id;
  1202. // orient the parts to the beginning of the feature sequence
  1203. if (!empty($rel_locs[$src]['parts'])) {
  1204. $parts = $rel_locs[$src]['parts'];
  1205. usort($parts, 'tripal_feature_sort_rel_parts_by_start');
  1206. foreach ($parts as $start => $types) {
  1207. foreach ($types as $type_name => $type){
  1208. if ($featureloc->strand >= 0) {
  1209. // this is on the forward strand. We need to convert the start on the src feature to the
  1210. // start on this feature's sequence
  1211. $parts[$start][$type_name]['start'] = $parts[$start][$type_name]['start'] - $featureloc->fmin;
  1212. $parts[$start][$type_name]['end'] = $parts[$start][$type_name]['end'] - $featureloc->fmin;
  1213. }
  1214. else {
  1215. // this is on the reverse strand. We need to swap the start and stop and calculate from the
  1216. // begining of the reverse sequence
  1217. $size = ($featureloc->fmax - $featureloc->fmin);
  1218. $start_orig = $parts[$start][$type_name]['start'];
  1219. $end_orig = $parts[$start][$type_name]['end'];
  1220. $parts[$start][$type_name]['start'] = $size - ($end_orig - $featureloc->fmin);
  1221. $parts[$start][$type_name]['end'] = $size - ($start_orig - $featureloc->fmin);
  1222. }
  1223. }
  1224. }
  1225. // if we're on the reverse strand we need to reverse sort our parts
  1226. if ($featureloc->strand < 0) {
  1227. $new = array();
  1228. $keys = array_keys($parts);
  1229. for ($x = count($keys) - 1; $x >= 0 ; $x--) {
  1230. $new[] = $parts[$x];
  1231. }
  1232. $parts = $new;
  1233. }
  1234. $floc_sequences[$src]['src'] = $src;
  1235. $floc_sequences[$src]['type'] = $featureloc->feature_id->type_id->name;
  1236. $sequence = db_fetch_object(chado_query($sql, $featureloc->fmin + 1, ($featureloc->fmax - $featureloc->fmin), $featureloc->srcfeature_id->feature_id));
  1237. $residues = $sequence->residues;
  1238. if ($featureloc->strand < 0) {
  1239. $residues = tripal_feature_reverse_complement($residues);
  1240. }
  1241. $strand = '.';
  1242. if ($featureloc->strand == 1) {
  1243. $strand = '+';
  1244. }
  1245. elseif ($featureloc->strand == -1) {
  1246. $strand = '-';
  1247. }
  1248. $defline = $featureloc->feature_id->name . " " . $featureloc->srcfeature_id->name . ":" . ($featureloc->fmin + 1) . ".." . $featureloc->fmax . " " . $strand;
  1249. $floc_sequences[$src]['formatted_seq'] = tripal_feature_color_sequence($residues, $parts, $defline);
  1250. }
  1251. }
  1252. return $floc_sequences;
  1253. }
  1254. /**
  1255. *
  1256. *
  1257. * @ingroup tripal_feature
  1258. */
  1259. function tripal_feature_get_matched_alignments($feature) {
  1260. // This function is for features that align through an intermediate such
  1261. // as 'EST_match' or 'match'. This occurs in the case where two sequences
  1262. // align but where one does not align perfectly. Some ESTs may be in a contig
  1263. // but not all of the EST. Portions may overhang and not be included in the
  1264. // consensus if quality is bad.
  1265. // For example:
  1266. //
  1267. // Feature 1: Contig --------------------
  1268. // Feature 2: EST_match -------
  1269. // Feature 3: EST ---------
  1270. //
  1271. // The feature provided to the function will always be the feature 1. The
  1272. // featureloc columns prefixed with 'right' (e.g. right_fmin) belong to the
  1273. // alignment of feature 3 with feature 2
  1274. //
  1275. // Features may align to more than one feature and are not matches. We do
  1276. // not want to include these, so we have to filter on the SO terms:
  1277. // match, or %_match
  1278. //
  1279. $sql = "SELECT ".
  1280. " FL1.featureloc_id as left_featureloc_id, ".
  1281. " FL1.srcfeature_id as left_srcfeature_id, ".
  1282. " FL1.feature_id as left_feature_id, ".
  1283. " FL1.fmin as left_fmin, ".
  1284. " FL1.is_fmin_partial as left_is_fmin_partial, ".
  1285. " FL1.fmax as left_fmax, ".
  1286. " FL1.is_fmax_partial as left_is_fmax_partial, ".
  1287. " FL1.strand as left_strand, ".
  1288. " FL1.phase as left_phase, ".
  1289. " FL1.locgroup as left_locgroup, ".
  1290. " FL1.rank as left_rank, ".
  1291. " FL2.featureloc_id as right_featureloc_id, ".
  1292. " FL2.srcfeature_id as right_srcfeature_id, ".
  1293. " FL2.feature_id as right_feature_id, ".
  1294. " FL2.fmin as right_fmin, ".
  1295. " FL2.is_fmin_partial as right_is_fmin_partial, ".
  1296. " FL2.fmax as right_fmax, ".
  1297. " FL2.is_fmax_partial as right_is_fmax_partial, ".
  1298. " FL2.strand as right_strand, ".
  1299. " FL2.phase as right_phase, ".
  1300. " FL2.locgroup as right_locgroup, ".
  1301. " FL2.rank as right_rank ".
  1302. "FROM feature F1 ".
  1303. " INNER JOIN featureloc FL1 on FL1.srcfeature_id = F1.feature_id ".
  1304. " INNER JOIN feature F2 on FL1.feature_id = F2.feature_id ".
  1305. " INNER JOIN featureloc FL2 on FL2.feature_id = F2.feature_id ".
  1306. " INNER JOIN feature F3 on FL2.srcfeature_id = F3.feature_id ".
  1307. " INNER JOIN cvterm CVT2 on F2.type_id = CVT2.cvterm_id ".
  1308. "WHERE F1.feature_id = %d and NOT F3.feature_id = %d ".
  1309. " AND (CVT2.name = 'match' or CVT2.name like '%_match') ".
  1310. "ORDER BY FL1.fmin";
  1311. $results = db_query($sql, $feature->feature_id, $feature->feature_id);
  1312. // iterate through the results and add them to our featurelocs array
  1313. $featurelocs = array();
  1314. while ($fl = db_fetch_object($results)) {
  1315. $featurelocs[] = $fl ;
  1316. }
  1317. return $featurelocs;
  1318. }
  1319. /**
  1320. *
  1321. *
  1322. * @ingroup tripal_feature
  1323. */
  1324. function tripal_feature_load_organism_feature_counts($organism) {
  1325. // don't show the browser if the settings in the admin page is turned off
  1326. // instead return the array indicating the status of the browser
  1327. $show_counts = variable_get('tripal_feature_summary_setting', 'show_feature_summary');
  1328. if (strcmp($show_counts, 'show_feature_summary')!=0) {
  1329. return array('enabled' => FALSE );
  1330. }
  1331. $args = array();
  1332. $names = array();
  1333. $order = array();
  1334. // build the where clause for the SQL statement if we have a custom term list
  1335. // we'll also keep track of the names the admin provided (if any) and the
  1336. // order that the terms should appear.
  1337. $is_custom = 0;
  1338. $temp = rtrim(variable_get('tripal_feature_summary_report_mapping', ''));
  1339. $where = '';
  1340. if ($temp) {
  1341. $is_custom = 1;
  1342. $temp = explode("\n", $temp);
  1343. foreach ($temp as $key => $value) {
  1344. // separate the key value pairs
  1345. $temp2 = explode("=", $value);
  1346. $feature_type = rtrim($temp2[0]);
  1347. $args[] = $feature_type;
  1348. $order[] = $feature_type;
  1349. // if a new name is provided then use that otherwise just
  1350. // use the feature type
  1351. if (count($temp2) == 2) {
  1352. $names[] = rtrim($temp2[1]);
  1353. }
  1354. else {
  1355. $names[] = $feature_type;
  1356. }
  1357. $where .= "OFC.feature_type = '%s' OR \n";
  1358. }
  1359. if ($where) {
  1360. $where = drupal_substr($where, 0, -5); # remove OR from the end
  1361. $where = "($where) AND";
  1362. }
  1363. }
  1364. // get the feature counts. This is dependent on a materialized view
  1365. // installed with the organism module
  1366. $sql = "
  1367. SELECT OFC.num_features,OFC.feature_type,CVT.definition
  1368. FROM {organism_feature_count} OFC
  1369. INNER JOIN {cvterm} CVT on OFC.cvterm_id = CVT.cvterm_id
  1370. WHERE $where organism_id = %d
  1371. ORDER BY num_features desc
  1372. ";
  1373. $args[] = $organism->organism_id;
  1374. $previous_db = tripal_db_set_active('chado'); // use chado database
  1375. $org_features = db_query($sql, $args);
  1376. tripal_db_set_active($previous_db); // now use drupal database
  1377. // iterate through the types
  1378. $types = array();
  1379. while ($type = db_fetch_object($org_features)) {
  1380. $types[$type->feature_type] = $type;
  1381. // if we don't have an order this means we didn't go through the loop
  1382. // above to set the names, so do that now
  1383. if (!$is_custom) {
  1384. $names[] = $type->feature_type;
  1385. $order[] = $type->feature_type;
  1386. }
  1387. }
  1388. # now reorder the types
  1389. $ordered_types = array();
  1390. foreach ($order as $type) {
  1391. $ordered_types[] = $types[$type];
  1392. }
  1393. return array( 'types' => $ordered_types, 'names' => $names, 'enabled' => TRUE );
  1394. }
  1395. /**
  1396. *
  1397. *
  1398. * @ingroup tripal_feature
  1399. */
  1400. function tripal_feature_load_organism_feature_browser($organism) {
  1401. // don't show the browser if the settings in the admin page is turned off
  1402. // instead return the array indicating the status of the browser
  1403. $show_browser = variable_get('tripal_feature_browse_setting', 'show_feature_browser');
  1404. if (strcmp($show_browser, 'show_feature_browser')!=0) {
  1405. return array('enabled' => FALSE);
  1406. }
  1407. // get the list of available sequence ontology terms for which
  1408. // we will build drupal pages from features in chado. If a feature
  1409. // is not one of the specified typse we won't build a node for it.
  1410. $allowed_types = variable_get('chado_browser_feature_types', 'EST contig');
  1411. $allowed_types = preg_replace("/[\s\n\r]+/", " ", $allowed_types);
  1412. $so_terms = split(' ', $allowed_types);
  1413. $where_cvt = "";
  1414. foreach ($so_terms as $term) {
  1415. $where_cvt .= "CVT.name = '$term' OR ";
  1416. }
  1417. $where_cvt = drupal_substr($where_cvt, 0, drupal_strlen($where_cvt)-3); # strip trailing 'OR'
  1418. // get the features for this organism
  1419. $sql = "SELECT F.name,F.feature_id,F.uniquename,CVT.name as cvname ".
  1420. "FROM {feature} F ".
  1421. " INNER JOIN {cvterm} CVT on F.type_id = CVT.cvterm_id ".
  1422. "WHERE organism_id = %s and ($where_cvt) ".
  1423. "ORDER BY feature_id ASC";
  1424. // the counting SQL
  1425. $csql = "SELECT count(*) ".
  1426. "FROM {feature} F".
  1427. " INNER JOIN {cvterm} CVT on F.type_id = CVT.cvterm_id ".
  1428. "WHERE organism_id = %s and ($where_cvt) ".
  1429. "GROUP BY organism_id ";
  1430. $previous_db = tripal_db_set_active('chado'); // use chado database
  1431. $org_features = pager_query($sql, 10, 0, $csql, $organism->organism_id);
  1432. tripal_db_set_active($previous_db); // now use drupal database
  1433. $pager = theme('pager');
  1434. // prepare the query that will lookup node ids
  1435. $sql = "SELECT nid FROM {chado_feature} ".
  1436. "WHERE feature_id = %d";
  1437. $i=0;
  1438. $features = array();
  1439. while ($feature = db_fetch_object($org_features)) {
  1440. $node = db_fetch_object(db_query($sql, $feature->feature_id));
  1441. $feature->nid = $node->nid;
  1442. $features[$i++] = $feature;
  1443. }
  1444. return array( 'features' => $features, 'pager' => $pager, 'enabled' => TRUE );
  1445. }
  1446. /**
  1447. * This generates the Feature Browser which can optionally be included on library pages
  1448. * and shows all features belonging to the given library. This Browse can be shown/hidden
  1449. * on the Feature Configuration page.
  1450. *
  1451. * @ingroup tripal_feature
  1452. */
  1453. function tripal_feature_load_library_feature_browser($library) {
  1454. // don't show the browser if the settings in the admin page is turned off
  1455. // instead return the array indicating the status of the browser
  1456. $show_browser = variable_get('tripal_library_feature_browse_setting', 'show_feature_browser');
  1457. if (strcmp($show_browser, 'show_feature_browser')!=0) {
  1458. return array('enabled' => FALSE);
  1459. }
  1460. // get a list of feature types to include in the browser
  1461. $allowed_types = variable_get('chado_browser_feature_types', 'EST contig');
  1462. $allowed_types = preg_replace("/[\s\n\r]+/", " ", $allowed_types);
  1463. $so_terms = split(' ', $allowed_types);
  1464. $where_cvt = "";
  1465. foreach ($so_terms as $term) {
  1466. $where_cvt .= "CVT.name = '$term' OR ";
  1467. }
  1468. $where_cvt = drupal_substr($where_cvt, 0, drupal_strlen($where_cvt)-3); # strip trailing 'OR'
  1469. // get the features for this library
  1470. $sql = "SELECT F.name,F.feature_id,F.uniquename,CVT.name as cvname ".
  1471. "FROM {feature} F ".
  1472. " INNER JOIN {cvterm} CVT on F.type_id = CVT.cvterm_id ".
  1473. " INNER JOIN {library_feature} LF on F.feature_id = LF.feature_id ".
  1474. " INNER JOIN {library} L on LF.library_id = L.library_id ".
  1475. "WHERE LF.library_id = %d and ($where_cvt) ".
  1476. "ORDER BY feature_id ASC";
  1477. // the counting SQL
  1478. $csql = "SELECT count(*) ".
  1479. "FROM {feature} F".
  1480. " INNER JOIN {cvterm} CVT on F.type_id = CVT.cvterm_id ".
  1481. " INNER JOIN {library_feature} LF on F.feature_id = LF.feature_id ".
  1482. " INNER JOIN {library} L on LF.library_id = L.library_id ".
  1483. "WHERE LF.library_id = %d and ($where_cvt) ".
  1484. "GROUP BY L.library_id ";
  1485. $previous_db = tripal_db_set_active('chado'); // use chado database
  1486. $org_features = pager_query($sql, 10, 0, $csql, $library->library_id);
  1487. tripal_db_set_active($previous_db); // now use drupal database
  1488. $pager = theme('pager');
  1489. // prepare the query that will lookup node ids
  1490. $sql = "SELECT nid FROM {chado_feature} ".
  1491. "WHERE feature_id = %d";
  1492. $i=0;
  1493. $features = array();
  1494. while ($feature = db_fetch_object($org_features)) {
  1495. $node = db_fetch_object(db_query($sql, $feature->feature_id));
  1496. $feature->nid = $node->nid;
  1497. $features[$i++] = $feature;
  1498. }
  1499. return array( 'features' => $features, 'pager' => $pager, 'enabled' => TRUE );
  1500. }
  1501. /**
  1502. * This generates the Feature Browse which can optionally be included on library pages
  1503. * and shows all features belonging to the given library. This Browse can be shown/hidden
  1504. * on the Feature Configuration page.
  1505. *
  1506. * @ingroup tripal_feature
  1507. */
  1508. function tripal_feature_load_analysis_feature_browser($analysis) {
  1509. // don't show the browser if the settings in the admin page is turned off
  1510. // instead return the array indicating the status of the browser
  1511. $show_browser = variable_get('tripal_analysis_feature_browse_setting', 'show_feature_browser');
  1512. if (strcmp($show_browser, 'show_feature_browser')!=0) {
  1513. return array('enabled' => FALSE);
  1514. }
  1515. // get a list of feature types to include in the browser
  1516. $allowed_types = variable_get('chado_browser_feature_types', 'EST contig');
  1517. $allowed_types = preg_replace("/[\s\n\r]+/", " ", $allowed_types);
  1518. $so_terms = split(' ', $allowed_types);
  1519. $where_cvt = "";
  1520. foreach ($so_terms as $term) {
  1521. $where_cvt .= "CVT.name = '$term' OR ";
  1522. }
  1523. $where_cvt = drupal_substr($where_cvt, 0, drupal_strlen($where_cvt)-3); # strip trailing 'OR'
  1524. // get the features for this library
  1525. $sql = "SELECT F.name,F.feature_id,F.uniquename,CVT.name as cvname ".
  1526. "FROM {feature} F ".
  1527. " INNER JOIN {cvterm} CVT on F.type_id = CVT.cvterm_id ".
  1528. " INNER JOIN {analysisfeature} AF on F.feature_id = AF.feature_id ".
  1529. " INNER JOIN {analysis} A on AF.analysis_id = A.analysis_id ".
  1530. "WHERE A.analysis_id = %d and ($where_cvt) ".
  1531. "ORDER BY feature_id ASC";
  1532. // the counting SQL
  1533. $csql = "SELECT count(*) ".
  1534. "FROM {feature} F".
  1535. " INNER JOIN {cvterm} CVT on F.type_id = CVT.cvterm_id ".
  1536. " INNER JOIN {analysisfeature} AF on F.feature_id = AF.feature_id ".
  1537. " INNER JOIN {analysis} A on AF.analysis_id = A.analysis_id ".
  1538. "WHERE A.analysis_id = %d and ($where_cvt) ".
  1539. "GROUP BY A.analysis_id ";
  1540. $previous_db = tripal_db_set_active('chado'); // use chado database
  1541. $org_features = pager_query($sql, 10, 0, $csql, $analysis->analysis_id);
  1542. tripal_db_set_active($previous_db); // now use drupal database
  1543. $pager = theme('pager');
  1544. // prepare the query that will lookup node ids
  1545. $sql = "SELECT nid FROM {chado_feature} ".
  1546. "WHERE feature_id = %d";
  1547. $i=0;
  1548. $features = array();
  1549. while ($feature = db_fetch_object($org_features)) {
  1550. $node = db_fetch_object(db_query($sql, $feature->feature_id));
  1551. $feature->nid = $node->nid;
  1552. $features[$i++] = $feature;
  1553. }
  1554. return array( 'features' => $features, 'pager' => $pager, 'enabled' => TRUE );
  1555. }
  1556. /**
  1557. * used to sort the list of relationship objects by start position
  1558. *
  1559. * @ingroup tripal_feature
  1560. */
  1561. function tripal_feature_sort_rel_objects($a, $b) {
  1562. return strnatcmp($a->fmin, $b->fmin);
  1563. }
  1564. /**
  1565. * used to sort the list of relationship parts by start position
  1566. *
  1567. * @ingroup tripal_feature
  1568. */
  1569. function tripal_feature_sort_rel_parts_by_start($a, $b) {
  1570. foreach ($a as $type_name => $details){
  1571. $astart = $a[$type_name]['start'];
  1572. break;
  1573. }
  1574. foreach ($b as $type_name => $details){
  1575. $bstart = $b[$type_name]['start'];
  1576. break;
  1577. }
  1578. return strnatcmp($astart, $bstart);
  1579. }
  1580. /**
  1581. * used to sort the list of relationship parts by start position
  1582. *
  1583. * @ingroup tripal_feature
  1584. */
  1585. function tripal_feature_sort_rel_parts_by_end($a, $b) {
  1586. if ($a['end'] == $b['end']) {
  1587. return strcmp($a['type'], $b['type']);
  1588. }
  1589. return strnatcmp($a['end'], $b['end']);
  1590. }
  1591. /**
  1592. *
  1593. *
  1594. * @ingroup tripal_feature
  1595. */
  1596. function tripal_feature_color_sequence($sequence, $parts, $defline) {
  1597. $types = array();
  1598. // first get the list of types so we can create a color legend
  1599. foreach ($parts as $index => $types) {
  1600. foreach ($types as $type_name => $details){
  1601. //if (!in_array($type_name, $types)) {
  1602. $types[$type_name] = 1;
  1603. //}
  1604. }
  1605. }
  1606. $newseq .= "<div id=\"tripal_feature-featureloc_sequence-legend\">Legend: ";
  1607. foreach ($types as $type_name => $present) {
  1608. $newseq .= "<span class=\"tripal_feature-featureloc_sequence-$type_name\">$type_name</span>";
  1609. }
  1610. $newseq .= "</div>";
  1611. // set the background color of the rows based on the type
  1612. $pos = 0;
  1613. $newseq .= "<pre id=\"tripal_feature-featureloc_sequence\">";
  1614. $newseq .= ">$defline\n";
  1615. // iterate through the parts. They should be in order.
  1616. foreach ($parts as $index => $types) {
  1617. // get the start for this part. All types in this part start at the
  1618. // same position so we only need the first record
  1619. foreach ($types as $type => $child) {
  1620. $start = $child['start'];
  1621. break;
  1622. }
  1623. // add in the sequence up to the start of this part
  1624. for ($i = $pos; $i < $start; $i++) {
  1625. $newseq .= $sequence{$pos};
  1626. $seqcount++;
  1627. if ($seqcount % 50 == 0) {
  1628. $newseq .= "\n";
  1629. }
  1630. $pos++;
  1631. }
  1632. // we want to sort the parts by their end. We want the span tag to
  1633. // to be added in the order the parts end.
  1634. usort($types,'tripal_feature_sort_rel_parts_by_end');
  1635. // now add the child span for all types that start at this position
  1636. foreach ($types as $type) {
  1637. $class = "class=\"tripal_feature-featureloc_sequence-" . $type['type'] ."\"";
  1638. $newseq .= "<span $class>";
  1639. }
  1640. // now continue adding sequence until we reach the end of the parts
  1641. // if we reach the end then close the span
  1642. $parts_done = 0;
  1643. while($parts_done < count($types)){
  1644. $newseq .= $sequence{$pos};
  1645. $seqcount++;
  1646. $pos++;
  1647. if ($seqcount % 50 == 0) {
  1648. $newseq .= "\n";
  1649. }
  1650. foreach ($types as $type => $child) {
  1651. $end = $child['end'];
  1652. if($pos == $end){
  1653. $newseq .= "</span>";
  1654. $parts_done++;
  1655. }
  1656. }
  1657. }
  1658. }
  1659. $newseq .= "</pre>";
  1660. return $newseq;
  1661. }
  1662. /**
  1663. * This function customizes the view of the chado_feature node. It allows
  1664. * us to generate the markup.
  1665. *
  1666. * @ingroup tripal_feature
  1667. */
  1668. function chado_feature_view($node, $teaser = FALSE, $page = FALSE) {
  1669. if (!$teaser) {
  1670. // use drupal's default node view:
  1671. $node = node_prepare($node, $teaser);
  1672. // if we're building the node for searching then
  1673. // we want to handle this within the module and
  1674. // not allow theme customization. We don't want to
  1675. // index all items (such as DNA sequence).
  1676. if ($node->build_mode == NODE_BUILD_SEARCH_INDEX) {
  1677. $node->content['index_version'] = array(
  1678. '#value' => theme('tripal_feature_search_index', $node),
  1679. '#weight' => 1,
  1680. );
  1681. }
  1682. elseif ($node->build_mode == NODE_BUILD_SEARCH_RESULT) {
  1683. $node->content['index_version'] = array(
  1684. '#value' => theme('tripal_feature_search_results', $node),
  1685. '#weight' => 1,
  1686. );
  1687. }
  1688. else {
  1689. // do nothing here, let the theme derived template handle display
  1690. }
  1691. }
  1692. return $node;
  1693. }
  1694. /**
  1695. * Display feature information for associated organisms. This function also
  1696. * provides contents for indexing
  1697. *
  1698. * @ingroup tripal_feature
  1699. */
  1700. function tripal_feature_nodeapi(&$node, $op, $teaser, $page) {
  1701. switch ($op) {
  1702. // Note that this function only adds feature view to an organism node.
  1703. // The view of a feature node is controled by the theme *.tpl file
  1704. case 'view':
  1705. switch ($node->type) {
  1706. case 'chado_organism':
  1707. // Show feature browser
  1708. $types_to_show = array('chado_organism', 'chado_library');
  1709. if (in_array($node->type, $types_to_show, TRUE)) {
  1710. $node->content['tripal_organism_feature_counts'] = array(
  1711. '#value' => theme('tripal_organism_feature_counts', $node),
  1712. );
  1713. $node->content['tripal_organism_feature_browser'] = array(
  1714. '#value' => theme('tripal_organism_feature_browser', $node),
  1715. );
  1716. }
  1717. break;
  1718. case 'chado_library':
  1719. $node->content['tripal_library_feature_browser'] = array(
  1720. '#value' => theme('tripal_library_feature_browser', $node),
  1721. );
  1722. break;
  1723. case 'chado_analysis':
  1724. $node->content['tripal_analysis_feature_browser'] = array(
  1725. '#value' => theme('tripal_analysis_feature_browser', $node),
  1726. );
  1727. break;
  1728. default:
  1729. }
  1730. break;
  1731. }
  1732. }
  1733. /**
  1734. * We need to let drupal know about our theme functions and their arguments.
  1735. * We create theme functions to allow users of the module to customize the
  1736. * look and feel of the output generated in this module
  1737. *
  1738. * @ingroup tripal_feature
  1739. */
  1740. function tripal_feature_theme() {
  1741. return array(
  1742. 'tripal_feature_search_index' => array(
  1743. 'arguments' => array('node'),
  1744. ),
  1745. 'tripal_feature_search_results' => array(
  1746. 'arguments' => array('node'),
  1747. ),
  1748. 'tripal_organism_feature_browser' => array(
  1749. 'arguments' => array('node' => NULL),
  1750. 'template' => 'tripal_organism_feature_browser',
  1751. ),
  1752. 'tripal_organism_feature_counts' => array(
  1753. 'arguments' => array('node' => NULL),
  1754. 'template' => 'tripal_organism_feature_counts',
  1755. ),
  1756. 'tripal_library_feature_browser' => array(
  1757. 'arguments' => array('node' => NULL),
  1758. 'template' => 'tripal_library_feature_browser',
  1759. ),
  1760. 'tripal_analysis_feature_browser' => array(
  1761. 'arguments' => array('node' => NULL),
  1762. 'template' => 'tripal_analysis_feature_browser',
  1763. ),
  1764. 'tripal_feature_base' => array(
  1765. 'arguments' => array('node' => NULL),
  1766. 'template' => 'tripal_feature_base',
  1767. ),
  1768. 'tripal_feature_sequence' => array(
  1769. 'arguments' => array('node' => NULL),
  1770. 'template' => 'tripal_feature_sequence',
  1771. ),
  1772. 'tripal_feature_synonyms' => array(
  1773. 'arguments' => array('node' => NULL),
  1774. 'template' => 'tripal_feature_synonyms',
  1775. ),
  1776. 'tripal_feature_featureloc_sequences' => array(
  1777. 'arguments' => array('node' => NULL),
  1778. 'template' => 'tripal_feature_featureloc_sequences',
  1779. ),
  1780. 'tripal_feature_references' => array(
  1781. 'arguments' => array('node' => NULL),
  1782. 'template' => 'tripal_feature_references',
  1783. ),
  1784. 'tripal_feature_properties' => array(
  1785. 'arguments' => array('node' => NULL),
  1786. 'template' => 'tripal_feature_properties',
  1787. ),
  1788. 'tripal_feature_alignments' => array(
  1789. 'arguments' => array('node' => NULL),
  1790. 'template' => 'tripal_feature_alignments',
  1791. ),
  1792. 'tripal_feature_relationships' => array(
  1793. 'arguments' => array('node' => NULL),
  1794. 'template' => 'tripal_feature_relationships',
  1795. ),
  1796. 'tripal_feature_edit_ALL_properties_form' => array(
  1797. 'arguments' => array('form' => NULL),
  1798. 'function' => 'theme_tripal_feature_edit_ALL_properties_form',
  1799. ),
  1800. );
  1801. }
  1802. /**
  1803. *
  1804. *
  1805. * @ingroup tripal_feature
  1806. */
  1807. function tripal_feature_preprocess_tripal_feature_relationships(&$variables) {
  1808. // we want to provide a new variable that contains the matched features.
  1809. $feature = $variables['node']->feature;
  1810. // expand the feature object to include the feature relationships.
  1811. $feature = tripal_core_expand_chado_vars($feature,
  1812. 'table','feature_relationship', array('order_by'=>array('rank' => 'ASC')));
  1813. // get the subject relationships
  1814. $srelationships = $feature->feature_relationship->subject_id;
  1815. if (!$srelationships) {
  1816. $srelationships = array();
  1817. }
  1818. elseif (!is_array($srelationships)) {
  1819. $srelationships = array($srelationships);
  1820. }
  1821. // get the object relationships
  1822. $orelationships = $feature->feature_relationship->object_id;
  1823. if (!$orelationships) {
  1824. $orelationships = array();
  1825. }
  1826. elseif (!is_array($orelationships)) {
  1827. $orelationships = array($orelationships);
  1828. }
  1829. // get alignment as child
  1830. $cfeaturelocs = $feature->featureloc->feature_id;
  1831. if (!$cfeaturelocs) {
  1832. $cfeaturelocs = array();
  1833. }
  1834. elseif (!is_array($cfeaturelocs)) {
  1835. $cfeaturelocs = array($cfeaturelocs);
  1836. }
  1837. // prepare the SQL statement to get the featureloc for the
  1838. // feature in the relationships.
  1839. if(!tripal_core_is_sql_prepared('sel_featureloc_preprocess_relationships')){
  1840. $psql = "PREPARE sel_featureloc_preprocess_relationships (int, int) AS " .
  1841. "SELECT FL.featureloc_id, F.name as srcfeature_name, FL.srcfeature_id, ".
  1842. " FL.feature_id, FL.fmin, FL.fmax, FL.strand, FL.phase ".
  1843. "FROM featureloc FL " .
  1844. " INNER JOIN feature F ON F.feature_id = FL.srcfeature_id ".
  1845. "WHERE FL.feature_id = $1 and FL.srcfeature_id = $2";
  1846. $prepared = chado_query($psql);
  1847. if(!$prepared){
  1848. watchdog('tripal_feature', "tripal_feature_preprocess_tripal_feature_relationships: not able to prepare '%name' statement for: %sql", array('%name' => 'sel_featureloc_preprocess_relationships', '%sql' => $psql), 'WATCHDOG ERROR');
  1849. return FALSE;
  1850. }
  1851. }
  1852. // combine both object and subject relationshisp into a single array
  1853. $relationships = array();
  1854. $relationships['object'] = array();
  1855. $relationships['subject'] = array();
  1856. // iterate through the object relationships
  1857. foreach ($orelationships as $relationship) {
  1858. $rel = new stdClass();
  1859. // get locations where the child feature and this feature overlap with the
  1860. // same landmark feature.
  1861. $rel->child_featurelocs = array();
  1862. foreach ($cfeaturelocs as $featureloc) {
  1863. $res = chado_query("EXECUTE sel_featureloc_preprocess_relationships (%d, %d)",
  1864. $relationship->subject_id->feature_id,
  1865. $featureloc->srcfeature_id->feature_id);
  1866. while ($loc = db_fetch_object($res)){
  1867. // add in the node id of the src feature if it exists and save this location
  1868. $loc->nid = $featureloc->srcfeature_id->nid;
  1869. $rel->child_featurelocs[] = $loc;
  1870. }
  1871. }
  1872. $rel->record = $relationship;
  1873. // get the relationship and child types
  1874. $rel_type = t(preg_replace('/_/'," ",$relationship->type_id->name));
  1875. $child_type = $relationship->subject_id->type_id->name;
  1876. // get the node id of the subject
  1877. $sql = "SELECT nid FROM chado_feature WHERE feature_id = %d";
  1878. $n = db_fetch_object(db_query($sql,$relationship->subject_id->feature_id));
  1879. if($n){
  1880. $rel->record->nid = $n->nid;
  1881. }
  1882. if (!array_key_exists($rel_type, $relationships['object'])) {
  1883. $relationships['object'][$rel_type] = array();
  1884. }
  1885. if (!array_key_exists($child_type, $relationships['object'][$rel_type])) {
  1886. $relationships['object'][$rel_type][$child_type] = array();
  1887. }
  1888. $relationships['object'][$rel_type][$child_type][] = $rel;
  1889. }
  1890. // now add in the subject relationships
  1891. foreach ($srelationships as $relationship) {
  1892. $rel = new stdClass();
  1893. // get locations where this feature overlaps with the parent
  1894. $rel->parent_featurelocs = array();
  1895. foreach ($cfeaturelocs as $featureloc) {
  1896. $res = chado_query("EXECUTE sel_featureloc_preprocess_relationships (%d, %d)",
  1897. $relationship->object_id->feature_id,
  1898. $featureloc->srcfeature_id->feature_id);
  1899. while ($loc = db_fetch_object($res)){
  1900. // add in the node id of the src feature if it exists and save this location
  1901. $loc->nid = $featureloc->srcfeature_id->nid;
  1902. $rel->parent_featurelocs[] = $loc;
  1903. }
  1904. }
  1905. $rel->record = $relationship;
  1906. $rel_type = t(preg_replace('/_/'," ",$relationship->type_id->name));
  1907. $parent_type = $relationship->object_id->type_id->name;
  1908. // get the node id of the subject
  1909. $sql = "SELECT nid FROM chado_feature WHERE feature_id = %d";
  1910. $n = db_fetch_object(db_query($sql,$relationship->object_id->feature_id));
  1911. if($n){
  1912. $rel->record->nid = $n->nid;
  1913. }
  1914. if (!array_key_exists($rel_type, $relationships['subject'])) {
  1915. $relationships['subject'][$rel_type] = array();
  1916. }
  1917. if (!array_key_exists($child_type, $relationships['subject'][$rel_type])) {
  1918. $relationships['subject'][$rel_type][$parent_type] = array();
  1919. }
  1920. $relationships['subject'][$rel_type][$parent_type][] = $rel;
  1921. }
  1922. $feature->all_relationships = $relationships;
  1923. }
  1924. /**
  1925. *
  1926. *
  1927. * @ingroup tripal_feature
  1928. */
  1929. function tripal_feature_preprocess_tripal_feature_alignments(&$variables) {
  1930. // we want to provide a new variable that contains the matched features.
  1931. $feature = $variables['node']->feature;
  1932. // get alignments as child
  1933. $cfeaturelocs = $feature->featureloc->feature_id;
  1934. if (!$cfeaturelocs) {
  1935. $cfeaturelocs = array();
  1936. }
  1937. elseif (!is_array($cfeaturelocs)) {
  1938. $cfeaturelocs = array($cfeaturelocs);
  1939. }
  1940. // get alignment as parent
  1941. $pfeaturelocs = $feature->featureloc->srcfeature_id;
  1942. if (!$pfeaturelocs) {
  1943. $pfeaturelocs = array();
  1944. }
  1945. elseif (!is_array($pfeaturelocs)) {
  1946. $pfeaturelocs = array($pfeaturelocs);
  1947. }
  1948. // get matched alignments (those with an itermediate 'match' or 'EST_match', etc
  1949. $mfeaturelocs = tripal_feature_get_matched_alignments($feature);
  1950. $feature->matched_featurelocs = tripal_feature_get_matched_alignments($feature);
  1951. // combine all three alignments into a single array for printing together in
  1952. // a single list
  1953. $alignments = array();
  1954. foreach ($pfeaturelocs as $featureloc) {
  1955. // if type is a 'match' then ignore it. We will handle those below
  1956. if (preg_match('/(^match$|^.*?_match)$/', $featureloc->feature_id->type_id->name)) {
  1957. continue;
  1958. }
  1959. $alignment = new stdClass();
  1960. $alignment->record = $featureloc;
  1961. $alignment->name = $featureloc->feature_id->name;
  1962. $alignment->nid = $featureloc->feature_id->nid;
  1963. $alignment->type = $featureloc->feature_id->type_id->name;
  1964. $alignment->fmin = $featureloc->fmin;
  1965. $alignment->fmax = $featureloc->fmax;
  1966. $alignment->phase = $featureloc->phase;
  1967. $alignment->strand = $featureloc->strand;
  1968. $alignments[] = $alignment;
  1969. }
  1970. foreach ($cfeaturelocs as $featureloc) {
  1971. // if type is a 'match' then ignore it. We will handle those below
  1972. if (preg_match('/(^match$|^.*?_match)$/', $featureloc->feature_id->type_id->name)) {
  1973. continue;
  1974. }
  1975. $alignment = new stdClass();
  1976. $alignment->record = $featureloc;
  1977. $alignment->name = $featureloc->srcfeature_id->name;
  1978. $alignment->nid = $featureloc->srcfeature_id->nid;
  1979. $alignment->type = $featureloc->srcfeature_id->type_id->name;
  1980. $alignment->fmin = $featureloc->fmin;
  1981. $alignment->is_fmin_partial = $featureloc->is_fmin_partial;
  1982. $alignment->fmax = $featureloc->fmax;
  1983. $alignment->is_fmax_partial = $featureloc->is_fmax_partial;
  1984. $alignment->phase = $featureloc->phase;
  1985. $alignment->strand = $featureloc->strand;
  1986. $alignments[] = $alignment;
  1987. }
  1988. // in matching features, the left feature is always the feature
  1989. // provided to this function.
  1990. foreach ($mfeaturelocs as $featureloc) {
  1991. // get more information about the right feature
  1992. $select = array('feature_id' => $featureloc->right_srcfeature_id);
  1993. $rfeature = tripal_core_generate_chado_var('feature', $select);
  1994. // now add to the list
  1995. $alignment = new stdClass();
  1996. $alignment->record = $featureloc;
  1997. $alignment->right_feature = $rfeature;
  1998. $alignment->name = $rfeature->name;
  1999. $alignment->nid = $rfeature->nid;
  2000. $alignment->type = $rfeature->type_id->name;
  2001. $alignment->fmin = $featureloc->left_fmin;
  2002. $alignment->is_fmin_partial = $featureloc->left_is_fmin_partial;
  2003. $alignment->fmax = $featureloc->left_fmax;
  2004. $alignment->is_fmax_partial = $featureloc->left_is_fmax_partial;
  2005. $alignment->phase = $featureloc->left_phase;
  2006. $alignment->strand = $featureloc->left_strand;
  2007. $alignment->right_fmin = $featureloc->right_fmin;
  2008. $alignment->right_is_fmin_partial = $featureloc->right_is_fmin_partial;
  2009. $alignment->right_fmax = $featureloc->right_fmax;
  2010. $alignment->right_is_fmax_partial = $featureloc->right_is_fmax_partial;
  2011. $alignment->right_phase = $featureloc->right_phase;
  2012. $alignment->right_strand = $featureloc->right_strand;
  2013. $alignments[] = $alignment;
  2014. }
  2015. $feature->all_featurelocs = $alignments;
  2016. }
  2017. /**
  2018. *
  2019. *
  2020. * @ingroup tripal_feature
  2021. */
  2022. function tripal_feature_preprocess_tripal_organism_feature_counts(&$variables) {
  2023. $organism = $variables['node']->organism;
  2024. $organism->feature_counts = tripal_feature_load_organism_feature_counts($organism);
  2025. }
  2026. /**
  2027. *
  2028. *
  2029. * @ingroup tripal_feature
  2030. */
  2031. function tripal_feature_preprocess_tripal_organism_feature_browser(&$variables) {
  2032. $organism = $variables['node']->organism;
  2033. $organism->feature_browser = tripal_feature_load_organism_feature_browser($organism);
  2034. }
  2035. /**
  2036. * Preprocessor function for the Library Feature Browser
  2037. *
  2038. * @ingroup tripal_feature
  2039. */
  2040. function tripal_feature_preprocess_tripal_library_feature_browser(&$variables) {
  2041. $library = $variables['node']->library;
  2042. $library->feature_browser = tripal_feature_load_library_feature_browser($library);
  2043. }
  2044. /**
  2045. * Preprocessor function for the Analysis Feature Browser
  2046. *
  2047. * @ingroup tripal_feature
  2048. */
  2049. function tripal_feature_preprocess_tripal_analysis_feature_browser(&$variables) {
  2050. $analysis = $variables['node']->analysis;
  2051. $analysis->feature_browser = tripal_feature_load_analysis_feature_browser($analysis);
  2052. }
  2053. /**
  2054. *
  2055. *
  2056. * @ingroup tripal_feature
  2057. */
  2058. function tripal_feature_cv_chart($chart_id) {
  2059. // we only want the chart to show feature types setup by the admin
  2060. $temp = rtrim(variable_get('tripal_feature_summary_report_mapping', ''));
  2061. $where = '';
  2062. if ($temp) {
  2063. $temp = explode("\n", $temp);
  2064. foreach ($temp as $key => $value) {
  2065. $temp2 = explode("=", $value);
  2066. $feature_type = rtrim($temp2[0]);
  2067. $where .= "CNT.feature_type = '$feature_type' OR \n";
  2068. }
  2069. if ($where) {
  2070. $where = drupal_substr($where, 0, -5); # remove OR from the end
  2071. $where = "($where) AND";
  2072. }
  2073. }
  2074. $organism_id = preg_replace("/^tripal_feature_cv_chart_(\d+)$/", "$1", $chart_id);
  2075. // The CV module will create the JSON array necessary for buillding a
  2076. // pie chart using jgChart and Google Charts. We have to pass to it
  2077. // a table that contains count information, tell it which column
  2078. // contains the cvterm_id and provide a filter for getting the
  2079. // results we want from the table.
  2080. $options = array(
  2081. count_mview => 'organism_feature_count',
  2082. cvterm_id_column => 'cvterm_id',
  2083. count_column => 'num_features',
  2084. size => '550x200',
  2085. filter => "$where CNT.organism_id = $organism_id",
  2086. );
  2087. return $options;
  2088. }
  2089. /**
  2090. *
  2091. *
  2092. * @ingroup tripal_feature
  2093. */
  2094. function tripal_feature_cv_tree($tree_id) {
  2095. // The CV module will create the JSON array necessary for buillding a
  2096. // pie chart using jgChart and Google Charts. We have to pass to it
  2097. // a table that contains count information, tell it which column
  2098. // contains the cvterm_id and provide a filter for getting the
  2099. // results we want from the table.
  2100. $organism_id = preg_replace("/^tripal_feature_cv_tree_(\d+)$/", "$1", $tree_id);
  2101. $options = array(
  2102. cv_id => tripal_cv_get_cv_id('sequence'),
  2103. count_mview => 'organism_feature_count',
  2104. cvterm_id_column => 'cvterm_id',
  2105. count_column => 'num_features',
  2106. filter => "CNT.organism_id = $organism_id",
  2107. label => 'Features',
  2108. );
  2109. return $options;
  2110. }
  2111. /**
  2112. * This function is an extension of the chado_feature_view by providing
  2113. * the markup for the feature object THAT WILL BE INDEXED.
  2114. *
  2115. * @ingroup tripal_feature
  2116. */
  2117. function theme_tripal_feature_search_index($node) {
  2118. $feature = $node->feature;
  2119. $content = '';
  2120. // get the accession prefix
  2121. $aprefix = variable_get('chado_feature_accession_prefix', 'ID');
  2122. $content .= "<h1>$feature->uniquename</h1>. ";
  2123. $content .= "<strong>$aprefix$feature->feature_id.</strong> ";
  2124. $content .= "$feature->cvname ";
  2125. $content .= "$feature->common_name ";
  2126. // add the synonyms of this feature to the text for searching
  2127. $synonyms = $node->synonyms;
  2128. if (count($synonyms) > 0) {
  2129. foreach ($synonyms as $result) {
  2130. $content .= "$result->name ";
  2131. }
  2132. }
  2133. return $content;
  2134. }
  2135. /**
  2136. * This function is an extension of the chado_feature_view by providing
  2137. * the markup for the feature object THAT WILL BE INDEXED.
  2138. *
  2139. * @ingroup tripal_feature
  2140. */
  2141. function theme_tripal_feature_search_results($node) {
  2142. $feature = $node->feature;
  2143. $content = '';
  2144. // get the accession prefix
  2145. $aprefix = variable_get('chado_feature_accession_prefix', 'ID');
  2146. $content .= "Feature Name: <h1>$feature->uniquename</h1>. ";
  2147. $content .= "<strong>Accession: $aprefix$feature->feature_id.</strong>";
  2148. $content .= "Type: $feature->cvname. ";
  2149. $content .= "Organism: $feature->common_name. ";
  2150. // add the synonyms of this feature to the text for searching
  2151. $synonyms = $node->synonyms;
  2152. if (count($synonyms) > 0) {
  2153. $content .= "Synonyms: ";
  2154. foreach ($synonyms as $result) {
  2155. $content .= "$result->name, ";
  2156. }
  2157. }
  2158. return $content;
  2159. }
  2160. /**
  2161. *
  2162. *
  2163. * @ingroup tripal_feature
  2164. */
  2165. function tripal_feature_set_vocabulary() {
  2166. //include the file containing the required functions for adding taxonomy vocabs
  2167. module_load_include('inc', 'taxonomy', 'taxonomy.admin');
  2168. // get the vocabularies so that we make sure we don't recreate
  2169. // the vocabs that already exist
  2170. $vocabularies = taxonomy_get_vocabularies();
  2171. $ft_vid = NULL;
  2172. $op_vid = NULL;
  2173. $lb_vid = NULL;
  2174. $an_vid = NULL;
  2175. // These taxonomic terms are hard coded because we
  2176. // konw we have these relationships in the chado tables
  2177. // through foreign key relationships. The tripal
  2178. // modules that correspond to these chado "modules" don't
  2179. // need to be installed for the taxonomy to work.
  2180. foreach ($vocabularies as $vocab) {
  2181. if ($vocab->name == 'Feature Type') {
  2182. $ft_vid = $vocab->vid;
  2183. }
  2184. if ($vocab->name == 'Organism') {
  2185. $op_vid = $vocab->vid;
  2186. }
  2187. if ($vocab->name == 'Library') {
  2188. $lb_vid = $vocab->vid;
  2189. }
  2190. if ($vocab->name == 'Analysis') {
  2191. $an_vid = $vocab->vid;
  2192. }
  2193. }
  2194. if (!$ft_vid) {
  2195. $form_state = array();
  2196. $values = array(
  2197. 'name' => t('Feature Type'),
  2198. 'nodes' => array('chado_feature' => 'chado_feature'),
  2199. 'description' => t('The feature type (or SO cvterm for this feature).'),
  2200. 'help' => t('Select the term that matches the feature'),
  2201. 'tags' => 0,
  2202. 'hierarchy' => 1,
  2203. 'relations' => 1,
  2204. 'multiple' => 0,
  2205. 'required' => 0,
  2206. 'weight' => 1,
  2207. );
  2208. drupal_execute('taxonomy_form_vocabulary', $form_state, $values);
  2209. drupal_execute('taxonomy_form_vocabulary', $form_state);
  2210. }
  2211. if (!$op_vid) {
  2212. $form_state = array();
  2213. $values = array(
  2214. 'name' => t('Organism'),
  2215. 'nodes' => array('chado_feature' => 'chado_feature'),
  2216. 'description' => t('The organism to which this feature belongs.'),
  2217. 'help' => t('Select the term that matches the feature'),
  2218. 'tags' => 0,
  2219. 'hierarchy' => 1,
  2220. 'relations' => 1,
  2221. 'multiple' => 0,
  2222. 'required' => 0,
  2223. 'weight' => 2,
  2224. );
  2225. drupal_execute('taxonomy_form_vocabulary', $form_state, $values);
  2226. drupal_execute('taxonomy_form_vocabulary', $form_state);
  2227. }
  2228. if (!$lb_vid) {
  2229. $form_state = array();
  2230. $values = array(
  2231. 'name' => t('Library'),
  2232. 'nodes' => array('chado_feature' => 'chado_feature'),
  2233. 'description' => t('Chado features associated with a library are assigned the term associated with the library'),
  2234. 'help' => t('Select the term that matches the feature'),
  2235. 'tags' => 0,
  2236. 'hierarchy' => 1,
  2237. 'relations' => 1,
  2238. 'multiple' => 0,
  2239. 'required' => 0,
  2240. 'weight' => 3,
  2241. );
  2242. drupal_execute('taxonomy_form_vocabulary', $form_state, $values);
  2243. drupal_execute('taxonomy_form_vocabulary', $form_state);
  2244. }
  2245. if (!$an_vid) {
  2246. $form_state = array();
  2247. $values = array(
  2248. 'name' => t('Analysis'),
  2249. 'nodes' => array('chado_feature' => 'chado_feature'),
  2250. 'description' => t('Any analysis to which this feature belongs.'),
  2251. 'help' => t('Select the term that matches the feature'),
  2252. 'tags' => 0,
  2253. 'hierarchy' => 1,
  2254. 'relations' => 1,
  2255. 'multiple' => 1,
  2256. 'required' => 0,
  2257. 'weight' => 4,
  2258. );
  2259. drupal_execute('taxonomy_form_vocabulary', $form_state, $values);
  2260. drupal_execute('taxonomy_form_vocabulary', $form_state);
  2261. }
  2262. }
  2263. /**
  2264. *
  2265. *
  2266. * @ingroup tripal_feature
  2267. */
  2268. function tripal_feature_del_vocabulary() {
  2269. //include the file containing the required functions for adding taxonomy vocabs
  2270. module_load_include('inc', 'taxonomy', 'taxonomy.admin');
  2271. // get the vocabularies
  2272. $vocabularies = taxonomy_get_vocabularies();
  2273. // These taxonomic terms are hard coded because we
  2274. // know we have these relationships in the chado tables
  2275. // through foreign key relationships. The tripal
  2276. // modules that correspond to these chado "modules" don't
  2277. // need to be installed for the taxonomy to work.
  2278. foreach ($vocabularies as $vocab) {
  2279. if ($vocab->name == 'Feature Type') {
  2280. taxonomy_del_vocabulary($vocab->vid);
  2281. }
  2282. if ($vocab->name == 'Organism') {
  2283. taxonomy_del_vocabulary($vocab->vid);
  2284. }
  2285. if ($vocab->name == 'Library') {
  2286. taxonomy_del_vocabulary($vocab->vid);
  2287. }
  2288. if ($vocab->name == 'Analysis') {
  2289. taxonomy_del_vocabulary($vocab->vid);
  2290. }
  2291. }
  2292. }
  2293. /**
  2294. *
  2295. *
  2296. * @ingroup tripal_feature
  2297. */
  2298. function tripal_features_set_taxonomy($max_sync = 0, $job_id = NULL) {
  2299. // make sure our vocabularies are cleaned and reset before proceeding
  2300. tripal_feature_del_vocabulary();
  2301. tripal_feature_set_vocabulary();
  2302. // iterate through all drupal feature nodes and set the taxonomy
  2303. $results = db_query("SELECT * FROM {chado_feature}");
  2304. $nsql = "SELECT * FROM {node} ".
  2305. "WHERE nid = %d";
  2306. $i = 0;
  2307. // load into ids array
  2308. $count = 0;
  2309. $chado_features = array();
  2310. while ($chado_feature = db_fetch_object($results)) {
  2311. $chado_features[$count] = $chado_feature;
  2312. $count++;
  2313. }
  2314. // Iterate through features that need to be synced
  2315. $interval = intval($count * 0.01);
  2316. foreach ($chado_features as $chado_feature) {
  2317. // update the job status every 1% features
  2318. if ($job_id and $i % $interval == 0) {
  2319. tripal_job_set_progress($job_id, intval(($i/$count)*100));
  2320. }
  2321. print "$i of $count: ";
  2322. $node = db_fetch_object(db_query($nsql, $chado_feature->nid));
  2323. tripal_feature_set_taxonomy($node, $chado_feature->feature_id);
  2324. $i++;
  2325. }
  2326. }
  2327. /**
  2328. *
  2329. *
  2330. * @ingroup tripal_feature
  2331. */
  2332. function tripal_feature_set_taxonomy($node, $feature_id) {
  2333. // iterate through the taxonomy classes that have been
  2334. // selected by the admin user and make sure we only set those
  2335. $tax_classes = variable_get('tax_classes', '');
  2336. $do_ft = 0;
  2337. $do_op = 0;
  2338. $do_lb = 0;
  2339. $do_an = 0;
  2340. foreach ($tax_classes as $class) {
  2341. if (strcmp($class , 'organism')==0) {
  2342. $do_op = 1;
  2343. }
  2344. if (strcmp($class, 'feature_type')==0) {
  2345. $do_ft = 1;
  2346. }
  2347. if (strcmp($class, 'library')==0) {
  2348. $do_lb = 1;
  2349. }
  2350. if (strcmp($class, 'analysis')==0) {
  2351. $do_an = 1;
  2352. }
  2353. }
  2354. // get the list of vocabularies and find our two vocabularies of interest
  2355. $vocabularies = taxonomy_get_vocabularies();
  2356. $ft_vid = NULL;
  2357. $op_vid = NULL;
  2358. $lb_vid = NULL;
  2359. $an_vid = NULL;
  2360. foreach ($vocabularies as $vocab) {
  2361. if ($vocab->name == 'Feature Type') {
  2362. $ft_vid = $vocab->vid;
  2363. }
  2364. if ($vocab->name == 'Organism') {
  2365. $op_vid = $vocab->vid;
  2366. }
  2367. if ($vocab->name == 'Library') {
  2368. $lb_vid = $vocab->vid;
  2369. }
  2370. if ($vocab->name == 'Analysis') {
  2371. $an_vid = $vocab->vid;
  2372. }
  2373. }
  2374. // get the cvterm and the organism for this feature
  2375. $sql = "SELECT CVT.name AS cvname, O.genus, O.species ".
  2376. "FROM {CVTerm} CVT ".
  2377. " INNER JOIN Feature F on F.type_id = CVT.cvterm_id ".
  2378. " INNER JOIN Organism O ON F.organism_id = O.organism_id ".
  2379. "WHERE F.feature_id = $feature_id";
  2380. $previous_db = tripal_db_set_active('chado'); // use chado database
  2381. $feature = db_fetch_object(db_query($sql));
  2382. tripal_db_set_active($previous_db); // now use drupal database
  2383. // Set the feature type for this feature
  2384. if ($do_ft && $ft_vid) {
  2385. $tags["$ft_vid"] = "$feature->cvname";
  2386. }
  2387. // Set the organism for this feature type
  2388. if ($do_op && $op_vid) {
  2389. $tags["$op_vid"] = "$feature->genus $feature->species";
  2390. }
  2391. // get the library that this feature may belong to and add it as taxonomy
  2392. if ($do_lb && $lb_vid) {
  2393. $sql = "SELECT L.name ".
  2394. "FROM {Library} L ".
  2395. " INNER JOIN Library_feature LF ON LF.library_id = L.library_id ".
  2396. "WHERE LF.feature_id = %d ";
  2397. $previous_db = tripal_db_set_active('chado'); // use chado database
  2398. $library = db_fetch_object(db_query($sql, $feature_id));
  2399. tripal_db_set_active($previous_db); // now use drupal database
  2400. $tags["$lb_vid"] = "$library->name";
  2401. }
  2402. // now add the taxonomy to the node
  2403. $terms['tags'] = $tags;
  2404. taxonomy_node_save($node, $terms);
  2405. // print "Setting $node->name: " . implode(", ",$tags) . "\n";
  2406. // get the analysis that this feature may belong to and add it as taxonomy
  2407. // We'll add each one individually since there may be more than one analysis
  2408. if ($do_an && $an_vid) {
  2409. $sql = "SELECT A.name ".
  2410. "FROM {Analysis} A ".
  2411. " INNER JOIN Analysisfeature AF ON AF.analysis_id = A.analysis_id ".
  2412. "WHERE AF.feature_id = $feature_id ";
  2413. $results = db_query($sql);
  2414. $previous_db = tripal_db_set_active('chado'); // use chado database
  2415. $analysis_terms = array();
  2416. while ($analysis=db_fetch_object($results)) {
  2417. $tags2["$an_vid"] = "$analysis->name";
  2418. $terms['tags'] = $tags2;
  2419. taxonomy_node_save($node, $terms);
  2420. }
  2421. tripal_db_set_active($previous_db); // now use drupal database
  2422. }
  2423. }
  2424. /**
  2425. *
  2426. *
  2427. * @ingroup tripal_feature
  2428. */
  2429. function tripal_features_cleanup($dummy = NULL, $job_id = NULL) {
  2430. // build the SQL statments needed to check if nodes point to valid features
  2431. $dsql = "SELECT * FROM {node} WHERE type = 'chado_feature' order by nid";
  2432. $nsql = "SELECT * FROM {node} WHERE nid = %d";
  2433. $csql = "SELECT * FROM {chado_feature} where nid = %d ";
  2434. $cfsql= "SELECT * FROM {chado_feature}";
  2435. // load into nodes array
  2436. $results = db_query($dsql);
  2437. $count = 0;
  2438. $nodes = array();
  2439. while ($node = db_fetch_object($results)) {
  2440. $nodes[$count] = $node;
  2441. $count++;
  2442. }
  2443. // load the chado_features into an array
  2444. $results = db_query($cfsql);
  2445. $cnodes = array();
  2446. while ($node = db_fetch_object($results)) {
  2447. $cnodes[$count] = $node;
  2448. $count++;
  2449. }
  2450. $interval = intval($count * 0.01);
  2451. if ($interval > 1) {
  2452. $interval = 1;
  2453. }
  2454. // iterate through all of the chado_feature nodes and delete those that aren't valid
  2455. foreach ($nodes as $nid) {
  2456. // update the job status every 1% features
  2457. if ($job_id and $i % $interval == 0) {
  2458. tripal_job_set_progress($job_id, intval(($i/$count)*100));
  2459. }
  2460. // check to see if the node has a corresponding entry
  2461. // in the chado_feature table. If not then delete the node.
  2462. $feature = db_fetch_object(db_query($csql, $nid->nid));
  2463. if (!$feature) {
  2464. node_delete($nid->nid);
  2465. $message = "Missing in chado_feature table.... DELETING: $nid->nid\n";
  2466. watchdog('tripal_feature', $message, array(), WATCHDOG_WARNING);
  2467. continue;
  2468. }
  2469. $i++;
  2470. }
  2471. // iterate through all of the chado_feature nodes and delete those that aren't valid
  2472. foreach ($cnodes as $nid) {
  2473. // update the job status every 1% features
  2474. if ($job_id and $i % $interval == 0) {
  2475. tripal_job_set_progress($job_id, intval(($i/$count)*100));
  2476. }
  2477. $node = db_fetch_object(db_query($nsql, $nid->nid));
  2478. if (!$node) {
  2479. db_query("DELETE FROM {chado_feature} WHERE nid = %nid", $nid->nid);
  2480. $message = "chado_feature missing node.... DELETING: $nid->nid\n";
  2481. watchdog('tripal_feature', $message, array(), WATCHDOG_WARNING);
  2482. }
  2483. $i++;
  2484. }
  2485. return '';
  2486. }
  2487. /**
  2488. *
  2489. *
  2490. * @ingroup tripal_feature
  2491. */
  2492. function tripal_feature_return_fasta($feature, $desc) {
  2493. $fasta = ">" . variable_get('chado_feature_accession_prefix', 'ID') . "$feature->feature_id|$feature->name";
  2494. $fasta .= " $desc\n";
  2495. $fasta .= wordwrap($feature->residues, 50, "\n", TRUE);
  2496. $fasta .= "\n\n";
  2497. return $fasta;
  2498. }
  2499. /**
  2500. *
  2501. *
  2502. * @ingroup tripal_feature
  2503. */
  2504. function tripal_feature_job_describe_args($callback, $args) {
  2505. $new_args = array();
  2506. if ($callback == 'tripal_feature_load_fasta') {
  2507. $new_args['FASTA file'] = $args[0];
  2508. $organism = tripal_core_chado_select('organism', array('genus', 'species'), array('organism_id' => $args[1]));
  2509. $new_args['Organism'] = $organism[0]->genus . " " . $organism[0]->species;
  2510. $new_args['Sequence Type'] = $args[2];
  2511. $new_args['Name Match Type'] = $args[14];
  2512. $new_args['Name RE'] = $args[4];
  2513. $new_args['Unique Name RE'] = $args[5];
  2514. // add in the relationship arguments
  2515. $new_args['Relationship Type'] = $args[8];
  2516. $new_args['Relationship Parent RE'] = $args[9];
  2517. $new_args['Relationship Parent Type'] = $args[10];
  2518. // add in the database reference arguments
  2519. if ($args[7]) {
  2520. $db = tripal_core_chado_select('db', array('name'), array('db_id' => $args[7]));
  2521. }
  2522. $new_args['Database Reference'] = $db[0]->name;
  2523. $new_args['Accession RE'] = $args[6];
  2524. $new_args['Method'] = $args[11];
  2525. // add in the analysis
  2526. if ($args[13]) {
  2527. $analysis = tripal_core_chado_select('analysis', array('name'), array('analysis_id' => $args[13]));
  2528. }
  2529. $new_args['Analysis'] = $analysis[0]->name;
  2530. }
  2531. if ($callback == 'tripal_feature_delete_features') {
  2532. if ($args[0]) {
  2533. $organism = tripal_core_chado_select('organism', array('genus', 'species'), array('organism_id' => $args[0]));
  2534. $new_args['Organism'] = $organism[0]->genus . " " . $organism[0]->species;
  2535. }
  2536. else {
  2537. $new_args['Organism'] = '';
  2538. }
  2539. if ($args[1]) {
  2540. $analysis = tripal_core_chado_select('analysis', array('name'), array('analysis_id' => $args[1]));
  2541. $new_args['Analysis'] = $analysis[0]->name;
  2542. }
  2543. else {
  2544. $new_args['Analysis'] = '';
  2545. }
  2546. $new_args['Sequence Type'] = $args[2];
  2547. $new_args['Is Unique Name'] = $args[3];
  2548. $new_args['Features Names'] = $args[4];
  2549. }
  2550. if ($callback == 'tripal_feature_sync_features') {
  2551. if ($args[0]) {
  2552. $organism = tripal_core_chado_select('organism', array('genus', 'species'), array('organism_id' => $args[0]));
  2553. $new_args['Organism'] = $organism[0]->genus . " " . $organism[0]->species;
  2554. }
  2555. else {
  2556. $new_args['Organism'] = '';
  2557. }
  2558. $new_args['Feature Types'] = $args[1];
  2559. }
  2560. return $new_args;
  2561. }
  2562. /**
  2563. * Implements hook_coder_ignore().
  2564. * Defines the path to the file (tripal_core.coder_ignores.txt) where ignore rules for coder are stored
  2565. */
  2566. function tripal_feature_coder_ignore() {
  2567. return array(
  2568. 'path' => drupal_get_path('module', 'tripal_feature'),
  2569. 'line prefix' => drupal_get_path('module', 'tripal_feature'),
  2570. );
  2571. }