function tripal_cv_obo_add_cvterm_prop
2.x tripal_cv.obo_loader.inc | tripal_cv_obo_add_cvterm_prop($cvterm, $property, $value, $rank) |
1.x obo_loader.inc | tripal_cv_obo_add_cvterm_prop($cvterm, $property, $value, $rank) |
Adds a property to a cvterm
Parameters
cvterm: A database object for the cvterm to which properties will be added
$property: The name of the property to add
$value: The value of the property
rank: The rank of the property
Related topics
1 call to tripal_cv_obo_add_cvterm_prop()
- tripal_cv_obo_process_term in tripal_cv/
includes/ tripal_cv.obo_loader.inc - Uses the provided term array to add/update information to Chado about the term including the term, dbxref, synonyms, properties, and relationships.
File
- tripal_cv/
includes/ tripal_cv.obo_loader.inc, line 1328 - Functions to aid in loading ontologies into the chado cv module
Code
function tripal_cv_obo_add_cvterm_prop($cvterm, $property, $value, $rank) {
// make sure the 'cvterm_property_type' CV exists
$cv = tripal_insert_cv('cvterm_property_type', '');
if (!$cv) {
tripal_cv_obo_quiterror("Cannot add/find cvterm_property_type cvterm");
}
// get the property type cvterm. If it doesn't exist then we want to add it
$values = array(
'name' => $property,
'cv_id' => $cv->cv_id,
);
$results = chado_select_record('cvterm', array('*'), $values);
if (count($results) == 0) {
$term = array(
'name' => $property,
'id' => "internal:$property",
'definition' => '',
'is_obsolete' => 0,
'cv_name' => $cv->name,
'is_relationship' => FALSE,
);
$cvproptype = tripal_insert_cvterm($term, array('update_existing' => FALSE));
if (!$cvproptype) {
tripal_cv_obo_quiterror("Cannot add cvterm property: internal:$property");
return FALSE;
}
}
else {
$cvproptype = $results[0];
}
// remove any properties that currently exist for this term. We'll reset them
if ($rank == 0) {
$values = array('cvterm_id' => $cvterm->cvterm_id);
$success = chado_delete_record('cvtermprop', $values);
if (!$success) {
tripal_cv_obo_quiterror("Could not remove existing properties to update property $property for term\n");
return FALSE;
}
}
// now add the property
$values = array(
'cvterm_id' => $cvterm->cvterm_id,
'type_id' => $cvproptype->cvterm_id,
'value' => $value,
'rank' => $rank,
);
$options = array('return_record' => FALSE);
$result = chado_insert_record('cvtermprop', $values, $options);
if (!$result) {
tripal_cv_obo_quiterror("Could not add property $property for term\n");
return FALSE;
}
return TRUE;
}