示例#1
0
    def go_enrichment(self, bioent_ids, callback=None):
        from src.sgd.model.perf.core import Bioentity, Bioconcept
        bioent_format_names = []
        num_chunks = ceil(1.0*len(bioent_ids)/500)
        for i in range(num_chunks):
            bioent_format_names.extend([json.loads(x.json)['format_name'] for x in DBSession.query(Bioentity).filter(Bioentity.id.in_(bioent_ids[i*500:(i+1)*500])).all()])
        enrichment_results = query_batter.query_go_processes(bioent_format_names)
        json_format = []

        for enrichment_result in enrichment_results:
            identifier = 'GO:' + str(int(enrichment_result[0][3:])).zfill(7)
            goterm_id = get_obj_id(str(identifier).upper(), 'BIOCONCEPT', 'GO')
            goterm = json.loads(get_obj(Bioconcept, 'json', goterm_id))
            json_format.append({'go': goterm,
                            'match_count': enrichment_result[1],
                            'pvalue': enrichment_result[2]})
        return json.dumps(json_format)
示例#2
0
def make_enrichment(bioent_ids):
    print len(bioent_ids)
    bioent_ids = list(set(bioent_ids))
    bioent_format_names = []
    num_chunks = int(ceil(1.0*len(bioent_ids)/500))
    for i in range(0, num_chunks):
        bioent_format_names.extend([x.format_name for x in DBSession.query(Locus).filter(Locus.id.in_(bioent_ids[i*500:(i+1)*500])).all()])
    enrichment_results = query_batter.query_go_processes(bioent_format_names)
    json_format = []
    for enrichment_result in enrichment_results:
        try:
            identifier = 'GO:' + str(int(enrichment_result[0][3:])).zfill(7)
            goterm_id = get_obj_id(identifier, class_type='BIOCONCEPT', subclass_type='GO')
            if goterm_id is not None:
                goterm = DBSession.query(Go).filter_by(id=goterm_id).first().to_json()
                json_format.append({'go': goterm,
                                'match_count': enrichment_result[1],
                                'pvalue': enrichment_result[2]})
            else:
                print 'Go term not found: ' + str(enrichment_result[0])
        except:
            print 'Bad GO ID' + enrichment_result[0]

    return json_format