コード例 #1
0
ファイル: mirna.py プロジェクト: IlyaLab/ISB-LSDF
    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 = 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)
コード例 #2
0
    def search(self, parameters):
        self.validate_feature_search_input(parameters)

        query = 'SELECT mirna_name, platform, value_field, internal_feature_id ' \
                'FROM {table_name} ' \
                'WHERE mirna_name LIKE %s ' \
                'AND platform LIKE %s ' \
                'AND value_field 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['platform'] + '%',
                      '%' + input['value_field'] + '%',
                      FOUND_FEATURE_LIMIT]

        try:
            db = 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')