function tripal_feature_set_taxonomy
1.x tripal_feature.admin.inc | tripal_feature_set_taxonomy($node, $feature_id) |
Related topics
4 calls to tripal_feature_set_taxonomy()
- tripal_features_set_taxonomy in tripal_feature/
includes/ tripal_feature.admin.inc - tripal_feature_sync_feature in tripal_feature/
includes/ tripal_feature.sync_features.inc - tripal_library_taxonify_features in tripal_library/
includes/ tripal_library.admin.inc - tripal_organism_taxonify_features in tripal_organism/
includes/ tripal_organism.admin.inc
File
- tripal_feature/
includes/ tripal_feature.admin.inc, line 456 - @todo Add file header description
Code
function tripal_feature_set_taxonomy($node, $feature_id) {
// iterate through the taxonomy classes that have been
// selected by the admin user and make sure we only set those
$tax_classes = variable_get('tax_classes', array());
$do_ft = 0;
$do_op = 0;
$do_lb = 0;
$do_an = 0;
foreach ($tax_classes as $class) {
if (strcmp($class, 'organism') == 0) {
$do_op = 1;
}
if (strcmp($class, 'feature_type') == 0) {
$do_ft = 1;
}
if (strcmp($class, 'library') == 0) {
$do_lb = 1;
}
if (strcmp($class, 'analysis') == 0) {
$do_an = 1;
}
}
// get the list of vocabularies and find our two vocabularies of interest
$vocabularies = taxonomy_get_vocabularies();
$ft_vid = NULL;
$op_vid = NULL;
$lb_vid = NULL;
$an_vid = NULL;
foreach ($vocabularies as $vocab) {
if ($vocab->name == 'Feature Type') {
$ft_vid = $vocab->vid;
}
if ($vocab->name == 'Organism') {
$op_vid = $vocab->vid;
}
if ($vocab->name == 'Library') {
$lb_vid = $vocab->vid;
}
if ($vocab->name == 'Analysis') {
$an_vid = $vocab->vid;
}
}
// get the cvterm and the organism for this feature
$sql = "SELECT CVT.name AS cvname, O.genus, O.species " .
"FROM {CVTerm} CVT " .
" INNER JOIN {Feature} F on F.type_id = CVT.cvterm_id " .
" INNER JOIN {Organism} O ON F.organism_id = O.organism_id " .
"WHERE F.feature_id = $feature_id";
$feature = db_fetch_object(chado_query($sql));
// Set the feature type for this feature
if ($do_ft && $ft_vid) {
$tags["$ft_vid"] = "$feature->cvname";
}
// Set the organism for this feature type
if ($do_op && $op_vid) {
$tags["$op_vid"] = "$feature->genus $feature->species";
}
// get the library that this feature may belong to and add it as taxonomy
if ($do_lb && $lb_vid) {
$sql = "SELECT L.name " .
"FROM {Library} L " .
" INNER JOIN {Library_feature} LF ON LF.library_id = L.library_id " .
"WHERE LF.feature_id = %d ";
$library = db_fetch_object(chado_query($sql, $feature_id));
$tags["$lb_vid"] = "$library->name";
}
// now add the taxonomy to the node
$terms['tags'] = $tags;
taxonomy_node_save($node, $terms);
// print "Setting $node->name: " . implode(", ",$tags) . "\n";
// get the analysis that this feature may belong to and add it as taxonomy
// We'll add each one individually since there may be more than one analysis
if ($do_an && $an_vid) {
$sql = "SELECT A.name " .
"FROM {Analysis} A " .
" INNER JOIN {Analysisfeature} AF ON AF.analysis_id = A.analysis_id " .
"WHERE AF.feature_id = $feature_id ";
$results = chado_query($sql);
$analysis_terms = array();
while ($analysis = db_fetch_object($results)) {
$tags2["$an_vid"] = "$analysis->name";
$terms['tags'] = $tags2;
taxonomy_node_save($node, $terms);
}
}
}