Tripal v1.0 (6.x-1.0)
|
tripal_ajax_cv_edit | ( | ) |
Purpose: The edit controlled vocabulary javascript
Definition at line 55 of file tripal_cv_admin.inc.
{ // get the database id, build the form and then return the JSON object $cvid = filter_xss($_POST['cvid']); $form = drupal_get_form('tripal_cv_edit_form', $cvid); drupal_json(array('status' => TRUE, 'data' => $form)); }
tripal_cv_add_form | ( | &$ | form_state = NULL | ) |
Purpose: Provides the Add controlled vocabulary form
Definition at line 178 of file tripal_cv_admin.inc.
{ $form['cvid'] = array( '#type' => 'hidden', '#value' => $cvid ); $form['name']= array( '#type' => 'textfield', '#title' => t("Controlled Vocabulary name"), '#description' => t('Please enter the name for this vocabulary. This field will be ignored if an OBO file or URL is provided above'), '#required' => FALSE, '#default_value' => $default_cv, '#weight' => 1 ); $form['definition']= array( '#type' => 'textarea', '#title' => t('Description'), '#description' => t('Please enter a description for this vocabulary'), '#default_value' => $default_desc, '#weight' => 2 ); $form['add'] = array( '#type' => 'submit', '#value' => t('Add'), '#weight' => 5, '#executes_submit_callback' => TRUE, ); $form['#redirect'] = 'admin/tripal/tripal_cv'; return $form; }
tripal_cv_add_form_submit | ( | $ | form, |
&$ | form_state | ||
) |
Purpose: The submit function for the add controlled vocabulary form
Definition at line 219 of file tripal_cv_admin.inc.
{ $name = $form_state['values']['name']; $desc = $form_state['values']['definition']; $sql = " INSERT INTO {cv} (name,definition) VALUES ('%s','%s') "; $db = chado_query($sql, $name, $desc); if ($db) { drupal_set_message(t("Controlled vocabulary added")); } else { drupal_set_message(t("Failed to add controlled vocabulary."), 'error'); } }
tripal_cv_chart | ( | $ | chart_id | ) |
Generates JSON used for generating a Google chart of count data associated with a controlled vocabulary. An example would be features assigned to Gene Ontology terms.
To generate a chart, the progammer must first create a materialized view that will generate count data for a given controlled vocabulary. For example, the Tripal Analysis GO creates a materialized view for counting Gene Ontology assignments to features. This view is created on install of the module and is named 'go_count_analysis'.
Next, an HTML 'div' box must be added to the desired page with a class name of 'tripal_cv_chart', and an id of the following format:
tripal_[module_name]_cv_chart_[unique id]
where [module_name] is the name of the tripal module (e.g. tripal_analyisis_go) and [unique id] is some unique identifier that the contolling module recognizes. This string is the $chart_id variable passed as the first argument to the function. For example, the Tripal GO Analysis module generates chart ids of the form:
tripal_analysis_go_cv_chart_10_2_bp
In this case the module that will manage this chart is identified as 'tripal_analysis_go' and within the [unique id] portion contains the organism_id (e.g. 10), analysis_id (e.g. 2) and chart type (bp = biological process).
Second, the programmer must then define a hook in the controlling module for setting some options used to build the chart. The hook has the form: hook_cv_chart($chart_id). This hook should accept the full $chart_id as the single parameter. For the Tripal Analysis GO module the hook is named: tripal_analysis_go_cv_chart.
The array returned by this hook must have the following fields:
Example from the tripal_analysis_go module:
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"; $analysis = db_fetch_object(chado_query($sql,$analysis_id)); 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; }
$chart_id | The unique identifier for the chart |
With these three components (materialized view, a 'div' box with proper CSS class and ID, and a hook_cv_chart) a chart will be created on the page. There is no need to call this function directly.
Definition at line 128 of file charts.inc.
{ // parse out the tripal module name from the chart_id to find out // which Tripal "hook" to call: $tripal_mod = preg_replace("/^(tripal_.+?)_cv_chart_(.+)$/", "$1", $chart_id); $callback = $tripal_mod . "_cv_chart"; // now call the function in the module responsible for the chart to fill out // an options array needed by the tripal_cv_count_chart call below. $opt = call_user_func_array($callback, array($chart_id)); // build the JSON array to return to the javascript caller $json_arr = tripal_cv_count_chart( $opt['count_mview'], $opt['cvterm_id_column'], $opt['count_column'], $opt['filter'], $opt['title'], $opt['type'], $opt['size'] ); $json_arr[] = $chart_id; // add the chart_id back into the json array return drupal_json($json_arr); }
tripal_cv_count_chart | ( | $ | cnt_table, |
$ | fk_column, | ||
$ | cnt_column, | ||
$ | filter = NULL , |
||
$ | title = '' , |
||
$ | type = 'p3' , |
||
$ | size = '300x75' |
||
) |
This function generates an array with fields compatible with Google charts used for generating pie charts of counts associated with terms in a controlled vocabulary. An example would be counts of features assigned to terms in the Sequence Ontology.
$cnt_table | The name of the table (most likely a materialized view) that contains count data for each term. The table must have at least two columns, one with the cvterm_id for each term, and a second column with the count (i.e. features assigned the term). |
$fk_column | This is the name of the column in the $cnt_table that holds the cvterm_id for each term. |
$cnt_column | The name of the column in the $cnt_table containing the counts |
$filter | An SQL compatible 'where' clause (without the word 'WHERE') used to filter the records in the $cnt_table |
$title | The title of the chart to be rendered. |
$type | The type of chart to be rendered. The value used here is the same as the type names for Google charts. Default is p3 (pie chart). |
$size | The size in pixels of the chart to be rendered. Default is 300x75. The size of the chart is constrained by Google charts. See the Google chart documentation for exact limitations. |
Definition at line 188 of file charts.inc.
{ if (!$type) { $type = 'p3'; } if (!$size) { $size = '300x75'; } if (!$filter) { $filter = '(1=1)'; } $is_pie = 0; if (strcmp($type, 'p') == 0 or strcmp($type, 'p3') == 0) { $is_pie = 1; } $sql = " SELECT CVT.name, CVT.cvterm_id, CNT.$cnt_column as num_items FROM {$cnt_table} CNT INNER JOIN {cvterm} CVT on CNT.$fk_column = CVT.cvterm_id WHERE $filter "; $features = array(); $results = chado_query($sql); $data = array(); $axis = array(); $legend = array(); $total = 0; $max = 0; $i = 1; while ($term = db_fetch_object($results)) { if ($is_pie) { $axis[] = "$term->name (" . number_format($term->num_items) . ")"; $data[] = array($term->num_items, 0, 0); } else { $axis[] = "$term->name (" . number_format($term->num_items) . ")"; $data[] = array($term->num_items); //$legend[] = "$term->name (" . number_format($term->num_items) . ")"; } if ($term->num_items > $max) { $max = $term->num_items; } $total += $term->num_items; $i++; } // convert numerical values into percentages foreach ($data as &$set) { $set[0] = ($set[0] / $total) * 100; } $opt[] = array( data => $data, axis_labels => $axis, legend => $legend, size => $size, type => $type, bar_width => 10, bar_spacing => 0, title => $title ); // $opt[] = $sql; return $opt; }
tripal_cv_cvterm_callback | ( | ) |
Purpose: This function gets called when the selecting of a cv from the select list triggers it. This function simply rebuilds the form with new information. No elements are created here
Definition at line 532 of file tripal_cv_admin.inc.
{ $status = TRUE; // prepare and render the form $form = tripal_core_ahah_prepare_form(); $data = drupal_render($form); // bind javascript events to the new objects that will be returned // so that AHAH enabled elements will work. $settings = tripal_core_ahah_bind_events(); // return the updated JSON drupal_json( array( 'status' => $status, 'data' => $data, 'settings' => $settings, ) ); }
tripal_cv_cvterm_form | ( | &$ | form_state, |
$ | action = 'add' |
||
) |
Purpose: Provides the form that allows adding of terms to an existing controlled vocabulary
Definition at line 246 of file tripal_cv_admin.inc.
{ tripal_core_ahah_init_form(); $form = array(); // get defaults $cv_id = $form_state['values']['cv_id'] ? $form_state['values']['cv_id'] : FALSE; $name = $form_state['values']['name'] ? $form_state['values']['name'] : ''; // if we have a cv_id and a term name then get the rest of the term details if ($cv_id and $name) { $values = array( 'cv_id' => $cv_id, 'name' => $name, ); $results = tripal_core_chado_select('cvterm', array('*'), $values); if (!$results or count($results) == 0) { // we can't find the cvterm so reset the name to blank $name = ''; } else { $cvterm = $results[0]; $definition = $cvterm->definition; $is_relationshiptype = $cvterm->is_relationshiptype; $is_obsolete = $cvterm->is_obsolete; // now get the database $values = array('dbxref_id' => $cvterm->dbxref_id); $results = tripal_core_chado_select('dbxref', array('*'), $values); $dbxref = $results[0]; $accession = $dbxref->accession; $db_id = $dbxref->db_id; } } $values = array(); $columns = array('cv_id', 'name'); $options = array('order_by' => array('name' => 'ASC')); $results = tripal_core_chado_select('cv', $columns, $values, $options); $cvs = array(); $cvs[] = ''; foreach ($results as $cv) { $cvs[$cv->cv_id] = $cv->name; } $form['wrapper-top'] = array( '#type' => 'markup', '#value' => '<div id="cvterm-form">', ); $form['form_action'] = array( '#type' => 'hidden', '#value' => $action, ); $form['cv_id'] = array( '#title' => t('Controlled Vocabulary (Ontology) Name'), '#type' => 'select', '#options' => $cvs, '#required' => TRUE, '#default_value' => $cv_id, '#ahah' => array( 'path' => 'admin/tripal/tripal_cv/cvterm/ahah', 'wrapper' => 'cvterm-form', 'event' => 'change', 'method' => 'replace', ), ); if ($cv_id) { $form['add_cvterm'] = array( '#type' => 'fieldset', '#title' => t('Term Details'), '#prefix' => '<div id="cvterm-add-div">', '#suffix' => '</div>' ); $description = t('Please enter the name for this vocabulary term.'); if ($action == 'edit') { $description = t('Enter the name of the term to edit. This field will update automatically as you type. Click outside of the box after entering the term.'); } $form['add_cvterm']['name']= array( '#type' => 'textfield', '#title' => t("Term Name"), '#description' => $description, '#default_value' => $name, '#required' => TRUE, ); if ($action == 'edit') { if ($name) { $form['add_cvterm']['name']['#attributes'] = array('readonly' => 'readonly'); $form['add_cvterm']['name']['#description'] = 'The term name cannot be changed. If the name is incorrect, please create a new term and make this one as obsolete.'; } else { $form['add_cvterm']['name']['#autocomplete_path'] = "admin/tripal/tripal_cv/cvterm/auto_name/$cv_id"; $form['add_cvterm']['name']['#ahah'] = array( 'path' => 'admin/tripal/tripal_cv/cvterm/ahah', 'wrapper' => 'cvterm-form', 'method' => 'replace', ); } } if ($action == 'add' or $name) { $form['add_cvterm']['definition']= array( '#type' => 'textarea', '#title' => t('Description'), '#description' => t('Please enter a description for this term'), '#default_value' => $definition, ); $form['add_cvterm']['is_relationshiptype'] = array( '#type' => 'checkbox', '#title' => t('This term describes a relationship?'), '#default_value' => $is_relationshiptype, ); $form['add_cvterm']['is_obsolete'] = array( '#type' => 'checkbox', '#title' => t('This term is obsolete?'), '#default_value' => $is_obsolete, ); $values = array(); $columns = array('db_id', 'name'); $options = array('order_by' => array('name' => 'ASC')); $results = tripal_core_chado_select('db', $columns, $values, $options); $dbs = array(); $dbs[] = ''; foreach ($results as $db) { $dbs[$db->db_id] = $db->name; } $form['add_cvterm']['db_id'] = array( '#type' => 'select', '#title' => t('Database'), '#description' => t('All terms must be assocated with an external database. Please select the external database to associate with this term'), '#options' => $dbs, '#default_value' => $db_id, '#required' => TRUE, ); if ($action == 'edit') { // we don't want to allow the user to change the database on an edit. $form['add_cvterm']['db_id']['#disabled'] = TRUE; $form['add_cvterm']['db_id']['#description'] = 'The database to which this term belongs cannot be changed.'; } $form['add_cvterm']['accession']= array( '#type' => 'textfield', '#title' => t("Accession"), '#description' => t('If this term has an existing accession (unique identifier) in the database please enter that here. If the accession is numeric with a database prefix (e.g. GO:003023), please enter just the numeric value. The database prefix will be appended whenever the term is displayed. If the accession is not numeric then enter it as is. If no value is provied, the term name provided above will be used as the accession.'), '#required' => FALSE, '#default_value' => $accession, ); if ($action == 'edit') { $form['add_cvterm']['accession']['#attributes'] = array('readonly' => 'readonly'); $form['add_cvterm']['accession']['#description'] = 'Cannot change the term accession.'; } $button_text = 'Add Term'; if ($action == 'edit') { $button_text = 'Update Term'; } $form['add_cvterm']['submit'] = array( '#type' => 'submit', '#value' => $button_text, ); } // end if name selected (or action == 'add') } //end of if cv selected $form['wrapper-bottom'] = array( '#type' => 'markup', '#value' => '</div>', ); return $form; }
tripal_cv_cvterm_form_submit | ( | $ | form, |
&$ | form_state | ||
) |
Purpose: Adds terms to an existing controlled vocabulary
Definition at line 460 of file tripal_cv_admin.inc.
{ // Ensure the AHAH in the form was called if (!empty($form_state['ahah_submission'])) { return; } // get the database $values = array('db_id' => $form_state['values']['db_id']); $results = tripal_core_chado_select('db', array('name'), $values); if (!$results or count($results) == 0){ drupal_set_message(t('Unable to add term. Cannot find the database.'), 'error'); return; } $db = $results[0]; // get the cv $values = array('cv_id' => $form_state['values']['cv_id']); $results = tripal_core_chado_select('cv', array('name'), $values); if (!$results or count($results) == 0){ drupal_set_message(t('Unable to add term. Cannot find the vocabulary.'), 'error'); return; } $cv = $results[0]; // get the accession for this term $accession = $form_state['values']['accession']; if (!$accession) { $accession = $form_state['values']['name']; } if (is_numeric($accession)) { $accession = $db->name . ":" . $accession; } $update = 0; if ($form_state['values']['form_action'] == 'edit') { $update = 1; } // now add the term $term = array( 'name' => $form_state['values']['name'], 'namespace' => $cv->name, 'id' => $accession, 'def' => $form_state['values']['definition'], 'is_obsolete' => $form_state['values']['is_obsolete'], ); $is_relationship = $form_state['values']['is_relationshiptype']; $cvterm = tripal_cv_add_cvterm($term, $cv->name, $is_relationship, $update, $db->name); if ($cvterm) { if (!$update) { drupal_set_message('Term added successfully.'); } else { drupal_set_message('Term updated successfully.'); } } else { drupal_set_message('Could not add term. Check Drupal recent logs for error messages.', 'error'); } }
tripal_cv_cvterm_form_validate | ( | $ | form, |
&$ | form_state | ||
) |
Purpose: Validates the input for adding a cvterm
Definition at line 446 of file tripal_cv_admin.inc.
{ // Ensure that submit does not get called unless the AHAH in the form was called if (!empty($form_state['ahah_submission'])) { return; } }
tripal_cv_cvterm_info | ( | $ | cvterm_id | ) |
Describe a cvterm (Rendered)
Definition at line 361 of file trees.inc.
{ // get the id of the term to look up $cv = check_plain($_REQUEST['cv']); $tree_id = check_plain($_REQUEST['tree_id']); // first get any additional information to add to the cvterm if (strcmp($tree_id, 'undefined') != 0) { $tripal_mod = preg_replace("/^(tripal_.+?)_cv_tree_(.+)$/", "$1", $tree_id); if ($tripal_mod) { $callback = $tripal_mod . "_cvterm_add"; $opt = call_user_func_array($callback, array($cvterm_id, $tree_id)); } } $sql = " SELECT CVT.name as cvtermname, CVT.definition, CV.name as cvname, DBX.accession,DB.urlprefix,DB.db_id,DB.name as dbname FROM {CVTerm} CVT INNER JOIN CV on CVT.cv_id = CV.cv_id INNER JOIN dbxref DBX on CVT.dbxref_id = DBX.dbxref_id INNER JOIN DB on DBX.db_id = DB.db_id WHERE CVT.cvterm_id = %d "; $cvterm = db_fetch_object(chado_query($sql, $cvterm_id)); $sql = " SELECT CVTS.synonym, CVT.name as cvname FROM {cvtermsynonym} CVTS INNER JOIN cvterm CVT on CVTS.type_id = CVT.cvterm_id WHERE CVTS.cvterm_id = %d "; $results = chado_query($sql, $cvterm_id); while ($synonym = db_fetch_object($results)) { $synonym_rows .= "<b>$synonym->cvname:</b> $synonym->synonym<br />"; } $accession = $cvterm->accession; if ($cvterm->urlprefix) { $accession = "<a href=\"$cvterm->urlprefix$cvterm->accession\">$cvterm->accession</a>"; } $content = " <div id=\"cvterm\"> <table> <tr><th>Term</th><td>$cvterm->cvtermname</td></tr> <tr><th>Accession</th><td>$accession</td></tr> <tr><th>Ontology</th><td>$cvterm->cvname</td></tr> <tr><th>Definition</th><td>$cvterm->definition</td></tr> <tr><th>Synonyms</th><td>$synonym_rows</td></tr> <tr><th>Internal ID</th><td>$cvterm_id</td></tr> "; // now add in any additional options from a hook if ($opt) { foreach ($opt as $key => $value) { $content .= "<tr><th>$key</th><td>$value</td>"; } } // close out the information table $content .= " </table> </div> "; drupal_json(array('update' => $content)); }
tripal_cv_cvtermpath_form | ( | ) |
Form for re-doing the cvterm path
Definition at line 141 of file obo_loader.inc.
{ // get a list of db from chado for user to choose $sql = "SELECT * FROM {cv} WHERE NOT name = 'tripal' ORDER BY name "; $results = chado_query($sql); $cvs = array(); $cvs[] = ''; while ($cv = db_fetch_object($results)) { $cvs[$cv->cv_id] = $cv->name; } $form['cvid'] = array( '#title' => t('Controlled Vocabulary/Ontology Name'), '#type' => 'select', '#options' => $cvs, '#description' => t('The Chado cvtermpath is a database table that provides lineage for ontology terms and is useful for quickly finding any ancestor parent of a term. This table must be populated for each ontology. Select a controlled vocabulary for which you would like to upate the cvtermpath.'), ); $form['description'] = array( '#type' => 'item', '#value' => t("Submit a job to update chado cvtermpath table."), '#weight' => 1, ); $form['button'] = array( '#type' => 'submit', '#value' => t('Update cvtermpath'), '#weight' => 2, ); return $form; }
tripal_cv_cvtermpath_form_submit | ( | $ | form, |
&$ | form_state | ||
) |
Cvterm path form submit
Definition at line 558 of file tripal_cv_admin.inc.
{ global $user; $cvid = $form_state['values']['cvid']; // first get the controlled vocabulary name: $cv = db_fetch_object(chado_query("SELECT * FROM {cv} WHERE cv_id = %d", $cvid)); // Submit a job to update cvtermpath $job_args = array($cvid); if ($form_state['values']['op'] == t('Update cvtermpath')) { tripal_add_job("Update cvtermpath: $cv->name", 'tripal_cv', 'tripal_cv_update_cvtermpath', $job_args, $user->uid); } }
tripal_cv_edit_form | ( | &$ | form_state = NULL , |
$ | cvid = NULL |
||
) |
Purpose: Provides a form to allow updating/deleteing of controlled vocabularies
Definition at line 69 of file tripal_cv_admin.inc.
{ $sql = "SELECT * FROM {cv} WHERE cv_id = %d "; $cv = db_fetch_object(chado_query($sql, $cvid)); // set the default values. If there is a value set in the // form_state then let's use that, otherwise, we'll pull // the values from the database $default_db = $form_state['values']['name']; $default_desc = $form_state['values']['description']; $default_url = $form_state['values']['url']; $default_urlprefix = $form_state['values']['urlprefix']; if (!$default_db) { $default_cv = $cv->name; } if (!$default_desc) { $default_desc = $cv->definition; } $form['cvid'] = array( '#type' => 'hidden', '#value' => $cvid ); $form['name']= array( '#type' => 'textfield', '#title' => t("Controlled Vocabulary name"), '#description' => t('Please enter the name for this vocabulary.'), '#required' => FALSE, '#default_value' => $default_cv, '#weight' => 1 ); $form['definition']= array( '#type' => 'textarea', '#title' => t('Description'), '#description' => t('Please enter a description for this vocabulary'), '#default_value' => $default_desc, '#weight' => 2 ); $form['update'] = array( '#type' => 'submit', '#value' => t('Update'), '#weight' => 5, '#executes_submit_callback' => TRUE, ); $form['delete'] = array( '#type' => 'submit', '#value' => t('Delete'), '#weight' => 6, '#executes_submit_callback' => TRUE, ); $form['#redirect'] = 'admin/tripal/tripal_cv'; return $form; }
tripal_cv_edit_form_submit | ( | $ | form, |
&$ | form_state | ||
) |
Purpose: The submit function of the update/delete controlled vocabulary form
Definition at line 134 of file tripal_cv_admin.inc.
{ $name = $form_state['values']['name']; $desc = $form_state['values']['definition']; $cvid = $form_state['values']['cvid']; $op = $form_state['values']['op']; if (strcmp($op, 'Update') == 0) { $sql = " UPDATE {cv} SET name = '%s', definition = '%s' WHERE cv_id = %d "; $db = chado_query($sql, $name, $desc, $cvid); if ($db) { drupal_set_message(t("Controlled vocabulary updated")); } else { drupal_set_message(t("Failed to update controlled vocabulary."), 'error'); } } if (strcmp($op, 'Delete')==0) { $sql = " DELETE FROM {cv} WHERE cv_id = %d "; $db = chado_query($sql, $cvid); if ($db) { drupal_set_message(t("Controlled vocabulary deleted")); } else { drupal_set_message(t("Failed to delete controlled vocabulary."), 'error'); } } }
tripal_cv_edit_page | ( | ) |
Purpose: Provides the form for Updating and Deleteing existing chado controlled vocabularies (See chado cv table)
Definition at line 8 of file tripal_cv_admin.inc.
{ $output .= drupal_get_form('tripal_cv_select_form'); $output .= '<div id="db-edit-div">Please select a vocabulary above to view or edit</div>'; return $output; }
tripal_cv_get_custom_tables | ( | $ | table = NULL | ) |
This function defines the custom tables that will be created in the chado schema.
Definition at line 681 of file tripal_cv.api.inc.
{ if (!$table or strcmp($table, 'tripal_obo_temp')==0) { $schema['tripal_obo_temp'] = array( 'table' => 'tripal_obo_temp', 'fields' => array( 'id' => array( 'type' => 'varchar', 'length' => '255', 'not null' => TRUE, ), 'stanza' => array( 'type' => 'text', 'not null' => TRUE, ), 'type' => array( 'type' => 'varchar', 'length' => '50', 'not null' => TRUE, ), ), 'indexes' => array( 'tripal_obo_temp_idx0' => array('id'), 'tripal_obo_temp_idx0' => array('type'), ), 'unique keys' => array( 'tripal_obo_temp_uq0' => array('id'), ), ); } return $schema; }
tripal_cv_init | ( | ) |
Implements hook_init(). Adds CSS and JS needed for this modules rendered content
Definition at line 20 of file tripal_cv.module.
{ // add the tripal_cv JS and CSS drupal_add_css(drupal_get_path('theme', 'tripal') . '/css/tripal_cv.css'); drupal_add_js(drupal_get_path('theme', 'tripal') . '/js/tripal_cv.js'); // add the jgCharts.js drupal_add_js(drupal_get_path('theme', 'tripal') . '/js/jgcharts/jgcharts.js'); // add the jsTree JS and CSS drupal_add_css(drupal_get_path('theme', 'tripal') . '/js/jsTree/source/tree_component.css'); drupal_add_js(drupal_get_path('theme', 'tripal') . '/js/jsTree/source/_lib.js'); drupal_add_js(drupal_get_path('theme', 'tripal') . '/js/jsTree/source/tree_component.js'); }
tripal_cv_init_browser | ( | $ | cv_id | ) |
Definition at line 335 of file trees.inc.
{ $content = " <div id=\"tripal_cv_cvterm_info_box\"> <a href=\"#\" onclick=\"$('#tripal_cv_cvterm_info_box').hide()\" style=\"float: right\">Close [X]</a> <h3>Term Information</h3> <div id=\"tripal_cv_cvterm_info\"></div> </div> <div id=\"tripal_ajaxLoading\" style=\"display:none\"> <div id=\"loadingText\">Loading...</div> <img src=\"$url\"> </div> <h3>Tree Browser</h3> <div id=\"browser\"</div> </div> "; drupal_json(array('update' => "$content")); }
tripal_cv_init_tree | ( | $ | cv_id, |
$ | cnt_table = NULL , |
||
$ | fk_column = NULL , |
||
$ | cnt_column = NULL , |
||
$ | filter = NULL , |
||
$ | label = NULL |
||
) |
Generates JSON needed for jsTree Root-level Branches
This function returns the JSON array for the jsTree jQuery code that builds a tree for browsing the ontology. This function should be called to generate the root level branches of the tree.
Definition at line 187 of file trees.inc.
{ // get the list of root terms for the provided CV $sql = " SELECT * FROM {cv_root_mview} CRM WHERE cv_id = %d "; $results = chado_query($sql, $cv_id); // prepare the SQL statement that will allow us to pull out count // information for each term in the tree. if ($cnt_table) { if (!$filter) { $filter = '(1=1)'; } $cnt_sql = " SELECT CVT.name, CVT.cvterm_id, CNT.$cnt_column as num_items FROM {$cnt_table} CNT INNER JOIN cvterm CVT on CNT.$fk_column = CVT.cvterm_id WHERE $filter AND CVT.cvterm_id = %d ORDER BY $cnt_column desc "; } while ($term = db_fetch_object($results)) { $name = $term->name; $count = 0; if ($cnt_table) { $cnt_results = chado_query($cnt_sql, $term->cvterm_id); while ($cnt = db_fetch_object($cnt_results)) { $count += $cnt->cnt; } if ($count > 0) { $name .= " ($count $label(s))"; } } $content[] = array( 'attributes' => array( 'id' => $term->cvterm_id, ), 'state' => 'closed', 'data' => $name, 'children' => array(), ); } return $content; }
tripal_cv_list_form | ( | $ | form_state | ) |
Form listing CVs
Definition at line 435 of file trees.inc.
{ // get a list of db from chado for user to choose $sql = " SELECT DISTINCT CV.name,CV.cv_id FROM {cvterm_relationship} CVTR INNER JOIN cvterm CVT on CVTR.object_id = CVT.cvterm_id INNER JOIN CV on CV.cv_id = CVT.cv_id "; $results = chado_query($sql); $blastdbs = array(); $cvs[''] = ''; while ($cv = db_fetch_object($results)) { $cvs[$cv->cv_id] = $cv->name; } $form['db_options'] = array( '#type' => 'value', '#value' => $cvs ); $form['cv_list'] = array( '#title' => t('CVs with relationships'), '#type' => 'select', '#description' => t('Choose the controlled vocabulary to browse'), '#options' => $form['db_options']['#value'], '#attributes' => array( 'onChange' => "return tripal_cv_init_browser(this)", ) ); return $form; }
tripal_cv_menu | ( | ) |
Implements hook_menu(). Registers all menu items associated with this module
Definition at line 41 of file tripal_cv.module.
{ $items = array(); $items['admin/tripal/tripal_cv'] = array( 'title' => 'Vocabularies', 'description' => 'Basic Description of Tripal CV Module Functionality', 'page callback' => 'theme', 'page arguments' => array('tripal_cv_admin'), 'access arguments' => array('administer controlled vocabularies'), 'type' => MENU_NORMAL_ITEM, ); $items['admin/tripal/tripal_cv/obo_loader'] = array( 'title' => 'Load Ontology', 'page callback' => 'drupal_get_form', 'page arguments' => array('tripal_cv_obo_form'), 'access arguments' => array('administer controlled vocabularies'), 'type' => MENU_NORMAL_ITEM, ); $items['admin/tripal/tripal_cv/cvtermpath'] = array( 'title' => 'Update Chado cvtermpath table', 'description' => 'The Chado cvtermpath table provides lineage for terms and is useful for quickly finding any ancestor parent of a term. However, this table must be populated. This page allows for populating of this table one vocabulary at a time', 'page callback' => 'drupal_get_form', 'page arguments' => array('tripal_cv_cvtermpath_form'), 'access arguments' => array('administer controlled vocabularies'), 'type' => MENU_NORMAL_ITEM, ); /* * Menu items for adding and editing CVs */ $items['admin/tripal/tripal_cv/cv/add'] = array( 'title' => 'Add a Vocabulary', 'page callback' => 'drupal_get_form', 'page arguments' => array('tripal_cv_add_form'), 'access arguments' => array('administer controlled vocabularies'), 'type' => MENU_NORMAL_ITEM, ); $items['admin/tripal/tripal_cv/cv/edit'] = array( 'title' => 'Edit a Vocabulary', 'description' => 'Edit a controlled vocabularies/ontolgoies in Chado ', 'page callback' => 'tripal_cv_edit_page', 'access arguments' => array('administer controlled vocabularies'), 'type' => MENU_NORMAL_ITEM, ); $items['admin/tripal/tripal_cv/cv/edit/js'] = array( 'page callback' => 'tripal_ajax_cv_edit', 'access arguments' => array('administer controlled vocabularies'), 'type' => MENU_CALLBACK, ); /* * Menu items for adding and editing CV terms */ $items['admin/tripal/tripal_cv/cvterm/add'] = array( 'title' => 'Add a Term', 'description' => 'Manage controlled vocabulary/ontology terms in Chado ', 'page callback' => 'drupal_get_form', 'page arguments' => array('tripal_cv_cvterm_form', 'add'), 'access arguments' => array('administer controlled vocabularies'), 'type' => MENU_NORMAL_ITEM, ); $items['admin/tripal/tripal_cv/cvterm/ahah'] = array( 'page callback' => 'tripal_cv_cvterm_callback', 'access arguments' => array('administer controlled vocabularies'), 'type' => MENU_CALLBACK, ); $items['admin/tripal/tripal_cv/cvterm/auto_name/%/%'] = array( 'page callback' => 'tripal_cv_cvterm_name_autocomplete', 'page arguments' => array(5, 6), 'access arguments' => array('administer controlled vocabularies'), 'type' => MENU_CALLBACK, ); $items['admin/tripal/tripal_cv/cvterm/edit'] = array( 'title' => 'Edit a Term', 'description' => 'Edit an existing controlled vocabulary/ontology terms in Chado ', 'page callback' => 'drupal_get_form', 'page arguments' => array('tripal_cv_cvterm_form', 'edit'), 'access arguments' => array('administer controlled vocabularies'), 'type' => MENU_NORMAL_ITEM, ); /* * Charts */ $items['tripal_cv_chart'] = array( 'path' => 'tripal_cv_chart', 'page callback' => 'tripal_cv_chart', 'page arguments' => array(1), 'access arguments' => array('access content'), 'type' => MENU_CALLBACK ); /* * Menu items for working with CV Trees */ $items['cv_browser'] = array( 'page callback' => 'tripal_cv_show_browser', 'access arguments' => array('access content'), 'type' => MENU_CALLBACK ); $items['tripal_cv_tree'] = array( 'path' => 'tripal_cv_tree', 'page callback' => 'tripal_cv_tree', 'page arguments' => array(1), 'access arguments' => array('access content'), 'type' => MENU_CALLBACK ); $items['tripal_cv_init_browser'] = array( 'path' => 'tripal_cv_init_browser', 'page callback' => 'tripal_cv_init_browser', 'page arguments' => array(1), 'access arguments' => array('access content'), 'type' => MENU_CALLBACK ); // menu item for interaction with the tree $items['tripal_cv_update_tree'] = array( 'path' => 'tripal_cv_update_tree', 'page callback' => 'tripal_cv_update_tree', 'page arguments' => array(2, 3), 'access arguments' => array('access content'), 'type' => MENU_CALLBACK ); // menu items for working with terms $items['tripal_cv_cvterm_info'] = array( 'path' => 'tripal_cv_cvterm_info', 'title' => 'CV Term Viewer', 'page callback' => 'tripal_cv_cvterm_info', 'page arguments' => array(1), 'access arguments' => array('access content'), 'type' => MENU_CALLBACK ); return $items; }
tripal_cv_perm | ( | ) |
Set the permission types that the chado module uses. Essentially we want permissionis that protect creation, editing and deleting of chado data objects
Definition at line 194 of file tripal_cv.module.
{ return array( 'administer controlled vocabularies', ); }
tripal_cv_select_form | ( | ) |
Purpose: Provides the actual "Select CV" form on the Update/Delete Controlled Vocabulary page. This form also triggers the edit javascript
Definition at line 22 of file tripal_cv_admin.inc.
{ // get a list of db from chado for user to choose $sql = "SELECT * FROM {cv} WHERE NOT name = 'tripal' ORDER BY name "; $results = chado_query($sql); $cvs = array(); $cvs[] = ''; while ($cv = db_fetch_object($results)) { $cvs[$cv->cv_id] = $cv->name; } $form['cvid'] = array( '#title' => t('Controlled Vocabulary/Ontology Name'), '#type' => 'select', '#options' => $cvs, '#ahah' => array( 'path' => 'admin/tripal/tripal_cv/cv/edit/js', 'wrapper' => 'db-edit-div', 'effect' => 'fade', 'event' => 'change', 'method' => 'replace', ), ); return $form; }
tripal_cv_show_browser | ( | ) |
tripal_cv_tree | ( | $ | tree_id | ) |
Generates JSON used for generating an exapandable tree of terms from a controlled vocabulary that has associated counts.
The progammer must first create a materialized view that will generate count data for a given controlled vocabulary. For example, the Tripal Analysis GO creates a materialized view for counting Gene Ontology assignments to features. This view is created on install of the module and is named 'go_count_analysis'.
Second, the progammer must add an HTML 'div' box to the desired page with a class name of 'tripal_cv_tree', and an id of the following format:
tripal_[module_name]_cv_tree_[unique id]
where [module_name] is the name of the tripal module (e.g. tripal_analyisis_go) and [unique id] is some unique identifier that the contolling module recognizes. This string is the $tree_id variable passed as the first argument to the function. For example, the Tripal GO Analysis module generates tree ids of the form:
tripal_analysis_go_cv_tree_10_2_bp
In this case the module that will manage this tree is identified as 'tripal_analysis_go' and within the [unique id] portion contains the organism_id (e.g. 10), analysis_id (e.g. 2) and tree type (bp = biological process).
Second, the programmer must then define a hook in the controlling module for setting some options used to build the chart. The hook has the form: hook_cv_tree($tree_id). This hook should accept the full $tree_id as the single parameter. For the Tripal Analysis GO module the hook is named: tripal_analysis_go_cv_tree.
The array returned by this hook must have the following fields:
Example from the tripal_analysis_go module:
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; }
$tree_id | The unique identifier for the tree |
With these three components (materialized view, a 'div' box with proper CSS class and ID, and a hook_cv_tree) a tree will be created on the page. There is no need to call this function directly.
Definition at line 118 of file trees.inc.
{ // parse out the tripal module name from the chart_id to find out // which Tripal "hook" to call: $tripal_mod = preg_replace("/^(tripal_.+?)_cv_tree_(.+)$/", "$1", $tree_id); if ($tripal_mod) { $callback = $tripal_mod . "_cv_tree"; // now call the function in the module responsible for the tree. This // should call the tripal_cv_init_cv with the proper parameters set for // getting the cv_id of the vocabulary to use $opt = call_user_func_array($callback, array($tree_id)); // we only need to return the cv_id for this function call. $json_array[] = $opt['cv_id']; } $json_array[] = $tree_id; return drupal_json($json_array); }
tripal_cv_update_tree | ( | ) |
Definition at line 143 of file trees.inc.
{ $content = array(); $ontology = 'sequence'; // get the id of the term to look up $cv = check_plain($_REQUEST['cv']); $term = check_plain($_REQUEST['term']); $tree_id = check_plain($_REQUEST['tree_id']); // get the options needed for this tree from the tripal module that // wants to create the tree $tripal_mod = preg_replace("/^(tripal_.+?)_cv_tree_(.+)$/", "$1", $tree_id); if ($tripal_mod) { $callback = $tripal_mod . "_cv_tree"; $opt = call_user_func_array($callback, array($tree_id)); } // get the CV root terms if (strcmp($term, 'root')==0) { if (!$cv) { $cv = $opt['cv_id']; } $content = tripal_cv_init_tree($cv, $opt['count_mview'], $opt['cvterm_id_column'], $opt['count_column'], $opt['filter'], $opt['label']); // get the children terms } else { $content = tripal_cv_get_term_children($term, $opt['count_mview'], $opt['cvterm_id_column'], $opt['count_column'], $opt['filter'], $opt['label']); } drupal_json($content); }
tripal_cv_views_api | ( | ) |
Implements hook_views_api() Purpose: Essentially this hook tells drupal that there is views support for for this module which then includes tripal_cv.views.inc where all the views integration code is
Definition at line 208 of file tripal_cv.module.
{ return array('api' => 2.0); }