Skip to content

Commit

Permalink
Merge pull request #133 from pedro-w/prefetch-check
Browse files Browse the repository at this point in the history
Prefetch check
  • Loading branch information
khoroshevskyi authored Feb 4, 2024
2 parents 095b2bc + cf50094 commit afa41bb
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions geofetch/geofetch.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import copy
import csv
import os
import subprocess
import sys
import requests
import xmltodict
Expand All @@ -11,7 +12,7 @@
from rich.progress import track
import re
import logmuse
from ubiquerg import expandpath, is_command_callable
from ubiquerg import expandpath
from typing import List, Union, Dict, Tuple, NoReturn
import peppy
import pandas as pd
Expand Down Expand Up @@ -63,6 +64,20 @@

_LOGGER = logging.getLogger(__name__)

def is_prefetch_callable() -> bool:
"""
Test if the prefetch command can be run.
:return: True if it is available.
"""
try:
# Option -V means display version and then quit.
subprocess.run(["prefetch", "-V"],
check=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
return True
except (subprocess.SubprocessError, OSError):
return False

class Geofetcher:
"""
Expand Down Expand Up @@ -351,7 +366,7 @@ def get_projects(
new_pr_dict[pr_key] = project_dict[pr_key]

return new_pr_dict

def fetch_all(self, input: str, name: str = None) -> Union[NoReturn, peppy.Project]:
"""
Main function driver/workflow
Expand All @@ -371,18 +386,11 @@ def fetch_all(self, input: str, name: str = None) -> Union[NoReturn, peppy.Proje

# check to make sure prefetch is callable
if not self.just_metadata and not self.processed:
if not is_command_callable("prefetch"):
if os.name == "nt":
_LOGGER.warning(
"GEOfetch is not checking if prefetch is installed on Windows,"
" please make sure it is installed and in your PATH, otherwise "
"it will not be possible to download raw data."
)
else:
raise SystemExit(
"To download raw data You must first install the sratoolkit, with prefetch in your PATH."
" Installation instruction: http://geofetch.databio.org/en/latest/install/"
)
if not is_prefetch_callable():
raise SystemExit(
"To download raw data, you must first install the sratoolkit, with prefetch in your PATH. "
"Installation instruction: http://geofetch.databio.org/en/latest/install/"
)

acc_GSE_list = parse_accessions(
input, self.metadata_expanded, self.just_metadata
Expand Down

0 comments on commit afa41bb

Please sign in to comment.