diff --git a/README.md b/README.md index 971025c..2a8b601 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ The Mainlab Chado Loader is created by Main Bioinformatics Lab (Main Lab) at Was - Drupal 7.x ## Version -1.0.0 +2.0.0 ##Download The MainLab Chado Loader module can be download from GitHub: @@ -76,7 +76,7 @@ After downloading the module, extract it into your site's module directory The file name should be 'mcl_template_stock_gdr.inc' ``` ii. Place the newly created class file under the template directory. - The template directory is 'mcl/include/class/template/module/'. + The template directory is 'mcl/templates'. b. Go to the admin page. diff --git a/includes/admin/mcl.admin.data_valid.inc b/includes/admin/mcl.admin.data_valid.inc index a0e4576..bed5af9 100644 --- a/includes/admin/mcl.admin.data_valid.inc +++ b/includes/admin/mcl.admin.data_valid.inc @@ -87,7 +87,7 @@ function _mcl_get_mcl_data_valid_type_form(&$form) { // Creates 'Delete' link. $confirm_attr = array( 'attributes' => array( - 'id' => 'delete_data_valid_type_' . $data_valid_type_id, + 'id' => 'delete_data_valid_type_' . $data_valid_type_id, 'class' => array('use-ajax', 'mcl-confirm'), ) ); @@ -229,21 +229,16 @@ function _mcl_get_mcl_data_valid_form(&$form, $target_data_valid_type_id = '') { $label = 'Add cvterm ID'; } $form['data_valid'][$id_fieldset][$id_value] = array( - '#type' => 'textfield', - '#title' => $title, - '#description' => $desc, - '#attributes' => array('style' => 'width:250px;'), + '#type' => 'textfield', + '#title' => $title, + '#description' => $desc, + '#default_value' => '', + '#attributes' => array('style' => 'width:250px;'), ); $form['data_valid'][$id_fieldset][$id_add_btn] = array( '#type' => 'submit', '#name' => $id_add_btn, '#value' => $label, - '#ajax' => array( - 'callback' => "mcl_admin_data_valid_form_ajax_callback", - 'wrapper' => 'mcl-admin-data-valid-form', - 'effect' => 'fade', - 'method' => 'replace', - ), ); } } @@ -255,65 +250,6 @@ function _mcl_get_mcl_data_valid_form(&$form, $target_data_valid_type_id = '') { * @param $form_state */ function mcl_admin_data_valid_form_ajax_callback($form, &$form_state) { - - // Checks for errors. - if (form_get_errors()) { - return $form; - } - - // Gets the trigger element. - $trigger_elem = $form_state['triggering_element']['#name']; - - // If "data_valid_type_btn" button is clicked. - if ($trigger_elem == "data_valid_type_btn") { - - // Gets the new data valid type. - $type = trim($form_state['values']['data_valid_type']['data_valid_types']['add_data_valid_type']['type']); - $cv_name = trim($form_state['values']['data_valid_type']['data_valid_types']['add_data_valid_type']['cv_name']); - - // Sets the type. - $details = array('type' => $type); - - // Gets cv_id. - if ($cv_name) { - $cv = MCL_CHADO_CV::getCV($cv_name); - $details['cv_id'] = $cv->getCvID(); - } - $mcl_data_valid_type = new MCL_DATA_VALID_TYPE($details); - if (!$mcl_data_valid_type->insert()) { - drupal_set_message("Failed to add a new type : $type"); - } - _mcl_get_mcl_data_valid_type_form($form); - } - - // If "data_valid_btn" button is clicked. - else if (preg_match("/data_valid_btn_(\d+)_(\d+)/", $trigger_elem, $matches)) { - $data_valid_type_id = $matches[1]; - $cv_id = $matches[2]; - - // Gets the value. - $id_fieldset = 'fs_' . $data_valid_type_id; - $id_value = 'value_' . $data_valid_type_id; - $value = trim($form_state['values']['data_valid'][$id_fieldset][$id_value]); - - // Add the value. - $details = array( - 'data_valid_type_id' => $data_valid_type_id, - 'name' => $value, - ); - if ($cv_id) { - $cvterm = MCL_CHADO_CVTERM::byKey(array('cvterm_id' => $value)); - $details['name'] = $cvterm->getName(); - $details['cvterm_id'] = $cvterm->getCvtermID(); - } - $data_valid = new PUBLIC_MCL_DATA_VALID($details); - if ($data_valid->insert()) { - _mcl_get_mcl_data_valid_form($form, $data_valid_type_id); - } - else { - drupal_set_message("Failed to add a new value : $value"); - } - } return $form; } @@ -392,8 +328,8 @@ function mcl_admin_data_valid_form_validate($form, &$form_state) { return; } $key = array( - 'cv_id' => $cv_id, - 'cvterm_id' => $value, + 'cv_id' => $cv_id, + 'cvterm_id' => $value, ); $cvterm = MCL_CHADO_CVTERM::byKey($key); if (!$cvterm) { @@ -411,6 +347,61 @@ function mcl_admin_data_valid_form_validate($form, &$form_state) { * @ingroup mcl_admin */ function mcl_admin_data_valid_form_submit($form, &$form_state) { - $form_state['rebuild'] = TRUE; + + // Gets the trigger element. + $trigger_elem = $form_state['triggering_element']['#name']; + + // If "data_valid_type_btn" button is clicked. + if ($trigger_elem == "data_valid_type_btn") { + + // Gets the new data valid type. + $type = trim($form_state['values']['data_valid_type']['data_valid_types']['add_data_valid_type']['type']); + $cv_name = trim($form_state['values']['data_valid_type']['data_valid_types']['add_data_valid_type']['cv_name']); + + // Sets the type. + $details = array('type' => $type); + + // Gets cv_id. + if ($cv_name) { + $cv = MCL_CHADO_CV::getCV($cv_name); + $details['cv_id'] = $cv->getCvID(); + } + $mcl_data_valid_type = new MCL_DATA_VALID_TYPE($details); + if ($mcl_data_valid_type->insert()) { + drupal_set_message("A new type added : $type"); + } + else { + drupal_set_message("Failed to add a new type : $type"); + } + } + + // If "data_valid_btn" button is clicked. + else if (preg_match("/data_valid_btn_(\d+)_(\d+)/", $trigger_elem, $matches)) { + $data_valid_type_id = $matches[1]; + $cv_id = $matches[2]; + + // Gets the value. + $id_fieldset = 'fs_' . $data_valid_type_id; + $id_value = 'value_' . $data_valid_type_id; + $value = trim($form_state['values']['data_valid'][$id_fieldset][$id_value]); + + // Add the value. + $details = array( + 'data_valid_type_id' => $data_valid_type_id, + 'name' => $value, + ); + if ($cv_id) { + $cvterm = MCL_CHADO_CVTERM::byKey(array('cvterm_id' => $value)); + $details['name'] = $cvterm->getName(); + $details['cvterm_id'] = $cvterm->getCvtermID(); + } + $data_valid = new PUBLIC_MCL_DATA_VALID($details); + if ($data_valid->insert()) { + drupal_set_message("A new value added : $value"); + } + else { + drupal_set_message("Failed to add a new value : $value"); + } + } } ?> diff --git a/includes/admin/mcl.admin.template.inc b/includes/admin/mcl.admin.template.inc index 342e411..d3eeb54 100644 --- a/includes/admin/mcl.admin.template.inc +++ b/includes/admin/mcl.admin.template.inc @@ -101,14 +101,16 @@ function mcl_admin_template_form_submit($form, &$form_state) { // Updates the visibility (public or private) of templates. - foreach ($form['templates'] as $template_id => $info) { - if (!preg_match("/^(\d+)$/", $template_id)) { - continue; + if (array_key_exists('templates', $form)) { + foreach ((array)$form['templates'] as $template_id => $info) { + if (!preg_match("/^(\d+)$/", $template_id)) { + continue; + } + $template = MCL_TEMPLATE::byKey(array('template_id' => $template_id)); + $public = $form_state['values']['templates'][$template_id]; + $template->setPublic($public); + $template->update(); } - $template = MCL_TEMPLATE::byKey(array('template_id' => $template_id)); - $public = $form_state['values']['templates'][$template_id]; - $template->setPublic($public); - $template->update(); } // Scans the template directory and add new templates or remove non-existance @@ -130,54 +132,56 @@ function theme_mcl_admin_template_form($variables) { $layout.= "
" . drupal_render($form['template_list']) . '
'; // Gets the template directory. - $template_path = drupal_get_path('module', 'mcl') . '/includes/class/template/module'; + $template_path = drupal_get_path('module', 'mcl') . '/templates'; // Gets all templates and populates the table with the templates. $rows = array(); - foreach ($form['templates'] as $template_id => $info) { - if (!preg_match("/^(\d+)$/", $template_id)) { - continue; - } - $template = MCL_TEMPLATE::byKey(array('template_id' => $template_id)); + if (array_key_exists('templates', $form)) { + foreach ((array)$form['templates'] as $template_id => $info) { + if (!preg_match("/^(\d+)$/", $template_id)) { + continue; + } + $template = MCL_TEMPLATE::byKey(array('template_id' => $template_id)); - // Checks the existance of the class file. - $class_file = 'mcl_template_' . strtolower($template->getTemplate()) . '.class.inc'; - $class_exists = (file_exists("$template_path/$class_file")) ? 'exists' : 'not exist'; + // Checks the existance of the class file. + $class_file = 'mcl_template_' . strtolower($template->getTemplate()) . '.class.inc'; + $class_exists = (file_exists("$template_path/$class_file")) ? 'exists' : 'not exist'; - // Gets the definition. - $description = 'N/A'; - if ($class_exists == 'exists') { - $template = MCL_TEMPLATE::getTemplateByID($template_id); - $description = $template->defineDescription(); - } + // Gets the definition. + $description = 'N/A'; + if ($class_exists == 'exists') { + $template = MCL_TEMPLATE::getTemplateByID($template_id); + $description = $template->defineDescription(); + } - $row = array( - drupal_render($form['templates'][$template_id]), - $template->getTemplateType(FALSE), - $template->getTemplate(), - $class_exists, - $description, - ); - $rows []= $row; + $row = array( + drupal_render($form['templates'][$template_id]), + $template->getTemplateType(FALSE), + $template->getTemplate(), + $class_exists, + $description, + ); + $rows []= $row; + } } - // Sets the headers. - $headers = array( - array('data' => 'Public', 'style' => 'width:10px'), - array('data' => 'Template Type', 'style' => 'width:15%'), - array('data' => 'Template', 'style' => 'width:10%'), - array('data' => 'Class File', 'style' => 'width:8%'), - 'Description', - ); - - $table_vars = array( - 'header' => $headers, - 'rows' => $rows, - 'attributes' => array(), - ); - - // Adds the template table. - $layout .= theme('table', $table_vars); - $layout .= drupal_render_children($form); - return $layout; + // Sets the headers. + $headers = array( + array('data' => 'Public', 'style' => 'width:10px'), + array('data' => 'Template Type', 'style' => 'width:15%'), + array('data' => 'Template', 'style' => 'width:10%'), + array('data' => 'Class File', 'style' => 'width:8%'), + 'Description', + ); + + $table_vars = array( + 'header' => $headers, + 'rows' => $rows, + 'attributes' => array(), + ); + + // Adds the template table. + $layout .= theme('table', $table_vars); + $layout .= drupal_render_children($form); + return $layout; } \ No newline at end of file diff --git a/includes/class/chado_table_class/chado_nd_geolocationprop.class.inc b/includes/class/chado_table_class/chado_nd_geolocationprop.class.inc index b616ce4..213abdd 100644 --- a/includes/class/chado_table_class/chado_nd_geolocationprop.class.inc +++ b/includes/class/chado_table_class/chado_nd_geolocationprop.class.inc @@ -166,7 +166,6 @@ class CHADO_ND_GEOLOCATIONPROP extends CHADO_TABLE { $fields['value'] = $this->value; $fields['rank'] = (is_numeric($this->rank)) ? $this->rank : 0; - // Updates the record. db_update('chado.nd_geolocationprop') ->fields($fields) diff --git a/includes/class/chado_table_class/chado_table.class.inc b/includes/class/chado_table_class/chado_table.class.inc index a9ded2b..1fa95bf 100644 --- a/includes/class/chado_table_class/chado_table.class.inc +++ b/includes/class/chado_table_class/chado_table.class.inc @@ -254,7 +254,7 @@ class CHADO_TABLE { * @return boolean */ public function addPropertyRanked(MCL_TEMPLATE $mcl_tmpl = NULL, $table_name, $target_field, $target_id, $type_id, $value, $rank) { - if ($value) { + if ($value != '') { // Checks duplication before adding a new property. $args = array( @@ -282,6 +282,45 @@ class CHADO_TABLE { } } + /** + * Updates one or more properties + * + * @param MCL_TEMPLATE $mcl_tmpl + * @param string $table_name + * @param string $target_field + * @param integer $target_id + * @param integer $type_id + * @param string $value + * @param string $separator + * + * @return boolean + */ + public function updateProperty(MCL_TEMPLATE $mcl_tmpl = NULL, $table_name, $target_field, $target_id, $type_id, $value) { + if ($value || $value == '0') { + + // Gets the table class. + $args = array( + $target_field => $target_id, + 'type_id' => $type_id, + ); + $class_name = strtoupper('CHADO_' . $table_name); + $obj = $class_name::byKey($args); + + + // If the property exists, update it. Otherwise add a new one. + if ($obj) { + $obj->setValue($value); + return $obj->update(); + } + else { + $args['value'] = $value; + $obj = new $class_name($args); + return $obj->insert(); + } + } + return FALSE; + } + /** * Adds a relationship. * diff --git a/includes/class/data_valid/mcl_data_valid_type.class.inc b/includes/class/data_valid/mcl_data_valid_type.class.inc index ec2902b..0cb2772 100644 --- a/includes/class/data_valid/mcl_data_valid_type.class.inc +++ b/includes/class/data_valid/mcl_data_valid_type.class.inc @@ -149,23 +149,29 @@ class MCL_DATA_VALID_TYPE extends PUBLIC_MCL_DATA_VALID_TYPE { * @return boolean */ public static function validate($data_valid_type, $value) { - if ($value) { + if ($value != '') { + // Gets data_valid_type_id. $mcl_data_valid_type = MCL_DATA_VALID_TYPE::byKey(array('type' => $data_valid_type)); - $data_valid_type_id = $mcl_data_valid_type->getDataValidTypeID(); - - // Checks the value. - $sql = " - SELECT COUNT(data_valid_id) - FROM {mcl_data_valid} - WHERE data_valid_type_id = :data_valid_type_id AND LOWER(name) = LOWER(:name) - "; - $args = array( - ':data_valid_type_id' => $data_valid_type_id, - ':name' => $value, - ); - $num = db_query($sql, $args)->fetchField(); - return ($num) ? TRUE : FALSE; + if (!$mcl_data_valid_type) { + return FALSE; + } + else { + $data_valid_type_id = $mcl_data_valid_type->getDataValidTypeID(); + + // Checks the value. + $sql = " + SELECT COUNT(data_valid_id) + FROM {mcl_data_valid} + WHERE data_valid_type_id = :data_valid_type_id AND LOWER(name) = LOWER(:name) + "; + $args = array( + ':data_valid_type_id' => $data_valid_type_id, + ':name' => $value, + ); + $num = db_query($sql, $args)->fetchField(); + return ($num) ? TRUE : FALSE; + } } return TRUE; } diff --git a/includes/class/job/mcl_job.class.inc b/includes/class/job/mcl_job.class.inc index cdc49b8..4134b01 100644 --- a/includes/class/job/mcl_job.class.inc +++ b/includes/class/job/mcl_job.class.inc @@ -14,6 +14,7 @@ class MCL_JOB extends PUBLIC_MCL_JOB { protected $user_dir = NULL; protected $job_dir = NULL; protected $log_dir = NULL; + protected $std_dir = NULL; protected $file_dir = NULL; protected $pid = NULL; @@ -88,6 +89,10 @@ class MCL_JOB extends PUBLIC_MCL_JOB { if ($log_dir) { $this->log_dir = $log_dir; } + $std_dir = $this->getPropByKey('std_dir'); + if ($std_dir) { + $this->std_dir = $std_dir; + } $file_dir = $this->getPropByKey('file_dir'); if ($file_dir) { $this->file_dir = $file_dir; @@ -142,11 +147,13 @@ class MCL_JOB extends PUBLIC_MCL_JOB { $this->user_dir = "$working_dir/$username"; $this->job_dir = $this->user_dir . '/' . $this->job_id; $this->log_dir = $this->job_dir . '/logs'; + $this->std_dir = $this->job_dir . '/std'; $this->file_dir = $this->job_dir . '/files'; $this->setPropByKey('working_dir', $this->user_dir); $this->setPropByKey('user_dir', $this->user_dir); $this->setPropByKey('job_dir', $this->job_dir); $this->setPropByKey('log_dir', $this->log_dir); + $this->setPropByKey('std_dir', $this->std_dir); $this->setPropByKey('file_dir', $this->file_dir); $this->setPropByKey('pid', $this->pid); $this->update(); @@ -154,6 +161,7 @@ class MCL_JOB extends PUBLIC_MCL_JOB { // Creates directories. mcl_create_dir($this->job_dir); mcl_create_dir($this->log_dir); + mcl_create_dir($this->std_dir); mcl_create_dir($this->file_dir); } else { @@ -197,18 +205,27 @@ class MCL_JOB extends PUBLIC_MCL_JOB { * Returns jobs that belong to the user. * * @parma integer $user_id + * @parma string $type * * @return array of MCL_UPLOAD_JOB */ - public static function getJobsByUser($user_id) { + public static function getJobsByUser($user_id, $type = NULL) { $sql = " SELECT J.job_id, J.class_name FROM {mcl_job} J WHERE J.user_id = :user_id - ORDER BY J.submit_date DESC "; - $results = db_query($sql, array(':user_id' => $user_id)); + $args =array (':user_id' => $user_id); + + // Adds conditions. + if ($type) { + $sql .= ' AND J.type = :type'; + $args[':type'] = $type; + } + + $sql .= ' ORDER BY J.submit_date DESC'; + $results = db_query($sql, $args); $mcl_jobs = array(); while ($obj = $results->fetchObject()) { $class_name = $obj->class_name; @@ -258,6 +275,17 @@ class MCL_JOB extends PUBLIC_MCL_JOB { } } + /** + * Returns the name of the std file. + * + * @param string $ext + * + * @return string + */ + public function getStdFile($ext) { + return $this->getStdDir() . '/mcl-' . date("Y-m-d-G-i-s") . '.' . $ext; + } + /** * Resets the logs. * @@ -352,7 +380,7 @@ class MCL_JOB extends PUBLIC_MCL_JOB { } /** - * Changes the working directory. Needs to update job_dir, log_dir + * Changes the working directory. Needs to update job_dir, log_dir, std_dir * and file_dir. * * @param string $working_dir @@ -364,6 +392,7 @@ class MCL_JOB extends PUBLIC_MCL_JOB { $this->setWorkingDir($working_dir); $this->setJobDir($job_dir); $this->setLogDir("$job_dir/logs"); + $this->setStdDir("$job_dir/std"); $this->setFileDir("$job_dir/files"); return $this->update(); } @@ -536,6 +565,25 @@ class MCL_JOB extends PUBLIC_MCL_JOB { $this->setPropByKey('log_dir', $log_dir); } + /** + * Retrieves the directory of the std files. + * + * @retrun string + */ + public function getStdDir() { + return $this->std_dir; + } + + /** + * Updates the directory of the std files. + * + * @param string $std_dir + */ + public function setStdDir($std_dir) { + $this->std_dir = $std_dir; + $this->setPropByKey('std_dir', $std_dir); + } + /** * Retrieves the directory of the files. * diff --git a/includes/class/job/mcl_job_upload.class.inc b/includes/class/job/mcl_job_upload.class.inc index ba59078..22566a3 100644 --- a/includes/class/job/mcl_job_upload.class.inc +++ b/includes/class/job/mcl_job_upload.class.inc @@ -45,9 +45,6 @@ class MCL_JOB_UPLOAD extends MCL_JOB { mcl_create_dir($this->csv_dir); } - // Resets 'columns' in job properties. - $this->setPropByKey('columns', array()); - // Resets new log files. if ($this->job_id) { $this->resetNewLogFiles(); @@ -713,6 +710,9 @@ class MCL_JOB_UPLOAD extends MCL_JOB { while (!feof($fdr)) { $line = trim(fgets($fdr)); + // Removes white space :   + $line = preg_replace('/\xc2\xa0/', ' ', $line); + // Exits if no data in the line. $check = preg_replace("/[\",\s]/", '', $line); if ($check == '') { @@ -902,8 +902,7 @@ class MCL_JOB_UPLOAD extends MCL_JOB { // Gets MCL_TEMPLATE object. $tmpl_obj = MCL_TEMPLATE::getTemplateClass($this, $csv_file); - // Runs the data error checking. Skips if the error checking has been - // completed. + // Runs the data error checking. Skips if the error checking has been completed. mcl_print("[$mcl_file_id] $filename", 1); mcl_print("- Running the data error checking", 2); if ($csv_file->hasPassed($this->status_int['data error']) && !$this->getForce()) { @@ -1067,36 +1066,43 @@ class MCL_JOB_UPLOAD extends MCL_JOB { // Adds log files (Warning / Errror / Dup-Data) in recent directory. $recent_dir = $this->getRecentLogDir('recent'); - $objects = scandir($recent_dir); - foreach ($objects as $object) { - if ($object === '.' or $object === '..') { - continue; - } - if (is_dir("$recent_dir/$object")) { - preg_match("/(\d+)-([A-Z])/", $object, $matches); - $status_int = $matches[1]; - $type = $matches[2]; - - // Skips new data log. - if ($type == 'N') { + if (file_exists($recent_dir)) { + $objects = scandir($recent_dir); + foreach ($objects as $object) { + if ($object === '.' or $object === '..') { continue; } + if (is_dir("$recent_dir/$object")) { + preg_match("/(\d+)-([A-Z])/", $object, $matches); + $status_int = $matches[1]; + $type = $matches[2]; + + // Skips new data log. + if ($type == 'N') { + continue; + } - // Initialzes the array. - if (!array_key_exists($type, $all_logs)) { - $all_logs[$type] = array(); - } + // Initialzes the array. + if (!array_key_exists($type, $all_logs)) { + $all_logs[$type] = array(); + } + + $files = file_scan_directory("$recent_dir/$object", "/\.log$/"); + $log_files = array(); + foreach ($files as $filepath => $file) { + preg_match("/-([A-Za-z\_]+)\.log$/", $filepath, $matches2); + $key = $matches2[1]; + $log_files []= array( + 'key' => $key, + 'filepath' => $filepath, + 'log_file' => "recent:$object:" . basename($filepath), + ); + } - $files = file_scan_directory("$recent_dir/$object", "/\.log$/"); - $log_files = array(); - foreach ($files as $filepath => $file) { - preg_match("/-([A-Za-z\_]+)\.log$/", $filepath, $matches2); - $key = $matches2[1]; - $log_files []= array( - 'key' => $key, - 'filepath' => $filepath, - 'log_file' => "recent:$object:" . basename($filepath), - ); + // Adds log files. + if (!empty($log_files)) { + $all_logs[$type][$status_int] = $log_files; + } } // Adds log files. @@ -1104,11 +1110,6 @@ class MCL_JOB_UPLOAD extends MCL_JOB { $all_logs[$type][$status_int] = $log_files; } } - - // Adds log files. - if (!empty($log_files)) { - $all_logs[$type][$status_int] = $log_files; - } } // Adds log file for new data. diff --git a/includes/class/mcl_chado_class/mcl_chado_contact.class.inc b/includes/class/mcl_chado_class/mcl_chado_contact.class.inc index 4ca37b4..90de4f2 100644 --- a/includes/class/mcl_chado_class/mcl_chado_contact.class.inc +++ b/includes/class/mcl_chado_class/mcl_chado_contact.class.inc @@ -51,8 +51,8 @@ class MCL_CHADO_CONTACT extends CHADO_CONTACT { // Gets the contacts. $names = preg_split(self::getSepRegex($separator), $contact, NULL, PREG_SPLIT_NO_EMPTY); foreach ($names as $name) { - $mcl_contact = MCL_CHADO_CONTACT::getContact(trim($name)); - if (!$mcl_contact) { + $contact = MCL_CHADO_CONTACT::getContact(trim($name)); + if (!$contact) { self::updateMsg($mcl_tmpl, 'E', "(name) = ($name) not found in contact"); $flag = FALSE; } @@ -93,8 +93,8 @@ class MCL_CHADO_CONTACT extends CHADO_CONTACT { } // Checks for duplication. - $mcl_contact = MCL_CHADO_CONTACT::byKey($args); - if ($mcl_contact) { + $contact = MCL_CHADO_CONTACT::byKey($args); + if ($contact) { self::addMsg($mcl_tmpl, 'D', 'contact', $args); } else { @@ -102,8 +102,8 @@ class MCL_CHADO_CONTACT extends CHADO_CONTACT { // Adds a new contact. $args['type_id'] = $type_id; $args['description'] = $description; - $mcl_contact = new MCL_CHADO_CONTACT($args); - if ($mcl_contact->insert()) { + $contact = new MCL_CHADO_CONTACT($args); + if ($contact->insert()) { self::addMsg($mcl_tmpl, 'N', 'contact', $args); } else { @@ -111,7 +111,24 @@ class MCL_CHADO_CONTACT extends CHADO_CONTACT { return NULL; } } - return $mcl_contact; + return $contact; + } + + /** + * Adds a property by type ID (cvterm ID). + * + * @param MCL_TEMPLATE $mcl_tmpl + * @param integer $type_id + * @param string $value + * @param string $separator + * + * @return boolean + */ + public function addPropByID(MCL_TEMPLATE $mcl_tmpl = NULL, $type_id, $value, $separator = '') { + if ($value != '') { + return $this->addProperty($mcl_tmpl, 'contactprop', 'contact_id', $this->contact_id, $type_id, $value, $separator); + } + return TRUE; } /** @@ -126,7 +143,7 @@ class MCL_CHADO_CONTACT extends CHADO_CONTACT { * @return boolean */ public function addProp(MCL_TEMPLATE $mcl_tmpl = NULL, $cv_name, $cvterm_name, $value, $separator = '') { - if ($value) { + if ($value != '') { $type_id = MCL_CHADO_CVTERM::getCvterm($cv_name, $cvterm_name)->getCvtermID(); return $this->addProperty($mcl_tmpl, 'contactprop', 'contact_id', $this->contact_id, $type_id, $value, $separator); } diff --git a/includes/class/mcl_chado_class/mcl_chado_cv.class.inc b/includes/class/mcl_chado_class/mcl_chado_cv.class.inc index 99e52b0..56e732d 100644 --- a/includes/class/mcl_chado_class/mcl_chado_cv.class.inc +++ b/includes/class/mcl_chado_class/mcl_chado_cv.class.inc @@ -48,8 +48,8 @@ class MCL_CHADO_CV extends CHADO_CV { if ($name) { // Gets the cv. - $mcl_cv = MCL_CHADO_CV::getCV($name); - if (!$mcl_cv) { + $cv = MCL_CHADO_CV::getCV($name); + if (!$cv) { self::updateMsg($mcl_tmpl, 'E', "(name) = ($name) not found in cv"); return FALSE; } @@ -77,8 +77,8 @@ class MCL_CHADO_CV extends CHADO_CV { if ($cv_id) { // Gets the cv. - $mcl_cv = MCL_CHADO_CV::byKey(array('cv_id' => $cv_id)); - if (!$mcl_cv) { + $cv = MCL_CHADO_CV::byKey(array('cv_id' => $cv_id)); + if (!$cv) { self::updateMsg($mcl_tmpl, 'E', "(cv_id) = ($cv_id) not found in cv"); return FALSE; } @@ -92,6 +92,17 @@ class MCL_CHADO_CV extends CHADO_CV { return TRUE; } + /** + * Returns the cv by cv ID. + * + * @param integer $cv_id + * + * @return MCL_CHADO_CV + */ + public static function getCVByID($cv_id) { + return MCL_CHADO_CV::bykey(array('cv_id' => $cv_id)); + } + /** * Returns the cv by name. * @@ -119,15 +130,15 @@ class MCL_CHADO_CV extends CHADO_CV { public static function addNull() { // Checks if it has already exists. - $mcl_cv = MCL_CHADO_CV::getCV('null'); - if (!$mcl_cv) { + $cv = MCL_CHADO_CV::getCV('null'); + if (!$cv) { $details = array('name' => 'null'); - $mcl_cv = new MCL_CHADO_CV($details); - if (!$mcl_cv->insert()) { + $cv = new MCL_CHADO_CV($details); + if (!$cv->insert()) { return NULL; } } - return $mcl_cv; + return $cv; } /** @@ -150,16 +161,16 @@ class MCL_CHADO_CV extends CHADO_CV { } // Checks for duplication. - $mcl_cv = MCL_CHADO_CV::byKey($args); - if ($mcl_cv) { + $cv = MCL_CHADO_CV::byKey($args); + if ($cv) { self::addMsg($mcl_tmpl, 'D', 'cv', $args); } else { // Adds a new cv. $args['definition'] = $definition; - $mcl_cv = new MCL_CHADO_CV($args); - if ($mcl_cv->insert()) { + $cv = new MCL_CHADO_CV($args); + if ($cv->insert()) { self::addMsg($mcl_tmpl, 'N', 'cv', $args); } else { @@ -167,6 +178,6 @@ class MCL_CHADO_CV extends CHADO_CV { return NULL; } } - return $mcl_cv; + return $cv; } } \ No newline at end of file diff --git a/includes/class/mcl_chado_class/mcl_chado_cvterm.class.inc b/includes/class/mcl_chado_class/mcl_chado_cvterm.class.inc index f70b493..2a1afeb 100644 --- a/includes/class/mcl_chado_class/mcl_chado_cvterm.class.inc +++ b/includes/class/mcl_chado_class/mcl_chado_cvterm.class.inc @@ -33,6 +33,18 @@ class MCL_CHADO_CVTERM extends CHADO_CVTERM { parent::__destruct(); } + /** + * @see CHADO_CVTERM::delete() + */ + public function delete() { + + // Deletes the dbxref first. + db_delete('chado.dbxref') + ->condition('dbxref_id', $this->dbxref_id, '=') + ->execute(); + parent::delete(); + } + /** * Checks the existance of cvterm. If not, write the error messasge * to the log. @@ -47,8 +59,8 @@ class MCL_CHADO_CVTERM extends CHADO_CVTERM { if ($cv_name && $cvterm_name) { // Gets the cvterm. - $mcl_cvterm = MCL_CHADO_CVTERM::getCvterm($cv_name, $cvterm_name); - if (!$mcl_cvterm) { + $cvterm = MCL_CHADO_CVTERM::getCvterm($cv_name, $cvterm_name); + if (!$cvterm) { self::updateMsg($mcl_tmpl, 'E', "(cv_name, cvterm_name) = ($cv_name, $cvterm_name) not found in cvterm"); return FALSE; } @@ -119,7 +131,7 @@ class MCL_CHADO_CVTERM extends CHADO_CVTERM { } /** - * Returns the cvterm. + * Returns the cvterm by cv and cvterm names. * @param string $cv_name * @param string $cvterm_name @@ -127,9 +139,36 @@ class MCL_CHADO_CVTERM extends CHADO_CVTERM { * @return MCL_CHADO_CVTERM */ public static function getCvterm($cv_name, $cvterm_name) { - $mcl_cv = MCL_CHADO_CV::getCV($cv_name); - if ($mcl_cv) { - return MCL_CHADO_CVTERM::bykey(array('cv_id' => $mcl_cv->getCvID(), 'name' => $cvterm_name)); + $cv = MCL_CHADO_CV::getCV($cv_name); + if ($cv) { + return MCL_CHADO_CVTERM::bykey(array('cv_id' => $cv->getCvID(), 'name' => $cvterm_name)); + } + return NULL; + } + + /** + * Returns the cvterm by cvterm ID. + + * @param integer $cvterm_id + * + * @return MCL_CHADO_CVTERM + */ + public static function getCvtermByID($cvterm_id) { + return MCL_CHADO_CVTERM::bykey(array('cvterm_id' => $cvterm_id)); + } + + /** + * Returns the cvterm by cv ID and cvterm name. + + * @param integer $cvterm_id + * @param string $cvterm_name + * + * @return MCL_CHADO_CVTERM + */ + public static function getCvtermByCvID($cv_id, $cvterm_name) { + $cv = MCL_CHADO_CV::getCVByID($cv_id); + if ($cv) { + return MCL_CHADO_CVTERM::bykey(array('cv_id' => $cv_id, 'name' => $cvterm_name)); } return NULL; } @@ -167,23 +206,23 @@ class MCL_CHADO_CVTERM extends CHADO_CVTERM { public static function addNull() { // Gets null. - $mcl_cv = MCL_CHADO_CV::addNull(); - $mcl_dbxref = MCL_CHADO_DBXREF::addNull(); + $cv = MCL_CHADO_CV::addNull(); + $dbxref = MCL_CHADO_DBXREF::addNull(); // Checks if it has already exists. - $mcl_cvterm = MCL_CHADO_CVTERM::getCvterm('null', 'null'); - if (!$mcl_cvterm) { + $cvterm = MCL_CHADO_CVTERM::getCvterm('null', 'null'); + if (!$cvterm) { $details = array( 'name' => 'null', - 'cv_id' => $mcl_cv->getCvID(), - 'dbxref_id' => $mcl_dbxref->getDbxrefID(), + 'cv_id' => $cv->getCvID(), + 'dbxref_id' => $dbxref->getDbxrefID(), ); - $mcl_cvterm = new MCL_CHADO_CVTERM($details); - if (!$mcl_cvterm->insert()) { + $cvterm = new MCL_CHADO_CVTERM($details); + if (!$cvterm->insert()) { return NULL; } } - return $mcl_cvterm; + return $cvterm; } /** @@ -221,42 +260,42 @@ class MCL_CHADO_CVTERM extends CHADO_CVTERM { } // Checks for duplication. - $mcl_cvterm = MCL_CHADO_CVTERM::getCvterm($cv_name, $cvterm_name); - if ($mcl_cvterm) { + $cvterm = MCL_CHADO_CVTERM::getCvterm($cv_name, $cvterm_name); + if ($cvterm) { self::updateMsg($mcl_tmpl, 'D', "(cv.name, cvterm.name) = ($cv_name, $cvterm_name) found in cvterm"); } else { // Gets db. - $mcl_db = MCL_CHADO_DB::getDB($db_name); - if (!$mcl_db) { + $db = MCL_CHADO_DB::getDB($db_name); + if (!$db) { self::updateMsg($mcl_tmpl, 'E', "(db.name) = ($db_name) not found in db"); return NULL; } // Gets cv. - $mcl_cv = MCL_CHADO_CV::getCV($cv_name); - if (!$mcl_cv) { + $cv = MCL_CHADO_CV::getCV($cv_name); + if (!$cv) { self::updateMsg($mcl_tmpl, 'E', "(cv.name) = ($cv_name) not found in cv"); return NULL; } // Sets the accession. if (!$accession) { - $accession = strtoupper($mcl_db->getName()) . ":$cv_name:$cvterm_name"; + $accession = $cv->getCvID() . ":$cvterm_name"; } // Gets dbxref. $args = array( - 'db_id' => $mcl_db->getDbID(), + 'db_id' => $db->getDbID(), 'accession' => $accession, ); - $mcl_dbxref = MCL_CHADO_DBXREF::byKey($args); - if (!$mcl_dbxref) { + $dbxref = MCL_CHADO_DBXREF::byKey($args); + if (!$dbxref) { // Adds a new dbxref. - $mcl_dbxref = new MCL_CHADO_DBXREF($args); - if ($mcl_dbxref->insert()) { + $dbxref = new MCL_CHADO_DBXREF($args); + if ($dbxref->insert()) { self::addMsg($mcl_tmpl, 'N', 'dbxref', $args); } else { @@ -264,17 +303,22 @@ class MCL_CHADO_CVTERM extends CHADO_CVTERM { return NULL; } } - - // Adds a new cvterm. - if ($mcl_dbxref) { + // Checks for duplication. + $dbxref_id = $dbxref->getDbxrefID(); + $cvterm = MCL_CHADO_CVTERM::byKey(array('dbxref_id' => $dbxref_id)); + if ($cvterm) { + self::updateMsg($mcl_tmpl, 'D', "(dbxref_id) = ($dbxref_id) found in cvterm"); + } + else { $args = array( - 'dbxref_id' => $mcl_dbxref->getDbxrefID(), - 'cv_id' => $mcl_cv->getCvID(), + 'dbxref_id' => $dbxref_id, + 'cv_id' => $cv->getCvID(), 'name' => $cvterm_name, 'definition' => $definition, ); - $mcl_cvterm = new MCL_CHADO_CVTERM($args); - if ($mcl_cvterm->insert()) { + $cvterm = new MCL_CHADO_CVTERM($args); + dpm($args); + if ($cvterm->insert()) { self::addMsg($mcl_tmpl, 'N', 'cvterm', $args); } else { @@ -283,7 +327,24 @@ class MCL_CHADO_CVTERM extends CHADO_CVTERM { } } } - return $mcl_cvterm; + return $cvterm; + } + + /** + * Adds a property by type ID (cvterm ID). + * + * @param MCL_TEMPLATE $mcl_tmpl + * @param integer $type_id + * @param string $value + * @param string $separator + * + * @return boolean + */ + public function addPropByID(MCL_TEMPLATE $mcl_tmpl = NULL, $type_id, $value, $separator = '') { + if ($value != '') { + return $this->addProperty($mcl_tmpl, 'cvtermprop', 'cvterm_id', $this->cvterm_id, $type_id, $value, $separator); + } + return TRUE; } /** @@ -298,13 +359,31 @@ class MCL_CHADO_CVTERM extends CHADO_CVTERM { * @return boolean */ public function addProp(MCL_TEMPLATE $mcl_tmpl = NULL, $cv_name, $cvterm_name, $value, $separator = '') { - if ($value) { + if ($value != '') { $type_id = MCL_CHADO_CVTERM::getCvterm($cv_name, $cvterm_name)->getCvtermID(); return $this->addProperty($mcl_tmpl, 'cvtermprop', 'cvterm_id', $this->cvterm_id, $type_id, $value, $separator); } return TRUE; } + /** + * Updates the property. + * + * @param MCL_TEMPLATE $mcl_tmpl + * @param string $cv_name + * @param string $cvterm_name + * @param string $value + * + * @return boolean + */ + public function updateProp(MCL_TEMPLATE $mcl_tmpl = NULL, $cv_name, $cvterm_name, $value) { + if ($value != '') { + $type_id = MCL_CHADO_CVTERM::getCvterm($cv_name, $cvterm_name)->getCvtermID(); + return $this->updateProperty($mcl_tmpl, 'cvtermprop', 'cvterm_id', $this->cvterm_id, $type_id, $value); + } + return TRUE; + } + /** * Adds aliases. * @@ -330,7 +409,7 @@ class MCL_CHADO_CVTERM extends CHADO_CVTERM { // Poluplates the array with aliases. $alias_arr = array(); if ($separator) { - $alias_arr = preg_split($this->getSepRegex($separator), $value, NULL, PREG_SPLIT_NO_EMPTY); + $alias_arr = preg_split($this->getSepRegex($separator), $alias, NULL, PREG_SPLIT_NO_EMPTY); } else { $alias_arr []= $value; @@ -339,11 +418,10 @@ class MCL_CHADO_CVTERM extends CHADO_CVTERM { // Adds each alias. $args = array( 'cvterm_id' => $this->cvterm_id, - 'type_id' => $type_id, + 'type_id' => $type_id, ); - $rank = 0; foreach ($alias_arr as $val) { - $args['synonym'] = $val; + $args['synonym'] = trim($val); $cvtermsynonym = CHADO_CVTERMSYNONYM::byKey($args); if ($cvtermsynonym) { $this->addMsg($mcl_tmpl, 'D', 'cvtermsynonym', $args); @@ -363,6 +441,52 @@ class MCL_CHADO_CVTERM extends CHADO_CVTERM { return $flag; } + /** + * Updates aliases. + * + * @param MCL_TEMPLATE $mcl_tmpl + * @param string $cv_name + * @param string $cvterm_name + * @param string $alias + * @param string $separator + * + * @return boolean + */ + public function updateAlias(MCL_TEMPLATE $mcl_tmpl = NULL, $cv_name, $cvterm_name, $alias, $separator = '') { + if ($alias) { + + // Removes the existing properties first and add new ones. + if (!$this->deleteAlias($cv_name, $cvterm_name)) { + return FALSE; + } + return $this->addAlias($mcl_tmpl, $cv_name, $cvterm_name, $alias, $separator); + } + return TRUE; + } + + /** + * Deletes all aliases for this cvterm. + * + * @param string $cv_name + * @param string $cvterm_name + * + * @return boolean + */ + public function deleteAlias($cv_name, $cvterm_name) { + + // Gets type_id. + $type_id = MCL_CHADO_CVTERM::getCvterm($cv_name, $cvterm_name)->getCvtermID(); + $args = array( + 'cvterm_id' => $this->cvterm_id, + 'type_id' => $type_id, + ); + + // Deletes the aliases. + $sql = "DELETE FROM {chado.cvtermsynonym} WHERE cvterm_id = :cvterm_id AND type_id = :type_id"; + db_query($sql, $args); + return TRUE; + } + /** * Adds the provided values for quantitative_code, code and qualitative. * diff --git a/includes/class/mcl_chado_class/mcl_chado_dataset.class.inc b/includes/class/mcl_chado_class/mcl_chado_dataset.class.inc index 7e45f09..5471fec 100644 --- a/includes/class/mcl_chado_class/mcl_chado_dataset.class.inc +++ b/includes/class/mcl_chado_class/mcl_chado_dataset.class.inc @@ -47,8 +47,8 @@ class MCL_CHADO_DATASET extends CHADO_PROJECT { if ($name) { // Gets the dataset. - $mcl_dataset = MCL_CHADO_DATASET::getDataset($name); - if (!$mcl_dataset) { + $dataset = MCL_CHADO_DATASET::getDataset($name); + if (!$dataset) { self::updateMsg($mcl_tmpl, 'E', "(name) = ($name) not found in project"); return FALSE; } @@ -69,8 +69,8 @@ class MCL_CHADO_DATASET extends CHADO_PROJECT { if ($project_id) { // Gets the dataset. - $mcl_dataset = MCL_CHADO_DATASET::byKey(array('project_id' => $project_id)); - if (!$mcl_dataset) { + $dataset = MCL_CHADO_DATASET::byKey(array('project_id' => $project_id)); + if (!$dataset) { self::updateMsg($mcl_tmpl, 'E', "(project_id) = ($project_id) not found in project"); return FALSE; } @@ -124,15 +124,15 @@ class MCL_CHADO_DATASET extends CHADO_PROJECT { } // Checks for duplication. - $mcl_dataset = MCL_CHADO_DATASET::byKey($args); - if ($mcl_dataset) { + $dataset = MCL_CHADO_DATASET::byKey($args); + if ($dataset) { self::addMsg($mcl_tmpl, 'D', 'project', $args); } else { // Adds a new dataset. - $mcl_dataset = new MCL_CHADO_DATASET($args); - if ($mcl_dataset->insert()) { + $dataset = new MCL_CHADO_DATASET($args); + if ($dataset->insert()) { self::addMsg($mcl_tmpl, 'N', 'project', $args); } else { @@ -140,7 +140,24 @@ class MCL_CHADO_DATASET extends CHADO_PROJECT { return NULL; } } - return $mcl_dataset; + return $dataset; + } + + /** + * Adds a property by type ID (cvterm ID). + * + * @param MCL_TEMPLATE $mcl_tmpl + * @param integer $type_id + * @param string $value + * @param string $separator + * + * @return boolean + */ + public function addPropByID(MCL_TEMPLATE $mcl_tmpl = NULL, $type_id, $value, $separator = '') { + if ($value != '') { + return $this->addProperty($mcl_tmpl, 'projectprop', 'project_id', $this->project_id, $type_id, $value, $separator); + } + return TRUE; } /** @@ -155,7 +172,7 @@ class MCL_CHADO_DATASET extends CHADO_PROJECT { * @return boolean */ public function addProp(MCL_TEMPLATE $mcl_tmpl = NULL, $cv_name, $cvterm_name, $value, $separator = '') { - if ($value) { + if ($value != '') { $type_id = MCL_CHADO_CVTERM::getCvterm($cv_name, $cvterm_name)->getCvtermID(); return $this->addProperty($mcl_tmpl, 'projectprop', 'project_id', $this->project_id, $type_id, $value, $separator); } @@ -176,9 +193,9 @@ class MCL_CHADO_DATASET extends CHADO_PROJECT { if ($contact) { $names = preg_split($this->getSepRegex($separator), $contact, NULL, PREG_SPLIT_NO_EMPTY); foreach ($names as $name) { - $mcl_contact = MCL_CHADO_CONTACT::byKey(array('name' => trim($name))); - if ($mcl_contact) { - if (!$this->addLink($mcl_tmpl, 'project_contact', 'project_id', $this->project_id, 'contact_id', $mcl_contact->getContactID())) { + $contact = MCL_CHADO_CONTACT::byKey(array('name' => trim($name))); + if ($contact) { + if (!$this->addLink($mcl_tmpl, 'project_contact', 'project_id', $this->project_id, 'contact_id', $contact->getContactID())) { $flag = FALSE; } } @@ -225,8 +242,8 @@ class MCL_CHADO_DATASET extends CHADO_PROJECT { $pub_ids = preg_split($this->getSepRegex($separator), $reference, NULL, PREG_SPLIT_NO_EMPTY); foreach ($pub_ids as $pub_id) { $pub_id = trim($pub_id); - $mcl_pub = MCL_CHADO_PUB::getPub($pub_id); - if ($mcl_pub) { + $pub = MCL_CHADO_PUB::getPub($pub_id); + if ($pub) { if ($this->addLink($mcl_tmpl, 'project_pub', 'project_id', $this->project_id, 'pub_id', $pub_id)) { $flag = FALSE; } diff --git a/includes/class/mcl_chado_class/mcl_chado_db.class.inc b/includes/class/mcl_chado_class/mcl_chado_db.class.inc index 1ba0703..41c5fcc 100644 --- a/includes/class/mcl_chado_class/mcl_chado_db.class.inc +++ b/includes/class/mcl_chado_class/mcl_chado_db.class.inc @@ -47,8 +47,8 @@ class MCL_CHADO_DB extends CHADO_DB { if ($db) { // Gets the db. - $mcl_db = MCL_CHADO_DB::getDB($db); - if (!$mcl_db) { + $db = MCL_CHADO_DB::getDB($db); + if (!$db) { self::updateMsg($mcl_tmpl, 'E', "(name) = ($db) not found in db"); return FALSE; } @@ -80,15 +80,15 @@ class MCL_CHADO_DB extends CHADO_DB { public static function addNull() { // Checks if it has already exists. - $mcl_db = MCL_CHADO_DB::getDB('null'); - if (!$mcl_db) { + $db = MCL_CHADO_DB::getDB('null'); + if (!$db) { $details = array('name' => 'null'); - $mcl_db = new MCL_CHADO_DB($details); - if (!$mcl_db->insert()) { + $db = new MCL_CHADO_DB($details); + if (!$db->insert()) { return NULL; } } - return $mcl_db; + return $db; } /** @@ -113,8 +113,8 @@ class MCL_CHADO_DB extends CHADO_DB { } // Checks for duplication. - $mcl_db = MCL_CHADO_DB::byKey($args); - if ($mcl_db) { + $db = MCL_CHADO_DB::byKey($args); + if ($db) { self::addMsg($mcl_tmpl, 'D', 'db', $args); } else { @@ -123,8 +123,8 @@ class MCL_CHADO_DB extends CHADO_DB { $args['urlprefix'] = $prefix_url; $args['url'] = $url; $args['definition'] = $definition; - $mcl_db = new MCL_CHADO_DB($args); - if ($mcl_db->insert()) { + $db = new MCL_CHADO_DB($args); + if ($db->insert()) { self::addMsg($mcl_tmpl, 'N', 'db', $args); } else { @@ -132,6 +132,6 @@ class MCL_CHADO_DB extends CHADO_DB { return NULL; } } - return $mcl_db; + return $db; } } \ No newline at end of file diff --git a/includes/class/mcl_chado_class/mcl_chado_dbxref.class.inc b/includes/class/mcl_chado_class/mcl_chado_dbxref.class.inc index e02e3ec..6b7a951 100644 --- a/includes/class/mcl_chado_class/mcl_chado_dbxref.class.inc +++ b/includes/class/mcl_chado_class/mcl_chado_dbxref.class.inc @@ -42,21 +42,21 @@ class MCL_CHADO_DBXREF extends CHADO_DBXREF { public static function addNull() { // Gets null db. - $mcl_db = MCL_CHADO_DB::addNull(); + $db = MCL_CHADO_DB::addNull(); // Checks if it has already exists. - $mcl_dbxref = MCL_CHADO_DBXREF::byKey(array('accession' => 'local:null')); - if (!$mcl_dbxref) { + $dbxref = MCL_CHADO_DBXREF::byKey(array('accession' => 'local:null')); + if (!$dbxref) { $details = array( 'accession' => 'local:null', - 'db_id' => $mcl_db->getDbID(), + 'db_id' => $db->getDbID(), ); - $mcl_dbxref = new MCL_CHADO_CVTERM($details); - if (!$mcl_dbxref->insert()) { + $dbxref = new MCL_CHADO_CVTERM($details); + if (!$dbxref->insert()) { return NULL; } } - return $mcl_dbxref; + return $dbxref; } /** @@ -82,15 +82,15 @@ class MCL_CHADO_DBXREF extends CHADO_DBXREF { } // Checks for duplication. - $mcl_dbxref = MCL_CHADO_DBXREF::byKey($args); - if ($mcl_dbxref) { + $dbxref = MCL_CHADO_DBXREF::byKey($args); + if ($dbxref) { self::addMsg($mcl_tmpl, 'D', 'dbxref', $args); } else { // Adds a new dbxref. - $mcl_dbxref = new MCL_CHADO_DBXREF($args); - if ($mcl_dbxref->insert()) { + $dbxref = new MCL_CHADO_DBXREF($args); + if ($dbxref->insert()) { self::addMsg($mcl_tmpl, 'N', 'dbxref', $args); } else { @@ -98,7 +98,24 @@ class MCL_CHADO_DBXREF extends CHADO_DBXREF { return NULL; } } - return $mcl_dbxref; + return $dbxref; + } + + /** + * Adds a property by type ID (cvterm ID). + * + * @param MCL_TEMPLATE $mcl_tmpl + * @param integer $type_id + * @param string $value + * @param string $separator + * + * @return boolean + */ + public function addPropByID(MCL_TEMPLATE $mcl_tmpl = NULL, $type_id, $value, $separator = '') { + if ($value != '') { + return $this->addProperty($mcl_tmpl, 'dbxrefrop', 'dbxref_id', $this->dbxref_id, $type_id, $value, $separator); + } + return TRUE; } /** @@ -113,7 +130,7 @@ class MCL_CHADO_DBXREF extends CHADO_DBXREF { * @return boolean */ public function addProp(MCL_TEMPLATE $mcl_tmpl = NULL, $cv_name, $cvterm_name, $value, $separator = '') { - if ($value) { + if ($value != '') { $type_id = MCL_CHADO_CVTERM::getCvterm($cv_name, $cvterm_name)->getCvtermID(); return $this->addProperty($mcl_tmpl, 'dbxrefrop', 'dbxref_id', $this->dbxref_id, $type_id, $value, $separator); } diff --git a/includes/class/mcl_chado_class/mcl_chado_feature.class.inc b/includes/class/mcl_chado_class/mcl_chado_feature.class.inc index 81f7657..c234050 100644 --- a/includes/class/mcl_chado_class/mcl_chado_feature.class.inc +++ b/includes/class/mcl_chado_class/mcl_chado_feature.class.inc @@ -53,9 +53,9 @@ class MCL_CHADO_FEATURE extends CHADO_FEATURE { // Checks the organism_id. $organism_id = ''; if ($genus && $species) { - $mcl_organism = MCL_CHADO_ORGANISM::getOrganism($genus, $species); - if ($mcl_organism) { - $organism_id = $mcl_organism->getOrganismID(); + $organism = MCL_CHADO_ORGANISM::getOrganism($genus, $species); + if ($organism) { + $organism_id = $organism->getOrganismID(); } else { self::updateMsg($mcl_tmpl, 'E', "$genus $species not found in organism"); @@ -93,15 +93,124 @@ class MCL_CHADO_FEATURE extends CHADO_FEATURE { } // Checks the feature. - $mcl_feature = MCL_CHADO_FEATURE::byKey($args); - if (!$mcl_feature) { - self::updateMsg($mcl_tmpl, 'E', self::arrStr($args) . " not found in feature"); + $checked = MCL_CHADO_FEATURE::checkFeatureAlias($mcl_tmpl, $uniquename, $genus, $species, $type_id); + if (!$checked) { $flag = FALSE; } } return $flag; } + /** + * Checks the existance of feature. If not, write the error messasge + * to the log. + * + * @param MCL_TEMPLATE $mcl_tmpl + * @param string $feature + * @param string $genus + * @param string $species + * @param integer $type_id + * @param string $separator + * + * @return boolean + */ + public static function checkFeatureAlias(MCL_TEMPLATE $mcl_tmpl = NULL, $feature, $genus, $species, $type_id, $separator = '') { + $flag = TRUE; + + // Checks the organism_id. + $organism_id = ''; + if ($genus && $species) { + $organism = MCL_CHADO_ORGANISM::getOrganism($genus, $species); + if ($organism) { + $organism_id = $organism->getOrganismID(); + } + else { + self::updateMsg($mcl_tmpl, 'E', "$genus $species not found in organism"); + return FALSE; + } + } + + // Gets the uniquenames. + $uniquenames = preg_split(self::getSepRegex($separator), $feature, NULL, PREG_SPLIT_NO_EMPTY); + foreach ($uniquenames as $uniquename) { + $uniquename = trim($uniquename); + + // Sets the arguments. + $args = array( + 'uniquename' => $uniquename, + 'type_id' => $type_id, + ); + if ($organism_id) { + $args['organism_id'] = $organism_id; + } + + // If '::' found in uniquename, update uniquename and organism_id. + if (preg_match("/^(.*?)\s+(.*?)::(.*?)$/", $uniquename, $matches)) { + $genus = trim($matches[1]); + $species = trim($matches[2]); + $uniquename = trim($matches[3]); + $diff_organism = MCL_CHADO_ORGANISM::getOrganism($genus, $species); + if ($diff_organism) { + $args['organism_id'] = $diff_organism->getOrganismID(); + } + else { + self::updateMsg($mcl_tmpl, 'E', "$genus $species not found in organism"); + $flag = FALSE; + } + } + + // Checks the feature. + $feature = MCL_CHADO_FEATURE::byKey($args); + if (!$feature) { + + // Search for alias. + $sql = " + SELECT COUNT(S.synonym_id) + FROM {chado.synonym} S + INNER JOIN {chado.feature_synonym} FS on FS.synonym_id = S.synonym_id + WHERE LOWER(S.name) = LOWER(:name) + "; + $num = db_query($sql, array(':name' => $uniquename))->fetchField(); + if ($num > 1) { + self::updateMsg($mcl_tmpl, 'E', "The alias '$uniquename' is ambiguous. Please not use this alias"); + $flag = FALSE; + } + else if ($num < 1) { + self::updateMsg($mcl_tmpl, 'E', self::arrStr($args) . " not found in feature"); + $flag = FALSE; + } + } + } + return $flag; + } + + /** + * Returns the feature by uniquename, genus, species and type_id. + * + * @param string $uniquename + * @param array $type_ids + * + * @return MCL_CHADO_FEATURE + */ + public static function checkMarkerMtlQtl(MCL_TEMPLATE $mcl_tmpl = NULL, $uniquename, $type_ids) { + + // Checks the uniquename for MTL. + $mtl = self::getFeature($uniquename, '', '', $type_ids['mtl']); + if (!$mtl) { + + // Checks the uniquename for QTL. + $qtl = self::getFeature($uniquename, '', '', $type_ids['qtl']); + if (!$qtl) { + + // Checks the uniquename for marker. + $marker = self::checkFeatureAlias($mcl_tmpl, $uniquename, '', '', $type_ids['marker']); + if (!$marker) { + $mcl_tmpl->updateMsg('E', "Error - $uniquename is not 'Genetic marker', 'QTL' or 'MTL'"); + } + } + } + } + /** * Returns the feature by uniquename, genus, species and type_id. * @@ -117,9 +226,9 @@ class MCL_CHADO_FEATURE extends CHADO_FEATURE { // Gets the organism_id. $organism_id = ''; if ($genus && $species) { - $mcl_organism = MCL_CHADO_ORGANISM::getOrganism($genus, $species); - if ($mcl_organism) { - $organism_id = $mcl_organism->getOrganismID(); + $organism = MCL_CHADO_ORGANISM::getOrganism($genus, $species); + if ($organism) { + $organism_id = $organism->getOrganismID(); } else { return NULL; @@ -153,9 +262,9 @@ class MCL_CHADO_FEATURE extends CHADO_FEATURE { // Gets the organism_id. $organism_id = ''; if ($genus && $species) { - $mcl_organism = MCL_CHADO_ORGANISM::getOrganism($genus, $species); - if ($mcl_organism) { - $organism_id = $mcl_organism->getOrganismID(); + $organism = MCL_CHADO_ORGANISM::getOrganism($genus, $species); + if ($organism) { + $organism_id = $organism->getOrganismID(); } else { return NULL; @@ -293,6 +402,23 @@ class MCL_CHADO_FEATURE extends CHADO_FEATURE { return $feature; } + /** + * Adds a property by type ID (cvterm ID). + * + * @param MCL_TEMPLATE $mcl_tmpl + * @param integer $type_id + * @param string $value + * @param string $separator + * + * @return boolean + */ + public function addPropByID(MCL_TEMPLATE $mcl_tmpl = NULL, $type_id, $value, $separator = '') { + if ($value != '') { + return $this->addProperty($mcl_tmpl, 'featureprop', 'feature_id', $this->feature_id, $type_id, $value, $separator); + } + return TRUE; + } + /** * Adds a property. * @@ -305,7 +431,7 @@ class MCL_CHADO_FEATURE extends CHADO_FEATURE { * @return boolean */ public function addProp(MCL_TEMPLATE $mcl_tmpl = NULL, $cv_name, $cvterm_name, $value, $separator = '') { - if ($value) { + if ($value != '') { $type_id = MCL_CHADO_CVTERM::getCvterm($cv_name, $cvterm_name)->getCvtermID(); return $this->addProperty($mcl_tmpl, 'featureprop', 'feature_id', $this->feature_id, $type_id, $value, $separator); } @@ -316,18 +442,19 @@ class MCL_CHADO_FEATURE extends CHADO_FEATURE { * Adds related feature to feature_relationship. * * @param MCL_TEMPLATE $mcl_tmpl - * @param MCL_CHADO_FEATURE $mcl_feature + * @param MCL_CHADO_FEATURE $feature * @param integer $type_id + * @param boolean $swap * * @return boolean */ - public function addRelatedFeature(MCL_TEMPLATE $mcl_tmpl = NULL, $mcl_feature, $type_id, $swap = FALSE) { - if ($mcl_feature) { + public function addRelatedFeature(MCL_TEMPLATE $mcl_tmpl = NULL, $feature, $type_id, $swap = FALSE) { + if ($feature) { if ($swap) { - return $this->addRelationship($mcl_tmpl, 'feature_relationship', 'subject_id', $mcl_feature->getFeatureID(), 'object_id', $this->feature_id, $type_id); + return $this->addRelationship($mcl_tmpl, 'feature_relationship', 'subject_id', $feature->getFeatureID(), 'object_id', $this->feature_id, $type_id); } else { - return $this->addRelationship($mcl_tmpl, 'feature_relationship', 'subject_id', $this->feature_id, 'object_id', $mcl_feature->getFeatureID(), $type_id); + return $this->addRelationship($mcl_tmpl, 'feature_relationship', 'subject_id', $this->feature_id, 'object_id', $feature->getFeatureID(), $type_id); } } return TRUE; @@ -342,10 +469,11 @@ class MCL_CHADO_FEATURE extends CHADO_FEATURE { * @param integer $relationship_type_id * @param boollean $use_organism_id * @param string $separator + * @param boolean $swap * * @return boolean */ - public function addRelatedFeatures(MCL_TEMPLATE $mcl_tmpl = NULL, $features, $feature_type_id, $use_organism_id, $relationship_type_id, $separator = '') { + public function addRelatedFeatures(MCL_TEMPLATE $mcl_tmpl = NULL, $features, $feature_type_id, $use_organism_id, $relationship_type_id, $separator = '', $swap = FALSE) { $flag = TRUE; if ($features) { $uniquenames = preg_split($this->getSepRegex($separator), $features, NULL, PREG_SPLIT_NO_EMPTY); @@ -372,10 +500,17 @@ class MCL_CHADO_FEATURE extends CHADO_FEATURE { } // Adds a feature. - $mcl_feature = MCL_CHADO_FEATURE::byKey($args); - if ($mcl_feature) { - if (!$this->addRelationship($mcl_tmpl, 'feature_relationship', 'subject_id', $this->feature_id, 'object_id', $mcl_feature->getFeatureID(), $relationship_type_id)) { - $flag = FALSE; + $feature = MCL_CHADO_FEATURE::byKey($args); + if ($feature) { + if ($swap) { + if (!$this->addRelationship($mcl_tmpl, 'feature_relationship', 'subject_id', $feature->getFeatureID(), 'object_id', $this->feature_id, $relationship_type_id)) { + $flag = FALSE; + } + } + else { + if (!$this->addRelationship($mcl_tmpl, 'feature_relationship', 'subject_id', $this->feature_id, 'object_id', $feature->getFeatureID(), $relationship_type_id)) { + $flag = FALSE; + } } } } @@ -456,20 +591,20 @@ class MCL_CHADO_FEATURE extends CHADO_FEATURE { 'type_id' => $type_id_feature, 'organism_id' => $this->organism_id, ); - $mcl_feature = MCL_CHADO_FEATURE::byKey($args); - if ($mcl_feature) { + $feature = MCL_CHADO_FEATURE::byKey($args); + if ($feature) { $this->addMsg($mcl_tmpl, 'D', 'feature', $args); } else { // Adds a sequence. $args['residues'] = $seq; - $mcl_feature = new MCL_CHADO_FEATURE($args); - if ($mcl_feature->insert()) { + $feature = new MCL_CHADO_FEATURE($args); + if ($feature->insert()) { $this->addMsg($mcl_tmpl, 'N', 'feature', $args); // Adds a relationship. - $this->addRelatedFeature($mcl_tmpl, $mcl_feature, $type_id_relationship, $swap); + $this->addRelatedFeature($mcl_tmpl, $feature, $type_id_relationship, $swap); } else { $this->addMsg($mcl_tmpl, 'E', 'feature', $args); @@ -496,9 +631,9 @@ class MCL_CHADO_FEATURE extends CHADO_FEATURE { $accessions = preg_split($this->getSepRegex($separator), $dbxref, NULL, PREG_SPLIT_NO_EMPTY); foreach ($accessions as $accession) { $accession = trim($accession); - $mcl_dbxref = MCL_CHADO_DBXREF::addDBXref($mcl_tmpl, $db_id, $accession); - if ($mcl_dbxref) { - if (!$this->addLink($mcl_tmpl, 'feature_dbxref', 'feature_id', $this->getFeatureID(), 'dbxref_id', $mcl_dbxref->getDbxrefID())) { + $dbxref = MCL_CHADO_DBXREF::addDBXref($mcl_tmpl, $db_id, $accession); + if ($dbxref) { + if (!$this->addLink($mcl_tmpl, 'feature_dbxref', 'feature_id', $this->getFeatureID(), 'dbxref_id', $dbxref->getDbxrefID())) { $flag = FALSE; } } @@ -635,16 +770,16 @@ class MCL_CHADO_FEATURE extends CHADO_FEATURE { * Adds synoym and feature_synoym. * * @param MCL_TEMPLATE $mcl_tmpl - * @param MCL_CHADO_SYNONYM $mcl_synonym + * @param MCL_CHADO_SYNONYM $synonym * * @return boolean */ - public function addSynonym(MCL_TEMPLATE $mcl_tmpl = NULL, MCL_CHADO_SYNONYM $mcl_synonym) { - if ($mcl_synonym) { + public function addSynonym(MCL_TEMPLATE $mcl_tmpl = NULL, MCL_CHADO_SYNONYM $synonym) { + if ($synonym) { // Checks for duplication. $args = array( - 'synonym_id' => $mcl_synonym->getSynonymID(), + 'synonym_id' => $synonym->getSynonymID(), 'feature_id' => $this->feature_id, 'pub_id' => MCL_VAR::getValueByName('PUB_ID'), ); @@ -683,9 +818,9 @@ class MCL_CHADO_FEATURE extends CHADO_FEATURE { $names = preg_split($this->getSepRegex($separator), $contact, NULL, PREG_SPLIT_NO_EMPTY); foreach ($names as $name) { $name = trim($name); - $mcl_contact = MCL_CHADO_CONTACT::getContact($name); - if ($mcl_contact) { - if (!$this->addLink($mcl_tmpl, 'feature_contact', 'feature_id', $this->feature_id, 'contact_id', $mcl_contact->getContactID())) { + $contact = MCL_CHADO_CONTACT::getContact($name); + if ($contact) { + if (!$this->addLink($mcl_tmpl, 'feature_contact', 'feature_id', $this->feature_id, 'contact_id', $contact->getContactID())) { $flag = FALSE; } } @@ -769,13 +904,13 @@ class MCL_CHADO_FEATURE extends CHADO_FEATURE { if ($stock) { // Gets orgaims_id. - $mcl_organism = MCL_CHADO_ORGANISM::getOrganism($genus, $species); - if ($mcl_organism) { + $organism = MCL_CHADO_ORGANISM::getOrganism($genus, $species); + if ($organism) { $uniquenames = preg_split($this->getSepRegex($separator), $stock, NULL, PREG_SPLIT_NO_EMPTY); foreach ($uniquenames as $uniquename) { $uniquename = trim($uniquename); - $organism_id = $mcl_organism->getOrganismID(); + $organism_id = $organism->getOrganismID(); // If '::' found in uniquename, update uniquename and organism_id. if (preg_match("/^(.*?)\s+(.*?)::(.*?)$/", $uniquename, $matches)) { @@ -787,9 +922,9 @@ class MCL_CHADO_FEATURE extends CHADO_FEATURE { } // Adds a stock. - $mcl_stock = MCL_CHADO_STOCK::byKey(array('uniquename' => $uniquename, 'organism_id' => $organism_id)); + $stock = MCL_CHADO_STOCK::byKey(array('uniquename' => $uniquename, 'organism_id' => $organism_id)); if ($mcl_stock) { - if (!$this->addLink($mcl_tmpl, 'feature_stock', 'feature_id', $this->feature_id, 'stock_id', $mcl_stock->getStockID(), $type_id)) { + if (!$this->addLink($mcl_tmpl, 'feature_stock', 'feature_id', $this->feature_id, 'stock_id', $stock->getStockID(), $type_id)) { $flag = FALSE; } } @@ -859,9 +994,9 @@ class MCL_CHADO_FEATURE extends CHADO_FEATURE { $eimage_ids = preg_split($this->getSepRegex($separator), $image, NULL, PREG_SPLIT_NO_EMPTY); foreach ($eimage_ids as $eimage_id) { $eimage_id = trim($eimage_id); - $mcl_image = MCL_CHADO_IMAGE::byKey(array('eimage_id' => $eimage_id)); - if ($mcl_image) { - if (!$this->addLink($mcl_tmpl, 'feature_image', 'feature_id', $this->feature_id, 'eimage_id', $mcl_image->getEimageID())) { + $image = MCL_CHADO_IMAGE::byKey(array('eimage_id' => $eimage_id)); + if ($image) { + if (!$this->addLink($mcl_tmpl, 'feature_image', 'feature_id', $this->feature_id, 'eimage_id', $image->getEimageID())) { $flag = FALSE; } } @@ -888,8 +1023,8 @@ class MCL_CHADO_FEATURE extends CHADO_FEATURE { $pub_ids = preg_split($this->getSepRegex($separator), $reference, NULL, PREG_SPLIT_NO_EMPTY); foreach ($pub_ids as $pub_id) { $pub_id = trim($pub_id); - $mcl_pub = MCL_CHADO_PUB::getPub($pub_id); - if ($mcl_pub) { + $pub = MCL_CHADO_PUB::getPub($pub_id); + if ($pub) { if (!$this->addLink($mcl_tmpl, 'feature_pub', 'feature_id', $this->feature_id, 'pub_id', $pub_id)) { $flag = FALSE; } diff --git a/includes/class/mcl_chado_class/mcl_chado_featuremap.class.inc b/includes/class/mcl_chado_class/mcl_chado_featuremap.class.inc index 3afdcb6..22e5828 100644 --- a/includes/class/mcl_chado_class/mcl_chado_featuremap.class.inc +++ b/includes/class/mcl_chado_class/mcl_chado_featuremap.class.inc @@ -52,8 +52,8 @@ class MCL_CHADO_FEATUREMAP extends CHADO_FEATUREMAP { $names = preg_split(self::getSepRegex($separator), $map, NULL, PREG_SPLIT_NO_EMPTY); foreach ($names as $name) { $name = trim($name); - $mcl_map = MCL_CHADO_FEATUREMAP::getMap($name); - if (!$mcl_map) { + $map = MCL_CHADO_FEATUREMAP::getMap($name); + if (!$map) { self::updateMsg($mcl_tmpl, 'E', "(name) = ($name) not found in featuremap"); $flag = FALSE; } @@ -74,8 +74,8 @@ class MCL_CHADO_FEATUREMAP extends CHADO_FEATUREMAP { public static function checkMapUnit(MCL_TEMPLATE $mcl_tmpl = NULL, $map_unit) { // Gets cvterm for the map unit. - $mcl_cvterm = MCL_CHADO_CVTERM::getCvterm('SITE_CV', $map_unit); - if (!$mcl_cvterm) { + $cvterm = MCL_CHADO_CVTERM::getCvterm('SITE_CV', $map_unit); + if (!$cvterm) { self::updateMsg($mcl_tmpl, 'E', "(map_unit) = ($map_unit) not found in cvterm"); return FALSE; } @@ -114,8 +114,8 @@ class MCL_CHADO_FEATUREMAP extends CHADO_FEATUREMAP { } // Checks for duplication. - $mcl_featuremap = MCL_CHADO_FEATUREMAP::byKey($args); - if ($mcl_featuremap) { + $featuremap = MCL_CHADO_FEATUREMAP::byKey($args); + if ($featuremap) { self::addMsg($mcl_tmpl, 'D', 'featuremap', $args); } else { @@ -130,8 +130,8 @@ class MCL_CHADO_FEATUREMAP extends CHADO_FEATUREMAP { // Adds a new map. $args['unittype_id'] = $cvterm->getCvtermID(); $args['description'] = $description; - $mcl_featuremap = new MCL_CHADO_FEATUREMAP($args); - if ($mcl_featuremap->insert()) { + $featuremap = new MCL_CHADO_FEATUREMAP($args); + if ($featuremap->insert()) { self::addMsg($mcl_tmpl, 'N', 'featuremap', $args); } else { @@ -139,7 +139,24 @@ class MCL_CHADO_FEATUREMAP extends CHADO_FEATUREMAP { return NULL; } } - return $mcl_featuremap; + return $featuremap; + } + + /** + * Adds a property by type ID (cvterm ID). + * + * @param MCL_TEMPLATE $mcl_tmpl + * @param integer $type_id + * @param string $value + * @param string $separator + * + * @return boolean + */ + public function addPropByID(MCL_TEMPLATE $mcl_tmpl = NULL, $type_id, $value, $separator = '') { + if ($value != '') { + return $this->addProperty($mcl_tmpl, 'featuremapprop', 'featuremap_id', $this->featuremap_id, $type_id, $value, $separator); + } + return TRUE; } /** @@ -154,7 +171,7 @@ class MCL_CHADO_FEATUREMAP extends CHADO_FEATUREMAP { * @return boolean */ public function addProp(MCL_TEMPLATE $mcl_tmpl = NULL, $cv_name, $cvterm_name, $value, $separator = '') { - if ($value) { + if ($value != '') { $type_id = MCL_CHADO_CVTERM::getCvterm($cv_name, $cvterm_name)->getCvtermID(); return $this->addProperty($mcl_tmpl, 'featuremapprop', 'featuremap_id', $this->featuremap_id, $type_id, $value, $separator); } @@ -179,9 +196,9 @@ class MCL_CHADO_FEATUREMAP extends CHADO_FEATUREMAP { $sp = trim($sp); // Gets the organism. - $mcl_organism = MCL_CHADO_ORGANISM::getOrganism($genus, $sp); - if ($mcl_organism) { - if (!$this->addLink($mcl_tmpl, 'featuremap_organism', 'featuremap_id', $this->featuremap_id, 'organism_id', $mcl_organism->getOrganismID())) { + $organism = MCL_CHADO_ORGANISM::getOrganism($genus, $sp); + if ($organism) { + if (!$this->addLink($mcl_tmpl, 'featuremap_organism', 'featuremap_id', $this->featuremap_id, 'organism_id', $organism->getOrganismID())) { $flag = FALSE; } } @@ -231,9 +248,9 @@ class MCL_CHADO_FEATUREMAP extends CHADO_FEATUREMAP { } // Gets the stock and add it. - $mcl_stock = MCL_CHADO_STOCK::byKey($args); - if ($mcl_stock) { - if (!$this->addLink($mcl_tmpl, 'featuremap_stock', 'featuremap_id', $this->featuremap_id, 'stock_id', $mcl_stock->getStockID())) { + $stock = MCL_CHADO_STOCK::byKey($args); + if ($stock) { + if (!$this->addLink($mcl_tmpl, 'featuremap_stock', 'featuremap_id', $this->featuremap_id, 'stock_id', $stock->getStockID())) { $flag = FALSE; } } @@ -261,9 +278,9 @@ class MCL_CHADO_FEATUREMAP extends CHADO_FEATUREMAP { $names = preg_split($this->getSepRegex($separator), $contact, NULL, PREG_SPLIT_NO_EMPTY); foreach ($names as $name) { $name = trim($name); - $mcl_contact = MCL_CHADO_CONTACT::getContact($name); - if ($mcl_contact) { - if (!$this->addLink($mcl_tmpl, 'featuremap_contact', 'featuremap_id', $this->featuremap_id, 'contact_id', $mcl_contact->getContactID())) { + $contact = MCL_CHADO_CONTACT::getContact($name); + if ($contact) { + if (!$this->addLink($mcl_tmpl, 'featuremap_contact', 'featuremap_id', $this->featuremap_id, 'contact_id', $contact->getContactID())) { $flag = FALSE; } } @@ -290,8 +307,8 @@ class MCL_CHADO_FEATUREMAP extends CHADO_FEATUREMAP { $pub_ids = preg_split($this->getSepRegex($separator), $reference, NULL, PREG_SPLIT_NO_EMPTY); foreach ($pub_ids as $pub_id) { $pub_id = trim($pub_id); - $mcl_pub = MCL_CHADO_PUB::getPub($pub_id); - if ($mcl_pub) { + $pub = MCL_CHADO_PUB::getPub($pub_id); + if ($pub) { if (!$this->addLink($mcl_tmpl, 'featuremap_pub', 'featuremap_id', $this->featuremap_id, 'pub_id', $pub_id)) { $flag = FALSE; } diff --git a/includes/class/mcl_chado_class/mcl_chado_featurepos.class.inc b/includes/class/mcl_chado_class/mcl_chado_featurepos.class.inc index 40f2828..17dec56 100644 --- a/includes/class/mcl_chado_class/mcl_chado_featurepos.class.inc +++ b/includes/class/mcl_chado_class/mcl_chado_featurepos.class.inc @@ -79,6 +79,23 @@ class MCL_CHADO_FEATUREPOS extends CHADO_FEATUREPOS { return $featurepos; } + /** + * Adds a property by type ID (cvterm ID). + * + * @param MCL_TEMPLATE $mcl_tmpl + * @param integer $type_id + * @param string $value + * @param string $separator + * + * @return boolean + */ + public function addPropByID(MCL_TEMPLATE $mcl_tmpl = NULL, $type_id, $value, $separator = '') { + if ($value != '') { + return $this->addProperty($mcl_tmpl, 'featureposprop', 'featurepos_id', $this->featurepos_id, $type_id, $value, $separator); + } + return TRUE; + } + /** * Adds a property. * diff --git a/includes/class/mcl_chado_class/mcl_chado_genotype.class.inc b/includes/class/mcl_chado_class/mcl_chado_genotype.class.inc index 603c0e1..76e8648 100644 --- a/includes/class/mcl_chado_class/mcl_chado_genotype.class.inc +++ b/includes/class/mcl_chado_class/mcl_chado_genotype.class.inc @@ -58,16 +58,16 @@ class MCL_CHADO_GENOTYPE extends CHADO_GENOTYPE { } // Checks for duplication. - $mcl_genotype = MCL_CHADO_GENOTYPE::byKey($args); - if ($mcl_genotype) { + $genotype = MCL_CHADO_GENOTYPE::byKey($args); + if ($genotype) { self::addMsg($mcl_tmpl, 'D', 'genotype', $args); } else { // Adds a new genotype. $args['description'] = $description; - $mcl_genotype = new MCL_CHADO_GENOTYPE($args); - if ($mcl_genotype->insert()) { + $genotype = new MCL_CHADO_GENOTYPE($args); + if ($genotype->insert()) { self::addMsg($mcl_tmpl, 'N', 'genotype', $args); } else { @@ -75,7 +75,24 @@ class MCL_CHADO_GENOTYPE extends CHADO_GENOTYPE { return NULL; } } - return $mcl_genotype; + return $genotype; + } + + /** + * Adds a property by type ID (cvterm ID). + * + * @param MCL_TEMPLATE $mcl_tmpl + * @param integer $type_id + * @param string $value + * @param string $separator + * + * @return boolean + */ + public function addPropByID(MCL_TEMPLATE $mcl_tmpl = NULL, $type_id, $value, $separator = '') { + if ($value != '') { + return $this->addProperty($mcl_tmpl, 'genotypeprop', 'genotype_id', $this->genotype_id, $type_id, $value, $separator); + } + return TRUE; } /** @@ -90,7 +107,7 @@ class MCL_CHADO_GENOTYPE extends CHADO_GENOTYPE { * @return boolean */ public function addProp(MCL_TEMPLATE $mcl_tmpl = NULL, $cv_name, $cvterm_name, $value, $separator = '') { - if ($value) { + if ($value != '') { $type_id = MCL_CHADO_CVTERM::getCvterm($cv_name, $cvterm_name)->getCvtermID(); return $this->addProperty($mcl_tmpl, 'genotypeprop', 'genotype_id', $this->genotype_id, $type_id, $value, $separator); } diff --git a/includes/class/mcl_chado_class/mcl_chado_genotype_call.class.inc b/includes/class/mcl_chado_class/mcl_chado_genotype_call.class.inc index aa58d08..7a2509a 100644 --- a/includes/class/mcl_chado_class/mcl_chado_genotype_call.class.inc +++ b/includes/class/mcl_chado_class/mcl_chado_genotype_call.class.inc @@ -49,15 +49,15 @@ class MCL_CHADO_GENOTYPE_CALL extends CHADO_GENOTYPE_CALL { } // Checks for duplication. - $mcl_genotype_call = MCL_CHADO_GENOTYPE_CALL::byKey($args); - if ($mcl_genotype_call) { + $genotype_call = MCL_CHADO_GENOTYPE_CALL::byKey($args); + if ($genotype_call) { self::addMsg($mcl_tmpl, 'D', 'genotype_call', $args); } else { // Adds a new genotype. - $mcl_genotype_call = new MCL_CHADO_GENOTYPE_CALL($args); - if ($mcl_genotype_call->insert()) { + $genotype_call = new MCL_CHADO_GENOTYPE_CALL($args); + if ($genotype_call->insert()) { self::addMsg($mcl_tmpl, 'N', 'genotype_call', $args); } else { @@ -65,6 +65,6 @@ class MCL_CHADO_GENOTYPE_CALL extends CHADO_GENOTYPE_CALL { return NULL; } } - return $mcl_genotype_call; + return $genotype_call; } } \ No newline at end of file diff --git a/includes/class/mcl_chado_class/mcl_chado_image.class.inc b/includes/class/mcl_chado_class/mcl_chado_image.class.inc index 0253619..99e3b5d 100644 --- a/includes/class/mcl_chado_class/mcl_chado_image.class.inc +++ b/includes/class/mcl_chado_class/mcl_chado_image.class.inc @@ -58,8 +58,8 @@ class MCL_CHADO_IMAGE extends CHADO_EIMAGE { continue; } $args = array('eimage_id' => $eimage_id); - $mcl_image = MCL_CHADO_IMAGE::byKey($args); - if (!$mcl_image) { + $image = MCL_CHADO_IMAGE::byKey($args); + if (!$image) { self::addMsg($mcl_tmpl, 'E', 'eimage', $args); $flag = FALSE; } @@ -93,14 +93,14 @@ class MCL_CHADO_IMAGE extends CHADO_EIMAGE { } // Checks for duplication. - $mcl_image = MCL_CHADO_IMAGE::byKey($args); - if ($mcl_image) { + $image = MCL_CHADO_IMAGE::byKey($args); + if ($image) { self::updateMsg($mcl_tmpl, 'D', 'eimage', $args); } else { // Adds a new image. - $mcl_image = new MCL_CHADO_IMAGE($args); - if ($mcl_image->insert()) { + $image = new MCL_CHADO_IMAGE($args); + if ($image->insert()) { self::updateMsg($mcl_tmpl, 'N', 'eimage', $args); } else { @@ -108,7 +108,24 @@ class MCL_CHADO_IMAGE extends CHADO_EIMAGE { return NULL; } } - return $mcl_image; + return $image; + } + + /** + * Adds a property by type ID (cvterm ID). + * + * @param MCL_TEMPLATE $mcl_tmpl + * @param integer $type_id + * @param string $value + * @param string $separator + * + * @return boolean + */ + public function addPropByID(MCL_TEMPLATE $mcl_tmpl = NULL, $type_id, $value, $separator = '') { + if ($value != '') { + return $this->addProperty($mcl_tmpl, 'eimageprop', 'eimage_id', $this->eimage_id, $type_id, $value, $separator); + } + return TRUE; } /** @@ -123,7 +140,7 @@ class MCL_CHADO_IMAGE extends CHADO_EIMAGE { * @return boolean */ public function addProp(MCL_TEMPLATE $mcl_tmpl = NULL, $cv_name, $cvterm_name, $value, $separator = '') { - if ($value) { + if ($value != '') { $type_id = MCL_CHADO_CVTERM::getCvterm($cv_name, $cvterm_name)->getCvtermID(); return $this->addProperty($mcl_tmpl, 'eimageprop', 'eimage_id', $this->eimage_id, $type_id, $value, $separator); } diff --git a/includes/class/mcl_chado_class/mcl_chado_library.class.inc b/includes/class/mcl_chado_class/mcl_chado_library.class.inc index f54148a..accfb75 100644 --- a/includes/class/mcl_chado_class/mcl_chado_library.class.inc +++ b/includes/class/mcl_chado_class/mcl_chado_library.class.inc @@ -53,8 +53,8 @@ class MCL_CHADO_LIBRARY extends CHADO_LIBRARY { } // Gets the library. - $mcl_library = MCL_CHADO_LIBRARY::getLibrary($uniquename, $type_id, $organism_id); - if (!$mcl_library) { + $library = MCL_CHADO_LIBRARY::getLibrary($uniquename, $type_id, $organism_id); + if (!$library) { self::updateMsg($mcl_tmpl, 'E', "(uniquename, type_id, organism_id) = ($uniquename, $type_id, $organism_id) not found in library"); return FALSE; } @@ -114,16 +114,16 @@ class MCL_CHADO_LIBRARY extends CHADO_LIBRARY { } // Checks for duplication. - $mcl_library = MCL_CHADO_LIBRARY::byKey($args); - if ($mcl_library) { + $library = MCL_CHADO_LIBRARY::byKey($args); + if ($library) { self::addMsg($mcl_tmpl, 'D', 'library', $args); } else { // Adds a new library. $args['name'] = $uniquename; - $mcl_library = new MCL_CHADO_LIBRARY($args); - if ($mcl_library->insert()) { + $library = new MCL_CHADO_LIBRARY($args); + if ($library->insert()) { self::addMsg($mcl_tmpl, 'N', 'library', $args); } else { @@ -131,7 +131,24 @@ class MCL_CHADO_LIBRARY extends CHADO_LIBRARY { return NULL; } } - return $mcl_library; + return $library; + } + + /** + * Adds a property by type ID (cvterm ID). + * + * @param MCL_TEMPLATE $mcl_tmpl + * @param integer $type_id + * @param string $value + * @param string $separator + * + * @return boolean + */ + public function addPropByID(MCL_TEMPLATE $mcl_tmpl = NULL, $type_id, $value, $separator = '') { + if ($value != '') { + return $this->addProperty($mcl_tmpl, 'libraryprop', 'library_id', $this->library_id, $type_id, $value, $separator); + } + return TRUE; } /** @@ -146,7 +163,7 @@ class MCL_CHADO_LIBRARY extends CHADO_LIBRARY { * @return boolean */ public function addProp(MCL_TEMPLATE $mcl_tmpl = NULL, $cv_name, $cvterm_name, $value, $separator = '') { - if ($value) { + if ($value != '') { $type_id = MCL_CHADO_CVTERM::getCvterm($cv_name, $cvterm_name)->getCvtermID(); return $this->addProperty($mcl_tmpl, 'libraryprop', 'library_id', $this->library_id, $type_id, $value, $separator); } @@ -157,16 +174,16 @@ class MCL_CHADO_LIBRARY extends CHADO_LIBRARY { * Adds synoym and library_synoym. * * @param MCL_TEMPLATE $mcl_tmpl - * @param MCL_CHADO_SYNONYM $mcl_synonym + * @param MCL_CHADO_SYNONYM $synonym * * @return boolean */ - public function addSynonym(MCL_TEMPLATE $mcl_tmpl = NULL, MCL_CHADO_SYNONYM $mcl_synonym) { - if ($mcl_synonym) { + public function addSynonym(MCL_TEMPLATE $mcl_tmpl = NULL, MCL_CHADO_SYNONYM $synonym) { + if ($synonym) { // Checks for duplication. $args = array( - 'synonym_id' => $mcl_synonym->getSynonymID(), + 'synonym_id' => $synonym->getSynonymID(), 'library_id' => $this->library_id, 'pub_id' => MCL_VAR::getValueByName('PUB_ID'), ); @@ -205,9 +222,9 @@ class MCL_CHADO_LIBRARY extends CHADO_LIBRARY { $names = preg_split($this->getSepRegex($separator), $contact, NULL, PREG_SPLIT_NO_EMPTY); foreach ($names as $name) { $name = trim($name); - $mcl_contact = MCL_CHADO_CONTACT::byKey(array('name' => $name)); - if ($mcl_contact) { - if (!$this->addLink($mcl_tmpl, 'library_contact', 'library_id', $this->library_id, 'contact_id', $mcl_contact->getContactID())) { + $contact = MCL_CHADO_CONTACT::byKey(array('name' => $name)); + if ($contact) { + if (!$this->addLink($mcl_tmpl, 'library_contact', 'library_id', $this->library_id, 'contact_id', $contact->getContactID())) { $flag = FALSE; } } @@ -234,8 +251,8 @@ class MCL_CHADO_LIBRARY extends CHADO_LIBRARY { $pub_ids = preg_split($this->getSepRegex($separator), $reference, NULL, PREG_SPLIT_NO_EMPTY); foreach ($pub_ids as $pub_id) { $pub_id = trim($pub_id); - $mcl_pub = MCL_CHADO_PUB::getPub($pub_id); - if ($mcl_pub) { + $pub = MCL_CHADO_PUB::getPub($pub_id); + if ($pub) { $this->addLink($mcl_tmpl, 'library_pub', 'library_id', $this->library_id, 'pub_id', $pub_id); } else { diff --git a/includes/class/mcl_chado_class/mcl_chado_location.class.inc b/includes/class/mcl_chado_class/mcl_chado_location.class.inc index d12a615..10a1b63 100644 --- a/includes/class/mcl_chado_class/mcl_chado_location.class.inc +++ b/includes/class/mcl_chado_class/mcl_chado_location.class.inc @@ -81,9 +81,9 @@ class MCL_CHADO_LOCATION extends CHADO_ND_GEOLOCATION { $args = array( 'description' => $description, ); - $mcl_location = MCL_CHADO_LOCATION::byKey($args); - if ($mcl_location) { - $nd_geolocation_id = $mcl_location->getNdGeolocationID(); + $location = MCL_CHADO_LOCATION::byKey($args); + if ($location) { + $nd_geolocation_id = $location->getNdGeolocationID(); } else { return NULL; @@ -136,9 +136,9 @@ class MCL_CHADO_LOCATION extends CHADO_ND_GEOLOCATION { $args = array( 'description' => $site_name, ); - $mcl_location = MCL_CHADO_LOCATION::byKey($args); - if ($mcl_location) { - $nd_geolocation_id = $mcl_location->getNdGeolocationID(); + $location = MCL_CHADO_LOCATION::byKey($args); + if ($location) { + $nd_geolocation_id = $location->getNdGeolocationID(); } else { return NULL; @@ -155,15 +155,15 @@ class MCL_CHADO_LOCATION extends CHADO_ND_GEOLOCATION { public static function addNA() { // Checks if it has already exists. - $mcl_location = MCL_CHADO_LOCATION::byKey(array('description' => 'Not Available')); - if (!$mcl_location) { + $location = MCL_CHADO_LOCATION::byKey(array('description' => 'Not Available')); + if (!$location) { $details = array('description' => 'Not Available'); - $mcl_location = new MCL_CHADO_LOCATION($details); - if (!$mcl_location->insert()) { + $location = new MCL_CHADO_LOCATION($details); + if (!$location->insert()) { return NULL; } } - return $mcl_location; + return $location; } /** @@ -202,8 +202,8 @@ class MCL_CHADO_LOCATION extends CHADO_ND_GEOLOCATION { } // Checks for duplication. - $mcl_location = MCL_CHADO_LOCATION::byKey($args); - if ($mcl_location) { + $location = MCL_CHADO_LOCATION::byKey($args); + if ($location) { self::addMsg($mcl_tmpl, 'D', 'nd_geolocation', $args); } else { @@ -215,8 +215,8 @@ class MCL_CHADO_LOCATION extends CHADO_ND_GEOLOCATION { } // Adds a new location. - $mcl_location = new MCL_CHADO_LOCATION($args); - if ($mcl_location->insert()) { + $location = new MCL_CHADO_LOCATION($args); + if ($location->insert()) { self::addMsg($mcl_tmpl, 'N', 'nd_geolocation', $args); } else { @@ -224,7 +224,24 @@ class MCL_CHADO_LOCATION extends CHADO_ND_GEOLOCATION { return NULL; } } - return $mcl_location; + return $location; + } + + /** + * Adds a property by type ID (cvterm ID). + * + * @param MCL_TEMPLATE $mcl_tmpl + * @param integer $type_id + * @param string $value + * @param string $separator + * + * @return boolean + */ + public function addPropByID(MCL_TEMPLATE $mcl_tmpl = NULL, $type_id, $value, $separator = '') { + if ($value != '') { + return $this->addProperty($mcl_tmpl, 'nd_geolocationprop', 'nd_geolocation_id', $this->nd_geolocation_id, $type_id, $value, $separator); + } + return TRUE; } /** @@ -239,10 +256,28 @@ class MCL_CHADO_LOCATION extends CHADO_ND_GEOLOCATION { * @return boolean */ public function addProp(MCL_TEMPLATE $mcl_tmpl = NULL, $cv_name, $cvterm_name, $value, $separator = '') { - if ($value) { + if ($value != '') { $type_id = MCL_CHADO_CVTERM::getCvterm($cv_name, $cvterm_name)->getCvtermID(); return $this->addProperty($mcl_tmpl, 'nd_geolocationprop', 'nd_geolocation_id', $this->nd_geolocation_id, $type_id, $value, $separator); } return TRUE; } + + /** + * Updates the property. + * + * @param MCL_TEMPLATE $mcl_tmpl + * @param string $cv_name + * @param string $cvterm_name + * @param string $value + * + * @return boolean + */ + public function updateProp(MCL_TEMPLATE $mcl_tmpl = NULL, $cv_name, $cvterm_name, $value) { + if ($value != '') { + $type_id = MCL_CHADO_CVTERM::getCvterm($cv_name, $cvterm_name)->getCvtermID(); + return $this->updateProperty($mcl_tmpl, 'nd_geolocationprop', 'nd_geolocation_id', $this->nd_geolocation_id, $type_id, $value); + } + return TRUE; + } } \ No newline at end of file diff --git a/includes/class/mcl_chado_class/mcl_chado_nd_experiment.class.inc b/includes/class/mcl_chado_class/mcl_chado_nd_experiment.class.inc index 8751223..d5aa310 100644 --- a/includes/class/mcl_chado_class/mcl_chado_nd_experiment.class.inc +++ b/includes/class/mcl_chado_class/mcl_chado_nd_experiment.class.inc @@ -79,7 +79,7 @@ class MCL_CHADO_ND_EXPERIMENT extends CHADO_ND_EXPERIMENT { } /** - * Returns parent by cross number. + * Returns the cross by cross number. * * @param integer $dataset_name * @param string $cross_number @@ -148,7 +148,7 @@ class MCL_CHADO_ND_EXPERIMENT extends CHADO_ND_EXPERIMENT { $chado_nd_experimentprop = CHADO_ND_EXPERIMENTPROP::byKey($args); if ($chado_nd_experimentprop) { self::updateMsg($mcl_tmpl, 'D', "nd_experiment of the dup_value ($dup_value) for $cvterm_id already exists"); - $mcl_nd_experiment = MCL_CHADO_ND_EXPERIMENT::byKey(array('nd_experiment_id' => $chado_nd_experimentprop->getNdExperimentID())); + $nd_experiment = MCL_CHADO_ND_EXPERIMENT::byKey(array('nd_experiment_id' => $chado_nd_experimentprop->getNdExperimentID())); } else { @@ -157,13 +157,13 @@ class MCL_CHADO_ND_EXPERIMENT extends CHADO_ND_EXPERIMENT { 'type_id' => $type_id, 'nd_geolocation_id' => $nd_geolocation_id, ); - $mcl_nd_experiment = new MCL_CHADO_ND_EXPERIMENT($args); - if ($mcl_nd_experiment->insert()) { + $nd_experiment = new MCL_CHADO_ND_EXPERIMENT($args); + if ($nd_experiment->insert()) { self::addMsg($mcl_tmpl, 'N', 'nd_experiment', $args); // Adds a new nd_experimentprop. $args = array( - 'nd_experiment_id' => $mcl_nd_experiment->getNdExperimentID(), + 'nd_experiment_id' => $nd_experiment->getNdExperimentID(), 'type_id' => $cvterm_id, 'value' => $dup_value, ); @@ -181,7 +181,24 @@ class MCL_CHADO_ND_EXPERIMENT extends CHADO_ND_EXPERIMENT { return NULL; } } - return $mcl_nd_experiment; + return $nd_experiment; + } + + /** + * Adds a property by type ID (cvterm ID). + * + * @param MCL_TEMPLATE $mcl_tmpl + * @param integer $type_id + * @param string $value + * @param string $separator + * + * @return boolean + */ + public function addPropByID(MCL_TEMPLATE $mcl_tmpl = NULL, $type_id, $value, $separator = '') { + if ($value != '') { + return $this->addProperty($mcl_tmpl, 'nd_experimentprop', 'nd_experiment_id', $this->nd_experiment_id, $type_id, $value, $separator); + } + return TRUE; } /** @@ -196,13 +213,31 @@ class MCL_CHADO_ND_EXPERIMENT extends CHADO_ND_EXPERIMENT { * @return boolean */ public function addProp(MCL_TEMPLATE $mcl_tmpl = NULL, $cv_name, $cvterm_name, $value, $separator = '') { - if ($value) { + if ($value != '') { $type_id = MCL_CHADO_CVTERM::getCvterm($cv_name, $cvterm_name)->getCvtermID(); return $this->addProperty($mcl_tmpl, 'nd_experimentprop', 'nd_experiment_id', $this->nd_experiment_id, $type_id, $value, $separator); } return TRUE; } + /** + * Updates the property. + * + * @param MCL_TEMPLATE $mcl_tmpl + * @param string $cv_name + * @param string $cvterm_name + * @param string $value + * + * @return boolean + */ + public function updateProp(MCL_TEMPLATE $mcl_tmpl = NULL, $cv_name, $cvterm_name, $value) { + if ($value != '') { + $type_id = MCL_CHADO_CVTERM::getCvterm($cv_name, $cvterm_name)->getCvtermID(); + return $this->updateProperty($mcl_tmpl, 'nd_experimentprop', 'nd_experiment_id', $this->nd_experiment_id, $type_id, $value); + } + return TRUE; + } + /** * Adds stock to nd_experiment_stock. * @@ -211,13 +246,52 @@ class MCL_CHADO_ND_EXPERIMENT extends CHADO_ND_EXPERIMENT { * * @return boolean */ - public function addStock(MCL_TEMPLATE $mcl_tmpl = NULL, MCL_CHADO_STOCK $mcl_stock, $type_id) { - if ($mcl_stock && $type_id) { - return $this->addLink($mcl_tmpl, 'nd_experiment_stock', 'nd_experiment_id', $this->nd_experiment_id, 'stock_id', $mcl_stock->getStockID(), $type_id); + public function addStock(MCL_TEMPLATE $mcl_tmpl = NULL, MCL_CHADO_STOCK $stock, $type_id) { + if ($stock && $type_id) { + return $this->addLink($mcl_tmpl, 'nd_experiment_stock', 'nd_experiment_id', $this->nd_experiment_id, 'stock_id', $stock->getStockID(), $type_id); } return TRUE; } + /** + * Updates the stock_id in nd_experiment_stock. + * + * @param MCL_TEMPLATE $mcl_tmpl + * @param integer $stock_id + * + * @return boolean + */ + public function updateStockByID(MCL_TEMPLATE $mcl_tmpl = NULL, $stock_id, $type_id) { + if ($type_id) { + + // Sets properties. + $args = array( + 'nd_experiment_id' => $this->nd_experiment_id, + 'type_id' => $type_id, + ); + $nes = CHADO_ND_EXPERIMENT_STOCK::byKey($args); + if ($nes) { + + // Updates the relationship. + if ($stock_id) { + $nes->setStockID($stock_id); + return $nes->update(); + } + + // Removes the relationship. + else { + return $nes->delete(); + } + } + else { + $args['stock_id'] = $stock_id; + $nes = new CHADO_ND_EXPERIMENT_STOCK($args); + return $nes->insert(); + } + } + return FALSE; + } + /** * Adds phenotype to nd_experiment_phenotype. * @@ -226,9 +300,9 @@ class MCL_CHADO_ND_EXPERIMENT extends CHADO_ND_EXPERIMENT { * * @return boolean */ - public function addPhenotype(MCL_TEMPLATE $mcl_tmpl = NULL, MCL_CHADO_PHENOTYPE $mcl_phenotype) { - if ($mcl_phenotype) { - return $this->addLink($mcl_tmpl, 'nd_experiment_phenotype', 'nd_experiment_id', $this->nd_experiment_id, 'phenotype_id', $mcl_phenotype->getPhenotypeID()); + public function addPhenotype(MCL_TEMPLATE $mcl_tmpl = NULL, MCL_CHADO_PHENOTYPE $phenotype) { + if ($phenotype) { + return $this->addLink($mcl_tmpl, 'nd_experiment_phenotype', 'nd_experiment_id', $this->nd_experiment_id, 'phenotype_id', $phenotype->getPhenotypeID()); } return TRUE; } @@ -241,9 +315,9 @@ class MCL_CHADO_ND_EXPERIMENT extends CHADO_ND_EXPERIMENT { * * @return boolean */ - public function addGenotype(MCL_TEMPLATE $mcl_tmpl = NULL, MCL_CHADO_GENOTYPE $mcl_genotype) { - if ($mcl_genotype) { - return $this->addLink($mcl_tmpl, 'nd_experiment_genotype', 'nd_experiment_id', $this->nd_experiment_id, 'genotype_id', $mcl_genotype->getGenotypeID()); + public function addGenotype(MCL_TEMPLATE $mcl_tmpl = NULL, MCL_CHADO_GENOTYPE $genotype) { + if ($genotype) { + return $this->addLink($mcl_tmpl, 'nd_experiment_genotype', 'nd_experiment_id', $this->nd_experiment_id, 'genotype_id', $genotype->getGenotypeID()); } return TRUE; } @@ -282,9 +356,9 @@ class MCL_CHADO_ND_EXPERIMENT extends CHADO_ND_EXPERIMENT { $names = preg_split($this->getSepRegex($separator), $contact, NULL, PREG_SPLIT_NO_EMPTY); foreach ($names as $name) { $name = trim($name); - $mcl_contact = MCL_CHADO_CONTACT::getContact($name); - if ($mcl_contact) { - if (!$this->addLink($mcl_tmpl, 'nd_experiment_contact', 'nd_experiment_id', $this->nd_experiment_id, 'contact_id', $mcl_contact->getContactID())) { + $contact = MCL_CHADO_CONTACT::getContact($name); + if ($contact) { + if (!$this->addLink($mcl_tmpl, 'nd_experiment_contact', 'nd_experiment_id', $this->nd_experiment_id, 'contact_id', $contact->getContactID())) { $flag = FALSE; } } @@ -311,8 +385,8 @@ class MCL_CHADO_ND_EXPERIMENT extends CHADO_ND_EXPERIMENT { $pub_ids = preg_split($this->getSepRegex($separator), $reference, NULL, PREG_SPLIT_NO_EMPTY); foreach ($pub_ids as $pub_id) { $pub_id = trim($pub_id); - $mcl_pub = MCL_CHADO_PUB::getPub($pub_id); - if ($mcl_pub) { + $pub = MCL_CHADO_PUB::getPub($pub_id); + if ($pub) { if (!$this->addLink($mcl_tmpl, 'nd_experiment_pub', 'nd_experiment_id', $this->nd_experiment_id, 'pub_id', $pub_id)) { $flag = FALSE; } diff --git a/includes/class/mcl_chado_class/mcl_chado_organism.class.inc b/includes/class/mcl_chado_class/mcl_chado_organism.class.inc index 1799fb0..a4a64ba 100644 --- a/includes/class/mcl_chado_class/mcl_chado_organism.class.inc +++ b/includes/class/mcl_chado_class/mcl_chado_organism.class.inc @@ -73,8 +73,8 @@ class MCL_CHADO_ORGANISM extends CHADO_ORGANISM { $sp = trim($sp); // Gets the orgainsm. - $mcl_orgainsm = MCL_CHADO_ORGANISM::getOrganism($genus, $sp); - if (!$mcl_orgainsm) { + $orgainsm = MCL_CHADO_ORGANISM::getOrganism($genus, $sp); + if (!$orgainsm) { self::updateMsg($mcl_tmpl, 'E', "(genus, species) = ($genus, $sp) not found in organism"); $flag = FALSE; } @@ -122,8 +122,8 @@ class MCL_CHADO_ORGANISM extends CHADO_ORGANISM { } // Checks for duplication. - $mcl_orgainsm = MCL_CHADO_ORGANISM::byKey($args); - if ($mcl_orgainsm) { + $orgainsm = MCL_CHADO_ORGANISM::byKey($args); + if ($orgainsm) { self::addMsg($mcl_tmpl, 'D', 'orgainsm', $args); } else { @@ -131,8 +131,8 @@ class MCL_CHADO_ORGANISM extends CHADO_ORGANISM { // Adds a new orgainsm. $args['type_id'] = $type_id; $args['description'] = $description; - $mcl_orgainsm = new MCL_CHADO_ORGANISM($args); - if ($mcl_orgainsm->insert()) { + $orgainsm = new MCL_CHADO_ORGANISM($args); + if ($orgainsm->insert()) { self::addMsg($mcl_tmpl, 'N', 'orgainsm', $args); } else { @@ -140,7 +140,7 @@ class MCL_CHADO_ORGANISM extends CHADO_ORGANISM { return NULL; } } - return $mcl_orgainsm; + return $orgainsm; } /** @@ -151,18 +151,35 @@ class MCL_CHADO_ORGANISM extends CHADO_ORGANISM { public static function addNA() { // Checks if it has already exists. - $mcl_organism = MCL_CHADO_ORGANISM::getOrganism('N/A', 'N/A'); - if (!$mcl_organism) { + $organism = MCL_CHADO_ORGANISM::getOrganism('N/A', 'N/A'); + if (!$organism) { $details = array( 'genus' => 'N/A', 'species' => 'N/A', ); - $mcl_organism = new MCL_CHADO_ORGANISM($details); - if (!$mcl_organism->insert()) { + $organism = new MCL_CHADO_ORGANISM($details); + if (!$organism->insert()) { return NULL; } } - return $mcl_organism; + return $organism; + } + + /** + * Adds a property by type ID (cvterm ID). + * + * @param MCL_TEMPLATE $mcl_tmpl + * @param integer $type_id + * @param string $value + * @param string $separator + * + * @return boolean + */ + public function addPropByID(MCL_TEMPLATE $mcl_tmpl = NULL, $type_id, $value, $separator = '') { + if ($value != '') { + return $this->addProperty($mcl_tmpl, 'organismprop', 'organism_id', $this->organism_id, $type_id, $value, $separator); + } + return TRUE; } /** @@ -177,7 +194,7 @@ class MCL_CHADO_ORGANISM extends CHADO_ORGANISM { * @return boolean */ public function addProp(MCL_TEMPLATE $mcl_tmpl = NULL, $cv_name, $cvterm_name, $value, $separator = '') { - if ($value) { + if ($value != '') { $type_id = MCL_CHADO_CVTERM::getCvterm($cv_name, $cvterm_name)->getCvtermID(); return $this->addProperty($mcl_tmpl, 'organismprop', 'organism_id', $this->organism_id, $type_id, $value, $separator); } @@ -227,9 +244,9 @@ class MCL_CHADO_ORGANISM extends CHADO_ORGANISM { $eimage_ids = preg_split($this->getSepRegex($separator), $image, NULL, PREG_SPLIT_NO_EMPTY); foreach ($eimage_ids as $eimage_id) { $eimage_id = trim($eimage_id); - $mcl_image = MCL_CHADO_IMAGE::byKey(array('eimage_id' => $eimage_id)); - if ($mcl_image) { - if (!$this->addLink($mcl_tmpl, 'organism_image', 'organism_id', $this->organism_id, 'eimage_id', $mcl_image->getEimageID())) { + $image = MCL_CHADO_IMAGE::byKey(array('eimage_id' => $eimage_id)); + if ($image) { + if (!$this->addLink($mcl_tmpl, 'organism_image', 'organism_id', $this->organism_id, 'eimage_id', $image->getEimageID())) { $flag = FALSE; } } @@ -256,8 +273,8 @@ class MCL_CHADO_ORGANISM extends CHADO_ORGANISM { $pub_ids = preg_split($this->getSepRegex($separator), $reference, NULL, PREG_SPLIT_NO_EMPTY); foreach ($pub_ids as $pub_id) { $pub_id = trim($pub_id); - $mcl_pub = MCL_CHADO_PUB::getPub($pub_id); - if ($mcl_pub) { + $pub = MCL_CHADO_PUB::getPub($pub_id); + if ($pub) { if (!$this->addLink($mcl_tmpl, 'organism_pub', 'organism_id', $this->organism_id, 'pub_id', $pub_id)) { $flag = FALSE; } diff --git a/includes/class/mcl_chado_class/mcl_chado_phenotype.class.inc b/includes/class/mcl_chado_class/mcl_chado_phenotype.class.inc index 83347c5..616c97d 100644 --- a/includes/class/mcl_chado_class/mcl_chado_phenotype.class.inc +++ b/includes/class/mcl_chado_class/mcl_chado_phenotype.class.inc @@ -47,8 +47,8 @@ class MCL_CHADO_PHENOTYPE extends CHADO_PHENOTYPE { } // Checks for duplication. - $mcl_phenotype = MCL_CHADO_PHENOTYPE::byKey($args); - if ($mcl_phenotype) { + $phenotype = MCL_CHADO_PHENOTYPE::byKey($args); + if ($phenotype) { self::addMsg($mcl_tmpl, 'D', 'phenotype', $args); } else { @@ -56,8 +56,8 @@ class MCL_CHADO_PHENOTYPE extends CHADO_PHENOTYPE { // Adds a new phenotype. $args['value'] = $value; $args['attr_id'] = $attr_id; - $mcl_phenotype = new MCL_CHADO_PHENOTYPE($args); - if ($mcl_phenotype->insert()) { + $phenotype = new MCL_CHADO_PHENOTYPE($args); + if ($phenotype->insert()) { self::addMsg($mcl_tmpl, 'N', 'phenotype', $args); } else { @@ -65,6 +65,6 @@ class MCL_CHADO_PHENOTYPE extends CHADO_PHENOTYPE { return NULL; } } - return $mcl_phenotype; + return $phenotype; } } \ No newline at end of file diff --git a/includes/class/mcl_chado_class/mcl_chado_pub.class.inc b/includes/class/mcl_chado_class/mcl_chado_pub.class.inc index 490432d..6548a06 100644 --- a/includes/class/mcl_chado_class/mcl_chado_pub.class.inc +++ b/includes/class/mcl_chado_class/mcl_chado_pub.class.inc @@ -81,20 +81,20 @@ class MCL_CHADO_PUB extends CHADO_PUB { public static function addNull() { // Gets null cvterm. - $mcl_cvterm = MCL_CHADO_CVTERM::addNull(); + $cvterm = MCL_CHADO_CVTERM::addNull(); // Checks if it has already exists. - $mcl_pub = MCL_CHADO_PUB::byKey(array('uniquename' => 'null')); - if (!$mcl_pub) { + $pub = MCL_CHADO_PUB::byKey(array('uniquename' => 'null')); + if (!$pub) { $details = array( 'uniquename' => 'null', - 'type_id' => $mcl_cvterm->getCvtermID(), + 'type_id' => $cvterm->getCvtermID(), ); - $mcl_pub = new MCL_CHADO_PUB($details); - if (!$mcl_pub->insert()) { + $pub = new MCL_CHADO_PUB($details); + if (!$pub->insert()) { return NULL; } } - return $mcl_pub; + return $pub; } } \ No newline at end of file diff --git a/includes/class/mcl_chado_class/mcl_chado_stock.class.inc b/includes/class/mcl_chado_class/mcl_chado_stock.class.inc index a3f2bc4..a63ba71 100644 --- a/includes/class/mcl_chado_class/mcl_chado_stock.class.inc +++ b/includes/class/mcl_chado_class/mcl_chado_stock.class.inc @@ -8,15 +8,6 @@ class MCL_CHADO_STOCK extends CHADO_STOCK { /** * Class data members. */ - // Valid stock types. - public static $stock_types = array( - 'breeding_research_material', - 'cultivar', - 'landrace', - 'population', - 'species', - 'wild_unimproved', - ); /** * @see CHADO_STOCK::__construct() @@ -43,24 +34,6 @@ class MCL_CHADO_STOCK extends CHADO_STOCK { parent::__destruct(); } - /** - * Returns stock types. - * - * @return array of stock types. - */ - public static function getStockTypeArray() { - - // Gets all stock types. - $stock_arr = array(); - foreach (self::$stock_types as $stock_type) { - $mcl_cvterm = MCL_CHADO_CVTERM::getCvterm('SITE_CV', $stock_type); - if ($mcl_cvterm) { - $stock_arr[$mcl_cvterm->getCvtermID()] = $stock_type; - } - } - return $stock_arr; - } - /** * Checks the existance of stock. If not, write the error messasge * to the log. @@ -115,8 +88,8 @@ class MCL_CHADO_STOCK extends CHADO_STOCK { } // Checks the stock. - $mcl_stock = MCL_CHADO_STOCK::byKey($args); - if (!$mcl_stock) { + $stock = MCL_CHADO_STOCK::byKey($args); + if (!$stock) { self::updateMsg($mcl_tmpl, 'E', self::arrStr($args) . " not found in stock"); $flag = FALSE; } @@ -201,8 +174,8 @@ class MCL_CHADO_STOCK extends CHADO_STOCK { } // Checks for duplication. - $mcl_stock = MCL_CHADO_STOCK::byKey($args); - if ($mcl_stock) { + $stock = MCL_CHADO_STOCK::byKey($args); + if ($stock) { self::addMsg($mcl_tmpl, 'D', 'stock', $args); } else { @@ -210,8 +183,8 @@ class MCL_CHADO_STOCK extends CHADO_STOCK { // Adds a new stock. $args['type_id'] = $type_id; $args['name'] = $name; - $mcl_stock = new MCL_CHADO_STOCK($args); - if ($mcl_stock->insert()) { + $stock = new MCL_CHADO_STOCK($args); + if ($stock->insert()) { self::addMsg($mcl_tmpl, 'N', 'stock', $args); } else { @@ -219,7 +192,7 @@ class MCL_CHADO_STOCK extends CHADO_STOCK { return NULL; } } - return $mcl_stock; + return $stock; } /** @@ -252,8 +225,8 @@ class MCL_CHADO_STOCK extends CHADO_STOCK { 'name' => $secondary_id, 'organism_id' => $organism_id, ); - $mcl_stock = MCL_CHADO_STOCK::byKey($args); - if ($mcl_stock) { + $stock = MCL_CHADO_STOCK::byKey($args); + if ($stock) { self::addMsg($mcl_tmpl, 'D', 'stock', $args); } else { @@ -263,8 +236,8 @@ class MCL_CHADO_STOCK extends CHADO_STOCK { 'uniquename' => $uniquename, 'organism_id' => $organism_id, ); - $mcl_stock = MCL_CHADO_STOCK::byKey($args); - if ($mcl_stock) { + $stock = MCL_CHADO_STOCK::byKey($args); + if ($stock) { self::updateMsg($mcl_tmpl, 'E', "The uniquename ($uniquename) has a different secondary ID"); } else { @@ -276,8 +249,8 @@ class MCL_CHADO_STOCK extends CHADO_STOCK { 'organism_id' => $organism_id, 'type_id' => $type_id, ); - $mcl_stock = new MCL_CHADO_STOCK($args); - if ($mcl_stock->insert()) { + $stock = new MCL_CHADO_STOCK($args); + if ($stock->insert()) { self::addMsg($mcl_tmpl, 'N', 'stock', $args); } else { @@ -286,7 +259,24 @@ class MCL_CHADO_STOCK extends CHADO_STOCK { } } } - return $mcl_stock; + return $stock; + } + + /** + * Adds a property by type ID (cvterm ID). + * + * @param MCL_TEMPLATE $mcl_tmpl + * @param integer $type_id + * @param string $value + * @param string $separator + * + * @return boolean + */ + public function addPropByID(MCL_TEMPLATE $mcl_tmpl = NULL, $type_id, $value, $separator = '') { + if ($value != '') { + return $this->addProperty($mcl_tmpl, 'stockprop', 'stock_id', $this->stock_id, $type_id, $value, $separator); + } + return TRUE; } /** @@ -301,7 +291,7 @@ class MCL_CHADO_STOCK extends CHADO_STOCK { * @return boolean */ public function addProp(MCL_TEMPLATE $mcl_tmpl = NULL, $cv_name, $cvterm_name, $value, $separator = '') { - if ($value) { + if ($value != '') { $type_id = MCL_CHADO_CVTERM::getCvterm($cv_name, $cvterm_name)->getCvtermID(); return $this->addProperty($mcl_tmpl, 'stockprop', 'stock_id', $this->stock_id, $type_id, $value, $separator); } @@ -376,13 +366,72 @@ class MCL_CHADO_STOCK extends CHADO_STOCK { } } else { - $this->updateMsg($mcl_tmpl, 'E', "Parent '$uniquename' dose not exists in stock table."); - return FALSE; + + if ($mcl_tmpl) { + + // Saves the parent that could not find in stock table. It may be in the + // later row of the same Excel file. Adds them after processing the + // stock sheet. + $missing_parent = array( + 'uniquename' => $uniquename, + 'organism_id' => $organism_id, + 'type_id' => $type_id_relationship, + ); + $parents = $mcl_tmpl->getTmpByKey('stock_parents'); + if (!is_array($parents)) { + $parents = array(); + } + $parents[$this->stock_id] = $missing_parent; + $mcl_tmpl->setTmpByKey('stock_parents', $parents); + } + else { + return FALSE; + } } } return TRUE; } + /** + * Updates the parent by stock ID. + * + * @param MCL_TEMPLATE $mcl_tmpl + * @param integer $stock_id + * @param integer $type_id + * + * @return boolean + */ + public function updateParentByID(MCL_TEMPLATE $mcl_tmpl = NULL, $stock_id, $type_id) { + if ($type_id) { + + // Sets properties. + $args = array( + 'object_id' => $this->stock_id, + 'type_id' => $type_id, + ); + $rel = CHADO_STOCK_RELATIONSHIP::byKey($args); + if ($rel) { + + // Updates the relationship. + if ($stock_id) { + $rel->setSubjectID($stock_id); + return $rel->update(); + } + + // Removes the relationship if stock ID is empty. + else { + return $rel->delete(); + } + } + else { + $args['subject_id'] = $stock_id; + $rel = new CHADO_STOCK_RELATIONSHIP($args); + return $rel->insert(); + } + } + return FALSE; + } + /** * Adds alias to stockprop. * @@ -442,9 +491,9 @@ class MCL_CHADO_STOCK extends CHADO_STOCK { $names = preg_split($this->getSepRegex($separator), $contact, NULL, PREG_SPLIT_NO_EMPTY); foreach ($names as $name) { $name = trim($name); - $mcl_contact = MCL_CHADO_CONTACT::getContact($name); - if ($mcl_contact) { - if (!$this->addLink($mcl_tmpl, 'stock_contact', 'stock_id', $this->stock_id, 'contact_id', $mcl_contact->getContactID())) { + $contact = MCL_CHADO_CONTACT::getContact($name); + if ($contact) { + if (!$this->addLink($mcl_tmpl, 'stock_contact', 'stock_id', $this->stock_id, 'contact_id', $contact->getContactID())) { $flag = FALSE; } } @@ -471,9 +520,9 @@ class MCL_CHADO_STOCK extends CHADO_STOCK { $eimage_ids = preg_split($this->getSepRegex($separator), $image, NULL, PREG_SPLIT_NO_EMPTY); foreach ($eimage_ids as $eimage_id) { $eimage_id = trim($eimage_id); - $mcl_image = MCL_CHADO_IMAGE::byKey(array('eimage_id' => $eimage_id)); - if ($mcl_image) { - if (!$this->addLink($mcl_tmpl, 'stock_image', 'stock_id', $this->stock_id, 'eimage_id', $mcl_image->getEimageID())) { + $image = MCL_CHADO_IMAGE::byKey(array('eimage_id' => $eimage_id)); + if ($image) { + if (!$this->addLink($mcl_tmpl, 'stock_image', 'stock_id', $this->stock_id, 'eimage_id', $image->getEimageID())) { $flag = FALSE; } } @@ -500,8 +549,8 @@ class MCL_CHADO_STOCK extends CHADO_STOCK { $pub_ids = preg_split($this->getSepRegex($separator), $reference, NULL, PREG_SPLIT_NO_EMPTY); foreach ($pub_ids as $pub_id) { $pub_id = trim($pub_id); - $mcl_pub = MCL_CHADO_PUB::getPub($pub_id); - if ($mcl_pub) { + $pub = MCL_CHADO_PUB::getPub($pub_id); + if ($pub) { if (!$this->addLink($mcl_tmpl, 'stock_pub', 'stock_id', $this->stock_id, 'pub_id', $pub_id)) { $flag = FALSE; } diff --git a/includes/class/mcl_chado_class/mcl_chado_synonym.class.inc b/includes/class/mcl_chado_class/mcl_chado_synonym.class.inc index 4c8dbcd..8478af6 100644 --- a/includes/class/mcl_chado_class/mcl_chado_synonym.class.inc +++ b/includes/class/mcl_chado_class/mcl_chado_synonym.class.inc @@ -73,15 +73,15 @@ class MCL_CHADO_SYNONYM extends CHADO_SYNONYM { } // Checks for duplication. - $mcl_synonym = MCL_CHADO_SYNONYM::byKey($args); - if ($mcl_synonym) { + $synonym = MCL_CHADO_SYNONYM::byKey($args); + if ($synonym) { self::addMsg($mcl_tmpl, 'D', 'synonym', $args); } else { // Adds a new synonym. - $mcl_synonym = new MCL_CHADO_SYNONYM($args); - if ($mcl_synonym->insert()) { + $synonym = new MCL_CHADO_SYNONYM($args); + if ($synonym->insert()) { self::addMsg($mcl_tmpl, 'N', 'synonym', $args); } else { @@ -89,6 +89,6 @@ class MCL_CHADO_SYNONYM extends CHADO_SYNONYM { return NULL; } } - return $mcl_synonym; + return $synonym; } } \ No newline at end of file diff --git a/includes/class/mcl_chado_class/mcl_chado_trait.class.inc b/includes/class/mcl_chado_class/mcl_chado_trait.class.inc index e69fbb9..d04f0b3 100644 --- a/includes/class/mcl_chado_class/mcl_chado_trait.class.inc +++ b/includes/class/mcl_chado_class/mcl_chado_trait.class.inc @@ -54,8 +54,8 @@ class MCL_CHADO_TRAIT extends MCL_CHADO_CVTERM { if ($cv_name && $cvterm_name) { // Gets the cvterm. - $mcl_cvterm = MCL_CHADO_CVTERM::getCvterm($cv_name, $cvterm_name); - if (!$mcl_cvterm) { + $cvterm = MCL_CHADO_CVTERM::getCvterm($cv_name, $cvterm_name); + if (!$cvterm) { self::updateMsg($mcl_tmpl, 'E', "(cv_name, cvterm_name) = ($cv_name, $cvterm_name) not found in cvterm"); return FALSE; } @@ -77,9 +77,9 @@ class MCL_CHADO_TRAIT extends MCL_CHADO_CVTERM { if (!$cv_name) { $cv_name = MCL_VAR::getValueByName('SITE_TRAIT_ONTOLOGY'); } - $mcl_cv = MCL_CHADO_CV::getCV($cv_name); - if ($mcl_cv) { - return MCL_CHADO_CVTERM::bykey(array('cv_id' => $mcl_cv->getCvID(), 'name' => $cvterm_name)); + $cv = MCL_CHADO_CV::getCV($cv_name); + if ($cv) { + return MCL_CHADO_CVTERM::bykey(array('cv_id' => $cv->getCvID(), 'name' => $cvterm_name)); } return NULL; } @@ -120,9 +120,9 @@ class MCL_CHADO_TRAIT extends MCL_CHADO_CVTERM { $categories = preg_split("/[,;]/", $trait_category, NULL, PREG_SPLIT_NO_EMPTY); $cv_name = MCL_VAR::getValueByName('SITE_TRAIT_ONTOLOGY'); foreach ($categories as $category) { - $mcl_category = MCL_CHADO_CVTERM::getCvterm($cv_name, $category); - if ($mcl_category) { - if (!$this->addRelationship($mcl_tmpl, 'cvterm_relationship', 'subject_id', $this->cvterm_id, 'object_id', $mcl_category->getCvtermID(), $type_id)) { + $category = MCL_CHADO_CVTERM::getCvterm($cv_name, $category); + if ($category) { + if (!$this->addRelationship($mcl_tmpl, 'cvterm_relationship', 'subject_id', $this->cvterm_id, 'object_id', $category->getCvtermID(), $type_id)) { $flag = FALSE; } } diff --git a/includes/class/mcl_class_loader.class.inc b/includes/class/mcl_class_loader.class.inc index 5644be6..595b393 100644 --- a/includes/class/mcl_class_loader.class.inc +++ b/includes/class/mcl_class_loader.class.inc @@ -9,15 +9,18 @@ class MCL_CLASS_LOADER { * Class data members. * */ - private $module_path = NULL; - private $class_path = NULL; + private $module_path = NULL; + private $class_path = NULL; + private $template_path = NULL; /** * Implements the class constructor. */ - public function __construct($module_path) { - $this->module_path = $module_path; - $this->class_path = "$module_path/includes/class"; + public function __construct() { + $module_path = drupal_get_path('module', 'mcl'); + $this->module_path = $module_path; + $this->class_path = $module_path . '/includes/class'; + $this->template_path = $module_path . '/templates'; } /** @@ -43,7 +46,18 @@ class MCL_CLASS_LOADER { * * @return boolean */ - public function loadClass($class_name) { + public function loadClass($class_name) { + + // Template classes. + if (preg_match("/^MCL_TEMPLATE/", $class_name, $matches)) { + $path = '/'; + if (preg_match("/^MCL_(TEMPLATE|TEMPLATE_TYPE)$/", $class_name, $matches)) { + $path = '/core/'; + } + $class_filepath = $this->template_path . $path . strtolower($class_name) . '.class.inc'; + require_once($class_filepath); + return TRUE; + } // Gets the path to the class file. $path = '/'; @@ -71,12 +85,6 @@ class MCL_CLASS_LOADER { else if (preg_match("/^MCL_TABLE/", $class_name, $matches)) { $path .= 'table/'; } - else if (preg_match("/^MCL_(TEMPLATE|TEMPLATE_TYPE)$/", $class_name, $matches)) { - $path .= 'template/'; - } - else if (preg_match("/^MCL_TEMPLATE/", $class_name, $matches)) { - $path .= 'template/module/'; - } else if (preg_match("/^MCL_([A-Z\_]+)/", $class_name, $matches)) { // Does nothing. The file is in the root of class directory. } @@ -89,4 +97,26 @@ class MCL_CLASS_LOADER { require_once($class_filepath); return TRUE; } + + /* + * Defines getters and setters below. + */ + /** + * Returns the module path. + */ + public function getModulePath() { + return $this->module_path; + } + /** + * Returns the class path. + */ + public function getClassPath() { + return $this->class_path; + } + /** + * Returns the template path. + */ + public function getTemplatePath() { + return $this->template_path; + } } \ No newline at end of file diff --git a/mcl.info b/mcl.info index fd0026b..a3e8851 100644 --- a/mcl.info +++ b/mcl.info @@ -4,5 +4,5 @@ package = Mainlab project = MCL core = 7.x version = 7.x-1.0 -configure = admin/mainlab_chado_loader +configure = admin/mcl dependencies[] = file \ No newline at end of file diff --git a/mcl.install b/mcl.install index 0dfdd47..de6e9de 100644 --- a/mcl.install +++ b/mcl.install @@ -360,7 +360,7 @@ function mcl_populate_table_defaults() { // Registers autoloader. require_once "$module_path/includes/class/mcl_class_loader.class.inc"; - $bims_autoloader = new MCL_CLASS_LOADER($module_path); + $bims_autoloader = new MCL_CLASS_LOADER(); $bims_autoloader->register(); // Populates mcl_var table. @@ -370,7 +370,7 @@ function mcl_populate_table_defaults() { mcl_populate_mcl_templates(); // Populates mcl_data_type table. - mcl_populate_mcl_data_type(); + mcl_populate_mcl_data_valid_type(); } /** @@ -413,14 +413,13 @@ function mcl_populate_mcl_templates() { // Default template types. $template_types = array( - 'COLUMN', 'DB', 'CV', + 'TRAIT', 'CVTERM', 'ORGANISM', 'CONTACT', 'LIBRARY', - 'TRAIT', 'DATASET', 'IMAGE', 'DESCRIPTOR', @@ -431,7 +430,6 @@ function mcl_populate_mcl_templates() { 'MARKER', 'MTL', 'QTL', - 'PROGENY', 'MAP', 'MAP_POSITION', 'FIELD_BOOK', @@ -492,14 +490,16 @@ function mcl_populate_mcl_data_valid_type() { // Adds descriptor format types. $data_types['descriptor_format'] = array( - 'numeric', - 'date', - 'percent', + 'audio', 'boolean', 'categorical', - 'text', + 'counter', + 'date', + 'multicat', + 'numeric', + 'percent', 'photo', - 'audio', + 'text', ); // Adds descriptor types. @@ -557,9 +557,12 @@ function mcl_populate_mcl_data_valid_type() { ); // Gets cv_id. - $cv_id= ''; + $cv_id = ''; if ($cv_name) { $cv = MCL_CHADO_CV::getCV($cv_name); + if (!$cv) { + continue; + } $cv_id = $cv->getCvID(); $details['cv_id'] = $cv_id; } @@ -607,7 +610,7 @@ function mcl_update_7019() { // Registers autoloader. $module_path = drupal_get_path('module', 'mcl'); require_once "$module_path/includes/class/mcl_class_loader.class.inc"; - $bims_autoloader = new MCL_CLASS_LOADER($module_path); + $bims_autoloader = new MCL_CLASS_LOADER(); $bims_autoloader->register(); $transaction = db_transaction(); @@ -626,16 +629,6 @@ function mcl_update_7019() { throw new Exception("Failed to populate data valid type"); } } - - // Adds a new template type. - $mcl_template_type = MCL_TEMPLATE_TYPE::byKey(array('type' => 'COLUMN')); - if (!$mcl_template_type) { - $details = array('type' => 'COLUMN', 'rank' => 10); - $mcl_template_type = new MCL_TEMPLATE_TYPE($details); - if (!$mcl_template_type->insert()) { - throw new Exception("Failed to add a template type"); - } - } } catch (\Exception $e) { $transaction->rollback(); diff --git a/mcl.module b/mcl.module index 745fd36..73fac70 100644 --- a/mcl.module +++ b/mcl.module @@ -15,7 +15,7 @@ function mcl_init() { // Registers autoloader. require_once "$module_path/includes/class/mcl_class_loader.class.inc"; - $mcl_autoloader = new MCL_CLASS_LOADER($module_path); + $mcl_autoloader = new MCL_CLASS_LOADER(); $mcl_autoloader->register(); // Includes .inc file. @@ -64,7 +64,6 @@ function mcl_access($access_args) { * Implementation of hook_theme(). */ function mcl_theme () { - $template_path = drupal_get_path('module', 'mcl') . '/theme/templates'; return array( 'mcl_admin_template_form' => array('render element' => 'form'), ); @@ -420,6 +419,22 @@ function mcl_download_template_excel($args) { return TRUE; } +/** + * Adds additional ajax commands to be returned by the bims_ajax_render_alter hook(). + * This is useful in the case of ajax callbacks on forms where the form still needs + * to be returned as usual via the form callback hook but ajax commands also need + * to be executed + * + * @param $commands + * A single Drupal compatible ajax command created by calling ajax_command_invoke(). + */ +function mcl_add_ajax_command($command) { + if(!array_key_exists('mcl-ajax-commands', $_SESSION)) { + $_SESSION['mcl-ajax-commands'] = array(); + } + $_SESSION['mcl-ajax-commands'][] = $command; +} + /************************************************/ /* EMAIL */ /************************************************/ diff --git a/schema/drupal7.public.sql b/schema/drupal7.public.sql index 4dd210a..2a4ee5b 100644 --- a/schema/drupal7.public.sql +++ b/schema/drupal7.public.sql @@ -544,7 +544,7 @@ CREATE TABLE bims_mview_descriptor ( min_value character varying(255), max_value character varying(255), categories text, - unit character varying(255), + data_unit character varying(255), prop text, definition text ); @@ -1074,6 +1074,48 @@ CREATE SEQUENCE blocked_ips_iid_seq ALTER SEQUENCE blocked_ips_iid_seq OWNED BY blocked_ips.iid; +-- +-- Name: book; Type: TABLE; Schema: public; Owner: -; Tablespace: +-- + +CREATE TABLE book ( + mlid bigint DEFAULT 0 NOT NULL, + nid bigint DEFAULT 0 NOT NULL, + bid bigint DEFAULT 0 NOT NULL, + CONSTRAINT book_bid_check CHECK ((bid >= 0)), + CONSTRAINT book_mlid_check CHECK ((mlid >= 0)), + CONSTRAINT book_nid_check CHECK ((nid >= 0)) +); + + +-- +-- Name: TABLE book; Type: COMMENT; Schema: public; Owner: - +-- + +COMMENT ON TABLE book IS 'Stores book outline information. Uniquely connects each node in the outline to a link in menu_links'; + + +-- +-- Name: COLUMN book.mlid; Type: COMMENT; Schema: public; Owner: - +-- + +COMMENT ON COLUMN book.mlid IS 'The book page''s menu_links.mlid.'; + + +-- +-- Name: COLUMN book.nid; Type: COMMENT; Schema: public; Owner: - +-- + +COMMENT ON COLUMN book.nid IS 'The book page''s node.nid.'; + + +-- +-- Name: COLUMN book.bid; Type: COMMENT; Schema: public; Owner: - +-- + +COMMENT ON COLUMN book.bid IS 'The book ID is the book.nid of the top-level page.'; + + -- -- Name: cache; Type: TABLE; Schema: public; Owner: -; Tablespace: -- @@ -1936,6 +1978,89 @@ CREATE SEQUENCE comment_cid_seq ALTER SEQUENCE comment_cid_seq OWNED BY comment.cid; +-- +-- Name: contact; Type: TABLE; Schema: public; Owner: -; Tablespace: +-- + +CREATE TABLE contact ( + cid integer NOT NULL, + category character varying(255) DEFAULT ''::character varying NOT NULL, + recipients text NOT NULL, + reply text NOT NULL, + weight integer DEFAULT 0 NOT NULL, + selected smallint DEFAULT 0 NOT NULL, + CONSTRAINT contact_cid_check CHECK ((cid >= 0)) +); + + +-- +-- Name: TABLE contact; Type: COMMENT; Schema: public; Owner: - +-- + +COMMENT ON TABLE contact IS 'Contact form category settings.'; + + +-- +-- Name: COLUMN contact.cid; Type: COMMENT; Schema: public; Owner: - +-- + +COMMENT ON COLUMN contact.cid IS 'Primary Key: Unique category ID.'; + + +-- +-- Name: COLUMN contact.category; Type: COMMENT; Schema: public; Owner: - +-- + +COMMENT ON COLUMN contact.category IS 'Category name.'; + + +-- +-- Name: COLUMN contact.recipients; Type: COMMENT; Schema: public; Owner: - +-- + +COMMENT ON COLUMN contact.recipients IS 'Comma-separated list of recipient e-mail addresses.'; + + +-- +-- Name: COLUMN contact.reply; Type: COMMENT; Schema: public; Owner: - +-- + +COMMENT ON COLUMN contact.reply IS 'Text of the auto-reply message.'; + + +-- +-- Name: COLUMN contact.weight; Type: COMMENT; Schema: public; Owner: - +-- + +COMMENT ON COLUMN contact.weight IS 'The category''s weight.'; + + +-- +-- Name: COLUMN contact.selected; Type: COMMENT; Schema: public; Owner: - +-- + +COMMENT ON COLUMN contact.selected IS 'Flag to indicate whether or not category is selected by default. (1 = Yes, 0 = No)'; + + +-- +-- Name: contact_cid_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE contact_cid_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: contact_cid_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE contact_cid_seq OWNED BY contact.cid; + + -- -- Name: ctools_css_cache; Type: TABLE; Schema: public; Owner: -; Tablespace: -- @@ -3648,16 +3773,35 @@ ALTER SEQUENCE gensas_files_file_id_seq OWNED BY gensas_files.file_id; -- CREATE TABLE gensas_gff3 ( - id character varying(200) NOT NULL, job_id character varying(200) NOT NULL, - parent character varying(200), prop text, - type character varying(200) NOT NULL, + id character varying(255) NOT NULL, + type character varying(255) NOT NULL, start integer, + parent character varying(255), landmark character varying(1024) NOT NULL ); +-- +-- Name: gensas_gff3_location_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE gensas_gff3_location_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: gensas_gff3_location_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE gensas_gff3_location_seq OWNED BY gensas_gff3.start; + + -- -- Name: gensas_group; Type: TABLE; Schema: public; Owner: -; Tablespace: -- @@ -4399,8 +4543,9 @@ CREATE TABLE gensas_user_tool ( CREATE TABLE history ( uid integer DEFAULT 0 NOT NULL, - nid integer DEFAULT 0 NOT NULL, - "timestamp" integer DEFAULT 0 NOT NULL + nid bigint DEFAULT 0 NOT NULL, + "timestamp" integer DEFAULT 0 NOT NULL, + CONSTRAINT history_nid_check CHECK ((nid >= 0)) ); @@ -6922,32 +7067,19 @@ ALTER SEQUENCE taxonomy_vocabulary_vid_seq OWNED BY taxonomy_vocabulary.vid; -- CREATE TABLE tmp ( + id integer NOT NULL, col1 character varying, col2 character varying, col3 character varying, - col4 character varying, - id integer NOT NULL -); - - --- --- Name: tmp2; Type: TABLE; Schema: public; Owner: -; Tablespace: --- - -CREATE TABLE tmp2 ( - col1 character varying, - col2 character varying, - col3 character varying, - col4 character varying, - id integer NOT NULL + col4 character varying ); -- --- Name: tmp2_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- Name: tmp_id_seq; Type: SEQUENCE; Schema: public; Owner: - -- -CREATE SEQUENCE tmp2_id_seq +CREATE SEQUENCE tmp_id_seq START WITH 1 INCREMENT BY 1 NO MINVALUE @@ -6956,29 +7088,10 @@ CREATE SEQUENCE tmp2_id_seq -- --- Name: tmp2_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- Name: tmp_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - -- -ALTER SEQUENCE tmp2_id_seq OWNED BY tmp2.id; - - --- --- Name: tmp3_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE tmp3_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: tmp3_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE tmp3_id_seq OWNED BY tmp.id; +ALTER SEQUENCE tmp_id_seq OWNED BY tmp.id; -- @@ -7048,6 +7161,88 @@ CREATE SEQUENCE url_alias_pid_seq ALTER SEQUENCE url_alias_pid_seq OWNED BY url_alias.pid; +-- +-- Name: user_restrictions; Type: TABLE; Schema: public; Owner: -; Tablespace: +-- + +CREATE TABLE user_restrictions ( + urid integer NOT NULL, + mask character varying(255) DEFAULT ''::character varying NOT NULL, + type character varying(255) DEFAULT ''::character varying NOT NULL, + subtype character varying(255) DEFAULT ''::character varying NOT NULL, + status smallint DEFAULT 0 NOT NULL, + expire integer DEFAULT 0 NOT NULL +); + + +-- +-- Name: TABLE user_restrictions; Type: COMMENT; Schema: public; Owner: - +-- + +COMMENT ON TABLE user_restrictions IS 'Stores user restrictions.'; + + +-- +-- Name: COLUMN user_restrictions.urid; Type: COMMENT; Schema: public; Owner: - +-- + +COMMENT ON COLUMN user_restrictions.urid IS 'Primary Key: Unique user restriction ID.'; + + +-- +-- Name: COLUMN user_restrictions.mask; Type: COMMENT; Schema: public; Owner: - +-- + +COMMENT ON COLUMN user_restrictions.mask IS 'Text mask used for filtering restrictions.'; + + +-- +-- Name: COLUMN user_restrictions.type; Type: COMMENT; Schema: public; Owner: - +-- + +COMMENT ON COLUMN user_restrictions.type IS 'Type of access rule: name, mail, or any value defined from a third-party module.'; + + +-- +-- Name: COLUMN user_restrictions.subtype; Type: COMMENT; Schema: public; Owner: - +-- + +COMMENT ON COLUMN user_restrictions.subtype IS 'Sub-type of access rule.'; + + +-- +-- Name: COLUMN user_restrictions.status; Type: COMMENT; Schema: public; Owner: - +-- + +COMMENT ON COLUMN user_restrictions.status IS 'Whether the restriction is to allow (1), or deny access (0).'; + + +-- +-- Name: COLUMN user_restrictions.expire; Type: COMMENT; Schema: public; Owner: - +-- + +COMMENT ON COLUMN user_restrictions.expire IS 'A Unix timestamp indicating when the restriction expires.'; + + +-- +-- Name: user_restrictions_urid_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE user_restrictions_urid_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: user_restrictions_urid_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE user_restrictions_urid_seq OWNED BY user_restrictions.urid; + + -- -- Name: users; Type: TABLE; Schema: public; Owner: -; Tablespace: -- @@ -7639,6 +7834,13 @@ ALTER TABLE ONLY blocked_ips ALTER COLUMN iid SET DEFAULT nextval('blocked_ips_i ALTER TABLE ONLY comment ALTER COLUMN cid SET DEFAULT nextval('comment_cid_seq'::regclass); +-- +-- Name: cid; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY contact ALTER COLUMN cid SET DEFAULT nextval('contact_cid_seq'::regclass); + + -- -- Name: dfid; Type: DEFAULT; Schema: public; Owner: - -- @@ -7937,21 +8139,21 @@ ALTER TABLE ONLY taxonomy_vocabulary ALTER COLUMN vid SET DEFAULT nextval('taxon -- Name: id; Type: DEFAULT; Schema: public; Owner: - -- -ALTER TABLE ONLY tmp ALTER COLUMN id SET DEFAULT nextval('tmp3_id_seq'::regclass); +ALTER TABLE ONLY tmp ALTER COLUMN id SET DEFAULT nextval('tmp_id_seq'::regclass); -- --- Name: id; Type: DEFAULT; Schema: public; Owner: - +-- Name: pid; Type: DEFAULT; Schema: public; Owner: - -- -ALTER TABLE ONLY tmp2 ALTER COLUMN id SET DEFAULT nextval('tmp2_id_seq'::regclass); +ALTER TABLE ONLY url_alias ALTER COLUMN pid SET DEFAULT nextval('url_alias_pid_seq'::regclass); -- --- Name: pid; Type: DEFAULT; Schema: public; Owner: - +-- Name: urid; Type: DEFAULT; Schema: public; Owner: - -- -ALTER TABLE ONLY url_alias ALTER COLUMN pid SET DEFAULT nextval('url_alias_pid_seq'::regclass); +ALTER TABLE ONLY user_restrictions ALTER COLUMN urid SET DEFAULT nextval('user_restrictions_urid_seq'::regclass); -- @@ -8224,6 +8426,22 @@ ALTER TABLE ONLY blocked_ips ADD CONSTRAINT blocked_ips_pkey PRIMARY KEY (iid); +-- +-- Name: book_nid_key; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: +-- + +ALTER TABLE ONLY book + ADD CONSTRAINT book_nid_key UNIQUE (nid); + + +-- +-- Name: book_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: +-- + +ALTER TABLE ONLY book + ADD CONSTRAINT book_pkey PRIMARY KEY (mlid); + + -- -- Name: cache_block_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: -- @@ -8336,6 +8554,22 @@ ALTER TABLE ONLY comment ADD CONSTRAINT comment_pkey PRIMARY KEY (cid); +-- +-- Name: contact_category_key; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: +-- + +ALTER TABLE ONLY contact + ADD CONSTRAINT contact_category_key UNIQUE (category); + + +-- +-- Name: contact_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: +-- + +ALTER TABLE ONLY contact + ADD CONSTRAINT contact_pkey PRIMARY KEY (cid); + + -- -- Name: ctools_css_cache_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: -- @@ -8609,11 +8843,11 @@ ALTER TABLE ONLY gensas_expire -- --- Name: gensas_gff3_id_job_id_key; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: +-- Name: gensas_gff3_job_id_id_key; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: -- ALTER TABLE ONLY gensas_gff3 - ADD CONSTRAINT gensas_gff3_id_job_id_key UNIQUE (id, job_id); + ADD CONSTRAINT gensas_gff3_job_id_id_key UNIQUE (job_id, id); -- @@ -9320,6 +9554,14 @@ ALTER TABLE ONLY url_alias ADD CONSTRAINT url_alias_pkey PRIMARY KEY (pid); +-- +-- Name: user_restrictions_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: +-- + +ALTER TABLE ONLY user_restrictions + ADD CONSTRAINT user_restrictions_pkey PRIMARY KEY (urid); + + -- -- Name: users_name_key; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: -- @@ -9384,6 +9626,13 @@ ALTER TABLE ONLY watchdog ADD CONSTRAINT watchdog_pkey PRIMARY KEY (wid); +-- +-- Name: authmap_uid_module_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: +-- + +CREATE INDEX authmap_uid_module_idx ON authmap USING btree (uid, module); + + -- -- Name: batch_token_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: -- @@ -9419,6 +9668,13 @@ CREATE INDEX block_role_rid_idx ON block_role USING btree (rid); CREATE INDEX blocked_ips_blocked_ip_idx ON blocked_ips USING btree (ip); +-- +-- Name: book_bid_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: +-- + +CREATE INDEX book_bid_idx ON book USING btree (bid); + + -- -- Name: cache_block_expire_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: -- @@ -9545,6 +9801,13 @@ CREATE INDEX comment_comment_status_pid_idx ON comment USING btree (pid, status) CREATE INDEX comment_comment_uid_idx ON comment USING btree (uid); +-- +-- Name: contact_list_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: +-- + +CREATE INDEX contact_list_idx ON contact USING btree (weight, category); + + -- -- Name: ctools_object_cache_updated_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: -- @@ -10098,6 +10361,13 @@ CREATE INDEX flood_purge_idx ON flood USING btree (expiration); CREATE INDEX gensas_expire_idx1_gensas_expire_idx ON gensas_expire USING btree (task_id); +-- +-- Name: gensas_gff3_landmark_job_id_id_key; Type: INDEX; Schema: public; Owner: -; Tablespace: +-- + +CREATE INDEX gensas_gff3_landmark_job_id_id_key ON gensas_gff3 USING btree (job_id, id, landmark); + + -- -- Name: gensas_job_cmd_idx_gensas_job_cmd_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: -- @@ -10637,6 +10907,34 @@ CREATE INDEX url_alias_alias_language_pid_idx ON url_alias USING btree (alias, l CREATE INDEX url_alias_source_language_pid_idx ON url_alias USING btree (source, language, pid); +-- +-- Name: user_restrictions_expire_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: +-- + +CREATE INDEX user_restrictions_expire_idx ON user_restrictions USING btree (expire); + + +-- +-- Name: user_restrictions_status_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: +-- + +CREATE INDEX user_restrictions_status_idx ON user_restrictions USING btree (status); + + +-- +-- Name: user_restrictions_subtype_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: +-- + +CREATE INDEX user_restrictions_subtype_idx ON user_restrictions USING btree (substr((subtype)::text, 1, 32)); + + +-- +-- Name: user_restrictions_type_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: +-- + +CREATE INDEX user_restrictions_type_idx ON user_restrictions USING btree (substr((type)::text, 1, 32)); + + -- -- Name: users_access_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: -- diff --git a/includes/class/template/mcl_template.class.inc b/templates/core/mcl_template.class.inc similarity index 90% rename from includes/class/template/mcl_template.class.inc rename to templates/core/mcl_template.class.inc index fdcab78..ee6a5fe 100644 --- a/includes/class/template/mcl_template.class.inc +++ b/templates/core/mcl_template.class.inc @@ -16,6 +16,7 @@ class MCL_TEMPLATE extends PUBLIC_MCL_TEMPLATE { protected $job = NULL; protected $line_no = NULL; protected $stats = NULL; + private $tmp = array(); /** * @see PUBLIC_MCL_TEMPLATE::__construct() @@ -214,7 +215,8 @@ DESC; public static function updateTemplates($remove = FALSE, $refresh = FALSE) { // Gets the template folder. - $template_dir = drupal_get_path('module', 'mcl') . '/includes/class/template/module'; + $class_loader = new MCL_CLASS_LOADER(); + $template_dir = $class_loader->getTemplatePath(); // Removes all templates from the table. if ($refresh) { @@ -226,6 +228,12 @@ DESC; $files = file_scan_directory($template_dir, "/\.inc$/"); $template_class = array(); foreach ($files as $filepath => $file) { + + // Skips files in /templates/core directory. + if (preg_match("/\/templates\/core/", $filepath)) { + continue; + } + if (preg_match("/^mcl_template_(.*)\.class$/", $file->name, $matches)) { $template_name = $matches[1]; $template_class[$template_name] = TRUE; @@ -367,11 +375,6 @@ DESC; */ public static function validateTemplate($template) { - // Updates the template name. - if (MCL_TEMPLATE::isColumnTemplate($template)) { - $template = 'COLUMN'; - } - // Checks if a template for this template exists. $mcl_template = MCL_TEMPLATE::byKey(array('template' => $template)); if ($mcl_template) { @@ -395,11 +398,6 @@ DESC; */ public static function getRank($template) { - // Updates the template name. - if (preg_match("/^([A-Za-z0-9\_]+)_column$/", $template, $matches)) { - $template = $matches[1]; - } - // Gets the rank of the template. $mcl_template = MCL_TEMPLATE::byKey(array('template' => $template)); return $mcl_template->template_type->getRank(); @@ -415,13 +413,8 @@ DESC; */ public static function getTemplateClass(MCL_JOB_UPLOAD $job, MCL_FILE_CSV $csv) { - // Gets and updates the template. - $template = $csv->getTemplate(); - if (MCL_TEMPLATE::isColumnTemplate($template)) { - $template = 'column'; - } - // Gets the child class object of MCL_TEMPLATE. + $template = $csv->getTemplate(); $class_name = 'MCL_TEMPLATE_' . strtoupper($template); $mcl_template = $class_name::byKey(array('template' => $template)); if ($mcl_template) { @@ -640,9 +633,15 @@ DESC; * * @param string $key * @param string $msg + * @param boolean $flag_line_no */ - public function updateMsg($key, $msg) { - $this->job->updateMsg($key, $msg, $this->line_no); + public function updateMsg($key, $msg, $flag_line_no = TRUE) { + if ($flag_line_no) { + $this->job->updateMsg($key, $msg, $this->line_no); + } + else { + $this->job->updateMsg($key, $msg); + } } /** @@ -889,10 +888,39 @@ DESC; continue; } - // Sets column #. - if (array_key_exists($column_name, $this->headers) || preg_match($regex, $column_name)) { + // Updates the header column array. + if (array_key_exists($column_name, $this->headers)) { $this->headers[$column_name]['col'] = $i; } + + // Handles the special coulmns. + else if (preg_match($regex, $column_name, $matches)) { + $this->headers[$column_name]['col'] = $i; + $prefix = $matches[0]; + $prefix_len = strlen($prefix); + + // Type 1 : double special character + cvterm.name. + if ($prefix_len == 2) { + + // Gets cv_id. + $cv_id = $this->getCvByPrefix($prefix); + if ($cv) { + + // Gets the cvterm. + $cvterm_name = substr($column_name, $prefix_len); + $cvterm = MCL_CHADO_CVTERM::getCvtermByCvID($cv_id, $cvterm_name); + if ($cvterm) { + $this->headers[$column_name]['cvterm_id'] = $cvterm->getCvtermID(); + } + else { + $this->updateMsg('E', "Error : $cvterm_name not found in cvterm table."); + } + } + else { + $this->updateMsg('E', "Error : cv could not found for $prefix."); + } + } + } } } @@ -920,6 +948,28 @@ DESC; return $this->isPassed(); } + /** + * Returns cv.cv_id from the parameter of this job if found. Otherwise, + * returns cv_id of 'SITE_CV'. + * + * @param string $prefix + * + * @return MCL_CHADO_CV + */ + public function getCvByPrefix($prefix) { + + // Returns cv_id for this prefix if it found in job param array. + $cv_id_map = $this->getJob()->getParamByKey('cv_id_map'); + if (is_array($cv_id_map) && array_key_exists($this->template, $cv_id_map)) { + if (array_key_exists($prefix, $cv_id_map[$this->template])) { + return MCL_CHADO_CV::getCVByID($cv_id_map[$this->template][$prefix]); + } + } + + // Returns MCL_CHADO_CV for 'SITE_TRAIT_ONTOLOGY'. + return MCL_CHADO_CV::getCV('SITE_TRAIT_ONTOLOGY'); + } + /** * Checks a data line for this template. * @@ -1017,6 +1067,9 @@ DESC; } } fclose($fh); + + // Calls postProcess(). + $this->postProcess(); return $this->isPassed(); } @@ -1030,27 +1083,51 @@ DESC; } /** - * Adds custom columns. + * The function to be called after uploading data. + */ + public function postProcess() { + // Defined in child class. + } + + /** + * Returns the special columns that start with the provided prefix. * * @param string $prefix - * @param MCL_TEMPLATE $mcl_template - * @param array $line + * + * @return array */ - public function addCustomColumns($prefix, MCL_TEMPLATE $mcl_template, $line) { + public function getSpecialColumns($prefix) { - // Checks if a column-template exists. - $columns = $this->job->getPropByKey('columns'); - $column_arr = array(); - if (array_key_exists($this->getTemplate(), $columns)) { - $column_arr = $columns[$this->getTemplate()]; + // Sets the regular expression. + $separator = "\\"; + $regex = '/^' . $separator . implode($separator, str_split($prefix)) . '.+/'; + + // Gets the matced columns. + $columns = array(); + foreach ($this->headers as $column_name => $prop) { + if (preg_match($regex, $column_name)) { + $columns[$column_name] = $prop; + } } + return $columns; + } - // Uploads a custom columns for this line. - if (!empty($column_arr)) { - foreach ($column_arr as $cvterm_name => $cv_name) { - $value = $line[$prefix . $cvterm_name]; - if ($value) { - $mcl_template->addProp($this, $cv_name, $cvterm_name, $value); + /** + * Adds special columns. + * + * @param string $prefix + * @param MCL_TEMPLATE $mcl_template + * @param array $line + */ + public function addSpecialColumns($prefix, MCL_TEMPLATE $mcl_template, $line) { + + // Gets the special columns. + $columns = $this->getSpecialColumns($prefix); + if (!empty($columns)) { + foreach ($columns as $column_name => $prop) { + $value = $line[$column_name]; + if ($value != '') { + $mcl_template->addPropByID($this, $prop['cvterm_id'], $value); } } } @@ -1067,7 +1144,7 @@ DESC; * @param string $separator */ public function addProperty($table_name, $target_field, $target_id, $type_id, $value, $separator = '') { - if ($value) { + if ($value != '') { // Checks duplication before adding a new property. $args = array( @@ -1112,7 +1189,7 @@ DESC; * @param integer $rank */ public function addPropertyRanked($table_name, $target_field, $target_id, $type_id, $value, $rank) { - if ($value) { + if ($value != '') { // Checks duplication before adding a new property. $args = array( @@ -1343,15 +1420,6 @@ DESC; return empty($data_str); } - /** - * Returns if this is a column-template. - * - * @return boolean - */ - public static function isColumnTemplate($template) { - return preg_match("/_column$/i", $template); - } - /* * Defines getters and setters below. */ @@ -1449,4 +1517,28 @@ DESC; public function setLineNo($line_no) { $this->line_no = $line_no; } + + /** + * Retrieves the value of the provided key in $this->tmp. + * + * @param string $key + * + * @return string + */ + public function getTmpByKey($key) { + if (array_key_exists($key, $this->tmp)) { + return $this->tmp[$key]; + } + return NULL; + } + + /** + * Updates the value of the provided key in $this->tmp. + * + * @param string $template_type + * @param string $value + */ + public function setTmpByKey($key, $value) { + $this->tmp[$key] = $value; + } } \ No newline at end of file diff --git a/includes/class/template/mcl_template_type.class.inc b/templates/core/mcl_template_type.class.inc similarity index 100% rename from includes/class/template/mcl_template_type.class.inc rename to templates/core/mcl_template_type.class.inc diff --git a/includes/class/template/module/mcl_template_contact.class.inc b/templates/mcl_template_contact.class.inc similarity index 100% rename from includes/class/template/module/mcl_template_contact.class.inc rename to templates/mcl_template_contact.class.inc diff --git a/includes/class/template/module/mcl_template_cross.class.inc b/templates/mcl_template_cross.class.inc similarity index 100% rename from includes/class/template/module/mcl_template_cross.class.inc rename to templates/mcl_template_cross.class.inc diff --git a/templates/mcl_template_cross_bims.class.inc b/templates/mcl_template_cross_bims.class.inc new file mode 100644 index 0000000..39bc3d4 --- /dev/null +++ b/templates/mcl_template_cross_bims.class.inc @@ -0,0 +1,152 @@ +getMemberArr()); + } + } + + /** + * @see MCL_TEMPLATE::defineDescription() + */ + public function defineDescription() { + $desc = 'The description for cross sheet'; + return $desc; + } + + /** + * @see MCL_TEMPLATE::defineHeaders() + */ + public function defineHeaders() { + $headers = array( + 'site_name' => array('req' => FALSE, 'width' => 10, 'desc' => "Site information where the stock for the phenotyping is planted. It should match 'site_name' in the 'Site' sheet."), + 'cross_number' => array('req' => TRUE, 'width' => 17, 'desc' => "ID number or name for this specific cross."), + 'mother' => array('req' => TRUE, 'width' => 13, 'desc' => "ID name or number for the seed parent for the cross. This ID must also be an entry in the Stock sheet."), + 'mother_location' => array('req' => FALSE, 'width' => 17, 'desc' => "Location details for the mother of this cross (eg. Plant location, individual stock name, etc)."), + 'father' => array('req' => TRUE, 'width' => 13, 'desc' => "ID name or number for the pollen parent for the cross. This ID must also be an entry in the Stock sheet."), + 'father_location' => array('req' => FALSE, 'width' => 17, 'desc' => "Location details for the father of this cross (eg. Plant location, individual stock name, etc)."), + 'cross_date' => array('req' => FALSE, 'width' => 15, 'desc' => "Date for the cross."), + ); + return $headers; + } + + /** + * @see MCL_TEMPLATE::defineCvterms() + */ + public function defineCvterms() { + $cvterms = array(); + $cvterms['SITE_CV']['cross_experiment'] = -1; + $cvterms['SITE_CV']['cross_date'] = -1; + $cvterms['SITE_CV']['cross_number'] = -1; + $cvterms['SITE_CV']['mother_location'] = -1; + $cvterms['SITE_CV']['father_location'] = -1; + $cvterms['SITE_CV']['maternal_parent'] = -1; + $cvterms['SITE_CV']['paternal_parent'] = -1; + return $cvterms; + } + + /** + * @see MCL_TEMPLATE::runErrorCheckDataLine() + */ + public function runErrorCheckDataLine($line) { + + // Checks program_id. + $program_id = $this->getJob()->getParamByKey('program_id'); + if (!$program_id) { + $this->updateMsg('E', "program_id not found in job.param"); + } + + // Checks cross dataset. + $project_id_cross = $this->getJob()->getParamByKey('project_id_cross'); + if ($project_id_cross) { + MCL_CHADO_DATASET::checkDatasetByID($this, $project_id_cross); + } + else { + $this->updateMsg('E', "project_id_cross not found in job.param"); + } + + // Checks site. + if ($line['site_name']) { + MCL_CHADO_LOCATION::checkSite($this, $program_id . '.' . $line['site_name']); + } + + // Checks maternal parent. + if ($line['mother'] != 'N/A') { + MCL_CHADO_STOCK::checkStock($this, $program_id . '.' . $line['mother']); + } + + // Checks paternal parent. + if ($line['father'] != 'N/A') { + MCL_CHADO_STOCK::checkStock($this, $program_id . '.' . $line['father']); + } + } + + /** + * @see MCL_TEMPLATE::uploadDataLine() + */ + public function uploadDataLine($line) { + + // Gets the program_id. + $program_id = $this->getJob()->getParamByKey('program_id'); + + // Gets cross dataset. + $project_id_cross = $this->getJob()->getParamByKey('project_id_cross'); + $cross_dataset = MCL_CHADO_DATASET::byKey(array('project_id' => $project_id_cross)); + + // Gets nd_geolocation_id. + $site_name = $line['site_name']; + if ($site_name) { + $site_name = $program_id . '.' . $line['site_name']; + } + $nd_geolocation_id = MCL_CHADO_LOCATION::getLocationIDBySite($site_name); + + // Adds a nd_experiment. + $dup_key = $project_id_cross . '_' . $line['cross_number']; + $cross = MCL_CHADO_ND_EXPERIMENT::addNdExperiment($this, $this->cvterms['SITE_CV']['cross_experiment'], $nd_geolocation_id, $this->cvterms['SITE_CV']['cross_experiment'], $dup_key); + if ($cross) { + + // Adds properties. + $cross->addProp($this, 'SITE_CV', 'cross_number', $line['cross_number']); + $cross->addProp($this, 'SITE_CV', 'cross_date', $line['cross_date']); + $cross->addProp($this, 'SITE_CV', 'mother_location', $line['mother_location']); + $cross->addProp($this, 'SITE_CV', 'father_location', $line['father_location']); + + // Adds a dataset. + $cross->addDataset($this, $cross_dataset->getName()); + + // Adds a maternal parent. + if ($line['mother'] != 'N/A') { + $mother = $program_id . '.' . $line['mother']; + $maternal_parent = MCL_CHADO_STOCK::getStock($mother); + $cross->addStock($this, $maternal_parent, $this->cvterms['SITE_CV']['maternal_parent']); + } + + // Adds a paternal parent. + if ($line['father'] != 'N/A') { + $father = $program_id . '.' . $line['father']; + $paternal_parent = MCL_CHADO_STOCK::getStock($father); + $cross->addStock($this, $paternal_parent, $this->cvterms['SITE_CV']['paternal_parent']); + } + } + } +} \ No newline at end of file diff --git a/includes/class/template/module/mcl_template_cv.class.inc b/templates/mcl_template_cv.class.inc similarity index 100% rename from includes/class/template/module/mcl_template_cv.class.inc rename to templates/mcl_template_cv.class.inc diff --git a/includes/class/template/module/mcl_template_cvterm.class.inc b/templates/mcl_template_cvterm.class.inc similarity index 88% rename from includes/class/template/module/mcl_template_cvterm.class.inc rename to templates/mcl_template_cvterm.class.inc index 5285891..3bd2016 100644 --- a/includes/class/template/module/mcl_template_cvterm.class.inc +++ b/templates/mcl_template_cvterm.class.inc @@ -42,6 +42,7 @@ class MCL_TEMPLATE_CVTERM extends MCL_TEMPLATE { 'db_name' => array('req' => TRUE, 'width' => 10, 'desc' => "Name of the db."), 'cv_name' => array('req' => TRUE, 'width' => 10, 'desc' => "Name of the control vocabulary."), 'cvterm_name' => array('req' => TRUE, 'width' => 10, 'desc' => "Name of the cvterm."), + 'alias' => array('req' => FALSE, 'width' => 15, 'desc' => "Alias of the cvterm."), 'accession' => array('req' => TRUE, 'width' => 10, 'desc' => "Accession of the cvterm."), 'definition' => array('req' => FALSE, 'width' => 15, 'desc' => "Definition of the cvterm."), ); @@ -53,6 +54,7 @@ class MCL_TEMPLATE_CVTERM extends MCL_TEMPLATE { */ public function defineCvterms() { $cvterms = array(); + $cvterms['SITE_CV']['alias'] = -1; return $cvterms; } @@ -75,5 +77,9 @@ class MCL_TEMPLATE_CVTERM extends MCL_TEMPLATE { // Adds a cvterm. $cvterm = MCL_CHADO_CVTERM::addCvterm($this, $line['db_name'], $line['cv_name'], $line['cvterm_name'], $line['definition'], $line['accession']); + if ($cvterm) { + // Adds aliases. + $cvterm->addAlias($this, 'SITE_CV', 'alias', $line['alias'], '[,;]'); + } } } \ No newline at end of file diff --git a/includes/class/template/module/mcl_template_column.class.inc b/templates/mcl_template_cvterm_bims.class.inc similarity index 54% rename from includes/class/template/module/mcl_template_column.class.inc rename to templates/mcl_template_cvterm_bims.class.inc index 4f7ccb3..af2c885 100644 --- a/includes/class/template/module/mcl_template_column.class.inc +++ b/templates/mcl_template_cvterm_bims.class.inc @@ -1,9 +1,9 @@ array('req' => TRUE, 'width' => 10, 'desc' => "Name of the cvterm."), + 'cvterm_name' => array('req' => TRUE, 'width' => 10, 'desc' => "Name of the cvterm."), 'alias' => array('req' => FALSE, 'width' => 15, 'desc' => "Alias of the cvterm."), - 'cv_name' => array('req' => FALSE, 'width' => 10, 'desc' => "Name of the control vocabulary."), - 'definition' => array('req' => FALSE, 'width' => 15, 'desc' => "Definition of the control vocabulary."), + 'definition' => array('req' => FALSE, 'width' => 15, 'desc' => "Definition of the cvterm."), ); return $headers; } @@ -52,6 +51,7 @@ class MCL_TEMPLATE_COLUMN extends MCL_TEMPLATE { */ public function defineCvterms() { $cvterms = array(); + $cvterms['SITE_CV']['alias'] = -1; return $cvterms; } @@ -60,11 +60,12 @@ class MCL_TEMPLATE_COLUMN extends MCL_TEMPLATE { */ public function runErrorCheckDataLine($line) { + // Checks cv_id. + $cv_id = $this->getJob()->getParamByKey('cv_id'); + MCL_CHADO_CV::checkCVByID($this, $cv_id, TRUE); + // Checks db. MCL_CHADO_DB::checkDB($this, MCL_VAR::getValueByName('SITE_DB')); - - // Checks cv. - MCL_CHADO_CV::checkCV($this, $line['cv_name']); } /** @@ -72,32 +73,19 @@ class MCL_TEMPLATE_COLUMN extends MCL_TEMPLATE { */ public function uploadDataLine($line) { - // Gets the template name for this columns. - $csv_filepath = $this->csv->getFilepath(); - if (preg_match("/\/([A-Za-z0-9\_]+)_column.csv$/", $csv_filepath, $matches)) { - $template = $matches[1]; - } - // Gets db. $db = MCL_CHADO_DB::getDB(MCL_VAR::getValueByName('SITE_DB')); + // Gets cv. + $cv_id = $this->getJob()->getParamByKey('cv_id'); + $cv = MCL_CHADO_CV::byKey(array('cv_id' => $cv_id)); + // Adds a cvterm. - $accession = $line['name']; - $cvterm = MCL_CHADO_CVTERM::addCvterm($this, $db->getName(), $line['cv_name'], $line['name'], $line['definition'], $accession); + $cvterm = MCL_CHADO_CVTERM::addCvterm($this, $db->getName(), $cv->getName(), $line['cvterm_name'], $line['definition'], $line['accession']); if ($cvterm) { - // Gets cv. - $cv = MCL_CHADO_CV::byKey(array('cv_id' => $cvterm->getCvID())); - - // Saves in job properties. - $prop = $this->job->getPropByKey('columns'); - if (array_key_exists($template, $prop)) { - $prop[$template][$cvterm->getName()] = $cv->getName(); - } - else { - $prop[$template] = array($cvterm->getName() => $cv->getName()); - } - $this->job->setPropByKey('columns', $prop); + // Adds aliases. + $cvterm->addAlias($this, 'SITE_CV', 'alias', $line['alias'], '[,;]'); } } } \ No newline at end of file diff --git a/includes/class/template/module/mcl_template_dataset.class.inc b/templates/mcl_template_dataset.class.inc similarity index 87% rename from includes/class/template/module/mcl_template_dataset.class.inc rename to templates/mcl_template_dataset.class.inc index 06ce4c2..439e44b 100644 --- a/includes/class/template/module/mcl_template_dataset.class.inc +++ b/templates/mcl_template_dataset.class.inc @@ -43,7 +43,6 @@ class MCL_TEMPLATE_DATASET extends MCL_TEMPLATE { 'type' => array('req' => TRUE, 'width' => 12, 'desc' => "Breeding, growing (for cultivar performance data), diversity (for study of genetic diversity) or QTL."), 'sub_type' => array('req' => FALSE, 'width' => 12, 'desc' => "To specify whether the markers used were SSR or SNP when the dataset is SSR or SNP genotyping data."), 'super_dataset' => array('req' => FALSE, 'width' => 16, 'desc' => "Larger dataset that this sub_dataset belngs to."), - 'trait_descriptor_set' => array('req' => FALSE, 'width' => 16, 'desc' => "The name of the trait descriptor set that each dataset or breeder uses. This is a required column if a type of a dataset is 'breeding'."), 'pi' => array('req' => FALSE, 'width' => 12, 'desc' => "Principal Investigator (eg. breeder, corresponding author of the QTL paper) of the Dataset. It should match a 'contact_name' column in 'Contact' sheet."), 'crop' => array('req' => FALSE, 'width' => 10, 'desc' => "Name of the crop for the dataset."), 'comments' => array('req' => FALSE, 'width' => 15, 'desc' => "Any comments for the dataset."), @@ -63,7 +62,6 @@ class MCL_TEMPLATE_DATASET extends MCL_TEMPLATE { public function defineCvterms() { $cvterms = array(); $cvterms['SITE_CV']['project_type'] = -1; - $cvterms['SITE_CV']['trait_descriptor'] = -1; $cvterms['SITE_CV']['sub_type'] = -1; $cvterms['SITE_CV']['description'] = -1; $cvterms['SITE_CV']['comments'] = -1; @@ -78,12 +76,6 @@ class MCL_TEMPLATE_DATASET extends MCL_TEMPLATE { */ public function runErrorCheckDataLine($line) { - // Checks 'trait_descriptor_set' column. The column becomes required column - // if dataset type is 'breeding'. - if ($line['type'] == 'breeding') { - MCL_CHADO_CV::checkCV($this, $line['trait_descriptor_set']); - } - // Checks super_datatset. MCL_CHADO_DATASET::checkDataset($this, $line['super_datatset']); @@ -105,7 +97,6 @@ class MCL_TEMPLATE_DATASET extends MCL_TEMPLATE { // Adds properties. $dataset->addProp($this, 'SITE_CV', 'project_type', $line['type']); - $dataset->addProp($this, 'SITE_CV', 'trait_descriptor', $line['trait_descriptor_set']); $dataset->addProp($this, 'SITE_CV', 'sub_type', $line['sub_type']); $dataset->addProp($this, 'SITE_CV', 'description', $line['description']); $dataset->addProp($this, 'SITE_CV', 'crop', $line['crop']); diff --git a/templates/mcl_template_dataset_bims.class.inc b/templates/mcl_template_dataset_bims.class.inc new file mode 100644 index 0000000..ea71215 --- /dev/null +++ b/templates/mcl_template_dataset_bims.class.inc @@ -0,0 +1,103 @@ +getMemberArr()); + } + } + + /** + * @see MCL_TEMPLATE::defineDescription() + */ + public function defineDescription() { + $desc = 'The description for dataset sheet'; + return $desc; + } + + /** + * @see MCL_TEMPLATE::defineHeaders() + */ + public function defineHeaders() { + $headers = array( + 'dataset_name' => array('req' => TRUE, 'width' => 20, 'desc' => "Names of the datasets."), + 'type' => array('req' => TRUE, 'width' => 12, 'desc' => "Breeding, growing (for cultivar performance data), diversity (for study of genetic diversity) or QTL."), + 'pi' => array('req' => FALSE, 'width' => 12, 'desc' => "Principal Investigator (eg. breeder, corresponding author of the QTL paper) of the Dataset. It should match a 'contact_name' column in 'Contact' sheet."), + 'crop' => array('req' => FALSE, 'width' => 10, 'desc' => "Name of the crop for the dataset."), + 'comments' => array('req' => FALSE, 'width' => 15, 'desc' => "Any comments for the dataset."), + 'permission' => array('req' => FALSE, 'width' => 10, 'desc' => "Permission of the dataset. '0' or empty indicates public. Other positive integer indicates private."), + 'description' => array('req' => FALSE, 'width' => 90, 'desc' => "General description of the dataset (purpose, target, how many crosses, etc)."), + ); + + // Adds labels. + $headers['pi']['label'] = 'PI'; + return $headers; + } + + /** + * @see MCL_TEMPLATE::defineCvterms() + */ + public function defineCvterms() { + $cvterms = array(); + $cvterms['SITE_CV']['project_type'] = -1; + $cvterms['SITE_CV']['description'] = -1; + $cvterms['SITE_CV']['comments'] = -1; + $cvterms['SITE_CV']['crop'] = -1; + $cvterms['SITE_CV']['permission'] = -1; + return $cvterms; + } + + /** + * @see MCL_TEMPLATE::runErrorCheckDataLine() + */ + public function runErrorCheckDataLine($line) { + + // Checks super_datatset. + MCL_CHADO_DATASET::checkDataset($this, $line['super_datatset']); + + // Checks PI. + MCL_CHADO_CONTACT::checkContact($this, $line['pi']); + } + + /** + * @see MCL_TEMPLATE::uploadDataLine() + */ + public function uploadDataLine($line) { + + // Adds a dataset for BIMS. Sets the database name [program_id + dataset_name]. + $program_id = $this->getJob()->getParamByKey('program_id'); + $dataset_name = $program_id . '.' . $line['dataset_name']; + $dataset = MCL_CHADO_DATASET::addDataset($this, $dataset_name); + if ($dataset) { + + // Adds properties. + $dataset->addProp($this, 'SITE_CV', 'project_type', $line['type']); + $dataset->addProp($this, 'SITE_CV', 'description', $line['description']); + $dataset->addProp($this, 'SITE_CV', 'crop', $line['crop']); + $dataset->addProp($this, 'SITE_CV', 'comments', $line['comments']); + $dataset->addProp($this, 'SITE_CV', 'permission', $line['permission']); + + // Adds PI. + $dataset->addContact($this, $line['pi']); + } + } +} \ No newline at end of file diff --git a/includes/class/template/module/mcl_template_db.class.inc b/templates/mcl_template_db.class.inc similarity index 100% rename from includes/class/template/module/mcl_template_db.class.inc rename to templates/mcl_template_db.class.inc diff --git a/includes/class/template/module/mcl_template_descriptor.class.inc b/templates/mcl_template_descriptor.class.inc similarity index 98% rename from includes/class/template/module/mcl_template_descriptor.class.inc rename to templates/mcl_template_descriptor.class.inc index d337360..572e931 100644 --- a/includes/class/template/module/mcl_template_descriptor.class.inc +++ b/templates/mcl_template_descriptor.class.inc @@ -85,7 +85,7 @@ class MCL_TEMPLATE_DESCRIPTOR extends MCL_TEMPLATE { MCL_CHADO_CVTERM::checkCvterm($this, MCL_VAR::getValueByName('SITE_TRAIT_ONTOLOGY'), $line['trait_name']); // Checks descirptor type. - if (!MCL_DATA_VALID_TYPE::validate('descirptor_type', $line['data_type'])) { + if (!MCL_DATA_VALID_TYPE::validate('descriptor_type', $line['data_type'])) { $this->updateMsg('E', 'Invalid descirptor type : ' . $line['data_type']); } } diff --git a/templates/mcl_template_descriptor_bims.class.inc b/templates/mcl_template_descriptor_bims.class.inc new file mode 100644 index 0000000..cbd6d08 --- /dev/null +++ b/templates/mcl_template_descriptor_bims.class.inc @@ -0,0 +1,120 @@ +getMemberArr()); + } + } + + /** + * @see MCL_TEMPLATE::defineDescription() + */ + public function defineDescription() { + $desc = 'The description for descriptor sheet'; + return $desc; + } + + /** + * @see MCL_TEMPLATE::defineHeaders() + */ + public function defineHeaders() { + $headers = array( + 'descriptor_name' => array('req' => TRUE, 'width' => 15, 'desc' => "Any trait descriptor that a breeder uses in their own program. These descriptors would be used as column heads the Cross or Phenotype sheets, with a '#' prefix."), + 'alias' => array('req' => FALSE, 'width' => 15, 'desc' => "Alias of the descriptor."), + 'trait_name' => array('req' => FALSE, 'width' => 20, 'desc' => "crop trait ontology term (no specific protocol or code is involved with trait name) that corresponds to the trait descriptor (name). This should exist in 'Trait' sheet."), + 'format' => array('req' => TRUE, 'width' => 15, 'desc' => "The format of the descriptor (numerical, categorical, date, text, etc.)."), + 'categories' => array('req' => FALSE, 'width' => 10, 'desc' => "The values of the categorical descriptor separated by '/'."), + 'data_unit' => array('req' => FALSE, 'width' => 10, 'desc' => "Unit for the trait descriptor."), + 'minimum' => array('req' => FALSE, 'width' => 10, 'desc' => "The minimum value of the descriptor."), + 'maximum' => array('req' => FALSE, 'width' => 10, 'desc' => "The maximum value of the descriptor."), + 'default_value' => array('req' => FALSE, 'width' => 10, 'desc' => "The default value of the descriptor."), + 'definition' => array('req' => FALSE, 'width' => 90, 'desc' => "The definition of the descriptor."), + ); + return $headers; + } + + /** + * @see MCL_TEMPLATE::defineCvterms() + */ + public function defineCvterms() { + $cvterms = array(); + $cvterms['SITE_CV']['alias'] = -1; + $cvterms['SITE_CV']['format'] = -1; + $cvterms['SITE_CV']['categories'] = -1; + $cvterms['SITE_CV']['min_value'] = -1; + $cvterms['SITE_CV']['max_value'] = -1; + $cvterms['SITE_CV']['default_value'] = -1; + $cvterms['SITE_CV']['data_unit'] = -1; + return $cvterms; + } + + /** + * @see MCL_TEMPLATE::runErrorCheckDataLine() + */ + public function runErrorCheckDataLine($line) { + + // Checks cv_id. + $cv_id = $this->getJob()->getParamByKey('cv_id'); + MCL_CHADO_CV::checkCVByID($this, $cv_id, TRUE); + + // Checks db. + MCL_CHADO_DB::checkDB($this, MCL_VAR::getValueByName('SITE_DB')); + + // Check categories. + MCL_CHADO_CVTERM::checkCategories($this, $line['categories']); + + // Checks descirptor format. + if (!MCL_DATA_VALID_TYPE::validate('descriptor_format', $line['format'])) { + $this->updateMsg('E', 'Invalid descirptor format : ' . $line['format']); + } + } + + /** + * @see MCL_TEMPLATE::uploadDataLine() + */ + public function uploadDataLine($line) { + + // Gets db. + $db = MCL_CHADO_DB::getDB(MCL_VAR::getValueByName('SITE_DB')); + + // Gets cv. + $cv_id = $this->getJob()->getParamByKey('cv_id'); + $cv = MCL_CHADO_CV::byKey(array('cv_id' => $cv_id)); + + // Adds a descriptor. + $descriptor = MCL_CHADO_CVTERM::addCvterm($this, $db->getName(), $cv->getName(), $line['descriptor_name'], $line['definition']); + if ($descriptor) { + + // Adds properties. + $descriptor->addProp($this, 'SITE_CV', 'format', $line['format']); + $descriptor->addProp($this, 'SITE_CV', 'categories', $line['categories']); + $descriptor->addProp($this, 'SITE_CV', 'min_value', $line['minimum']); + $descriptor->addProp($this, 'SITE_CV', 'max_value', $line['maximum']); + $descriptor->addProp($this, 'SITE_CV', 'default_value', $line['default_value']); + $descriptor->addProp($this, 'SITE_CV', 'data_unit', $line['data_unit']); + + // Adds aliases. + $descriptor->addAlias($this, 'SITE_CV', 'alias', $line['alias'], '[,;]'); + } + } +} \ No newline at end of file diff --git a/includes/class/template/module/mcl_template_fieldbook.class.inc b/templates/mcl_template_fieldbook.class.inc similarity index 100% rename from includes/class/template/module/mcl_template_fieldbook.class.inc rename to templates/mcl_template_fieldbook.class.inc diff --git a/includes/class/template/module/mcl_template_genotype.class.inc b/templates/mcl_template_genotype.class.inc similarity index 100% rename from includes/class/template/module/mcl_template_genotype.class.inc rename to templates/mcl_template_genotype.class.inc diff --git a/includes/class/template/module/mcl_template_genotype_snp.class.inc b/templates/mcl_template_genotype_snp.class.inc similarity index 100% rename from includes/class/template/module/mcl_template_genotype_snp.class.inc rename to templates/mcl_template_genotype_snp.class.inc diff --git a/includes/class/template/module/mcl_template_genotype_snp_marker_column.class.inc b/templates/mcl_template_genotype_snp_marker_column.class.inc similarity index 97% rename from includes/class/template/module/mcl_template_genotype_snp_marker_column.class.inc rename to templates/mcl_template_genotype_snp_marker_column.class.inc index afcdf4f..5f011f2 100644 --- a/includes/class/template/module/mcl_template_genotype_snp_marker_column.class.inc +++ b/templates/mcl_template_genotype_snp_marker_column.class.inc @@ -121,9 +121,11 @@ class MCL_TEMPLATE_GENOTYPE_SNP_MARKER_COLUMN extends MCL_TEMPLATE { private function _checkMarkers($line) { // This should be called once. - if ($line['line_no'] != 3 || $this->getJob()->getParamByKey('marker_cols')) { + if ($line['line_no'] != 3) { return; } + //$this->getJob()->getParamByKey('marker_cols') + //$this->getJob()->getForce()) { // Gets feature_id for the markers. $markers = array(); diff --git a/includes/class/template/module/mcl_template_genotype_snp_stock_column.class.inc b/templates/mcl_template_genotype_snp_stock_column.class.inc similarity index 100% rename from includes/class/template/module/mcl_template_genotype_snp_stock_column.class.inc rename to templates/mcl_template_genotype_snp_stock_column.class.inc diff --git a/includes/class/template/module/mcl_template_genotype_ssr.class.inc b/templates/mcl_template_genotype_ssr.class.inc similarity index 100% rename from includes/class/template/module/mcl_template_genotype_ssr.class.inc rename to templates/mcl_template_genotype_ssr.class.inc diff --git a/includes/class/template/module/mcl_template_image.class.inc b/templates/mcl_template_image.class.inc similarity index 100% rename from includes/class/template/module/mcl_template_image.class.inc rename to templates/mcl_template_image.class.inc diff --git a/includes/class/template/module/mcl_template_library.class.inc b/templates/mcl_template_library.class.inc similarity index 100% rename from includes/class/template/module/mcl_template_library.class.inc rename to templates/mcl_template_library.class.inc diff --git a/includes/class/template/module/mcl_template_map.class.inc b/templates/mcl_template_map.class.inc similarity index 100% rename from includes/class/template/module/mcl_template_map.class.inc rename to templates/mcl_template_map.class.inc diff --git a/includes/class/template/module/mcl_template_map_position.class.inc b/templates/mcl_template_map_position.class.inc similarity index 91% rename from includes/class/template/module/mcl_template_map_position.class.inc rename to templates/mcl_template_map_position.class.inc index 83691d8..7c32afc 100644 --- a/includes/class/template/module/mcl_template_map_position.class.inc +++ b/templates/mcl_template_map_position.class.inc @@ -88,28 +88,12 @@ class MCL_TEMPLATE_MAP_POSITION extends MCL_TEMPLATE { MCL_CHADO_FEATUREMAP::checkMap($this, $line['map_name']); // Checks feature. It must be generic marker, MTL or QTL. - $marker_qtl_mtl = $line['marker_qtl_mtl']; - - // Gets genetic marker. - $feature = MCL_CHADO_FEATURE::getFeatureAlias($marker_qtl_mtl, $genus, $species, $this->cvterms['sequence']['genetic_marker']); - if (!$feature) { - - // Gets the QTL. - $args = array( - 'uniquename' => $marker_qtl_mtl, - 'type_id' => $this->cvterms['sequence']['qtl'], - ); - $feature = MCL_CHADO_FEATURE::byKey($args); - if (!$feature) { - - // Gets the MTL. - $args['type_id'] = $this->cvterms['sequence']['heritable_phenotypic_marker']; - $feature = MCL_CHADO_FEATURE::byKey($args); - if (!$feature) { - $this->updateMsg('E', "Error - $marker_qtl_mtl is not 'Marker, 'QTL' or 'MTL'"); - } - } - } + $type_ids = array( + 'marker' => $this->cvterms['sequence']['genetic_marker'], + 'qtl' => $this->cvterms['sequence']['qtl'], + 'mtl' => $this->cvterms['sequence']['heritable_phenotypic_marker'], + ); + MCL_CHADO_FEATURE::checkMarkerMtlQtl($this, $line['marker_qtl_mtl'], $type_ids); } /** @@ -187,7 +171,7 @@ class MCL_TEMPLATE_MAP_POSITION extends MCL_TEMPLATE { $bin_name = $line['bin_name']; if ($bin_name) { $uniquename = $map->getName() . '.' . $bin_name; - $bin = MCL_CHADO_FEATURE::addFeature($this, $uniquename, '', $this->cvterms['SITE_CV']['bin'], $organism_id); + $bin = MCL_CHADO_FEATURE::addFeature($this, $uniquename, '', $this->cvterms['SITE_CV']['bin'], $organism_id_lg); if ($bin) { // Adds a relationship. diff --git a/includes/class/template/module/mcl_template_marker.class.inc b/templates/mcl_template_marker.class.inc similarity index 100% rename from includes/class/template/module/mcl_template_marker.class.inc rename to templates/mcl_template_marker.class.inc diff --git a/includes/class/template/module/mcl_template_mtl.class.inc b/templates/mcl_template_mtl.class.inc similarity index 93% rename from includes/class/template/module/mcl_template_mtl.class.inc rename to templates/mcl_template_mtl.class.inc index 621efd0..732bef7 100644 --- a/includes/class/template/module/mcl_template_mtl.class.inc +++ b/templates/mcl_template_mtl.class.inc @@ -71,7 +71,7 @@ class MCL_TEMPLATE_MTL extends MCL_TEMPLATE { $cvterms['SITE_CV']['screening_method'] = -1; $cvterms['SITE_CV']['description'] = -1; $cvterms['SITE_CV']['published_symbol'] = -1; - $cvterms['sequence']['genetic_marker'] = -1; + $cvterms['sequence']['marker_locus'] = -1; $cvterms['sequence']['heritable_phenotypic_marker'] = -1; $cvterms['relationship']['located_in'] = -1; $cvterms['relationship']['adjacent_to'] = -1; @@ -93,10 +93,10 @@ class MCL_TEMPLATE_MTL extends MCL_TEMPLATE { MCL_CHADO_TRAIT::checkTrait($this, $line['trait_name'], $line['trait_descriptor_set']); // Checks colocalized_markers. - MCL_CHADO_FEATURE::checkFeature($this, $line['neighboring_marker'], $line['genus'], $line['species'], $this->cvterms['sequence']['genetic_marker'], '[;,]'); + MCL_CHADO_FEATURE::checkFeature($this, $line['colocalized_marker'], $line['genus'], $line['species'], $this->cvterms['sequence']['marker_locus'], '[;,]'); // Checks neighboring_markers. - MCL_CHADO_FEATURE::checkFeature($this, $line['neighboring_marker'], $line['genus'], $line['species'], $this->cvterms['sequence']['genetic_marker'], '[;,]'); + MCL_CHADO_FEATURE::checkFeature($this, $line['neighboring_marker'], $line['genus'], $line['species'], $this->cvterms['sequence']['marker_locus'], '[;,]'); // Checks images. MCL_CHADO_IMAGE::checkImage($this, $line['image'], '[;,]'); @@ -124,10 +124,10 @@ class MCL_TEMPLATE_MTL extends MCL_TEMPLATE { $mtl->addProp($this, 'SITE_CV', 'published_symbol', $line['published_symbol']); // Adds colocalized_markers. - $mtl->addRelatedFeatures($this, $line['colocalized_marker'], $this->cvterms['sequence']['genetic_marker'], FALSE, $this->cvterms['relationship']['adjacent_to'], "[,;]"); + $mtl->addRelatedFeatures($this, $line['colocalized_marker'], $this->cvterms['sequence']['marker_locus'], FALSE, $this->cvterms['relationship']['adjacent_to'], "[,;]", TRUE); // Adds neighboring_markers. - $mtl->addRelatedFeatures($this, $line['neighboring_marker'], $this->cvterms['sequence']['genetic_marker'], FALSE, $this->cvterms['relationship']['located_in'], "[,;]"); + $mtl->addRelatedFeatures($this, $line['neighboring_marker'], $this->cvterms['sequence']['marker_locus'], FALSE, $this->cvterms['relationship']['located_in'], "[,;]", TRUE); // Adds dbxref. $db = MCL_CHADO_DB::getDB('DB:genbank'); diff --git a/includes/class/template/module/mcl_template_organism.class.inc b/templates/mcl_template_organism.class.inc similarity index 100% rename from includes/class/template/module/mcl_template_organism.class.inc rename to templates/mcl_template_organism.class.inc diff --git a/includes/class/template/module/mcl_template_phenotype.class.inc b/templates/mcl_template_phenotype.class.inc similarity index 92% rename from includes/class/template/module/mcl_template_phenotype.class.inc rename to templates/mcl_template_phenotype.class.inc index 345a9f4..35dde79 100644 --- a/includes/class/template/module/mcl_template_phenotype.class.inc +++ b/templates/mcl_template_phenotype.class.inc @@ -56,6 +56,8 @@ class MCL_TEMPLATE_PHENOTYPE extends MCL_TEMPLATE { 'data_year' => array('req' => FALSE, 'width' => 10, 'desc' => "Phenotyping date if only year is known."), 'evaluation_date' => array('req' => FALSE, 'width' => 10, 'desc' => "Date of phenotype evaluation."), 'pick_date' => array('req' => FALSE, 'width' => 10, 'desc' => "Date of the sample collection if the collection is done on a different date than the phenotype evaluation."), + 'previous_entry' => array('req' => FALSE, 'width' => 10, 'desc' => "stock ID of the previous entry."), + 'barcode' => array('req' => FALSE, 'width' => 10, 'desc' => "Barcode"), 'fiber_pkg' => array('req' => FALSE, 'width' => 10, 'desc' => "Group of samples for phenotyping, can contain samples from multiple germplasm."), 'storage_time' => array('req' => FALSE, 'width' => 10, 'desc' => "Time between collection and phenotyping."), 'storage_regime' => array('req' => FALSE, 'width' => 10, 'desc' => "The condition of sample storage between the collection and phenotyping."), @@ -89,9 +91,10 @@ class MCL_TEMPLATE_PHENOTYPE extends MCL_TEMPLATE { $cvterms['SITE_CV']['evaluation_date'] = -1; $cvterms['SITE_CV']['storage_time'] = -1; $cvterms['SITE_CV']['storage_regime'] = -1; + $cvterms['SITE_CV']['previous_entry'] = -1; + $cvterms['SITE_CV']['barcode'] = -1; $cvterms['SITE_CV']['fiber_pkg'] = -1; $cvterms['SITE_CV']['comments'] = -1; - $cvterms['SITE_CV']['trait_descriptor'] = -1; $cvterms['SITE_CV']['source'] = -1; $cvterms['SITE_CV']['previous_entry'] = -1; @@ -195,12 +198,13 @@ class MCL_TEMPLATE_PHENOTYPE extends MCL_TEMPLATE { $sample->addProp($this, 'SITE_CV', 'plant_date', $line['plant_date']); $sample->addProp($this, 'SITE_CV', 'pick_date', $line['pick_date']); $sample->addProp($this, 'SITE_CV', 'storage_time', $line['storage_time']); + $sample->addProp($this, 'SITE_CV', 'barcode', $line['barcode']); $sample->addProp($this, 'SITE_CV', 'fiber_pkg', $line['fiber_pkg']); $sample->addProp($this, 'SITE_CV', 'storage_regime', $line['storage_regime']); $sample->addProp($this, 'SITE_CV', 'comments', $line['comments']); // Adds previous-entry. - $sample->addPreviousEntry($this, $line['##previous-entry']); + $sample->addPreviousEntry($this, $line['previous-entry']); // Adds phenotyping data for each descriptor. $descriptors = $this->getJob()->getParamByKey('descriptors'); @@ -212,7 +216,7 @@ class MCL_TEMPLATE_PHENOTYPE extends MCL_TEMPLATE { } // Adds a phenotype. - $uniquename = substr($descriptor . '_' . $line[$descriptor], 1); + $uniquename = $descriptor . '_' . $line[$descriptor]; $phenotype = MCL_CHADO_PHENOTYPE::addPhenotype($this, $uniquename, $cvterm_id, $line[$descriptor]); // Adds a nd_experiment. @@ -246,18 +250,19 @@ class MCL_TEMPLATE_PHENOTYPE extends MCL_TEMPLATE { private function _checkDescriptors($line, $dataset_name) { // This should be called once. - if ($line['line_no'] != 3 || $this->getJob()->getParamByKey('descriptors')) { + if ($line['line_no'] != 3) { return; } + //$this->getJob()->getParamByKey('descriptors') + //$this->getJob()->getForce()) { - // Gets the project ID and check for trait_descriptor. - $dataset = MCL_CHADO_DATASET::getDataset($line['dataset_name']); - $project_id = $dataset->getProjectID(); - $cv_name = $dataset->getProp('SITE_CV', 'trait_descriptor'); - if (!$cv_name) { - $this->updateMsg('E', "$dataset_name does not have trait_descriptor as a project property"); + // Gets the cv for the descriptors. + $cv = $this->getCvByPrefix('#'); + if (!$cv) { + $this->updateMsg('E', "cv does not exist for prefix '#'."); return; } + $cv_id = $cv->getCvID(); // Go through headers stord in the line array. $descriptors = array(); @@ -265,7 +270,7 @@ class MCL_TEMPLATE_PHENOTYPE extends MCL_TEMPLATE { if (preg_match("/^#[A-Za-z0-9\_]/", $column)) { $cvterm_name = str_replace('#', '', $column); - $cvterm = MCL_CHADO_CVTERM::getCvterm($cv_name, $cvterm_name); + $cvterm = MCL_CHADO_CVTERM::getCvtermByCvID($cv_id, $cvterm_name); if ($cvterm) { $descriptors[$column] = $cvterm->getCvtermID(); } diff --git a/templates/mcl_template_phenotype_bims.class.inc b/templates/mcl_template_phenotype_bims.class.inc new file mode 100644 index 0000000..6e848d3 --- /dev/null +++ b/templates/mcl_template_phenotype_bims.class.inc @@ -0,0 +1,396 @@ +getMemberArr()); + } + } + + /** + * @see MCL_TEMPLATE::defineDescription() + */ + public function defineDescription() { + $desc = 'The description for phenotype sheet'; + return $desc; + } + + /** + * @see MCL_TEMPLATE::defineHeaders() + */ + public function defineHeaders() { + $headers = array( + 'dataset_name' => array('req' => TRUE, 'width' => 10, 'desc' => "Name of the phenotyping dataset. It should match a 'dataset_name' column entry in the 'Dataset' sheet."), + 'stock_name' => array('req' => TRUE, 'width' => 10, 'desc' => "ID of the stock that has been phenotyped. It should match a 'stock_name' column entry in the 'Stock' sheet."), + 'genus' => array('req' => TRUE, 'width' => 10, 'desc' => ""), + 'species' => array('req' => TRUE, 'width' => 10, 'desc' => ""), + 'sample_id' => array('req' => TRUE, 'width' => 10, 'desc' => "The ID of the smallest sample or sub-sample that was tested (Each row should have unique sample_ID). If there is no unique sample ID, users can concatenate a set of columns that gives a unique phenotypic value and those columns become required fields. For example, if a combination of dataset_name, ID, phenotyping_date is unique for the specific phenotype, those three can be concatenated with '_' in between."), + 'clone_id' => array('req' => FALSE, 'width' => 10, 'desc' => "ID of a spefic clone if available (eg. individual tree)."), + 'evaluator' => array('req' => FALSE, 'width' => 10, 'desc' => "Person who did the phenotyping. Multiple person can be entered with ';' in between. It should match 'contact_name' of the Contact sheet."), + 'site_name' => array('req' => FALSE, 'width' => 10, 'desc' => "Site information where the stock for the phenotyping is planted. It should match 'site_name' in the 'Site' sheet."), + 'rep' => array('req' => FALSE, 'width' => 10, 'desc' => "Any repetition number."), + 'rootstock' => array('req' => FALSE, 'width' => 10, 'desc' => "Name of the rootstock if the plant are grafted to a rootstock. It should match an 'stock_name' column of the 'Stock' sheet."), + 'plot' => array('req' => FALSE, 'width' => 10, 'desc' => "Plot name."), + 'row' => array('req' => FALSE, 'width' => 10, 'desc' => "Row."), + 'position' => array('req' => FALSE, 'width' => 10, 'desc' => "Position of the plant."), + 'plant_date' => array('req' => FALSE, 'width' => 10, 'desc' => "Date of the planting."), + 'data_year' => array('req' => FALSE, 'width' => 10, 'desc' => "Phenotyping date if only year is known."), + 'evaluation_date' => array('req' => FALSE, 'width' => 10, 'desc' => "Date of phenotype evaluation."), + 'pick_date' => array('req' => FALSE, 'width' => 10, 'desc' => "Date of the sample collection if the collection is done on a different date than the phenotype evaluation."), + 'previous_entry' => array('req' => FALSE, 'width' => 10, 'desc' => "stock ID of the previous entry."), + 'barcode' => array('req' => FALSE, 'width' => 10, 'desc' => "Barcode"), + 'fiber_pkg' => array('req' => FALSE, 'width' => 10, 'desc' => "Group of samples for phenotyping, can contain samples from multiple germplasm."), + 'storage_time' => array('req' => FALSE, 'width' => 10, 'desc' => "Time between collection and phenotyping."), + 'storage_regime' => array('req' => FALSE, 'width' => 10, 'desc' => "The condition of sample storage between the collection and phenotyping."), + 'comments' => array('req' => FALSE, 'width' => 10, 'desc' => "Any comments for the phenotyping."), + '$$' => array('req' => FALSE, 'width' => 10, 'desc' => "Followed by cvterm name. The data will be stored in stockprop table."), + '##' => array('req' => FALSE, 'width' => 10, 'desc' => "Followed by cvterm name. The data will be stored in nd_experiementprop table."), + ); + + // Adds labels. + $headers['sample_id']['label'] = 'sample_ID'; + $headers['clone_id']['label'] = 'clone_ID'; + return $headers; + } + + /** + * @see MCL_TEMPLATE::defineCvterms() + */ + public function defineCvterms() { + $cvterms = array(); + $cvterms['SITE_CV']['phenotyping'] = -1; + $cvterms['SITE_CV']['rootstock_id'] = -1; + $cvterms['SITE_CV']['nd_geolocation_id'] = -1; + $cvterms['SITE_CV']['sample'] = -1; + $cvterms['SITE_CV']['sample_of'] = -1; + $cvterms['SITE_CV']['clone'] = -1; + $cvterms['SITE_CV']['clone_of'] = -1; + $cvterms['SITE_CV']['clone_id'] = -1; + $cvterms['SITE_CV']['plot'] = -1; + $cvterms['SITE_CV']['row'] = -1; + $cvterms['SITE_CV']['position'] = -1; + $cvterms['SITE_CV']['data_year'] = -1; + $cvterms['SITE_CV']['plant_date'] = -1; + $cvterms['SITE_CV']['pick_date'] = -1; + $cvterms['SITE_CV']['evaluation_date'] = -1; + $cvterms['SITE_CV']['storage_time'] = -1; + $cvterms['SITE_CV']['storage_regime'] = -1; + $cvterms['SITE_CV']['previous_entry'] = -1; + $cvterms['SITE_CV']['barcode'] = -1; + $cvterms['SITE_CV']['fiber_pkg'] = -1; + $cvterms['SITE_CV']['comments'] = -1; + $cvterms['SITE_CV']['source'] = -1; + $cvterms['SITE_CV']['previous_entry'] = -1; + + return $cvterms; + } + + /** + * @see MCL_TEMPLATE::runErrorCheckDataLine() + */ + public function runErrorCheckDataLine($line) { + + // Gets the program_id. + $program_id = $this->getJob()->getParamByKey('program_id'); + + // Adds prefix. + $dataset_name = $program_id . '.' . $line['dataset_name']; + $stock_name = $program_id . '.' . $line['stock_name']; + $clone_id = $program_id . '.' . $line['clone_id']; + $site_name = $program_id . '.' . $line['site_name']; + + // Checks dataset. + MCL_CHADO_DATASET::checkDataset($this, $dataset_name); + + // Checks organisms. + MCL_CHADO_ORGANISM::checkOrganism($this, $line['genus'], $line['species']); + + // Checks stock. + MCL_CHADO_STOCK::checkStock($this, $stock_name, $line['genus'], $line['species']); + + // Checks rootstock. + if ($line['rootstock']) { + $rootstock_name = $program_id . '.' . $line['rootstock']; + MCL_CHADO_STOCK::checkStock($this, $rootstock_name, $line['genus'], $line['species']); + } + + // Checks evaluator for contact. + MCL_CHADO_CONTACT::checkContact($this, $line['evaluator'], '[;]'); + + // Checks site. + MCL_CHADO_LOCATION::checkSite($this, $site_name); + + // Checks phenotypic descriptor. + $this->_checkDescriptors($line); + } + + /** + * @see MCL_TEMPLATE::uploadDataLine() + */ + public function uploadDataLine($line) { + + // Checks the data column. Skip this line if no data presents. + if ($this->isEmptyRow($line, '^#')) { + return TRUE; + } + + // Gets the organims. + $organism = MCL_CHADO_ORGANISM::getOrganism($line['genus'], $line['species']); + + // Gets the program_id. + $program_id = $this->getJob()->getParamByKey('program_id'); + + // Adds prefix. + $dataset_name = $program_id . '.' . $line['dataset_name']; + $stock_name = $program_id . '.' . $line['stock_name']; + $site_name = $program_id . '.' . $line['site_name']; + $sample_id = $program_id . '.' . $line['sample_id']; + + // Gets the stock. + $args = array( + 'uniquename' => $stock_name, + 'organism_id' => $organism->getOrganismID(), + ); + $stock = MCL_CHADO_STOCK::byKey($args); + if ($stock) { + + // Adds sample. + $sample = MCL_CHADO_STOCK::addStock($this, $sample_id, $line['sample_id'], $organism->getOrganismID(), $this->cvterms['SITE_CV']['sample']); + if (!$sample) { + return FALSE; + } + + // Adds clone. + $clone_id = $line['clone_id']; + $clone = NULL; + if ($clone_id) { + $clone_id = $program_id . '.' . $clone_id; + $clone = MCL_CHADO_STOCK::addStock($this, $clone_id, '', $organism->getOrganismID(), $this->cvterms['SITE_CV']['clone']); + } + + // Adds relationships between stock, sample and clone. + if ($clone) { + $clone->addRelatedStock($this, $stock, $this->cvterms['SITE_CV']['clone_of']); + $sample->addRelatedStock($this, $clone, $this->cvterms['SITE_CV']['sample_of']); + } + $sample->addRelatedStock($this, $stock, $this->cvterms['SITE_CV']['sample_of']); + + // Gets rootstock_id. + $rootstock_id = ''; + if ($line['rootstock']) { + $rootstock_name = $program_id . '.' . $line['rootstock']; + $rootstock = MCL_CHADO_STOCK::getStock($rootstock_name, $line['genus'], $line['species']); + if ($rootstock) { + $rootstock_id = $rootstock->getStockID(); + } + + // Adds rootstock. + $sample->addProp($this, 'SITE_CV', 'rootstock_id', $rootstock_id); + if ($clone) { + $clone->addProp($this, 'SITE_CV', 'rootstock_id', $rootstock_id); + } + } + + // Gets nd_geolocation_id. + $nd_geolocation_id = MCL_CHADO_LOCATION::getLocationIDBySite($site_name); + + // Adds clone properties. + if ($clone) { + $clone->addProp($this, 'SITE_CV', 'nd_geolocation_id', $nd_geolocation_id); + $clone->addProp($this, 'SITE_CV', 'clone_id', $clone_id); + $clone->addProp($this, 'SITE_CV', 'rep', $line['rep']); + $clone->addProp($this, 'SITE_CV', 'plot', $line['plot']); + $clone->addProp($this, 'SITE_CV', 'row', $line['row']); + $clone->addProp($this, 'SITE_CV', 'position', $line['position']); + $clone->addProp($this, 'SITE_CV', 'plant_date', $line['plant_date']); + } + + // Adds sample properties. + $sample->addProp($this, 'SITE_CV', 'nd_geolocation_id', $nd_geolocation_id); + $sample->addProp($this, 'SITE_CV', 'clone_id', $clone_id); + $sample->addProp($this, 'SITE_CV', 'rep', $line['rep']); + $sample->addProp($this, 'SITE_CV', 'plot', $line['plot']); + $sample->addProp($this, 'SITE_CV', 'row', $line['row']); + $sample->addProp($this, 'SITE_CV', 'position', $line['position']); + $sample->addProp($this, 'SITE_CV', 'plant_date', $line['plant_date']); + $sample->addProp($this, 'SITE_CV', 'pick_date', $line['pick_date']); + $sample->addProp($this, 'SITE_CV', 'storage_time', $line['storage_time']); + $sample->addProp($this, 'SITE_CV', 'barcode', $line['barcode']); + $sample->addProp($this, 'SITE_CV', 'fiber_pkg', $line['fiber_pkg']); + $sample->addProp($this, 'SITE_CV', 'storage_regime', $line['storage_regime']); + $sample->addProp($this, 'SITE_CV', 'comments', $line['comments']); + + // Adds special columns. + $this->addSpecialColumns('$$', $sample, $line); + + // Adds previous-entry. + $sample->addPreviousEntry($this, $line['previous-entry']); + + // Gets phenotyping data. + $descriptors = $this->getJob()->getParamByKey('descriptors'); + foreach ($descriptors as $cvterm_id => $descriptor) { + $name = strtolower($descriptor['name']); + + // Adds the value. + $value = $line['#' . $name]; + + // Sets the default value if provided. + if (!$value && $descriptor['default_value']) { + $value = $descriptor['default_value']; + } + + // Adds the value. + if ($value || $value == '0') { + + // Checks the value for min and max. + if ($descriptor['max_value']) {} + if ($descriptor['min_value']) {} + + // Adds a phenotype. + $uniquename = $program_id . '.' . $name . '_' . $value; + $phenotype = MCL_CHADO_PHENOTYPE::addPhenotype($this, $uniquename, $cvterm_id, $value); + + // Adds a nd_experiment. + $nd_experiment = MCL_CHADO_ND_EXPERIMENT::addNdExperiment($this, $this->cvterms['SITE_CV']['phenotyping'], $nd_geolocation_id, $cvterm_id, $sample->getStockID()); + + if ($nd_experiment) { + + // Adds properties. + $nd_experiment->addProp($this, 'SITE_CV', 'data_year', $line['data_year']); + $nd_experiment->addProp($this, 'SITE_CV', 'evaluation_date', $line['evaluation_date']); + + // Adds special columns. + $this->addSpecialColumns('##', $nd_experiment, $line); + + // Adds evaluators. + $nd_experiment->addContact($this, $line['evaluator'], "[;]"); + + // Adds a stock. + $nd_experiment->addStock($this, $sample, $sample->getTypeID()); + + // Adds a dataset. + $nd_experiment->addDataset($this, $dataset_name); + + // Adds a phenotype. + $nd_experiment->addPhenotype($this, $phenotype); + } + } + } + } + } + + /** + * Checks trait descriptors for cvterm_id. Save them in job.param. + * + * @param array $line + */ + private function _checkDescriptors($line) { + + // This should be called once. + if ($line['line_no'] != 3) { + return; + } + + // Gets the cv for the descriptors. + $cv = $this->getCvByPrefix('#'); + if (!$cv) { + $this->updateMsg('E', "cv does not exist for prefix '#'."); + return; + } + $cv_id = $cv->getCvID(); + + // Go through headers stored in the line array. + $descriptors = array(); + foreach ($line as $column => $value) { + if (preg_match("/^#[A-Za-z0-9\_]/", $column)) { + + $cvterm_name = str_replace('#', '', $column); + $cvterm = MCL_CHADO_CVTERM::getCvtermByCvID($cv_id, $cvterm_name); + if ($cvterm) { + $cvterm_id = $cvterm->getCvtermID(); + $sql = " + SELECT C.cvterm_id, C.name, FORMAT.value AS format, + MIN_VAL.value AS min_value, MAX_VAL.value AS max_value, + DEF_VAL.value AS default_value, CAT.value AS categories + FROM {chado.cvterm} C + LEFT JOIN ( + SELECT CP.cvterm_id, CP.value + FROM chado.cvtermprop CP + INNER JOIN chado.cvterm C on C.cvterm_id = CP.type_id + INNER JOIN chado.cv CV on CV.cv_id = C.cv_id + WHERE LOWER(C.name) = :format AND LOWER(CV.name) = :cv_name + ) FORMAT on FORMAT.cvterm_id = C.cvterm_id + LEFT JOIN ( + SELECT CP.cvterm_id, CP.value + FROM chado.cvtermprop CP + INNER JOIN chado.cvterm C on C.cvterm_id = CP.type_id + INNER JOIN chado.cv CV on CV.cv_id = C.cv_id + WHERE LOWER(C.name) = :min_value AND LOWER(CV.name) = :cv_name + ) MIN_VAL on MIN_VAL.cvterm_id = C.cvterm_id + LEFT JOIN ( + SELECT CP.cvterm_id, CP.value + FROM chado.cvtermprop CP + INNER JOIN chado.cvterm C on C.cvterm_id = CP.type_id + INNER JOIN chado.cv CV on CV.cv_id = C.cv_id + WHERE LOWER(C.name) = :max_value AND LOWER(CV.name) = :cv_name + ) MAX_VAL on MAX_VAL.cvterm_id = C.cvterm_id + LEFT JOIN ( + SELECT CP.cvterm_id, CP.value + FROM chado.cvtermprop CP + INNER JOIN chado.cvterm C on C.cvterm_id = CP.type_id + INNER JOIN chado.cv CV on CV.cv_id = C.cv_id + WHERE LOWER(C.name) = :default_value AND LOWER(CV.name) = :cv_name + ) DEF_VAL on DEF_VAL.cvterm_id = C.cvterm_id + LEFT JOIN ( + SELECT CP.cvterm_id, CP.value + FROM chado.cvtermprop CP + INNER JOIN chado.cvterm C on C.cvterm_id = CP.type_id + INNER JOIN chado.cv CV on CV.cv_id = C.cv_id + WHERE LOWER(C.name) = :categories AND LOWER(CV.name) = :cv_name + ) CAT on CAT.cvterm_id = C.cvterm_id + WHERE C.cvterm_id = :cvterm_id + "; + $args = array( + ':cv_name' => 'main', + ':format' => 'format', + ':min_value' => 'min_value', + ':max_value' => 'max_value', + ':default_value' => 'default_value', + ':categories' => 'categories', + ':cvterm_id' => $cvterm_id + ); + $obj = db_query($sql, $args)->fetch(PDO::FETCH_ASSOC); + $descriptors[$cvterm_id] = $obj; + } + else { + $this->updateMsg('E', "$cvterm_name not found in cvterm"); + } + } + } + $this->getJob()->setParamByKey('descriptors', $descriptors); + $this->getJob()->update(); + } +} \ No newline at end of file diff --git a/includes/class/template/module/mcl_template_progeny.class.inc b/templates/mcl_template_progeny.class.inc similarity index 100% rename from includes/class/template/module/mcl_template_progeny.class.inc rename to templates/mcl_template_progeny.class.inc diff --git a/includes/class/template/module/mcl_template_progeny_bims.class.inc b/templates/mcl_template_progeny_bims.class.inc similarity index 100% rename from includes/class/template/module/mcl_template_progeny_bims.class.inc rename to templates/mcl_template_progeny_bims.class.inc diff --git a/includes/class/template/module/mcl_template_qtl.class.inc b/templates/mcl_template_qtl.class.inc similarity index 91% rename from includes/class/template/module/mcl_template_qtl.class.inc rename to templates/mcl_template_qtl.class.inc index 45a0fb4..3b31660 100644 --- a/includes/class/template/module/mcl_template_qtl.class.inc +++ b/templates/mcl_template_qtl.class.inc @@ -55,8 +55,8 @@ class MCL_TEMPLATE_QTL extends MCL_TEMPLATE { 'dominance_effect' => array('req' => FALSE, 'width' => 10, 'desc' => "The deviation of the heterozygote phenotype from the mean of the homozygotes."), 'additivity_dominance_ratio' => array('req' => FALSE, 'width' => 10, 'desc' => "The average phenotype effect of substituting a q allele for a Q allele dominance effect The deviation of the heterozygote phenotype from the mean of the homozygotes."), 'direction' => array('req' => FALSE, 'width' => 10, 'desc' => " The direction of additive effect on the phenotype."), - 'colocalized_marker' => array('req' => FALSE, 'width' => 10, 'desc' => "Marker that are mapped within the interval defined by the QTL. Multiple markers can be added, separated by a semicolon (;)."), - 'neighboring_marker' => array('req' => FALSE, 'width' => 10, 'desc' => "Marker that is mapped in the nearest flanking position outside the interval defined by the QTL. Used to estimate QTL position if no appropriate colocalized markers are found. Multiple markers can be added, separated by a semicolon (;)."), + 'colocalized_marker' => array('req' => FALSE, 'width' => 10, 'desc' => "Marker locus that are mapped within the interval defined by the QTL. Multiple markers can be added, separated by a semicolon (;)."), + 'neighboring_marker' => array('req' => FALSE, 'width' => 10, 'desc' => "Marker locus that is mapped in the nearest flanking position outside the interval defined by the QTL. Used to estimate QTL position if no appropriate colocalized markers are found. Multiple markers can be added, separated by a semicolon (;)."), 'screening_method' => array('req' => FALSE, 'width' => 10, 'desc' => "Any specific method for the phenotypic inspection."), 'comments' => array('req' => FALSE, 'width' => 10, 'desc' => "Any comments."), 'mean' => array('req' => FALSE, 'width' => 10, 'desc' => "Mean value of the phenotype (if one QTL has multiple mean values based on the condition and/or population, enter them in QTL_trait_Data sheet."), @@ -97,7 +97,7 @@ class MCL_TEMPLATE_QTL extends MCL_TEMPLATE { $cvterms['SITE_CV']['comments'] = -1; $cvterms['SITE_CV']['population_low_value'] = -1; $cvterms['SITE_CV']['population_high_value'] = -1; - $cvterms['sequence']['genetic_marker'] = -1; + $cvterms['sequence']['marker_locus'] = -1; $cvterms['sequence']['qtl'] = -1; $cvterms['relationship']['located_in'] = -1; $cvterms['relationship']['adjacent_to'] = -1; @@ -122,10 +122,10 @@ class MCL_TEMPLATE_QTL extends MCL_TEMPLATE { MCL_CHADO_LOCATION::checkSite($this, $line['site_name']); // Checks colocalized_markers. - MCL_CHADO_FEATURE::checkFeature($this, $line['colocalized_marker'], '', '', $this->cvterms['sequence']['genetic_marker'], '[;,]'); + MCL_CHADO_FEATURE::checkFeature($this, $line['colocalized_marker'], '', '', $this->cvterms['sequence']['marker_locus'], '[;,]'); // Checks neighboring_markers. - MCL_CHADO_FEATURE::checkFeature($this, $line['neighboring_marker'], '', '', $this->cvterms['sequence']['genetic_marker'], '[;,]'); + MCL_CHADO_FEATURE::checkFeature($this, $line['neighboring_marker'], '', '', $this->cvterms['sequence']['marker_locus'], '[;,]'); // Checks references. MCL_CHADO_PUB::checkPub($this, $line['reference'], '[;,]'); @@ -177,10 +177,10 @@ class MCL_TEMPLATE_QTL extends MCL_TEMPLATE { $qtl->addSite($this, $line['site_name']); // Adds colocalized markers. - $qtl->addRelatedFeatures($this, $line['colocalized_marker'], $this->cvterms['sequence']['genetic_marker'], FALSE, $this->cvterms['relationship']['adjacent_to'], "[,;]"); + $qtl->addRelatedFeatures($this, $line['colocalized_marker'], $this->cvterms['sequence']['marker_locus'], FALSE, $this->cvterms['relationship']['adjacent_to'], "[,;]", TRUE); // Adds neighboring markers. - $qtl->addRelatedFeatures($this, $line['neighboring_marker'], $this->cvterms['sequence']['genetic_marker'], FALSE, $this->cvterms['relationship']['located_in'], "[,;]"); + $qtl->addRelatedFeatures($this, $line['neighboring_marker'], $this->cvterms['sequence']['marker_locus'], FALSE, $this->cvterms['relationship']['located_in'], "[,;]", TRUE); // Adds stocks. $qtl->addStock($this, $line['source'], $line['genus'], $line['species'], $this->cvterms['SITE_CV']['source'], "[,;]"); diff --git a/includes/class/template/module/mcl_template_qtl_trait_data.class.inc b/templates/mcl_template_qtl_trait_data.class.inc similarity index 100% rename from includes/class/template/module/mcl_template_qtl_trait_data.class.inc rename to templates/mcl_template_qtl_trait_data.class.inc diff --git a/includes/class/template/module/mcl_template_site.class.inc b/templates/mcl_template_site.class.inc similarity index 97% rename from includes/class/template/module/mcl_template_site.class.inc rename to templates/mcl_template_site.class.inc index 401212b..5c7079b 100644 --- a/includes/class/template/module/mcl_template_site.class.inc +++ b/templates/mcl_template_site.class.inc @@ -40,6 +40,7 @@ class MCL_TEMPLATE_SITE extends MCL_TEMPLATE { public function defineHeaders() { $headers = array( 'site_name' => array('req' => TRUE, 'width' => 10, 'desc' => "Curator-assigned name of the site."), + 'site_long_name' => array('req' => FALSE, 'width' => 10, 'desc' => "long name of the site."), 'latitude' => array('req' => FALSE, 'width' => 10, 'desc' => "The decimal latitude coordinate of the georeference, using positive and negative sign to indicate N and S, respectively."), 'longitude' => array('req' => FALSE, 'width' => 10, 'desc' => "The decimal longitude coordinate of the georeference, using positive and negative sign to indicate E and W, respectively."), 'altitude' => array('req' => FALSE, 'width' => 10, 'desc' => "The altitude (elevation) of the location in meters. If the altitude is only known as a range, this is the average, and altitude_dev will hold half of the width of the range."), diff --git a/templates/mcl_template_site_bims.class.inc b/templates/mcl_template_site_bims.class.inc new file mode 100644 index 0000000..5bc3325 --- /dev/null +++ b/templates/mcl_template_site_bims.class.inc @@ -0,0 +1,122 @@ +getMemberArr()); + } + } + + /** + * @see MCL_TEMPLATE::defineDescription() + */ + public function defineDescription() { + $desc = 'The description for site sheet'; + return $desc; + } + + /** + * @see MCL_TEMPLATE::defineHeaders() + */ + public function defineHeaders() { + $headers = array( + 'site_name' => array('req' => TRUE, 'width' => 10, 'desc' => "Curator-assigned name of the site."), + 'site_long_name' => array('req' => FALSE, 'width' => 10, 'desc' => "long name of the site."), + 'latitude' => array('req' => FALSE, 'width' => 10, 'desc' => "The decimal latitude coordinate of the georeference, using positive and negative sign to indicate N and S, respectively."), + 'longitude' => array('req' => FALSE, 'width' => 10, 'desc' => "The decimal longitude coordinate of the georeference, using positive and negative sign to indicate E and W, respectively."), + 'altitude' => array('req' => FALSE, 'width' => 10, 'desc' => "The altitude (elevation) of the location in meters. If the altitude is only known as a range, this is the average, and altitude_dev will hold half of the width of the range."), + 'geodetic_datum' => array('req' => FALSE, 'width' => 10, 'desc' => "The geodetic system on which the geo-reference coordinates are based. For geo-references measured between 1984 and 2010, this will typically be WGS84."), + 'type' => array('req' => FALSE, 'width' => 10, 'desc' => "'orchard', 'nursery' or any other types of location."), + 'country' => array('req' => FALSE, 'width' => 10, 'desc' => "Country where the site belongs to."), + 'state' => array('req' => FALSE, 'width' => 10, 'desc' => "State where the site belongs to."), + 'region' => array('req' => FALSE, 'width' => 10, 'desc' => "Region where the site belongs to."), + 'address' => array('req' => FALSE, 'width' => 10, 'desc' => "The entire address except the country."), + 'comments' => array('req' => FALSE, 'width' => 10, 'desc' => "Any further comments on the site."), + ); + return $headers; + } + + /** + * @see MCL_TEMPLATE::defineCvterms() + */ + public function defineCvterms() { + $cvterms = array(); + $cvterms['SITE_CV']['type'] = -1; + $cvterms['SITE_CV']['site_long_name'] = -1; + $cvterms['SITE_CV']['country'] = -1; + $cvterms['SITE_CV']['state'] = -1; + $cvterms['SITE_CV']['region'] = -1; + $cvterms['SITE_CV']['address'] = -1; + $cvterms['SITE_CV']['comments'] = -1; + $cvterms['SITE_CV']['site_code'] = -1; + return $cvterms; + } + + /** + * @see MCL_TEMPLATE::runErrorCheckDataLine() + */ + public function runErrorCheckDataLine($line) { + + // Checks for the contact type. + if (!MCL_DATA_VALID_TYPE::validate('location_type', $line['type'])) { + $this->updateMsg('E', 'Invalid location type : ' . $line['type']); + } + } + + /** + * @see MCL_TEMPLATE::uploadDataLine() + */ + public function uploadDataLine($line) { + + // Adds a location. + $loc_info = array(); + if ($line['latitude']) { + $loc_info['latitude'] = $line['latitude']; + } + if ($line['longitude']) { + $loc_info['longitude'] = $line['longitude']; + } + if ($line['altitude']) { + $loc_info['altitude'] = $line['altitude']; + } + if ($line['geodetic_datum']) { + $loc_info['geodetic_datum'] = $line['geodetic_datum']; + } + + // Sets the site name [program_id + site_name]. + $program_id = $this->getJob()->getParamByKey('program_id'); + $site_name = $program_id . '.' . $line['site_name']; + $location = MCL_CHADO_LOCATION::addLocation($this, $site_name, $loc_info); + if ($location) { + + // Adds properties. + $location->addProp($this, 'SITE_CV', 'type', $line['type']); + $location->addProp($this, 'SITE_CV', 'site_long_name', $line['site_long_name']); + $location->addProp($this, 'SITE_CV', 'country', $line['country']); + $location->addProp($this, 'SITE_CV', 'state', $line['state']); + $location->addProp($this, 'SITE_CV', 'region', $line['region']); + $location->addProp($this, 'SITE_CV', 'address', $line['address']); + $location->addProp($this, 'SITE_CV', 'country', $line['country']); + $location->addProp($this, 'SITE_CV', 'comments', $line['comments']); + } + } +} \ No newline at end of file diff --git a/includes/class/template/module/mcl_template_site_cotton.class.inc b/templates/mcl_template_site_cotton.class.inc similarity index 100% rename from includes/class/template/module/mcl_template_site_cotton.class.inc rename to templates/mcl_template_site_cotton.class.inc diff --git a/includes/class/template/module/mcl_template_stock.class.inc b/templates/mcl_template_stock.class.inc similarity index 94% rename from includes/class/template/module/mcl_template_stock.class.inc rename to templates/mcl_template_stock.class.inc index 3c5d665..99c3c7f 100644 --- a/includes/class/template/module/mcl_template_stock.class.inc +++ b/templates/mcl_template_stock.class.inc @@ -190,4 +190,24 @@ class MCL_TEMPLATE_STOCK extends MCL_TEMPLATE { $stock->addReference($this, $line['reference'], "[,;]"); } } + + /** + * @see MCL_TEMPLATE::postProcess() + */ + public function postProcess() { + + // Adds all missing parents now. + $parents = $this->getTmpByKey('stock_parents'); + foreach ((array)$parents as $stock_id => $info) { + + // Gets the parent info. + $uniquename = $info['uniquename']; + $organism_id = $info['organism_id']; + $type_id = $info['type_id']; + + // Adds the parent. + $stock = MCL_CHADO_STOCK::byKey(array('stock_id' => $stock_id)); + $stock->addParent($this, $uniquename, $organism_id, $type_id); + } + } } \ No newline at end of file diff --git a/templates/mcl_template_stock_bims.class.inc b/templates/mcl_template_stock_bims.class.inc new file mode 100644 index 0000000..6b32283 --- /dev/null +++ b/templates/mcl_template_stock_bims.class.inc @@ -0,0 +1,234 @@ +getMemberArr()); + } + } + + /** + * @see MCL_TEMPLATE::defineDescription() + */ + public function defineDescription() { + $desc = 'The description for stock sheet'; + return $desc; + } + + /** + * @see MCL_TEMPLATE::defineHeaders() + */ + public function defineHeaders() { + $headers = array( + 'stock_name' => array('req' => TRUE, 'width' => 10, 'desc' => "Primary ID or name of stock. The most important ID or name (unique and stable at least within the breeding program) should be in this column. For mapping population, follow the naming convention of each database."), + 'germplasm_type' => array('req' => TRUE, 'width' => 10, 'desc' => "Select from the three choices (cultivar, breeding_research_material, or wild_unimproved) for an individual germplasm or 'population' for a group of individual."), + 'genus' => array('req' => TRUE, 'width' => 10, 'desc' => "Genus to which the stock belongs to."), + 'species' => array('req' => TRUE, 'width' => 10, 'desc' => "Species name. Enter 'sp.' to represent one unknown species, 'spp.' to represent multiple unknown species."), + 'grin_id' => array('req' => FALSE, 'width' => 10, 'desc' => "Accession ID (ACID) in the GRIN database, if it is known."), + 'subspecies' => array('req' => FALSE, 'width' => 10, 'desc' => "Subspecies name."), + 'description' => array('req' => FALSE, 'width' => 10, 'desc' => "Stock_name for the pollen parent of this entry. This stock_name must also have its own record in this table (it should be entered before being listed as a parent)."), + 'secondary_id' => array('req' => FALSE, 'width' => 10, 'desc' => "Alternate ID or name that is commonly used to refer to the entry."), + 'paternal_parent' => array('req' => FALSE, 'width' => 10, 'desc' => "Stock_name for the pollen parent of this entry. This stock_name must also have its own record in this table (it should be entered before being listed as a parent)."), + 'maternal_parent' => array('req' => FALSE, 'width' => 10, 'desc' => "Stock_name for the seed parent of this entry. This stock_name must also have its own record in this table (it should be entered before being listed as a parent)."), + 'mutation_parent' => array('req' => FALSE, 'width' => 10, 'desc' => "Stock_name of the mutaion parent. This stock_name must also have its own record in this table (it should be entered before being listed as a parent)."), + 'selfing_parent' => array('req' => FALSE, 'width' => 10, 'desc' => "Stock_name of the selfing parent. This stock_name must also have its own record in this table (it should be entered before being listed as a parent)."), + 'alias' => array('req' => FALSE, 'width' => 10, 'desc' => "A concatenation of all other less commonly used names or designations for the entry. the aliases. The format is 'Alias type1:Alias1; Alias type2:Alias2'. When there is no specific type for aliases, just write the aliases without the specific type. (eg. Collector:98HT-227; Site:W6 21306; ABC-1; 21306) The format is 'Alias type1:Alias1; Alias type2:Alias2'. When there is no specific type for an alias, just write the aliases without the specific type. (eg. Collector:98HT-227; Site:W6 21306; ABC-1; 21306)."), + 'cultivar' => array('req' => FALSE, 'width' => 10, 'desc' => "Cultivar name if It is a named, cultivated variety."), + 'pedigree' => array('req' => FALSE, 'width' => 10, 'desc' => "Any additional pedigree information: When the exact parents are not known, or any additional information beyond just parents (eg. Red-fruit sport of Jonathan, Pyrus sp. X Cydonia sp., etc)."), + 'origin' => array('req' => FALSE, 'width' => 10, 'desc' => "The original country for the variety (especially for wild variety)."), + 'population_size' => array('req' => FALSE, 'width' => 10, 'desc' => "Only for type 'population'."), + 'germplasm_center' => array('req' => FALSE, 'width' => 10, 'desc' => "Stock center or lab where the stock is distributed. Otherwise, provide the details of the contact person in contact column (from whom the material can be obtained) in the 'Contact' sheet."), + 'description' => array('req' => FALSE, 'width' => 10, 'desc' => "any description for the stock."), + 'comments' => array('req' => FALSE, 'width' => 10, 'desc' => "Any comments on the stock."), + 'image' => array('req' => FALSE, 'width' => 10, 'desc' => "Image_ID of any associated image (Detailed info in 'Image' sheet.) Multiple images, separated by comma, can be added."), + 'reference' => array('req' => FALSE, 'width' => 10, 'desc' => "pub_id if any publication is associated with the stock."), + '##stockprop' => array('req' => FALSE, 'width' => 10, 'desc' => "Special columns (##) : followed by cvterm name of the stockprop type_id."), + ); + + // Adds labels. + $headers['grin_id']['label'] = 'GRIN_ID'; + $headers['secondary_id']['label'] = 'secondary_ID'; + return $headers; + } + + /** + * @see MCL_TEMPLATE::defineCvterms() + */ + public function defineCvterms() { + $cvterms = array(); + $cvterms['SITE_CV']['alias'] = -1; + $cvterms['SITE_CV']['secondary_id'] = -1; + $cvterms['SITE_CV']['germplasm_center'] = -1; + $cvterms['SITE_CV']['variety'] = -1; + $cvterms['SITE_CV']['cultivar'] = -1; + $cvterms['SITE_CV']['breeding_research_material'] = -1; + $cvterms['SITE_CV']['wild_unimproved'] = -1; + $cvterms['SITE_CV']['tbd'] = -1; + $cvterms['SITE_CV']['landrace'] = -1; + $cvterms['SITE_CV']['germplasm'] = -1; + $cvterms['SITE_CV']['population'] = -1; + $cvterms['SITE_CV']['species'] = -1; + $cvterms['SITE_CV']['is_a_maternal_parent_of'] = -1; + $cvterms['SITE_CV']['is_a_paternal_parent_of'] = -1; + $cvterms['SITE_CV']['is_a_mutation_parent_of'] = -1; + $cvterms['SITE_CV']['is_a_selfing_parent_of'] = -1; + $cvterms['SITE_CV']['maternal_parent'] = -1; + $cvterms['SITE_CV']['paternal_parent'] = -1; + $cvterms['SITE_CV']['mutation_parent'] = -1; + $cvterms['SITE_CV']['selfing_parent'] = -1; + $cvterms['SITE_CV']['pedigree'] = -1; + $cvterms['SITE_CV']['description'] = -1; + $cvterms['SITE_CV']['origin'] = -1; + $cvterms['SITE_CV']['comments'] = -1; + $cvterms['SITE_CV']['population_size'] = -1; + $cvterms['SITE_CV']['subspecies'] = -1; + return $cvterms; + } + + /** + * @see MCL_TEMPLATE::runErrorCheckDataLine() + */ + public function runErrorCheckDataLine($line) { + + // Checks program_id. + $program_id = $this->getJob()->getParamByKey('program_id'); + if (!$program_id) { + $this->updateMsg('E', "program_id not found in job.param"); + } + + // Checks DB for GRIN. + MCL_CHADO_DB::checkDB($this, 'GRIN'); + + // Checks organism. + MCL_CHADO_ORGANISM::checkOrganism($this, $line['genus'], $line['species']); + + // Checks aliases. + MCL_CHADO_STOCK::checkAlias($this, $line['alias'], '[;,]'); + + // Checks images. + MCL_CHADO_IMAGE::checkImage($this, $line['image'], '[;,]'); + + // Checks references. + MCL_CHADO_PUB::checkPub($this, $line['reference'], '[;,]'); + + // Checks germplasm type. + if (!MCL_DATA_VALID_TYPE::validate('stock_type', $line['germplasm_type'])) { + $this->updateMsg('E', 'Invalid stock type : ' . $line['germplasm_type']); + } + } + + /** + * @see MCL_TEMPLATE::uploadDataLine() + */ + public function uploadDataLine($line) { + + // Gets the organism. + $organism = MCL_CHADO_ORGANISM::getOrganism($line['genus'], $line['species']); + $organism_id = $organism->getOrganismID(); + + // Gets type_id. + $type_id = $this->cvterms['SITE_CV'][strtolower($line['germplasm_type'])]; + + // Updates name. + $name = ($line['secondary_id']) ? $line['secondary_id'] : ''; + + // Gets the program_id. + $program_id = $this->getJob()->getParamByKey('program_id'); + + // Sets the uniquename [program_id + stock_name]. + $uniquename = $program_id . '.' . $line['stock_name']; + + // Adds a stock. + $stock = MCL_CHADO_STOCK::addStock($this, $uniquename, $line['stock_name'], $organism_id, $type_id); + if ($stock) { + + // Gets db of GRIN and add a dbxref. + $db = MCL_CHADO_DB::getDB('GRIN'); + $dbxref = MCL_CHADO_DBXREF::addDBXref($this, $db->getDbID(), $line['grin_id']); + if ($dbxref) { + + // Adds dbxref to stock_dbxref table. + $stock->addDBXref($this, $dbxref); + + // Updates stock.dbxref_id. + $stock->setDbxrefID($dbxref->getDbxrefID()); + $stock->update(); + } + + // Adds properties. + $stock->addProp($this, 'SITE_CV', 'secondary_id', $line['secondary_id']); + $stock->addProp($this, 'SITE_CV', 'description', $line['description']); + $stock->addProp($this, 'SITE_CV', 'cultivar', $line['cultivar']); + $stock->addProp($this, 'SITE_CV', 'pedigree', $line['pedigree']); + $stock->addProp($this, 'SITE_CV', 'origin', $line['origin']); + $stock->addProp($this, 'SITE_CV', 'population_size', $line['population_size']); + $stock->addProp($this, 'SITE_CV', 'subspecies', $line['subspecies']); + $stock->addProp($this, 'SITE_CV', 'germplasm_center', $line['germplasm_center']); + $stock->addProp($this, 'SITE_CV', 'comments', $line['comments']); + + // Adds aliases. + $stock->addAlias($this, $line['alias'], "[,;]"); + + // Adds parents. + if ($line['paternal_parent']) { + $stock->addParent($this, $program_id . '.' . $line['paternal_parent'], '', $this->cvterms['SITE_CV']['is_a_maternal_parent_of']); + } + if ($line['maternal_parent']) { + $stock->addParent($this, $program_id . '.' . $line['maternal_parent'], '', $this->cvterms['SITE_CV']['is_a_paternal_parent_of']); + } + if ($line['mutation_parent']) { + $stock->addParent($this, $program_id . '.' . $line['mutation_parent'], '', $this->cvterms['SITE_CV']['is_a_mutation_parent_of']); + } + if ($line['selfing_parent']) { + $stock->addParent($this, $program_id . '.' . $line['selfing_parent'], '', $this->cvterms['SITE_CV']['is_a_selfing_parent_of']); + } + + // Adds images. + $stock->addImage($this, $line['image'], "[,;]"); + + // Adds references. + $stock->addReference($this, $line['reference'], "[,;]"); + } + } + + /** + * @see MCL_TEMPLATE::postProcess() + */ + public function postProcess() { + + // Gets the program_id. + $program_id = $this->getJob()->getParamByKey('program_id'); + + // Adds all missing parents now. + $parents = $this->getTmpByKey('stock_parents'); + foreach ((array)$parents as $stock_id => $info) { + // Gets the parent info. + $uniquename = $info['uniquename']; + $organism_id = $info['organism_id']; + $type_id = $info['type_id']; + + // Adds the parent. + $stock = MCL_CHADO_STOCK::byKey(array('stock_id' => $stock_id)); + $stock->addParent($this, $program_id . '.' . $uniquename, $organism_id, $type_id); + } + } +} \ No newline at end of file diff --git a/includes/class/template/module/mcl_template_stock_cotton.class.inc b/templates/mcl_template_stock_cotton.class.inc similarity index 94% rename from includes/class/template/module/mcl_template_stock_cotton.class.inc rename to templates/mcl_template_stock_cotton.class.inc index 5d7802e..67d519f 100644 --- a/includes/class/template/module/mcl_template_stock_cotton.class.inc +++ b/templates/mcl_template_stock_cotton.class.inc @@ -187,4 +187,24 @@ class MCL_TEMPLATE_STOCK_COTTON extends MCL_TEMPLATE { $stock->addReference($this, $line['reference'], "[,;]"); } } + + /** + * @see MCL_TEMPLATE::postProcess() + */ + public function postProcess() { + + // Adds all missing parents now. + $parents = $this->getTmpByKey('stock_parents'); + foreach ((array)$parents as $stock_id => $info) { + + // Gets the parent info. + $uniquename = $info['uniquename']; + $organism_id = $info['organism_id']; + $type_id = $info['type_id']; + + // Adds the parent. + $stock = MCL_CHADO_STOCK::byKey(array('stock_id' => $stock_id)); + $stock->addParent($this, $uniquename, $organism_id, $type_id); + } + } } \ No newline at end of file diff --git a/includes/class/template/module/mcl_template_trait.class.inc b/templates/mcl_template_trait.class.inc similarity index 100% rename from includes/class/template/module/mcl_template_trait.class.inc rename to templates/mcl_template_trait.class.inc