tripal_analysis_unigene.module 28 KB

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