123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178 |
- <?php
-
- require_once "tripal_feature.admin.inc";
- require_once "syncFeatures.php";
- require_once "indexFeatures.php";
- require_once "fasta_loader.php";
- require_once "gff_loader.php";
- require_once "tripal_feature.api.inc";
- require_once "tripal_feature-secondary_tables.inc";
- require_once "tripal_feature-properties.inc";
- require_once "tripal_feature-relationships.inc";
- require_once "tripal_feature-db_references.inc";
- function tripal_feature_init(){
-
- drupal_add_js (drupal_get_path('theme', 'tripal').'/js/tripal_feature.js');
- drupal_add_js (drupal_get_path('theme', 'tripal').'/js/jgcharts/jgcharts.js');
- drupal_add_css(drupal_get_path('theme', 'tripal').
- '/css/tripal_feature.css');
- }
-
- 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'),
- 'module' => '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_perm(){
- return array(
- 'access chado_feature content',
- 'create chado_feature content',
- 'delete chado_feature content',
- 'edit chado_feature content',
- 'manage chado_feature aggregator',
- );
- }
- function chado_feature_access($op, $node, $account) {
- if ($op == 'create') {
- return user_access('create chado_feature content', $account);
- }
- if ($op == 'update') {
- if (user_access('edit chado_feature content', $account)) {
- return TRUE;
- }
- }
- if ($op == 'delete') {
- if (user_access('delete chado_feature content', $account)) {
- return TRUE;
- }
- }
- if ($op == 'view') {
- if (user_access('access chado_feature content', $account)) {
- return TRUE;
- }
- }
- return FALSE;
- }
- function tripal_feature_menu() {
- $items = array();
-
- $items['admin/tripal/tripal_feature'] = array(
- 'title' => 'Features',
- 'description' => 'Basic Description of Tripal Organism Module Functionality',
- 'page callback' => 'tripal_feature_module_description_page',
- 'access arguments' => array('administer site configuration'),
- 'type' => MENU_NORMAL_ITEM,
- );
- $items['admin/tripal/tripal_feature/configuration'] = array(
- 'title' => 'Feature Configuration',
- 'description' => 'Settings for Chado Features',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_feature_admin'),
- 'access arguments' => array('administer site configuration'),
- 'type' => MENU_NORMAL_ITEM,
- );
- $items['admin/tripal/tripal_feature/fasta_loader'] = array(
- 'title' => 'Import a multi-FASTA file',
- '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 site configuration'),
- 'type' => MENU_NORMAL_ITEM,
- );
- $items['admin/tripal/tripal_feature/gff3_load'] = array(
- 'title' => 'Import a GFF3 file',
- 'description' => 'Import a GFF3 file into Chado',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_core_gff3_load_form'),
- 'access arguments' => array('access administration pages'),
- 'type' => MENU_NORMAL_ITEM,
- );
-
- $items['node/%tf_node/tf_properties'] = array(
- 'title' => t('Add Properties & Synonyms'),
- 'description' => t('Settings for Features'),
- 'page callback' => 'tripal_feature_add_ALL_property_page',
- 'page arguments' => array(1),
- 'access arguments' => array('create chado_feature content'),
- 'type' => MENU_CALLBACK
- );
- $items['node/%tf_node/tf_db_references'] = array(
- 'title' => t('Add Database References'),
- 'description' => t('Settings for Features'),
- 'page callback' => 'tripal_feature_add_ALL_dbreferences_page',
- 'page arguments' => array(1),
- 'access arguments' => array('create chado_feature content'),
- 'type' => MENU_CALLBACK
- );
- $items['node/%tf_node/tf_relationships'] = array(
- 'title' => t('Add Relationships'),
- 'description' => t('Settings for Features'),
- 'page callback' => 'tripal_feature_add_ALL_relationships_page',
- 'page arguments' => array(1),
- 'access arguments' => array('create chado_feature content'),
- 'type' => MENU_CALLBACK
- );
-
- $items['node/%tf_node/tf_edit_db_references'] = array(
- 'title' => t('Edit References'),
- 'description' => t('Settings for Feature'),
- 'page callback' => 'tripal_feature_edit_ALL_dbreferences_page',
- 'page arguments' => array(1),
- 'access arguments' => array('edit chado_feature content'),
- 'type' => MENU_LOCAL_TASK,
- 'weight' => 10,
- );
-
- $items['admin/tripal/tripal_feature/aggregate'] = array(
- 'title' => 'Feature Relationship Aggegators',
- 'description' => t('Features have relationships with other features and it may be desirable to aggregate the content from one ore more child or parent feature.'),
- 'page callback' => 'tripal_feature_aggregator_page',
- 'access arguments' => array('manage chado_feature aggregator'),
- 'type' => MENU_NORMAL_ITEM,
- );
- $items['admin/tripal/tripal_feature/aggregate/new'] = array(
- 'title' => 'Add an Aggregator',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_feature_aggregator_form'),
- 'access arguments' => array('manage chado_feature aggregator'),
- 'type' => MENU_NORMAL_ITEM,
- );
- $items['admin/tripal/tripal_feature/aggregate/edit/js'] = array(
- 'title' => 'Edit an Aggegator',
- 'page callback' => 'tripal_feature_aggregator_ajax_edit',
- 'access arguments' => array('manage chado_feature aggregator'),
- 'type' => MENU_CALLBACK,
- );
- return $items;
- }
- function tf_node_load($nid) {
- if (is_numeric($nid)) {
- $node = node_load($nid);
- if ($node->type == 'chado_feature') {
- return $node;
- }
- }
- return FALSE;
- }
- function tripal_feature_block($op = 'list', $delta = 0, $edit=array()){
- switch($op) {
- case 'list':
- $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['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['featureloc_sequences']['info'] = t('Tripal Formatted Location Sequence');
- $blocks['featureloc_sequences']['cache'] = BLOCK_NO_CACHE;
- $blocks['featurelocs_as_parent']['info'] = t('Tripal Feature Locations as Parent');
- $blocks['featurelocs_as_parent']['cache'] = BLOCK_NO_CACHE;
- $blocks['featurelocs_as_child']['info'] = t('Tripal Feature Locations as Child');
- $blocks['featurelocs_as_child']['cache'] = BLOCK_NO_CACHE;
- $blocks['relationships_as_object']['info'] = t('Tripal Feature Relationships as Object');
- $blocks['relationships_as_object']['cache'] = BLOCK_NO_CACHE;
- $blocks['relationships_as_subject']['info'] = t('Tripal Feature Relationships as Subject');
- $blocks['relationships_as_subject']['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;
- case 'view':
- 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 '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 'featurelocs_as_parent':
- $block['subject'] = t('Parent Features');
- $block['content'] = theme('tripal_feature_featurelocs_as_parent',$node);
- break;
- case 'featurelocs_as_child':
- $block['subject'] = t('Child Features');
- $block['content'] = theme('tripal_feature_featurelocs_as_child',$node);
- break;
- case 'relationships_as_object':
- $block['subject'] = t('Object Relationships');
- $block['content'] = theme('tripal_feature_relationships_as_object',$node);
- break;
- case 'relationships_as_subject':
- $block['subject'] = t('Subject Relationships');
- $block['content'] = theme('tripal_feature_relationships_as_child',$node);
- break;
- case 'org_feature_counts':
- $block['subject'] = t('Feature Type Summary');
- $block['content'] = theme('tripal_organism_feature_counts', $node);
- break;
- case 'org_feature_browser':
- $block['subject'] = t('Feature Browser');
- $block['content'] = theme('tripal_organism_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' => strlen($residues),
- 'is_obsolete' => $obsolete,
- 'type_id' => $type[0]->cvterm_id,
- 'md5checksum' => md5($residues)
- );
- $istatus = tripal_core_chado_insert('feature', $values);
- if (!$istatus) {
- drupal_set_message('Unable to add feature.', 'warning');
- watchdog('tripal_organism',
- '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 = '%s'";
- $node_check = db_fetch_object(db_query($node_check_sql,$feature[0]->feature_id));
- if(!$node_check){
-
- $sql = "INSERT INTO {chado_feature} (nid, vid, feature_id, sync_date) ".
- "VALUES (%d, %d, %d, " . time() . ")";
- db_query($sql,$node->nid,$node->vid,$feature[0]->feature_id);
- }
- }
- function chado_feature_update($node){
- if($node->revision){
-
- } else {
- $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) ;
- 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' => strlen($residues),
- 'is_obsolete' => $obsolete,
- 'type_id' => $type[0]->cvterm_id,
- 'md5checksum' => md5($residues)
- );
- $status = tripal_core_chado_update('feature', $match,$values);
-
- chado_feature_add_synonyms($node->synonyms,$feature_id);
- }
- else {
- drupal_set_message('Unable to update feature.', 'warning');
- watchdog('tripal_organism',
- '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);
-
- $sql_del = "DELETE FROM {chado_feature} ".
- "WHERE nid = %d ".
- "AND vid = %d";
- db_query($sql_del, $node->nid, $node->vid);
- $sql_del = "DELETE FROM {node} ".
- "WHERE nid = %d ".
- "AND vid = %d";
- db_query($sql_del, $node->nid, $node->vid);
- $sql_del = "DELETE FROM {node_revisions} ".
- "WHERE nid = %d ".
- "AND vid = %d";
- db_query($sql_del, $node->nid, $node->vid);
-
-
-
- $previous_db = tripal_db_set_active('chado');
- db_query("DELETE FROM {feature} WHERE feature_id = %d", $feature_id);
- tripal_db_set_active($previous_db);
-
- drupal_set_message("The feature and all associated data were removed from ".
- "chado");
- }
- function chado_feature_add_synonyms($synonyms,$feature_id){
-
- $synonyms = preg_replace("/[\s\n\r]+/"," ",$synonyms);
-
- $syn_array = array();
- $syn_array = explode(" ",$synonyms);
-
- $previous_db = tripal_db_set_active('chado');
-
- $feature_syn_dsql = "DELETE FROM {feature_synonym} WHERE feature_id = %d";
- if(!db_query($feature_syn_dsql,$feature_id)){
- $error .= "Could not remove synonyms from feature. ";
- }
-
- if(!$synonyms){
- tripal_db_set_active($previous_db);
- return;
- }
-
- foreach($syn_array as $syn){
-
- if(!$syn){ break; }
-
-
-
- $synonym_sql = "SELECT synonym_id FROM {synonym} ".
- "WHERE name = '%s'";
- $synonym = db_fetch_object(db_query($synonym_sql,$syn));
- if(!$synonym){
- $synonym_isql = "INSERT INTO {synonym} (name,synonym_sgml,type_id) ".
- "VALUES ('%s','%s', ".
- " (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(!db_query($synonym_isql,$syn,$syn)){
- $error .= "Could not add synonym. ";
- }
-
- $synonym_sql = "SELECT synonym_id FROM {synonym} ".
- "WHERE name = '%s'";
- $synonym = db_fetch_object(db_query($synonym_sql,$syn));
- }
-
- $feature_syn_isql = "INSERT INTO {feature_synonym} (synonym_id,feature_id,pub_id) ".
- "VALUES (%d,%d,1)";
- if(!db_query($feature_syn_isql,$synonym->synonym_id,$feature_id)){
- $error .= "Could not add synonyms to feature. ";
- }
- }
-
- tripal_db_set_active($previous_db);
- return $error;
- }
- function chado_feature_add_gbaccession($accession,$feature_id){
-
- $previous_db = tripal_db_set_active('chado');
-
- $fdbxref_dsql = "DELETE FROM {feature_dbxref} ".
- "WHERE feature_id = %d 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 = %d)";
- if(!db_query($fdbxref_dsql,$feature_id,$feature_id)){
- $error .= "Could not remove accession from feature. ";
- }
-
- if(!$accession){
- tripal_db_set_active($previous_db);
- return;
- }
-
- $db_sql = "SELECT db_id FROM {DB} ".
- "WHERE name = 'DB:Genbank_est'";
- $db = db_fetch_object(db_query($db_sql));
-
-
-
- $dbxref_sql = "SELECT dbxref_id FROM {dbxref} ".
- "WHERE db_id = %d and accession = '%s'";
- $dbxref = db_fetch_object(db_query($dbxref_sql,$db->db_id,$accession));
- if(!$dbxref){
-
- $dbxref_isql = "INSERT INTO {dbxref} (db_id,accession) ".
- " VALUES (%d, '%s') ";
- if(!db_query($dbxref_isql,$db->db_id,$accession)){
- $error .= 'Could not add accession as a database reference ';
- }
-
- $dbxref_sql = "SELECT dbxref_id FROM {dbxref} ".
- "WHERE db_id = %d and accession = '%s'";
- $dbxref = db_fetch_object(db_query($dbxref_sql,$db->db_id,$accession));
- }
-
- $feature_dbxref_isql = "INSERT INTO {feature_dbxref} (feature_id,dbxref_id) ".
- " VALUES (%d, %d) ";
- if(!db_query($feature_dbxref_isql,$feature_id,$dbxref->dbxref_id)){
- $error .= 'Could not add feature database reference. ';
- }
- tripal_db_set_active($previous_db);
- return $error;
- }
- function chado_feature_form ($node,$param){
- $type = node_get_types('type', $node);
- $form = array();
- $feature = $node->feature;
-
- $feature = tripal_core_expand_chado_vars($feature,'field','feature.residues');
-
-
- $synonyms = $node->synonyms;
- $feature = tripal_core_expand_chado_vars($feature,'table','feature_synonym');
- $feature_synonyms = $feature->feature_synonym;
- if(!$synonyms){
- if (!is_array($feature_synonyms)) {
- $synonyms = $feature_synonyms->synonym_id->name;
- }
- elseif(is_array($feature_synonyms)) {
- foreach($feature_synonyms as $index => $synonym){
- $synonyms .= $synonym->synonym_id->name ."\n";
- }
- }
- }
- $analyses = $node->analyses;
- $references = $node->references;
-
- $form['feature'] = array(
- '#type' => 'value',
- '#value' => $feature
- );
-
- $form['synonyms'] = array(
- '#type' => 'value',
- '#value' => $synonyms
- );
-
- $form['analyses'] = array(
- '#type' => 'value',
- '#value' => $analyses
- );
-
- $form['references'] = array(
- '#type' => 'value',
- '#value' => $references
- );
-
-
- $form['feature_id'] = array(
- '#type' => 'value',
- '#value' => $feature->feature_id,
- );
- $form['title']= array(
- '#type' => 'textfield',
- '#title' => t('Title'),
- '#required' => TRUE,
- '#default_value' => $node->title,
- '#description' => t('The title must be a unique identifier for this feature. It is recommended to use a combination of uniquename, organism and feature type in the title as this is guranteed to be unique.'),
- '#weight' => 1,
- '#maxlength' => 255
- );
- $form['uniquename']= array(
- '#type' => 'textfield',
- '#title' => t('Unique Feature Name'),
- '#required' => TRUE,
- '#default_value' => $feature->uniquename,
- '#description' => t('Enter a unique name for this feature. This name must be unique for the organism and feature type.'),
- '#weight' => 1,
- '#maxlength' => 255
- );
- $form['fname']= array(
- '#type' => 'textfield',
- '#title' => t('Feature Name'),
- '#required' => TRUE,
- '#default_value' => $feature->name,
- '#description' => t('Enter the name used by humans to refer to this feature.'),
- '#weight' => 1,
- '#maxlength' => 255
- );
-
- $ftypes = array();
- $ftypes[''] = '';
- $supported_ftypes = split("[ \n]",variable_get('chado_feature_types','EST contig'));
- foreach($supported_ftypes as $ftype){
- $ftypes["$ftype"] = $ftype;
- }
- $form['feature_type'] = array (
- '#title' => t('Feature Type'),
- '#type' => t('select'),
- '#description' => t("Choose the feature type."),
- '#required' => TRUE,
- '#default_value' => $feature->type_id->name,
- '#options' => $ftypes,
- '#weight' => 2
- );
-
- $sql = "SELECT * FROM {Organism} ORDER BY genus, species";
- $previous_db = tripal_db_set_active('chado');
- $org_rset = db_query($sql);
- tripal_db_set_active($previous_db);
-
- $organisms = array();
- $organisms[''] = '';
- while($organism = db_fetch_object($org_rset)){
- $organisms[$organism->organism_id] = "$organism->genus $organism->species ($organism->common_name)";
- }
- $form['organism_id'] = array (
- '#title' => t('Organism'),
- '#type' => t('select'),
- '#description' => t("Choose the organism with which this feature is associated "),
- '#required' => TRUE,
- '#default_value' => $feature->organism_id->organism_id,
- '#options' => $organisms,
- '#weight' => 3,
- );
-
- if ($synonyms) {
- if (is_array($synonyms)) {
- foreach ($synonyms as $synonym){
- $syn_text .= "$synonym->name\n";
- }
- } else {
- $syn_text = $synonyms;
- }
- }
- $form['synonyms']= array(
- '#type' => 'textarea',
- '#title' => t('Synonyms'),
- '#required' => FALSE,
- '#default_value' => $syn_text,
- '#description' => t('Enter alternate names (synonmys) for this feature to help in searching and identification. You may enter as many alternate names as needed separated by spaces or on different lines.'),
- '#weight' => 5,
- );
- $form['residues']= array(
- '#type' => 'textarea',
- '#title' => t('Residues'),
- '#required' => FALSE,
- '#default_value' => $feature->residues,
- '#description' => t('Enter the nucelotide sequences for this feature'),
- '#weight' => 6
- );
- $checked = '';
- if($feature->is_obsolete == 't'){
- $checked = '1';
- }
- $form['is_obsolete']= array(
- '#type' => 'checkbox',
- '#title' => t('Is Obsolete'),
- '#required' => FALSE,
- '#default_value' => $checked,
- '#description' => t('Check this box if this sequence should be retired and no longer included in further analysis.'),
- '#weight' => 8
- );
- return $form;
- }
- function chado_feature_validate($node){
- $result = 0;
-
-
-
- if($node->feature_id){
- $sql = "SELECT *
- FROM {Feature} F
- INNER JOIN {cvterm} CVT ON F.type_id = CVT.cvterm_id
- WHERE uniquename = '%s'
- AND organism_id = %d AND CVT.name = '%s' AND NOT feature_id = %d";
- $previous_db = tripal_db_set_active('chado');
- $result = db_fetch_object(db_query($sql, $node->uniquename,$node->organism_id,$node->feature_type,$node->feature_id));
- tripal_db_set_active($previous_db);
- if($result){
- form_set_error('uniquename',t("Feature update cannot proceed. The feature name '$node->uniquename' is not unique for this organism. Please provide a unique name for this feature. "));
- }
- }
-
-
- else {
- $sql = "SELECT *
- FROM {Feature} F
- INNER JOIN {cvterm} CVT ON F.type_id = CVT.cvterm_id
- WHERE uniquename = '%s'
- AND organism_id = %d AND CVT.name = '%s'";
- $previous_db = tripal_db_set_active('chado');
- $result = db_fetch_object(db_query($sql, $node->uniquename,$node->organism_id,$node->feature_type));
- tripal_db_set_active($previous_db);
- if($result){
- form_set_error('uniquename',t("Feature insert cannot proceed. The feature name '$node->uniquename' already exists for this organism. Please provide a unique name for this feature. "));
- }
- }
-
-
-
- if($node->residues){
- $residues = preg_replace("/[^\w]/",'',$node->residues);
- if(!preg_match("/^[ACTGURYMKSWBDHVN]+$/i",$residues)){
- form_set_error('residues',t("The residues in feature $node->name contains more than the nucleotide IUPAC characters. Only the following characters are allowed: A,C,T,G,U,R,Y,M,K,S,W,B,D,H,V,N: '" . $residues ."'"));
- }
- }
-
- if($node->feature_type == 'contig' and $node->gbaccession){
- form_set_error('gbaccession',t("Contigs cannot have a genbank accession number. Please change the feature type or remove the accession number"));
- }
- }
- function chado_feature_load($node){
-
- $feature_id = chado_get_id_for_node('feature',$node);
- $values = array('feature_id' => $feature_id);
- $feature = tripal_core_generate_chado_var('feature',$values);
- $additions->feature = $feature;
- return $additions;
- }
- function tripal_feature_load_organism ($organism_id){
-
- $sql = "SELECT * FROM {organism} WHERE organism_id = %d";
- $previous_db = tripal_db_set_active('chado');
- $organism = db_fetch_object(db_query($sql,$organism_id));
- tripal_db_set_active($previous_db);
- 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 = %d ".
- "ORDER BY S.name ";
- $previous_db = tripal_db_set_active('chado');
- $results = db_query($sql,$feature_id);
- tripal_db_set_active($previous_db);
- $synonyms = array();
- $i=0;
- while($synonym = db_fetch_object($results)){
- $synonyms[$i++] = $synonym;
- }
- return $synonyms;
- }
- function tripal_feature_load_properties ($feature_id){
- $sql = "SELECT CVT.name as cvname, FS.type_id, FS.value, FS.rank,
- CVT.definition, CVT.is_obsolete,
- 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 = %d
- ORDER BY FS.rank ASC";
- $previous_db = tripal_db_set_active('chado');
- $results = db_query($sql,$feature_id);
- tripal_db_set_active($previous_db);
- $i=0;
- $properties = array();
- while($property = db_fetch_object($results)){
- $properties[$i++] = $property;
- }
- return $properties;
- }
- function tripal_feature_load_references ($feature_id){
- $sql = "SELECT F.uniquename,F.Feature_id,DBX.accession,DB.description as dbdesc, ".
- " DB.db_id, DB.name as db_name, DB.urlprefix,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 = %d ".
- "ORDER BY DB.name ";
- $previous_db = tripal_db_set_active('chado');
- $results = db_query($sql,$feature_id);
- tripal_db_set_active($previous_db);
- $references = array();
- $i=0;
- while($accession = db_fetch_object($results)){
- $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 = %d ";
- }
- if(strcmp($side,'as_child')==0){
- $sql .= "WHERE FL.feature_id = %d ";
- }
- $previous_db = tripal_db_set_active('chado');
- $flresults = db_query($sql, $feature_id);
- tripal_db_set_active($previous_db);
-
- $i=0;
- $featurelocs = array();
- while($loc = db_fetch_object($flresults)){
-
-
- $sql = 'SELECT nid FROM {chado_feature} WHERE feature_id = %d';
- $ffeature = db_fetch_object(db_query($sql, $loc->feature_id));
- $sfeature = db_fetch_object(db_query($sql, $loc->src_feature_id));
- $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,
- 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,
- FR.object_id,
- FR.rank
- 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 = %d";
- }
- if(strcmp($side,'as_subject')==0){
- $sql .= " WHERE FR.subject_id = %d";
- }
- $sql .= " ORDER BY FR.rank";
-
- $previous_db = tripal_db_set_active('chado');
- $results = db_query($sql, $feature_id);
- tripal_db_set_active($previous_db);
-
-
- $i=0;
- $nodesql = "SELECT nid FROM {chado_feature} WHERE feature_id = %d";
- $relationships = array();
- while($rel = db_fetch_object($results)){
- $node = db_fetch_object(db_query($nodesql,$rel->subject_id));
- if($node){
- $rel->subject_nid = $node->nid;
- }
- $node = db_fetch_object(db_query($nodesql,$rel->object_id));
- if($node){
- $rel->object_nid = $node->nid;
- }
- $relationships[$i++] = $rel;
- }
- return $relationships;
- }
- function tripal_feature_get_aggregate_types($feature_id){
-
- $sql = 'SELECT type_id FROM {feature} WHERE feature_id = %d';
- $previous_db = tripal_db_set_active('chado');
- $feature = db_fetch_object(db_query($sql, $feature_id));
- tripal_db_set_active($previous_db);
-
- $sql = "SELECT * FROM {tripal_feature_relagg} WHERE type_id = %d";
- $types = array();
- $results = db_query($sql,$feature->type_id);
- while($agg = db_fetch_object($results)){
- $types[] = $agg->rel_type_id;
- }
-
- return $types;
- }
- 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;
- }
-
- $relationships = tripal_feature_load_relationships($feature_id,'as_object');
-
-
- $i=0;
- $new_relationships = array();
- foreach($relationships as $rindex => $rel){
-
- if(!$base_type_id){
- $base_type_id = $rel->object_type_id;
- }
-
- $sql = "SELECT * FROM {tripal_feature_relagg} WHERE type_id = %d and rel_type_id = %d";
- $agg = db_fetch_object(db_query($sql,$base_type_id,$rel->subject_type_id));
- if($agg){
-
-
- if(!$substitute){
- $new_relationships[$i++] = $rel;
- }
-
- $agg_relationships = tripal_feature_get_aggregate_relationships(
- $rel->subject_id,$levels,$base_type_id,$depth++);
-
-
- if(!$agg_relationships and $substitute){
- $new_relationships[$i++] = $rel;
- }
-
- foreach($agg_relationships as $aindex => $arel){
- $new_relationships[$i++] = $arel;
- }
- }
- else {
-
- $new_relationships[$i++] = $rel;
- }
- }
- return $new_relationships;
- }
- 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->$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;
- $rel_locs[$src]['parts'][$start]['type'] = $rel->subject_type;
- $rel_locs[$src]['parts'][$start]['start'] = $start;
- $rel_locs[$src]['parts'][$start]['end'] = $end;
- }
- }
-
-
-
-
- $sql = "SELECT residues FROM {feature} WHERE feature_id = %d";
- $floc_sequences = array();
- foreach ($featurelocs as $featureloc){
-
- $previous_db = tripal_db_set_active('chado');
- $feature = db_fetch_object(db_query($sql,$featureloc->srcfeature_id->feature_id));
- tripal_db_set_active($previous_db);
- $src = $featureloc->srcfeature_id->feature_id ."-". $featureloc->srcfeature_id->type_id->cvterm_id;
-
- $parts = $rel_locs[$src]['parts'];
- usort($parts, 'tripal_feature_sort_rel_parts');
- foreach ($parts as $start => $attrs){
- $parts[$start]['start'] = $parts[$start]['start'] - $featureloc->fmin;
- $parts[$start]['end'] = $parts[$start]['end'] - $featureloc->fmin;
- }
- $floc_sequences[$src]['src'] = $src;
- $floc_sequences[$src]['type'] = $featureloc->feature_id->type_id->name;
- $sequence = substr($feature->residues,$featureloc->fmin-1,($featureloc->fmax - $featureloc->fmin)+1);
- $floc_sequences[$src]['formatted_seq'] = tripal_feature_color_sequence (
- $sequence,$parts);
- }
- return $floc_sequences;
- }
- 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 );
- }
-
-
- $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 organism_id = %d
- ORDER BY num_features desc
- ";
- $previous_db = tripal_db_set_active('chado');
- $org_features = db_query($sql,$organism->organism_id);
- tripal_db_set_active($previous_db);
- $i=0;
- $types = array();
- while($type = db_fetch_object($org_features)){
- $types[$i++] = $type;
- }
- return array ( 'types' => $types, 'enabled' => true );
- }
- function tripal_feature_load_organism_feature_browser($organism){
-
-
- $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_feature_types','EST contig');
- $allowed_types = preg_replace("/[\s\n\r]+/"," ",$allowed_types);
- $so_terms = split(' ',$allowed_types);
- $where_cvt = "";
- foreach ($so_terms as $term){
- $where_cvt .= "CVT.name = '$term' OR ";
- }
- $where_cvt = substr($where_cvt,0,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 ".
- "WHERE organism_id = %s and ($where_cvt) ".
- "ORDER BY feature_id ASC";
-
- $csql = "SELECT count(*) ".
- "FROM {feature} F".
- " INNER JOIN {cvterm} CVT on F.type_id = CVT.cvterm_id ".
- "WHERE organism_id = %s and ($where_cvt) ".
- "GROUP BY organism_id ";
- $previous_db = tripal_db_set_active('chado');
- $org_features = pager_query($sql,10,0,$csql,$organism->organism_id);
- tripal_db_set_active($previous_db);
- $pager = theme('pager');
-
- $sql = "SELECT nid FROM {chado_feature} ".
- "WHERE feature_id = %d";
- $i=0;
- $features = array();
- while($feature = db_fetch_object($org_features)){
- $node = db_fetch_object(db_query($sql,$feature->feature_id));
- $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($a,$b){
- return strnatcmp($a['start'], $b['start']);
- }
- function tripal_feature_color_sequence ($sequence,$parts){
- $types = array();
-
- foreach ($parts as $index => $child){
- $type = $child['type'];
- if(!in_array($type,$types)){
- $types[] = $type;
- }
- }
-
- $newseq .= "<div id=\"tripal_feature-featureloc_sequence-legend\">Legend: ";
- foreach($types as $type){
- $newseq .= "<span class=\"tripal_feature-featureloc_sequence-$type\">$type</span>";
- }
- $newseq .= "</div>";
-
-
- $pos = 0;
- $newseq .= "<pre id=\"tripal_feature-featureloc_sequence\">";
- foreach ($parts as $index => $child){
- $type = $child['type'];
- $start = $child['start'];
- $end = $child['end']+1;
-
- $class = "class=\"tripal_feature-featureloc_sequence-$type\"";
-
- for ($i = $pos; $i < $end; $i++){
-
-
-
- if($pos == $start){
- $newseq .= "<span $class>";
- $func = 'uc';
- }
- $newseq .= $sequence{$pos};
- $seqcount++;
- if($seqcount % 60 == 0){
- $newseq .= "\n";
- }
- $pos++;
- if($pos == $end){
- $newseq .= "</span>";
- $func = 'lc';
- }
- }
- }
- $newseq .= "</pre>";
- return $newseq;
- }
- function chado_feature_view ($node, $teaser = FALSE, $page = FALSE) {
- if (!$teaser) {
-
- $node = node_prepare($node, $teaser);
-
-
-
-
- if($node->build_mode == NODE_BUILD_SEARCH_INDEX){
- $node->content['index_version'] = array(
- '#value' => theme('tripal_feature_search_index',$node),
- '#weight' => 1,
- );
- }
- elseif($node->build_mode == NODE_BUILD_SEARCH_RESULT){
- $node->content['index_version'] = array(
- '#value' => theme('tripal_feature_search_results',$node),
- '#weight' => 1,
- );
- }
- else {
-
- }
- }
- return $node;
- }
- function tripal_feature_nodeapi(&$node, $op, $teaser, $page) {
- switch ($op) {
-
-
- case 'view':
- switch($node->type){
- case 'chado_organism':
-
- $types_to_show = array('chado_organism', 'chado_library');
- if (in_array($node->type, $types_to_show, TRUE)) {
- $node->content['tripal_organism_feature_counts'] = array(
- '#value' => theme('tripal_organism_feature_counts', $node),
- );
- $node->content['tripal_organism_feature_browser'] = array(
- '#value' => theme('tripal_organism_feature_browser', $node),
- );
- }
- break;
- case 'chado_library':
- break;
- default:
- }
- break;
- }
- }
- function tripal_feature_theme () {
- return array(
- 'tripal_feature_search_index' => array (
- 'arguments' => array('node'),
- ),
- 'tripal_feature_search_results' => array (
- 'arguments' => array('node'),
- ),
- 'tripal_organism_feature_browser' => array (
- 'arguments' => array('node'=> null),
- 'template' => 'tripal_organism_feature_browser',
- ),
- 'tripal_organism_feature_counts' => array (
- 'arguments' => array('node'=> null),
- 'template' => 'tripal_organism_feature_counts',
- ),
- 'tripal_feature_base' => array (
- 'arguments' => array('node'=> null),
- 'template' => 'tripal_feature_base',
- ),
- 'tripal_feature_sequence' => array (
- 'arguments' => array('node'=> null),
- 'template' => 'tripal_feature_sequence',
- ),
- 'tripal_feature_synonyms' => array (
- 'arguments' => array('node'=> null),
- 'template' => 'tripal_feature_synonyms',
- ),
- 'tripal_feature_featureloc_sequences' => array (
- 'arguments' => array('node'=> null),
- 'template' => 'tripal_feature_featureloc_sequences',
- ),
- 'tripal_feature_references' => array (
- 'arguments' => array('node'=> null),
- 'template' => 'tripal_feature_references',
- ),
- 'tripal_feature_properties' => array (
- 'arguments' => array('node'=> null),
- 'template' => 'tripal_feature_properties',
- ),
- 'tripal_feature_featurelocs_as_parent' => array (
- 'arguments' => array('node'=> null),
- 'template' => 'tripal_feature_featurelocs_as_parent',
- ),
- 'tripal_feature_featurelocs_as_child' => array (
- 'arguments' => array('node'=> null),
- 'template' => 'tripal_feature_featurelocs_as_child',
- ),
- 'tripal_feature_relationships_as_object' => array (
- 'arguments' => array('node'=> null),
- 'template' => 'tripal_feature_relationships_as_object',
- ),
- 'tripal_feature_relationships_as_subject' => array (
- 'arguments' => array('node'=> null),
- 'template' => 'tripal_feature_relationships_as_subject',
- ),
- );
- }
- function tripal_feature_preprocess_tripal_organism_feature_counts(&$variables){
- $organism = $variables['node']->organism;
- $variables['tripal_feature']['feature_counts'] = tripal_feature_load_organism_feature_counts($organism);
- }
- function tripal_feature_preprocess_tripal_organism_feature_browser(&$variables){
- $organism = $variables['node']->organism;
- $variables['tripal_feature']['browser'] = tripal_feature_load_organism_feature_browser($organism);
- }
- function tripal_feature_cv_chart($chart_id){
-
-
-
-
-
- $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 => "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 theme_tripal_feature_search_index ($node) {
- $feature = $node->feature;
- $content = '';
-
- $aprefix = variable_get('chado_feature_accession_prefix','ID');
- $content .= "<h1>$feature->uniquename</h1>. ";
- $content .= "<strong>$aprefix$feature->feature_id.</strong> ";
- $content .= "$feature->cvname ";
- $content .= "$feature->common_name ";
-
- $synonyms = $node->synonyms;
- if(count($synonyms) > 0){
- foreach ($synonyms as $result){
- $content .= "$result->name ";
- }
- }
- return $content;
- }
- function theme_tripal_feature_search_results ($node) {
- $feature = $node->feature;
- $content = '';
-
- $aprefix = variable_get('chado_feature_accession_prefix','ID');
- $content .= "Feature Name: <h1>$feature->uniquename</h1>. ";
- $content .= "<strong>Accession: $aprefix$feature->feature_id.</strong>";
- $content .= "Type: $feature->cvname. ";
- $content .= "Organism: $feature->common_name. ";
-
- $synonyms = $node->synonyms;
- if(count($synonyms) > 0){
- $content .= "Synonyms: ";
- foreach ($synonyms as $result){
- $content .= "$result->name, ";
- }
- }
- return $content;
- }
- function tripal_feature_set_vocabulary (){
-
- module_load_include('inc', 'taxonomy', 'taxonomy.admin');
-
-
- $vocabularies = taxonomy_get_vocabularies();
- $ft_vid = NULL;
- $op_vid = NULL;
- $lb_vid = NULL;
- $an_vid = NULL;
-
-
-
-
-
- foreach($vocabularies as $vocab){
- if($vocab->name == 'Feature Type'){
- $ft_vid = $vocab->vid;
- }
- if($vocab->name == 'Organism'){
- $op_vid = $vocab->vid;
- }
- if($vocab->name == 'Library'){
- $lb_vid = $vocab->vid;
- }
- if($vocab->name == 'Analysis'){
- $an_vid = $vocab->vid;
- }
- }
- if(!$ft_vid){
- $form_state = array();
- $values = array(
- 'name' => t('Feature Type'),
- 'nodes' => array('chado_feature' => 'chado_feature'),
- 'description' => t('The feature type (or SO cvterm for this feature).'),
- 'help' => t('Select the term that matches the feature '),
- 'tags' => 0,
- 'hierarchy' => 1,
- 'relations' => 1,
- 'multiple' => 0,
- 'required' => 0,
- 'weight' => 1,
- );
- drupal_execute('taxonomy_form_vocabulary', $form_state,$values);
- drupal_execute('taxonomy_form_vocabulary', $form_state);
- }
- if(!$op_vid){
- $form_state = array();
- $values = array(
- 'name' => t('Organism'),
- 'nodes' => array('chado_feature' => 'chado_feature'),
- 'description' => t('The organism to which this feature belongs.'),
- 'help' => t('Select the term that matches the feature '),
- 'tags' => 0,
- 'hierarchy' => 1,
- 'relations' => 1,
- 'multiple' => 0,
- 'required' => 0,
- 'weight' => 2,
- );
- drupal_execute('taxonomy_form_vocabulary', $form_state,$values);
- drupal_execute('taxonomy_form_vocabulary', $form_state);
- }
- if(!$lb_vid){
- $form_state = array();
- $values = array(
- 'name' => t('Library'),
- 'nodes' => array('chado_feature' => 'chado_feature'),
- 'description' => t('Chado features associated with a library are assigned the term associated with the library'),
- 'help' => t('Select the term that matches the feature '),
- 'tags' => 0,
- 'hierarchy' => 1,
- 'relations' => 1,
- 'multiple' => 0,
- 'required' => 0,
- 'weight' => 3,
- );
- drupal_execute('taxonomy_form_vocabulary', $form_state, $values);
- drupal_execute('taxonomy_form_vocabulary', $form_state);
- }
- if(!$an_vid){
- $form_state = array();
- $values = array(
- 'name' => t('Analysis'),
- 'nodes' => array('chado_feature' => 'chado_feature'),
- 'description' => t('Any analysis to which this feature belongs.'),
- 'help' => t('Select the term that matches the feature '),
- 'tags' => 0,
- 'hierarchy' => 1,
- 'relations' => 1,
- 'multiple' => 1,
- 'required' => 0,
- 'weight' => 4,
- );
- drupal_execute('taxonomy_form_vocabulary', $form_state,$values);
- drupal_execute('taxonomy_form_vocabulary', $form_state);
- }
- }
- 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_del_vocabulary($vocab->vid);
- }
- if($vocab->name == 'Organism'){
- taxonomy_del_vocabulary($vocab->vid);
- }
- if($vocab->name == 'Library'){
- taxonomy_del_vocabulary($vocab->vid);
- }
- if($vocab->name == 'Analysis'){
- taxonomy_del_vocabulary($vocab->vid);
- }
- }
- }
- function tripal_features_set_taxonomy($max_sync = 0,$job_id = NULL){
-
- tripal_feature_del_vocabulary();
- tripal_feature_set_vocabulary();
-
- $results = db_query("SELECT * FROM {chado_feature}");
- $nsql = "SELECT * FROM {node} ".
- "WHERE nid = %d";
- $i = 0;
-
- $count = 0;
- $chado_features = array();
- while($chado_feature = db_fetch_object($results)){
- $chado_features[$count] = $chado_feature;
- $count++;
- }
-
- $interval = intval($count * 0.01);
- foreach($chado_features as $chado_feature){
-
- if($job_id and $i % $interval == 0){
- tripal_job_set_progress($job_id,intval(($i/$count)*100));
- }
- $node = db_fetch_object(db_query($nsql,$chado_feature->nid));
- tripal_feature_set_taxonomy($node,$chado_feature->feature_id);
- $i++;
- }
- }
- function tripal_feature_set_taxonomy ($node,$feature_id){
-
-
- $tax_classes = variable_get('tax_classes', '');
- $do_ft = 0;
- $do_op = 0;
- $do_lb = 0;
- $do_an = 0;
- foreach($tax_classes as $class){
- if(strcmp($class ,'organism')==0){
- $do_op = 1;
- }
- if(strcmp($class,'feature_type')==0){
- $do_ft = 1;
- }
- if(strcmp($class,'library')==0){
- $do_lb = 1;
- }
- if(strcmp($class,'analysis')==0){
- $do_an = 1;
- }
- }
-
- $vocabularies = taxonomy_get_vocabularies();
- $ft_vid = NULL;
- $op_vid = NULL;
- $lb_vid = NULL;
- $an_vid = NULL;
- foreach($vocabularies as $vocab){
- if($vocab->name == 'Feature Type'){
- $ft_vid = $vocab->vid;
- }
- if($vocab->name == 'Organism'){
- $op_vid = $vocab->vid;
- }
- if($vocab->name == 'Library'){
- $lb_vid = $vocab->vid;
- }
- if($vocab->name == 'Analysis'){
- $an_vid = $vocab->vid;
- }
- }
-
- $sql = "SELECT CVT.name AS cvname, O.genus, O.species ".
- "FROM {CVTerm} CVT ".
- " INNER JOIN Feature F on F.type_id = CVT.cvterm_id ".
- " INNER JOIN Organism O ON F.organism_id = O.organism_id ".
- "WHERE F.feature_id = $feature_id";
- $previous_db = tripal_db_set_active('chado');
- $feature = db_fetch_object(db_query($sql));
- tripal_db_set_active($previous_db);
-
- if($do_ft && $ft_vid){
- $tags["$ft_vid"] = "$feature->cvname";
- }
-
- if($do_op && $op_vid){
- $tags["$op_vid"] = "$feature->genus $feature->species";
- }
-
- if($do_lb && $lb_vid){
- $sql = "SELECT L.name ".
- "FROM {Library} L ".
- " INNER JOIN Library_feature LF ON LF.library_id = L.library_id ".
- "WHERE LF.feature_id = %d ";
- $previous_db = tripal_db_set_active('chado');
- $library = db_fetch_object(db_query($sql,$feature_id));
- tripal_db_set_active($previous_db);
- $tags["$lb_vid"] = "$library->name";
- }
-
- $terms['tags'] = $tags;
- taxonomy_node_save($node,$terms);
-
-
-
- if($do_an && $an_vid){
- $sql = "SELECT A.name ".
- "FROM {Analysis} A ".
- " INNER JOIN Analysisfeature AF ON AF.analysis_id = A.analysis_id ".
- "WHERE AF.feature_id = $feature_id ";
- $results = db_query($sql);
- $previous_db = tripal_db_set_active('chado');
- $analysis_terms = array();
- while($analysis=db_fetch_object($results)){
- $tags2["$an_vid"] = "$analysis->name";
- $terms['tags'] = $tags2;
- taxonomy_node_save($node,$terms);
- }
- tripal_db_set_active($previous_db);
- }
- }
- function tripal_features_cleanup($dummy = NULL, $job_id = NULL) {
-
- $dsql = "SELECT * FROM {node} WHERE type = 'chado_feature' order by nid";
- $nsql = "SELECT * FROM {node} WHERE nid = %d";
- $csql = "SELECT * FROM {chado_feature} where nid = %d ";
- $cfsql= "SELECT * FROM {chado_feature}";
- $tsql = "SELECT * FROM {feature} F ".
- " INNER JOIN CVTerm CVT ON F.type_id = CVT.cvterm_id ".
- "WHERE feature_id = %d AND (";
- $supported_ftypes = split("[ \n]",variable_get('chado_feature_types','EST contig'));
- foreach($supported_ftypes as $ftype){
- $tsql .= " CVT.name = '$ftype' OR ";
- }
- $tsql .= " 0=1) ";
-
- $results = db_query($dsql);
- $count = 0;
- $nodes = array();
- while($node = db_fetch_object($results)){
- $nodes[$count] = $node;
- $count++;
- }
-
- $results = db_query($cfsql);
- $cnodes = array();
- while($node = db_fetch_object($results)){
- $cnodes[$count] = $node;
- $count++;
- }
- $interval = intval($count * 0.01);
-
- foreach($nodes as $nid){
-
- if($job_id and $i % $interval == 0){
- tripal_job_set_progress($job_id,intval(($i/$count)*100));
- }
-
-
- $feature = db_fetch_object(db_query($csql,$nid->nid));
- if(!$feature){
- node_delete($nid->nid);
- $message = "Missing in chado_feature table.... DELETING: $nid->nid\n";
- watchdog('tripal_feature',$message,array(),WATCHDOG_WARNING);
- continue;
- }
-
-
-
-
- $previous_db = tripal_db_set_active('chado');
- $ftype = db_fetch_object(db_query($tsql,$feature->feature_id));
- tripal_db_set_active($previous_db);
- if(!$ftype){
- node_delete($nid->nid);
- db_query("DELETE FROM {chado_feature} WHERE feature_id = $feature->feature_id");
- $message = "Node of the wrong feature type.... DELETING: $nid->nid\n";
- watchdog('tripal_feature',$message,array(),WATCHDOG_WARNING);
- }
- $i++;
- }
-
- foreach($cnodes as $nid){
-
- if($job_id and $i % $interval == 0){
- tripal_job_set_progress($job_id,intval(($i/$count)*100));
- }
- $node = db_fetch_object(db_query($nsql,$nid->nid));
- if(!$node){
- db_query("DELETE FROM {chado_feature} WHERE nid = $nid->nid");
- $message = "chado_feature missing node.... DELETING: $nid->nid\n";
- watchdog('tripal_feature',$message,array(),WATCHDOG_WARNING);
- }
- $i++;
- }
- return '';
- }
- function tripal_feature_return_fasta($feature,$desc){
- $fasta = ">" . variable_get('chado_feature_accession_prefix','ID') . "$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 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];
- if($args[11]){
- $new_args['Update and Insert'] = 'Yes';
- }
- else {
- $new_args['Insert Only New Features'] = 'Yes';
- }
-
- if($args[13]){
- $analysis = tripal_core_chado_select('analysis',array('name'),array('analysis_id' => $args[13]));
- }
- $new_args['Analysis'] = $analysis[0]->name;
- }
- return $new_args;
- }
|