function chado_feature_insert
2.x tripal_feature.chado_node.inc | chado_feature_insert($node) |
3.x tripal_feature.chado_node.inc | chado_feature_insert($node) |
1.x tripal_feature.module | chado_feature_insert($node) |
Implements hook_insert().
When a new chado_feature node is created we also need to add information to our chado_feature table. This function is called on insert of a new node of type 'chado_feature' and inserts the necessary information.
Related topics
File
- tripal_feature/
includes/ tripal_feature.chado_node.inc, line 414 - Implementation of hooks to create a feature content type
Code
function chado_feature_insert($node) {
$feature_id = '';
// if there is a feature_id in the $node object then this must be a sync so
// we can skip adding the feature as it is already there, although
// we do need to proceed with insertion into the chado/drupal linking table.
if (!property_exists($node, 'feature_id')) {
$node->uniquename = trim($node->uniquename);
$node->fname = trim($node->fname);
$node->feature_type = trim($node->feature_type);
$node->residues = trim($node->residues);
// remove spaces, newlines from residues
$residues = preg_replace("/[\n\r\s]/", "", $node->residues);
$obsolete = 'FALSE';
if ($node->is_obsolete) {
$obsolete = 'TRUE';
}
// get the feature type id
$values = array(
'cv_id' => array(
'name' => 'sequence'
),
'name' => $node->feature_type
);
$type = chado_select_record('cvterm', array('cvterm_id'), $values);
$values = array(
'organism_id' => $node->organism_id,
'name' => $node->fname,
'uniquename' => $node->uniquename,
'residues' => $residues,
'seqlen' => drupal_strlen($residues),
'is_obsolete' => $obsolete,
'type_id' => $type[0]->cvterm_id,
'md5checksum' => md5($residues)
);
$feature = chado_insert_record('feature', $values);
if (!$feature) {
drupal_set_message(t('Unable to add feature.'), 'warning');
tripal_report_error('tripal_feature', TRIPAL_WARNING, 'Insert feature: Unable to create feature where values: %values',
array('%values' => print_r($values, TRUE)));
return;
}
$feature_id = $feature['feature_id'];
// add the genbank accession and synonyms
chado_feature_add_synonyms($node->synonyms, $feature_id);
// * Properties Form *
$details = array(
'property_table' => 'featureprop', // the name of the prop table
'base_table' => 'feature', // the name of your chado base table
'foreignkey_name' => 'feature_id', // the name of the key in your base table
'foreignkey_value' => $feature_id // the value of the feature_id key
);
chado_update_node_form_properties($node, $details);
// * Additional DBxrefs Form *
$details = array(
'linking_table' => 'feature_dbxref', // the name of your _dbxref table
'foreignkey_name' => 'feature_id', // the name of the key in your base table
'foreignkey_value' => $feature_id // the value of the feature_id key
);
chado_update_node_form_dbxrefs($node, $details);
// * Relationships Form *
$details = array(
'relationship_table' => 'feature_relationship',
'foreignkey_value' => $feature_id
);
chado_update_node_form_relationships($node, $details);
}
else {
$feature_id = $node->feature_id;
}
// Make sure the entry for this feature doesn't already exist in the
// chado_feature table if it doesn't exist then we want to add it.
$check_org_id = chado_get_id_from_nid('feature', $node->nid);
if (!$check_org_id) {
$record = new stdClass();
$record->nid = $node->nid;
$record->vid = $node->vid;
$record->feature_id = $feature_id;
drupal_write_record('chado_feature', $record);
}
}