| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162 | <?phpfunction tripal_chado_install() {//   // The foreign key specification doesn't really add one to the//   // Drupal schema, it is just used internally, but we want one.//   db_query('//       ALTER TABLE {tripal_custom_tables}//       ADD CONSTRAINT tripal_custom_tables_fk1//       FOREIGN KEY (mview_id) REFERENCES {tripal_mviews} (mview_id)//       ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED//   ');  if (chado_is_installed()) {    // For an upgraded site we need to move some vocabulary terms over    // to the new 'local' vocabulary:    tripal_insert_db(array(      'name' => 'local',      'description' => variable_get('site_name', 'This site.'),    ));    // Move the library properties out of the tripal database and into the    // local database.    $sql = "      UPDATE {dbxref}        SET db_id = (SELECT db_id FROM {db} WHERE name = 'local')      WHERE dbxref_id IN (        SELECT DISTINCT CVT.dbxref_id        FROM {cvterm} CVT          INNER JOIN {cv} CV ON CV.cv_id = CVT.cv_id        WHERE CV.name IN (          'library_property',          'library_type',          'project_property',          'nd_experiment_types',          'nd_geolocation_property',          'tripal_analysis'        )      )    ";    chado_query($sql);  }}/** * Implementation of hook_uninstall(). * * @ingroup tripal */function tripal_chado_uninstall() {//   // Drop the foreign key between tripal_custom_tables and tripal_mviews//   // so that Drupal can then drop the tables//   db_query('//     ALTER TABLE {tripal_custom_tables}//     DROP CONSTRAINT tripal_custom_tables_fk1 CASCADE//   ');  variable_set('tripal_chado_is_prepared', FALSE);}function tripal_chado_chado_semweb_schema(){  return array(    'fields' => array(      'chado_semweb_id' => array(        'type' => 'serial',        'not null' => TRUE      ),      'chado_table' => array(        'type' => 'varchar',        'length ' => 128,        'not null' => TRUE      ),      'chado_column' => array(        'type' => 'text',        'length ' => 128,        'not null' => TRUE      ),      'cvterm_id' => array(        'type' => 'int',      ),    ),    'primary key' => array(      0 => 'chado_semweb_id',    ),    'indexes' => array(      'chado_semweb_id_idx1' => array('cvterm_id'),      'chado_semweb_id_idx2' => array('chado_column'),      'chado_semweb_id_idx3' => array('chado_table'),    ),    'unique keys' => array(      'chado_semweb_uq1' => array('chado_table', 'chado_column'),    ),  );}/** * Table definition for the tripal_cv_obo table * @param $schema */function tripal_chado_tripal_cv_obo_schema() {  return array(    'fields' => array(      'obo_id' => array(        'type' => 'serial',        'unsigned' => TRUE,        'not null' => TRUE      ),      'name' => array(        'type' => 'varchar',        'length' => 255      ),      'path'  => array(        'type' => 'varchar',        'length' => 1024      ),    ),    'indexes' => array(      'tripal_cv_obo_idx1' => array('obo_id'),    ),    'primary key' => array('obo_id'),  );}/** * */function tripal_chado_enable() {  // If Tripal v2 is already installed, then when the module is first enabled  // after an upgade, the installation of this module will try and recreate  // some of the tables created with tripal_core and the installation will fail.  // Therefore, the tables were temporarily moved out of the way to preserve  // the data. Now we'll move them back.  tripal_chado_upgrade_v2_v3_enable();}/** * Implements hook_schema(). */function tripal_chado_schema() {  // If Tripal v2 is already installed, then when the module is first enabled  // after an upgade, the installation of this module will try and recreate  // some of the tables created with tripal_core and the installation will fail.  // Therefore, we need to temporarily move those tables out of the way, let  // the module install and then move them back.  $migrated = variable_get('tripal_v2_upgrade_v3_check_chado', FALSE);  if (!$migrated) {    try {      tripal_chado_upgrade_v2_v3_pre_enable();      variable_set('tripal_v2_upgrade_v3_check_chado', TRUE);    }    catch(Exception $e) {      watchdog_exception('tripal_chado', $e);    }  }  // Links TripalEntity entities to the chado record.  $schema['chado_bundle'] = tripal_chado_chado_bundle_schema();  $schema['chado_semweb'] = tripal_chado_chado_semweb_schema();  $schema['tripal_mviews'] = tripal_chado_tripal_mviews_schema();  $schema['tripal_custom_tables'] = tripal_chado_tripal_custom_tables_schema();  $schema['tripal_cv_obo'] = tripal_chado_tripal_cv_obo_schema();  $schema['tripal_pub_import'] = tripal_chado_tripal_pub_import_schema();  // if this module is already installed and enabled, then we want to provide  // the schemas for all of the custom tables.  This will allow Views to  // see the schemas.  We check if the module is installed because during  // installation we don't want to make these custom tables available as we don't  // want them created in the Drupal database.  The custom tables go in the  // Chado database.  if (db_table_exists('tripal_custom_tables')) {    $sql = 'SELECT * FROM {tripal_custom_tables}';    $results = db_query($sql);    foreach ($results as $custom) {      $schema[$custom->table_name] = unserialize($custom->schema);    }  }  // Map cvterm usage to chado tables  $schema['chado_cvterm_mapping'] = tripal_chado_chado_cvterm_mapping_schema();  // When a chado Tripal content type is created, a linking table is also created to  // link the entity to it's record in chado (@see tripal_chado_bundle_create() ).  // This table is created via db_create_table() but in order to expose it to  // the Drupal Schema API, we also need to define each one here.  if (db_table_exists('chado_bundle')) {    $resource = db_query('SELECT tb.name FROM chado_bundle cb LEFT JOIN tripal_bundle tb ON tb.id=cb.bundle_id');    foreach ($resource as $r) {      $bundle_name = $r->name;      // This makes an assumption about the name of the linking table.      // @todo: Switch to chado_get_bundle_entity_table($bundle).      $chado_entity_table = 'chado_' . $bundle_name;      $schema[$chado_entity_table] = array(        'description' => 'The linker table that associates TripalEntities with Chado records for entities of type ' . $bundle_name . '.',        'fields' => array(          'mapping_id' => array(            'type' => 'serial',            'not null' => TRUE          ),          'entity_id' => array(            'description' => 'The unique entity id.',            'type' => 'int',            'not null' => TRUE,          ),          'record_id' => array(            'description' => 'The unique numerical identifier for the record that this entity is associated with (e.g. feature_id, stock_id, library_id, etc.).',            'type' => 'int',            'not null' => TRUE,          ),          'nid' => array(            'description' => 'Optional. For linking nid to the entity when migrating Tripal v2 content',            'type' => 'int',          )        ),        'primary key' => array(          'mapping_id',        ),        'indexes' => array(          'record_id' => array('record_id'),          'entity_id' => array('entity_id'),          'nid' => array('nid'),        ),        'unique keys' => array(          'table_record' => array('record_id'),          'entity_id' => array('entity_id'),        ),      );    }  }  return $schema;}/** * This function should be executed only one time during upgrade of v2 to v3. */function tripal_chado_upgrade_v2_v3_pre_enable() {  // If Tripal v2 is already installed, then when the module is first enabled  // after an upgade, the installation of this module will try and recreate  // some of the tables created with tripal_core and the installation will fail.  // Therefore, we need to temporarily move those tables out of the way, let  // the module install and then move them back.  if (db_table_exists('tripal_mviews')) {    // Move the tripal_mviews table out of the way.    $sql = "ALTER TABLE tripal_mviews RENAME TO tripal_mviews2";    db_query($sql);    if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_mviews_mv_name_key'")->fetchField()) {      $sql = "ALTER INDEX tripal_mviews_mv_name_key RENAME TO tripal_mviews_mv_name_key2";    }    else {      $sql = "CREATE UNIQUE INDEX tripal_mviews_mv_name_key2 ON tripal_mviews2 USING btree (name)";    }    db_query($sql);    if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_mviews_mv_table_key'")->fetchField()) {      $sql = "ALTER INDEX tripal_mviews_mv_table_key RENAME TO tripal_mviews_mv_table_key2";    }    else {      $sql = "CREATE UNIQUE INDEX tripal_mviews_mv_table_key2 ON tripal_mviews2 USING btree (mv_table)";    }    db_query($sql);    if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_mviews_mview_id_idx'")->fetchField()) {      $sql = "ALTER INDEX tripal_mviews_mview_id_idx RENAME TO tripal_mviews_mview_id_idx2";    }    else {      $sql = "CREATE INDEX tripal_mviews_mview_id_idx2 ON tripal_mviews2 USING btree (mview_id)";    }    db_query($sql);    if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_mviews_pkey'")->fetchField()) {      $sql = "ALTER INDEX tripal_mviews_pkey RENAME TO tripal_mviews_pkey2";    }    else {      $sql = "CREATE UNIQUE INDEX tripal_mviews_pkey2 ON tripal_mviews2 USING btree (mview_id)";    }    db_query($sql);  }  if (db_table_exists('tripal_custom_tables')) {    // Move the tripal_custom_tables table out of the way.    $sql = "ALTER TABLE tripal_custom_tables RENAME TO tripal_custom_tables2";    db_query($sql);    if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_custom_tables_pkey'")->fetchField()) {      $sql = "ALTER INDEX tripal_custom_tables_pkey RENAME TO tripal_custom_tables_pkey2";    }    else {      $sql = "CREATE UNIQUE INDEX tripal_custom_tables_pkey2 ON tripal_custom_tables2 USING btree (table_id)";    }    db_query($sql);    if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_custom_tables_table_id_idx'")->fetchField()) {      $sql = "ALTER INDEX tripal_custom_tables_table_id_idx RENAME TO tripal_custom_tables_table_id_idx2";    }    else {      $sql = "CREATE INDEX tripal_custom_tables_table_id_idx2 ON tripal_custom_tables2 USING btree (table_id)";    }    db_query($sql);  }  if (db_table_exists('tripal_cv_obo')) {    // Move the tripal_cv_obo table out of the way.    $sql = "ALTER TABLE tripal_cv_obo RENAME TO tripal_cv_obo2";    db_query($sql);    if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_cv_obo_obo_id_idx'")->fetchField()) {      $sql = "ALTER INDEX tripal_cv_obo_obo_id_idx RENAME TO tripal_cv_obo_obo_id_idx2";    }    else if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_cv_obo_tripal_cv_obo_idx1_idx'")->fetchField()) {      $sql = "ALTER INDEX tripal_cv_obo_tripal_cv_obo_idx1_idx RENAME TO tripal_cv_obo_obo_id_idx2";    }    else {      $sql = "CREATE INDEX tripal_cv_obo_obo_id_idx2 ON tripal_cv_obo2 USING btree (obo_id)";    }    db_query($sql);    if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_cv_obo_pkey'")->fetchField()) {      $sql = "ALTER INDEX tripal_cv_obo_pkey RENAME TO tripal_cv_obo_pkey2";    }    else {      $sql = "CREATE UNIQUE INDEX tripal_cv_obo_pkey2 ON tripal_cv_obo2 USING btree (obo_id)";    }    db_query($sql);  }  if (db_table_exists('tripal_pub_import')) {    // Move the tripal_pub_import table out of the way.    $sql = "ALTER TABLE tripal_pub_import RENAME TO tripal_pub_import2";    db_query($sql);    if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_pub_import_name_idx'")->fetchField()) {      $sql = "ALTER INDEX tripal_pub_import_name_idx RENAME TO tripal_pub_import_name_idx2";    }    else {      $sql = "CREATE INDEX tripal_pub_import_name_idx2 ON tripal_pub_import2 USING btree (name)";    }    db_query($sql);    if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_pub_import_pkey'")->fetchField()) {      $sql = "ALTER INDEX tripal_pub_import_pkey RENAME TO tripal_pub_import_pkey2";    }    else {      $sql = "CREATE UNIQUE INDEX tripal_pub_import_pkey2 ON tripal_pub_import2 USING btree (pub_import_id)";    }    db_query($sql);  }}/** * This function should be executed only one time during upgrade of v2 to v3. */function tripal_chado_upgrade_v2_v3_enable() {  // If Tripal v2 is already installed, the installation of this module  // will try and recreate some of the tables created with tripal_core and the  // installation will fail.  Therefore, in the install we renamed it. Now  // we want to move it back.  if (db_table_exists('tripal_mviews2')) {    // tripal_mviews    $sql = "DROP TABLE tripal_mviews";    db_query($sql);    $sql = "ALTER TABLE tripal_mviews2 RENAME to tripal_mviews";    db_query($sql);    $sql = "ALTER INDEX tripal_mviews_mv_name_key2 RENAME TO tripal_mviews_mv_name_key";    db_query($sql);    $sql = "ALTER INDEX tripal_mviews_mv_table_key2 RENAME TO tripal_mviews_mv_table_key";    db_query($sql);    $sql = "ALTER INDEX tripal_mviews_mview_id_idx2 RENAME TO tripal_mviews_mview_id_idx";    db_query($sql);    $sql = "ALTER INDEX tripal_mviews_pkey2 RENAME TO tripal_mviews_pkey";    db_query($sql);  }  // tripal_custom_tables  if (db_table_exists('tripal_custom_tables2')) {    $sql = "DROP TABLE tripal_custom_tables";    db_query($sql);    $sql = "ALTER TABLE tripal_custom_tables2 RENAME to tripal_custom_tables";    db_query($sql);    $sql = "ALTER INDEX tripal_custom_tables_pkey2 RENAME TO tripal_custom_tables_pkey";    db_query($sql);    $sql = "ALTER INDEX tripal_custom_tables_table_id_idx2 RENAME TO tripal_custom_tables_table_id_idx";    db_query($sql);  }  // tripal_cv_obo  if (db_table_exists('tripal_cv_obo2')) {    $sql = "DROP TABLE tripal_cv_obo";    db_query($sql);    $sql = "ALTER TABLE tripal_cv_obo2 RENAME to tripal_cv_obo";    db_query($sql);    $sql = "ALTER INDEX tripal_cv_obo_obo_id_idx2 RENAME TO tripal_cv_obo_obo_id_idx";    db_query($sql);    if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_cv_obo_pkey2'")->fetchField()) {      $sql = "ALTER INDEX tripal_cv_obo_pkey2 RENAME TO tripal_cv_obo_pkey";    }    db_query($sql);  }  // tripal_pub_import  if (db_table_exists('tripal_pub_import2')) {    $sql = "DROP TABLE tripal_pub_import";    db_query($sql);    $sql = "ALTER TABLE tripal_pub_import2 RENAME to tripal_pub_import";    db_query($sql);    $sql = "ALTER INDEX tripal_pub_import_name_idx2 RENAME TO tripal_pub_import_name_idx";    db_query($sql);    $sql = "ALTER INDEX tripal_pub_import_pkey2 RENAME TO tripal_pub_import_pkey";    db_query($sql);  }}/** * @section * Schema Definitions. *//** * Implementation of hook_schema(). * * @ingroup tripal_pub */function tripal_chado_tripal_pub_import_schema() {  return array(    'fields' => array(      'pub_import_id' => array(        'type' => 'serial',        'not null' => TRUE      ),      'name' => array(        'type' => 'varchar',        'length' => 255,        'not null' => TRUE      ),      'criteria' => array(        'type' => 'text',        'size' => 'normal',        'not null' => TRUE,        'description' => 'Contains a serialized PHP array containing the search criteria'      ),      'disabled'  => array(        'type' => 'int',        'unsigned' => TRUE,        'not NULL' => TRUE,        'default' => 0      ),      'do_contact'  => array(        'type' => 'int',        'unsigned' => TRUE,        'not NULL' => TRUE,        'default' => 0      ),    ),    'primary key' => array('pub_import_id'),    'indexes' => array(      'name' => array('name')    ),  );}/** * Describes the Tripal Custom Tables (tripal_custom_tables) table * This keeps track of tables created by Tripal and stored in chado that may or may not * also be materialized views. * * @ingroup tripal */function tripal_chado_tripal_custom_tables_schema() {  return array(    'fields' => array(      'table_id' => array(        'type' => 'serial',        'unsigned' => TRUE,        'not NULL' => TRUE      ),      'table_name' => array(        'type' => 'varchar',        'length' => 255,        'not NULL' => TRUE      ),      'schema' => array(        'type' => 'text',        'not NULL' => TRUE      ),      'mview_id' => array(        'type' => 'int',        'not NULL' => FALSE      )    ),    'indexes' => array(      'table_id' => array('table_id'),    ),    'primary key' => array('table_id'),    'foreign keys' => array(      'tripal_mviews' => array(        'table' => 'tripal_mviews',        'columns' => array(          'mview_id' => 'mview_id'        ),      ),    ),  );}/** * Describes the Tripal Materialized View (tripal_mviews) table * This table keeps track of all materialized views created by Tripal and stored in chado * * @ingroup tripal */function tripal_chado_tripal_mviews_schema() {  return array(    'fields' => array(      'mview_id' => array(        'type' => 'serial',        'unsigned' => TRUE,        'not NULL' => TRUE      ),      'name' => array(        'type' => 'varchar',        'length' => 255,        'not NULL' => TRUE      ),      'modulename' => array(        'type' => 'varchar',        'length' => 50,        'not NULL' => TRUE,        'description' => 'The module name that provides the callback for this job'      ),      'mv_table' => array(        'type' => 'varchar',        'length' => 128,        'not NULL' => FALSE      ),      'mv_specs' => array(        'type' => 'text',        'size' => 'normal',        'not NULL' => FALSE      ),      'mv_schema' => array(        'type' => 'text',        'size' => 'normal',        'not NULL' => FALSE      ),      'indexed' => array(        'type' => 'text',        'size' => 'normal',        'not NULL' => FALSE      ),      'query' => array(        'type' => 'text',        'size' => 'normal',        'not NULL' => TRUE      ),      'special_index' => array(        'type' => 'text',        'size' => 'normal',        'not NULL' => FALSE      ),      'last_update' => array(        'type' => 'int',        'not NULL' => FALSE,        'description' => 'UNIX integer time'      ),      'status'        => array(        'type' => 'text',        'size' => 'normal',        'not NULL' => FALSE      ),      'comment' => array(        'type' => 'text',        'size' => 'normal',        'not NULL' => FALSE      ),    ),    'indexes' => array(      'mview_id' => array('mview_id')    ),    'unique keys' => array(      'mv_table' => array('mv_table'),      'mv_name' => array('name'),    ),    'primary key' => array('mview_id'),  );}/** * Links Biological Data Entities to the chado "base" table the data is stored in. * This is where we would specify that a particular gene maps to the record in the * chado.feature table with a feature_id=2432; */function tripal_chado_chado_bundle_schema() {  $schema = array(    'description' => 'Describes how a bundle maps data to Chado',    'fields' => array(      'chado_bundle_id' => array(        'description' => 'The primary identifier for this table.',        'type' => 'serial',        'unsigned' => TRUE,        'not null' => TRUE,      ),      'bundle_id' => array(        'description' => 'The unique entity id.',        'type' => 'int',        'not null' => TRUE,      ),      'data_table' => array(        'description' => 'The table in Chado that this term services (e.g. feature, stock, library, etc.)',        'type' => 'varchar',        'length' => 128,        'not null' => TRUE,        'default' => '',      ),      'type_linker_table' => array(        'description' => 'If a linker table (e.g. cvterm/prop) is needed to uniquely identify a content type then that table name is provided here.',        'type' => 'varchar',        'length' => 128,        'not null' => FALSE,        'default' => '',      ),      'type_column' => array(        'description' => 'The column in the data table or linker table that distinguishes the data type. This must be in a foreign key relationship to the cvterm table.',        'type' => 'varchar',        'length' => 128,        'not null' => FALSE,        'default' => '',      ),      'type_id' => array(        'description' => 'If a type_column is set then this is the cvterm_id of the data type that this bundle maps to.',        'type' => 'varchar',        'length' => 128,        'not null' => TRUE,        'default' => '',      ),      'type_value' => array(        'description' => 'If a property table is used for a linker, then the value that should be matched to identify this content type is stored here.',        'type' => 'text',        'not null' => FALSE,        'default' => '',      )    ),    'indexes' => array(      'bundle_id' => array('bundle_id'),      'data_table' => array('data_table'),    ),    'unique keys' => array(      'record' => array('bundle_id'),    ),    'primary key' => array('chado_bundle_id'),  );  return $schema;}/** * Tripal cvterm mapping schema * Map cvterms to chado tables that use them */function tripal_chado_chado_cvterm_mapping_schema() {  $schema = array (    'table' => 'chado_cvterm_mapping',    'fields' => array (      'mapping_id' => array(        'type' => 'serial',        'not null' => TRUE      ),      'cvterm_id' => array (        'type' => 'int',        'not null' => TRUE      ),      'chado_table' => array (        'type' => 'varchar',        'length' => 128,        'not null' => TRUE      ),      'chado_field' => array (        'type' => 'varchar',        'length' => 128,        'not null' => FALSE      ),    ),    'primary key' => array (      0 => 'mapping_id'    ),    'unique key' => array(      'cvterm_id',    ),    'indexes' => array(      'tripal_cvterm2table_idx1' => array('cvterm_id'),      'tripal_cvterm2table_idx2' => array('chado_table'),      'tripal_cvterm2table_idx3' => array('chado_table', 'chado_field'),    ),  );  return $schema;}/** * Fixes the phase on the tripal_gffcds_temp table used for importing GFF files, and fixes the db.name term mapping. * */function tripal_chado_update_7300() {  try {    if (chado_table_exists('tripal_gffcds_temp')) {      chado_query("ALTER TABLE {tripal_gffcds_temp} ALTER COLUMN phase DROP NOT NULL;");    }    $term = tripal_insert_cvterm(array(      'id' => 'data:1048',      'name' => 'Database ID',      'cv_name' => 'EDAM',      'definition' => 'An identifier of a biological or bioinformatics database.',    ));    tripal_associate_chado_semweb_term('db', 'name', $term);  }  catch (\PDOException $e) {    $error = $e->getMessage();    throw new DrupalUpdateException('Could not fix phase on tripal_gffcds_temp table: '. $error);  }}/** * Divides chado_entity table for better integration with views. */function tripal_chado_update_7301() {  module_load_include('inc', 'tripal_chado', 'includes/tripal_chado.bundle');  try {    $transaction = db_transaction();    $query = db_select('chado_bundle', 'CB');    $query->join('tripal_bundle', 'TB', 'TB.id = CB.bundle_id');    $query->fields('CB', array('data_table'));    $query->fields('TB', array('name'));    $cbundles = $query->execute();    // If the table for the bundle doesn't exist then create one, and then    // move all of the records from the chado_entity table to it.    while($cbundle = $cbundles->fetchObject()) {      $cbundle_table = chado_get_bundle_entity_table($cbundle);      if (!db_table_exists($cbundle_table)) {        // Create the bundle table.        tripal_chado_create_bundle_table($cbundle);        // Now move the records over.        $sql = "          INSERT INTO {$cbundle_table} (entity_id, record_id, nid)           SELECT CE.entity_id, CE.record_id, CE.nid            FROM {chado_entity} CE              INNER JOIN {tripal_entity} TE ON CE.entity_id = TE.id            WHERE TE.bundle = :bundle        ";        db_query($sql, array(':bundle' => $cbundle->name));      }    }    // Now remove the chado_entity table.    db_drop_table('chado_entity');  }  catch (\PDOException $e) {    $transaction->rollback();    $error = $e->getMessage();    throw new DrupalUpdateException('Could not perform update: '. $error);  }}/** * Corrections to the EDAM database. */function tripal_chado_update_7302(){  try {    // Add the term for the field.    tripal_insert_db(array(      'name' => 'format',      'description' => 'A defined way or layout of representing and structuring data in a computer file, blob, string, message, or elsewhere. The main focus in EDAM lies on formats as means of structuring data exchanged between different tools or resources. ',      'url' => 'http://edamontology.org/page',      'urlprefix' => 'http://edamontology.org/{db}_{accession}',    ));    tripal_insert_db(array(      'name' => 'operation',      'description' => 'A function that processes a set of inputs and results in a set of outputs, or associates arguments (inputs) with values (outputs). Special cases are: a) An operation that consumes no input (has no input arguments).',      'url' => 'http://edamontology.org/page',      'urlprefix' => 'http://edamontology.org/{db}_{accession}',    ));    tripal_insert_db(array(      'name' => 'topic',      'description' => 'A category denoting a rather broad domain or field of interest, of study, application, work, data, or technology. Topics have no clearly defined borders between each other.',      'url' => 'http://edamontology.org/page',      'urlprefix' => 'http://edamontology.org/{db}_{accession}',    ));    tripal_insert_cv(      'EDAM',      'EDAM is an ontology of well established, familiar concepts that are prevalent within bioinformatics, including types of data and data identifiers, data formats, operations and topics. EDAM is a simple ontology - essentially a set of terms with synonyms and definitions - organised into an intuitive hierarchy for convenient use by curators, software developers and end-users. EDAM is suitable for large-scale semantic annotations and categorization of diverse bioinformatics resources. EDAM is also suitable for diverse application including for example within workbenches and workflow-management systems, software distributions, and resource registries.'    );  }  catch (\PDOException $e) {    $transaction->rollback();    $error = $e->getMessage();    throw new DrupalUpdateException('Could not perform update: '. $error);  }}/** * Fixes inconsistency with Chado v1.3 update if was applied. */function tripal_chado_update_7303() {  try {    $chado_version = chado_get_version();    if ($chado_version == '1.3') {      module_load_include('inc', 'tripal_chado', 'includes/setup/tripal_chado.setup');      tripal_chado_fix_v1_3_custom_tables();    }  }  catch (\PDOException $e) {    $transaction->rollback();    $error = $e->getMessage();    throw new DrupalUpdateException('Could not perform update: '. $error);  }}/** * Add some new controlled vocabulary terms. */function tripal_chado_update_7304() {  try {    $term = tripal_insert_cvterm(array(      'id' => 'SIO:001080',      'name' => 'vocabulary',      'cv_name' => 'SIO',      'definition' => 'A vocabulary is a collection of terms.',    ));    tripal_associate_chado_semweb_term('cvterm', 'cv_id', $term);    $term = tripal_insert_cvterm(array(      'id' => 'data:2976',      'name' => 'Protein sequence',      'cv_name' => 'EDAM',      'definition' => 'One or more protein sequences, possibly with associated annotation.',    ));    $term = tripal_insert_cvterm(array(      'id' => 'local:fmin',      'name' => 'minimal boundary',      'definition' => 'The leftmost, minimal boundary in the linear range ' .      'represented by the feature location. Sometimes this is called ' .      'start although this is confusing because it does not necessarily ' .      'represent the 5-prime coordinate.',      'cv_name' => 'local',    ));    tripal_associate_chado_semweb_term('featureloc', 'fmin', $term);    $term = tripal_insert_cvterm(array(      'id' => 'local:fmax',      'name' => 'maximal boundary',      'definition' => 'The rightmost, maximal boundary in the linear range ' .      'represented by the featureloc. Sometimes this is called end although ' .      'this is confusing because it does not necessarily represent the ' .      '3-prime coordinate',      'cv_name' => 'local',    ));    tripal_associate_chado_semweb_term('featureloc', 'fmax', $term);    $term = tripal_insert_cvterm(array(      'id' => 'data:2336',      'name' => 'Translation phase specification',      'cv_name' => 'EDAM',      'definition' => 'Phase for translation of DNA (0, 1 or 2) relative to a fragment of the coding sequence.',    ));    tripal_associate_chado_semweb_term('featureloc', 'phase', $term);    $term = tripal_insert_cvterm(array(      'id' => 'data:3002',      'name' => 'Annotation track',      'cv_name' => 'EDAM',      'definition' => 'Annotation of one particular positional feature on a ' .        'biomolecular (typically genome) sequence, suitable for import and ' .        'display in a genome browser. Synonym: Sequence annotation track.',    ));    tripal_associate_chado_semweb_term('featureloc', 'srcfeature_id', $term);  }  catch (\PDOException $e) {    $transaction->rollback();    $error = $e->getMessage();    throw new DrupalUpdateException('Could not perform update: '. $error);  }}/** * Adding missing cv/db details and cvterms. */function tripal_chado_update_7305() {  try {    tripal_insert_db(array(      'name' => 'rdfs',      'description' => 'Resource Description Framework Schema',      'url' => 'https://www.w3.org/TR/rdf-schema/',      'urlprefix' => 'https://www.w3.org/TR/rdf-schema/#ch_{accession}',    ));    tripal_insert_cv('rdfs', 'Resource Description Framework Schema');    tripal_insert_db(array(      'name' => 'SO',      'description' => 'The sequence ontology.',      'url' => 'http://www.sequenceontology.org/',      'urlprefix' => 'http://www.sequenceontology.org/browser/current_svn/term/{db}:{accession}',    ));    tripal_insert_cv('sequence', 'The sequence ontology.');    tripal_insert_db(array(      'name' => 'TAXRANK',      'description' => 'A vocabulary of taxonomic ranks (species, family, phylum, etc)',      'url' => 'http://www.obofoundry.org/ontology/taxrank.html',      'urlprefix' => 'http://purl.obolibrary.org/obo/{db}_{accession}',    ));    tripal_insert_cv('taxonomic_rank', 'A vocabulary of taxonomic ranks (species, family, phylum, etc)');    tripal_insert_db(array(      'name' => 'hydra',      'description' => 'A Vocabulary for Hypermedia-Driven Web APIs',      'url' => 'https://www.hydra-cg.com/spec/latest/core/',      'urlprefix' => 'https://www.hydra-cg.com/spec/latest/core/#{db}:{accession}',    ));    tripal_insert_cv(      'hydra',      'A Vocabulary for Hypermedia-Driven Web APIs.'    );    tripal_insert_db(array(      'name' => 'dc',      'description' => 'DCMI Metadata Terms.',      'url' => 'http://purl.org/dc/dcmitype/',      'urlprefix' => 'http://purl.org/dc/terms/{accession}',    ));    tripal_insert_cv(      'dc',      'DCMI Metadata Terms.'    );    $term = tripal_insert_cvterm(array(      'id' => 'dc:Service',      'name' => 'Service',      'cv_name' => 'dc',      'definition' => 'A system that provides one or more functions.',    ));    $name = tripal_insert_cvterm(array(      'id' => 'hydra:Collection',      'name' => 'Collection',      'cv_name' => 'hydra',      'definition' => 'A collection holding references to a number of related resources.',    ));    $name = tripal_insert_cvterm(array(      'id' => 'hydra:member',      'name' => 'member',      'cv_name' => 'hydra',      'definition' => 'A member of the collection',    ));    $name = tripal_insert_cvterm(array(      'id' => 'hydra:description',      'name' => 'description',      'cv_name' => 'hydra',      'definition' => 'A description.',    ));    $name = tripal_insert_cvterm(array(      'id' => 'hydra:totalItems',      'name' => 'totalItems',      'cv_name' => 'hydra',      'definition' => 'The total number of items referenced by a collection.',    ));    $name = tripal_insert_cvterm(array(      'id' => 'hydra:title',      'name' => 'title',      'cv_name' => 'hydra',      'definition' => 'A title, often used along with a description.',    ));    $name = tripal_insert_cvterm(array(      'id' => 'hydra:PartialCollectionView',      'name' => 'PartialCollectionView',      'cv_name' => 'hydra',      'definition' => 'A PartialCollectionView describes a partial view of a Collection. Multiple PartialCollectionViews can be connected with the the next/previous properties to allow a client to retrieve all members of the collection.',    ));    $term = tripal_insert_cvterm(array(      'id' => 'schema:ItemPage',      'name' => 'ItemPage',      'cv_name' => 'schema',      'definition' => 'A page devoted to a single item, such as a particular product or hotel.',    ));    global $base_path;    tripal_insert_db(array(      'name' => 'null',      'description' => 'No online database.',      'url' => $base_path . 'cv/lookup/null',      'urlprefix' => $base_path. 'cv/lookup/{db}/{accession}',    ));    tripal_insert_db(array(      'name' => 'local',      'description' => 'Terms created for this site.',      'url' => $base_path . 'cv/lookup/local',      'urlprefix' => $base_path . 'cv/lookup/{db}/{accession}',    ));    $term = tripal_insert_cvterm(array(      'id' => 'local:rank',      'name' => 'rank',      'definition' => 'A taxonmic rank',      'cv_name' => 'local',    ));  }  catch (\PDOException $e) {    $transaction->rollback();    $error = $e->getMessage();    throw new DrupalUpdateException('Could not perform update: '. $error);  }}/** * Add cvterm mapping for the Map entity type */function tripal_chado_update_7306() {  try {    $identifier = array(      'cv_id' => array('name' => 'EDAM'),      'name' => 'Map'    );    $cvterm = tripal_get_cvterm($identifier);    tripal_chado_add_cvterm_mapping($cvterm->cvterm_id, 'featuremap', NULL);  }  catch (\PDOException $e) {    $error = $e->getMessage();    throw new DrupalUpdateException('Could not perform update: '. $error);  }}/** * Add cvterm mapping for the Publication entity type */function tripal_chado_update_7307() {  try {    $identifier = array(      'cv_id' => array('name' => 'tripal_pub'),      'name' => 'Publication'    );    $cvterm = tripal_get_cvterm($identifier);    tripal_chado_add_cvterm_mapping($cvterm->cvterm_id, 'pub', NULL);  }  catch (\PDOException $e) {    $error = $e->getMessage();    throw new DrupalUpdateException('Could not perform update: '. $error);  }}/** * Add cvterm mapping for the analysis.sourcversion and analysis.sourcename. */function tripal_chado_update_7308() {  try {    $term = tripal_insert_cvterm(array(      'id' => 'IAO:0000129',      'name' => 'version number',      'cv_name' => 'IAO',      'definition' => 'A version number is an ' .      'information content entity which is a sequence of characters ' .      'borne by part of each of a class of manufactured products or its ' .      'packaging and indicates its order within a set of other products ' .      'having the same name.',    ));    tripal_associate_chado_semweb_term('analysis', 'sourceversion', $term);    tripal_associate_chado_semweb_term(NULL, 'version', $term);    $term = tripal_insert_cvterm(array(      'id' => 'schema:name',      'name' => 'name',      'cv_name' => 'schema',      'definition' => 'The name of the item.',    ));    tripal_associate_chado_semweb_term('analysis', 'sourcename', $term);    $term = tripal_insert_cvterm(array(      'id' => 'data:2091',      'name' => 'Accession',      'cv_name' => 'EDAM',      'definition' => 'A persistent (stable) and unique identifier, typically identifying an object (entry) from a database.',    ));    tripal_associate_chado_semweb_term('dbxref', 'accession', $term);  }  catch (\PDOException $e) {    $error = $e->getMessage();    throw new DrupalUpdateException('Could not perform update: '. $error);  }}/** * Add cvterm 'annotation' and maps to cvterm linking tables. */function tripal_chado_update_7309() {  try {    $term = tripal_insert_cvterm(array(      'id' => 'SIO:001166',      'name' => 'annotation',      'cv_name' => 'SIO',      'definition' => 'An annotation is a written explanatory or critical description, or other in-context information (e.g., pattern, motif, link), that has been associated with data or other types of information.',    ));    tripal_associate_chado_semweb_term('feature_cvterm', 'cvterm_id', $term);    tripal_associate_chado_semweb_term('analysis_cvterm', 'cvterm_id', $term);    tripal_associate_chado_semweb_term('cell_line_cvterm', 'cvterm_id', $term);    tripal_associate_chado_semweb_term('environment_cvterm', 'cvterm_id', $term);    tripal_associate_chado_semweb_term('expression_cvterm', 'cvterm_id', $term);    tripal_associate_chado_semweb_term('library_cvterm', 'cvterm_id', $term);    tripal_associate_chado_semweb_term('organism_cvterm', 'cvterm_id', $term);    tripal_associate_chado_semweb_term('phenotype_cvterm', 'cvterm_id', $term);    tripal_associate_chado_semweb_term('stock_cvterm', 'cvterm_id', $term);    tripal_associate_chado_semweb_term('stock_relationship_cvterm', 'cvterm_id', $term);    $term = tripal_insert_cvterm(array(      'id' => 'SIO:000281',      'name' => 'negation',      'cv_name' => 'SIO',      'definition' => 'NOT is a logical operator in that has the value true if its operand is false.',    ));    tripal_associate_chado_semweb_term('feature_cvterm', 'is_not', $term);    tripal_associate_chado_semweb_term('analysis_cvterm', 'is_not', $term);    tripal_associate_chado_semweb_term('organism_cvterm', 'is_not', $term);    tripal_associate_chado_semweb_term('stock_cvterm', 'is_not', $term);  }  catch (\PDOException $e) {    $error = $e->getMessage();    throw new DrupalUpdateException('Could not perform update: '. $error);  }}/** * Adds the 'OBCS' and rank order term. */function tripal_chado_update_7310() {  try {    tripal_insert_db(array(      'name' => 'OBCS',      'description' => 'Ontology of Biological and Clinical Statistics.',      'url' => 'https://github.com/obcs/obcs',      'urlprefix' => 'http://purl.obolibrary.org/obo/{db}_{accession}',    ));    tripal_insert_cv(        'OBCS',        'Ontology of Biological and Clinical Statistics.'    );    $term = tripal_insert_cvterm(array(      'id' => 'OBCS:0000117',      'name' => 'rank order',      'cv_name' => 'OBCS',      'definition' => 'A data item that represents an arrangement according to a rank, i.e., the position of a particular case relative to other cases on a defined scale.',    ));    tripal_associate_chado_semweb_term(NULL, 'rank', $term);  }  catch (\PDOException $e) {    $error = $e->getMessage();    throw new DrupalUpdateException('Could not perform update: '. $error);  }}/** * Fix a mistake with the association of the term with featureloc.fmin. */function tripal_chado_update_7311() {  try {    $term = tripal_insert_cvterm(array(      'id' => 'local:fmin',      'name' => 'minimal boundary',      'definition' => 'The leftmost, minimal boundary in the linear range ' .        'represented by the feature location. Sometimes this is called ' .        'start although this is confusing because it does not necessarily ' .        'represent the 5-prime coordinate.',      'cv_name' => 'local',    ));    tripal_associate_chado_semweb_term('featureloc', 'fmin', $term);  }  catch (\PDOException $e) {    $error = $e->getMessage();    throw new DrupalUpdateException('Could not perform update: '. $error);  }}
 |