1
$\begingroup$

I am using the following one-liner with NCBI entrez to query their databases from the terminal (see Entrez Direct: E-utilities on the Unix Command Line:

esearch -db assembly -query ${species name} |
    xtract -pattern ENTREZ_DIRECT -element Count

This works a charm but occasionally it sends an xml error that messes up the output.

Here is an example of the error:

xml
FAILURE ( Fri Jan 27 01:12:44 PM CST 2023 )
nquire -url https://eutils.ncbi.nlm.nih.gov/entrez/eutils/ esearch.fcgi -retmax 0 -usehistory y -db assembly -term "Crepis commutata" -tool edirect -edirect 18.7 -edirect_os Linux -email {}
<ErrorList>
  <PhraseNotFound>commutata</PhraseNotFound>
  <PhraseNotFound>Crepis commutata[All Fields]</PhraseNotFound>
<ErrorList>
SECOND ATTEMPT

Entrez, unfortunately, does not have a man page or --help entry on my installation for some reason and I am not quite sure where I should change the one-liner to change this behavior.

Does anyone have any clues?

$\endgroup$

1 Answer 1

1
$\begingroup$

This is because there are not assemblies for Crepis commutate within NCBI's assembly database.

The cross check is here:

https://www.ncbi.nlm.nih.gov/assembly/?term=Crepis+commutata

The output is a bit clearer than Entrez

The following terms were not found in Assembly: commutata, Crepis commutata[All Fields]. No items found.

All you need do to correct it is issue a next statement in the a loop of species above the code you've presented.

if [[ "$species" == 'Crepis commutata' ]]; then
  continue
fi
esearch -db assembly -query "$species" | xtract -pattern ENTREZ_DIRECT -element Count

To answer the comments if this is done via a Python subprocess, you could simply issue the following code (which has not been checked)

import subprocess

for species in List:
    try:
        subprocess.run(["esearch", "-db" "assembly", "-query", f"${species}", "|", "xtract", "-pattern", "ENTREZ_DIRECT", "-", "element"], shell=True")
    except ValueError as ve:
        print(f'Species {species}, is not present.')
        continue
$\endgroup$
2
  • $\begingroup$ Right but is there a way to set entrez tools to pipe the error? Being able to do that would help me clean up the output produced from an automated session a bit easier. Crepis commutate no existing on NCBI is not the issue, rather not being able to cleanly pipe the outcome is the issue. $\endgroup$
    – Sudoh
    Commented Jan 27, 2023 at 19:38
  • 1
    $\begingroup$ 2>&1 Merge stderr into stdout ; stackoverflow.com/questions/818255/what-does-21-mean $\endgroup$
    – pippo1980
    Commented Jan 27, 2023 at 23:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.