private function TaxonomyImporter::addOrganism
3.x TaxonomyImporter.inc | private TaxonomyImporter::addOrganism($sci_name, $rank) |
Adds a new organism record to Chado.
Parameters
sci_name: The scientific name as provied by NCBI Taxonomy.
$rank: The rank of the organism as provied by NCBI Taxonomy.
1 call to TaxonomyImporter::addOrganism()
- TaxonomyImporter::importRecord in tripal_chado/
includes/ TripalImporter/ TaxonomyImporter.inc - Imports an organism from the NCBI taxonomy DB by its taxonomy ID
File
- tripal_chado/
includes/ TripalImporter/ TaxonomyImporter.inc, line 580
Class
Code
private function addOrganism($sci_name, $rank) {
$organism = NULL;
$matches = array();
$genus = '';
$species = '';
$infra = '';
$values = array();
// Check if the scientific name has an infraspecific part or is just
// a species name.
if (preg_match('/^(.+?)\s+(.+?)\s+(.+)$/', $sci_name, $matches)) {
$genus = $matches[1];
$species = $matches[2];
$infra = $matches[3];
// Get the CV term for the rank.
$type = chado_get_cvterm(array(
'name' => preg_replace('/ /', '_', $rank),
'cv_id' => array('name' => 'taxonomic_rank')
));
// Remove the rank from the infraspecific name.
$abbrev = chado_abbreviate_infraspecific_rank($rank);
$infra = preg_replace("/$abbrev/", "", $infra);
$infra = trim($infra);
$values = array(
'genus' => $genus,
'species' => $species,
'abbreviation' => $genus[0] . '. ' . $species,
'type_id' => $type->cvterm_id,
'infraspecific_name' => $infra,
);
$organism = chado_insert_record('organism', $values);
$organism = (object) $organism;
$organism->type = $rank;
}
else if (preg_match('/^(.+?)\s+(.+?)$/', $sci_name, $matches)) {
$genus = $matches[1];
$species = $matches[2];
$infra = '';
$values = array(
'genus' => $genus,
'species' => $species,
'abbreviation' => $genus[0] . '. ' . $species,
);
$organism = chado_insert_record('organism', $values);
$organism = (object) $organism;
}
if ($organism) {
$organism->is_new = TRUE;
$this->all_orgs[] = $organism;
}
return $organism;
}