def search(self, keyword, field): self.validate_search_field(keyword, field) query = 'SELECT mirna_name, platform, value_field, internal_feature_id ' \ 'FROM {table_name} WHERE {search_field} LIKE %s LIMIT %s'.format( table_name=self.get_table_name(), search_field=field ) # Format the keyword for MySQL string matching sql_keyword = '%' + keyword + '%' query_args = [sql_keyword, FOUND_FEATURE_LIMIT] try: db = get_sql_connection() cursor = db.cursor(DictCursor) cursor.execute(query, tuple(query_args)) items = [] for row in cursor.fetchall(): items.append(row) # Generate human readable labels for item in items: item['feature_type'] = MIRN_FEATURE_TYPE item['label'] = build_feature_label(item) return items except MySQLError: raise BackendException('database error', keyword, field)
def field_value_search(self, keyword, field): self.validate_field_search_input(keyword, field) query = 'SELECT DISTINCT {search_field} FROM {table_name} WHERE {search_field} LIKE %s LIMIT %s'.format( table_name=self.get_table_name(), search_field=field ) # Format the keyword for MySQL string matching sql_keyword = '%' + keyword + '%' query_args = [sql_keyword, FOUND_FEATURE_LIMIT] logging.debug("CLOUDSQL_QUERY_GEXP_FIELDS: {}".format(query)) try: db = get_sql_connection() cursor = db.cursor(DictCursor) cursor.execute(query, tuple(query_args)) items = [] for row in cursor.fetchall(): items.append(row[field]) return items except MySQLError as mse: raise BackendException("MySQLError: {}".format(str(mse)))
def search(self, parameters): self.validate_feature_search_input(parameters) query = 'SELECT gene_name, probe_name, platform, relation_to_gene, relation_to_island, ' \ 'value_field, internal_feature_id ' \ 'FROM {table_name} ' \ 'WHERE gene_name=%s ' \ 'AND probe_name LIKE %s ' \ 'AND platform LIKE %s ' \ 'AND relation_to_gene LIKE %s ' \ 'AND relation_to_island LIKE %s ' \ 'LIMIT %s'.format(table_name=self.get_table_name() ) # Fills in '' for fields that were not specified in the parameters input = defaultdict(lambda: '', parameters) # Format the keyword for MySQL string matching query_args = [ input['gene_name'], '%' + input['probe_name'] + '%', '%' + input['platform'] + '%', '%' + input['relation_to_gene'] + '%', '%' + input['relation_to_island'] + '%', FOUND_FEATURE_LIMIT ] try: db = get_sql_connection() cursor = db.cursor(DictCursor) cursor.execute(query, tuple(query_args)) items = [] for row in cursor.fetchall(): items.append(row) # Generate human readable labels for item in items: item['feature_type'] = METH_FEATURE_TYPE item['label'] = self.build_feature_label(item) return items except MySQLError: raise BackendException('database error')
def search(self, parameters): self.validate_feature_search_input(parameters) query = 'SELECT gene_name, platform, generating_center, value_label, internal_feature_id' \ ' FROM {table_name}' \ ' WHERE gene_name=%s'\ ' AND platform LIKE %s' \ ' AND generating_center LIKE %s'\ ' LIMIT %s'.format(table_name=self.get_table_name() ) logging.debug("CLOUDSQL_QUERY_GEXP_SEARCH: {}".format(query)) # Fills in '' for fields that were not specified in the parameters input = defaultdict(lambda: '', parameters) # Format the keyword for MySQL string matching # sql_keyword = '%' + keyword + '%' query_args = [ input['gene_name'], '%' + input['platform'] + '%', '%' + input['center'] + '%', FOUND_FEATURE_LIMIT ] try: db = get_sql_connection() cursor = db.cursor(DictCursor) cursor.execute(query, tuple(query_args)) items = [] for row in cursor.fetchall(): items.append(row) # Generate human readable labels for item in items: item['feature_type'] = GEXP_FEATURE_TYPE item['label'] = self.build_feature_label( item['gene_name'], item) return items except MySQLError as mse: raise BackendException("MySQLError: {}".format(str(mse)))