tripal_analysis_unigene.module 26 KB

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