Transfer GI to taxID by efetch in a loop
1
0
Entering edit mode
6.9 years ago
wyc661217 ▴ 10

I am a new guy and want to add taxID to the fasta file (1.fa) which begins with GI for each line. So firstly I try to get the taxID by efetch through the following code.

cat 1.fa | while read line
do
GI=`grep ">" | cut -d '>' -f 2 | cut -d ' ' -f 1`
wget curl "http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=nuccore&id=${GI}&rettype=fasta&retmode=xml"
done

But it did not work by saying:

--2017-06-01 16:10:48-- http://curl/ Resolving curl (curl)... failed: Name or service not known. wget: unable to resolve host address ‘curl’ URL transformed to HTTPS due to an HSTS policy --2017-06-01 16:10:48-- https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=nuccore&id=X51700.1%0AX68321.1%0AX55027.1%0AZ12029.1%0AX52700.1&rettype=fasta&retmode=xml Resolving eutils.ncbi.nlm.nih.gov eutils.ncbi.nlm.nih.gov)... 130.14.29.110, 2607:f220:41e:4290::110 Connecting to eutils.ncbi.nlm.nih.gov eutils.ncbi.nlm.nih.gov)|130.14.29.110|:443... connected. HTTP request sent, awaiting response... 400 Bad Request 2017-06-01 16:10:49 ERROR 400: Bad Request.

However it works well when replacing the ${GI} to the real GI numbers, like

wget curl "http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=nuccore&id=X51700.1&rettype=fasta&retmode=xml"

And could produce the correct GI no. by

cat 1.fa | while read line
do
GI=`grep ">" | cut -d '>' -f 2 | cut -d ' ' -f 1`
echo "$GI"
done

Could anyone tell me where is the mistake? Thank you guys!

efetch software error GI taxid • 2.3k views
ADD COMMENT
0
Entering edit mode
6.9 years ago
GenoMax 141k

Once you figure out how to get a clean single value for GI (looks like you have multiple values in the example you posted), use only curl with https. Redirect output to a file or use -o filename to save.

ADD COMMENT
0
Entering edit mode

Thanks! I have got the clean GI. And also I tried to curl the https, but it did not work even when I typed the GI manually:

curl "http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=nuccore&id=X52700.1&rettype=fasta&retmode=xml"


<html><head>
301 Moved Permanently
</head><body>

Moved Permanently

The document has moved https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=nuccore&id=X52700.1&rettype=fasta&retmode=xml">here.

</body></html>
ADD REPLY
0
Entering edit mode
ADD REPLY
0
Entering edit mode

It works now. Thanks a lot!!

ADD REPLY

Login before adding your answer.

Traffic: 1697 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6