def cloud_storage_file_paths(self, request): """ Takes a sample barcode as a required parameter and returns cloud storage paths to files associated with that sample. """ cursor = None db = None sample_barcode = request.get_assigned_value('sample_barcode') platform = request.get_assigned_value('platform') pipeline = request.get_assigned_value('pipeline') if are_there_bad_keys(request): err_msg = construct_parameter_error_message(request, False) raise endpoints.BadRequestException(err_msg) query_str, query_tuple = CohortsSamplesFilesQueryBuilder().build_query( platform=platform, pipeline=pipeline, sample_barcode=sample_barcode) try: db = sql_connection() cursor = db.cursor(MySQLdb.cursors.DictCursor) cursor.execute(query_str, query_tuple) cursor_rows = cursor.fetchall() # add 'cloud_storage_path' to cursor_rows bad_repo_count, bad_repo_set = CohortsSamplesFilesMessageBuilder().get_GCS_file_paths_and_bad_repos(cursor_rows) cloud_storage_path_list = [row['cloud_storage_path'] for row in cursor_rows] if bad_repo_count > 0: logger.warn("not returning {count} row(s) in sample_details due to repositories: {bad_repo_list}" .format(count=bad_repo_count, bad_repo_list=list(bad_repo_set))) return GCSFilePathList(cloud_storage_file_paths=cloud_storage_path_list, count=len(cloud_storage_path_list)) except (IndexError, TypeError), e: logger.warn(e) raise endpoints.NotFoundException("File paths for sample {} not found.".format(sample_barcode))
def preview(self, request): """ Takes a JSON object of filters in the request body and returns a "preview" of the cohort that would result from passing a similar request to the cohort **save** endpoint. This preview consists of two lists: the lists of participant (aka patient) barcodes, and the list of sample barcodes. Authentication is not required. """ patient_cursor = None sample_cursor = None if are_there_bad_keys(request) or are_there_no_acceptable_keys(request): err_msg = construct_parameter_error_message(request, True) raise endpoints.BadRequestException(err_msg) query_dict, gte_query_dict, lte_query_dict = CohortsCreatePreviewQueryBuilder().build_query_dictionaries( request ) patient_query_str, sample_query_str, value_tuple = CohortsCreatePreviewQueryBuilder().build_query( query_dict, gte_query_dict, lte_query_dict ) patient_barcodes = [] sample_barcodes = [] try: db = sql_connection() patient_cursor = db.cursor(MySQLdb.cursors.DictCursor) patient_cursor.execute(patient_query_str, value_tuple) for row in patient_cursor.fetchall(): patient_barcodes.append(row["case_barcode"]) sample_cursor = db.cursor(MySQLdb.cursors.DictCursor) sample_cursor.execute(sample_query_str, value_tuple) for row in sample_cursor.fetchall(): sample_barcodes.append(row["sample_barcode"]) except (IndexError, TypeError), e: logger.warn(e) raise endpoints.NotFoundException("Error retrieving samples or patients: {}".format(e))