Exemplo n.º 1
0
    def enrich_go(self):
        "count ac2counts(local,global),sel_num"
        sel_num = self.model.count()
        go2ids = {'cc': {}, 'bp': {}, 'mf': {}}
        m_mod = self.model.join(Go, on=(Contig.id == Go.contig))
        for i in m_mod:
            t2gos = json.loads(
                url_tool.post(self.app_conf['url_go_extype'],
                              {'gos': i.gos[0].goid}))
            for j, k in t2gos.items():
                temp = [go2ids[j].setdefault(x, []).append(i.id) for x in k]
        go2ids = {x: y for x, y in go2ids.items() if y}
        # associated tree
        total_gos = []
        temp = [total_gos.extend(y.keys()) for x, y in go2ids.items()]
        go_tree = json.loads(
            url_tool.post(self.app_conf['url_go_type2tree'],
                          {'gos': ','.join(total_gos)}))
        # global data input
        t_info = json.load(
            open(os.path.join(g.conf.static_dir, 'json', 'enrich_go.json')))
        pool_info = {'num': t_info['pool_count'], 'go2num': {}}
        for i, j in go2ids.items():
            for t_goid in j.keys():
                pool_info['go2num'][t_goid] = t_info['go2count'][i][t_goid]

        return {
            'sel_num': sel_num,
            'go2ids': go2ids,
            'pool_info': pool_info,
            'go_tree': go_tree
        }
Exemplo n.º 2
0
 def lineage(self):
     "output taxid map to their lv name + taxname"
     ids = [str(x.taxa_id) for x in self.model]
     t_url = json.loads(url_tool.post(url_tool.make(g.conf.service_conf,'taxa_lv'),\
      {'ids':','.join(ids)}))
     return {
         'tax2names': {
             y: (t_url['lv_name'][x] + [t_url['taxname'][x]])
             for x, y in enumerate(t_url['h_ids'])
         },
         'ex': t_url['ex'],
         'lv_tag': t_url['default_lv']
     }
Exemplo n.º 3
0
 def tax2comp(self):
     "detect component group"
     ids = [str(x.taxa_id) for x in self.model]
     t_url = json.loads(
         url_tool.post(self.app_conf['url_lineage_id'],
                       {'ids': ','.join(ids)}))
     tax2comp = {
         '33208': 'Coral',
         '33630': 'Symbiodinium',
         '33634': 'Symbiodinium',
         '33090': 'Symbiodinium',
         '2': 'Bacteria'
     }
     tax_set = set(tax2comp.keys())
     res = {}
     for i, j in t_url['tax2line'].items():
         t_inter = tax_set.intersection(j)
         if t_inter:
             res[i] = tax2comp[t_inter.pop()]
         else:
             res[i] = 'intermediate homology'
     return res
Exemplo n.º 4
0
 def enrich_kegg(self):
     "count ac2counts(local,global),sel_num"
     sel_num = self.model.count()
     # get anno_db_id
     o_db = Anno_db.get(Anno_db.name == 'kegg')
     ac2ids = {}
     m_mod = self.model.join(
         Anno_info, on=(Contig.id == Anno_info.contig)).join(
             Anno_hit, on=(Anno_hit.id == Anno_info.anno_hit)).join(
                 Anno_db, on=(Anno_db.id == Anno_hit.anno_db))
     for i in m_mod.where(Anno_db.name == o_db.name):
         for j in i.anno_infos:
             if j.anno_hit.anno_db == o_db:
                 t_ac = j.anno_hit.ac
                 ac2ids.setdefault(t_ac, []).append(i.id)
     # associated pathway
     enrich_info = json.loads(
         url_tool.post(self.app_conf['url_enrich_kegg'],
                       {'kos': ','.join(ac2ids.keys())}))
     # global data input
     t_info = json.load(
         open(
             os.path.join(g.conf.static_dir, g.conf.db_conn,
                          'enrich_kegg.json')))
     enrich_info.update({
         'path2count': {
             x: t_info['path2count'][x]
             for x in enrich_info['path2kos'] if x in t_info['path2count']
         },
         'count_pool': t_info['pool_count']
     })
     return {
         'sel_num': sel_num,
         'ac2ids': ac2ids,
         'enrich_info': enrich_info
     }