예제 #1
0
    def from_user_feature_id(cls, feature_id):
        logging.debug("UserFeatureDef.from_user_feature_id {0}".format(
            str([feature_id])))
        # ID breakdown: project ID:Feature ID
        # Example ID: USER:1:6
        regex = re_compile("^USER:"******"([0-9]+):"
                           # Feature ID
                           "([0-9]+)$")

        feature_fields = regex.findall(feature_id)
        if len(feature_fields) == 0:
            raise FeatureNotFoundException(feature_id)
        project_id, user_feature_id = feature_fields[0]
        bq_id = None
        shared_id = None
        is_numeric = False

        try:
            db = get_sql_connection()
            cursor = db.cursor(MySQLdb.cursors.DictCursor)
            cursor.execute(
                """
                SELECT feature_name, bq_map_id, shared_map_id, is_numeric
                FROM projects_user_feature_definitions
                WHERE id = %s
            """, (user_feature_id, ))
            for row in cursor.fetchall():
                if row['shared_map_id']:
                    shared_id = row['shared_map_id']
                bq_id = row["bq_map_id"]
                is_numeric = row['is_numeric'] == 1

            cursor.close()
            db.close()

        except Exception as e:
            if db: db.close()
            if cursor: cursor.close()
            raise e

        if shared_id is not None:
            return cls.from_feature_id(bq_id, project_id)

        if bq_id is None:
            raise FeatureNotFoundException(feature_id)

        # Else we're querying a very specific feature from a specific project
        bq_table, column_name, symbol = cls.get_table_and_field(bq_id)
        if bq_table is None or column_name is None:
            raise FeatureNotFoundException(feature_id)

        logging.debug("{0} {1} {2}".format(bq_table, column_name, symbol))

        filters = None
        if symbol is not None:
            filters = {'Symbol': symbol}

        return [cls(bq_table, column_name, project_id, is_numeric, filters)]
예제 #2
0
    def from_feature_id(cls, feature_id):
        feature_fields = cls.regex.findall(feature_id)
        if len(feature_fields) == 0:
            raise FeatureNotFoundException(feature_id)
        column_name = feature_fields[0]

        table_field, value_type = cls.get_table_field_and_value_type(column_name)
        if table_field is None:
            raise FeatureNotFoundException(feature_id)

        return cls(table_field, value_type)
    def from_feature_id(cls, feature_id):
        feature_fields = cls.regex.findall(feature_id)
        if len(feature_fields) == 0:
            raise FeatureNotFoundException(feature_id)
        logging.debug(feature_fields)
        value_field, chromosome, start, end = feature_fields[0]

        valid_chr_set = frozenset([str(x)
                                   for x in range(1, 24)] + ['X', 'Y', 'M'])
        if chromosome not in valid_chr_set:
            raise FeatureNotFoundException(feature_id)

        return cls(value_field, chromosome, start, end)
예제 #4
0
    def parse_internal_feature_id(self, feature_id):
        # TODO Better input validation
        feature_type, gene_label, value_field = feature_id.split(':')
        if value_field not in VALUES:
            raise FeatureNotFoundException(feature_id)

        self.feature_type = feature_type
        self.gene_label = gene_label
        self.value_field = value_field
        self.table_info = get_table_info()

        if self.table_info is None:
            raise FeatureNotFoundException(feature_id)

        self.table_name = self.table_info['name']
예제 #5
0
    def from_feature_id(cls, feature_id, project_id=None):
        logging.debug("UserFeatureDef.from_feature_id: {0}".format(
            str([feature_id, project_id])))
        if feature_id is None:
            raise FeatureNotFoundException(feature_id)
        # ID breakdown: project ID:Feature ID
        # Example ID: USER:1:6
        regex = re_compile("^USER:"******"([0-9]+):"
                           # Feature ID
                           "([0-9]+)$")

        feature_fields = regex.findall(feature_id)
        if len(feature_fields) == 0:
            raise FeatureNotFoundException(feature_id)
        project_id, user_feature_id = feature_fields[0]

        try:
            db = get_sql_connection()
            cursor = db.cursor(MySQLdb.cursors.DictCursor)
            cursor.execute(
                """
                SELECT bq_map_id, project_id, is_numeric
                FROM projects_user_feature_definitions
                WHERE id = %s
            """, (user_feature_id, ))

            results = []
            for row in cursor.fetchall():
                bq_table, column_name, symbol = cls.get_table_and_field(
                    row['bq_map_id'])
                filters = None
                if symbol is not None:
                    filters = {'Symbol': symbol}
                results.append(
                    cls(bq_table, column_name, row['project_id'],
                        row['is_numeric'] == 1, filters))

            cursor.close()
            db.close()

            return results

        except Exception as e:
            if db: db.close()
            if cursor: cursor.close()
            raise e
