123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809 |
- <?php
- function tripal_analysis_node_info() {
- $nodes = array();
- $nodes['chado_analysis'] = array(
- 'name' => t('Analysis'),
- 'base' => 'chado_analysis',
- 'description' => t('An analysis'),
- 'has_title' => TRUE,
- 'locked' => TRUE,
- 'chado_node_api' => array(
- 'base_table' => 'analysis',
- 'hook_prefix' => 'chado_analysis',
- 'record_type_title' => array(
- 'singular' => t('Analysis'),
- 'plural' => t('Analyses')
- ),
- 'sync_filters' => array(
- 'type_id' => FALSE,
- 'organism_id' => FALSE,
- 'checkboxes' => array('name'),
- ),
- )
- );
- return $nodes;
- }
- function chado_analysis_chado_node_sync_form($form, &$form_state) {
- if (array_key_exists('sync', $form) and array_key_exists('ids', $form['sync'])) {
- $form['sync']['ids']['#prefix'] .= t('Please note that if analyses exist
- that were created by other Tripal modules (e.g. Tripal Analysis Blast)
- then you should sync those using that module\'s sync interface. Otherwise
- they may not have all of the proper functionality.');
- }
- return $form;
- }
- function chado_analysis_form($node, &$form_state) {
- $form = array();
-
-
-
-
-
-
-
-
-
- $analysis_id = null;
- $analysisname = '';
- $program = '';
- $programversion = '';
- $algorithm = '';
- $sourcename = '';
- $sourceversion = '';
- $sourceuri = '';
- $timeexecuted = '';
- $description = '';
- $d_removed = array();
- $num_new = 0;
-
- if (property_exists($node, 'analysis')) {
- $analysis = $node->analysis;
- $analysis = chado_expand_var($analysis, 'field', 'analysis.description');
- $analysis_id = $analysis->analysis_id;
-
- $analysisname = $analysis->name;
- $program = $analysis->program;
- $programversion = $analysis->programversion;
- $algorithm = $analysis->algorithm;
- $sourcename = $analysis->sourcename;
- $sourceversion = $analysis->sourceversion;
- $sourceuri = $analysis->sourceuri;
- $timeexecuted = $analysis->timeexecuted;
- $description = $analysis->description;
- $analysis_type = $node->type;
-
- $form['analysis_id'] = array(
- '#type' => 'value',
- '#value' => $analysis->analysis_id,
- );
- }
-
-
- if (array_key_exists('values', $form_state)) {
- $analysisname = $form_state['values']['analysisname'];
- $program = $form_state['values']['program'];
- $programversion = $form_state['values']['programversion'];
- $algorithm = $form_state['values']['algorithm'];
- $sourcename = $form_state['values']['sourcename'];
- $sourceversion = $form_state['values']['sourceversion'];
- $sourceuri = $form_state['values']['sourceuri'];
- $timeexecuted = $form_state['values']['timeexecuted'];
- $description = $form_state['values']['description'];
- $d_removed = $form_state['values']['removed'];
- $num_new = $form_state['values']['num_new'] ? $form_state['values']['num_new'] : 0;
- $analysis_type = $form_state['values']['analysis_type'];
- }
-
-
- if (array_key_exists('input', $form_state) and !empty($form_state['input'])) {
- $analysisname = $form_state['input']['analysisname'];
- $program = $form_state['input']['program'];
- $programversion = $form_state['input']['programversion'];
- $algorithm = $form_state['input']['algorithm'];
- $sourcename = $form_state['input']['sourcename'];
- $sourceversion = $form_state['input']['sourceversion'];
- $sourceuri = $form_state['input']['sourceuri'];
- $timeexecuted = $form_state['input']['timeexecuted'];
- $description = $form_state['input']['description'];
- $d_removed = isset($form_state['input']['removed']) ? $form_state['input']['removed'] : array();
- $num_new = isset($form_state['input']['num_new']) ? $form_state['input']['num_new'] : 0;
- $analysis_type = isset($form_state['input']['analysis_type']) ? $form_state['input']['analysis_type'] : '';
- }
- $form['title']= array(
- '#type' => 'value',
- '#default_value' => $node->title,
- );
- $form['instructions'] = array(
- '#markup' => t('When adding any type of data it is good to associate it with
- an analysis so that site visitors can identify the source of the data including
- necessary materials and methods. The fields below imply that all analyses
- are derived from some software package. But, data can also be derived via retreival
- from an external source or an analysis pipeline with multipel software components.
- In these cases, provide values for the fields below that best makes sense
- '),
- );
- $form['analysisname']= array(
- '#type' => 'textfield',
- '#title' => t('Analysis Name'),
- '#required' => TRUE,
- '#default_value' => $analysisname,
- '#description' => t("This should be a brief name that
- describes the analysis succintly. This name will helps the user find analyses."),
- );
- $form['program']= array(
- '#type' => 'textfield',
- '#title' => t('Program, Pipeline Name or Method Name'),
- '#required' => TRUE,
- '#default_value' => $program,
- '#description' => t("Program name, e.g. blastx, blastp, sim4, genscan. If the analysis was not derived from a software package, provide a very brief description of the pipeline or method."),
- );
- $form['programversion']= array(
- '#type' => 'textfield',
- '#title' => t('Program, Pipeline or Method version'),
- '#required' => TRUE,
- '#default_value' => $programversion,
- '#description' => t("Version description, e.g. TBLASTX 2.0MP-WashU [09-Nov-2000]. Enter 'n/a' if no version is available or applicable."),
- );
- $form['algorithm']= array(
- '#type' => 'textfield',
- '#title' => t('Algorithm'),
- '#required' => FALSE,
- '#default_value' => $algorithm,
- '#description' => t("Algorithm name, e.g. blast."),
- );
- $form['sourcename']= array(
- '#type' => 'textfield',
- '#title' => t('Source Name'),
- '#required' => TRUE,
- '#default_value' => $sourcename,
- '#description' => t('The name of the source data. This could be a file name, data set name or a
- small description for how the data was collected. For long descriptions use the description field below'),
- );
- $form['sourceversion']= array(
- '#type' => 'textfield',
- '#title' => t('Source Version'),
- '#required' => FALSE,
- '#default_value' => $sourceversion,
- '#description' => t('If the source dataset has a version, include it here'),
- );
- $form['sourceuri']= array(
- '#type' => 'textfield',
- '#title' => t('Source URI'),
- '#required' => FALSE,
- '#default_value' => $sourceuri,
- '#description' => t("This is a permanent URL or URI for the source of the analysis.
- Someone could recreate the analysis directly by going to this URI and
- fetching the source data (e.g. the blast database, or the training model)."),
- );
-
- $default_time = $timeexecuted;
- $year = preg_replace("/^(\d+)-\d+-\d+ .*/", "$1", $default_time);
- $month = preg_replace("/^\d+-0?(\d+)-\d+ .*/", "$1", $default_time);
- $day = preg_replace("/^\d+-\d+-0?(\d+) .*/", "$1", $default_time);
-
- if (!$default_time) {
- $default_time = time();
- $year = format_date($default_time, 'custom', 'Y');
- $month = format_date($default_time, 'custom', 'n');
- $day = format_date($default_time, 'custom', 'j');
- }
- $form['timeexecuted']= array(
- '#type' => 'date',
- '#title' => t('Time Executed'),
- '#required' => TRUE,
- '#default_value' => array(
- 'year' => $year,
- 'month' => $month,
- 'day' => $day,
- ),
- );
- $form['description']= array(
- '#type' => 'text_format',
- '#rows' => 15,
- '#title' => t('Materials & Methods (Description and/or Program Settings)'),
- '#required' => FALSE,
- '#default_value' => $description,
- '#description' => t('Please provide all necessary information to allow
- someone to recreate the analysis, including materials and methods
- for collection of the source data and performing the analysis'),
- );
-
-
-
- $instructions = t('To add additional properties to the drop down. ' . l("Add terms to the analysis_property vocabulary", "admin/tripal/loaders/chado_cv/cvterm/add") . ".");
- $prop_cv = tripal_get_default_cv('analysisprop', 'type_id');
- $cv_id = $prop_cv ? $prop_cv->cv_id : NULL;
- $details = array(
- 'property_table' => 'analysisprop',
- 'chado_id' => $analysis_id,
- 'cv_id' => $cv_id,
- 'fieldset_title' => 'Properties',
- 'additional_instructions' => $instructions
- );
- chado_add_node_form_properties($form, $form_state, $details);
- return $form;
- }
- function chado_analysis_validate($node, $form, &$form_state) {
-
- tripal_analysis_validate($node, $form, $form_state);
- }
- function tripal_analysis_validate($node, $form, &$form_state) {
-
-
-
-
- if($node->op != 'Save') {
- return;
- }
-
-
- if (is_null($node->nid) and property_exists($node, 'analysis_id') and $node->analysis_id != 0) {
- return;
- }
-
- $node->analysisname = trim($node->analysisname);
- $node->program = trim($node->program);
- $node->programversion = trim($node->programversion);
- $node->algorithm = trim($node->algorithm);
- $node->sourcename = trim($node->sourcename);
- $node->sourceversion = trim($node->sourceversion);
- $node->sourceuri = trim($node->sourceuri);
-
- if (!is_null($node->nid)) {
-
- $values = array('analysis_id' => $node->analysis_id);
- $result = chado_select_record('analysis', array('*'), $values);
- $analysis = $result[0];
-
- if ($analysis->name != $node->analysisname) {
- $values = array('name' => $node->analysisname);
- $result = chado_select_record('analysis', array('analysis_id'), $values);
- if ($result and count($result) > 0) {
- form_set_error('analysisname', 'Cannot update the analysis with this analysis name. An analysis with this name already exists.');
- return;
- }
- }
-
-
- if ($analysis->program != $node->program or $analysis->programversion != $node->programversion or
- $analysis->sourcename != $node->sourcename) {
- $values = array(
- 'program' => $node->program,
- 'programversion' => $node->programversion,
- 'sourcename' => $node->sourcename,
- );
- $result = chado_select_record('analysis', array('analysis_id'), $values);
- if ($result and count($result) > 0) {
- if ($analysis->program != $node->program) {
- $field = 'program';
- }
- if ($analysis->programversion != $node->programversion) {
- $field = 'programversion';
- }
- if ($analysis->sourcename != $node->sourcename) {
- $field = 'sourcename';
- }
- form_set_error($field, 'Cannot update the analysis with this program,
- program version and source name. An analysis with these values already exists.');
- return;
- }
- }
- }
-
- else {
- $values = array(
- 'program' => $node->program,
- 'programversion' => $node->programversion,
- 'sourcename' => $node->sourcename,
- );
- $analysis = chado_select_record('analysis', array('analysis_id'), $values);
- if ($analysis and count($analysis) > 0) {
- form_set_error('program', 'Cannot add the analysis with this program,
- program version and source name. An analysis with these values already exists.');
- return;
- }
-
-
-
- $values = array('name' => $node->analysisname);
- $result = chado_select_record('analysis', array('analysis_id'), $values);
- if ($result and count($result) > 0) {
- form_set_error('analysisname', 'Cannot add the analysis with this analysis name. An analysis with this name already exists.');
- return;
- }
- }
- }
- function chado_analysis_insert($node) {
- $node->analysisname = trim($node->analysisname);
- $node->program = trim($node->program);
- $node->programversion = trim($node->programversion);
- $node->algorithm = trim($node->algorithm);
- $node->sourcename = trim($node->sourcename);
- $node->sourceversion = trim($node->sourceversion);
- $node->sourceuri = trim($node->sourceuri);
- $node->description = trim($node->description['value']);
-
-
-
- if (!property_exists($node, 'analysis_id')) {
-
- $time = $node->timeexecuted;
- $month = $time['month'];
- $day = $time['day'];
- $year = $time['year'];
- $timestamp = $month . '/' . $day . '/' . $year;
-
- $values = array(
- 'name' => $node->analysisname,
- 'description' => $node->description,
- 'program' => $node->program,
- 'programversion' => $node->programversion,
- 'algorithm' => $node->algorithm,
- 'sourcename' => $node->sourcename,
- 'sourceversion' => $node->sourceversion,
- 'sourceuri' => $node->sourceuri,
- 'timeexecuted' => $timestamp
- );
- $analysis = chado_insert_record('analysis', $values);
- if (!$analysis) {
- drupal_set_message(t('Unable to add analysis.', 'warning'));
- tripal_report_error('tripal_analysis', TRIPAL_ERROR, 'Insert analysis: Unable to create analysis where values:%values',
- array('%values' => print_r($values, TRUE)));
- return;
- }
- $analysis_id = $analysis['analysis_id'];
-
- $details = array(
- 'property_table' => 'analysisprop',
- 'base_table' => 'analysis',
- 'foreignkey_name' => 'analysis_id',
- 'foreignkey_value' => $analysis_id
- );
- chado_update_node_form_properties($node, $details);
- }
- else {
- $analysis_id = $node->analysis_id;
- }
-
-
- $check_org_id = chado_get_id_from_nid('analysis', $node->nid);
- if (!$check_org_id) {
- $record = new stdClass();
- $record->nid = $node->nid;
- $record->vid = $node->vid;
- $record->analysis_id = $analysis_id;
- drupal_write_record('chado_analysis', $record);
- }
-
-
- $node->analysis = $analysis;
- $node->analysis_id = $analysis_id;
- }
- function chado_analysis_delete($node) {
- $analysis_id = chado_get_id_from_nid('analysis', $node->nid);
-
-
- if (!$analysis_id) {
- return;
- }
-
- $sql_del = "DELETE FROM {chado_analysis} WHERE nid = :nid AND vid = :vid";
- db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
- $sql_del = "DELETE FROM {node} WHERE nid = :nid AND vid = :vid";
- db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
- $sql_del = "DELETE FROM {node_revision} WHERE nid = :nid AND vid = :vid";
- db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
-
- chado_query("DELETE FROM {analysis} WHERE analysis_id = :analysis_id", array(':analysis_id' => $analysis_id));
- }
- function chado_analysis_update($node) {
- $node->analysisname = trim($node->analysisname);
- $node->program = trim($node->program);
- $node->programversion = trim($node->programversion);
- $node->algorithm = trim($node->algorithm);
- $node->sourcename = trim($node->sourcename);
- $node->sourceversion = trim($node->sourceversion);
- $node->sourceuri = trim($node->sourceuri);
- $node->description = trim($node->description['value']);
-
- $time = $node->timeexecuted;
- $month = $time['month'];
- $day = $time['day'];
- $year = $time['year'];
- $timestamp = $month . '/' . $day . '/' . $year;
-
- $analysis_id = chado_get_id_from_nid('analysis', $node->nid);
- $match = array(
- 'analysis_id' => $node->analysis_id,
- );
- $values = array(
- 'name' => $node->analysisname,
- 'description' => $node->description,
- 'program' => $node->program,
- 'programversion' => $node->programversion,
- 'algorithm' => $node->algorithm,
- 'sourcename' => $node->sourcename,
- 'sourceversion' => $node->sourceversion,
- 'sourceuri' => $node->sourceuri,
- 'timeexecuted' => $timestamp,
- 'analysis_id' => $analysis_id
- );
- $status = chado_update_record('analysis', $match, $values);
- if (!$status) {
- drupal_set_message(t('Unable to update analysis.', 'warning'));
- tripal_report_error('tripal_analysis', TRIPAL_ERROR, 'Update analysis: Unable to update analysis where values: %values',
- array('%values' => print_r($values, TRUE)));
- }
-
-
- $details = array(
- 'property_table' => 'analysisprop',
- 'base_table' => 'analysis',
- 'foreignkey_name' => 'analysis_id',
- 'foreignkey_value' => $analysis_id
- );
- chado_update_node_form_properties($node, $details);
- }
- function chado_analysis_load($nodes) {
- foreach ($nodes as $nid => $node) {
-
- $analysis_id = chado_get_id_from_nid('analysis', $nid);
-
-
- if (!$analysis_id) {
- continue;
- }
-
- $values = array('analysis_id' => $analysis_id);
- $analysis = chado_generate_var('analysis', $values);
-
- $analysis = chado_expand_var($analysis, 'field', 'analysis.description');
- $nodes[$nid]->analysis = $analysis;
-
- $node->title = chado_get_node_title($node);
- }
- }
- function tripal_analysis_node_access($node, $op, $account) {
- $node_type = $node;
- if (is_object($node)) {
- $node_type = $node->type;
- }
- if($node_type == 'chado_analysis') {
- if ($op == 'create') {
- if (!user_access('create chado_analysis content', $account)) {
- return NODE_ACCESS_DENY;
- }
- return NODE_ACCESS_ALLOW;
- }
- if ($op == 'update') {
- if (!user_access('edit chado_analysis content', $account)) {
- return NODE_ACCESS_DENY;
- }
- }
- if ($op == 'delete') {
- if (!user_access('delete chado_analysis content', $account)) {
- return NODE_ACCESS_DENY;
- }
- }
- if ($op == 'view') {
- if (!user_access('access chado_analysis content', $account)) {
- return NODE_ACCESS_DENY;
- }
- }
- return NODE_ACCESS_IGNORE;
- }
- }
- function tripal_analysis_node_view($node, $view_mode, $langcode) {
- switch ($node->type) {
- case 'chado_analysis':
-
- if ($view_mode == 'full') {
- $node->content['tripal_analysis_base'] = array(
- '#theme' => 'tripal_analysis_base',
- '#node' => $node,
- '#tripal_toc_id' => 'base',
- '#tripal_toc_title' => 'Overview',
- '#weight' => -100,
- );
- $node->content['tripal_analysis_properties'] = array(
- '#theme' => 'tripal_analysis_properties',
- '#node' => $node,
- '#tripal_toc_id' => 'properties',
- '#tripal_toc_title' => 'Properties',
- );
- }
- if ($view_mode == 'teaser') {
- $node->content['tripal_analysis_teaser'] = array(
- '#theme' => 'tripal_analysis_teaser',
- '#node' => $node,
- );
- }
- break;
- }
- }
- function tripal_analysis_node_presave($node) {
- $name = '';
- $program = '';
- $programversion = '';
- $sourcename = '';
-
-
-
-
-
-
-
-
-
-
-
- if (property_exists($node, 'program') and
- property_exists($node, 'programversion') and
- property_exists($node, 'sourcename')) {
- $name = $node->analysisname;
- $program = $node->program;
- $programversion = $node->programversion;
- $sourcename = $node->sourcename;
-
- $node->title = "$program ($programversion) $sourcename";
- if ($name) {
- $node->title = $name;
- }
-
-
- }
- else if (property_exists($node, 'analysis')) {
- $name = $node->analysis->name;
- $program = $node->analysis->program;
- $programversion = $node->analysis->programversion;
- $sourcename = $node->analysis->sourcename;
-
- $node->title = "$program ($programversion) $sourcename";
- if ($name) {
- $node->title = $name;
- }
-
- }
- }
- function tripal_analysis_node_insert($node) {
- switch ($node->type) {
- case 'chado_analysis':
-
-
-
- $analysis_id = chado_get_id_from_nid('analysis', $node->nid);
- $values = array('analysis_id' => $analysis_id);
- $analysis = chado_generate_var('analysis', $values);
- $node->analysis = $analysis;
-
- $node->title = chado_get_node_title($node);
-
- chado_set_node_url($node);
- break;
- }
- }
- function tripal_analysis_node_update($node) {
- switch ($node->type) {
- case 'chado_analysis':
-
- $node->title = chado_get_node_title($node);
-
- chado_set_node_url($node);
- break;
- }
- }
- function chado_analysis_chado_node_default_title_format() {
- return '[analysis.name]';
- }
- function chado_analysis_chado_node_default_url_format() {
- return '/analysis/[analysis.analysis_id]';
- }
|