1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242 |
- <?php
- require_once "api/tripal_feature.api.inc";
- require_once "includes/tripal_feature.admin.inc";
- require_once "includes/tripal_feature.sync_features.inc";
- require_once "includes/fasta_loader.inc";
- require_once "includes/gff_loader.inc";
- require_once "includes/seq_extract.inc";
- require_once "includes/tripal_feature-delete.inc";
- require_once "includes/tripal_feature.form.inc";
- function tripal_feature_init() {
- drupal_add_css(drupal_get_path('module', 'tripal_feature') . '/theme/css/tripal_feature.css');
- drupal_add_js(drupal_get_path('module', 'tripal_feature') . '/theme/js/tripal_feature.js');
- }
- function tripal_feature_views_api() {
- return array(
- 'api' => 2.0,
- );
- }
- function tripal_feature_help($path, $arg) {
- $output = '';
- switch ($path) {
- case "admin/help#tripal_feature":
- $output='<p>' . t("Displays links to nodes created on this date") . '</p>';
- break;
- }
- return $output;
- }
- function tripal_feature_node_info() {
- $nodes = array();
- $nodes['chado_feature'] = array(
- 'name' => t('Feature'),
- 'base' => 'chado_feature',
- 'description' => t('A feature from the chado database'),
- 'has_title' => FALSE,
- 'title_label' => t('Feature'),
- 'has_body' => FALSE,
- 'body_label' => t('Feature Description'),
- 'locked' => TRUE
- );
- return $nodes;
- }
- function tripal_feature_permissions() {
- return array(
- 'access chado_feature content' => array(
- 'title' => t('View Features'),
- 'description' => t('Allow users to view feature pages.'),
- ),
- 'create chado_feature content' => array(
- 'title' => t('Create Features'),
- 'description' => t('Allow users to create new feature pages.'),
- ),
- 'delete chado_feature content' => array(
- 'title' => t('Delete Features'),
- 'description' => t('Allow users to delete feature pages.'),
- ),
- 'edit chado_feature content' => array(
- 'title' => t('Edit Features'),
- 'description' => t('Allow users to edit feature pages.'),
- ),
- 'adminster tripal feature' => array(
- 'title' => t('Administer Features'),
- 'description' => t('Allow users to administer all features.'),
- ),
- );
- }
- function chado_feature_node_access($node, $op, $account) {
- if ($op == 'create') {
- if (!user_access('create chado_feature content', $account)) {
- return FALSE;
- }
- return TRUE;
- }
- if ($op == 'update') {
- if (!user_access('edit chado_feature content', $account)) {
- return FALSE;
- }
- }
- if ($op == 'delete') {
- if (!user_access('delete chado_feature content', $account)) {
- return FALSE;
- }
- }
- if ($op == 'view') {
- if (!user_access('access chado_feature content', $account)) {
- return FALSE;
- }
- }
- return NULL;
- }
- function tripal_feature_menu() {
- $items = array();
-
- $items['find/sequences'] = array(
- 'title' => 'Sequence Retrieval',
- 'description' => 'Download a file of sequences',
- 'page callback' => 'tripal_feature_seq_extract_page',
- 'access arguments' => array('access chado_feature content'),
- 'type' => MENU_CALLBACK,
- );
- $items['find/sequences/ajax'] = array(
- 'title' => 'Sequence Retrieval',
- 'page callback' => 'tripal_feature_seq_extract_form_ahah_update',
- 'access arguments' => array('access chado_feature content'),
- 'type' => MENU_CALLBACK,
- );
-
- $items['admin/tripal/chado/tripal_feature'] = array(
- 'title' => 'Features',
- 'description' => 'A biological sequence or a section of a biological sequence, or a collection of such sections.',
- 'page callback' => 'tripal_feature_admin_feature_view',
- 'access arguments' => array('administer tripal features'),
- 'type' => MENU_NORMAL_ITEM,
- );
- $items['admin/tripal/chado/tripal_feature/sync'] = array(
- 'title' => ' Sync',
- 'description' => 'Sync features from Chado with Drupal',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_feature_sync_form'),
- 'access arguments' => array('administer tripal features'),
- 'type' => MENU_LOCAL_TASK,
- 'weight' => 0
- );
- $items['admin/tripal/chado/tripal_feature/delete'] = array(
- 'title' => ' Delete',
- 'description' => 'Delete multiple features from Chado',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_feature_delete_form'),
- 'access arguments' => array('administer tripal features'),
- 'type' => MENU_LOCAL_TASK,
- 'weight' => 2
- );
- $items['admin/tripal/chado/tripal_feature/configuration'] = array(
- 'title' => 'Settings',
- 'description' => 'Configure the Tripal Feature module.',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_feature_admin'),
- 'access arguments' => array('administer tripal features'),
- 'type' => MENU_LOCAL_TASK,
- 'weight' => 5
- );
- $items['admin/tripal/chado/tripal_feature/help'] = array(
- 'title' => 'Help',
- 'description' => 'Help with the Tripal Feature module.',
- 'page callback' => 'theme',
- 'page arguments' => array('tripal_feature_help'),
- 'access arguments' => array('administer tripal features'),
- 'type' => MENU_LOCAL_TASK,
- 'weight' => 10
- );
-
- $items['admin/tripal/loaders/fasta_loader'] = array(
- 'title' => 'Multi-FASTA file Loader',
- 'description' => 'Load sequences from a multi-FASTA file into Chado',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_feature_fasta_load_form'),
- 'access arguments' => array('administer tripal features'),
- 'type' => MENU_NORMAL_ITEM,
- );
- $items['admin/tripal/loaders/gff3_load'] = array(
- 'title' => 'GFF3 file Loader',
- 'description' => 'Import a GFF3 file into Chado',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_feature_gff3_load_form'),
- 'access arguments' => array('administer tripal features'),
- 'type' => MENU_NORMAL_ITEM,
- );
-
- $items['feature/%'] = array(
- 'page callback' => 'tripal_feature_match_features_page',
- 'page arguments' => array(1),
- 'access arguments' => array('access chado_feature content'),
- 'type' => MENU_LOCAL_TASK,
- );
-
- $items['admin/tripal/chado/tripal_feature/views/features/enable'] = array(
- 'title' => 'Enable feature Administrative View',
- 'page callback' => 'tripal_views_admin_enable_view',
- 'page arguments' => array('tripal_feature_admin_features', 'admin/tripal/chado/tripal_feature'),
- 'access arguments' => array('administer tripal_bulk_loader'),
- 'type' => MENU_CALLBACK,
- );
- return $items;
- }
- function tripal_feature_theme($existing, $type, $theme, $path) {
- $core_path = drupal_get_path('module', 'tripal_core');
-
- $items = array(
- 'node__chado_feature' => array(
- 'template' => 'node--chado-generic',
- 'render element' => 'node',
- 'base hook' => 'node',
- 'path' => "$core_path/theme",
- ),
- 'tripal_organism_feature_browser' => array(
- 'variables' => array('node' => NULL),
- 'template' => 'tripal_organism_feature_browser',
- 'path' => "$path/theme/tripal_organism",
- ),
- 'tripal_organism_feature_counts' => array(
- 'variables' => array('node' => NULL),
- 'template' => 'tripal_organism_feature_counts',
- 'path' => "$path/theme/tripal_organism",
- ),
- 'tripal_feature_base' => array(
- 'variables' => array('node' => NULL),
- 'template' => 'tripal_feature_base',
- 'path' => "$path/theme/tripal_feature",
- ),
- 'tripal_feature_sequence' => array(
- 'variables' => array('node' => NULL),
- 'template' => 'tripal_feature_sequence',
- 'path' => "$path/theme/tripal_feature",
- ),
- 'tripal_feature_proteins' => array(
- 'variables' => array('node' => NULL),
- 'template' => 'tripal_feature_proteins',
- 'path' => "$path/theme/tripal_feature",
- ),
- 'tripal_feature_synonyms' => array(
- 'variables' => array('node' => NULL),
- 'template' => 'tripal_feature_synonyms',
- 'path' => "$path/theme/tripal_feature",
- ),
- 'tripal_feature_phenotypes' => array(
- 'variables' => array('node' => NULL),
- 'template' => 'tripal_feature_phenotypes',
- 'path' => "$path/theme/tripal_feature",
- ),
- 'tripal_feature_featurepos' => array(
- 'arguments' => array('node' => NULL),
- 'template' => 'tripal_feature_featurepos',
- 'path' => "$path/theme/tripal_feature",
- ),
- 'tripal_feature_featureloc_sequences' => array(
- 'variables' => array('node' => NULL),
- 'template' => 'tripal_feature_featureloc_sequences',
- 'path' => "$path/theme/tripal_feature",
- ),
- 'tripal_feature_references' => array(
- 'variables' => array('node' => NULL),
- 'template' => 'tripal_feature_references',
- 'path' => "$path/theme/tripal_feature",
- ),
- 'tripal_feature_properties' => array(
- 'variables' => array('node' => NULL),
- 'template' => 'tripal_feature_properties',
- 'path' => "$path/theme/tripal_feature",
- ),
- 'tripal_feature_terms' => array(
- 'variables' => array('node' => NULL),
- 'template' => 'tripal_feature_terms',
- 'path' => "$path/theme/tripal_feature",
- ),
- 'tripal_feature_alignments' => array(
- 'variables' => array('node' => NULL),
- 'template' => 'tripal_feature_alignments',
- 'path' => "$path/theme/tripal_feature",
- ),
- 'tripal_feature_relationships' => array(
- 'variables' => array('node' => NULL),
- 'template' => 'tripal_feature_relationships',
- 'path' => "$path/theme/tripal_feature",
- ),
- 'tripal_feature_help' => array(
- 'template' => 'tripal_feature_help',
- 'variables' => array(NULL),
- 'path' => drupal_get_path('module', 'tripal_feature') . '/theme'
- ),
-
- 'tripal_feature_seq_extract_form' => array(
- 'arguments' => array('form'),
- )
- );
-
- return $items;
- }
- function tripal_feature_block_info() {
- $blocks['references']['info'] = t('Tripal Feature References');
- $blocks['references']['cache'] = BLOCK_NO_CACHE;
- $blocks['base']['info'] = t('Tripal Feature Details');
- $blocks['base']['cache'] = BLOCK_NO_CACHE;
- $blocks['sequence']['info'] = t('Tripal Feature Sequence');
- $blocks['sequence']['cache'] = BLOCK_NO_CACHE;
- $blocks['featureloc_sequences']['info'] = t('Tripal Feature Annotated Sequence');
- $blocks['featureloc_sequences']['cache'] = BLOCK_NO_CACHE;
- $blocks['synonyms']['info'] = t('Tripal Feature Synonyms');
- $blocks['synonyms']['cache'] = BLOCK_NO_CACHE;
- $blocks['properties']['info'] = t('Tripal Feature Properties');
- $blocks['properties']['cache'] = BLOCK_NO_CACHE;;
- $blocks['terms']['info'] = t('Tripal Annotated Terms');
- $blocks['terms']['cache'] = BLOCK_NO_CACHE;;
- $blocks['alignments']['info'] = t('Tripal Feature Alignments');
- $blocks['alignments']['cache'] = BLOCK_NO_CACHE;
- $blocks['relationships']['info'] = t('Tripal Feature Relationships');
- $blocks['relationships']['cache'] = BLOCK_NO_CACHE;
- $blocks['org_feature_counts']['info'] = t('Tripal Organism Feature Counts');
- $blocks['org_feature_counts']['cache'] = BLOCK_NO_CACHE;
- $blocks['org_feature_browser']['info'] = t('Tripal Organism Feature Browser');
- $blocks['org_feature_browser']['cache'] = BLOCK_NO_CACHE;
- return $blocks;
- }
- function tripal_feature_block_view($delta = '') {
- if (user_access('access chado_feature content') and arg(0) == 'node' and is_numeric(arg(1))) {
- $nid = arg(1);
- $node = node_load($nid);
- $block = array();
- switch ($delta) {
- case 'references':
- $block['subject'] = t('References');
- $block['content'] = theme('tripal_feature_references', $node);
- break;
- case 'base':
- $block['subject'] = t('Feature Details');
- $block['content'] = theme('tripal_feature_base', $node);
- break;
- case 'synonyms':
- $block['subject'] = t('Synonyms');
- $block['content'] = theme('tripal_feature_synonyms', $node);
- break;
- case 'properties':
- $block['subject'] = t('Properties');
- $block['content'] = theme('tripal_feature_properties', $node);
- break;
- case 'terms':
- $block['subject'] = t('Annotated Terms');
- $block['content'] = theme('tripal_feature_terms', $node);
- break;
- case 'sequence':
- $block['subject'] = t('Sequence');
- $block['content'] = theme('tripal_feature_sequence', $node);
- break;
- case 'featureloc_sequences':
- $block['subject'] = t('Formatted Sequences');
- $block['content'] = theme('tripal_feature_featureloc_sequences', $node);
- break;
- case 'alignments':
- $block['subject'] = t('Alignments');
- $block['content'] = theme('tripal_feature_alignments', $node);
- break;
- case 'relationships':
- $block['subject'] = t('Relationships');
- $block['content'] = theme('tripal_feature_relationships', $node);
- break;
- case 'org_feature_counts':
- $block['subject'] = t('Feature Type Summary');
- $block['content'] = theme('tripal_organism_feature_counts', array('node' => $node));
- break;
- case 'org_feature_browser':
- $block['subject'] = t('Feature Browser');
- $block['content'] = theme('tripal_organism_feature_browser', array('node' => $node));
- break;
- case 'library_feature_browser':
- $block['subject'] = t('Library Feature Browser');
- $block['content'] = theme('tripal_library_feature_browser', $node);
- break;
- case 'analysis_feature_browser':
- $block['subject'] = t('Analysis Feature Browser');
- $block['content'] = theme('tripal_analysis_feature_browser', $node);
- break;
- default :
- }
- return $block;
- }
- }
- function chado_feature_insert($node) {
-
- $residues = preg_replace("/[\n\r\s]/", "", $node->residues);
- $obsolete = 'FALSE';
- if ($node->is_obsolete) {
- $obsolete = 'TRUE';
- }
-
- $values = array(
- 'cv_id' => array(
- 'name' => 'sequence'
- ),
- 'name' => $node->feature_type
- );
- $type = tripal_core_chado_select('cvterm', array('cvterm_id'), $values);
- $values = array(
- 'organism_id' => $node->organism_id,
- 'name' => $node->fname,
- 'uniquename' => $node->uniquename,
- 'residues' => $residues,
- 'seqlen' => drupal_strlen($residues),
- 'is_obsolete' => $obsolete,
- 'type_id' => $type[0]->cvterm_id,
- 'md5checksum' => md5($residues)
- );
- $options = array('is_duplicate' => TRUE, 'has_record' => TRUE);
- $exists = tripal_core_chado_select('feature', array('*'), $values, $options);
-
- if (!$exists) {
- $istatus = tripal_core_chado_insert('feature', $values);
- if (!$istatus) {
- drupal_set_message(t('Unable to add feature.'), 'warning');
- watchdog('tripal_feature', 'Insert feature: Unable to create feature where values: %values',
- array('%values' => print_r($values, TRUE)), WATCHDOG_WARNING);
- }
- }
-
- $values = array(
- 'organism_id' => $node->organism_id,
- 'uniquename' => $node->uniquename,
- 'type_id' => $type[0]->cvterm_id,
- );
- $feature = tripal_core_chado_select('feature', array('feature_id'), $values);
-
- chado_feature_add_synonyms($node->synonyms, $feature[0]->feature_id);
-
-
- $node_check_sql = "
- SELECT * FROM {chado_feature}
- WHERE feature_id = :feature_id
- ";
- $node_check = db_query($node_check_sql, array(':feature_id' => $feature[0]->feature_id))->fetchObject();
- if (!$node_check) {
-
- $sql = "
- INSERT INTO {chado_feature} (nid, vid, feature_id, sync_date)
- VALUES (:nid, :vid, :feature_id, :time)
- ";
- db_query($sql, array(':nid' => $node->nid, ':vid' => $node->vid,
- ':feature_id' => $feature[0]->feature_id, ':time' => REQUEST_TIME));
- }
- }
- function chado_feature_update($node) {
- if ($node->revision) {
-
-
- }
- $residues = preg_replace("/[\n\r\s]/", "", $node->residues);
- $obsolete = 'FALSE';
- if ($node->is_obsolete) {
- $obsolete = 'TRUE';
- }
-
- $values = array(
- 'cv_id' => array(
- 'name' => 'sequence'
- ),
- 'name' => $node->feature_type
- );
- $type = tripal_core_chado_select('cvterm', array('cvterm_id'), $values);
- $feature_id = chado_get_id_for_node('feature', $node->nid) ;
- if (sizeof($type) > 0) {
- $match = array(
- 'feature_id' => $feature_id,
- );
- $values = array(
- 'organism_id' => $node->organism_id,
- 'name' => $node->fname,
- 'uniquename' => $node->uniquename,
- 'residues' => $residues,
- 'seqlen' => drupal_strlen($residues),
- 'is_obsolete' => $obsolete,
- 'type_id' => $type[0]->cvterm_id,
- 'md5checksum' => md5($residues)
- );
- $options = array('return_record' => TRUE);
- $status = tripal_core_chado_update('feature', $match, $values, $options);
-
- chado_feature_add_synonyms($node->synonyms, $feature_id);
- }
- else {
- drupal_set_message(t('Unable to update feature.'), 'warning');
- watchdog('tripal_feature',
- 'Update feature: Unable to update feature where values: %values',
- array('%values' => print_r($values, TRUE)),
- WATCHDOG_WARNING
- );
- }
- }
- function chado_feature_delete($node) {
- $feature_id = chado_get_id_for_node('feature', $node->nid);
-
-
- if (!$feature_id) {
- return;
- }
-
- $sql_del = "DELETE FROM {chado_feature} WHERE nid = :nid AND vid = :vid";
- db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
- $sql_del = "DELETE FROM {node} WHERE nid = :nid AND vid = :vid";
- db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
- $sql_del = "DELETE FROM {node_revision} WHERE nid = :nid AND vid = :vid";
- db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
-
-
-
- chado_query("DELETE FROM {feature} WHERE feature_id = :feature_id", array(':feature_id' => $feature_id));
- drupal_set_message(t("The feature and all associated data were removed from") .
- "chado");
- }
- function chado_feature_add_synonyms($synonyms, $feature_id) {
-
- $synonyms = preg_replace("/[\n\r]+/", " ", $synonyms);
-
- $syn_array = array();
- $syn_array = explode(" ", $synonyms);
-
- $feature_syn_dsql = "DELETE FROM {feature_synonym} WHERE feature_id = :feature_id";
- if (!chado_query($feature_syn_dsql, array(':feature_id' => $feature_id))) {
- watchdog('tripal_feature', "Could not remove synonyms from feature. ", array(), WATCHDOG_ERROR);
- return;
- }
-
- if (!$synonyms) {
- return;
- }
-
- foreach ($syn_array as $syn) {
-
- if (!$syn) {
- break;
- }
-
-
-
- $synonym_sql = "SELECT synonym_id FROM {synonym} WHERE name = :name";
- $synonym = chado_query($synonym_sql, array(':name' => $syn))->fetchObject();
- if (!$synonym) {
- $synonym_isql = "
- INSERT INTO {synonym} (name, synonym_sgml, type_id)
- VALUES (:name, :synonym_sgml,
- (SELECT cvterm_id
- FROM {cvterm} CVT
- INNER JOIN {cv} ON CVT.cv_id = CV.cv_id
- WHERE CV.name = 'feature_property' and CVT.name = 'synonym')
- )
- ";
- if (!chado_query($synonym_isql, array(':name' => $syn, ':synonym_sgml' => $syn))) {
- watchdog('tripal_feature', "Could not add synonym. ", array(), WATCHDOG_WARNING);
- return;
- }
-
- $synonym_sql = "SELECT synonym_id FROM {synonym} WHERE name = :name";
- $synonym = chado_query($synonym_sql, array(':name' => $syn))->fetchObject();
- }
-
- $feature_syn_isql = "
- INSERT INTO {feature_synonym} (synonym_id,feature_id,pub_id)
- VALUES (:synonym_id, :feature_id, :pub_id)";
- $args = array(':synonym_id' => $synonym->synonym_id, ':feature_id' => $feature_id, ':pub_id'=> 1);
- if (!chado_query($feature_syn_isql, $args)) {
- watchdog('tripal_feature', "Could not associate synonym with feature. ", array(), WATCHDOG_WARNING);
- return;
- }
- }
- }
- function chado_feature_add_gbaccession($accession, $feature_id) {
-
-
- $fdbxref_dsql = "
- DELETE FROM {feature_dbxref}
- WHERE feature_id = :feature_id and dbxref_id IN
- (SELECT DBX.dbxref_id
- FROM {dbxref} DBX
- INNER JOIN DB ON DB.db_id = DBX.db_id
- INNER JOIN feature_dbxref FDBX ON DBX.dbxref_id = FDBX.dbxref_id
- WHERE DB.name = 'DB:Genbank' and FDBX.feature_id = :feature_id
- )
- ";
- if (!chado_query($fdbxref_dsql, array(':feature_id' => $feature_id))) {
- $error .= "Could not remove accession from feature. ";
- }
-
- if (!$accession) {
- return;
- }
-
- $db_sql = "SELECT db_id FROM {DB} WHERE name = 'DB:Genbank_est'";
- $db = chado_query($db_sql)->fetchObject();
-
-
-
- $dbxref_sql = "SELECT dbxref_id FROM {dbxref} WHERE db_id = :db_id and accession = :accession";
- $dbxref = chado_query($dbxref_sql, array(':db_id' => $db->db_id, ':accession' => $accession))->fetchObject();
- if (!$dbxref) {
-
- $dbxref_isql = "INSERT INTO {dbxref} (db_id, accession) VALUES (:db_id, :accession) ";
- if (!chado_query($dbxref_isql, array(':db_id' => $db->db_id, ':accession' => $accession))) {
- $error .= 'Could not add accession as a database reference ';
- }
-
- $dbxref_sql = "SELECT dbxref_id FROM {dbxref} WHERE db_id = :db_id and accession = :accession";
- $dbxref = chado_query($dbxref_sql, array(':db_id' => $db->db_id, ':accession' => $accession))->fetchObject();
- }
-
- $feature_dbxref_isql = "INSERT INTO {feature_dbxref} (feature_id, dbxref_id) VALUES (:feature_id, :dbxref_id) ";
- if (!chado_query($feature_dbxref_isql, array(':feature_id' => $feature_id, ':dbxref_id' => $dbxref->dbxref_id))) {
- $error .= 'Could not add feature database reference. ';
- }
- return $error;
- }
- function chado_feature_load($nodes) {
- foreach ($nodes as $nid => $node) {
-
- $feature_id = chado_get_id_for_node('feature', $nid);
-
-
- $values = array('feature_id' => $feature_id);
- $feature = tripal_core_generate_chado_var('feature', $values);
- $nodes[$nid]->feature = $feature;
-
-
-
-
- $title_type = variable_get('chado_feature_title', 'unique_constraint');
- if ($title_type == 'unique_constraint') {
- if (strcmp($feature->name, $feature->uniquename)==0) {
- $node->title = $feature->name . " (" . $feature->type_id->name . ") " . $feature->organism_id->genus . " " . $feature->organism_id->species ;
- }
-
-
- else {
- $node->title = $feature->name . ", " . $feature->uniquename . " (" . $feature->type_id->name . ") " . $feature->organism_id->genus . " " . $feature->organism_id->species ;
- }
- }
-
- if ($title_type == 'feature_name') {
- $node->title = $feature->name;
- }
- if ($title_type == 'feature_unique_name') {
- $node->title = $feature->uniquename;
- }
- }
- }
- function tripal_feature_load_organism($organism_id) {
-
- $sql = "SELECT * FROM {organism} WHERE organism_id = :organism_id";
- $organism = chado_query($sql, array(':organism_id' => $organism_id))->fetchObject();
- return $organism;
- }
- function tripal_feature_load_synonyms($feature_id) {
- $sql = "
- SELECT S.name
- FROM {feature_synonym} FS
- INNER JOIN {synonym} S ON FS.synonym_id = S.Synonym_id
- WHERE FS.feature_id = :feature_id
- ORDER BY S.name
- ";
- $results = chado_query($sql, array(':feature_id' => $feature_id));
- $synonyms = array();
- $i=0;
- while ($synonym = $results->fetchObject()) {
- $synonyms[$i++] = $synonym;
- }
- return $synonyms;
- }
- function tripal_feature_load_properties($feature_id) {
- $sql = "
- SELECT
- CVT.name as cvname, CVT.definition, CVT.is_obsolete,
- FS.type_id, FS.value, FS.rank,
- DBX.dbxref_id,DBX.accession,DB.name as dbname,
- DB.urlprefix, DB.description as db_description, DB.url
- FROM {featureprop} FS
- INNER JOIN {cvterm} CVT ON FS.type_id = CVT.cvterm_id
- INNER JOIN {dbxref} DBX ON CVT.dbxref_id = DBX.dbxref_id
- INNER JOIN {db} DB ON DB.db_id = DBX.db_id
- WHERE
- FS.feature_id = :feature_id
- ORDER BY FS.rank ASC
- ";
- $results = chado_query($sql, array(':feature_id' => $feature_id));
- $i=0;
- $properties = array();
- while ($property = $results->fetchObject()) {
- $properties[$i++] = $property;
- }
- return $properties;
- }
- function tripal_feature_load_references($feature_id) {
- $sql = "
- SELECT
- F.uniquename, F.Feature_id,
- DB.description as dbdesc, DB.db_id, DB.name as db_name, DB.urlprefix,
- DBX.accession, DBX.dbxref_id
- FROM {feature} F
- INNER JOIN {feature_dbxref} FDBX ON F.feature_id = FDBX.feature_id
- INNER JOIN {dbxref} DBX ON DBX.dbxref_id = FDBX.dbxref_id
- INNER JOIN {db} ON DB.db_id = DBX.db_id
- WHERE
- F.feature_id = :feature_id
- ORDER BY DB.name
- ";
- $results = chado_query($sql, array(':feature_id' => $feature_id));
- $references = array();
- $i=0;
- while ($accession = $results->fetchObject()) {
- $references[$i++] = $accession;
- }
- return $references;
- }
- function tripal_feature_load_featurelocs($feature_id, $side = 'as_parent', $aggregate = 1) {
- $sql = "
- SELECT
- F.name, F.feature_id, F.uniquename,
- FS.name as src_name, FS.feature_id as src_feature_id, FS.uniquename as src_uniquename,
- CVT.name as cvname, CVT.cvterm_id,
- CVTS.name as src_cvname, CVTS.cvterm_id as src_cvterm_id,
- FL.fmin, FL.fmax, FL.is_fmin_partial, FL.is_fmax_partial,FL.strand, FL.phase
- FROM {featureloc} FL
- INNER JOIN {feature} F ON FL.feature_id = F.feature_id
- INNER JOIN {feature} FS ON FS.feature_id = FL.srcfeature_id
- INNER JOIN {cvterm} CVT ON F.type_id = CVT.cvterm_id
- INNER JOIN {cvterm} CVTS ON FS.type_id = CVTS.cvterm_id
- ";
- if (strcmp($side, 'as_parent')==0) {
- $sql .= "WHERE FL.srcfeature_id = :feature_id ";
- }
- if (strcmp($side, 'as_child')==0) {
- $sql .= "WHERE FL.feature_id = :feature_id ";
- }
- $flresults = chado_query($sql, array(':feature_id' => $feature_id));
-
- $i=0;
- $featurelocs = array();
- while ($loc = $flresults->fetchObject()) {
-
-
- $sql = 'SELECT nid FROM {chado_feature} WHERE feature_id = :feature_id';
- $ffeature = db_query($sql, array(':feature_id' => $loc->feature_id))->fetchObject();
- $sfeature = db_query($sql, array(':feature_id' => $loc->src_feature_id))->fetchObject();
- $loc->fnid = $ffeature->nid;
- $loc->snid = $sfeature->nid;
-
- $featurelocs[$i++] = $loc;
- }
-
- if ($aggregate and strcmp($side, 'as_parent')==0) {
-
-
- $relationships = tripal_feature_get_aggregate_relationships($feature_id, 0);
- foreach ($relationships as $rindex => $rel) {
-
- $rel_featurelocs = tripal_feature_load_featurelocs($rel->subject_id, 'as_child', 0);
- foreach ($rel_featurelocs as $findex => $rfloc) {
- $featurelocs[$i++] = $rfloc;
- }
- }
- }
- usort($featurelocs, 'tripal_feature_sort_locations');
- return $featurelocs;
- }
- function tripal_feature_sort_locations($a, $b) {
- return strnatcmp($a->fmin, $b->fmin);
- }
- function tripal_feature_load_relationships($feature_id, $side = 'as_subject') {
-
-
- $sql = "
- SELECT
- FS.name as subject_name, FS.uniquename as subject_uniquename,
- CVTS.name as subject_type, CVTS.cvterm_id as subject_type_id,
- FR.subject_id, FR.type_id as relationship_type_id, FR.object_id, FR.rank,
- CVT.name as rel_type,
- FO.name as object_name, FO.uniquename as object_uniquename,
- CVTO.name as object_type, CVTO.cvterm_id as object_type_id
- FROM {feature_relationship} FR
- INNER JOIN {cvterm} CVT ON FR.type_id = CVT.cvterm_id
- INNER JOIN {feature} FS ON FS.feature_id = FR.subject_id
- INNER JOIN {feature} FO ON FO.feature_id = FR.object_id
- INNER JOIN {cvterm} CVTO ON FO.type_id = CVTO.cvterm_id
- INNER JOIN {cvterm} CVTS ON FS.type_id = CVTS.cvterm_id
- ";
- if (strcmp($side, 'as_object')==0) {
- $sql .= " WHERE FR.object_id = :feature_id";
- }
- if (strcmp($side, 'as_subject')==0) {
- $sql .= " WHERE FR.subject_id = :feature_id";
- }
- $sql .= " ORDER BY FR.rank";
-
- $results = chado_query($sql, array(':feature_id' => $feature_id));
-
-
- $i=0;
- $nodesql = "SELECT nid FROM {chado_feature} WHERE feature_id = :feature_id";
- $relationships = array();
- while ($rel = $results->fetchObject()) {
- $node = db_query($nodesql, array(':feature_id' => $rel->subject_id))->fetchObject();
- if ($node) {
- $rel->subject_nid = $node->nid;
- }
- $node = db_query($nodesql, array(':feature_id' => $rel->object_id))->fetchObject();
- if ($node) {
- $rel->object_nid = $node->nid;
- }
- $relationships[$i++] = $rel;
- }
- return $relationships;
- }
- function tripal_feature_get_aggregate_relationships($feature_id, $substitute=1,
- $levels=0, $base_type_id=NULL, $depth=0) {
-
-
-
- if ($levels > 0 and $levels == $depth) {
- return NULL;
- }
-
- return tripal_feature_load_relationships($feature_id, 'as_object');
- }
- function tripal_feature_load_featureloc_sequences($feature_id, $featurelocs) {
-
- if (!$featurelocs) {
- return array();
- }
-
-
- $relationships = tripal_feature_get_aggregate_relationships($feature_id);
- if (!$relationships) {
- return array();
- }
-
-
- foreach ($relationships as $rindex => $rel) {
-
- $rel_featurelocs = tripal_feature_load_featurelocs($rel->subject_id, 'as_child', 0);
- foreach ($rel_featurelocs as $rfindex => $rel_featureloc) {
-
- $src = $rel_featureloc->src_feature_id . "-" . $rel_featureloc->src_cvterm_id;
-
-
-
- $rel->featurelocs = new stdClass();
- $rel->featurelocs->$src = new stdClass();
- $rel->featurelocs->$src->src_uniquename = $rel_featureloc->src_uniquename;
- $rel->featurelocs->$src->src_cvterm_id = $rel_featureloc->src_cvterm_id;
- $rel->featurelocs->$src->src_cvname = $rel_featureloc->src_cvname;
- $rel->featurelocs->$src->fmin = $rel_featureloc->fmin;
- $rel->featurelocs->$src->fmax = $rel_featureloc->fmax;
- $rel->featurelocs->$src->src_name = $rel_featureloc->src_name;
-
- $start = $rel->featurelocs->$src->fmin;
- $end = $rel->featurelocs->$src->fmax;
- $type = $rel->subject_type;
- $rel_locs[$src]['parts'][$start][$type]['start'] = $start;
- $rel_locs[$src]['parts'][$start][$type]['end'] = $end;
- $rel_locs[$src]['parts'][$start][$type]['type'] = $type;
- }
- }
-
-
-
-
- $sql = "
- SELECT substring(residues from :start for :size) as residues
- FROM {feature}
- WHERE feature_id = :feature_id
- ";
- $floc_sequences = array();
- foreach ($featurelocs as $featureloc) {
-
- $src = $featureloc->srcfeature_id->feature_id . "-" . $featureloc->srcfeature_id->type_id->cvterm_id;
-
- if (!empty($rel_locs[$src]['parts'])) {
- $parts = $rel_locs[$src]['parts'];
- $rparts = array();
- foreach ($parts as $start => $types) {
- foreach ($types as $type_name => $type) {
- if ($featureloc->strand >= 0) {
-
-
- $parts[$start][$type_name]['start'] = $parts[$start][$type_name]['start'] - $featureloc->fmin;
- $parts[$start][$type_name]['end'] = $parts[$start][$type_name]['end'] - $featureloc->fmin;
- $parts[$start][$type_name]['type'] = $type_name;
- }
- else {
-
-
- $size = ($featureloc->fmax - $featureloc->fmin);
- $start_orig = $parts[$start][$type_name]['start'];
- $end_orig = $parts[$start][$type_name]['end'];
- $new_start = $size - ($end_orig - $featureloc->fmin);
- $new_end = $size - ($start_orig - $featureloc->fmin);
- $rparts[$new_start][$type_name]['start'] = $new_start;
- $rparts[$new_start][$type_name]['end'] = $new_end;
- $rparts[$new_start][$type_name]['type'] = $type_name;
- }
- }
- }
-
-
- if ($featureloc->strand >= 0) {
- usort($parts, 'tripal_feature_sort_rel_parts_by_start');
- }
- else {
- usort($rparts, 'tripal_feature_sort_rel_parts_by_start');
- $parts = $rparts;
- }
- $floc_sequences[$src]['src'] = $src;
- $floc_sequences[$src]['type'] = $featureloc->feature_id->type_id->name;
- $args = array(':start' => $featureloc->fmin + 1, ':size' => ($featureloc->fmax - $featureloc->fmin), ':feature_id' => $featureloc->srcfeature_id->feature_id);
- $sequence = chado_query($sql, $args)->fetchObject();
- $residues = $sequence->residues;
- if ($featureloc->strand < 0) {
- $residues = tripal_feature_reverse_complement($residues);
- }
- $strand = '.';
- if ($featureloc->strand == 1) {
- $strand = '+';
- }
- elseif ($featureloc->strand == -1) {
- $strand = '-';
- }
- $defline = $featureloc->feature_id->name . " " . $featureloc->srcfeature_id->name . ":" . ($featureloc->fmin + 1) . ".." . $featureloc->fmax . " " . $strand;
- $floc_sequences[$src]['formatted_seq'] = tripal_feature_color_sequence($residues, $parts, $defline);
- }
- }
- return $floc_sequences;
- }
- function tripal_feature_get_matched_alignments($feature) {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- $sql = "
- SELECT
- FL1.featureloc_id as left_featureloc_id,
- FL1.srcfeature_id as left_srcfeature_id,
- FL1.feature_id as left_feature_id,
- FL1.fmin as left_fmin,
- FL1.is_fmin_partial as left_is_fmin_partial,
- FL1.fmax as left_fmax,
- FL1.is_fmax_partial as left_is_fmax_partial,
- FL1.strand as left_strand,
- FL1.phase as left_phase,
- FL1.locgroup as left_locgroup,
- FL1.rank as left_rank,
- FL2.featureloc_id as right_featureloc_id,
- FL2.srcfeature_id as right_srcfeature_id,
- FL2.feature_id as right_feature_id,
- FL2.fmin as right_fmin,
- FL2.is_fmin_partial as right_is_fmin_partial,
- FL2.fmax as right_fmax,
- FL2.is_fmax_partial as right_is_fmax_partial,
- FL2.strand as right_strand,
- FL2.phase as right_phase,
- FL2.locgroup as right_locgroup,
- FL2.rank as right_rank
- FROM {feature} F1
- INNER JOIN {featureloc} FL1 on FL1.srcfeature_id = F1.feature_id
- INNER JOIN {feature} F2 on FL1.feature_id = F2.feature_id
- INNER JOIN {featureloc} FL2 on FL2.feature_id = F2.feature_id
- INNER JOIN {cvterm} CVT2 on F2.type_id = CVT2.cvterm_id
- WHERE
- F1.feature_id = :feature_id AND
- (CVT2.name = 'match' or CVT2.name like '%_match')
- ORDER BY FL1.fmin
- ";
- $results = chado_query($sql, array(':feature_id' => $feature->feature_id));
-
- $featurelocs = array();
- while ($fl = $results->fetchObject()) {
-
- if (strcmp($fl->left_srcfeature_id, $fl->right_srcfeature_id) == 0) {
- continue;
- }
- $featurelocs[] = $fl ;
- }
- return $featurelocs;
- }
- function tripal_feature_load_organism_feature_counts($organism) {
-
-
- $show_counts = variable_get('tripal_feature_summary_setting', 'show_feature_summary');
- if (strcmp($show_counts, 'show_feature_summary')!=0) {
- return array('enabled' => FALSE );
- }
- $args = array();
- $names = array();
- $order = array();
-
-
-
- $is_custom = 0;
- $temp = rtrim(variable_get('tripal_feature_summary_report_mapping', ''));
- $where = '';
- if ($temp) {
- $is_custom = 1;
- $temp = explode("\n", $temp);
- $i = 0;
- foreach ($temp as $key => $value) {
-
- $temp2 = explode("=", $value);
- $feature_type = rtrim($temp2[0]);
- $args[] = $feature_type;
- $order[] = $feature_type;
-
-
- if (count($temp2) == 2) {
- $names[":name$i"] = rtrim($temp2[1]);
- }
- else {
- $names[":name$i"] = $feature_type;
- }
- $where .= " OFC.feature_type = :name$i OR ";
- $i++;
- }
- if ($where) {
- $where = drupal_substr($where, 0, -5);
- $where = "($where) AND";
- }
- }
-
-
- $sql = "
- SELECT OFC.num_features,OFC.feature_type,CVT.definition
- FROM {organism_feature_count} OFC
- INNER JOIN {cvterm} CVT on OFC.cvterm_id = CVT.cvterm_id
- WHERE $where organism_id = :organism_id
- ORDER BY num_features desc
- ";
- $args[':organism_id'] = $organism->organism_id;
- $org_features = chado_query($sql, $args);
-
- $types = array();
- while ($type = $org_features->fetchObject()) {
- $types[$type->feature_type] = $type;
-
-
- if (!$is_custom) {
- $names[] = $type->feature_type;
- $order[] = $type->feature_type;
- }
- }
-
- $ordered_types = array();
- foreach ($order as $type) {
- $ordered_types[] = $types[$type];
- }
- return array( 'types' => $ordered_types, 'names' => $names, 'enabled' => TRUE );
- }
- function tripal_feature_load_organism_feature_browser($organism) {
- if (!$organism) {
- return array();
- }
-
-
- $show_browser = variable_get('tripal_feature_browse_setting', 'show_feature_browser');
- if (strcmp($show_browser, 'show_feature_browser')!=0) {
- return array('enabled' => FALSE);
- }
-
-
-
- $allowed_types = variable_get('chado_browser_feature_types', 'EST contig');
- $allowed_types = preg_replace("/[\s\n\r]+/", " ", $allowed_types);
- $so_terms = split(' ', $allowed_types);
-
- $values = array(
- 'organism_id' => $organism->organism_id,
- 'type_id' => array(
- 'name' => $so_terms
- ),
- );
- $columns = array('feature_id', 'name', 'uniquename', 'type_id');
- $options = array(
- 'pager' => array('limit' => 10, 'element' => 0),
- 'order_by' => array('name' => 'ASC'),
- );
- $features = tripal_core_chado_select('feature', $columns, $values, $options);
- $pager = theme('pager');
-
- $nsql = "SELECT nid FROM {chado_feature} WHERE feature_id = :feature_id";
- $tsql = "SELECT name FROM {cvterm} WHERE cvterm_id = :cvterm_id";
- foreach ($features as $feature) {
- $node = db_query($nsql, array(':feature_id' => $feature->feature_id))->fetchObject();
- $type = chado_query($tsql, array(':cvterm_id' => $feature->type_id))->fetchObject();
- $feature->nid = $node->nid;
- $feature->type_name = $type->name;
- }
- return array( 'features' => $features, 'pager' => $pager, 'enabled' => TRUE );
- }
- function tripal_feature_load_library_feature_browser($library) {
-
-
- $show_browser = variable_get('tripal_library_feature_browse_setting', 'show_feature_browser');
- if (strcmp($show_browser, 'show_feature_browser')!=0) {
- return array('enabled' => FALSE);
- }
-
- $allowed_types = variable_get('chado_browser_feature_types', 'EST contig');
- $allowed_types = preg_replace("/[\s\n\r]+/", " ", $allowed_types);
- $so_terms = split(' ', $allowed_types);
- $where_cvt = "";
- $args = array();
- $i = 0;
- foreach ($so_terms as $term) {
- $where_cvt .= "CVT.name = :cvtname$i OR ";
- $args[':cvtname$i'] = $term;
- $i++;
- }
- $where_cvt = drupal_substr($where_cvt, 0, drupal_strlen($where_cvt)-3);
-
- $sql = "
- SELECT F.name, F.feature_id, F.uniquename, CVT.name as cvname
- FROM {feature} F
- INNER JOIN {cvterm} CVT ON F.type_id = CVT.cvterm_id
- INNER JOIN {library_feature} LF ON F.feature_id = LF.feature_id
- INNER JOIN {library} L ON LF.library_id = L.library_id
- WHERE LF.library_id = :library_id and ($where_cvt)
- ORDER BY feature_id ASC
- ";
- $args[':library_id'] = $library->libary_id;
-
- $csql = "
- SELECT count(*)
- FROM {feature} F
- INNER JOIN {cvterm} CVT on F.type_id = CVT.cvterm_id
- INNER JOIN {library_feature} LF on F.feature_id = LF.feature_id
- INNER JOIN {library} L on LF.library_id = L.library_id
- WHERE LF.library_id = :library_id and ($where_cvt)
- GROUP BY L.library_id ";
- $org_features = chado_pager_query($sql, 10, 0, $csql, $args);
- $pager = theme('pager');
-
- $sql = "SELECT nid FROM {chado_feature} WHERE feature_id = :feature_id";
- $i=0;
- $features = array();
- while ($feature = $org_features->fetchObject()) {
- $node = db_query($sql, array(':feature_id' => $feature->feature_id))->fetchObject();
- $feature->nid = $node->nid;
- $features[$i++] = $feature;
- }
- return array( 'features' => $features, 'pager' => $pager, 'enabled' => TRUE );
- }
- function tripal_feature_load_analysis_feature_browser($analysis) {
-
-
- $show_browser = variable_get('tripal_analysis_feature_browse_setting', 'show_feature_browser');
- if (strcmp($show_browser, 'show_feature_browser')!=0) {
- return array('enabled' => FALSE);
- }
-
- $allowed_types = variable_get('chado_browser_feature_types', 'EST contig');
- $allowed_types = preg_replace("/[\s\n\r]+/", " ", $allowed_types);
- $so_terms = split(' ', $allowed_types);
- $where_cvt = "";
- $i = 0;
- $args = array();
- foreach ($so_terms as $term) {
- $where_cvt .= "CVT.name = :aname$i OR ";
- $args[":aname$i"] = $term;
- $i++;
- }
- $where_cvt = drupal_substr($where_cvt, 0, drupal_strlen($where_cvt)-3);
-
- $sql = "
- SELECT F.name,F.feature_id,F.uniquename,CVT.name as cvname
- FROM {feature} F
- INNER JOIN {cvterm} CVT on F.type_id = CVT.cvterm_id
- INNER JOIN {analysisfeature} AF on F.feature_id = AF.feature_id
- INNER JOIN {analysis} A on AF.analysis_id = A.analysis_id
- WHERE A.analysis_id = :analysis_id and ($where_cvt)
- ORDER BY feature_id ASC
- ";
- $args[':analysis_id'] = $analysis->analysis_id;
-
- $csql = "
- SELECT count(*)
- FROM {feature} F
- INNER JOIN {cvterm} CVT on F.type_id = CVT.cvterm_id
- INNER JOIN {analysisfeature} AF on F.feature_id = AF.feature_id
- INNER JOIN {analysis} A on AF.analysis_id = A.analysis_id
- WHERE A.analysis_id = %d and ($where_cvt)
- GROUP BY A.analysis_id
- ";
- $org_features = chado_pager_query($sql, 10, 0, $csql, $args);
- $pager = theme('pager');
-
- $sql = "SELECT nid FROM {chado_feature} WHERE feature_id = :feature_id";
- $i=0;
- $features = array();
- while ($feature = $org_features->fetchObject()) {
- $node = db_query($sql, array(':feature_id' => $feature->feature_id))->fetchObject();
- $feature->nid = $node->nid;
- $features[$i++] = $feature;
- }
- return array( 'features' => $features, 'pager' => $pager, 'enabled' => TRUE );
- }
- function tripal_feature_sort_rel_objects($a, $b) {
- return strnatcmp($a->fmin, $b->fmin);
- }
- function tripal_feature_sort_rel_parts_by_start($a, $b) {
- foreach ($a as $type_name => $details) {
- $astart = $a[$type_name]['start'];
- break;
- }
- foreach ($b as $type_name => $details) {
- $bstart = $b[$type_name]['start'];
- break;
- }
- return strnatcmp($astart, $bstart);
- }
- function tripal_feature_sort_rel_parts_by_end($a, $b) {
- $val = strnatcmp($b['end'], $a['end']);
- if ($val == 0) {
- return strcmp($a['type'], $b['type']);
- }
- return $val;
- }
- function tripal_feature_color_sequence($sequence, $parts, $defline) {
- $types = array();
-
- foreach ($parts as $index => $t) {
- foreach ($t as $type_name => $details) {
- $types[$type_name] = 1;
- }
- }
- $newseq .= "<div id=\"tripal_feature-featureloc_sequence-legend\">Legend: ";
- foreach ($types as $type_name => $present) {
- $newseq .= "<span id=\"tripal_feature-legend-$type_name\" class=\"tripal_feature-legend-item tripal_feature-featureloc_sequence-$type_name\" script=\"\">$type_name</span>";
- }
- $newseq .= "</div>Hold the cursor over a type above to highlight its positions in the sequence below. The colors in the sequence below merge when types overlap.";
-
- $pos = 0;
- $newseq .= "<pre id=\"tripal_feature-featureloc_sequence\">";
- $newseq .= ">$defline\n";
-
- $ends = array();
- foreach ($parts as $index => $types) {
-
-
- foreach ($types as $type => $child) {
- $start = $child['start'];
- break;
- }
-
- for ($i = $pos; $i < $start; $i++) {
- $newseq .= $sequence{$pos};
- $seqcount++;
- if ($seqcount % 50 == 0) {
- $newseq .= "\n";
- }
- if (array_key_exists($pos, $ends)) {
- foreach ($ends[$pos] as $end) {
- $newseq .= "</span>";
- }
- }
- $pos++;
- }
-
-
- usort($types, 'tripal_feature_sort_rel_parts_by_end');
-
- foreach ($types as $type) {
- $class = "tripal_feature-featureloc_sequence-" . $type['type'];
- $newseq .= "<span class=\"$class\">";
-
- $end = $type['end'];
- $ends[$end][] = $end;
- }
- }
-
- for ($i = $pos; $i <= strlen($sequence); $i++) {
- $newseq .= $sequence{$pos};
- $seqcount++;
- if ($seqcount % 50 == 0) {
- $newseq .= "\n";
- }
- if (array_key_exists($pos, $ends)) {
- foreach ($ends[$pos] as $end) {
- $newseq .= "</span>";
- }
- }
- $pos++;
- }
- $newseq .= "</pre>";
- return $newseq;
- }
- function tripal_feature_node_presave($node) {
-
- switch ($node->type) {
- case 'chado_feature':
- $values = array('organism_id' => $node->organism_id);
- $organism = tripal_core_chado_select('organism', array('genus', 'species'), $values);
- $node->title = $node->fname . ', ' . $node->uniquename . ' (' . $node->feature_type . ') ' . $organism[0]->genus . ' ' . $organism[0]->species;
- break;
- }
- }
- function tripal_feature_node_insert($node) {
-
-
- switch ($node->type) {
- case 'chado_feature':
- if (!$node->feature_id) {
- $sql = "SELECT * FROM {chado_feature} WHERE nid = :nid";
- $chado_feature = db_query($sql, array(':nid' => $node->nid))->fetchObject();
- $node->feature_id = $chado_feature->feature_id;
- }
-
- db_query("DELETE FROM {url_alias} WHERE source = :source", array(':source' => "node/$node->nid"));
-
- $url_alias = tripal_feature_get_feature_url($node);
- $path_alias = array("source" => "node/$node->nid", "alias" => $url_alias);
- path_save($path_alias);
- break;
- }
- }
- function tripal_feature_node_view($node, $view_mode, $langcode) {
- switch ($node->type) {
- case 'chado_feature':
-
- if ($view_mode == 'full') {
- $node->content['tripal_feature_base'] = array(
- '#value' => theme('tripal_feature_base', array('node' => $node)),
- );
- $node->content['tripal_feature_seqence'] = array(
- '#value' => theme('tripal_feature_sequence', array('node' => $node)),
- );
- $node->content['tripal_feature_synonyms'] = array(
- '#value' => theme('tripal_feature_synonyms', array('node' => $node)),
- );
- }
- if ($view_mode == 'teaser') {
- $node->content['tripal_feature_teaser'] = array(
- '#value' => theme('tripal_feature_teaser', array('node' => $node)),
- );
- }
- break;
- case 'chado_organism':
-
- if ($view_mode == 'full') {
- $node->content['tripal_organism_feature_counts'] = array(
- '#value' => theme('tripal_organism_feature_counts', array('node' => $node)),
- );
- $node->content['tripal_organism_feature_browser'] = array(
- '#value' => theme('tripal_organism_feature_browser', array('node' => $node)),
- );
- }
- break;
-
- case 'chado_library':
- break;
- case 'chado_stock':
- break;
- case 'chado_analysis':
- break;
- }
- }
- function tripal_feature_node_update($node) {
-
- switch ($node->type) {
- case 'chado_feature':
-
- db_query("DELETE FROM {url_alias} WHERE source = :source", array(':source' => "node/$node->nid"));
-
- $url_alias = tripal_feature_get_feature_url($node);
- $path_alias = array("source" => "node/$node->nid", "alias" => $url_alias);
- path_save($path_alias);
- break;
- }
- }
- function tripal_feature_preprocess_tripal_feature_relationships(&$variables) {
-
- $feature = $variables['node']->feature;
- if (!$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 (!$feature->all_relationships) {
- $feature->all_relationships = tripal_feature_get_feature_relationships($feature);
- }
- }
- function tripal_feature_preprocess_tripal_feature_alignments(&$variables) {
-
- $feature = $variables['node']->feature;
- $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);
- }
-
- $pfeaturelocs = $feature->featureloc->srcfeature_id;
- if (!$pfeaturelocs) {
- $pfeaturelocs = array();
- }
- elseif (!is_array($pfeaturelocs)) {
- $pfeaturelocs = array($pfeaturelocs);
- }
-
- $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->nid = $featureloc->feature_id->nid;
- $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;
- }
- 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->nid = $featureloc->srcfeature_id->nid;
- $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;
- }
-
-
- foreach ($mfeaturelocs as $featureloc) {
-
- $select = array('feature_id' => $featureloc->right_srcfeature_id);
- $rfeature = tripal_core_generate_chado_var('feature', $select);
-
- $alignment = new stdClass();
- $alignment->record = $featureloc;
- $alignment->right_feature = $rfeature;
- $alignment->name = $rfeature->name;
- $alignment->nid = $rfeature->nid;
- $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;
- }
- $feature->all_featurelocs = $alignments;
- }
- function tripal_feature_preprocess_tripal_organism_feature_counts(&$variables, $hook) {
-
-
- }
- function tripal_feature_preprocess_tripal_organism_feature_browser(&$variables, $hook) {
-
-
- }
- function tripal_feature_preprocess_tripal_library_feature_browser(&$variables) {
- $library = $variables['node']->library;
- $library->feature_browser = tripal_feature_load_library_feature_browser($library);
- }
- function tripal_feature_preprocess_tripal_analysis_feature_browser(&$variables) {
- $analysis = $variables['node']->analysis;
- $analysis->feature_browser = tripal_feature_load_analysis_feature_browser($analysis);
- }
- function tripal_feature_cv_chart($chart_id) {
-
- $temp = rtrim(variable_get('tripal_feature_summary_report_mapping', ''));
- $where = '';
- if ($temp) {
- $temp = explode("\n", $temp);
- foreach ($temp as $key => $value) {
- $temp2 = explode("=", $value);
- $feature_type = rtrim($temp2[0]);
- $where .= "CNT.feature_type = '$feature_type' OR \n";
- }
- if ($where) {
- $where = drupal_substr($where, 0, -5);
- $where = "($where) AND";
- }
- }
- $organism_id = preg_replace("/^tripal_feature_cv_chart_(\d+)$/", "$1", $chart_id);
-
-
-
-
-
- $options = array(
- count_mview => 'organism_feature_count',
- cvterm_id_column => 'cvterm_id',
- count_column => 'num_features',
- size => '550x200',
- filter => "$where CNT.organism_id = $organism_id",
- );
- return $options;
- }
- function tripal_feature_cv_tree($tree_id) {
-
-
-
-
-
- $organism_id = preg_replace("/^tripal_feature_cv_tree_(\d+)$/", "$1", $tree_id);
- $options = array(
- cv_id => tripal_cv_get_cv_id('sequence'),
- count_mview => 'organism_feature_count',
- cvterm_id_column => 'cvterm_id',
- count_column => 'num_features',
- filter => "CNT.organism_id = $organism_id",
- label => 'Features',
- );
- return $options;
- }
- function tripal_feature_del_vocabulary() {
-
- module_load_include('inc', 'taxonomy', 'taxonomy.admin');
-
- $vocabularies = taxonomy_get_vocabularies();
-
-
-
-
-
- foreach ($vocabularies as $vocab) {
- if ($vocab->name == 'Feature Type') {
- taxonomy_vocabulary_delete($vocab->vid);
- }
- if ($vocab->name == 'Organism') {
- taxonomy_vocabulary_delete($vocab->vid);
- }
- if ($vocab->name == 'Library') {
- taxonomy_vocabulary_delete($vocab->vid);
- }
- if ($vocab->name == 'Analysis') {
- taxonomy_vocabulary_delete($vocab->vid);
- }
- }
- }
- function tripal_feature_return_fasta($feature, $desc) {
- $fasta = ">" . variable_get('chado_feature_accession_prefix', 'FID') . "$feature->feature_id|$feature->name";
- $fasta .= " $desc\n";
- $fasta .= wordwrap($feature->residues, 50, "\n", TRUE);
- $fasta .= "\n\n";
- return $fasta;
- }
- function tripal_feature_job_describe_args($callback, $args) {
- $new_args = array();
- if ($callback == 'tripal_feature_load_fasta') {
- $new_args['FASTA file'] = $args[0];
- $organism = tripal_core_chado_select('organism', array('genus', 'species'), array('organism_id' => $args[1]));
- $new_args['Organism'] = $organism[0]->genus . " " . $organism[0]->species;
- $new_args['Sequence Type'] = $args[2];
- $new_args['Name Match Type'] = $args[14];
- $new_args['Name RE'] = $args[4];
- $new_args['Unique Name RE'] = $args[5];
-
- $new_args['Relationship Type'] = $args[8];
- $new_args['Relationship Parent RE'] = $args[9];
- $new_args['Relationship Parent Type'] = $args[10];
-
- if ($args[7]) {
- $db = tripal_core_chado_select('db', array('name'), array('db_id' => $args[7]));
- }
- $new_args['Database Reference'] = $db[0]->name;
- $new_args['Accession RE'] = $args[6];
- $new_args['Method'] = $args[11];
-
- if ($args[13]) {
- $analysis = tripal_core_chado_select('analysis', array('name'), array('analysis_id' => $args[13]));
- }
- $new_args['Analysis'] = $analysis[0]->name;
- }
- if ($callback == 'tripal_feature_delete_features') {
- if ($args[0]) {
- $organism = tripal_core_chado_select('organism', array('genus', 'species'), array('organism_id' => $args[0]));
- $new_args['Organism'] = $organism[0]->genus . " " . $organism[0]->species;
- }
- else {
- $new_args['Organism'] = '';
- }
- if ($args[1]) {
- $analysis = tripal_core_chado_select('analysis', array('name'), array('analysis_id' => $args[1]));
- $new_args['Analysis'] = $analysis[0]->name;
- }
- else {
- $new_args['Analysis'] = '';
- }
- $new_args['Sequence Type'] = $args[2];
- $new_args['Is Unique Name'] = $args[3];
- $new_args['Features Names'] = $args[4];
- }
- elseif ($callback == 'tripal_feature_load_gff3') {
- $new_args['GFF File'] = $args[0];
- $organism = tripal_core_chado_select('organism', array('genus', 'species'), array('organism_id' => $args[1]));
- $new_args['Organism'] = $organism[0]->genus . " " . $organism[0]->species;
- $analysis = tripal_core_chado_select('analysis', array('name'), array('analysis_id' => $args[2]));
- $new_args['Analysis'] = $analysis[0]->name;
- $new_args['Use a Transaction'] = ($args[7] == 1) ? "Yes" : "No";
- $new_args['Import only new features'] = ($args[3] == 1) ? "Yes" : "No";
- $new_args['Import all and update'] = ($args[4] == 1) ? "Yes" : "No";
- $new_args['Import all and replace'] = ($args[5] == 1) ? "Yes" : "No";
- $new_args['Delete features'] = ($args[6] == 1) ? "Yes" : "No";
- $target_organism = tripal_core_chado_select('organism', array('genus', 'species'), array('organism_id' => $args[8]));
- $new_args['Target organism'] = $target_organism[0]->genus . " " . $target_organism[0]->species;
- $new_args['Target type'] = $args[9];
- $new_args['Create target'] = ($args[10] == 1) ? "Yes" : "No";
- $new_args['Starting line'] = $args[11];
- $new_args['Landmark Type'] = $args[12];
- $new_args['Alternate ID attribute'] = $args[13];
- $new_args['Create Organism'] = ($args[14] == 1) ? "Yes" : "No";
- }
- if ($callback == 'tripal_feature_sync_features') {
- if ($args[0]) {
- $organism = tripal_core_chado_select('organism', array('genus', 'species'), array('organism_id' => $args[0]));
- $new_args['Organism'] = $organism[0]->genus . " " . $organism[0]->species;
- }
- else {
- $new_args['Organism'] = '';
- }
- $new_args['Feature Types'] = $args[1];
- }
- return $new_args;
- }
- function tripal_feature_coder_ignore() {
- return array(
- 'path' => drupal_get_path('module', 'tripal_feature'),
- 'line prefix' => drupal_get_path('module', 'tripal_feature'),
- );
- }
- function tripal_feature_match_features_page($id) {
-
-
-
- $url_alias = variable_get('chado_feature_url_string', '/feature/[genus]/[species]/[type]/[uniquename]');
- if (!$url_alias) {
- $url_alias = '/feature/[genus]/[species]/[type]/[uniquename]';
- }
- $url_alias = preg_replace('/^\//', '', $url_alias);
- if (preg_match('/^feature\//', $url_alias)) {
- drupal_goto($id);
- }
- $sql = "
- SELECT
- F.name, F.uniquename, F.feature_id,
- O.genus, O.species, O.organism_id,
- CVT.cvterm_id, CVT.name as type_name,
- CF.nid,
- array_agg(S.name) as synonyms
- FROM {feature} F
- INNER JOIN {organism} O on F.organism_id = O.organism_id
- INNER JOIN {cvterm} CVT on CVT.cvterm_id = F.type_id
- LEFT JOIN {feature_synonym} FS on FS.feature_id = F.feature_id
- LEFT JOIN {synonym} S on S.synonym_id = FS.synonym_id
- INNER JOIN public.chado_feature CF on CF.feature_id = F.feature_id
- WHERE
- F.uniquename = :uname or
- F.name = :fname' or
- S.name = :sname
- GROUP BY F.name, F.uniquename, F.feature_id, O.genus, O.species,
- O.organism_id, CVT.cvterm_id, CVT.name, CF.nid
- ";
- $results = chado_query($sql, array(':uname' => $id, ':fname' => $id, ':sname' => $id));
- $num_matches = 0;
-
- $header = array('Uniquename', 'Name', 'Type', 'Species', 'Synonyms');
- $rows = array();
- $curr_match;
- while ($match = $results->fetchObject()) {
- $curr_match = $match;
- $synonyms = $match->synonyms;
- $synonyms = preg_replace('/[\"\{\}]/', '', $synonyms);
- $rows[] = array(
- $match->uniquename,
- "<a href=\"" . url("node/" . $match->nid) . "\">" . $match->name . "</a>",
- $match->type_name,
- '<i>' . $match->genus . ' ' . $match->species . '</i>',
- $synonyms,
- );
- $num_matches++;
- }
-
-
- if ($num_matches == 1) {
- drupal_goto("node/" . $curr_match->nid);
- }
- if ($num_matches == 0) {
- return "<p>No features matched the given name '$id'</p>";
- }
- $table_attrs = array(
- 'class' => 'tripal-table tripal-table-horz'
- );
- $output = "<p>The following features match the name '$id'.</p>";
- $output .= theme_table($header, $rows, $table_attrs, $caption);
- return $output;
- }
- function tripal_feature_form_alter(&$form, &$form_state, $form_id) {
- if ($form_id == "tripal_feature_seq_extract_form") {
-
-
-
- $form['#action'] = url("find/sequences");
- }
- }
|