Package: unipressed
UnipressedPlease visit theproject websitefor more comprehensive documentation.IntroductionUnipressed (Uniprot REST) is an API client for the protein databaseUniprot.
It provides thoroughly typed and documented code to ensure your use of the library is easy, fast, and correct!ExampleLet's say we're interested in very long proteins that are encoded within a chloroplast, in any organism:fromunipressedimportUniprotkbClientforrecordinUniprotkbClient.search(query={"and_":[{"organelle":"chloroplast"},{"length":(5000,"*")}]},fields=["length","gene_names"]).each_record():display(record){'primaryAccession':'A0A088CK67','genes':[{'geneName':{'evidences':[{'evidenceCode':'ECO:0000313','source':'EMBL','id':'AID67672.1'}],'value':'ftsH'}}],'sequence':{'length':5242}}AdvantagesDetailed type hints for autocompleting queries as you typeAutocompletion for return fieldsDocumentation for each fieldAutomatic results parsing, forjson,tsv,list, andxmlBuilt-in pagination, so you don't have to handle any of that yourself!Most of the API is automatically generated, ensuring very rapid updates whenever the API changesThoroughly tested, with 41 unit tests and counting!UsageInstallationIf you're using poetry:poetryaddunipressedOtherwise:pipinstallunipressedDataset ClientsTheunipressedmodule exports a client object for each UniProt dataset:fromunipressedimportUniprotkbClient,UniparcClientWith one of these clients, you can search the dataset:records=UniprotkbClient.search({"length":(5000,6000)}).each_record()# Show the first recordnext(records){'entryType':'UniProtKB reviewed (Swiss-Prot)','primaryAccession':'Q96RW7','secondaryAccessions':...,'uniProtkbId':'HMCN1_HUMAN','entryAudit':...,'annotationScore':5.0,'organism':...,'proteinExistence':'1: Evidence at protein level','proteinDescription':...,'genes':...,'comments':...,'features':...,'keywords':...,'references':...,'uniProtKBCrossReferences':...,'sequence':...,'extraAttributes':...}You can request a single record by ID:UniprotkbClient.fetch_one("Q96RW7"){'entryType':'UniProtKB reviewed (Swiss-Prot)','primaryAccession':'Q96RW7','secondaryAccessions':...,'uniProtkbId':'HMCN1_HUMAN','entryAudit':...,'annotationScore':5.0,'organism':...,'proteinExistence':'1: Evidence at protein level','proteinDescription':...,'genes':...,'comments':...,'features':...,'keywords':...,'references':...,'uniProtKBCrossReferences':...,'sequence':...,'extraAttributes':...}You can also request multiple records:UniprotkbClient.fetch_many(["A0A0C5B5G6","A0A1B0GTW7"])[{'entryType':'UniProtKB reviewed (Swiss-Prot)','primaryAccession':'A0A0C5B5G6','uniProtkbId':'MOTSC_HUMAN','entryAudit':...,'annotationScore':5.0,'organism':...,'proteinExistence':'1: Evidence at protein level','proteinDescription':...,'genes':...,'comments':...,'features':...,'geneLocations':...,'keywords':...,'references':...,'uniProtKBCrossReferences':...,'sequence':...,'extraAttributes':...},{'entryType':'UniProtKB reviewed (Swiss-Prot)','primaryAccession':'A0A1B0GTW7','secondaryAccessions':...,'uniProtkbId':'CIROP_HUMAN','entryAudit':...,'annotationScore':5.0,'organism':...,'proteinExistence':'1: Evidence at protein level','proteinDescription':...,'genes':...,'comments':...,'features':...,'keywords':...,'references':...,'uniProtKBCrossReferences':...,'sequence':...,'extraAttributes':...}]ID MappingUnipressed also provides one other unique client, which is designed for mapping identifiers. You provide the source and destination database (both of which will autocomplete in VS Code), and a list of identifiers for the source database.fromunipressedimportIdMappingClientrequest=IdMappingClient.submit(source="UniProtKB_AC-ID",dest="Gene_Name",ids={"A1L190","A0JP26","A0PK11"})list(request.each_result())[{'from':'A1L190','to':'SYCE3'},{'from':'A0PK11','to':'CLRN2'},{'from':'A0JP26','to':'POTEB3'}]Note that, if you submit a large number of IDs, you might need to add asleep()call between submitting the request and retrieving the results.Query SyntaxThe query syntax refers to the values you pass in to thequeryargument of thesearch()method.In general, you can't go wrong by following the type hints.
I strongly recommend using something likepylanceforVisual Studio Code, which will provide automatic completions and warn you when you have used the wrong syntax.If you already know how to use the Uniprot query language, you can always just input your queries as strings:UniprotkbClient.search(query="(gene:BRCA*) AND (organism_id:10090)")However, if you want some built-in query validation and code completion using Python's type system, then you can instead use a dictionary.
The simplest query is a dictionary with a single key:UniprotkbClient.search(query={"family":"kinase"})You can compile more complex queries using theand_,or_andnot_keys.
These first two operators take a list of query dictionaries:UniprotkbClient.search(query={"and_":[{"family":"kinase"},{"organism_id":"9606"},]})Most "leaf" nodes of the query tree (ie those that aren't operators likeand_) are strings, integers or floats, which you input as normal Python literals as you can see above.
For string fields, you also have access to wildcards, namely the*character.
For example, if you want every human protein belonging to a gene whose name starts withPRO, you could use:UniprotkbClient.search(query={"and_":[{"gene":"PRO*"},{"organism_id":"9606"},]})A few query fields areranges, which you input using a tuple with two elements, indicating the start and end of the range.
If you use the literal"*"then you can leave the range open at one end.
For example, this query returns any protein that is in the range $[5000, \infty)$UniprotkbClient.search(query={"length":(5000,"*")})Finally, a few query fields take dates.
These you input as a Pythondatetime.dateobject.
For example, to find proteins added to UniProt since July 2022, we would do:fromdatetimeimportdateUniprotkbClient.search(query={"date_created":(date(2022,7,1),"*")})Use with Visual Studio CodeTo get VS Code to offer suggestions, press theTrigger Suggestshortcut which is usually bound toCtrl + Space.
In particular, code completion generally won't workuntilyou open a string literal using a quotation mark.Secondly, to get live access to the documentation, you can either use theShow Hovershortcut, which is usually bound toCtrl + K, Ctrl + I, or you can install thedocs-viewextension, which lets you view the docstrings in the sidebar without interfering with your code.