123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918 |
- <?php
- function tripal_autocomplete_feature($string = '') {
- $items = array();
- $sql = "
- SELECT
- F.feature_id, F.uniquename, F.name,
- O.genus, O,species,
- CVT.name as type
- FROM {feature} F
- INNER JOIN {organism} O ON O.organism_id = F.organism_id
- INNER JOIN {cvterm} CVT ON CVT.cvterm_id = F.type_id
- WHERE lower(F.uniquename) like lower(:str)
- ORDER by F.uniquename
- LIMIT 25 OFFSET 0
- ";
- $features = chado_query($sql, array(':str' => $string . '%'));
- while ($feature = $features->fetchObject()) {
- $key = "$feature->uniquename [id: $feature->feature_id]";
- $items[$key] = "$feature->uniquename ($feature->name, $feature->type, $feature->genus $feature->species)";
- }
- drupal_json_output($items);
- }
- function tripal_reverse_compliment_sequence($sequence) {
- $seq = strtoupper($sequence);
- $seq = strrev($seq);
- $seq = str_replace("A", "t", $seq);
- $seq = str_replace("T", "a", $seq);
- $seq = str_replace("G", "c", $seq);
- $seq = str_replace("C", "g", $seq);
- $seq = str_replace("Y", "r", $seq);
- $seq = str_replace("R", "y", $seq);
- $seq = str_replace("W", "w", $seq);
- $seq = str_replace("S", "s", $seq);
- $seq = str_replace("K", "m", $seq);
- $seq = str_replace("M", "k", $seq);
- $seq = str_replace("D", "h", $seq);
- $seq = str_replace("V", "b", $seq);
- $seq = str_replace("H", "d", $seq);
- $seq = str_replace("B", "v", $seq);
- return strtoupper($seq);
- }
- function tripal_get_feature_sequences($feature, $options) {
-
- $feature_id = array_key_exists('feature_id', $feature) ? $feature['feature_id'] : 0;
- $parent_id = array_key_exists('parent_id', $feature) ? $feature['parent_id'] : 0;
- $featureloc_id = array_key_exists('featureloc_id', $feature) ? $feature['featureloc_id'] : 0;
- $feature_name = array_key_exists('name', $feature) ? $feature['name'] : '';
-
- $num_bases_per_line = array_key_exists('width', $options) ? $options['width'] : 50;
- $derive_from_parent = array_key_exists('derive_from_parent', $options) ? $options['derive_from_parent'] : 0;
- $aggregate = array_key_exists('aggregate', $options) ? $options['aggregate'] : 0;
- $upstream = array_key_exists('upstream', $options) ? $options['upstream'] : 0;
- $downstream = array_key_exists('downstream', $options) ? $options['downstream'] : 0;
- $sub_features = array_key_exists('sub_feature_types', $options) ? $options['sub_feature_types'] : array();
- $relationship = array_key_exists('relationship_type', $options) ? $options['relationship_type'] : '';
- $rel_part = array_key_exists('relationship_part', $options) ? $options['relationship_part'] : '';
- $is_html = array_key_exists('is_html', $options) ? $options['is_html'] : 0;
- $is_txt = array_key_exists('is_txt', $options) ? $options['is_txt'] : 0;
- $is_raw = array_key_exists('is_raw', $options) ? $options['is_raw'] : 1;
- if (!$upstream) {
- $upstream = 0;
- }
- if (!$downstream) {
- $downstream = 0;
- }
-
- if (!is_array($sub_features)) {
- tripal_report_error('tripal_feature', TRIPAL_ERROR,
- "'sub_features' option must be an array for function tripal_get_feature_sequences().",
- array()
- );
- return array();
- }
-
-
-
- if ($rel_part == "object" or $rel_part == "subject") {
- if ($rel_part == "subject") {
- $sql = '
- SELECT FO.feature_id, FO.name, FO.uniquename, CVTO.name as feature_type, O.genus, O.species
- FROM {feature} FS
- INNER JOIN {feature_relationship} FR ON FR.subject_id = FS.feature_id
- INNER JOIN {cvterm} CVTFR ON CVTFR.cvterm_id = FR.type_id
- INNER JOIN {feature} FO ON FO.feature_id = FR.object_id
- INNER JOIN {cvterm} CVTO ON CVTO.cvterm_id = FO.type_id
- INNER JOIN {organism} O ON O.organism_id = FO.organism_id
- WHERE
- FS.feature_id = :feature_id AND
- CVTFR.name = :relationship
- ';
- $features = chado_query($sql, array(':feature_id' => $feature_id, ':relationship' => $relationship));
- }
- if ($rel_part == "object") {
- $sql = '
- SELECT FS.feature_id, FS.name, FS.uniquename, CVTO.name as feature_type, O.genus, O.species
- FROM {feature} FO
- INNER JOIN {feature_relationship} FR ON FR.object_id = FO.feature_id
- INNER JOIN {cvterm} CVTFR ON CVTFR.cvterm_id = FR.type_id
- INNER JOIN {feature} FS ON FS.feature_id = FR.subject_id
- INNER JOIN {cvterm} CVTO ON CVTO.cvterm_id = FS.type_id
- INNER JOIN {organism} O ON O.organism_id = FS.organism_id
- WHERE
- FO.feature_id = :feature_id AND
- CVTFR.name = :relationship
- ';
- $features = chado_query($sql, array(':feature_id' => $feature_id, ':relationship' => $relationship));
- }
- $sequences = '';
- while ($feature = $features->fetchObject()) {
-
- if ($rel_part == "subject") {
- $defline = "$feature_name, $relationship, $feature->uniquename $feature->feature_type ($feature->genus $feature->species)";
- }
- if ($rel_part == "object") {
- $defline = "$feature->uniquename $feature->feature_type ($feature->genus $feature->species), $relationship, $feature_name";
- }
- return tripal_get_feature_sequences(
- array(
- 'feature_id' => $feature->feature_id,
- 'name' => $defline,
- 'parent_id' => $parent_id,
- ),
- array(
- 'width' => $num_bases_per_line,
- 'derive_from_parent' => $derive_from_parent,
- 'aggregate' => $aggregate,
- 'upstream' => $upstream,
- 'downstream' => $downstream,
- 'sub_features' => $sub_features,
- )
- );
- }
- }
-
-
-
-
-
- $parent_sql ='
- SELECT featureloc_id, srcname, srcfeature_id, strand, srctypename, typename,
- fmin, fmax, upstream, downstream, adjfmin, adjfmax,
- substring(residues from (cast(adjfmin as int4) + 1) for cast((upstream + (fmax - fmin) + downstream) as int4)) as residues,
- genus, species
- FROM (
- SELECT
- FL.featureloc_id, OF.name srcname, FL.srcfeature_id, FL.strand,
- OCVT.name as srctypename, SCVT.name as typename,
- FL.fmin, FL.fmax, OO.genus, OO.species,
- CASE
- WHEN FL.strand >= 0 THEN
- CASE
- WHEN FL.fmin - :upstream <= 0 THEN 0
- ELSE FL.fmin - :upstream
- END
- WHEN FL.strand < 0 THEN
- CASE
- WHEN FL.fmin - :downstream <= 0 THEN 0
- ELSE FL.fmin - :downstream
- END
- END as adjfmin,
- CASE
- WHEN FL.strand >= 0 THEN
- CASE
- WHEN FL.fmax + :downstream > OF.seqlen THEN OF.seqlen
- ELSE FL.fmax + :downstream
- END
- WHEN FL.strand < 0 THEN
- CASE
- WHEN FL.fmax + :upstream > OF.seqlen THEN OF.seqlen
- ELSE FL.fmax + :upstream
- END
- END as adjfmax,
- CASE
- WHEN FL.strand >= 0 THEN
- CASE
- WHEN FL.fmin - :upstream <= 0 THEN FL.fmin
- ELSE :upstream
- END
- ELSE
- CASE
- WHEN FL.fmax + :upstream > OF.seqlen THEN OF.seqlen - FL.fmax
- ELSE :upstream
- END
- END as upstream,
- CASE
- WHEN FL.strand >= 0 THEN
- CASE
- WHEN FL.fmax + :downstream > OF.seqlen THEN OF.seqlen - FL.fmax
- ELSE :downstream
- END
- ELSE
- CASE
- WHEN FL.fmin - :downstream <= 0 THEN FL.fmin
- ELSE :downstream
- END
- END as downstream,
- OF.residues
- FROM {featureloc} FL
- INNER JOIN {feature} SF on FL.feature_id = SF.feature_id
- INNER JOIN {cvterm} SCVT on SF.type_id = SCVT.cvterm_id
- INNER JOIN {feature} OF on FL.srcfeature_id = OF.feature_id
- INNER JOIN {cvterm} OCVT on OF.type_id = OCVT.cvterm_id
- INNER JOIN {organism} OO on OF.organism_id = OO.organism_id
- WHERE SF.feature_id = :feature_id and NOT (OF.residues = \'\' or OF.residues IS NULL)) as tbl1
- ';
-
-
-
- $sfsql = '
- SELECT SF.feature_id, CVT.name as type_name, SF.type_id
- FROM {feature_relationship} FR
- INNER JOIN {feature} SF ON SF.feature_id = FR.subject_id
- INNER JOIN {cvterm} CVT ON CVT.cvterm_id = SF.type_id
- INNER JOIN {featureloc} FL ON FL.feature_id = FR.subject_id
- INNER JOIN {feature} PF ON PF.feature_id = FL.srcfeature_id
- WHERE FR.object_id = :feature_id and PF.feature_id = :srcfeature_id
- ORDER BY FL.fmin ASC
- ';
-
- $fsql ='
- SELECT count(*) as num_children
- FROM {feature_relationship} FR
- INNER JOIN {feature} SF ON SF.feature_id = FR.subject_id
- INNER JOIN {cvterm} CVT ON CVT.cvterm_id = SF.type_id
- INNER JOIN {featureloc} FL ON FL.feature_id = FR.subject_id
- INNER JOIN {feature} PF ON PF.feature_id = FL.srcfeature_id
- WHERE FR.object_id = :feature_id and PF.feature_id = :srcfeature_id
- ';
-
- $sequences = array();
-
- if ($derive_from_parent) {
-
- $parents = chado_query($parent_sql, array(':upstream' => $upstream, ':downstream' => $downstream, ':feature_id' => $feature_id));
- while ($parent = $parents->fetchObject()) {
-
-
- if ($parent_id and $parent_id != $parent->srcfeature_id) {
- continue;
- }
-
-
- if ($featureloc_id and $featureloc_id != $parent->featureloc_id) {
- continue;
- }
-
- $seq = '';
- $notes = '';
- $types = array();
-
-
- if ($aggregate) {
-
- $children = chado_query($sfsql, array(':feature_id' => $feature_id, ':srcfeature_id' => $parent->srcfeature_id));
- $num_children = chado_query($fsql, array(':feature_id' => $feature_id, ':srcfeature_id' => $parent->srcfeature_id))->fetchField();
-
-
- $i = 0;
- while ($child = $children->fetchObject()) {
-
-
-
- if (count($sub_features) > 0 and !in_array($child->type_name, $sub_features)) {
- $i++;
- continue;
- }
-
- if (!in_array($child->type_name, $types)) {
- $types[] = $child->type_name;
- }
-
-
- if ($i == 0 and $parent->strand >= 0) {
-
-
-
- $q = chado_query($parent_sql, array(':upstream' => $upstream, ':downstream' => 0, ':feature_id' => $child->feature_id));
- }
- elseif ($i == 0 and $parent->strand < 0) {
-
-
-
- $q = chado_query($parent_sql, array(':upstream' => 0, ':downstream' => $downstream, ':feature_id' => $child->feature_id));
- }
-
-
- elseif ($i == $num_children - 1 and $parent->strand >= 0) {
-
-
-
- $q = chado_query($parent_sql, array(':upstream' => 0, ':downstream' => $downstream, ':feature_id' => $child->feature_id));
- }
- elseif ($i == $num_children - 1 and $parent->strand < 0) {
-
-
-
- $q = chado_query($parent_sql, array(':upstream' => $upstream, ':downstream' => 0, ':feature_id' => $child->feature_id));
- }
-
- else {
- $q = chado_query($parent_sql, array(':upstream' => 0, ':downstream' => 0, ':feature_id' => $child->feature_id));
- }
- while ($subseq = $q->fetchObject()) {
-
- if ($subseq->srcfeature_id == $parent->srcfeature_id) {
- $seq .= $subseq->residues;
- }
- if ($subseq->upstream > 0 ) {
- $notes .= "Includes " . $subseq->upstream . " bases upstream. ";
- }
- if ($subseq->downstream > 0) {
- $notes .= "Includes " . $subseq->downstream . " bases downstream. ";
- }
- }
- $i++;
- }
- }
-
- else {
- $seq = $parent->residues;
- if ($parent->upstream > 0) {
- $notes .= "Includes " . $parent->upstream . " bases upstream. ";
- }
- if ($parent->downstream > 0) {
- $notes .= "Includes " . $parent->downstream . " bases downstream. ";
- }
- }
-
- $dir = 'forward';
- $length = strlen($seq);
- if ($parent->strand < 0) {
- $seq = tripal_reverse_compliment_sequence($seq);
- $dir = 'reverse';
- }
-
- if ($is_html) {
- $seq = wordwrap($seq, $num_bases_per_line, "<br>", TRUE);
- }
- if ($is_txt) {
- $seq = wordwrap($seq, $num_bases_per_line, "\r\n", TRUE);
- }
- if (!$seq) {
- $notes .= "No sequence available.";
- }
- if (count($types) > 0) {
- $notes .= "Excludes all bases but those of type(s): " . implode(', ', $types) . ". " ;
- }
-
-
-
- $featureloc = new stdClass;
- $featureloc->feature_id = $feature;
- $featureloc->fmin = $parent->adjfmin;
- $featureloc->fmax = $parent->adjfmax;
- $featureloc->strand = $parent->strand;
- $featureloc->srcfeature_id = new stdClass;
- $featureloc->srcfeature_id->name = $parent->srcname;
- $featureloc->srcfeature_id->type_id = $parent->srctypename;
- $featureloc->srcfeature_id->organism_id = new stdClass;
- $featureloc->srcfeature_id->organism_id->genus = $parent->genus;
- $featureloc->srcfeature_id->organism_id->species = $parent->species;
-
- $f = chado_generate_var('feature', array('feature_id' => $feature_id));
- $defline = tripal_get_fasta_defline($f, $notes, $featureloc, '', $length);
- $sequences[] = array(
- 'types' => $types,
- 'upstream' => $parent->upstream,
- 'downstream' => $parent->downstream,
- 'defline' => $defline,
- 'residues' => $seq,
- 'featureloc_id' => $parent->featureloc_id,
- 'length' => $length,
- );
- }
- }
-
-
- else {
- $f = chado_generate_var('feature', array('feature_id' => $feature_id));
- $f = chado_expand_var($f, 'field', 'feature.residues');
- $residues = $f->residues;
- $length = strlen($residues);
- if ($is_html) {
- $residues = wordwrap($residues, $num_bases_per_line, "<br>", TRUE);
- }
- else {
- $residues = wordwrap($residues, $num_bases_per_line, "\r\n", TRUE);
- }
-
- $defline = tripal_get_fasta_defline($f, '', NULL, '', $length);
-
- $sequences[] = array(
- 'types' => $f->type_id->name,
- 'upstream' => 0,
- 'downstream' => 0,
- 'defline' => $defline,
- 'residues' => $residues,
- 'length' => $length,
- );
- }
- return $sequences;
- }
- function tripal_get_bulk_feature_sequences($options) {
-
- $org_commonname = array_key_exists('org_commonname', $options) ? $options['org_commonname'] : '';
- $genus = array_key_exists('genus', $options) ? $options['genus'] : '';
- $species = array_key_exists('species', $options) ? $options['species'] : '';
- $analysis_name = array_key_exists('analysis_name', $options) ? $options['analysis_name'] : '';
- $type = array_key_exists('type', $options) ? $options['type'] : '';
- $feature_name = array_key_exists('feature_name', $options) ? $options['feature_name'] : '';
- $feature_uname = array_key_exists('feature_uname', $options) ? $options['feature_uname'] : '';
- $derive_from_parent = array_key_exists('derive_from_parent', $options) ? $options['derive_from_parent'] : 0;
- $aggregate = array_key_exists('aggregate', $options) ? $options['aggregate'] : 0;
- $sub_features = array_key_exists('sub_feature_types', $options) ? $options['sub_feature_types'] : array();
- $relationship = array_key_exists('relationship_type', $options) ? $options['relationship_type'] : '';
- $rel_part = array_key_exists('relationship_part', $options) ? $options['relationship_part'] : '';
- $num_bases_per_line = array_key_exists('width', $options) ? $options['width'] : 50;
- $upstream = array_key_exists('upstream', $options) ? $options['upstream'] : 0;
- $downstream = array_key_exists('downstream', $options) ? $options['downstream'] : 0;
- if (!$type and !$feature_name and !$genus) {
- print "Please provide a type, feature name or genus\n";
- return;
- }
-
- $vars = array();
- $sql = "
- SELECT DISTINCT F.feature_id, F.name, F.uniquename,
- O.genus, O.species, CVT.name as feature_type
- FROM {feature} F
- INNER JOIN {organism} O on O.organism_id = F.organism_id
- INNER JOIN {cvterm} CVT on CVT.cvterm_id = F.type_id
- ";
- if ($analysis_name) {
- $sql .= "
- INNER JOIN {analysisfeature} AF on AF.feature_id = F.feature_id
- INNER JOIN {analysis} A on AF.analysis_id = A.analysis_id
- ";
- }
- $sql .= "WHERE (1=1) ";
- if ($org_commonname) {
- $sql .= "AND O.common_name = :common_name ";
- $vars[':common_name'] = $org_commonname;
- }
- if ($genus) {
- $sql .= "AND O.genus = :genus ";
- $vars[':genus'] = $genus;
- }
- if ($species) {
- $sql .= "AND O.species = :species ";
- $vars[':species'] = $species;
- }
- if ($type) {
- $sql .= "AND CVT.name = :cvtname ";
- $vars[':cvtname'] = $type;
- }
- if ($feature_name) {
- if (is_array($feature_name)) {
- $sql .= "AND F.name IN (";
- foreach ($feature_name as $i => $fname) {
- $sql .= ":fname$i, ";
- $vars[":fname$i"] = $fname;
- }
-
- $sql = substr($sql, 0, -2) . ")";
- }
- else {
- $sql .= "AND F.name = :fname";
- $vars[':fname'] = $feature_name;
- }
- }
- if ($feature_uname) {
- if (is_array($feature_uname)) {
- $sql .= "AND F.uniquename IN (";
- foreach ($feature_uname as $i => $funame) {
- $sql .= ":funame$i, ";
- $vars[":funame$i"] = $funame;
- }
-
- $sql = substr($sql, 0, -2) . ")";
- }
- else {
- $sql .= "AND F.uniquename = :funame";
- $vars[':funame'] = $feature_uname;
- }
- }
- if ($analysis_name) {
- $sql .= "AND A.name = :aname";
- $vars[':aname'] = $analysis_name;
- }
- $num_bases_per_line = 50;
- $num_seqs = 0;
- $q = chado_query($sql, $vars);
- $sequences = array();
- while ($feature = $q->fetchObject()) {
-
- $seqs = tripal_get_feature_sequences(array('feature_id' => $feature->feature_id), $options);
- $sequences = array_merge($sequences, $seqs);
- $num_seqs++;
- }
- return $sequences;
- }
- function tripal_get_fasta_defline($feature, $notes = '', $featureloc = NULL, $type = '', $length = 0) {
-
- if ($featureloc) {
- if (!is_object($featureloc->srcfeature_id)) {
- $featureloc->srcfeature_id = chado_generate_var('feature', array('feature_id' => $featureloc->srcfeature_id));
- }
- if (!is_object($featureloc->srcfeature_id->organism_id)) {
- $featureloc->srcfeature_id->organism_id = chado_generate_var('organism', array('organism_id' => $featureloc->srcfeature_id->organism_id));
- }
- }
-
- if (!is_object($feature->organism_id)) {
- $feature->organism_id = chado_generate_var('organism', array('organism_id' => $feature->organism_id));
- }
-
- if (!$type) {
- $type = $feature->type_id->name;
- }
-
- $defline = $feature->uniquename . " " .
- 'ID=' . $feature->uniquename . "|" .
- 'Name=' . $feature->name . "|" .
- 'organism=' . $feature->organism_id->genus . " " . $feature->organism_id->species . "|" .
- 'type=' . $type . '|';
- if ($length > 0) {
- $defline .= "length=" . $length . "bp|";
- }
- if ($featureloc) {
- $defline .= "location=Sequence derived from alignment at " . tripal_get_location_string($featureloc);
- $defline .= " (" . $featureloc->srcfeature_id->organism_id->genus . " " . $featureloc->srcfeature_id->organism_id->species . ")|";
- }
- if ($notes) {
- $defline .= "Notes=$notes|";
- }
- $defline = substr($defline, 0, -1);
- return $defline;
- }
- function tripal_get_location_string($featureloc) {
- $feature = $featureloc->feature_id;
- $strand = '';
- if ($featureloc->strand == 1) {
- $strand = '+';
- }
- elseif ($featureloc->strand == -1) {
- $strand = '-';
- }
- return $featureloc->srcfeature_id->name . ":" . ($featureloc->fmin + 1) . ".." . $featureloc->fmax . $strand;
- }
- function tripal_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(
- 'return_array' => 1,
- '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;
-
- 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;
- 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;
- }
|