Skip to content

Commit fb0a230

Browse files
jggattersaketkc
andauthored
Fix GeoSearch elink using retmode xml (#200)
* fix GeoSearch elink using retmode xml * Format * Update sphinx --------- Co-authored-by: Saket Choudhary <[email protected]>
1 parent 50994f4 commit fb0a230

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

.github/workflows/pull_request.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,5 @@ jobs:
3939
codecov
4040
- uses: ammaraskar/sphinx-action@master
4141
with:
42-
pre-build-command: "pip install -r requirements.txt && pip install . && pip install sphinx myst-parser && pip install sphinxcontrib-gtagjs ipython numpydoc sphinx-tabs sphinx_rtd_theme nbsphinx ipython pydata-sphinx-theme nbsphinx-link sphinx-panels"
42+
pre-build-command: "pip install -r requirements.txt && pip install . && pip install -U sphinx myst-parser && pip install sphinxcontrib-gtagjs ipython numpydoc sphinx-tabs sphinx_rtd_theme nbsphinx ipython pydata-sphinx-theme nbsphinx-link sphinx-panels"
4343
docs-folder: "docs/"

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,5 @@ venv.bak/
108108
.mypy_cache/
109109
*.sqlite
110110
*.sqlite.gz
111+
112+
geoweb_downloads/

pysradb/search.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -1660,6 +1660,7 @@ def _format_request(self):
16601660
return payload
16611661

16621662
def search(self):
1663+
"""Sends the user query via requests to SRA, GEO DataSets, or both"""
16631664
if not self.search_geo:
16641665
super().search()
16651666
else:
@@ -1679,7 +1680,7 @@ def search(self):
16791680
elink_payload = {
16801681
"dbfrom": "gds",
16811682
"db": "sra",
1682-
"retmode": "json",
1683+
"retmode": "xml",
16831684
"query_key": query_key,
16841685
"WebEnv": web_env,
16851686
}
@@ -1690,9 +1691,12 @@ def search(self):
16901691
)
16911692
r.raise_for_status()
16921693
try:
1693-
data = r.json()
1694-
uids_from_geo = data["linksets"][0]["linksetdbs"][0]["links"]
1695-
except (JSONDecodeError, KeyError, IndexError):
1694+
root = Et.fromstring(r.text)
1695+
uids_from_geo = [
1696+
elem.text
1697+
for elem in root.findall(".//LinkSet/LinkSetDb/Link/Id")
1698+
]
1699+
except (Et.ParseError, TypeError, ValueError):
16961700
uids_from_geo = []
16971701
# Step 2: Retrieve list of uids from SRA and
16981702
# Find the intersection of both lists of uids

tests/test_search.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1179,8 +1179,10 @@ def test_geo_search_1():
11791179
instance = GeoSearch(3, 1000, geo_query="human")
11801180
instance.search()
11811181
df = instance.get_df()
1182-
df = instance.get_df()["experiment_accession"].to_list()
1183-
assert len(df) > 10
1182+
assert not df.empty
1183+
1184+
experiment_accessions = instance.get_df()["experiment_accession"].to_list()
1185+
assert len(experiment_accessions) > 10
11841186
# with open("./tests/data/test_search/geo_search_test1.txt", "r") as f:
11851187
# expected_accessions = f.read().splitlines()
11861188

0 commit comments

Comments
 (0)