function tripal_feature_add_organism_count_mview
2.x tripal_feature.install | tripal_feature_add_organism_count_mview() |
1.x tripal_feature.install | tripal_feature_add_organism_count_mview() |
Creates a materialized view that stores the type & number of features per organism
Related topics
1 call to tripal_feature_add_organism_count_mview()
- tripal_feature_install in tripal_feature/
tripal_feature.install - Implements hook_install().
File
- tripal_feature/
tripal_feature.install, line 243 - Installation of the feature module
Code
function tripal_feature_add_organism_count_mview() {
$view_name = 'organism_feature_count';
$comment = 'Stores the type and number of features per organism';
$schema = array(
'description' => $comment,
'table' => $view_name,
'fields' => array(
'organism_id' => array(
'size' => 'big',
'type' => 'int',
'not null' => TRUE,
),
'genus' => array(
'type' => 'varchar',
'length' => '255',
'not null' => TRUE,
),
'species' => array(
'type' => 'varchar',
'length' => '255',
'not null' => TRUE,
),
'common_name' => array(
'type' => 'varchar',
'length' => '255',
'not null' => FALSE,
),
'num_features' => array(
'type' => 'int',
'not null' => TRUE,
),
'cvterm_id' => array(
'size' => 'big',
'type' => 'int',
'not null' => TRUE,
),
'feature_type' => array(
'type' => 'varchar',
'length' => '255',
'not null' => TRUE,
),
),
'indexes' => array(
'organism_feature_count_idx1' => array('organism_id'),
'organism_feature_count_idx2' => array('cvterm_id'),
'organism_feature_count_idx3' => array('feature_type'),
),
);
$sql = "
SELECT
O.organism_id, O.genus, O.species, O.common_name,
count(F.feature_id) as num_features,
CVT.cvterm_id, CVT.name as feature_type
FROM organism O
INNER JOIN feature F ON O.Organism_id = F.organism_id
INNER JOIN cvterm CVT ON F.type_id = CVT.cvterm_id
GROUP BY
O.Organism_id, O.genus, O.species, O.common_name, CVT.cvterm_id, CVT.name
";
tripal_add_mview($view_name, 'tripal_feature', $schema, $sql, $comment);
}