Download all SRA of one species
1
0
Entering edit mode
7.5 years ago
nhaituan ▴ 10

I try to run the code below

!/usr/bin/python2.7

import json, urllib

query = '"Vibrio cholerae O1"[Organism]"'

params = {'db':'sra', 'term':query, 'usehistory':'y', 'retmode':'json',}
url = 'http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi' stream = urllib.urlopen(url, urllib.urlencode(params)) answer = json.loads(stream.read()) webenv = answer["esearchresult"]["webenv"] query_key = answer["esearchresult"]["querykey"]

params = {'db':'sra', 'save':'efetch', 'rettype':'runinfo', 'WebEnv':webenv, 'query_key':query_key,} url = 'http://trace.ncbi.nlm.nih.gov/Traces/sra/sra.cgi' outfile = 'runinfo.csv' urllib.urlretrieve(url, data=urllib.urlencode(params), filename=outfile)

#

Up to line answer = json.loads(stream.read()) It prompts error :

answer = json.loads(stream.read()) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python2.7/json/__init__.py", line 339, in loads return _default_decoder.decode(s) File "/usr/lib/python2.7/json/decoder.py", line 364, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib/python2.7/json/decoder.py", line 382, in raw_decode raise ValueError("No JSON object could be decoded") ValueError: No JSON object could be decoded

Is there any solution or suggestion, it would be highly appreciated.

software error • 1.8k views
ADD COMMENT
0
Entering edit mode
ADD COMMENT

Login before adding your answer.

Traffic: 1926 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