tripal_analysis_unigene.module 29 KB

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