tripal_feature.module 96 KB

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