tripal_analysis_unigene.module 28 KB

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