Skip to content

Commit

Permalink
Fix GeoSearch elink using retmode xml (#200)
Browse files Browse the repository at this point in the history
* fix GeoSearch elink using retmode xml

* Format

* Update sphinx

---------

Co-authored-by: Saket Choudhary <[email protected]>
  • Loading branch information
jggatter and saketkc authored Sep 17, 2023
1 parent 50994f4 commit fb0a230
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ jobs:
codecov
- uses: ammaraskar/sphinx-action@master
with:
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"
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"
docs-folder: "docs/"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,5 @@ venv.bak/
.mypy_cache/
*.sqlite
*.sqlite.gz

geoweb_downloads/
12 changes: 8 additions & 4 deletions pysradb/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -1660,6 +1660,7 @@ def _format_request(self):
return payload

def search(self):
"""Sends the user query via requests to SRA, GEO DataSets, or both"""
if not self.search_geo:
super().search()
else:
Expand All @@ -1679,7 +1680,7 @@ def search(self):
elink_payload = {
"dbfrom": "gds",
"db": "sra",
"retmode": "json",
"retmode": "xml",
"query_key": query_key,
"WebEnv": web_env,
}
Expand All @@ -1690,9 +1691,12 @@ def search(self):
)
r.raise_for_status()
try:
data = r.json()
uids_from_geo = data["linksets"][0]["linksetdbs"][0]["links"]
except (JSONDecodeError, KeyError, IndexError):
root = Et.fromstring(r.text)
uids_from_geo = [
elem.text
for elem in root.findall(".//LinkSet/LinkSetDb/Link/Id")
]
except (Et.ParseError, TypeError, ValueError):
uids_from_geo = []
# Step 2: Retrieve list of uids from SRA and
# Find the intersection of both lists of uids
Expand Down
6 changes: 4 additions & 2 deletions tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -1179,8 +1179,10 @@ def test_geo_search_1():
instance = GeoSearch(3, 1000, geo_query="human")
instance.search()
df = instance.get_df()
df = instance.get_df()["experiment_accession"].to_list()
assert len(df) > 10
assert not df.empty

experiment_accessions = instance.get_df()["experiment_accession"].to_list()
assert len(experiment_accessions) > 10
# with open("./tests/data/test_search/geo_search_test1.txt", "r") as f:
# expected_accessions = f.read().splitlines()

Expand Down

0 comments on commit fb0a230

Please sign in to comment.