1
$\begingroup$

I have a long list of uniprot IDs. How can I get the mass of the "canonical" isoform for each? Ideally from some Python library.

$\endgroup$

1 Answer 1

4
$\begingroup$

You don't need any external library, it's enough to query Uniprot and extract the data you want from the response.

Here an example in Python 3:

from urllib.request import urlopen

id = "P42212"
data = urlopen("http://www.uniprot.org/uniprot/" + id + ".txt").read().decode()
result = data.split('SQ   ')[-1] #here all the info you need
mw = int(result.split(';')[1].strip().split()[0]) #extract the molecular weigth
print(mw)

If you want to batch query a lot of sequences then I suggest to sleep(0.5) after each query to avoid problems with their server.

Update

As correctly pointed out by @Jerven (see comment below), you can query the mass directly.

In this case, the code is the following:

from urllib.request import urlopen

id = "P42212"
data = urlopen("http://www.uniprot.org/uniprot/?query=id:{}&format=tab&columns=id,mass".format(id)).read().decode()
result = data.split('\n')[1].replace(',','')
mw = int(result.split('\t')[-1])
print(mw)
$\endgroup$
5
  • $\begingroup$ I don't have Python 3 available, so I can't try this as it is. I am not sure how to translate into Python 2... $\endgroup$
    – a06e
    Commented Nov 21, 2017 at 17:16
  • $\begingroup$ It should be the same, except the import from urllib import urlopen maybe also .decode() can be removed. Of course, print without parentheses. I can't try now. Let me know. $\endgroup$
    – alec_djinn
    Commented Nov 21, 2017 at 17:22
  • 1
    $\begingroup$ You can use the column/tab/csv download to avoid needing to fetch the whole TXT file. Also do keep in mind that these are predicted masses and are not suitable for e.g. MS work as is. e.g. uniprot.org/uniprot/… $\endgroup$
    – Jerven
    Commented Nov 22, 2017 at 15:13
  • $\begingroup$ @Jerven I am not sure how to interpret that table. I agree that it would be nicer to have a smaller text to download, but the masses reported on the link you posted are not related to the whole protein. Can you make an example of how to get the protein mass for ID P42212 using "column/tab/csv download" ? $\endgroup$
    – alec_djinn
    Commented Nov 24, 2017 at 12:27
  • 2
    $\begingroup$ @alec_djinn just add id:P42212 to the query field i.e. uniprot.org/uniprot/… see our help pages for more details uniprot.org/help/programmatic_access $\endgroup$
    – Jerven
    Commented Nov 28, 2017 at 10:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .