Tripal Plant PopGen Submit
ncbi_utils.inc File Reference

Go to the source code of this file.

Functions

 tpps_ncbi_get_subkingdom ($organism)
 
 tpps_ncbi_get_taxon_id ($organism, $list=FALSE)
 
 tpps_ncbi_get_taxonomy ($organism, $rank)
 

Detailed Description

Defines EUtils functions for NCBI's EUtils API.

Definition in file ncbi_utils.inc.

Function Documentation

◆ tpps_ncbi_get_subkingdom()

tpps_ncbi_get_subkingdom (   $organism)

Retrieves a subkingdom based on an organism name.

Parameters
string$organismThe name of the organism.
Returns
mixed The name of the subkingdom or FALSE on failure.

Definition at line 53 of file ncbi_utils.inc.

53  {
54  $id = tpps_ncbi_get_taxon_id($organism);
55  $fetch = new EFetch('taxonomy');
56  $fetch->addParam('id', "$id");
57  $response = $fetch->get()->xml();
58  if (empty($response->Taxon->Lineage)) {
59  drupal_set_message(t('Unable to load Lineage information from NCBI for organism: @org', array('@org' => $organism)));
60  return FALSE;
61  }
62 
63  $lineage = $response->Taxon->Lineage;
64  if (preg_match('/(angiosperm|gymnosperm)/', $lineage, $matches)) {
65  if (!empty($matches[1])) {
66  return $matches[1];
67  }
68  }
69  drupal_set_message(t('Unable to determine subkingdom from NCBI for organism: @org', array('@org' => $organism)));
70  return FALSE;
71 }
tpps_ncbi_get_taxon_id($organism, $list=FALSE)
Definition: ncbi_utils.inc:82

◆ tpps_ncbi_get_taxon_id()

tpps_ncbi_get_taxon_id (   $organism,
  $list = FALSE 
)

Retrieves the NCBI Taxonomy Id of an organism based on its name.

Parameters
string$organismThe name of the organism.
Returns
mixed The NCBI Taxonomy Id, or FALSE on failure.

Definition at line 82 of file ncbi_utils.inc.

82  {
83  $formatted_org = implode('+', explode(' ', $organism));
84  $search = new ESearch('taxonomy');
85  $search->addParam('term', "{$formatted_org}[Scientific+Name]");
86 
87  $err_msg = 'Unable to load Taxon ID from NCBI for organism named: ' . $organism;
88  try {
89  $response = $search->get()->xml();
90  if (empty($response->IdList->Id)) {
91  drupal_set_message($err_msg);
92  return FALSE;
93  }
94  if (!$list) {
95  return $response->IdList->Id;
96  }
97  return $response->IdList;
98  }
99  catch (\Exception $e) {
100  drupal_set_message($err_msg . ' EUtils Error: ' . $e->getMessage());
101  }
102 }

◆ tpps_ncbi_get_taxonomy()

tpps_ncbi_get_taxonomy (   $organism,
  $rank 
)

Retrieves taxonomy information based on an organism name.

Parameters
string$organismThe name of the organism.
string$rankThe taxonomic rank (subkingdom, order, family, etc).
Returns
mixed The name of the family or FALSE on failure.

Definition at line 19 of file ncbi_utils.inc.

19  {
20  // Subkingdom is a little different.
21  if ($rank == 'subkingdom') {
22  return tpps_ncbi_get_subkingdom($organism);
23  }
24 
25  $id = tpps_ncbi_get_taxon_id($organism);
26  $fetch = new EFetch('taxonomy');
27  $fetch->addParam('id', "$id");
28  $response = $fetch->get()->xml();
29  if (empty($response->Taxon->LineageEx->Taxon)) {
30  drupal_set_message(t('Unable to load Lineage information from NCBI for organism: @org', array('@org' => $organism)));
31  return FALSE;
32  }
33 
34  $lineage = $response->Taxon->LineageEx->Taxon;
35  foreach ($lineage as $item) {
36  if ($item->Rank == $rank) {
37  return $item->ScientificName;
38  }
39  }
40  drupal_set_message("Unable to determine $rank from NCBI for organism: $organism");
41  return FALSE;
42 }
tpps_ncbi_get_taxon_id($organism, $list=FALSE)
Definition: ncbi_utils.inc:82
tpps_ncbi_get_subkingdom($organism)
Definition: ncbi_utils.inc:53