private function GFF3Importer::loadOntology

3.x GFF3Importer.inc private GFF3Importer::loadOntology($feature, $dbxrefs)

Load the cvterms for a feature.

Assumes there is a dbxref.accession matching a cvterm.name

Parameters

$feature:

$dbxrefs:

1 call to GFF3Importer::loadOntology()
GFF3Importer::loadGFF3 in tripal_chado/includes/TripalImporter/GFF3Importer.inc
Actually load a GFF3 file. This is the function called by tripal jobs

File

tripal_chado/includes/TripalImporter/GFF3Importer.inc, line 1353

Class

GFF3Importer

Code

private function loadOntology($feature, $dbxrefs) {

  // iterate through each of the dbxrefs
  foreach ($dbxrefs as $dbxref) {

    // get the database name from the reference.  If it doesn't exist then create one.
    $ref = explode(":", $dbxref);
    $dbname = trim($ref[0]);
    $accession = trim($ref[1]);

    // first look for the database name
    $db = chado_select_record('db', array('db_id'), array('name' => "DB:$dbname"));
    if (sizeof($db) == 0) {
      // now look for the name without the 'DB:' prefix.
      $db = chado_select_record('db', array('db_id'), array('name' => "$dbname"));
      if (sizeof($db) == 0) {
        $this->logMessage("Database, $dbname, is not present. Cannot associate term: $dbname:$accession.", array(), TRIPAL_WARNING);
        return 0;
      }
    }
    $db = $db[0];

    // now check to see if the accession exists
    $dbxref = chado_select_record('dbxref', array('dbxref_id'), 
    array('accession' => $accession, 'db_id' => $db->db_id));
    if (sizeof($dbxref) == 0) {
      $this->logMessage("Accession, $accession is missing for reference: $dbname:$accession.", array(), TRIPAL_WARNING);
      return 0;
    }
    $dbxref = $dbxref[0];

    // now check to see if the cvterm exists
    $cvterm = chado_select_record('cvterm', array('cvterm_id'), array(
      'dbxref_id' => $dbxref->dbxref_id));
    // if it doesn't exist in the cvterm table, look for an alternate id
    if (sizeof($cvterm) == 0) {
      $cvterm = chado_select_record('cvterm_dbxref', array('cvterm_id'), array(
        'dbxref_id' => $dbxref->dbxref_id));
      if (sizeof($cvterm) == 0) {
        $this->logMessage("CV Term is missing for reference: $dbname:$accession.", array(), TRIPAL_WARNING);
        return 0;
      }
    }
    $cvterm = $cvterm[0];


    // check to see if this feature cvterm already exists
    $fcvt = chado_select_record('feature_cvterm', array('feature_cvterm_id'), 
    array('cvterm_id' => $cvterm->cvterm_id, 'feature_id' => $feature->feature_id));

    // now associate this feature with the cvterm if it doesn't already exist
    if (sizeof($fcvt) == 0) {
      $values = array(
        'cvterm_id' => $cvterm->cvterm_id,
        'feature_id' => $feature->feature_id,
        'pub_id' => array(
          'uniquename' => 'null',
        ),
      );
      $success = chado_insert_record('feature_cvterm', $values);

      if (!$success) {
        $this->logMessage("Failed to insert ontology term: $dbname:$accession.", array(), TRIPAL_WARNING);
        return 0;
      }
    }
  }
  return 1;
}