Пример #1
0
    def _get_gene_features(self, db, klass, target_coord, query_coord,
                           where_feature):
        """returns all genes"""
        xref_table = [None, db.getTable('xref')][db.Type == 'core']
        gene_table = db.getTable('gene')

        # after release 65, the gene_id_table is removed. The following is to maintain
        # support for earlier releases.
        if self.GeneralRelease >= 65:
            gene_id_table = None
        else:
            gene_id_table = db.getTable('gene_stable_id')

        # note gene records are at chromosome, not contig, level
        condition = gene_table.c.seq_region_id == query_coord.seq_region_id
        query = self._build_gene_query(db, condition, gene_table,
                                       gene_id_table, xref_table)
        query = location_query(gene_table,
                               query_coord.EnsemblStart,
                               query_coord.EnsemblEnd,
                               query=query,
                               where=where_feature)

        for record in query.execute():
            new = Coordinate(self,
                             CoordName=query_coord.CoordName,
                             Start=record['seq_region_start'],
                             End=record['seq_region_end'],
                             Strand=record['seq_region_strand'],
                             seq_region_id=record['seq_region_id'],
                             ensembl_coord=True)

            gene = klass(self, db, Location=new, data=record)
            yield gene
Пример #2
0
 def _get_gene_features(self, db, klass, target_coord, query_coord,
                        where_feature):
     """returns all genes"""
     xref_table = [None, db.getTable('xref')][db.Type == 'core']
     gene_table = db.getTable('gene')
     
     # after release 65, the gene_id_table is removed. The following is to maintain
     # support for earlier releases.
     if self.GeneralRelease >= 65:
         gene_id_table = None
     else:
         gene_id_table = db.getTable('gene_stable_id')
     
     # note gene records are at chromosome, not contig, level
     condition = gene_table.c.seq_region_id == query_coord.seq_region_id
     query = self._build_gene_query(db, condition, gene_table, gene_id_table, xref_table)
     query = location_query(gene_table, query_coord.EnsemblStart,
                 query_coord.EnsemblEnd, query=query, where=where_feature)
     
     for record in query.execute():
         new = Coordinate(self, CoordName=query_coord.CoordName,
                         Start=record['seq_region_start'],
                         End = record['seq_region_end'],
                         Strand = record['seq_region_strand'], 
                         seq_region_id=record['seq_region_id'],
                         ensembl_coord=True)
         
         gene = klass(self, db, Location=new, data=record)
         yield gene
Пример #3
0
 def _get_repeat_features(self, db, klass, target_coord, query_coord,
                          where_feature):
     """returns Repeat region instances"""
     # we build repeats using coordinates from repeat_feature table
     # the repeat_consensus_id is required to get the repeat name, class
     # and type
     repeat_feature_table = db.getTable('repeat_feature')
     query = sql.select(
         [repeat_feature_table],
         repeat_feature_table.c.seq_region_id == query_coord.seq_region_id)
     query = location_query(repeat_feature_table,
                            query_coord.EnsemblStart,
                            query_coord.EnsemblEnd,
                            query=query,
                            where=where_feature)
     for record in query.execute():
         coord = Coordinate(self,
                            CoordName=query_coord.CoordName,
                            Start=record['seq_region_start'],
                            End=record['seq_region_end'],
                            seq_region_id=record['seq_region_id'],
                            Strand=record['seq_region_strand'],
                            ensembl_coord=True)
         if query_coord.CoordName != target_coord.CoordName:
             coord = asserted_one(
                 get_coord_conversion(coord, target_coord.CoordType,
                                      self.CoreDb))[1]
         # coord = coord.makeRelativeTo(query_coord) #TODO: fix here if query_coord and target_coord have different coordName
         # coord = coord.makeRelativeTo(target_coord, False)
         yield klass(self,
                     db,
                     Location=coord,
                     Score=record['score'],
                     data=record)
