tripal_feature.module 81 KB

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