1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129 |
- <?php
- function tripal_feature_analysis_get_property($analysis_id = NULL, $feature_id = NUll,
- $analysisfeature_id = NULL, $property, $cv_name = 'tripal') {
-
- if (($analysis_id and !$feature_id) or
- (!$analysis_id and $feature_id)) {
- watchdog('tripal_feature',
- 'tripal_feature_analysis_get_property: Both an analysis ID and feature ID should be specified',
- array(), WATCHDOG_WARNING);
- }
-
- if (!$analysisfeature_id) {
- $columns = array('analysisfeature_id');
- $values = array('analysis_id' => $analysis_id, 'feature_id' => $feature_id);
- $result = tripal_core_chado_select('analysisfeature', $columns, $values);
- $analysisfeature_id = $result[0]->analysisfeature_id;
- }
-
- return tripal_core_get_property('analysisfeature', $analysisfeature_id, $property, $cv_name);
- }
- function tripal_feature_analysis_insert_property($analysis_id = NULL, $feature_id = NUll,
- $analysisfeature_id = NULL, $property, $value, $update_if_present = 0, $cv_name = 'tripal') {
-
- if (($analysis_id and !$feature_id) or
- (!$analysis_id and $feature_id)) {
- watchdog('tripal_feature',
- 'tripal_feature_analysis_insert_property: Both an analysis ID and feature ID should be specified',
- array(), WATCHDOG_WARNING);
- }
-
- if (!$analysisfeature_id) {
- $columns = array('analysisfeature_id');
- $values = array('analysis_id' => $analysis_id, 'feature_id' => $feature_id);
- $result = tripal_core_chado_select('analysisfeature', $columns, $values);
- $analysisfeature_id = $result[0]->analysisfeature_id;
- }
-
- $success = tripal_core_insert_property('analysisfeature', $analysisfeature_id,
- $property, $cv_name, $value, $update_if_present);
- if (!$success) {
- watchdog('tripal_feature',
- 'tripal_feature_analysis_insert_property: Failed to insert analysis feature property',
- array(), WATCHDOG_WARNING);
- return FALSE;
- }
- return $success;
- }
- function tripal_feature_analysis_update_property($analysis_id = NULL, $feature_id = NUll,
- $analysisfeature_id = NULL, $property, $value, $insert_if_missing = 0,
- $cv_name = 'tripal') {
-
- if (($analysis_id and !$feature_id) or
- (!$analysis_id and $feature_id)) {
- watchdog('tripal_feature',
- 'tripal_feature_analysis_update_property: Both an analysis ID and feature ID should be specified',
- array(), WATCHDOG_WARNING);
- }
-
- if (!$analysisfeature_id) {
- $columns = array('analysisfeature_id');
- $values = array('analysis_id' => $analysis_id, 'feature_id' => $feature_id);
- $result = tripal_core_chado_select('analysisfeature', $columns, $values);
- $analysisfeature_id = $result[0]->analysisfeature_id;
- }
-
- return tripal_core_update_property('analysisfeature', $analysisfeature_id, $property, $cv_name, $value, $insert_if_missing);
- }
- function tripal_feature_analysis_update_property_by_id($analysisfeatureprop_id,
- $property, $value, $cv_name = 'tripal') {
-
- return tripal_core_update_property_by_id('analysisfeature',
- $analysisfeatureprop_id, $property, $cv_name, $value);
- }
- function tripal_feature_analysis_delete_property($analysis_id = NULL, $feature_id = NUll,
- $analysisfeature_id = NULL, $property, $cv_name = 'tripal') {
-
- if (($analysis_id and !$feature_id) or
- (!$analysis_id and $feature_id)) {
- watchdog('tripal_feature',
- 'tripal_feature_analysis_delete_property: Both an analysis ID and feature ID should be specified',
- array(), WATCHDOG_WARNING);
- }
-
- if (!$analysisfeature_id) {
- $columns = array('analysisfeature_id');
- $values = array('analysis_id' => $analysis_id, 'feature_id' => $feature_id);
- $result = tripal_core_chado_select('analysisfeature', $columns, $values);
- $analysisfeature_id = $result[0]->analysisfeature_id;
- }
-
- return tripal_core_delete_property('analysisfeature', $analysisfeature_id, $property, $cv_name);
- }
- function tripal_feature_analysis_delete_property_by_id($analysisfeatureprop_id) {
-
- return tripal_core_delete_property_by_id('analysisfeature', $analysisfeatureprop_id);
- }
- function tripal_feature_get_property($feature_id, $property, $cv_name='tripal') {
- return tripal_core_get_property('feature', $feature_id, $property, $cv_name);
- }
- function tripal_feature_insert_property($feature_id, $property, $value,
- $update_if_present = 0, $cv_name = 'tripal') {
- return tripal_core_insert_property('feature', $feature_id, $property,
- $cv_name, $value, $update_if_present);
- }
- function tripal_feature_update_property($feature_id, $property,
- $value, $insert_if_missing = 0, $cv_name = 'tripal') {
- return tripal_core_update_property('feature', $feature_id, $property, $cv_name, $value, $insert_if_missing);
- }
- function tripal_feature_update_property_by_id($featureprop_id, $property,
- $value, $cv_name = 'tripal') {
- return tripal_core_update_property_by_id('feature', $featureprop_id, $property, $cv_name, $value);
- }
- function tripal_feature_delete_property($feature_id, $property, $cv_name='tripal') {
- return tripal_core_delete_property('feature', $feature_id, $property, $cv_name);
- }
- function tripal_feature_delete_property_by_id($featureprop_id) {
- return tripal_core_delete_property_by_id('feature', $featureprop_id);
- }
- function tripal_feature_reverse_complement($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_feature_get_formatted_sequence($feature_id, $feature_name,
- $num_bases_per_line, $derive_from_parent, $aggregate, $output_format,
- $upstream, $downstream, $sub_features = array(), $relationship = '', $rel_part = '') {
-
-
- $connection = tripal_db_persistent_chado();
-
- if (!$upstream) {
- $upstream = 0;
- }
- if (!$downstream) {
- $downstream = 0;
- }
-
- if ($rel_part == "object" or $rel_part == "subject") {
- if ($rel_part == "subject") {
- $psql = '
- PREPARE feature_rel_get_object (int, text) AS
- 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 = $1 AND
- CVTFR.name = $2
- ';
- $status = tripal_core_chado_prepare('feature_rel_get_object', $psql, array('int', 'text'));
- if (!$status) {
- watchdog('tripal_feature', "init: not able to prepare SQL statement '%name'",
- array('%name' => 'feature_by_subject'), 'WATCHDOG ERROR');
- }
- $sql = "EXECUTE feature_rel_get_object(:feature_id, :relationship)";
- $features = chado_query($sql, array(':feature_id' => $feature_id, ':relationship' => $relationship));
- }
- if ($rel_part == "object") {
- $psql = '
- PREPARE feature_rel_get_subject (int, text) AS
- 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 = $1 AND
- CVTFR.name = $2
- ';
- $status = tripal_core_chado_prepare('feature_rel_get_subject', $psql, array('int', 'text'));
- if (!$status) {
- watchdog('tripal_feature', "init: not able to prepare SQL statement '%name'",
- array('%name' => 'feature_by_object'), 'WATCHDOG ERROR');
- }
- $sql = "EXECUTE feature_rel_get_subject(:feature_id, :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";
- }
- $sequences .= tripal_feature_get_formatted_sequence($feature->feature_id, $defline,
- $num_bases_per_line, $derive_from_parent, $aggregate, $output_format,
- $upstream, $downstream, $sub_features, '', '');
- }
- return $sequences;
- }
-
-
- if (!tripal_core_is_sql_prepared('sequence_by_parent')) {
-
-
-
-
-
- $psql ='
- PREPARE sequence_by_parent (int, int, int) AS
- SELECT srcname, srcfeature_id, strand, srctypename, typename,
- fmin, fmax, upstream, downstream, adjfmin, adjfmax,
- substring(residues from (adjfmin + 1) for (upstream + (fmax - fmin) + downstream)) as residues,
- genus, species
- FROM (
- SELECT
- 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 - $1 <= 0 THEN 0
- ELSE FL.fmin - $1
- END
- WHEN FL.strand < 0 THEN
- CASE
- WHEN FL.fmin - $2 <= 0 THEN 0
- ELSE FL.fmin - $2
- END
- END as adjfmin,
- CASE
- WHEN FL.strand >= 0 THEN
- CASE
- WHEN FL.fmax + $2 > OF.seqlen THEN OF.seqlen
- ELSE FL.fmax + $2
- END
- WHEN FL.strand < 0 THEN
- CASE
- WHEN FL.fmax + $1 > OF.seqlen THEN OF.seqlen
- ELSE FL.fmax + $1
- END
- END as adjfmax,
- CASE
- WHEN FL.strand >= 0 THEN
- CASE
- WHEN FL.fmin - $1 <= 0 THEN FL.fmin
- ELSE $1
- END
- ELSE
- CASE
- WHEN FL.fmax + $1 > OF.seqlen THEN OF.seqlen - FL.fmax
- ELSE $1
- END
- END as upstream,
- CASE
- WHEN FL.strand >= 0 THEN
- CASE
- WHEN FL.fmax + $2 > OF.seqlen THEN OF.seqlen - FL.fmax
- ELSE $2
- END
- ELSE
- CASE
- WHEN FL.fmin - $2 <= 0 THEN FL.fmin
- ELSE $2
- 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 = $3 and NOT (OF.residues = \'\' or OF.residues IS NULL)) as tbl1
- ';
- $status = tripal_core_chado_prepare('sequence_by_parent', $psql, array('int', 'int', 'int'));
- if (!$status) {
- watchdog('tripal_feature',
- "init: not able to prepare SQL statement '%name'",
- array('%name' => 'sequence_by_parent'), 'WATCHDOG ERROR');
- }
-
-
-
-
- $psql ='PREPARE sub_features (int, int) AS
- 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 = $1 and PF.feature_id = $2
- ORDER BY FL.fmin ASC';
- $status = tripal_core_chado_prepare('sub_features', $psql, array('int', 'int'));
- if (!$status) {
- watchdog('tripal_views_handler_field_sequence',
- "init: not able to prepare SQL statement '%name'",
- array('%name' => 'ssub_features'), 'WATCHDOG ERROR');
- }
- $psql ='PREPARE count_sub_features (int, int) AS
- 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 = $1 and PF.feature_id = $2';
- $status = tripal_core_chado_prepare('count_sub_features', $psql, array('int', 'int'));
- if (!$status) {
- watchdog('tripal_views_handler_field_sequence',
- "init: not able to prepare SQL statement '%name'",
- array('%name' => 'count_sub_features'), 'WATCHDOG ERROR');
- }
- }
-
-
- if ($derive_from_parent) {
-
-
- $sql = "EXECUTE sequence_by_parent (:upstream, :downstream, :feature_id)";
- $parents = chado_query($sql, array(':uptream' => $upstream, ':downstream' => $downstream, ':feature_id' => $feature_id));
- while ($parent = $parents->fetchObject()) {
- $seq = '';
-
-
- if ($aggregate) {
-
-
- $sql = "EXECUTE sub_features (:feature_id, :srcfeature_id)";
- $children = chado_query($sql, array(':feature_id' => $feature_id, ':srcfeature_id' => $parent->srcfeature_id));
- $sql = "EXECUTE count_sub_features (:feature_id, :srcfeature_id)";
- $sub_features = chado_query($sql, array(':feature_id' => $feature_id, ':srcfeature_id' => $parent->srcfeature_id));
- $num_children = $sub_features->fetchObject();
-
-
-
- $types = array();
- $i = 0;
- while ($child = $children->fetchObject()) {
-
-
-
- if (count($sub_features) > 0 and !in_array($child->type_name, $sub_features)) {
- continue;
- }
-
-
- if (!in_array($child->type_name, $types)) {
- $types[] = $child->type_name;
- }
-
- $sql = "EXECUTE sequence_by_parent (:upstream, %d, :feature_id)";
-
-
- if ($i == 0 and $parent->strand >= 0) {
-
-
-
- $q = chado_query($sql, array(':upstream' => $upstream, ':downstream' => 0, ':feature_id' => $child->feature_id));
- }
- elseif ($i == 0 and $parent->strand < 0) {
-
-
-
- $q = chado_query($sql, array(':upstream' => 0, ':downstream' => $downstream, ':feature_id' => $child->feature_id));
- }
-
-
-
- if ($i == $num_children->num_children - 1 and $parent->strand >= 0) {
-
-
-
- $q = chado_query($sql, array(':upstream' => 0, ':downstream' => $downstream, ':feature_id' => $child->feature_id));
- }
- elseif ($i == $num_children->num_children - 1 and $parent->strand < 0) {
-
-
-
- $q = chado_query($sql, array(':upstream' => $upstream, ':downstream' => 0, ':feature_id' => $child->feature_id));
- }
-
-
- else {
- $sql = "EXECUTE sequence_by_parent (%d, %d, %d)";
- $q = chado_query($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;
- }
- }
- $i++;
- }
- }
-
- else {
- $seq = $parent->residues;
- }
-
-
- $dir = 'forward';
- if ($parent->strand < 0) {
- $seq = tripal_feature_reverse_complement($seq);
- $dir = 'reverse';
- }
-
-
- if ($output_format == 'fasta_html') {
- $seq = wordwrap($seq, $num_bases_per_line, "<br>", TRUE);
- }
- elseif ($output_format == 'fasta_txt') {
- $seq = wordwrap($seq, $num_bases_per_line, "\r\n", TRUE);
- }
- $residues .= ">$feature_name. Sequence derived from feature of type, '$parent->srctypename', of $parent->genus $parent->species: $parent->srcname:" . ($parent->adjfmin + 1) . ".." . $parent->adjfmax . " ($dir). ";
- if (count($types) > 0) {
- $residues .= "Excludes all bases but those of type(s): " . implode(', ', $types) . ". " ;
- }
- if ($parent->upstream > 0) {
- $residues .= "Includes " . $parent->upstream . " bases upstream. ";
- }
- if ($parent->downstream > 0) {
- $residues .= "Includes " . $parent->downstream . " bases downstream. ";
- }
- if (!$seq) {
-
- if ($output_format == 'fasta_html') {
- $residues .= "No sequence available.</br>";
- }
- else {
- $residues .= "No sequence available.\r\n";
- }
- }
- else {
- if ($output_format == 'fasta_html') {
- $residues .= "<br>";
- }
- $residues .= "\r\n" . $seq . "\r\n";
- if ($output_format == 'fasta_html') {
- $residues .= "<br>";
- }
- }
- }
- }
-
-
- else {
- $sql = "SELECT * FROM {feature} F WHERE feature_id = :feature_id";
- $values = chado_query($sql, array(':feature_id' => $feature_id))->fetchObject();
- $residues = $values->residues;
- if ($output_format == 'fasta_html') {
- $residues = wordwrap($residues, $num_bases_per_line, "<br>", TRUE);
- }
- elseif ($output_format == 'fasta_txt') {
- $residues = wordwrap($residues, $num_bases_per_line, "\r\n", TRUE);
- }
- $residues = ">$feature_name\r\n$residues\r\n";
- }
-
-
- if ($residues and $num_bases_per_line) {
- if ($output_format == 'fasta_html') {
- $residues = '<span style="font-family: monospace;">' . $residues . '</span>';
- }
- }
- return $residues;
- }
- function tripal_feature_get_custom_tables($table = NULL) {
- if (!$table or strcmp($table, 'tripal_gff_temp')==0) {
- $schema['tripal_gff_temp'] = array(
- 'table' => 'tripal_gff_temp',
- 'fields' => array(
- 'feature_id' => array(
- 'type' => 'int',
- 'not null' => TRUE,
- ),
- 'organism_id' => array(
- 'type' => 'int',
- 'not null' => TRUE,
- ),
- 'uniquename' => array(
- 'type' => 'text',
- 'not null' => TRUE,
- ),
- 'type_name' => array(
- 'type' => 'varchar',
- 'length' => '1024',
- 'not null' => TRUE,
- ),
- ),
- 'indexes' => array(
- 'tripal_gff_temp_idx0' => array('feature_id'),
- 'tripal_gff_temp_idx0' => array('organism_id'),
- 'tripal_gff_temp_idx1' => array('uniquename'),
- ),
- 'unique keys' => array(
- 'tripal_gff_temp_uq0' => array('feature_id'),
- 'tripal_gff_temp_uq1' => array('uniquename', 'organism_id', 'type_name'),
- ),
- );
- }
- return $schema;
- }
- function tripal_feature_get_feature_relationships($feature) {
-
- $options = array(
- 'return_array' => 1,
- 'order_by' => array('rank' => 'ASC'),
- );
- $feature = tripal_core_expand_chado_vars($feature, 'table',
- 'feature_relationship', $options);
-
- $srelationships = $feature->feature_relationship->subject_id;
- $orelationships = $feature->feature_relationship->object_id;
-
-
-
- $feature = tripal_core_expand_chado_vars($feature, 'table', 'featureloc');
- $cfeaturelocs = $feature->featureloc->feature_id;
- if (!$cfeaturelocs) {
- $cfeaturelocs = array();
- }
- elseif (!is_array($cfeaturelocs)) {
- $cfeaturelocs = array($cfeaturelocs);
- }
-
-
-
- $connection = tripal_db_persistent_chado();
- $psql = "
- PREPARE sel_featureloc_preprocess_relationships (int, int) AS
- 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 = $1 and FL.srcfeature_id = $2
- ";
- tripal_core_chado_prepare('sel_featureloc_preprocess_relationships', $psql, array('int', 'int'));
-
-
- $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("EXECUTE sel_featureloc_preprocess_relationships (:relationship, :featureloc)",
- array(':relationship' => $relationship->subject_id->feature_id, ':featureloc' => $featureloc->srcfeature_id->feature_id));
- while ($loc = $res->fetchObject()) {
-
- $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("EXECUTE sel_featureloc_preprocess_relationships (:feature_id, :srcfeature_id)",
- array('feature_id' => $relationship->object_id->feature_id, ':srcfeature_id' => $featureloc->srcfeature_id->feature_id));
- while ($loc = $res->fetchObject()) {
-
- $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($child_type, $relationships['subject'][$rel_type])) {
- $relationships['subject'][$rel_type][$parent_type] = array();
- }
- $relationships['subject'][$rel_type][$parent_type][] = $rel;
- }
- }
- return $relationships;
- }
- function tripal_feature_add_dbxref($feature_id, $dbname, $accession) {
-
-
- $values = array('name' => $dbname);
- $options = array('statement_name' => 'sel_db_na');
- $db = tripal_core_chado_select('db', array('db_id'), $values, $options);
- if (!$db or count($db) == 0) {
- $options = array('statement_name' => 'ins_db_na');
- $success = tripal_core_chado_insert('db', $values, $options);
- if (!$success) {
- watchdog('tripal_feature', 'tripal_feature_add_dbxref: The feature dbxref entry for feature, %feature_id, " .
- "could not be added because the database, %dbname, does not exist and cannot be added.',
- array('%feature_id' => $feature_id, '%dbname' => $dbname), WATCHDOG_WARNING);
- return FALSE;
- }
- }
-
-
- $values = array(
- 'dbxref_id' => array(
- 'accession' => $accession,
- 'db_id' => array(
- 'name' => $dbname
- ),
- ),
- 'feature_id' => $feature_id,
- );
- $options = array('statement_name' => 'sel_featuredbxref_dbfe');
- $xref = tripal_core_chado_select('feature_dbxref', array('feature_dbxref_id'), $values, $options);
- if (count($xref) == 0) {
-
- $options = array('statement_name' => 'ins_featuredbxref_dbfe');
- $success = tripal_core_chado_insert('feature_dbxref', $values, $options);
- if (!$success) {
- watchdog('tripal_feature', 'tripal_feature_add_dbxref: The feature dbxref entry for feature, %feature_id, ' .
- 'could not be added: %db:%accession.', array('%feature_id' => $feature_id, '%db' => $dbname,
- '%accession' => $accession), WATCHDOG_WARNING);
- return FALSE;
- }
- }
- return TRUE;
- }
- function tripal_feature_add_cvterm($feature_id, $cvname, $cvterm) {
-
-
- $values = array('name' => $cvname);
- $options = array('statement_name' => 'sel_cv_na');
- $cv = tripal_core_chado_select('cv', array('cv_id'), $values, $options);
- if (!$cv or count($cv) == 0) {
- $options = array('statement_name' => 'ins_cv_na');
- $success = tripal_core_chado_insert('cv', $values, $options);
- if (!$success) {
- watchdog('tripal_feature', 'tripal_feature_add_cvterm: The feature cvterm entry for feature, %feature_id, " .
- "could not be added because the CV, %cvname, does not exist and cannot be added.',
- array('%feature_id' => $feature_id, '%cvname' => $cvname), WATCHDOG_WARNING);
- return FALSE;
- }
- }
-
-
- $values = array(
- 'cvterm_id' => array(
- 'name' => $cvterm,
- 'cv_id' => array(
- 'name' => $cvname
- ),
- ),
- 'feature_id' => $feature_id,
- 'pub_id' => 1,
- );
- $options = array('statement_name' => 'sel_featuredcvterm_cvfepu');
- $xref = tripal_core_chado_select('feature_cvterm', array('feature_cvterm_id'), $values, $options);
- if (count($xref) == 0) {
-
- $options = array('statement_name' => 'ins_featurecvterm_cvfepu');
- $success = tripal_core_chado_insert('feature_cvterm', $values, $options);
- if (!$success) {
- watchdog('tripal_feature', 'tripal_feature_add_cvterm: The feature cvterm entry for feature, %feature_id, ' .
- 'could not be added: %cvterm.', array('%feature_id' => $feature_id, '%cvterm' => $cvterm), WATCHDOG_WARNING);
- return FALSE;
- }
- }
- return TRUE;
- }
|