From 3a708a0089c87437bfe5336258a4a63a56a90d29 Mon Sep 17 00:00:00 2001 From: chambm Date: Fri, 13 May 2016 10:53:56 -0500 Subject: [PATCH 1/2] Add filter_failed_datasets_from_collection.py script --- .../filter_failed_datasets_from_collection.py | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 scripts/api/filter_failed_datasets_from_collection.py diff --git a/scripts/api/filter_failed_datasets_from_collection.py b/scripts/api/filter_failed_datasets_from_collection.py new file mode 100644 index 00000000000..d3b0fa88cd1 --- /dev/null +++ b/scripts/api/filter_failed_datasets_from_collection.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python +""" +Given a history name and a collection integer id in that history, this script will split the collection into the failed/pending/empty +datasets "(not ok)" and the successfully finished datasets "(ok)". + +Sample call: +python filter_failed_datasets_from_collection.py MySpecialHistory 1234 +""" +import sys +import bioblend +from bioblend.galaxy import GalaxyInstance +from bioblend.galaxy import dataset_collections as collections + +if (len(sys.argv) < 5): + print("Usage: %s " % sys.argv[0]) + exit(0) + +galaxyUrl = sys.argv[1] +galaxyApiKey = sys.argv[2] +historyName = sys.argv[3] +collectionHistoryId = int(sys.argv[4]) + +gi = GalaxyInstance(url=galaxyUrl, key=galaxyApiKey) + +historyMatches = gi.histories.get_histories(name=historyName) +if (len(historyMatches) > 1): + print("Error: more than one history matches that name.") + exit(1) + +historyId = historyMatches[0]['id'] +historyContents = gi.histories.show_history(historyId, contents=True, deleted=False, visible=True, details=False) +matchingCollections = filter(lambda x: x['hid'] == collectionHistoryId, historyContents) + +if (len(matchingCollections) == 0): + print("Error: no collections matching that id found.") + exit(1) + +if (len(matchingCollections) > 1): + print("Error: more than one collection matching that id found (WTF?)") + exit(1) + +collectionId = matchingCollections[0]['id'] +failedCollection = gi.histories.show_dataset_collection(historyId, collectionId) +okDatasets = filter(lambda d: d['object']['state'] == 'ok' and d['object']['file_size'] > 0, failedCollection['elements']) +notOkDatasets = filter(lambda d: d['object']['state'] != 'ok' or d['object']['file_size'] == 0, failedCollection['elements']) +okCollectionName = failedCollection['name'] + " (ok)"; +notOkCollectionName = failedCollection['name'] + " (not ok)"; + +gi.histories.create_dataset_collection( + history_id=historyId, + collection_description=collections.CollectionDescription( + name=okCollectionName, + elements=[collections.HistoryDatasetElement(d['object']['name'], d['object']['id']) for d in okDatasets])) + +gi.histories.create_dataset_collection( + history_id=historyId, + collection_description=collections.CollectionDescription( + name=notOkCollectionName, + elements=[collections.HistoryDatasetElement(d['object']['name'], d['object']['id']) for d in notOkDatasets])) \ No newline at end of file From 384bdbfe7099bfb5360e0b43af55c99da8b179b0 Mon Sep 17 00:00:00 2001 From: Matt Chambers Date: Fri, 13 May 2016 11:38:48 -0500 Subject: [PATCH 2/2] Fix flaky "errors" --- .../api/filter_failed_datasets_from_collection.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/scripts/api/filter_failed_datasets_from_collection.py b/scripts/api/filter_failed_datasets_from_collection.py index d3b0fa88cd1..a67d4493a67 100644 --- a/scripts/api/filter_failed_datasets_from_collection.py +++ b/scripts/api/filter_failed_datasets_from_collection.py @@ -7,7 +7,6 @@ Sample call: python filter_failed_datasets_from_collection.py MySpecialHistory 1234 """ import sys -import bioblend from bioblend.galaxy import GalaxyInstance from bioblend.galaxy import dataset_collections as collections @@ -26,7 +25,7 @@ historyMatches = gi.histories.get_histories(name=historyName) if (len(historyMatches) > 1): print("Error: more than one history matches that name.") exit(1) - + historyId = historyMatches[0]['id'] historyContents = gi.histories.show_history(historyId, contents=True, deleted=False, visible=True, details=False) matchingCollections = filter(lambda x: x['hid'] == collectionHistoryId, historyContents) @@ -34,17 +33,17 @@ matchingCollections = filter(lambda x: x['hid'] == collectionHistoryId, historyC if (len(matchingCollections) == 0): print("Error: no collections matching that id found.") exit(1) - + if (len(matchingCollections) > 1): print("Error: more than one collection matching that id found (WTF?)") exit(1) - + collectionId = matchingCollections[0]['id'] failedCollection = gi.histories.show_dataset_collection(historyId, collectionId) okDatasets = filter(lambda d: d['object']['state'] == 'ok' and d['object']['file_size'] > 0, failedCollection['elements']) notOkDatasets = filter(lambda d: d['object']['state'] != 'ok' or d['object']['file_size'] == 0, failedCollection['elements']) -okCollectionName = failedCollection['name'] + " (ok)"; -notOkCollectionName = failedCollection['name'] + " (not ok)"; +okCollectionName = failedCollection['name'] + " (ok)" +notOkCollectionName = failedCollection['name'] + " (not ok)" gi.histories.create_dataset_collection( history_id=historyId, @@ -56,4 +55,4 @@ gi.histories.create_dataset_collection( history_id=historyId, collection_description=collections.CollectionDescription( name=notOkCollectionName, - elements=[collections.HistoryDatasetElement(d['object']['name'], d['object']['id']) for d in notOkDatasets])) \ No newline at end of file + elements=[collections.HistoryDatasetElement(d['object']['name'], d['object']['id']) for d in notOkDatasets]))