def get_queries(): """Get galaxy queries (json datasets) Returns ------- json error: True if error, else False errorMessage: the error message of error, else an empty string """ history_id = None if request.method == 'POST': if request.get_json(): history_id = request.get_json().get("history_id") try: galaxy = Galaxy(current_app, session) ginfo = galaxy.get_datasets_and_histories(history_id, query=True) except Exception as e: traceback.print_exc(file=sys.stdout) return jsonify({ 'datasets': [], 'histories': [], 'error': True, 'errorMessage': str(e) }), 500 return jsonify({ 'datasets': ginfo['datasets'], 'histories': ginfo['histories'], 'error': False, 'errorMessage': '' })
def add_galaxy_account(self, user, url, apikey): """Add a Galaxy account Parameters ---------- user : dict Previous user info url : string Galaxy URL apikey : string Galaxy API key Returns ------- dict Updated user """ database = Database(self.app, self.session) galaxy = Galaxy(self.app, self.session, url, apikey) valid = galaxy.check_galaxy_instance() error_message = "Not a valid Galaxy" if valid: error_message = "" query = ''' INSERT INTO galaxy_accounts VALUES( NULL, ?, ?, ? ) ''' database.execute_sql_query( query, (self.session["user"]["id"], url, apikey)) user["galaxy"] = {"url": url, "apikey": apikey} return { "error": not valid, "error_message": error_message, "user": user }
def update_galaxy_account(self, user, url, apikey): """Update a Galaxy account Parameters ---------- user : dict Previous user info url : string Galaxy URL apikey : string Galaxy API key Returns ------- dict Updated user """ database = Database(self.app, self.session) galaxy = Galaxy(self.app, self.session, url, apikey) valid = galaxy.check_galaxy_instance() error_message = "Not a valid Galaxy" if valid: error_message = "" query = ''' UPDATE galaxy_accounts SET url = ?, apikey = ? WHERE user_id = ? ''' database.execute_sql_query( query, (url, apikey, self.session["user"]["id"])) user["galaxy"] = {"url": url, "apikey": apikey} return { "error": not valid, "error_message": error_message, "user": user }
def upload_datasets(): """Download a galaxy datasets into AskOmics Returns ------- json error: True if error, else False errorMessage: the error message of error, else an empty string """ files_utils = FilesUtils(current_app, session) disk_space = files_utils.get_size_occupied_by_user() if "user" in session else None if session["user"]["quota"] > 0 and disk_space >= session["user"]["quota"]: return jsonify({ 'errorMessage': "Exceeded quota", "error": True }), 400 data = request.get_json() if not (data and data.get("datasets_id")): return jsonify({ 'error': True, 'errorMessage': "Missing datasets_id parameter" }), 400 datasets_id = data["datasets_id"] try: galaxy = Galaxy(current_app, session) galaxy.download_datasets(datasets_id) except Exception as e: traceback.print_exc(file=sys.stdout) return jsonify({ 'error': True, 'errorMessage': str(e) }), 500 return jsonify({ 'error': False, 'errorMessage': '' })
def get_dataset_content(): """Download a galaxy datasets into AskOmics Returns ------- json dataset_content: content of the requested Galaxy dataset error: True if error, else False errorMessage: the error message of error, else an empty string """ data = request.get_json() if not (data and data.get("dataset_id")): return jsonify({ 'error': True, 'errorMessage': "Missing dataset_id parameter" }), 400 dataset_id = data["dataset_id"] try: galaxy = Galaxy(current_app, session) dataset_content = galaxy.get_dataset_content(dataset_id) except Exception as e: traceback.print_exc(file=sys.stdout) return jsonify({ 'dataset_content': {}, 'error': True, 'errorMessage': str(e) }), 500 return jsonify({ 'dataset_content': json.loads(dataset_content), 'error': False, 'errorMessage': '' })