Пример #4
0
 def _get_simple_features(self, db, klass, target_coord, query_coord,
                          where_feature):
     """returns feature_type records for the query_coord from the
     simple_feature table. The returned coord is referenced to
     target_coord. At present, only CpG islands being queried."""
     simple_feature_table = db.getTable('simple_feature')
     feature_types = ['CpGisland']
     feature_type_ids=[str(self._feature_type_ids.get(f)) for f in feature_types]
     # fix the following
     query = sql.select([simple_feature_table],
         sql.and_(simple_feature_table.c.analysis_id.in_(feature_type_ids),
         simple_feature_table.c.seq_region_id == query_coord.seq_region_id))
     query = location_query(simple_feature_table,query_coord.EnsemblStart,
                     query_coord.EnsemblEnd, query=query,
                     where=where_feature)
     records = query.execute()
     for record in records:
         coord = Coordinate(self, CoordName=query_coord.CoordName,
                         Start=record['seq_region_start'],
                         End = record['seq_region_end'],
                         seq_region_id=record['seq_region_id'],
                         Strand = record['seq_region_strand'],
                         ensembl_coord=True)
         if query_coord.CoordName != target_coord.CoordName:
             coord = asserted_one(get_coord_conversion(coord, target_coord.CoordType, self.CoreDb))[1]
             
         # coord = coord.makeRelativeTo(query_coord) #TODO: fix here if query_coord and target_coord have different coordName
         # coord = coord.makeRelativeTo(target_coord, False)
         yield klass(self, db, Location=coord, Score=record['score'])
Пример #5
0
 def _get_repeat_features(self, db, klass, target_coord, query_coord, where_feature):
     """returns Repeat region instances"""
     # we build repeats using coordinates from repeat_feature table
     # the repeat_consensus_id is required to get the repeat name, class
     # and type
     repeat_feature_table = db.getTable("repeat_feature")
     query = sql.select([repeat_feature_table], repeat_feature_table.c.seq_region_id == query_coord.seq_region_id)
     query = location_query(
         repeat_feature_table, query_coord.EnsemblStart, query_coord.EnsemblEnd, query=query, where=where_feature
     )
     for record in query.execute():
         coord = Coordinate(
             self,
             CoordName=query_coord.CoordName,
             Start=record["seq_region_start"],
             End=record["seq_region_end"],
             seq_region_id=record["seq_region_id"],
             Strand=record["seq_region_strand"],
             ensembl_coord=True,
         )
         if query_coord.CoordName != target_coord.CoordName:
             coord = asserted_one(get_coord_conversion(coord, target_coord.CoordType, self.CoreDb))[1]
         # coord = coord.makeRelativeTo(query_coord) #TODO: fix here if query_coord and target_coord have different coordName
         # coord = coord.makeRelativeTo(target_coord, False)
         yield klass(self, db, Location=coord, Score=record["score"], data=record)
Пример #6
0
 def _get_variation_features(self, db, klass, target_coord, query_coord, where_feature):
     """returns variation instances within the specified region"""
     # variation features at supercontig level
     var_feature_table = self.VarDb.getTable("variation_feature")
     # note gene records are at chromosome, not contig, level
     query = sql.select([var_feature_table], var_feature_table.c.seq_region_id == query_coord.seq_region_id)
     query = location_query(
         var_feature_table, query_coord.EnsemblStart, query_coord.EnsemblEnd, query=query, where=where_feature
     )
     for record in query.execute():
         yield klass(self, self.CoreDb, Symbol=record["variation_name"], data=record)
Пример #7
0
    def _get_genomic_align_blocks_for_dna_frag_id(self, method_clade_id,
                                                  dnafrag_id, coord):
        genomic_align_table = self.ComparaDb.getTable('genomic_align')
        query = sql.select([genomic_align_table.c.genomic_align_id,
                           genomic_align_table.c.genomic_align_block_id],
                sql.and_(genomic_align_table.c.method_link_species_set_id ==\
                                                    method_clade_id,
                        genomic_align_table.c.dnafrag_id == dnafrag_id))
        query = location_query(genomic_align_table,
                               coord.EnsemblStart,
                               coord.EnsemblEnd,
                               start_col='dnafrag_start',
                               end_col='dnafrag_end',
                               query=query)

        return query.execute().fetchall()
