tripal_analysis_unigene.module 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  1. <?php
  2. // $Id:
  3. //
  4. // Copyright 2009 Clemson University
  5. //
  6. function tripal_analysis_unigene_init(){
  7. // Add style sheet
  8. drupal_add_css(drupal_get_path('theme', 'tripal').
  9. '/css/tripal_analysis_unigene.css');
  10. }
  11. /*******************************************************************************
  12. * HOOK: Implemntation of hook_menu() to provide a call back for EST Assembly Tab
  13. */
  14. function tripal_analysis_unigene_menu() {
  15. $items['node/%/assembly'] = array(
  16. 'title' => t('EST Assemblies'),
  17. 'page callback' => 'tripal_analysis_unigene_organism_assembly',
  18. 'page arguments' => array(1),
  19. 'access callback' => 'tripal_analysis_unigene_node_has_menu',
  20. 'access arguments' => array('access chado_analysis content',1),
  21. 'type' => MENU_LOCAL_TASK | MENU_NORMAL_ITEM
  22. );
  23. return $items;
  24. }
  25. /*******************************************************************************
  26. * Dynamic addition/removal of menu item
  27. */
  28. function tripal_analysis_unigene_node_has_menu($type,$vid){
  29. // check to see if this node is an organism node
  30. $sql = 'SELECT organism_id FROM {chado_organism} WHERE vid = %d';
  31. $result = db_query($sql, $vid);
  32. // menu status
  33. $box_status =variable_get("tripal_analysis_unigene-box-assembly","menu_off");
  34. // if this node is not an organism or a feature node then return false
  35. // we don't want the menu item to be shown, otherwise get the normal perms
  36. if($org_id = db_fetch_object($result)){
  37. if(strcmp($box_status,"menu_on")==0){
  38. return user_access($type);
  39. }
  40. } else {
  41. return FALSE;
  42. }
  43. }
  44. /*******************************************************************************
  45. * tripal_analysis_unigene_nodeapi()
  46. * HOOK: Implementation of hook_nodeapi()
  47. * Display unigene results for allowed node types
  48. */
  49. function tripal_analysis_unigene_nodeapi(&$node, $op, $teaser, $page) {
  50. switch ($op) {
  51. case 'view':
  52. // Find out which node types for showing the unigene
  53. $types_to_show = variable_get('tripal_analysis_unigene_setting',
  54. array('chado_feature','chado_organism'));
  55. // Abort if this node is not one of the types we should show.
  56. if (!in_array($node->type, $types_to_show, TRUE)) {
  57. // Turn the menu off if it's on
  58. $box_status = variable_get("tripal_analysis_unigene-box-assembly","menu_off");
  59. if (strcmp($box_status,"menu_on")==0 && $node->type =='chado_organism'){
  60. variable_set("tripal_analysis_unigene-box-assembly","menu_off");
  61. }
  62. break;
  63. }
  64. // Add unigene to the content item if it's not a teaser
  65. if (!$teaser) {
  66. // add the alignment to the feature search indexing
  67. if($node->build_mode == NODE_BUILD_SEARCH_INDEX){
  68. $node->content['tripal_analysis_unigene_index_version'] = array(
  69. '#value' => theme('tripal_analysis_unigene_search_index',$node),
  70. '#weight' => 4,
  71. );
  72. } else if ($node->build_mode == NODE_BUILD_SEARCH_RESULT) {
  73. $node->content['tripal_analysis_unigene_index_version'] = array(
  74. '#value' => theme('tripal_analysis_unigene_search_result',$node),
  75. '#weight' => 4,
  76. );
  77. } else {
  78. if(strcmp($node->type,'chado_feature')==0){
  79. // Show unigene content if not at teaser view
  80. $node->content['tripal_analysis_unigene_node_addition'] = array(
  81. '#value' => theme('tripal_analysis_unigene_feature_alignments', $node),
  82. '#weight' => 4
  83. );
  84. }
  85. if(strcmp($node->type,'chado_organism')==0){
  86. // Show unigene content if not at teaser view
  87. $node->content['tripal_analysis_unigene_node_add'] = array(
  88. '#value' => theme('tripal_analysis_unigene_node_add', $node),
  89. '#weight' => 4
  90. );
  91. }
  92. }
  93. }
  94. }
  95. }
  96. /************************************************************************
  97. * We need to let drupal know about our theme functions and their arguments.
  98. * We create theme functions to allow users of the module to customize the
  99. * look and feel of the output generated in this module
  100. */
  101. function tripal_analysis_unigene_theme () {
  102. return array(
  103. 'tripal_analysis_unigene_search_index' => array (
  104. 'arguments' => array('node'),
  105. ),
  106. 'tripal_analysis_unigene_search_result' => array (
  107. 'arguments' => array('node'),
  108. ),
  109. 'tripal_analysis_unigene_feature_alignments' => array (
  110. 'arguments' => array('node'),
  111. ),
  112. 'tripal_analysis_unigene_node_add' => array (
  113. 'arguments' => array('node'),
  114. ),
  115. );
  116. }
  117. /************************************************************************
  118. * This function is an extension of the chado_feature_view by providing
  119. * the markup for the feature object THAT WILL BE INDEXED.
  120. */
  121. function theme_tripal_analysis_unigene_search_index ($node) {
  122. $feature = $node->feature;
  123. $obj_feature = tripal_analysis_unigene_get_alignments($feature);
  124. $alignments = $obj_feature->alignments;
  125. $content = "<strong>";
  126. if(count($alignments) > 0){
  127. // iterate through each alignment
  128. foreach ($alignments as $result){
  129. // EST alignments in chado use an EST_match type to map ESTs to
  130. // contigs and a rank to indicate the major srcfeature.
  131. // We don't want to show EST_matches on the alignment view
  132. // since that doesn't make much sense to the end user. If this
  133. // is an EST_match and the feature is an EST then we want to show
  134. // the contig in the alignments. The contig name is part of the
  135. // uniquename in the EST_match
  136. if($node->feature->cvname == 'EST' && $result->cvname == 'EST_match'){
  137. $sql = "SELECT srcfeature_id ".
  138. "FROM {featureloc} ".
  139. "WHERE feature_id = $result->feature_id ".
  140. "ORDER BY rank";
  141. $previous_db = db_set_active ('chado');
  142. $contig_fid = db_result(db_query($sql));
  143. $sql = "SELECT name FROM {feature} WHERE feature_id = $contig_fid";
  144. $contig_name = db_result(db_query($sql));
  145. db_set_active($previous_db);
  146. $sql = "SELECT nid ".
  147. "FROM {chado_feature} ".
  148. "WHERE feature_id = $contig_fid";
  149. $contig_nid = db_result(db_query($sql));
  150. // Check if the EST exists as a drupal node. If yes, add a link to
  151. // it. If no, just show the name
  152. if ($contig_nid != 0) {
  153. $sql = "SELECT nid FROM {node} WHERE nid=$contig_nid";
  154. $node_exists = db_result(db_query($sql));
  155. }
  156. $content .= "$contig_name " ;
  157. }
  158. elseif($node->feature->cvname == 'contig' && $result->cvname == 'EST_match'){
  159. $sql = "SELECT vid ".
  160. "FROM {node} ".
  161. "WHERE title = '$result->feature_name'".
  162. "ORDER BY vid DESC";
  163. // since the feature name is also the node title we can look it up
  164. $est_node = db_fetch_object(db_query($sql));
  165. $content .= "$result->feature_name ";
  166. }
  167. else {
  168. $content .= "$result->cvname $result->feature_name ";
  169. }
  170. }
  171. }
  172. $content .= "</strong>";
  173. return $content;
  174. }
  175. /************************************************************************
  176. * This function is an extension of the chado_feature_view by providing
  177. * the markup for the feature object to show on a search result page.
  178. */
  179. function theme_tripal_analysis_unigene_search_result ($node) {
  180. $feature = $node->feature;
  181. $obj_feature = tripal_analysis_unigene_get_alignments($feature);
  182. $alignments = $obj_feature->alignments;
  183. $content = "<strong>";
  184. if(count($alignments) > 0){
  185. // iterate through each alignment
  186. foreach ($alignments as $result){
  187. // EST alignments in chado use an EST_match type to map ESTs to
  188. // contigs and a rank to indicate the major srcfeature.
  189. // We don't want to show EST_matches on the alignment view
  190. // since that doesn't make much sense to the end user. If this
  191. // is an EST_match and the feature is an EST then we want to show
  192. // the contig in the alignments. The contig name is part of the
  193. // uniquename in the EST_match
  194. if($node->feature->cvname == 'EST' && $result->cvname == 'EST_match'){
  195. $sql = "SELECT srcfeature_id ".
  196. "FROM {featureloc} ".
  197. "WHERE feature_id = $result->feature_id ".
  198. "ORDER BY rank";
  199. $previous_db = db_set_active ('chado');
  200. $contig_fid = db_result(db_query($sql));
  201. $sql = "SELECT name FROM {feature} WHERE feature_id = $contig_fid";
  202. $contig_name = db_result(db_query($sql));
  203. db_set_active($previous_db);
  204. $sql = "SELECT nid ".
  205. "FROM {chado_feature} ".
  206. "WHERE feature_id = $contig_fid";
  207. $contig_nid = db_result(db_query($sql));
  208. // Check if the EST exists as a drupal node. If yes, add a link to
  209. // it. If no, just show the name
  210. if ($contig_nid != 0) {
  211. $sql = "SELECT nid FROM {node} WHERE nid=$contig_nid";
  212. $node_exists = db_result(db_query($sql));
  213. }
  214. $content .= "Alignment to contig $contig_name. " ;
  215. }
  216. elseif($node->feature->cvname == 'contig' && $result->cvname == 'EST_match'){
  217. $sql = "SELECT vid ".
  218. "FROM {node} ".
  219. "WHERE title = '$result->feature_name'".
  220. "ORDER BY vid DESC";
  221. // since the feature name is also the node title we can look it up
  222. $est_node = db_fetch_object(db_query($sql));
  223. $content .= "Aligned EST: $result->feature_name ";
  224. }
  225. else {
  226. $content .= "Aligned $result->cvname: $result->feature_name ";
  227. }
  228. }
  229. }
  230. $content .= "</strong>";
  231. return $content;
  232. }
  233. /*******************************************************************************
  234. * tripal_analysis_unigene_results ()
  235. * Prepare unigene result for the feature shown on the page
  236. */
  237. function theme_tripal_analysis_unigene_feature_alignments($node) {
  238. $feature = $node->feature;
  239. $obj_feature = tripal_analysis_unigene_get_alignments($feature);
  240. $alignments = $obj_feature->alignments;
  241. if(count($alignments) > 0){
  242. $content = "<div id=\"tripal_analysis_unigene_box\" class=\"tripal_unigene-info-box\">";
  243. // we're showing contig alignments in GBrowse so create a link here for
  244. // that if this feature is a contig
  245. if($node->feature->cvname == 'contig'){
  246. $content .= "<div class=\"tripal_expandableBox\">".
  247. " <h3>ESTs in this contig</h3>".
  248. "</div>";
  249. $content .= "<div class=\"tripal_expandableBoxContent\">";
  250. } else {
  251. $content .= "<div class=\"tripal_expandableBox\">".
  252. " <h3>Alignments</h3>".
  253. "</div>";
  254. $content .= "<div class=\"tripal_expandableBoxContent\">";
  255. }
  256. $content .= "".
  257. "<table class=\"tripal_table_horz\">".
  258. " <tr>".
  259. " <th>Type</th>".
  260. " <th>Feature</th>".
  261. " <th align=\"right\">Position</th>".
  262. " </tr>";
  263. // iterate through each alignment
  264. foreach ($alignments as $result){
  265. // EST alignments in chado use an EST_match type to map ESTs to
  266. // contigs and a rank to indicate the major srcfeature.
  267. // We don't want to show EST_matches on the alignment view
  268. // since that doesn't make much sense to the end user. If this
  269. // is an EST_match and the feature is an EST then we want to show
  270. // the contig in the alignments. The contig name is part of the
  271. // uniquename in the EST_match
  272. if($node->feature->cvname == 'EST' && $result->cvname == 'EST_match'){
  273. $sql = "SELECT srcfeature_id ".
  274. "FROM {featureloc} ".
  275. "WHERE feature_id = $result->feature_id ".
  276. "ORDER BY rank";
  277. $previous_db = db_set_active ('chado');
  278. $contig_fid = db_result(db_query($sql));
  279. $sql = "SELECT name FROM {feature} WHERE feature_id = $contig_fid";
  280. $contig_name = db_result(db_query($sql));
  281. db_set_active($previous_db);
  282. $sql = "SELECT nid ".
  283. "FROM {chado_feature} ".
  284. "WHERE feature_id = $contig_fid";
  285. $contig_nid = db_result(db_query($sql));
  286. // Check if the EST exists as a drupal node. If yes, add a link to
  287. // it. If no, just show the name
  288. if ($contig_nid != 0) {
  289. $sql = "SELECT nid FROM {node} WHERE nid=$contig_nid";
  290. $node_exists = db_result(db_query($sql));
  291. }
  292. $content .=
  293. "<tr>".
  294. " <td>Contig</td>".
  295. " <td>";
  296. if ($node_exists != 0) {
  297. $content .= "<a href=\"".url("node/$contig_nid")."\">".
  298. "$contig_name</a>";
  299. } else {
  300. $content .= $contig_name;
  301. }
  302. $content .=
  303. " </td>".
  304. " <td align=\"right\">".
  305. number_format($result->fmin).
  306. "-".
  307. number_format($result->fmax).
  308. " </td>".
  309. "</tr>";
  310. }
  311. elseif($node->feature->cvname == 'contig' &&
  312. $result->cvname == 'EST_match'){
  313. $sql = "SELECT vid ".
  314. "FROM {node} ".
  315. "WHERE title = '$result->feature_name'".
  316. "ORDER BY vid DESC";
  317. // since the feature name is also the node title we can look it up
  318. $est_node = db_fetch_object(db_query($sql));
  319. $content .=
  320. "<tr>".
  321. " <td>EST</td>".
  322. " <td>";
  323. //Check if the EST exists as a drupal node before adding a hyperlink
  324. if ($est_node->vid != 0) {
  325. $content .=
  326. "<a href=\"".url("node/$est_node->vid")."\">".
  327. $result->feature_name.
  328. "</a>";
  329. } else {
  330. $content .= $result->feature_name;
  331. }
  332. $content .=
  333. " </td>".
  334. " <td align=\"right\">".
  335. number_format($result->fmin).
  336. "-".
  337. number_format($result->fmax).
  338. " </td>".
  339. "</tr>";
  340. }
  341. else {
  342. $content .= "".
  343. "<tr>".
  344. " <td>$result->cvname</td>".
  345. " <td>$result->feature_name</td>".
  346. " <td align=\"right\">$result->fmin</td>".
  347. " <td align=\"right\">$result->fmax</td>".
  348. " <td align=\"right\">$result->strand</td>".
  349. "</tr>";
  350. }
  351. }
  352. $content .= "</table>";
  353. /* if this is a contig then get the alignment
  354. if($node->feature->cvname == 'contig'){
  355. // get the directory prefix
  356. $prefix = preg_replace("/^(\d*)\d{3}$/","$1",$node->feature_id);
  357. if(!$prefix){
  358. $prefix = '0';
  359. }
  360. $data_url = variable_get('chado_feature_data_url','sites/default/files/data');
  361. $fh = fopen("$data_url/misc/$prefix/$node->feature->feature_id/alignment.txt", 'r');
  362. if($fh){
  363. $content .= "<b>Alignment:</b><div class=\"tripal_feature_assembly_alignment\"><pre>";
  364. while(!feof($fh)){
  365. $content .= fgets($fh);
  366. }
  367. $content .="</pre></div>";
  368. }
  369. fclose($fh);
  370. }
  371. */
  372. $content .= "</div></div>";
  373. }
  374. return $content;
  375. }
  376. /*******************************************************************************
  377. *
  378. */
  379. function tripal_analysis_unigene_get_alignments($map) {
  380. // get the alignments for this feature
  381. $sql = "SELECT F.name as feature_name, FL.fmin, FL.fmax, FL.strand, ".
  382. " FL.phase, CVT.name as cvname, F.feature_id, F.uniquename, ".
  383. " FL.featureloc_id ".
  384. "FROM {featureloc} FL ".
  385. " INNER JOIN Feature F ON F.feature_id = FL.feature_id ".
  386. " INNER JOIN Cvterm CVT ON CVT.cvterm_id = F.type_id ".
  387. "WHERE srcfeature_id = %d AND ".
  388. " NOT(CVT.name = 'match' or CVT.name = 'match_part') ".
  389. "ORDER BY FL.fmin, FL.fmax";
  390. $previous_db = db_set_active('chado');
  391. $results = db_query($sql,$map->feature_id);
  392. $alignments = array();
  393. $i=0;
  394. while($subfeature = db_fetch_object($results)){
  395. $alignments[$i++] = $subfeature;
  396. }
  397. $additions->alignments = $alignments;
  398. /* get the GO Terms
  399. $sql = "SELECT DISTINCT * FROM {go_results_mview} ".
  400. "WHERE feature_id = %d";
  401. $results = db_query($sql,$map->feature_id);
  402. $go_terms = array();
  403. $i=0;
  404. while($term = db_fetch_object($results)){
  405. $go_terms[$i++] = $term;
  406. }
  407. $additions->go_terms = $go_terms;
  408. // get the feature properties
  409. $sql = "SELECT FP.value,FP.rank,CVT.name,CVT.definition ".
  410. "FROM {featureprop} FP".
  411. " INNER JOIN Cvterm CVT ".
  412. " ON FP.type_id = CVT.cvterm_id ".
  413. "WHERE feature_id = %d";
  414. $results = db_query($sql,$map->feature_id);
  415. $properties = array();
  416. $i=0;
  417. while($property = db_fetch_object($results)){
  418. $properties[$i++] = $property;
  419. }
  420. $additions->properties = $properties;
  421. */
  422. db_set_active($previous_db);
  423. return $additions;
  424. }
  425. /************************************************************************
  426. *
  427. */
  428. function tripal_analysis_unigene_organism_assembly($node){
  429. $node = node_load($node);
  430. return tripal_analysis_unigene_organism_add($node);
  431. }
  432. /************************************************************************
  433. *
  434. */
  435. function theme_tripal_analysis_unigene_node_add ($node){
  436. if(strcmp($node->type,'chado_organism')==0){
  437. $box_status = variable_get("tripal_analysis_unigene-box-assembly","menu_off");
  438. if (strcmp($box_status,"menu_off")==0){
  439. $content = tripal_analysis_unigene_organism_add($node);
  440. }
  441. }
  442. return $content;
  443. }
  444. /************************************************************************
  445. *
  446. */
  447. function tripal_analysis_unigene_organism_add($node){
  448. // get the organism_id for this node:
  449. $sql = 'SELECT * FROM {chado_organism} WHERE vid = %d';
  450. $org_id = db_fetch_object(db_query($sql, $node->nid));
  451. // get information about this organism
  452. $sql = "SELECT * FROM {organism} ".
  453. "WHERE organism_id = %d";
  454. $previous_db = db_set_active('chado'); // use chado database
  455. $organism = db_fetch_object(db_query($sql,$org_id->organism_id));
  456. db_set_active($previous_db); // now use drupal database
  457. // get information about this assembly and add it to the items in this node
  458. $sql = "SELECT * FROM {unigene_mview} ".
  459. "WHERE organism_id = %d ".
  460. "ORDER BY analysis_id DESC";
  461. $previous_db = db_set_active('chado'); // use chado database
  462. $results = db_query($sql,$org_id->organism_id);
  463. db_set_active($previous_db); // now use drupal database
  464. $i = 0;
  465. while ($assembly = db_fetch_object($results)){
  466. // get information about this organism and add it to the items in this node
  467. $libraries = array();
  468. $libraries_sql = "SELECT library_id, library_name ".
  469. "FROM {unigene_libraries_mview} ".
  470. "WHERE analysis_id = %d ";
  471. $previous_db = db_set_active('chado'); // use chado database
  472. $libraries_result = db_query($libraries_sql,$assembly->analysis_id);
  473. db_set_active($previous_db); // now use drupal database
  474. $library_sql = "SELECT * FROM {chado_library} WHERE library_id = %d";
  475. $k = 0;
  476. while ($library = db_fetch_object($libraries_result)){
  477. $library_node = db_fetch_object(db_query($library_sql,$library->library_id));
  478. $library->node_id = $library_node->nid;
  479. $libraries[$k++] = $library;
  480. }
  481. $assembly->libraries = $libraries;
  482. $assemblies[$i++] = $assembly;
  483. }
  484. // if this content is intended to be a menu item the
  485. // we need to know so we can format the content slightly different
  486. $box_status =variable_get("tripal_analysis_unigene-box-assembly","menu_off");
  487. if(count($assemblies) > 0){
  488. $content = "<div id=\"organism_tab_content\">".
  489. "<p>New assemblies are built after a significant number of sequences are added to the project or new software is available. ".
  490. "Click on name for more information.</p><br>";
  491. foreach($assemblies as $assembly){
  492. $content .= "<div class=\"tripal_unigene-info-box\">".
  493. "<div class=\"tripal_expandableBox\"><h3><a name=\"$assembly->name\">$assembly->name</a></h3></div>".
  494. "<div class=\"tripal_expandableBoxContent\">";
  495. $content .= "<table>".
  496. "<tr><td class=\"dbfieldname\"> Version </td>".
  497. " <td class=\"dbfieldvalue\">$assembly->uversion </td></tr>".
  498. "<tr><td class=\"dbfieldname\"> Analysis ID </td>".
  499. " <td class=\"dbfieldvalue\">$assembly->analysis_id </td></tr>".
  500. "<tr><td class=\"dbfieldname\"> Date </td>".
  501. " <td class=\"dbfieldvalue\">$assembly->adate </td></tr>".
  502. "<tr><td class=\"dbfieldname\"> Software </td>".
  503. " <td class=\"dbfieldvalue\">$assembly->program </td></tr>".
  504. "<tr><td class=\"dbfieldname\"> Software Version </td>".
  505. " <td class=\"dbfieldvalue\">$assembly->programversion </td></tr>".
  506. "<tr><td class=\"dbfieldname\"> Number of Contigs </td>".
  507. " <td class=\"dbfieldvalue\">$assembly->num_contigs </td></tr>".
  508. "<tr><td class=\"dbfieldname\"> Description </td>".
  509. " <td class=\"dbfieldvalue\">$assembly->description </td></tr>".
  510. "<tr><td class=\"dbfieldname\"> Libraries Included in Assembly </td>".
  511. " <td class=\"dbfieldvalue\"> ";
  512. # TODO: THIS SHOULD NOT HAVE A LINK IF THERE IS NO LIBRARY NODE IN DRUPAL
  513. foreach($assembly->libraries as $library){
  514. $content .= "<a href=\"/node/$library->node_id\">$library->library_name</a> ";
  515. }
  516. $content .= " </td></tr>".
  517. "</table>";
  518. # Generate the download linkes
  519. $a_dir = tripal_get_moddir('tripal_analysis_unigene') .
  520. "/$assembly->analysis_id";
  521. if(is_dir($a_dir)){
  522. $content .= "<ul class=\"organism\">";
  523. if($target_file = file_scan_directory($a_dir,'\.contigs.fasta$',
  524. array('.','..','CVS'),0,FALSE)){
  525. foreach($target_file as $key=>$value){
  526. $target = $target_file[$key];
  527. }
  528. $link = url($target->filename);
  529. $content .= "
  530. <li>
  531. <a href=\"$link\">Download contigs </a>
  532. </li>
  533. ";
  534. }
  535. if($target_file = file_scan_directory($a_dir,'\.contigs.qual$',
  536. array('.','..','CVS'),0,FALSE)){
  537. foreach($target_file as $key=>$value){
  538. $target = $target_file[$key];
  539. }
  540. $link = url($target->filename);
  541. $content .= "
  542. <li>
  543. <a href=\"$link\">Download contigs quality </a>
  544. </li>
  545. ";
  546. }
  547. if($target_file = file_scan_directory($a_dir,'\.singlets.fasta$',
  548. array('.','..','CVS'),0,FALSE)){
  549. foreach($target_file as $key=>$value){
  550. $target = $target_file[$key];
  551. }
  552. $link = url($target->filename);
  553. $content .= "
  554. <li>
  555. <a href=\"$link\">Download singlets </a>
  556. </li>
  557. ";
  558. }
  559. if($target_file = file_scan_directory($a_dir,'\.singlets.qual$',
  560. array('.','..','CVS'),0,FALSE)){
  561. foreach($target_file as $key=>$value){
  562. $target = $target_file[$key];
  563. }
  564. $link = url($target->filename);
  565. $content .= "
  566. <li>
  567. <a href=\"$link\">Download singlets quality </a>
  568. </li>
  569. ";
  570. }
  571. if($target_file = file_scan_directory($a_dir,'\.ace$',
  572. array('.','..','CVS'),0,FALSE)){
  573. foreach($target_file as $key=>$value){
  574. $target = $target_file[$key];
  575. }
  576. $link = url($target->filename);
  577. $content .= "
  578. <li>
  579. <a href=\"$link\">Download ace file </a>
  580. </li>
  581. ";
  582. ;
  583. }
  584. $content .= "</ul>";
  585. }
  586. if(user_access('access administrative pages')){
  587. $link = url("tripal_toggle_box_menu/tripal_analysis_unigene/assembly/$node->nid");
  588. if(strcmp($box_status,"menu_off")==0){
  589. $content .= "<a href=\"$link\">Show on menu</a>";
  590. } else {
  591. $content .= "<a href=\"$link\">Remove from menu</a>";
  592. }
  593. }
  594. $content .= "</div></div>";
  595. }
  596. $content .= "</div>";
  597. }
  598. return $content;
  599. }
  600. /*******************************************************************************
  601. * Tripal Unigene administrative setting form. This function is called by
  602. * tripal_analysis module which asks for an admin form to show on the page
  603. */
  604. function tripal_analysis_unigene_get_settings() {
  605. // Get an array of node types with internal names as keys
  606. $options = node_get_types('names');
  607. // Add 'chado_feature' to allowed content types for showing unigene results
  608. $allowedoptions ['chado_feature'] = "Show 'ESTs in this contig' on feature pages";
  609. $allowedoptions ['chado_organism'] = "Show assemblies on organism pages";
  610. $form['description'] = array(
  611. '#type' => 'item',
  612. '#value' => t("This option allows user to display the unigene assembly ".
  613. "information. For contigs, this would include an alignment and for ".
  614. "organisms this would be a list of assemblies. Check the box to ".
  615. "enable the display of unigene information. Uncheck to disable."),
  616. '#weight' => 0,
  617. );
  618. $form['tripal_analysis_unigene_setting'] = array(
  619. '#type' => 'checkboxes',
  620. '#options' => $allowedoptions,
  621. '#default_value'=>variable_get('tripal_analysis_unigene_setting',array()),
  622. );
  623. $settings->form = $form;
  624. $settings->title = "Tripal Unigene";
  625. return $settings;
  626. }
  627. /*******************************************************************************
  628. * Set the permission types that the chado module uses. Essentially we
  629. * want permissionis that protect creation, editing and deleting of chado
  630. * data objects
  631. */
  632. function tripal_analysis_unigene_perm(){
  633. return array(
  634. 'access chado_analysis_unigene content',
  635. 'create chado_analysis_unigene content',
  636. 'delete chado_analysis_unigene content',
  637. 'edit chado_analysis_unigene content',
  638. );
  639. }
  640. /*******************************************************************************
  641. * The following function proves access control for users trying to
  642. * perform actions on data managed by this module
  643. */
  644. function chado_analysis_unigene_access($op, $node, $account){
  645. if ($op == 'create') {
  646. return user_access('create chado_analysis_unigene content', $account);
  647. }
  648. if ($op == 'update') {
  649. if (user_access('edit chado_analysis_unigene content', $account)) {
  650. return TRUE;
  651. }
  652. }
  653. if ($op == 'delete') {
  654. if (user_access('delete chado_analysis_unigene content', $account)) {
  655. return TRUE;
  656. }
  657. }
  658. if ($op == 'view') {
  659. if (user_access('access chado_analysis_unigene content', $account)) {
  660. return TRUE;
  661. }
  662. }
  663. return FALSE;
  664. }