2
$\begingroup$

I am using the xtract tool of the Entrez Direct (EDirect) package of NBCI. I have a list of Accession Numbers:

U47804, U47803, U47802, U47801, U47800, U47799, U47798, X92938

and try to get information about:

  1. Name of organism (Org-ref_taxname tag)
  2. Product of gene (Prot-ref_name_E tag)
  3. Public year (Date-std_year tag)

I executed the following command:

for i in {U47804 U47803 U47802 U47801 U47800 U47799 U47798 X92938}
do
  efetch -db "nucleotide" -id "$i" -format full; done |
    xtract -pattern Seq-entry -element Org-ref_taxname \
      -block Prot-ref_name -def "-" -element Prot-ref_name_E \
      -block Date-std -position first -element Date-std_year

The result I got:

Human immunodeficiency virus 1  gp120   1996
Human immunodeficiency virus 1  gp120   1996
Human immunodeficiency virus 1  gp120   1996
Human immunodeficiency virus 1  gp120   1996
Human immunodeficiency virus 1  gp120   1996
Human immunodeficiency virus 1  gp120   1996
Human immunodeficiency virus 1  gp120   1996
Human immunodeficiency virus 1  1995

Because the X92938 doesn't have <Prot-ref_name>, so I was expecting to replace the missing fields with "-" by the -def tag of the extract tool. It means my desired result is as follows:

Human immunodeficiency virus 1  gp120   1996
Human immunodeficiency virus 1  gp120   1996
Human immunodeficiency virus 1  gp120   1996
Human immunodeficiency virus 1  gp120   1996
Human immunodeficiency virus 1  gp120   1996
Human immunodeficiency virus 1  gp120   1996
Human immunodeficiency virus 1  gp120   1996
Human immunodeficiency virus 1    -     1995

Can someone have experience with the NBCI tool may help me? Thanks a lot.

$\endgroup$
2
  • 2
    $\begingroup$ I saw this on stackoverflow but I couldn't figure out the problem. One of the great things about bioinformatics.stackexchange.com is that you can include heaps more detail here; if you could please provide more context it might help e.g. Why do you want this data? Have you looked at other sources e.g. the Rentrez package? Could you post-format the data using e.g. awk? Etc $\endgroup$ Feb 16, 2023 at 23:40
  • $\begingroup$ Thanks for your helpful suggestion. According to your suggestion, I have used Rentrez and realized it is much easier to use and more powerful than the Entrez bash. So in some special cases like creating bioinformatics pipelines, using bash Entrez is a compulsory thing. $\endgroup$ Feb 19, 2023 at 2:37

1 Answer 1

2
$\begingroup$

After trying myself in many ways, I have found that the method of creating a checkmark column when a desired column is recorded is more efficient and easier to understand.

Here is my bash script to solve my problem in a verbose way (I guess has others way shorter).

#!/usr/bin/bash

change_index(){
    local in="$(< /dev/stdin)" # Variable assignment from the stdin
    local col_num=$(head -n 1 <(echo "$in") |awk -F"\t" '{print -1+NF/2}')  # Number of fields

    
    for k in $(seq 0 $(($col_num-1))); do # Loop through number of field
        in=$(awk -v ia="$k" -F"\t"  '{sub("/[^"ia"]","/"ia"\t-\t/"((ia+1)),$(2*ia+1)) ;print $0}' <(echo "$in")) # Supplement missing fields
    done
    
    in=$(awk -v ia="$col_num" -F"\t"  '{sub("/[^"ia"]","/"ia"\t-",$(2*ia+1)) ;print $0}' <(echo "$in")) # Supplement missing the last fields
    in=$(sed 's/\/[[:digit:]]\+//g' <(echo "$in")) # Remove markers
    echo "$in"
}

for i in {U47804 U47803 U47802 U47801 U47800 U47799 U47798 X92938}; do \
    efetch -db "nucleotide" -id "$i" -format full; done |    
    xtract -pattern Seq-entry \
        -lbl "/0" -element Org-ref_taxname \
        -block Prot-ref_name -lbl "/1" -element Prot-ref_name_E \
        -block Date-std -position first -lbl "/2" -element Date-std_year |
    change_index| column -t

Explanation

The main idea is that if a field is recorded there will be a marker field lay before the recorded field. This action is done by -lbl tag. And we have the following draft table:

/0  Human  immunodeficiency  virus  1  /1  gp120  /2  1996
/0  Human  immunodeficiency  virus  1  /1  gp120  /2  1996
/0  Human  immunodeficiency  virus  1  /1  gp120  /2  1996
/0  Human  immunodeficiency  virus  1  /1  gp120  /2  1996
/0  Human  immunodeficiency  virus  1  /1  gp120  /2  1996
/0  Human  immunodeficiency  virus  1  /1  gp120  /2  1996
/0  Human  immunodeficiency  virus  1  /1  gp120  /2  1996
/0  Human  immunodeficiency  virus  1  /2  1995       

After having a draft table, and cleaning the table by change_index() function I wrote.

$\endgroup$

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.