-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update to use the v2 API as v1 has been fully discontinued #6
Open
ncoish
wants to merge
8
commits into
sbliven:master
Choose a base branch
from
ncoish:search-v2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+25
−44
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
89c57a9
Update all references to v1 search API to v2
ncoish 930881a
Update metadata_schema to v2
ncoish feaec12
Correct small Downloading typo
ncoish dca553e
Remove deprecated 'range_closed' operator
ncoish 6d6473e
Rename pager request option to paginate for v2
ncoish ebbe3fc
Modify TextQuery to use full_text service
ncoish 3286127
Change API and documentation for v2 version of 'range'
ncoish dbdfe38
Address mypy type issues
ncoish File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
from dataclasses import dataclass | ||
from datetime import date | ||
from typing import ( | ||
Any, | ||
Callable, | ||
Dict, | ||
Generic, | ||
|
@@ -52,6 +53,7 @@ | |
Tuple[int, ...], | ||
Tuple[float, ...], | ||
Tuple[date, ...], | ||
Dict[str, Any], | ||
] | ||
# Types valid for numeric operators | ||
TNumberLike = Union[int, float, date, "Value[int]", "Value[float]", "Value[date]"] | ||
|
@@ -195,7 +197,7 @@ class Terminal(Query): | |
>>> Terminal(value="tubulin") | ||
|
||
A full list of attributes is available in the | ||
`schema <http://search.rcsb.org/rcsbsearch/v1/metadata/schema>`_. | ||
`schema <http://search.rcsb.org/rcsbsearch/v2/metadata/schema>`_. | ||
Operators are documented `here <http://search.rcsb.org/#field-queries>`_. | ||
|
||
The :py:class:`Attr` class provides a more pythonic way of constructing Terminals. | ||
|
@@ -205,7 +207,7 @@ class Terminal(Query): | |
operator: Optional[str] = None | ||
value: Optional[TValue] = None | ||
service: str = "text" | ||
negation: bool = False | ||
negation: Optional[bool] = False | ||
node_id: int = 0 | ||
|
||
def to_dict(self): | ||
|
@@ -274,14 +276,14 @@ def __str__(self): | |
class TextQuery(Terminal): | ||
"""Special case of a Terminal for free-text queries""" | ||
|
||
def __init__(self, value: str, negation: bool = False): | ||
def __init__(self, value: str): | ||
"""Search for the string value anywhere in the text | ||
|
||
Args: | ||
value: free-text query | ||
negation: find structures without the pattern | ||
""" | ||
super().__init__(value=value, negation=negation) | ||
super().__init__(service="full_text", value=value, negation=None) | ||
|
||
|
||
@dataclass(frozen=True) | ||
|
@@ -343,7 +345,7 @@ def _assign_ids(self, node_id=0) -> Tuple[Query, int]: | |
return (self, node_id) | ||
|
||
def __str__(self): | ||
"" # hide in documentation | ||
"""""" # hide in documentation | ||
if self.operator == "and": | ||
return f"({' & '.join((str(n) for n in self.nodes))})" | ||
elif self.operator == "or": | ||
|
@@ -378,9 +380,7 @@ class Attr: | |
+--------------------+---------------------+ | ||
| equals | attr == date,number | | ||
+--------------------+---------------------+ | ||
| range | attr[start:end] | | ||
+--------------------+---------------------+ | ||
| range_closed | | | ||
| range | dict (keys below)* | | ||
+--------------------+---------------------+ | ||
| exists | bool(attr) | | ||
+--------------------+---------------------+ | ||
|
@@ -392,8 +392,13 @@ class Attr: | |
Pre-instantiated attributes are available from the | ||
:py:data:`rcsbsearch.rcsb_attributes` object. These are generally easier to use | ||
than constructing Attr objects by hand. A complete list of valid attributes is | ||
available in the `schema <http://search.rcsb.org/rcsbsearch/v1/metadata/schema>`_. | ||
available in the `schema <http://search.rcsb.org/rcsbsearch/v2/metadata/schema>`_. | ||
|
||
* The `range` dictionary requires the following keys: | ||
* "from" -> int | ||
* "to" -> int | ||
* "include_lower" -> bool | ||
* "include_upper" -> bool | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's unclear to me if this is the best change of API that we want in the library, but it is a direct change to the new format specified in v2. Open to suggestions! |
||
""" | ||
|
||
attribute: str | ||
|
@@ -454,7 +459,7 @@ def equals(self, value: TNumberLike) -> Terminal: | |
value = value.value | ||
return Terminal(self.attribute, "equals", value) | ||
|
||
def range(self, value: Union[List[int], Tuple[int, int]]) -> Terminal: | ||
def range(self, value: Dict[str, Any]) -> Terminal: | ||
"""Attribute is within the specified half-open range | ||
|
||
Args: | ||
|
@@ -464,21 +469,6 @@ def range(self, value: Union[List[int], Tuple[int, int]]) -> Terminal: | |
value = value.value | ||
return Terminal(self.attribute, "range", value) | ||
|
||
def range_closed( | ||
self, | ||
value: Union[ | ||
List[int], Tuple[int, int], "Value[List[int]]", "Value[Tuple[int, int]]" | ||
], | ||
) -> Terminal: | ||
"""Attribute is within the specified closed range | ||
|
||
Args: | ||
value: lower and upper bounds `[a, b]` | ||
""" | ||
if isinstance(value, Value): | ||
value = value.value | ||
return Terminal(self.attribute, "range_closed", value) | ||
|
||
def exists(self) -> Terminal: | ||
"""Attribute is defined for the structure""" | ||
return Terminal(self.attribute, "exists") | ||
|
@@ -729,16 +719,7 @@ def equals(self, value: TNumberLike) -> Query: | |
... | ||
|
||
@_attr_delegate(Attr.range) | ||
def range(self, value: Union[List[int], Tuple[int, int]]) -> Query: | ||
... | ||
|
||
@_attr_delegate(Attr.range_closed) | ||
def range_closed( | ||
self, | ||
value: Union[ | ||
List[int], Tuple[int, int], "Value[List[int]]", "Value[Tuple[int, int]]" | ||
], | ||
) -> Query: | ||
def range(self, value: Dict[str, Any]) -> Query: | ||
... | ||
|
||
@_attr_delegate(Attr.exists) | ||
|
@@ -974,7 +955,7 @@ class Session(Iterable[str]): | |
Handles paging the query and parsing results | ||
""" | ||
|
||
url = "http://search.rcsb.org/rcsbsearch/v1/query" | ||
url = "http://search.rcsb.org/rcsbsearch/v2/query" | ||
query_id: str | ||
query: Query | ||
return_type: ReturnType | ||
|
@@ -1012,7 +993,7 @@ def _make_params(self, start=0): | |
query=self.query.to_dict(), | ||
return_type=self.return_type, | ||
request_info=dict(query_id=self.query_id, src="ui"), # TODO src deprecated? | ||
request_options=dict(pager=dict(start=start, rows=self.rows)), | ||
request_options=dict(paginate=dict(start=start, rows=self.rows)), | ||
) | ||
|
||
def _single_query(self, start=0) -> Optional[Dict]: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally I think we should swap this to
None
as well, but I was afraid of breaking existing workflows which depend on this default. Instead I am passingnegation=None
in theTextQuery
classsuper().__init__
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I'm now seeing that this might have been a longer-standing error which was raised in another PR:
#5