どのように聞UniProt上HTTP Python?
-
23-08-2019 - |
質問
ようにしているものの結果からUniProtであるタンパク質データベース(詳細がきを持参してください。.私は利用しようといくつかのスクリプトに変換するかのようなIDです。ることができたこの手のブラウザでないとエラーになります。
に http://www.uniprot.org/faq/28 ありサンプルのイントロダクションです。またPerlの一つというので問題は私のPythonのことを伝え、"よくやった!(動作)スクリプト:
## 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)どういうPython?
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()
他のヒント
あなたは別のIDの1セットを変換するために、EBIからのタンパク質識別子クロスリファレンスサービスを使用してオフにおそらく方がよいでしょう。それは非常に良いRESTインターフェースを持っています。
http://www.ebi.ac.uk/Tools/picr/
私はまた、UniProtのが利用可能非常に良いWebサービスを持っていることを言及する必要があります。あなたは、その後、何らかの理由で単純な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())
こ返しますdataframeすべての情報を入力します。
質問2 同じ答えになります。この規模です。
免責事項:私の著書であるbioservices
PIPでのpythonパッケージには、正確に何をしたいんこれがある
pip install uniprot-mapper