Just noting that you are not parsing taxonomy XMLs. The output piped from esearch already is using the protein database and esummary ignores -db taxonomy in this instance. If you want to do cross-database searches you will need to use elink. If all you need is taxonomy info (and not sequence) you can do something like:
for i in `cat file_w_accession_one_per_line`; do
printf ${i}"\t"; \
epost -db protein -id ${i} -format acc \
| elink -target taxonomy \
| efetch -format xml \
| xtract -pattern TaxaSet -first ScientificName -element Lineage ;
done > SummaryTable.tsv
If on the other hand, you want the sequence as well, you can simplify it to:
for i in `cat file_w_accession_one_per_line`; do
printf ${i}"\t"; \
efetch -db protein -id ${i} -format xml \
| xtract -pattern Seq-entry -element Org-ref_taxname, OrgName_lineage, NCBIeaa, Textseq-id_accession ;
done > SummaryTable.tsv
Please use the formatting bar (especially the
codeoption) to present your post better. You can use backticks for inline code (`text` becomestext), or select a chunk of text and use the highlighted button to format it as a code block. I've done it for you this time.Thank you! I didn't know that, very helpful :)