문제

단백질 데이터베이스 인 Uniprot에서 결과를 얻으려고 노력하고 있습니다 (세부 사항은 중요하지 않음). 한 종류의 ID에서 다른 종류로 변환되는 스크립트를 사용하려고합니다. 브라우저에서 수동으로 할 수 있었지만 파이썬에서는 할 수 없었습니다.

~ 안에 http://www.uniprot.org/faq/28 샘플 스크립트가 있습니다. 나는 perl을 시도했는데 작동하는 것 같습니다. 그래서 문제는 내 파이썬 시도입니다. (작동) 스크립트는 다음과 같습니다.

## tool_example.pl ##
use strict;
use warnings;
use LWP::UserAgent;

my $base = 'http://www.uniprot.org';
my $tool = 'mapping';
my $params = {
  from => 'ACC', to => 'P_REFSEQ_AC', format => 'tab',
  query => 'P13368 P20806 Q9UM73 P97793 Q17192'
};

my $agent = LWP::UserAgent->new;
push @{$agent->requests_redirectable}, 'POST';
print STDERR "Submitting...\n";
my $response = $agent->post("$base/$tool/", $params);

while (my $wait = $response->header('Retry-After')) {
  print STDERR "Waiting ($wait)...\n";
  sleep $wait;
  print STDERR "Checking...\n";
  $response = $agent->get($response->base);
}

$response->is_success ?
  print $response->content :
  die 'Failed, got ' . $response->status_line . 
    ' for ' . $response->request->uri . "\n";

내 질문은 다음과 같습니다.

1) 파이썬에서 어떻게 하시겠습니까?

2) (예 : 쿼리 필드에서 많은 항목을 사용하는 대량 규모”를 할 수 있습니까?

도움이 되었습니까?

해결책

질문 1:

이것은 Python의 urllibs를 사용하여 수행 할 수 있습니다.

import urllib, urllib2
import time
import sys

query = ' '.join(sys.argv)   

# encode params as a list of 2-tuples
params = ( ('from','ACC'), ('to', 'P_REFSEQ_AC'), ('format','tab'), ('query', query))
# url encode them
data = urllib.urlencode(params)    
url = 'http://www.uniprot.org/mapping/'

# fetch the data
try:
    foo = urllib2.urlopen(url, data)
except urllib2.HttpError, e:
    if e.code == 503:
        # blah blah get the value of the header...
        wait_time = int(e.hdrs.get('Retry-after', 0))
        print 'Sleeping %i seconds...' % (wait_time,)
        time.sleep(wait_time)
        foo = urllib2.urlopen(url, data)


# foo is a file-like object, do with it what you will.
foo.read()

다른 팁

EBI의 단백질 식별자 크로스 참조 서비스를 사용하여 한 ID 세트를 다른 ID 세트로 변환하는 것이 좋습니다. 그것은 매우 좋은 휴식 인터페이스를 가지고 있습니다.

http://www.ebi.ac.uk/tools/picr/

또한 Uniprot은 매우 우수한 웹 서비스를 사용할 수 있다고 언급해야합니다. 어떤 이유로 간단한 HTTP 요청을 사용하는 경우 유용하지 않을 것입니다.

Python 2.5를 사용하고 있다고 가정 해 봅시다. 우리는 사용할 수 있습니다 httplib 웹 사이트를 직접 전화하려면 :

import httplib, urllib
querystring = {}
#Build the query string here from the following keys (query, format, columns, compress, limit, offset)
querystring["query"] = "" 
querystring["format"] = "" # one of html | tab | fasta | gff | txt | xml | rdf | rss | list
querystring["columns"] = "" # the columns you want comma seperated
querystring["compress"] = "" # yes or no
## These may be optional
querystring["limit"] = "" # I guess if you only want a few rows
querystring["offset"] = "" # bring on paging 

##From the examples - query=organism:9606+AND+antigen&format=xml&compress=no
##Delete the following and replace with your query
querystring = {}
querystring["query"] =  "organism:9606 AND antigen" 
querystring["format"] = "xml" #make it human readable
querystring["compress"] = "no" #I don't want to have to unzip

conn = httplib.HTTPConnection("www.uniprot.org")
conn.request("GET", "/uniprot/?"+ urllib.urlencode(querystring))
r1 = conn.getresponse()
if r1.status == 200:
   data1 = r1.read()
   print data1  #or do something with it

그런 다음 쿼리 문자열 생성과 관련하여 기능을 만들 수 있으며 멀리 있어야합니다.

이것 좀 봐 bioservices. Python을 통해 많은 데이터베이스를 인터페이스합니다.https://pythonhosted.org/bioservices/_modules/bioservices/uniprot.html

conda install bioservices --yes

O.RKA 답변을 보완하여 :

질문 1:

from bioservices import UniProt
u = UniProt()
res = u.get_df("P13368 P20806 Q9UM73 P97793 Q17192".split())

이는 각 항목에 대한 모든 정보와 함께 데이터 프레임을 반환합니다.

Question 2: 같은 대답. 이것은 확장해야합니다.

부인 성명: 저는 바이오 서비스의 저자입니다

PIP에는 파이썬 패키지가 있습니다.

pip install uniprot-mapper
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top