Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull request for linkout repairs #4

Closed
wants to merge 9 commits into from
Closed
Binary file added .DS_Store
Binary file not shown.
Binary file added api/.DS_Store
Binary file not shown.
103 changes: 101 additions & 2 deletions api/blast_ui.api.inc
Original file line number Diff line number Diff line change
@@ -1,5 +1,101 @@
<?php

/**
* This program is used for services module specifically.
* Run BLAST (should be called from the command-line)
*
* @param $program
* Which BLAST program to run (ie: 'blastn', 'tblastn', tblastx', 'blastp','blastx')
* @param $query
* The full path and filename of the query FASTA file
* @param $database
* The full path and filename prefix (excluding .nhr, .nin, .nsq, etc.)
* @param $output_filestub
* The filename (not including path) to give the results. Should not include file type suffix
* @param $options
* An array of additional option where the key is the name of the option used by
* BLAST (ie: 'num_alignments') and the value is relates to this particular
* BLAST job (ie: 250)
* @param $format
* Which specifies Json or asn format of file or program
* @param $format_type
* which specify the number of format used by BLAST e.g json has 11 and json as 12.
*/


function run_BLAST_tripal_job_services($program, $query, $database, $output_filestub, $options, $format, $format_type, $job_id = NULL) {



$output_file = file_directory_temp() . DIRECTORY_SEPARATOR . $output_filestub . '.blast.' . $format_type;


// $output_file = file_directory_temp() . DIRECTORY_SEPARATOR . $output_filestub . '.blast.json';

$output_dir = variable_get('file_public_path', conf_path() . '/files')
. DIRECTORY_SEPARATOR . 'tripal' . DIRECTORY_SEPARATOR . 'tripal_blast';

print "\nExecuting $program\n\n";
print "Query: $query\n";
print "Database: $database\n";
print "Results File: $output_file\n";

print "Options:\n";

// Allow administrators to use an absolute path for these commands.
// Defaults to using $PATH.
$blast_path = variable_get('blast_path', '');
$blast_threads = variable_get('blast_threads', '');

// Strip the extension off the BLAST target
$database = preg_replace("/(.*)\.[pn]\w\w/", '$1', $database);

// The executables:
$program = $blast_path . $program;
$blast_formatter_command = $blast_path . 'blast_formatter';

//$blast_cmd = "$program -query '$query' -db '$database' -out '$output_file' -outfmt=11";
$blast_cmd = "$program -query '$query' -db '$database' -out '$output_file' -outfmt=".$format;

if (!empty($options)) {
foreach ($options as $opt => $val) {
if ($val) {
print "\t$opt: $val\n";
$blast_cmd .= " -$opt $val";
}
}
}

// Setting the value of threads by admin page
$blast_cmd .= " -num_threads ".$blast_threads;

print "\nExecuting the following BLAST command:\n" . $blast_cmd . "\n";

system($blast_cmd);

if (!file_exists($output_file)) {
tripal_report_error(
'blast_ui',
TRIPAL_ERROR,
"BLAST did not complete successfully as is implied by the lack of output file (%file). The command run was @command",
array('%file' => $output_file, '@command' => $blast_cmd),
array('print' => TRUE)
);
return FALSE;
}
print "\nDone!\n";

}