Пример #8
0
 def _get_genomic_align_blocks_for_dna_frag_id(self, method_clade_id,
                                               dnafrag_id, coord):
     genomic_align_table = self.ComparaDb.getTable('genomic_align')
     query = sql.select([genomic_align_table.c.genomic_align_id,
                        genomic_align_table.c.genomic_align_block_id],
             sql.and_(genomic_align_table.c.method_link_species_set_id ==\
                                                 method_clade_id,
                     genomic_align_table.c.dnafrag_id == dnafrag_id))
     query = location_query(genomic_align_table,
                            coord.EnsemblStart,
                            coord.EnsemblEnd,
                            start_col = 'dnafrag_start',
                            end_col = 'dnafrag_end',
                            query = query)
     
     return query.execute().fetchall()
Пример #9
0
 def _get_variation_features(self, db, klass, target_coord, query_coord,
                             where_feature):
     """returns variation instances within the specified region"""
     # variation features at supercontig level
     var_feature_table = self.VarDb.getTable('variation_feature')
     # note gene records are at chromosome, not contig, level
     query = sql.select(
         [var_feature_table],
         var_feature_table.c.seq_region_id == query_coord.seq_region_id)
     query = location_query(var_feature_table,
                            query_coord.EnsemblStart,
                            query_coord.EnsemblEnd,
                            query=query,
                            where=where_feature)
     for record in query.execute():
         yield klass(self,
                     self.CoreDb,
                     Symbol=record['variation_name'],
                     data=record)
Пример #10
0
    def _get_simple_features(self, db, klass, target_coord, query_coord,
                             where_feature):
        """returns feature_type records for the query_coord from the
        simple_feature table. The returned coord is referenced to
        target_coord. At present, only CpG islands being queried."""
        simple_feature_table = db.getTable('simple_feature')
        feature_types = ['CpGisland']
        feature_type_ids = [
            self._feature_type_ids.get(f) for f in feature_types
        ]
        # fix the following
        query = sql.select(
            [simple_feature_table],
            sql.and_(
                simple_feature_table.c.analysis_id.in_(feature_type_ids),
                simple_feature_table.c.seq_region_id ==
                query_coord.seq_region_id))
        query = location_query(simple_feature_table,
                               query_coord.EnsemblStart,
                               query_coord.EnsemblEnd,
                               query=query,
                               where=where_feature)
        records = query.execute()
        for record in records:
            coord = Coordinate(self,
                               CoordName=query_coord.CoordName,
                               Start=record['seq_region_start'],
                               End=record['seq_region_end'],
                               seq_region_id=record['seq_region_id'],
                               Strand=record['seq_region_strand'],
                               ensembl_coord=True)
            if query_coord.CoordName != target_coord.CoordName:
                coord = asserted_one(
                    get_coord_conversion(coord, target_coord.CoordType,
                                         self.CoreDb))[1]

            # coord = coord.makeRelativeTo(query_coord) #TODO: fix here if query_coord and target_coord have different coordName
            # coord = coord.makeRelativeTo(target_coord, False)
            yield klass(self, db, Location=coord, Score=record['score'])
Пример #11
0
 def _get_gene_features(self, db, klass, target_coord, query_coord,
                        where_feature):
     """returns all genes"""
     xref_table = [None, db.getTable('xref')][db.Type == 'core']
     gene_table = db.getTable('gene')
     
     # note gene records are at chromosome, not contig, level
     condition = gene_table.c.seq_region_id == query_coord.seq_region_id
     query = self._build_gene_query(db, condition, gene_table, xref_table)
     query = location_query(gene_table, query_coord.EnsemblStart,
                 query_coord.EnsemblEnd, query=query, where=where_feature)
     for record in query.execute():
         new = Coordinate(self, CoordName=query_coord.CoordName,
                         Start=record['seq_region_start'],
                         End = record['nd'],
                         Strand = record['seq_region_strand'], 
                         seq_region_id=record['seq_region_id'],
                         ensembl_coord=True)
         if query_coord.CoordName != target_coord.CoordName:
             coord = asserted_one(get_coord_conversion(coord, target_coord.CoordType, self.CoreDb))[1]
         
         # TODO: check coord, used 'new' here. where is coord (above line) used? 
         gene = klass(self, db, Location=new, data=record)
         yield gene