tripal_analysis_unigene.module 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. <?php
  2. function tripal_analysis_unigene_init(){
  3. // Add style sheet
  4. drupal_add_css(drupal_get_path('theme', 'tripal').'/css/tripal_analysis_unigene.css');
  5. }
  6. /**
  7. *
  8. */
  9. function tripal_analysis_unigene_node_info() {
  10. $nodes = array();
  11. $nodes['chado_analysis_unigene'] = array(
  12. 'name' => t('Analysis: Unigene'),
  13. 'module' => 'chado_analysis_unigene',
  14. 'description' => t('A unigene assembly constructed from transcriptomic reads.'),
  15. 'has_title' => FALSE,
  16. 'title_label' => t('Analysis: Unigene'),
  17. 'has_body' => FALSE,
  18. 'body_label' => t('Unigene Analysis Description'),
  19. 'locked' => TRUE
  20. );
  21. return $nodes;
  22. }
  23. /*******************************************************************************
  24. * Set the permission types that the chado module uses. Essentially we
  25. * want permissionis that protect creation, editing and deleting of chado
  26. * data objects
  27. */
  28. function tripal_analysis_unigene_perm(){
  29. return array(
  30. 'access chado_analysis_unigene content',
  31. 'create chado_analysis_unigene content',
  32. 'delete chado_analysis_unigene content',
  33. 'edit chado_analysis_unigene content',
  34. );
  35. }
  36. /*******************************************************************************
  37. * The following function proves access control for users trying to
  38. * perform actions on data managed by this module
  39. */
  40. function chado_analysis_unigene_access($op, $node, $account){
  41. if ($op == 'create') {
  42. return user_access('create chado_analysis_unigene content', $account);
  43. }
  44. if ($op == 'update') {
  45. if (user_access('edit chado_analysis_unigene content', $account)) {
  46. return TRUE;
  47. }
  48. }
  49. if ($op == 'delete') {
  50. if (user_access('delete chado_analysis_unigene content', $account)) {
  51. return TRUE;
  52. }
  53. }
  54. if ($op == 'view') {
  55. if (user_access('access chado_analysis_unigene content', $account)) {
  56. return TRUE;
  57. }
  58. }
  59. return FALSE;
  60. }
  61. /**
  62. *
  63. */
  64. function chado_analysis_unigene_form ($node){
  65. // add in the default fields
  66. $form = chado_analysis_form($node);
  67. $unigene = $node->analysis->tripal_analysis_unigene;
  68. $unigene_name = $unigene->unigene_name;
  69. $num_reads = $unigene->num_reads;
  70. $num_clusters = $unigene->num_clusters;
  71. $num_contigs = $unigene->num_contigs;
  72. $num_singlets = $unigene->num_singlets;
  73. $form['unigene_name'] = array(
  74. '#title' => t('Unigene Name'),
  75. '#type' => 'textfield',
  76. '#required' => TRUE,
  77. '#description' => t('A distinct name used to identify this unigene'),
  78. '#default_value' => $unigene_name,
  79. );
  80. $form['num_reads'] = array(
  81. '#title' => t('Number of Reads'),
  82. '#type' => 'textfield',
  83. '#required' => FALSE,
  84. '#description' => t('Provide the number of reads, after filtering that were used for input into the assembly'),
  85. '#default_value' => $num_reads,
  86. );
  87. $form['num_clusters'] = array(
  88. '#title' => t('Number of Clusters'),
  89. '#type' => 'textfield',
  90. '#required' => FALSE,
  91. '#description' => t('Provide the number of clusters generated by the asssembly if a clustering mechanism was used for unigene constructions'),
  92. '#default_value' => $num_clusters,
  93. );
  94. $form['num_contigs'] = array(
  95. '#title' => t('Number of Contigs'),
  96. '#type' => 'textfield',
  97. '#required' => FALSE,
  98. '#description' => t('Provide the number of contigs generated by the assembly'),
  99. '#default_value' => $num_contigs,
  100. );
  101. $form['num_singlets'] = array(
  102. '#title' => t('Number of Singlets'),
  103. '#type' => 'textfield',
  104. '#required' => FALSE,
  105. '#description' => t('Provide the number of singlets remaining in the assembly'),
  106. '#default_value' => $num_singlets,
  107. );
  108. }
  109. /**
  110. *
  111. */
  112. function chado_analysis_unigene_insert($node){
  113. // insert the analysis
  114. chado_analysis_insert($node);
  115. // add the unigene name as a property of the anslysis
  116. tripal_analysis_insert_property($node->analysis->analysis_id,'analysis_type','tripal_analysis_unigene');
  117. tripal_analysis_insert_property($node->analysis->analysis_id,'analysis_unigene_name',$node->unigene_name);
  118. tripal_analysis_insert_property($node->analysis->analysis_id,'analysis_unigene_num_contigs',$node->num_contigs);
  119. tripal_analysis_insert_property($node->analysis->analysis_id,'analysis_unigene_num_reads',$node->num_reads);
  120. tripal_analysis_insert_property($node->analysis->analysis_id,'analysis_unigene_num_clusters',$node->num_clusters);
  121. tripal_analysis_insert_property($node->analysis->analysis_id,'analysis_unigene_num_singlets',$node->num_clusters);
  122. }
  123. /**
  124. *
  125. */
  126. function chado_analysis_unigene_update($node){
  127. chado_analysis_update($node);
  128. tripal_analysis_update_property($node->analysis_id,'analysis_unigene_name',$node->unigene_name,1);
  129. tripal_analysis_update_property($node->analysis_id,'analysis_unigene_num_contigs',$node->num_contigs,1);
  130. tripal_analysis_update_property($node->analysis_id,'analysis_unigene_num_reads',$node->num_reads,1);
  131. tripal_analysis_update_property($node->analysis_id,'analysis_unigene_num_clusters',$node->num_clusters,1);
  132. tripal_analysis_update_property($node->analysis_id,'analysis_unigene_num_singlets',$node->num_singlets,1);
  133. }
  134. /**
  135. *
  136. */
  137. function chado_analysis_unigene_delete($node){
  138. chado_analysis_delete($node);
  139. }
  140. /**
  141. *
  142. */
  143. function chado_analysis_unigene_view ($node, $teaser = FALSE, $page = FALSE) {
  144. // use drupal's default node view:
  145. $node = node_prepare($node, $teaser);
  146. return $node;
  147. }
  148. /**
  149. *
  150. */
  151. function chado_analysis_unigene_load($node){
  152. // load the default set of analysis fields
  153. $additions = chado_analysis_load($node);
  154. // create some variables for easier lookup
  155. $analysis = $additions->analysis;
  156. $analysis_id = $analysis->analysis_id;
  157. // add in the properties
  158. $unigene_name = tripal_analysis_get_property($analysis_id,'analysis_unigene_name');
  159. $num_contigs = tripal_analysis_get_property($analysis_id,'analysis_unigene_num_contigs');
  160. $num_reads = tripal_analysis_get_property($analysis_id,'analysis_unigene_num_reads');
  161. $num_clusters = tripal_analysis_get_property($analysis_id,'analysis_unigene_num_clusters');
  162. $num_singlets = tripal_analysis_get_property($analysis_id,'analysis_unigene_num_singlets');
  163. $analysis->tripal_analysis_unigene->unigene_name = $unigene_name->value;
  164. $analysis->tripal_analysis_unigene->num_contigs = $num_contigs->value;
  165. $analysis->tripal_analysis_unigene->num_reads = $num_reads->value;
  166. $analysis->tripal_analysis_unigene->num_clusters = $num_clusters->value;
  167. $analysis->tripal_analysis_unigene->num_singlets = $num_singlets->value;
  168. // add in organism information using the materialized view
  169. $sql = "SELECT * FROM {organism_unigene_mview} OUM ".
  170. " INNER JOIN {organism} O on OUM.organism_id = O.organism_id ".
  171. "WHERE OUM.analysis_id = %d ".
  172. "ORDER BY O.genus, O.species";
  173. $previous_db = tripal_db_set_active('chado'); // use chado database
  174. $organisms = db_query($sql,$analysis_id);
  175. tripal_db_set_active($previous_db); // now use drupal database
  176. while($organism = db_fetch_object($organisms)){
  177. $sql = "SELECT nid FROM {chado_organism} WHERE organism_id = %d";
  178. $c_org = db_fetch_object(db_query($sql,$organism->organism_id));
  179. $organism->nid = $c_org->nid;
  180. $analysis->tripal_analysis_unigene->organisms[] = $organism;
  181. }
  182. return $additions;
  183. }
  184. /*******************************************************************************
  185. * tripal_analysis_unigene_nodeapi()
  186. * HOOK: Implementation of hook_nodeapi()
  187. * Display unigene results for allowed node types
  188. */
  189. function tripal_analysis_unigene_nodeapi(&$node, $op, $teaser, $page) {
  190. switch ($op) {
  191. case 'view':
  192. // Find out which node types for showing the unigene
  193. $types_to_show = variable_get('tripal_analysis_unigene_setting',
  194. array('chado_feature','chado_organism'));
  195. // Abort if this node is not one of the types we should show.
  196. if (in_array($node->type, $types_to_show, TRUE)) {
  197. // Add unigene to the content item if it's not a teaser
  198. if ($teaser) {
  199. return '';
  200. }
  201. // add the alignment to the feature search indexing
  202. if($node->build_mode == NODE_BUILD_SEARCH_INDEX){
  203. $node->content['tripal_analysis_unigene_index_version'] = array(
  204. '#value' => theme('tripal_analysis_unigene_search_index',$node),
  205. '#weight' => 4,
  206. );
  207. } else if ($node->build_mode == NODE_BUILD_SEARCH_RESULT) {
  208. $node->content['tripal_analysis_unigene_index_version'] = array(
  209. '#value' => theme('tripal_analysis_unigene_search_result',$node),
  210. '#weight' => 4,
  211. );
  212. } else {
  213. if(strcmp($node->type,'chado_organism')==0){
  214. $node->content['tripal_organism_unigenes'] = array(
  215. '#value' => theme('tripal_organism_unigenes', $node),
  216. '#weight' => 4
  217. );
  218. }
  219. }
  220. }
  221. break;
  222. }
  223. }
  224. /************************************************************************
  225. * We need to let drupal know about our theme functions and their arguments.
  226. * We create theme functions to allow users of the module to customize the
  227. * look and feel of the output generated in this module
  228. */
  229. function tripal_analysis_unigene_theme () {
  230. return array(
  231. 'tripal_analysis_unigene_search_index' => array (
  232. 'arguments' => array('node'),
  233. ),
  234. 'tripal_analysis_unigene_search_result' => array (
  235. 'arguments' => array('node'),
  236. ),
  237. 'tripal_organism_unigenes' => array (
  238. 'arguments' => array('node'=> null),
  239. 'template' => 'tripal_organism_unigenes',
  240. ),
  241. 'tripal_analysis_unigene_base' => array (
  242. 'arguments' => array('node'=> null),
  243. 'template' => 'tripal_analysis_unigene_base',
  244. ),
  245. );
  246. }
  247. /*******************************************************************************
  248. *
  249. */
  250. function tripal_analysis_unigene_preprocess_tripal_organism_unigenes(&$variables){
  251. $node = $variables['node'];
  252. $organism = $node->organism;
  253. $unigenes = tripal_analysis_unigene_load_organism_unigenes($organism);
  254. $node->organism->tripal_analysis_unigene->unigenes = $unigenes;
  255. }
  256. /************************************************************************
  257. * This function is an extension of the chado_feature_view by providing
  258. * the markup for the feature object THAT WILL BE INDEXED.
  259. */
  260. function theme_tripal_analysis_unigene_search_index ($node) {
  261. $feature = $node->feature;
  262. $obj_feature = tripal_analysis_unigene_get_alignments($feature);
  263. $alignments = $obj_feature->alignments;
  264. $content = "<strong>";
  265. if(count($alignments) > 0){
  266. // iterate through each alignment
  267. foreach ($alignments as $result){
  268. // EST alignments in chado use an EST_match type to map ESTs to
  269. // contigs and a rank to indicate the major srcfeature.
  270. // We don't want to show EST_matches on the alignment view
  271. // since that doesn't make much sense to the end user. If this
  272. // is an EST_match and the feature is an EST then we want to show
  273. // the contig in the alignments. The contig name is part of the
  274. // uniquename in the EST_match
  275. if($node->feature->cvname == 'EST' && $result->cvname == 'EST_match'){
  276. $sql = "SELECT srcfeature_id ".
  277. "FROM {featureloc} ".
  278. "WHERE feature_id = $result->feature_id ".
  279. "ORDER BY rank";
  280. $previous_db = tripal_db_set_active ('chado');
  281. $contig_fid = db_result(db_query($sql));
  282. $sql = "SELECT name FROM {feature} WHERE feature_id = $contig_fid";
  283. $contig_name = db_result(db_query($sql));
  284. tripal_db_set_active($previous_db);
  285. $sql = "SELECT nid ".
  286. "FROM {chado_feature} ".
  287. "WHERE feature_id = $contig_fid";
  288. $contig_nid = db_result(db_query($sql));
  289. // Check if the EST exists as a drupal node. If yes, add a link to
  290. // it. If no, just show the name
  291. if ($contig_nid != 0) {
  292. $sql = "SELECT nid FROM {node} WHERE nid=$contig_nid";
  293. $node_exists = db_result(db_query($sql));
  294. }
  295. $content .= "$contig_name " ;
  296. }
  297. elseif($node->feature->cvname == 'contig' && $result->cvname == 'EST_match'){
  298. $sql = "SELECT vid ".
  299. "FROM {node} ".
  300. "WHERE title = '$result->feature_name'".
  301. "ORDER BY vid DESC";
  302. // since the feature name is also the node title we can look it up
  303. $est_node = db_fetch_object(db_query($sql));
  304. $content .= "$result->feature_name ";
  305. }
  306. else {
  307. $content .= "$result->cvname $result->feature_name ";
  308. }
  309. }
  310. }
  311. $content .= "</strong>";
  312. return $content;
  313. }
  314. /************************************************************************
  315. * This function is an extension of the chado_feature_view by providing
  316. * the markup for the feature object to show on a search result page.
  317. */
  318. function theme_tripal_analysis_unigene_search_result ($node) {
  319. $feature = $node->feature;
  320. $obj_feature = tripal_analysis_unigene_get_alignments($feature);
  321. $alignments = $obj_feature->alignments;
  322. $content = "<strong>";
  323. if(count($alignments) > 0){
  324. // iterate through each alignment
  325. foreach ($alignments as $result){
  326. // EST alignments in chado use an EST_match type to map ESTs to
  327. // contigs and a rank to indicate the major srcfeature.
  328. // We don't want to show EST_matches on the alignment view
  329. // since that doesn't make much sense to the end user. If this
  330. // is an EST_match and the feature is an EST then we want to show
  331. // the contig in the alignments. The contig name is part of the
  332. // uniquename in the EST_match
  333. if($node->feature->cvname == 'EST' && $result->cvname == 'EST_match'){
  334. $sql = "SELECT srcfeature_id ".
  335. "FROM {featureloc} ".
  336. "WHERE feature_id = $result->feature_id ".
  337. "ORDER BY rank";
  338. $previous_db = tripal_db_set_active ('chado');
  339. $contig_fid = db_result(db_query($sql));
  340. $sql = "SELECT name FROM {feature} WHERE feature_id = $contig_fid";
  341. $contig_name = db_result(db_query($sql));
  342. tripal_db_set_active($previous_db);
  343. $sql = "SELECT nid ".
  344. "FROM {chado_feature} ".
  345. "WHERE feature_id = $contig_fid";
  346. $contig_nid = db_result(db_query($sql));
  347. // Check if the EST exists as a drupal node. If yes, add a link to
  348. // it. If no, just show the name
  349. if ($contig_nid != 0) {
  350. $sql = "SELECT nid FROM {node} WHERE nid=$contig_nid";
  351. $node_exists = db_result(db_query($sql));
  352. }
  353. $content .= "Alignment to contig $contig_name. " ;
  354. }
  355. elseif($node->feature->cvname == 'contig' && $result->cvname == 'EST_match'){
  356. $sql = "SELECT vid ".
  357. "FROM {node} ".
  358. "WHERE title = '$result->feature_name'".
  359. "ORDER BY vid DESC";
  360. // since the feature name is also the node title we can look it up
  361. $est_node = db_fetch_object(db_query($sql));
  362. $content .= "Aligned EST: $result->feature_name ";
  363. }
  364. else {
  365. $content .= "Aligned $result->cvname: $result->feature_name ";
  366. }
  367. }
  368. }
  369. $content .= "</strong>";
  370. return $content;
  371. }
  372. /*******************************************************************************
  373. * tripal_analysis_unigene_results ()
  374. * Prepare unigene result for the feature shown on the page
  375. */
  376. function theme_tripal_analysis_unigene_feature_alignments($node) {
  377. $feature = $node->feature;
  378. $obj_feature = tripal_analysis_unigene_get_alignments($feature);
  379. $alignments = $obj_feature->alignments;
  380. if(count($alignments) > 0){
  381. $content = "<div id=\"tripal_analysis_unigene_box\" class=\"tripal_unigene-info-box\">";
  382. // we're showing contig alignments in GBrowse so create a link here for
  383. // that if this feature is a contig
  384. if($node->feature->cvname == 'contig'){
  385. $content .= "<div class=\"tripal_expandableBox\">".
  386. " <h3>ESTs in this contig</h3>".
  387. "</div>";
  388. $content .= "<div class=\"tripal_expandableBoxContent\">";
  389. } else {
  390. $content .= "<div class=\"tripal_expandableBox\">".
  391. " <h3>Alignments</h3>".
  392. "</div>";
  393. $content .= "<div class=\"tripal_expandableBoxContent\">";
  394. }
  395. $content .= "".
  396. "<table class=\"tripal_table_horz\">".
  397. " <tr>".
  398. " <th>Type</th>".
  399. " <th>Feature</th>".
  400. " <th align=\"right\">Position</th>".
  401. " </tr>";
  402. // iterate through each alignment
  403. foreach ($alignments as $result){
  404. // EST alignments in chado use an EST_match type to map ESTs to
  405. // contigs and a rank to indicate the major srcfeature.
  406. // We don't want to show EST_matches on the alignment view
  407. // since that doesn't make much sense to the end user. If this
  408. // is an EST_match and the feature is an EST then we want to show
  409. // the contig in the alignments. The contig name is part of the
  410. // uniquename in the EST_match
  411. if($node->feature->cvname == 'EST' && $result->cvname == 'EST_match'){
  412. $sql = "SELECT srcfeature_id ".
  413. "FROM {featureloc} ".
  414. "WHERE feature_id = $result->feature_id ".
  415. "ORDER BY rank";
  416. $previous_db = tripal_db_set_active ('chado');
  417. $contig_fid = db_result(db_query($sql));
  418. $sql = "SELECT name FROM {feature} WHERE feature_id = $contig_fid";
  419. $contig_name = db_result(db_query($sql));
  420. tripal_db_set_active($previous_db);
  421. $sql = "SELECT nid ".
  422. "FROM {chado_feature} ".
  423. "WHERE feature_id = $contig_fid";
  424. $contig_nid = db_result(db_query($sql));
  425. // Check if the EST exists as a drupal node. If yes, add a link to
  426. // it. If no, just show the name
  427. if ($contig_nid != 0) {
  428. $sql = "SELECT nid FROM {node} WHERE nid=$contig_nid";
  429. $node_exists = db_result(db_query($sql));
  430. }
  431. $content .=
  432. "<tr>".
  433. " <td>Contig</td>".
  434. " <td>";
  435. if ($node_exists != 0) {
  436. $content .= "<a href=\"".url("node/$contig_nid")."\">".
  437. "$contig_name</a>";
  438. } else {
  439. $content .= $contig_name;
  440. }
  441. $content .=
  442. " </td>".
  443. " <td align=\"right\">".
  444. number_format($result->fmin).
  445. "-".
  446. number_format($result->fmax).
  447. " </td>".
  448. "</tr>";
  449. }
  450. elseif($node->feature->cvname == 'contig' &&
  451. $result->cvname == 'EST_match'){
  452. $sql = "SELECT vid ".
  453. "FROM {node} ".
  454. "WHERE title = '$result->feature_name'".
  455. "ORDER BY vid DESC";
  456. // since the feature name is also the node title we can look it up
  457. $est_node = db_fetch_object(db_query($sql));
  458. $content .=
  459. "<tr>".
  460. " <td>EST</td>".
  461. " <td>";
  462. //Check if the EST exists as a drupal node before adding a hyperlink
  463. if ($est_node->vid != 0) {
  464. $content .=
  465. "<a href=\"".url("node/$est_node->vid")."\">".
  466. $result->feature_name.
  467. "</a>";
  468. } else {
  469. $content .= $result->feature_name;
  470. }
  471. $content .=
  472. " </td>".
  473. " <td align=\"right\">".
  474. number_format($result->fmin).
  475. "-".
  476. number_format($result->fmax).
  477. " </td>".
  478. "</tr>";
  479. }
  480. else {
  481. $content .= "".
  482. "<tr>".
  483. " <td>$result->cvname</td>".
  484. " <td>$result->feature_name</td>".
  485. " <td align=\"right\">$result->fmin</td>".
  486. " <td align=\"right\">$result->fmax</td>".
  487. " <td align=\"right\">$result->strand</td>".
  488. "</tr>";
  489. }
  490. }
  491. $content .= "</table>";
  492. /* if this is a contig then get the alignment
  493. if($node->feature->cvname == 'contig'){
  494. // get the directory prefix
  495. $prefix = preg_replace("/^(\d*)\d{3}$/","$1",$node->feature_id);
  496. if(!$prefix){
  497. $prefix = '0';
  498. }
  499. $data_url = variable_get('chado_feature_data_url','sites/default/files/data');
  500. $fh = fopen("$data_url/misc/$prefix/$node->feature->feature_id/alignment.txt", 'r');
  501. if($fh){
  502. $content .= "<b>Alignment:</b><div class=\"tripal_feature_assembly_alignment\"><pre>";
  503. while(!feof($fh)){
  504. $content .= fgets($fh);
  505. }
  506. $content .="</pre></div>";
  507. }
  508. fclose($fh);
  509. }
  510. */
  511. $content .= "</div></div>";
  512. }
  513. return $content;
  514. }
  515. /*******************************************************************************
  516. *
  517. */
  518. function tripal_analysis_unigene_get_alignments($map) {
  519. // get the alignments for this feature
  520. $sql = "SELECT F.name as feature_name, FL.fmin, FL.fmax, FL.strand, ".
  521. " FL.phase, CVT.name as cvname, F.feature_id, F.uniquename, ".
  522. " FL.featureloc_id ".
  523. "FROM {featureloc} FL ".
  524. " INNER JOIN Feature F ON F.feature_id = FL.feature_id ".
  525. " INNER JOIN Cvterm CVT ON CVT.cvterm_id = F.type_id ".
  526. "WHERE srcfeature_id = %d AND ".
  527. " NOT(CVT.name = 'match' or CVT.name = 'match_part') ".
  528. "ORDER BY FL.fmin, FL.fmax";
  529. $previous_db = tripal_db_set_active('chado');
  530. $results = db_query($sql,$map->feature_id);
  531. $alignments = array();
  532. $i=0;
  533. while($subfeature = db_fetch_object($results)){
  534. $alignments[$i++] = $subfeature;
  535. }
  536. $additions->alignments = $alignments;
  537. /* get the GO Terms
  538. $sql = "SELECT DISTINCT * FROM {go_results_mview} ".
  539. "WHERE feature_id = %d";
  540. $results = db_query($sql,$map->feature_id);
  541. $go_terms = array();
  542. $i=0;
  543. while($term = db_fetch_object($results)){
  544. $go_terms[$i++] = $term;
  545. }
  546. $additions->go_terms = $go_terms;
  547. // get the feature properties
  548. $sql = "SELECT FP.value,FP.rank,CVT.name,CVT.definition ".
  549. "FROM {featureprop} FP".
  550. " INNER JOIN Cvterm CVT ".
  551. " ON FP.type_id = CVT.cvterm_id ".
  552. "WHERE feature_id = %d";
  553. $results = db_query($sql,$map->feature_id);
  554. $properties = array();
  555. $i=0;
  556. while($property = db_fetch_object($results)){
  557. $properties[$i++] = $property;
  558. }
  559. $additions->properties = $properties;
  560. */
  561. tripal_db_set_active($previous_db);
  562. return $additions;
  563. }
  564. /************************************************************************
  565. *
  566. */
  567. function tripal_analysis_unigene_load_organism_unigenes($organism){
  568. // get information about this assemblies and add it to the items in this node
  569. $sql = "SELECT * FROM {organism_unigene_mview} OUM ".
  570. " INNER JOIN {analysis} A ON A.analysis_id = OUM.analysis_id ".
  571. "WHERE OUM.organism_id = %d ".
  572. "ORDER BY A.timeexecuted DESC";
  573. $previous_db = tripal_db_set_active('chado'); // use chado database
  574. $results = db_query($sql,$organism->organism_id);
  575. tripal_db_set_active($previous_db); // now use drupal database
  576. $unigenes = array();
  577. $i=0;
  578. $sql = "SELECT nid FROM {chado_analysis} WHERE analysis_id = %d";
  579. while($unigene = db_fetch_object($results)){
  580. $analysis_id = $unigene->analysis_id;
  581. $c_node = db_fetch_object(db_query($sql,$analysis_id));
  582. if($c_node){
  583. $unigene->nid = $c_node->nid;
  584. }
  585. // add in the properties
  586. $unigene_name = tripal_analysis_get_property($analysis_id,'analysis_unigene_name');
  587. $num_contigs = tripal_analysis_get_property($analysis_id,'analysis_unigene_num_contigs');
  588. $num_reads = tripal_analysis_get_property($analysis_id,'analysis_unigene_num_reads');
  589. $num_clusters = tripal_analysis_get_property($analysis_id,'analysis_unigene_num_clusters');
  590. $num_singlets = tripal_analysis_get_property($analysis_id,'analysis_unigene_num_singlets');
  591. $unigene->unigene_name = $unigene_name->value;
  592. $unigene->num_reads = $num_reads->value;
  593. $unigene->num_clusters = $num_clusters->value;
  594. $unigene->num_contigs = $num_contigs->value;
  595. $unigene->num_singlets = $num_singlets->value;
  596. $unigenes[$i++] = $unigene;
  597. }
  598. return $unigenes;
  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. }