123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511 |
- <?php
- function tripal_analysis_go_init(){
- // Add style sheet
- drupal_add_css(drupal_get_path('theme', 'tripal').'/css/tripal_analysis_go.css');
- drupal_add_js(drupal_get_path('theme', 'tripal').'/js/tripal_analysis_go.js');
- }
- /*******************************************************************************
- * Menu items are automatically added for the new node types created
- * by this module to the 'Create Content' Navigation menu item. This function
- * adds more menu items needed for this module.
- */
- function tripal_analysis_go_menu() {
- $items = array();
- $items['download_goterm_features'] = array(
- 'path' => 'download_goterm_features',
- 'title' => t('Get GO Term Features'),
- 'page callback' => 'tripal_analysis_go_get_goterm_features',
- 'page arguments' => array(1,2),
- 'access arguments' => array('access chado_analysis_go content'),
- 'type' => MENU_CALLBACK
- );
- $items['tripal_analysis_go_org_charts'] = array(
- 'path' => 'tripal_analysis_go_org_charts',
- 'title' => t('Analysis GO Charts'),
- 'page callback' => 'tripal_analysis_go_org_charts',
- 'page arguments' => array(1),
- 'access arguments' => array('access chado_analysis_go content'),
- 'type' => MENU_CALLBACK
- );
- return $items;
- }
- /*******************************************************************************
- * Set the permission types that the chado module uses. Essentially we
- * want permissionis that protect creation, editing and deleting of chado
- * data objects
- */
- function tripal_analysis_go_perm(){
- return array(
- 'access chado_analysis_go content',
- 'create chado_analysis_go content',
- 'delete chado_analysis_go content',
- 'edit chado_analysis_go content',
- );
- }
- /*******************************************************************************
- * The following function proves access control for users trying to
- * perform actions on data managed by this module
- */
- function chado_analysis_go_access($op, $node, $account){
- if ($op == 'create') {
- return user_access('create chado_analysis_go content', $account);
- }
- if ($op == 'update') {
- if (user_access('edit chado_analysis_go content', $account)) {
- return TRUE;
- }
- }
- if ($op == 'delete') {
- if (user_access('delete chado_analysis_go content', $account)) {
- return TRUE;
- }
- }
- if ($op == 'view') {
- if (user_access('access chado_analysis_go content', $account)) {
- return TRUE;
- }
- }
- return FALSE;
- }
- /*******************************************************************************
- *
- */
- function tripal_analysis_go_block($op = 'list', $delta = 0, $edit=array()){
- switch($op) {
- case 'list':
- $blocks['tago_org_sum']['info'] = t('Tripal Organism GO Analysis Report');
- $blocks['tago_org_sum']['cache'] = BLOCK_NO_CACHE;
- return $blocks;
- case 'view':
- if(user_access('access chado_analysis_go content') and arg(0) == 'node' and is_numeric(arg(1))) {
- $nid = arg(1);
- $node = node_load($nid);
-
- $block = array();
- switch($delta){
- case 'tago_org_sum':
- $block['subject'] = t('GO Summary');
- $block['content'] = theme('tripal_analysis_go_org_summary',$node);
- break;
- default :
- }
- return $block;
- }
- }
- }
- /*******************************************************************************
- * HOOK: Implementation of hook_nodeapi()
- * Display library information for associated features or organisms
- * This function also provides contents for indexing
- */
- function tripal_analysis_go_nodeapi(&$node, $op, $teaser, $page) {
- switch ($op) {
- case 'view':
-
- if ($teaser) {
- return;
- }
- // add the library to the organism/feature search indexing
- if($node->build_mode == NODE_BUILD_SEARCH_INDEX){
- $node->content['tripal_analysis_go_search_index'] = array(
- '#value' => theme('tripal_analysis_go_search_index',$node),
- '#weight' => 5,
- );
- } else if ($node->build_mode == NODE_BUILD_SEARCH_RESULT) {
- $node->content['tripal_analysis_go_search_result'] = array(
- '#value' => theme('tripal_analysis_go_search_result',$node),
- '#weight' => 5,
- );
- } else {
- // Show go terms if the organism/feature is not at teaser view
- switch($node->type){
- case 'chado_organism':
- $node->content['tripal_organism_go_summary'] = array(
- '#value' => theme('tripal_organism_go_summary',$node),
- '#weight' => 5,
- );
- break;
- case 'chado_feature':
- $node->content['tripal_feature_go_terms'] = array(
- '#value' => theme('tripal_feature_go_terms',$node),
- '#weight' => 5,
- );
- break;
- }
- }
- break;
- }
- }
- /************************************************************************
- * We need to let drupal know about our theme functions and their arguments.
- * We create theme functions to allow users of the module to customize the
- * look and feel of the output generated in this module
- */
- function tripal_analysis_go_theme () {
- return array(
-
- 'tripal_analysis_go_search_index' => array (
- 'arguments' => array('node'),
- ),
- 'tripal_analysis_go_search_result' => array (
- 'arguments' => array('node'),
- ),
- 'tripal_organism_go_summary' => array (
- 'arguments' => array('node'=> null),
- 'template' => 'tripal_organism_go_summary',
- ),
- 'tripal_feature_go_terms' => array (
- 'arguments' => array('node'=> null),
- 'template' => 'tripal_feature_go_terms',
- )
- );
- }
- /************************************************************************
- */
- function theme_tripal_analysis_go_search_index($node){
- }
- /************************************************************************
- */
- function theme_tripal_analysis_go_search_result($node){
- }
- /************************************************************************
- */
- function tripal_analysis_go_preprocess_tripal_feature_go_terms(&$variables){
- $feature = $variables['node']->feature;
- $variables['tripal_analysis_go']['terms'] = tripal_analysis_go_load_feature_terms($feature);
- }
- /************************************************************************
- */
- function tripal_analysis_go_preprocess_tripal_organism_go_summary(&$variables){
- $node = $variables['node'];
- $variables['tripal_analysis_go']['select_form'] = tripal_analysis_go_load_organism_go_summary($node);
- }
- /************************************************************************
- */
- function tripal_analysis_go_select_form(&$form_state = NULL,$node){
- $form = array();
- // find analyses that have GO terms
- $sql = "
- SELECT DISTINCT A.analysis_id, A.name, GCA.organism_id
- FROM {go_count_analysis} GCA
- INNER JOIN Analysis A on GCA.analysis_id = A.analysis_id
- WHERE organism_id = %d
- ORDER BY analysis_id DESC
- ";
- $previous_db = tripal_db_set_active('chado');
- $results = db_query($sql,$node->organism->organism_id);
- tripal_db_set_active($previous_db);
- $analyses = array();
- $analyses[''] = '';
- while($analysis = db_fetch_object($results)){
- $analyses[$analysis->analysis_id."-".$analysis->organism_id] = "$analysis->name";
- }
-
- # create the select box
- $form['tripal_analysis_go_select'] = array(
- '#title' => t('Select a GO report to view'),
- '#description' => t('Any analysis with GO results related to this organism are available for viewing. For further information, see the analysis information page.'),
- '#type' => 'select',
- '#options' => $analyses,
- '#attributes' => array (
- 'onchange' => 'tripal_analysis_go_org_charts(this.options[this.selectedIndex].value)'
- ),
- );
- return $form;
- }
- /************************************************************************
- */
- function tripal_analysis_go_org_charts ($element) {
- $analysis_id = preg_replace("/^(\d+)-(\d+)$/","$1",$element);
- $organism_id = preg_replace("/^(\d+)-(\d+)$/","$2",$element);
- $content = '';
- if($analysis_id and $organism_id){
- $content = "
- <b>Biological Process</b>
- <br><i>Expand the tree to browse term counts. Click a term to view term details.</i>
- <div class=\"tripal_cv_tree\" id=\"tripal_analysis_go_cv_tree_".$organism_id."-".$analysis_id."_bp\"></div>
- <br><br><img class=\"tripal_cv_chart\" id=\"tripal_analysis_go_cv_chart_".$organism_id."-".$analysis_id."_bp\" src=\"\" border=\"0\">
- <br><br><br><br>
- <b>Cellular Component</b>
- <br><i>Expand the tree to browse term counts. Click a term to view term details.</i>
- <div class=\"tripal_cv_tree\" id=\"tripal_analysis_go_cv_tree_".$organism_id."-".$analysis_id."_cc\"></div>
- <br><br><img class=\"tripal_cv_chart\" id=\"tripal_analysis_go_cv_chart_".$organism_id."-".$analysis_id."_cc\" src=\"\" border=\"0\">
- <br><br><br><br>
- <b>Molecular Function</b>
- <br><i>Expand the tree to browse term counts. Click a term to view term details.</i>
- <div class=\"tripal_cv_tree\" id=\"tripal_analysis_go_cv_tree_".$organism_id."-".$analysis_id."_mf\"></div>
- <br><br><img class=\"tripal_cv_chart\" id=\"tripal_analysis_go_cv_chart_".$organism_id."-".$analysis_id."_mf\" src=\"\" border=\"0\">
- ";
- }
- $opt = array($content);
- return drupal_json($opt);
- }
- /************************************************************************
- */
- function tripal_analysis_go_load_organism_go_summary($node) {
- $organism = $node->organism;
- // check to see if we have any analyses
- $sql = "
- SELECT count(*) as cnt
- FROM {go_count_analysis} GCA
- INNER JOIN Analysis A on GCA.analysis_id = A.analysis_id
- WHERE organism_id = %d
- ";
- $previous_db = tripal_db_set_active('chado');
- $results = db_fetch_object(db_query($sql,$organism->organism_id));
- tripal_db_set_active($previous_db);
- $has_results = 0;
- if($results){
- $has_results = 1;
- }
- return array (
- 'has_results' => $has_results,
- 'form' => drupal_get_form('tripal_analysis_go_select_form',$node),
- );
- }
- /************************************************************************
- *
- */
- function tripal_analysis_go_cv_chart($chart_id){
- // The CV module will create the JSON array necessary for buillding a
- // pie chart using jgChart and Google Charts. We have to pass to it
- // a table that contains count information, tell it which column
- // contains the cvterm_id and provide a filter for getting the
- // results we want from the table.
- $organism_id = preg_replace("/^tripal_analysis_go_cv_chart_(\d+)-(\d+)_(bp|cc|mf)$/","$1",$chart_id);
- $analysis_id = preg_replace("/^tripal_analysis_go_cv_chart_(\d+)-(\d+)_(bp|cc|mf)$/","$2",$chart_id);
- $type = preg_replace("/^tripal_analysis_go_cv_chart_(\d+)-(\d+)_(bp|cc|mf)$/","$3",$chart_id);
- $sql = "SELECT * FROM {Analysis} WHERE analysis_id = %d";
- $previous_db = tripal_db_set_active('chado'); // use chado database
- $analysis = db_fetch_object(db_query($sql,$analysis_id));
- tripal_db_set_active($previous_db); // now use drupal database
-
- if(strcmp($type,'mf')==0){
- $class = 'molecular_function';
- $title = "Number of Molecular Function Terms From $analysis->name Analysis";
- }
- if(strcmp($type,'cc')==0){
- $class = 'cellular_component';
- $title = "Number of Cellular Component Terms From $analysis->name Analysis";
- }
- if(strcmp($type,'bp')==0){
- $class = 'biological_process';
- $title = "Number of Biological Process Terms From $analysis->name Analysis";
- }
- $options = array(
- count_mview => 'go_count_analysis',
- cvterm_id_column => 'cvterm_id',
- count_column => 'feature_count',
- filter => "
- CNT.organism_id = $organism_id AND
- CNT.analysis_id = $analysis_id AND
- CNT.cvterm_id IN (
- SELECT CVTR.subject_id
- FROM {CVTerm_relationship} CVTR
- INNER JOIN CVTerm CVT on CVTR.object_id = CVT.cvterm_id
- INNER JOIN CV on CVT.cv_id = CV.cv_id
- WHERE CVT.name = '$class' AND
- CV.name = '$class'
- )
- ",
- type => 'p',
- size => '550x175',
- title => $title,
- );
- return $options;
- }
- /************************************************************************
- *
- */
- function tripal_analysis_go_cv_tree($tree_id){
- $organism_id = preg_replace("/^tripal_analysis_go_cv_tree_(\d+)-(\d+)_(bp|cc|mf)$/","$1",$tree_id);
- $analysis_id = preg_replace("/^tripal_analysis_go_cv_tree_(\d+)-(\d+)_(bp|cc|mf)$/","$2",$tree_id);
- $type = preg_replace("/^tripal_analysis_go_cv_tree_(\d+)-(\d+)_(bp|cc|mf)$/","$3",$tree_id);
- if(strcmp($type,'mf')==0){
- $class = 'molecular_function';
- }
- if(strcmp($type,'cc')==0){
- $class = 'cellular_component';
- }
- if(strcmp($type,'bp')==0){
- $class = 'biological_process';
- }
- $options = array(
- cv_id => tripal_cv_get_cv_id($class),
- count_mview => 'go_count_analysis',
- cvterm_id_column => 'cvterm_id',
- count_column => 'feature_count',
- filter => "CNT.organism_id = $organism_id AND CNT.analysis_id = $analysis_id",
- label => 'Features',
- );
- return $options;
- }
- /************************************************************************
- */
- function tripal_analysis_go_cvterm_add($cvterm_id,$tree_id){
- $organism_id = preg_replace("/^tripal_analysis_go_cv_tree_(\d+)-(\d+)_(bp|cc|mf)$/","$1",$tree_id);
- $analysis_id = preg_replace("/^tripal_analysis_go_cv_tree_(\d+)-(\d+)_(bp|cc|mf)$/","$2",$tree_id);
- $sql = "
- SELECT DBX.accession
- FROM {cvterm} CVT
- INNER JOIN dbxref DBX on DBX.dbxref_id = CVT.dbxref_id
- WHERE cvterm_id = %d
- ";
- $previous_db = tripal_db_set_active('chado');
- $xref = db_fetch_object(db_query($sql,$cvterm_id));
- tripal_db_set_active($previous_db);
- $link = url("download_goterm_features/$cvterm_id/$tree_id");
- $options = array(
- 'Download sequences' => "<a href=\"$link\">GO_".$xref->accession.".fasta</a>",
- );
- return $options;
- }
- /************************************************************************
- */
- function tripal_analysis_go_get_goterm_features($cvterm_id,$tree_id){
- // get hte accession number for this cvterm and use it in naming the download
- $sql = "
- SELECT DBX.accession
- FROM {cvterm} CVT
- INNER JOIN dbxref DBX on DBX.dbxref_id = CVT.dbxref_id
- WHERE cvterm_id = %d
- ";
- $previous_db = tripal_db_set_active('chado');
- $xref = db_fetch_object(db_query($sql,$cvterm_id));
- tripal_db_set_active($previous_db);
- drupal_set_header('Content-Type: text');
- drupal_set_header('Content-Disposition: attachment; filename="GO_'.$xref->accession.'.fasta"');
- $organism_id = preg_replace("/^tripal_analysis_go_cv_tree_(\d+)-(\d+)_(bp|cc|mf)$/","$1",$tree_id);
- $analysis_id = preg_replace("/^tripal_analysis_go_cv_tree_(\d+)-(\d+)_(bp|cc|mf)$/","$2",$tree_id);
- $sql = "
- SELECT DISTINCT F.name,F.residues,F.feature_id
- FROM {cvtermpath} CVTP
- INNER JOIN CVTerm CVT1 on CVTP.subject_id = CVT1.cvterm_id
- INNER JOIN CVTerm CVT2 on CVTP.object_id = CVT2.cvterm_id
- INNER JOIN AnalysisFeatureProp AFP on AFP.type_id = CVTP.subject_id
- INNER JOIN AnalysisFeature AF on AF.analysisfeature_id = AFP.analysisfeature_id
- INNER JOIN Feature F on AF.feature_id = F.feature_id
- WHERE CVTP.object_id = %d and F.organism_id = %d and AF.analysis_id = %d
- ORDER BY F.name
- ";
- $previous_db = tripal_db_set_active('chado');
- $results = db_query($sql,$cvterm_id,$organism_id,$analysis_id);
- tripal_db_set_active($previous_db);
- while($feature = db_fetch_object($results)){
- // get the go term information for each sequence
- $sql = "
- SELECT CVT.name,DBX.accession
- FROM {Feature_CVTerm} FCVT
- INNER JOIN CVTerm CVT on FCVT.cvterm_id = CVT.cvterm_id
- INNER JOIN DBXref DBX on CVT.dbxref_id = DBX.dbxref_id
- WHERE FCVT.feature_id = %d
- ";
- $previous_db = tripal_db_set_active('chado');
- $terms = db_query($sql,$feature->feature_id);
- tripal_db_set_active($previous_db);
- $desc = '[';
- while($term = db_fetch_object($terms)){
- $desc .= "GO:$term->accession $term->name; ";
- }
- $desc = chop($desc);
- $desc = chop($desc,';');
- $desc .= ']';
- print tripal_feature_return_fasta($feature, $desc);
- }
- return;
- }
- /************************************************************************
- */
- function tripal_analysis_go_load_feature_terms($feature) {
- $sql = "
- SELECT DISTINCT FCVT.feature_id,DBX.accession,CVT.name as goterm,
- CVT.cvterm_id as go_id, CV.name as cvname, CVT.definition
- FROM {Feature_Cvterm} FCVT
- INNER JOIN Cvterm CVT ON CVT.cvterm_ID = FCVT.cvterm_ID
- INNER JOIN CV ON CV.cv_id = CVT.cv_id
- INNER JOIN dbxref DBX ON DBX.dbxref_id = CVT.dbxref_id
- WHERE
- (CV.name = 'biological_process' OR
- CV.name = 'cellular_component' OR
- CV.name = 'molecular_function') AND
- FCVT.feature_id = %d
- ORDER BY CV.name, CVT.name
- ";
- $previous_db = tripal_db_set_active('chado');
- $results = db_query($sql,$feature->feature_id);
- tripal_db_set_active($previous_db);
- $i=0;
- $terms = array();
- while($term = db_fetch_object($results)){
- $terms[$i++] = $term;
- }
- return $terms;
- }
- /*******************************************************************************
- * Tripal GO administrative setting form. This function is called by
- * tripal_analysis module which asks for an admin form to show on the page
- */
- function tripal_analysis_go_get_settings() {
- // Get an array of node types with internal names as keys
- $options = node_get_types('names');
- // Add 'chado_feature' to allowed content types for showing unigene results
- $allowedoptions ['chado_feature'] = "Show GO terms on feature pages";
- $allowedoptions ['chado_organism'] = "Show GO analysis on organism pages";
- $form['description'] = array(
- '#type' => 'item',
- '#value' => t("This option allows user to display the Gene Ontology (GO) ".
- "information. For features, this would include all GO terms assigned to a feature ".
- "and for organisms this would be statistical pie charts of GO terms for a organism. Check the box to ".
- "enable the display of GO information. Uncheck to disable."),
- '#weight' => 0,
- );
- $form['tripal_analysis_go_setting'] = array(
- '#type' => 'checkboxes',
- '#options' => $allowedoptions,
- '#default_value'=>variable_get('tripal_analysis_go_setting',array('chado_feature', 'chado_organism')),
- );
- $settings->form = $form;
- $settings->title = "Tripal GO";
- return $settings;
- }
|