function tripal_feature_load_gff3_alias
2.x tripal_feature.gff_loader.inc | tripal_feature_load_gff3_alias($feature, $aliases) |
1.x gff_loader.inc | tripal_feature_load_gff3_alias($feature, $aliases) |
Load any aliases for a feature
Parameters
$feature:
$aliases:
Related topics
1 call to tripal_feature_load_gff3_alias()
- tripal_feature_load_gff3 in tripal_feature/
includes/ tripal_feature.gff_loader.inc - Actually load a GFF3 file. This is the function called by tripal jobs
File
- tripal_feature/
includes/ tripal_feature.gff_loader.inc, line 1547 - Provides gff3 loading functionality. Creates features based on their specification in a GFF3 file.
Code
function tripal_feature_load_gff3_alias($feature, $aliases) {
// make sure we have a 'synonym_type' vocabulary
$select = array('name' => 'synonym_type');
$results = chado_select_record('cv', array('*'), $select);
if (count($results) == 0) {
// insert the 'synonym_type' vocabulary
$values = array(
'name' => 'synonym_type',
'definition' => 'vocabulary for synonym types',
);
$success = chado_insert_record('cv', $values);
if (!$success) {
tripal_report_error("tripal_feature", TRIPAL_WARNING, "Failed to add the synonyms type vocabulary", array());
return 0;
}
// now that we've added the cv we need to get the record
$results = chado_select_record('cv', array('*'), $select);
if (count($results) > 0) {
$syncv = $results[0];
}
}
else {
$syncv = $results[0];
}
// get the 'exact' cvterm, which is the type of synonym we're adding
$select = array(
'name' => 'exact',
'cv_id' => array(
'name' => 'synonym_type'
),
);
$result = chado_select_record('cvterm', array('*'), $select);
if (count($result) == 0) {
$term = array(
'name' => 'exact',
'id' => "local:exact",
'definition' => '',
'is_obsolete' => 0,
'cv_name' => $syncv->name,
'is_relationship' => FALSE
);
$syntype = tripal_insert_cvterm($term, array('update_existing' => TRUE));
if (!$syntype) {
tripal_report_error("tripal_feature", TRIPAL_WARNING, "Cannot add synonym type: internal:$type", array());
return 0;
}
}
else {
$syntype = $result[0];
}
// iterate through all of the aliases and add each one
foreach ($aliases as $alias) {
// check to see if the alias already exists in the synonym table
// if not, then add it
$select = array(
'name' => $alias,
'type_id' => $syntype->cvterm_id,
);
$result = chado_select_record('synonym', array('*'), $select);
if (count($result) == 0) {
$values = array(
'name' => $alias,
'type_id' => $syntype->cvterm_id,
'synonym_sgml' => '',
);
$success = chado_insert_record('synonym', $values);
if (!$success) {
tripal_report_error("tripal_feature", TRIPAL_WARNING, "Cannot add alias $alias to synonym table", array());
return 0;
}
$result = chado_select_record('synonym', array('*'), $select);
$synonym = $result[0];
}
else {
$synonym = $result[0];
}
// check to see if we have a NULL publication in the pub table. If not,
// then add one.
$select = array('uniquename' => 'null');
$result = chado_select_record('pub', array('*'), $select);
if (count($result) == 0) {
$pub_sql = "
INSERT INTO {pub} (uniquename,type_id)
VALUES (:uname,
(SELECT cvterm_id
FROM {cvterm} CVT
INNER JOIN {dbxref} DBX ON DBX.dbxref_id = CVT.dbxref_id
INNER JOIN {db} DB ON DB.db_id = DBX.db_id
WHERE CVT.name = :type_id))
";
$status = chado_query($psql);
if (!$status) {
tripal_report_error("tripal_feature", TRIPAL_WARNING, "Cannot prepare statement 'ins_pub_uniquename_typeid", array());
return 0;
}
// insert the null pub
$result = chado_query($pub_sql, array(':uname' => 'null', ':type_id' => 'null'))->fetchObject();
if (!$result) {
tripal_report_error("tripal_feature", TRIPAL_WARNING, "Cannot add null publication needed for setup of alias", array());
return 0;
}
$result = chado_select_record('pub', array('*'), $select);
$pub = $result[0];
}
else {
$pub = $result[0];
}
// check to see if the synonym exists in the feature_synonym table
// if not, then add it.
$values = array(
'synonym_id' => $synonym->synonym_id,
'feature_id' => $feature->feature_id,
'pub_id' => $pub->pub_id,
);
$columns = array('feature_synonym_id');
$result = chado_select_record('feature_synonym', $columns, $values);
if (count($result) == 0) {
$values = array(
'synonym_id' => $synonym->synonym_id,
'feature_id' => $feature->feature_id,
'pub_id' => $pub->pub_id,
);
$success = chado_insert_record('feature_synonym', $values);
if (!$success) {
tripal_report_error("tripal_feature", TRIPAL_WARNING, "Cannot add alias $alias to feature synonym table", array());
return 0;
}
}
}
return 1;
}