Tripal Plant PopGen Submit
ncbi_utils.inc
Go to the documentation of this file.
1 <?php
2 
19 function tpps_ncbi_get_taxonomy($organism, $rank) {
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 }
43 
53 function tpps_ncbi_get_subkingdom($organism) {
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 }
72 
82 function tpps_ncbi_get_taxon_id($organism, $list = FALSE) {
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_taxon_id($organism, $list=FALSE)
Definition: ncbi_utils.inc:82
tpps_ncbi_get_taxonomy($organism, $rank)
Definition: ncbi_utils.inc:19
tpps_ncbi_get_subkingdom($organism)
Definition: ncbi_utils.inc:53