123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909 |
- <?php
- require_once "includes/parse_blast_XML.inc";
- /*******************************************************************************
- * Tripal Blast Result lets users show/hide blast results associated
- * with a tripal feature
- ******************************************************************************/
- function tripal_analysis_blast_init(){
- // Add javascript and style sheet
- drupal_add_css(drupal_get_path('module', 'tripal_analysis_blast') .'/theme/css/tripal_analysis_blast.css');
- drupal_add_js(drupal_get_path('module', 'tripal_analysis_blast') .'/theme/js/tripal_analysis_blast.js');
- }
- /*******************************************************************************
- * tripal_analysis_blast_menu()
- * HOOK: Implementation of hook_menu()
- * Entry points and paths of the module
- */
- function tripal_analysis_blast_menu() {
- // Show top 10/25/all blast results for ajax calls
- $items['tripal_top_blast'] = array(
- 'path' => 'top_blast',
- 'title' => t('Blast Hits'),
- 'page callback' => 'tripal_get_feature_blast_results_ajax',
- 'page arguments' => array(1,2,3),
- 'access arguments' => array('access content'),
- 'type' => MENU_CALLBACK
- );
- // Show regular expressions for selected database in Blast admin page
- $items['admin/tripal/tripal_analysis/tripal_blast_regex/%'] = array(
- 'title' => t('Blast Regex'),
- 'page callback' => 'tripal_get_blast_regex',
- 'page arguments' => array(4),
- 'access arguments' => array('administer site configuration'),
- 'type' => MENU_CALLBACK
- );
- $items['tripal_blast_report'] = array(
- 'title' => t('Homology Report'),
- 'page callback' => 'tripal_get_blast_report',
- 'page arguments' => array(1,2,3,4,5),
- 'access arguments' => array('access chado_analysis_blast content'),
- 'type' => MENU_CALLBACK,
- 'file' => 'tripal_analysis_blast_htmlreport.inc'
- );
-
- return $items;
- }
- /**
- *
- *
- * @ingroup tripal_analysis_blast
- */
- function tripal_analysis_blast_block($op = 'list', $delta = 0, $edit=array()){
- switch($op) {
- case 'list':
- $blocks['blast_base']['info'] = t('Analysis: Blast Details');
- $blocks['blast_base']['cache'] = BLOCK_NO_CACHE;
- $blocks['featureblast']['info'] = t('Tripal Feature Blast Results');
- $blocks['featureblast']['cache'] = BLOCK_NO_CACHE;
-
- return $blocks;
- case 'view':
- if(user_access('access chado_analysis_blast content') and arg(0) == 'node' and is_numeric(arg(1))) {
- $nid = arg(1);
- $node = node_load($nid);
-
- $block = array();
- switch($delta){
- case 'blast_base':
- $block['subject'] = t('Blast Details');
- $block['content'] = theme('tripal_analysis_blast_base',$node);
- break;
- case 'featureblast':
- $block['subject'] = t('Homology');
- $block['content'] = theme('tripal_feature_blast_results',$node);
- break;
- default :
- }
- return $block;
- }
- }
- }
- /*******************************************************************************
- * tripal_analysis_blast_nodeapi()
- * HOOK: Implementation of hook_nodeapi()
- * Display blast results for allowed node types
- */
- function tripal_analysis_blast_nodeapi(&$node, $op, $teaser, $page) {
- switch ($op) {
- case 'view':
- if($teaser){
- return '';
- }
- // Find out which node types for showing the blast
- $types_to_show = variable_get('tripal_analysis_blast_setting',
- array('chado_feature'));
- // Abort if this node is not one of the types we should show.
- if (!in_array($node->type, $types_to_show, TRUE)) {
- break;
- }
- if(strcmp($node->type,'chado_feature')==0){
- if($node->build_mode == NODE_BUILD_SEARCH_INDEX){
- $node->content['tripal_analysis_blast_index_version'] = array(
- '#value' => theme('tripal_analysis_blast_results_index_version',$node),
- '#weight' => 8,
- );
- } else {
- // Show blast result if not at teaser view
- $node->content['tripal_feature_blast_results'] = array(
- '#value' => theme('tripal_feature_blast_results', $node),
- '#weight' => 8
- );
- }
- }
- break;
- }
- }
- /**
- * Implements hook_theme_registry_alter().
- */
- function tripal_analysis_blast_theme_registry_alter(&$info) {
- // Inject our module into the node theme registry as being an available theme
- // path so that we can override the node template for our content type.
- array_splice($info['node']['theme paths'], 1, 0, array(drupal_get_path('module', 'tripal_analysis_blast')));
- }
- /************************************************************************
- * 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_blast_theme () {
- $path = drupal_get_path('module', 'tripal_analysis_blast') . '/theme';
- $theme = array(
- 'tripal_analysis_blast_results_index_version' => array (
- 'arguments' => array('node'),
- ),
- 'tripal_feature_blast_results' => array(
- 'template' => 'tripal_feature_blast_results',
- 'arguments' => array('node'=> null),
- 'path' => $path . '/tripal_feature',
- ),
- 'tripal_analysis_blast_report' => array(
- 'template' => 'tripal_analysis_blast_report',
- 'arguments' => array('report_object'=> null),
- 'path' => $path . '/tripal_analysis_blast',
- ),
- 'tripal_analysis_blast_base' => array(
- 'template' => 'tripal_analysis_blast_base',
- 'arguments' => array('report_object'=> null),
- 'path' => $path . '/tripal_analysis_blast',
- )
- );
- return $theme;
- }
- /*******************************************************************************
- *
- */
- function tripal_get_feature_blast_results_ajax($feature_id, $db_id, $max){
- $sql = "SELECT nid FROM {chado_feature} WHERE feature_id = %d";
- $nid = db_fetch_object(db_query($sql,$feature_id));
- $node = node_load($nid->nid);
- // add the additional variables that the theme needs to generate the output
- $node->db_id = $db_id;
- $node->max = $max;
- // call the theme to rebuild the blast results
- drupal_json(array('update' => theme('tripal_feature_blast_results',$node)));
- }
- /*******************************************************************************
- *
- */
- function tripal_analysis_blast_preprocess_tripal_feature_blast_results(&$variables){
- $feature = $variables['node']->feature;
- $db_id = $variables['node']->db_id; // this value only gets set on an ajax call
-
- $max = 10;
- if(isset($variables['node']->max)){
- $max = $variables['node']->max;
- }
- $blast_results = tripal_get_feature_blast_results($feature->feature_id, $db_id, $max);
- $feature->tripal_analysis_blast->blast_results_list = $blast_results;
-
-
- }
- /*******************************************************************************
- * Prepare blast result for the feature shown on the page
- */
- function theme_tripal_analysis_blast_results_index_version ($node) {
- $feature = $node->feature;
- $content = tripal_get_blast_results_index_version($feature->feature_id);
- return $content;
- }
- /*******************************************************************************
- * tripal_get_feature_blast_results()
- * Get blast result from featureprop table for the feature
- */
- function tripal_get_feature_blast_results($feature_id, $db_id, $max){
- // Get the blast results stored as XML from the analysisfeatureprop table
- // the type for the property is named 'analysis_blast_output_iteration_hits'
- // and is found in the 'tripal' controlled vocabulary. This CV term was
- // added by this module.
- $select = array(
- 'analysisfeature_id' => array(
- 'feature_id' => $feature_id,
- ),
- 'type_id' => array(
- 'name' => 'analysis_blast_output_iteration_hits',
- 'cv_id' => array(
- 'name' => 'tripal'
- ),
- ),
- );
- $blast_results = tripal_core_chado_select('analysisfeatureprop',array('*'),$select);
- if (!$blast_results){
- return;
- }
- // get the HTML content for viewing each of the XML file
- $blast_obj_array = array ();
- $blast_obj_counter = 0;
- foreach ($blast_results as $index => $analysisfeatureprop) {
- // get the blast XML for this feature
- $blast_xml = $analysisfeatureprop->value;
- // get the analysis record
- $analysisfeature_arr = tripal_core_chado_select('analysisfeature',array('analysis_id'),
- array('analysisfeature_id' => $analysisfeatureprop->analysisfeature_id));
- $analysis_arr = tripal_core_chado_select('analysis',array('*'),
- array('analysis_id' => $analysisfeature_arr[0]->analysis_id));
- $analysis = $analysis_arr[0];
- $analysis_id = $analysis->analysis_id;
- // the old style was to store all parameters in a single CV term in the analysisprop
- // table. However now each property has it's own CV term in that table. But,
- // we still need to support the old method for backwards compatibility.
- // so, first get the old style variable and see if it has values. In
- // particular we need the database setting
- $blast_settings = tripal_analysis_get_property($analysis_id,'analysis_blast_settings');
- if($blast_settings){
- $blastsettings = explode("|", $blast_settings->value);
- // if we don't have the proper number of fields in the value column then
- // skip this entry
- if(count($blastsettings) != 3){
- continue;
- }
- $adb_id = $blastsettings[0];
- }
- // if we're not using the old style then try the new method to get the
- // database id
- else {
- $blastdb = tripal_analysis_get_property($analysis_id,'analysis_blast_blastdb');
- $adb_id = $blastdb->value;
- }
- // if the callee specified a database to show then we want to check that
- // with the database id of the analysis we're looking at. If they
- // don't match then skip this blast. If a database id was not specified
- // then continue
- if($db_id and $adb_id != $db_id){
- continue;
- }
- // get the database
- if($adb_id){
- $db_arr = tripal_core_chado_select('db',array('*'),array('db_id' => $adb_id));
- $db = $db_arr[0];
- }
- // parse the XML and add it to the array of blast results to be returned
- $blast_obj = tripal_analysis_blast_get_result_object($blast_xml,$db,$max,$feature_id, $analysis);
- $blast_obj->analysis = $analysis;
- $blast_obj_array [$blast_obj_counter] = $blast_obj;
- $blast_obj_counter ++;
- }
- return $blast_obj_array;
- }
- /*******************************************************************************
- * Scanning the file folder for blast results and prepare content for indexing
- */
- function tripal_get_blast_results_index_version ($feature_id){
- // Get cvterm_id for 'analysis_blast_output_iteration_hits' which is required
- // for inserting into the analysisfeatureprop table
- $previous_db = tripal_db_set_active('chado');
- $sql = "SELECT CVT.cvterm_id FROM {cvterm} CVT ".
- "INNER JOIN cv ON cv.cv_id = CVT.cv_id ".
- "WHERE CVT.name = 'analysis_blast_output_iteration_hits' ".
- "AND CV.name = 'tripal'";
- $type_id = db_result(db_query($sql));
- // Get xml string from analysisfeatureprop value column, get db_id from analysisprop value column
- // , and get analysis_id from analysisfeature table
- $sql = "SELECT AP.value AS apvalue, AFP.value AS afpvalue, AF.analysis_id AS aid
- FROM {analysisfeatureprop} AFP
- INNER JOIN analysisfeature AF ON AF.analysisfeature_id = AFP.analysisfeature_id
- INNER JOIN analysisprop AP ON AP.analysis_id = AF.analysis_id
- WHERE feature_id = %d
- AND AFP.type_id = %d ";
- $result = db_query($sql, $feature_id, $type_id);
- tripal_db_set_active($previous_db);
- // get the HTML content for viewing each of the XML file
- while ($analysisfeatureprop = db_fetch_object($result)) {
- // get analysis name and date
- $previous_db = tripal_db_set_active('chado');
- $sql = "SELECT analysis_id AS aid, name, to_char(timeexecuted, 'MM-DD-YYYY') AS time
- FROM {analysis} WHERE analysis_id = %d";
- $analysis = db_fetch_object(db_query($sql, $analysisfeatureprop->aid));
- tripal_db_set_active($previous_db);
- $blastsettings = explode("|", $analysisfeatureprop->apvalue);
- $att_db_id = $blastsettings [0];
- // Get db object using the db_id
- $previous_db = tripal_db_set_active('chado');
- $sql = "SELECT * FROM {db} WHERE db_id=%d";
- $db = db_fetch_object(db_query($sql, $att_db_id));
- tripal_db_set_active($previous_db);
- // Only index best 10 hits because the default page only shows 10 blast results
- $max = 10;
- $content .= parse_NCBI_Blast_XML_index_version($analysisfeatureprop->afpvalue,$db,$max,$feature_id,$ajax, $analysis);
-
- }
- return $content;
- }
- /*******************************************************************************
- * Tripal Blast 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_blast_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 blast results
- $allowedoptions ['chado_feature'] = "Show blast results on feature pages";
- $form['description'] = array(
- '#type' => 'item',
- '#value' => t("Most chado features were analyzed by blast against major sequence databases. This option allows user to display the blast analysis results. Please read user manual for storage and display of blast files. Check the box to enable the analysis results. Uncheck to disable it."),
- '#weight' => 0,
- );
- $form['tripal_analysis_blast_setting'] = array(
- '#type' => 'checkboxes',
- '#options' => $allowedoptions,
- '#default_value' => variable_get('tripal_analysis_blast_setting',
- array('chado_feature')),
- );
- $form['blast_parser'] = array(
- '#title' => t('Blast Parser Settings'),
- '#type' => 'fieldset',
- '#description' => t('Configure parsers for showing blast results. Each database is '.
- 'allowed to have one xml parser.'),
- '#weight' => 10
- );
- $previous_db = tripal_db_set_active('chado'); // use chado database
- // get a list of db from chado for user to choose
- $sql = 'SELECT db_id, name FROM {db} ORDER BY lower(name)';
- $results = db_query ($sql);
- $blastdbs = array();
- while ($db = db_fetch_object($results)){
- $blastdbs[$db->db_id] = $db->name;
- }
- $form['db_options'] = array(
- '#type' => 'value',
- '#value' => $blastdbs
- );
- $form['blast_parser']['blastdb'] = array(
- '#title' => t('Database'),
- '#type' => 'select',
- '#description' => t('The database used for the blast analysis.'),
- '#options' => $form['db_options']['#value'],
- '#attributes' => array(
- 'onChange' => "return tripal_update_regex(this)",
- )
- );
- $form['blast_parser']['displayname'] = array(
- '#title' => t('Title for the blast analysis'),
- '#type' => 'textfield',
- );
- $form['blast_parser']['gb_style_parser'] = array(
- '#title' => t('Use Genebank style parser. This will clear all regular expression settings for the selected database.'),
- '#type' => 'checkbox',
- '#attributes' => array(
- 'onClick' => "return tripal_set_genbank_style(this)",
- )
- );
- $form['blast_parser']['hit_id'] = array(
- '#title' => t('Regular expression for Hit Name'),
- '#type' => 'textfield',
- );
- $form['blast_parser']['hit_def'] = array(
- '#title' => t('Regular expression for Hit Description'),
- '#type' => 'textfield',
- );
- $form['blast_parser']['hit_accession'] = array(
- '#title' => t('Regular expression for Hit Accession'),
- '#type' => 'textfield',
- );
- $form['blast_parser']['button'] = array(
- '#type' => 'submit',
- '#value' => t('Save settings')
- );
- tripal_db_set_active($previous_db); // use drupal database
- $settings->form = $form;
- $settings->title = "Tripal Blast";
- return $settings;
- }
- /*******************************************************************************
- * This function is only called by ajax to get regular expressions for blast
- * admin page
- */
- function tripal_get_blast_regex ($db_id) {
- $sql = "SELECT * FROM {tripal_analysis_blast} WHERE db_id = %d";
- $blast_regexs = db_fetch_object(db_query($sql, $db_id));
- drupal_json(array(
- 'name' => $blast_regexs->displayname,
- 'genbank_style' => $blast_regexs->genbank_style,
- 'reg1' => $blast_regexs->regex_hit_id,
- 'reg2' => $blast_regexs->regex_hit_def,
- 'reg3' => $blast_regexs->regex_hit_accession)
- );
- }
- /*******************************************************************************
- * Provide information to drupal about the node types that we're creating
- * in this module
- */
- function tripal_analysis_blast_node_info() {
- $nodes = array();
- $nodes['chado_analysis_blast'] = array(
- 'name' => t('Analysis: Blast'),
- 'module' => 'chado_analysis_blast',
- 'description' => t('A blast analysis from the chado database'),
- 'has_title' => FALSE,
- 'title_label' => t('Analysis: Blast'),
- 'has_body' => FALSE,
- 'body_label' => t('Blast Analysis Description'),
- 'locked' => TRUE
- );
- return $nodes;
- }
- /*******************************************************************************
- * Provide a Blast Analysis form
- */
- function chado_analysis_blast_form ($node){
- // add in the default fields
- $form = chado_analysis_form($node);
- // set the default values
- $blast = $node->analysis->tripal_analysis_blast;
- $blastdb = $blast->blastdb;
- $blastfile = $blast->blastfile;
- $blastfile_ext = $blast->blastfile_ext;
- $blastparameters = $blast->blastparameters;
- $query_re = $blast->query_re;
- $query_type = $blast->query_type;
- $query_uniquename = $blast->query_uniquename;
- $is_concat = $blast->is_concat;
-
- $form['blast'] = array(
- '#title' => t('Blast Settings'),
- '#type' => 'fieldset',
- '#description' => t('Specific Settings for Blast Analysis.'),
- '#collapsible' => TRUE,
- '#attributes' => array('id' => 'blast-extra-settings'),
- '#weight' => 11
- );
- $previous_db = tripal_db_set_active('chado'); // use chado database
- // get a list of db from chado for user to choose
- $sql = 'SELECT db_id, name FROM {db} ORDER BY lower(name)';
- $results = db_query ($sql);
- tripal_db_set_active($previous_db);
- $blastdbs = array();
- while ($db = db_fetch_object($results)){
- $blastdbs[$db->db_id] = $db->name;
- }
- $form['db_options'] = array(
- '#type' => 'value',
- '#value' => $blastdbs
- );
- $form['blast']['blastdb'] = array(
- '#title' => t('Database'),
- '#type' => 'select',
- '#description' => t('The database used for the blast analysis. If the database does not appear in this list, please add it.'),
- '#options' => $form['db_options']['#value'],
- '#default_value' => $blastdb,
- );
- $form['blast']['blastfile'] = array(
- '#title' => t('Blast XML File/Directory: (if you input a directory without the tailing slash, all xml files in the directory will be loaded)'),
- '#type' => 'textfield',
- '#description' => t('The xml output file generated by blast in full path.'),
- '#default_value' => $blastfile,
- );
- $form['blast']['blastfile_ext'] = array(
- '#title' => t('Blast XML file extension'),
- '#type' => 'textfield',
- '#description' => t('If a directory is provide for the blast file setting above, then a file extension can be provided here. Files with this extension in the directory will be parsed. If no extension is provided then files with a .xml extension will be parsed within the directory. Please provide the extension without the preceeding period (e.g. "out" rather than ".out"'),
- '#default_value' => $blastfile_ext,
- );
- $form['blast']['is_concat'] = array(
- '#title' => t('Is the XML file concatenated?'),
- '#type' => 'checkbox',
- '#description' => t('Is the XML file a set of concatenated XML results? Such is the case, for instance, if
- <a href="http://www.blast2go.org/">Blast2GO</a> was used to generate the blast results.'),
- '#default_value' => $is_concat,
- );
- $form['blast']['no_parsed'] = array(
- '#title' => t('Number of hits to be parsed'),
- '#type' => 'textfield',
- '#description' => t("The number of hits to be parsed. Tripal will parse only top 10 hits if you input '10'' in this field."),
- '#default_value' => 'all',
- );
- $form['blast']['query_re'] = array(
- '#title' => t('Query Name RE'),
- '#type' => 'textfield',
- '#description' => t('Enter the regular expression that will extract the '.
- 'feature name from the query line in the blast results. This should be '.
- 'the same as the definition line in the query FASTA file. This option is '.
- 'is only required when the query does not identically match a feature '.
- 'in the database.'),
- '#default_value' => $query_re,
- );
- $form['blast']['query_type'] = array(
- '#title' => t('Query Type'),
- '#type' => 'textfield',
- '#description' => t('Please enter the Sequence Ontology term that describes '.
- 'the query sequences used for blasting. This is only necessary if two '.
- 'or more sequences have the same name.'),
- '#default_value' => $query_type,
- );
- $form['blast']['query_uniquename'] = array(
- '#title' => t('Use Unique Name'),
- '#type' => 'checkbox',
- '#description' => t('Select this checboxk if the query name in the blast file '.
- 'matches the uniquename of the feature. By default, the blast results will '.
- 'mapped to the "name" of the feature.'),
- '#default_value' => $query_uniquename,
- );
- $form['blast']['blastparameters'] = array(
- '#title' => t('Parameters'),
- '#type' => 'textfield',
- '#description' => t('The parameters for running the blast analysis.'),
- '#default_value' => $blastparameters,
- );
-
- $form['blast']['blastjob'] = array(
- '#type' => 'checkbox',
- '#title' => t('Submit a job to parse the xml output into Chado'),
- '#description' => t('Note: features associated with the blast results must '.
- 'exist in chado before parsing the file. Otherwise, blast '.
- 'results that cannot be linked to a feature will be '.
- 'discarded. '),
- '#default_value' => $blastjob
- );
-
- /* $form['blast']['blastbesthit'] = array(
- '#type' => 'checkbox',
- '#title' => t('Submit a job to generate a "best hits" report.'),
- '#description' => t('Note: the checkbox above must also be selected.'),
- '#default_value' => $blastbesthit
- );
- */
- return $form;
- }
- /**
- *
- */
- function chado_analysis_blast_validate($node, &$form){
- // use the analysis parent to validate the node
- tripal_analysis_validate($node, $form);
- }
- /*******************************************************************************
- * When a node is requested by the user this function is called to allow us
- * to add auxiliary data to the node object.
- */
- function chado_analysis_blast_load($node){
- // load the default set of analysis fields
- $additions = chado_analysis_load($node);
- // create some variables for easier lookup
- $analysis = $additions->analysis;
- $analysis_id = $analysis->analysis_id;
- $blast_settings = tripal_analysis_get_property($analysis->analysis_id,'analysis_blast_settings');
- $blastdb = tripal_analysis_get_property($analysis->analysis_id,'analysis_blast_blastdb');
- $blastfile = tripal_analysis_get_property($analysis->analysis_id,'analysis_blast_blastfile');
- $blastparameters = tripal_analysis_get_property($analysis->analysis_id,'analysis_blast_blastparameters');
- $no_parsed = tripal_analysis_get_property($analysis->analysis_id,'analysis_blast_no_parsed');
- $query_re = tripal_analysis_get_property($analysis->analysis_id,'analysis_blast_query_re');
- $query_type = tripal_analysis_get_property($analysis->analysis_id,'analysis_blast_query_type');
- $query_uniquename= tripal_analysis_get_property($analysis->analysis_id,'analysis_blast_query_uniquename');
- $blastfile_ext = tripal_analysis_get_property($analysis->analysis_id,'analysis_blast_blastfile_ext');
- $is_concat = tripal_analysis_get_property($analysis->analysis_id,'analysis_blast_is_concat');
- $analysis->tripal_analysis_blast->blastdb = $blastdb->value;
- $analysis->tripal_analysis_blast->blastfile = $blastfile->value;
- $analysis->tripal_analysis_blast->blastparameters = $blastparameters->value;
- $analysis->tripal_analysis_blast->no_parsed = $no_parsed->value;
- $analysis->tripal_analysis_blast->query_re = $query_re->value;
- $analysis->tripal_analysis_blast->query_type = $query_type->value;
- $analysis->tripal_analysis_blast->query_uniquename= $query_uniquename->value;
- $analysis->tripal_analysis_blast->blastfile_ext = $blastfile_ext->value;
- $analysis->tripal_analysis_blast->is_concat = $is_concat->value;
- // get the database information so that we don't have to require callers
- // to do the lookup
- $select = array('db_id' => $blastdb->value);
- $analysis->tripal_analysis_blast->db = tripal_core_generate_chado_var('db',$select);
- // if there is an old style 'blast_settings' array, then break these out for
- // use in the new format
- if(count($blast_settings)>0){
- $prop_values = explode ("|", $blast_settings->value);
- $analysis->tripal_analysis_blast->blastdb = $prop_values[0];
- $analysis->tripal_analysis_blast->blastfile = $prop_values[1];
- $analysis->tripal_analysis_blast->blastparameters = $prop_values[2];
- }
- /* check if there exists a best hit report. if yes, reuturn the report url
- $select = array(
- 'analysisfeature_id' => array(
- 'analysis_id' => $analysis_id,
- ),
- 'type_id' => array(
- 'name' => 'analysis_blast_besthit_query',
- 'cv_id' => array(
- 'name' => 'tripal'
- ),
- ),
- );
- $blast_report = tripal_core_chado_select('analysisfeatureprop',array('analysisfeatureprop_id'),$select);
- */
- $sql = "SELECT AFP.analysisfeature_id
- FROM {analysisfeature} AF
- INNER JOIN {analysisfeatureprop} AFP ON AF.analysisfeature_id = AFP.analysisfeature_id
- WHERE analysis_id = %d
- AND AFP.type_id = (
- SELECT cvterm_id
- FROM {cvterm}
- WHERE name = '%s'
- AND cv_id = (
- SELECT cv_id
- FROM {cv}
- WHERE name = 'tripal'
- )
- ) LIMIT 1 OFFSET 0";
- $blast_report = db_result(chado_query($sql, $analysis_id, 'analysis_blast_besthit_query'));
- if ($blast_report) {
- $report_url = url("tripal_blast_report/".$analysis->analysis_id."/1/0/0/20");
- $analysis->blast_report = $report_url;
- }
- return $additions;
- }
- /**
- *
- */
- function chado_analysis_blast_insert($node){
- // insert the analysistripal_core_generate_chado_var
- chado_analysis_insert($node);
- // set the type for this analysis
- tripal_analysis_insert_property($node->analysis_id,'analysis_type','tripal_analysis_blast');
- // now add in the remaining settings as a single property but separated by bars
- tripal_analysis_insert_property($node->analysis_id,'analysis_blast_blastdb',$node->blastdb);
- tripal_analysis_insert_property($node->analysis_id,'analysis_blast_blastfile',$node->blastfile);
- tripal_analysis_insert_property($node->analysis_id,'analysis_blast_blastparameters',$node->blastparameters);
- tripal_analysis_insert_property($node->analysis_id,'analysis_blast_no_parsed',$node->no_parsed);
- tripal_analysis_insert_property($node->analysis_id,'analysis_blast_query_re',$node->query_re);
- tripal_analysis_insert_property($node->analysis_id,'analysis_blast_query_type',$node->query_type);
- tripal_analysis_insert_property($node->analysis_id,'analysis_blast_query_uniquename',$node->query_uniquename);
- tripal_analysis_insert_property($node->analysis_id,'analysis_blast_blastfile_ext',$node->blastfile_ext);
- tripal_analysis_insert_property($node->analysis_id,'analysis_blast_is_concat',$node->is_concat);
-
- // submit the parsing jobs
- chado_analysis_blast_submit_jobs($node);
- }
- /**
- *
- */
- function chado_analysis_blast_update($node){
- // update the anlaysis
- chado_analysis_update($node);
- // add the blast settings
- tripal_analysis_update_property($node->analysis_id,'analysis_type','tripal_analysis_blast',1);
- tripal_analysis_update_property($node->analysis_id,'analysis_blast_blastdb',$node->blastdb,1);
- tripal_analysis_update_property($node->analysis_id,'analysis_blast_blastfile',$node->blastfile,1);
- tripal_analysis_update_property($node->analysis_id,'analysis_blast_blastparameters',$node->blastparameters,1);
- tripal_analysis_update_property($node->analysis_id,'analysis_blast_no_parsed',$node->no_parsed,1);
- tripal_analysis_update_property($node->analysis_id,'analysis_blast_query_re',$node->query_re,1);
- tripal_analysis_update_property($node->analysis_id,'analysis_blast_query_type',$node->query_type,1);
- tripal_analysis_update_property($node->analysis_id,'analysis_blast_query_uniquename',$node->query_uniquename,1);
- tripal_analysis_update_property($node->analysis_id,'analysis_blast_blastfile_ext',$node->blastfile_ext,1);
- tripal_analysis_update_property($node->analysis_id,'analysis_blast_is_concat',$node->is_concat,1);
- // if this analysis uses the old style blast settings cvterm then remove that term
- $old = tripal_analysis_get_property($node->analysis_id,'analysis_blast_settings');
- if(count($old) > 0){
- tripal_analysis_delete_property($node->analysis_id,'analysis_blast_settings');
- }
- // submit the parsing jobs
- chado_analysis_blast_submit_jobs($node);
- }
- /**
- *
- */
- function chado_analysis_blast_submit_jobs($node){
- global $user;
- // add a job if the user wants to parse the XML
- if($node->blastjob) {
- $job_args = array(
- $node->analysis_id,
- $node->blastdb,
- $node->blastfile,
- $node->no_parsed,
- $node->blastfile_ext,
- $node->query_re,
- $node->query_type,
- $node->query_uniquename,
- $node->is_concat
- );
- if (is_readable($node->blastfile)) {
- tripal_add_job("Parse blast: $node->blastfile",'tripal_analysis_blast',
- 'tripal_analysis_blast_parseXMLFile', $job_args, $user->uid);
- } else {
- drupal_set_message("Blast output file, $node->blastfile, is not readable
- by the server. Check existence of file and file permissions.
- Job not scheduled.");
- }
- }
- // add a job if the user wants to create a best hits report.
- if($node->blastbesthit) {
- $j_args[0] = $node->analysis_id;
- tripal_add_job("Parse best hit: $node->blastfile",'tripal_analysis_blast',
- 'tripal_analysis_blast_parse_best_hit', $j_args, $user->uid);
- }
-
- }
- /*******************************************************************************
- * Delete blast anlysis
- */
- function chado_analysis_blast_delete($node){
- chado_analysis_delete($node);
- }
- /*******************************************************************************
- * This function customizes the view of the chado_analysis node. It allows
- * us to generate the markup.
- */
- function chado_analysis_blast_view ($node, $teaser = FALSE, $page = FALSE) {
- // use drupal's default node view:
- //dprint_r($node);
- if (!$teaser) {
- $node = node_prepare($node, $teaser);
- // When previewing a node submitting form, it shows 'Array' instead of
- // correct date format. We need to format the date here
- $time = $node->timeexecuted;
- if(is_array($time)){
- $month = $time['month'];
- $day = $time['day'];
- $year = $time['year'];
- $timestamp = $year.'-'.$month.'-'.$day;
- $node->timeexecuted = $timestamp;
- }
- // When viewing a node, we need to reformat the analysisprop since we
- // separate each value with a bar |
- if (preg_match("/.*\|.*\|.*/",$node->blastdb)) {
- $prop_values = explode("|", $node->blastdb);
- $node->blastdb = $prop_values[0];
- $node->blastfile = $prop_values[1];
- $node->blastparameters = $prop_values[2];
- }
- }
- return $node;
- }
- /*******************************************************************************
- * 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_blast_perm(){
- return array(
- 'access chado_analysis_blast content',
- 'create chado_analysis_blast content',
- 'delete chado_analysis_blast content',
- 'edit chado_analysis_blast content',
- );
- }
- /*******************************************************************************
- * The following function proves access control for users trying to
- * perform actions on data managed by this module
- */
- function chado_analysis_blast_access($op, $node, $account){
- if ($op == 'create') {
- if(!user_access('create chado_analysis_blast content', $account)){
- return FALSE;
- }
- }
- if ($op == 'update') {
- if (!user_access('edit chado_analysis_blast content', $account)) {
- return FALSE;
- }
- }
- if ($op == 'delete') {
- if (!user_access('delete chado_analysis_blast content', $account)) {
- return FALSE;
- }
- }
- if ($op == 'view') {
- if(!user_access('access chado_analysis_blast content', $account)){
- return FALSE;
- }
- }
- return NULL;
- }
- /**
- *
- *
- * @ingroup tripal_feature
- */
- function tripal_analysis_blast_job_describe_args($callback,$args){
- $new_args = array();
- if($callback == 'tripal_analysis_blast_parseXMLFile'){
- // add in the analysis
- if($args[0]){
- $analysis = tripal_core_chado_select('analysis',array('name'),array('analysis_id' => $args[0]));
- }
- $new_args['Analysis'] = $analysis[0]->name;
- // add in the database
- if($args[1]){
- $db = tripal_core_chado_select('db',array('name'),array('db_id' => $args[1]));
- }
- $new_args['Database'] = $db[0]->name;
- $new_args['File or Directory Name'] = $args[2];
- if($args[7] == 1){
- $new_args['Is XML file concatenated'] = 'Yes';
- } else {
- $new_args['Is XML file concatenated'] = 'No';
- }
- $new_args['File Extension (if directory)'] = $args[4];
- $new_args['Number matches parsed per query'] = $args[3];
- $new_args['Query name regular expression'] = $args[5];
- $new_args['Query type'] = $args[6];
- if($args[7] == 1){
- $new_args['Feature identifier'] = 'feature unique name';
- } else {
- $new_args['Feature identifier'] = 'feature name';
- }
-
- }
- return $new_args;
- }
|