Skip to content

Commit

Permalink
Update download shared history cutoff time
Browse files Browse the repository at this point in the history
  • Loading branch information
qiagu committed Mar 23, 2021
1 parent 4ab287b commit a8139eb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
15 changes: 9 additions & 6 deletions cycif_db/galaxy_download/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def download_datasets(destination, *datasets, server=None, api_key=None,
if not gi:
gi = galaxy_client(server=server, api_key=api_key)
dataset_cli = galaxy.datasets.DatasetClient(gi)
his_cli = galaxy.histories.HistoryClient(gi)

if isinstance(destination, str):
destination = pathlib.Path(destination)
Expand All @@ -54,11 +53,9 @@ def download_datasets(destination, *datasets, server=None, api_key=None,
dataset_cli.download_dataset(dataset_id, str(destination),
use_default_filename=True)

annotation = {"server": server or gi.url[:-4]}
annotation = {"server": server or gi.url[:-3]}
history_id = dataset_cli.show_dataset(dataset_id)['history_id']
history_username_and_slug = \
his_cli.show_history(history_id)['username_and_slug']
annotation['history_username_and_slug'] = history_username_and_slug
annotation['history_id'] = history_id
annotation['datasets'] = datasets

with open(destination.joinpath('annotation.txt'), 'w') as fp:
Expand All @@ -82,6 +79,11 @@ def find_markers_csv_and_quantification(his_client, history_id,
--------
None or tuple of dataset_ids ({quantification}, {markers_csv}).
"""
is_ok = his_client.get_histories(history_id, deleted=False)
if not is_ok:
log.error(f"The history `{history_id}` was deleted?")
return

contents = his_client.show_history(history_id, contents=True,
deleted=False, types=['dataset'])
contents = [dataset for dataset in contents if dataset['state'] == 'ok']
Expand Down Expand Up @@ -117,7 +119,8 @@ def is_marker_csv(dataset_meta) -> bool:
if is_naivestate(dataset)]

if not ns_dataset:
log.warn("Error: make sure the history is completed successfully! %s."
log.warn("Error: make sure the history runs cycif workflow and is "
"completed successfully! %s."
% history_id)
return

Expand Down
2 changes: 1 addition & 1 deletion cycif_db/galaxy_download/_list_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class SharedGalaxy(GalaxyDriver):
"""
def __init__(self, browser='Chrome', headless=True, server=None,
username=None, password=None, wait_time=10,
cutoff_time='2021-01-01',
cutoff_time='2021-02-06',
**kwargs) -> None:
super().__init__(browser=browser, headless=headless, server=server,
username=username, password=password, **kwargs)
Expand Down
9 changes: 8 additions & 1 deletion scripts/download_shared_histories.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
parser.add_argument(
'destination', type=str,
help="The folder to save the downloaded files.")
parser.add_argument(
'-c', '--cutoff_time', type=str,
help="Download histories whose update time are later than cutoff time.")
parser.add_argument(
'-v', '--verbose', default=False, action='store_true',
help="Show detailed log.")
Expand All @@ -32,6 +35,10 @@
if args.debug:
logging.basicConfig(level=logging.DEBUG)

shared = SharedGalaxy(browser='Chrome', headless=True, cutoff_time='2021-01-13')
cutoff_time = args.cutoff_time
if not cutoff_time:
cutoff_time = '2021-02-06'

shared = SharedGalaxy(browser='Chrome', headless=True, cutoff_time=cutoff_time)
shared.download(args.destination, server=args.server, api_key=args.api_key)
shared.quit()

0 comments on commit a8139eb

Please sign in to comment.