diff --git a/includes/TripalFields/analyzedphenotypes.fields.inc b/includes/TripalFields/analyzedphenotypes.fields.inc index aecaef9..def29ec 100644 --- a/includes/TripalFields/analyzedphenotypes.fields.inc +++ b/includes/TripalFields/analyzedphenotypes.fields.inc @@ -155,6 +155,25 @@ function analyzedphenotypes_bundle_fields_info($entity_type, $bundle) { ), ); + // Phenotype Ontology. + tripal_insert_cvterm(array( + 'id' => 'NCIT:C52469', + 'name' => 'Synonym', + 'cv_name' => 'NCIT', + 'definition' => 'A word having the same or nearly the same meaning as another word or other words in a language; a word or an expression that serves as a figurative or symbolic substitute for another', + )); + $field_name = 'ncit__synonym'; + $field_type = 'ncit__synonym'; + $fields[$field_name] = array( + 'field_name' => $field_name, + 'type' => $field_type, + 'cardinality' => 1, + 'locked' => FALSE, + 'storage' => array( + 'type' => 'field_chado_storage', + ), + ); + // Phenotype Image tripal_insert_cvterm(array( 'id' => 'NCIT:C48179', @@ -503,6 +522,38 @@ function analyzedphenotypes_bundle_instances_info($entity_type, $bundle) { ), ); + // Phenotype Ontology - Synonym. + $field_name = 'ncit__synonym'; + $field_type = 'ncit__synonym'; + $instances[$field_name] = array( + 'field_name' => $field_name, + 'entity_type' => $entity_type, + 'bundle' => $bundle->name, + 'label' => 'Phenotype Ontology', + 'description' => 'Phenotype Ontology.', + 'required' => FALSE, + 'settings' => array( + 'term_vocabulary' => 'NCIT', + 'term_name' => 'Synonym', + 'term_accession' => 'c52469', + 'auto_attach' => FALSE, + 'chado_table' => $bundle->data_table, + 'chado_column' => $bundle->data_table . '_id', + 'base_table' => $bundle->data_table, + ), + 'widget' => array( + 'type' => 'ncit__synonym_widget', + 'settings' => array(), + ), + 'display' => array( + 'default' => array( + 'label' => 'hidden', + 'type' => 'ncit__synonym_formatter', + 'settings' => array(), + ), + ), + ); + // Phenotype Image. $field_name = 'ncit__image'; $field_type = 'ncit__image'; diff --git a/includes/TripalFields/ncit__synonym/ncit__synonym.inc b/includes/TripalFields/ncit__synonym/ncit__synonym.inc new file mode 100644 index 0000000..fd5580d --- /dev/null +++ b/includes/TripalFields/ncit__synonym/ncit__synonym.inc @@ -0,0 +1,220 @@ + 'tripal_no_storage', + // It is expected that all fields set a 'value' in the load() function. + // In many cases, the value may be an associative array of key/value pairs. + // In order for Tripal to provide context for all data, the keys should + // be a controlled vocabulary term (e.g. rdfs:type). Keys in the load() + // function that are supported by the query() function should be + // listed here. + 'browseable_keys' => array(), + ); + + // Provide a list of instance specific settings. These can be access within + // the instanceSettingsForm. When the instanceSettingsForm is submitted + // then Drupal with automatically change these settings for the instance. + // It is recommended to put settings at the instance level whenever possible. + // If you override this variable in a child class be sure to replicate the + // term_name, term_vocab, term_accession and term_fixed keys as these are + // required for all TripalFields. + public static $default_instance_settings = array( + // The short name for the vocabulary (e.g. schema, SO, GO, PATO, etc.). + 'term_vocabulary' => 'NCIT', + // The name of the term. + 'term_name' => 'Synonym', + // The unique ID (i.e. accession) of the term. + 'term_accession' => 'c52469', + // Set to TRUE if the site admin is not allowed to change the term + // type, otherwise the admin can change the term mapped to a field. + 'term_fixed' => FALSE, + // Indicates if this field should be automatically attached to display + // or web services or if this field should be loaded separately. This + // is convenient for speed. Fields that are slow should for loading + // should have auto_attach set to FALSE so tha their values can be + // attached asynchronously. + 'auto_attach' => FALSE, + // The table where the options for this specific field are stored. + // This can be one of trpfancy_browse_options or trpfancy_browse_options_per_entity + // based on admin configuration. Default: trpfancy_browse_options. + 'option_storage' => '', + // A list of browser types this field intends to provide. + 'browser_types' => '', + + 'chado_table' => 'cvterm_relationship', + 'chado_column' => 'cvterm_relationship_id', + 'base_table' => 'cvterm_relationship' + + ); + + // A boolean specifying that users should not be allowed to create + // fields and instances of this field type through the UI. Such + // fields can only be created programmatically with field_create_field() + // and field_create_instance(). + public static $no_ui = FALSE; + // A boolean specifying that the field will not contain any data. This + // should exclude the field from web services or downloads. An example + // could be a quick browse field that appears on the page that redirects + // the user but otherwise provides no data. + public static $no_data = TRUE; + + /** + * Loads the field values from the underlying data store. + * + * @param $entity + * + * @return + * An array of the following format: + * $entity->{$field_name}['und'][0]['value'] = $value; + * where: + * - $entity is the entity object to which this field is attached. + * - $field_name is the name of this field + * - 'und' is the language code (in this case 'und' == undefined) + * - 0 is the cardinality. Increment by 1 when more than one item is + * available. + * - 'value' is the key indicating the value of this field. It should + * always be set. The value of the 'value' key will be the contents + * used for web services and for downloadable content. The value + * should be of the follow format types: 1) A single value (text, + * numeric, etc.) 2) An array of key value pair. 3) If multiple entries + * then cardinality should incremented and format types 1 and 2 should + * be used for each item. + * The array may contain as many other keys at the same level as 'value' + * but those keys are for internal field use and are not considered the + * value of the field. + * + * + */ + public function load($entity) { + $record = $entity->chado_record_id; + + if ($record) { + // We need the term configuration for term Related used when creating relationship. + $sysvar = ap_get_variablenames( + array('variablename' => 'related'), + array('set' => 'terms') + ); + $sysvar_related = variable_get($sysvar); + + if ($sysvar_related) { + // Inspect to see if this trait has crop ontology set in chado.cvterm_relationship + // using what is known - type_id of ontology Related (in configuration) and the object_id + // which is the current trait. + + $identifiers = array( + 'column' => array('cvterm_relationship_id', 'subject_id'), + 'value' => array('type_id' => $sysvar_related, 'object_id' => $record) + ); + $rel = chado_select_record('cvterm_relationship', $identifiers['column'], $identifiers['value']); + + $field_name = $this->field['field_name']; + $field_table = 'chado-cvterm_relationship__'; + + if ($rel) { + // Has crop ontology. + + // For chado mechnanism. + $entity->{$field_name}['und'][0] = array( + // Row id #. + $field_table . 'cvterm_relationship_id' => $rel[0]->cvterm_relationship_id, + // Relationship details. + $field_table . 'type_id' => $sysvar_related, + $field_table . 'object_id' => $entity->chado_record_id, + $field_table . 'subject_id' => $rel[0]->subject_id + ); + + // For end user. + // Sending the term, accession and cv name. Last two items are used to constuct + // direct link to vocabulary lookup to a more details about a term. + $termprop = chado_generate_var('cvterm', array( + 'cvterm_id' => $rel[0]->subject_id + )); + + // Term. + $relationship_term = tripal_get_chado_semweb_term('cvterm_relationship', 'subject_id'); + $entity->{$field_name}['und'][0]['value'][ $relationship_term ] = $termprop->name; + + // Accession. + $accession = tripal_get_chado_semweb_term('dbxref', 'accession'); + $entity->{$field_name}['und'][0]['value'][ $accession ] = $termprop->dbxref_id->accession; + + // CV. + $cv_term = tripal_get_chado_semweb_term('cv', 'name'); + $entity->{$field_name}['und'][0]['value'][ $cv_term ] = $termprop->cv_id->name; + } + else { + // Crop ontology not set. + // Nothing here, just forward what we know so far, Related term and the trait id. + $entity->{$field_name}['und'][0] = array( + 'value' => array(), + $field_table . 'object_id' => $entity->chado_record_id, + $field_table . 'type_id' => $sysvar_related, + ); + } + } + } + } + + /** + * Provides a form for the 'Field Settings' of an instance of this field. + * + * This function corresponds to the hook_field_instance_settings_form() + * function of the Drupal Field API. + * + * Validation of the instance settings form is not supported by Drupal, but + * the TripalField class does provide a mechanism for supporting validation. + * To allow for validation of your setting form you must call the parent + * in your child class: + * + * @code + * $element = parent::instanceSettingsForm(); + * @endcode + * + * Please note, the form generated with this function does not easily + * support AJAX calls in the same way that other Drupal forms do. If you + * need to use AJAX you must manually alter the $form in your ajax call. + * The typical way to handle updating the form via an AJAX call is to make + * the changes in the form function itself but that doesn't work here. + */ + public function instanceSettingsForm() { + + // Retrieve the current settings. + // If this field was just created these will contain the default values. + $settings = $this->instance['settings']; + + // Allow the parent Tripal Field to set up the form element for us. + $element = parent::instanceSettingsForm(); + + return $element; + } +} diff --git a/includes/TripalFields/ncit__synonym/ncit__synonym_formatter.inc b/includes/TripalFields/ncit__synonym/ncit__synonym_formatter.inc new file mode 100644 index 0000000..50b6bb7 --- /dev/null +++ b/includes/TripalFields/ncit__synonym/ncit__synonym_formatter.inc @@ -0,0 +1,77 @@ + array('target' => '_blank'))); + + $element[0] = array( + '#type' => 'markup', + '#markup' => '