예제 #6
0
    def from_feature_id(cls, feature_id):
        feature_fields = cls.regex.findall(feature_id)
        if len(feature_fields) == 0:
            raise FeatureNotFoundException(feature_id)

        gene_label, protein_name = feature_fields[0]
        return cls(gene_label, protein_name)
예제 #7
0
    def get_provider_class_from_feature_id(cls, feature_id):
        """
        Args:
            feature_id: Feature identifier

        Returns:
            Feature data provider class for the datatype defined in the
            feature identifier.

        Raises:
            FeatureNotFoundException: If the datatype part of the feature
            identifier is unknown.

        """
        feature_type = cls.get_feature_type_string(feature_id)
        if feature_type is None:
            logging.debug("FeatureProviderFactory.from_feature_id: invalid feature ID: " + str(feature_id))
            raise FeatureNotFoundException(feature_id)

        if feature_type == CLINICAL_FEATURE_TYPE:
            return ClinicalFeatureProvider
        elif feature_type == GEXP_FEATURE_TYPE:
            return GEXPFeatureProvider
        elif feature_type == METH_FEATURE_TYPE:
            return METHFeatureProvider
        elif feature_type == CNVR_FEATURE_TYPE:
            return CNVRFeatureProvider
        elif feature_type == RPPA_FEATURE_TYPE:
            return RPPAFeatureProvider
        elif feature_type == MIRN_FEATURE_TYPE:
            return MIRNFeatureProvider
        elif feature_type == GNAB_FEATURE_TYPE:
            return GNABFeatureProvider
        elif feature_type == USER_FEATURE_TYPE:
            return UserFeatureProvider
예제 #8
0
    def from_feature_id(cls, feature_id):
        feature_fields = cls.regex.findall(feature_id)
        if len(feature_fields) == 0:
            raise FeatureNotFoundException(feature_id)

        gene_label, table_id = feature_fields[0]
        value_field = cls.get_table_info(table_id)['value_field']
        return cls(gene_label, value_field, table_id)
예제 #9
0
    def parse_internal_feature_id(self, feature_id):
        self.feature_def = GNABFeatureDef.from_feature_id(feature_id)
        self.table_info = self.get_table_info()

        if self.table_info is None:
            raise FeatureNotFoundException(feature_id)

        self.table_name = self.table_info['name']
예제 #10
0
    def from_feature_id(cls, feature_id):
        feature_fields = cls.regex.findall(feature_id)
        if len(feature_fields) == 0:
            raise FeatureNotFoundException(feature_id)

        mirna_name, table_id = feature_fields[0]
        table_info = cls.get_table_info(table_id)
        platform = table_info['platform']
        value_field = table_info['value_field']

        return cls(mirna_name, platform, value_field, table_id)
예제 #11
0
    def from_feature_id(cls, feature_id):
        # Example ID: METH:cg08246323:HumanMethylation450:methylation_chr16
        regex = re_compile("^METH:"
                           # TODO better validation for probe name
                           "([a-zA-Z0-9_.\-]+):"
                           # platform
                           "(HumanMethylation27|HumanMethylation450):"
                           # validate outside - chromosome 1-23, X, Y, M
                           "methylation_chr(\d|\d\d|X|Y|M)$")

        feature_fields = regex.findall(feature_id)
        if len(feature_fields) == 0:
            raise FeatureNotFoundException(feature_id)
        probe, platform, chromosome = feature_fields[0]

        valid_chr_set = frozenset([str(x)
                                   for x in xrange(1, 24)] + ['X', 'Y', 'M'])
        if chromosome not in valid_chr_set:
            raise FeatureNotFoundException(feature_id)

        return cls(probe, platform, chromosome)
예제 #12
0
    def parse_internal_feature_id(self, feature_id):
        # TODO better feature ID input validation
        feature_type, gene_label, table_id = feature_id.split(':')
        self.feature_type = feature_type
        self.gene_label = gene_label
        self.table_id = table_id
        self.table_info = get_table_info(table_id)

        if self.table_info is None:
            raise FeatureNotFoundException(feature_id)

        self.table_name = self.table_info['table_id']
        self.value_field = self.table_info['value_field']