function tripal_feature_sync_features
1.x tripal_feature.sync_features.inc | tripal_feature_sync_features($max_sync = 0, $organism_id = NULL,
$feature_types = NULL, $job_id = NULL) |
Related topics
1 call to tripal_feature_sync_features()
- tripal_feature.sync_features.inc in tripal_feature/
includes/ tripal_feature.sync_features.inc - @todo Add file header description
4 string references to 'tripal_feature_sync_features'
- drush_tripal_core_tripal_node_sync in tripal_core/
tripal_core.drush.inc - Sync's chado records with drupal creating nodes for the given chado-centric module.
- tripal_feature_admin_validate in tripal_feature/
includes/ tripal_feature.admin.inc - tripal_feature_job_describe_args in tripal_feature/
tripal_feature.module - tripal_feature_sync_form_submit in tripal_feature/
includes/ tripal_feature.sync_features.inc
File
- tripal_feature/
includes/ tripal_feature.sync_features.inc, line 300 - @todo Add file header description
Code
function tripal_feature_sync_features($max_sync = 0, $organism_id = NULL,
$feature_types = NULL, $job_id = NULL) {
$i = 0;
// get the list of available sequence ontology terms for which
// we will build drupal pages from features in chado. If a feature
// is not one of the specified typse we won't build a node for it.
if (!$feature_types) {
$allowed_types = variable_get('chado_sync_feature_types', 'gene contig');
}
else {
$allowed_types = $feature_types;
}
$allowed_types = preg_replace("/[\s\n\r]+/", " ", $allowed_types);
print "Looking for features of type: $allowed_types\n";
$so_terms = split(' ', $allowed_types);
$where_cvt = "";
foreach ($so_terms as $term) {
$where_cvt .= "CVT.name = '$term' OR ";
}
$where_cvt = drupal_substr($where_cvt, 0, drupal_strlen($where_cvt) -3); # strip trailing 'OR'
// get the list of organisms that are synced and only include features from
// those organisms
$orgs = tripal_organism_get_synced();
$where_org = "";
foreach ($orgs as $org) {
if ($organism_id) {
if ($org->organism_id and $org->organism_id == $organism_id) {
$where_org .= "F.organism_id = $org->organism_id OR ";
}
}
else {
if ($org->organism_id) {
$where_org .= "F.organism_id = $org->organism_id OR ";
}
}
}
$where_org = drupal_substr($where_org, 0, drupal_strlen($where_org) -3); # strip trailing 'OR'
// use this SQL statement to get the features that we're going to upload
$sql = "SELECT feature_id " .
"FROM {FEATURE} F " .
" INNER JOIN {Cvterm} CVT ON F.type_id = CVT.cvterm_id " .
" INNER JOIN {CV} on CV.cv_id = CVT.cv_id " .
"WHERE ($where_cvt) AND ($where_org) AND CV.name = 'sequence' " .
"ORDER BY feature_id";
// get the list of features
$results = chado_query($sql);
// load into ids array
$count = 0;
$ids = array();
while ($id = db_fetch_object($results)) {
$ids[$count] = $id->feature_id;
$count++;
}
// make sure our vocabularies are set before proceeding
tripal_feature_set_vocabulary();
// pre-create the SQL statement that will be used to check
// if a feature has already been synced. We skip features
// that have been synced
$sql = "SELECT * FROM {chado_feature} WHERE feature_id = %d";
// Iterate through features that need to be synced
$interval = intval($count * 0.01);
if ($interval < 1) {
$interval = 1;
}
$num_ids = sizeof($ids);
$i = 0;
foreach ($ids as $feature_id) {
// update the job status every 1% features
if ($job_id and $i % $interval == 0) {
tripal_job_set_progress($job_id, intval(($i / $count) * 100));
}
// if we have a maximum number to sync then stop when we get there
// if not then just continue on
if ($max_sync and $i == $max_sync) {
return '';
}
if (!db_fetch_object(db_query($sql, $feature_id))) {
# parsing all the features can cause memory overruns
# we are not sure why PHP does not clean up the memory as it goes
# to avoid this problem we will call this script through an
# independent system call
print "$i of $num_ids Syncing feature id: $feature_id\n";
$cmd = "php " . drupal_get_path('module', 'tripal_feature') . "/includes/tripal_feature.sync_features.inc -f $feature_id -t chado_feature";
system($cmd);
}
$i++;
}
return '';
}