Exemple #1
0
 def __getitem__(self, key):
     if isinstance(key, Feature):
         key = key.id
     c = self.conn.cursor()
     try:
         c.execute(constants._SELECT + ' WHERE id = ?', (key,))
     except sqlite3.ProgrammingError:
         c.execute(
             constants._SELECT + ' WHERE id = ?',
             (key.decode(self.default_encoding),))
     results = c.fetchone()
     # TODO: raise error if more than one key is found
     if results is None:
         raise FeatureNotFoundError(key)
     return self._feature_returner(**results)
Exemple #2
0
    def get_gene_id_by_name(self, gene_name, select_longest=True):
        try:
            gene_id_list = self._gene_name_to_id_list[gene_name]
        except KeyError:
            raise FeatureNotFoundError(gene_name)

        if len(gene_id_list) == 1:
            gene_id = gene_id_list[0]
        else:
            if select_longest:
                gene_id = self._select_longest_id(gene_id_list)
            else:
                raise ValueError(
                    f'gene_name {gene_name} corresponding to {len(gene_id_list)} '
                    f'{len(gene_id_list)} transcripts: {gene_id_list}. But '
                    f'select_longest=False.')
        return gene_id