00001 <?php
00002
00003
00004
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 function dbsf_ssaha2_menu() {
00048 $items = array();
00049 $items['admin/dbsf/ssaha2'] = array(
00050 'file' => 'dbsf_ssaha2.inc',
00051 'title' => 'SSAHA2 Server administration',
00052 'page callback' => 'dbsf_admin_ssaha2_page',
00053 'access arguments' => array('Administrate SSAHA2 Server'),
00054 'description' => 'Configure SSAHA2 specific settings',
00055 'type' => MENU_NORMAL_ITEM,
00056 );
00057 $items['dbsf/ssaha2'] = array(
00058 'file' => 'dbsf_ssaha2.inc',
00059 'title' => 'dbsf SSAHA2 Server',
00060 'page callback' => 'dbsf_ssaha2_page',
00061 'access arguments' => array('Access SSAHA2 Server'),
00062 'type' => MENU_CALLBACK,
00063 );
00064 $items['dbsf/ssaha2_result'] = array(
00065 'title' => 'dbsf SSAHA2 Results',
00066 'page callback' => 'dbsf_ssaha2_result_page',
00067 'page arguments' => array(2),
00068 'access arguments' => array('Access SSAHA2 Server'),
00069 'type' => MENU_CALLBACK,
00070 );
00071 return $items;
00072 }
00073
00074 function dbsf_add_software_ssaha2() {
00075 db_query("INSERT INTO {ic_software} (uniquename,description) VALUES ('ssaha2Build','Format reference sequences as a SSAHA2 database. Needed for creating your own SSAHA2 databases.')");
00076
00077 $dbxref_id = icbasic_get_add_dbxref_withnames('Sanger', 'SSAHA2');
00078 $cvterm_id = icbasic_get_add_cv_withnames('resource_type', 'software option');
00079 $link_sql = 'INSERT INTO {ic_software_resource} (software_id,resource_id) VALUES (' . "(SELECT software_id from {ic_software} where uniquename='%s')" . ",(SELECT resource_id from {ic_resource} where uniquename='%s')" . ')';
00080 $options_array = array(
00081 'ssaha_seeds' => 'Number of kmer matches required to flag a hit',
00082 'ssaha_score' => 'Minimum score for match to be reported',
00083 'ssaha_identity' => 'Minimum identity for match to be reported',
00084 'ssaha_cmatch' => 'Minimum match length for cross_match matching',
00085 'ssaha_ckmer' => 'Word size for cross_match matching',
00086 'ssaha_cut' => 'Number of repeats allowed before this kmer is ignored',
00087 'ssaha_depth' => 'Number of hits to consider for alignment',
00088 'ssaha_best' => 'Only report best alignment',
00089 'ssaha_query_type' => 'Optimize options for a specific query sequencing technology',
00090 );
00091 foreach ($options_array as $option => $description) {
00092 dbsf_add_software_option($option, $dbxref_id, $cvterm_id, $description);
00093
00094 switch ($option) {
00095 case 'ssaha_seeds':
00096 icbasic_populate_prop('ic_resource', $option, $cvterm_id, array(
00097 '5', '1', '2', '8', '10', '12', '14', '18', '22', '30',
00098 )
00099 );
00100 icbasic_populate_cvterms('ic_resource', $option, 'input type', array('select'));
00101 break;
00102
00103 case 'ssaha_score':
00104 icbasic_populate_prop('ic_resource', $option, $cvterm_id, array(
00105 '30', '5', '12', '15', '18', '20', '25', '30', '50', '100', '200', '500', '1000', '1500', '2000',
00106 )
00107 );
00108 icbasic_populate_cvterms('ic_resource', $option, 'input type', array('select'));
00109 break;
00110
00111 case 'ssaha_identity':
00112 icbasic_populate_prop('ic_resource', $option, $cvterm_id, array(
00113 '50', '20', '30', '40', '45', '55', '60', '65', '70', '75', '80', '85', '90', '95', '98',
00114 )
00115 );
00116 icbasic_populate_cvterms('ic_resource', $option, 'input type', array('select'));
00117 break;
00118
00119 case 'ssaha_cmatch':
00120 icbasic_populate_prop('ic_resource', $option, $cvterm_id, array(
00121 '14', '5', '9', '16', '18', '20', '22', '24', '28', '32', '40', '50', '100',
00122 )
00123 );
00124 icbasic_populate_cvterms('ic_resource', $option, 'input type', array('select'));
00125 break;
00126
00127 case 'ssaha_ckmer':
00128 icbasic_populate_prop('ic_resource', $option, $cvterm_id, array(
00129 '10', '4', '5', '6', '8', '11', '12', '14', '18', '20', '30',
00130 )
00131 );
00132 icbasic_populate_cvterms('ic_resource', $option, 'input type', array('select'));
00133 break;
00134
00135 case 'ssaha_cut':
00136 icbasic_populate_prop('ic_resource', $option, $cvterm_id, array(
00137 '10000', '3000', '5000', '8000', '15000', '20000', '40000', '80000', '100000', '500000',
00138 )
00139 );
00140 icbasic_populate_cvterms('ic_resource', $option, 'input type', array('select'));
00141 break;
00142
00143 case 'ssaha_depth':
00144 icbasic_populate_prop('ic_resource', $option, $cvterm_id, array(
00145 '50',
00146 )
00147 );
00148 icbasic_populate_cvterms('ic_resource', $option, 'input type', array('textfield'));
00149 break;
00150
00151 case 'ssaha_best':
00152 icbasic_populate_prop('ic_resource', $option, $cvterm_id, array(
00153 '0',
00154 )
00155 );
00156 icbasic_populate_cvterms('ic_resource', $option, 'input type', array('checkbox'));
00157 break;
00158
00159 case 'ssaha_query_type':
00160 icbasic_populate_prop('ic_resource', $option, $cvterm_id, array(
00161 'Custom', 'Sanger ABI', '454', 'Illumina-Solexa',
00162 )
00163 );
00164 icbasic_populate_cvterms('ic_resource', $option, 'input type', array('select'));
00165 break;
00166 }
00167 db_query($link_sql, 'ssaha2', $option);
00168 }
00169 }
00170
00171 function dbsf_software_ssaha2_core_settings_form($form_state) {
00172 $software = 'ssaha2';
00173 $form = array();
00174 $res = db_fetch_array(db_query("SELECT active from {ic_software} where uniquename='%s'", $software));
00175 if ($res['active'] == 'f') {
00176 return $form;
00177 }
00178 $select_software_path = 'SELECT value FROM {ic_softwareprop} where software_id=' . "(SELECT software_id from {ic_software} where uniquename='%s')" . ' AND rank=0 AND type_id=' . "(SELECT cvterm_id from {ic_cvterm} as cvterm JOIN {ic_cv} as cv on cv.cv_id=cvterm.cv_id where cv.name='software path' AND cvterm.name='%s')";
00179 $core_exec = db_fetch_array(db_query($select_software_path, $software, 'executable'));
00180 $format_exec = db_fetch_array(db_query($select_software_path, 'ssaha2Build', 'executable'));
00181
00182
00183 $form['settings'] = array(
00184 '#type' => 'fieldset',
00185 '#title' => $software . t(' core settings'),
00186 '#description' => t('Please set some important settings for ') . $software,
00187 'submit' => array(
00188 '#type' => 'submit',
00189 '#value' => "Save core $software settings",
00190 '#weight' => 5,
00191 ),
00192 'core_executable' => array(
00193 '#type' => 'textfield',
00194 '#title' => t('Core executable path'),
00195 '#description' => t("Please provide the <b>full path</b> to the <b>$software</b> executable on the server, e.g. /usr/bin/$software ."),
00196 '#required' => TRUE,
00197 '#default_value' => $core_exec['value'],
00198 ),
00199 'format_executable' => array(
00200 '#type' => 'textfield',
00201 '#title' => t('Executable path for database formating'),
00202 '#description' => t('Please provide the <b>full path</b> to the <b>ssaha2Build</b> executable on the server, e.g. /usr/bin/ssaha2Build .'),
00203 '#required' => TRUE,
00204 '#default_value' => $format_exec['value'],
00205 ),
00206 );
00207 return $form;
00208 }
00209
00210 function dbsf_software_ssaha2_core_settings_form_validate($form, &$form_state) {
00211 $software = 'ssaha2';
00212 $core_exec = escapeshellcmd(trim($form_state['values']['core_executable']));
00213 $format_exec = escapeshellcmd(trim($form_state['values']['format_executable']));
00214
00215 if (!empty($core_exec)) {
00216 if (!file_exists($core_exec)) {
00217 form_set_error('core_executable', "Cannot find executable $core_exec on the server.");
00218 }
00219 $form_state['values']['core_executable'] = $core_exec;
00220 }
00221
00222 if (!empty($format_exec)) {
00223 if (!file_exists($format_exec)) {
00224 form_set_error('format_executable', "Cannot find executable $format_exec on the server.");
00225 }
00226 $form_state['values']['format_executable'] = $format_exec;
00227 }
00228 }
00229
00230 function dbsf_software_ssaha2_core_settings_form_submit($form, &$form_state) {
00231 $software = 'ssaha2';
00232 $store_software_path = 'INSERT INTO {ic_softwareprop} (software_id,type_id,rank,value) VALUES (' . "(SELECT software_id from {ic_software} where uniquename='%s')" . ",(SELECT cvterm_id from {ic_cvterm} as cvterm JOIN {ic_cv} as cv on cv.cv_id=cvterm.cv_id where cv.name='software path' AND cvterm.name='%s')" . ",0,'%s')";
00233 $delete_software_path = 'DELETE FROM {ic_softwareprop} where software_id=' . "(SELECT software_id from {ic_software} where uniquename='%s')" . ' AND rank=0 AND type_id=' . "(SELECT cvterm_id from {ic_cvterm} as cvterm JOIN {ic_cv} as cv on cv.cv_id=cvterm.cv_id where cv.name='software path' AND cvterm.name='%s')";
00234 $select_software_path = 'SELECT value FROM {ic_softwareprop} where software_id=' . "(SELECT software_id from {ic_software} where uniquename='%s')" . ' AND rank=0 AND type_id=' . "(SELECT cvterm_id from {ic_cvterm} as cvterm JOIN {ic_cv} as cv on cv.cv_id=cvterm.cv_id where cv.name='software path' AND cvterm.name='%s')";
00235
00236 $core_exec = db_fetch_array(db_query($select_software_path, $software, 'executable'));
00237 $format_exec = db_fetch_array(db_query($select_software_path, 'ssaha2Build', 'executable'));
00238
00239 $user_core_exec = $form_state['values']['core_executable'];
00240 $user_format_exec = $form_state['values']['format_executable'];
00241
00242 if (!empty($user_core_exec) && $user_core_exec != $core_exec['value']) {
00243 db_query($delete_software_path, $software, 'executable');
00244 db_query($store_software_path, $software, 'executable', $user_core_exec);
00245 drupal_set_message("$user_core_exec is now the $software executable.", 'warning');
00246 }
00247 if (!empty($user_format_exec) && $user_format_exec != $format_exec['value']) {
00248 db_query($delete_software_path, 'ssaha2Build', 'executable');
00249 db_query($store_software_path, 'ssaha2Build', 'executable', $user_format_exec);
00250 drupal_set_message("$user_format_exec is now the ssaha2Build executable.", 'warning');
00251 }
00252 }
00253
00254 function dbsf_admin_ssaha2_page($software = 'ssaha2') {
00255 $software = 'ssaha2';
00256 $check_active = dbsf_check_software_active($software);
00257 if (empty($check_active)) {
00258 drupal_set_message("I'm sorry, but $software does not seem to have been activated yet.<br>".
00259 l('See the software settings page', 'admin/dbsf/software'), 'error'
00260 );
00261 return FALSE;
00262 }
00263 $database_link_form = drupal_get_form('dbsf_admin_link_dataset_software_form', $software);
00264 if (strlen($database_link_form) < 600) {
00265 $database_link_form = "You have no datasets defined to link them to $software. Please see ". l('the dataset administration page', 'admin/dbsf/software', array('fragment' => 'available-datasets'));
00266 }
00267 $table = dbsf_admin_database_table($software);
00268
00269 $page_tabs = array(
00270 'settings' => array(
00271 '#type' => 'tabset',
00272 'variables' => array(
00273 '#type' => 'tabpage',
00274 '#title' => 'Link datasets to '. strtoupper($software),
00275 '#content' => $database_link_form . $table,
00276 '#weight' => 0,
00277 ),
00278 ),
00279 );
00280 $return_text = tabs_render($page_tabs);
00281 return $return_text;
00282 }
00283
00284 function dbsf_check_ssaha2($software) {
00285 $check_active = dbsf_check_software_active($software);
00286 if (empty($check_active)) {
00287 return 'active';
00288 }
00289 $check = 0;
00290 $software_prop = dbsf_get_softwareprop(NULL, TRUE);
00291 if (!empty($software_prop)) {
00292 foreach ($software_prop as $name => $data) {
00293 if (in_array($name, array('ssaha2', 'ssaha2Build'))) {
00294 foreach ($data as $term_name => $v) {
00295 if ($term_name == 'executable' || $term_name == 'data') {
00296 $check++;
00297 }
00298 }
00299 }
00300 }
00301 }
00302 if ($check < 2) {
00303 return 'variables';
00304 }
00305 $sql = 'SELECT count(distinct rcv.cvterm_id) from {ic_resource_cvterm} rcv ' . ' JOIN {ic_software_resource} sr ON sr.resource_id=rcv.resource_id ' . " WHERE sr.software_id=(SELECT software_id from {ic_software} where uniquename='%s') " . " AND rcv.cvterm_id IN (SELECT cvterm_id FROM {ic_cvterm} where cv_id=(SELECT cv_id from {ic_cv} where name='dataset_type'))";
00306 $count = db_fetch_array(db_query($sql, $software));
00307 if ($count['count'] < 1) {
00308 return 'datasets';
00309 }
00310 return TRUE;
00311 }
00312
00313 function dbsf_ssaha2_page() {
00314 $setup = dbsf_check_ssaha2('ssaha2');
00315 if ($setup === TRUE) {
00316 return drupal_get_form('dbsf_ssaha2_form');
00317 }
00318 else {
00319 $return_text = "<p>I'm sorry but your SSAHA2 software has not been setup properly.</p><ul>";
00320 switch ($setup) {
00321 case 'datasets':
00322 $return_text .= '<li>Not enough datasets have been defined. Please define at least one dataset at the '. l('dataset registration page', 'admin/dbsf/dataset', array('fragment' => 'available-datasets')) .' and then register them with SSAHA2 at the '. l('SSAHA2 settings page', 'admin/dbsf/ssaha2');
00323 break;
00324
00325 case 'active':
00326 $return_text .= '<li>SSAHA2 has not been activated. Please activate it at the '. l('software settings page', 'admin/dbsf/software');
00327 break;
00328
00329 case 'variables':
00330 $return_text .= '<li>SSAHA2 variable paths have not been defined. Please define them at at the '. l('SSAHA2 settings page', 'admin/dbsf/software', array('fragment' => 'ssaha2'));
00331 break;
00332 }
00333 drupal_set_message($return_text .'</ul>', 'error');
00334 return ' ';
00335 }
00336 }
00337
00338 function dbsf_ssaha2_form($form_state) {
00339 $form = array();
00340 $software = 'ssaha2';
00341 $software_options = _dbsf_generate_options($software);
00342
00343 $dbs = dbsf_get_user_datasets($software);
00344
00345 $nucleotide_dbs = (array)$dbs['nucleotide'];
00346 $option_form = array();
00347 if (empty($nucleotide_dbs)) {
00348 global $user;
00349 $roles_str = implode(', ', $user->roles);
00350 drupal_set_message("I'm sorry, but the system administrator has not authorized your role ($roles_str) to have access to at least 1 dataset with $software. Please let them know.", 'error');
00351 return FALSE;
00352 }
00353 if (!empty($software_options)) {
00354 foreach ($software_options as $name => $data) {
00355 $option_form[$name] = array(
00356 '#type' => $data['type'],
00357 '#title' => $name,
00358 '#description' => $data['description'],
00359 );
00360 if ($data['type'] !== 'textfield') {
00361 $option_form[$name]['#options'] = $data['options'];
00362 }
00363 }
00364 }
00365 $form['program'] = array(
00366 '#type' => 'fieldset',
00367 '#title' => strtoupper($software),
00368 'query_sequence' => array(
00369 '#type' => 'textarea',
00370 '#title' => t('Enter query sequence in simple text, FASTA or FASTQ format'),
00371 ),
00372 'query_file_'. $software => array(
00373 '#type' => 'file',
00374 '#title' => t('or upload query sequence in FASTA or FASTQ format'),
00375 '#description' => t('Please give a text file, not a MS-Word or other document'),
00376
00377 '#tree' => FALSE,
00378 ),
00379 'subject_db' => array(
00380 '#type' => 'select',
00381 '#title' => t('Dataset(s)'),
00382 '#description' => t('Please select one dataset.'),
00383 '#size' => 1,
00384 '#options' => $nucleotide_dbs,
00385 ),
00386 'subject_file_'. $software => array(
00387 '#type' => 'file',
00388 '#title' => t('or upload your own database as a FASTA'),
00389 '#description' => t('Please give a FASTA text file, not a MS-Word or other document'),
00390
00391 '#tree' => FALSE,
00392 ),
00393 'advanced parameters' => array(
00394 '#type' => 'fieldset',
00395 '#title' => 'Advance Search Parameters',
00396 '#collapsible' => TRUE,
00397 '#collapsed' => TRUE,
00398 $option_form,
00399 ),
00400 );
00401
00402 $form['buttons'] = array(
00403 '#weight' => 10,
00404 'db_submit' => array(
00405 '#type' => 'submit',
00406 '#value' => t('Run '. $software),
00407 '#disabled' => TRUE,
00408 ),
00409 'clear' => array(
00410 '#attributes' => array('title' => t('Clear the form')),
00411 '#type' => 'submit',
00412 '#value' => 'Reset data',
00413 '#validate' => array('dbsf_form_clear'),
00414 '#weight' => 2,
00415 ),
00416 );
00417 $form['#attributes']['enctype'] = "multipart/form-data";
00418 return $form;
00419 }
00420
00421 function dbsf_ssaha2_form_validate($form, &$form_state) {
00422 $data = $form_state['values'];
00423 if (!empty($data['query_sequence'])) {
00424 if (!empty($_FILES['files']['tmp_name']['query_file_' . 'ssaha2'])) {
00425 form_set_error("query_sequence", "It seems you both typed a query sequence and uploaded one.");
00426 return FALSE;
00427 }
00428 if (empty($data['subject_db']) && empty($_FILES['files']['tmp_name']['subject_file_' . 'ssaha2'])) {
00429 form_set_error("query_sequence", "It seems you provided a query sequence but no subject database (or file).");
00430 return FALSE;
00431 }
00432
00433 $result = icbasic_validate_seq_dna($data['query_sequence']);
00434 if ($result === FALSE || is_numeric($result)) {
00435 form_set_error("query_sequence", "Sorry your sequence does not seem to be a valid DNA sequence ($result errors).");
00436 return FALSE;
00437 }
00438 else {
00439 $form_state['query_sequence'] = $result;
00440 }
00441 }
00442 elseif (!empty($_FILES['files']['tmp_name']['query_file_' . 'ssaha2'])) {
00443
00444 if (empty($data['subject_db']) && empty($_FILES['files']['tmp_name']['subject_file_' . 'ssaha2'])) {
00445 form_set_error("query_sequence", "It seems you provided a query but no database database (or file).");
00446 return FALSE;
00447 }
00448 }
00449
00450 if (!empty($data['subject_db'])) {
00451 if (empty($data['query_sequence']) && empty($_FILES['files']['tmp_name']['query_file_' . 'ssaha2'])) {
00452 form_set_error("subject_db", "It seems you provided a subject database but no query sequence (or file).");
00453 return FALSE;
00454 }
00455
00456 }
00457 elseif (!empty($_FILES['files']['tmp_name']['subject_file_' . 'ssaha2'])) {
00458
00459 if (empty($data['query_sequence']) && empty($_FILES['files']['tmp_name']['query_file_' . 'ssaha2'])) {
00460 form_set_error("subject_db", "It seems you provided a subject database but no query sequence (or file).");
00461 return FALSE;
00462 }
00463 }
00464 }
00465
00466 function dbsf_ssaha2_form_submit($form, &$form_state) {
00467 dpm($form_state);
00468
00469 $validators_file = array('file_validate_size' => array(10000));
00470 $tmpdir = file_directory_temp();
00471
00472 $timestamp = time();
00473 $sessionid = session_id();
00474 $dirpath = file_create_path() .'/dbsf';
00475 $data = $form_state['values'];
00476
00477 $operations = array();
00478
00479 $save_array = array();
00480 $subject_dbs = '';
00481
00482 $form_uid = icbasic_create_uid($sessionid, $timestamp, 'ssaha2');
00483 $batch_file_data = array();
00484
00485 $file_type = 'nucleotide';
00486 $verify = array();
00487 $uid = icbasic_create_uid($sessionid, $timestamp, 'ssaha2');
00488
00489
00490
00491
00492 if (isset($_FILES['files']) && !empty($_FILES['files']['tmp_name']['query_file_' . 'ssaha2'])) {
00493 $file = file_save_upload('query_file_' . 'ssaha2', $validators_file, $tmpdir, FILE_EXISTS_RENAME);
00494 if (empty($file)) {
00495 form_set_error('query_file_' . 'ssaha2', "Sorry your file for 'ssaha2' was not saved. Maybe it is too large (>1 Mb)? Otherwise, ". l('contact', 'contact') ." the administrator (quote $uid).");
00496 }
00497 else {
00498 $verify['runq']++;
00499 file_set_status($file, FILE_STATUS_TEMPORARY);
00500 $batch_file_data['infile'][$uid] = $file->filepath;
00501 $batch_file_data['outfile'][$uid] = $dirpath .'/'. $uid .'.query';
00502 $batch_file_data['filetype'][$uid] = $file_type;
00503 $batch_file_data['format'][$uid] = FALSE;
00504 }
00505 }
00506 elseif (!empty($data['query_sequence'])) {
00507 $verify['runq']++;
00508
00509 $batch_file_data['infile'][$uid] = $data['query_sequence'];
00510 $batch_file_data['outfile'][$uid] = $dirpath .'/'. $uid .'.query';
00511 $batch_file_data['filetype'][$uid] = $file_type;
00512 $batch_file_data['format'][$uid] = FALSE;
00513 }
00514
00515 $file_type = 'nucleotide';
00516
00517 if (isset($_FILES['files']) && !empty($_FILES['files']['tmp_name']['subject_file_' . 'ssaha2'])) {
00518 $file = file_save_upload('subject_file_' . 'ssaha2', $validators_file, $tmpdir, FILE_EXISTS_RENAME);
00519 if (empty($file)) {
00520 form_set_error('subject_file_' . 'ssaha2', "Sorry your file for 'ssaha2' was not saved. Maybe it is too large (>10 Mb)? Otherwise, ". l('contact', 'contact') ." the administrator (quote $uid).");
00521 }
00522 else {
00523 $verify['rundb']++;
00524 file_set_status($file, FILE_STATUS_TEMPORARY);
00525 $batch_file_data['infile'][$uid] = $file->filepath;
00526 $batch_file_data['outfile'][$uid] = $dirpath .'/'. $uid .'.subject';
00527 $batch_file_data['filetype'][$uid] = $file_type;
00528 $batch_file_data['format'][$uid] = TRUE;
00529 }
00530 }
00531 if (!empty($data['subject_db'])) {
00532
00533
00534 foreach ($data['subject_db'] as $db => $value) {
00535 $verify['rundb']++;
00536 $subject_dbs[] = dbsf_get_dataset_path($db);
00537 }
00538 }
00539
00540 if (!empty($verify['runq']) && $verify['runq'] == 1 && !empty($verify['rundb'])) {
00541
00542 $save_array[$form_uid][$uid]['par'] = $par;
00543 $save_array[$form_uid][$uid]['sub'] = $subject_dbs;
00544 $save_array[$form_uid][$uid]['algorithm'] = 'ssaha2';
00545 }
00546
00547
00548 $operations[] = array('dbsf_batch_upload_fasta', array($batch_file_data));
00549 $operations[] = array('dbsf_batch_save_data', array($save_array));
00550 $batch = array(
00551 'title' => t('Preparing data needed for SSAHA2...'),
00552 'operations' => $operations,
00553 'init_message' => t('Starting SSAHA2 submission...'),
00554 'progress_message' => t('@remaining operations remaining...'),
00555 'error_message' => t('Your SSAHA2 submission encountered an error.'),
00556 'finished' => 'dbsf_ssaha2_batch_finished',
00557 );
00558 batch_set($batch);
00559 $form_state['redirect'] = array('dbsf/ssaha2_result', "submission_uid=$form_uid");
00560 return "dbsf/ssaha2_result?submission_uid=$form_uid";
00561 }
00562
00563 function dbsf_ssaha2_result_page($submission_uid = NULL) {
00564 if (empty($submission_uid)) {
00565 $submission_uid = $_GET['submission_uid'];
00566 if (empty($submission_uid)) {
00567 return 'No submission data provided';
00568 }
00569 }
00570 $basepath = file_create_path();
00571 $dirpath = $basepath .'/dbsf/';
00572 $data = array();
00573
00574
00575 $infile = $dirpath . $submission_uid .'.submission';
00576 if (file_exists($infile)) {
00577 if ($inhandle = fopen($infile, 'rb')) {
00578 while (!feof($inhandle)) {
00579 $line = trim(fgets($inhandle));
00580 if (!empty($line)&& preg_match('/^algorithm;id=/', $line)) {
00581 $line_data = explode('=', $line);
00582 $alg_data = explode(';', $line_data[1]);
00583 $data[$alg_data[0]] = $alg_data[1];
00584 }
00585 }
00586 }
00587 }
00588 else {
00589 dpm("Did not find $infile");
00590 return 'Submission ID not found. Maybe it has expired or is invalid?';
00591 }
00592 if (empty($data)) {
00593 dpm("$infile has no data");
00594 return 'Not a valid submission ID or ID has expired.';
00595 }
00596 $content = '';
00597 foreach ($data as $algorithm => $uid) {
00598 $ssaha2file = $dirpath . $uid .'.output';
00599 $graph = $ssaha2file .'.graph.png';
00600 $content = t('Your report is not ready yet. Please wait or ') . l('try again', 'dbsf/ssaha2_result/'. $submission_uid
00601 ) . t(' in a few moments or bookmark this page.');
00602 if (file_exists($graph)) {
00603 $content = '<p>'. l(
00604 theme_image($graph, 'SSAHA2 results of all queries', 'SSAHA2 results graphical overview', array('width' => '100%'), FALSE)
00605 , $ssaha2file .'.html', array('html' => TRUE, 'alias' => TRUE, 'attributes' => array('target' => '_blank'))
00606 ) .'</p>'. drupal_get_form('dbsf_ssaha2_result_form', $uid, $ssaha2file);
00607 }
00608 else {
00609 drupal_set_html_head('<meta http-equiv="refresh" content="15;url=http://'. $_SERVER['SERVER_NAME'] . $basename .'/dbsf/ssaha2_result/'. $submission_uid .'" />');
00610 }
00611 }
00612 return $content;
00613 }
00614
00615
00616