123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329 |
- <?php
- function tripal_feature_preprocess_tripal_feature_sequence(&$variables) {
-
- $feature = $variables['node']->feature;
-
- $options = array(
- 'return_array' => 1,
- 'include_fk' => array(
- 'srcfeature_id' => array(
- 'type_id' => 1
- ),
- ),
- );
- $feature = chado_expand_var($feature, 'table', 'featureloc', $options);
-
-
- $ffeaturelocs = $feature->featureloc->feature_id;
-
- $featureloc_sequences = tripal_feature_load_featureloc_sequences($feature->feature_id, $ffeaturelocs);
- $feature->featureloc_sequences = $featureloc_sequences;
- }
- function tripal_feature_preprocess_tripal_feature_relationships(&$variables) {
-
- $feature = $variables['node']->feature;
- if (!property_exists($feature, 'all_relationships')) {
- $feature->all_relationships = tripal_feature_get_feature_relationships($feature);
- }
- }
- function tripal_feature_preprocess_tripal_feature_proteins(&$variables) {
-
- $feature = $variables['node']->feature;
- if (!property_exists($feature, 'all_relationships')) {
- $feature->all_relationships = tripal_feature_get_feature_relationships($feature);
- }
- }
- function tripal_feature_preprocess_tripal_feature_alignments(&$variables) {
-
- $feature = $variables['node']->feature;
- $options = array(
- 'return_array' => 1,
- 'include_fk' => array(
- 'srcfeature_id' => array(
- 'type_id' => 1,
- ),
- 'feature_id' => array(
- 'type_id' => 1
- ),
- )
- );
- $feature = chado_expand_var($feature, 'table', 'featureloc', $options);
-
- $cfeaturelocs = $feature->featureloc->feature_id;
- if (!$cfeaturelocs) {
- $cfeaturelocs = array();
- }
-
- $pfeaturelocs = $feature->featureloc->srcfeature_id;
- if (!$pfeaturelocs) {
- $pfeaturelocs = array();
- }
-
- $mfeaturelocs = tripal_feature_get_matched_alignments($feature);
- $feature->matched_featurelocs = $mfeaturelocs;
-
-
- $alignments = array();
- foreach ($pfeaturelocs as $featureloc) {
-
- if (preg_match('/(^match$|^.*?_match|match_part)$/', $featureloc->feature_id->type_id->name)) {
- continue;
- }
- $alignment = new stdClass();
- $alignment->record = $featureloc;
- $alignment->name = $featureloc->feature_id->name;
- $alignment->type = $featureloc->feature_id->type_id->name;
- $alignment->fmin = $featureloc->fmin;
- $alignment->fmax = $featureloc->fmax;
- $alignment->phase = $featureloc->phase;
- $alignment->strand = $featureloc->strand;
- $alignments[] = $alignment;
- if (property_exists($featureloc->feature_id, 'nid')) {
- $alignment->nid = $featureloc->feature_id->nid;
- }
- }
- foreach ($cfeaturelocs as $featureloc) {
-
- if (preg_match('/(^match$|^.*?_match|match_part)$/', $featureloc->feature_id->type_id->name)) {
- continue;
- }
- $alignment = new stdClass();
- $alignment->record = $featureloc;
- $alignment->name = $featureloc->srcfeature_id->name;
- $alignment->type = $featureloc->srcfeature_id->type_id->name;
- $alignment->fmin = $featureloc->fmin;
- $alignment->is_fmin_partial = $featureloc->is_fmin_partial;
- $alignment->fmax = $featureloc->fmax;
- $alignment->is_fmax_partial = $featureloc->is_fmax_partial;
- $alignment->phase = $featureloc->phase;
- $alignment->strand = $featureloc->strand;
- $alignments[] = $alignment;
- if (property_exists($featureloc->srcfeature_id, 'nid')) {
- $alignment->nid = $featureloc->srcfeature_id->nid;
- }
- }
-
-
- foreach ($mfeaturelocs as $featureloc) {
-
- $select = array('feature_id' => $featureloc->right_srcfeature_id);
- $rfeature = chado_generate_var('feature', $select);
-
- $alignment = new stdClass();
- $alignment->record = $featureloc;
- $alignment->right_feature = $rfeature;
- $alignment->name = $rfeature->name;
- $alignment->type = $rfeature->type_id->name;
- $alignment->fmin = $featureloc->left_fmin;
- $alignment->is_fmin_partial = $featureloc->left_is_fmin_partial;
- $alignment->fmax = $featureloc->left_fmax;
- $alignment->is_fmax_partial = $featureloc->left_is_fmax_partial;
- $alignment->phase = $featureloc->left_phase;
- $alignment->strand = $featureloc->left_strand;
- $alignment->right_fmin = $featureloc->right_fmin;
- $alignment->right_is_fmin_partial = $featureloc->right_is_fmin_partial;
- $alignment->right_fmax = $featureloc->right_fmax;
- $alignment->right_is_fmax_partial = $featureloc->right_is_fmax_partial;
- $alignment->right_phase = $featureloc->right_phase;
- $alignment->right_strand = $featureloc->right_strand;
- $alignments[] = $alignment;
- if (property_exists($rfeature, 'nid')) {
- $alignment->nid = $rfeature->nid;
- }
- }
- $feature->all_featurelocs = $alignments;
- }
- function tripal_feature_preprocess_tripal_organism_feature_counts(&$variables, $hook) {
- $organism = $variables['node']->organism;
- $organism->feature_counts = tripal_feature_load_organism_feature_counts($organism);
- }
- function tripal_feature_get_feature_relationships($feature) {
-
- $options = array(
- 'return_array' => 1,
- 'order_by' => array('rank' => 'ASC'),
-
-
-
- 'include_fk' => array(
- 'type_id' => 1,
- 'object_id' => array(
- 'type_id' => 1,
- 'organism_id' => 1
- ),
- 'subject_id' => array(
- 'type_id' => 1,
- 'organism_id' => 1
- ),
- ),
- );
- $feature = chado_expand_var($feature, 'table', 'feature_relationship', $options);
-
- $srelationships = $feature->feature_relationship->subject_id;
- $orelationships = $feature->feature_relationship->object_id;
-
-
- $options = array(
- 'include_fk' => array(
- 'srcfeature_id' => 1,
- 'feature_id' => 1,
- ),
- );
- $feature = chado_expand_var($feature, 'table', 'featureloc', $options);
- $cfeaturelocs = $feature->featureloc->feature_id;
- if (!$cfeaturelocs) {
- $cfeaturelocs = array();
- }
- elseif (!is_array($cfeaturelocs)) {
- $cfeaturelocs = array($cfeaturelocs);
- }
-
-
- $flrels_sql = "
- SELECT
- FL.featureloc_id, F.name as srcfeature_name, FL.srcfeature_id,
- FL.feature_id, FL.fmin, FL.fmax, FL.strand, FL.phase
- FROM {featureloc} FL
- INNER JOIN {feature} F ON F.feature_id = FL.srcfeature_id
- WHERE FL.feature_id = :feature_id and FL.srcfeature_id = :srcfeature_id
- ";
-
- $relationships = array();
- $relationships['object'] = array();
- $relationships['subject'] = array();
-
- if ($orelationships) {
- foreach ($orelationships as $relationship) {
- $rel = new stdClass();
-
-
- $rel->child_featurelocs = array();
- foreach ($cfeaturelocs as $featureloc) {
- $res = chado_query($flrels_sql, array(':feature_id' => $relationship->subject_id->feature_id, ':srcfeature_id' => $featureloc->srcfeature_id->feature_id));
- while ($loc = $res->fetchObject()) {
-
- if (property_exists($featureloc->srcfeature_id, 'nid')) {
- $loc->nid = $featureloc->srcfeature_id->nid;
- }
- $rel->child_featurelocs[] = $loc;
- }
- }
- $rel->record = $relationship;
-
-
- $rel_type = t(preg_replace('/_/', " ", $relationship->type_id->name));
- $child_type = $relationship->subject_id->type_id->name;
-
-
- $sql = "SELECT nid FROM {chado_feature} WHERE feature_id = :feature_id";
- $n = db_query($sql, array(':feature_id' => $relationship->subject_id->feature_id))->fetchObject();
- if ($n) {
- $rel->record->nid = $n->nid;
- }
- if (!array_key_exists($rel_type, $relationships['object'])) {
- $relationships['object'][$rel_type] = array();
- }
- if (!array_key_exists($child_type, $relationships['object'][$rel_type])) {
- $relationships['object'][$rel_type][$child_type] = array();
- }
- $relationships['object'][$rel_type][$child_type][] = $rel;
- }
- }
-
- if ($srelationships) {
- foreach ($srelationships as $relationship) {
- $rel = new stdClass();
-
- $rel->parent_featurelocs = array();
- foreach ($cfeaturelocs as $featureloc) {
- $res = chado_query($flrels_sql, array(':feature_id' => $relationship->object_id->feature_id, ':srcfeature_id' => $featureloc->srcfeature_id->feature_id));
- while ($loc = $res->fetchObject()) {
-
- if (property_exists($featureloc->srcfeature_id, 'nid')) {
- $loc->nid = $featureloc->srcfeature_id->nid;
- }
- $rel->parent_featurelocs[] = $loc;
- }
- }
- $rel->record = $relationship;
- $rel_type = t(preg_replace('/_/', " ", $relationship->type_id->name));
- $parent_type = $relationship->object_id->type_id->name;
-
-
- $sql = "SELECT nid FROM {chado_feature} WHERE feature_id = :feature_id";
- $n = db_query($sql, array(':feature_id' => $relationship->object_id->feature_id))->fetchObject();
- if ($n) {
- $rel->record->nid = $n->nid;
- }
-
- if (!array_key_exists($rel_type, $relationships['subject'])) {
- $relationships['subject'][$rel_type] = array();
- }
- if (!array_key_exists($parent_type, $relationships['subject'][$rel_type])) {
- $relationships['subject'][$rel_type][$parent_type] = array();
- }
- $relationships['subject'][$rel_type][$parent_type][] = $rel;
- }
- }
- return $relationships;
- }
|