123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536 |
- <?php
- function tripal_analysis_admin() {
-
-
-
- $form = array();
-
-
-
- $active_jobs = FALSE;
- if (tripal_get_module_active_jobs('tripal_organism')) {
- $active_jobs = TRUE;
- }
-
- if (!$active_jobs) {
-
- get_tripal_analysis_admin_form_sync_set($form);
- get_tripal_analysis_admin_form_cleanup_set($form);
- }
- else {
- $form['notice'] = array(
- '#type' => 'fieldset',
- '#title' => t('Analysis Management Temporarily Unavailable')
- );
- $form['notice']['message'] = array(
- '#value' => t('Currently, analysis management jobs are waiting or are running. . Managemment features have been hidden until these jobs complete. Please check back later once these jobs have finished. You can view the status of pending jobs in the Tripal jobs page.'),
- );
- }
-
-
- $sql = "SELECT modulename FROM {tripal_analysis}";
- $result = db_query($sql);
- $counter = 0;
- while ($data = $result->fetchObject()) {
-
- $func = $data->modulename . "_get_settings";
- $functions = get_defined_functions();
- $settings;
- foreach ($functions['user'] as $function) {
- if ($function == $func) {
- $settings = $func();
- }
- }
-
- if ($settings) {
-
- $form["field$counter"] = array(
- '#type' => 'fieldset',
- '#title' => "$settings->title",
- '#collapsible' => TRUE
- );
- $form["field$counter"]["$settings->title"] = $settings->form;
- }
- $counter ++;
- }
- return system_settings_form($form);
- }
- function get_tripal_analysis_admin_form_taxonomy_set(&$form) {
- $form['taxonify'] = array(
- '#type' => 'fieldset',
- '#title' => t('Assign Drupal Taxonomy to Analysis Features')
- );
-
- $sql = "SELECT * FROM {analysis} ORDER BY name";
- $lib_rset = chado_query($sql);
-
- $lib_boxes = array();
- while ($analysis = $lib_rset->fetchObject()) {
- $lib_boxes[$analysis->analysis_id] = "$analysis->name";
- }
- $form['taxonify']['description'] = array(
- '#type' => 'item',
- '#value' => t("Drupal allows for assignment of \"taxonomy\" or catagorical terms to " .
- "nodes. These terms allow for advanced filtering during searching. This option allows " .
- "for setting taxonomy only for features that belong to the selected analyses below. All other features will be unaffected. To set taxonomy for all features in the site see the Feature Administration page."),
- '#weight' => 1,
- );
- $form['taxonify']['tx-analyses'] = array(
- '#title' => t('Analyses'),
- '#type' => t('checkboxes'),
- '#description' => t("Check the analyses whose features you want to reset taxonomy. Note: this list contains all analyses, even those that may not be synced."),
- '#required' => FALSE,
- '#prefix' => '<div id="lib_boxes">',
- '#suffix' => '</div>',
- '#options' => $lib_boxes,
- '#weight' => 2
- );
- $form['taxonify']['tx-button'] = array(
- '#type' => 'submit',
- '#value' => t('Set Feature Taxonomy'),
- '#weight' => 3
- );
- }
- function get_tripal_analysis_admin_form_reindex_set(&$form) {
-
- $form['reindex'] = array(
- '#type' => 'fieldset',
- '#title' => t('Reindex Analysis Features')
- );
-
- $sql = "SELECT * FROM {analysis} ORDER BY name";
- $lib_rset = chado_query($sql);
-
- $lib_boxes = array();
- while ($analysis = $lib_rset->fetchObject()) {
- $lib_boxes[$analysis->analysis_id] = "$analysis->name";
- }
- $form['reindex']['description'] = array(
- '#type' => 'item',
- '#value' => t("This option allows for reindexing of only those features that belong to the selected analyses below. All other features will be unaffected. To reindex all features in the site see the Feature Administration page."),
- '#weight' => 1,
- );
- $form['reindex']['re-analyses'] = array(
- '#title' => t('Libraries'),
- '#type' => t('checkboxes'),
- '#description' => t("Check the analyses whoee features you want to reindex. Note: this list contains all analyses, even those that may not be synced."),
- '#required' => FALSE,
- '#prefix' => '<div id="lib_boxes">',
- '#suffix' => '</div>',
- '#options' => $lib_boxes,
- '#weight' => 2,
- );
- $form['reindex']['re-button'] = array(
- '#type' => 'submit',
- '#value' => t('Reindex Features'),
- '#weight' => 3,
- );
- }
- function get_tripal_analysis_admin_form_cleanup_set(&$form) {
- $form['cleanup'] = array(
- '#type' => 'fieldset',
- '#title' => t('Clean Up')
- );
- $form['cleanup']['description'] = array(
- '#type' => 'item',
- '#value' => t("With Drupal and chado residing in different databases " .
- "it is possible that nodes in Drupal and analyses in Chado become " .
- "\"orphaned\". This can occur if an analysis node in Drupal is " .
- "deleted but the corresponding chado analysis is not and/or vice " .
- "versa. Click the button below to resolve these discrepancies."),
- '#weight' => 1,
- );
- $form['cleanup']['button'] = array(
- '#type' => 'submit',
- '#value' => t('Clean up orphaned analyses'),
- '#weight' => 2,
- );
- }
- function get_tripal_analysis_admin_form_sync_set(&$form) {
-
- $form['sync'] = array(
- '#type' => 'fieldset',
- '#title' => t('Sync Analyses')
- );
-
-
-
- $active_jobs = FALSE;
- if (tripal_get_module_active_jobs('tripal_analysis')) {
- $active_jobs = TRUE;
- }
- if (!$active_jobs) {
-
- $sql = "SELECT * FROM {analysis} ORDER BY name";
- $ana_rset = chado_query($sql);
-
-
-
-
- $ana_boxes = array();
- $added = 0;
- while ($analysis = $ana_rset->fetchObject()) {
-
-
- $sql = "SELECT * FROM {chado_analysis} WHERE analysis_id = :analysis_id";
- if (!db_query($sql, array(':analysis_id' => $analysis->analysis_id))->fetchObject()) {
- $ana_boxes[$analysis->analysis_id] = "$analysis->name";
- $added++;
- }
- }
-
-
- if ($added > 0) {
- $ana_boxes['all'] = "All analyses";
- $form['sync']['analyses'] = array(
- '#title' => t('Available analyses'),
- '#type' => t('checkboxes'),
- '#description' => t("Check the analyses you want to sync. Drupal " .
- "content will be created for each of the analyses listed above. " .
- "Select 'All analyses' to sync all of them."),
- '#required' => FALSE,
- '#prefix' => '<div id="ana_boxes">',
- '#suffix' => '</div>',
- '#options' => $ana_boxes,
- );
- $form['sync']['button'] = array(
- '#type' => 'submit',
- '#value' => t('Submit Sync Job')
- );
- }
-
- else {
- $form['sync']['value'] = array(
- '#value' => t('All analyses in Chado are currently synced with Drupal.')
- );
- }
- }
-
- else {
- $form['sync']['value'] = array(
- '#value' => t('Currently, jobs exist related to chado analyses. Please check back later for analyses that can by synced once these jobs have finished. You can view the status of pending jobs in the Tripal jobs page.')
- );
- }
- }
- function tripal_analysis_admin_validate($form, &$form_state) {
- global $user;
- $job_args = array();
- if ($form_state['values']['op'] == t('Submit Sync Job')) {
-
-
- $analyses = $form_state['values']['analyses'];
- $do_all = FALSE;
- $to_sync = array();
- foreach ($analyses as $analysis_id) {
- if (preg_match("/^all$/i", $analysis_id)) {
- $do_all = TRUE;
- }
- if ($analysis_id and preg_match("/^\d+$/i", $analysis_id)) {
-
- $sql = "SELECT * FROM {analysis} WHERE analysis_id = :analysis_id";
- $analysis = chado_query($sql, array(':analysis_id' => $analysis_id))->fetchObject();
- $to_sync[$analysis_id] = $analysis->name;
- }
- }
-
- if ($do_all) {
- tripal_add_job('Sync all analyses', 'tripal_analysis', 'tripal_analysis_sync_analyses', $job_args, $user->uid);
- }
- else{
- foreach ($to_sync as $analysis_id => $name) {
- $job_args[0] = $analysis_id;
- tripal_add_job("Sync analysis: $name", 'tripal_analysis', 'tripal_analysis_sync_analyses', $job_args, $user->uid);
- }
- }
- }
-
-
- if ($form_state['values']['op'] == t('Reindex Features')) {
- global $user;
- $job_args = array();
- $analyses = $form_state['values']['re-analyses'];
- foreach ($analyses as $analysis_id) {
- if ($analysis_id and preg_match("/^\d+$/i", $analysis_id)) {
-
- $sql = "SELECT * FROM {analysis} WHERE analysis_id = :analysis_id";
- $analysis = chado_query($sql, array(':analysis_id' => $analysis_id))->fetchObject();
- $job_args[0] = $analysis_id;
- tripal_add_job("Reindex features for analysis: $analysis->name", 'tripal_analysis',
- 'tripal_analysis_reindex_features', $job_args, $user->uid);
- }
- }
- }
-
-
- if ($form_state['values']['op'] == t('Set Feature Taxonomy')) {
- global $user;
- $job_args = array();
- $analyses = $form_state['values']['tx-analyses'];
- foreach ($analyses as $analysis_id) {
- if ($analysis_id and preg_match("/^\d+$/i", $analysis_id)) {
-
- $sql = "SELECT * FROM {analysis} WHERE analysis_id = :analysis_id";
- $analysis = chado_query($sql, array(':analysis_id' => $analysis_id))->fetchObject();
- $job_args[0] = $analysis_id;
- tripal_add_job("Set taxonomy for features in analysis: $analysis->name", 'tripal_analysis',
- 'tripal_analysis_taxonify_features', $job_args, $user->uid);
- }
- }
- }
-
-
- if ($form_state['values']['op'] == t('Clean up orphaned analyses')) {
- tripal_add_job('Cleanup orphaned analyses', 'tripal_analysis',
- 'tripal_analyses_cleanup', $job_args, $user->uid);
- }
- }
- function tripal_analysis_sync_analyses($analysis_id = NULL, $job_id = NULL) {
- global $user;
- $page_content = '';
- if (!$analysis_id) {
- $sql = "SELECT Analysis_id, name, description, program, " .
- " programversion, algorithm, sourcename, sourceversion, sourceuri, " .
- " timeexecuted " .
- "FROM {analysis} ";
- $results = chado_query($sql);
- }
- else {
- $sql = "SELECT Analysis_id, name, description, program, " .
- " programversion, algorithm, sourcename, sourceversion, sourceuri, " .
- " timeexecuted " .
- "FROM {analysis} " .
- "WHERE analysis_id = :analysis_id";
- $results = chado_query($sql, array(':analysis_id' => $analysis_id));
- }
-
-
- $sql = "SELECT * FROM {chado_analysis} " .
- "WHERE analysis_id = :analysis_id";
- while ($analysis = $results->fetchObject()) {
- print "syncing analysis ";
- print $analysis->name;
- print ", ";
- print $analysis->analysis_id;
- print "\n";
-
-
- if (!db_query($sql, array(':analysis_id' => $analysis->analysis_id))->fetchObject()) {
- $new_node = new stdClass();
-
- $sql = "SELECT * FROM {analysisprop}
- WHERE analysis_id = :analysis_id
- AND type_id =
- (SELECT cvterm_id from {cvterm} where name = :name)
- ";
- $analysis_type = chado_query($sql, array(':analysis_id' => $analysis->analysis_id, ':name' => "analysis_type"))->fetchObject();
-
-
- if ($analysis_type) {
-
- if ($analysis_type->value == 'tripal_analysis_unigene') {
- $new_node->type = 'chado_analysis_unigene';
-
- }
- elseif ($analysis_type->value == 'tripal_analysis_blast') {
- $new_node->type = 'chado_analysis_blast';
-
- }
- elseif ($analysis_type->value == 'tripal_analysis_interpro') {
- $new_node->type = 'chado_analysis_interpro';
-
- }
- elseif ($analysis_type->value == 'tripal_analysis_kegg' ) {
- $new_node->type = 'chado_analysis_kegg';
- }
- else {
- $new_node->type = 'chado_analysis';
- }
-
- }
- else {
- $new_node->type = 'chado_analysis';
- }
- print "analysis type is $new_node->type\n";
- $new_node->uid = $user->uid;
- $new_node->analysis_id = $analysis->analysis_id;
- $new_node->analysisname = $analysis->name;
- $new_node->description = $analysis->description;
- $new_node->program = $analysis->program;
- $new_node->programversion = $analysis->programversion;
- $new_node->algorithm = $analysis->algorithm;
- $new_node->sourcename = $analysis->sourcename;
- $new_node->sourceversion = $analysis->sourceversion;
- $new_node->sourceuri = $analysis->sourceuri;
- $new_node->timeexecuted = $analysis->timeexecuted;
-
-
- if ($new_node->analysisname) {
- $new_node->title = $new_node->analysisname;
- }
- else {
-
- $new_node->title = "$analysis->program ($analysis->programversion)";
- }
- node_validate($new_node);
- $errors = form_get_errors();
- if ($errors) {
- print_r($errors);
- }
- else{
-
- $node = node_submit($new_node);
- node_save($node);
- if ($node->nid) {
- $page_content .= "Added $new_node->title<br />";
- }
- }
- }
- else {
- $page_content .= "Skipped $new_node->title<br />";
- }
- }
- return $page_content;
- }
- function tripal_analyses_cleanup($dummy = NULL, $job_id = NULL) {
- return tripal_core_clean_orphaned_nodes('analysis', $job_id);
-
- }
|