Skip to content

Commit af2e032

Browse files
committed
Fix doctest
1 parent b6aae93 commit af2e032

File tree

1 file changed

+46
-46
lines changed

1 file changed

+46
-46
lines changed

src/biotite/database/rcsb/query.py

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
class Query(metaclass=abc.ABCMeta):
3333
"""
3434
A representation of a JSON query for the RCSB search API.
35-
35+
3636
This is the abstract base class for all queries.
3737
"""
3838
@abc.abstractmethod
@@ -62,7 +62,7 @@ def __or__(self, query):
6262
class SingleQuery(Query, metaclass=abc.ABCMeta):
6363
"""
6464
A terminal query node for the RCSB search API.
65-
65+
6666
Multiple :class:`SingleQuery` objects can be combined to
6767
:class:`CompositeQuery`objects using the ``|`` and ``&`` operators.
6868
@@ -77,7 +77,7 @@ def get_content(self):
7777
class CompositeQuery(Query):
7878
"""
7979
A group query node for the RCSB search API.
80-
80+
8181
A composite query is an combination of other queries, combined
8282
either with the `'and'` or `'or'` operator.
8383
Usually, a :class:`CompositeQuery` will not be created by calling
@@ -98,11 +98,11 @@ def __init__(self, queries, operator):
9898
f"Operator must be 'or' or 'and', not '{operator}'"
9999
)
100100
self._operator = operator
101-
101+
102102
def get_content(self):
103103
"""
104104
A dictionary representation of the query.
105-
This dictionary is the content of the ``'query'`` key in the
105+
This dictionary is the content of the ``'query'`` key in the
106106
JSON query.
107107
108108
Returns
@@ -133,13 +133,13 @@ class BasicQuery(SingleQuery):
133133
The matching is not case-sensitive.
134134
Logic combinations of terms is described
135135
`here <https://search.rcsb.org/#basic-queries>`_.
136-
136+
137137
Examples
138138
--------
139-
139+
140140
>>> query = BasicQuery("tc5b")
141-
>>> print(search(query))
142-
['1L2Y', '8ANM', '8ANH', '8ANG', '8ANI']
141+
>>> print(sorted(search(query)))
142+
['1L2Y', '8ANG', '8ANH', '8ANI', '8ANM']
143143
"""
144144
def __init__(self, term):
145145
super().__init__()
@@ -207,7 +207,7 @@ class FieldQuery(SingleQuery):
207207
208208
Examples
209209
--------
210-
210+
211211
>>> query = FieldQuery("reflns.d_resolution_high", less_or_equal=0.6)
212212
>>> print(sorted(search(query)))
213213
['1EJG', '1I0T', '3NIR', '3P4J', '4JLJ', '5D8V', '5NW3', '7ATG', '7R0H']
@@ -218,7 +218,7 @@ def __init__(self, field, molecular_definition=False, case_sensitive=False, **kw
218218
self._field = field
219219
self._mol_definition = molecular_definition
220220
self._case_sensitive = case_sensitive
221-
221+
222222
if len(kwargs) > 1:
223223
raise TypeError("Only one operator must be given")
224224
elif len(kwargs) == 1:
@@ -228,7 +228,7 @@ def __init__(self, field, molecular_definition=False, case_sensitive=False, **kw
228228
# No operator is given
229229
self._operator = "exists"
230230
self._value = None
231-
231+
232232
if self._operator not in [
233233
"exact_match",
234234
"contains_words", "contains_phrase",
@@ -241,7 +241,7 @@ def __init__(self, field, molecular_definition=False, case_sensitive=False, **kw
241241
f"Constructor got an unexpected keyword argument "
242242
f"'{self._operator}'"
243243
)
244-
244+
245245
# Convert dates into ISO 8601
246246
if isinstance(self._value, datetime):
247247
self._value = _to_isoformat(self._value)
@@ -250,7 +250,7 @@ def __init__(self, field, molecular_definition=False, case_sensitive=False, **kw
250250
_to_isoformat(val) if isinstance(val, datetime) else val
251251
for val in self._value
252252
]
253-
253+
254254
# Create dictionary for 'range' operator
255255
if self._operator == "range":
256256
self._value = {
@@ -266,7 +266,7 @@ def __init__(self, field, molecular_definition=False, case_sensitive=False, **kw
266266
"to": self._value[1],
267267
"include_upper": True
268268
}
269-
269+
270270
# Rename operators to names used in API
271271
if self._operator == "is_in":
272272
# 'in' is not an available parameter name in Python
@@ -326,7 +326,7 @@ class SequenceQuery(SingleQuery):
326326
327327
Examples
328328
--------
329-
329+
330330
>>> sequence = "NLYIQWLKDGGPSSGRPPPS"
331331
>>> query = SequenceQuery(sequence, scope="protein", min_identity=0.8)
332332
>>> print(sorted(search(query)))
@@ -338,12 +338,12 @@ def __init__(self, sequence, scope,
338338
self._target = _scope_to_target.get(scope.lower())
339339
if self._target is None:
340340
raise ValueError(f"'{scope}' is an invalid scope")
341-
341+
342342
if isinstance(sequence, NucleotideSequence) and scope.lower() == "rna":
343343
self._sequence = str(sequence).replace("T", "U")
344344
else:
345345
self._sequence = str(sequence)
346-
346+
347347
self._min_identity = min_identity
348348
self._max_expect_value = max_expect_value
349349

@@ -371,10 +371,10 @@ class MotifQuery(SingleQuery):
371371
The type of the pattern.
372372
scope : {'protein', 'dna', 'rna'}
373373
The type of molecule to find.
374-
374+
375375
Examples
376376
--------
377-
377+
378378
>>> query = MotifQuery(
379379
... "C-x(2,4)-C-x(3)-[LIVMFYWC]-x(8)-H-x(3,5)-H.",
380380
... "prosite",
@@ -416,7 +416,7 @@ class StructureQuery(SingleQuery):
416416
strict : bool, optional
417417
If true, structure comparison is strict, otherwise it is
418418
relaxed.
419-
419+
420420
Examples
421421
--------
422422
@@ -442,7 +442,7 @@ def __init__(self, pdb_id, chain=None, assembly=None, strict=True):
442442
"entry_id": pdb_id,
443443
"asym_id": chain
444444
}
445-
445+
446446
self._operator = "strict_shape_match" if strict \
447447
else "relaxed_shape_match"
448448

@@ -462,15 +462,15 @@ class Sorting:
462462
def __init__(self, field, descending=True):
463463
self._field = field
464464
self._descending = descending
465-
465+
466466
@property
467467
def field(self):
468468
return self._field
469469

470470
@property
471471
def descending(self):
472472
return self._descending
473-
473+
474474
def get_content(self):
475475
"""
476476
Get the sorting content, i.e. the data belonging to the
@@ -497,7 +497,7 @@ def get_content(self):
497497

498498
class Grouping(metaclass=abc.ABCMeta):
499499
"""
500-
A representation of the JSON grouping options of the RCSB search
500+
A representation of the JSON grouping options of the RCSB search
501501
API.
502502
503503
Parameters
@@ -521,7 +521,7 @@ def __init__(self, sort_by=None):
521521
self._sorting = sort_by
522522
else:
523523
self._sorting = Sorting(sort_by)
524-
524+
525525
@abc.abstractmethod
526526
def get_content(self):
527527
"""
@@ -542,7 +542,7 @@ def get_content(self):
542542
return {"ranking_criteria_type" : self._sorting.get_content()}
543543
else:
544544
return {}
545-
545+
546546
@abc.abstractmethod
547547
def is_compatible_return_type(self, return_type):
548548
"""
@@ -555,7 +555,7 @@ def is_compatible_return_type(self, return_type):
555555
----------
556556
return_type : str
557557
The ``return_type`` attribute to be checked.
558-
558+
559559
Returns
560560
-------
561561
is_compatible : bool
@@ -593,7 +593,7 @@ def get_content(self):
593593
content = super().get_content()
594594
content["aggregation_method"] = "matching_deposit_group_id"
595595
return content
596-
596+
597597
def is_compatible_return_type(self, return_type):
598598
return return_type == "entry"
599599

@@ -640,7 +640,7 @@ def get_content(self):
640640
content["aggregation_method"] = "sequence_identity"
641641
content["similarity_cutoff"] = self._similarity_cutoff
642642
return content
643-
643+
644644
def is_compatible_return_type(self, return_type):
645645
return return_type == "polymer_entity"
646646

@@ -672,7 +672,7 @@ def get_content(self):
672672
content = super().get_content()
673673
content["aggregation_method"] = "matching_uniprot_accession"
674674
return content
675-
675+
676676
def is_compatible_return_type(self, return_type):
677677
return return_type == "polymer_entity"
678678

@@ -685,9 +685,9 @@ def count(query, return_type="entry", group_by=None,
685685
"""
686686
Count PDB entries that meet the given query requirements,
687687
via the RCSB search API.
688-
688+
689689
This function requires an internet connection.
690-
690+
691691
Parameters
692692
----------
693693
query : Query
@@ -719,17 +719,17 @@ def count(query, return_type="entry", group_by=None,
719719
count : int
720720
The total number of PDB IDs (or groups) that would be returned
721721
by calling :func:`search()` using the same parameters.
722-
722+
723723
Notes
724724
-----
725725
If `group_by` is set, the number of results may be lower than in an
726726
ungrouped query, as grouping is not applicable to all structures.
727727
For example a DNA structure has no associated *Uniprot* accession
728728
and hence is omitted by :class:`UniprotGrouping`.
729-
729+
730730
Examples
731731
--------
732-
732+
733733
>>> query = FieldQuery("reflns.d_resolution_high", less_or_equal=0.6)
734734
>>> print(count(query))
735735
9
@@ -742,9 +742,9 @@ def count(query, return_type="entry", group_by=None,
742742
)
743743

744744
query_dict["request_options"]["return_counts"] = True
745-
745+
746746
r = requests.get(_search_url, params={"json": json.dumps(query_dict)})
747-
747+
748748
if r.status_code == 200:
749749
if group_by is None:
750750
return r.json()["total_count"]
@@ -766,9 +766,9 @@ def search(query, return_type="entry", range=None, sort_by=None, group_by=None,
766766
"""
767767
Get all PDB IDs that meet the given query requirements,
768768
via the RCSB search API.
769-
769+
770770
This function requires an internet connection.
771-
771+
772772
Parameters
773773
----------
774774
query : Query
@@ -786,7 +786,7 @@ def search(query, return_type="entry", range=None, sort_by=None, group_by=None,
786786
of non-polymeric entities is returned (e.g. ``'XXXX_1'``).
787787
- ``'polymer_instance'``: The PDB ID appended with chain ID
788788
(more exactly ``'asym_id'``) is returned (e.g. ``'XXXX.A'``).
789-
789+
790790
range : tuple(int, int), optional
791791
If this parameter is specified, only PDB IDs in this range
792792
are selected from all matching PDB IDs and returned
@@ -832,7 +832,7 @@ def search(query, return_type="entry", range=None, sort_by=None, group_by=None,
832832
returned.
833833
This dictionary maps group identifiers to a list of all PDB IDs
834834
belonging to this group.
835-
835+
836836
Notes
837837
-----
838838
If `group_by` is set, the number of results may be lower than in an
@@ -846,7 +846,7 @@ def search(query, return_type="entry", range=None, sort_by=None, group_by=None,
846846
847847
Examples
848848
--------
849-
849+
850850
>>> query = FieldQuery("reflns.d_resolution_high", less_or_equal=0.6)
851851
>>> print(sorted(search(query)))
852852
['1EJG', '1I0T', '3NIR', '3P4J', '4JLJ', '5D8V', '5NW3', '7ATG', '7R0H']
@@ -894,7 +894,7 @@ def search(query, return_type="entry", range=None, sort_by=None, group_by=None,
894894
}
895895

896896
r = requests.get(_search_url, params={"json": json.dumps(query_dict)})
897-
897+
898898
if r.status_code == 200:
899899
if group_by is None or not return_groups:
900900
return [result["identifier"] for result in r.json()["result_set"]]
@@ -926,9 +926,9 @@ def _initialize_query_dict(query, return_type, group_by, content_types):
926926
"polymer_entity", "non_polymer_entity",
927927
]:
928928
raise ValueError(f"'{return_type}' is an invalid return type")
929-
929+
930930
request_options = {}
931-
931+
932932
if len(content_types) == 0:
933933
raise ValueError("At least one content type must be specified")
934934
for content_type in content_types:

0 commit comments

Comments
 (0)