function tripal_cv_load_obo_v1_2

2.x tripal_cv.obo_loader.inc tripal_cv_load_obo_v1_2($file, $jobid = NULL, &$newcvs)
1.x obo_loader.inc tripal_cv_load_obo_v1_2($file, $jobid = NULL, &$newcvs)

Related topics

2 calls to tripal_cv_load_obo_v1_2()

File

tripal_cv/includes/obo_loader.inc, line 271
Tripal Ontology Loader

Code

function tripal_cv_load_obo_v1_2($file, $jobid = NULL, &$newcvs) {

  $header = array();

  // make sure our temporary table exists
  $ret = array();
  if (!db_table_exists('tripal_obo_temp')) {
    $schema = tripal_cv_get_custom_tables('tripal_obo_temp');
    $success = tripal_core_create_custom_table($ret, 'tripal_obo_temp', $schema['tripal_obo_temp']);
    if (!$success) {
      watchdog('T_obo_loader', "Cannot create temporary loading table", array(), WATCHDOG_ERROR);
      return;
    }
  }
  // empty the temp table
  $sql = "DELETE FROM {tripal_obo_temp}";
  chado_query($sql);

  // get a persistent connection
  $connection = tripal_db_persistent_chado();
  if (!$connection) {
    print "A persistant connection was not obtained. Loading will be slow\n";
  }

  // if we cannot get a connection then let the user know the loading will be slow
  tripal_db_start_transaction();
  if ($connection) {
    print "\nNOTE: Loading of this OBO file is performed using a database transaction. \n" .
      "If the load fails or is terminated prematurely then the entire set of \n" .
      "insertions/updates is rolled back and will not be found in the database\n\n";
  }

  print "Step 1: Preloading File $file\n";

  // make sure we have an 'internal' and a '_global' database
  if (!tripal_db_add_db('internal')) {
    tripal_cv_obo_quiterror("Cannot add 'internal' database");
  }
  if (!tripal_db_add_db('_global')) {
    tripal_cv_obo_quiterror("Cannot add '_global' database");
  }

  // parse the obo file
  $default_db = tripal_cv_obo_parse($file, $header, $jobid);

  // add the CV for this ontology to the database
  $defaultcv = tripal_cv_add_cv($header['default-namespace'][0], '');
  if (!$defaultcv) {
    tripal_cv_obo_quiterror('Cannot add namespace ' . $header['default-namespace'][0]);
  }
  $newcvs[$header['default-namespace'][0]] = $defaultcv->cv_id;

  // add any typedefs to the vocabulary first
  print "\nStep 2: Loading type defs...\n";
  tripal_cv_obo_load_typedefs($defaultcv, $newcvs, $default_db, $jobid);

  // next add terms to the vocabulary
  print "\nStep 3: Loading terms...\n";
  if (!tripal_cv_obo_process_terms($defaultcv, $jobid, $newcvs, $default_db)) {
    tripal_cv_obo_quiterror('Cannot add terms from this ontology');
  }

  // transaction is complete
  tripal_db_commit_transaction();
  return;
}