Question: how to get protein sequence biopython
0
gravatar for Xylanaser
2.9 years ago by
Xylanaser60
Poland - Warsaw - SGGW/WULS
Xylanaser60 wrote:

hey what's wrong with my script :(?

from Bio import Entrez
Entrez.email = '<censored>'
import time

def fetch(ID):
    handle = Entrez.efetch(db = 'Protein', id = ID, retmode = 'fasta', rettype = 'text')
    seq = handle.read()
    time.sleep(1)
    return seq
ids = ['ATK1','Cat','Lig1']
out = [fetch(id) for id in ids] 
with open('out.fasta', 'w') as f:
    f.writelines(out)
biopython protein sequence python • 1.2k views
ADD COMMENTlink modified 2.9 years ago by WouterDeCoster43k • written 2.9 years ago by Xylanaser60
1

hey what's the error you're getting?

ADD REPLYlink written 2.9 years ago by st.ph.n2.5k

HTTPError: Bad Request

ADD REPLYlink written 2.9 years ago by Xylanaser60

This?

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/wdecoster/anaconda3/lib/python3.5/site-packages/Bio/Entrez/__init__.py", line 180, in efetch
    return _open(cgi, variables, post=post)
  File "/home/wdecoster/anaconda3/lib/python3.5/site-packages/Bio/Entrez/__init__.py", line 526, in _open
    raise exception
  File "/home/wdecoster/anaconda3/lib/python3.5/site-packages/Bio/Entrez/__init__.py", line 524, in _open
    handle = _urlopen(cgi)
  File "/home/wdecoster/anaconda3/lib/python3.5/urllib/request.py", line 163, in urlopen
    return opener.open(url, data, timeout)
  File "/home/wdecoster/anaconda3/lib/python3.5/urllib/request.py", line 472, in open
    response = meth(req, response)
  File "/home/wdecoster/anaconda3/lib/python3.5/urllib/request.py", line 582, in http_response
    'http', request, response, code, msg, hdrs)
  File "/home/wdecoster/anaconda3/lib/python3.5/urllib/request.py", line 510, in error
    return self._call_chain(*args)
  File "/home/wdecoster/anaconda3/lib/python3.5/urllib/request.py", line 444, in _call_chain
    result = func(*args)
  File "/home/wdecoster/anaconda3/lib/python3.5/urllib/request.py", line 590, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 400: Bad Request
ADD REPLYlink modified 2.9 years ago • written 2.9 years ago by WouterDeCoster43k
File "<ipython-input-42-0be173f176eb>", line 1, in <module>
    runfile('C:/Users/MGrad/Dropbox/Leg/bioPythonSearch.py', wdir='C:/Users/MGrad/Dropbox/Leg')

  File "C:\Users\MGrad\AppData\Local\conda\conda\envs\my_root\lib\site-packages\spyder\utils\site\sitecustomize.py", line 880, in runfile
    execfile(filename, namespace)

  File "C:\Users\MGrad\AppData\Local\conda\conda\envs\my_root\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "C:/Users/MGrad/Dropbox/Leg/bioPythonSearch.py", line 20, in <module>
    out = [fetch(id) for id in ids] # where ids is a Python list containing gene ids/accession numbers

  File "C:/Users/MGrad/Dropbox/Leg/bioPythonSearch.py", line 20, in <listcomp>
    out = [fetch(id) for id in ids] # where ids is a Python list containing gene ids/accession numbers

  File "C:/Users/MGrad/Dropbox/Leg/bioPythonSearch.py", line 14, in fetch
    handle = Entrez.efetch(db = 'Protein', id = ID, retmode = 'fasta', rettype = 'text')

  File "C:\Users\MGrad\AppData\Local\conda\conda\envs\my_root\lib\site-packages\Bio\Entrez\__init__.py", line 180, in efetch
    return _open(cgi, variables, post=post)

  File "C:\Users\MGrad\AppData\Local\conda\conda\envs\my_root\lib\site-packages\Bio\Entrez\__init__.py", line 526, in _open
    raise exception

  File "C:\Users\MGrad\AppData\Local\conda\conda\envs\my_root\lib\site-packages\Bio\Entrez\__init__.py", line 524, in _open
    handle = _urlopen(cgi)

  File "C:\Users\MGrad\AppData\Local\conda\conda\envs\my_root\lib\urllib\request.py", line 223, in urlopen
    return opener.open(url, data, timeout)

  File "C:\Users\MGrad\AppData\Local\conda\conda\envs\my_root\lib\urllib\request.py", line 532, in open
    response = meth(req, response)

  File "C:\Users\MGrad\AppData\Local\conda\conda\envs\my_root\lib\urllib\request.py", line 642, in http_response
    'http', request, response, code, msg, hdrs)

  File "C:\Users\MGrad\AppData\Local\conda\conda\envs\my_root\lib\urllib\request.py", line 570, in error
    return self._call_chain(*args)

  File "C:\Users\MGrad\AppData\Local\conda\conda\envs\my_root\lib\urllib\request.py", line 504, in _call_chain
    result = func(*args)

  File "C:\Users\MGrad\AppData\Local\conda\conda\envs\my_root\lib\urllib\request.py", line 650, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)

HTTPError: Bad Request
ADD REPLYlink written 2.9 years ago by Xylanaser60

See also this thread

ADD REPLYlink written 2.9 years ago by WouterDeCoster43k

FYI, I censored your email address.

ADD REPLYlink written 2.9 years ago by WouterDeCoster43k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 929 users visited in the last hour