/**
* @file
* Contains more generally applicable functions as well as some meant to help developers
Expand Down Expand Up @@ -84,8 +180,11 @@ function get_blast_database_options($type) {
}
}

// Sort alphabetically
asort($options);
$options[0] = 'Select a Dataset';

// Prepend prompt; note that array_unshift() will re-index the array
$options = array('Select a Dataset') + $options;

return $options;
}
Expand Down Expand Up @@ -668,4 +767,4 @@ function generate_blast_hit_image($acc = '', $scores, $hits, $tsize, $qsize, $na
ob_end_clean();

return $b64_img;
}
}
3 changes: 3 additions & 0 deletions blast_ui.module
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,13 @@ function show_blast_output($job_string) {
*
*/
function blast_ui_ctools_plugin_api($owner, $api) {
$webservices = variable_get('Enable_webservices');
if($webservices == 1){
if ($owner == 'services' && $api == 'services') {
return array(
'version' => 3,
'file' => 'includes/blast_ui.services.inc'
);
}
}
}
Binary file added includes/.DS_Store
Binary file not shown.
116 changes: 112 additions & 4 deletions includes/blast_ui.admin.inc
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,26 @@ function blast_ui_admin_form($form, $form_state) {

$form['general']['eVal']= array(
'#type' => 'textfield',
'#title' => t('e-Value (Expected Threshold)'),
'#description' => t('Expected number of chance matches in a random model. This number should be give in a decimal format.'),
'#title' => t('Default e-value (Expected Threshold)'),
'#description' => t('Expected number of chance matches in a random model. This number should be given in a decimal format.'),
'#default_value' => variable_get('eVal', 0.001),
//'#default_value' => variable_get('blast_threads', 1),
);

$form['general']['qRange']= array(
'#type' => 'textfield',
'#title' => t('Max matches in a query range'),
'#title' => t('Default max matches in a query range'),
'#description' => t('Limit the number of matches to a query range. This option is useful if many strong matches to one part of a query may prevent BLAST from presenting weaker matches to another part of the query.'),
'#default_value' => variable_get('qRange', 0),
);

$form['general']['Enable_webservices'] = array(
'#type' => 'checkbox',
'#title' => 'Enable webservices of blast',
'#description' => 'When checked, a blast webservices gets enabled.',
'#default_value' => variable_get('Enable_webservices', true),
);

$form['file_upload'] = array(
'#type' => 'fieldset',
'#title' => 'Allow File Upload',
Expand Down Expand Up @@ -156,6 +163,99 @@ function blast_ui_admin_form_validate($form, &$form_state) {

}

/*
**
** custom method disabled the web services
**
*/

function disable_web_services()
{
$ar=array('services', 'rest_server');
$result = module_disable($ar,true);
try{
$eid = 1;
$num_deleted = db_delete('services_endpoint')->condition('eid', $eid)->execute();
} catch(Exception $e){
//drupal_set_message(t("Web-Services of blast are already disabled"), 'error');
}

}

/*
** custom method enable the web services
**
*/

function enable_web_services()
{
$ar=array('services', 'rest_server');
$result = module_enable($ar, true);
if (empty($result)) {
throw new DrupalUpdateException(implode(', ', $ar) . ' or dependencies could not be enabled, please install services ');
}

$server_settings = array(
'formatters' => array(
'bencode' => TRUE,
'json' => TRUE,
'jsonp' => TRUE,
'php' => TRUE,
'xml' => TRUE,
),
'parsers' => array(
'application/json' => TRUE,
'application/vnd.php.serialized' => TRUE,
'application/x-www-form-urlencoded' => TRUE,
'application/xml' => TRUE,
'multipart/form-data' => TRUE,
'text/xml' => TRUE,
),
);

$resources = array(
'blast' => array(
'operations' => array(
'retrieve' => array(
'enabled' => '1',
),
'index' => array(
'enabled' => '1',
),
),
'actions' => array(
'getJobId' => array(
'enabled' => '1',
),
'getBlastStatus' => array(
'enabled' => '1',
),
'getDatabaseOptions' => array(
'enabled' => '1',
),
),
),
);

try{
$nid = db_insert('services_endpoint')->fields(
array(
'eid' => 1,
'debug' => 1,
'name' => 'restapi',
'server' => 'rest_server',
'path' => 'restapi',
'resources' => serialize($resources), //'a:1:{s:5:"blast";a:2:{s:10:"operations";a:2:{s:8:"retrieve";a:1:{s:7:"enabled";s:1:"1";}s:5:"index";a:1:{s:7:"enabled";s:1:"1";}}s:7:"actions";a:2:{s:8:"getJobId";a:1:{s:7:"enabled";s:1:"1";}s:18:"getDatabaseOptions";a:1:{s:7:"enabled";s:1:"1";}}}}',
'server_settings' => serialize($server_settings),
'authentication' => 'a:0:{}',
))->execute();
}
catch(Exception $e){
//drupal_set_message(t("Web-Services of blast are already Enabled"), 'error');
}

}

/**
* Submit the Admin/settings form.
*/
Expand All @@ -167,9 +267,17 @@ function blast_ui_admin_form_submit($form, $form_state) {
variable_set('eVal', $form_state['values']['eVal']);
variable_set('qRange', $form_state['values']['qRange']);

// Logic to enable web services on single click
variable_set('Enable_webservices', $form_state['values']['Enable_webservices']);
variable_set('blast_ui_allow_query_upload', $form_state['values']['query_upload']);
variable_set('blast_ui_allow_target_upload', $form_state['values']['target_upload']);

variable_set('blast_ui_nucleotide_example_sequence', $form_state['values']['nucleotide_example']);
variable_set('blast_ui_protein_example_sequence', $form_state['values']['protein_example']);
}

if($form_state['values']['Enable_webservices'] == 1){
enable_web_services();
}else{
disable_web_services();
}
}
Loading