def search_studies(tags=None, version=None, projectID=None): """ :param tags: optional list of tags :param version: :param projectID: :return: studies that match the filters """ db_session = orm.get_session() study = orm.models.Study try: studies = db_session.query(study) if version: studies = studies.filter(study.version.like('%' + version + '%')) if tags: # return any study that matches at least one tag studies = studies.filter( or_(*[study.tags.contains(tag) for tag in tags])) if projectID: validate_uuid_string('projectID', projectID) studies = studies.filter(study.parentProjectID == projectID) except IdentifierFormatError as e: _report_search_failed('project', e) return [], 200 except orm.ORMException as e: err = _report_search_failed('project', e) return err, 500 return [orm.dump(x) for x in studies], 200
def search_files(tags=None, projectID=None, studyID=None, fileType=None): """ :param tags: optional comma separated tag list :param projectID: optional project identifier :param studyID: optional study identifier :param fileType: optional file type :return: manifest of download URL(s) for matching files """ db_session = orm.get_session() file = orm.models.File try: files = db_session.query(file) if tags: files = files.filter( or_(*[file.tags.contains(tag) for tag in tags])) if projectID: validate_uuid_string('projectID', projectID) study_list = get_study_by_project(projectID) files = files.filter(file.studyID.in_(study_list)) if studyID: validate_uuid_string('studyID', studyID) files = files.filter(file.studyID == studyID) if fileType: files = files.filter(file.fileType == fileType) except IdentifierFormatError as e: _report_search_failed('file', e) return [], 200 except orm.ORMException as e: err = _report_search_failed('file', e) return err, 500 return [orm.dump(x) for x in files], 200
def post_search_expressions(expression_search): # Parse search object version = expression_search.get("version") tags = expression_search.get("tags") studyID = expression_search.get("studyID") projectID = expression_search.get("projectID") sampleID = expression_search.get("sampleID") featureIDList = expression_search.get("featureIDList") featureNameList = expression_search.get("featureNameList") maxExpression = expression_search.get("maxExpression") minExpression = expression_search.get("minExpression") # If not supplied, set defaults file_type = expression_search.get("format", "h5") try: expressions = filter_expression_data(version, tags, studyID, projectID) if not any([ sampleID, featureIDList, featureNameList, maxExpression, minExpression ]): expressions = filter_expression_format(expressions, format) else: # H5 queries responses = [] try: for expr in expressions: file_response = slice_expression_data( expr, sampleID, featureIDList, featureNameList, minExpression, maxExpression, file_type, threshold_label=None, threshold_input_type='object') if file_response: responses.append(file_response) except (ThresholdValueError, UnsupportedOutputError) as e: err = Error(message=str(e), code=400) return err, 400 return responses, 200 except IdentifierFormatError as e: _report_search_failed('expression', e) return [], 200 except orm.ORMException as e: err = _report_search_failed('expression', e) return err, 500 return [orm.dump(expr_matrix) for expr_matrix in expressions], 200
def get_change_log(version): """ :param version: required release version :return: changes associated with specified release version """ db_session = orm.get_session() change_log = orm.models.ChangeLog try: log = db_session.query(change_log)\ .get(version) except orm.ORMException as e: err = _report_search_failed('change log', e) return err, 500 if not log: err = Error(message="Change log not found", code=404) return err, 404 return orm.dump(log), 200
def get_project_by_id(projectId): """ :param projectId: :return: all projects or if projectId specified, corresponding project """ db_session = orm.get_session() project = orm.models.Project try: validate_uuid_string('id', projectId) specified_project = db_session.query(project)\ .get(projectId) except IdentifierFormatError as e: err = Error(message=str(e), code=404) return err, 404 if not specified_project: err = Error(message="Project not found: " + str(projectId), code=404) return err, 404 return orm.dump(specified_project), 200
def get_expression_by_id(expressionId): """ :param expressionId: required identifier :return: a single specified expression matrix """ db_session = orm.get_session() expression = orm.models.File try: validate_uuid_string('id', expressionId) expr_matrix = db_session.query(expression).get(expressionId) except IdentifierFormatError as e: err = Error(message=str(e), code=404) return err, 404 if not expr_matrix: err = Error(message="Expression matrix not found: " + expressionId, code=404) return err, 404 return orm.dump(expr_matrix), 200
def get_study_by_id(studyId): """ :param studyId: required identifier :return: a single specified study """ db_session = orm.get_session() study = orm.models.Study try: validate_uuid_string('studyID', studyId) specified_study = db_session.query(study)\ .get(studyId) except IdentifierFormatError as e: err = Error(message=str(e), code=404) return err, 404 if not specified_study: err = Error(message="Study not found: " + studyId, code=404) return err, 404 return orm.dump(specified_study), 200
def get_file(fileID): """ :param fileID: required identifier :return: a single specified file download URL """ db_session = orm.get_session() file = orm.models.File try: validate_uuid_string('fileID', fileID) file_q = db_session.query(file).get(fileID) except IdentifierFormatError as e: err = Error(message=str(e), code=404) return err, 404 except orm.ORMException as e: err = _report_search_failed('file', e, file_id=fileID) return err, 500 if not file_q: err = Error(message="File not found: " + fileID, code=404) return err, 404 return orm.dump(file_q), 200
def search_projects(tags=None, version=None): """ :param tags: :param version: :return: """ db_session = orm.get_session() project = orm.models.Project try: projects = db_session.query(project) if version: projects = projects.filter( project.version.like('%' + version + '%')) if tags: # return any project that matches at least one tag projects = projects.filter( or_(*[project.tags.contains(tag) for tag in tags])) except orm.ORMException as e: err = _report_search_failed('project', e) return err, 500 return [orm.dump(x) for x in projects], 200
def get_search_expressions(tags=None, sampleID=None, projectID=None, studyID=None, version=None, featureIDList=None, featureNameList=None, minExpression=None, maxExpression=None, featureThresholdLabel="name", format="h5"): """ :param tags: optional Comma separated tag list :param sampleID: optional sample identifier :param projectID: optional project identifier :param studyID: optional study identifier :param version: optional version :param featureIDList: optional filter by listed feature IDs :param featureNameList: optional filter by listed features :param format: output file type (not a part of schema yet) :return: expression matrices matching filters """ try: expressions = filter_expression_data(version, tags, studyID, projectID) if not any([ sampleID, featureIDList, featureNameList, maxExpression, minExpression ]): expressions = filter_expression_format(expressions, format) else: responses = [] try: for expr in expressions: file_response = slice_expression_data( expr, sampleID, featureIDList, featureNameList, minExpression, maxExpression, format, threshold_label=featureThresholdLabel, threshold_input_type='array') if file_response: responses.append(file_response) except (ThresholdValueError, UnsupportedOutputError) as e: err = Error(message=str(e), code=400) return err, 400 return responses, 200 except IdentifierFormatError as e: _report_search_failed('expression', e) return [], 200 except orm.ORMException as e: err = _report_search_failed('expression', e) return err, 500 return [orm.dump(expr_matrix) for expr_matrix in expressions], 200