private function TaxonomyImporter::updateExisting

3.x TaxonomyImporter.inc private TaxonomyImporter::updateExisting()

Imports details from NCBI Taxonomy for organisms that alrady exist.

1 call to TaxonomyImporter::updateExisting()
TaxonomyImporter::run in tripal_chado/includes/TripalImporter/TaxonomyImporter.inc
Performs the import.

File

tripal_chado/includes/TripalImporter/TaxonomyImporter.inc, line 463

Class

TaxonomyImporter

Code

private function updateExisting() {

  foreach ($this->all_orgs as $organism) {
    // If the organism record is marked as new then let's skip it because
    // it was newly added and should have the updated information already.
    if ($organism->is_new) {
      continue;
    }

    // TODO: we should check if the organism already has a taxonomy ID.
    // if so we should use that instead of the scientific name.

    // Build the query string to get the information about this species.
    $sci_name = chado_get_organism_scientific_name($organism);
    $sci_name = urlencode($sci_name);
    $search_url = "http://www.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?" .
      "db=taxonomy" .
      "&term=$sci_name";

    // Get the search response from NCBI.
    $rfh = fopen($search_url, "r");
    $xml_text = '';
    while (!feof($rfh)) {
      $xml_text .= fread($rfh, 255);
    }
    fclose($rfh);

    // Parse the XML to get the taxonomy ID
    $xml = new SimpleXMLElement($xml_text);
    if ($xml) {
      $taxid = (string) $xml->IdList->Id;
      if ($taxid) {
        $this->importRecord($taxid, $organism);
      }
    }
    $this->addItemsHandled(1);
  }
}