|
@@ -189,13 +189,13 @@ class TaxonomyImporter extends TripalImporter {
|
|
$taxonomy_ids = $arguments['taxonomy_ids'];
|
|
$taxonomy_ids = $arguments['taxonomy_ids'];
|
|
$import_existing = $arguments['import_existing'];
|
|
$import_existing = $arguments['import_existing'];
|
|
|
|
|
|
-
|
|
|
|
// Get the list of all organisms as we'll need this to lookup existing
|
|
// Get the list of all organisms as we'll need this to lookup existing
|
|
// organisms.
|
|
// organisms.
|
|
$sql = "
|
|
$sql = "
|
|
SELECT O.*, CVT.name as type
|
|
SELECT O.*, CVT.name as type
|
|
FROM {organism} O
|
|
FROM {organism} O
|
|
LEFT JOIN {cvterm} CVT ON CVT.cvterm_id = O.type_id
|
|
LEFT JOIN {cvterm} CVT ON CVT.cvterm_id = O.type_id
|
|
|
|
+ ORDER BY O.genus, O.species
|
|
";
|
|
";
|
|
$results = chado_query($sql);
|
|
$results = chado_query($sql);
|
|
while ($item = $results->fetchObject()) {
|
|
while ($item = $results->fetchObject()) {
|
|
@@ -244,7 +244,6 @@ class TaxonomyImporter extends TripalImporter {
|
|
$this->logMessage('Updating Existing...');
|
|
$this->logMessage('Updating Existing...');
|
|
$this->updateExisting();
|
|
$this->updateExisting();
|
|
}
|
|
}
|
|
-
|
|
|
|
// Now import the tree.
|
|
// Now import the tree.
|
|
$options = array('taxonomy' => 1);
|
|
$options = array('taxonomy' => 1);
|
|
tripal_phylogeny_import_tree($this->tree, $this->phylotree, $options);
|
|
tripal_phylogeny_import_tree($this->tree, $this->phylotree, $options);
|
|
@@ -321,7 +320,12 @@ class TaxonomyImporter extends TripalImporter {
|
|
'branch_set' => array(),
|
|
'branch_set' => array(),
|
|
);
|
|
);
|
|
|
|
|
|
|
|
+ $total = count($this->all_orgs);
|
|
|
|
+ $j = 1;
|
|
foreach ($this->all_orgs as $organism) {
|
|
foreach ($this->all_orgs as $organism) {
|
|
|
|
+ $sci_name = tripal_get_organism_scientific_name($organism);
|
|
|
|
+ //$this->logMessage("- " . ($j++) . " of $total. Adding @organism", array('@organism' => $sci_name));
|
|
|
|
+
|
|
// First get the phylonode record for this organism.
|
|
// First get the phylonode record for this organism.
|
|
$sql = "
|
|
$sql = "
|
|
SELECT P.*
|
|
SELECT P.*
|
|
@@ -368,22 +372,23 @@ class TaxonomyImporter extends TripalImporter {
|
|
'phylotree_id' => $this->phylotree->phylotree_id,
|
|
'phylotree_id' => $this->phylotree->phylotree_id,
|
|
'label' => $child,
|
|
'label' => $child,
|
|
);
|
|
);
|
|
- $options = array(
|
|
|
|
- 'include_fk' => array(
|
|
|
|
- 'type_id' => array(
|
|
|
|
- 'cv_id' => 1,
|
|
|
|
- 'dbxref_id' => 1,
|
|
|
|
- ),
|
|
|
|
- )
|
|
|
|
- );
|
|
|
|
- $phylonode = chado_generate_var('phylonode', $values, $options);
|
|
|
|
- $lineage_nodes[$child] = $phylonode;
|
|
|
|
- if (!$phylonode) {
|
|
|
|
|
|
+ $columns = array('*');
|
|
|
|
+ $phylonode = chado_select_record('phylonode', $columns, $values);
|
|
|
|
+ if (count($phylonode) == 0) {
|
|
|
|
+ $lineage_nodes[$child] = NULL;
|
|
$lineage_good = FALSE;
|
|
$lineage_good = FALSE;
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
- $options = array('return_array' => TRUE);
|
|
|
|
- $phylonode = chado_expand_var($phylonode, 'table', 'phylonodeprop', $options);
|
|
|
|
|
|
+ $phylonode = $phylonode[0];
|
|
|
|
+ $lineage_nodes[$child] = $phylonode;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ $values = array(
|
|
|
|
+ 'phylonode_id' => $phylonode->phylonode_id,
|
|
|
|
+ 'type_id' => $rank_cvterm->cvterm_id,
|
|
|
|
+ );
|
|
|
|
+ $columns = array('*');
|
|
|
|
+ $phylonodeprop = chado_select_record('phylonodeprop', $columns, $values);
|
|
}
|
|
}
|
|
$name = $child;
|
|
$name = $child;
|
|
$node_rank = (string) $child->Rank;
|
|
$node_rank = (string) $child->Rank;
|
|
@@ -399,7 +404,7 @@ class TaxonomyImporter extends TripalImporter {
|
|
'branch_set' => array(),
|
|
'branch_set' => array(),
|
|
'parent' => $parent['name'],
|
|
'parent' => $parent['name'],
|
|
'properties' => array(
|
|
'properties' => array(
|
|
- $phylonode->phylonodeprop[0]->type_id->cvterm_id => $phylonode->phylonodeprop[0]->value,
|
|
|
|
|
|
+ $rank_cvterm->cvterm_id => $phylonodeprop[0]->value,
|
|
),
|
|
),
|
|
);
|
|
);
|
|
$parent = $node;
|
|
$parent = $node;
|
|
@@ -414,17 +419,7 @@ class TaxonomyImporter extends TripalImporter {
|
|
}
|
|
}
|
|
|
|
|
|
// Now add in the leaf node
|
|
// Now add in the leaf node
|
|
- $sci_name = $organism->genus . ' ' . $organism->species;
|
|
|
|
- if ($organism->type_id) {
|
|
|
|
- if ($organism->type and $organism->type == 'no_rank') {
|
|
|
|
- $sci_name .= ' ' . $organism->infraspecific_name;
|
|
|
|
- }
|
|
|
|
- else {
|
|
|
|
- $type = tripal_abbreviate_infraspeicifc_rank($organism->type);
|
|
|
|
- $sci_name .= ' ' . $type . ' ' . $organism->infraspecific_name;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ $sci_name = tripal_get_organism_scientific_name($organism);
|
|
$node = array(
|
|
$node = array(
|
|
'name' => $sci_name,
|
|
'name' => $sci_name,
|
|
'depth' => $i,
|
|
'depth' => $i,
|
|
@@ -464,16 +459,7 @@ class TaxonomyImporter extends TripalImporter {
|
|
// if so we should use that instead of the scientific name.
|
|
// if so we should use that instead of the scientific name.
|
|
|
|
|
|
// Build the query string to get the information about this species.
|
|
// Build the query string to get the information about this species.
|
|
- $sci_name = $organism->genus . ' ' . $organism->species;
|
|
|
|
- if ($organism->type_id) {
|
|
|
|
- $type = tripal_abbreviate_infraspeicifc_rank($organism->type);
|
|
|
|
- if ($type) {
|
|
|
|
- $sci_name .= ' ' . $type . ' ' . $infraspecific_name;
|
|
|
|
- }
|
|
|
|
- else {
|
|
|
|
- $sci_name .= ' ' . $infraspecific_name;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ $sci_name = tripal_get_organism_scientific_name($organism);
|
|
$sci_name = urlencode($sci_name);
|
|
$sci_name = urlencode($sci_name);
|
|
$search_url = "http://www.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?".
|
|
$search_url = "http://www.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?".
|
|
"db=taxonomy" .
|
|
"db=taxonomy" .
|
|
@@ -561,36 +547,12 @@ class TaxonomyImporter extends TripalImporter {
|
|
// Second, check if the full name includes the infraspecific name.
|
|
// Second, check if the full name includes the infraspecific name.
|
|
if (!$organism) {
|
|
if (!$organism) {
|
|
foreach ($this->all_orgs as $item) {
|
|
foreach ($this->all_orgs as $item) {
|
|
- if (!$item->type) {
|
|
|
|
- if ($sci_name == trim($item->genus) . ' ' . trim($item->species)) {
|
|
|
|
- $organism = $item;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- else {
|
|
|
|
- if ($item->type == 'no_rank') {
|
|
|
|
- if ($sci_name == trim($item->genus) . ' ' . trim($item->species) . ' ' . trim($item->infraspecific_name)) {
|
|
|
|
- $organism = $item;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- else {
|
|
|
|
- $valid_terms = array(
|
|
|
|
- 'subspecies' => 'subsp.',
|
|
|
|
- 'varietas' => 'var.',
|
|
|
|
- 'subvariety' => 'subvar.',
|
|
|
|
- 'forma' => 'forma',
|
|
|
|
- 'subforma' => 'subforma',
|
|
|
|
- 'strain' => 'strain',
|
|
|
|
- );
|
|
|
|
- if (array_key_exists($rank, $valid_terms)) {
|
|
|
|
- if ($sci_name == trim($item->genus) . ' ' . trim($item->species) . ' ' . $valid_terms[$rank] . ' ' . trim($item->infraspecific_name)) {
|
|
|
|
- $organism = $item;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ $internal_sci_name = tripal_get_organism_scientific_name($item);
|
|
|
|
+ if ($sci_name == $internal_sci_name) {
|
|
|
|
+ $organism = $item;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
return $organism;
|
|
return $organism;
|
|
}
|
|
}
|
|
/**
|
|
/**
|
|
@@ -615,11 +577,19 @@ class TaxonomyImporter extends TripalImporter {
|
|
if (preg_match('/^(.+?)\s+(.+?)\s+(.+)$/', $sci_name, $matches)) {
|
|
if (preg_match('/^(.+?)\s+(.+?)\s+(.+)$/', $sci_name, $matches)) {
|
|
$genus = $matches[1];
|
|
$genus = $matches[1];
|
|
$species = $matches[2];
|
|
$species = $matches[2];
|
|
|
|
+ $infra = $matches[3];
|
|
|
|
+
|
|
|
|
+ // Get the CV term for the rank.
|
|
$type = tripal_get_cvterm(array(
|
|
$type = tripal_get_cvterm(array(
|
|
'name' => preg_replace('/ /','_', $rank),
|
|
'name' => preg_replace('/ /','_', $rank),
|
|
'cv_id' => array('name' => 'taxonomic_rank')
|
|
'cv_id' => array('name' => 'taxonomic_rank')
|
|
));
|
|
));
|
|
- $infra = $matches[3];
|
|
|
|
|
|
+
|
|
|
|
+ // Remove the rank from the infraspecific name.
|
|
|
|
+ $abbrev = tripal_abbreviate_infraspeicifc_rank($rank);
|
|
|
|
+ $infra = preg_replace("/$abbrev/", "", $infra);
|
|
|
|
+ $infra = trim($infra);
|
|
|
|
+
|
|
$values = array(
|
|
$values = array(
|
|
'genus' => $genus,
|
|
'genus' => $genus,
|
|
'species' => $species,
|
|
'species' => $species,
|
|
@@ -690,6 +660,7 @@ class TaxonomyImporter extends TripalImporter {
|
|
$parent = (string) $taxon->ParentTaxId;
|
|
$parent = (string) $taxon->ParentTaxId;
|
|
$rank = (string) $taxon->Rank;
|
|
$rank = (string) $taxon->Rank;
|
|
$sci_name = (string) $taxon->ScientificName;
|
|
$sci_name = (string) $taxon->ScientificName;
|
|
|
|
+ //$this->logMessage(' - Importing @sci_name', array('@sci_name' => $sci_name));
|
|
|
|
|
|
// If we don't have an organism record provided then see if there
|
|
// If we don't have an organism record provided then see if there
|
|
// is one provided by Chado, if not, the try to add one.
|
|
// is one provided by Chado, if not, the try to add one.
|